Updates PMM to use physical_t instead of void*

This commit is contained in:
Felix Queißner 2016-05-03 17:49:04 +02:00
parent 1771a81bc2
commit d557bedaa9
4 changed files with 21 additions and 27 deletions

View file

@ -1,5 +1,7 @@
#pragma once
#include "pointer.hpp"
/**
* Physical memory management tool.
*/
@ -12,16 +14,16 @@ public:
* Marks a page as occupied by external memory management.
* @returns true if the page was previously free, false if it was already allocated.
*/
static bool markOccupied(void *page);
static bool markOccupied(physical_t page);
/**
* Allocates a single page.
* @param success This boolean will contain true if the allocation was successful.
*/
static void* alloc(bool &success);
static physical_t alloc(bool &success);
/**
* Frees a given page by pointer.
*/
static void free(void *page);
static void free(physical_t page);
};

View file

@ -10,6 +10,11 @@
template<typename TIdent>
class pointer
{
public:
/**
* A value that declares the pointer invalid.
*/
static pointer invalid;
private:
void *ptr;
public:
@ -65,6 +70,9 @@ public:
}
};
template <class T>
pointer<T> pointer<T>::invalid(uint32_t(0));
struct physical_t_ident;
struct virtual_t_ident;

View file

@ -14,7 +14,7 @@ extern "C" void init(void)
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
<< "Hello default color.\n";
PMM::markOccupied((void*)0x1500);
PMM::markOccupied(physical_t(0x1500));
for(int i = 0; i < 10; i++) {
bool success;

View file

@ -19,22 +19,6 @@ static const uint32_t BitmapLength = BitmapSize / 32;
*/
static uint32_t bitmap[BitmapLength];
/**
* Casts a pointer to an integer.
*/
static uint32_t ptrcast(void *ptr)
{
return reinterpret_cast<uint32_t>(ptr);
}
/**
* Casts an integer to a pointer
*/
static void *ptrcast(uint32_t ptr)
{
return reinterpret_cast<void*>(ptr);
}
/**
* Checks if an interger is 4096-aligned
*/
@ -43,9 +27,9 @@ static bool isAligned(uint32_t ptr)
return (ptr % 4096) == 0;
}
bool PMM::markOccupied(void *page)
bool PMM::markOccupied(physical_t page)
{
uint32_t ptr = ptrcast(page);
uint32_t ptr = page.numeric();
if(!isAligned(ptr))
; // Do something about it!
uint32_t pageId = ptr / 4096;
@ -58,7 +42,7 @@ bool PMM::markOccupied(void *page)
return wasSet;
}
void *PMM::alloc(bool &success)
physical_t PMM::alloc(bool &success)
{
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
// fast skip when all bits are set
@ -79,17 +63,17 @@ void *PMM::alloc(bool &success)
success = true;
return ptrcast(ptr);
return physical_t(ptr);
}
}
// Do something here!
success = false;
return nullptr;
return physical_t::invalid;
}
void PMM::free(void *page)
void PMM::free(physical_t page)
{
uint32_t ptr = ptrcast(page);
uint32_t ptr = page.numeric();
if(!isAligned(ptr))
; // Do something about it!
uint32_t pageId = ptr / 4096;