diff options
Diffstat (limited to 'src/kernel/core')
-rw-r--r-- | src/kernel/core/kmain.cpp | 49 | ||||
-rw-r--r-- | src/kernel/core/sys.cpp | 15 |
2 files changed, 31 insertions, 33 deletions
diff --git a/src/kernel/core/kmain.cpp b/src/kernel/core/kmain.cpp index e74ff33..f745fdf 100644 --- a/src/kernel/core/kmain.cpp +++ b/src/kernel/core/kmain.cpp @@ -3,16 +3,19 @@ #include "multiboot.h" #include "sys.h" -#include <dev/vgatxt.h> -#include <task/idt.h> -#include <task/timer.h> -#include <task/task.h> #include <mem/gdt.h> #include <mem/paging.h> #include <mem/mem.h> -#include <linker/elf.h> + #include <vfs/node.h> + +#include <task/idt.h> +#include <task/timer.h> +#include <task/task.h> +#include <linker/elf.h> + #include <ui/vt.h> +#include <dev/vgatxt.h> #include <dev/ps2keyboard.h> /* The kernel's main procedure. This function is called in loader_.asm. @@ -23,13 +26,10 @@ extern "C" void kmain(multiboot_info_t* mbd, int32_t magic) { ASSERT(magic == MULTIBOOT_BOOTLOADER_MAGIC); - size_t totalRam = 0; - uint32_t i; - mem_placementAddr = ((size_t)&end & 0xFFFFF000) + 0x1000; mbd->cmdline += K_HIGHHALF_ADDR; mbd->mods_addr += K_HIGHHALF_ADDR; module_t *mods = (module_t*)mbd->mods_addr; - for (i = 0; i < mbd->mods_count; i++) { + for (unsigned i = 0; i < mbd->mods_count; i++) { mods[i].mod_start += K_HIGHHALF_ADDR; mods[i].mod_end += K_HIGHHALF_ADDR; mods[i].string += K_HIGHHALF_ADDR; @@ -40,7 +40,7 @@ extern "C" void kmain(multiboot_info_t* mbd, int32_t magic) { // Init memory managment functions idt_init(); - totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024); + size_t totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024); paging_init(totalRam); gdt_init(); paging_cleanup(); @@ -60,36 +60,35 @@ extern "C" void kmain(multiboot_info_t* mbd, int32_t magic) { // Say hello ke_vt->fgcolor = TC_LIGHTGRAY; - ke_vt->writeStr("Hello. This is "); - ke_vt->fgcolor = TC_WHITE; ke_vt->writeStr(K_OS_NAME); - ke_vt->fgcolor = TC_LIGHTGRAY; ke_vt->writeStr(" version "); - ke_vt->fgcolor = TC_WHITE; ke_vt->writeStr(K_OS_VER); - ke_vt->fgcolor = TC_LIGHTGRAY; ke_vt->writeStr(" codename '"); - ke_vt->fgcolor = TC_WHITE; ke_vt->writeStr(K_OS_CODENAME); - ke_vt->fgcolor = TC_LIGHTGRAY; ke_vt->writeStr("'. Enjoy!\n"); + *ke_vt << "Hello. This is "; + ke_vt->fgcolor = TC_WHITE; *ke_vt << K_OS_NAME; + ke_vt->fgcolor = TC_LIGHTGRAY; *ke_vt << " version "; + ke_vt->fgcolor = TC_WHITE; *ke_vt << K_OS_VER; + ke_vt->fgcolor = TC_LIGHTGRAY; *ke_vt << " codename '"; + ke_vt->fgcolor = TC_WHITE; *ke_vt << K_OS_CODENAME; + ke_vt->fgcolor = TC_LIGHTGRAY; *ke_vt << "'. Enjoy!\n"; // Init devices kbd = new ps2kbd(dot_dev); dot_dev->add_child("ps2kbd", kbd); // Load modules - ke_vt->writeStr("Loading modules :\n"); - for (i = 0; i < mbd->mods_count; i++) { - ke_vt->writeStr(" * "); - ke_vt->writeStr((char*)mods[i].string); + *ke_vt << "Loading modules :\n"; + for (unsigned i = 0; i < mbd->mods_count; i++) { + *ke_vt << " * " << (char*)mods[i].string; if (elf_check((uint8_t*)mods[i].mod_start)) { - ke_vt->writeStr(" : Invalid ELF file\n"); + *ke_vt << " : Invalid ELF file\n"; } else { process *pr = elf_exec((uint8_t*)mods[i].mod_start, PL_USER); if (pr == 0) { - ke_vt->writeStr(" : Error loading\n"); + *ke_vt << " : Error loading\n"; } else { - ke_vt->writeStr(" : OK, pid="); ke_vt->writeDec(pr->pid); ke_vt->writeStr("\n"); + *ke_vt << " : OK, pid=" << (int)pr->pid << "\n"; } } } - ke_vt->writeStr("Giving control to userland processes.\n\n"); + *ke_vt << "Giving control to userland processes.\n\n"; sti(); schedule(); PANIC("Should never happen. Something probably went wrong with multitasking."); diff --git a/src/kernel/core/sys.cpp b/src/kernel/core/sys.cpp index 2eefa57..32ed988 100644 --- a/src/kernel/core/sys.cpp +++ b/src/kernel/core/sys.cpp @@ -31,9 +31,8 @@ uint16_t inw(uint16_t port) { void stack_trace(size_t bp) { uint32_t *stack = (uint32_t*)bp, i; for (i = 0; i < 5 && (size_t)stack > K_HIGHHALF_ADDR && (size_t)stack < (bp + 0x8000); i++) { - ke_vt->writeStr("| "); ke_vt->writeHex((size_t)stack); - ke_vt->writeStr("\tnext:"); ke_vt->writeHex(stack[0]); ke_vt->writeStr("\t\tret:"); ke_vt->writeHex(stack[1]); - ke_vt->writeStr("\n"); + *ke_vt << " | " << (size_t)stack; + *ke_vt << "\tnext:" << stack[0] << "\t\tret:" << stack[1] << "\n"; stack = (uint32_t*)stack[0]; } } @@ -41,10 +40,10 @@ void stack_trace(size_t bp) { /* For internal use only. Used by panic and panic_assert. */ static void panic_do(char* file, int line) { asm volatile("cli;"); - ke_vt->writeStr("\n File:\t\t"); ke_vt->writeStr(file); ke_vt->writeStr(":"); ke_vt->writeDec(line); - ke_vt->writeStr("\nTrace:\n"); + *ke_vt << "\n File:\t\t" << file << ":" << line; + *ke_vt << "\nTrace:\n"; size_t bp; asm volatile("mov %%ebp,%0" : "=r"(bp)); stack_trace(bp); - ke_vt->writeStr("\n\t\tSystem halted -_-'"); + *ke_vt << "\n\t\tSystem halted -_-'"; asm volatile("hlt"); } @@ -53,7 +52,7 @@ void panic(char* message, char* file, int line) { ke_vt->fgcolor = TC_WHITE; ke_vt->bgcolor = TC_BLUE; ke_vt->outputTo(text_display); - ke_vt->writeStr("\nPANIC:\t\t"); ke_vt->writeStr(message); + *ke_vt << "\nPANIC:\t" << message; panic_do(file, line); } @@ -61,7 +60,7 @@ void panic_assert(char* assertion, char* file, int line) { ke_vt->fgcolor = TC_WHITE; ke_vt->bgcolor = TC_RED; ke_vt->outputTo(text_display); - ke_vt->writeStr("\nASSERT FAILED:\t"); ke_vt->writeStr(assertion); + *ke_vt << "\nASSERT FAILED:\t" << assertion; panic_do(file, line); } |