Skip to content

Commit

Permalink
Kernel: Removing hardcoded offsets from Memory Manager
Browse files Browse the repository at this point in the history
Now the kernel page directory and the page tables are located at a
safe address, to prevent from paging data colliding with garbage.
  • Loading branch information
supercomputer7 authored and awesomekling committed Nov 8, 2019
1 parent 39fcd92 commit c3c905a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
7 changes: 7 additions & 0 deletions Kernel/Arch/i386/Boot/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +57,9 @@ start:

mov %ebx, multiboot_info_ptr

pushl $page_tables_start
call init
add $4, %esp

pushl $exit_message
call kprintf
Expand Down
14 changes: 6 additions & 8 deletions Kernel/VM/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Kernel/VM/MemoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);

Expand Down Expand Up @@ -79,7 +79,7 @@ class MemoryManager {
}

private:
MemoryManager();
MemoryManager(u32 physical_address_for_kernel_page_tables);
~MemoryManager();

void register_vmo(VMObject&);
Expand Down
4 changes: 2 additions & 2 deletions Kernel/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Kernel/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SECTIONS
{
Arch/i386/Boot/boot.ao
*(.multiboot)
*(.page_tables)
*(.text)
*(.text.startup)
}
Expand Down

0 comments on commit c3c905a

Please sign in to comment.