2011-02-21 11:23:58 +00:00
|
|
|
#include "types.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-07-02 11:03:29 +00:00
|
|
|
//#include "Tier0/acpi.h"
|
|
|
|
//#include "Tier0/interrupts.h"
|
|
|
|
//#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"
|
2011-07-02 11:03:29 +00:00
|
|
|
//#include "Tier0/heap.h"
|
|
|
|
//#include "Tier0/cpp.h"
|
|
|
|
//#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"
|
|
|
|
|
2011-08-25 17:56:32 +00:00
|
|
|
extern u64 _start;
|
2011-07-02 11:03:29 +00:00
|
|
|
extern u64 _end;
|
2011-03-13 14:18:08 +00:00
|
|
|
|
2011-08-27 17:43:37 +00:00
|
|
|
u8 test[4096 * 2];
|
|
|
|
u8 test2[4096 * 2];
|
|
|
|
|
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
|
|
|
{
|
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-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);
|
|
|
|
system_parse_load_context(LoadContext);
|
|
|
|
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());
|
2011-08-25 17:56:32 +00:00
|
|
|
kprintf("[i] Kernel physical: %x-%x.\n", LoadContext->KernelPhysicalStart, LoadContext->KernelPhysicalEnd);
|
2011-08-27 13:11:48 +00:00
|
|
|
kprintf("[i] Loader physical: %x-%x.\n", LoadContext->LoaderPhysicalStart, LoadContext->LoaderPhysicalEnd);
|
2011-08-25 17:56:32 +00:00
|
|
|
kprintf("[i] Kernel virtual: %x-%x.\n", &_start, &_end);
|
2011-06-28 11:15:42 +00:00
|
|
|
|
2011-08-27 17:43:37 +00:00
|
|
|
paging_temp_page_setup(LoadContext);
|
2011-08-27 20:08:59 +00:00
|
|
|
|
|
|
|
// Not using GDT in 64-bit mode... We'll use the loader-provided one.
|
2011-08-27 17:43:37 +00:00
|
|
|
//gdt_create_flat();
|
2011-08-27 13:11:48 +00:00
|
|
|
|
2011-07-02 11:03:29 +00:00
|
|
|
for (;;) {}
|
2011-03-18 14:09:49 +00:00
|
|
|
|
2011-03-13 21:59:28 +00:00
|
|
|
//Add kernel memory as reserved.
|
2011-08-27 17:43:37 +00:00
|
|
|
/*physmem_mark_as_used(0);
|
2011-03-13 21:59:28 +00:00
|
|
|
physmem_mark_as_used(1);
|
|
|
|
|
2011-02-23 03:12:36 +00:00
|
|
|
kprintf("[i] Booting via %s.\n", system_get_bootloader_name());
|
|
|
|
kprintf("[i] Memory available: %uk.\n", system_get_memory_upper());
|
2011-03-13 14:18:08 +00:00
|
|
|
|
2011-02-22 17:09:58 +00:00
|
|
|
u32 RSDPAddress = acpi_find_rsdp();
|
|
|
|
if (RSDPAddress == 0)
|
|
|
|
{
|
|
|
|
kprintf("[e] Fatal! ACPI not found.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
interrupts_init_simple();
|
2011-03-16 07:33:27 +00:00
|
|
|
exceptions_init_simple();
|
2011-03-13 14:18:08 +00:00
|
|
|
pic_init(0, 0);
|
|
|
|
ps2_init_simple();
|
2011-03-13 17:32:05 +00:00
|
|
|
kbd_layout_set_default();
|
2011-03-13 14:18:08 +00:00
|
|
|
|
|
|
|
__asm__ volatile("sti");
|
|
|
|
|
2011-03-13 17:32:05 +00:00
|
|
|
kprintf("[i] Hardware interrupts are now enabled.\n");
|
|
|
|
|
2011-03-14 16:49:22 +00:00
|
|
|
heap_init_simple();
|
2011-03-14 19:31:10 +00:00
|
|
|
|
2011-04-03 16:49:04 +00:00
|
|
|
kprintf("[i] Initializing PRNG...\n");
|
|
|
|
u16 RLow, RHigh;
|
|
|
|
__asm__ __volatile__ ("rdtsc" : "=a" (RLow), "=d" (RHigh));
|
|
|
|
u32 R = (RHigh << 16) | RLow;
|
|
|
|
kprintf("[i] %i\n", R);
|
|
|
|
kseed(R);
|
|
|
|
for (u32 Rl = 0; Rl < R; Rl++)
|
|
|
|
{
|
|
|
|
krand();
|
|
|
|
}
|
2011-04-01 19:51:14 +00:00
|
|
|
|
2011-04-03 16:49:04 +00:00
|
|
|
// Let's create a new kernel stack
|
|
|
|
u32 StackPhysical = physmem_allocate_page() * 1024 * 4;
|
|
|
|
paging_map_kernel_page(0xA0000000, StackPhysical);
|
2011-04-01 19:51:14 +00:00
|
|
|
|
|
|
|
// And now let's use it and forget ebp because we can.
|
2011-04-03 16:49:04 +00:00
|
|
|
__asm__ volatile("mov %0, %%esp" : : "r" (0xA0000000 + 4095));
|
2011-04-01 19:51:14 +00:00
|
|
|
|
2011-04-03 16:49:04 +00:00
|
|
|
// This automagically creates a new usable stack frame
|
2011-06-28 11:15:42 +00:00
|
|
|
kmain_newstack();*/
|
2011-04-01 19:51:14 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 11:15:42 +00:00
|
|
|
/*void kmain_newstack(void)
|
2011-04-01 19:51:14 +00:00
|
|
|
{
|
|
|
|
kprintf("[i] Now using real stack...\n");
|
2011-03-14 19:31:10 +00:00
|
|
|
cpp_call_ctors();
|
|
|
|
cpp_start_ckernel();
|
|
|
|
kprintf("[i] Returned from Tier1, sleeping forever.\n");
|
2011-03-13 14:18:08 +00:00
|
|
|
LOOPFOREVER;
|
2011-06-28 11:15:42 +00:00
|
|
|
}*/
|