mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 12:24:21 +00:00
Cleanup kernel init code a bit
svn path=/branches/ros-amd64-bringup/; revision=43552
This commit is contained in:
parent
036ea51418
commit
0fb6c8265c
4 changed files with 51 additions and 163 deletions
|
@ -1,81 +0,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__,
|
|
||||||
|
|
|
@ -108,12 +108,14 @@ KiInitializeGdt(struct _KPCR* Pcr);
|
||||||
VOID
|
VOID
|
||||||
Ki386ApplicationProcessorInitializeTSS(VOID);
|
Ki386ApplicationProcessorInitializeTSS(VOID);
|
||||||
|
|
||||||
|
// Hack
|
||||||
|
VOID KiRosPrepareForSystemStartup(ULONG, PROS_LOADER_PARAMETER_BLOCK);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
FASTCALL
|
FASTCALL
|
||||||
Ki386InitializeTss(
|
Ki386InitializeTss(
|
||||||
IN PKTSS Tss,
|
IN PKTSS Tss,
|
||||||
IN PKIDTENTRY Idt,
|
IN PVOID GdtBase,
|
||||||
IN PKGDTENTRY Gdt,
|
|
||||||
IN UINT64 Stack
|
IN UINT64 Stack
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -387,18 +387,16 @@ KiGetCacheInformation(VOID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
FASTCALL
|
FASTCALL
|
||||||
Ki386InitializeTss(IN PKTSS64 Tss,
|
Ki386InitializeTss(IN PKTSS64 Tss,
|
||||||
IN PKIDTENTRY Idt,
|
IN PVOID GdtBase,
|
||||||
IN PKGDTENTRY Gdt,
|
|
||||||
IN UINT64 Stack)
|
IN UINT64 Stack)
|
||||||
{
|
{
|
||||||
PKGDTENTRY64 TssEntry;
|
PKGDTENTRY64 TssEntry;
|
||||||
|
|
||||||
/* Initialize the TSS descriptor entry */
|
/* 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.Type = 9;//AMD64_TSS;
|
||||||
TssEntry->Bits.Dpl = 0;
|
TssEntry->Bits.Dpl = 0;
|
||||||
TssEntry->Bits.Present = 1;
|
TssEntry->Bits.Present = 1;
|
||||||
|
|
|
@ -328,18 +328,17 @@ KiInitMachineDependent(VOID)
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
KiInitializePcr(IN ULONG ProcessorNumber,
|
KiInitializePcr(IN PKIPCR Pcr,
|
||||||
IN PKIPCR Pcr,
|
IN ULONG ProcessorNumber,
|
||||||
IN PKIDTENTRY Idt,
|
|
||||||
IN PKGDTENTRY Gdt,
|
|
||||||
IN PKTSS Tss,
|
|
||||||
IN PKTHREAD IdleThread,
|
IN PKTHREAD IdleThread,
|
||||||
IN PVOID DpcStack)
|
IN PVOID DpcStack)
|
||||||
{
|
{
|
||||||
RtlZeroMemory(Pcr, PAGE_SIZE);
|
KDESCRIPTOR GdtDescriptor = {{0},0,0}, IdtDescriptor = {{0},0,0};
|
||||||
|
KGDTENTRY64 TssSelector;
|
||||||
|
USHORT Tr = 0;
|
||||||
|
|
||||||
/* Set the Current Thread */
|
/* Zero out the PCR */
|
||||||
Pcr->Prcb.CurrentThread = IdleThread;
|
RtlZeroMemory(Pcr, PAGE_SIZE);
|
||||||
|
|
||||||
/* Set pointers to ourselves */
|
/* Set pointers to ourselves */
|
||||||
Pcr->Self = (PKPCR)Pcr;
|
Pcr->Self = (PKPCR)Pcr;
|
||||||
|
@ -349,7 +348,7 @@ KiInitializePcr(IN ULONG ProcessorNumber,
|
||||||
Pcr->MajorVersion = PCR_MAJOR_VERSION;
|
Pcr->MajorVersion = PCR_MAJOR_VERSION;
|
||||||
Pcr->MinorVersion = PCR_MINOR_VERSION;
|
Pcr->MinorVersion = PCR_MINOR_VERSION;
|
||||||
|
|
||||||
/* Set the PCRB Version */
|
/* Set the PRCB Version */
|
||||||
Pcr->Prcb.MajorVersion = 1;
|
Pcr->Prcb.MajorVersion = 1;
|
||||||
Pcr->Prcb.MinorVersion = 1;
|
Pcr->Prcb.MinorVersion = 1;
|
||||||
|
|
||||||
|
@ -366,27 +365,44 @@ KiInitializePcr(IN ULONG ProcessorNumber,
|
||||||
Pcr->Prcb.Number = (UCHAR)ProcessorNumber;
|
Pcr->Prcb.Number = (UCHAR)ProcessorNumber;
|
||||||
Pcr->Prcb.SetMember = 1 << ProcessorNumber;
|
Pcr->Prcb.SetMember = 1 << ProcessorNumber;
|
||||||
|
|
||||||
/* Set the PRCB for this Processor */
|
/* Get GDT and IDT descriptors */
|
||||||
KiProcessorBlock[ProcessorNumber] = &Pcr->Prcb;
|
__sgdt(&GdtDescriptor.Limit);
|
||||||
|
__sidt(&IdtDescriptor.Limit);
|
||||||
|
Pcr->GdtBase = (PVOID)GdtDescriptor.Base;
|
||||||
|
Pcr->IdtBase = (PKIDTENTRY)IdtDescriptor.Base;
|
||||||
|
|
||||||
/* Start us out at PASSIVE_LEVEL */
|
/* Get TSS Selector */
|
||||||
// Pcr->Irql = PASSIVE_LEVEL;
|
Ke386GetTr(Tr); // <- FIXME: this is ugly!
|
||||||
KeSetCurrentIrql(PASSIVE_LEVEL);
|
if (Tr != KGDT_TSS) Tr = KGDT_TSS; // FIXME: HACKHACK
|
||||||
|
|
||||||
/* Set the GDT, IDT, TSS and DPC Stack */
|
/* Get TSS Selector, mask it and get its GDT Entry */
|
||||||
Pcr->GdtBase = (PVOID)Gdt;
|
TssSelector = *(PKGDTENTRY)((ULONG_PTR)Pcr->GdtBase + (Tr & ~RPL_MASK));
|
||||||
Pcr->IdtBase = Idt;
|
|
||||||
Pcr->TssBase = Tss;
|
/* 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;
|
Pcr->Prcb.DpcStack = DpcStack;
|
||||||
|
|
||||||
Pcr->Prcb.RspBase = Tss->Rsp0;
|
|
||||||
|
|
||||||
/* Setup the processor set */
|
/* Setup the processor set */
|
||||||
Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember;
|
Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember;
|
||||||
|
|
||||||
/* Clear DR6/7 to cleanup bootloader debugging */
|
/* Clear DR6/7 to cleanup bootloader debugging */
|
||||||
Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0;
|
Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0;
|
||||||
Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -600,42 +616,6 @@ KiInitializeKernel(IN PKPROCESS InitProcess,
|
||||||
LoaderBlock->Prcb = 0;
|
LoaderBlock->Prcb = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
KiSystemStartup(IN ULONG_PTR Dummy,
|
KiSystemStartup(IN ULONG_PTR Dummy,
|
||||||
|
@ -652,21 +632,16 @@ KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
||||||
ULONG Cpu;
|
ULONG Cpu;
|
||||||
PKTHREAD InitialThread;
|
PKTHREAD InitialThread;
|
||||||
ULONG64 InitialStack;
|
ULONG64 InitialStack;
|
||||||
PKGDTENTRY Gdt;
|
|
||||||
PKIDTENTRY Idt;
|
|
||||||
// KIDTENTRY NmiEntry, DoubleFaultEntry;
|
|
||||||
PKTSS Tss;
|
|
||||||
PKIPCR Pcr;
|
PKIPCR Pcr;
|
||||||
|
|
||||||
/* Save the loader block and get the current CPU */
|
/* Save the loader block */
|
||||||
KeLoaderBlock = LoaderBlock;
|
KeLoaderBlock = LoaderBlock;
|
||||||
|
|
||||||
/* Get the current CPU number */
|
/* Get the current CPU number */
|
||||||
Cpu = KeNumberProcessors;
|
Cpu = KeNumberProcessors++;
|
||||||
|
|
||||||
/* Set active processors */
|
/* Set active processors */
|
||||||
KeActiveProcessors |= 1 << Cpu;
|
KeActiveProcessors |= 1 << Cpu;
|
||||||
KeNumberProcessors++;
|
|
||||||
|
|
||||||
/* LoaderBlock initialization for Cpu 0 */
|
/* LoaderBlock initialization for Cpu 0 */
|
||||||
if (Cpu == 0)
|
if (Cpu == 0)
|
||||||
|
@ -681,6 +656,9 @@ KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
||||||
/* Get Pcr from loader block */
|
/* Get Pcr from loader block */
|
||||||
Pcr = CONTAINING_RECORD(LoaderBlock->Prcb, KIPCR, Prcb);
|
Pcr = CONTAINING_RECORD(LoaderBlock->Prcb, KIPCR, Prcb);
|
||||||
|
|
||||||
|
/* Set the PRCB for this Processor */
|
||||||
|
KiProcessorBlock[Cpu] = &Pcr->Prcb;
|
||||||
|
|
||||||
/* Set GS base */
|
/* Set GS base */
|
||||||
__writemsr(X86_MSR_GSBASE, (ULONG64)Pcr);
|
__writemsr(X86_MSR_GSBASE, (ULONG64)Pcr);
|
||||||
__writemsr(X86_MSR_KERNEL_GSBASE, (ULONG64)Pcr);
|
__writemsr(X86_MSR_KERNEL_GSBASE, (ULONG64)Pcr);
|
||||||
|
@ -706,23 +684,14 @@ KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
||||||
/* Set us as the current process */
|
/* Set us as the current process */
|
||||||
InitialThread->ApcState.Process = (PVOID)LoaderBlock->Process;
|
InitialThread->ApcState.Process = (PVOID)LoaderBlock->Process;
|
||||||
|
|
||||||
/* Get GDT, IDT, PCR and TSS pointers */
|
|
||||||
KiGetMachineBootPointers(&Gdt, &Idt, &Pcr, &Tss);
|
|
||||||
|
|
||||||
/* Initialize the PCR */
|
/* Initialize the PCR */
|
||||||
KiInitializePcr(Cpu,
|
KiInitializePcr(Pcr, Cpu, InitialThread, KiDoubleFaultStack);
|
||||||
Pcr,
|
|
||||||
Idt,
|
|
||||||
Gdt,
|
|
||||||
Tss,
|
|
||||||
InitialThread,
|
|
||||||
KiDoubleFaultStack);
|
|
||||||
|
|
||||||
/* Skip initial setup if this isn't the Boot CPU */
|
/* Initial setup for the boot CPU */
|
||||||
if (Cpu == 0)
|
if (Cpu == 0)
|
||||||
{
|
{
|
||||||
/* Setup the TSS descriptors and entries */
|
/* Setup the TSS descriptors and entries */
|
||||||
Ki386InitializeTss(Tss, Idt, Gdt, InitialStack);
|
Ki386InitializeTss(Pcr->TssBase, Pcr->GdtBase, InitialStack);
|
||||||
|
|
||||||
/* Setup the IDT */
|
/* Setup the IDT */
|
||||||
KeInitExceptions();
|
KeInitExceptions();
|
||||||
|
@ -749,7 +718,7 @@ KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
||||||
LoaderBlock->NtBootPathName);
|
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 */
|
/* Initialize the Processor with HAL */
|
||||||
HalInitializeProcessor(Cpu, KeLoaderBlock);
|
HalInitializeProcessor(Cpu, KeLoaderBlock);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue