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.

215 lines
5.5 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. xor eax, eax ; restore debug registers
  53. mov dr7, rax ;
  54. mov rax, PsKernelDr0[rcx] ;
  55. mov dr0, rax ;
  56. mov rax, PsKernelDr1[rcx] ;
  57. mov dr1, rax ;
  58. mov rax, PsKernelDr2[rcx] ;
  59. mov dr2, rax ;
  60. mov rax, PsKernelDr3[rcx] ;
  61. mov dr3, rax ;
  62. xor edx, edx ;
  63. mov dr6, rdx ;
  64. mov rax, PsKernelDr7[rcx] ;
  65. mov dr7, rax ;
  66. lgdt fword ptr PsGdtr[rcx] ; restore GDTR
  67. lidt fword ptr PsIdtr[rcx] ; restore IDTR
  68. ;
  69. ; Force the TSS descriptor into a non-busy state, so we don't fault
  70. ; when we load the TR.
  71. ;
  72. movzx eax, word ptr PsTr[rcx] ; rax == TSS selector
  73. add rax, PsGdtr[rcx]+2 ; rax -> TSS GDT entry
  74. and byte ptr [rax]+5, NOT 2 ; Busy bit clear
  75. ltr word ptr PsTr[rcx] ; restore TR
  76. sub eax, eax ; load a NULL selector into the ldt
  77. lldt ax
  78. ldmxcsr dword ptr PsMxCsr[rcx] ; restore XMM control/status
  79. ret ; return
  80. LEAF_END KiRestoreProcessorControlState, _TEXT$00
  81. subttl "Save Processor Control State"
  82. ;++
  83. ;
  84. ; KiSaveProcessorControlState(
  85. ; PKPROCESSOR_STATE ProcessorState
  86. ; );
  87. ;
  88. ; Routine Description:
  89. ;
  90. ; This routine saves the control state of the current processor.
  91. ;
  92. ; Arguments:
  93. ;
  94. ; ProcessorState (rcx) - Supplies a pointer to a processor state structure.
  95. ;
  96. ; Return Value:
  97. ;
  98. ; None.
  99. ;
  100. ;--
  101. LEAF_ENTRY KiSaveProcessorControlState, _TEXT$00
  102. mov rax, cr0 ; save processor control state
  103. mov PsCr0[rcx], rax ;
  104. mov rax, cr2 ;
  105. mov PsCr2[rcx], rax ;
  106. mov rax, cr3 ;
  107. mov PsCr3[rcx], rax ;
  108. mov rax, cr4 ;
  109. mov PsCr4[rcx], rax ;
  110. mov rax, dr0 ; save debug registers
  111. mov PsKernelDr0[rcx], rax ;
  112. mov rax, dr1 ;
  113. mov PsKernelDr1[rcx], rax ;
  114. mov rax, dr2 ;
  115. mov PsKernelDr2[rcx], rax ;
  116. mov rax, dr3 ;
  117. mov PsKernelDr3[rcx], rax ;
  118. mov rax, dr6 ;
  119. mov PsKernelDr6[rcx], rax ;
  120. mov rax, dr7 ;
  121. mov PsKernelDr7[rcx], rax ;
  122. xor eax, eax ;
  123. mov dr7, rax ;
  124. sgdt fword ptr PsGdtr[rcx] ; save GDTR
  125. sidt fword ptr PsIdtr[rcx] ; save IDTR
  126. str word ptr PsTr[rcx] ; save TR
  127. sldt word ptr PsLdtr[rcx] ; save LDTR
  128. stmxcsr dword ptr PsMxCsr[rcx] ; save XMM control/status
  129. ret ; return
  130. LEAF_END KiSaveProcessorControlState, _TEXT$00
  131. subttl "Restore Floating Point State"
  132. ;++
  133. ;
  134. ; NTSTATUS
  135. ; KiRestoreFloatingPointState(
  136. ; PKFLOATING_STATE SaveArea
  137. ; );
  138. ;
  139. ; Routine Description:
  140. ;
  141. ; This routine restore the floating status and control information from
  142. ; the specified save area.
  143. ;
  144. ; Arguments:
  145. ;
  146. ; SaveArea (rcx) - Supplies a pointer to a floating state save area.
  147. ;
  148. ; Return Value:
  149. ;
  150. ; STATUS_SUCCESS.
  151. ;
  152. ;--
  153. LEAF_ENTRY KeRestoreFloatingPointState, _TEXT$00
  154. ldmxcsr FsMxCsr[rcx] ; restore floating status/control
  155. xor eax, eax ; set success status
  156. ret ; return
  157. LEAF_END KeRestoreFloatingPointState, _TEXT$00
  158. subttl "Save Floating Point State"
  159. ;++
  160. ;
  161. ; NTSTATUS
  162. ; KisaveFloatingPointState(
  163. ; PKFLOATING_STATE SaveArea
  164. ; );
  165. ;
  166. ; Routine Description:
  167. ;
  168. ; This routine saves the floating status and control information in the
  169. ; specified save area and sets the control information to the system
  170. ; defautl value.
  171. ;
  172. ; Arguments:
  173. ;
  174. ; SaveArea (rcx) - Supplies a pointer to a floating state save area.
  175. ;
  176. ; Return Value:
  177. ;
  178. ; STATUS_SUCCESS.
  179. ;
  180. ;--
  181. LEAF_ENTRY KeSaveFloatingPointState, _TEXT$00
  182. stmxcsr FsMxCsr[rcx] ; save floating status/control
  183. ldmxcsr dword ptr gs:[PcMxCsr] ; set default XMM control/status
  184. xor eax, eax ; set success status
  185. ret ;
  186. LEAF_END KeSaveFloatingPointState, _TEXT$00
  187. end