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 | |
parent | 440d9dc470703d20a55365b3a560196e71d450d4 (diff) | |
download | kogata-f90436dd7415354105a27846e587adefaea7ef63.tar.gz kogata-f90436dd7415354105a27846e587adefaea7ef63.zip |
Make way for nullfs
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/core/kmain.c | 55 | ||||
-rw-r--r-- | src/kernel/include/multiboot.h | 8 | ||||
-rw-r--r-- | src/kernel/user/nullfs.c | 14 |
3 files changed, 63 insertions, 14 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 diff --git a/src/kernel/include/multiboot.h b/src/kernel/include/multiboot.h index 581337a..f84b626 100644 --- a/src/kernel/include/multiboot.h +++ b/src/kernel/include/multiboot.h @@ -28,7 +28,7 @@ struct elf_section_header_table_t { unsigned long shndx; }; -struct multiboot_info_t { +typedef struct { unsigned long flags; unsigned long mem_lower; unsigned long mem_upper; @@ -42,14 +42,14 @@ struct multiboot_info_t { } u; unsigned long mmap_length; unsigned long mmap_addr; -}; +} multiboot_info_t; -struct module_t { +typedef struct { unsigned long mod_start; unsigned long mod_end; unsigned long string; unsigned long reserved; -}; +} multiboot_module_t; struct memory_map_t { unsigned long size; diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c index 3c11198..cb866c0 100644 --- a/src/kernel/user/nullfs.c +++ b/src/kernel/user/nullfs.c @@ -15,9 +15,7 @@ void register_nullfs_driver() { register_fs_driver("nullfs", &nullfs_driver_ops); } -nullfs_t *make_nullfs(char* options) { - fs_t *it = make_fs("nullfs", 0, options); - if (it == 0) return 0; +nullfs_t *as_nullfs(fs_t *it) { if (it->ops != &nullfs_ops) return 0; return (nullfs_t*)it->data; } @@ -27,4 +25,14 @@ bool nullfs_i_make(fs_handle_t *source, char* opts, fs_t *d) { return false; } +bool nullfs_add(nullfs_t *f, const char* name, void* data, nullfs_node_ops_t *ops) { + // TODO + return false; +} + +bool nullfs_add_ram_file(nullfs_t *f, const char* name, void* data, size_t init_sz, int ok_modes) { + // TODO + return false; +} + /* vim: set ts=4 sw=4 tw=0 noet :*/ |