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.

305 lines
7.7 KiB

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;
  3. ; STARTEND.ASM
  4. ;
  5. ; Copyright (c) Microsoft Corporation 1989, 1990. All rights reserved.
  6. ;
  7. ; This module contains the routines which initialize, and clean
  8. ; up the driver after Libentry/WEP/Enable/Diable called by windows.
  9. ;
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ?PLM=1 ; pascal call convention
  12. ?WIN=0 ; Windows prolog/epilog code
  13. ?DF=1
  14. PMODE=1
  15. .xlist
  16. include cmacros.inc
  17. include int31.inc
  18. include windows.inc
  19. include mmddk.inc
  20. include mmsystem.inc
  21. include timer.inc
  22. .list
  23. externA __WinFlags
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ;
  26. ; Local data segment
  27. ;
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. sBegin DATA
  30. ; ISR support
  31. public lpOLDISR
  32. lpOldISR dd ?
  33. ifdef RMODE_INT
  34. public RModeOldISR
  35. RModeOldISR dd 0
  36. public RModeCodeSegment
  37. RModeCodeSegment dw ?
  38. endif ;RMODE_INT
  39. externW Events
  40. externW wNextTime
  41. ifdef NEC_98
  42. externB bClockFlag ; 5Mhz = 0 ; 8Mhz = other
  43. endif ; NEC_98
  44. sEnd DATA
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. ;
  47. ; Code segment
  48. ;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. externFP tddISR ; in local.asm
  51. externFP tddSetInterruptPeriodFar ; in timer.asm
  52. ifdef RMODE_INT
  53. externW RmodeDataSegment ; in local.asm
  54. externFP tddRModeISR ; in local.asm
  55. endif
  56. externFP GetSelectorBase ; kernel
  57. externFP AllocCStoDSAlias ; kernel
  58. externFP FreeSelector ; kernel
  59. sBegin CodeInit
  60. assumes cs,CodeInit
  61. assumes ds,Data
  62. assumes es,nothing
  63. ;----------------------------Private-Routine----------------------------;
  64. ; SegmentFromSelector
  65. ;
  66. ; Converts a selector to a segment...note that this routine assumes
  67. ; the memory pointed to by the selector is below the 1Meg line!
  68. ;
  69. ; Params:
  70. ; AX = selector to convert to segment
  71. ;
  72. ; Returns:
  73. ; AX = segment of selector given
  74. ;
  75. ; Error Returns:
  76. ; None
  77. ;
  78. ; Registers Destroyed:
  79. ; none
  80. ;
  81. ;-----------------------------------------------------------------------;
  82. assumes ds,Data
  83. assumes es,nothing
  84. SegmentFromSelector proc near
  85. cCall GetSelectorBase,<ax> ;DX:AX = base of selector
  86. rept 4
  87. shr dx,1
  88. rcr ax,1
  89. endm
  90. ;AX now points to *segment* (iff selector is based below 1Mb)
  91. ret
  92. SegmentFromSelector endp
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ;
  95. ; @doc INTERNAL
  96. ;
  97. ; @api WORD | Enable | This function enables the driver. It
  98. ; will hook interrupts and validate the hardware.
  99. ;
  100. ; @rdesc Returns 1 if successfull, and 0 otherwise.
  101. ;
  102. ; @comm This function is automatically invoked when the library is
  103. ; first loaded. It is included so that win386 could call it
  104. ; when it switches VMs.
  105. ;
  106. ; @xref Disable
  107. ;
  108. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  109. cProc Enable286 <FAR, PUBLIC> <si, di>
  110. cBegin
  111. ; make sure clock interrupts are disabled until after
  112. ; service routine has been initialized!!
  113. AssertSLI
  114. cli
  115. ; get the currently owned timer interrupt vector
  116. ; get interrupt vector, and specify timer interrupt number
  117. ; mov ax,03500H + TIMERINTERRUPT
  118. ; push es
  119. ; int 21h ; get the current vector in ES:BX
  120. ; mov lpOldISR.Sel,es
  121. ; mov lpOldISR.Off,bx ; save the old vector
  122. ; pop es
  123. ;
  124. ; ; set vector to our isr
  125. ;
  126. ; ; set interrupt vector function, and specify the timer interrupt number
  127. ; mov ax,02500h + TIMERINTERRUPT
  128. ; push ds
  129. ; mov dx,seg tddISR
  130. ; mov ds,dx
  131. ; assumes ds,nothing
  132. ; mov dx,offset tddISR
  133. ; int 21h ; set the new vector
  134. ; pop ds
  135. ; assumes ds,DATA
  136. ;
  137. ; mov ax,[wNextTime]
  138. ; not ax
  139. ; mov [wNextTime],ax ; force set of period
  140. ; call tddSetInterruptPeriodFar
  141. ifdef RMODE_INT
  142. ;
  143. ; if running under DOSX set the RMODE interrupt too
  144. ;
  145. mov ax,__WinFlags
  146. test ax,WF_PMODE
  147. jz enable_no_dosx
  148. mov ax,seg tddRModeISR
  149. call SegmentFromSelector
  150. or dx,dx ; ACK! above 1Mb
  151. jnz enable_no_dosx
  152. mov [RModeCodeSegment],ax ; save the segment of the code segment
  153. mov ax,ds ; get SEGMENT of our data segment
  154. call SegmentFromSelector
  155. push ax ; save on stack
  156. mov ax,seg tddRModeISR ; write data SEGMENT into _INTERRUPT
  157. cCall AllocCStoDSAlias,<ax> ; code segment -- requires a data alias
  158. mov es,ax
  159. pop ax
  160. mov es:[RModeDataSegment],ax
  161. cCall FreeSelector,<es> ; don't need CS alias any longer
  162. mov ax,Get_RM_IntVector ; get the real mode IRQ0 vector
  163. mov bl,DOSX_IRQ + TIMERINTERRUPT
  164. int 31h ; DOSX get real mode vector in CX:DX
  165. mov RModeOldISR.lo,dx ; save old ISR
  166. mov RModeOldISR.hi,cx
  167. mov cx,RModeCodeSegment ; CX:DX --> real mode ISR
  168. mov dx,offset tddRModeISR
  169. mov ax,Set_RM_IntVector ; DOSX Set Vector Function
  170. int 31h ; Set the DOS vector real mode
  171. enable_no_dosx:
  172. endif
  173. sti
  174. mov ax,1
  175. cEnd
  176. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  177. ;
  178. ; @doc INTERNAL
  179. ;
  180. ; @api WORD | Disable | This function disables the driver.
  181. ; It disables the hardware, unhooks interrupts and removes
  182. ; all time events from the queue.
  183. ;
  184. ; @rdesc Returns 1 if successfull, and 0 otherwise.
  185. ;
  186. ; @comm This function is called automatically when Windows unloads
  187. ; the library and invokes the WEP() function. It is included
  188. ; here so that WIN386 can use it when switching VMs.
  189. ;
  190. ; @xref Enable
  191. ;
  192. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  193. cProc Disable286 <FAR, PUBLIC> <si, di>
  194. ; note that all this is in the reverse order to Enable
  195. cBegin
  196. AssertSLI
  197. cli
  198. ifdef NEC_98
  199. setmask TIMERMASK
  200. mov al,36h
  201. out timodeset,al ; Timer mode set
  202. delay 8253,O-O
  203. mov ax,0f000h ; count(25msec * 2457.6)
  204. cmp byte ptr bClockFlag,00h ; Q : clock 5 MHz ?
  205. jz @f ; 5MHz,10MHz,12MHz,20MHz,25MHz set
  206. mov ax,0c300h ; 8MHz,16MHz set
  207. @@:
  208. out ticntset,al
  209. delay 8253,O-O
  210. xchg ah,al
  211. out ticntset,al
  212. unmask TIMERMASK
  213. else ; NEC_98
  214. ; set timer back to 55ms BIOS service
  215. xor cx,cx ; 65536 ticks per period
  216. mov al,TMR_MODE3_RW ; Read/Write counter 0 mode 3 (two bytes)
  217. out TMR_CTRL_REG,al
  218. mov al,cl
  219. out TMR_CNTR_0,al ; write low byte
  220. mov al,ch
  221. out TMR_CNTR_0,al ; write high byte
  222. endif ; NEC_98
  223. ifdef RMODE_INT
  224. ;
  225. ; check for a REAL mode int handler and un-hook it.
  226. ;
  227. mov dx,RModeOldISR.lo
  228. mov cx,RModeOldISR.hi
  229. jcxz disable_no_dosx
  230. mov bl,DOSX_IRQ + TIMERINTERRUPT
  231. mov ax,Set_RM_IntVector ;DOSX Set Vector Function
  232. int 31h ;Set the DOS vector real mode
  233. disable_no_dosx:
  234. endif
  235. ; restore the old interrupt vector
  236. mov ax,02500h + TIMERINTERRUPT
  237. ; set interrupt vector function, and specify the timer interrupt number
  238. push ds
  239. lds dx,lpOldISR
  240. assumes ds,nothing
  241. int 21h ; reset the old vector
  242. pop ds
  243. assumes ds,DATA
  244. sti
  245. mov ax,1
  246. cEnd
  247. sEnd
  248. end