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/sys.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/sys.c')
-rw-r--r-- | src/kernel/core/sys.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/kernel/core/sys.c b/src/kernel/core/sys.c index 725843e..2908868 100644 --- a/src/kernel/core/sys.c +++ b/src/kernel/core/sys.c @@ -3,6 +3,8 @@ #include <thread.h> #include <string.h> +#include <elf.h> + #include <btree.h> @@ -44,31 +46,21 @@ void sys_panic_assert(const char* assertion, const char* file, int line) { btree_t *kernel_symbol_map = 0; -void load_kernel_symbol_map(char* text, size_t len) { +void load_kernel_symbol_table(elf_shdr_t *sym, elf_shdr_t *str) { kernel_symbol_map = create_btree(id_key_cmp_fun, 0); ASSERT (kernel_symbol_map != 0); - dbg_printf("Loading kernel symbol map...\n"); - - char* it = text; - while (it < text + len) { - char* eol = it; - while (eol < text + len && *eol != 0 && *eol != '\n') eol++; - if (eol >= text + len) break; - *eol = 0; - - if (it[16] == '0' && it[17] == 'x' && it[34] == ' ' && it[49] == ' ') { - uint32_t addr = 0; - for (unsigned i = 18; i < 34; i++) { - addr *= 16; - if (it[i] >= '0' && it[i] <= '9') addr += it[i] - '0'; - if (it[i] >= 'a' && it[i] <= 'f') addr += it[i] - 'a' + 10; - } - btree_add(kernel_symbol_map, (void*)addr, it + 50); - } + dbg_printf("Loading kernel symbol table...\n"); - it = eol + 1; - } + + ASSERT(sym->sh_entsize == sizeof(elf_sym_t)); + unsigned nsym = sym->sh_size / sym->sh_entsize; + + elf_sym_t *st = (elf_sym_t*)sym->sh_addr; + const char* strtab = (const char*)(str->sh_addr); + for (unsigned j = 0; j < nsym; j++) { + btree_add(kernel_symbol_map, (void*)st[j].st_value, (void*)(strtab + st[j].st_name)); + } } void kernel_stacktrace(uint32_t ebp, uint32_t eip) { |