* This file contains most of the code to interpret the FPU instructions
* which load and store from user memory.
* Copyright (C) 1992, 1993 W. Metzenthen, 22 Parker St, Ormond,
* E-mail apm233m@vaxc.cc.monash.edu.au
* This copyright notice covers the redistribution and use of the
* FPU emulator developed by W. Metzenthen. It covers only its use
* in the 386BSD operating system. Any other use is not permitted
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must include information specifying
* that source code for the emulator is freely available and include
* a) an offer to provide the source code for a nominal distribution
* b) list at least two alternative methods whereby the source
* can be obtained, e.g. a publically accessible bulletin board
* and an anonymous ftp site from which the software can be
* 3. All advertising materials specifically mentioning features or use of
* this emulator must acknowledge that it was developed by W. Metzenthen.
* 4. The name of W. Metzenthen may not be used to endorse or promote
* products derived from this software without specific prior written
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*---------------------------------------------------------------------------+
| The file contains code which accesses user memory. |
| Emulator static data may change when user memory is accessed, due to |
| other processes using the emulator while swapping is in progress. |
+---------------------------------------------------------------------------*/
#define _NONE_ 0 /* FPU_st0_ptr etc not needed */
#define _REG0_ 1 /* Will be storing st(0) */
#define _PUSH_ 3 /* Need to check for space to push onto stack */
#define _null_ 4 /* Function illegal or not implemented */
#define pop_0() { pop_ptr->tag = TW_Empty; top++; }
static unsigned char type_table
[32] = {
_PUSH_
, _PUSH_
, _PUSH_
, _PUSH_
,
_null_
, _null_
, _null_
, _null_
,
_REG0_
, _REG0_
, _REG0_
, _REG0_
,
_REG0_
, _REG0_
, _REG0_
, _REG0_
,
_NONE_
, _null_
, _NONE_
, _PUSH_
,
_NONE_
, _PUSH_
, _null_
, _PUSH_
,
_NONE_
, _null_
, _NONE_
, _REG0_
,
_NONE_
, _REG0_
, _NONE_
, _REG0_
load_store_instr(char type
)
FPU_REG
*pop_ptr
; /* We need a version of FPU_st0_ptr which
pop_ptr
= NULL
; /* Initialized just to stop compiler warnings. */
switch (type_table
[(int) (unsigned) type
]) {
pop_ptr
= &st(0); /* Some of these instructions pop
FPU_st0_ptr
= pop_ptr
; /* Set the global variables. */
FPU_st0_tag
= FPU_st0_ptr
->tag
;
if (pop_ptr
->tag
!= TW_Empty
) {
return EXCEPTION(EX_INTERNAL
);
case 000: /* fld m32real */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
case 001: /* fild m32int */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
case 002: /* fld m64real */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
case 003: /* fild m16int */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
case 010: /* fst m32real */
case 011: /* fist m32int */
case 012: /* fst m64real */
case 013: /* fist m16int */
case 014: /* fstp m32real */
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */
case 015: /* fistp m32int */
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */
case 016: /* fstp m64real */
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */
case 017: /* fistp m16int */
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */
case 020: /* fldenv m14/28byte */
case 022: /* frstor m94/108byte */
case 023: /* fbld m80dec */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
control_word
= fuword((unsigned short *) FPU_data_address
);
if (!(control_word
& EX_Underflow
)) {
control_word
|= EX_Underflow
;
FPU_data_address
= (void *) data_operand_offset
; /* We want no net effect */
FPU_entry_eip
= ip_offset
; /* We want no net effect */
case 025: /* fld m80real */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
case 027: /* fild m64int */
setcc(0); /* Clear the SW_C1 bit, "other bits undefined" */
reg_move(&FPU_loaded_data
, pop_ptr
);
case 030: /* fstenv m14/28byte */
FPU_data_address
= (void *) data_operand_offset
; /* We want no net effect */
FPU_entry_eip
= ip_offset
; /* We want no net effect */
FPU_data_address
= (void *) data_operand_offset
; /* We want no net effect */
FPU_entry_eip
= ip_offset
; /* We want no net effect */
case 033: /* fbstp m80dec */
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */
case 034: /* fstcw m16int */
/* verify_area(VERIFY_WRITE, FPU_data_address, 2);*/
suword( (short *) FPU_data_address
,control_word
);
FPU_data_address
= (void *) data_operand_offset
; /* We want no net effect */
FPU_entry_eip
= ip_offset
; /* We want no net effect */
case 035: /* fstp m80real */
if (reg_store_extended())
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */
case 036: /* fstsw m2byte */
status_word
|= (top
& 7) << SW_Top_Shift
;
/* verify_area(VERIFY_WRITE, FPU_data_address, 2);*/
suword( (short *) FPU_data_address
,status_word
);
FPU_data_address
= (void *) data_operand_offset
; /* We want no net effect */
FPU_entry_eip
= ip_offset
; /* We want no net effect */
case 037: /* fistp m64int */
pop_0();/* pop only if the number was actually stored
* (see the 80486 manual p16-28) */