Source code of Windows XP (NT5)
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.

448 lines
12 KiB

  1. ;
  2. ;
  3. ; Copyright (C) Microsoft Corporation, 1987-92
  4. ;
  5. ; This Module contains Proprietary Information of Microsoft
  6. ; Corporation and should be treated as Confidential.
  7. ;
  8. title emoem.asm - OEM dependent code for 80x87
  9. ;--------------------------------------------------------------------
  10. ;
  11. ; OEM customization routines for 8087/80287/80387 coprocessor
  12. ;
  13. ; This module is designed to work with the following
  14. ; Microsoft language releases:
  15. ;
  16. ; Microsoft C 3.00 and later
  17. ; Microsoft FORTRAN 77 3.30 and later
  18. ; Microsoft Pascal 3.30 and later
  19. ;
  20. ; This module supersedes the OEMR7.ASM module used in earlier
  21. ; versions of Microsoft FORTRAN 77 and Pascal. The documentation
  22. ; provided with the FORTRAN and Pascal releases refers to the old
  23. ; OEMR7.ASM module and is only slightly relevant to this module.
  24. ;
  25. ; The following routines need to be written to properly handle the
  26. ; 8087/80287/80387 installation, termination, and interrupt handler
  27. ;
  28. ; __FPINSTALL87 install 80x87 interrupt handler
  29. ; __FPTERMINATE87 deinstall 80x87 interrupt handler
  30. ; __fpintreset reset OEM hardware if an 80x87 interrupt
  31. ;
  32. ; ***** NEW INSTRUCTIONS *****
  33. ;
  34. ; If you want a PC clone version, do nothing. The libraries are
  35. ; setup for working on IBM PC's and clones.
  36. ;
  37. ; These instructions only need to be followed if a non-IBM PC
  38. ; clone version is desired.
  39. ;
  40. ; This module should be assembled with the
  41. ; Microsoft Macro Assembler Version 4.00 or later as follows:
  42. ;
  43. ; masm -DOEM -r emoem.asm;
  44. ;
  45. ; Most hardware handles the 8087/80287/80387 in one of the following
  46. ; three ways -
  47. ;
  48. ; 1. NMI - IBM PC and clones all handle the interrupt this way
  49. ; 2. single 8259
  50. ; 3. master/slave 8259
  51. ;
  52. ; Manufacturer specific initialization is supported for these 3
  53. ; machine configurations either by modifying this file and replacing
  54. ; the existing EMOEM module in the math libraries or by patching
  55. ; the .LIB and .EXE files directly.
  56. ;
  57. ; LIB 87-+EMOEM;
  58. ; LIB EM-+EMOEM;
  59. ;
  60. ;--------------------------------------------------------------------
  61. ifdef OEM
  62. if1
  63. %out OEM version for non-clone support
  64. endif
  65. endif
  66. ;---------------------------------------------------------------------
  67. ; Assembly constants.
  68. ;---------------------------------------------------------------------
  69. ; MS-DOS OS calls
  70. OPSYS EQU 21H
  71. SETVECOP EQU 25H
  72. GETVECOP EQU 35H
  73. DOSVERSION EQU 30h
  74. CTLCVEC EQU 23h
  75. EMULATOR_DATA segment para public 'FAR_DATA'
  76. assume ds:EMULATOR_DATA
  77. ; User may place data here if DS is setup properly.
  78. ; Recommend keeping the data items in the code segment.
  79. EMULATOR_DATA ends
  80. EMULATOR_TEXT segment para public 'CODE'
  81. assume cs:EMULATOR_TEXT
  82. public __FPINSTALL87 ; DO NOT CHANGE THE CASE ON
  83. public __FPTERMINATE87 ; THESE PUBLIC DEFINITIONS
  84. extrn __FPEXCEPTION87:near ; DO NOT CHANGE CASE
  85. ifdef OEM
  86. ;***********************************************************************
  87. ;
  88. ; Hardware dependent parameters in the 80x87 exception handler.
  89. ;
  90. ; For machines using 2 8259's to handle the 80x87 exception, be sure that
  91. ; the slave 8259 is the 1st below and the master is the 2nd.
  92. ;
  93. ; The last 4 fields allow you to enable extra interrupt lines into the
  94. ; 8259s. It should only be necessary to use these fields if the 80x87
  95. ; interrupt is being masked out by the 8259 PIC.
  96. ;
  97. ; The ocw2's (EOI commands) can be either non-specific (20H) or
  98. ; specific (6xH where x=0 to 7). If you do not know which interrupt
  99. ; request line on the 8259 the 80x87 exception uses, then you should issue
  100. ; the non-specific EOI (20H). Interrupts are off at this point in the
  101. ; interrupt handler so a higher priority interrupt will not be seen.
  102. oeminfo struc
  103. oemnum db 0 ; MS-DOS OEM number (IBM is 00h)
  104. intnum db 2 ; IBM PC clone interrupt number
  105. share db 0 ; nonzero if original vector should be taken
  106. a8259 dw 0 ; 1st 8259 (A0=0) port #
  107. aocw2 db 0 ; 1st 8259 (A0=0) EOI command
  108. b8259 dw 0 ; 2nd 8259 (A0=0) port #
  109. bocw2 db 0 ; 2nd 8259 (A0=0) EOI command
  110. a8259m dw 0 ; 1st 8259 (A0=1) port #
  111. aocw1m db 0 ; 1st 8259 (A0=1) value to mask against IMR
  112. b8259m dw 0 ; 2nd 8259 (A0=1) port #
  113. bocw1m db 0 ; 2nd 8259 (A0=1) value to mask against IMR
  114. oeminfo ends
  115. ;-----------------------------------------------------------------------
  116. ; OEM specific 80x87 information
  117. ;
  118. ; If the OEM number returned from the DOS version call matches,
  119. ; this information is automatically moved into the oem struc below.
  120. oemtab label byte ; Table of OEM specific values for 80x87
  121. ; OEM#, int, shr, a59, acw2,b59, bcw2,a59m,acw1,b59m,bcw1
  122. ;TI Professional Computer
  123. TI_prof oeminfo <028h,047h,000h,018h,020h,0000,0000,0000,0000,0000,0000>
  124. db 0 ; end of table
  125. ; Unique pattern that can be searched for with the debugger so that
  126. ; .LIB or .EXE files can be patched with the correct values.
  127. ; If new values are patched into .LIB or .EXE files, care must be
  128. ; taken in insure the values are correct. In particular, words and
  129. ; bytes are intermixed in oeminfo structure. Remember words are
  130. ; stored low byte - high byte in memory on the 8086 family.
  131. db '<<8087>>' ; older versions used '<8087>'
  132. ; Some manufacturer's machines can not be differentiated by the
  133. ; OEM number returned by the MS-DOS version check system call.
  134. ; For these machines it is necessary to replace the line below
  135. oem1 oeminfo <> ; default values for IBM PC & clones
  136. ; with one of the following. If your machine has an 80x87 capability
  137. ; and it is not in the list below, you should contact your hardware
  138. ; manufacturer for the necessary information.
  139. ;ACT Apricot
  140. ;oem1 oeminfo <000h,055h,000h,000h,020h,000h,000h,000h,000h,000h,000h>
  141. ;NEC APC3 and PC-9801 (OEM number returned by NEC MS-DOS's is different)
  142. ;oem1 oeminfo <000h,016h,000h,008h,066h,000h,067h,00Ah,0BFh,002h,07Fh>
  143. ;---------------------------------------------------------------------
  144. aoldIMR db 0 ; 1st 8259 original IMR value
  145. boldIMR db 0 ; 2nd 8259 original IMR value
  146. endif ;OEM
  147. statwd dw 0 ; Temporary for status word
  148. oldvec dd 0 ; Old value in 80x87 exception interrupt vector
  149. ctlc dd 0 ; Old value of Control-C vector (INT 23h)
  150. page
  151. ;---------------------------------------------------------------------
  152. ;
  153. ; Perform OEM specific initialization of the 80x87.
  154. ;
  155. __FPINSTALL87:
  156. push ds ; DS = EMULATOR_DATA
  157. push cs ; Move current CS to DS for opsys calls.
  158. pop ds
  159. assume ds:EMULATOR_TEXT
  160. ifdef OEM
  161. push ds
  162. pop es ; CS = DS = ES
  163. mov ah,DOSVERSION
  164. int OPSYS ; bh = OEM#
  165. cld
  166. mov si,offset oemtab ; start of OEM 80x87 info table
  167. mov di,offset oem1+1
  168. mov cx,(size oem1)-1
  169. OEMloop:
  170. lodsb ; get OEM#
  171. or al,al
  172. jz OEMdone ; OEM# = 0 - did not find OEM
  173. cmp al,bh ; correct OEM#
  174. je OEMfound
  175. add si,cx ; skip over OEM information
  176. jmp OEMloop
  177. OEMfound:
  178. rep movsb ; move the information
  179. OEMdone: ; done with automatic customization
  180. endif ;OEM
  181. ; Save old interrupt vector.
  182. ; Ask operating system for vector.
  183. ifdef WINDOWS
  184. mov ax, word ptr [oldvec]
  185. or ax, word ptr [oldvec+2]
  186. jnz SetVector
  187. endif ;WINDOWS
  188. ifdef OEM
  189. mov al,[oem1].intnum ; Interrupt vector number.
  190. mov ah,GETVECOP ; Operating system call interrupt.
  191. else
  192. mov ax,GETVECOP shl 8 + 2 ; get interrupt vector 2
  193. endif ;OEM
  194. int OPSYS ; Call operating system.
  195. mov word ptr [oldvec],bx ; Squirrel away old vector.
  196. mov word ptr [oldvec+2],es
  197. ; Have operating system install interrupt vectors.
  198. SetVector:
  199. mov dx,offset __fpinterrupt87 ; Load DX with 80x87 interrupt handler.
  200. ifdef OEM
  201. mov ah,SETVECOP ; Set interrupt vector code in AH.
  202. mov al,[oem1].intnum ; Set vector number.
  203. else
  204. mov ax,SETVECOP shl 8 + 2 ; set interrupt vector 2
  205. endif ;OEM
  206. int OPSYS ; Install vector.
  207. ; Intercept Control-C vector to guarentee cleanup
  208. mov ax,GETVECOP shl 8 + CTLCVEC
  209. int OPSYS
  210. mov word ptr [ctlc],bx
  211. mov word ptr [ctlc+2],es
  212. mov dx,offset ctlcexit
  213. mov ax,SETVECOP shl 8 + CTLCVEC
  214. int OPSYS
  215. ifdef OEM
  216. ; set up 8259's so that 80x87 interrupts are enabled
  217. mov ah,[oem1].aocw1m ; get mask for 1st 8259 IMR
  218. or ah,ah ; if 0, don't need to do this
  219. jz installdone ; and only 1 8259
  220. mov dx,[oem1].a8259m ; get port number for 1st 8259 (A0=1)
  221. in al,dx ; read old IMR value
  222. mov [aoldIMR],al ; save it to restore at termination
  223. and al,ah ; mask to enable interrupt
  224. jmp short $+2 ; for 286's
  225. out dx,al ; write out new mask value
  226. mov ah,[oem1].bocw1m ; get mask for 2nd 8259 IMR
  227. or ah,ah ; if 0, don't need to do this
  228. jz installdone ;
  229. mov dx,[oem1].b8259m ; get port number for 2nd 8259 (A0=1)
  230. in al,dx ; read old IMR value
  231. mov [boldIMR],al ; save it to restore at termination
  232. and al,ah ; mask to enable interrupt
  233. jmp short $+2 ; for 286's
  234. out dx,al ; write out new mask value
  235. installdone:
  236. endif ;OEM
  237. assume ds:EMULATOR_DATA
  238. pop ds
  239. ret
  240. page
  241. ; __FPTERMINATE87
  242. ;
  243. ; This routine should do the OEM 80x87 cleanup. This routine is called
  244. ; before the program exits.
  245. ;
  246. ; DS = EMULATOR_DATA
  247. __FPTERMINATE87:
  248. push ds
  249. push ax
  250. push dx
  251. ifdef OEM
  252. mov ah,SETVECOP
  253. mov al,[oem1].intnum
  254. else
  255. mov ax,SETVECOP shl 8 + 2
  256. endif ;OEM
  257. lds dx,[oldvec]
  258. int OPSYS
  259. ifdef OEM
  260. ; reset 8259 IMR's to original state
  261. push cs
  262. pop ds ; DS = CS
  263. assume ds:EMULATOR_TEXT
  264. cmp [oem1].aocw1m,0 ; did we have to change 1st 8259 IMR
  265. je term2nd8259 ; no - check 2nd 8259
  266. mov al,[aoldIMR] ; get old IMR
  267. mov dx,[oem1].a8259m ; get 1st 8259 (A0=1) port #
  268. out dx,al ; restore IMR
  269. term2nd8259:
  270. cmp [oem1].bocw1m,0 ; did we have to change 2nd 8259 IMR
  271. je terminatedone ; no
  272. mov al,[boldIMR] ; get old IMR
  273. mov dx,[oem1].b8259m ; get 2nd 8259 (A0=1) port #
  274. out dx,al ; restore IMR
  275. terminatedone:
  276. endif ;OEM
  277. pop dx
  278. pop ax
  279. pop ds
  280. assume ds:EMULATOR_DATA
  281. ret
  282. ; Forced cleanup of 80x87 exception handling on Control-C
  283. ctlcexit:
  284. push ax
  285. push dx
  286. push ds
  287. call __FPTERMINATE87 ; forced cleanup of exception handler
  288. lds dx,[ctlc] ; load old control C vector
  289. mov ax,SETVECOP shl 8 + CTLCVEC
  290. int OPSYS
  291. pop ds
  292. pop dx
  293. pop ax
  294. jmp [ctlc] ; go through old vector
  295. page
  296. ; __fpinterrupt87
  297. ;
  298. ; This is the 80x87 exception interrupt routine.
  299. ;
  300. ; All OEM specific interrupt and harware handling should be done in
  301. ; __fpintreset because __FPEXCEPTION87 (the OEM independent 80x87
  302. ; exception handler) may not return. __FPEXCEPTION87 also turns
  303. ; interrupts back on.
  304. ;
  305. PENDINGBIT= 80h ; Bit in status word for interrupt pending
  306. __fpinterrupt87:
  307. assume ds:nothing
  308. nop
  309. fnstsw [statwd] ; Store out exceptions
  310. push cx ; waste time
  311. mov cx,3
  312. self:
  313. loop self
  314. pop cx
  315. test byte ptr [statwd],PENDINGBIT ; Test for 80x87 interrupt
  316. jz not87int ; Not an 80x87 interrupt.
  317. ifdef OEM
  318. call __fpintreset ; OEM interrupt reset routine
  319. endif ;OEM
  320. call __FPEXCEPTION87 ; 80x87 error handling - may not return
  321. ; this routine turns interrupts back on
  322. ifdef OEM
  323. cmp [oem1].share,0 ; Should we execute the old interrupt routine?
  324. jnz not87int ; if so then do it
  325. ; else return from interrupt
  326. ; If you fall through here to do further hardware resetting, things
  327. ; may not always work because __FPEXCEPTION87 does not always return
  328. ; This only happens when the 80x87 handler gets an exception that is
  329. ; a fatal error in the language runtimes. I.e., divide by zero
  330. ; is a fatal error in all the languages, unless the control word has
  331. ; set to mask out divide by zero errors.
  332. endif ;OEM
  333. done8087:
  334. iret
  335. not87int:
  336. jmp [oldvec] ; We should never return from here.
  337. ifdef OEM
  338. __fpintreset:
  339. push ax
  340. push dx
  341. mov al,[oem1].aocw2 ; Load up EOI instruction.
  342. or al,al ; Is there at least one 8259 to be reset?
  343. jz Reset8259ret ; no
  344. mov dx,[oem1].a8259
  345. out dx,al ; Reset (master) 8259 interrupt controller.
  346. mov al,[oem1].bocw2 ; Load up EOI instruction.
  347. or al,al ; Is there a slave 8259 to be reset?
  348. jz Reset8259ret
  349. mov dx,[oem1].b8259
  350. out dx,al ; Reset slave 8259 interrupt controller.
  351. Reset8259ret:
  352. pop dx
  353. pop ax
  354. ret
  355. endif ;OEM
  356. EMULATOR_TEXT ends
  357. end