root/kernel/FPU-emu/load_store.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. load_store_instr

   1 /*---------------------------------------------------------------------------+
   2  |  load_store.c                                                             |
   3  |                                                                           |
   4  | This file contains most of the code to interpret the FPU instructions     |
   5  | which load and store from user memory.                                    |
   6  |                                                                           |
   7  | Copyright (C) 1992,1993                                                   |
   8  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
   9  |                       Australia.  E-mail apm233m@vaxc.cc.monash.edu.au    |
  10  |                                                                           |
  11  |                                                                           |
  12  +---------------------------------------------------------------------------*/
  13 
  14 /*---------------------------------------------------------------------------+
  15  | Note:                                                                     |
  16  |    The file contains code which accesses user memory.                     |
  17  |    Emulator static data may change when user memory is accessed, due to   |
  18  |    other processes using the emulator while swapping is in progress.      |
  19  +---------------------------------------------------------------------------*/
  20 
  21 #include <asm/segment.h>
  22 
  23 #include "fpu_system.h"
  24 #include "exception.h"
  25 #include "fpu_emu.h"
  26 #include "status_w.h"
  27 
  28 
  29 #define _NONE_ 0   /* FPU_st0_ptr etc not needed */
  30 #define _REG0_ 1   /* Will be storing st(0) */
  31 #define _PUSH_ 3   /* Need to check for space to push onto stack */
  32 #define _null_ 4   /* Function illegal or not implemented */
  33 
  34 #define pop_0() { pop_ptr->tag = TW_Empty; top++; }
  35 
  36 
  37 static unsigned char type_table[32] = {
  38   _PUSH_, _PUSH_, _PUSH_, _PUSH_,
  39   _null_, _null_, _null_, _null_,
  40   _REG0_, _REG0_, _REG0_, _REG0_,
  41   _REG0_, _REG0_, _REG0_, _REG0_,
  42   _NONE_, _null_, _NONE_, _PUSH_,
  43   _NONE_, _PUSH_, _null_, _PUSH_,
  44   _NONE_, _null_, _NONE_, _REG0_,
  45   _NONE_, _REG0_, _NONE_, _REG0_
  46   };
  47 
  48 void load_store_instr(char type)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50   FPU_REG *pop_ptr;  /* We need a version of FPU_st0_ptr which won't change. */
  51 
  52   pop_ptr = NULL;    /* Initialized just to stop compiler warnings. */
  53   switch ( type_table[(int) (unsigned) type] )
  54     {
  55     case _NONE_:
  56       break;
  57     case _REG0_:
  58       pop_ptr = &st(0);       /* Some of these instructions pop after
  59                                  storing */
  60 
  61       FPU_st0_ptr = pop_ptr;      /* Set the global variables. */
  62       FPU_st0_tag = FPU_st0_ptr->tag;
  63       break;
  64     case _PUSH_:
  65       {
  66         pop_ptr = &st(-1);
  67         if ( pop_ptr->tag != TW_Empty )
  68           { stack_overflow(); return; }
  69         top--;
  70       }
  71       break;
  72     case _null_:
  73       return Un_impl();
  74 #ifdef PARANOID
  75     default:
  76       return EXCEPTION(EX_INTERNAL);
  77 #endif PARANOID
  78     }
  79 
  80 switch ( type )
  81   {
  82   case 000:       /* fld m32real */
  83     reg_load_single();
  84     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
  85     reg_move(&FPU_loaded_data, pop_ptr);
  86     break;
  87   case 001:      /* fild m32int */
  88     reg_load_int32();
  89     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
  90     reg_move(&FPU_loaded_data, pop_ptr);
  91     break;
  92   case 002:      /* fld m64real */
  93     reg_load_double();
  94     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
  95     reg_move(&FPU_loaded_data, pop_ptr);
  96     break;
  97   case 003:      /* fild m16int */
  98     reg_load_int16();
  99     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
 100     reg_move(&FPU_loaded_data, pop_ptr);
 101     break;
 102   case 010:      /* fst m32real */
 103     reg_store_single();
 104     break;
 105   case 011:      /* fist m32int */
 106     reg_store_int32();
 107     break;
 108   case 012:     /* fst m64real */
 109     reg_store_double();
 110     break;
 111   case 013:     /* fist m16int */
 112     reg_store_int16();
 113     break;
 114   case 014:     /* fstp m32real */
 115     if ( reg_store_single() )
 116       pop_0();  /* pop only if the number was actually stored
 117                  (see the 80486 manual p16-28) */
 118     break;
 119   case 015:     /* fistp m32int */
 120     if ( reg_store_int32() )
 121       pop_0();  /* pop only if the number was actually stored
 122                  (see the 80486 manual p16-28) */
 123     break;
 124   case 016:     /* fstp m64real */
 125     if ( reg_store_double() )
 126       pop_0();  /* pop only if the number was actually stored
 127                  (see the 80486 manual p16-28) */
 128     break;
 129   case 017:     /* fistp m16int */
 130     if ( reg_store_int16() )
 131       pop_0();  /* pop only if the number was actually stored
 132                  (see the 80486 manual p16-28) */
 133     break;
 134   case 020:     /* fldenv  m14/28byte */
 135     fldenv();
 136     break;
 137   case 022:     /* frstor m94/108byte */
 138     frstor();
 139     break;
 140   case 023:     /* fbld m80dec */
 141     reg_load_bcd();
 142     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
 143     reg_move(&FPU_loaded_data, pop_ptr);
 144     break;
 145   case 024:     /* fldcw */
 146     RE_ENTRANT_CHECK_OFF
 147     control_word = get_fs_word((unsigned short *) FPU_data_address);
 148     RE_ENTRANT_CHECK_ON
 149 #ifdef NO_UNDERFLOW_TRAP
 150     if ( !(control_word & EX_Underflow) )
 151       {
 152         control_word |= EX_Underflow;
 153       }
 154 #endif
 155     FPU_data_address = (void *)data_operand_offset; /* We want no net effect */
 156     FPU_entry_eip = ip_offset;               /* We want no net effect */
 157     break;
 158   case 025:      /* fld m80real */
 159     reg_load_extended();
 160     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
 161     reg_move(&FPU_loaded_data, pop_ptr);
 162     break;
 163   case 027:      /* fild m64int */
 164     reg_load_int64();
 165     setcc(0);     /* Clear the SW_C1 bit, "other bits undefined" */
 166     reg_move(&FPU_loaded_data, pop_ptr);
 167     break;
 168   case 030:     /* fstenv  m14/28byte */
 169     fstenv();
 170     FPU_data_address = (void *)data_operand_offset; /* We want no net effect */
 171     FPU_entry_eip = ip_offset;               /* We want no net effect */
 172     break;
 173   case 032:      /* fsave */
 174     fsave();
 175     FPU_data_address = (void *)data_operand_offset; /* We want no net effect */
 176     FPU_entry_eip = ip_offset;               /* We want no net effect */
 177     break;
 178   case 033:      /* fbstp m80dec */
 179     if ( reg_store_bcd() )
 180       pop_0();  /* pop only if the number was actually stored
 181                  (see the 80486 manual p16-28) */
 182     break;
 183   case 034:      /* fstcw m16int */
 184     RE_ENTRANT_CHECK_OFF
 185     verify_area(VERIFY_WRITE,FPU_data_address,2);
 186     put_fs_word(control_word, (short *) FPU_data_address);
 187     RE_ENTRANT_CHECK_ON
 188     FPU_data_address = (void *)data_operand_offset; /* We want no net effect */
 189     FPU_entry_eip = ip_offset;               /* We want no net effect */
 190     break;
 191   case 035:      /* fstp m80real */
 192     if ( reg_store_extended() )
 193       pop_0();  /* pop only if the number was actually stored
 194                  (see the 80486 manual p16-28) */
 195     break;
 196   case 036:      /* fstsw m2byte */
 197     status_word &= ~SW_Top;
 198     status_word |= (top&7) << SW_Top_Shift;
 199     RE_ENTRANT_CHECK_OFF
 200     verify_area(VERIFY_WRITE,FPU_data_address,2);
 201     put_fs_word(status_word,(short *) FPU_data_address);
 202     RE_ENTRANT_CHECK_ON
 203     FPU_data_address = (void *)data_operand_offset; /* We want no net effect */
 204     FPU_entry_eip = ip_offset;               /* We want no net effect */
 205     break;
 206   case 037:      /* fistp m64int */
 207     if ( reg_store_int64() )
 208       pop_0();  /* pop only if the number was actually stored
 209                  (see the 80486 manual p16-28) */
 210     break;
 211   }
 212 }

/* [previous][next][first][last][top][bottom][index][help] */