aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorTheSoeren <imhofabian@gmail.com>2024-10-01 11:59:40 +0000
committerTheSoeren <imhofabian@gmail.com>2024-10-01 11:59:40 +0000
commit4c60bad3150b07e973eb385613a90ebb8c94ecac (patch)
tree87c4a87111c7449ce11ba8d26c4af673fd049764 /arch/x86_64/src
parente90fcb84fa43773d1e48bd82ce08381c6549a9cb (diff)
downloadteachos-4c60bad3150b07e973eb385613a90ebb8c94ecac.tar.xz
teachos-4c60bad3150b07e973eb385613a90ebb8c94ecac.zip
add structs, clean mip code
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/kernel/main.cpp60
1 files changed, 46 insertions, 14 deletions
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index 2040fe3..4deac6d 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -6,14 +6,28 @@
namespace teachos::arch::kernel
{
+ auto print_mem_info(basic_memory_info * mem_info) -> void
+ {
+ using namespace video::vga;
+
+ auto mem_lower = mem_info->mem_lower;
+ text::write("Lower memory (kB): ", text::common_attributes::green_on_black);
+ text::write_number(mem_lower, text::common_attributes::green_on_black);
+
+ auto mem_upper = mem_info->mem_upper;
+ text::write("Upper memory (kB): ", text::common_attributes::green_on_black);
+ text::write_number(mem_upper, text::common_attributes::green_on_black);
+ }
+
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);
+
+ uint32_t const entry_version = mminfo->entry_version;
text::write("Version: ", text::common_attributes::green_on_black);
text::write_number(entry_version, text::common_attributes::green_on_black);
@@ -26,10 +40,13 @@ namespace teachos::arch::kernel
{
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);
}
@@ -42,9 +59,11 @@ namespace teachos::arch::kernel
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);
@@ -56,32 +75,41 @@ namespace teachos::arch::kernel
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("Section address: ", 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("Section offset: ", 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("Section size: ", 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("Section link: ", 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("Section info: ", 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("Section address align: ", 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("Section entry size: ", text::common_attributes::green_on_black);
text::write_number(sh_entsize, text::common_attributes::green_on_black);
}
}
@@ -94,20 +122,24 @@ namespace teachos::arch::kernel
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);
+ multiboot_info * multiboot_information_pointer = (multiboot_info *)arch::boot::multiboot_information_pointer;
+ auto multiboot_tag = &(multiboot_information_pointer->tags);
/*
* Loop over the multiboot2 tags to access the information needed.
- * Tags are defined in the header.
+ * 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 != MULTIBOOT_TAG_TYPE_END;
- tag = (struct multiboot_tag *)((uint8_t *)tag + ((tag->size + 7) & ~7)))
+ tag = (struct multiboot_tag *)(((uint8_t *)tag) + ((tag->size + 7) & ~7)))
{
switch (tag->type)
{
+ case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
+ print_mem_info((struct basic_memory_info *)tag);
+ break;
case MULTIBOOT_TAG_TYPE_ELF_SECTIONS:
print_elf_sections((struct elf_symbols_section *)tag);
break;