2011-02-21 11:23:58 +00:00
|
|
|
#include "types.h"
|
2011-08-27 23:07:51 +00:00
|
|
|
#include "version.h"
|
2011-08-25 17:56:32 +00:00
|
|
|
#include "load_context.h"
|
2011-02-21 11:23:58 +00:00
|
|
|
#include "Tier0/kstdio.h"
|
2011-08-27 17:43:37 +00:00
|
|
|
#include "Tier0/kstdlib.h"
|
2011-08-27 20:08:59 +00:00
|
|
|
#include "Tier0/gdt.h"
|
2011-02-21 11:23:58 +00:00
|
|
|
#include "Tier0/paging.h"
|
2011-08-27 20:17:54 +00:00
|
|
|
#include "Tier0/acpi.h"
|
2011-08-28 23:42:26 +00:00
|
|
|
#include "Tier0/apic.h"
|
2011-08-28 11:01:47 +00:00
|
|
|
#include "Tier0/smp.h"
|
2012-05-08 12:57:44 +00:00
|
|
|
#include "Tier0/interrupts.h"
|
2011-07-02 11:03:29 +00:00
|
|
|
//#include "Tier0/ps2.h"
|
2011-02-23 03:12:36 +00:00
|
|
|
#include "Tier0/system.h"
|
2011-07-02 11:03:29 +00:00
|
|
|
//#include "Tier0/pic.h"
|
|
|
|
//#include "Tier0/kbd_layout.h"
|
2011-08-25 18:06:16 +00:00
|
|
|
#include "Tier0/physmem.h"
|
2012-05-08 13:35:12 +00:00
|
|
|
#include "Tier0/heap.h"
|
2012-10-01 13:03:10 +00:00
|
|
|
#include "Tier0/cpp.h"
|
2012-05-08 12:57:44 +00:00
|
|
|
#include "Tier0/exceptions.h"
|
2011-08-25 17:56:32 +00:00
|
|
|
#include "Tier0/panic.h"
|
2011-07-02 11:03:29 +00:00
|
|
|
//#include "Tier0/prng.h"
|
|
|
|
|
2012-05-08 12:57:44 +00:00
|
|
|
void kmain_newstack(void);
|
2012-05-07 16:53:06 +00:00
|
|
|
|
2011-06-28 11:15:42 +00:00
|
|
|
// Real kernel entry point, called from loader
|
2011-08-25 17:56:32 +00:00
|
|
|
void kmain(u32 LoadContextAddress)
|
2011-02-20 22:38:15 +00:00
|
|
|
{
|
2013-07-05 12:48:24 +00:00
|
|
|
for(;;){}
|
2011-08-25 17:56:32 +00:00
|
|
|
T_LOAD_CONTEXT *LoadContext = (T_LOAD_CONTEXT*)(u64)LoadContextAddress;
|
2011-04-04 16:25:20 +00:00
|
|
|
kstdio_init();
|
2011-08-25 17:56:32 +00:00
|
|
|
|
|
|
|
if (LoadContext->VGATextModeUsed)
|
|
|
|
kstdio_set_globals(LoadContext->VGACurrentLine, LoadContext->VGACursorX, LoadContext->VGACursorY);
|
|
|
|
else
|
|
|
|
kclear();
|
|
|
|
|
2011-08-27 17:43:37 +00:00
|
|
|
kprintf(" _ \n"
|
2011-02-22 17:09:58 +00:00
|
|
|
" ___ _ _ ___ _ _ _____| |_ ___ ___ \n"
|
|
|
|
" | _| | | _| | | | . | -_| _|\n"
|
|
|
|
" |___|___|___|___|_|_|_|___|___|_| \n\n");
|
2011-06-28 11:15:42 +00:00
|
|
|
kprintf("[i] Welcome to Cucumber (x86-64)!\n");
|
2011-08-27 23:07:51 +00:00
|
|
|
kprintf("[i] %s\n\n", CUCUMBER_VERION);
|
2011-08-25 17:56:32 +00:00
|
|
|
kprintf("[i] Load Context @%x \n", LoadContext);
|
|
|
|
if (!LoadContext->MultibootUsed)
|
|
|
|
PANIC("No Multiboot header provided by loader!");
|
2011-06-28 11:15:42 +00:00
|
|
|
|
2011-08-25 17:56:32 +00:00
|
|
|
kprintf("[i] Multiboot header @%x\n", LoadContext->MultibootHeader);
|
2011-08-28 23:42:26 +00:00
|
|
|
|
2011-08-28 16:06:40 +00:00
|
|
|
system_parse_cpu_features();
|
2011-08-28 23:42:26 +00:00
|
|
|
|
|
|
|
extern T_SYSTEM_INFO g_SystemInfo;
|
|
|
|
if (!CPUID_HAS(FPU))
|
|
|
|
PANIC("CPU doesn't have FPU!");
|
|
|
|
if (!CPUID_HAS(MSR))
|
|
|
|
PANIC("CPU doesn't support MSR!");
|
|
|
|
if (!CPUID_HAS(APIC))
|
|
|
|
PANIC("CPU doesn't support APIC!");
|
|
|
|
|
2012-10-30 14:37:51 +00:00
|
|
|
system_parse_load_context(LoadContext);
|
2011-08-25 17:56:32 +00:00
|
|
|
kprintf("[i] Booting via %s.\n", LoadContext->LoaderName);
|
2011-07-02 11:03:29 +00:00
|
|
|
kprintf("[i] Memory available: %uk.\n", system_get_memory_upper());
|
2012-10-30 11:34:20 +00:00
|
|
|
kprintf("[i] Kernel physical: %x-%x.\n", system_get_kernel_physical_start(),
|
|
|
|
system_get_kernel_physical_start() + system_get_kernel_size());
|
2011-08-27 13:11:48 +00:00
|
|
|
kprintf("[i] Loader physical: %x-%x.\n", LoadContext->LoaderPhysicalStart, LoadContext->LoaderPhysicalEnd);
|
2012-10-30 11:34:20 +00:00
|
|
|
kprintf("[i] Kernel virtual: %x-%x.\n", system_get_kernel_virtual_start(),
|
|
|
|
system_get_kernel_virtual_start() + system_get_kernel_size());
|
2011-06-28 11:15:42 +00:00
|
|
|
|
2012-10-30 11:27:12 +00:00
|
|
|
paging_temp_page_setup();
|
2012-10-30 14:37:51 +00:00
|
|
|
physmem_init();
|
2012-10-30 15:35:01 +00:00
|
|
|
paging_scratch_initialize();
|
2012-05-08 12:57:44 +00:00
|
|
|
// Let's create a new kernel stack
|
2013-02-03 13:38:48 +00:00
|
|
|
u64 StackVirtual = (u64)paging_scratch_allocate();
|
2012-05-08 12:57:44 +00:00
|
|
|
kprintf("[i] New kernel stack 0x%x\n", StackVirtual);
|
|
|
|
|
|
|
|
// And now let's use it and forget ebp because we can.
|
|
|
|
__asm__ volatile("mov %0, %%rsp" : : "r" (StackVirtual + 4096));
|
|
|
|
|
|
|
|
// And let's create a new stack frame.
|
|
|
|
// (and prevent gcc from inlinin the function call)
|
|
|
|
void (*kmain_newstack_ptr)() = kmain_newstack;
|
|
|
|
kmain_newstack_ptr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void kmain_newstack(void)
|
|
|
|
{
|
2011-08-27 20:08:59 +00:00
|
|
|
|
2011-08-27 20:17:54 +00:00
|
|
|
u64 RSDPAddress = acpi_find_rsdp();
|
2011-02-22 17:09:58 +00:00
|
|
|
if (RSDPAddress == 0)
|
2012-10-30 11:36:42 +00:00
|
|
|
PANIC("ACPI not supported! What is this, 1999?");
|
2011-08-27 20:17:54 +00:00
|
|
|
|
2013-02-03 13:38:48 +00:00
|
|
|
//smp_initialize();
|
2012-05-07 16:53:06 +00:00
|
|
|
interrupts_init_simple();
|
2012-05-08 12:57:44 +00:00
|
|
|
exceptions_init_simple();
|
2012-07-09 10:45:27 +00:00
|
|
|
apic_enable_lapic();
|
2012-05-08 13:35:12 +00:00
|
|
|
heap_init_simple();
|
2012-07-20 22:00:19 +00:00
|
|
|
// enable FPU/SSE...
|
|
|
|
__asm__ volatile(
|
|
|
|
"movq %cr0, %rax;"
|
|
|
|
"and $0xfffb, %ax;"
|
|
|
|
"or $0x2, %rax;"
|
|
|
|
"movq %rax, %cr0;"
|
|
|
|
"movq %cr4, %rax;"
|
2012-07-20 22:02:56 +00:00
|
|
|
"orq $0x600, %rax;"
|
2012-07-20 22:00:19 +00:00
|
|
|
"movq %rax, %cr4;");
|
2012-10-01 13:03:10 +00:00
|
|
|
|
|
|
|
cpp_call_ctors();
|
|
|
|
cpp_start_ckernel();
|
|
|
|
kprintf("[i] Returned from Tier1, sleeping forever.\n");
|
2012-10-30 14:37:51 +00:00
|
|
|
kprintf("[i] Free memory: %i KiB.\n", physmem_get_free());
|
2012-10-01 13:03:10 +00:00
|
|
|
LOOPFOREVER;
|
2012-05-08 12:57:44 +00:00
|
|
|
}
|