#include "arch/kernel/main.hpp" #include "arch/boot/multiboot.hpp" #include "arch/boot/pointers.hpp" #include "arch/video/vga/text.hpp" namespace teachos::arch::kernel { auto print_memory_map(memory_map_info * mminfo) -> void { using namespace video::vga; 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); 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(entry->base_addr, text::common_attributes::green_on_black); text::write("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(entry->type, text::common_attributes::green_on_black); text::write("Reserved: ", text::common_attributes::green_on_black); text::write_number(entry->reserved, text::common_attributes::green_on_black); } } auto print_elf_sections(elf_symbols_section * symbol) -> void { using namespace video::vga; uint16_t const num = symbol->num; text::write("Number of entries: ", text::common_attributes::green_on_black); text::write_number(num, text::common_attributes::green_on_black); uint16_t const entsize = symbol->entsize; text::write("Entry Size: ", text::common_attributes::green_on_black); text::write_number(entsize, text::common_attributes::green_on_black); uint16_t const shndx = symbol->shndx; text::write("Section index: ", text::common_attributes::green_on_black); text::write_number(shndx, text::common_attributes::green_on_black); auto begin = &symbol->sections; auto end = begin + num; for (auto section = begin; section != end; ++section) { uint32_t const sh_name = section->sh_name; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_name, text::common_attributes::green_on_black); uint32_t const sh_type = section->sh_type; text::write("Section type: ", text::common_attributes::green_on_black); text::write_number(sh_type, text::common_attributes::green_on_black); uint64_t const sh_flags = section->sh_flags; text::write("Section flags: ", text::common_attributes::green_on_black); text::write_number(sh_flags, text::common_attributes::green_on_black); uint64_t const sh_addr = section->sh_addr; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_addr, text::common_attributes::green_on_black); uint64_t const sh_offset = section->sh_offset; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_offset, text::common_attributes::green_on_black); uint64_t const sh_size = section->sh_size; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_size, text::common_attributes::green_on_black); uint32_t const sh_link = section->sh_link; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_link, text::common_attributes::green_on_black); uint32_t const sh_info = section->sh_info; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_info, text::common_attributes::green_on_black); uint64_t const sh_addralign = section->sh_addralign; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_addralign, text::common_attributes::green_on_black); uint64_t const sh_entsize = section->sh_entsize; text::write("Section name: ", text::common_attributes::green_on_black); text::write_number(sh_entsize, text::common_attributes::green_on_black); } } auto main() -> void { using namespace video::vga; text::clear(); text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); auto mip = arch::boot::multiboot_information_pointer; // Address of the first multiboot tag auto multiboot_tag = (struct multiboot_tag *)((uint8_t *)mip + 8); /* * Loop over the multiboot2 tags to access the information needed. * Tags are defined in the header. */ for (auto tag = multiboot_tag; tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag *)((uint8_t *)tag + ((tag->size + 7) & ~7))) { switch (tag->type) { case MULTIBOOT_TAG_TYPE_ELF_SECTIONS: print_elf_sections((struct elf_symbols_section *)tag); break; case MULTIBOOT_TAG_TYPE_MMAP: print_memory_map((struct memory_map_info *)tag); break; } } } } // namespace teachos::arch::kernel