]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix: replace hardcoded 0xC0000000 in pmm.c with hal_mm_kernel_virt_base()
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:09:56 +0000 (01:09 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:09:56 +0000 (01:09 -0300)
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.

src/mm/pmm.c

index b6cbf59c4747a7c090b03fe8538b45578a942c64..5a81163e97a197334cc9bd5c1281cce80ec4fce6 100644 (file)
@@ -3,6 +3,7 @@
 #include "utils.h"
 #include "uart_console.h"
 #include "hal/cpu.h"
+#include "hal/mm.h"
 #include <stddef.h>
 #include <stdint.h>
 
@@ -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
         }
     }