revert my last change, yes it IS a stupid idea to mess with the stack in the middle of a C function....

svn path=/branches/ros-amd64-bringup/; revision=35524
This commit is contained in:
Timo Kreuzer
2008-08-22 10:07:57 +00:00
parent 734fd03c81
commit 3c6891fdc8
5 changed files with 99 additions and 66 deletions
@@ -11,17 +11,6 @@
#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
@@ -0,0 +1,86 @@
/*
* 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
+12 -40
View File
@@ -366,7 +366,6 @@ 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;
@@ -387,7 +386,6 @@ KiInitializeKernel(IN PKPROCESS InitProcess,
IN CCHAR Number,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
FrLdrDbgPrint("Enter KiInitializeKernel\n");
#if 0
BOOLEAN NpxPresent;
ULONG FeatureBits;
@@ -644,17 +642,6 @@ 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)
@@ -753,15 +740,13 @@ 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(InterlockedBitTestAndSet64((PLONG64)&KiFreezeExecutionLock, 0));
#endif
} while(InterlockedBitTestAndSet((PLONG)&KiFreezeExecutionLock, 0));
/* Setup CPU-related fields */
Pcr->Prcb.Number = Cpu;
@@ -788,29 +773,16 @@ 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 &= ~(16 - 1);
InitialStack &= ~(KTRAP_FRAME_ALIGN - 1);
/* Switch to new kernel Stack */
KiSwapStack(InitialStack);
FrLdrDbgPrint("Before KiSetupStackAndInitializeKernel\n");
for(;;);
/* 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();
/* Switch to new kernel stack and start kernel bootstrapping */
KiSetupStackAndInitializeKernel(&KiInitialProcess.Pcb,
InitialThread,
(PVOID)InitialStack,
&Pcr->Prcb,
(CCHAR)Cpu,
KeLoaderBlock);
}
-15
View File
@@ -13,23 +13,8 @@
.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,6 +90,7 @@
</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>