KraKern

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

commit a4da11ed597d682d8019f0c76bc3237b8db84484
parent 2f15c34362d7982dc9b8a5012a7963b25d937c19
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed,  1 Jun 2016 01:24:23 +0200

Add(Console & New pics)

Diffstat:
M.ycm_extra_conf.py | 7+++----
MMakefile | 7++++++-
Mdocs/screen.png | 0
Aincludes/core/Environment.hpp | 16++++++++++++++++
Mincludes/core/Kernel.hpp | 2++
Aincludes/lib/data.hpp | 31+++++++++++++++++++++++++++++++
Akernel/Environment.cpp | 15+++++++++++++++
Mkernel/Io.cpp | 6+++---
Mkernel/Kernel.cpp | 20+++++++++++---------
Mkernel/Makefile | 2+-
Mlib/Makefile | 2+-
Mlib/baselib.cpp | 16----------------
Alib/data.cpp | 46++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/x86/ModuleConsole.cpp | 17++++++++++++-----
Mmodules/x86/ModuleConsole.hpp | 2++
15 files changed, 149 insertions(+), 40 deletions(-)

diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py @@ -81,11 +81,10 @@ flags = [ './tests/gmock', '-isystem', './tests/gmock/include', -'-I', -'includes/core', +'-I', 'includes/core', '-I', './modules/x86/', -'-I', -'includes/boot', +'-I', 'includes/boot', +'-I', 'includes/lib', '-fno-builtin', '-fno-stack-protector', '-nostdlib', diff --git a/Makefile b/Makefile @@ -9,6 +9,7 @@ LD = ld ## Includes INCS = -I includes/boot \ -I includes/core \ + -I includes/lib \ -I modules/$(ARCH)/ ## Flags @@ -19,6 +20,10 @@ CFLAGS = -g -O2 -w $(INCS) -trigraphs -fno-builtin \ LDFLAG = -melf_i386 -static -L ./ -T ./boot/$(ARCH)/linker.ld --entry=_start ASMFLAGS = -f elf -o +## Versions +VERSION = 1.0 +EXTRAVERSION = dev + include ./boot/$(ARCH)/Makefile include ./kernel/Makefile include ./lib/Makefile @@ -30,7 +35,7 @@ $(KERNEL): $(OBJS) $(LD) $(LDFLAG) -o $@ $^ %.o: %.cpp - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -DNAME=\"$(KERNEL)\" -DARCH=\"$(ARCH)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -c $< -o $@ %.o: %.s $(CC) $(CFLAGS) -c $< -o $@ diff --git a/docs/screen.png b/docs/screen.png Binary files differ. diff --git a/includes/core/Environment.hpp b/includes/core/Environment.hpp @@ -0,0 +1,16 @@ +#ifndef __ENVIRONMENT__ +# define __ENVIRONMENT__ + +# include <data.hpp> + +class Environment { + public: + Environment(void); + ~Environment(void); + + map vars; +}; + +# include <Kernel.hpp> + +#endif diff --git a/includes/core/Kernel.hpp b/includes/core/Kernel.hpp @@ -11,6 +11,7 @@ # include <IDE.hpp> # include <Scheduler.hpp> # include <ELF.hpp> +# include <Environment.hpp> class Modules; @@ -32,6 +33,7 @@ class Kernel { IDE ide; Scheduler sch; ELF elf; + Environment env; int is_panic; }; diff --git a/includes/lib/data.hpp b/includes/lib/data.hpp @@ -0,0 +1,31 @@ +#ifndef __DATA__ +# define __DATA__ +# include <base_lib.h> + +// Datas types + +struct data_map { + char *key; + char *data; + struct data_map *next; + + struct data_map &operator=(const char *data); +}; + + +class map { + public: + map(void); + ~map(void); + + struct data_map &operator [](char *str); + + private: + struct data_map *_data; +}; + +# ifndef __ENVIRONMENT__ +# include <Kernel.hpp> +# endif + +#endif diff --git a/kernel/Environment.cpp b/kernel/Environment.cpp @@ -0,0 +1,15 @@ +# include <Environment.hpp> + +Environment::Environment(void) { + __kern.io.loading("Environment ..."); + this->vars["VERSION"] = VERSION; + this->vars["ARCH"] = ARCH; + this->vars["NAME"] = NAME; + this->vars["EXTRAVERSION"] = EXTRAVERSION; + this->vars["PWD"] = "/"; + __kern.io.done(); +} + +Environment::~Environment(void) { + +} diff --git a/kernel/Io.cpp b/kernel/Io.cpp @@ -138,7 +138,7 @@ void Io::printk(const char *s, ...) { this->putc(*s); } } - this->set_color(COLOR_WHITE); + this->set_color(COLOR_LIGHT_GREY); } void Io::clear(void) { @@ -180,7 +180,7 @@ u32 Io::read(char *buf, u32 count) { void Io::loading(const char *s) { this->printk("%e%s%e", COLOR_LIGHT_GREY, s, COLOR_WHITE); - for (int padding = 80 - strlen(s) - 10; padding > 0; padding--, this->puts(" ")); + for (int padding = 81 - strlen(s) - 10; padding > 0; padding--, this->puts(" ")); this->_in_loading = 1; } @@ -192,7 +192,7 @@ void Io::done(void) { void Io::panic(const char *s) { if (this->_in_loading) this->printk("[%e FAIL %e]", COLOR_RED, COLOR_WHITE); - this->printk("\n[%e PANIC %e]: %s", COLOR_RED, COLOR_WHITE, s); + this->printk("\n[%e PANIC %e]: %s\n", COLOR_RED, COLOR_WHITE, s); __kern.is_panic = 1; asm("hlt"); while (1); diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -45,6 +45,7 @@ void Kernel::init(multiboot_info *mbi) { this->sch = *(new Scheduler()); this->elf = *(new ELF()); this->is_panic = 0; + this->env = *(new Environment()); this->mods->ready(); this->ready(); __kern.io.puts("\n"); @@ -56,17 +57,18 @@ void Kernel::init(multiboot_info *mbi) { void Kernel::welcome(void) { this->io.set_color(COLOR_LIGHT_RED); - this->io.puts(" \n\ - _ __ _ __ \n\ - | |/ / | |/ / \n\ - | ' / _ __ __ _| ' / ___ _ __ _ __ \n\ - | < | '__/ _` | < / _ \\ '__| '_ \\ \n\ - | . \\| | | (_| | . \\ __/ | | | | | \n\ - |_|\\_\\_| \\__,_|_|\\_\\___|_| |_| |_|\n\n\n"); + this->io.puts("\ + __ _ _ __ \n\ + \\ \\| || |/ /\n\ + \\ ' || ' /\n\ + > || <\n\ + / . || . \\\n\ + /_/|_||_|\\_\\\n"); - this->io.set_color(COLOR_DARK_GREY); - for (int i = 0; i < 80; i++, this->io.puts("#")); + this->io.printk(" %eKraKern\n", COLOR_WHITE); this->io.set_color(COLOR_WHITE); + for (int i = 0; i < 80; i++, this->io.puts("#")); + this->io.set_color(COLOR_DARK_GREY); } void Kernel::ready(void) { diff --git a/kernel/Makefile b/kernel/Makefile @@ -1 +1 @@ -OBJS += kernel/main.o kernel/Io.o kernel/Kernel.o kernel/Memory.o kernel/Process.o kernel/File.o kernel/FileSystem.o kernel/ProcessTable.o kernel/Modules.o kernel/IDE.o kernel/Scheduler.o kernel/ELF.o +OBJS += kernel/main.o kernel/Io.o kernel/Kernel.o kernel/Memory.o kernel/Process.o kernel/File.o kernel/FileSystem.o kernel/ProcessTable.o kernel/Modules.o kernel/IDE.o kernel/Scheduler.o kernel/ELF.o kernel/Environment.o diff --git a/lib/Makefile b/lib/Makefile @@ -1 +1 @@ -OBJS += lib/baselib.o lib/cxx.o lib/Buffer.o +OBJS += lib/baselib.o lib/cxx.o lib/Buffer.o lib/data.o diff --git a/lib/baselib.cpp b/lib/baselib.cpp @@ -96,20 +96,4 @@ extern "C" { } } -// Datas types -struct data_map { - char *key; - void *data; - struct data_map *next; -}; - -class map { - public: - map(void); - ~map(void); - - struct data_map &operator [](char *str); - - private: -}; diff --git a/lib/data.cpp b/lib/data.cpp @@ -0,0 +1,46 @@ +# include <data.hpp> + +// Maps + +map::map(void) { + this->_data = 0x0; +} + +map::~map(void) { + struct data_map *tmp; + + for (tmp = this->_data; tmp; tmp = tmp->next) { + __kern.mem.kfree(tmp->key); + if (tmp->data) + __kern.mem.kfree(tmp->data); + __kern.mem.kfree(tmp); + } +} + +struct data_map &map::operator[](char *str) { + struct data_map *tmp, *n; + + for (tmp = this->_data; tmp && strcmp(str, tmp->key); tmp = tmp->next); + if (tmp) + return *tmp; + n = (struct data_map *)__kern.mem.kmalloc(sizeof(struct data_map)); + n->next = 0x0; + n->key = (char *)__kern.mem.kmalloc(sizeof(char) * strlen(str) + 1); + n->data = 0x0; + strcpy(n->key, str); + if (this->_data) { + for (tmp = this->_data; tmp->next; tmp = tmp->next); + tmp->next = n; + } else { + this->_data = n; + } + return *n; +} + +// Data maps + +struct data_map &data_map::operator=(const char *data) { + this->data = (char *)__kern.mem.kmalloc(strlen(data)); + strcpy(this->data, data); + return *this; +} diff --git a/modules/x86/ModuleConsole.cpp b/modules/x86/ModuleConsole.cpp @@ -26,7 +26,10 @@ void ModuleConsole::tick(void) { } void ModuleConsole::prompt(void) { - __kern.io.printk("Krakern >"); + __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) { @@ -44,10 +47,14 @@ void ModuleConsole::list_files(File *root, int depth) { 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); + __kern.io.printk("%e%s ", COLOR_LIGHT_BLUE, tmp->get_name()); + else + __kern.io.printk("%s ", tmp->get_name()); + //if (tmp->get_type() == TYPE_DIRECTORY) + //tmp->scan(); + //if (tmp->get_child()) + //list_files(tmp, depth + 1); } + __kern.io.printk("\n"); } diff --git a/modules/x86/ModuleConsole.hpp b/modules/x86/ModuleConsole.hpp @@ -3,6 +3,7 @@ # define __DO_NOT_LOAD_MODULES__ # include <Module.hpp> +# include <data.hpp> class ModuleConsole : public Module { public: @@ -16,6 +17,7 @@ class ModuleConsole : public Module { private: int _is_waiting; + map _map; }; #endif