diff --git a/OVMFbin/OVMF_VARS-pure-efi.fd b/OVMFbin/OVMF_VARS-pure-efi.fd index f6bce0b..dccf4a9 100644 Binary files a/OVMFbin/OVMF_VARS-pure-efi.fd and b/OVMFbin/OVMF_VARS-pure-efi.fd differ diff --git a/kernel/bin/CustomOS.img b/kernel/bin/CustomOS.img index 6a76328..e900d93 100644 Binary files a/kernel/bin/CustomOS.img and b/kernel/bin/CustomOS.img differ diff --git a/kernel/bin/kernel.elf b/kernel/bin/kernel.elf index 6de9165..d07eeb2 100755 Binary files a/kernel/bin/kernel.elf and b/kernel/bin/kernel.elf differ diff --git a/kernel/lib/paging/PageFrameAllocator.o b/kernel/lib/paging/PageFrameAllocator.o index e6f966d..96b60f5 100644 Binary files a/kernel/lib/paging/PageFrameAllocator.o and b/kernel/lib/paging/PageFrameAllocator.o differ diff --git a/kernel/src/paging/PageFrameAllocator.cpp b/kernel/src/paging/PageFrameAllocator.cpp index 1bf43f8..e3ffb9e 100644 --- a/kernel/src/paging/PageFrameAllocator.cpp +++ b/kernel/src/paging/PageFrameAllocator.cpp @@ -52,23 +52,6 @@ void PageFrameAllocator::InitBitmap(size_t bitmapSize, void* bufferAddress){ } } -void PageFrameAllocator::FreePage(void* address) { - uint64_t index = (uint64_t)address / 4096; - if (PageBitmap[index] == false) return; // page is already free - - // free page in bitmap - if (PageBitmap.Set(index, false)) { - freeMemory += 4096; - usedMemory -= 4096; - } -} - -void PageFrameAllocator::FreePages(void* address, uint64_t pageCount) { - for (int t = 0; t < pageCount; t++) { - FreePage((void*)((uint64_t)address + (t * 4096))); - } -} - void PageFrameAllocator::LockPage(void* address) { uint64_t index = (uint64_t)address / 4096; if (PageBitmap[index] == true) return; // page is already locked @@ -86,23 +69,6 @@ void PageFrameAllocator::LockPages(void* address, uint64_t pageCount) { } } -void PageFrameAllocator::UnreservePage(void* address) { - uint64_t index = (uint64_t)address / 4096; - if (PageBitmap[index] == false) return; // page is already free - - // free page in bitmap - if (PageBitmap.Set(index, false)) { - freeMemory += 4096; - reservedMemory -= 4096; - } -} - -void PageFrameAllocator::UnreservePages(void* address, uint64_t pageCount) { - for (int t = 0; t < pageCount; t++) { - UnreservePage((void*)((uint64_t)address + (t * 4096))); - } -} - void PageFrameAllocator::ReservePage(void* address) { uint64_t index = (uint64_t)address / 4096; if (PageBitmap[index] == true) return; // page is already locked @@ -120,17 +86,58 @@ void PageFrameAllocator::ReservePages(void* address, uint64_t pageCount) { } } +uint64_t pageBitmapIndex = 0; void* PageFrameAllocator::RequestPage() { - for (uint64_t index = 0; index < PageBitmap.Size * 8; index++) { - if (PageBitmap[index] == true) continue; + for (; pageBitmapIndex < PageBitmap.Size * 8; pageBitmapIndex++) { + if (PageBitmap[pageBitmapIndex] == true) continue; - LockPage((void*)(index * 4096)); - return (void*)(index * 4096); + LockPage((void*)(pageBitmapIndex * 4096)); + return (void*)(pageBitmapIndex * 4096); } return NULL; // page frame swap to file } +void PageFrameAllocator::FreePage(void* address) { + uint64_t index = (uint64_t)address / 4096; + if (PageBitmap[index] == false) return; // page is already free + + // free page in bitmap + if (PageBitmap.Set(index, false)) { + freeMemory += 4096; + usedMemory -= 4096; + + if (pageBitmapIndex > index) pageBitmapIndex = index; + + + } +} + +void PageFrameAllocator::FreePages(void* address, uint64_t pageCount) { + for (int t = 0; t < pageCount; t++) { + FreePage((void*)((uint64_t)address + (t * 4096))); + } +} + +void PageFrameAllocator::UnreservePage(void* address) { + uint64_t index = (uint64_t)address / 4096; + if (PageBitmap[index] == false) return; // page is already free + + // free page in bitmap + if (PageBitmap.Set(index, false)) { + freeMemory += 4096; + reservedMemory -= 4096; + + if (pageBitmapIndex > index) pageBitmapIndex = index; + } +} + +void PageFrameAllocator::UnreservePages(void* address, uint64_t pageCount) { + for (int t = 0; t < pageCount; t++) { + UnreservePage((void*)((uint64_t)address + (t * 4096))); + } +} + uint64_t PageFrameAllocator::GetFreeRAM() { return freeMemory; }