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.

268 lines
8.8 KiB

  1. page 78,132
  2. title emulator - 80387 emulator for flat 32-bit OS
  3. ;*******************************************************************************
  4. ; Copyright (c) Microsoft Corporation 1991
  5. ; All Rights Reserved
  6. ;
  7. ;emulator.asm - 80387 emulator
  8. ; by Tim Paterson
  9. ;
  10. ;Revision History:
  11. ;
  12. ; [] 09/05/91 TP Initial 32-bit version.
  13. ; [] 11/13/92 JWM Bug fixes for esp-indexed addressing, handling of denormals.
  14. ; [] 01/18/93 JWM Bug fixes for preservation of condition & error codes.
  15. ;
  16. ;*******************************************************************************
  17. .386p
  18. .387
  19. .model flat,Pascal
  20. option oldstructs ;JWM
  21. ;*******************************************************************************
  22. ;
  23. ; Define segments.
  24. ;
  25. ;*******************************************************************************
  26. ;These equates give access to the program that's using floating point.
  27. dseg equ ss ;Segment of program's data
  28. cseg equ es ;Segment of program's code
  29. edata segment dword public 'FAR_DATA'
  30. edata ends
  31. ecode segment dword public 'CODE'
  32. ecode ends
  33. assume cs:ecode
  34. ifdef NT386
  35. assume ds:nothing
  36. assume fs:edata
  37. else
  38. assume ds:edata
  39. assume fs:nothing
  40. endif
  41. assume es:nothing
  42. assume gs:nothing
  43. assume ss:nothing
  44. ifdef NT386
  45. include ks386.inc
  46. include nt386npx.inc
  47. include callconv.inc
  48. include vdmtib.inc
  49. endif ; NT386
  50. ;*******************************************************************************
  51. ;
  52. ; List external functions.
  53. ;
  54. ;*******************************************************************************
  55. ifdef NT386
  56. EXTRNP _NtRaiseException,3
  57. EXTRNP _RtlRaiseStatus,1
  58. EXTRNP _ZwRaiseException,3
  59. EXTRNP _NpxNpSkipInstruction,1
  60. endif ; NT386
  61. ifdef _DOS32EXT
  62. extern _SelKrnGetEmulData:NEAR
  63. extern DOS32RAISEEXCEPTION:NEAR
  64. endif ; _DOS32EXT
  65. ifdef _CRUISER
  66. extern DOS32IRAISEEXCEPTION:near
  67. endif ; CRUISER
  68. ;*******************************************************************************
  69. ;
  70. ; Segment override macro (for NT)
  71. ;
  72. ;*******************************************************************************
  73. ifdef NT386
  74. EMSEG EQU FS
  75. else
  76. EMSEG EQU DS
  77. endif
  78. ;;*******************************************************************************
  79. ;;
  80. ;; Include some more macros and constants.
  81. ;;
  82. ;;*******************************************************************************
  83. ;
  84. include em387.inc
  85. include emstack.inc ; stack management macros
  86. ;**************************************************************************
  87. ;**************************************************************************
  88. ;**************************************************************************
  89. subttl emulator.asm - Emulator Task DATA Segment
  90. page
  91. ;*********************************************************************;
  92. ; ;
  93. ; Emulator Task DATA Segment ;
  94. ; ;
  95. ;*********************************************************************;
  96. edata segment
  97. ifdef NT386
  98. db size EmulatorTebData dup (?) ; Make space for varibles
  99. else ; ifdef NT386
  100. Numlev equ 8 ; Number of stack registers
  101. InitControlWord equ 37FH ; Default - Round near,
  102. ; 64 bits, all exceptions masked
  103. RoundMode dd ? ;Address of rounding routine
  104. SavedRoundMode dd ? ;For restoring RoundMode
  105. ZeroVector dd ? ;Address of sum-to-zero routine
  106. TransRound dd ? ;Round mode w/o precision
  107. Result dd ? ;Result pointer
  108. PrevCodeOff dd ?
  109. PrevDataOff dd ?
  110. (See note below on 'Emulator stack area')
  111. CURstk dd ?
  112. XBEGstk db (Numlev-1)*Reg87Len dup(?) ;Allocate register 1 - 7
  113. BEGstk EQU offset edata:XBEGstk
  114. INITstk EQU offset edata:XINITstk
  115. ENDstk EQU offset edata:XENDstk
  116. FloatTemp db Reg87Len dup(?)
  117. ArgTemp db Reg87Len dup(?)
  118. public Trap7Handler
  119. Trap7Handler dd 0
  120. ;We're DWORD aligned at this point
  121. LongStatusWord label dword ;Combined Einstall, CURerr, StatusWord
  122. .erre Einstall eq $
  123. .erre StatusWord eq $+1
  124. .erre CURerr eq $+3
  125. Einstall db 0 ; Emulator installed flag
  126. StatusWord label word
  127. SWerr db ? ; Initially no exceptions (sticky flags)
  128. CurErrCond label word ; Combined error and condition codes
  129. SWcc db ? ; Condition codes from various operations
  130. CURerr db ? ; initially 8087 exception flags clear
  131. ; this is the internal flag reset after
  132. ; each operation to detect per instruction
  133. ; errors
  134. LongControlWord label dword ;Combined ControlWord and ErrMask
  135. .erre ControlWord eq $
  136. .erre ErrMask eq $+2
  137. ControlWord label word
  138. CWmask db ? ; exception masks
  139. CWcntl db ? ; arithmetic control flags
  140. ErrMask db ?
  141. dummy db ?
  142. endif ; ifdef NT386 else
  143. ;*******************************************************************************
  144. ;
  145. ; Emulator stack area
  146. ;
  147. ;The top of stack pointer CURstk is initialized to the last register
  148. ;in the list; on a real 8087, this corresponds to hardware register 0.
  149. ;The stack grows toward lower addresses, so the first push (which is
  150. ;hardware register 7) is stored into the second-to-last slot. This gives
  151. ;the following relationship between hardware registers and memory
  152. ;locations:
  153. ;
  154. ; BEGstk --> | reg 1 | (lowest memory address)
  155. ; | reg 2 |
  156. ; | reg 3 |
  157. ; | reg 4 |
  158. ; | reg 5 |
  159. ; | reg 6 |
  160. ; | reg 7 |
  161. ; | reg 0 | <-- Initial top of stack (empty)
  162. ; ENDstk -->
  163. ;
  164. ;This means that the wrap-around case on decrementing CURstk will not
  165. ;occur until the last (8th) item is pushed.
  166. ;
  167. ;Note that the physical register numbers are only used in regard to
  168. ;the tag word. All other operations are relative the current top.
  169. edata ends
  170. subttl emulator.asm
  171. page
  172. ;*********************************************************************;
  173. ; ;
  174. ; Start of Code Segment ;
  175. ; ;
  176. ;*********************************************************************;
  177. ecode segment
  178. ; public __fpemulatorbegin ; unused code label commented out for BBT
  179. ;__fpemulatorbegin equ $ ; emulator really starts here
  180. include emfinit.asm
  181. include emerror.asm ; error handler
  182. include emdisp.asm ; dispatch tables
  183. include emf386.asm ; Flat 386 emulation entry
  184. include emdecode.asm ; instruction decoder
  185. include emarith.asm ; arithmetic dispatcher
  186. include emfadd.asm ; add and subtract
  187. include emfmul.asm ; multiply
  188. include emfdiv.asm ; division
  189. include emround.asm ; rounding
  190. include emload.asm ; load memory operands
  191. include emstore.asm ; store memory operands
  192. include emfmisc.asm ; miscellaneous instructions
  193. include emfcom.asm ; compare
  194. include emfconst.asm ; constant loading
  195. include emlsbcd.asm ; packed BCD conversion
  196. include emxtract.asm ; xtract and scale
  197. include emfprem.asm ; partial remainder
  198. include emtrig.asm ; trig instructions
  199. include emftran.asm ; transcendentals
  200. include emlsenv.asm
  201. include emfsqrt.asm ; square root
  202. ifndef NT386
  203. include emccall.asm
  204. endif
  205. UNUSED:
  206. eFSETPM:
  207. eFNOP:
  208. eFENI:
  209. eFDISI:
  210. ret ;Return to EMLFINISH
  211. ; public __fpemulatorend ; unused code label commented out for BBT
  212. ;__fpemulatorend equ $ ; emulator ends here ; commented out for BBT
  213. ecode ends
  214. END