diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-18 11:10:53 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-18 11:10:53 +0200 |
commit | c19415d2ffb6f063f91983ff505e2530ab500908 (patch) | |
tree | 021263be30daa438387ce3a12453a7719bc8dccf | |
parent | 593bf4df3d8db49286c1a7ae4ef75c887b629930 (diff) | |
download | TCE-c19415d2ffb6f063f91983ff505e2530ab500908.tar.gz TCE-c19415d2ffb6f063f91983ff505e2530ab500908.zip |
Minor changes.
-rw-r--r-- | src/kernel/core/kmain.cpp | 49 | ||||
-rw-r--r-- | src/kernel/core/sys.cpp | 15 | ||||
-rw-r--r-- | src/kernel/mem/paging.cpp | 14 | ||||
-rw-r--r-- | src/kernel/task/idt.cpp | 6 | ||||
-rw-r--r-- | src/kernel/task/task.cpp | 10 | ||||
-rw-r--r-- | src/kernel/ui/vt.cpp | 6 | ||||
-rw-r--r-- | src/kernel/ui/vt.h | 7 |
7 files changed, 57 insertions, 50 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); } diff --git a/src/kernel/mem/paging.cpp b/src/kernel/mem/paging.cpp index 01a1780..a6daf68 100644 --- a/src/kernel/mem/paging.cpp +++ b/src/kernel/mem/paging.cpp @@ -136,14 +136,14 @@ uint32_t paging_fault(registers *regs) { } if (seg == 0) { - NL; WHERE; ke_vt->writeStr("Unhandled Page Fault\t"); - ke_vt->writeStr("cr2:"); ke_vt->writeHex(addr); + NL; WHERE; *ke_vt << "Unhandled Page Fault\t"; + *ke_vt << "cr2:" << addr; NL; TAB; - if (regs->err_code & 0x1) ke_vt->writeStr("present"); TAB; - if (regs->err_code & 0x2) ke_vt->writeStr("write"); TAB; - if (regs->err_code & 0x4) ke_vt->writeStr("user"); TAB; - if (regs->err_code & 0x8) ke_vt->writeStr("rsvd"); TAB; - if (regs->err_code & 0x10) ke_vt->writeStr("opfetch"); + if (regs->err_code & 0x1) *ke_vt << "present"; TAB; + if (regs->err_code & 0x2) *ke_vt << "write"; TAB; + if (regs->err_code & 0x4) *ke_vt << "user"; TAB; + if (regs->err_code & 0x8) *ke_vt << "rsvd"; TAB; + if (regs->err_code & 0x10) *ke_vt << "opfetch"; return 1; } return 0; diff --git a/src/kernel/task/idt.cpp b/src/kernel/task/idt.cpp index 634350c..3d6d3cb 100644 --- a/src/kernel/task/idt.cpp +++ b/src/kernel/task/idt.cpp @@ -81,9 +81,9 @@ static struct irq_waiter { extern "C" void idt_isrHandler(registers regs) { if ((regs.int_no == 14 && paging_fault(®s) != 0) || regs.int_no != 14) { if (tasking_handleException(®s) == 0) { - ke_vt->writeStr("\nREALLY BAD THIS TIME\t\tUnhandled exception\t#"); - ke_vt->writeDec(regs.int_no); - ke_vt->writeStr("\t@"); ke_vt->writeHex(regs.eip); + *ke_vt << "\nREALLY BAD THIS TIME\t\tUnhandled exception\t#"; + *ke_vt << regs.int_no; + *ke_vt << "\t@" << regs.eip; PANIC("Unhandled Exception"); } } diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp index e54b96e..e513608 100644 --- a/src/kernel/task/task.cpp +++ b/src/kernel/task/task.cpp @@ -102,18 +102,18 @@ uint32_t tasking_handleException(registers *regs) { "Into Detected Overflow","Out of Bounds","Invalid Opcode","No Coprocessor", "Double Fault", "Coprocessor Segment Overrun","Bad TSS","Segment Not Present","Stack Fault","General Protection Fault", "Page Fault","Unknown Interrupt","Coprocessor Fault","Alignment Check","Machine Check"}; - ke_vt->writeStr(exception_messages[regs->int_no]); - ke_vt->writeStr("'\teip:"); ke_vt->writeHex(regs->eip); + *ke_vt << exception_messages[regs->int_no]; + *ke_vt << "'\teip:" << regs->eip; if (regs->eip >= K_HIGHHALF_ADDR) { - ke_vt->writeStr("\n Exception stack trace :\n"); + *ke_vt << "\n Exception stack trace :\n"; stack_trace(regs->ebp); PANIC("Kernel error'd."); } if (regs->int_no == 14) { - ke_vt->writeStr("\n>>> Process exiting.\n"); + *ke_vt << "\n>>> Process exiting.\n"; thread_exit_stackJmp(EX_PR_EXCEPTION); } else { - ke_vt->writeStr("\n>>> Thread exiting.\n"); + *ke_vt << "\n>>> Thread exiting.\n"; thread_exit_stackJmp(EX_TH_EXCEPTION); } PANIC("This should never have happened. Please report this."); diff --git a/src/kernel/ui/vt.cpp b/src/kernel/ui/vt.cpp index 4675cdc..683d484 100644 --- a/src/kernel/ui/vt.cpp +++ b/src/kernel/ui/vt.cpp @@ -91,11 +91,15 @@ void vt::writeHex(uint32_t v) { } } -void vt::writeDec(uint32_t v) { +void vt::writeDec(int v) { if (v == 0) { put('0'); return; } + if (v < 0) { + put ('-'); + v = -v; + } char numbers[] = "0123456789"; while (v > 0) { diff --git a/src/kernel/ui/vt.h b/src/kernel/ui/vt.h index b4f3672..ebafe5f 100644 --- a/src/kernel/ui/vt.h +++ b/src/kernel/ui/vt.h @@ -28,7 +28,12 @@ class vt : public node { void clear(); void writeStr(char* str); void writeHex(uint32_t v); - void writeDec(uint32_t v); + void writeDec(int v); + // shortcuts + vt& operator<< (char* str) { writeStr(str); return *this; } + vt& operator<< (uint32_t t) { writeHex(t); return *this; } + vt& operator<< (int i) { writeDec(i); return *this; } + int outputTo(display *display); |