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.

642 lines
12 KiB

  1. ;------------------------------ Module Header ------------------------------;
  2. ; Module Name: Timer interface procedures
  3. ;
  4. ; Created: ??-???-83
  5. ;
  6. ; Copyright (c) 1983, 1984, 1985, 1986, 1987 Microsoft Corporation
  7. ;
  8. ; History:
  9. ; 10-Jan-87 by ronm Adusted StackBase to be even
  10. ; 9-Jan-87 by ronm Patches to support HiTime.asm
  11. ;---------------------------------------------------------------------------;
  12. TITLE Timer interface procedures
  13. include system.inc
  14. include wow.inc
  15. include wowusr.inc
  16. include vint.inc
  17. ifdef NEC_98
  18. include timer.inc
  19. externA __ROMBIOS
  20. endif ; NEC_98
  21. externFP WOW16Call
  22. ; Interrupt vector to use
  23. VECTOR equ 08h
  24. assumes CS,CODE
  25. sBegin DATA
  26. PUBLIC timerTable
  27. timerTable LABEL BYTE
  28. tiblock <-1,0,0>
  29. tiblock <-1,0,0>
  30. tiblock <-1,0,0>
  31. tiblock <-1,0,0>
  32. tiblock <-1,0,0>
  33. tiblock <-1,0,0>
  34. tiblock <-1,0,0>
  35. tiblock <-1,0,0>
  36. DW -1
  37. DW -1
  38. ifdef WOW
  39. cTimers DW 0
  40. endif
  41. enabled DB 0 ; 0 means int 8 hook not installed
  42. ; 1 means int 8 hook installed
  43. ; >1 means inside our int 8 hook
  44. ifdef NEC_98
  45. externB reflected ; 930206
  46. endif ; NEC_98
  47. if 0
  48. ;
  49. ; no longer used
  50. ;
  51. public StackBase
  52. EVEN ; Put the stack at a word boundary!
  53. StackBase DB 64 DUP (-1)
  54. PUBLIC prevInt8Proc,prevSSSP,enabled
  55. PUBLIC cms, cmsRound
  56. DB 128 DUP (?)
  57. int8stack LABEL BYTE ; Stack to use inside our int 8 hook
  58. prevSSSP DD 0 ; Previous stack when inside our hook
  59. endif
  60. prevInt8Proc DD 0 ; Previous int 8 interrupt handler
  61. cms DD 0 ; msec count.
  62. cmsRound DW 0 ; for rounding off the msec count.
  63. ifdef NEC_98
  64. DB '@@@@'
  65. TIINTFLAG1 DW 0
  66. TIINTFLAG2 DW 0
  67. endif ; NEC_98
  68. sEnd
  69. sBegin CODE ; Beginning of code segment
  70. assumes CS,CODE
  71. externW MyCSDS ; always in CS (even in ROM)
  72. ;--- timer hardware service -----------------------
  73. ;
  74. noevent:
  75. ifdef NEC_98
  76. assumes ds, DATA
  77. cmp [reflected],0
  78. jne @f
  79. NoReflect:
  80. push ax
  81. mov al,20h ; eoi
  82. out 0,al
  83. pop ax
  84. pop ds
  85. iret
  86. @@: assumes ds,nothing
  87. push ds
  88. push ax
  89. mov ax, __ROMBIOS
  90. mov ds, ax
  91. cmp word ptr ds:[018ah], 1 ; Q : timer counter end ?
  92. pop ax
  93. pop ds
  94. je short NoReflect
  95. endif ; NEC_98
  96. assumes ds, DATA
  97. ; push address
  98. push word ptr prevInt8Proc[2]
  99. push word ptr prevInt8Proc[0]
  100. ; restore ds out of stack
  101. push bp
  102. mov bp, sp
  103. mov ds, [bp+6]
  104. assumes ds,nothing
  105. pop bp
  106. ; jump to prev proc popping saved ds
  107. retf 2
  108. ;----------------------------- Private Function ----------------------------;
  109. ;
  110. ; Entry: call far ptr timer_int
  111. ;
  112. ; Returns: nothing
  113. ;
  114. ; Registers Destroyed: none
  115. ;
  116. ; History:
  117. ; 09-Jan-87 by ronm Added hooks for the high resolution timer fns
  118. ; in hitime.asm
  119. ; ??-???-?? by ???? Wrote it
  120. ;---------------------------------------------------------------------------;
  121. assumes ds,nothing
  122. assumes es,nothing
  123. cProc timer_int,<FAR,PUBLIC>
  124. cBegin nogen
  125. ; Don't trash any registers.
  126. push ds
  127. mov ds,MyCSDS
  128. assumes ds, DATA
  129. add word ptr [cms][0],(res_low / 1000)
  130. adc word ptr [cms][2],0
  131. add [cmsRound],(res_low - ((res_low / 1000) * 1000))
  132. cmp [cmsRound],1000
  133. jb ti0
  134. sub [cmsRound],1000
  135. inc word ptr [cms][0]
  136. jnz ti0
  137. inc word ptr [cms][2]
  138. ti0:
  139. ifdef NEC_98
  140. push dx ; clear int share reg.
  141. push ax
  142. mov dx,879h
  143. in al,dx
  144. pop ax
  145. pop dx
  146. endif ; NEC_98
  147. cmp [enabled],1
  148. jne noevent
  149. inc [enabled]
  150. ifdef NEC_98
  151. cmp [reflected],0
  152. je short ti01
  153. endif ; NEC_98
  154. pushf
  155. ; enable IF flag in stack flags to prevInt8Proc if they were
  156. ; on when this routine was entered -- this allows the 286 DOS
  157. ; extender to enable ints after running real mode Int 8 handler.
  158. FLAGS1 = 3 ; +0 +2 +4 +6 +8 +10
  159. FLAGS2 = 11 ; BP -> [bp] [fl] [ds] [ip] [cs] [fl]
  160. push bp
  161. mov bp,sp
  162. test byte ptr FLAGS2[bp],02h
  163. jz @f
  164. or byte ptr FLAGS1[bp],02h
  165. @@: pop bp
  166. call [prevInt8Proc] ; call previous Int 8 routine
  167. ifdef NEC_98
  168. push ax
  169. mask TIMERMASK
  170. mov al,36h
  171. out timodeset,al ; Timer mode set
  172. delay 8253,O-O
  173. mov ax,0f000h ;count(25msec * 2457.6)
  174. push es
  175. push ax
  176. mov ax,40h
  177. mov es,ax
  178. test byte ptr es:[101h],80h ; Q : clock 2.5 MHz ?
  179. pop ax
  180. pop es
  181. jz @f ;5MHz,10MHz,12MHz,20MHz 25MHz set
  182. mov ax,0c300h ;8MHz,16MHz set
  183. @@:
  184. out ticntset,al
  185. delay 8253,O-O
  186. xchg ah,al
  187. out ticntset,al
  188. unmask TIMERMASK
  189. pop ax
  190. jmp short ti1
  191. ti01:
  192. push ax
  193. mov al,20h ; eoi
  194. out 0,al
  195. pop ax
  196. endif ; NEC_98
  197. public ti1
  198. ti1:
  199. comment ~
  200. FCLI
  201. mov word ptr [prevSSSP][2],ss
  202. mov word ptr [prevSSSP][0],sp
  203. push ds
  204. pop ss
  205. mov sp,codeOffset int8stack
  206. FSTI ; Allow interrupts
  207. end comment ~
  208. push ax
  209. mov al,00001011b ; ask for 8259 status
  210. ifdef NEC_98
  211. out 00h,al
  212. jmp $+2
  213. jmp $+2
  214. in al,00h ; get the status
  215. else ; NEC_98
  216. out 20h,al
  217. jmp $+2
  218. in al,20h ; get the status
  219. endif ; NEC_98
  220. or al,al
  221. jnz TheEnd ; if other pending EOIs, just exit
  222. push bp
  223. push es
  224. push bx
  225. push cx
  226. push dx
  227. push si
  228. push di
  229. xor bp,bp ; No valid BP chain
  230. mov si,doffset TimerTable
  231. nextent:
  232. cld
  233. lodsw ; Get timer rate
  234. .errnz tirate
  235. inc ax ; -1 means unused entry
  236. jnz checkent ; no, check used entry
  237. lodsw ; yes, get timer count
  238. .errnz 2-ticount
  239. inc ax ; another -1 means end of table
  240. jz lastent ; yes, all done
  241. add si,4 ; o.w. skip to next entry
  242. jmp nextent
  243. checkent:
  244. dec ax ; 0 means call at maximum rate
  245. jz callent
  246. dec word ptr DS:[si] ; o.w. decrement rate counter
  247. .errnz 2-ticount
  248. jz callent ; zero means timer has gone off
  249. add si,6 ; o.w. skip to next entry
  250. jmp nextent
  251. callent:
  252. mov DS:[si],ax
  253. inc si
  254. inc si
  255. lea ax,[si-4] ; Pass timer handle in AX
  256. .errnz 4-tiproc
  257. call dword ptr DS:[si]
  258. add si,4
  259. jmp nextent
  260. lastent:
  261. pop di
  262. pop si
  263. pop dx
  264. pop cx
  265. pop bx
  266. pop es
  267. pop bp
  268. TheEnd:
  269. pop ax
  270. dec [enabled]
  271. comment ~
  272. FCLI
  273. mov ss,word ptr [prevSSSP][2]
  274. mov sp,word ptr [prevSSSP][0]
  275. FSTI
  276. end comment ~
  277. pop ds
  278. iret
  279. cEnd nogen
  280. ;============================================================================
  281. ; DWORD GetSystemMsecCount(void) - returns msec count.
  282. ;
  283. assumes ds,nothing
  284. assumes es,nothing
  285. DUserThunk GETSYSTEMMSECCOUNT,0
  286. ;LabelFP <PUBLIC, GetSystemMsecCount>
  287. ;
  288. ; push ds
  289. ; mov ds, MyCSDS
  290. ; assumes ds, DATA
  291. ;
  292. ; mov ax,word ptr [cms][0]
  293. ; mov dx,word ptr [cms][2]
  294. ; pop ds
  295. ; retf
  296. ;----------------------------- Private Function ----------------------------;
  297. ;
  298. ; EnableSystemTimers() - enable hardware timer interrupts
  299. ;
  300. ; Entry: cCall far ptr EnableSystemTimers
  301. ;
  302. ; Returns: nothing
  303. ;
  304. ; Registers Destroyed: ??
  305. ;
  306. ; History:
  307. ; 09-Jan-87 by ronm Patched to support hitime.asm
  308. ; ??-???-?? by ???? Wrote it
  309. ;---------------------------------------------------------------------------;
  310. assumes ds,nothing
  311. assumes es,nothing
  312. cProc EnableSystemTimers,<FAR,PUBLIC>
  313. cBegin nogen
  314. ; All done if just already enabled
  315. push ds
  316. mov ds,MyCSDS
  317. assumes ds, DATA
  318. ifdef WOW
  319. ; see if we're being called by Create to really enable tics
  320. cmp cTimers, 1
  321. je est_doit
  322. endif
  323. cmp enabled,0
  324. jne edone
  325. est_doit:
  326. mov [enabled],1
  327. ifdef WOW
  328. ; don't install the tic handler if no systemtimers registered
  329. cmp cTimers, 0
  330. je edone
  331. endif
  332. ; Save away current timer interrupt vector value
  333. mov ax,3500h or VECTOR
  334. int 21h
  335. mov word ptr [PrevInt8Proc][0],bx
  336. mov word ptr [PrevInt8Proc][2],es
  337. ; Setup timer interrupt vector to point to our interrupt routine
  338. mov ax,2500h or VECTOR
  339. push cs
  340. pop ds
  341. mov dx,codeOFFSET timer_int
  342. int 21h
  343. ifdef NEC_98
  344. mask TIMERMASK
  345. mov al,36h
  346. out timodeset,al ; Timer mode set
  347. delay 8253,O-O
  348. mov ax,0f000h ;count(25msec * 2457.6)
  349. push es
  350. push ax
  351. mov ax,40h
  352. mov es,ax
  353. test byte ptr es:[101h],80h ; Q : clock 2.5 MHz ?
  354. pop ax
  355. pop es
  356. jz @f ;5MHz,10MHz,12MHz,20MHz 25MHz set
  357. mov ax,0c300h ;8MHz,16MHz set
  358. @@:
  359. out ticntset,al
  360. delay 8253,O-O
  361. xchg ah,al
  362. out ticntset,al
  363. unmask TIMERMASK
  364. sti
  365. endif ; NEC_98
  366. edone:
  367. pop ds
  368. ret
  369. cEnd nogen
  370. ;-----------------------------------------------------------------------;
  371. ; DisableSystemTimers
  372. ;
  373. ; DisableSystemTimers() - disable system timer interrupts, restoring
  374. ; the previous timer interrupt handler.
  375. ;
  376. ; Entry:
  377. ;
  378. ; Returns:
  379. ;
  380. ; Registers Destroyed:
  381. ;
  382. ; History:
  383. ; Mon 21-Nov-1988 18:44:44 -by- David N. Weise [davidw]
  384. ; Added this nifty comment block.
  385. ;-----------------------------------------------------------------------;
  386. assumes ds,nothing
  387. assumes es,nothing
  388. cProc DisableSystemTimers,<FAR,PUBLIC>
  389. cBegin nogen
  390. push ds
  391. mov ds,MyCSDS
  392. assumes ds, DATA
  393. ; Do nothing if not enabled
  394. cmp [enabled],0
  395. je ddone
  396. ifdef NEC_98
  397. mask TIMERMASK
  398. endif ; NEC_98
  399. mov [enabled],0
  400. ; Restore the timer interrupt vector to point to previous value
  401. mov ax,2500h or VECTOR
  402. lds dx,prevInt8Proc
  403. int 21h
  404. ddone:
  405. pop ds
  406. ret
  407. cEnd nogen
  408. ;-----------------------------------------------------------------------;
  409. ; CreateSystemTimer
  410. ;
  411. ;
  412. ; Entry:
  413. ;
  414. ; Returns:
  415. ;
  416. ; Registers Destroyed:
  417. ;
  418. ; History:
  419. ; Mon 21-Nov-1988 18:44:44 -by- David N. Weise [davidw]
  420. ; Added this nifty comment block.
  421. ;-----------------------------------------------------------------------;
  422. assumes ds,nothing
  423. assumes es,nothing
  424. cProc CreateSystemTimer,<PUBLIC,FAR>
  425. ParmW rate
  426. ParmD lpproc
  427. cBegin
  428. mov ds,MyCSDS
  429. assumes ds, DATA
  430. mov bx,doffset timerTable
  431. mov ax,rate
  432. or ax,ax
  433. jz ctfirst
  434. mov cx,1000 ; change msecs into ticks.
  435. mul cx
  436. mov cx,res_low
  437. div cx
  438. ctfirst:
  439. FCLI ; beginning of critical section
  440. ctloop:
  441. cmp ds:[bx].tirate,-1
  442. jne ctnext
  443. cmp ds:[bx].ticount,-1
  444. je ctfail
  445. mov cx,OFF_lpproc
  446. mov dx,SEG_lpproc
  447. mov word ptr ds:[bx].tiproc[0],cx
  448. mov word ptr ds:[bx].tiproc[2],dx
  449. mov ds:[bx].ticount,ax
  450. mov ds:[bx].tirate,ax ; Set this last
  451. ifdef WOW
  452. ; turn on tics if the count is going from 0 -> 1 and they're
  453. ; supposed to be enabled
  454. inc cTimers
  455. cmp cTimers, 1
  456. jne @f
  457. cmp enabled, 0 ; need to turn on tics?
  458. je @f ; -> nope
  459. push bx
  460. call EnableSystemTimers
  461. pop bx
  462. @@:
  463. endif
  464. jmp short ctexit
  465. ctnext: add bx,SIZE tiblock
  466. jmp ctloop
  467. ctfail: xor bx,bx
  468. ctexit: FSTI ; end of critical section
  469. mov ax,bx
  470. mov cx,bx
  471. cEnd
  472. ;-----------------------------------------------------------------------;
  473. ; KillSystemTimer
  474. ;
  475. ;
  476. ; Entry:
  477. ;
  478. ; Returns:
  479. ;
  480. ; Registers Destroyed:
  481. ;
  482. ; History:
  483. ; Mon 21-Nov-1988 18:44:44 -by- David N. Weise [davidw]
  484. ; Added this nifty comment block.
  485. ;-----------------------------------------------------------------------;
  486. assumes ds,nothing
  487. assumes es,nothing
  488. cProc KillSystemTimer,<PUBLIC,FAR>,<di>
  489. parmW htimer
  490. cBegin
  491. mov es,MyCSDS
  492. assumes es,nothing
  493. mov di,doffset TimerTable
  494. mov ax,htimer
  495. ktloop: cmp es:[di].tirate,-1
  496. jne ktmatch
  497. cmp es:[di].ticount,-1
  498. jne ktnext
  499. jmp short ktexit
  500. ktmatch:
  501. cmp di,ax
  502. jne ktnext
  503. cld
  504. mov ax,-1
  505. stosw
  506. not ax
  507. stosw
  508. stosw
  509. stosw
  510. ifdef WOW
  511. dec es:[cTimers] ; was this the last one?
  512. jnz @f ; -> nope
  513. cmp es:[enabled], 0 ; are tics on?
  514. je @f ; -> nope
  515. ; Restore the timer interrupt vector to point to previous value
  516. push ax
  517. mov ax,2500h or VECTOR
  518. lds dx,es:[prevInt8Proc]
  519. int 21h
  520. pop ax
  521. @@:
  522. endif
  523. jmp short ktexit
  524. ktnext: add di,SIZE tiblock
  525. jmp ktloop
  526. ktexit: mov cx,ax
  527. cEnd
  528. ifdef NEC_98
  529. LabelFP <PUBLIC, InquireLongInts>
  530. ;------- '88/01/07 -----------------------------------
  531. MOV AX,1
  532. ; mov ax,cs:[AT_DOS30]
  533. ;------------------------------------------------------
  534. mov cx,ax
  535. retf
  536. endif ; NEC_98
  537. sEnd CODE ; End of code segment
  538. END