diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-18 03:06:34 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-18 03:08:29 +0200 |
commit | 14c896ec58c1cb810d1e854f5117ac2a28ea6ffc (patch) | |
tree | 97a520c64e80f17c73793ad8c9a20299f4dbfcfa | |
parent | ba92c07a7577176918348134dd3cca8e92822e1a (diff) | |
download | serenity-14c896ec58c1cb810d1e854f5117ac2a28ea6ffc.zip |
Kernel: Pass ELF program header locations from multiboot to kernel.
Patch contributed by "pd"
-rw-r--r-- | Kernel/Boot/boot.S | 7 | ||||
-rw-r--r-- | Kernel/Process.cpp | 28 |
2 files changed, 31 insertions, 4 deletions
diff --git a/Kernel/Boot/boot.S b/Kernel/Boot/boot.S index 0fa21e34dc..ff0c5665d3 100644 --- a/Kernel/Boot/boot.S +++ b/Kernel/Boot/boot.S @@ -1,7 +1,7 @@ .set MULTIBOOT_MAGIC, 0x1badb002 .set MULTIBOOT_PAGE_ALIGN, 0x1 .set MULTIBOOT_MEMORY_INFO, 0x2 -.set MULTIBOOT_VIDEO_MODE, 0x4 +.set MULTIBOOT_VIDEO_MODE, 0x0 .set multiboot_flags, MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_VIDEO_MODE .set multiboot_checksum, -(MULTIBOOT_MAGIC + multiboot_flags) @@ -39,6 +39,9 @@ stack_top: .extern init .type init, @function +.extern multiboot_ptr +.type multiboot_ptr, @object + start: cli cld @@ -51,6 +54,8 @@ start: pushl %eax /* Multiboot header magic */ pushl %ebx /* Multiboot header pointer */ + mov %ebx, multiboot_ptr + call init pushl $exit_message diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index c91d5c1e87..99ae1af503 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1405,11 +1405,33 @@ enum class KernelMemoryCheckResult { AccessDenied }; +// FIXME: Nothing about this is really super... +// This structure is only present at offset 28 in the main multiboot info struct +// if bit 5 of offset 0 (flags) is set. We're just assuming that the flag is set. +// +// Also, there's almost certainly a better way to get that information here than +// a global set by boot.S +// +// Also I'm not 100% sure any of this is correct... + +struct mb_elf { + uint32_t num; + uint32_t size; + uint32_t addr; + uint32_t shndx; +}; + +extern "C" { +void* multiboot_ptr; +} + static KernelMemoryCheckResult check_kernel_memory_access(LinearAddress laddr, bool is_write) { - auto* kernel_elf_header = (Elf32_Ehdr*)0xf000; - auto* kernel_program_headers = (Elf32_Phdr*)(0xf000 + kernel_elf_header->e_phoff); - for (unsigned i = 0; i < kernel_elf_header->e_phnum; ++i) { + // FIXME: It would be better to have a proper structure for this... + auto* sections = (const mb_elf*)((const byte*)multiboot_ptr + 28); + + auto* kernel_program_headers = (Elf32_Phdr*)(sections->addr); + for (unsigned i = 0; i < sections->num; ++i) { auto& segment = kernel_program_headers[i]; if (segment.p_type != PT_LOAD || !segment.p_vaddr || !segment.p_memsz) continue; |