diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-17 17:56:23 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-17 17:56:23 +0200 |
commit | 593bf4df3d8db49286c1a7ae4ef75c887b629930 (patch) | |
tree | 988a104c9611d72e1252282789688586efd9a394 /src/kernel/core | |
parent | 7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef (diff) | |
download | TCE-593bf4df3d8db49286c1a7ae4ef75c887b629930.tar.gz TCE-593bf4df3d8db49286c1a7ae4ef75c887b629930.zip |
Devices using the VFS structure. Basic keyboard handler.
Diffstat (limited to 'src/kernel/core')
-rw-r--r-- | src/kernel/core/kmain.cpp | 56 | ||||
-rw-r--r-- | src/kernel/core/monitor.cpp | 114 | ||||
-rw-r--r-- | src/kernel/core/monitor.h | 21 | ||||
-rw-r--r-- | src/kernel/core/sys.cpp | 25 |
4 files changed, 51 insertions, 165 deletions
diff --git a/src/kernel/core/kmain.cpp b/src/kernel/core/kmain.cpp index eb2c3ec..e74ff33 100644 --- a/src/kernel/core/kmain.cpp +++ b/src/kernel/core/kmain.cpp @@ -2,8 +2,8 @@ #include <config.h> #include "multiboot.h" -#include "monitor.h" #include "sys.h" +#include <dev/vgatxt.h> #include <task/idt.h> #include <task/timer.h> #include <task/task.h> @@ -12,6 +12,8 @@ #include <mem/mem.h> #include <linker/elf.h> #include <vfs/node.h> +#include <ui/vt.h> +#include <dev/ps2keyboard.h> /* The kernel's main procedure. This function is called in loader_.asm. This function calls the initializer functions for all system parts. @@ -35,47 +37,59 @@ extern "C" void kmain(multiboot_info_t* mbd, int32_t magic) { mem_placementAddr = (mods[i].mod_end & 0xFFFFF000) + 0x1000; } - monitor_clear(); - - monitor_write(K_OS_NAME); - monitor_write(" version "); - monitor_write(K_OS_VER); - monitor_write(" codename '"); - monitor_write(K_OS_CODENAME); - monitor_write("' starting up :\n"); - + // Init memory managment functions idt_init(); - totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024); paging_init(totalRam); gdt_init(); paging_cleanup(); _no_more_ksbrk = true; - //kheap_init(); + // Init higher level stuff timer_init(30); tasking_init(); - vfs_setup(); - - monitor_write("\nLoading modules :\n"); + + // Init display devices + text_display = new vgatxt(dot_dev); + dot_dev->add_child("vgatxt", text_display); + ke_vt = new vt(dot_dev, 80, 25); + dot_ui->add_child("klog", ke_vt); + ke_vt->outputTo(text_display); + + // 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"); + + // 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++) { - monitor_write(" * "); - monitor_write((char*)mods[i].string); + ke_vt->writeStr(" * "); + ke_vt->writeStr((char*)mods[i].string); if (elf_check((uint8_t*)mods[i].mod_start)) { - monitor_write(" : Invalid ELF file\n"); + ke_vt->writeStr(" : Invalid ELF file\n"); } else { process *pr = elf_exec((uint8_t*)mods[i].mod_start, PL_USER); if (pr == 0) { - monitor_write(" : Error loading\n"); + ke_vt->writeStr(" : Error loading\n"); } else { - monitor_write(" : OK, pid="); monitor_writeDec(pr->pid); monitor_write("\n"); + ke_vt->writeStr(" : OK, pid="); ke_vt->writeDec(pr->pid); ke_vt->writeStr("\n"); } } } - monitor_write("Giving control to userland processes.\n\n"); + ke_vt->writeStr("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/monitor.cpp b/src/kernel/core/monitor.cpp deleted file mode 100644 index ba2a6df..0000000 --- a/src/kernel/core/monitor.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "monitor.h" -#include "sys.h" - -#include "mem/mem.h" - -static int cursor_x = 0, cursor_y = 0; -static uint16_t *video_memory = (uint16_t*)((size_t)K_HIGHHALF_ADDR + 0xB8000); - -static uint8_t attribute = 0x07; // 0 = background = black, 7 = foreground = white - -/* For internal use only. Tells hardware to move the cursor at (cursor_x, cursor_y). */ -static void move_cursor() { - uint16_t cursor_location = cursor_y * 80 + cursor_x; - outb(0x3D4, 14); //Sending high cursor byte - outb(0x3D5, cursor_location >> 8); - outb(0x3D4, 15); //Sending high cursor byte - outb(0x3D5, cursor_location); -} - -/* For internal use only. Scrolls everything up one line. */ -static void scroll() { - uint16_t blank = (attribute << 8) | 0x20; - - if (cursor_y >= 25) { - int i; - for (i = 0; i < 80*24; i++) { - video_memory[i] = video_memory[i+80]; - } - for (i = 80*24; i < 80*25; i++) { - video_memory[i] = blank; - } - cursor_y = 24; - } -} - -/* Put one character on the screen. This function handles special characters \b, \t, \r and \n. */ -void monitor_put(char c) { - if (c == '\b' && cursor_x) { //Backspace - cursor_x--; - } else if (c == '\t') { //Tab - cursor_x = (cursor_x + 8) & ~(8 - 1); - } else if (c == '\r') { //Carriage return - cursor_x = 0; - } else if (c == '\n') { //New line - cursor_x = 0; - cursor_y++; - } else if (c >= ' ') { //Any printable character - video_memory[cursor_y * 80 + cursor_x] = c | (attribute << 8); - cursor_x++; - } - if (cursor_x >= 80) { - cursor_x = 0; - cursor_y++; - } - - scroll(); - move_cursor(); -} - -/* Clears the screen and moves cursor to (0,0) (top left corner) */ -void monitor_clear() { - uint16_t blank = (attribute << 8) | 0x20; - - int i; - - for (i = 0; i < 80*25; i++) { - video_memory[i] = blank; - } - - cursor_x = 0; cursor_y = 0; - move_cursor(); -} - -/* Writes a string to the monitor */ -void monitor_write(char *s) { - while (*s) { - monitor_put(*(s++)); - } -} - -/* Writes a number in hexadecimal notation to the monitor */ -void monitor_writeHex(uint32_t v) { - int i; - - monitor_put('0'); monitor_put('x'); - char hexdigits[] = "0123456789abcdef"; - - for (i = 0; i < 8; i++) { - monitor_put(hexdigits[v >> 28]); - v = v << 4; - } -} - -/* Writes a number in decimal notation to the monitor */ -void monitor_writeDec(uint32_t v) { - if (v == 0) { - monitor_put('0'); - return; - } - - char numbers[] = "0123456789"; - while (v > 0) { - int order = 1, no = 1; - while (v / order > 0) order *= 10; - order /= 10; - monitor_put(numbers[v / order]); - v = v - (v / order * order); - while (v / no > 0) no *= 10; - while (no < order) { - monitor_put('0'); - no *= 10; - } - } -} diff --git a/src/kernel/core/monitor.h b/src/kernel/core/monitor.h deleted file mode 100644 index bb8e16e..0000000 --- a/src/kernel/core/monitor.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef DEF_MONITOR_H -#define DEF_MONITOR_H - -#include "types.h" - -void monitor_put(char c); -void monitor_clear(); -void monitor_write(char *s); -void monitor_writeHex(uint32_t v); -void monitor_writeDec(uint32_t v); - -#define NL monitor_put('\n'); -#define TAB monitor_put('\t'); -#define WHERE { monitor_write("(kernel:"); \ - monitor_write(__FILE__); \ - monitor_write(":"); \ - monitor_writeDec(__LINE__); \ - monitor_write(")\t"); } - -#endif - diff --git a/src/kernel/core/sys.cpp b/src/kernel/core/sys.cpp index d95b678..2eefa57 100644 --- a/src/kernel/core/sys.cpp +++ b/src/kernel/core/sys.cpp @@ -1,5 +1,6 @@ #include "sys.h" -#include "monitor.h" +#include <ui/vt.h> +#include <dev/vgatxt.h> #include "mem/mem.h" @@ -30,9 +31,9 @@ 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++) { - monitor_write("| "); monitor_writeHex((size_t)stack); - monitor_write("\tnext:"); monitor_writeHex(stack[0]); monitor_write("\t\tret:"); monitor_writeHex(stack[1]); - monitor_write("\n"); + 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"); stack = (uint32_t*)stack[0]; } } @@ -40,21 +41,27 @@ 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;"); - monitor_write("\n File:\t\t"); monitor_write(file); monitor_put(':'); monitor_writeDec(line); - monitor_write("\nTrace:\n"); + ke_vt->writeStr("\n File:\t\t"); ke_vt->writeStr(file); ke_vt->writeStr(":"); ke_vt->writeDec(line); + ke_vt->writeStr("\nTrace:\n"); size_t bp; asm volatile("mov %%ebp,%0" : "=r"(bp)); stack_trace(bp); - monitor_write("\n\t\tSystem halted -_-'"); + ke_vt->writeStr("\n\t\tSystem halted -_-'"); asm volatile("hlt"); } /* These functions stop the system, reporting an error message, because something bad happenned. */ void panic(char* message, char* file, int line) { - monitor_write("\nPANIC:\t\t"); monitor_write(message); + 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); panic_do(file, line); } void panic_assert(char* assertion, char* file, int line) { - monitor_write("\nASSERT FAILED:\t"); monitor_write(assertion); + 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); panic_do(file, line); } |