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.

247 lines
8.5 KiB

  1. title "Miscellaneous Functions"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; miscs.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements machine dependent miscellaneous kernel functions.
  13. ;
  14. ; Author:
  15. ;
  16. ; David N. Cutler (davec) 8-Aug-2000
  17. ;
  18. ; Environment:
  19. ;
  20. ; Kernel mode only.
  21. ;
  22. ;--
  23. include ksamd64.inc
  24. extern KeTestAlertThread:proc
  25. extern KiContinue:proc
  26. extern KiExceptionExit:proc
  27. extern KiRaiseException:proc
  28. subttl "Continue Execution System Service"
  29. ;++
  30. ;
  31. ; NTSTATUS
  32. ; NtContinue (
  33. ; IN PCONTEXT ContextRecord,
  34. ; IN BOOLEAN TestAlert
  35. ; )
  36. ;
  37. ; Routine Description:
  38. ;
  39. ; This routine is called as a system service to continue execution after
  40. ; an exception has occurred. Its function is to transfer information from
  41. ; the specified context record into the trap frame that was built when the
  42. ; system service was executed, and then exit the system as if an exception
  43. ; had occurred.
  44. ;
  45. ; Arguments:
  46. ;
  47. ; ContextRecord (rcx) - Supplies a pointer to a context record.
  48. ;
  49. ; TestAlert (dl) - Supplies a boolean value that specifies whether alert
  50. ; should be tested for the previous processor mode.
  51. ;
  52. ; Implicit Arguments:
  53. ;
  54. ; rbp - Supplies the address of a trap frame.
  55. ;
  56. ; Return Value:
  57. ;
  58. ; Normally there is no return from this routine. However, if the specified
  59. ; context record is misaligned or is not accessible, then the appropriate
  60. ; status code is returned.
  61. ;
  62. ;--
  63. NESTED_ENTRY NtContinue, _TEXT$00
  64. GENERATE_EXCEPTION_FRAME ; generate exception frame
  65. ;
  66. ; Transfer information from the context frame to the exception and trap frames.
  67. ;
  68. mov rbx, gs:[PcCurrentThread] ; get current thread address
  69. cmp byte ptr ThNpxState[rbx],LEGACY_STATE_SWITCH ; check if switched
  70. jne short KiCO10 ; if ne, legacy state not switched
  71. ;
  72. ; N.B. The legacy floating point state must be saved and restored since saving
  73. ; the state initializes some of the state.
  74. ;
  75. ; N.B. Interrupts must also be disabled during this sequence to ensure that a
  76. ; get context APC interrupt does not occur.
  77. ;
  78. lea rsi, (KTRAP_FRAME_LENGTH - 128)[rbp] ; get legacy save address
  79. cli ; disable interrupts
  80. fnsaved [rsi] ; save legacy floating state
  81. mov di, LfControlWord[rsi] ; save current control word
  82. mov word ptr LfControlWord[rsi], 03fh ; set to mask all exceptions
  83. frstord [rsi] ; restore legacy floating point state
  84. mov LfControlWord[rsi], di ; restore control word
  85. fldcw word ptr LfControlWord[rsi] ; load legacy control word
  86. sti ; enable interrupt
  87. KiCO10: mov dil, dl ; save test alert argument
  88. mov rdx, rsp ; set exception frame address
  89. lea r8, (-128)[rbp] ; set trap frame address
  90. call KiContinue ; transfer context to kernel frames
  91. ;
  92. ; If the kernel continuation routine returns success, then exit via the
  93. ; exception exit code. Otherwise, return to the system service dispatcher.
  94. ;
  95. test eax, eax ; test if service failed
  96. jnz short KiCO40 ; if nz, service failed
  97. ;
  98. ; Check to determine if alert should be tested for the previous processor
  99. ; mode and restore the previous mode in the thread object.
  100. ;
  101. mov r8, TrTrapFrame[rbp] ; set previous trap frame address
  102. mov ThTrapFrame[rbx], r8 ;
  103. mov cl, ThPreviousMode[rbx] ; get thread previous mode
  104. mov dl, TrPreviousMode[rbp] ; get frame previous mode
  105. mov ThPreviousMode[rbx], dl ; set thread previous mode
  106. test dil, dil ; test if test alert specified
  107. jz short KiCO20 ; if z, test alert not specified
  108. call KeTestAlertThread ; test alert for current thread
  109. ;
  110. ; If the legacy stated is switched, then restore the legacy floating state.
  111. ;
  112. KiCO20: cmp byte ptr ThNpxState[rbx],LEGACY_STATE_SWITCH ; check if switched
  113. jne short KiCO30 ; if ne, legacy state not switched
  114. mov di, LfControlWord[rsi] ; save current control word
  115. mov word ptr LfControlWord[rsi], 03fh ; set to mask all exceptions
  116. frstord [rsi] ; restore legacy floating state
  117. mov LfControlWord[rsi], di ; restore control word
  118. fldcw word ptr LfControlWord[rsi] ; load legacy control word
  119. KiCO30: jmp KiExceptionExit ;
  120. ;
  121. ; Context record is misaligned or not accessible.
  122. ;
  123. KiCO40: RESTORE_EXCEPTION_STATE ; restore exception state/deallocate
  124. ret ; return
  125. NESTED_END NtContinue, _TEXT$00
  126. subttl "Raise Exception System Service"
  127. ;++
  128. ;
  129. ; NTSTATUS
  130. ; NtRaiseException (
  131. ; IN PEXCEPTION_RECORD ExceptionRecord,
  132. ; IN PCONTEXT ContextRecord,
  133. ; IN BOOLEAN FirstChance
  134. ; )
  135. ;
  136. ; Routine Description:
  137. ;
  138. ; This routine is called as a system service to raise an exception. Its
  139. ; function is to transfer information from the specified context record
  140. ; into the trap frame that was built when the system service was executed.
  141. ; The exception may be raised as a first or second chance exception.
  142. ;
  143. ; Arguments:
  144. ;
  145. ; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
  146. ;
  147. ; ContextRecord (rdx) - Suppilies a pointer to a context record.
  148. ;
  149. ; FirstChance (r8b) - Supplies a boolean value that specifies whether
  150. ; this is the first (TRUE) or second chance (FALSE) for dispatching
  151. ; the exception.
  152. ;
  153. ; Implicit Arguments:
  154. ;
  155. ; rbp - Supplies a pointer to a trap frame.
  156. ;
  157. ; Return Value:
  158. ;
  159. ; Normally there is no return from this routine. However, if the specified
  160. ; context record or exception record is misaligned or is not accessible,
  161. ; then the appropriate status code is returned.
  162. ;
  163. ;--
  164. NESTED_ENTRY NtRaiseException, _TEXT$00
  165. GENERATE_EXCEPTION_FRAME ; generate exception frame
  166. ;
  167. ; Call the raise exception kernel routine which will marshall the arguments
  168. ; and then call the exception dispatcher.
  169. ;
  170. mov rbx, gs:[PcCurrentThread] ; get current thread address
  171. cmp byte ptr ThNpxState[rbx],LEGACY_STATE_SWITCH ; check if switched
  172. jne short KiRE10 ; if ne, legacy state not switched
  173. ;
  174. ; N.B. The legacy floating point state must be saved and restored since saving
  175. ; the state initializes some of the state.
  176. ;
  177. ; N.B. Interrupts must also be disabled during this sequence to ensure that a
  178. ; get context APC interrupt does not occur.
  179. ;
  180. lea rsi, (KTRAP_FRAME_LENGTH - 128)[rbp] ; get legacy save address
  181. cli ; disable interrupts
  182. fnsaved [rsi] ; save legacy floating state
  183. mov di, LfControlWord[rsi] ; save current control word
  184. mov word ptr LfControlWord[rsi], 03fh ; set to mask all exceptions
  185. frstord [rsi] ; restore legacy floating point state
  186. mov LfControlWord[rsi], di ; restore control word
  187. fldcw word ptr LfControlWord[rsi] ; load legacy control word
  188. sti ; enabel interrupts
  189. KiRE10: mov ExP5[rsp], r8b ; set first chance parameter
  190. mov r8, rsp ; set exception frame address
  191. lea r9, (-128)[rbp] ; set trap frame address
  192. call KiRaiseException ; call raise exception routine
  193. ;
  194. ; If the kernel raise exception routine returns success, then exit via the
  195. ; exception exit code. Otherwise, return to the system service dispatcher.
  196. ;
  197. test eax, eax ; test if service failed
  198. jnz short KiRE20 ; if nz, service failed
  199. ;
  200. ; Exit via the exception exit code which will restore the machine state.
  201. ;
  202. mov r8, TrTrapFrame[rbp] ; set previous trap frame address
  203. mov ThTrapFrame[rbx], r8 ;
  204. jmp KiExceptionExit ;
  205. ;
  206. ; The context or exception record is misaligned or not accessible, or the
  207. ; exception was not handled.
  208. ;
  209. KiRE20: RESTORE_EXCEPTION_STATE ; restore exception state/deallocate
  210. ret ; return
  211. NESTED_END NtRaiseException, _TEXT$00
  212. end