forked from xt-sys/exectos
Switch kernel stack and move boot structures initialization into separate routine
This commit is contained in:
48
xtoskrnl/ke/amd64/krnlinit.c
Normal file
48
xtoskrnl/ke/amd64/krnlinit.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/ke/amd64/krnlinit.c
|
||||
* DESCRIPTION: CPU architecture specific kernel initialization
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
|
||||
|
||||
/**
|
||||
* This routine starts up the XT kernel. It is called after switching boot stack.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepStartKernel(VOID)
|
||||
{
|
||||
LdrPrint(L"Hello from new kernel stack!\n");
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to a new kernel boot stack.
|
||||
*
|
||||
* @return This routine does not return any value
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepSwitchBootStack(IN ULONG_PTR Stack)
|
||||
{
|
||||
/* Discard old stack frame, switch stack and jump to KepStartKernel() */
|
||||
asm volatile("mov %0, %%rdx\n"
|
||||
"xor %%rbp, %%rbp\n"
|
||||
"mov %%rdx, %%rsp\n"
|
||||
"sub %1, %%rsp\n"
|
||||
"jmp KepStartKernel\n"
|
||||
:
|
||||
: "m" (Stack),
|
||||
"i" (FLOATING_SAVE_AREA_SIZE | KEXCEPTION_FRAME_SIZE | KSWITCH_FRAME_SIZE),
|
||||
"p" (KepStartKernel));
|
||||
}
|
50
xtoskrnl/ke/i686/krnlinit.c
Normal file
50
xtoskrnl/ke/i686/krnlinit.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/ke/i686/krnlinit.c
|
||||
* DESCRIPTION: CPU architecture specific kernel initialization
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
|
||||
|
||||
/**
|
||||
* This routine starts up the XT kernel. It is called after switching boot stack.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepStartKernel(VOID)
|
||||
{
|
||||
LdrPrint(L"Hello from new kernel stack!\n");
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to a new kernel boot stack.
|
||||
*
|
||||
* @return This routine does not return any value
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepSwitchBootStack(IN ULONG_PTR Stack)
|
||||
{
|
||||
/* Discard old stack frame, switch stack, make space for NPX and jump to KepStartKernel() */
|
||||
asm volatile("mov %0, %%edx\n"
|
||||
"xor %%ebp, %%ebp\n"
|
||||
"mov %%edx, %%esp\n"
|
||||
"sub %1, %%esp\n"
|
||||
"push %2\n"
|
||||
"jmp _KepStartKernel@0\n"
|
||||
:
|
||||
: "m" (Stack),
|
||||
"i" (KTRAP_FRAME_ALIGN | KTRAP_FRAME_SIZE | NPX_FRAME_SIZE),
|
||||
"i" (CR0_EM | CR0_MP | CR0_TS),
|
||||
"p" (KepStartKernel));
|
||||
}
|
@@ -45,6 +45,27 @@ KeStartXtSystem(IN PKERNEL_INITIALIZATION_BLOCK Parameters)
|
||||
);
|
||||
|
||||
|
||||
/* Initialize kernel boot structures */
|
||||
KepInitializeBootStructures(Parameters);
|
||||
|
||||
/* Switch boot stack alligning it to 4 byte boundary */
|
||||
KepSwitchBootStack(KeInitializationBlock->KernelBootStack & ~0x3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes boot structures needed by the kernel startup code.
|
||||
*
|
||||
* @param Parameters
|
||||
* Supplies a pointer to memory area containing parameters passed to kernel by bootloader.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepInitializeBootStructures(IN PKERNEL_INITIALIZATION_BLOCK Parameters)
|
||||
{
|
||||
/* Make sure kernel boot stack is initialized */
|
||||
if(!Parameters->KernelBootStack)
|
||||
{
|
||||
|
Reference in New Issue
Block a user