OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [i386/] [math-emu/] [errors.c] - Diff between revs 1765 and 1782

Only display areas with differences | Details | Blame | View Log

Rev 1765 Rev 1782
/*---------------------------------------------------------------------------+
/*---------------------------------------------------------------------------+
 |  errors.c                                                                 |
 |  errors.c                                                                 |
 |                                                                           |
 |                                                                           |
 |  The error handling functions for wm-FPU-emu                              |
 |  The error handling functions for wm-FPU-emu                              |
 |                                                                           |
 |                                                                           |
 | Copyright (C) 1992,1993,1994,1996                                         |
 | Copyright (C) 1992,1993,1994,1996                                         |
 |                  W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
 |                  W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
 |                  E-mail   billm@jacobi.maths.monash.edu.au                |
 |                  E-mail   billm@jacobi.maths.monash.edu.au                |
 |                                                                           |
 |                                                                           |
 |                                                                           |
 |                                                                           |
 +---------------------------------------------------------------------------*/
 +---------------------------------------------------------------------------*/
 
 
/*---------------------------------------------------------------------------+
/*---------------------------------------------------------------------------+
 | Note:                                                                     |
 | Note:                                                                     |
 |    The file contains code which accesses user memory.                     |
 |    The file contains code which accesses user memory.                     |
 |    Emulator static data may change when user memory is accessed, due to   |
 |    Emulator static data may change when user memory is accessed, due to   |
 |    other processes using the emulator while swapping is in progress.      |
 |    other processes using the emulator while swapping is in progress.      |
 +---------------------------------------------------------------------------*/
 +---------------------------------------------------------------------------*/
 
 
#include <linux/signal.h>
#include <linux/signal.h>
 
 
#include <asm/segment.h>
#include <asm/segment.h>
 
 
#include "fpu_system.h"
#include "fpu_system.h"
#include "exception.h"
#include "exception.h"
#include "fpu_emu.h"
#include "fpu_emu.h"
#include "status_w.h"
#include "status_w.h"
#include "control_w.h"
#include "control_w.h"
#include "reg_constant.h"
#include "reg_constant.h"
#include "version.h"
#include "version.h"
 
 
/* */
/* */
#undef PRINT_MESSAGES
#undef PRINT_MESSAGES
/* */
/* */
 
 
 
 
void Un_impl(void)
void Un_impl(void)
{
{
  unsigned char byte1, FPU_modrm;
  unsigned char byte1, FPU_modrm;
  unsigned long address = FPU_ORIG_EIP;
  unsigned long address = FPU_ORIG_EIP;
 
 
  RE_ENTRANT_CHECK_OFF;
  RE_ENTRANT_CHECK_OFF;
  /* No need to verify_area(), we have previously fetched these bytes. */
  /* No need to verify_area(), we have previously fetched these bytes. */
  printk("Unimplemented FPU Opcode at eip=%p : ", (void *) address);
  printk("Unimplemented FPU Opcode at eip=%p : ", (void *) address);
  if ( FPU_CS == USER_CS )
  if ( FPU_CS == USER_CS )
    {
    {
      while ( 1 )
      while ( 1 )
        {
        {
          byte1 = get_fs_byte((unsigned char *) address);
          byte1 = get_fs_byte((unsigned char *) address);
          if ( (byte1 & 0xf8) == 0xd8 ) break;
          if ( (byte1 & 0xf8) == 0xd8 ) break;
          printk("[%02x]", byte1);
          printk("[%02x]", byte1);
          address++;
          address++;
        }
        }
      printk("%02x ", byte1);
      printk("%02x ", byte1);
      FPU_modrm = get_fs_byte(1 + (unsigned char *) address);
      FPU_modrm = get_fs_byte(1 + (unsigned char *) address);
 
 
      if (FPU_modrm >= 0300)
      if (FPU_modrm >= 0300)
        printk("%02x (%02x+%d)\n", FPU_modrm, FPU_modrm & 0xf8, FPU_modrm & 7);
        printk("%02x (%02x+%d)\n", FPU_modrm, FPU_modrm & 0xf8, FPU_modrm & 7);
      else
      else
        printk("/%d\n", (FPU_modrm >> 3) & 7);
        printk("/%d\n", (FPU_modrm >> 3) & 7);
    }
    }
  else
  else
    {
    {
      printk("cs selector = %04x\n", FPU_CS);
      printk("cs selector = %04x\n", FPU_CS);
    }
    }
 
 
  RE_ENTRANT_CHECK_ON;
  RE_ENTRANT_CHECK_ON;
 
 
  EXCEPTION(EX_Invalid);
  EXCEPTION(EX_Invalid);
 
 
}
}
 
 
 
 
/*
/*
   Called for opcodes which are illegal and which are known to result in a
   Called for opcodes which are illegal and which are known to result in a
   SIGILL with a real 80486.
   SIGILL with a real 80486.
   */
   */
void FPU_illegal(void)
void FPU_illegal(void)
{
{
  math_abort(FPU_info,SIGILL);
  math_abort(FPU_info,SIGILL);
}
}
 
 
 
 
 
 
void emu_printall(void)
void emu_printall(void)
{
{
  int i;
  int i;
  static const char *tag_desc[] = { "Valid", "Zero", "ERROR", "ERROR",
  static const char *tag_desc[] = { "Valid", "Zero", "ERROR", "ERROR",
                              "DeNorm", "Inf", "NaN", "Empty" };
                              "DeNorm", "Inf", "NaN", "Empty" };
  unsigned char byte1, FPU_modrm;
  unsigned char byte1, FPU_modrm;
  unsigned long address = FPU_ORIG_EIP;
  unsigned long address = FPU_ORIG_EIP;
 
 
  RE_ENTRANT_CHECK_OFF;
  RE_ENTRANT_CHECK_OFF;
  /* No need to verify_area(), we have previously fetched these bytes. */
  /* No need to verify_area(), we have previously fetched these bytes. */
  printk("At %p:", (void *) address);
  printk("At %p:", (void *) address);
  if ( FPU_CS == USER_CS )
  if ( FPU_CS == USER_CS )
    {
    {
#define MAX_PRINTED_BYTES 20
#define MAX_PRINTED_BYTES 20
      for ( i = 0; i < MAX_PRINTED_BYTES; i++ )
      for ( i = 0; i < MAX_PRINTED_BYTES; i++ )
        {
        {
          byte1 = get_fs_byte((unsigned char *) address);
          byte1 = get_fs_byte((unsigned char *) address);
          if ( (byte1 & 0xf8) == 0xd8 )
          if ( (byte1 & 0xf8) == 0xd8 )
            {
            {
              printk(" %02x", byte1);
              printk(" %02x", byte1);
              break;
              break;
            }
            }
          printk(" [%02x]", byte1);
          printk(" [%02x]", byte1);
          address++;
          address++;
        }
        }
      if ( i == MAX_PRINTED_BYTES )
      if ( i == MAX_PRINTED_BYTES )
        printk(" [more..]\n");
        printk(" [more..]\n");
      else
      else
        {
        {
          FPU_modrm = get_fs_byte(1 + (unsigned char *) address);
          FPU_modrm = get_fs_byte(1 + (unsigned char *) address);
 
 
          if (FPU_modrm >= 0300)
          if (FPU_modrm >= 0300)
            printk(" %02x (%02x+%d)\n", FPU_modrm, FPU_modrm & 0xf8, FPU_modrm & 7);
            printk(" %02x (%02x+%d)\n", FPU_modrm, FPU_modrm & 0xf8, FPU_modrm & 7);
          else
          else
            printk(" /%d, mod=%d rm=%d\n",
            printk(" /%d, mod=%d rm=%d\n",
                   (FPU_modrm >> 3) & 7, (FPU_modrm >> 6) & 3, FPU_modrm & 7);
                   (FPU_modrm >> 3) & 7, (FPU_modrm >> 6) & 3, FPU_modrm & 7);
        }
        }
    }
    }
  else
  else
    {
    {
      printk("%04x\n", FPU_CS);
      printk("%04x\n", FPU_CS);
    }
    }
 
 
  partial_status = status_word();
  partial_status = status_word();
 
 
#ifdef DEBUGGING
#ifdef DEBUGGING
if ( partial_status & SW_Backward )    printk("SW: backward compatibility\n");
if ( partial_status & SW_Backward )    printk("SW: backward compatibility\n");
if ( partial_status & SW_C3 )          printk("SW: condition bit 3\n");
if ( partial_status & SW_C3 )          printk("SW: condition bit 3\n");
if ( partial_status & SW_C2 )          printk("SW: condition bit 2\n");
if ( partial_status & SW_C2 )          printk("SW: condition bit 2\n");
if ( partial_status & SW_C1 )          printk("SW: condition bit 1\n");
if ( partial_status & SW_C1 )          printk("SW: condition bit 1\n");
if ( partial_status & SW_C0 )          printk("SW: condition bit 0\n");
if ( partial_status & SW_C0 )          printk("SW: condition bit 0\n");
if ( partial_status & SW_Summary )     printk("SW: exception summary\n");
if ( partial_status & SW_Summary )     printk("SW: exception summary\n");
if ( partial_status & SW_Stack_Fault ) printk("SW: stack fault\n");
if ( partial_status & SW_Stack_Fault ) printk("SW: stack fault\n");
if ( partial_status & SW_Precision )   printk("SW: loss of precision\n");
if ( partial_status & SW_Precision )   printk("SW: loss of precision\n");
if ( partial_status & SW_Underflow )   printk("SW: underflow\n");
if ( partial_status & SW_Underflow )   printk("SW: underflow\n");
if ( partial_status & SW_Overflow )    printk("SW: overflow\n");
if ( partial_status & SW_Overflow )    printk("SW: overflow\n");
if ( partial_status & SW_Zero_Div )    printk("SW: divide by zero\n");
if ( partial_status & SW_Zero_Div )    printk("SW: divide by zero\n");
if ( partial_status & SW_Denorm_Op )   printk("SW: denormalized operand\n");
if ( partial_status & SW_Denorm_Op )   printk("SW: denormalized operand\n");
if ( partial_status & SW_Invalid )     printk("SW: invalid operation\n");
if ( partial_status & SW_Invalid )     printk("SW: invalid operation\n");
#endif DEBUGGING
#endif DEBUGGING
 
 
  printk(" SW: b=%d st=%ld es=%d sf=%d cc=%d%d%d%d ef=%d%d%d%d%d%d\n",
  printk(" SW: b=%d st=%ld es=%d sf=%d cc=%d%d%d%d ef=%d%d%d%d%d%d\n",
         partial_status & 0x8000 ? 1 : 0,   /* busy */
         partial_status & 0x8000 ? 1 : 0,   /* busy */
         (partial_status & 0x3800) >> 11,   /* stack top pointer */
         (partial_status & 0x3800) >> 11,   /* stack top pointer */
         partial_status & 0x80 ? 1 : 0,     /* Error summary status */
         partial_status & 0x80 ? 1 : 0,     /* Error summary status */
         partial_status & 0x40 ? 1 : 0,     /* Stack flag */
         partial_status & 0x40 ? 1 : 0,     /* Stack flag */
         partial_status & SW_C3?1:0, partial_status & SW_C2?1:0, /* cc */
         partial_status & SW_C3?1:0, partial_status & SW_C2?1:0, /* cc */
         partial_status & SW_C1?1:0, partial_status & SW_C0?1:0, /* cc */
         partial_status & SW_C1?1:0, partial_status & SW_C0?1:0, /* cc */
         partial_status & SW_Precision?1:0, partial_status & SW_Underflow?1:0,
         partial_status & SW_Precision?1:0, partial_status & SW_Underflow?1:0,
         partial_status & SW_Overflow?1:0, partial_status & SW_Zero_Div?1:0,
         partial_status & SW_Overflow?1:0, partial_status & SW_Zero_Div?1:0,
         partial_status & SW_Denorm_Op?1:0, partial_status & SW_Invalid?1:0);
         partial_status & SW_Denorm_Op?1:0, partial_status & SW_Invalid?1:0);
 
 
printk(" CW: ic=%d rc=%ld%ld pc=%ld%ld iem=%d     ef=%d%d%d%d%d%d\n",
printk(" CW: ic=%d rc=%ld%ld pc=%ld%ld iem=%d     ef=%d%d%d%d%d%d\n",
         control_word & 0x1000 ? 1 : 0,
         control_word & 0x1000 ? 1 : 0,
         (control_word & 0x800) >> 11, (control_word & 0x400) >> 10,
         (control_word & 0x800) >> 11, (control_word & 0x400) >> 10,
         (control_word & 0x200) >> 9, (control_word & 0x100) >> 8,
         (control_word & 0x200) >> 9, (control_word & 0x100) >> 8,
         control_word & 0x80 ? 1 : 0,
         control_word & 0x80 ? 1 : 0,
         control_word & SW_Precision?1:0, control_word & SW_Underflow?1:0,
         control_word & SW_Precision?1:0, control_word & SW_Underflow?1:0,
         control_word & SW_Overflow?1:0, control_word & SW_Zero_Div?1:0,
         control_word & SW_Overflow?1:0, control_word & SW_Zero_Div?1:0,
         control_word & SW_Denorm_Op?1:0, control_word & SW_Invalid?1:0);
         control_word & SW_Denorm_Op?1:0, control_word & SW_Invalid?1:0);
 
 
  for ( i = 0; i < 8; i++ )
  for ( i = 0; i < 8; i++ )
    {
    {
      FPU_REG *r = &st(i);
      FPU_REG *r = &st(i);
      char tagi = r->tag;
      char tagi = r->tag;
      switch (tagi)
      switch (tagi)
        {
        {
        case TW_Empty:
        case TW_Empty:
          continue;
          continue;
          break;
          break;
        case TW_Zero:
        case TW_Zero:
#if 0
#if 0
          printk("st(%d)  %c .0000 0000 0000 0000         ",
          printk("st(%d)  %c .0000 0000 0000 0000         ",
                 i, r->sign ? '-' : '+');
                 i, r->sign ? '-' : '+');
          break;
          break;
#endif
#endif
        case TW_Valid:
        case TW_Valid:
        case TW_NaN:
        case TW_NaN:
/*      case TW_Denormal: */
/*      case TW_Denormal: */
        case TW_Infinity:
        case TW_Infinity:
          printk("st(%d)  %c .%04lx %04lx %04lx %04lx e%+-6ld ", i,
          printk("st(%d)  %c .%04lx %04lx %04lx %04lx e%+-6ld ", i,
                 r->sign ? '-' : '+',
                 r->sign ? '-' : '+',
                 (long)(r->sigh >> 16),
                 (long)(r->sigh >> 16),
                 (long)(r->sigh & 0xFFFF),
                 (long)(r->sigh & 0xFFFF),
                 (long)(r->sigl >> 16),
                 (long)(r->sigl >> 16),
                 (long)(r->sigl & 0xFFFF),
                 (long)(r->sigl & 0xFFFF),
                 r->exp - EXP_BIAS + 1);
                 r->exp - EXP_BIAS + 1);
          break;
          break;
        default:
        default:
          printk("Whoops! Error in errors.c: tag%d is %d ", i, tagi);
          printk("Whoops! Error in errors.c: tag%d is %d ", i, tagi);
          continue;
          continue;
          break;
          break;
        }
        }
      printk("%s\n", tag_desc[(int) (unsigned) tagi]);
      printk("%s\n", tag_desc[(int) (unsigned) tagi]);
    }
    }
 
 
  RE_ENTRANT_CHECK_ON;
  RE_ENTRANT_CHECK_ON;
 
 
}
}
 
 
static struct {
static struct {
  int type;
  int type;
  const char *name;
  const char *name;
} exception_names[] = {
} exception_names[] = {
  { EX_StackOver, "stack overflow" },
  { EX_StackOver, "stack overflow" },
  { EX_StackUnder, "stack underflow" },
  { EX_StackUnder, "stack underflow" },
  { EX_Precision, "loss of precision" },
  { EX_Precision, "loss of precision" },
  { EX_Underflow, "underflow" },
  { EX_Underflow, "underflow" },
  { EX_Overflow, "overflow" },
  { EX_Overflow, "overflow" },
  { EX_ZeroDiv, "divide by zero" },
  { EX_ZeroDiv, "divide by zero" },
  { EX_Denormal, "denormalized operand" },
  { EX_Denormal, "denormalized operand" },
  { EX_Invalid, "invalid operation" },
  { EX_Invalid, "invalid operation" },
  { EX_INTERNAL, "INTERNAL BUG in "FPU_VERSION },
  { EX_INTERNAL, "INTERNAL BUG in "FPU_VERSION },
  { 0, NULL }
  { 0, NULL }
};
};
 
 
/*
/*
 EX_INTERNAL is always given with a code which indicates where the
 EX_INTERNAL is always given with a code which indicates where the
 error was detected.
 error was detected.
 
 
 Internal error types:
 Internal error types:
       0x14   in fpu_etc.c
       0x14   in fpu_etc.c
       0x1nn  in a *.c file:
       0x1nn  in a *.c file:
              0x101  in reg_add_sub.c
              0x101  in reg_add_sub.c
              0x102  in reg_mul.c
              0x102  in reg_mul.c
              0x104  in poly_atan.c
              0x104  in poly_atan.c
              0x105  in reg_mul.c
              0x105  in reg_mul.c
              0x107  in fpu_trig.c
              0x107  in fpu_trig.c
              0x108  in reg_compare.c
              0x108  in reg_compare.c
              0x109  in reg_compare.c
              0x109  in reg_compare.c
              0x110  in reg_add_sub.c
              0x110  in reg_add_sub.c
              0x111  in fpe_entry.c
              0x111  in fpe_entry.c
              0x112  in fpu_trig.c
              0x112  in fpu_trig.c
              0x113  in errors.c
              0x113  in errors.c
              0x115  in fpu_trig.c
              0x115  in fpu_trig.c
              0x116  in fpu_trig.c
              0x116  in fpu_trig.c
              0x117  in fpu_trig.c
              0x117  in fpu_trig.c
              0x118  in fpu_trig.c
              0x118  in fpu_trig.c
              0x119  in fpu_trig.c
              0x119  in fpu_trig.c
              0x120  in poly_atan.c
              0x120  in poly_atan.c
              0x121  in reg_compare.c
              0x121  in reg_compare.c
              0x122  in reg_compare.c
              0x122  in reg_compare.c
              0x123  in reg_compare.c
              0x123  in reg_compare.c
              0x125  in fpu_trig.c
              0x125  in fpu_trig.c
              0x126  in fpu_entry.c
              0x126  in fpu_entry.c
              0x127  in poly_2xm1.c
              0x127  in poly_2xm1.c
              0x128  in fpu_entry.c
              0x128  in fpu_entry.c
              0x129  in fpu_entry.c
              0x129  in fpu_entry.c
              0x130  in get_address.c
              0x130  in get_address.c
              0x131  in get_address.c
              0x131  in get_address.c
              0x132  in get_address.c
              0x132  in get_address.c
              0x133  in get_address.c
              0x133  in get_address.c
              0x140  in load_store.c
              0x140  in load_store.c
              0x141  in load_store.c
              0x141  in load_store.c
              0x150  in poly_sin.c
              0x150  in poly_sin.c
              0x151  in poly_sin.c
              0x151  in poly_sin.c
              0x160  in reg_ld_str.c
              0x160  in reg_ld_str.c
              0x161  in reg_ld_str.c
              0x161  in reg_ld_str.c
              0x162  in reg_ld_str.c
              0x162  in reg_ld_str.c
              0x163  in reg_ld_str.c
              0x163  in reg_ld_str.c
       0x2nn  in an *.S file:
       0x2nn  in an *.S file:
              0x201  in reg_u_add.S
              0x201  in reg_u_add.S
              0x202  in reg_u_div.S
              0x202  in reg_u_div.S
              0x203  in reg_u_div.S
              0x203  in reg_u_div.S
              0x204  in reg_u_div.S
              0x204  in reg_u_div.S
              0x205  in reg_u_mul.S
              0x205  in reg_u_mul.S
              0x206  in reg_u_sub.S
              0x206  in reg_u_sub.S
              0x207  in wm_sqrt.S
              0x207  in wm_sqrt.S
              0x208  in reg_div.S
              0x208  in reg_div.S
              0x209  in reg_u_sub.S
              0x209  in reg_u_sub.S
              0x210  in reg_u_sub.S
              0x210  in reg_u_sub.S
              0x211  in reg_u_sub.S
              0x211  in reg_u_sub.S
              0x212  in reg_u_sub.S
              0x212  in reg_u_sub.S
              0x213  in wm_sqrt.S
              0x213  in wm_sqrt.S
              0x214  in wm_sqrt.S
              0x214  in wm_sqrt.S
              0x215  in wm_sqrt.S
              0x215  in wm_sqrt.S
              0x220  in reg_norm.S
              0x220  in reg_norm.S
              0x221  in reg_norm.S
              0x221  in reg_norm.S
              0x230  in reg_round.S
              0x230  in reg_round.S
              0x231  in reg_round.S
              0x231  in reg_round.S
              0x232  in reg_round.S
              0x232  in reg_round.S
              0x233  in reg_round.S
              0x233  in reg_round.S
              0x234  in reg_round.S
              0x234  in reg_round.S
              0x235  in reg_round.S
              0x235  in reg_round.S
              0x236  in reg_round.S
              0x236  in reg_round.S
              0x240  in div_Xsig.S
              0x240  in div_Xsig.S
              0x241  in div_Xsig.S
              0x241  in div_Xsig.S
              0x242  in div_Xsig.S
              0x242  in div_Xsig.S
 */
 */
 
 
void exception(int n)
void exception(int n)
{
{
  int i, int_type;
  int i, int_type;
 
 
  int_type = 0;         /* Needed only to stop compiler warnings */
  int_type = 0;         /* Needed only to stop compiler warnings */
  if ( n & EX_INTERNAL )
  if ( n & EX_INTERNAL )
    {
    {
      int_type = n - EX_INTERNAL;
      int_type = n - EX_INTERNAL;
      n = EX_INTERNAL;
      n = EX_INTERNAL;
      /* Set lots of exception bits! */
      /* Set lots of exception bits! */
      partial_status |= (SW_Exc_Mask | SW_Summary | SW_Backward);
      partial_status |= (SW_Exc_Mask | SW_Summary | SW_Backward);
    }
    }
  else
  else
    {
    {
      /* Extract only the bits which we use to set the status word */
      /* Extract only the bits which we use to set the status word */
      n &= (SW_Exc_Mask);
      n &= (SW_Exc_Mask);
      /* Set the corresponding exception bit */
      /* Set the corresponding exception bit */
      partial_status |= n;
      partial_status |= n;
      /* Set summary bits iff exception isn't masked */
      /* Set summary bits iff exception isn't masked */
      if ( partial_status & ~control_word & CW_Exceptions )
      if ( partial_status & ~control_word & CW_Exceptions )
        partial_status |= (SW_Summary | SW_Backward);
        partial_status |= (SW_Summary | SW_Backward);
      if ( n & (SW_Stack_Fault | EX_Precision) )
      if ( n & (SW_Stack_Fault | EX_Precision) )
        {
        {
          if ( !(n & SW_C1) )
          if ( !(n & SW_C1) )
            /* This bit distinguishes over- from underflow for a stack fault,
            /* This bit distinguishes over- from underflow for a stack fault,
               and roundup from round-down for precision loss. */
               and roundup from round-down for precision loss. */
            partial_status &= ~SW_C1;
            partial_status &= ~SW_C1;
        }
        }
    }
    }
 
 
  RE_ENTRANT_CHECK_OFF;
  RE_ENTRANT_CHECK_OFF;
  if ( (~control_word & n & CW_Exceptions) || (n == EX_INTERNAL) )
  if ( (~control_word & n & CW_Exceptions) || (n == EX_INTERNAL) )
    {
    {
#ifdef PRINT_MESSAGES
#ifdef PRINT_MESSAGES
      /* My message from the sponsor */
      /* My message from the sponsor */
      printk(FPU_VERSION" "__DATE__" (C) W. Metzenthen.\n");
      printk(FPU_VERSION" "__DATE__" (C) W. Metzenthen.\n");
#endif PRINT_MESSAGES
#endif PRINT_MESSAGES
 
 
      /* Get a name string for error reporting */
      /* Get a name string for error reporting */
      for (i=0; exception_names[i].type; i++)
      for (i=0; exception_names[i].type; i++)
        if ( (exception_names[i].type & n) == exception_names[i].type )
        if ( (exception_names[i].type & n) == exception_names[i].type )
          break;
          break;
 
 
      if (exception_names[i].type)
      if (exception_names[i].type)
        {
        {
#ifdef PRINT_MESSAGES
#ifdef PRINT_MESSAGES
          printk("FP Exception: %s!\n", exception_names[i].name);
          printk("FP Exception: %s!\n", exception_names[i].name);
#endif PRINT_MESSAGES
#endif PRINT_MESSAGES
        }
        }
      else
      else
        printk("FPU emulator: Unknown Exception: 0x%04x!\n", n);
        printk("FPU emulator: Unknown Exception: 0x%04x!\n", n);
 
 
      if ( n == EX_INTERNAL )
      if ( n == EX_INTERNAL )
        {
        {
          printk("FPU emulator: Internal error type 0x%04x\n", int_type);
          printk("FPU emulator: Internal error type 0x%04x\n", int_type);
          emu_printall();
          emu_printall();
        }
        }
#ifdef PRINT_MESSAGES
#ifdef PRINT_MESSAGES
      else
      else
        emu_printall();
        emu_printall();
#endif PRINT_MESSAGES
#endif PRINT_MESSAGES
 
 
      /*
      /*
       * The 80486 generates an interrupt on the next non-control FPU
       * The 80486 generates an interrupt on the next non-control FPU
       * instruction. So we need some means of flagging it.
       * instruction. So we need some means of flagging it.
       * We use the ES (Error Summary) bit for this.
       * We use the ES (Error Summary) bit for this.
       */
       */
    }
    }
  RE_ENTRANT_CHECK_ON;
  RE_ENTRANT_CHECK_ON;
 
 
#ifdef __DEBUG__
#ifdef __DEBUG__
  math_abort(FPU_info,SIGFPE);
  math_abort(FPU_info,SIGFPE);
#endif __DEBUG__
#endif __DEBUG__
 
 
}
}
 
 
 
 
/* Real operation attempted on two operands, one a NaN. */
/* Real operation attempted on two operands, one a NaN. */
/* Returns nz if the exception is unmasked */
/* Returns nz if the exception is unmasked */
asmlinkage int real_2op_NaN(FPU_REG const *a, FPU_REG const *b, FPU_REG *dest)
asmlinkage int real_2op_NaN(FPU_REG const *a, FPU_REG const *b, FPU_REG *dest)
{
{
  FPU_REG const *x;
  FPU_REG const *x;
  int signalling;
  int signalling;
 
 
  /* The default result for the case of two "equal" NaNs (signs may
  /* The default result for the case of two "equal" NaNs (signs may
     differ) is chosen to reproduce 80486 behaviour */
     differ) is chosen to reproduce 80486 behaviour */
  x = a;
  x = a;
  if (a->tag == TW_NaN)
  if (a->tag == TW_NaN)
    {
    {
      if (b->tag == TW_NaN)
      if (b->tag == TW_NaN)
        {
        {
          signalling = !(a->sigh & b->sigh & 0x40000000);
          signalling = !(a->sigh & b->sigh & 0x40000000);
          /* find the "larger" */
          /* find the "larger" */
          if ( significand(a) < significand(b) )
          if ( significand(a) < significand(b) )
            x = b;
            x = b;
        }
        }
      else
      else
        {
        {
          /* return the quiet version of the NaN in a */
          /* return the quiet version of the NaN in a */
          signalling = !(a->sigh & 0x40000000);
          signalling = !(a->sigh & 0x40000000);
        }
        }
    }
    }
  else
  else
#ifdef PARANOID
#ifdef PARANOID
    if (b->tag == TW_NaN)
    if (b->tag == TW_NaN)
#endif PARANOID
#endif PARANOID
    {
    {
      signalling = !(b->sigh & 0x40000000);
      signalling = !(b->sigh & 0x40000000);
      x = b;
      x = b;
    }
    }
#ifdef PARANOID
#ifdef PARANOID
  else
  else
    {
    {
      signalling = 0;
      signalling = 0;
      EXCEPTION(EX_INTERNAL|0x113);
      EXCEPTION(EX_INTERNAL|0x113);
      x = &CONST_QNaN;
      x = &CONST_QNaN;
    }
    }
#endif PARANOID
#endif PARANOID
 
 
  if ( !signalling )
  if ( !signalling )
    {
    {
      if ( !(x->sigh & 0x80000000) )  /* pseudo-NaN ? */
      if ( !(x->sigh & 0x80000000) )  /* pseudo-NaN ? */
        x = &CONST_QNaN;
        x = &CONST_QNaN;
      reg_move(x, dest);
      reg_move(x, dest);
      return 0;
      return 0;
    }
    }
 
 
  if ( control_word & CW_Invalid )
  if ( control_word & CW_Invalid )
    {
    {
      /* The masked response */
      /* The masked response */
      if ( !(x->sigh & 0x80000000) )  /* pseudo-NaN ? */
      if ( !(x->sigh & 0x80000000) )  /* pseudo-NaN ? */
        x = &CONST_QNaN;
        x = &CONST_QNaN;
      reg_move(x, dest);
      reg_move(x, dest);
      /* ensure a Quiet NaN */
      /* ensure a Quiet NaN */
      dest->sigh |= 0x40000000;
      dest->sigh |= 0x40000000;
    }
    }
 
 
  EXCEPTION(EX_Invalid);
  EXCEPTION(EX_Invalid);
 
 
  return !(control_word & CW_Invalid);
  return !(control_word & CW_Invalid);
}
}
 
 
 
 
/* Invalid arith operation on Valid registers */
/* Invalid arith operation on Valid registers */
/* Returns nz if the exception is unmasked */
/* Returns nz if the exception is unmasked */
asmlinkage int arith_invalid(FPU_REG *dest)
asmlinkage int arith_invalid(FPU_REG *dest)
{
{
 
 
  EXCEPTION(EX_Invalid);
  EXCEPTION(EX_Invalid);
 
 
  if ( control_word & CW_Invalid )
  if ( control_word & CW_Invalid )
    {
    {
      /* The masked response */
      /* The masked response */
      reg_move(&CONST_QNaN, dest);
      reg_move(&CONST_QNaN, dest);
    }
    }
 
 
  return !(control_word & CW_Invalid);
  return !(control_word & CW_Invalid);
 
 
}
}
 
 
 
 
/* Divide a finite number by zero */
/* Divide a finite number by zero */
asmlinkage int divide_by_zero(int sign, FPU_REG *dest)
asmlinkage int divide_by_zero(int sign, FPU_REG *dest)
{
{
 
 
  if ( control_word & CW_ZeroDiv )
  if ( control_word & CW_ZeroDiv )
    {
    {
      /* The masked response */
      /* The masked response */
      reg_move(&CONST_INF, dest);
      reg_move(&CONST_INF, dest);
      dest->sign = (unsigned char)sign;
      dest->sign = (unsigned char)sign;
    }
    }
 
 
  EXCEPTION(EX_ZeroDiv);
  EXCEPTION(EX_ZeroDiv);
 
 
  return !(control_word & CW_ZeroDiv);
  return !(control_word & CW_ZeroDiv);
 
 
}
}
 
 
 
 
/* This may be called often, so keep it lean */
/* This may be called often, so keep it lean */
int set_precision_flag(int flags)
int set_precision_flag(int flags)
{
{
  if ( control_word & CW_Precision )
  if ( control_word & CW_Precision )
    {
    {
      partial_status &= ~(SW_C1 & flags);
      partial_status &= ~(SW_C1 & flags);
      partial_status |= flags;   /* The masked response */
      partial_status |= flags;   /* The masked response */
      return 0;
      return 0;
    }
    }
  else
  else
    {
    {
      exception(flags);
      exception(flags);
      return 1;
      return 1;
    }
    }
}
}
 
 
 
 
/* This may be called often, so keep it lean */
/* This may be called often, so keep it lean */
asmlinkage void set_precision_flag_up(void)
asmlinkage void set_precision_flag_up(void)
{
{
  if ( control_word & CW_Precision )
  if ( control_word & CW_Precision )
    partial_status |= (SW_Precision | SW_C1);   /* The masked response */
    partial_status |= (SW_Precision | SW_C1);   /* The masked response */
  else
  else
    exception(EX_Precision | SW_C1);
    exception(EX_Precision | SW_C1);
 
 
}
}
 
 
 
 
/* This may be called often, so keep it lean */
/* This may be called often, so keep it lean */
asmlinkage void set_precision_flag_down(void)
asmlinkage void set_precision_flag_down(void)
{
{
  if ( control_word & CW_Precision )
  if ( control_word & CW_Precision )
    {   /* The masked response */
    {   /* The masked response */
      partial_status &= ~SW_C1;
      partial_status &= ~SW_C1;
      partial_status |= SW_Precision;
      partial_status |= SW_Precision;
    }
    }
  else
  else
    exception(EX_Precision);
    exception(EX_Precision);
}
}
 
 
 
 
asmlinkage int denormal_operand(void)
asmlinkage int denormal_operand(void)
{
{
  if ( control_word & CW_Denormal )
  if ( control_word & CW_Denormal )
    {   /* The masked response */
    {   /* The masked response */
      partial_status |= SW_Denorm_Op;
      partial_status |= SW_Denorm_Op;
      return 0;
      return 0;
    }
    }
  else
  else
    {
    {
      exception(EX_Denormal);
      exception(EX_Denormal);
      return 1;
      return 1;
    }
    }
}
}
 
 
 
 
asmlinkage int arith_overflow(FPU_REG *dest)
asmlinkage int arith_overflow(FPU_REG *dest)
{
{
 
 
  if ( control_word & CW_Overflow )
  if ( control_word & CW_Overflow )
    {
    {
      char sign;
      char sign;
      /* The masked response */
      /* The masked response */
/* ###### The response here depends upon the rounding mode */
/* ###### The response here depends upon the rounding mode */
      sign = dest->sign;
      sign = dest->sign;
      reg_move(&CONST_INF, dest);
      reg_move(&CONST_INF, dest);
      dest->sign = sign;
      dest->sign = sign;
    }
    }
  else
  else
    {
    {
      /* Subtract the magic number from the exponent */
      /* Subtract the magic number from the exponent */
      dest->exp -= (3 * (1 << 13));
      dest->exp -= (3 * (1 << 13));
    }
    }
 
 
  EXCEPTION(EX_Overflow);
  EXCEPTION(EX_Overflow);
  if ( control_word & CW_Overflow )
  if ( control_word & CW_Overflow )
    {
    {
      /* The overflow exception is masked. */
      /* The overflow exception is masked. */
      /* By definition, precision is lost.
      /* By definition, precision is lost.
         The roundup bit (C1) is also set because we have
         The roundup bit (C1) is also set because we have
         "rounded" upwards to Infinity. */
         "rounded" upwards to Infinity. */
      EXCEPTION(EX_Precision | SW_C1);
      EXCEPTION(EX_Precision | SW_C1);
      return !(control_word & CW_Precision);
      return !(control_word & CW_Precision);
    }
    }
 
 
  return 0;
  return 0;
 
 
}
}
 
 
 
 
asmlinkage int arith_underflow(FPU_REG *dest)
asmlinkage int arith_underflow(FPU_REG *dest)
{
{
 
 
  if ( control_word & CW_Underflow )
  if ( control_word & CW_Underflow )
    {
    {
      /* The masked response */
      /* The masked response */
      if ( dest->exp <= EXP_UNDER - 63 )
      if ( dest->exp <= EXP_UNDER - 63 )
        {
        {
          reg_move(&CONST_Z, dest);
          reg_move(&CONST_Z, dest);
          partial_status &= ~SW_C1;       /* Round down. */
          partial_status &= ~SW_C1;       /* Round down. */
        }
        }
    }
    }
  else
  else
    {
    {
      /* Add the magic number to the exponent. */
      /* Add the magic number to the exponent. */
      dest->exp += (3 * (1 << 13));
      dest->exp += (3 * (1 << 13));
    }
    }
 
 
  EXCEPTION(EX_Underflow);
  EXCEPTION(EX_Underflow);
  if ( control_word & CW_Underflow )
  if ( control_word & CW_Underflow )
    {
    {
      /* The underflow exception is masked. */
      /* The underflow exception is masked. */
      EXCEPTION(EX_Precision);
      EXCEPTION(EX_Precision);
      return !(control_word & CW_Precision);
      return !(control_word & CW_Precision);
    }
    }
 
 
  return 0;
  return 0;
 
 
}
}
 
 
 
 
void stack_overflow(void)
void stack_overflow(void)
{
{
 
 
 if ( control_word & CW_Invalid )
 if ( control_word & CW_Invalid )
    {
    {
      /* The masked response */
      /* The masked response */
      top--;
      top--;
      reg_move(&CONST_QNaN, &st(0));
      reg_move(&CONST_QNaN, &st(0));
    }
    }
 
 
  EXCEPTION(EX_StackOver);
  EXCEPTION(EX_StackOver);
 
 
  return;
  return;
 
 
}
}
 
 
 
 
void stack_underflow(void)
void stack_underflow(void)
{
{
 
 
 if ( control_word & CW_Invalid )
 if ( control_word & CW_Invalid )
    {
    {
      /* The masked response */
      /* The masked response */
      reg_move(&CONST_QNaN, &st(0));
      reg_move(&CONST_QNaN, &st(0));
    }
    }
 
 
  EXCEPTION(EX_StackUnder);
  EXCEPTION(EX_StackUnder);
 
 
  return;
  return;
 
 
}
}
 
 
 
 
void stack_underflow_i(int i)
void stack_underflow_i(int i)
{
{
 
 
 if ( control_word & CW_Invalid )
 if ( control_word & CW_Invalid )
    {
    {
      /* The masked response */
      /* The masked response */
      reg_move(&CONST_QNaN, &(st(i)));
      reg_move(&CONST_QNaN, &(st(i)));
    }
    }
 
 
  EXCEPTION(EX_StackUnder);
  EXCEPTION(EX_StackUnder);
 
 
  return;
  return;
 
 
}
}
 
 
 
 
void stack_underflow_pop(int i)
void stack_underflow_pop(int i)
{
{
 
 
 if ( control_word & CW_Invalid )
 if ( control_word & CW_Invalid )
    {
    {
      /* The masked response */
      /* The masked response */
      reg_move(&CONST_QNaN, &(st(i)));
      reg_move(&CONST_QNaN, &(st(i)));
      pop();
      pop();
    }
    }
 
 
  EXCEPTION(EX_StackUnder);
  EXCEPTION(EX_StackUnder);
 
 
  return;
  return;
 
 
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.