Changes PMM internals from "all free" to "all used". Adds markFree, removes markOccupied.
This commit is contained in:
parent
15cabe92ad
commit
87f83eeca3
2 changed files with 11 additions and 13 deletions
|
@ -11,10 +11,9 @@ private:
|
||||||
PMM() = delete;
|
PMM() = delete;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Marks a page as occupied by external memory management.
|
* Marks a page as free by external memory management.
|
||||||
* @returns true if the page was previously free, false if it was already allocated.
|
|
||||||
*/
|
*/
|
||||||
static bool markOccupied(physical_t page);
|
static void markFree(physical_t page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates a single page.
|
* Allocates a single page.
|
||||||
|
|
|
@ -14,8 +14,8 @@ static const uint32_t BitmapLength = BitmapSize / 32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bitmap that stores the page status.
|
* Bitmap that stores the page status.
|
||||||
* A set bit marks a used page
|
* A set bit marks a page as free.
|
||||||
* An unset bit marks an unused page
|
* An unset bit marks a page as used.
|
||||||
*/
|
*/
|
||||||
static uint32_t bitmap[BitmapLength];
|
static uint32_t bitmap[BitmapLength];
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ static bool isAligned(uint32_t ptr)
|
||||||
return (ptr % 4096) == 0;
|
return (ptr % 4096) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PMM::markOccupied(physical_t page)
|
void PMM::markFree(physical_t page)
|
||||||
{
|
{
|
||||||
uint32_t ptr = page.numeric();
|
uint32_t ptr = page.numeric();
|
||||||
if(!isAligned(ptr))
|
if(!isAligned(ptr))
|
||||||
|
@ -37,26 +37,25 @@ bool PMM::markOccupied(physical_t page)
|
||||||
uint32_t idx = pageId / 32;
|
uint32_t idx = pageId / 32;
|
||||||
uint32_t bit = pageId % 32;
|
uint32_t bit = pageId % 32;
|
||||||
|
|
||||||
bool wasSet = (bitmap[idx] & (1<<bit)) != 0;
|
|
||||||
bitmap[idx] |= (1<<bit);
|
bitmap[idx] |= (1<<bit);
|
||||||
return wasSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
physical_t PMM::alloc(bool &success)
|
physical_t PMM::alloc(bool &success)
|
||||||
{
|
{
|
||||||
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
|
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
|
||||||
// fast skip when all bits are set
|
// fast skip when no bit is set
|
||||||
if(bitmap[idx] == 0xFFFFFFFF) {
|
if(bitmap[idx] == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for(uint32_t bit = 0; bit < 32; bit++) {
|
for(uint32_t bit = 0; bit < 32; bit++) {
|
||||||
uint32_t mask = (1<<bit);
|
uint32_t mask = (1<<bit);
|
||||||
if((bitmap[idx] & mask) != 0) {
|
if((bitmap[idx] & mask) == 0) {
|
||||||
|
// If bit is not set, ignore the bit.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the selected bit as used.
|
// Mark the selected bit as used.
|
||||||
bitmap[idx] |= mask;
|
bitmap[idx] &= ~mask;
|
||||||
|
|
||||||
uint32_t pageId = 32 * idx + bit;
|
uint32_t pageId = 32 * idx + bit;
|
||||||
uint32_t ptr = 4096 * pageId;
|
uint32_t ptr = 4096 * pageId;
|
||||||
|
@ -82,5 +81,5 @@ void PMM::free(physical_t page)
|
||||||
uint32_t bit = pageId % 32;
|
uint32_t bit = pageId % 32;
|
||||||
|
|
||||||
// Mark the selected bit as free.
|
// Mark the selected bit as free.
|
||||||
bitmap[idx] &= ~(1<<bit);
|
bitmap[idx] |= (1<<bit);
|
||||||
}
|
}
|
Loading…
Reference in a new issue