Implement KiSystemStartup in C instead of asm, implement KiSwapStack intrinsic, get rid of KiSetupStackandInitializeKernel, instead do the work in KiSystemStartupReal in C. Move Stack definitions into trap.S and get rid of the whole boot.S file. Comment out the sync loop for the moment and add a comment why it doesn't work (InterlockedBitTestAndSet64 doesn't work correctly).

svn path=/branches/ros-amd64-bringup/; revision=35518
This commit is contained in:
Timo Kreuzer
2008-08-21 21:16:57 +00:00
parent 0aaed0f738
commit 734fd03c81
5 changed files with 66 additions and 99 deletions
@@ -11,6 +11,17 @@
#if defined(__GNUC__)
ULONG64
FORCEINLINE
KiSwapStack(ULONG64 NewStack)
{
ULONG64 OldStack;
asm volatile ("movq %%rsp, %[oldstack]\n movq %[newstack], %%rsp\n"
: [oldstack] "=rm" (OldStack)
: [newstack] "rm" (NewStack));
return OldStack;
}
#define Ke386SetInterruptDescriptorTable(X) \
__asm__("lidt %0\n\t" \
: /* no outputs */ \
-86
View File
@@ -1,86 +0,0 @@
/*
* FILE: ntoskrnl/ke/i386/boot.S
* COPYRIGHT: See COPYING in the top level directory
* PURPOSE: FreeLDR Wrapper Bootstrap Code and Bootstrap Trampoline
* PROGRAMMERs: Alex Ionescu (alex@relsoft.net)
* Thomas Weidenmueller <w3seek@reactos.org>
*/
/* INCLUDES ******************************************************************/
#include <asm.h>
.intel_syntax noprefix
.code64
/* GLOBALS *******************************************************************/
.bss
.align 16
/* Kernel Boot Stack */
.globl _P0BootStack
.space KERNEL_STACK_SIZE
_P0BootStack:
/* Kernel Double-Fault and Temporary DPC Stack */
.globl _KiDoubleFaultStack
.space KERNEL_STACK_SIZE
_KiDoubleFaultStack:
/* FUNCTIONS *****************************************************************/
.global _KiSystemStartup
.text
.func KiSystemStartup
_KiSystemStartup:
/* NTLDR Boot: Call the main kernel initialization */
test rcx, 0x80000000
jnz _KiSystemStartupReal
/* FREELDR Boot: Cal the FreeLDR wrapper */
jmp _KiRosPrepareForSystemStartup
.endfunc
/**
* VOID
* KiSetupStackAndInitializeKernel(
* esp+4 = ? -> rcx
* esp+8 = ? -> rdx
* PVOID pNewstack // esp+12 = new stack -> r8
* esp+16 -> r9
* esp+20 -> rsp + 8
* esp+24 -> rsp + 16?
*/
.globl _KiSetupStackAndInitializeKernel
.func KiSetupStackAndInitializeKernel
_KiSetupStackAndInitializeKernel:
/* Save current stack */
mov rsi, rsp
/* Setup the new stack */
mov rsp, r8
sub rsp, NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH
push CR0_EM + CR0_TS + CR0_MP
/* Copy stack parameters to the new stack */
push [rsi + 16]
push [rsi + 8]
xor rbp, rbp
call _KiInitializeKernel
/* Set the priority of this thread to 0 */
mov rbx, PCR[KPCR_CURRENT_THREAD]
mov byte ptr [rbx+KTHREAD_PRIORITY], 0
/* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */
sti
mov rcx, DISPATCH_LEVEL
mov cr8, rcx
/* Set the right wait IRQL */
mov byte ptr [rbx+KTHREAD_WAIT_IRQL], DISPATCH_LEVEL;
/* Jump into the idle loop */
jmp _KiIdleLoop
.endfunc
+40 -12
View File
@@ -366,6 +366,7 @@ KiInitializePcr(IN ULONG ProcessorNumber,
/* Start us out at PASSIVE_LEVEL */
// Pcr->Irql = PASSIVE_LEVEL;
KeSetCurrentIrql(PASSIVE_LEVEL);
/* Set the GDI, IDT, TSS and DPC Stack */
Pcr->GdtBase = (PVOID)Gdt;
@@ -386,6 +387,7 @@ KiInitializeKernel(IN PKPROCESS InitProcess,
IN CCHAR Number,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
FrLdrDbgPrint("Enter KiInitializeKernel\n");
#if 0
BOOLEAN NpxPresent;
ULONG FeatureBits;
@@ -642,6 +644,17 @@ KiGetMachineBootPointers(IN PKGDTENTRY *Gdt,
(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)
{
KiRosPrepareForSystemStartup(Dummy, LoaderBlock);
}
VOID
NTAPI
KiSystemStartupReal(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
@@ -740,13 +753,15 @@ FrLdrDbgPrint("Gdt = %p, Idt = %p, Pcr = %p, Tss = %p\n", Gdt, Idt, Pcr, Tss);
// RtlCopyMemory(&Idt[8], &DoubleFaultEntry, sizeof(KIDTENTRY));
}
#if 0 // FIXME: InterlockedBitTestAndSet64 is broken! It needs to be specified
// that it should reference an absolute address!
/* Loop until we can release the freeze lock */
do
{
/* Loop until execution can continue */
while (*(volatile PKSPIN_LOCK*)&KiFreezeExecutionLock == (PVOID)1);
} while(InterlockedBitTestAndSet((PLONG)&KiFreezeExecutionLock, 0));
} while(InterlockedBitTestAndSet64((PLONG64)&KiFreezeExecutionLock, 0));
#endif
/* Setup CPU-related fields */
Pcr->Prcb.Number = Cpu;
@@ -773,16 +788,29 @@ FrLdrDbgPrint("Gdt = %p, Idt = %p, Pcr = %p, Tss = %p\n", Gdt, Idt, Pcr, Tss);
KfRaiseIrql(HIGH_LEVEL);
/* Align stack and make space for the trap frame and NPX frame */
InitialStack &= ~(KTRAP_FRAME_ALIGN - 1);
InitialStack &= ~(16 - 1);
FrLdrDbgPrint("Before KiSetupStackAndInitializeKernel\n");
for(;;);
/* Switch to new kernel Stack */
KiSwapStack(InitialStack);
/* Switch to new kernel stack and start kernel bootstrapping */
KiSetupStackAndInitializeKernel(&KiInitialProcess.Pcb,
InitialThread,
(PVOID)InitialStack,
&Pcr->Prcb,
(CCHAR)Cpu,
KeLoaderBlock);
/* Initialize kernel */
KiInitializeKernel(&KiInitialProcess.Pcb,
InitialThread,
(PVOID)InitialStack,
&Pcr->Prcb,
(CCHAR)Cpu,
KeLoaderBlock);
/* Set the priority of this thread to 0 */
InitialThread->Priority = 0;
/* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */
_enable();
KeLowerIrql(DISPATCH_LEVEL);
/* Set the right wait IRQL */
InitialThread->WaitIrql = DISPATCH_LEVEL;
/* Jump into the idle loop */
KiIdleLoop();
}
+15
View File
@@ -13,8 +13,23 @@
.intel_syntax noprefix
.code64
#define KERNEL_STACK_SIZE 0x6000
/* GLOBALS *******************************************************************/
.bss
.align 16
/* Kernel Boot Stack */
.globl _P0BootStack
.space KERNEL_STACK_SIZE
_P0BootStack:
/* Kernel Double-Fault and Temporary DPC Stack */
.globl _KiDoubleFaultStack
.space KERNEL_STACK_SIZE
_KiDoubleFaultStack:
.data
_MsgGeneralProtFault:
@@ -90,7 +90,6 @@
</if>
<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>