Adds semi-tested version of PMM. Adds fancy boolean printing.

This commit is contained in:
Felix Queißner 2016-05-03 17:07:58 +02:00
parent e8666e90ae
commit 167e578276
5 changed files with 25 additions and 7 deletions

View file

@ -117,4 +117,6 @@ public:
Console & operator << (int32_t value);
Console & operator << (void *value);
Console & operator << (bool value);
};

View file

@ -16,8 +16,9 @@ public:
/**
* Allocates a single page.
* @param success This boolean will contain true if the allocation was successful.
*/
static void* alloc();
static void* alloc(bool &success);
/**
* Frees a given page by pointer.

View file

@ -12,10 +12,11 @@ extern "C" void init(void)
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
<< "Hello default color.\n";
for(int i = 0; i < 25; i++) {
Console::main << (-i) << "\n";
for(int i = 0; i < 4097; i++) {
bool success;
void *page = PMM::alloc(success);
Console::main << "allocated page " << i << " [" << success << "]: 0x" << page << "\n";
}
Console::main << "addrof(init) = 0x" << reinterpret_cast<void*>(0xFF00FF) << "\n";
}
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");

View file

@ -30,7 +30,7 @@ void Console::clear()
void Console::put(char c)
{
switch(c) {
case '\0': return;
case '\r': break; /* ignore \r */
case '\n':
this->newline();
@ -42,7 +42,7 @@ void Console::put(char c)
sc.bg = (int)this->bg;
break;
}
if(this->x >= this->screen->height) {
if(this->x >= this->screen->width) {
this->newline();
}
this->updateCaret();
@ -131,4 +131,14 @@ Console & Console::operator << (void *value)
this->put(buffer[i]);
}
return *this;
}
Console & Console::operator << (bool value)
{
if(value == true) {
*this << "true";
} else {
*this << "false";
}
return *this;
}

View file

@ -58,7 +58,7 @@ bool PMM::markOccupied(void *page)
return wasSet;
}
void *PMM::alloc()
void *PMM::alloc(bool &success)
{
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
// fast skip when all bits are set
@ -76,10 +76,14 @@ void *PMM::alloc()
uint32_t pageId = 32 * idx + bit;
uint32_t ptr = 4096 * pageId;
success = true;
return ptrcast(ptr);
}
}
// Do something here!
success = false;
return nullptr;
}