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.

220 lines
7.0 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. ; N.B. If the previous mode is user, then the legacy floating point state is
  69. ; saved in case the context record does not specify floating context.
  70. ;
  71. test byte ptr TrSegCs[rbp], MODE_MASK ; check if previous mode user
  72. jz short KiCO10 ; if z, preevious mode not user
  73. lea rsi, (KTRAP_FRAME_LENGTH - 128)[rbp] ; get save area address
  74. fnsaved [rsi] ; save legacy floating state
  75. KiCO10: mov bl, dl ; save test alert argument
  76. mov rdx, rsp ; set exception frame address
  77. lea r8, (-128)[rbp] ; set trap frame address
  78. call KiContinue ; transfer context to kernel frames
  79. ;
  80. ; If the kernel continuation routine returns success, then exit via the
  81. ; exception exit code. Otherwise, return to the system service dispatcher.
  82. ;
  83. test eax, eax ; test if service failed
  84. jnz short KiCO40 ; if nz, service failed
  85. ;
  86. ; Check to determine if alert should be tested for the previous processor
  87. ; mode and restore the previous mode in the thread object.
  88. ;
  89. mov rax, gs:[PcCurrentThread] ; get current thread address
  90. mov r8, TrTrapFrame[rbp] ; set previous trap frame address
  91. mov ThTrapFrame[rax], r8 ;
  92. mov cl, ThPreviousMode[rax] ; get thread previous mode
  93. mov dl, TrPreviousMode[rbp] ; get frame previous mode
  94. mov ThPreviousMode[rax], dl ; set thread previous mode
  95. test bl, bl ; test if test alert specified
  96. jz short KiCO20 ; if z, test alert not specified
  97. call KeTestAlertThread ; test alert for current thread
  98. ;
  99. ; If the previous mode is user, then restore the legacy floating state.
  100. ;
  101. KiCO20: test byte ptr TrSegCs[rbp], MODE_MASK ; check if previous mode user
  102. jz short KiCO30 ; if z, previous mode not user
  103. mov ax, LfControlWord[rsi] ; save current control word
  104. mov word ptr LfControlWord[rsi], 03fh ; set to mask all exceptions
  105. frstord [rsi] ; restore legacy floating state
  106. mov LfControlWord[rsi], ax ; restore control word
  107. fldcw word ptr LfControlWord[rsi] ; load legacy control word
  108. KiCO30: jmp KiExceptionExit ;
  109. ;
  110. ; Context record is misaligned or not accessible.
  111. ;
  112. KiCO40: RESTORE_EXCEPTION_STATE ; restore exception state/deallocate
  113. ret ; return
  114. NESTED_END NtContinue, _TEXT$00
  115. subttl "Raise Exception System Service"
  116. ;++
  117. ;
  118. ; NTSTATUS
  119. ; NtRaiseException (
  120. ; IN PEXCEPTION_RECORD ExceptionRecord,
  121. ; IN PCONTEXT ContextRecord,
  122. ; IN BOOLEAN FirstChance
  123. ; )
  124. ;
  125. ; Routine Description:
  126. ;
  127. ; This routine is called as a system service to raise an exception. Its
  128. ; function is to transfer information from the specified context record
  129. ; into the trap frame that was built when the system service was executed.
  130. ; The exception may be raised as a first or second chance exception.
  131. ;
  132. ; Arguments:
  133. ;
  134. ; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
  135. ;
  136. ; ContextRecord (rdx) - Suppilies a pointer to a context record.
  137. ;
  138. ; FirstChance (r8b) - Supplies a boolean value that specifies whether
  139. ; this is the first (TRUE) or second chance (FALSE) for dispatching
  140. ; the exception.
  141. ;
  142. ; Implicit Arguments:
  143. ;
  144. ; rbp - Supplies a pointer to a trap frame.
  145. ;
  146. ; Return Value:
  147. ;
  148. ; Normally there is no return from this routine. However, if the specified
  149. ; context record or exception record is misaligned or is not accessible,
  150. ; then the appropriate status code is returned.
  151. ;
  152. ;--
  153. NESTED_ENTRY NtRaiseException, _TEXT$00
  154. GENERATE_EXCEPTION_FRAME ; generate exception frame
  155. ;
  156. ; Call the raise exception kernel routine which will marshall the arguments
  157. ; and then call the exception dispatcher.
  158. ;
  159. ; N.B. If the previous mode is user, then the legacy floating point state is
  160. ; saved in case the context record does not specify floating context.
  161. ;
  162. lea r9, (-128)[rbp] ; set trap frame address
  163. test byte ptr TrSegCs[rbp], MODE_MASK ; check if previous mode user
  164. jz short KiRE10 ; if z, previous mode not user
  165. fnsaved KTRAP_FRAME_LENGTH[r9] ; save legacy floating state
  166. KiRE10: mov ExP5[rsp], r8b ; set first chance parameter
  167. mov r8, rsp ; set exception frame address
  168. call KiRaiseException ; call raise exception routine
  169. ;
  170. ; If the kernel raise exception routine returns success, then exit via the
  171. ; exception exit code. Otherwise, return to the system service dispatcher.
  172. ;
  173. test eax, eax ; test if service failed
  174. jnz short KiRE20 ; if nz, service failed
  175. ;
  176. ; Exit via the exception exit code which will restore the machine state.
  177. ;
  178. mov rax, gs:[PcCurrentThread] ; get current thread address
  179. mov r8, TrTrapFrame[rbp] ; set previous trap frame address
  180. mov ThTrapFrame[rax], r8 ;
  181. jmp KiExceptionExit ;
  182. ;
  183. ; The context or exception record is misaligned or not accessible, or the
  184. ; exception was not handled.
  185. ;
  186. KiRE20: RESTORE_EXCEPTION_STATE ; restore exception state/deallocate
  187. ret ; return
  188. NESTED_END NtRaiseException, _TEXT$00
  189. end