diff options
-rw-r--r-- | src/boot/mod_mem_map.c | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/src/boot/mod_mem_map.c b/src/boot/mod_mem_map.c index 701a12e..aee2cc9 100644 --- a/src/boot/mod_mem_map.c +++ b/src/boot/mod_mem_map.c @@ -4,8 +4,68 @@ __asm__(".code16gcc\n"); +struct bios_address_descriptor { + uint32_t base_addr_low; + uint32_t base_addr_high; + uint32_t length_low; + uint32_t length_high; + uint32_t type; +}; + +uint32_t bios_mem_map_range(uint32_t continuation); +void show_bios_mem_descriptor(struct bios_address_descriptor descriptor); + +static struct bios_address_descriptor curr_address_descriptor; + void populate_memory_map(void) { - vga_graphics_write_str("pretend i populated the memory map, ok?"); - vga_graphics_write_str(" system_memory_map = "); - vga_graphics_byte_hex(0x10); + vga_graphics_newln(); + vga_graphics_return(); + vga_graphics_write_str("system_memory_map = "); + vga_graphics_newln(); + vga_graphics_return(); + uint32_t cont = 0; + do { + cont = bios_mem_map_range(cont); + //vga_graphics_int_hex(cont); + show_bios_mem_descriptor(curr_address_descriptor); + } while (cont != 0); +} + + +void show_bios_mem_descriptor(struct bios_address_descriptor descriptor) { + vga_graphics_write_str("descriptor: "); + vga_graphics_write_str(" base: 0x"); + vga_graphics_int_hex(descriptor.base_addr_high); + vga_graphics_int_hex(descriptor.base_addr_low); + vga_graphics_write_str(" length: 0x"); + vga_graphics_int_hex(descriptor.length_high); + vga_graphics_int_hex(descriptor.length_low); + vga_graphics_write_str(" "); + vga_graphics_int_hex(descriptor.type); + vga_graphics_return(); + vga_graphics_newln(); +} + +uint32_t bios_mem_map_range(uint32_t continuation) { +// I know I really want the bottom 16 bits of this address. So no warning, thanks. +#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" + uint16_t address_descriptor = (uint16_t)(&curr_address_descriptor); +#pragma GCC diagnostic pop + __asm__( + "push %%es \n" + "mov %0, %%ebx \n" + "mov $0xE820, %%eax \n" + "mov %1, %%di \n" + "mov $0, %%cx \n" + "mov %%cx, %%es \n" + "mov $0x14, %%ecx \n" + "mov $0x534d4150, %%edx \n" + "int $0x15 \n" + "mov %%ebx, %0 \n" + "pop %%es \n" + :"+r"(continuation) + :"r"(address_descriptor) + : "%eax", "%ebx", "%ecx", "%edx", "cc" + ); + return continuation; } |