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.

208 lines
5.2 KiB

  1. // TITLE("Win32 Thunks")
  2. //++
  3. //
  4. // Copyright (c) 1990 Microsoft Corporation
  5. //
  6. // Module Name:
  7. //
  8. // thunk.s
  9. //
  10. // Abstract:
  11. //
  12. // This module implements Win32 functions that must be written in assembler.
  13. //
  14. // Author:
  15. //
  16. // Mark Lucovsky (markl) 5-Oct-1990
  17. //
  18. // Revision History:
  19. //
  20. // Thomas Van Baak (tvb) 21-Jul-1992
  21. //
  22. // Adapted for Alpha AXP.
  23. //
  24. //--
  25. #include "ksalpha.h"
  26. SBTTL("Switch Stack Then Terminate")
  27. //++
  28. //
  29. // VOID
  30. // BaseSwitchStackThenTerminate (
  31. // IN PVOID StackLimit,
  32. // IN PVOID NewStack,
  33. // IN DWORD ExitCode
  34. // )
  35. //
  36. // Routine Description:
  37. //
  38. // This API is called during thread termination to delete a thread's
  39. // stack, switch to a stack in the thread's TEB, and then terminate.
  40. //
  41. // Arguments:
  42. //
  43. // StackLimit (a0) - Supplies the address of the stack to be freed.
  44. //
  45. // NewStack (a1) - Supplies an address within the terminating thread's TE
  46. // that is to be used as its temporary stack while exiting.
  47. //
  48. // ExitCode (a2) - Supplies the termination status that the thread
  49. // is to exit with.
  50. //
  51. // Return Value:
  52. //
  53. // None.
  54. //
  55. //--
  56. LEAF_ENTRY(BaseSwitchStackThenTerminate)
  57. //
  58. // Switch stacks and then jump to BaseFreeStackAndTerminate.
  59. //
  60. mov a1, sp // set new stack pointer
  61. mov a2, a1 // set exit code argument
  62. br zero, BaseFreeStackAndTerminate // jump
  63. .end BaseSwitchStackThenTerminate
  64. //++
  65. //
  66. // VOID
  67. // WINAPI
  68. // SwitchToFiber (
  69. // LPVOID lpFiber
  70. // )
  71. //
  72. // Routine Description:
  73. //
  74. // This function saves the state of the current fiber and switches
  75. // to the new fiber.
  76. //
  77. // Arguments:
  78. //
  79. // CurrentFiber - Supplies the address of the current fiber.
  80. //
  81. // NewFiber - Supplies the address of the new fiber.
  82. //
  83. // Return Value:
  84. //
  85. // None.
  86. //
  87. //--
  88. LEAF_ENTRY(SwitchToFiber)
  89. GET_THREAD_ENVIRONMENT_BLOCK // get current TEB address
  90. //
  91. // Get current fiber address.
  92. //
  93. LDP a1, TeFiberData(v0) //
  94. //
  95. // Set new deallocation stack and fiber data in TEB.
  96. //
  97. LDP t0, FbDeallocationStack(a0) // set deallocation stack address
  98. STP t0, TeDeallocationStack(v0) //
  99. STP a0, TeFiberData(v0) // set new fiber address
  100. //
  101. // Save stack limit.
  102. //
  103. LDP t1, TeStackLimit(v0) // save current stack limit
  104. STP t1, FbStackLimit(a1) //
  105. //
  106. // Save nonvolatile integer state.
  107. //
  108. stq s0, CxIntS0 + FbFiberContext(a1) //
  109. stq s1, CxIntS1 + FbFiberContext(a1) //
  110. stq s2, CxIntS2 + FbFiberContext(a1) //
  111. stq s3, CxIntS3 + FbFiberContext(a1) //
  112. stq s4, CxIntS4 + FbFiberContext(a1) //
  113. stq s5, CxIntS5 + FbFiberContext(a1) //
  114. stq fp, CxIntFp + FbFiberContext(a1) //
  115. //
  116. // Save nonvolatile float state.
  117. //
  118. stt f2, CxFltF2 + FbFiberContext(a1) //
  119. stt f3, CxFltF3 + FbFiberContext(a1) //
  120. stt f4, CxFltF4 + FbFiberContext(a1) //
  121. stt f5, CxFltF5 + FbFiberContext(a1) //
  122. stt f6, CxFltF6 + FbFiberContext(a1) //
  123. stt f7, CxFltF7 + FbFiberContext(a1) //
  124. stt f8, CxFltF8 + FbFiberContext(a1) //
  125. stt f9, CxFltF9 + FbFiberContext(a1) //
  126. //
  127. // Save RA and SP.
  128. //
  129. stq ra, CxFir + FbFiberContext(a1) //
  130. stq sp, CxIntSp + FbFiberContext(a1) //
  131. //
  132. // Restore new fiber's stack base and stack limit.
  133. //
  134. LDP t0, FbStackBase(a0) // restore StackBase
  135. STP t0, TeStackBase(v0) //
  136. LDP t1, FbStackLimit(a0) // restore StackLimit
  137. STP t1, TeStackLimit(v0) //
  138. //
  139. // Restore nonvolatile integer state.
  140. //
  141. ldq s0, CxIntS0 + FbFiberContext(a0) //
  142. ldq s1, CxIntS1 + FbFiberContext(a0) //
  143. ldq s2, CxIntS2 + FbFiberContext(a0) //
  144. ldq s3, CxIntS3 + FbFiberContext(a0) //
  145. ldq s4, CxIntS4 + FbFiberContext(a0) //
  146. ldq s5, CxIntS5 + FbFiberContext(a0) //
  147. ldq fp, CxIntFp + FbFiberContext(a0) //
  148. //
  149. // Restore nonvolatile float state
  150. //
  151. ldt f2, CxFltF2 + FbFiberContext(a0) //
  152. ldt f3, CxFltF3 + FbFiberContext(a0) //
  153. ldt f4, CxFltF4 + FbFiberContext(a0) //
  154. ldt f5, CxFltF5 + FbFiberContext(a0) //
  155. ldt f6, CxFltF6 + FbFiberContext(a0) //
  156. ldt f7, CxFltF7 + FbFiberContext(a0) //
  157. ldt f8, CxFltF8 + FbFiberContext(a0) //
  158. ldt f9, CxFltF9 + FbFiberContext(a0) //
  159. //
  160. // Swap x86 exception list pointer, wx86tib.
  161. //
  162. ldl t1, 0(v0) // save current exception list
  163. stl t1, FbExceptionList(a1) //
  164. LDP t0, TeVdm(v0) // save current emulator TIB address
  165. STP t0, FbWx86Tib(a1) //
  166. ldl t0, FbExceptionList(a0) // set next exception list
  167. stl t0, 0(v0) //
  168. LDP t0, FbWx86Tib(a0) // set next emulator TIB address
  169. STP t0, TeVdm(v0) //
  170. //
  171. // Restore RA and SP.
  172. //
  173. ldq ra, CxFir + FbFiberContext(a0) //
  174. ldq sp, CxIntSp + FbFiberContext(a0) //
  175. ret zero, (ra)
  176. .end BasepSwitchToFiber
  177.