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.

489 lines
12 KiB

  1. ;
  2. ; timer.inc
  3. ;
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5. ;
  6. ; segments
  7. ;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. createSeg FIXED_TEXT,Code386, word, public, CODE
  10. createSeg FIXED_TEXT,CodeFixed, word, public, CODE
  11. createSeg FIXED_286, Code286, word, public, CODE
  12. createSeg INIT_CODE, CodeInit, word, public, CODE
  13. createSeg _DATA,Data,word,public,DATA,DGROUP
  14. defgrp DGROUP,Data
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16. ;
  17. ; Equates and structure definitions
  18. ;
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. IDS_ERRORTITLE equ 1
  21. IDS_ERRORTEXT equ 2
  22. ;RMODE_INT equ 1
  23. ifdef DEBUG
  24. TDD_GETTICK equ 42
  25. TDD_GETRINTCOUNT equ 43
  26. TDD_GETPINTCOUNT equ 44
  27. endif
  28. ifdef NEC_98
  29. TDD_MINRESOLUTION equ 25 ; minimun resolution.(ms)
  30. else ; NEC_98
  31. TDD_MINRESOLUTION equ 55 ; minimum resolution. (ms)
  32. endif ; NEC_98
  33. TDD_MAX386RESOLUTION equ 1 ; maximum resolution. (ms)
  34. TDD_MAX286RESOLUTION equ 2 ; maximum resolution. (ms)
  35. TDD_MAXPERIOD equ 0FFFFh ; maximum ms period.
  36. TDD_MIN386PERIOD equ 01h ; minimum ms period.
  37. TDD_MIN286PERIOD equ 02h ; minimum ms period.
  38. ifdef NEC_98
  39. TMR_CNTR_0 equ 071h ; counter 0 - programmable system interrupt
  40. TMR_CTRL_REG equ 077h ; timer control word register
  41. else ; NEC_98
  42. TMR_CNTR_0 equ 040h ; counter 0 - programmable system interrupt
  43. TMR_CTRL_REG equ 043h ; timer control word register
  44. endif ; NEC_98
  45. TMR_MODE2_RW equ 00110100b ; Read/Write counter 0 mode 2 (two bytes)
  46. ; (countdown mode)
  47. TMR_MODE3_RW equ 00110110b ; Read/Write counter 0 mode 3 (two bytes)
  48. ; (square wave mode)
  49. PS2_SysCtrlPortB equ 61h ; IBM PS2 System Control Port B
  50. PS2_LatchBit equ 80h ; Latch clear bit for PS2
  51. ifdef NEC_98
  52. PICDATA equ 00h ; Programmable interrupt controller port
  53. SPECIFIC_EOI equ 00100000b ; IRQ 0 end-of-interrupt PIC command
  54. else ; NEC_98
  55. PICDATA equ 020h ; Programmable interrupt controller port
  56. SPECIFIC_EOI equ 01100000b ; IRQ 0 end-of-interrupt PIC command
  57. EOI_STATUS equ 00001011b ; Status of pending EOIs
  58. endif ; NEC_98
  59. TIME_BIOSEVENT equ 8000h ; special flag for bios event
  60. TIMERINTERRUPT equ 8 ; interrupt number for timer counter
  61. ; The following defines the maximum number of simultaneous events which
  62. ; can be queued. This value covers event slots 0 to 15. Note that this
  63. ; is 4 bits of data, which is relied upon in the code.
  64. ;
  65. ; The two constants defined after are used to increment and filter the
  66. ; mask added to the event slot IDs to create an event handle to return.
  67. ; They illustrate the dependence upon the MAXEVENTS constant.
  68. MAXEVENTS equ 16
  69. MASKINCREMENT equ 0010h
  70. MASKFILTER equ 000fh
  71. ; The following flags are used during the process of killing an event.
  72. ;
  73. ; The first flag indicates that an event slot is being checked by the
  74. ; kill event function, and that the EVENT_DESTROYED flag should be set
  75. ; if the pevent is killed during interrupt time before the original
  76. ; function completes its check.
  77. ;
  78. ; The second flag indicates that an event is currently being killed, and
  79. ; should not be allowed to execute. This is set in the kill timer
  80. ; function, and either cleared, or replaced with the EVENT_DESTROYED
  81. ; flag when complete.
  82. ;
  83. ; The third flag can be set either in the interrupt handler for oneshot
  84. ; events, or in the kill timer function. This is only set if the timer
  85. ; was currently being checked when an interrupt occurred, and the event
  86. ; was killed by the interrupt. This flag disallows any new event to be
  87. ; created in the event slot until the flag is cleared by the original
  88. ; kill event function exiting.
  89. EVENT_CHECKING equ 1
  90. EVENT_DESTROYING equ 2
  91. EVENT_DESTROYED equ 4
  92. EventStruct STRUC
  93. evTime dd ? ; actual time when the event will go off (in ticks)
  94. evDelay dd ? ; event delay time (in ticks)
  95. evCallback dd ? ; call back function
  96. evUser dd ? ; parameter to call-back function
  97. evResolution dw ? ; event resolution (in Ms)
  98. evID dw ? ; timer event id
  99. evFlags dw ? ; bits 1,0 = flags (one-shot/periodic)
  100. evCreate db ? ; Creation flag
  101. evDestroy db ? ; Destroying flag
  102. EventStruct ENDS
  103. errnz <(SIZE EventStruct) and 1>
  104. SizeEvent equ <(SIZE EventStruct)>
  105. ; Macro to cause a delay in between I/O accesses to the same device.
  106. IO_Delay MACRO
  107. jmp $+2
  108. ENDM
  109. ; this macro makes sure interrupts are disabled in debug driver
  110. AssertCLI MACRO
  111. ifdef DEBUG
  112. push ax
  113. pushf
  114. pop ax
  115. test ah,2
  116. jz @f
  117. int 3
  118. @@: pop ax
  119. endif
  120. ENDM
  121. ; this macro makes sure interrupts are enabled in debug driver
  122. AssertSLI MACRO
  123. ifdef DEBUG
  124. push ax
  125. pushf
  126. pop ax
  127. test ah,2
  128. jnz @f
  129. int 3
  130. @@: pop ax
  131. endif
  132. ENDM
  133. DefineInfo MACRO
  134. ifdef DEBUG
  135. externNP savedebuginfo
  136. endif
  137. ENDM
  138. SaveInfo MACRO value
  139. ifdef DEBUG
  140. ifdef savedebuginfo
  141. push ax
  142. mov ax,value
  143. call savedebuginfo
  144. pop ax
  145. else
  146. safd
  147. endif
  148. endif
  149. ENDM
  150. ; The DOS Extender used for Standard mode Windows remaps the master 8259 from
  151. ; Int vectors 8h-Fh to 50h-57h. In order to speed up com port interrupt
  152. ; response as much as possible, this driver hooks real mode interrupts
  153. ; when running in Standard mode. It currently uses the following adjustment
  154. ; value to hook the real hardware int vector. When time permits, this
  155. ; HARDCODED equate should be changed to be adjustible at run time.
  156. DOSX_IRQ equ (50h - 8h) ; Adjustment for DOSX remapping the
  157. ; master 8259 from 8h to 50h
  158. ; WinFlags[0] constants...remove when included in windows.inc
  159. WF_PMODE equ 01h
  160. WF_CPU286 equ 02h
  161. WF_CPU386 equ 04h
  162. WF_CPU486 equ 08h
  163. WF_WIN286 equ 10h ; WF_STANDARD
  164. WF_WIN386 equ 20h ; WF_ENHANCED
  165. WF_CPU086 equ 40h
  166. WF_CPU186 equ 80h
  167. ; Interrupt 31h service call equates
  168. Get_RM_IntVector equ <(Int31_Int_Serv SHL 8 ) OR Int_Get_Real_Vec>
  169. Set_RM_IntVector equ <(Int31_Int_Serv SHL 8 ) OR Int_Set_Real_Vec>
  170. GetSystemConfig equ 0c0h
  171. ;---------------------------------Macro---------------------------------;
  172. ;
  173. ; EnterCrit
  174. ;
  175. ; saves the current state of the interrupt flag on the stack then
  176. ; disables interrupts.
  177. ;
  178. ; Registers Destroyed:
  179. ; BX, FLAGS
  180. ;
  181. ;------------------------------------------------------------------------;
  182. EnterCrit macro
  183. local no_cli
  184. pushf
  185. pushf
  186. pop cx
  187. test ch,2 ; if interrupts are already off, dont blow
  188. jz no_cli ; ... ~300 clocks doing the cli
  189. cli
  190. no_cli:
  191. endm
  192. ;---------------------------------Macro---------------------------------;
  193. ;
  194. ; LeaveCrit
  195. ;
  196. ; restore the interrupt state saved by EnterCrit
  197. ;
  198. ; Registers Destroyed:
  199. ; CX, FLAGS
  200. ;
  201. ;------------------------------------------------------------------------;
  202. LeaveCrit macro reg
  203. local no_sti
  204. pop cx
  205. test ch, 2
  206. jz no_sti
  207. sti
  208. no_sti:
  209. endm
  210. ;------------------------------------------------------------------------;
  211. ;------------------------------------------------------------------------;
  212. externFP OutputDebugStr
  213. DOUT macro text
  214. local string_buffer
  215. ifdef DEBUG
  216. _DATA segment
  217. string_buffer label byte
  218. db "&text&",13,10,0
  219. _DATA ends
  220. push DataBASE
  221. push DataOFFSET string_buffer
  222. call OutputDebugStr
  223. endif
  224. endm
  225. ifdef NEC_98
  226. ; Module Name: Timer interface procedures
  227. ;
  228. ; Created: 03-08-90 NEC Y.Ueno
  229. TIMODESET EQU 77H
  230. TICNTSET EQU 71H
  231. TIMERMASK EQU 01H
  232. setmask macro code
  233. cli ; mask timer int
  234. in al,02h
  235. delay 8259,I-O
  236. or al,code
  237. out 02h,al
  238. jmp $+2
  239. sti
  240. endm
  241. unmask macro code
  242. cli ; mask timer int
  243. in al,02h
  244. delay 8259,I-O
  245. and al,not code
  246. out 02h,al
  247. jmp $+2
  248. sti
  249. endm
  250. ; DELAY MACRO FOR 80386
  251. ; This macro is defined in SYSMAC.INC(V23 ROM BIOS) <880203 ver2.1
  252. ;
  253. DELAY MACRO DEV,ACT,MOD
  254. IFIDN <DEV>,<8237>
  255. IFIDN <ACT>,<O-O>
  256. JMP SHORT $+2
  257. ENDIF
  258. IFIDN <ACT>,<O-I>
  259. JMP SHORT $+2
  260. ENDIF
  261. IFIDN <ACT>,<>
  262. JMP SHORT $+2
  263. ENDIF
  264. ENDIF
  265. IFIDN <DEV>,<8253>
  266. IFIDN <ACT>,<O-O>
  267. REPT 2
  268. JMP SHORT $+2
  269. ENDM
  270. ENDIF
  271. IFIDN <ACT>,<I-I>
  272. JMP SHORT $+2
  273. ENDIF
  274. IFIDN <ACT>,<O-I>
  275. REPT 2
  276. JMP SHORT $+2
  277. ENDM
  278. ENDIF
  279. IFIDN <ACT>,<I-O>
  280. JMP SHORT $+2
  281. ENDIF
  282. IFIDN <ACT>,<>
  283. REPT 2
  284. JMP SHORT $+2
  285. ENDM
  286. ENDIF
  287. ENDIF
  288. IFIDN <DEV>,<8255>
  289. IFIDN <ACT>,<O-O>
  290. REPT 2
  291. JMP SHORT $+2
  292. ENDM
  293. ENDIF
  294. IFIDN <ACT>,<I-I>
  295. JMP SHORT $+2
  296. ENDIF
  297. IFIDN <ACT>,<O-I>
  298. REPT 2
  299. JMP SHORT $+2
  300. ENDM
  301. ENDIF
  302. IFIDN <ACT>,<I-O>
  303. JMP SHORT $+2
  304. ENDIF
  305. IFIDN <ACT>,<>
  306. REPT 2
  307. JMP SHORT $+2
  308. ENDM
  309. ENDIF
  310. ENDIF
  311. IFIDN <DEV>,<8259>
  312. IFIDN <ACT>,<O-O>
  313. JMP SHORT $+2
  314. ENDIF
  315. IFIDN <ACT>,<I-I>
  316. ENDIF
  317. IFIDN <ACT>,<O-I>
  318. JMP SHORT $+2
  319. ENDIF
  320. IFIDN <ACT>,<I-O>
  321. ENDIF
  322. IFIDN <ACT>,<>
  323. JMP SHORT $+2
  324. ENDIF
  325. ENDIF
  326. IFIDN <DEV>,<8251>
  327. IFIDN <ACT>,<O-O>
  328. IFIDN <MOD>,<INIT>
  329. REPT 4
  330. JMP SHORT $+2
  331. ENDM
  332. ENDIF
  333. IFIDN <MOD>,<ASYNC>
  334. REPT 5
  335. JMP SHORT $+2
  336. ENDM
  337. ENDIF
  338. IFIDN <MOD>,<SYNC>
  339. REPT 10
  340. JMP SHORT $+2
  341. ENDM
  342. ENDIF
  343. ENDIF
  344. ENDIF
  345. IFIDN <DEV>,<765>
  346. ENDIF
  347. IFIDN <DEV>,<7220>
  348. IFIDN <ACT>,<O-O>
  349. IFIDN <MOD>,<GRAPH>
  350. REPT 4
  351. JMP SHORT $+2
  352. ENDM
  353. ENDIF
  354. IFIDN <MOD>,<TEXT>
  355. REPT 2
  356. JMP SHORT $+2
  357. ENDM
  358. ENDIF
  359. ENDIF
  360. IFIDN <ACT>,<I-I>
  361. IFIDN <MOD>,<GRAPH>
  362. REPT 3
  363. JMP SHORT $+2
  364. ENDM
  365. ENDIF
  366. IFIDN <MOD>,<TEXT>
  367. JMP SHORT $+2
  368. ENDIF
  369. ENDIF
  370. IFIDN <ACT>,<O-I>
  371. IFIDN <MOD>,<GRAPH>
  372. REPT 4
  373. JMP SHORT $+2
  374. ENDM
  375. ENDIF
  376. IFIDN <MOD>,<TEXT>
  377. REPT 2
  378. JMP SHORT $+2
  379. ENDM
  380. ENDIF
  381. ENDIF
  382. IFIDN <ACT>,<I-O>
  383. IFIDN <MOD>,<GRAPH>
  384. REPT 3
  385. JMP SHORT $+2
  386. ENDM
  387. ENDIF
  388. IFIDN <MOD>,<TEXT>
  389. JMP SHORT $+2
  390. ENDIF
  391. ENDIF
  392. ENDIF
  393. IFIDN <DEV>,<7201>
  394. IFIDN <ACT>,<O-O>
  395. JMP SHORT $+2
  396. ENDIF
  397. IFIDN <ACT>,<O-I>
  398. JMP SHORT $+2
  399. ENDIF
  400. ENDIF
  401. IFIDN <DEV>,<7210>
  402. IFIDN <ACT>,<O-O>
  403. JMP SHORT $+2
  404. ENDIF
  405. IFIDN <ACT>,<O-I>
  406. JMP SHORT $+2
  407. ENDIF
  408. ENDIF
  409. IFIDN <DEV>,<4990>
  410. REPT 3
  411. JMP SHORT $+2
  412. ENDM
  413. ENDIF
  414. ENDM
  415. endif ; NEC_98