From 2e2861c813c7d42f1183f786c12dcf8d3f9ff8e1 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 22 Jan 2014 16:54:44 +0100 Subject: [PATCH] Prepare architecture for later --- kernel/include/physical_allocator.hpp | 10 ++++++++-- kernel/src/kernel.cpp | 3 ++- kernel/src/memory.cpp | 2 +- kernel/src/paging.cpp | 4 ++-- kernel/src/physical_allocator.cpp | 12 ++++++++++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/kernel/include/physical_allocator.hpp b/kernel/include/physical_allocator.hpp index f3ca9fed..30c5ed37 100644 --- a/kernel/include/physical_allocator.hpp +++ b/kernel/include/physical_allocator.hpp @@ -10,8 +10,14 @@ #include "stl/types.hpp" -void init_physical_allocator(); +namespace physical_allocator { -size_t allocate_physical_memory(size_t pages); +void early_init(); +void init(); + +size_t early_allocate(size_t pages); +size_t allocate(size_t pages); + +} //end of physical_allocator namespace #endif diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index eba52ecc..71c123ab 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -33,8 +33,9 @@ void kernel_main(){ interrupt::setup_interrupts(); //Prepare memory - init_physical_allocator(); + physical_allocator::early_init(); paging::init(); + physical_allocator::init(); init_memory_manager(); //Install drivers diff --git a/kernel/src/memory.cpp b/kernel/src/memory.cpp index edb03bb2..e388abf7 100644 --- a/kernel/src/memory.cpp +++ b/kernel/src/memory.cpp @@ -106,7 +106,7 @@ uintptr_t max_address; //Address of the next block being allocated uintptr_t current_virtual = 0x400000; uint64_t* allocate_block(uint64_t blocks){ - auto memory = allocate_physical_memory(blocks); + auto memory = physical_allocator::allocate(blocks); if(!memory){ return nullptr; diff --git a/kernel/src/paging.cpp b/kernel/src/paging.cpp index abf36f81..06e5961a 100644 --- a/kernel/src/paging.cpp +++ b/kernel/src/paging.cpp @@ -45,7 +45,7 @@ void paging::init(){ auto pd = reinterpret_cast(0x72000); - auto physical = allocate_physical_memory(1); + auto physical = physical_allocator::early_allocate(1); pt[256] = reinterpret_cast(physical | PRESENT | WRITE | USER); flush_tlb(reinterpret_cast(0x100000)); @@ -60,7 +60,7 @@ void paging::init(){ for(size_t pd_index = 2; pd_index < 512; ++pd_index){ //1. Allocate space for the new Page Table - physical = allocate_physical_memory(1); + physical = physical_allocator::early_allocate(1); //2. Compute logical address uint64_t logical = 0x200000 + (pd_index - 2) * paging::PAGE_SIZE; diff --git a/kernel/src/physical_allocator.cpp b/kernel/src/physical_allocator.cpp index f75f833b..14d0c955 100644 --- a/kernel/src/physical_allocator.cpp +++ b/kernel/src/physical_allocator.cpp @@ -16,11 +16,19 @@ uintptr_t current_mmap_entry_position = 0; } //End of anonymous namespace -void init_physical_allocator(){ +void physical_allocator::early_init(){ e820::finalize_memory_detection(); } -size_t allocate_physical_memory(size_t blocks){ +void physical_allocator::init(){ + //TODO +} + +size_t physical_allocator::early_allocate(size_t blocks){ + return allocate(blocks); +} + +size_t physical_allocator::allocate(size_t blocks){ if(!current_mmap_entry){ for(uint64_t i = 0; i < e820::mmap_entry_count(); ++i){ auto& entry = e820::mmap_entry(i);