diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-01 07:42:09 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-10-01 07:42:09 +0000 |
| commit | b8e58d2f64fbb171b8687b9dd104ddd22fe4fc8e (patch) | |
| tree | 2cd042bd040e41b23af63d788a8c7f2f4c14e7e0 | |
| parent | 20a5e5377c0f8e0769d67a7928891597bc463e3d (diff) | |
| download | teachos-b8e58d2f64fbb171b8687b9dd104ddd22fe4fc8e.tar.xz teachos-b8e58d2f64fbb171b8687b9dd104ddd22fe4fc8e.zip | |
Adjust printing of memory map
| -rw-r--r-- | arch/x86_64/include/arch/boot/multiboot.hpp | 11 | ||||
| -rw-r--r-- | arch/x86_64/src/kernel/main.cpp | 46 |
2 files changed, 25 insertions, 32 deletions
diff --git a/arch/x86_64/include/arch/boot/multiboot.hpp b/arch/x86_64/include/arch/boot/multiboot.hpp index 4182a18..c39081a 100644 --- a/arch/x86_64/include/arch/boot/multiboot.hpp +++ b/arch/x86_64/include/arch/boot/multiboot.hpp @@ -2,8 +2,7 @@ struct multiboot_tag { - uint16_t type; - uint16_t flags; + uint32_t type; uint32_t size; }; @@ -27,6 +26,14 @@ struct memory_map_entry uint32_t reserved; }; +struct memory_map_info +{ + multiboot_tag tag; + uint32_t entry_size; + uint32_t entry_version; + struct memory_map_entry entries; +}; + /* * Define all multiboot tag types to ther respective values * The gnu boot information format is defined here: diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 6eb8521..7107a36 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -6,43 +6,32 @@ namespace teachos::arch::kernel { - - auto print_meminfo(multiboot_tag * tag) -> void + auto print_memory_map(memory_map_info * mminfo) -> void { using namespace video::vga; - uint32_t * pointer = &tag->size; - uint32_t mem_lower = *(++pointer); - uint32_t mem_upper = *(++pointer); - - text::write("Lower memory bound: ", text::common_attributes::green_on_black); - text::write_number(mem_lower, text::common_attributes::green_on_black); - text::write("Upper memory bound: ", text::common_attributes::green_on_black); - text::write_number(mem_upper, text::common_attributes::green_on_black); - } - - auto print_memory_map(multiboot_tag * tag) -> void - { - using namespace video::vga; - - uint32_t * pointer = &tag->size; - uint32_t entry_size = *(++pointer); - uint32_t entry_version = *(++pointer); + uint32_t const entry_size = mminfo->entry_size; + uint32_t const entry_version = mminfo->entry_version; + text::write("Entry Size: ", text::common_attributes::green_on_black); + text::write_number(entry_size, text::common_attributes::green_on_black); text::write("Version: ", text::common_attributes::green_on_black); text::write_number(entry_version, text::common_attributes::green_on_black); - auto begin = (struct memory_map_entry *)++pointer; - auto end = begin + entry_size; - for (auto itr = begin; itr < end; ++itr) + uint32_t const remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); + uint32_t const entry_amount = remaining_size / entry_size; + + auto begin = &mminfo->entries; + auto end = begin + entry_amount; + for (auto entry = begin; entry != end; ++entry) { text::write("Base Address: ", text::common_attributes::green_on_black); - text::write_number(itr->base_addr, text::common_attributes::green_on_black); + text::write_number(entry->base_addr, text::common_attributes::green_on_black); text::write("Length: ", text::common_attributes::green_on_black); - text::write_number(itr->length, text::common_attributes::green_on_black); + text::write_number(entry->length, text::common_attributes::green_on_black); text::write("Type: ", text::common_attributes::green_on_black); - text::write_number(itr->type, text::common_attributes::green_on_black); + text::write_number(entry->type, text::common_attributes::green_on_black); text::write("Reserved: ", text::common_attributes::green_on_black); - text::write_number(itr->reserved, text::common_attributes::green_on_black); + text::write_number(entry->reserved, text::common_attributes::green_on_black); } } @@ -68,11 +57,8 @@ namespace teachos::arch::kernel { switch (tag->type) { - case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: - print_meminfo(tag); - break; case MULTIBOOT_TAG_TYPE_MMAP: - print_memory_map(tag); + print_memory_map((struct memory_map_info *)tag); break; } } |
