diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 2630a759..2fcde2f3 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -299,114 +299,6 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo) if ( !initrd ) Panic("No init ramdisk provided"); - // Load the kernel symbols if provided by the bootloader. - do if ( bootinfo->flags & MULTIBOOT_INFO_ELF_SHDR ) - { - // On i386 and x86_64 we identity map the first 4 MiB memory, if the - // debugging sections are outside that region, we can't access them - // directly and we'll have to memory map some physical memory. - // TODO: Correctly handle the memory being outside 4 MiB. You need to - // teach the memory management code to reserve these ranges for - // a while until we have used them and add additional complexity - // in this code. - #define BELOW_4MIB(addr, length) ((addr) + (length) <= 4*1024*1024) - - // Find and the verify the section table. - multiboot_elf_section_header_table_t* elf_sec = &bootinfo->u.elf_sec; - if ( !BELOW_4MIB(elf_sec->addr, elf_sec->size) ) - { - Log::PrintF("Warning: the section table was loaded inappropriately by the boot loader, kernel debugging symbols will not be available.\n"); - break; - } - - #define SECTION(num) ((Elf32_Shdr*) ((uintptr_t) elf_sec->addr + (uintptr_t) elf_sec->size * (uintptr_t) (num))) - - // Verify the section name section. - Elf32_Shdr* section_string_section = SECTION(elf_sec->shndx); - if ( !BELOW_4MIB(section_string_section->sh_addr, section_string_section->sh_size) ) - { - Log::PrintF("Warning: the section string table was loaded inappropriately by the boot loader, kernel debugging symbols will not be available.\n"); - break; - } - - if ( !section_string_section ) - break; - - const char* section_string_table = (const char*) (uintptr_t) section_string_section->sh_addr; - - // Find the symbol table. - Elf32_Shdr* symbol_table_section = NULL; - for ( unsigned i = 0; i < elf_sec->num && !symbol_table_section; i++ ) - { - Elf32_Shdr* section = SECTION(i); - if ( !strcmp(section_string_table + section->sh_name, ".symtab") ) - symbol_table_section = section; - } - - if ( !symbol_table_section ) - break; - - if ( !BELOW_4MIB(symbol_table_section->sh_addr, symbol_table_section->sh_size) ) - { - Log::PrintF("Warning: the symbol table was loaded inappropriately by the boot loader, kernel debugging symbols will not be available.\n"); - break; - } - - // Find the symbol string table. - Elf32_Shdr* string_table_section = NULL; - for ( unsigned i = 0; i < elf_sec->num && !string_table_section; i++ ) - { - Elf32_Shdr* section = SECTION(i); - if ( !strcmp(section_string_table + section->sh_name, ".strtab") ) - string_table_section = section; - } - - if ( !string_table_section ) - break; - - if ( !BELOW_4MIB(string_table_section->sh_addr, string_table_section->sh_size) ) - { - Log::PrintF("Warning: the symbol string table was loaded inappropriately by the boot loader, kernel debugging symbols will not be available.\n"); - break; - } - - // Duplicate the data structures and convert them to the kernel symbol - // table format and register it for later debugging. - const char* elf_string_table = (const char*) (uintptr_t) string_table_section->sh_addr; - size_t elf_string_table_size = string_table_section->sh_size; - Elf32_Sym* elf_symbols = (Elf32_Sym*) (uintptr_t) symbol_table_section->sh_addr; - size_t elf_symbol_count = symbol_table_section->sh_size / sizeof(Elf32_Sym); - - if ( !elf_symbol_count || elf_symbol_count == 1 /* null symbol */) - break; - - char* string_table = new char[elf_string_table_size]; - if ( !string_table ) - { - Log::PrintF("Warning: unable to allocate the kernel symbol string table, kernel debugging symbols will not be available.\n"); - break; - } - memcpy(string_table, elf_string_table, elf_string_table_size); - - Symbol* symbols = new Symbol[elf_symbol_count-1]; - if ( !symbols ) - { - Log::PrintF("Warning: unable to allocate the kernel symbol table, kernel debugging symbols will not be available.\n"); - delete[] string_table; - break; - } - - // Copy all entires except the leading null entry. - for ( size_t i = 1; i < elf_symbol_count; i++ ) - { - symbols[i-1].address = elf_symbols[i].st_value; - symbols[i-1].size = elf_symbols[i].st_size; - symbols[i-1].name = string_table + elf_symbols[i].st_name; - } - - SetKernelSymbolTable(symbols, elf_symbol_count-1); - } while ( false ); - // Initialize the interrupt handler table and enable interrupts. Interrupt::Init();