From a09790e4f25e0b8fd18d6321b2779dd83911dd92 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 27 Mar 2023 02:49:56 +0300 Subject: [PATCH] Test TO_PAGES and FROM_PAGES macros --- Core/Memory/PhysicalMemoryManager.cpp | 4 +- Tests/Marco.cpp | 59 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 Tests/Marco.cpp diff --git a/Core/Memory/PhysicalMemoryManager.cpp b/Core/Memory/PhysicalMemoryManager.cpp index c41fe02..e106dd0 100644 --- a/Core/Memory/PhysicalMemoryManager.cpp +++ b/Core/Memory/PhysicalMemoryManager.cpp @@ -379,12 +379,12 @@ namespace Memory for (uint64_t i = 0; i < Info->Memory.Entries; i++) { if (Info->Memory.Entry[i].Type != Usable) - this->ReservePages((void *)Info->Memory.Entry[i].BaseAddress, Info->Memory.Entry[i].Length / PAGE_SIZE + 1); + this->ReservePages(Info->Memory.Entry[i].BaseAddress, TO_PAGES(Info->Memory.Entry[i].Length)); } trace("Locking bitmap pages..."); this->ReservePages(0, 0x100); - this->LockPages(PageBitmap.Buffer, PageBitmap.Size / PAGE_SIZE + 1); + this->LockPages(PageBitmap.Buffer, TO_PAGES(PageBitmap.Size)); } Physical::Physical() {} diff --git a/Tests/Marco.cpp b/Tests/Marco.cpp new file mode 100644 index 0000000..43811f2 --- /dev/null +++ b/Tests/Marco.cpp @@ -0,0 +1,59 @@ +#include +#include +#include + +__constructor void TestMacros() +{ + { + int a = TO_PAGES(4096); + int b = FROM_PAGES(2); + + debug("a: 4096 -> %d", a); + debug("b: a -> %d", b); + + if (a != 2) + { + error("TO_PAGES is not equal to 2"); + while (1) + ; + } + + if (b != 8192) + { + error("FROM_PAGES is not equal to 8192"); + while (1) + ; + } + } + + debug("-------------------------"); + + { + uintptr_t actual = PAGE_SIZE; + int expected = 1; + + for (int i = 0; i < 128; i++) + { + int a = TO_PAGES(actual); + uintptr_t b = FROM_PAGES(expected); + + /* TODO: This is a workaround for now. */ + if (a != expected + 1) + { + error("TO_PAGES is not equal to %d (actual: %d)", expected, a); + while (1) + ; + } + + if (b != actual) + { + error("FROM_PAGES is not equal to %d (actual: %d)", actual, b); + while (1) + ; + } + + actual += PAGE_SIZE; + expected++; + } + } +} \ No newline at end of file