summaryrefslogtreecommitdiff
path: root/src/kernel/core/kmain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/core/kmain.cpp')
-rw-r--r--src/kernel/core/kmain.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/kernel/core/kmain.cpp b/src/kernel/core/kmain.cpp
new file mode 100644
index 0000000..0a5f2d8
--- /dev/null
+++ b/src/kernel/core/kmain.cpp
@@ -0,0 +1,79 @@
+#include <types.h>
+#include <config.h>
+
+#include "multiboot.h"
+#include "monitor.h"
+#include "sys.h"
+#include <task/idt.h>
+#include <task/timer.h>
+#include <task/task.h>
+#include <mem/gdt.h>
+#include <mem/paging.h>
+#include <mem/mem.h>
+#include <linker/elf.h>
+
+/* The kernel's main procedure. This function is called in loader_.asm.
+ This function calls the initializer functions for all system parts.
+ It then loads the modules the kernel was given by the bootloader.
+ This function never returns : once multitasking is started for good,
+ the execution flow of this function is never returned to. */
+extern "C" void kmain(multiboot_info_t* mbd, int32_t magic) {
+ ASSERT(magic == MULTIBOOT_BOOTLOADER_MAGIC);
+
+ size_t totalRam = 0;
+ uint32_t i;
+
+ mem_placementAddr = ((size_t)&end & 0xFFFFF000) + 0x1000;
+ mbd->cmdline += K_HIGHHALF_ADDR; mbd->mods_addr += K_HIGHHALF_ADDR;
+ module_t *mods = (module_t*)mbd->mods_addr;
+ for (i = 0; i < mbd->mods_count; i++) {
+ mods[i].mod_start += K_HIGHHALF_ADDR;
+ mods[i].mod_end += K_HIGHHALF_ADDR;
+ mods[i].string += K_HIGHHALF_ADDR;
+ if (mods[i].mod_end > mem_placementAddr)
+ mem_placementAddr = (mods[i].mod_end & 0xFFFFF000) + 0x1000;
+ }
+
+ monitor_clear();
+
+ monitor_write(K_OS_NAME);
+ monitor_write(" version ");
+ monitor_write(K_OS_VER);
+ monitor_write(" codename '");
+ monitor_write(K_OS_CODENAME);
+ monitor_write("' starting up :\n");
+
+
+ idt_init();
+
+ totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024);
+ paging_init(totalRam);
+ _no_more_ksbrk = true;
+ gdt_init();
+ paging_cleanup();
+
+ //kheap_init();
+ timer_init(30);
+ tasking_init();
+
+ monitor_write("\nLoading modules :\n");
+ for (i = 0; i < mbd->mods_count; i++) {
+ monitor_write(" * ");
+ monitor_write((char*)mods[i].string);
+ if (elf_check((uint8_t*)mods[i].mod_start)) {
+ monitor_write(" : Invalid ELF file\n");
+ } else {
+ process *pr = elf_exec((uint8_t*)mods[i].mod_start, PL_USER);
+ if (pr == 0) {
+ monitor_write(" : Error loading\n");
+ } else {
+ monitor_write(" : OK, pid="); monitor_writeDec(pr->pid); monitor_write("\n");
+ }
+ }
+ }
+
+ monitor_write("Modules now RULE THE WORLD !\n\n");
+ sti();
+ schedule();
+ PANIC("Should never happen. Something probably went wrong with multitasking.");
+}