From d7c12c5210ed1545549b9d2b14fb9fb89ce652e2 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 13 May 2015 01:18:53 +0200 Subject: implementing multiboot spec stuff --- kernel/kernel.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 21 deletions(-) (limited to 'kernel/kernel.c') diff --git a/kernel/kernel.c b/kernel/kernel.c index 8bd60ca..d0f1bce 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -13,6 +13,7 @@ #include "mem.h" #include "vmem.h" #include "interrupts.h" +#include "multiboot.h" #include "console.h" @@ -23,31 +24,79 @@ #include "task.h" -// mp informs us if this if this is the main processor -void kernel_main(uint32_t initial_stack, int mp) +void kernel_main(uint32_t eax,uint32_t ebx) { -/* - int i=0; - while(true) - { - size_t *terminal_buffer = (uint16_t*) 0xB8000; - uint16_t c16='X'; - i++; - if (i%2)c16='_'; - - c16 = c16 | 4 << 8; - terminal_buffer[2] = c16; - } - */ + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kernel_main: eax=0x%08X ebx=0x%08X",eax,ebx); - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial_stack: 0x%08X",initial_stack); // // Configuring the PIT timer. // + timer_init(); + // + // Process Multiboot Header + // + + if(eax!=0x2badb002)panic(FOOLOS_MODULE_NAME,"EAX was not set properly by your bootlaoder!"); + + multiboot_information *info; + info=ebx; + if(info->flags&&1<<9) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loaded by: \"%s\"",info->boot_loader_name); + } + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"multiboot flags: 0x%08X",info->flags); + + if(info->flags&&1<<0) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mem_lower: %d KB",info->mem_lower); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mem_upper: %d KB",info->mem_upper); + } + + if(info->flags&&1<<2) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cmdline: \"%s\"",info->cmdline); + } + + if(info->flags&&1<<3) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d modules loaded",info->mods_count); + + multiboot_mod *mod=info->mods_addr; + + for(int i=0;imods_count;i++) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mod at 0x08%X-0x08%X : %s", + mod->mod_start,mod->mod_end, mod->string); + mod++; + } + } + + if(info->flags&&1<<6) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"memory map of length %d provided by bootloader",info->mmap_length); + + uint32_t mmap_addr=info->mmap_addr; + + while(mmap_addrmmap_addr+info->mmap_length) + { + multiboot_mmap *mmap=mmap_addr; + uint32_t mem_start=mmap->base_addr; + uint32_t mem_end=mmap->base_addr+mmap->length; + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%08X - %08X / type: %d, size: %d", + mem_start, mem_end, mmap->type, mmap->size); + + mmap_addr+=mmap->size+4; + } + + + } + else panic(FOOLOS_MODULE_NAME,"Unable to continue without memory map, sorry!"); + // // Memory Init // @@ -57,22 +106,24 @@ void kernel_main(uint32_t initial_stack, int mp) // we know that here, the bootloader placed the memory map and // the number of entries. // - mem_init((physical_address)0xa001,(int)(*((uint16_t *)(0xa000)))); +// mem_init((physical_address)0xa001,(int)(*((uint16_t *)(0xa000)))); + // // init output to screen // uint32_t physbase=console_init(); + // // Activate Virtual Memory (paging) - pdirectory *dir=vmem_init(physbase); +// pdirectory *dir=vmem_init(physbase); // log buffered messages to console log_log(); - //while(1); + while(1); // // Setup Interrupts (code segment: 0x08) @@ -110,7 +161,7 @@ void kernel_main(uint32_t initial_stack, int mp) // // Initialize Multitasking // - task_init(dir); //; this will never return! + //task_init(dir); //; this will never return! } -- cgit v1.2.3