Adds semi-tested version of PMM. Adds fancy boolean printing.
This commit is contained in:
parent
e8666e90ae
commit
167e578276
5 changed files with 25 additions and 7 deletions
|
@ -117,4 +117,6 @@ public:
|
||||||
Console & operator << (int32_t value);
|
Console & operator << (int32_t value);
|
||||||
|
|
||||||
Console & operator << (void *value);
|
Console & operator << (void *value);
|
||||||
|
|
||||||
|
Console & operator << (bool value);
|
||||||
};
|
};
|
|
@ -16,8 +16,9 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates a single page.
|
* 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.
|
* Frees a given page by pointer.
|
||||||
|
|
|
@ -12,10 +12,11 @@ extern "C" void init(void)
|
||||||
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
|
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
|
||||||
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
|
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
|
||||||
<< "Hello default color.\n";
|
<< "Hello default color.\n";
|
||||||
for(int i = 0; i < 25; i++) {
|
for(int i = 0; i < 4097; i++) {
|
||||||
Console::main << (-i) << "\n";
|
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.");
|
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");
|
|
@ -30,7 +30,7 @@ void Console::clear()
|
||||||
void Console::put(char c)
|
void Console::put(char c)
|
||||||
{
|
{
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
case '\0': return;
|
||||||
case '\r': break; /* ignore \r */
|
case '\r': break; /* ignore \r */
|
||||||
case '\n':
|
case '\n':
|
||||||
this->newline();
|
this->newline();
|
||||||
|
@ -42,7 +42,7 @@ void Console::put(char c)
|
||||||
sc.bg = (int)this->bg;
|
sc.bg = (int)this->bg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(this->x >= this->screen->height) {
|
if(this->x >= this->screen->width) {
|
||||||
this->newline();
|
this->newline();
|
||||||
}
|
}
|
||||||
this->updateCaret();
|
this->updateCaret();
|
||||||
|
@ -131,4 +131,14 @@ Console & Console::operator << (void *value)
|
||||||
this->put(buffer[i]);
|
this->put(buffer[i]);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console & Console::operator << (bool value)
|
||||||
|
{
|
||||||
|
if(value == true) {
|
||||||
|
*this << "true";
|
||||||
|
} else {
|
||||||
|
*this << "false";
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
}
|
}
|
|
@ -58,7 +58,7 @@ bool PMM::markOccupied(void *page)
|
||||||
return wasSet;
|
return wasSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *PMM::alloc()
|
void *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 all bits are set
|
||||||
|
@ -76,10 +76,14 @@ void *PMM::alloc()
|
||||||
|
|
||||||
uint32_t pageId = 32 * idx + bit;
|
uint32_t pageId = 32 * idx + bit;
|
||||||
uint32_t ptr = 4096 * pageId;
|
uint32_t ptr = 4096 * pageId;
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
|
||||||
return ptrcast(ptr);
|
return ptrcast(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do something here!
|
// Do something here!
|
||||||
|
success = false;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue