Test TO_PAGES and FROM_PAGES macros

This commit is contained in:
Alex 2023-03-27 02:49:56 +03:00
parent d136f9fd42
commit a09790e4f2
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 61 additions and 2 deletions

View File

@ -379,12 +379,12 @@ namespace Memory
for (uint64_t i = 0; i < Info->Memory.Entries; i++) for (uint64_t i = 0; i < Info->Memory.Entries; i++)
{ {
if (Info->Memory.Entry[i].Type != Usable) 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..."); trace("Locking bitmap pages...");
this->ReservePages(0, 0x100); this->ReservePages(0, 0x100);
this->LockPages(PageBitmap.Buffer, PageBitmap.Size / PAGE_SIZE + 1); this->LockPages(PageBitmap.Buffer, TO_PAGES(PageBitmap.Size));
} }
Physical::Physical() {} Physical::Physical() {}

59
Tests/Marco.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <types.h>
#include <memory.hpp>
#include <debug.h>
__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++;
}
}
}