From 99704be2023f914cba072338aab214012b910dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Tue, 3 May 2016 09:23:38 +0200 Subject: [PATCH] Implements simple bitmap allocation. --- prototypes/base/src/pmm.cpp | 74 ++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/prototypes/base/src/pmm.cpp b/prototypes/base/src/pmm.cpp index e0c5834..74af1c5 100644 --- a/prototypes/base/src/pmm.cpp +++ b/prototypes/base/src/pmm.cpp @@ -1,16 +1,88 @@ +#include #include "pmm.hpp" + +/** + * Number stored of pages in the bitmap + */ +static const uint32_t BitmapSize = 4096; /* 16 MB */ + +/** + * Number of 32-bit tuples in the bitmap. + */ +static const uint32_t BitmapLength = BitmapSize / 32; + +/** + * Bitmap that stores the page status. + * A set bit marks a used page + * An unset bit marks an unused page + */ +static uint32_t bitmap[BitmapLength]; + +static uint32_t ptrcast(void *ptr) +{ + return reinterpret_cast(ptr); +} + +static void *ptrcast(uint32_t ptr) +{ + return reinterpret_cast(ptr); +} + +static bool isAligned(uint32_t ptr) +{ + return (ptr % 4096) == 0; +} + bool PMM::markOccupied(void *page) { - return false; + uint32_t ptr = ptrcast(page); + if(!isAligned(ptr)) + ; // Do something about it! + uint32_t pageId = ptr / 4096; + + uint32_t idx = pageId / 32; + uint32_t bit = pageId % 32; + + bool wasSet = (bitmap[idx] & (1<