KraKern

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

commit 06100fffc6cc6b624ca1f4eb73b290de37304ccb
parent d14171dd290a4ff68c61e326078dd15ee755af8d
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri,  5 Feb 2016 14:21:26 +0100

Panic(All): Dat power

Diffstat:
MMakefile | 1+
Mincludes/core/Module.hpp | 3++-
Mincludes/core/Modules.hpp | 24++++++++++++++++++------
Mkern.img | 0
Mkernel/Kernel.cpp | 9++++++++-
Mkernel/Modules.cpp | 20++++++++++++++------
Mmodules/x86/Makefile | 2+-
Mmodules/x86/ModuleKeyboard.hpp | 1+
Amodules/x86/ModuleTime.cpp | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amodules/x86/ModuleTime.hpp | 34++++++++++++++++++++++++++++++++++
Mmodules/x86/modules_conf.cpp | 3+++
11 files changed, 142 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile @@ -44,6 +44,7 @@ install: $(KERNEL) sudo cp $(KERNEL) /mnt/boot/. sudo umount /mnt sudo losetup -d /dev/loop1 + ./qemu.sh clean: rm -f $(OBJS) diff --git a/includes/core/Module.hpp b/includes/core/Module.hpp @@ -7,7 +7,8 @@ enum { MODULE_FILESYSTEM, MODULE_DEVICE, - MODULE_KEYBOARD + MODULE_KEYBOARD, + MODULE_TIME }; class Module : public File { diff --git a/includes/core/Modules.hpp b/includes/core/Modules.hpp @@ -5,10 +5,19 @@ extern Kernel __kern; -# define MODULE_SIZE 255 -# define import_module(m, r, n, name) m *n = new m(name, r); -# define main_module void Modules::load_modules(void) -# define reg_module(n) __kern.io.loading(n->name); this->_tmp = (struct s_modules *)__kern.mem.kmalloc(sizeof(struct s_modules)); this->_tmp->m = n; this->_tmp->name = n->name; this->_tmp->flags = n->flags; this->_list[this->_mod_count++] = this->_tmp; __kern.io.done(); +# define MODULE_SIZE 255 +# define import_module(m, r, n, name) m *n = new m(name, r); +# define main_module void Modules::load_modules(void) +# define reg_module(n) __kern.io.loading(n->name); \ + this->_tmp = (struct s_modules *)__kern.mem.kmalloc(sizeof(struct s_modules));\ + this->_tmp->m = n; this->_tmp->name = n->name; this->_tmp->flags = n->flags; this->_tmp->next = 0x0;\ + if (!this->_list) { \ + this->_list = this->_tmp;\ + } else { \ + for (this->_tmp2 = this->_list; this->_tmp2->next != 0x0; this->_tmp2 = this->_tmp2->next); \ + this->_tmp2->next = this->_tmp;\ + }\ + __kern.io.done(); class Module; @@ -16,6 +25,7 @@ struct s_modules { Module *m; const char *name; u8 flags; + s_modules *next; }; class Modules { @@ -24,10 +34,12 @@ class Modules { void load_modules(void); void call_keyboard(void); + Module *get(const char *n); + private: - struct s_modules *_list[MODULE_SIZE]; + struct s_modules *_list; int _mod_count; - struct s_modules *_tmp; + struct s_modules *_tmp, *_tmp2; }; #endif diff --git a/kern.img b/kern.img Binary files differ. diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -1,4 +1,5 @@ #include <Kernel.hpp> +# include <ModuleTime.hpp> extern Io __io; extern GDT __gdt; @@ -39,7 +40,13 @@ void Kernel::init(multiboot_info *mbi) { this->pt.init(); this->mods = &__modules; this->mods->init(); - //__kern.io.clear(); + struct s_clock *h = (struct s_clock *)__kern.mem.kmalloc(sizeof(struct s_clock)); + + this->mods->get("module_time")->ioctl(ACPI_GET_CLOCK, (u8 *)h); + char str[3]; + itoa(str, h->hour, 10); + __kern.io.puts(str); + //list_files(this->fs.get_root(), 0); while (1); } diff --git a/kernel/Modules.cpp b/kernel/Modules.cpp @@ -4,7 +4,7 @@ Modules __modules; void Modules::init(void) { - this->_mod_count = 0; + this->_list = 0x0; __kern.io.set_color(COLOR_LIGHT_GREY); __kern.io.puts("=================================="); __kern.io.set_color(COLOR_LIGHT_RED); @@ -16,10 +16,18 @@ void Modules::init(void) { } void Modules::call_keyboard(void) { - for (int i = 0; i < this->_mod_count; i++) { - if (this->_list[i]->flags == (MODULE_DEVICE | MODULE_KEYBOARD)) { - this->_list[i]->m->scan(); - break ; - } + for (s_modules *tmp = this->_list; tmp; tmp = tmp->next ) { + if (tmp->flags == (MODULE_DEVICE | MODULE_KEYBOARD)) + tmp->m->scan(); } } + +Module *Modules::get(const char *n) { + s_modules *tmp; + + for (tmp = this->_list; tmp; tmp = tmp->next) { + if (!strcmp(tmp->name, n)) + return tmp->m; + } + return 0x0; +} diff --git a/modules/x86/Makefile b/modules/x86/Makefile @@ -1 +1 @@ -OBJS += modules/$(ARCH)/modules_conf.o modules/$(ARCH)/ModuleKeyboard.o +OBJS += modules/$(ARCH)/modules_conf.o modules/$(ARCH)/ModuleKeyboard.o modules/$(ARCH)/ModuleTime.o diff --git a/modules/x86/ModuleKeyboard.hpp b/modules/x86/ModuleKeyboard.hpp @@ -10,6 +10,7 @@ class ModuleKeyboard : public Module { ~ModuleKeyboard(void); virtual void scan(void); + private: u8 _lshift; u8 _rshift; diff --git a/modules/x86/ModuleTime.cpp b/modules/x86/ModuleTime.cpp @@ -0,0 +1,60 @@ +#include <ModuleTime.hpp> + +ModuleTime::ModuleTime(char *name, u8 t) : Module(name, t) { + +} + +ModuleTime::~ModuleTime(void) { + return ; +} + +void ModuleTime::_get_time(u32 *h, u32 *m, u32 *s) { + u32 dh, dm, ds; + + __kern.io.obyte(0x70, 0x95); + __kern.io.obyte(0x70, 4); + dh = __kern.io.ibyte(0x71); + *h = dh - (dh / 16) * 6; + __kern.io.obyte(0x70, 2); + dm = __kern.io.ibyte(0x71); + *m = dm - (dm / 16) * 6; + __kern.io.obyte(0x70, 0); + ds = __kern.io.ibyte(0x71); + *s = ds - (ds / 16) * 6; +} + +void ModuleTime::_get_date(u32 *y, u32 *m, u32 *d) { + +} + +void ModuleTime::_update(void) { + this->_get_time(&this->_cdate.hour, &this->_cdate.minute, &this->_cdate.second); +} + + +u32 ModuleTime::ioctl(u32 id, u8 *buffer) { + switch (id) { + case ACPI_GET_CLOCK: this->_update(); memcpy((char *)buffer, (char *)&this->_cdate, sizeof(struct s_clock)); return 0; break; + } + return 0; +} + +char *getTextTime(s_clock t) { + char *ret; + + ret = (char *)__kern.mem.kmalloc(sizeof(char) * 9); + if (ret) { + //if (h < 10) + //*ret++ = '0'; + itoa(ret, t.hour, 10); + ret += 2; *ret = ':'; + //if (m < 10) + //*ret++ = '0'; + itoa(ret, t.minute, 10); + ret += 2; *ret = ':'; + itoa(ret, t.second, 10); + return ret; + } + return 0x0; +} + diff --git a/modules/x86/ModuleTime.hpp b/modules/x86/ModuleTime.hpp @@ -0,0 +1,34 @@ +#ifndef __MODULE_TIME__ +# define __MODULE_TIME__ +# define __DO_NOT_LOAD_MODULES__ +# include <Module.hpp> + +#define ACPI_GET_CLOCK 1 + +struct s_clock { + u32 year; + u32 month; + u32 day; + u32 hour; + u32 minute; + u32 second; +}; + +class ModuleTime : public Module { + public: + ModuleTime(char *name, u8 t); + ~ModuleTime(void); + + virtual u32 ioctl(u32 id, u8 *buffer); + + private: + void _get_time(u32 *h, u32 *m, u32 *s); + void _get_date(u32 *y, u32 *m, u32 *d); + void _update(void); + + s_clock _cdate; +}; + +char *getTextTime(s_clock t); + +#endif diff --git a/modules/x86/modules_conf.cpp b/modules/x86/modules_conf.cpp @@ -1,13 +1,16 @@ #ifndef __MODULE_CONF__ # define __MODULE_CONF__ # include <ModuleKeyboard.hpp> +# include <ModuleTime.hpp> main_module { // Importations Lines import_module(ModuleKeyboard, MODULE_DEVICE | MODULE_KEYBOARD, module_keyboard, "module_keyboard"); + import_module(ModuleTime, MODULE_DEVICE | MODULE_TIME, module_time, "module_time"); // Creations lines reg_module(module_keyboard); + reg_module(module_time); } #endif