- Allocated the initial stacks page aligned.  
- Add a guard page for the initial stacks.
- Fixed the size of the initial stacks.
Modified: trunk/reactos/ntoskrnl/ke/i386/main_asm.S
Modified: trunk/reactos/ntoskrnl/ke/main.c
Modified: trunk/reactos/ntoskrnl/mm/mminit.c

Modified: trunk/reactos/ntoskrnl/ke/i386/main_asm.S
--- trunk/reactos/ntoskrnl/ke/i386/main_asm.S	2006-01-15 18:21:43 UTC (rev 20896)
+++ trunk/reactos/ntoskrnl/ke/i386/main_asm.S	2006-01-15 18:28:40 UTC (rev 20897)
@@ -3,8 +3,33 @@
 
 #define AP_MAGIC (0x12481020)
 
+.global _kernel_stack
+.global _kernel_stack_top
+.global _kernel_trap_stack
+.global _kernel_trap_stack_top
+
 .globl _NtProcessStartup
 
+.bss
+.align 4096
+
+
+/* guard page for the kernel stack */
+.fill 4096, 1, 0
+
+_kernel_stack:
+.fill 3*4096, 1, 0
+_kernel_stack_top:
+
+/* guard page for the trap stack */
+.fill 4096, 1, 0
+
+_kernel_trap_stack:
+.fill 3*4096, 1, 0
+_kernel_trap_stack_top:
+	
+.text
+
 _NtProcessStartup:
 
     /* FIXME: Application processors should have their own GDT/IDT */
@@ -34,13 +59,12 @@
     
 .m1:     
     /* Load the initial kernel stack */
-    lea _kernel_stack, %eax
-    add $0x2000, %eax
-    and $0xFFFFE000, %eax
-    add $(0x3000 - SIZEOF_FX_SAVE_AREA), %eax
+    lea _kernel_stack_top, %eax
+    sub $(SIZEOF_FX_SAVE_AREA), %eax
     movl %eax, %esp
     
     /* Call the main kernel initialization */
     pushl %edx
     pushl %ecx
     call __main
+

Modified: trunk/reactos/ntoskrnl/ke/main.c
--- trunk/reactos/ntoskrnl/ke/main.c	2006-01-15 18:21:43 UTC (rev 20896)
+++ trunk/reactos/ntoskrnl/ke/main.c	2006-01-15 18:28:40 UTC (rev 20897)
@@ -48,15 +48,17 @@
 
 ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */
 
-/* We allocate 5 pages, but we only use 4. The 5th is to guarantee page alignment */
-ULONG kernel_stack[5120];
-ULONG double_trap_stack[5120];
+/* the initial stacks are declared in main_asm.S */
+extern ULONG kernel_stack;
+extern ULONG kernel_stack_top;
+extern ULONG kernel_trap_stack;
+extern ULONG kernel_trap_stack_top;
 
 /* These point to the aligned 3 pages */
-ULONG init_stack;
-ULONG init_stack_top;
-ULONG trap_stack;
-ULONG trap_stack_top;
+ULONG init_stack = (ULONG)&kernel_stack;
+ULONG init_stack_top = (ULONG)&kernel_stack_top;
+ULONG trap_stack = (ULONG)&kernel_trap_stack;
+ULONG trap_stack_top = (ULONG)&kernel_trap_stack_top;
 
 /* Cached modules from the loader block */
 PLOADER_MODULE CachedModules[MaximumCachedModuleType];
@@ -155,13 +157,6 @@
     PIMAGE_OPTIONAL_HEADER OptHead;
     CHAR* s;
 
-    /* Set up the Stacks (Initial Kernel Stack and Double Trap Stack)
-       and save a page for the fx savings area */
-    trap_stack = PAGE_ROUND_UP(&double_trap_stack) + PAGE_SIZE;
-    trap_stack_top = trap_stack + 3 * PAGE_SIZE;
-    init_stack = PAGE_ROUND_UP(&kernel_stack) + PAGE_SIZE;
-    init_stack_top = init_stack + 3 * PAGE_SIZE;
-
     /* Copy the Loader Block Data locally since Low-Memory will be wiped */
     memcpy(&KeLoaderBlock, _LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK));
     memcpy(&KeLoaderModules[1],

Modified: trunk/reactos/ntoskrnl/mm/mminit.c
--- trunk/reactos/ntoskrnl/mm/mminit.c	2006-01-15 18:21:43 UTC (rev 20896)
+++ trunk/reactos/ntoskrnl/mm/mminit.c	2006-01-15 18:28:40 UTC (rev 20897)
@@ -38,6 +38,7 @@
 
 extern ULONG init_stack;
 extern ULONG init_stack_top;
+extern ULONG trap_stack;
 
 VOID INIT_FUNCTION NTAPI MmInitVirtualMemory(ULONG_PTR LastKernelAddress, ULONG KernelLength);
 
@@ -394,6 +395,10 @@
                        AddressRangeCount);
    kernel_len = LastKrnlPhysAddr - FirstKrnlPhysAddr;
 
+   /* Unmap the guard pages from the initial stacks */
+   MmDeleteVirtualMapping(NULL, (PVOID)(init_stack - PAGE_SIZE), FALSE, NULL, NULL);
+   MmDeleteVirtualMapping(NULL, (PVOID)(trap_stack - PAGE_SIZE), FALSE, NULL, NULL);
+
    /*
     * Unmap low memory
     */