#include "arch/kernel/main.hpp" #include "arch/boot/pointers.hpp" #include "arch/memory/multiboot.hpp" #include "arch/video/vga/text.hpp" namespace teachos::arch::kernel { auto print_mem_info(arch::memory::memory_info * mem_info) -> void { using namespace video::vga; auto mem_lower = mem_info->mem_lower; auto mem_upper = mem_info->mem_upper; } auto print_memory_map(arch::memory::memory_map * mminfo) -> void { using namespace video::vga; auto entry_size = mminfo->entry_size; auto entry_version = mminfo->entry_version; auto remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); auto entry_amount = remaining_size / entry_size; auto begin = &mminfo->entries; auto end = begin + entry_amount; for (auto entry = begin; entry != end; entry = (teachos::arch::memory::memory_area *)(((uint8_t *)entry) + ((entry_size + 7) & ~7))) { auto base_addr = entry->base_addr; auto length = entry->length; auto type = entry->type; auto reserved = entry->reserved; } } auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void { using namespace video::vga; auto num = symbol->num; auto entsize = symbol->entsize; auto shndx = symbol->shndx; auto begin = &symbol->sections; auto end = begin + num; /* * Loop over the elf section to access the information needed. * Sections are defined in the header file and are padded so that each * Section starts at an 8-bytes aligned adress. * * The increment part aligns the size to an 8-byte address. */ for (auto section = begin; section != end; section = (teachos::arch::memory::elf_section_header *)(((uint8_t *)section) + ((entsize + 7) & ~7))) { auto sh_name = section->sh_name; auto sh_type = section->sh_type; auto sh_flags = section->sh_flags; auto sh_addr = section->sh_addr; auto sh_offset = section->sh_offset; auto sh_size = section->sh_size; auto sh_link = section->sh_link; auto sh_info = section->sh_info; auto sh_addralign = section->sh_addralign; auto sh_entsize = section->sh_entsize; } } auto main() -> void { using namespace video::vga; text::clear(); text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); arch::memory::multi_boot_info * multiboot_information_pointer = (arch::memory::multi_boot_info *)arch::boot::multiboot_information_pointer; auto multiboot_tag = &(multiboot_information_pointer->tags); auto multiboot_start = arch::boot::multiboot_information_pointer; auto multiboot_end = arch::boot::multiboot_information_pointer + multiboot_information_pointer->total_size; /* * Loop over the multiboot2 tags to access the information needed. * Tags are defined in the header file and are padded so that each * Tag starts at an 8-bytes aligned adress. * * The increment part aligns the size to an 8-byte address. */ for (auto tag = multiboot_tag; tag->type != arch::memory::multi_boot_tag_type::END; tag = (arch::memory::multi_boot_tag *)(((uint8_t *)tag) + ((tag->size + 7) & ~7))) { switch (tag->type) { case arch::memory::multi_boot_tag_type::BASIC_MEMORY_INFO: print_mem_info((arch::memory::memory_info *)tag); break; case arch::memory::multi_boot_tag_type::ELF_SECTIONS: print_elf_sections((arch::memory::elf_symbols_section *)tag); break; case arch::memory::multi_boot_tag_type::MEMORY_MAP: print_memory_map((arch::memory::memory_map *)tag); break; default: // All other cases are not important and can be ignored break; } } } } // namespace teachos::arch::kernel