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.

170 lines
3.6 KiB

  1. /*++
  2. Module Name:
  3. context.c
  4. Abstract:
  5. This module contains the context management routines for
  6. Win32
  7. Author:
  8. Revision History:
  9. --*/
  10. #include "basedll.h"
  11. #include "kxia64.h"
  12. VOID
  13. BaseInitializeContext(
  14. OUT PCONTEXT Context,
  15. IN PVOID Parameter OPTIONAL,
  16. IN PVOID InitialPc OPTIONAL,
  17. IN PVOID InitialSp OPTIONAL,
  18. IN BASE_CONTEXT_TYPE ContextType
  19. )
  20. /*++
  21. Routine Description:
  22. This function initializes a context structure so that it can
  23. be used in a subsequent call to NtCreateThread.
  24. Arguments:
  25. Context - Supplies a context buffer to be initialized by this routine.
  26. Parameter - Supplies the thread's parameter.
  27. InitialPc - Supplies an initial program counter value.
  28. InitialSp - Supplies an initial stack pointer value.
  29. NewThread - Supplies a flag that specifies that this is a new
  30. thread, or a new process.
  31. Return Value:
  32. Raises STATUS_BAD_INITIAL_STACK if the value of InitialSp is not properly
  33. aligned.
  34. Raises STATUS_BAD_INITIAL_PC if the value of InitialPc is not properly
  35. aligned.
  36. --*/
  37. {
  38. ULONG ArgumentsCount;
  39. //
  40. // Initialize the Context
  41. //
  42. RtlZeroMemory((PVOID)Context, sizeof(CONTEXT));
  43. Context->StFPSR = USER_FPSR_INITIAL;
  44. Context->StIPSR = USER_PSR_INITIAL;
  45. Context->RsBSP = Context->IntSp = (ULONG_PTR)InitialSp;
  46. Context->IntSp -= STACK_SCRATCH_AREA; // scratch area as per convention
  47. Context->IntS1 = (ULONG_PTR)InitialPc;
  48. Context->IntS2 = (ULONG_PTR)Parameter;
  49. //
  50. // Enable RSE engine
  51. //
  52. Context->RsRSC = (RSC_MODE_EA<<RSC_MODE)
  53. | (RSC_BE_LITTLE<<RSC_BE)
  54. | (0x3<<RSC_PL);
  55. if ( ContextType == BaseContextTypeThread ) {
  56. Context->IntS0 = Context->StIIP = (ULONG_PTR)BaseThreadStartThunk;
  57. }
  58. else if ( ContextType == BaseContextTypeFiber ) {
  59. Context->IntS0 = Context->StIIP = (ULONG_PTR)BaseFiberStart;
  60. //
  61. // set up the return pointer here..
  62. // when SwitchToFiber restores context and calls return,
  63. // the contorl goes to this routine
  64. //
  65. Context->BrRp = *((ULONGLONG *)((PUCHAR)BaseFiberStart));
  66. //
  67. // set up sof = 96 in pfs. This will be used to set up CFM for above
  68. // routine
  69. //
  70. Context->RsPFS = 0x60;
  71. }
  72. else {
  73. Context->IntS0 = Context->StIIP = (ULONG_PTR)(LONG_PTR)BaseProcessStartThunk;
  74. }
  75. Context->RsPFS |= MASK_IA64(PFS_PPL, 3i64);
  76. Context->ContextFlags = CONTEXT_CONTROL| CONTEXT_INTEGER;
  77. Context->Eflag = 0x3000i64;
  78. }
  79. VOID
  80. BaseFiberStart(
  81. VOID
  82. )
  83. /*++
  84. Routine Description:
  85. This function is called to start a Win32 fiber. Its purpose
  86. is to call BaseThreadStart, getting the necessary arguments
  87. from the fiber context record.
  88. Arguments:
  89. None.
  90. Return Value:
  91. None.
  92. --*/
  93. {
  94. PFIBER Fiber;
  95. Fiber = GetCurrentFiber();
  96. BaseThreadStart( (LPTHREAD_START_ROUTINE)Fiber->FiberContext.IntS1,
  97. (LPVOID)Fiber->FiberContext.IntS2 );
  98. }
  99. VOID
  100. BaseProcessStartupIA64(
  101. IN PTHREAD_START_ROUTINE StartRoutine,
  102. IN PVOID ThreadParameter
  103. )
  104. /*++
  105. Routine Description:
  106. This function calls to the portable thread starter after moving
  107. its arguments from registers to the argument registers.
  108. Arguments:
  109. StartRoutine - User Target start program counter
  110. ThreadParameter
  111. Return Value:
  112. Never Returns
  113. --*/
  114. {
  115. (StartRoutine)(ThreadParameter);
  116. }