From d5f41b1ef9a405251321f1127a854491c6b5fb92 Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Sat, 31 May 2025 17:52:36 +0300 Subject: [PATCH] mm: fix pagetable calculation in get_physaddr & map_page --- src/mm/page_tables.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mm/page_tables.c b/src/mm/page_tables.c index 263eb03..46472ae 100644 --- a/src/mm/page_tables.c +++ b/src/mm/page_tables.c @@ -78,7 +78,7 @@ void *get_physaddr(void *virtualaddr) { unsigned long *pd = (unsigned long *)0xFFFFF000; // Here you need to check whether the PD entry is present. - unsigned long *pt = ((unsigned long *)0xFFC00000) + (0x400 * pdindex); + uint32_t *pt = (uint32_t*)(0xFFC00000 + (pdindex << 12)); // Here you need to check whether the PT entry is present. return (void *)((pt[ptindex] & ~0xFFF) + ((unsigned long)virtualaddr & 0xFFF)); @@ -109,7 +109,7 @@ void map_page(void *physaddr, void *virtualaddr, unsigned int flags) { pd[pdindex] = (uint32_t)new_pt | (flags & 0x7); // Add User bit if needed } - unsigned long *pt = ((unsigned long *)0xFFC00000) + (0x400 * pdindex); + uint32_t *pt = (uint32_t*)(0xFFC00000 + (pdindex << 12)); // Here you need to check whether the PT entry is present. // When it is, then there is already a mapping present. What do you do now?