P_EMUL.A 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. (* Release 3.10 *)
  2. (*-------------------------------------------------------------------------*
  3. * *
  4. * P_EMUL.A - protected-mode emulator support *
  5. * *
  6. * COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
  7. * All Rights Reserved *
  8. * *
  9. *--------------------------------------------------------------------------*)
  10. module p_emul
  11. auto_select = 1 (* use 8087 if one is present at run time *)
  12. public FIDRQQ = 0
  13. public FIWRQQ = 0
  14. public FIERQQ = 0
  15. public FIARQQ = 0
  16. public FISRQQ = 0
  17. public FICRQQ = 0
  18. public FJERQQ = 0
  19. public FJARQQ = 0
  20. public FJSRQQ = 0
  21. public FJCRQQ = 0
  22. public FIXRQQ = 0
  23. segment EMU_TEXT (EMU_CODE,28H)
  24. foption 2
  25. extrn emulate8087
  26. oldFlags = 22
  27. oldCS = 20
  28. oldIP = 18
  29. oldAX = 16
  30. oldBX = 14
  31. oldBX = 12
  32. oldDX = 10
  33. oldSI = 8
  34. oldDI = 6
  35. oldDS = 4
  36. oldES = 2
  37. oldBP = 0
  38. e286_entry :
  39. push ax
  40. push bx
  41. push cx
  42. push dx
  43. push si
  44. push di
  45. push ds
  46. push es
  47. push bp
  48. mov bp,sp
  49. cld (* forward string direction *)
  50. lds si, [bp][oldIP]
  51. sub dl, dl (* records whether there was a segment override *)
  52. lodsw
  53. sub al, 0D8H
  54. cmp al, 8
  55. jae override
  56. decoded:
  57. jmp emulate8087
  58. resume:
  59. (* ggfb: check for another float instruction *)
  60. lds si, [bp][oldIP]
  61. cld (* !! it may not be clear! *)
  62. search:
  63. lodsw
  64. cmp al, 90H
  65. je skip
  66. cmp al, 9BH
  67. je skip
  68. sub al, 0D8H
  69. cmp al, 8
  70. jae notanother (* seg-overrides cause not checked *)
  71. sub dl, dl
  72. jmp emulate8087 (* ax,bx,cx,dl,bp,ds,si,di must all be all valid ! *)
  73. notanother:
  74. mov sp, bp
  75. pop bp
  76. pop es
  77. pop ds
  78. pop di
  79. pop si
  80. pop dx
  81. pop cx
  82. pop bx
  83. pop ax
  84. iret
  85. override:
  86. cmp al, 3EH-0D8H (* ds: ? *)
  87. je DSfix
  88. cmp al, 26H-0D8H (* es: ? *)
  89. je ESfix
  90. cmp al, 2EH-0D8H (* cs: ? *)
  91. je CSfix
  92. (*jmp SSfix*)
  93. SSfix: mov di, ss; jmp segfix
  94. CSfix: mov di, ds; jmp segfix
  95. ESfix: mov di, [bp][oldES]; jmp segfix
  96. DSfix: mov di, [bp][oldDS]; (*jmp segfix*)
  97. segfix:
  98. mov es, di
  99. lodsb (* advance to pick up mod/r/m byte *)
  100. xchg ah, al
  101. and al, 7
  102. inc dl
  103. jmp emulate8087
  104. skip:
  105. dec si
  106. jmp search
  107. public __FloatInit:
  108. push bp
  109. mov bp,sp
  110. sub sp, 4
  111. extrn __fp_1
  112. call far __fp_1
  113. db 0FH, 01H, 66H, 0FEH; (* smsw ds:[bp][-2] *)
  114. test word [bp][-2],2
  115. (*%T auto_select*)
  116. jnz emulation_not_required (* disable jump for debugging *)
  117. (*%E*)
  118. mov ax, 7 ; push ax (* push 7 *)
  119. mov ax, EMU_TEXT ; push ax
  120. mov ax, e286_entry ; push ax (* push e286_entry *)
  121. push ss
  122. lea ax, [bp][-4]; push ax (* push address for result *)
  123. extrn DOSSETVEC
  124. call far DOSSETVEC
  125. emulation_not_required:
  126. mov sp, bp
  127. pop bp
  128. mov bx, ss
  129. (*call __FloatInitInstance*)
  130. (*ret far 0*)
  131. public __FloatInitInstance:
  132. mov ax, resume
  133. extrn __EmulInitInstance
  134. call __EmulInitInstance
  135. push bp
  136. mov bp,sp
  137. sub sp,2
  138. finit
  139. fstcw [bp][-2]
  140. fwait
  141. or word [bp][-2], 0C00H
  142. and word [bp][-2],~001DH (* enable invalid op/underflow/overflow/divide by zero exception *)
  143. fldcw [bp][-2]
  144. extrn __FloatInitStack
  145. call far __FloatInitStack
  146. mov sp,bp
  147. pop bp
  148. ret far 0
  149. public __FloatFinish:
  150. ret far 0
  151. public __FloatMathExcepOs2 :
  152. (* always far called from coresig *)
  153. (*
  154. stack contains far return address to signal handler, then status word,
  155. then far return address to error location, the iret flags.
  156. This is how __math_excep likes it, so just jump there.
  157. *)
  158. extrn __math_excep
  159. fclex
  160. jmp far __math_excep
  161. public __FloatEmulNMI:
  162. emws_status = 414 (* org 2, aligned. Result of comparisons *)
  163. push ss:[emws_status] (* as per OS/2, status word onto stack *)
  164. extrn sigHandlerFPE1
  165. jmp far sigHandlerFPE1
  166. public __FloatJmpSave :
  167. st1_reg = 20
  168. st2_reg = 30
  169. fld st(0), st(1)
  170. fstp tbyte es:[di][st1_reg], st(0)
  171. fld st(0), st(2)
  172. fstp tbyte es:[di][st2_reg], st(0)
  173. fwait
  174. ret far 0
  175. public __FloatJmpRestore :
  176. fld tbyte st(0), ds:[si][st1_reg]
  177. fstp st(2), st(0)
  178. fld tbyte st(0), ds:[si][st2_reg]
  179. fstp st(3), st(0)
  180. ret far 0
  181. ProcessFloat = 14
  182. public __FloatSave :
  183. fsave es:[ProcessFloat]
  184. ret far 0
  185. public __FloatRestore :
  186. frstor ds:[ProcessFloat]
  187. ret far 0
  188. public __FloatExecSave :
  189. public __FloatExecRestore :
  190. ret far 0
  191. segment EMU_STATE(DATA,68H)
  192. emuRecSize = 490
  193. select EMU_STATE
  194. public emuBuffer:
  195. db 0
  196. org emuRecSize-1
  197. end (*P_EMUL.A*)