[ros-diffs] [ion] 23901: - Add Ke386SetInterruptDescriptorTable inlined function to set the IDT. - Rename and fixup initial stacks, instead of using 16 different variables all with confusining meanings and values. Define P0BootStack as the initial kernel stack, and KiDoubleFaultStack as the double-fault trap (and initial DPC) stack. - Fix call to KiInitializePcr which was setting an incorrect DPC stack. - Make space on the initial stack for a KTRAP_FRAME as well, not only for the FPU save area. - Also push initial CR0 NPX state on the initial stack. - Load the IDT and GDT directly in KiRosPrepareForSystemStartup. - Completely rewrite main_asm.S in Intel syntax and clean it up.

ion at svn.reactos.org ion at svn.reactos.org
Sun Sep 3 21:57:56 CEST 2006


Author: ion
Date: Sun Sep  3 23:57:55 2006
New Revision: 23901

URL: http://svn.reactos.org/svn/reactos?rev=23901&view=rev
Log:
- Add Ke386SetInterruptDescriptorTable inlined function to set the IDT.
- Rename and fixup initial stacks, instead of using 16 different variables all with confusining meanings and values. Define P0BootStack as the initial kernel stack, and KiDoubleFaultStack as the double-fault trap (and initial DPC) stack.
- Fix call to KiInitializePcr which was setting an incorrect DPC stack.
- Make space on the initial stack for a KTRAP_FRAME as well, not only for the FPU save area.
- Also push initial CR0 NPX state on the initial stack.
- Load the IDT and GDT directly in KiRosPrepareForSystemStartup.
- Completely rewrite main_asm.S in Intel syntax and clean it up.

Modified:
    trunk/reactos/include/ndk/asm.h
    trunk/reactos/ntoskrnl/include/internal/i386/ke.h
    trunk/reactos/ntoskrnl/include/internal/ke.h
    trunk/reactos/ntoskrnl/ke/i386/cpu.c
    trunk/reactos/ntoskrnl/ke/i386/kernel.c
    trunk/reactos/ntoskrnl/ke/i386/main_asm.S
    trunk/reactos/ntoskrnl/ke/i386/trap.s
    trunk/reactos/ntoskrnl/ke/main.c
    trunk/reactos/ntoskrnl/mm/mminit.c
    trunk/reactos/ntoskrnl/ps/idle.c

Modified: trunk/reactos/include/ndk/asm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/asm.h?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/include/ndk/asm.h (original)
+++ trunk/reactos/include/ndk/asm.h Sun Sep  3 23:57:55 2006
@@ -493,6 +493,11 @@
 // Kernel Feature Bits
 //
 #define KF_RDTSC                                0x00000002
+
+//
+// Kernel Stack Size
+//
+#define KERNEL_STACK_SIZE                       0x3000
 #endif
 
 //

Modified: trunk/reactos/ntoskrnl/include/internal/i386/ke.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/i386/ke.h?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/i386/ke.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/i386/ke.h Sun Sep  3 23:57:55 2006
@@ -145,6 +145,10 @@
                                  __asm__("lldt %0\n\t" \
                                      : /* no outputs */ \
                                      : "m" (X));
+#define Ke386SetInterruptDescriptorTable(X) \
+                                 __asm__("lidt %0\n\t" \
+                                     : /* no outputs */ \
+                                     : "m" (X));
 #define Ke386SetGlobalDescriptorTable(X) \
                                  __asm__("lgdt %0\n\t" \
                                      : /* no outputs */ \

Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/ke.h?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ke.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ke.h Sun Sep  3 23:57:55 2006
@@ -96,7 +96,11 @@
 extern BOOLEAN KeI386VirtualIntExtensions;
 extern KIDTENTRY KiIdt[];
 extern KGDTENTRY KiBootGdt[];
+extern KDESCRIPTOR KiGdtDescriptor;
+extern KDESCRIPTOR KiIdtDescriptor;
 extern KTSS KiBootTss;
+extern UCHAR P0BootStack[];
+extern UCHAR KiDoubleFaultStack[];
 extern FAST_MUTEX KernelAddressSpaceLock;
 extern ULONG KiMaximumDpcQueueDepth;
 extern ULONG KiMinimumDpcRate;
@@ -119,7 +123,6 @@
 extern PKPRCB KiProcessorBlock[];
 extern ULONG KiMask32Array[MAXIMUM_PRIORITY];
 extern ULONG IdleProcessorMask;
-extern ULONG trap_stack_top;
 extern VOID KiTrap8(VOID);
 extern VOID KiTrap2(VOID);
 

Modified: trunk/reactos/ntoskrnl/ke/i386/cpu.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/cpu.c?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/cpu.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/cpu.c Sun Sep  3 23:57:55 2006
@@ -582,7 +582,7 @@
     Tss = (PKTSS)KiDoubleFaultTSS;
     KiInitializeTSS(Tss);
     Tss->CR3 = _Ke386GetCr(3);
-    Tss->Esp0 = trap_stack_top;
+    Tss->Esp0 = PtrToUlong(KiDoubleFaultStack);
     Tss->Eip = PtrToUlong(KiTrap8);
     Tss->Cs = KGDT_R0_CODE;
     Tss->Fs = KGDT_R0_PCR;
@@ -613,7 +613,7 @@
     Tss = (PKTSS)KiNMITSS;
     KiInitializeTSS(Tss);
     Tss->CR3 = _Ke386GetCr(3);
-    Tss->Esp0 = trap_stack_top;
+    Tss->Esp0 = PtrToUlong(KiDoubleFaultStack);
     Tss->Eip = PtrToUlong(KiTrap2);
     Tss->Cs = KGDT_R0_CODE;
     Tss->Fs = KGDT_R0_PCR;

Modified: trunk/reactos/ntoskrnl/ke/i386/kernel.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kernel.c?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/kernel.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/kernel.c Sun Sep  3 23:57:55 2006
@@ -26,7 +26,7 @@
 EPROCESS KiInitialProcess;
 
 extern ULONG Ke386GlobalPagesEnabled;
-extern PVOID trap_stack, init_stack;
+extern PVOID trap_stack;
 
 /* System-defined Spinlocks */
 KSPIN_LOCK KiDispatcherLock;
@@ -514,7 +514,7 @@
                     KiBootGdt,
                     &KiBootTss,
                     &KiInitialThread.Tcb,
-                    trap_stack);
+                    KiDoubleFaultStack);
 
     /* Set us as the current process */
     KiInitialThread.Tcb.ApcState.Process = &KiInitialProcess.Pcb;
@@ -554,7 +554,7 @@
     /* Call main kernel intialization */
     KiInitializeKernel(&KiInitialProcess.Pcb,
                        &KiInitialThread.Tcb,
-                       init_stack,
+                       P0BootStack,
                        Prcb,
                        Cpu,
                        LoaderBlock);

Modified: trunk/reactos/ntoskrnl/ke/i386/main_asm.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/main_asm.S?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/main_asm.S (original)
+++ trunk/reactos/ntoskrnl/ke/i386/main_asm.S Sun Sep  3 23:57:55 2006
@@ -1,46 +1,45 @@
-#include <roscfg.h>
-#include <ndk/asm.h>
+/*
+ * FILE:            ntoskrnl/ke/i386/main_asm.S
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PURPOSE:         Kernel Bootstrap Code
+ * PROGRAMMER:      Alex Ionescu (alex at relsoft.net)
+ */
 
-#define AP_MAGIC (0x12481020)
+/* INCLUDES ******************************************************************/
 
-.global _kernel_stack
-.global _kernel_stack_top
-.global _kernel_trap_stack
-.global _kernel_trap_stack_top
+#include <asm.h>
+.intel_syntax noprefix
 
-.globl _NtProcessStartup
+/* GLOBALS *******************************************************************/
 
 .bss
-.align 4096
+.align 16
 
+/* Kernel Boot Stack */
+.globl _P0BootStack
+.space KERNEL_STACK_SIZE
+_P0BootStack:
 
-/* guard page for the kernel stack */
-.fill 4096, 1, 0
+/* Kernel Double-Fault and Temporary DPC Stack */
+.globl _KiDoubleFaultStack
+.space KERNEL_STACK_SIZE
+_KiDoubleFaultStack:
 
-_kernel_stack:
-.fill 3*4096, 1, 0
-_kernel_stack_top:
+/* FUNCTIONS *****************************************************************/
 
-/* guard page for the trap stack */
-.fill 4096, 1, 0
-
-_kernel_trap_stack:
-.fill 3*4096, 1, 0
-_kernel_trap_stack_top:
-	
 .text
-
+.func NtProcessStartup
 _NtProcessStartup:
 
-    /* FIXME: Application processors should have their own GDT/IDT */
-    lgdt _KiGdtDescriptor
-    lidt _KiIdtDescriptor
+    /* Load the initial kernel stack */
+    lea eax, _P0BootStack
+    sub eax, (NPX_FRAME_LENGTH + KTRAP_FRAME_LENGTH + KTRAP_FRAME_ALIGN)
+    mov esp, eax
 
-    /* Load the initial kernel stack */
-    lea _kernel_stack_top, %eax
-    sub $(SIZEOF_FX_SAVE_AREA), %eax
-    movl %eax, %esp
+    /* Save initial CR0 state */
+    push CR0_EM + CR0_TS + CR0_MP
 
     /* Call the main kernel initialization */
-    pushl %edx
+    push edx
     call _KiRosPrepareForSystemStartup at 4
+.endfunc

Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/trap.s (original)
+++ trunk/reactos/ntoskrnl/ke/i386/trap.s Sun Sep  3 23:57:55 2006
@@ -86,9 +86,6 @@
 _UnexpectedMsg:
     .asciz "\n\x7\x7!!! Unexpected Interrupt %02lx !!!\n"
 
-Broken:
-    .asciz "\n\x7\x7!!! Broken TrapFrame. Magic: %08lx MagicB: %08lx!!!\n"
-
 /* SOFTWARE INTERRUPT SERVICES ***********************************************/
 
 _KiGetTickCount:

Modified: trunk/reactos/ntoskrnl/ke/main.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/main.c?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/main.c (original)
+++ trunk/reactos/ntoskrnl/ke/main.c Sun Sep  3 23:57:55 2006
@@ -48,18 +48,6 @@
 
 ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */
 
-/* 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)&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];
 
@@ -97,6 +85,10 @@
     PIMAGE_OPTIONAL_HEADER OptHead;
     CHAR* s;
 
+    /* Load the GDT and IDT */
+    Ke386SetGlobalDescriptorTable(KiGdtDescriptor);
+    Ke386SetInterruptDescriptorTable(KiIdtDescriptor);
+
     /* Copy the Loader Block Data locally since Low-Memory will be wiped */
     memcpy(&KeLoaderBlock, LoaderBlock, sizeof(ROS_LOADER_PARAMETER_BLOCK));
     memcpy(&KeLoaderModules[1],

Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c Sun Sep  3 23:57:55 2006
@@ -35,10 +35,6 @@
 
 PVOID MiNonPagedPoolStart;
 ULONG MiNonPagedPoolLength;
-
-extern ULONG init_stack;
-extern ULONG init_stack_top;
-extern ULONG trap_stack;
 
 VOID INIT_FUNCTION NTAPI MmInitVirtualMemory(ULONG_PTR LastKernelAddress, ULONG KernelLength);
 
@@ -394,10 +390,6 @@
                        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
     */

Modified: trunk/reactos/ntoskrnl/ps/idle.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/idle.c?rev=23901&r1=23900&r2=23901&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ps/idle.c (original)
+++ trunk/reactos/ntoskrnl/ps/idle.c Sun Sep  3 23:57:55 2006
@@ -59,19 +59,19 @@
                               BOOLEAN First)
 {
     PETHREAD Thread;
-    ULONG_PTR KernelStack;
-    extern unsigned int init_stack_top;
+    PVOID KernelStack;
 
     Thread = ExAllocatePool(NonPagedPool, sizeof(ETHREAD));
     RtlZeroMemory(Thread, sizeof(ETHREAD));
     Thread->ThreadsProcess = Process;
     if (First)
     {
-        KernelStack = init_stack_top;
+        KernelStack = P0BootStack;
     }
     else
     {
-        KernelStack = (ULONG_PTR)MmCreateKernelStack(FALSE) + KERNEL_STACK_SIZE;
+        KernelStack = (PVOID)((ULONG_PTR)MmCreateKernelStack(FALSE) +
+                              KERNEL_STACK_SIZE);
     }
     KeInitializeThread(&Process->Pcb,
                        &Thread->Tcb,
@@ -80,7 +80,7 @@
                        NULL,
                        NULL,
                        NULL,
-                       (PVOID)KernelStack);
+                       KernelStack);
     InitializeListHead(&Thread->IrpList);
     *ThreadPtr = Thread;
     return STATUS_SUCCESS;




More information about the Ros-diffs mailing list