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.

151 lines
4.4 KiB

  1. // TITLE("Thread Startup")
  2. //++
  3. //
  4. // Copyright (c) 1990 Microsoft Corporation
  5. // Copyright (c) 1992, 1993 Digital Equipment Corporation
  6. //
  7. // Module Name:
  8. //
  9. // threadbg.s
  10. //
  11. // Abstract:
  12. //
  13. // This module implements the MIPS machine dependent code necessary to
  14. // startup a thread in kernel mode.
  15. //
  16. // Author:
  17. //
  18. // David N. Cutler (davec) 28-Mar-1990
  19. // Joe Notarangelo 21-Apr-1992
  20. //
  21. // Environment:
  22. //
  23. // Kernel mode only, IRQL APC_LEVEL.
  24. //
  25. // Revision History:
  26. //
  27. //--
  28. #include "ksalpha.h"
  29. //++
  30. //
  31. // RoutineDescription:
  32. //
  33. // The following code is never executed. Its purpose is to allow the
  34. // kernel debugger to walk call frames backwards through thread startup
  35. // and to support get/set user context.
  36. //
  37. //--
  38. NESTED_ENTRY(KiThreadDispatch, ExceptionFrameLength, zero)
  39. lda sp, -ExceptionFrameLength(sp) // allocate exception frame
  40. stq ra, ExIntRa(sp) // save return address
  41. stq s0, ExIntS0(sp) // save integer regs s0-s5
  42. stq s1, ExIntS1(sp) //
  43. stq s2, ExIntS2(sp) //
  44. stq s3, ExIntS3(sp) //
  45. stq s4, ExIntS4(sp) //
  46. stq s5, ExIntS5(sp) //
  47. stt f2, ExFltF2(sp) // save floating regs f2 - f9
  48. stt f3, ExFltF3(sp) //
  49. stt f4, ExFltF4(sp) //
  50. stt f5, ExFltF5(sp) //
  51. stt f6, ExFltF6(sp) //
  52. stt f7, ExFltF7(sp) //
  53. stt f8, ExFltF8(sp) //
  54. stt f9, ExFltF9(sp) //
  55. PROLOGUE_END
  56. //++
  57. //
  58. // Routine Description:
  59. //
  60. // This routine is called at thread startup. Its function is to call the
  61. // initial thread procedure. If control returns from the initial thread
  62. // procedure and a user mode context was established when the thread
  63. // was initialized, then the user mode context is restored and control
  64. // is transfered to user mode. Otherwise a bug check will occur.
  65. //
  66. //
  67. // Arguments:
  68. //
  69. // sp - Supplies a pointer to the exception frame which contains the
  70. // startup parameters.
  71. //
  72. // Within Exception frame:
  73. //
  74. // s0 - Supplies a boolean value that specified whether a user mode
  75. // thread context was established when the thread was initialized.
  76. //
  77. // s1 - Supplies the starting context parameter for the initial thread
  78. // procedure.
  79. //
  80. // s2 - Supplies the starting address of the initial thread routine.
  81. //
  82. // s3 - Supplies the starting address of the initial system routine.
  83. //
  84. // Return Value:
  85. //
  86. // None.
  87. //
  88. //--
  89. ALTERNATE_ENTRY(KiThreadStartup)
  90. //
  91. // Capture the arguments for startup from the exception frame.
  92. // After the arguments are captured, deallocate the exception frame.
  93. //
  94. ldq s0, ExIntS0(sp) // capture user context boolean
  95. ldq s1, ExIntS1(sp) // set startup context parameter
  96. ldq s2, ExIntS2(sp) // set address of thread routine
  97. ldq s3, ExIntS3(sp) // capture startup routine address
  98. ldq s4, ExIntS4(sp) // restore s4
  99. ldq s5, ExIntS5(sp) // restore s5
  100. ldq fp, ExIntFp(sp) // restore trap frame pointer
  101. lda sp, ExceptionFrameLength(sp) // deallocate exception frame
  102. //
  103. // Lower Irql to APC level.
  104. //
  105. ldil a0, APC_LEVEL // set IRQL to APC level
  106. SWAP_IRQL // lower IRQL
  107. //
  108. // Jump to the startup routine with the address of the thread routine and
  109. // the startup context parameter.
  110. //
  111. bis s2, zero, a0 // set address of thread routine
  112. bis s1, zero, a1 // set startup context parameter
  113. jsr ra, (s3) // call system startup routine
  114. //
  115. // If we return and no user context was supplied then we have trouble.
  116. //
  117. beq s0, 20f // if eq, no user context
  118. //
  119. // Finish in common exception exit code which will restore the nonvolatile
  120. // registers and exit to user mode.
  121. //
  122. br zero, KiExceptionExit // finish in exception exit code
  123. //
  124. // An attempt was made to enter user mode for a thread that has no user mode
  125. // context. Generate a bug check.
  126. //
  127. 20: ldil a0, NO_USER_MODE_CONTEXT // set bug check code
  128. bsr ra, KeBugCheck // call bug check routine
  129. .end KiThreadDispatch
  130.