bootloader: Don't use random packing in memory map

This commit is contained in:
2026-07-08 21:46:22 +03:00
parent 2e9f7077c9
commit ecfd98fad0
2 changed files with 19 additions and 10 deletions

View File

@@ -2,6 +2,8 @@
.section .stage2
.set mmap_entry_size, 24
# fills memory map data structure
# doesn't return on error
# NO REGISTERS SAVED
@@ -12,7 +14,7 @@ get_memory_map:
movl $0x0000E820, %eax
movl $0x534D4150, %edx
xorl %ebx, %ebx
movl $20, %ecx
movl $mmap_entry_size, %ecx
movw $memory_map_entries, %di
clc
@@ -24,15 +26,15 @@ get_memory_map:
cmpl $0x534D4150, %eax
jne .get_memory_map_error
# FIXME: don't assume BIOS to always return 20 bytes
# confirm that we got at least 20 bytes
cmpl $20, %ecx
jne .get_memory_map_error
jl .get_memory_map_error
# increment entry count
incl (memory_map_entry_count)
# increment entry pointer
addw %cx, %di
addw $mmap_entry_size, %di
# BIOS can indicate end of list by 0 in ebx
testl %ebx, %ebx
@@ -107,7 +109,7 @@ print_memory_map:
call print_newline
addw $20, %si
addw $mmap_entry_size, %si
decl %edx
jnz .loop_memory_map
@@ -127,6 +129,8 @@ memory_map_error_msg:
memory_map:
memory_map_entry_count:
.skip 4
# 100 entries should be enough...
memory_map_padding:
.skip 4
# 128 entries should be enough...
memory_map_entries:
.skip 20 * 100
.skip mmap_entry_size * 128

View File

@@ -21,13 +21,17 @@ struct BananBootloaderMemoryMapEntry
uint64_t address;
uint64_t length;
uint32_t type;
} __attribute__((packed));
uint32_t unused;
};
static_assert(sizeof(BananBootloaderMemoryMapEntry) == 24);
struct BananBootloaderMemoryMapInfo
{
uint32_t entry_count;
uint32_t padding;
struct BananBootloaderMemoryMapEntry entries[];
} __attribute__((packed));
};
static_assert(sizeof(BananBootloaderMemoryMapInfo) == 8);
struct BananBootloaderInfo
{
@@ -35,4 +39,5 @@ struct BananBootloaderInfo
uint32_t framebuffer_addr;
uint32_t memory_map_addr;
uint32_t kernel_paddr;
} __attribute__((packed));
};
static_assert(sizeof(BananBootloaderInfo) == 16);