page table testing

This commit is contained in:
2026-01-28 20:49:24 +11:00
parent e4620f60c9
commit 1ef6ed223e
11 changed files with 42 additions and 17 deletions

Binary file not shown.

View File

@@ -59,4 +59,4 @@ buildimg:
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BUILDDIR)/zap-light18.psf ::
run:
qemu-system-x86_64 -drive file=$(BUILDDIR)/$(OSNAME).img -m 64M -cpu qemu64 -drive if=pflash,format=raw,unit=0,file="$(OVMFDIR)/OVMF_CODE-pure-efi.fd",readonly=on -drive if=pflash,format=raw,unit=1,file="$(OVMFDIR)/OVMF_VARS-pure-efi.fd" -net none
qemu-system-x86_64 -drive file=$(BUILDDIR)/$(OSNAME).img -m 256M -cpu qemu64 -drive if=pflash,format=raw,unit=0,file="$(OVMFDIR)/OVMF_CODE-pure-efi.fd",readonly=on -drive if=pflash,format=raw,unit=1,file="$(OVMFDIR)/OVMF_VARS-pure-efi.fd" -net none

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,8 @@
#include "Bitmap.h"
bool Bitmap::operator[](uint64_t index){
if (index > Size * 8) return false;
uint64_t byteIndex = index / 8;
uint8_t bitIndex = index % 8;
uint8_t bitIndexer = 0b10000000 >> bitIndex;
@@ -11,7 +13,9 @@ bool Bitmap::operator[](uint64_t index){
}
void Bitmap::Set(uint64_t index, bool value){
bool Bitmap::Set(uint64_t index, bool value){
if (index > Size * 8) return false;
uint64_t byteIndex = index / 8;
uint8_t bitIndex = index % 8;
uint8_t bitIndexer = 0b10000000 >> bitIndex;
@@ -19,4 +23,6 @@ void Bitmap::Set(uint64_t index, bool value){
if (value) {
Buffer[byteIndex] |= bitIndexer;
}
return true;
}

View File

@@ -7,5 +7,5 @@ class Bitmap {
size_t Size;
uint8_t* Buffer;
bool operator[](uint64_t index);
void Set(uint64_t index, bool value);
bool Set(uint64_t index, bool value);
};

View File

@@ -28,8 +28,14 @@ extern uint64_t _KernelStart;
extern uint64_t _KernelEnd;
extern "C" void _start(BootInfo* bootInfo) {
BasicRenderer newRenderer = BasicRenderer(bootInfo->framebuffer, bootInfo->psf1_Font);
newRenderer.Print("Setting up memory map...");
newRenderer.cursorPosition = {0, newRenderer.cursorPosition.y + 18};
// display information of memory map
uint64_t mMapEntries = bootInfo->mMapSize / bootInfo->mMapDescriptorSize;
@@ -53,14 +59,23 @@ extern "C" void _start(BootInfo* bootInfo) {
uint64_t fbBase = (uint64_t)bootInfo->framebuffer->BaseAddress;
uint64_t fbSize = (uint64_t)bootInfo->framebuffer->BufferSize + 0x1000;
GlobalAllocator.LockPages((void*)fbBase, fbSize / 0x1000 + 1);
for (uint64_t t = fbBase; t < fbBase + fbSize; t += 4096) {
pageTableManager.MapMemory((void*)t, (void*)t);
}
asm("mov %0, %%cr3" :: "r" (PML4));
memset(bootInfo->framebuffer->BaseAddress, 0, bootInfo->framebuffer->BufferSize);
newRenderer.Print("WE'RE USING THE NEW PAGE MAP!!!!");
newRenderer.Print("Page map set up!");
pageTableManager.MapMemory((void*)0x600000000, (void*)0x80000);
uint64_t* test = (uint64_t*)0x600000000;
*test = 26;
newRenderer.cursorPosition = {0, newRenderer.cursorPosition.y + 18};
newRenderer.Print("this should be \"26\": ");
newRenderer.Print(to_string(*test));
return;
}

View File

@@ -57,9 +57,10 @@ void PageFrameAllocator::FreePage(void* address) {
if (PageBitmap[index] == false) return; // page is already free
// free page in bitmap
PageBitmap.Set(index, false);
if (PageBitmap.Set(index, false)) {
freeMemory += 4096;
usedMemory -= 4096;
}
}
void PageFrameAllocator::FreePages(void* address, uint64_t pageCount) {
@@ -73,9 +74,10 @@ void PageFrameAllocator::LockPage(void* address) {
if (PageBitmap[index] == true) return; // page is already locked
// lock page in bitmap
PageBitmap.Set(index, true);
if (PageBitmap.Set(index, true)) {
freeMemory -= 4096;
usedMemory += 4096;
}
}
void PageFrameAllocator::LockPages(void* address, uint64_t pageCount) {
@@ -89,9 +91,10 @@ void PageFrameAllocator::UnreservePage(void* address) {
if (PageBitmap[index] == false) return; // page is already free
// free page in bitmap
PageBitmap.Set(index, false);
if (PageBitmap.Set(index, false)) {
freeMemory += 4096;
reservedMemory -= 4096;
}
}
void PageFrameAllocator::UnreservePages(void* address, uint64_t pageCount) {
@@ -105,9 +108,10 @@ void PageFrameAllocator::ReservePage(void* address) {
if (PageBitmap[index] == true) return; // page is already locked
// lock page in bitmap
PageBitmap.Set(index, true);
if (PageBitmap.Set(index, true)) {
freeMemory -= 4096;
reservedMemory += 4096;
}
}
void PageFrameAllocator::ReservePages(void* address, uint64_t pageCount) {