From: Tulio A M Mendes Date: Tue, 10 Feb 2026 04:09:56 +0000 (-0300) Subject: fix: replace hardcoded 0xC0000000 in pmm.c with hal_mm_kernel_virt_base() X-Git-Url: https://projects.tadryanom.me/docs/static/gitweb.css?a=commitdiff_plain;h=9a3854c8e48867812264de31893064449740c571;p=AdrOS.git fix: replace hardcoded 0xC0000000 in pmm.c with hal_mm_kernel_virt_base() pmm.c used raw 0xC0000000 to detect higher-half kernel and adjust physical addresses. Replace with hal_mm_kernel_virt_base() so the PMM works correctly on architectures with different kernel virtual base addresses. Passes: make, cppcheck, QEMU smoke test. --- diff --git a/src/mm/pmm.c b/src/mm/pmm.c index b6cbf59..5a81163 100644 --- a/src/mm/pmm.c +++ b/src/mm/pmm.c @@ -3,6 +3,7 @@ #include "utils.h" #include "uart_console.h" #include "hal/cpu.h" +#include "hal/mm.h" #include #include @@ -241,9 +242,10 @@ void pmm_init(void* boot_info) { uint64_t phys_start = (uint64_t)virt_start_ptr; uint64_t phys_end = (uint64_t)virt_end_ptr; - if (virt_start_ptr >= 0xC0000000U) { - phys_start -= 0xC0000000; - phys_end -= 0xC0000000; + uintptr_t kvbase = hal_mm_kernel_virt_base(); + if (kvbase && virt_start_ptr >= kvbase) { + phys_start -= kvbase; + phys_end -= kvbase; uart_print("[PMM] Detected Higher Half Kernel. Adjusting protection range.\n"); } @@ -292,7 +294,7 @@ void pmm_init(void* boot_info) { // 4. Protect Multiboot info (if x86) uintptr_t bi_ptr = (uintptr_t)boot_info; - if (bi_ptr < 0xC0000000U) { + if (!kvbase || bi_ptr < kvbase) { pmm_mark_region((uint64_t)bi_ptr, 4096, 1); // Protect at least 1 page } }