diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-30 20:37:21 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-30 20:37:21 +0200 |
commit | fa5327d4cc5e47656326b8c0c55d23cd71b04462 (patch) | |
tree | e0b9f5a9bf45bedbf8383b8839c98b04c5e44552 /src/kernel/core/kmain.c | |
parent | 6466208ec051e58b824cc3c839b6b086ae910fe6 (diff) | |
download | kogata-fa5327d4cc5e47656326b8c0c55d23cd71b04462.tar.gz kogata-fa5327d4cc5e47656326b8c0c55d23cd71b04462.zip |
Use elf symbol table instead of map file for kernel
Diffstat (limited to 'src/kernel/core/kmain.c')
-rw-r--r-- | src/kernel/core/kmain.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index d09a1b5..dd66805 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -69,6 +69,9 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) { // to allocate memory ; they just increment it of the allocated quantity void* kernel_data_end = (void*)&k_end_addr; + elf_shdr_t *elf_sections = (elf_shdr_t*)(mbd->elf_sec.addr + K_HIGHHALF_ADDR); + ASSERT(sizeof(elf_shdr_t) == mbd->elf_sec.size); + dbglog_setup(); dbg_printf("Hello, kernel world!\n"); @@ -95,6 +98,14 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) { kernel_data_end = mod_end_pa; } + for (unsigned i = 0; i < mbd->elf_sec.num; i++) { + elf_sections[i].sh_addr += K_HIGHHALF_ADDR; + size_t section_end = elf_sections[i].sh_addr + elf_sections[i].sh_size; + void* section_end_pa = (void*)((section_end & 0xFFFFF000) + 0x1000); + if (section_end_pa > kernel_data_end) + kernel_data_end = section_end_pa; + } + gdt_init(); dbg_printf("GDT set up.\n"); idt_init(); dbg_printf("IDT set up.\n"); @@ -125,17 +136,13 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) { setup_syscall_table(); dbg_printf("System calls setup ok.\n"); - // If we have a kernel map, load it now - for (unsigned i = 0; i < mbd->mods_count; i++) { - char* modname = (char*)mods[i].string; - size_t len = mods[i].mod_end - mods[i].mod_start; - - if (strlen(modname) > 4 && strcmp(modname + strlen(modname) - 4, ".map") == 0) { - // Copy data to somewhere safe, as it will be modified - void* dup_data = malloc(len + 1); - memcpy(dup_data, (void*)mods[i].mod_start, len); - - load_kernel_symbol_map((char*)dup_data, len); + // Look for kernel symbol table section + for (unsigned i = 0; i < mbd->elf_sec.num; i++) { + dbg_printf("0x%p section type %d addr 0x%p - 0x%p\n", + &elf_sections[i], elf_sections[i].sh_type, + elf_sections[i].sh_addr, elf_sections[i].sh_addr + elf_sections[i].sh_size); + if (elf_sections[i].sh_type == SHT_SYMTAB) { + load_kernel_symbol_table(&elf_sections[i], &elf_sections[elf_sections[i].sh_link]); } } |