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/?a=commitdiff_plain;h=93afa612c1aa6b1bf053eef36d51ba220447b002;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 30b85081..a1f0cc45 100644 --- a/src/mm/pmm.c +++ b/src/mm/pmm.c @@ -12,6 +12,7 @@ #include "utils.h" #include "uart_console.h" #include "hal/cpu.h" +#include "hal/mm.h" #include #include @@ -250,9 +251,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"); } @@ -301,7 +303,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 } }