KraKern

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

commit 1898b0d1b66250a99643b38a199481caf7d9a8b8
parent 2afc6d6ce448940ad25cfce05726be1d78d1e634
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon,  1 Feb 2016 17:35:04 +0100

Add(Module Interface): Basic module interface

Diffstat:
M.ycm_extra_conf.py | 3++-
MMakefile | 6+++++-
Mincludes/core/Kernel.hpp | 5+++++
Aincludes/core/Module.hpp | 27+++++++++++++++++++++++++++
Aincludes/core/Modules.hpp | 32++++++++++++++++++++++++++++++++
Mkernel/Kernel.cpp | 5++++-
Mkernel/Makefile | 2+-
Akernel/Modules.cpp | 17+++++++++++++++++
Amodules/x86/Makefile | 1+
Amodules/x86/ModuleTest.cpp | 4++++
Amodules/x86/ModuleTest.hpp | 15+++++++++++++++
Amodules/x86/modules_conf.cpp | 7+++++++
Amodules/x86/modules_conf.h | 7+++++++
13 files changed, 127 insertions(+), 4 deletions(-)

diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py @@ -52,7 +52,7 @@ flags = [ # a "-std=<something>". # For a C project, you would set this to something like 'c99' instead of # 'c++11'. -'-std=c++11', +'-std=c++98', # ...and the same thing goes for the magic -x option which specifies the # language that the files to be compiled are written in. This is mostly # relevant for c++ headers. @@ -83,6 +83,7 @@ flags = [ './tests/gmock/include', '-I', 'includes/core', +'-I', './modules/x86/', '-I', 'includes/boot', '-fno-builtin', diff --git a/Makefile b/Makefile @@ -8,7 +8,8 @@ LD = ld ## Includes INCS = -I includes/boot \ - -I includes/core + -I includes/core \ + -I modules/$(ARCH)/ ## Flags CFLAGS = -g -O2 -w $(INCS) -trigraphs -fno-builtin \ @@ -21,6 +22,7 @@ ASMFLAGS = -f elf -o include ./boot/$(ARCH)/Makefile include ./kernel/Makefile include ./lib/Makefile +include ./modules/$(ARCH)/Makefile all: $(KERNEL) @@ -37,9 +39,11 @@ $(KERNEL): $(OBJS) $(ASM) $(ASMFLAGS) -c $< -o $@ install: $(KERNEL) + sudo losetup -o 512 /dev/loop1 ./kern.img sudo mount /dev/loop1 /mnt sudo cp $(KERNEL) /mnt/boot/. sudo umount /mnt + sudo losetup -d /dev/loop1 clean: rm -f $(OBJS) diff --git a/includes/core/Kernel.hpp b/includes/core/Kernel.hpp @@ -10,6 +10,8 @@ # include <FileSystem.hpp> # include <ProcessTable.hpp> +class Modules; + class Kernel { public: Kernel(void); @@ -24,6 +26,9 @@ class Kernel { Keyboard keyboard; FileSystem fs; ProcessTable pt; + Modules *mods; }; +# include <Modules.hpp> + #endif diff --git a/includes/core/Module.hpp b/includes/core/Module.hpp @@ -0,0 +1,27 @@ +#ifndef __MODULE__ +# define __MODULE__ + +# include <File.hpp> +# include <kern_types.h> + +enum { + MODULE_FILESYSTEM, + MODULE_DEVICE +}; + +class Module : public File { + public: + Module(char *name, u8 t) : File(name, t) {}; + virtual u32 open(u32 flag) { return -1; }; + virtual u32 close(void) { return -1; }; + virtual u32 read(u32 pos, u8 *buffer, u32 size) { return -1; }; + virtual u32 write(u32 pos, u8 *buffer, u32 size) { return -1; }; + virtual u32 ioctl(u32 id, u8 *buffer) { return -1; }; + virtual u32 remove(void) { return -1; }; + virtual void scan(void) {}; +}; + +# include <Kernel.hpp> +# include <Modules.hpp> + +#endif diff --git a/includes/core/Modules.hpp b/includes/core/Modules.hpp @@ -0,0 +1,32 @@ +#ifndef __MODULES__ +# define __MODULES__ + +# include <Kernel.hpp> + +extern Kernel __kern; + +# define MODULE_SIZE 255 +# define REGISTER_MODULE(m, r, n, name) m n(name, r) +# define import_module(m, n) extern m n; +# define main_module void Modules::load_modules(void) +# define reg_module(n, z) __kern.io.loading(z); this->_tmp = (struct s_modules *)__kern.mem.kmalloc(sizeof(struct s_modules)); this->_tmp->m = &n; this->_tmp->name = z; this->_list[this->_mod_count++] = this->_tmp; __kern.io.done(); + +class Module; + +struct s_modules { + Module *m; + const char *name; +}; + +class Modules { + public: + void init(void); + void load_modules(void); + + private: + struct s_modules *_list[MODULE_SIZE]; + int _mod_count; + struct s_modules *_tmp; +}; + +#endif diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -4,7 +4,8 @@ extern Io __io; extern GDT __gdt; extern IDT __idt; extern Memory __mem; -extern Keyboard __keyboard; +extern Keyboard __keyboard; +extern Modules __modules; Kernel __kern; void list_files(File *root, int depth) { @@ -39,6 +40,8 @@ void Kernel::init(multiboot_info *mbi) { this->fs.init(); this->pt = *(new ProcessTable()); this->pt.init(); + this->mods = &__modules; + this->mods->init(); //__kern.io.clear(); //list_files(this->fs.get_root(), 0); while (1); diff --git a/kernel/Makefile b/kernel/Makefile @@ -1 +1 @@ -OBJS += kernel/main.o kernel/Io.o kernel/Kernel.o kernel/Memory.o kernel/Keyboard.o kernel/Process.o kernel/File.o kernel/FileSystem.o kernel/ProcessTable.o +OBJS += kernel/main.o kernel/Io.o kernel/Kernel.o kernel/Memory.o kernel/Keyboard.o kernel/Process.o kernel/File.o kernel/FileSystem.o kernel/ProcessTable.o kernel/Modules.o diff --git a/kernel/Modules.cpp b/kernel/Modules.cpp @@ -0,0 +1,17 @@ +# include <Modules.hpp> + +Modules __modules; + +void Modules::init(void) { + this->_mod_count = 0; + __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); + this->load_modules(); +} + + diff --git a/modules/x86/Makefile b/modules/x86/Makefile @@ -0,0 +1 @@ +OBJS += modules/$(ARCH)/modules_conf.o modules/$(ARCH)/ModuleTest.o diff --git a/modules/x86/ModuleTest.cpp b/modules/x86/ModuleTest.cpp @@ -0,0 +1,4 @@ +# include <ModuleTest.hpp> + + +REGISTER_MODULE(ModuleTest, MODULE_DEVICE, module_test, "module_test"); diff --git a/modules/x86/ModuleTest.hpp b/modules/x86/ModuleTest.hpp @@ -0,0 +1,15 @@ +#ifndef __MODULE_TEST__ +# define __MODULE_TEST__ +# define __DO_NOT_LOAD_MODULES__ + +# include <Module.hpp> + +class ModuleTest : public Module { + public: + ModuleTest(char *name, u8 t) : Module(name, t) { + __kern.io.puts("Hi there o/"); + }; + ~ModuleTest(void) {}; +}; + +#endif diff --git a/modules/x86/modules_conf.cpp b/modules/x86/modules_conf.cpp @@ -0,0 +1,7 @@ +# include <ModuleTest.hpp> + +import_module(ModuleTest, module_test); + +main_module { + reg_module(module_test, "module_test"); +} diff --git a/modules/x86/modules_conf.h b/modules/x86/modules_conf.h @@ -0,0 +1,7 @@ +# include <ModuleTest.hpp> + +import_module(ModuleTest, module_test); + +main_module { + reg_module(module_test, "module_test"); +}