ktimer5.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:4k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. ;*
  2. ;* COW : Character Oriented Windows
  3. ;*
  4. ;* ktimer5.asm : DOS 5 kernel timer (for ticks)
  5. include kernel.inc
  6. IFNDEF DOS5
  7. .error -- only DOS 5
  8. ENDIF
  9. sBegin DATA
  10.     assumes DS,DGROUP
  11. externDP pwndAlarm ;* != NULL if alarm set
  12. externD  semaMessage ;* message semaphore
  13. labelD dmsKick ;* time to sleep
  14. staticW OFF_dmsKick,-1
  15. staticW SEG_dmsKick,-1
  16. sEnd DATA
  17. sBegin BSS
  18.     assumes DS,DGROUP
  19. staticD semaTimer, 0 ;* timer semaphore
  20. staticW idThread, 0 ;* id of timer thread
  21. staticB fTimerLive, 0 ;* TRUE => timer alive
  22. ;* * stack
  23. DB 64 DUP (?)
  24. labelB wStackMax
  25. sEnd BSS
  26. ;*****************************************************************************
  27. ;* * DOS 5 calls
  28. externFP  <DosCreateThread, DosSemClear, DosSemSetWait, DosSemClear, DosExit>
  29. ;*****************************************************************************
  30. sBegin KERNEL
  31.     assumes CS,KERNEL
  32.     assumes SS,NOTHING
  33.     assumes DS,NOTHING ;* interrupt handler may be called from anywhere
  34. ;********* TimerThread **********
  35. ;* entry : semaEvent and semaTimer valid
  36. ;* * THREAD for processing timer
  37. ;* exit : n/a (dies when killed)
  38. labelFP TimerThread
  39.     assumes DS,DATA
  40. ;* * when timer semaphore gets cleared, clear the message semaphore
  41. ;* * (this thread is necessary since we want 1 semaphore for all
  42. ;* *  input events).
  43. test fTimerLive,-1
  44. jz TimerDies
  45. PushArg <ds, <dataOffset semaTimer>> ;* hsemaTimer
  46. PushArg <SEG_dmsKick, OFF_dmsKick> ;* wait time
  47. cCall DosSemSetWait
  48. ;* * timer has elapsed, clear message semaphore
  49. PushArg <ds, <dataOffset semaMessage>>
  50. cCall DosSemClear
  51. jmp TimerThread ;* forever
  52. TimerDies:
  53. xor ax,ax
  54. cCall DosExit, <ax, ax> ;* kill this thread
  55. ;* * NOTREACHED
  56. ;********** KickTimer **********
  57. ;* entry : dms = time in ms to kick timer
  58. ;* *
  59. cPrivate KickTimer, <>
  60.     parmD dms
  61. cBegin KickTimer
  62. mov ax,OFF_dms
  63. mov dx,SEG_dms
  64. mov OFF_dmsKick,ax
  65. mov SEG_dmsKick,dx
  66. ;* * now kick the timer to install the new time
  67. PushArg <ds, <dataOffset semaTimer>> ;* hsemaTimer
  68. cCall DosSemClear
  69. cEnd KickTimer
  70. sEnd KERNEL
  71. ;*****************************************************************************
  72. sBegin INIT
  73.     assumes CS,INIT
  74.     assumes DS,DGROUP
  75.     assumes SS,DGROUP
  76. ;********** InitSysTimer **********
  77. ;* entry : n/a
  78. ;* * Called to initialize the timer routine
  79. ;* exit : ax != 0 => ok
  80. cProc FInitSysTimer,<FAR,PUBLIC,ATOMIC>
  81. cBegin FInitSysTimer
  82. ;* * create the timer thread
  83. mov ax,-1
  84. mov OFF_dmsKick,ax
  85. mov SEG_dmsKick,ax ;* longest time to sleep
  86. mov fTimerLive,al
  87. IFNDEF COW_SWAPPED
  88. mov dx,cs
  89. ELSE
  90. mov dx,SEG kernelBase
  91. ENDIF
  92. mov ax,kernelOffset TimerThread
  93. PushArg <dx, ax>
  94. PushArg <ds, <dataOffset idThread>>
  95. PushArg <ss, <dataOffset wStackMax>>
  96. cCall DosCreateThread
  97. or ax,ax
  98. jnz init_timer_error
  99. ExitTrueUnless init_timer_error
  100. cEnd FInitSysTimer
  101. sEnd INIT
  102. ;*****************************************************************************
  103. sBegin EXIT
  104.     assumes CS,EXIT
  105.     assumes SS,DATA
  106.     assumes DS,DATA
  107. ;********** EndSysTimer **********
  108. ;* entry : n/a
  109. ;* * Unhook the timer interrupt
  110. ;* exit : n/a
  111. cProc EndSysTimer,<FAR,PUBLIC,ATOMIC>
  112. cBegin EndSysTimer
  113. ;* * kill thread
  114. mov fTimerLive,0
  115. ;* * kick the thread (timer semaphore) so the thread dies
  116. PushArg <ds, <dataOffset semaTimer>> ;* hsemaTimer
  117. cCall DosSemClear
  118. cEnd EndSysTimer
  119. sEnd EXIT
  120. ;*****************************************************************************
  121. END