From 167e578276e1ec9fb4c8bf6ad05345fdc8ccf2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Tue, 3 May 2016 17:07:58 +0200 Subject: [PATCH] Adds semi-tested version of PMM. Adds fancy boolean printing. --- prototypes/base/include/console.hpp | 2 ++ prototypes/base/include/pmm.hpp | 3 ++- prototypes/base/init.cpp | 7 ++++--- prototypes/base/src/console.cpp | 14 ++++++++++++-- prototypes/base/src/pmm.cpp | 6 +++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/prototypes/base/include/console.hpp b/prototypes/base/include/console.hpp index 3b790fb..6c6f394 100644 --- a/prototypes/base/include/console.hpp +++ b/prototypes/base/include/console.hpp @@ -117,4 +117,6 @@ public: Console & operator << (int32_t value); Console & operator << (void *value); + + Console & operator << (bool value); }; \ No newline at end of file diff --git a/prototypes/base/include/pmm.hpp b/prototypes/base/include/pmm.hpp index f50c97b..52478cb 100644 --- a/prototypes/base/include/pmm.hpp +++ b/prototypes/base/include/pmm.hpp @@ -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. diff --git a/prototypes/base/init.cpp b/prototypes/base/init.cpp index 9fc1799..bc94c14 100644 --- a/prototypes/base/init.cpp +++ b/prototypes/base/init.cpp @@ -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(0xFF00FF) << "\n"; } static_assert(sizeof(void*) == 4, "Target platform is not 32 bit."); \ No newline at end of file diff --git a/prototypes/base/src/console.cpp b/prototypes/base/src/console.cpp index 8390c93..99326c7 100644 --- a/prototypes/base/src/console.cpp +++ b/prototypes/base/src/console.cpp @@ -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; } \ No newline at end of file diff --git a/prototypes/base/src/pmm.cpp b/prototypes/base/src/pmm.cpp index c067d83..2f9b5b8 100644 --- a/prototypes/base/src/pmm.cpp +++ b/prototypes/base/src/pmm.cpp @@ -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; }