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 {
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
.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
*/
/* 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
*/
/* 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 */
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)
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) */
*/
/* 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