Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

445 lines
13 KiB

  1. subttl em387.inc - Emulator Internal Format and Macros
  2. page
  3. ;***
  4. ;em387.inc - Emulator Internal Format and Macros
  5. ;
  6. ; Microsoft Confidential
  7. ;
  8. ; Copyright (c) Microsoft Corporation 1987, 1992
  9. ;
  10. ; All Rights Reserved
  11. ;
  12. ;Purpose:
  13. ; Emulator Internal Format and Macros
  14. ;
  15. ;Revision History: (also see emulator.hst)
  16. ;
  17. ; 8/23/91 TP New tag definitions
  18. ; 10/30/89 WAJ Added this header.
  19. ; 02/12/89 WAJ Added local stack frame definition.
  20. ;
  21. ;*******************************************************************************
  22. GetEmData macro dest,use
  23. ifdef _CRUISER
  24. mov dest,[edataSEG]
  25. elseifdef _DOS32EXT
  26. ifdifi <use>,<ax>
  27. push eax
  28. call _SelKrnGetEmulData
  29. mov dest,ax
  30. pop eax
  31. else
  32. call _SelKrnGetEmulData
  33. mov dest,ax
  34. endif
  35. endif
  36. endm
  37. ;The SKIP macro optimizes very short jumps by treating the code
  38. ;as data to a "cmp" instruction. This reduces jump time from
  39. ;8 clocks or more down to 2 clocks. It destroy the flags!
  40. SKIP macro dist,target
  41. if dist eq 4
  42. db 3DH ;cmp eax,<immed>
  43. elseif dist eq 3
  44. db 3DH,0 ;cmp eax,<immed>
  45. elseif dist eq 2
  46. db 66H,3DH ;cmp ax,<immed>
  47. elseif dist eq 1
  48. db 3CH ;cmp al,<immed>
  49. else
  50. .err
  51. endif
  52. ifnb <target>
  53. .erre $+dist eq target
  54. endif
  55. endm
  56. ;*******************************************************************************
  57. ;
  58. ; 80x87 environment structures.
  59. ;
  60. ;*******************************************************************************
  61. Env80x87_32 struc
  62. E32_ControlWord dw ?
  63. reserved1 dw ?
  64. E32_StatusWord dw ?
  65. reserved2 dw ?
  66. E32_TagWord dw ?
  67. reserved3 dw ?
  68. E32_CodeOff dd ?
  69. E32_CodeSeg dw ?
  70. reserved4 dw ?
  71. E32_DataOff dd ?
  72. E32_DataSeg dw ?
  73. reserved5 dw ?
  74. Env80x87_32 ends
  75. ;---------------------------------------------------------------------------
  76. ;
  77. ; Emulator Internal Format:
  78. ;
  79. ; +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11
  80. ; .___.___.___.___.___.___.___.___.___.___.___.___.
  81. ; ptr --> |___|___|___|___|___|___|___|___|___|___|___|___|
  82. ; lsb msb tag sgn exl exh
  83. ; |<--- mantissa --->| |exponent
  84. ;
  85. ; The mantissa contains the leading 1 before the decimal point in the hi
  86. ; bit of the msb. The exponent is not biased (signed two's complement).
  87. ; The flag and tag bytes are as below.
  88. ;
  89. ; bit: 7 6 5 4 3 2 1 0
  90. ; .___.___.___.___.___.___.___.___.
  91. ; Sign: |___|_X_|_X_|_X_|_X_|_X_|_X_|_X_| X = unused
  92. ; ^
  93. ; SIGN
  94. ;
  95. ;
  96. ; bit: 7 6 5 4 3 2 1 0
  97. ; .___.___.___.___.___.___.___.___.
  98. ; Tag: |___|___|_X_|_X_|___|___|___|___| X = unused
  99. ; ^ ^ ^ ^ ^ ^
  100. ; | | | | | |
  101. ; 387 tag -+---+ | | | |
  102. ; | | | |
  103. ; Special enumeration -----+---+ | |
  104. ; | |
  105. ; Internal tag --------------------+---+
  106. ;
  107. ;There are four internal tags: Single, Double, Zero, Special. Within
  108. ;Special, there is NAN, Infinity, Denormal, and Empty.
  109. ;
  110. ;Representations for Single, Double, and Denormal are the same. Denormals
  111. ;are not actually kept denormalized, although they are rounded to the
  112. ;correct number of bits as if they were. The Single tag means the
  113. ;low 32 bits of the mantissa are zero. This allows optimizing multiply
  114. ;and divide.
  115. ;
  116. ;Tag Mantissa Exponent Sign
  117. ;---------------------------------------------------
  118. ;Zero 0 0 valid
  119. ;Empty ? ? ?
  120. ;NAN valid TexpMax valid
  121. ;Infinity 8000...000 TexpMax valid
  122. ;
  123. ;The mantissa for a NAN distinguishes between a quiet NAN (QNAN) or a
  124. ;signaling NAN (SNAN). If the bit below the MSB is 1, it is a QNAN,
  125. ;otherwise it is an SNAN.
  126. ;
  127. ;*******************************************************************************
  128. ;*
  129. ;* Stack entry defineds with a struct.
  130. ;*
  131. ;*******************************************************************************
  132. EmStackEntry struc
  133. bMan0 db ?
  134. bMan1 db ?
  135. bMan2 db ?
  136. bMan3 db ?
  137. bMan4 db ?
  138. bMan5 db ?
  139. bMan6 db ?
  140. bMan7 db ?
  141. bTag db ?
  142. bSgn db ?
  143. bExpLo db ?
  144. bExpHi db ?
  145. EmStackEntry ends
  146. wMantisa struc
  147. wMan0 dw ?
  148. wMan1 dw ?
  149. wMan2 dw ?
  150. wMan3 dw ?
  151. TagSgn dw ?
  152. wExp dw ?
  153. wMantisa ends
  154. lMantisa struc
  155. lManLo dd ?
  156. lManHi dd ?
  157. ExpSgn dd ?
  158. lMantisa ends
  159. .erre size lMantisa eq size wMantisa
  160. Reg87Len equ size lMantisa
  161. ;*******************************************************************************
  162. ;*
  163. ;* bFlags and bTag constants.
  164. ;*
  165. ;*******************************************************************************
  166. ;The rules for internal number formats:
  167. ;
  168. ;1. Everything is either normalized or zero--unnormalized formats cannot
  169. ;get in. So if the high half mantissa is zero, the number must be all zero.
  170. ;
  171. ;2. Although the exponent bias is different, NANs and Infinities are in
  172. ;standard IEEE format - exponent is TexpMax, mantissa indicates NAN vs.
  173. ;infinity (mantissa for infinity is 800..000H).
  174. ;
  175. ;3. Denormals have an exponent less than TexpMin.
  176. ;
  177. ;4. If the low half of the mantissa is zero, it is tagged bTAG_SNGL
  178. ;
  179. ;5. Everything else is bTAG_VALID
  180. bSign equ 80h
  181. ;These are the INTERNAL flags
  182. TAG_MASK equ 3
  183. TAG_SHIFT equ 2
  184. ;
  185. TAG_SNGL equ 0 ;SINGLE: low 32 bits are zero
  186. TAG_VALID equ 1
  187. TAG_ZERO equ 2
  188. TAG_SPCL equ 3 ;NAN, Infinity, Denormal, Empty
  189. ZEROorSPCL equ 2 ;Test for Zero or Special
  190. ;Enumeration of "special":
  191. TAG_SPCLBITS equ 0CH
  192. TAG_EMPTY equ TAG_SPCL+(0 shl TAG_SHIFT)
  193. TAG_INF equ TAG_SPCL+(1 shl TAG_SHIFT)
  194. TAG_NAN equ TAG_SPCL+(2 shl TAG_SHIFT)
  195. TAG_DEN equ TAG_SPCL+(3 shl TAG_SHIFT)
  196. ;These are the tags used by the 387
  197. T87_VALID equ 0
  198. T87_ZERO equ 1
  199. T87_SPCL equ 2 ;NAN, Infinity, Denormal
  200. T87_EMPTY equ 3
  201. ;The tag word for each stack entry combines these two tags.
  202. ;Internal tags are in the low bits, 387 tags are in the high two bits
  203. bTAG_VALID equ (T87_VALID shl 6) or TAG_VALID
  204. bTAG_SNGL equ (T87_VALID shl 6) or TAG_SNGL
  205. bTAG_ZERO equ (T87_ZERO shl 6) or TAG_ZERO
  206. bTAG_NAN equ (T87_SPCL shl 6) or TAG_NAN
  207. bTAG_INF equ (T87_SPCL shl 6) or TAG_INF
  208. bTAG_EMPTY equ (T87_EMPTY shl 6) or TAG_EMPTY
  209. bTAG_DEN equ (T87_SPCL shl 6) or TAG_DEN
  210. bTAG_NOPOP equ -1
  211. bTAG_MASK equ 3
  212. MantissaByteCnt equ 8
  213. IexpBias equ 3FFFh ; 16,383
  214. IexpMax equ 7FFFh ; Biased Exponent for Infinity
  215. IexpMin equ 0 ; Biased Exponent for zero
  216. DexpBias equ 3FFh ; 1023
  217. DexpMax equ 7FFh ; Biased Exponent for Infinity
  218. DexpMin equ 0 ; Biased Exponent for zero
  219. SexpBias equ 07Fh ; 127
  220. SexpMax equ 0FFh ; Biased Exponent for Infinity
  221. SexpMin equ 0 ; Biased Exponent for zero
  222. TexpBias equ 0 ; Bias for internal format of temp real
  223. UnderBias equ 24576 ; 3 * 2^13. Extra bias for unmasked underflow
  224. TexpMax equ IexpMax - IexpBias + TexpBias ;NAN/Infinity exponent
  225. TexpMin equ IexpMin-IexpBias+1 ;Smallest non-denormal exponent
  226. ; Control Word Format CWcntl
  227. RoundControl equ 0Ch
  228. RCchop equ 0Ch
  229. RCup equ 08h
  230. RCdown equ 04h
  231. RCnear equ 0
  232. PrecisionControl equ 03h
  233. PC24 equ 0
  234. PC53 equ 02h
  235. PC64 equ 03h
  236. ; Status Word Format SWcc
  237. C0 equ 01h
  238. C1 equ 02h
  239. C2 equ 04h
  240. C3 equ 40h
  241. ConditionCode equ C3 or C2 or C1 or C0
  242. CCgreater equ 0
  243. CCless EQU C0
  244. CCequal equ C3
  245. CCincomprable equ C3 or C2 or C0
  246. RoundUp equ C1
  247. StackOverflow equ C1
  248. ; Status Flags Format CURerr
  249. Invalid equ 1h ; chip status flags
  250. Denormal equ 2h
  251. ZeroDivide equ 4h
  252. Overflow equ 8h
  253. Underflow equ 10h
  254. Precision equ 20h
  255. StackFlag equ 40h
  256. Summary equ 80h
  257. SavedErrs equ Invalid or Denormal or ZeroDivide or Overflow or Underflow or Precision or StackFlag
  258. LongSavedFlags equ (CCincomprable SHL 16) OR (SavedErrs SHL 8) ; save C0, C2, C3 & errs
  259. ;*******************************************************************************
  260. ;*
  261. ;* Define emulator interrupt stack frame.
  262. ;*
  263. ;*******************************************************************************
  264. StackFrame struc
  265. regEAX dd ?
  266. regECX dd ?
  267. regEDX dd ?
  268. regEBX dd ?
  269. regESP dd ?
  270. regEBP dd ?
  271. regESI dd ?
  272. regEDI dd ?
  273. OldCodeOff dd ?
  274. OldLongStatus dd ?
  275. regDS dd ?
  276. regEIP dd ?
  277. regCS dd ?
  278. regFlg dd ?
  279. StackFrame ends
  280. regAX equ word ptr regEAX
  281. ; .erre StatusWord eq LongStatusWord+1
  282. OldStatus equ word ptr OldLongStatus+1
  283. ;*******************************************************************************
  284. ;*
  285. ;* Define emulator entry point macro.
  286. ;*
  287. ;*******************************************************************************
  288. EM_ENTRY macro entryname
  289. ifdef NT386
  290. public ___&entryname
  291. ___&entryname:
  292. endif ; ifdef NT386
  293. endm
  294. Em87Busy EQU 1
  295. Em87Idle EQU 0
  296. ifdef NT386
  297. ;*********************************************************************;
  298. ; ;
  299. ; Emulator TEB Layout ;
  300. ; ;
  301. ;*********************************************************************;
  302. .errnz (TbSystemReserved1 and 3) ; Make sure TB is dword aligned
  303. Numlev equ 8 ; Number of stack registers
  304. InitControlWord equ 37FH ; Default - Round near,
  305. ; 64 bits, all exceptions masked
  306. DefaultControlWord equ 27FH ; Default - Round near,
  307. ; 53 bits, all exceptions masked
  308. EmulatorTebData struc
  309. TbSystemResrvd db TbSystemReserved1 DUP (?) ; Skip to Emulator area
  310. RoundMode dd ? ; Address of rounding routine
  311. SavedRoundMode dd ? ; For restoring RoundMode
  312. ZeroVector dd ? ; Address of sum-to-zero routine
  313. TransRound dd ? ; Round mode w/o precision
  314. Result dd ? ; Result pointer
  315. PrevCodeOff dd ?
  316. PrevDataOff dd ?
  317. ;(See comment below on 'emulator stack area'
  318. CURstk dd ? ; init to start of stack
  319. BEGstk db (Numlev-1)*Reg87Len dup(?) ;Allocate register 1 - 7
  320. INITstk db Reg87Len dup(?)
  321. FloatTemp db Reg87Len dup(?)
  322. ArgTemp db Reg87Len dup(?)
  323. Einstall db 0 ; Emulator installed flag
  324. SWerr db ? ; Initially no exceptions (sticky flags)
  325. SWcc db ? ; Condition codes from various operations
  326. CURerr db ? ; initially 8087 exception flags clear
  327. ; this is the internal flag reset after
  328. ; each operation to detect per instruction
  329. ; errors
  330. CWmask db ? ; exception masks
  331. CWcntl db ? ; arithmetic control flags
  332. ErrMask db ?
  333. dummy db ?
  334. EmulatorTebData ends
  335. ENDstk equ byte ptr INITstk + Reg87Len
  336. LongStatusWord equ dword ptr Einstall ;Combine Einstall, CURerr, StatusWord
  337. StatusWord equ word ptr SWerr ;Combine SWerr, SWcc
  338. CurErrCond equ word ptr SWcc ;Combine SWcc, CURErr
  339. LongControlWord equ dword ptr CWmask ;Combine CWMask, CWcntl, ErrMask, dummy
  340. ControlWord equ word ptr CWmask ;Combine CWMask, CWcntl
  341. YFloatTemp equ FloatTemp
  342. YArgTemp equ ArgTemp
  343. .errnz (SWerr - Einstall -1)
  344. .errnz (SWcc - Einstall -2)
  345. .errnz (CURerr - Einstall -3)
  346. .errnz (CWcntl - CWmask -1)
  347. .errnz (ErrMask - CWmask -2)
  348. .errnz (dummy - CWmask -3)
  349. ;*******************************************************************************
  350. ;
  351. ; Emulator stack area
  352. ;
  353. ;The top of stack pointer CURstk is initialized to the last register
  354. ;in the list; on a real 8087, this corresponds to hardware register 0.
  355. ;The stack grows toward lower addresses, so the first push (which is
  356. ;hardware register 7) is stored into the second-to-last slot. This gives
  357. ;the following relationship between hardware registers and memory
  358. ;locations:
  359. ;
  360. ; BEGstk --> | reg 1 | (lowest memory address)
  361. ; | reg 2 |
  362. ; | reg 3 |
  363. ; | reg 4 |
  364. ; | reg 5 |
  365. ; | reg 6 |
  366. ; | reg 7 |
  367. ; | reg 0 | <-- Initial top of stack (empty)
  368. ; ENDstk -->
  369. ;
  370. ;This means that the wrap-around case on decrementing CURstk will not
  371. ;occur until the last (8th) item is pushed.
  372. ;
  373. ;Note that the physical register numbers are only used in regard to
  374. ;the tag word. All other operations are relative the current top.
  375. endif