diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-09 19:41:18 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-09 19:41:18 +0100 |
commit | f90436dd7415354105a27846e587adefaea7ef63 (patch) | |
tree | ed8390925b4d6b3a0c71b189d04e79d4333aa3aa /src/kernel/core/kmain.c | |
parent | 440d9dc470703d20a55365b3a560196e71d450d4 (diff) | |
download | kogata-f90436dd7415354105a27846e587adefaea7ef63.tar.gz kogata-f90436dd7415354105a27846e587adefaea7ef63.zip |
Make way for nullfs
Diffstat (limited to 'src/kernel/core/kmain.c')
-rw-r--r-- | src/kernel/core/kmain.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index 2782cc1..9ad8178 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -18,6 +18,7 @@ #include <slab_alloc.h> #include <hashtbl.h> +#include <string.h> extern const void k_end_addr; // defined in linker script : 0xC0000000 plus kernel stuff @@ -155,7 +156,12 @@ void test_thread(void* a) { } void kernel_init_stage2(void* data); -void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { +void kmain(multiboot_info_t *mbd, int32_t mb_magic) { + // used for allocation of data structures before malloc is set up + // a pointer to this pointer is passed to the functions that might have + // to allocate memory ; they just increment it of the allocated quantity + void* kernel_data_end = (void*)&k_end_addr; + dbglog_setup(); dbg_printf("Hello, kernel world!\n"); @@ -163,6 +169,20 @@ void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { ASSERT(mb_magic == MULTIBOOT_BOOTLOADER_MAGIC); + // Rewrite multiboot header so that we are in higher half + // Also check that kernel_data_end is after all modules, otherwise + // we might overwrite something. + mbd->cmdline += K_HIGHHALF_ADDR; + mbd->mods_addr += K_HIGHHALF_ADDR; + multiboot_module_t *mods = (multiboot_module_t*)mbd->mods_addr; + for (unsigned 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 ((void*)mods[i].mod_end > kernel_data_end) + kernel_data_end = (void*)((mods[i].mod_end & 0xFFFFF000) + 0x1000); + } + gdt_init(); dbg_printf("GDT set up.\n"); idt_init(); dbg_printf("IDT set up.\n"); @@ -172,10 +192,6 @@ void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { size_t total_ram = ((mbd->mem_upper + mbd->mem_lower) * 1024); dbg_printf("Total ram: %d Kb\n", total_ram / 1024); - // used for allocation of data structures before malloc is set up - // a pointer to this pointer is passed to the functions that might have - // to allocate memory ; they just increment it of the allocated quantity - void* kernel_data_end = (void*)&k_end_addr; frame_init_allocator(total_ram, &kernel_data_end); dbg_printf("kernel_data_end: 0x%p\n", kernel_data_end); @@ -196,11 +212,13 @@ void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { // enter multi-threading mode // interrupts are enabled at this moment, so all // code run from now on should be preemtible (ie thread-safe) - threading_setup(kernel_init_stage2, 0); + threading_setup(kernel_init_stage2, mbd); PANIC("Should never come here."); } void kernel_init_stage2(void* data) { + multiboot_info_t *mbd = (multiboot_info_t*)data; + dbg_print_region_info(); dbg_print_frame_stats(); @@ -215,10 +233,33 @@ void kernel_init_stage2(void* data) { for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx"); } + // Create devfs register_nullfs_driver(); - fs_t *devfs = make_fs("nullfs", 0, ""); + fs_t *devfs_fs = make_fs("nullfs", 0, ""); + ASSERT(devfs_fs != 0); + nullfs_t *devfs = as_nullfs(devfs_fs); ASSERT(devfs != 0); + // Populate devfs with files for kernel modules + multiboot_module_t *mods = (multiboot_module_t*)mbd->mods_addr; + for (unsigned i = 0; i < mbd->mods_count; i++) { + char* modname = (char*)mods[i].string; + char* e = strchr(modname, ' '); + if (e != 0) (*e) = 0; // ignore arguments + + char *b = strrchr(modname, '/'); + if (b != 0) modname = b+1; // ignore path + + char name[6 + strlen(b)]; + strcpy(name, "/mod/"); + strcpy(name+5, modname); + + nullfs_add_ram_file(devfs, name, + (void*)mods[i].mod_start, + mods[i].mod_end - mods[i].mod_start, + FM_READ); + } + //TODO : // - populate devfs with information regarding kernel command line & modules // - create user process with init module provided on command line |