Author: tkreuzer Date: Sun Oct 18 16:18:42 2009 New Revision: 43552
URL: http://svn.reactos.org/svn/reactos?rev=43552&view=rev Log: Cleanup kernel init code a bit
Removed: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/asmmacro.S Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/ke.h branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c
Removed: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/asmmacro.S URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/asmmacro.S [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/asmmacro.S (removed) @@ -1,81 +1,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS Kernel - * FILE: ntoskrnl/include/amd64/asmmacro.S - * PURPOSE: Macros for x64 assembly - * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org) - */ - -.intel_syntax noprefix -.code64 - -/* Macros for x64 stack unwind OPs */ - -.macro .proc name - .func name - .global _\name - _\name: - .cfi_startproc - .equ cfa_current_offset, -8 -.endm - -.macro .endproc - .cfi_endproc - .endfunc -.endm - -.macro .allocstack size - .cfi_adjust_cfa_offset \size - .set cfa_current_offset, cfa_current_offset - \size -.endm - -.macro .pushframe code - .if (\code == 0) - .cfi_adjust_cfa_offset 0x28 - .set cfa_current_offset, cfa_current_offset - 0x28 - .else - .cfi_adjust_cfa_offset 0x30 - .set cfa_current_offset, cfa_current_offset - 0x30 - .endif -.endm - -.macro .pushreg reg - .cfi_adjust_cfa_offset 8 - .equ cfa_current_offset, cfa_current_offset - 8 - .cfi_offset \reg, cfa_current_offset -.endm - -.macro .savereg reg, offset - // checkme!!! - .cfi_offset \reg, \offset -.endm - -.macro .savexmm128 reg, offset - // checkme!!! - .cfi_offset \reg, \offset -.endm - -.macro .setframe reg, offset - .cfi_def_cfa reg, \offset - .equ cfa_current_offset, \offset -.endm - -.macro .endprolog -.endm - -.macro UNIMPLEMENTED2 line, func - jmp 3f - .equ expr, 12 -1: .asciz "\func" -2: .asciz __FILE__ -3: - sub rsp, 0x20 - lea rcx, _MsgUnimplemented[rip] - lea rdx, 1b[rip] - lea r8, 2b[rip] - mov r9, \line - call _DbgPrint - add rsp, 0x20 -.endm -#define UNIMPLEMENTED UNIMPLEMENTED2 __LINE__, -
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/ke.h URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/ke.h [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/include/internal/amd64/ke.h [iso-8859-1] Sun Oct 18 16:18:42 2009 @@ -108,12 +108,14 @@ VOID Ki386ApplicationProcessorInitializeTSS(VOID);
+// Hack +VOID KiRosPrepareForSystemStartup(ULONG, PROS_LOADER_PARAMETER_BLOCK); + VOID FASTCALL Ki386InitializeTss( IN PKTSS Tss, - IN PKIDTENTRY Idt, - IN PKGDTENTRY Gdt, + IN PVOID GdtBase, IN UINT64 Stack );
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/cpu.c [iso-8859-1] Sun Oct 18 16:18:42 2009 @@ -387,18 +387,16 @@ } }
- VOID FASTCALL Ki386InitializeTss(IN PKTSS64 Tss, - IN PKIDTENTRY Idt, - IN PKGDTENTRY Gdt, + IN PVOID GdtBase, IN UINT64 Stack) { PKGDTENTRY64 TssEntry;
/* Initialize the TSS descriptor entry */ - TssEntry = (PVOID)((ULONG64)Gdt + KGDT_TSS); + TssEntry = (PVOID)((ULONG64)GdtBase + KGDT_TSS); TssEntry->Bits.Type = 9;//AMD64_TSS; TssEntry->Bits.Dpl = 0; TssEntry->Bits.Present = 1;
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- 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] Sun Oct 18 16:18:42 2009 @@ -328,18 +328,17 @@
VOID NTAPI -KiInitializePcr(IN ULONG ProcessorNumber, - IN PKIPCR Pcr, - IN PKIDTENTRY Idt, - IN PKGDTENTRY Gdt, - IN PKTSS Tss, +KiInitializePcr(IN PKIPCR Pcr, + IN ULONG ProcessorNumber, IN PKTHREAD IdleThread, IN PVOID DpcStack) { + KDESCRIPTOR GdtDescriptor = {{0},0,0}, IdtDescriptor = {{0},0,0}; + KGDTENTRY64 TssSelector; + USHORT Tr = 0; + + /* Zero out the PCR */ RtlZeroMemory(Pcr, PAGE_SIZE); - - /* Set the Current Thread */ - Pcr->Prcb.CurrentThread = IdleThread;
/* Set pointers to ourselves */ Pcr->Self = (PKPCR)Pcr; @@ -349,7 +348,7 @@ Pcr->MajorVersion = PCR_MAJOR_VERSION; Pcr->MinorVersion = PCR_MINOR_VERSION;
- /* Set the PCRB Version */ + /* Set the PRCB Version */ Pcr->Prcb.MajorVersion = 1; Pcr->Prcb.MinorVersion = 1;
@@ -366,27 +365,44 @@ Pcr->Prcb.Number = (UCHAR)ProcessorNumber; Pcr->Prcb.SetMember = 1 << ProcessorNumber;
- /* Set the PRCB for this Processor */ - KiProcessorBlock[ProcessorNumber] = &Pcr->Prcb; + /* Get GDT and IDT descriptors */ + __sgdt(&GdtDescriptor.Limit); + __sidt(&IdtDescriptor.Limit); + Pcr->GdtBase = (PVOID)GdtDescriptor.Base; + Pcr->IdtBase = (PKIDTENTRY)IdtDescriptor.Base; + + /* Get TSS Selector */ + Ke386GetTr(Tr); // <- FIXME: this is ugly! + if (Tr != KGDT_TSS) Tr = KGDT_TSS; // FIXME: HACKHACK + + /* Get TSS Selector, mask it and get its GDT Entry */ + TssSelector = *(PKGDTENTRY)((ULONG_PTR)Pcr->GdtBase + (Tr & ~RPL_MASK)); + + /* Get the KTSS itself */ + Pcr->TssBase = (PKTSS)(ULONG_PTR)(TssSelector.BaseLow | + TssSelector.Bytes.BaseMiddle << 16 | + TssSelector.Bytes.BaseHigh << 24 | + (ULONG64)TssSelector.BaseUpper << 32); + + Pcr->Prcb.RspBase = Pcr->TssBase->Rsp0; + + /* Set DPC Stack */ + Pcr->Prcb.DpcStack = DpcStack; + + /* Setup the processor set */ + Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember; + + /* Clear DR6/7 to cleanup bootloader debugging */ + Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0; + Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 0; + + /* Set the Current Thread */ + Pcr->Prcb.CurrentThread = IdleThread;
/* Start us out at PASSIVE_LEVEL */ // Pcr->Irql = PASSIVE_LEVEL; KeSetCurrentIrql(PASSIVE_LEVEL);
- /* Set the GDT, IDT, TSS and DPC Stack */ - Pcr->GdtBase = (PVOID)Gdt; - Pcr->IdtBase = Idt; - Pcr->TssBase = Tss; - Pcr->Prcb.DpcStack = DpcStack; - - Pcr->Prcb.RspBase = Tss->Rsp0; - - /* Setup the processor set */ - Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember; - - /* Clear DR6/7 to cleanup bootloader debugging */ - Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0; - Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 0; }
VOID @@ -601,42 +617,6 @@ }
VOID -FASTCALL -KiGetMachineBootPointers(IN PKGDTENTRY *Gdt, - IN PKIDTENTRY *Idt, - IN PKIPCR *Pcr, - IN PKTSS *Tss) -{ - KDESCRIPTOR GdtDescriptor = {{0},0,0}, IdtDescriptor = {{0},0,0}; - KGDTENTRY64 TssSelector; - USHORT Tr = 0; - - /* Get GDT and IDT descriptors */ - __sgdt(&GdtDescriptor.Limit); - __sidt(&IdtDescriptor.Limit); - - /* Save IDT and GDT */ - *Gdt = (PKGDTENTRY)GdtDescriptor.Base; - *Idt = (PKIDTENTRY)IdtDescriptor.Base; - - /* Get TSS and FS Selectors */ - Ke386GetTr(Tr); - if (Tr != KGDT_TSS) Tr = KGDT_TSS; // FIXME: HACKHACK - - /* 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.Bytes.BaseMiddle << 16 | - TssSelector.Bytes.BaseHigh << 24 | - (ULONG64)TssSelector.BaseUpper << 32); -} - -// Hack -VOID KiRosPrepareForSystemStartup(ULONG, PROS_LOADER_PARAMETER_BLOCK); - -VOID NTAPI KiSystemStartup(IN ULONG_PTR Dummy, IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock) @@ -652,21 +632,16 @@ ULONG Cpu; PKTHREAD InitialThread; ULONG64 InitialStack; - PKGDTENTRY Gdt; - PKIDTENTRY Idt; -// KIDTENTRY NmiEntry, DoubleFaultEntry; - PKTSS Tss; PKIPCR Pcr;
- /* Save the loader block and get the current CPU */ + /* Save the loader block */ KeLoaderBlock = LoaderBlock;
/* Get the current CPU number */ - Cpu = KeNumberProcessors; + Cpu = KeNumberProcessors++;
/* Set active processors */ KeActiveProcessors |= 1 << Cpu; - KeNumberProcessors++;
/* LoaderBlock initialization for Cpu 0 */ if (Cpu == 0) @@ -681,6 +656,9 @@ /* Get Pcr from loader block */ Pcr = CONTAINING_RECORD(LoaderBlock->Prcb, KIPCR, Prcb);
+ /* Set the PRCB for this Processor */ + KiProcessorBlock[Cpu] = &Pcr->Prcb; + /* Set GS base */ __writemsr(X86_MSR_GSBASE, (ULONG64)Pcr); __writemsr(X86_MSR_KERNEL_GSBASE, (ULONG64)Pcr); @@ -706,23 +684,14 @@ /* Set us as the current process */ InitialThread->ApcState.Process = (PVOID)LoaderBlock->Process;
- /* Get GDT, IDT, PCR and TSS pointers */ - KiGetMachineBootPointers(&Gdt, &Idt, &Pcr, &Tss); - /* Initialize the PCR */ - KiInitializePcr(Cpu, - Pcr, - Idt, - Gdt, - Tss, - InitialThread, - KiDoubleFaultStack); - - /* Skip initial setup if this isn't the Boot CPU */ + KiInitializePcr(Pcr, Cpu, InitialThread, KiDoubleFaultStack); + + /* Initial setup for the boot CPU */ if (Cpu == 0) { /* Setup the TSS descriptors and entries */ - Ki386InitializeTss(Tss, Idt, Gdt, InitialStack); + Ki386InitializeTss(Pcr->TssBase, Pcr->GdtBase, InitialStack);
/* Setup the IDT */ KeInitExceptions(); @@ -749,7 +718,7 @@ LoaderBlock->NtBootPathName); }
- DPRINT1("Gdt = %p, Idt = %p, Pcr = %p, Tss = %p\n", Gdt, Idt, Pcr, Tss); +// DPRINT1("Gdt = %p, Idt = %p, Pcr = %p, Tss = %p\n", Gdt, Idt, Pcr, Tss);
/* Initialize the Processor with HAL */ HalInitializeProcessor(Cpu, KeLoaderBlock);