From: Tulio A M Mendes Date: Fri, 6 Feb 2026 00:53:54 +0000 (-0300) Subject: x86: fix multiboot2 mmap tag and boot.S physical symbol addressing X-Git-Url: https://projects.tadryanom.me/sitemap.xml?a=commitdiff_plain;h=15b91627ac803d4cb8247bd6aacde7f2252920aa;p=AdrOS.git x86: fix multiboot2 mmap tag and boot.S physical symbol addressing --- diff --git a/include/arch/x86/multiboot2.h b/include/arch/x86/multiboot2.h index c412097..c336290 100644 --- a/include/arch/x86/multiboot2.h +++ b/include/arch/x86/multiboot2.h @@ -48,12 +48,19 @@ struct multiboot_tag_basic_meminfo { uint32_t mem_upper; }; +struct multiboot_mmap_entry { + uint64_t addr; + uint64_t len; + uint32_t type; + uint32_t zero; +}; + struct multiboot_tag_mmap { uint32_t type; uint32_t size; uint32_t entry_size; uint32_t entry_version; - struct multiboot_mmap_entry entries[0]; + struct multiboot_mmap_entry entries[]; }; struct multiboot_tag_module { @@ -64,13 +71,6 @@ struct multiboot_tag_module { char string[0]; }; -struct multiboot_mmap_entry { - uint64_t addr; - uint64_t len; - uint32_t type; - uint32_t zero; -}; - #define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 diff --git a/src/arch/x86/boot.S b/src/arch/x86/boot.S index c1c48a9..3714db5 100644 --- a/src/arch/x86/boot.S +++ b/src/arch/x86/boot.S @@ -9,10 +9,9 @@ .set PAGE_SIZE, 4096 /* - * This macro converts a virtual address (symbol) to a physical address - * by subtracting 3GB. We need this before paging is enabled. + * Convert virtual symbols to physical addresses before paging is enabled + * by subtracting KERNEL_VIRT_BASE. */ -#define V2P(x) ((x) - KERNEL_VIRT_BASE) .section .multiboot_header .align 8 @@ -37,7 +36,8 @@ _start: */ /* Setup a temporary stack (using physical address) */ - mov $(V2P(stack_top)), %esp + mov $stack_top, %esp + sub $KERNEL_VIRT_BASE, %esp /* Save Multiboot Info (ebx) and Magic (eax) */ push %eax @@ -51,7 +51,8 @@ _start: */ /* 1. Get Physical Address of Page Table 0 (PT0) */ - mov $(V2P(boot_pt0)), %edi + mov $boot_pt0, %edi + sub $KERNEL_VIRT_BASE, %edi /* 2. Map 0-4MB to this PT (fill 1024 entries) */ /* Entry 0: Addr 0 | Present | RW */ @@ -67,10 +68,12 @@ _start: loop 1b /* 3. Get Physical Address of Page Directory */ - mov $(V2P(boot_pd)), %edi + mov $boot_pd, %edi + sub $KERNEL_VIRT_BASE, %edi /* 4. Link PT0 to PD at index 0 (Identity Map 0-4MB) */ - mov $(V2P(boot_pt0)), %edx + mov $boot_pt0, %edx + sub $KERNEL_VIRT_BASE, %edx or $3, %edx mov %edx, (%edi) @@ -79,12 +82,14 @@ _start: mov %edx, 3072(%edi) /* Offset 768 * 4 bytes = 3072 */ /* 6. Recursive Mapping (Optional, good for VMM later) at index 1023 */ - mov $(V2P(boot_pd)), %edx + mov $boot_pd, %edx + sub $KERNEL_VIRT_BASE, %edx or $3, %edx mov %edx, 4092(%edi) /* 7. Load CR3 */ - mov $(V2P(boot_pd)), %ecx + mov $boot_pd, %ecx + sub $KERNEL_VIRT_BASE, %ecx mov %ecx, %cr3 /* 8. Enable Paging (Set PG bit in CR0) */ @@ -131,7 +136,8 @@ higher_half_start: */ /* Re-map low memory for safety until PMM parses tags */ - mov $(V2P(boot_pt0)), %edx + mov $boot_pt0, %edx + sub $KERNEL_VIRT_BASE, %edx or $3, %edx mov %edx, boot_pd