KraKern

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

commit d83388597073fdeb6be07f8d0ef1911aef6ef3a0
parent 06100fffc6cc6b624ca1f4eb73b290de37304ccb
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sat,  6 Feb 2016 12:12:38 +0100

Fix(DateTime): Now support Date & Time.

Diffstat:
Mincludes/core/Kernel.hpp | 1+
Mincludes/core/Modules.hpp | 6++----
Mkernel/Kernel.cpp | 27+++++++++++++++++++--------
Mkernel/Modules.cpp | 9++-------
Mmodules/x86/ModuleTime.cpp | 50++++++++++++++++++++++++++++++++++++++++++--------
Mmodules/x86/ModuleTime.hpp | 1+
Mmodules/x86/modules_conf.cpp | 4++--
7 files changed, 69 insertions(+), 29 deletions(-)

diff --git a/includes/core/Kernel.hpp b/includes/core/Kernel.hpp @@ -17,6 +17,7 @@ class Kernel { void init(multiboot_info *mbi); void welcome(void); + void ready(void); Io io; GDT gdt; diff --git a/includes/core/Modules.hpp b/includes/core/Modules.hpp @@ -8,16 +8,14 @@ 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));\ +# define reg_module(n) 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; diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -40,14 +40,7 @@ void Kernel::init(multiboot_info *mbi) { this->pt.init(); this->mods = &__modules; this->mods->init(); - 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); + this->ready(); while (1); } @@ -65,3 +58,21 @@ void Kernel::welcome(void) { for (int i = 0; i < 80; i++, this->io.puts("#")); this->io.set_color(COLOR_WHITE); } + +void Kernel::ready(void) { + s_clock *h = (struct s_clock *)__kern.mem.kmalloc(sizeof(struct s_clock)); + + __kern.mods->get("time")->ioctl(ACPI_GET_CLOCK, (u8 *)h); + __kern.io.puts("\n"); + __kern.io.set_color(COLOR_LIGHT_GREY); + for (int i = 0; i < 26; i++, this->io.puts("=")); + __kern.io.set_color(COLOR_WHITE); + __kern.io.puts(" Boot done, Host is ready ! "); + __kern.io.set_color(COLOR_LIGHT_GREY); + for (int i = 0; i < 26; i++, this->io.puts("=")); + __kern.io.set_color(COLOR_WHITE); + __kern.io.puts("Date: "); + __kern.io.puts(getTextDate(*h)); + __kern.io.puts(" "); + __kern.io.puts(getTextTime(*h)); +} diff --git a/kernel/Modules.cpp b/kernel/Modules.cpp @@ -5,14 +5,9 @@ Modules __modules; void Modules::init(void) { this->_list = 0x0; - __kern.io.set_color(COLOR_LIGHT_GREY); - __kern.io.puts("=================================="); - __kern.io.set_color(COLOR_LIGHT_RED); - __kern.io.puts(" MODULES "); - __kern.io.set_color(COLOR_LIGHT_GREY); - __kern.io.puts("===================================\n"); - __kern.io.set_color(COLOR_WHITE); + __kern.io.loading("Modules ..."); this->load_modules(); + __kern.io.done(); } void Modules::call_keyboard(void) { diff --git a/modules/x86/ModuleTime.cpp b/modules/x86/ModuleTime.cpp @@ -24,11 +24,23 @@ void ModuleTime::_get_time(u32 *h, u32 *m, u32 *s) { } void ModuleTime::_get_date(u32 *y, u32 *m, u32 *d) { + u32 dy, dm, dd; + __kern.io.obyte(0x70, 0x95); + __kern.io.obyte(0x70, 9); + dy = __kern.io.ibyte(0x71); + *y = dy - (dy / 16) * 6; + __kern.io.obyte(0x70, 8); + dm = __kern.io.ibyte(0x71); + *m = dm - (dm / 16) * 6; + __kern.io.obyte(0x70, 7); + dd = __kern.io.ibyte(0x71); + *d = dd - (dd / 16) * 6; } void ModuleTime::_update(void) { this->_get_time(&this->_cdate.hour, &this->_cdate.minute, &this->_cdate.second); + this->_get_date(&this->_cdate.year, &this->_cdate.month, &this->_cdate.day); } @@ -40,21 +52,43 @@ u32 ModuleTime::ioctl(u32 id, u8 *buffer) { } char *getTextTime(s_clock t) { - char *ret; + char *ret, *str; ret = (char *)__kern.mem.kmalloc(sizeof(char) * 9); + str = ret; if (ret) { - //if (h < 10) - //*ret++ = '0'; + if (t.hour < 10) + *ret++ = '0'; itoa(ret, t.hour, 10); - ret += 2; *ret = ':'; - //if (m < 10) - //*ret++ = '0'; + ret = (t.hour < 10 ? ret + 1 : ret + 2); *ret++ = ':'; + if (t.minute < 10) + *ret++ = '0'; itoa(ret, t.minute, 10); - ret += 2; *ret = ':'; + ret = (t.minute < 10 ? ret + 1 : ret + 2); *ret++ = ':'; + if (t.second < 10) + *ret++ = '0'; itoa(ret, t.second, 10); - return ret; + return str; } return 0x0; } +char *getTextDate(s_clock t) { + char *ret, *str; + + ret = (char *)__kern.mem.kmalloc(sizeof(char) * 12); + str = ret; + if (ret) { + if (t.day < 10) + *ret++ = '0'; + itoa(ret, t.day, 10); + ret = (t.day < 10 ? ret + 1 : ret + 2); *ret++ = '/'; + if (t.month < 10) + *ret++ = '0'; + itoa(ret, t.month, 10); + ret = (t.month < 10 ? ret + 1 : ret + 2); *ret++ = '/'; + itoa(ret, t.year, 10); + return str; + } + return 0x0; +} diff --git a/modules/x86/ModuleTime.hpp b/modules/x86/ModuleTime.hpp @@ -30,5 +30,6 @@ class ModuleTime : public Module { }; char *getTextTime(s_clock t); +char *getTextDate(s_clock t); #endif diff --git a/modules/x86/modules_conf.cpp b/modules/x86/modules_conf.cpp @@ -6,8 +6,8 @@ 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"); + import_module(ModuleKeyboard, MODULE_DEVICE | MODULE_KEYBOARD, module_keyboard, "keyboard"); + import_module(ModuleTime, MODULE_DEVICE | MODULE_TIME, module_time, "time"); // Creations lines reg_module(module_keyboard);