Adds alignment to pointer<T>. Adds markUsed to PMM.
This commit is contained in:
parent
0b7b656b01
commit
3f77600a86
3 changed files with 48 additions and 6 deletions
|
@ -15,6 +15,11 @@ public:
|
|||
*/
|
||||
static void markFree(physical_t page);
|
||||
|
||||
/**
|
||||
* Marks a page as used by external memory management.
|
||||
*/
|
||||
static void markUsed(physical_t page);
|
||||
|
||||
/**
|
||||
* Allocates a single page.
|
||||
* @param success This boolean will contain true if the allocation was successful.
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Provides a strong pointer type which can be used to address
|
||||
* Provides a strong pointer wrapper which can be used to address
|
||||
* different memory types (physical, virtual, ...) and preventing
|
||||
* a wrong assignment.
|
||||
* @remarks The pointer size is fixed to 32 bits.
|
||||
*/
|
||||
template<typename TIdent>
|
||||
class pointer
|
||||
|
@ -16,13 +17,13 @@ public:
|
|||
*/
|
||||
static pointer invalid;
|
||||
private:
|
||||
void *ptr;
|
||||
uint32_t ptr;
|
||||
public:
|
||||
/**
|
||||
* Creates the pointer by giving a raw pointer.
|
||||
*/
|
||||
explicit pointer(void *ptr) :
|
||||
ptr(ptr)
|
||||
ptr(reinterpret_cast<uint32_t>(ptr))
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -31,7 +32,7 @@ public:
|
|||
* Creates the pointer by giving an integer value.
|
||||
*/
|
||||
explicit pointer(uint32_t value) :
|
||||
ptr(reinterpret_cast<void*>(value))
|
||||
ptr(value)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -40,18 +41,23 @@ public:
|
|||
pointer(pointer &&) = default;
|
||||
~pointer() = default;
|
||||
|
||||
pointer & operator = (const pointer & other) {
|
||||
this->ptr = other.ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numeric integer value of the pointer.
|
||||
*/
|
||||
uint32_t numeric() const {
|
||||
return reinterpret_cast<uint32_t>(this->ptr);
|
||||
return this->ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pointer as a raw pointer.
|
||||
*/
|
||||
void * data() const {
|
||||
return this->ptr;
|
||||
return reinterpret_cast<void*>(this->ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,6 +74,24 @@ public:
|
|||
explicit operator void * () const {
|
||||
return this->ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an aligned version of the pointer.
|
||||
* Rounds the pointer to the memory bottom.
|
||||
*/
|
||||
pointer alignLower(uint32_t alignment) {
|
||||
if(alignment == 0) return pointer::invalid;
|
||||
return pointer(this->ptr & ~(alignment - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an aligned version of the pointer.
|
||||
* Rounds the pointer to the memory top.
|
||||
*/
|
||||
pointer alignUpper(uint32_t alignment) {
|
||||
if(alignment == 0) return pointer::invalid;
|
||||
return pointer((this->ptr + (alignment - 1)) & ~(alignment - 1));
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
template <class T>
|
||||
|
|
|
@ -40,6 +40,19 @@ void PMM::markFree(physical_t page)
|
|||
bitmap[idx] |= (1<<bit);
|
||||
}
|
||||
|
||||
void PMM::markUsed(physical_t page)
|
||||
{
|
||||
uint32_t ptr = page.numeric();
|
||||
if(!isAligned(ptr))
|
||||
; // Do something about it!
|
||||
uint32_t pageId = ptr / 4096;
|
||||
|
||||
uint32_t idx = pageId / 32;
|
||||
uint32_t bit = pageId % 32;
|
||||
|
||||
bitmap[idx] &= ~(1<<bit);
|
||||
}
|
||||
|
||||
physical_t PMM::alloc(bool &success)
|
||||
{
|
||||
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
|
||||
|
|
Loading…
Reference in a new issue