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.

323 lines
8.1 KiB

  1. title "Processor State Save Restore"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; procstat.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements procedures for saving and restoring
  13. ; processor control state, and processor run&control state.
  14. ; These procedures support debugging of UP and MP systems.
  15. ;
  16. ; Author:
  17. ;
  18. ; Shie-Lin Tzong (shielint) 30-Aug-1990
  19. ;
  20. ; Environment:
  21. ;
  22. ; Kernel mode only.
  23. ;
  24. ; Revision History:
  25. ;
  26. ;--
  27. .386p
  28. .xlist
  29. include ks386.inc
  30. include i386\kimacro.inc
  31. include callconv.inc
  32. .list
  33. EXTRNP _KeContextToKframes,5
  34. EXTRNP _KeContextFromKframes,3
  35. extrn _KeFeatureBits:DWORD
  36. page ,132
  37. _TEXT SEGMENT DWORD PUBLIC 'CODE'
  38. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  39. subttl "Save Processor State"
  40. ;++
  41. ;
  42. ; KiSaveProcessorState(
  43. ; PKTRAP_FRAME TrapFrame,
  44. ; PKEXCEPTION_FRAME ExceptionFrame
  45. ; );
  46. ;
  47. ; Routine Description:
  48. ;
  49. ; This routine saves the processor state for debugger. When the current
  50. ; processor receives the request of IPI_FREEZE, it saves all the registers
  51. ; in a save area in the PRCB so the debugger can get access to them.
  52. ;
  53. ; Arguments:
  54. ;
  55. ; TrapFrame (esp+4) - Pointer to machine trap frame
  56. ;
  57. ; ExceptionFrame (esp+8) - Pointer to exception frame
  58. ; (IGNORED on the x86!)
  59. ;
  60. ; Return Value:
  61. ;
  62. ; None.
  63. ;
  64. ;--
  65. cPublicProc _KiSaveProcessorState ,2
  66. mov eax, [esp+4] ; (eax) -> TrapFrame
  67. mov edx, PCR[PcPrcb] ; (edx)->PrcbData
  68. add edx, PbProcessorState ; (edx)->ProcessorState
  69. push edx
  70. ;
  71. ; Copy the whole TrapFrame to our ProcessorState
  72. ;
  73. lea ecx, [edx].PsContextFrame
  74. mov dword ptr [ecx].CsContextFlags, CONTEXT_FULL OR CONTEXT_DEBUG_REGISTERS
  75. ; ecx - ContextFrame
  76. ; 0 - ExceptionFrame == NULL
  77. ; eax - TrapFrame
  78. stdCall _KeContextFromKframes, <eax, 0, ecx>
  79. ;
  80. ; Save special registers for debugger
  81. ;
  82. ; TOS = PKPROCESSOR_STATE
  83. call _KiSaveProcessorControlState@4
  84. stdRET _KiSaveProcessorState
  85. stdENDP _KiSaveProcessorState
  86. page ,132
  87. subttl "Save Processor Control State"
  88. ;++
  89. ;
  90. ; KiSaveProcessorControlState(
  91. ; PKPROCESSOR_STATE ProcessorState
  92. ; );
  93. ;
  94. ; Routine Description:
  95. ;
  96. ; This routine saves the control subset of the processor state.
  97. ; (Saves the same information as KiSaveProcessorState EXCEPT that
  98. ; data in TrapFrame/ExceptionFrame=Context record is NOT saved.)
  99. ; Called by the debug subsystem, and KiSaveProcessorState()
  100. ;
  101. ; N.B. This procedure will save Dr7, and then 0 it. This prevents
  102. ; recursive hardware trace breakpoints and allows debuggers
  103. ; to work.
  104. ;
  105. ; Arguments:
  106. ;
  107. ; Return Value:
  108. ;
  109. ; None.
  110. ;
  111. ;--
  112. cPublicProc _KiSaveProcessorControlState ,1
  113. mov edx, [esp+4] ; ProcessorState
  114. ;
  115. ; Save special registers for debugger
  116. ;
  117. xor ecx,ecx
  118. mov eax, cr0
  119. mov [edx].PsSpecialRegisters.SrCr0, eax
  120. mov eax, cr2
  121. mov [edx].PsSpecialRegisters.SrCr2, eax
  122. mov eax, cr3
  123. mov [edx].PsSpecialRegisters.SrCr3, eax
  124. mov [edx].PsSpecialRegisters.SrCr4, ecx
  125. test _KeFeatureBits, KF_CR4
  126. jz short @f
  127. .586p
  128. mov eax, cr4
  129. mov [edx].PsSpecialRegisters.SrCr4, eax
  130. .486p
  131. @@:
  132. mov eax,dr0
  133. mov [edx].PsSpecialRegisters.SrKernelDr0,eax
  134. mov eax,dr1
  135. mov [edx].PsSpecialRegisters.SrKernelDr1,eax
  136. mov eax,dr2
  137. mov [edx].PsSpecialRegisters.SrKernelDr2,eax
  138. mov eax,dr3
  139. mov [edx].PsSpecialRegisters.SrKernelDr3,eax
  140. mov eax,dr6
  141. mov [edx].PsSpecialRegisters.SrKernelDr6,eax
  142. mov eax,dr7
  143. mov dr7,ecx
  144. mov [edx].PsSpecialRegisters.SrKernelDr7,eax
  145. sgdt fword ptr [edx].PsSpecialRegisters.SrGdtr
  146. sidt fword ptr [edx].PsSpecialRegisters.SrIdtr
  147. str word ptr [edx].PsSpecialRegisters.SrTr
  148. sldt word ptr [edx].PsSpecialRegisters.SrLdtr
  149. stdRET _KiSaveProcessorControlState
  150. stdENDP _KiSaveProcessorControlState
  151. page ,132
  152. subttl "Restore Processor State"
  153. ;++
  154. ;
  155. ; KiRestoreProcessorState(
  156. ; PKTRAP_FRAME TrapFrame,
  157. ; PKEXCEPTION_FRAME ExceptionFrame
  158. ; );
  159. ;
  160. ; Routine Description:
  161. ;
  162. ; This routine Restores the processor state for debugger. When the
  163. ; control returns from debugger (UnFreezeExecution), this function
  164. ; restores the entire processor state.
  165. ;
  166. ; Arguments:
  167. ;
  168. ; TrapFrame (esp+4) - Pointer to machine trap frame
  169. ;
  170. ; ExceptionFrame (esp+8) - Pointer to exception frame
  171. ; (IGNORED on the x86!)
  172. ;
  173. ; Return Value:
  174. ;
  175. ; None.
  176. ;
  177. ;--
  178. cPublicProc _KiRestoreProcessorState ,2
  179. mov eax, [esp+4] ; (eax) -> TrapFrame
  180. mov edx, PCR[PcPrcb] ; (edx)->PrcbData
  181. add edx, PbProcessorState ; (edx)->ProcessorState
  182. push edx
  183. ;
  184. ; Copy the whole ContextFrame to TrapFrame
  185. ;
  186. lea ecx, [edx].PsContextFrame
  187. mov edx, [edx].PsContextFrame.CsSegCs
  188. and edx, MODE_MASK
  189. ; edx - Previous mode
  190. ; ecx - ContextFrame
  191. ; 0 - ExceptionFrame == NULL
  192. ; eax - TrapFrame
  193. stdCall _KeContextToKframes, <eax,0,ecx,[ecx].CsContextFlags,edx>
  194. ;
  195. ; Save special registers for debugger
  196. ;
  197. ; TOS = KPROCESSOR_STATE
  198. call _KiRestoreProcessorControlState@4
  199. stdRET _KiRestoreProcessorState
  200. stdENDP _KiRestoreProcessorState
  201. page ,132
  202. subttl "Restore Processor Control State"
  203. ;++
  204. ;
  205. ; KiRestoreProcessorControlState(
  206. ; );
  207. ;
  208. ; Routine Description:
  209. ;
  210. ; This routine restores the control subset of the processor state.
  211. ; (Restores the same information as KiRestoreProcessorState EXCEPT that
  212. ; data in TrapFrame/ExceptionFrame=Context record is NOT restored.)
  213. ; Called by the debug subsystem, and KiRestoreProcessorState()
  214. ;
  215. ; Arguments:
  216. ;
  217. ; Return Value:
  218. ;
  219. ; None.
  220. ;
  221. ;--
  222. cPublicProc _KiRestoreProcessorControlState,1
  223. mov edx, [esp+4] ; (edx)->ProcessorState
  224. ;
  225. ; Restore special registers for debugger
  226. ;
  227. mov eax, [edx].PsSpecialRegisters.SrCr0
  228. mov cr0, eax
  229. mov eax, [edx].PsSpecialRegisters.SrCr2
  230. mov cr2, eax
  231. mov eax, [edx].PsSpecialRegisters.SrCr3
  232. mov cr3, eax
  233. test _KeFeatureBits, KF_CR4
  234. jz short @f
  235. .586p
  236. mov eax, [edx].PsSpecialRegisters.SrCr4
  237. mov cr4, eax
  238. .486p
  239. @@:
  240. mov eax, [edx].PsSpecialRegisters.SrKernelDr0
  241. mov dr0, eax
  242. mov eax, [edx].PsSpecialRegisters.SrKernelDr1
  243. mov dr1, eax
  244. mov eax, [edx].PsSpecialRegisters.SrKernelDr2
  245. mov dr2, eax
  246. mov eax, [edx].PsSpecialRegisters.SrKernelDr3
  247. mov dr3, eax
  248. mov eax, [edx].PsSpecialRegisters.SrKernelDr6
  249. mov dr6, eax
  250. mov eax, [edx].PsSpecialRegisters.SrKernelDr7
  251. mov dr7, eax
  252. lgdt fword ptr [edx].PsSpecialRegisters.SrGdtr
  253. lidt fword ptr [edx].PsSpecialRegisters.SrIdtr
  254. ;
  255. ; Force the TSS descriptor into a non-busy state, so we don't fault
  256. ; when we load the TR.
  257. ;
  258. mov eax, [edx].PsSpecialRegisters.SrGdtr+2 ; (eax)->GDT base
  259. xor ecx, ecx
  260. mov cx, word ptr [edx].PsSpecialRegisters.SrTr
  261. add eax, 5
  262. add eax, ecx ; (eax)->TSS Desc. Byte
  263. and byte ptr [eax],NOT 2
  264. ltr word ptr [edx].PsSpecialRegisters.SrTr
  265. lldt word ptr [edx].PsSpecialRegisters.SrLdtr
  266. stdRET _KiRestoreProcessorControlState
  267. stdENDP _KiRestoreProcessorControlState
  268. _TEXT ENDS
  269. END