KraKern

C++ Kernel
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/KraKern

commit 3faa4092a27108f5020038c863fae8535417543d
parent d967d4940e15f3d433e776e72389d7cd00cb8408
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed,  8 Jun 2016 18:18:00 +0200

Fix(IO):

Fix bad reading on get_line
Now copying read(2) behavior
Small fix on IDT

Diffstat:
Mboot/x86/IDT.cpp | 2+-
Mincludes/core/base_lib.h | 1+
Mincludes/lib/data.hpp | 1+
Mkernel/Io.cpp | 5++++-
Mlib/baselib.cpp | 5+++++
Mlib/data.cpp | 2++
Mmodules/x86/ModuleConsole.cpp | 12++++++++----
7 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/boot/x86/IDT.cpp b/boot/x86/IDT.cpp @@ -53,7 +53,7 @@ void IDT::_init_idt(void) { this->_init_idt_desc(0x08, (u32)_asm_exc_PF, INT_GATE, &this->_idtdesc[14]); this->_init_idt_desc(0x08, (u32)_asm_schedule, INT_GATE, &this->_idtdesc[32]); this->_init_idt_desc(0x08, (u32)_asm_int_1, INT_GATE, &this->_idtdesc[33]); - //this->_init_idt_desc(0x08, (u32)_asm_syscalls, TRAP_GATE, &this->_idtdesc[48]); + this->_init_idt_desc(0x08, (u32)_asm_syscalls, TRAP_GATE, &this->_idtdesc[48]); this->_init_idt_desc(0x08, (u32)_asm_syscalls, INT_GATE | 0x6000, &this->_idtdesc[48]); this->_init_idt_desc(0x08, (u32)_asm_syscalls, TRAP_GATE, &this->_idtdesc[128]); this->_idtr.limite = IDT_SIZE * 8; diff --git a/includes/core/base_lib.h b/includes/core/base_lib.h @@ -13,6 +13,7 @@ extern "C" { void *memset(void *dst, int c, u32 n); void itoa(char *buf, u32 n, int base); void strreplace(char *s, char a, char b); + void bzero(char *s); } #endif diff --git a/includes/lib/data.hpp b/includes/lib/data.hpp @@ -19,6 +19,7 @@ class map { ~map(void); struct data_map &operator [](char *str); + struct data_map *get_data(void); private: struct data_map *_data; diff --git a/kernel/Io.cpp b/kernel/Io.cpp @@ -204,6 +204,8 @@ void Io::key_callback(char c) { if (c == '\n') { this->_gline_ready = 1; + this->_line[pos++] = '\n'; + this->_line[pos + 1] = 0; pos = 0; } else { this->_line[pos++] = c; @@ -215,9 +217,10 @@ int Io::get_line(char *c) { int tmp; if (this->_gline_ready) { + bzero(c); tmp = strlen(this->_line); strcpy(c, this->_line); - strcpy(this->_line, ""); + bzero(this->_line); this->_gline_ready = 0; return tmp; } diff --git a/lib/baselib.cpp b/lib/baselib.cpp @@ -94,6 +94,11 @@ extern "C" { s++; } } + + void bzero(char *s) { + for (int i = 0; s[i]; i++) + s[i] = 0; + } } diff --git a/lib/data.cpp b/lib/data.cpp @@ -37,6 +37,8 @@ struct data_map &map::operator[](char *str) { return *n; } +struct data_map *map::get_data(void) { return this->_data; }; + // Data maps struct data_map &data_map::operator=(const char *data) { diff --git a/modules/x86/ModuleConsole.cpp b/modules/x86/ModuleConsole.cpp @@ -17,10 +17,11 @@ void ModuleConsole::tick(void) { this->_is_waiting = 1; } else { if ((ret = __kern.io.get_line(line))) { - line[ret] = 0; - this->command(line); - this->_is_waiting = 0; + line[ret - 1] = 0; + if (ret - 1 > 0) + this->command(line); strcpy(line, ""); + this->_is_waiting = 0; } } } @@ -29,7 +30,6 @@ void ModuleConsole::prompt(void) { __kern.io.printk("%e%s %e::%e %s%e > %e", COLOR_WHITE, __kern.env.vars["NAME"].data, COLOR_MAGENTA, COLOR_GREEN, __kern.env.vars["PWD"].data, COLOR_LIGHT_BLUE, COLOR_LIGHT_GREY); - //__kern.io.printk("> "); } void ModuleConsole::command(char *str) { @@ -37,6 +37,10 @@ void ModuleConsole::command(char *str) { this->list_files(__kern.fs.get_root(), 0); } else if (!strcmp(str, "reboot")) { __kern.io.obyte(0x64, 0xFE); + } else if (!strcmp(str, "env")) { + for (struct data_map *tmp = __kern.env.vars.get_data(); tmp; tmp = tmp->next) { + __kern.io.printk("%s = %s\n", tmp->key, tmp->data); + } } else { __kern.io.printk("%s: Command not found\n", str); }