[ros-diffs] [tkreuzer] 35496: Fix KiSystemStartupReal, KiGetMachineBootPointers and KiInitializePcr. Add trap.S for ISRs (unimplemented). Add except.c with KiInterruptInitTable and KeInitExceptions, initializing the IDT. Add irql.c for IRQL functions (unimplemented). Update stubs file. Based on info from http://www.msuiche.net/papers/Windows_Vista_64bits_and_unexported_kernel_symbols.pdf. We now reach KiSetupStackAndInitializeKernel, but there's a few things still missing.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Thu Aug 21 01:54:53 CEST 2008


Author: tkreuzer
Date: Wed Aug 20 18:54:52 2008
New Revision: 35496

URL: http://svn.reactos.org/svn/reactos?rev=35496&view=rev
Log:
Fix KiSystemStartupReal, KiGetMachineBootPointers and KiInitializePcr. Add trap.S for ISRs (unimplemented). Add except.c with KiInterruptInitTable and KeInitExceptions, initializing the IDT. Add irql.c for IRQL functions (unimplemented). Update stubs file. Based on info from http://www.msuiche.net/papers/Windows_Vista_64bits_and_unexported_kernel_symbols.pdf. We now reach KiSetupStackAndInitializeKernel, but there's a few things still missing.

Added:
    branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c   (with props)
    branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/except.c   (with props)
    branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c   (with props)
    branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/trap.S   (with props)
Modified:
    branches/ros-amd64-bringup/reactos/ntoskrnl/amd64stubs.c
    branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c
    branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl-amd64hack.rbuild
    branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def

Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/amd64stubs.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/amd64stubs.c?rev=35496&r1=35495&r2=35496&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/amd64stubs.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/amd64stubs.c [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -1,17 +1,13 @@
 
-
-#define STUB(x) void x() {}
+unsigned long (*FrLdrDbgPrint)(const char *Format, ...);
+
+
+
+#define STUB(x) void x() {FrLdrDbgPrint("Sorry, %s is only a stub!\n", __FUNCTION__);}
 
 STUB(KdpEnableSafeMem)
-STUB(KfLowerIrql)
-STUB(KeRaiseIrql)
-STUB(KeLowerIrql)
-STUB(KeRaiseIrqlToSynchLevel)
-STUB(KeRaiseIrqlToDpcLevel)
 STUB(KiIdleLoop)
-STUB(KeGetCurrentIrql)
 STUB(KeAcquireInStackQueuedSpinLockRaiseToSynch)
-STUB(KeNumberProcessors)
 STUB(KeBugcheckCallbackListHead)
 STUB(ExpInterlockedPushEntrySList)
 STUB(NtContinue)
@@ -173,7 +169,6 @@
 STUB(KeUpdateSystemTime)
 STUB(KeUserModeCallback)
 STUB(KeWaitForMutexObject)
-STUB(KfRaiseIrql)
 STUB(KiBugCheckData)
 STUB(KiCpuId)
 STUB(MmCommitSessionMappedView)

Added: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c?rev=35496&view=auto
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c (added)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -1,0 +1,59 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            ntoskrnl/ke/amd64/cpu.c
+ * PURPOSE:         Routines for CPU-level support
+ * PROGRAMMERS:     Timo Kreuzer (timo.kreuzer at reactos.org)
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+/* GLOBALS *******************************************************************/
+
+/* The Boot TSS */
+KTSS64 KiBootTss;
+
+/* The TSS to use for Double Fault Traps (INT 0x9) */
+UCHAR KiDoubleFaultTSS[KTSS_IO_MAPS];
+
+/* The TSS to use for NMI Fault Traps (INT 0x2) */
+UCHAR KiNMITSS[KTSS_IO_MAPS];
+
+/* CPU Features and Flags */
+ULONG KeI386MachineType;
+
+CHAR KeNumberProcessors = 0;
+
+/* FUNCTIONS *****************************************************************/
+
+
+VOID
+FASTCALL
+Ki386InitializeTss(IN PKTSS Tss,
+                   IN PKIDTENTRY Idt,
+                   IN PKGDTENTRY Gdt)
+{
+ //   UNIMPLEMENTED;
+}
+
+VOID
+NTAPI
+KeFlushCurrentTb(VOID)
+{
+    /* Flush the TLB by resetting CR3 */
+    __writecr3(__readcr3());
+}
+
+VOID
+NTAPI
+KiInitializeMachineType(VOID)
+{
+    /* Set the Machine Type we got from NTLDR */
+    KeI386MachineType = KeLoaderBlock->u.I386.MachineType & 0x000FF;
+}
+
+

Propchange: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/except.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/except.c?rev=35496&view=auto
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/except.c (added)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/except.c [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -1,0 +1,90 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            ntoskrnl/ke/i386/exp.c
+ * PURPOSE:         Exception Dispatching and Context<->Trap Frame Conversion
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu at reactos.org)
+ *                  Gregor Anich
+ *                  Skywing (skywing at valhallalegends.com)
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+/* GLOBALS *******************************************************************/
+
+KIDT_INIT KiInterruptInitTable[] =
+{
+    {0x00, 0x00, 0x00, KiDivideErrorFault},
+    {0x01, 0x00, 0x00, KiDebugTrapOrFault},
+    {0x02, 0x00, 0x03, KiNmiInterrupt},
+    {0x03, 0x03, 0x00, KiBreakpointTrap},
+    {0x04, 0x03, 0x00, KiOverflowTrap},
+    {0x05, 0x00, 0x00, KiBoundFault},
+    {0x06, 0x00, 0x00, KiInvalidOpcodeFault},
+    {0x07, 0x00, 0x00, KiNpxNotAvailableFault},
+    {0x08, 0x00, 0x01, KiDoubleFaultAbort},
+    {0x09, 0x00, 0x00, KiNpxSegmentOverrunAbort},
+    {0x0A, 0x00, 0x00, KiInvalidTssFault},
+    {0x0B, 0x00, 0x00, KiSegmentNotPresentFault},
+    {0x0C, 0x00, 0x00, KiStackFault},
+    {0x0D, 0x00, 0x00, KiGeneralProtectionFault},
+    {0x0E, 0x00, 0x00, KiPageFault},
+    {0x10, 0x00, 0x00, KiFloatingErrorFault},
+    {0x11, 0x00, 0x00, KiAlignmentFault},
+    {0x12, 0x00, 0x02, KiMcheckAbort},
+    {0x13, 0x00, 0x00, KiXmmException},
+    {0x1F, 0x00, 0x00, KiApcInterrupt},
+    {0x2C, 0x03, 0x00, KiRaiseAssertion},
+    {0x2D, 0x03, 0x00, KiDebugServiceTrap},
+    {0x2F, 0x00, 0x00, KiDpcInterrupt},
+    {0xE1, 0x00, 0x00, KiIpiInterrupt},
+    {0, 0}
+};
+
+KIDTENTRY64 KiIdt[256];
+KDESCRIPTOR KiIdtDescriptor = {{0}, sizeof(KiIdt) - 1, KiIdt};
+
+/* FUNCTIONS *****************************************************************/
+
+
+
+VOID
+INIT_FUNCTION
+NTAPI
+KeInitExceptions(VOID)
+{
+    int i, j;
+
+    /* Initialize the Idt */
+    for (j = i = 0; i < 256; i++)
+    {
+        ULONG64 Offset;
+
+        if (KiInterruptInitTable[j].InterruptId == i)
+        {
+            Offset = (ULONG64)KiInterruptInitTable[j].ServiceRoutine;
+            KiIdt[i].Dpl = KiInterruptInitTable[j].Dpl;
+            j++;
+        }
+        else
+        {
+            Offset = (ULONG64)KiUnexpectedInterrupt;
+            KiIdt[i].Dpl = 0;
+        }
+        KiIdt[i].OffsetLow = Offset & 0xffff;
+        KiIdt[i].Selector = KGDT_64_R0_CODE;
+        KiIdt[i].Type = 0x0e;
+        KiIdt[i].IstIndex = 0;
+        KiIdt[i].Reserved0 = 0;
+        KiIdt[i].Present = 1;
+        KiIdt[i].OffsetMiddle = (Offset >> 16) & 0xffff;
+        KiIdt[i].OffsetHigh = (Offset >> 32);
+        KiIdt[i].Reserved1 = 0;
+    }
+
+}
+

Propchange: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/except.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c?rev=35496&view=auto
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c (added)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -1,0 +1,70 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * PURPOSE:         Routines for IRQL-level support
+ * PROGRAMMERS:     Timo Kreuzer
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#undef UNIMPLEMENTED
+
+#define UNIMPLEMENTED \
+ FrLdrDbgPrint("Sorry, %s is unimplemented!\n", __FUNCTION__)
+
+/* FUNCTIONS ****************************************************************/
+
+#undef KeGetCurrentIrql
+NTKERNELAPI
+KIRQL
+KeGetCurrentIrql(VOID)
+{
+    UNIMPLEMENTED;
+    return 0;
+}
+
+
+NTKERNELAPI
+VOID
+KfLowerIrql(IN KIRQL NewIrql)
+{
+    UNIMPLEMENTED;
+}
+
+NTKERNELAPI
+KIRQL
+KfRaiseIrql(IN KIRQL NewIrql)
+{
+    UNIMPLEMENTED;
+    return 0;
+}
+
+NTKERNELAPI
+KIRQL
+KeRaiseIrqlToDpcLevel(VOID)
+{
+    UNIMPLEMENTED;
+    return 0;
+}
+
+NTKERNELAPI
+KIRQL
+KeRaiseIrqlToSynchLevel(VOID)
+{
+    UNIMPLEMENTED;
+    return 0;
+}
+
+NTKERNELAPI
+VOID
+KeLowerIrql(IN KIRQL NewIrql)
+{
+    UNIMPLEMENTED;
+    return 0;
+}
+
+/* EOF */

Propchange: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/irql.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c?rev=35496&r1=35495&r2=35496&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -21,6 +21,8 @@
 /* BIOS Memory Map. Not NTLDR-compliant yet */
 extern ULONG KeMemoryMapRangeCount;
 extern ADDRESS_RANGE KeMemoryMap[64];
+
+KIPCR KiInitialPcr;
 
 /* FUNCTIONS *****************************************************************/
 
@@ -331,57 +333,48 @@
                 IN PKTHREAD IdleThread,
                 IN PVOID DpcStack)
 {
-#if 0
-    /* Setup the TIB */
-    Pcr->NtTib.ExceptionList = EXCEPTION_CHAIN_END;
-    Pcr->NtTib.StackBase = 0;
-    Pcr->NtTib.StackLimit = 0;
-    Pcr->NtTib.Self = NULL;
-
     /* Set the Current Thread */
-    Pcr->PrcbData.CurrentThread = IdleThread;
+    Pcr->Prcb.CurrentThread = IdleThread;
 
     /* Set pointers to ourselves */
     Pcr->Self = (PKPCR)Pcr;
-    Pcr->Prcb = &Pcr->PrcbData;
+    Pcr->CurrentPrcb = &Pcr->Prcb;
 
     /* Set the PCR Version */
     Pcr->MajorVersion = PCR_MAJOR_VERSION;
     Pcr->MinorVersion = PCR_MINOR_VERSION;
 
     /* Set the PCRB Version */
-    Pcr->PrcbData.MajorVersion = 1;
-    Pcr->PrcbData.MinorVersion = 1;
+    Pcr->Prcb.MajorVersion = 1;
+    Pcr->Prcb.MinorVersion = 1;
 
     /* Set the Build Type */
-    Pcr->PrcbData.BuildType = 0;
+    Pcr->Prcb.BuildType = 0;
 #ifndef CONFIG_SMP
-    Pcr->PrcbData.BuildType |= PRCB_BUILD_UNIPROCESSOR;
+    Pcr->Prcb.BuildType |= PRCB_BUILD_UNIPROCESSOR;
 #endif
 #ifdef DBG
-    Pcr->PrcbData.BuildType |= PRCB_BUILD_DEBUG;
+    Pcr->Prcb.BuildType |= PRCB_BUILD_DEBUG;
 #endif
 
     /* Set the Processor Number and current Processor Mask */
-    Pcr->PrcbData.Number = (UCHAR)ProcessorNumber;
-    Pcr->PrcbData.SetMember = 1 << ProcessorNumber;
+    Pcr->Prcb.Number = (UCHAR)ProcessorNumber;
+    Pcr->Prcb.SetMember = 1 << ProcessorNumber;
 
     /* Set the PRCB for this Processor */
-    KiProcessorBlock[ProcessorNumber] = Pcr->Prcb;
+    KiProcessorBlock[ProcessorNumber] = &Pcr->Prcb;
 
     /* Start us out at PASSIVE_LEVEL */
-    Pcr->Irql = PASSIVE_LEVEL;
+//    Pcr->Irql = PASSIVE_LEVEL;
 
     /* Set the GDI, IDT, TSS and DPC Stack */
-    Pcr->GDT = (PVOID)Gdt;
-    Pcr->IDT = Idt;
-    Pcr->TSS = Tss;
-    Pcr->TssCopy = Tss;
-    Pcr->PrcbData.DpcStack = DpcStack;
+    Pcr->GdtBase = (PVOID)Gdt;
+    Pcr->IdtBase = Idt;
+    Pcr->TssBase = Tss;
+    Pcr->Prcb.DpcStack = DpcStack;
 
     /* Setup the processor set */
-    Pcr->PrcbData.MultiThreadProcessorSet = Pcr->PrcbData.SetMember;
-#endif
+    Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember;
 }
 
 VOID
@@ -616,14 +609,20 @@
                          IN PKIPCR *Pcr,
                          IN PKTSS *Tss)
 {
-#if 0
-    KDESCRIPTOR GdtDescriptor = {0}, IdtDescriptor = {0};
-    KGDTENTRY TssSelector, PcrSelector;
-    USHORT Tr = 0, Fs;
+    KDESCRIPTOR GdtDescriptor = {{0},0,0}, IdtDescriptor = {{0},0,0};
+    KGDTENTRY64 TssSelector;
+    USHORT Tr = 0;
 
     /* Get GDT and IDT descriptors */
-    Ke386GetGlobalDescriptorTable(*(PKDESCRIPTOR)&GdtDescriptor.Limit);
-    Ke386GetInterruptDescriptorTable(*(PKDESCRIPTOR)&IdtDescriptor.Limit);
+    Ke386GetGlobalDescriptorTable(GdtDescriptor.Limit);
+    Ke386GetInterruptDescriptorTable(IdtDescriptor.Limit);
+
+    // FIXME: for some strange reason the gdt needs some time before it's finished...
+    if (!GdtDescriptor.Base)
+    {
+        FrLdrDbgPrint("1. Base = %p, Limit = 0x%x\n", GdtDescriptor.Base, GdtDescriptor.Limit);
+    }
+    FrLdrDbgPrint("2. Base = %p, Limit = 0x%x\n", GdtDescriptor.Base, GdtDescriptor.Limit);
 
     /* Save IDT and GDT */
     *Gdt = (PKGDTENTRY)GdtDescriptor.Base;
@@ -632,24 +631,15 @@
     /* Get TSS and FS Selectors */
     Ke386GetTr(Tr);
     if (Tr != KGDT_TSS) Tr = KGDT_TSS; // FIXME: HACKHACK
-    Fs = Ke386GetFs();
-
-    /* Get PCR Selector, mask it and get its GDT Entry */
-    PcrSelector = *(PKGDTENTRY)((ULONG_PTR)*Gdt + (Fs & ~RPL_MASK));
-
-    /* Get the KPCR itself */
-    *Pcr = (PKIPCR)(ULONG_PTR)(PcrSelector.BaseLow |
-                               PcrSelector.HighWord.Bytes.BaseMid << 16 |
-                               PcrSelector.HighWord.Bytes.BaseHi << 24);
 
     /* Get TSS Selector, mask it and get its GDT Entry */
     TssSelector = *(PKGDTENTRY)((ULONG_PTR)*Gdt + (Tr & ~RPL_MASK));
 
     /* Get the KTSS itself */
     *Tss = (PKTSS)(ULONG_PTR)(TssSelector.BaseLow |
-                              TssSelector.HighWord.Bytes.BaseMid << 16 |
-                              TssSelector.HighWord.Bytes.BaseHi << 24);
-#endif
+                              TssSelector.Bytes.BaseMiddle << 16 |
+                              TssSelector.Bytes.BaseHigh << 24 |
+                              (ULONG64)TssSelector.BaseUpper << 32);
 }
 
 VOID
@@ -657,26 +647,30 @@
 KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 {
 	FrLdrDbgPrint("Enter KiSystemStartupReal()\n");
-	for(;;);
-
-#if 0
+
     ULONG Cpu;
     PKTHREAD InitialThread;
-    ULONG InitialStack;
+    ULONG64 InitialStack;
     PKGDTENTRY Gdt;
     PKIDTENTRY Idt;
-    KIDTENTRY NmiEntry, DoubleFaultEntry;
+//    KIDTENTRY NmiEntry, DoubleFaultEntry;
     PKTSS Tss;
     PKIPCR Pcr;
 
     /* Save the loader block and get the current CPU */
     KeLoaderBlock = LoaderBlock;
+
+    /* Get Pcr from loader block */
+//    Pcr = CONTAINING_RECORD(LoaderBlock->Prcb, KIPCR, Prcb);
+    Pcr = &KiInitialPcr;
+
     Cpu = KeNumberProcessors;
-    if (!Cpu)
-    {
-        /* If this is the boot CPU, set FS and the CPU Number*/
-        Ke386SetFs(KGDT_R0_PCR);
-        __writefsdword(KPCR_PROCESSOR_NUMBER, Cpu);
+    if (Cpu == 0)
+    {
+        /* If this is the boot CPU, set GS base and the CPU Number*/
+        __writemsr(X86_MSR_GSBASE, (ULONG64)Pcr);
+        __writemsr(X86_MSR_KERNEL_GSBASE, (ULONG64)Pcr);
+        Pcr->Prcb.Number = Cpu;
 
         /* Set the initial stack and idle thread as well */
         LoaderBlock->KernelStack = (ULONG_PTR)P0BootStack;
@@ -684,7 +678,7 @@
     }
 
     /* Save the initial thread and stack */
-    InitialStack = LoaderBlock->KernelStack;
+    InitialStack = LoaderBlock->KernelStack; // Chekme
     InitialThread = (PKTHREAD)LoaderBlock->Thread;
 
     /* Clean the APC List Head */
@@ -694,53 +688,59 @@
     KiInitializeMachineType();
 
     /* Skip initial setup if this isn't the Boot CPU */
-    if (Cpu) goto AppCpuInit;
-
-    /* Get GDT, IDT, PCR and TSS pointers */
-    KiGetMachineBootPointers(&Gdt, &Idt, &Pcr, &Tss);
-
-    /* Setup the TSS descriptors and entries */
-    Ki386InitializeTss(Tss, Idt, Gdt);
-
-    /* Initialize the PCR */
-    RtlZeroMemory(Pcr, PAGE_SIZE);
-    KiInitializePcr(Cpu,
-                    Pcr,
-                    Idt,
-                    Gdt,
-                    Tss,
-                    InitialThread,
-                    KiDoubleFaultStack);
-
-    /* Set us as the current process */
-    InitialThread->ApcState.Process = &KiInitialProcess.Pcb;
-
-    /* Clear DR6/7 to cleanup bootloader debugging */
-    __writefsdword(KPCR_TEB, 0);
-    __writefsdword(KPCR_DR6, 0);
-    __writefsdword(KPCR_DR7, 0);
-
-    /* Setup the IDT */
-    KeInitExceptions();
-
-    /* Load Ring 3 selectors for DS/ES */
-    Ke386SetDs(KGDT_R3_DATA | RPL_MASK);
-    Ke386SetEs(KGDT_R3_DATA | RPL_MASK);
-
-    /* Save NMI and double fault traps */
-    RtlCopyMemory(&NmiEntry, &Idt[2], sizeof(KIDTENTRY));
-    RtlCopyMemory(&DoubleFaultEntry, &Idt[8], sizeof(KIDTENTRY));
-
-    /* Copy kernel's trap handlers */
-    RtlCopyMemory(Idt,
-                  (PVOID)KiIdtDescriptor.Base,
-                  KiIdtDescriptor.Limit + 1);
-
-    /* Restore NMI and double fault */
-    RtlCopyMemory(&Idt[2], &NmiEntry, sizeof(KIDTENTRY));
-    RtlCopyMemory(&Idt[8], &DoubleFaultEntry, sizeof(KIDTENTRY));
-
-AppCpuInit:
+    if (Cpu == 0)
+    {
+        /* Get GDT, IDT, PCR and TSS pointers */
+        KiGetMachineBootPointers(&Gdt, &Idt, &Pcr, &Tss);
+
+FrLdrDbgPrint("Gdt = %p, Idt = %p, Pcr = %p, Tss = %p\n", Gdt, Idt, Pcr, Tss);
+
+        /* Setup the TSS descriptors and entries */
+        Ki386InitializeTss(Tss, Idt, Gdt);
+
+        /* Initialize the PCR */
+        RtlZeroMemory(Pcr, PAGE_SIZE);
+        KiInitializePcr(Cpu,
+                        Pcr,
+                        Idt,
+                        Gdt,
+                        Tss,
+                        InitialThread,
+                        KiDoubleFaultStack);
+
+        /* Set us as the current process */
+        InitialThread->ApcState.Process = &KiInitialProcess.Pcb;
+
+        /* Clear DR6/7 to cleanup bootloader debugging */
+        Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0;
+        Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 0;
+
+        /* Setup the IDT */
+        KeInitExceptions();
+
+        /* Load Ring 3 selectors for DS/ES/FS */
+        Ke386SetDs(KGDT_64_DATA | RPL_MASK);
+        Ke386SetEs(KGDT_64_DATA | RPL_MASK);
+//        Ke386SetFs(KGDT_32_R3_TEB | RPL_MASK);
+
+        /* LDT is unused */
+        Ke386SetLocalDescriptorTable(0);
+
+        /* Save NMI and double fault traps */
+//        RtlCopyMemory(&NmiEntry, &Idt[2], sizeof(KIDTENTRY));
+//        RtlCopyMemory(&DoubleFaultEntry, &Idt[8], sizeof(KIDTENTRY));
+
+        /* Copy kernel's trap handlers */
+//        RtlCopyMemory(Idt,
+//                      (PVOID)KiIdtDescriptor.Base,
+//                      KiIdtDescriptor.Limit + 1);
+
+        /* Restore NMI and double fault */
+//        RtlCopyMemory(&Idt[2], &NmiEntry, sizeof(KIDTENTRY));
+//        RtlCopyMemory(&Idt[8], &DoubleFaultEntry, sizeof(KIDTENTRY));
+    }
+
+
     /* Loop until we can release the freeze lock */
     do
     {
@@ -749,26 +749,24 @@
     } while(InterlockedBitTestAndSet((PLONG)&KiFreezeExecutionLock, 0));
 
     /* Setup CPU-related fields */
-    __writefsdword(KPCR_NUMBER, Cpu);
-    __writefsdword(KPCR_SET_MEMBER, 1 << Cpu);
-    __writefsdword(KPCR_SET_MEMBER_COPY, 1 << Cpu);
-    __writefsdword(KPCR_PRCB_SET_MEMBER, 1 << Cpu);
+    Pcr->Prcb.Number = Cpu;
+    Pcr->Prcb.SetMember = 1 << Cpu;
 
     /* Initialize the Processor with HAL */
-    HalInitializeProcessor(Cpu, KeLoaderBlock);
+//    HalInitializeProcessor(Cpu, KeLoaderBlock);
 
     /* Set active processors */
-    KeActiveProcessors |= __readfsdword(KPCR_SET_MEMBER);
+    KeActiveProcessors |= 1 << Cpu;
     KeNumberProcessors++;
 
     /* Check if this is the boot CPU */
-    if (!Cpu)
+    if (Cpu == 0)
     {
         /* Initialize debugging system */
-        KdInitSystem(0, KeLoaderBlock);
+//        KdInitSystem(0, KeLoaderBlock);
 
         /* Check for break-in */
-        if (KdPollBreakIn()) DbgBreakPointWithStatus(1);
+//        if (KdPollBreakIn()) DbgBreakPointWithStatus(1);
     }
 
     /* Raise to HIGH_LEVEL */
@@ -776,13 +774,15 @@
 
     /* Align stack and make space for the trap frame and NPX frame */
     InitialStack &= ~(KTRAP_FRAME_ALIGN - 1);
+
+FrLdrDbgPrint("Before KiSetupStackAndInitializeKernel\n");
+for(;;);
 
     /* Switch to new kernel stack and start kernel bootstrapping */
     KiSetupStackAndInitializeKernel(&KiInitialProcess.Pcb,
                                     InitialThread,
                                     (PVOID)InitialStack,
-                                    (PKPRCB)__readfsdword(KPCR_PRCB),
+                                    &Pcr->Prcb,
                                     (CCHAR)Cpu,
                                     KeLoaderBlock);
-#endif
 }

Added: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/trap.S
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/trap.S?rev=35496&view=auto
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/trap.S (added)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/trap.S [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -1,0 +1,131 @@
+/*
+ * FILE:            ntoskrnl/ke/amd64/trap.S
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PURPOSE:         System Traps, Entrypoints and Exitpoints
+ * PROGRAMMER:      Timo Kreuzer (timo.kreuzer at reactos.org)
+ * NOTE:            See asmmacro.S for the shared entry/exit code.
+ */
+
+/* INCLUDES ******************************************************************/
+
+//#include <asm.h>
+//#include <internal/amd64/asmmacro.S>
+.intel_syntax noprefix
+.code64
+
+/* GLOBALS *******************************************************************/
+
+.data
+
+_MsgGeneralProtFault:
+.ascii "General protection fault at %p!\n\0"
+
+_MsgBreakpointTrap:
+.ascii "BreakpointTrap at %p\n\0"
+
+_MsgUnexpectedInterrupt:
+.ascii "UnexpectedInterrupt\n\0"
+
+
+/* SOFTWARE INTERRUPT SERVICES ***********************************************/
+.text
+.code64
+
+.global _KiDivideErrorFault
+_KiDivideErrorFault:
+
+.global _KiDebugTrapOrFault
+_KiDebugTrapOrFault:
+
+.global _KiNmiInterrupt
+_KiNmiInterrupt:
+
+.global _KiBreakpointTrap
+_KiBreakpointTrap:
+//    mov rdx, [rsp]
+    sub rsp, 0x10
+//    movabs rcx, offset _MsgBreakpointTrap
+//    movabs rax, offset _FrLdrDbgPrint
+//    call [rax]
+    add rsp, 0x10
+    iret
+
+.global _KiOverflowTrap
+_KiOverflowTrap:
+
+.global _KiBoundFault
+_KiBoundFault:
+
+.global _KiInvalidOpcodeFault
+_KiInvalidOpcodeFault:
+
+.global _KiNpxNotAvailableFault
+_KiNpxNotAvailableFault:
+
+.global _KiDoubleFaultAbort
+_KiDoubleFaultAbort:
+
+.global _KiNpxSegmentOverrunAbort
+_KiNpxSegmentOverrunAbort:
+
+.global _KiInvalidTssFault
+_KiInvalidTssFault:
+
+.global _KiSegmentNotPresentFault
+_KiSegmentNotPresentFault:
+
+.global _KiStackFault
+_KiStackFault:
+
+jmp $
+
+
+.global _KiGeneralProtectionFault
+_KiGeneralProtectionFault:
+    mov rdx, 0
+    mov dx, ss
+    movabs rcx, offset _MsgGeneralProtFault
+    movabs rax, offset _FrLdrDbgPrint
+    call [rax]
+    jmp $
+
+
+.global _KiPageFault
+_KiPageFault:
+
+.global _KiFloatingErrorFault
+_KiFloatingErrorFault:
+
+.global _KiAlignmentFault
+_KiAlignmentFault:
+
+.global _KiMcheckAbort
+_KiMcheckAbort:
+
+.global _KiXmmException
+_KiXmmException:
+
+.global _KiApcInterrupt
+_KiApcInterrupt:
+
+
+.global _KiRaiseAssertion
+_KiRaiseAssertion:
+
+.global _KiDebugServiceTrap
+_KiDebugServiceTrap:
+
+.global _KiDpcInterrupt
+_KiDpcInterrupt:
+
+
+.global _KiIpiInterrupt
+_KiIpiInterrupt:
+    iret
+
+.global _KiUnexpectedInterrupt
+_KiUnexpectedInterrupt:
+    movabs rcx, offset _MsgUnexpectedInterrupt
+    movabs rax, offset _FrLdrDbgPrint
+    call [rax]
+    jmp $

Propchange: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/trap.S
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl-amd64hack.rbuild
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl-amd64hack.rbuild?rev=35496&r1=35495&r2=35496&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl-amd64hack.rbuild [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl-amd64hack.rbuild [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -91,7 +91,11 @@
 		<if property="ARCH" value="amd64">
 			<directory name="amd64">
 				<file first="true">boot.S</file>
+				<file>cpu.c</file>
+				<file>except.c</file>
+				<file>irql.c</file>
 				<file>kiinit.c</file>
+				<file>trap.S</file>
 			</directory>
 		</if>
 		<file>apc.c</file>

Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def?rev=35496&r1=35495&r2=35496&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl_amd64.def [iso-8859-1] Wed Aug 20 18:54:52 2008
@@ -6,7 +6,6 @@
 ;
 KfAcquireSpinLock
 KfReleaseSpinLock
-KeRaiseIrql
 KefAcquireSpinLockAtDpcLevel
 KefReleaseSpinLockFromDpcLevel
 KeInitializeSpinLock



More information about the Ros-diffs mailing list