From 332f74c9a931a07aba7d420c011bd177551d8fc9 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 6 Feb 2016 20:03:23 +0100 Subject: [PATCH] Added a alloc and free function (operators >> and <<) to the PMM. Now compiles --- kernel/hal/x86/include/pmm.hpp | 2 ++ kernel/hal/x86/mm/pmm.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/kernel/hal/x86/include/pmm.hpp b/kernel/hal/x86/include/pmm.hpp index 300abc2..8e6575a 100644 --- a/kernel/hal/x86/include/pmm.hpp +++ b/kernel/hal/x86/include/pmm.hpp @@ -2,6 +2,7 @@ #define _PMM_HPP #include #include +namespace MTGosHAL { class PMM { private: uint32_t bitmap[0x8000]; //Enough for 4 GB @@ -14,4 +15,5 @@ public: auto operator()(int pages) -> void*; //alloc_multipage }; +} #endif \ No newline at end of file diff --git a/kernel/hal/x86/mm/pmm.cpp b/kernel/hal/x86/mm/pmm.cpp index 89a2b4d..a54d796 100644 --- a/kernel/hal/x86/mm/pmm.cpp +++ b/kernel/hal/x86/mm/pmm.cpp @@ -2,6 +2,7 @@ #include extern "C" const int kernel_start; extern "C" const int kernel_end; //those are voids actually +namespace MTGosHAL { PMM::PMM(struct multiboot_info * mb_info) { for(int i=0;i<0x8000;i++) bitmap[i]=0; @@ -32,4 +33,28 @@ auto PMM::markUsed(void * addr) -> void { int bit=1<<(address&0x1F); bitmap[index]&=~bit; } -//auto PMM::operator >> (void * &addr) -> PMM &; \ No newline at end of file +auto PMM::operator >> (void * &addr) -> PMM & { + for(int i=0;i<0x8000;i++) { + if(!bitmap[i]) + continue; + for(int j=0;j<32;j++) { + if(bitmap[i]&(1< PMM & { + unsigned int address=(unsigned int)addr; + address>>=12; + int index=address>>5; + int bit=1<<(address&0x1F); + bitmap[index]|=bit; + return *this; +} +} \ No newline at end of file