|
12 | 12 | #define NDEBUG
|
13 | 13 | #include <debug.h>
|
14 | 14 |
|
| 15 | + |
| 16 | +VOID |
| 17 | +NTAPI |
| 18 | +KiSetupStackAndInitializeKernel(IN PKPROCESS InitProcess, |
| 19 | + IN PKTHREAD InitThread, |
| 20 | + IN PVOID IdleStack, |
| 21 | + IN PKPRCB Prcb, |
| 22 | + IN CCHAR Number, |
| 23 | + IN PLOADER_PARAMETER_BLOCK LoaderBlock); |
| 24 | + |
15 | 25 | /* GLOBALS *******************************************************************/
|
16 | 26 |
|
17 | 27 | /* Spinlocks used only on X86 */
|
@@ -752,28 +762,32 @@ KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
752 | 762 | KfRaiseIrql(HIGH_LEVEL);
|
753 | 763 |
|
754 | 764 | /* Align stack and make space for the trap frame and NPX frame */
|
755 |
| - InitialStack &= -KTRAP_FRAME_ALIGN; |
756 |
| -#ifdef __GNUC__ |
757 |
| - __asm__ __volatile__("xorl %ebp, %ebp"); |
758 |
| - __asm__ __volatile__("movl %0,%%esp" : :"r" (InitialStack)); |
759 |
| - __asm__ __volatile__("subl %0,%%esp" : :"r" (NPX_FRAME_LENGTH + |
760 |
| - KTRAP_FRAME_LENGTH + |
761 |
| - KTRAP_FRAME_ALIGN)); |
762 |
| - __asm__ __volatile__("push %0" : :"r" (CR0_EM + CR0_TS + CR0_MP)); |
763 |
| -#else |
764 |
| - __asm xor ebp, ebp; |
765 |
| - __asm mov esp, InitialStack; |
766 |
| - __asm sub esp, NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH; |
767 |
| - __asm push CR0_EM + CR0_TS + CR0_MP; |
768 |
| -#endif |
| 765 | + InitialStack &= ~(KTRAP_FRAME_ALIGN - 1); |
| 766 | + |
| 767 | + /* NOTE: We cannot setup the stack using inline assembly and then later assume |
| 768 | + that the compiler is smart enough to figure out how the stack layout |
| 769 | + changed! This is to avoid generating wrong code. We cannot directly |
| 770 | + call KiInitializeKernel from here! */ |
| 771 | + |
| 772 | + KiSetupStackAndInitializeKernel(&KiInitialProcess.Pcb, |
| 773 | + InitialThread, |
| 774 | + (PVOID)InitialStack, |
| 775 | + (PKPRCB)__readfsdword(KPCR_PRCB), |
| 776 | + (CCHAR)Cpu, |
| 777 | + KeLoaderBlock); |
| 778 | + |
| 779 | + /* NOTE: KiSetupStackAndInitializeKernel never returns! Do NOT add any code here! */ |
| 780 | + ASSERT(FALSE); |
| 781 | +} |
769 | 782 |
|
770 |
| - /* Call main kernel initialization */ |
771 |
| - KiInitializeKernel(&KiInitialProcess.Pcb, |
772 |
| - InitialThread, |
773 |
| - (PVOID)InitialStack, |
774 |
| - (PKPRCB)__readfsdword(KPCR_PRCB), |
775 |
| - (CCHAR)Cpu, |
776 |
| - KeLoaderBlock); |
| 783 | +VOID |
| 784 | +NTAPI |
| 785 | +KiSystemStartupFinal(VOID) |
| 786 | +{ |
| 787 | + /* NOTE: This routine is called after setting up the stack in KiSystemStartup! |
| 788 | + This code cannot be moved to KiSystemStartup because it cannot be assumed |
| 789 | + that the compiler can generate working code after modifying ESP/EBP |
| 790 | + using inline assembly! */ |
777 | 791 |
|
778 | 792 | /* Set the priority of this thread to 0 */
|
779 | 793 | KeGetCurrentThread()->Priority = 0;
|
|
0 commit comments