This commit is contained in:
nub31
2025-09-03 18:31:10 +02:00
parent 0583c8c1a3
commit f05e7c9e64
31 changed files with 164 additions and 163 deletions

View File

@@ -1,8 +1,5 @@
#include "pmm.h"
#include "../arch/api.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "arch.h"
#define BITMAP_SIZE 32768 // Supports up to 1GB of RAM
#define USABLE_REGION_SIZE 32
@@ -19,8 +16,8 @@ void pmm_init()
{
memory_region_t region = memory_map.regions[i];
uint64_t start_page = region.base_address / PAGE_SIZE;
uint64_t num_pages = region.length / PAGE_SIZE;
uint64_t start_page = region.base_address / arch_page_size();
uint64_t num_pages = region.length / arch_page_size();
for (uint64_t page = start_page; page < start_page + num_pages; page++)
{
@@ -39,7 +36,7 @@ void pmm_init()
}
// Reserve first 64MB which is reserved by boot code
for (uint64_t page = 0; page < (64 * 1024 * 1024) / PAGE_SIZE; page++)
for (uint64_t page = 0; page < (64 * 1024 * 1024) / arch_page_size(); page++)
{
if (page < BITMAP_SIZE * 8)
{
@@ -65,7 +62,7 @@ uint64_t pmm_alloc_page()
{
page_bitmap[i] |= (1 << bit);
free_pages--;
return ((i * 8 + bit) * PAGE_SIZE);
return ((i * 8 + bit) * arch_page_size());
}
}
}
@@ -77,7 +74,7 @@ uint64_t pmm_alloc_page()
// Frees the physical page at the specified address
void pmm_free_page(uint64_t addr)
{
uint64_t page = addr / PAGE_SIZE;
uint64_t page = addr / arch_page_size();
if (page < BITMAP_SIZE * 8)
{
if (page_bitmap[page / 8] & (1 << (page % 8)))