diff options
author | supercomputer7 <liavalb@gmail.com> | 2019-11-08 16:37:33 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-08 17:38:23 +0100 |
commit | c3c905aa6c36d63b55736d361ebecb857ecfd605 (patch) | |
tree | 3e4e304da50e76a08d140de01af9bff359eec8ca /Kernel | |
parent | 39fcd92210599f903566fc914ba31f67b6c4f758 (diff) | |
download | serenity-c3c905aa6c36d63b55736d361ebecb857ecfd605.zip |
Kernel: Removing hardcoded offsets from Memory Manager
Now the kernel page directory and the page tables are located at a
safe address, to prevent from paging data colliding with garbage.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Arch/i386/Boot/boot.S | 7 | ||||
-rw-r--r-- | Kernel/VM/MemoryManager.cpp | 14 | ||||
-rw-r--r-- | Kernel/VM/MemoryManager.h | 4 | ||||
-rw-r--r-- | Kernel/init.cpp | 4 | ||||
-rw-r--r-- | Kernel/linker.ld | 1 |
5 files changed, 18 insertions, 12 deletions
diff --git a/Kernel/Arch/i386/Boot/boot.S b/Kernel/Arch/i386/Boot/boot.S index baab5ec2e8..535f13d848 100644 --- a/Kernel/Arch/i386/Boot/boot.S +++ b/Kernel/Arch/i386/Boot/boot.S @@ -31,6 +31,11 @@ stack_bottom: .skip 32768 stack_top: +.section .page_tables +.align 4096 +page_tables_start: +.skip 4096*3 + .section .text .global start @@ -52,7 +57,9 @@ start: mov %ebx, multiboot_info_ptr + pushl $page_tables_start call init + add $4, %esp pushl $exit_message call kprintf diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 475d9015bc..39fa0ad3c6 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -20,13 +20,11 @@ MemoryManager& MM return *s_the; } -MemoryManager::MemoryManager() +MemoryManager::MemoryManager(u32 physical_address_for_kernel_page_tables) { - // FIXME: Hard-coding these is stupid. Find a better way. - m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(0x4000)); - m_page_table_zero = (PageTableEntry*)0x6000; - m_page_table_one = (PageTableEntry*)0x7000; - + m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(physical_address_for_kernel_page_tables)); + m_page_table_zero = (PageTableEntry*)(physical_address_for_kernel_page_tables + PAGE_SIZE); + m_page_table_one = (PageTableEntry*)(physical_address_for_kernel_page_tables + PAGE_SIZE * 2); initialize_paging(); kprintf("MM initialized.\n"); @@ -262,9 +260,9 @@ void MemoryManager::create_identity_mapping(PageDirectory& page_directory, Virtu } } -void MemoryManager::initialize() +void MemoryManager::initialize(u32 physical_address_for_kernel_page_tables) { - s_the = new MemoryManager; + s_the = new MemoryManager(physical_address_for_kernel_page_tables); } Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr) diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 4fad7782c2..9a3ffd1018 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -38,7 +38,7 @@ class MemoryManager { public: static MemoryManager& the(); - static void initialize(); + static void initialize(u32 physical_address_for_kernel_page_tables); PageFaultResponse handle_page_fault(const PageFault&); @@ -79,7 +79,7 @@ public: } private: - MemoryManager(); + MemoryManager(u32 physical_address_for_kernel_page_tables); ~MemoryManager(); void register_vmo(VMObject&); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 77f60f1c10..16f03a59e8 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -206,7 +206,7 @@ extern "C" int __cxa_atexit ( void (*)(void *), void *, void *) return 0; } -extern "C" [[noreturn]] void init() +extern "C" [[noreturn]] void init(u32 physical_address_for_kernel_page_tables) { // this is only used one time, directly below here. we can't use this part // of libc at this point in the boot process, or we'd just pull strstr in @@ -268,7 +268,7 @@ extern "C" [[noreturn]] void init() kprintf("Starting Serenity Operating System...\n"); - MemoryManager::initialize(); + MemoryManager::initialize(physical_address_for_kernel_page_tables); if (APIC::init()) APIC::enable(0); diff --git a/Kernel/linker.ld b/Kernel/linker.ld index 169fe43c3a..43d1115caf 100644 --- a/Kernel/linker.ld +++ b/Kernel/linker.ld @@ -8,6 +8,7 @@ SECTIONS { Arch/i386/Boot/boot.ao *(.multiboot) + *(.page_tables) *(.text) *(.text.startup) } |