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.

282 lines
7.4 KiB

  1. title "Processor State Save Restore"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; procstat.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements routines to save and restore processor control
  13. ; state.
  14. ;
  15. ; Author:
  16. ;
  17. ; David N. Cutler (davec) 24-Aug-2000
  18. ;
  19. ; Environment:
  20. ;
  21. ; Kernel mode only.
  22. ;
  23. ;--
  24. include ksamd64.inc
  25. subttl "Restore Processor Control State"
  26. ;++
  27. ;
  28. ; KiRestoreProcessorControlState (
  29. ; VOID
  30. ; );
  31. ;
  32. ; Routine Description:
  33. ;
  34. ; This routine restores the control state of the current processor.
  35. ;
  36. ; Arguments:
  37. ;
  38. ; ProcessorState (rcx) - Supplies a pointer to a processor state structure.
  39. ;
  40. ; Return Value:
  41. ;
  42. ; None.
  43. ;
  44. ;--
  45. LEAF_ENTRY KiRestoreProcessorControlState, _TEXT$00
  46. mov rax, PsCr0[rcx] ; restore processor control registers
  47. mov cr0, rax ;
  48. mov rax, PsCr3[rcx] ;
  49. mov cr3, rax ;
  50. mov rax, PsCr4[rcx] ;
  51. mov cr4, rax ;
  52. mov rax, PsCr8[rcx] ;
  53. mov cr8, rax ;
  54. xor eax, eax ; restore debug registers
  55. mov dr7, rax ;
  56. mov rax, PsKernelDr0[rcx] ;
  57. mov dr0, rax ;
  58. mov rax, PsKernelDr1[rcx] ;
  59. mov dr1, rax ;
  60. mov rax, PsKernelDr2[rcx] ;
  61. mov dr2, rax ;
  62. mov rax, PsKernelDr3[rcx] ;
  63. mov dr3, rax ;
  64. xor edx, edx ;
  65. mov dr6, rdx ;
  66. mov rax, PsKernelDr7[rcx] ;
  67. mov dr7, rax ;
  68. lgdt fword ptr PsGdtr[rcx] ; restore GDTR
  69. lidt fword ptr PsIdtr[rcx] ; restore IDTR
  70. ;
  71. ; Force the TSS descriptor into a non-busy state, so we don't fault
  72. ; when we load the TR.
  73. ;
  74. movzx eax, word ptr PsTr[rcx] ; rax == TSS selector
  75. add rax, PsGdtr[rcx]+2 ; rax -> TSS GDT entry
  76. and byte ptr [rax]+5, NOT 2 ; Busy bit clear
  77. ltr word ptr PsTr[rcx] ; restore TR
  78. sub eax, eax ; load a NULL selector into the ldt
  79. lldt ax
  80. ldmxcsr dword ptr PsMxCsr[rcx] ; restore XMM control/status
  81. ret ; return
  82. LEAF_END KiRestoreProcessorControlState, _TEXT$00
  83. subttl "Save Processor Control State"
  84. ;++
  85. ;
  86. ; KiSaveProcessorControlState (
  87. ; PKPROCESSOR_STATE ProcessorState
  88. ; );
  89. ;
  90. ; Routine Description:
  91. ;
  92. ; This routine saves the control state of the current processor.
  93. ;
  94. ; Arguments:
  95. ;
  96. ; ProcessorState (rcx) - Supplies a pointer to a processor state structure.
  97. ;
  98. ; Return Value:
  99. ;
  100. ; None.
  101. ;
  102. ;--
  103. LEAF_ENTRY KiSaveProcessorControlState, _TEXT$00
  104. mov rax, cr0 ; save processor control state
  105. mov PsCr0[rcx], rax ;
  106. mov rax, cr2 ;
  107. mov PsCr2[rcx], rax ;
  108. mov rax, cr3 ;
  109. mov PsCr3[rcx], rax ;
  110. mov rax, cr4 ;
  111. mov PsCr4[rcx], rax ;
  112. mov rax, cr8 ;
  113. mov PsCr8[rcx], rax ;
  114. mov rax, dr0 ; save debug registers
  115. mov PsKernelDr0[rcx], rax ;
  116. mov rax, dr1 ;
  117. mov PsKernelDr1[rcx], rax ;
  118. mov rax, dr2 ;
  119. mov PsKernelDr2[rcx], rax ;
  120. mov rax, dr3 ;
  121. mov PsKernelDr3[rcx], rax ;
  122. mov rax, dr6 ;
  123. mov PsKernelDr6[rcx], rax ;
  124. mov rax, dr7 ;
  125. mov PsKernelDr7[rcx], rax ;
  126. xor eax, eax ;
  127. mov dr7, rax ;
  128. sgdt fword ptr PsGdtr[rcx] ; save GDTR
  129. sidt fword ptr PsIdtr[rcx] ; save IDTR
  130. str word ptr PsTr[rcx] ; save TR
  131. sldt word ptr PsLdtr[rcx] ; save LDTR
  132. stmxcsr dword ptr PsMxCsr[rcx] ; save XMM control/status
  133. ret ; return
  134. LEAF_END KiSaveProcessorControlState, _TEXT$00
  135. subttl "Restore Floating Point State"
  136. ;++
  137. ;
  138. ; NTSTATUS
  139. ; KeRestoreFloatingPointState (
  140. ; PKFLOATING_STATE SaveArea
  141. ; );
  142. ;
  143. ; Routine Description:
  144. ;
  145. ; This routine restore the floating status and control information from
  146. ; the specified save area.
  147. ;
  148. ; Arguments:
  149. ;
  150. ; SaveArea (rcx) - Supplies a pointer to a floating state save area.
  151. ;
  152. ; Return Value:
  153. ;
  154. ; STATUS_SUCCESS.
  155. ;
  156. ;--
  157. LEAF_ENTRY KeRestoreFloatingPointState, _TEXT$00
  158. ldmxcsr FsMxCsr[rcx] ; restore floating status/control
  159. xor eax, eax ; set success status
  160. ret ; return
  161. LEAF_END KeRestoreFloatingPointState, _TEXT$00
  162. subttl "Save Floating Point State"
  163. ;++
  164. ;
  165. ; NTSTATUS
  166. ; KeSaveFloatingPointState (
  167. ; PKFLOATING_STATE SaveArea
  168. ; );
  169. ;
  170. ; Routine Description:
  171. ;
  172. ; This routine saves the floating status and control information in the
  173. ; specified save area and sets the control information to the system
  174. ; defautl value.
  175. ;
  176. ; Arguments:
  177. ;
  178. ; SaveArea (rcx) - Supplies a pointer to a floating state save area.
  179. ;
  180. ; Return Value:
  181. ;
  182. ; STATUS_SUCCESS.
  183. ;
  184. ;--
  185. LEAF_ENTRY KeSaveFloatingPointState, _TEXT$00
  186. stmxcsr FsMxCsr[rcx] ; save floating status/control
  187. ldmxcsr dword ptr gs:[PcMxCsr] ; set default XMM control/status
  188. xor eax, eax ; set success status
  189. ret ;
  190. LEAF_END KeSaveFloatingPointState, _TEXT$00
  191. subttl "Restore Legacy Floating Point State"
  192. ;++
  193. ;
  194. ; VOID
  195. ; KeRestoreLegacyFloatingPointState (
  196. ; PLEGACY_SAVE_AREA NpxFrame
  197. ; );
  198. ;
  199. ; Routine Description:
  200. ;
  201. ; This routine restores the legacy floating point state for the current
  202. ; thread.
  203. ;
  204. ; Arguments:
  205. ;
  206. ; NpxFrame (rcx) - Supplies the address of the legacy floating save area.
  207. ;
  208. ; Return Value:
  209. ;
  210. ; None.
  211. ;
  212. ;--
  213. LEAF_ENTRY KeRestoreLegacyFloatingPointState, _TEXT$00
  214. mov ax, LfControlWord[rcx] ; save current control word
  215. mov word ptr LfControlWord[rcx], 03fh ; set to mask all exceptions
  216. frstord [rcx] ; restore legacy floating state
  217. mov LfControlWord[rcx], ax ; restore control word
  218. fldcw word ptr LfControlWord[rcx] ; load legacy control word
  219. ret ; return
  220. LEAF_END KeRestoreLegacyFloatingPointState, _TEXT$00
  221. subttl "Save Legacy Floating Point State"
  222. ;++
  223. ;
  224. ; VOID
  225. ; KeSaveLegacyFloatingPointState (
  226. ; PLEGACY_SAVE_AREA NpxFrame
  227. ; );
  228. ;
  229. ; Routine Description:
  230. ;
  231. ; This routine saves the legacy floating state for the current thread.
  232. ;
  233. ; Arguments:
  234. ;
  235. ; NpxFrame (rcx) - Supplies the address of the legacy floating save area.
  236. ;
  237. ; Return Value:
  238. ;
  239. ; None.
  240. ;
  241. ;--
  242. LEAF_ENTRY KeSaveLegacyFloatingPointState, _TEXT$00
  243. fnsaved [rcx] ; save legacy floating state
  244. ret ;
  245. LEAF_END KeSaveLegacyFloatingPointState, _TEXT$00
  246. end