;       SCCSID = @(#)e80387.inc	6.3 92/03/03
;
;...FEBRUARY 21, 1987...
;
;...DEFINITION OF GLOBAL REENTRANT DATA SEGMENT
;
GLOBAL_RECORD_1         STRUC
;
MEM_OPERAND_POINTER             DF      ?
INSTRUCTION_POINTER             DF      ?
OPERATION_TYPE                  DB      ?
REG_NUM                         DB      ?
;
OP1_FORMAT                      DB      ?
OP1_LOCATION                    DB      ?
OP1_USE_UP                      DB      ?
;
OP2_FORMAT                      DB      ?
OP2_LOCATION                    DB      ?
OP2_USE_UP                      DB      ?
;
RESULT_FORMAT                   DB      ?
RESULT_LOCATION                 DB      ?
;
RESULT2_FORMAT                  DB      ?
RESULT2_LOCATION                DB      ?
;
DWORD_FRAC1                     DD      3 DUP(?)
SIGN1                           DB      ?
SIGN1_EXT                       DB      ?
TAG1                            DB      ?
TAG1_EXT                        DB      ?
EXPON1                          DW      ?
EXPON1_EXT                      DW      ?
;
DWORD_FRAC2                     DD      3 DUP(?)
SIGN2                           DB      ?
SIGN2_EXT                       DB      ?
TAG2                            DB      ?
TAG2_EXT                        DB      ?
EXPON2                          DW      ?
EXPON2_EXT                      DW      ?
;
BEFORE_ERROR_SIGNALS            DD ?
;
EXTRA_DWORD_REG                 DD      3 DUP(?)
;
RESULT_DWORD_FRAC               DD      3 DUP(?)
RESULT_SIGN                     DB      ?
RESULT_SIGN_EXT                 DB      ?
RESULT_TAG                      DB      ?
RESULT_TAG_EXT                  DB      ?
RESULT_EXPON                    DW      ?
RESULT_EXPON_EXT                DW      ?
;
RESULT2_DWORD_FRAC              DD      3 DUP(?)
RESULT2_SIGN                    DB      ?
RESULT2_SIGN_EXT                DB      ?
RESULT2_TAG                     DB      ?
RESULT2_TAG_EXT                 DB      ?
RESULT2_EXPON                   DW      ?
RESULT2_EXPON_EXT               DW      ?
;
GLOBAL_RECORD_1         ENDS
;
GLOBAL_RECORD_2         STRUC

                    DB      78H DUP(?)
;
DWORD_COP           DD      3 DUP(?)
DWORD_DOP           DD      3 DUP(?)
;
OPRND_SIZ32         DB      ?
ADDRS_SIZ32         DB      ?
CORRECT_SS          DW      ?
CORRECT_ESP         DD      ?
;
SAVED_GS            DW      ?
FILL_1              DW      ?
SAVED_FS            DW      ?
FILL_2              DW      ?
SAVED_ES            DW      ?
FILL_3              DW      ?
SAVED_EDI           DD      ?
SAVED_ESI           DD      ?
SAVED_EBP           DD      ?
SAVED_EBX           DD      ?
SAVED_EDX           DD      ?
SAVED_ECX           DD      ?
SAVED_EAX           DD      ?
SAVED_DS            DW      ?
FILL_4              DW      ?
SAVED_ESP           DD      ?

SAVED_EIP           DD      ?
SAVED_CS            DW      ?
FILL_5              DW      ?
SAVED_FLAGS         DD      ?

GLOBAL_RECORD_2     ENDS
;
GLOBAL_REENT_SEG_LENGTH                 EQU             SAVED_GS
;
;       CONVENIENCE DEFINITIONS
;
;
; NEW ONES -387
;
WORD_FRAC1            EQU             WORD PTR [EBP].DWORD_FRAC1+2
WORD_FRAC2            EQU             WORD PTR [EBP].DWORD_FRAC2+2
RESULT_WORD_FRAC      EQU             WORD PTR [EBP].RESULT_DWORD_FRAC+2
RESULT2_WORD_FRAC     EQU             WORD PTR [EBP].RESULT2_DWORD_FRAC+2

DWORD_EXPON1          EQU             DWORD PTR [EBP].EXPON1
DWORD_EXPON2          EQU             DWORD PTR [EBP].EXPON2
DWORD_RESULT_EXPON    EQU             DWORD PTR [EBP].RESULT_EXPON
DWORD_RESULT2_EXPON   EQU             DWORD PTR [EBP].RESULT2_EXPON

DOP                   EQU             WORD PTR [EBP].DWORD_DOP+2
COP                   EQU             WORD PTR [EBP].DWORD_COP+2
;
EXTRA_WORD_REG        EQU             WORD PTR [EBP].EXTRA_DWORD_REG+2
;
OFFSET_OP1_REC        EQU             OFFSET OP1_FORMAT
OFFSET_OP2_REC        EQU             OFFSET OP2_FORMAT
OFFSET_RESULT_REC     EQU             OFFSET RESULT_FORMAT
OFFSET_RESULT2_REC    EQU             OFFSET RESULT2_FORMAT
OFFSET_OPERAND1       EQU             OFFSET DWORD_FRAC1
OFFSET_OPERAND2       EQU             OFFSET DWORD_FRAC2
OFFSET_RESULT         EQU             OFFSET RESULT_DWORD_FRAC
OFFSET_RESULT2        EQU             OFFSET RESULT2_DWORD_FRAC


; These are redefined for MASM because MASM did not properly handle the
; nested equates. As a result, the Byte ptr turned into a Word pointer
; and in some operations the extra byte was mangled. This resulted in
; incorrect answers.

LSB_FRAC1             EQU             BYTE PTR [EBP].DWORD_FRAC1 + 2
MSB_FRAC1             EQU             BYTE PTR [EBP].DWORD_FRAC1 + 11
LSB_FRAC2             EQU             BYTE PTR [EBP].DWORD_FRAC2 + 2
MSB_FRAC2             EQU             BYTE PTR [EBP].DWORD_FRAC2 + 11
LSB_RESULT            EQU             BYTE PTR [EBP].RESULT_DWORD_FRAC + 2
MSB_RESULT            EQU             BYTE PTR [EBP].RESULT_DWORD_FRAC + 11
LSB_RESULT2           EQU             BYTE PTR [EBP].RESULT2_DWORD_FRAC + 2
MSB_RESULT2           EQU             BYTE PTR [EBP].RESULT2_DWORD_FRAC + 11



OFFSET_COP            EQU             OFFSET DWORD_COP
LSB_COP               EQU             BYTE PTR COP
MSB_COP               EQU             BYTE PTR LSB_COP + 9
OFFSET_DOP            EQU             OFFSET DWORD_DOP
LSB_DOP               EQU             BYTE PTR DOP
MSB_DOP               EQU             BYTE PTR LSB_DOP + 9
Q                     EQU             BYTE PTR [EBP].MEM_OPERAND_POINTER
HI_Q                  EQU             BYTE PTR [EBP].MEM_OPERAND_POINTER + 1
EXP_TMP               EQU             WORD PTR [EBP].MEM_OPERAND_POINTER
; THE FOLLOWING TWO DEFINITIONS HAVE BEEN REVERSED FROM THEIR COUNTERPARTS
; IN EARLIER VERSIONS OF THE EMULATOR:
LOOP_CT               EQU             WORD PTR [EBP].MEM_OPERAND_POINTER + 2
SISO                  EQU             WORD PTR [EBP].MEM_OPERAND_POINTER + 4
; AND THE FOLLOWING DEFINITION HAS BEEN ADDED
LOG_LOOP_CT           EQU             DWORD PTR [EBP].MEM_OPERAND_POINTER
;
; NOTE THAT LOG_LOOP_CT MUST BE SAVED BEFORE ANY CALL TO ACCEL_DIVX, OR
; TO DIVID THAT CALLS ACCEL_DIVX, FOR ACCEL_DIVX MODIFIES Q, WHICH IS THE
; FIRST BYTE OF LOG_LOOP_CT.
;
BIT_CT                EQU             BYTE PTR [EBP].INSTRUCTION_POINTER
ADDED_ONE             EQU             BYTE PTR [EBP].INSTRUCTION_POINTER + 1
RND_HISTORY           EQU             WORD PTR [EBP].INSTRUCTION_POINTER + 2
RND1_INEXACT          EQU             BYTE PTR [EBP].INSTRUCTION_POINTER + 2
RND2_INEXACT          EQU             BYTE PTR [EBP].INSTRUCTION_POINTER + 3
;
;
SIGNAL_I_ERROR?       EQU             BYTE PTR [EBP].BEFORE_ERROR_SIGNALS
SIGNAL_Z_ERROR?       EQU             BYTE PTR [EBP].BEFORE_ERROR_SIGNALS + 1
SIGNAL_D_ERROR?       EQU             BYTE PTR [EBP].BEFORE_ERROR_SIGNALS + 2
;
DWORD_EXP_TMP         EQU             DWORD PTR [EBP].BEFORE_ERROR_SIGNALS
;
; DWORD_EXP_TMP SHOULD NOT BE USED FOR ROUTINES THAT PUSH RESULTS ONTO THE '87
; STACK, BECAUSE SUCH ROUTINES USE [EBP].BEFORE_ERROR_SIGNALS.
;
;...DEFINE COMPONENT FLAGS OF TRANS_INFO
;
TRANS_INFO            EQU             DWORD PTR [EBP].EXTRA_DWORD_REG
OP_TYPE               EQU             BYTE PTR [EBP].EXTRA_DWORD_REG
SIN_SIGN              EQU             BYTE PTR [EBP].EXTRA_DWORD_REG + 1
COS_SIGN              EQU             BYTE PTR [EBP].EXTRA_DWORD_REG + 2
COFUNC_FLAG           EQU             BYTE PTR [EBP].EXTRA_DWORD_REG + 3
;
RES_SIGNS             EQU             WORD PTR [EBP].EXTRA_DWORD_REG + 1
;
;...DEFINE STRUCTURE OF OPERAND INFO AND RESULT INFO STRUCTURES...
;
FORMAT                EQU             0
LOCATION              EQU             1
USE_UP                EQU             2
;
;...DEFINE FORMAT CODES...
;
SINGLE_REAL           EQU             0
DOUBLE_REAL           EQU             1
INT16                 EQU             2
INT32                 EQU             3
INT64                 EQU             4
EXTENDED_FP           EQU             5
NULL                  EQU             7
BCD                   EQU             8
OP_NO_RESULT          EQU             9
NO_OP_RESULT          EQU             10
OP2_POP               EQU             11
OP2_NO_POP            EQU             12
RESULT2               EQU             13
OP1_TOP_OP2           EQU             14
;
;...DEFINE OPERATION TYPE CODES...
;
SAVE_PTRS             EQU             80H
LOAD_OP               EQU             0
STORE_OP              EQU             1
CHSIGN_OP             EQU             2
COMPAR_OP             EQU             3
ERROR_OP              EQU             4+SAVE_PTRS
ADD_OP                EQU             5
SUB_OP                EQU             6
MUL_OP                EQU             7
DIV_OP                EQU             8
LDCW_OP               EQU             9+SAVE_PTRS
SAVE_OP               EQU             10+SAVE_PTRS
RESTORE_OP            EQU             11+SAVE_PTRS
NULL_OP               EQU             12+SAVE_PTRS
ABS_OP                EQU             13
INIT_OP               EQU             14+SAVE_PTRS
FXTRAC_OP             EQU             15
LOG_OP                EQU             16
SPLOG_OP              EQU             17
EXP_OP                EQU             18
TAN_OP                EQU             19
ARCTAN_OP             EQU             20
SQRT_OP               EQU             21
REMR_OP               EQU             22
INTPT_OP              EQU             23
SCALE_OP              EQU             24
EXCHANGE_OP           EQU             25
FREE_OP               EQU             26
LDENV_OP              EQU             27+SAVE_PTRS
STENV_OP              EQU             28+SAVE_PTRS
STCW_OP               EQU             29+SAVE_PTRS
STSW_OP               EQU             30+SAVE_PTRS
LOAD_1_OP             EQU             31
LOAD_L2T_OP           EQU             32
LOAD_L2E_OP           EQU             33
LOAD_PI_OP            EQU             34
LOAD_LG2_OP           EQU             35
LOAD_LN2_OP           EQU             36
LOAD_0_OP             EQU             37
DECSTP_OP             EQU             38
INCSTP_OP             EQU             39
CLER_OP               EQU             40+SAVE_PTRS
TEST_OP               EQU             41
EXAM_OP               EQU             42
SIN_OP                EQU             43
COS_OP                EQU             44
SINCOS_OP             EQU             45
REM1_OP               EQU             46
UCOM_OP               EQU             47
COMPAR_POP            EQU             48
SUBR_OP               EQU             49
DIVR_OP               EQU             50
STORE_POP             EQU             51
UCOM_POP              EQU             52
;
;...DEFINITION OF REGISTER TAG CODES...
;
VALID                 EQU             0
SPECIAL               EQU             1
INV                   EQU             2
EMPTY                 EQU             3
DENORMD               EQU             6
INFINTY               EQU             0AH
UNSUPP                EQU             12H
;
;...INFINITY_CONTROL SETTINGS...
;
PROJECTIVE            EQU             0
AFFINE                EQU             1
;
;...DEFINE LOCATION CODES...
;
MEMORY_OPND           EQU             0
STACK_TOP             EQU             1
STACK_TOP_MINUS_1     EQU             2
STACK_TOP_PLUS_1      EQU             3
REG                   EQU             4
;
;...DEFINE USE_UP CODES...
;
FREE                  EQU             0
POP_STACK             EQU             1
DO_NOTHING            EQU             2
;
;...DEFINITION OF OPERAND AND RESULT RECORDS IN GLOBAL REENT SEG...
;
FRAC80                EQU             2
FRAC64                EQU             4
FRAC32                EQU             8
MSB                   EQU             11
SIGN                  EQU             12
TAG                   EQU             14
EXPON                 EQU             16
;
;...DEFINITION OF PRECISION CODES...
;
PREC24                EQU             0
PREC32                EQU             1
PREC53                EQU             2
PREC64                EQU             3
PREC16                EQU             4
;
;...DEFINE ROUND CONTROL CODES...
;
RND_TO_EVEN           EQU             0000H
RND_DOWN              EQU             0004H
RND_UP                EQU             0008H
RND_TO_ZERO           EQU             000CH
;
;...DEFINE POSITIVE AND NEGATIVE...
;
POSITIVE              EQU             0000H
NEGATIVE              EQU             00FFH
;
;...DEFINITION OF TRUE AND FALSE...
;
TRUE                  EQU             00FFH
FALSE                 EQU             0000H
;
WRAP_AROUND_CONSTANT  EQU             6000H
NO_CHANGE             EQU             00F0H
EXPONENT_BIAS         EQU             3FFFH
;
SINGLE_EXP_OFFSET     EQU             3F80H
DOUBLE_EXP_OFFSET     EQU             3C00H
;
ZERO_MASK             EQU             40H
SIGN_MASK             EQU             01H
A_MASK                EQU             02H
C_MASK                EQU             04H
INEXACT_MASK          EQU             20H
UNDERFLOW_MASK        EQU             10H
OVERFLOW_MASK         EQU             08H
ZERO_DIVIDE_MASK      EQU             04H
INVALID_MASK          EQU             01H
DENORM_MASK           EQU             02H
TOP_MASK              EQU             38H
PRECISION_MASK        EQU             03H
RND_CONTROL_MASK      EQU             0CH
INFINITY_CONTROL_MASK EQU             10H
HIGH_EXTENDED_EXPON_FOR_SINGLE  EQU             407EH
LOW_EXTENDED_EXPON_FOR_SINGLE   EQU             3F81H
HIGH_EXTENDED_EXPON_FOR_DOUBLE  EQU             43FEH
LOW_EXTENDED_EXPON_FOR_DOUBLE   EQU             3C01H
HIGH_INT16_EXPONENT   EQU             400EH
MAX_INT16_SHIFT       EQU             17
HIGH_INT32_EXPONENT   EQU             401EH
MAX_INT32_SHIFT       EQU             33
HIGH_INT64_EXPONENT   EQU             403EH
MAX_INT64_SHIFT       EQU             65
;
; THE LEAST SCALE TERM FOR WHICH EXTREME OVERFLOW IS CERTAIN:
LEAST_SF_XTRM_OVFL          EQU             0000E03DH
;
; THE GREATEST SCALE TERM FOR WHICH EXTREME UNDERFLOW IS CERTAIN:
GRTST_SF_XTRM_UNFL          EQU             0FFFF2002H

;;
;; Stuff added for the IBM OS/2 port.
;;

;;
;; This was buried in dcode.asm as a magic number. The ifdef'd equ looks
;; nicer

STACK_BYTES_PUSHED      EQU     0CH
SEL_LDT     equ     4h          ; Table bit, set for LDT selectors.
StackFlag               equ       40h
Invalid                 equ        1h           ; chip status flags
Summary                 equ       80h

EmStackEntry struc
    lMan0   dd      ?
    lMan1   dd      ?
    wExp    dw      ?
EmStackEntry ends

;*******************************************************************************
;
;   Constants for LAR.
;
;*******************************************************************************


AR_GRAN     equ     800000h
AR_DEFAULT  equ     400000h     ; Default bit. Set if code segment is a use32 segment.
AR_BIG      equ     400000h     ; Big bit. Set if data segment is a big segment.
SEL_LDT     equ     4h          ; Table bit, set for LDT selectors.


;*******************************************************************************
;
;   80x87 environment structures.
;
;*******************************************************************************

Env80x87_32 struc
    E32_ControlWord     dw      ?
     reserved1          dw      ?
    E32_StatusWord      dw      ?
     reserved2          dw      ?
    E32_TagWord         dw      ?
     reserved3          dw      ?
    E32_CodeOff         dd      ?
    E32_CodeSeg         dw      ?
    E32_OpCode          dw      ?
    E32_DataOff         dd      ?
    E32_DataSeg         dw      ?
     reserved4          dw      ?
Env80x87_32 ends

lab     macro   name
public  name
name:
            endm
