;       SCCSID = @(#)npx.inc	6.1 90/11/17
;      SCCSID = @(#)npx.inc	1.6 90/09/27
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
;
; Component Name: NPX
;
; This file contains information needed to support the NPX.
;

;
; NPX protect mode environment
;
NPX_ENV STRUC			     ;
	npx_cw	     DD	     ?	     ;	Control word
	npx_sw	     DD	     ?	     ;	Status word
	npx_tw	     DD	     ?	     ;	Tag word
	npx_ipo	     DD	     ?	     ;	Instruction pointer
	npx_css	     DD	     ?	     ;	Code segment selector
	npx_doo	     DD	     ?	     ;	Data operand offset
	npx_dos	     DD	     ?	     ;	Data operand selector
NPX_ENV ENDS

NPX_CON_BUSY_BIT     EQU     npx_css
NPX_STACK_SIZE	     EQU     (8*10)  ;	Eight temporary reals
NPX_CONTEXT_387	     EQU     SIZE NPX_ENV + NPX_STACK_SIZE;

;
; Number of blocks that BMP should allocate at a time
;
NPX_GRODELT	     EQU     2

NPX_EXC_BITS	     EQU     03Fh    ;	Low 6 bits of status/control word

;
; Constants used to clear the NPX  exception
;
MSTR_PIC_PORT		EQU	020H	; Master PIC port
SLV_PIC_PORT		EQU	0A0H	; Slave PIC port
NPX_BUSY_PORT		EQU	0F0H	; NPX BUSY latch
NPX_REAL_PORT		EQU	0F1H	; NPX real/reset port
NPX_PRESENT		EQU	1	; for Comparison to MathCop

npxsw_busy    equ     1000000000000000b
npxsw_error   equ     0000000010000000b

; control word
npxcw_invop   equ     0000000000000001b
npxcw_invopoff equ    1111111111111110b

; equates for DHInitNPX error return code

NPX_NOT_PRESENT EQU	1
NPX_287_PRESENT EQU	2
NPX_386B1_WITH_387 EQU	3

; equates for DosHlpValidNPXSwitch return values

VNS_NOERROR			equ	0
VNS_ERROR_INT_PENDING		equ	1 ; npx int pending
VNS_ERROR_INT_DISABLED		equ	2 ; interrupts disabled
VNS_ERROR_INT_IN_SERVICE	equ	3 ; higher priority int in service

; macros for isr values

ISR_HIGHER_PRIORITY_NPX		equ    01FFFh ; irq's w/ higher priority than npx

NPXIRQ_MASK	equ	2000H

; SpinCount calculations:

; Loops*ClocksPerLoop/CpuClockFreq = ClocksForLongestInstruction/NpxClockFreq
; Loops = (ClocksForLongestInstruction/ClocksPerLoop)*(CpuClockFreq/NpxClockFreq)

; In the following calculations, the system clock is used as a reference. Since
; we're really interested only in the ratio of the CPU clock to the NPX clock,
; the specific value chosen for the system clock is unimportant. However, since
; MASM can only handle integer arithmetic, it must be evenly divisible by both
; 2 and 3.

; Rounding up is forced by adding the denominator minus one to the numerator
; before dividing. Again, this is because MASM only handles integers.

; SpinCount for 386/387 and 486 machines.

NpxClocks	= 809+76	;FSINCOS with x > Pi/4
CpuClocks	= 2+2+7		;DEC AX + OR AX,AX + JNZ
SysFreq		= 24		;typical - see note above
NpxFreq		= SysFreq/3	;NPX divides the system clock by 3
CpuFreq		= SysFreq/2	;CPU divides the system clock by 2

SpinCount_387	= ((NpxClocks+(CpuClocks-1))/CpuClocks)*((CpuFreq+(NpxFreq-1))/NpxFreq)
;; Integer math is just to inaccurate for performance sensitive stuff.
;; Calculated on a real calculator, here's the number:
SpinCount_387	= 121		;(809+76)/(2+2+7)*((24/2)/(24/3)) = 120.68
