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.

106 lines
3.4 KiB

  1. title "Thread Startup"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; threadbg.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the code necessary to startup a thread in kernel
  13. ; mode.
  14. ;
  15. ; Author:
  16. ;
  17. ; David N. Cutler (davec) 10-Jun-2000
  18. ;
  19. ; Environment:
  20. ;
  21. ; Kernel mode only, IRQL APC_LEVEL.
  22. ;
  23. ;--
  24. include ksamd64.inc
  25. altentry KiThreadStartup
  26. extern KeBugCheck:proc
  27. extern KiExceptionExit:proc
  28. subttl "Thread Startup"
  29. ;++
  30. ;
  31. ; Routine Description:
  32. ;
  33. ; This routine is called at thread startup. Its function is to call the
  34. ; initial thread procedure. If control returns from the initial thread
  35. ; procedure and a user mode context was established when the thread
  36. ; was initialized, then the user mode context is restored and control
  37. ; is transfered to user mode. Otherwise a bug check will occur.
  38. ;
  39. ; N.B. At thread startup the stack contains at least a legacy floating
  40. ; point save area and an exception frame. If the thread is a user
  41. ; mode thread, then it also contains a trap frame. The exception
  42. ; frame contains the system start call address and parameters. As
  43. ; soon as these values are captured the exception frame is deallocated.
  44. ;
  45. ; Arguments:
  46. ;
  47. ; r12 - Supplies a logical value that specifies whether a user mode thread
  48. ; context was established when the thread was initialized.
  49. ;
  50. ; r13 - Supplies the starting context parameter for the initial thread
  51. ; routine.
  52. ;
  53. ; r14 - Supplies the starting address of the initial thread routine.
  54. ;
  55. ; r15 - Supplies the starting address of the initial system routine.
  56. ;
  57. ; rbp - Supplies the address of a trap frame if a user thread is being
  58. ; started. Otherwise, it contains the value 128 and is not meaningful.
  59. ;
  60. ; Return Value:
  61. ;
  62. ; None.
  63. ;
  64. ;--
  65. NESTED_ENTRY KxThreadStartup, _TEXT$00
  66. alloc_stack LEGACY_SAVE_AREA_LENGTH - 8 ; allocate legacy save area
  67. set_frame rbx, 0 ; set frame register
  68. END_PROLOGUE
  69. sub rsp, KEXCEPTION_FRAME_LENGTH ; allocate exception frame
  70. ALTERNATE_ENTRY KiThreadStartup
  71. mov rbx, ExRbx[rsp] ; set frame register
  72. mov r12, ExR12[rsp] ; get user context address
  73. mov r13, ExR13[rsp] ; get startup context parameter
  74. mov r14, ExR14[rsp] ; get initial thread routine address
  75. mov r15, ExR15[rsp] ; get initial system routine address
  76. test r12, r12 ; test if user context specified
  77. jnz short KiTs10 ; if nz, user context specified
  78. add rsp, KEXCEPTION_FRAME_LENGTH - (2 * 8) ; deallocate exception frame
  79. KiTs10: mov ecx, APC_LEVEL ; set IRQL to APC level
  80. SetIrql ;
  81. mov rcx, r14 ; set address of thread routine
  82. mov rdx, r13 ; set startup context parameter
  83. call r15 ; call system routine
  84. test r12, r12 ; test if user context specified
  85. jz short KiTs20 ; if z, no user context specified
  86. jmp KiExceptionExit ; finish in exception exit code
  87. KiTs20: mov rcx, NO_USER_MODE_CONTEXT ; set bug check parameter
  88. call KeBugCheck ; call bug check - no return
  89. NESTED_END KxThreadStartup, _TEXT$00
  90. end