KraKern

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

commit 76ce0c44753b82a93c47e41173b51ca4b3fbbd29
parent 7fd521461fbfde50c1b271b12500696b1354af94
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 24 May 2016 18:09:16 +0200

Add(Modules): Some ->

Add a console module
Add some callbacks to the modules

Diffstat:
Mboot/x86/IDT.cpp | 1+
Mincludes/core/Io.hpp | 4++++
Mincludes/core/Module.hpp | 3+++
Mincludes/core/Modules.hpp | 2++
Mkernel/ELF.cpp | 1+
Mkernel/Io.cpp | 26++++++++++++++++++++++++++
Mkernel/Kernel.cpp | 5+++--
Mkernel/Modules.cpp | 13+++++++++++++
Mkernel/ProcessTable.cpp | 2++
Mmodules/x86/Makefile | 3++-
Amodules/x86/ModuleConsole.cpp | 47+++++++++++++++++++++++++++++++++++++++++++++++
Amodules/x86/ModuleConsole.hpp | 20++++++++++++++++++++
Mmodules/x86/ModuleKeyboard.cpp | 4+++-
Mmodules/x86/modules_conf.cpp | 3+++
14 files changed, 130 insertions(+), 4 deletions(-)

diff --git a/boot/x86/IDT.cpp b/boot/x86/IDT.cpp @@ -19,6 +19,7 @@ extern "C" { void isr_schedule_int(void) { if (!__kern.is_panic) { + __kern.mods->tick(); __kern.sch.tick(); __kern.io.obyte(0x20,0x20); __kern.io.obyte(0xA0,0x20); diff --git a/includes/core/Io.hpp b/includes/core/Io.hpp @@ -61,6 +61,8 @@ class Io { void loading(const char *); void done(void); void panic(const char *s); + void key_callback(char c); + int get_line(char *c); enum console_type { BUFFERED, @@ -75,8 +77,10 @@ class Io { char _screen[SIZE_SCREEN]; char _inbuf[512]; + char _line[512]; int _keypos; int _inlock; + int _gline_ready; int _keystate; int _in_loading; void _move_cursor(void); diff --git a/includes/core/Module.hpp b/includes/core/Module.hpp @@ -5,6 +5,7 @@ # include <kern_types.h> enum { + MODULE_TICK, MODULE_FILESYSTEM, MODULE_DEVICE, MODULE_KEYBOARD, @@ -21,6 +22,8 @@ class Module : public File { virtual u32 ioctl(u32 id, u8 *buffer) { return -1; }; virtual u32 remove(void) { return -1; }; virtual void scan(void) {}; + virtual void tick(void) {}; + virtual void ready(void) {}; u8 flags; char *name; diff --git a/includes/core/Modules.hpp b/includes/core/Modules.hpp @@ -31,6 +31,8 @@ class Modules { void init(void); void load_modules(void); void call_keyboard(void); + void tick(void); + void ready(void); Module *get(const char *n); diff --git a/kernel/ELF.cpp b/kernel/ELF.cpp @@ -29,6 +29,7 @@ u32 ELF::load_elf(char *file, process_st *proc) { if (!this->_is_elf(file)) __kern.io.panic("ELF: load_elf(): File not in ELF format !"); for (int pe = 0; pe < hdr->e_phnum; pe++, p_entry++) { + if (p_entry->p_type == PT_LOAD) { v_begin = p_entry->p_vaddr; v_end = p_entry->p_vaddr + p_entry->p_memsz; diff --git a/kernel/Io.cpp b/kernel/Io.cpp @@ -7,6 +7,7 @@ char *Io::_vidmem = (char *)RAM_SCREEN; Io::Io(void) { this->_real_screen = (char *)RAM_SCREEN; + this->_gline_ready = 0; } Io::~Io(void) { @@ -198,6 +199,31 @@ void Io::panic(const char *s) { // Reboot } +void Io::key_callback(char c) { + static int pos = 0; + + if (c == '\n') { + this->_gline_ready = 1; + pos = 0; + } else { + this->_line[pos++] = c; + this->_line[pos + 1] = 0; + } +} + +int Io::get_line(char *c) { + int tmp; + + if (this->_gline_ready) { + tmp = strlen(this->_line); + strcpy(c, this->_line); + strcpy(this->_line, ""); + this->_gline_ready = 0; + return tmp; + } + return 0; +} + void Io::_move_cursor(void) { u16 c_pos; diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -25,7 +25,6 @@ Kernel::Kernel(void) { } void Kernel::init(multiboot_info *mbi) { - this->is_panic = 0; this->io = __io; this->gdt = __gdt; this->idt = __idt; @@ -45,11 +44,13 @@ void Kernel::init(multiboot_info *mbi) { this->pt.init(); this->sch = *(new Scheduler()); this->elf = *(new ELF()); + this->is_panic = 0; + this->mods->ready(); this->ready(); __kern.io.puts("\n"); asm("sti"); //list_files(this->fs.get_root(), 0); - this->elf.execv("/hello", 0, 0x0); + //this->elf.execv("/hello", 0, 0x0); while (1); } diff --git a/kernel/Modules.cpp b/kernel/Modules.cpp @@ -17,6 +17,13 @@ void Modules::call_keyboard(void) { } } +void Modules::tick(void) { + for (s_modules *tmp = this->_list; tmp; tmp = tmp->next) { + if (tmp->flags << MODULE_TICK || tmp->flags == MODULE_TICK) + tmp->m->tick(); + } +} + Module *Modules::get(const char *n) { s_modules *tmp; @@ -26,3 +33,9 @@ Module *Modules::get(const char *n) { } return 0x0; } + +void Modules::ready(void) { + for (s_modules *tmp = this->_list; tmp; tmp = tmp->next) { + tmp->m->ready(); + } +} diff --git a/kernel/ProcessTable.cpp b/kernel/ProcessTable.cpp @@ -42,6 +42,7 @@ int ProcessTable::create_proc(process_st *info, char *f, int ac, char **av) { } param[i] = 0x0; } + info->pd = __kern.mem.pd_create(); INIT_LIST_HEAD(&(info->pglist)); previous = this->_current->get_p_info(); @@ -118,6 +119,7 @@ void ProcessTable::destroy_process(Process *pp) { process_st *proc_current = this->_current->get_p_info(), *pid_proc = pp->get_p_info(); u32 *pd0; + // ICI asm("mov %0, %%eax ;mov %%eax, %%cr3"::"m" (pid_proc->regs.cr3)); list_for_each_safe(p, n, &pid_proc->pglist) { pg = list_entry(p, struct page, list); diff --git a/modules/x86/Makefile b/modules/x86/Makefile @@ -1 +1,2 @@ -OBJS += modules/$(ARCH)/modules_conf.o modules/$(ARCH)/ModuleKeyboard.o modules/$(ARCH)/ModuleTime.o modules/$(ARCH)/ModuleExt2.o modules/$(ARCH)/Ext2File.o +OBJS += modules/$(ARCH)/modules_conf.o modules/$(ARCH)/ModuleKeyboard.o modules/$(ARCH)/ModuleTime.o modules/$(ARCH)/ModuleExt2.o modules/$(ARCH)/Ext2File.o\ + modules/$(ARCH)/ModuleConsole.o diff --git a/modules/x86/ModuleConsole.cpp b/modules/x86/ModuleConsole.cpp @@ -0,0 +1,47 @@ +# include <ModuleConsole.hpp> + +ModuleConsole::ModuleConsole(char *name, u8 t) : Module(name, t) { + this->_is_waiting = 0; +} + +ModuleConsole::~ModuleConsole(void) { + +} + +void ModuleConsole::tick(void) { + static char line[512] = ""; + int ret; + + if (!this->_is_waiting) { + __kern.io.printk("KraKern > "); + this->_is_waiting = 1; + } else { + if ((ret = __kern.io.get_line(line))) { + line[ret] = 0; + this->command(line); + this->_is_waiting = 0; + strcpy(line, ""); + } + } +} + +void ModuleConsole::command(char *str) { + if (!strcmp(str, "ls")) { + this->list_files(__kern.fs.get_root(), 0); + } else { + __kern.io.printk("%s: Command not found\n", str); + } +} + +void ModuleConsole::list_files(File *root, int depth) { + File *tmp; + + for (tmp = root->get_child(); tmp; tmp = tmp->get_next()) { + for (int i = 0; i < depth; __kern.io.puts(" "), i++); + __kern.io.printk("%s\n", tmp->get_name()); + if (tmp->get_type() == TYPE_DIRECTORY) + tmp->scan(); + if (tmp->get_child()) + list_files(tmp, depth + 1); + } +} diff --git a/modules/x86/ModuleConsole.hpp b/modules/x86/ModuleConsole.hpp @@ -0,0 +1,20 @@ +#ifndef __MODULE_CONSOLE__ +# define __MODULE_CONSOLE__ +# define __DO_NOT_LOAD_MODULES__ + +# include <Module.hpp> + +class ModuleConsole : public Module { + public: + ModuleConsole(char *name, u8 t); + ~ModuleConsole(void); + + virtual void tick(void); + void command(char *str); + void list_files(File *root, int depth); + + private: + int _is_waiting; +}; + +#endif diff --git a/modules/x86/ModuleKeyboard.cpp b/modules/x86/ModuleKeyboard.cpp @@ -27,10 +27,13 @@ void ModuleKeyboard::scan(void) { default: if (this->_alt) { __kern.io.putc(this->_map[i * 4 + 2]); + __kern.io.key_callback(this->_map[i * 4 + 2]); } else if (this->_rshift || this->_lshift) { __kern.io.putc(this->_map[i * 4 + 1]); + __kern.io.key_callback(this->_map[i * 4 + 1]); } else { __kern.io.putc(this->_map[i * 4]); + __kern.io.key_callback(this->_map[i * 4]); } break; } @@ -43,5 +46,4 @@ void ModuleKeyboard::scan(void) { case 0x37: this->_alt = 0; break; } } - } diff --git a/modules/x86/modules_conf.cpp b/modules/x86/modules_conf.cpp @@ -3,16 +3,19 @@ # include <ModuleKeyboard.hpp> # include <ModuleTime.hpp> # include <ModuleExt2.hpp> +# include <ModuleConsole.hpp> main_module { // Importations Lines import_module(ModuleKeyboard, MODULE_DEVICE | MODULE_KEYBOARD, module_keyboard, "keyboard"); import_module(ModuleTime, MODULE_DEVICE | MODULE_TIME, module_time, "time"); import_module(ModuleExt2, MODULE_DEVICE | MODULE_FILESYSTEM, module_ext2, "ext2"); + import_module(ModuleConsole, MODULE_TICK, module_console, "console"); // Creations lines reg_module(module_keyboard); reg_module(module_time); reg_module(module_ext2); + reg_module(module_console); } #endif