From 6288868ebd728720236d6a857df2658bff2d6547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 29 Sep 2024 07:02:25 +0000 Subject: Pass multiboot info to main function --- arch/x86_64/src/kernel/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 0e90264..01c14a5 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -2,14 +2,19 @@ #include "arch/video/vga/text.hpp" +#include "stdio.h" + namespace teachos::arch::kernel { - auto main() -> void + auto main(size_t multiboot_information_address) -> void { using namespace video::vga; text::clear(); text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); + char address[32U] = {}; + snprintf(address, sizeof(address), "Multiboot address: (%lu)", multiboot_information_address); + text::write(address, text::common_attributes::green_on_black); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 4e991f05b8beb7538cee6939777f36610f8b7bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 29 Sep 2024 07:56:50 +0000 Subject: Pass multiboot to main from edi register --- arch/x86_64/src/kernel/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 01c14a5..cb5092c 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -2,8 +2,6 @@ #include "arch/video/vga/text.hpp" -#include "stdio.h" - namespace teachos::arch::kernel { auto main(size_t multiboot_information_address) -> void @@ -13,8 +11,9 @@ namespace teachos::arch::kernel text::clear(); text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); - char address[32U] = {}; - snprintf(address, sizeof(address), "Multiboot address: (%lu)", multiboot_information_address); - text::write(address, text::common_attributes::green_on_black); + if (multiboot_information_address > 5) + { + return; + } } } // namespace teachos::arch::kernel -- cgit v1.2.3 From eeee7967c17704fee443a3b5b02d53a580f18b73 Mon Sep 17 00:00:00 2001 From: TheSoeren Date: Sun, 29 Sep 2024 08:52:28 +0000 Subject: use multiboot_information_pointer public variable --- arch/x86_64/src/kernel/main.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index cb5092c..e77818e 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,19 +1,25 @@ #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 main(size_t multiboot_information_address) -> void + auto main() -> void { using namespace video::vga; + auto t = arch::boot::multiboot_information_pointer; + // auto multiboot_tag = (struct multiboot_tag *) ((uint8_t) t + 8); + // for (auto tag = multiboot_tag; tag->type != ) + + if (t == 300) + { + } + text::clear(); text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); - if (multiboot_information_address > 5) - { - return; - } } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 8f91d0ef50e01440f7e6e9f4afa5887f6afefea1 Mon Sep 17 00:00:00 2001 From: TheSoeren Date: Sun, 29 Sep 2024 09:26:17 +0000 Subject: read basic mem info --- arch/x86_64/src/kernel/main.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index e77818e..8ca577a 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -10,16 +10,34 @@ namespace teachos::arch::kernel { using namespace video::vga; - auto t = arch::boot::multiboot_information_pointer; - // auto multiboot_tag = (struct multiboot_tag *) ((uint8_t) t + 8); - // for (auto tag = multiboot_tag; tag->type != ) - - if (t == 300) - { - } - 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_BASIC_MEMINFO: + uint32_t size = tag->size; + uint32_t mem_lower = *(uint32_t *)(&size + 32); + uint32_t mem_upper = *(uint32_t *)(&size + 64); + if (mem_lower > mem_upper) + { + } + text::write("BUFFER IS HERE", text::common_attributes::green_on_black); + break; + } + } } } // namespace teachos::arch::kernel -- cgit v1.2.3 From d2e1c8ba686d7d4ab32eda91c2f532676e9b8acf Mon Sep 17 00:00:00 2001 From: TheSoeren Date: Sun, 29 Sep 2024 14:03:39 +0000 Subject: create write_number function --- arch/x86_64/src/kernel/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 8ca577a..a5ffbb4 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -32,10 +32,12 @@ namespace teachos::arch::kernel uint32_t size = tag->size; uint32_t mem_lower = *(uint32_t *)(&size + 32); uint32_t mem_upper = *(uint32_t *)(&size + 64); - if (mem_lower > mem_upper) - { - } - text::write("BUFFER IS HERE", text::common_attributes::green_on_black); + + text::write_number(mem_lower, text::common_attributes::green_on_black); + 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); break; } } -- cgit v1.2.3 From 20a5e5377c0f8e0769d67a7928891597bc463e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 30 Sep 2024 11:32:56 +0000 Subject: Attempt to print memory map --- arch/x86_64/src/kernel/main.cpp | 53 ++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index a5ffbb4..6eb8521 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -6,6 +6,46 @@ namespace teachos::arch::kernel { + + auto print_meminfo(multiboot_tag * tag) -> 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); + 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) + { + text::write("Base Address: ", text::common_attributes::green_on_black); + text::write_number(itr->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("Type: ", text::common_attributes::green_on_black); + text::write_number(itr->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); + } + } + auto main() -> void { using namespace video::vga; @@ -29,15 +69,10 @@ namespace teachos::arch::kernel switch (tag->type) { case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: - uint32_t size = tag->size; - uint32_t mem_lower = *(uint32_t *)(&size + 32); - uint32_t mem_upper = *(uint32_t *)(&size + 64); - - text::write_number(mem_lower, text::common_attributes::green_on_black); - 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); + print_meminfo(tag); + break; + case MULTIBOOT_TAG_TYPE_MMAP: + print_memory_map(tag); break; } } -- cgit v1.2.3 From b8e58d2f64fbb171b8687b9dd104ddd22fe4fc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 1 Oct 2024 07:42:09 +0000 Subject: Adjust printing of memory map --- arch/x86_64/src/kernel/main.cpp | 46 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'arch/x86_64/src/kernel') 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; } } -- cgit v1.2.3 From e90fcb84fa43773d1e48bd82ce08381c6549a9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 1 Oct 2024 08:22:40 +0000 Subject: Added efl section print method --- arch/x86_64/src/kernel/main.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 7107a36..2040fe3 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -35,6 +35,57 @@ namespace teachos::arch::kernel } } + 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; @@ -57,6 +108,9 @@ namespace teachos::arch::kernel { 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; -- cgit v1.2.3 From 4c60bad3150b07e973eb385613a90ebb8c94ecac Mon Sep 17 00:00:00 2001 From: TheSoeren Date: Tue, 1 Oct 2024 11:59:40 +0000 Subject: add structs, clean mip code --- arch/x86_64/src/kernel/main.cpp | 60 +++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 14 deletions(-) (limited to 'arch/x86_64/src/kernel') 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; -- cgit v1.2.3 From 32add45849744dc976c7af6ec24f985bbace47d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 2 Oct 2024 13:02:35 +0000 Subject: Creating base frame allocation code --- arch/x86_64/src/kernel/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 4deac6d..da496a6 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -125,6 +125,12 @@ namespace teachos::arch::kernel multiboot_info * multiboot_information_pointer = (multiboot_info *)arch::boot::multiboot_information_pointer; auto multiboot_tag = &(multiboot_information_pointer->tags); + text::write("Multiboot Start: ", text::common_attributes::green_on_black); + text::write_number(arch::boot::multiboot_information_pointer, text::common_attributes::green_on_black); + text::write("Multiboot End: ", text::common_attributes::green_on_black); + text::write_number(arch::boot::multiboot_information_pointer + multiboot_information_pointer->total_size, + text::common_attributes::green_on_black); + /* * Loop over the multiboot2 tags to access the information needed. * Tags are defined in the header file and are padded so that each -- cgit v1.2.3 From c2c7ad21fdd42111180d317ef50b15b7404769d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 2 Oct 2024 13:32:28 +0000 Subject: Improve naming, add enums and move into namespace --- arch/x86_64/src/kernel/main.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index da496a6..cffbfb8 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,12 +1,12 @@ #include "arch/kernel/main.hpp" -#include "arch/boot/multiboot.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(basic_memory_info * mem_info) -> void + auto print_mem_info(arch::memory::MemoryInfo * mem_info) -> void { using namespace video::vga; @@ -19,7 +19,7 @@ namespace teachos::arch::kernel text::write_number(mem_upper, text::common_attributes::green_on_black); } - auto print_memory_map(memory_map_info * mminfo) -> void + auto print_memory_map(arch::memory::MemoryMap * mminfo) -> void { using namespace video::vga; @@ -45,14 +45,15 @@ namespace teachos::arch::kernel 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_number(static_cast::type>(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 + auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void { using namespace video::vga; @@ -122,7 +123,8 @@ namespace teachos::arch::kernel text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); - multiboot_info * multiboot_information_pointer = (multiboot_info *)arch::boot::multiboot_information_pointer; + arch::memory::MultibootInfo * multiboot_information_pointer = + (arch::memory::MultibootInfo *)arch::boot::multiboot_information_pointer; auto multiboot_tag = &(multiboot_information_pointer->tags); text::write("Multiboot Start: ", text::common_attributes::green_on_black); @@ -138,19 +140,22 @@ namespace teachos::arch::kernel * * 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))) + for (auto tag = multiboot_tag; tag->type != arch::memory::MultibootTagType::END; + tag = (arch::memory::MultibootTag *)(((uint8_t *)tag) + ((tag->size + 7) & ~7))) { switch (tag->type) { - case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: - print_mem_info((struct basic_memory_info *)tag); + case arch::memory::MultibootTagType::BASIC_MEMORY_INFO: + print_mem_info((arch::memory::MemoryInfo *)tag); break; - case MULTIBOOT_TAG_TYPE_ELF_SECTIONS: - print_elf_sections((struct elf_symbols_section *)tag); + case arch::memory::MultibootTagType::ELF_SECTIONS: + print_elf_sections((arch::memory::elf_symbols_section *)tag); break; - case MULTIBOOT_TAG_TYPE_MMAP: - print_memory_map((struct memory_map_info *)tag); + case arch::memory::MultibootTagType::MEMORY_MAP: + print_memory_map((arch::memory::MemoryMap *)tag); + break; + default: + // All other cases are not important and can be ignored break; } } -- cgit v1.2.3 From 1ab9c3c09d32283b39ca1026a9e29ada5ff7fda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 07:34:30 +0000 Subject: Renaming scheme --- arch/x86_64/src/kernel/main.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index cffbfb8..4d6296a 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -6,7 +6,7 @@ namespace teachos::arch::kernel { - auto print_mem_info(arch::memory::MemoryInfo * mem_info) -> void + auto print_mem_info(arch::memory::memory_info * mem_info) -> void { using namespace video::vga; @@ -19,7 +19,7 @@ namespace teachos::arch::kernel text::write_number(mem_upper, text::common_attributes::green_on_black); } - auto print_memory_map(arch::memory::MemoryMap * mminfo) -> void + auto print_memory_map(arch::memory::memory_map * mminfo) -> void { using namespace video::vga; @@ -45,7 +45,7 @@ namespace teachos::arch::kernel text::write_number(entry->length, text::common_attributes::green_on_black); text::write("Type: ", text::common_attributes::green_on_black); - text::write_number(static_cast::type>(entry->type), + text::write_number(static_cast::type>(entry->type), text::common_attributes::green_on_black); text::write("Reserved: ", text::common_attributes::green_on_black); @@ -123,8 +123,8 @@ namespace teachos::arch::kernel text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); - arch::memory::MultibootInfo * multiboot_information_pointer = - (arch::memory::MultibootInfo *)arch::boot::multiboot_information_pointer; + 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); text::write("Multiboot Start: ", text::common_attributes::green_on_black); @@ -140,19 +140,19 @@ namespace teachos::arch::kernel * * The increment part aligns the size to an 8-byte address. */ - for (auto tag = multiboot_tag; tag->type != arch::memory::MultibootTagType::END; - tag = (arch::memory::MultibootTag *)(((uint8_t *)tag) + ((tag->size + 7) & ~7))) + 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::MultibootTagType::BASIC_MEMORY_INFO: - print_mem_info((arch::memory::MemoryInfo *)tag); + case arch::memory::multi_boot_tag_type::BASIC_MEMORY_INFO: + print_mem_info((arch::memory::memory_info *)tag); break; - case arch::memory::MultibootTagType::ELF_SECTIONS: + case arch::memory::multi_boot_tag_type::ELF_SECTIONS: print_elf_sections((arch::memory::elf_symbols_section *)tag); break; - case arch::memory::MultibootTagType::MEMORY_MAP: - print_memory_map((arch::memory::MemoryMap *)tag); + 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 -- cgit v1.2.3 From f7df7167f0c54bd8da79dbf2d48bda5d7491fd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 08:45:04 +0000 Subject: Remove high memory kernel and needless prints --- arch/x86_64/src/kernel/main.cpp | 120 ++++++++++++---------------------------- 1 file changed, 35 insertions(+), 85 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 4d6296a..e867bad 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -9,47 +9,28 @@ 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; - 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(arch::memory::memory_map * mminfo) -> void { using namespace video::vga; - uint32_t const entry_size = mminfo->entry_size; - 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); - - uint32_t const remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); - uint32_t const entry_amount = remaining_size / entry_size; + 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) + for (auto entry = begin; entry != end; + entry = (teachos::arch::memory::memory_area *)(((uint8_t *)entry) + ((entry_size + 7) & ~7))) { - 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(static_cast::type>(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 base_addr = entry->base_addr; + auto length = entry->length; + auto type = entry->type; + auto reserved = entry->reserved; } } @@ -57,61 +38,33 @@ namespace teachos::arch::kernel { 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 num = symbol->num; + auto entsize = symbol->entsize; + auto shndx = symbol->shndx; 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 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 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 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 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 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 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 entry size: ", text::common_attributes::green_on_black); - text::write_number(sh_entsize, text::common_attributes::green_on_black); + /* + * 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; } } @@ -127,11 +80,8 @@ namespace teachos::arch::kernel (arch::memory::multi_boot_info *)arch::boot::multiboot_information_pointer; auto multiboot_tag = &(multiboot_information_pointer->tags); - text::write("Multiboot Start: ", text::common_attributes::green_on_black); - text::write_number(arch::boot::multiboot_information_pointer, text::common_attributes::green_on_black); - text::write("Multiboot End: ", text::common_attributes::green_on_black); - text::write_number(arch::boot::multiboot_information_pointer + multiboot_information_pointer->total_size, - text::common_attributes::green_on_black); + 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. -- cgit v1.2.3 From f044a1740f49d632d1436df949fa2285918e5937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 08:53:21 +0000 Subject: Remove unused variable declarations --- arch/x86_64/src/kernel/main.cpp | 42 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index e867bad..3436127 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -8,42 +8,28 @@ 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; + video::vga::text::write("Memory info low: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(mem_info->mem_lower, video::vga::text::common_attributes::green_on_black); } 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 entry_amount = remaining_size / mminfo->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))) + entry = (teachos::arch::memory::memory_area *)(((uint8_t *)entry) + ((mminfo->entry_size + 7) & ~7))) { - auto base_addr = entry->base_addr; - auto length = entry->length; - auto type = entry->type; - auto reserved = entry->reserved; + video::vga::text::write("Looping Memory area", video::vga::text::common_attributes::green_on_black); } } 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; + auto end = begin + symbol->num; /* * Loop over the elf section to access the information needed. @@ -53,18 +39,9 @@ namespace teachos::arch::kernel * 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))) + section = (teachos::arch::memory::elf_section_header *)(((uint8_t *)section) + ((symbol->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; + video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); } } @@ -80,9 +57,6 @@ namespace teachos::arch::kernel (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 -- cgit v1.2.3 From 8e3c15daad14dfba76444d83bc4133acd00eaf8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 09:12:40 +0000 Subject: Revert 8 byte aligning --- arch/x86_64/src/kernel/main.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 3436127..d94cbba 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -19,8 +19,7 @@ namespace teachos::arch::kernel auto begin = &mminfo->entries; auto end = begin + entry_amount; - for (auto entry = begin; entry != end; - entry = (teachos::arch::memory::memory_area *)(((uint8_t *)entry) + ((mminfo->entry_size + 7) & ~7))) + for (auto entry = begin; entry != end; ++entry) { video::vga::text::write("Looping Memory area", video::vga::text::common_attributes::green_on_black); } @@ -30,16 +29,7 @@ namespace teachos::arch::kernel { auto begin = &symbol->sections; auto end = begin + symbol->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) + ((symbol->entsize + 7) & ~7))) + for (auto section = begin; section != end; ++section) { video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); } -- cgit v1.2.3 From 1b33fc5746be4d23b1c4adacc02263fbcf994524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 09:58:17 +0000 Subject: Add assert method --- arch/x86_64/src/kernel/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index d94cbba..fa1e464 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -6,6 +6,15 @@ namespace teachos::arch::kernel { + auto assert(bool condition) -> void + { + video::vga::text::write("Assert failed", video::vga::text::common_attributes::green_on_black); + while (!condition) + { + ; + } + } + auto print_mem_info(arch::memory::memory_info * mem_info) -> void { video::vga::text::write("Memory info low: ", video::vga::text::common_attributes::green_on_black); @@ -14,6 +23,10 @@ namespace teachos::arch::kernel auto print_memory_map(arch::memory::memory_map * mminfo) -> void { + auto expected_entry_size = mminfo->entry_size; + constexpr auto actual_size = sizeof(arch::memory::memory_area); + assert(expected_entry_size == actual_size); + auto remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); auto entry_amount = remaining_size / mminfo->entry_size; -- cgit v1.2.3 From b9c5aea495653bb9fc347fa6ba5976b42510af53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 12:40:33 +0000 Subject: Added elf section type enum --- arch/x86_64/src/kernel/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index fa1e464..481264c 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -24,8 +24,8 @@ namespace teachos::arch::kernel auto print_memory_map(arch::memory::memory_map * mminfo) -> void { auto expected_entry_size = mminfo->entry_size; - constexpr auto actual_size = sizeof(arch::memory::memory_area); - assert(expected_entry_size == actual_size); + constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); + assert(expected_entry_size == actual_entry_size); auto remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); auto entry_amount = remaining_size / mminfo->entry_size; @@ -40,6 +40,10 @@ namespace teachos::arch::kernel auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void { + auto expected_entry_size = symbol->entsize; + constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); + assert(expected_entry_size == actual_entry_size); + auto begin = &symbol->sections; auto end = begin + symbol->num; for (auto section = begin; section != end; ++section) -- cgit v1.2.3 From 78153377d8a964d6b7290d966e5c1d30369abc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 6 Oct 2024 13:40:24 +0000 Subject: Improve naming --- arch/x86_64/src/kernel/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 481264c..636ddf2 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -40,12 +40,12 @@ namespace teachos::arch::kernel auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void { - auto expected_entry_size = symbol->entsize; + auto expected_entry_size = symbol->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); assert(expected_entry_size == actual_entry_size); auto begin = &symbol->sections; - auto end = begin + symbol->num; + auto end = begin + symbol->number_of_sections; for (auto section = begin; section != end; ++section) { video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); -- cgit v1.2.3 From a6018f84cc8971859d90109740fbada8d77ff5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 8 Oct 2024 07:58:53 +0000 Subject: Add more asserts for elf sections --- arch/x86_64/src/kernel/main.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 636ddf2..2ba4fe2 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -11,7 +11,12 @@ namespace teachos::arch::kernel video::vga::text::write("Assert failed", video::vga::text::common_attributes::green_on_black); while (!condition) { - ; + // Trick the compiler into thinking the variable is changes at run time, + // to prevent the while loop being optimized away + // See + // https://stackoverflow.com/questions/9495856/how-to-prevent-g-from-optimizing-out-a-loop-controlled-by-a-variable-that-can + // for mroe information. + asm volatile("" : "+g"(condition)); } } @@ -44,8 +49,20 @@ namespace teachos::arch::kernel constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); assert(expected_entry_size == actual_entry_size); + auto expected_total_size = symbol->tag.size; + auto actual_total_entry_size = actual_entry_size * symbol->number_of_sections; + constexpr auto actual_total_section_size = + sizeof(arch::memory::elf_symbols_section) - actual_entry_size - sizeof(uint32_t); + auto actual_total_size = actual_total_entry_size + actual_total_section_size; + assert(expected_total_size == actual_total_size); + auto begin = &symbol->sections; auto end = begin + symbol->number_of_sections; + // TODO: Last value is completly wrong, should show 0 but shows huge value for size of entries in the table of the + // SHT_NULL elf section entry. Memory around value also make no sense and look even worse? But according to api + // value should be zero :( + // assert(begin->is_null()); + for (auto section = begin; section != end; ++section) { video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); -- cgit v1.2.3 From 7edd03e9a14a3025b4d2b2ff51d838d20b79b2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 8 Oct 2024 11:30:01 +0000 Subject: Added doxygen comments to all fields and structs --- arch/x86_64/src/kernel/main.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 2ba4fe2..6486b7c 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -63,6 +63,9 @@ namespace teachos::arch::kernel // value should be zero :( // assert(begin->is_null()); + // TODO: Check if only contains one DYNSYM or SYMTAB but not both! + // TODO: Check if only contains one dynamic section + for (auto section = begin; section != end; ++section) { video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); -- cgit v1.2.3 From 88818847446c010ccbfce0690a20a4e6531ca6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 8 Oct 2024 11:39:32 +0000 Subject: Add additional sanity checks to elf parsing --- arch/x86_64/src/kernel/main.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 6486b7c..40b2fe5 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -63,13 +63,26 @@ namespace teachos::arch::kernel // value should be zero :( // assert(begin->is_null()); - // TODO: Check if only contains one DYNSYM or SYMTAB but not both! - // TODO: Check if only contains one dynamic section + std::size_t symbol_table_section_count = 0U; + std::size_t dynamic_section_count = 0U; for (auto section = begin; section != end; ++section) { + if (section->type == arch::memory::elf_section_type::DYNAMIC_SYMBOL_TABLE || + section->type == arch::memory::elf_section_type::SYMBOL_TABLE) + { + symbol_table_section_count++; + } + else if (section->type == arch::memory::elf_section_type::DYNAMIC) + { + dynamic_section_count++; + } video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); } + + // TODO: Contains two symbol tables and 4 dynamic sections, that is definetly wrong, perhaps same reason as above? + assert(symbol_table_section_count == 1U); + assert(dynamic_section_count == 1U); } auto main() -> void -- cgit v1.2.3 From 553f3a824511bb8107982b2b2737f5b1dff59855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 13 Oct 2024 08:28:30 +0000 Subject: Add missing cpp files to cmake and fix elf alignment issues --- arch/x86_64/src/kernel/main.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 40b2fe5..01c955b 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -28,6 +28,7 @@ namespace teachos::arch::kernel auto print_memory_map(arch::memory::memory_map * mminfo) -> void { + // TODO: Probably same issue as elf sections because the values are kind of weird as well auto expected_entry_size = mminfo->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); assert(expected_entry_size == actual_entry_size); @@ -45,23 +46,20 @@ namespace teachos::arch::kernel auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void { + // TODO: Check if sectiosn now actually match the elf file auto expected_entry_size = symbol->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); assert(expected_entry_size == actual_entry_size); auto expected_total_size = symbol->tag.size; auto actual_total_entry_size = actual_entry_size * symbol->number_of_sections; - constexpr auto actual_total_section_size = - sizeof(arch::memory::elf_symbols_section) - actual_entry_size - sizeof(uint32_t); + constexpr auto actual_total_section_size = sizeof(arch::memory::elf_symbols_section) - sizeof(uint32_t); auto actual_total_size = actual_total_entry_size + actual_total_section_size; assert(expected_total_size == actual_total_size); - auto begin = &symbol->sections; + auto begin = reinterpret_cast(&symbol->end); auto end = begin + symbol->number_of_sections; - // TODO: Last value is completly wrong, should show 0 but shows huge value for size of entries in the table of the - // SHT_NULL elf section entry. Memory around value also make no sense and look even worse? But according to api - // value should be zero :( - // assert(begin->is_null()); + assert(begin->is_null()); std::size_t symbol_table_section_count = 0U; std::size_t dynamic_section_count = 0U; @@ -80,9 +78,8 @@ namespace teachos::arch::kernel video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); } - // TODO: Contains two symbol tables and 4 dynamic sections, that is definetly wrong, perhaps same reason as above? assert(symbol_table_section_count == 1U); - assert(dynamic_section_count == 1U); + assert(dynamic_section_count <= 1U); } auto main() -> void -- cgit v1.2.3 From b3c8a1819226b7dbaad82623c8294b99c91297ef Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 13 Oct 2024 10:58:34 +0000 Subject: continue implementing frame allocator --- arch/x86_64/src/kernel/main.cpp | 99 ++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 32 deletions(-) (limited to 'arch/x86_64/src/kernel') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 01c955b..3fa44d3 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,6 +1,7 @@ #include "arch/kernel/main.hpp" #include "arch/boot/pointers.hpp" +#include "arch/memory/frame_allocator.hpp" #include "arch/memory/multiboot.hpp" #include "arch/video/vga/text.hpp" @@ -20,33 +21,21 @@ namespace teachos::arch::kernel } } - auto print_mem_info(arch::memory::memory_info * mem_info) -> void + auto process_memory_map(arch::memory::memory_map * mminfo, arch::memory::memory_area ** memory_areas, + uint8_t * area_count) -> void { - video::vga::text::write("Memory info low: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(mem_info->mem_lower, video::vga::text::common_attributes::green_on_black); - } - - auto print_memory_map(arch::memory::memory_map * mminfo) -> void - { - // TODO: Probably same issue as elf sections because the values are kind of weird as well auto expected_entry_size = mminfo->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); assert(expected_entry_size == actual_entry_size); - auto remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t)); - auto entry_amount = remaining_size / mminfo->entry_size; - - auto begin = &mminfo->entries; - auto end = begin + entry_amount; - for (auto entry = begin; entry != end; ++entry) - { - video::vga::text::write("Looping Memory area", video::vga::text::common_attributes::green_on_black); - } + *memory_areas = &mminfo->entries; + *area_count = sizeof(mminfo->entries) / mminfo->entry_size; } - auto print_elf_sections(arch::memory::elf_symbols_section * symbol) -> void + auto process_elf_sections(arch::memory::elf_symbols_section * symbol, uint64_t * kernel_start, + uint64_t * kernel_end) -> void { - // TODO: Check if sectiosn now actually match the elf file + // Validate ELF sections auto expected_entry_size = symbol->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); assert(expected_entry_size == actual_entry_size); @@ -66,16 +55,31 @@ namespace teachos::arch::kernel for (auto section = begin; section != end; ++section) { - if (section->type == arch::memory::elf_section_type::DYNAMIC_SYMBOL_TABLE || - section->type == arch::memory::elf_section_type::SYMBOL_TABLE) + switch (section->type) { - symbol_table_section_count++; - } - else if (section->type == arch::memory::elf_section_type::DYNAMIC) - { - dynamic_section_count++; + case arch::memory::elf_section_type::PROGRAMM: + if (section->virtual_address < *kernel_start) + { + *kernel_start = section->virtual_address; + } + + if (section->virtual_address + section->section_size > *kernel_end) + { + *kernel_end = section->virtual_address + section->section_size; + } + break; + case arch::memory::elf_section_type::DYNAMIC_SYMBOL_TABLE: + case arch::memory::elf_section_type::SYMBOL_TABLE: + symbol_table_section_count++; + break; + case arch::memory::elf_section_type::DYNAMIC: + symbol_table_section_count++; + dynamic_section_count++; + break; + default: + // All other cases are not important and can be ignored + break; } - video::vga::text::write("Looping Code section", video::vga::text::common_attributes::green_on_black); } assert(symbol_table_section_count == 1U); @@ -94,6 +98,13 @@ namespace teachos::arch::kernel (arch::memory::multi_boot_info *)arch::boot::multiboot_information_pointer; auto multiboot_tag = &(multiboot_information_pointer->tags); + uint64_t kernel_start = UINT64_MAX; + uint64_t kernel_end = 0; + uint64_t multiboot_start = arch::boot::multiboot_information_pointer; + uint64_t multiboot_end = multiboot_start + multiboot_information_pointer->total_size; + arch::memory::memory_area * memory_areas = nullptr; + uint8_t area_count = 0; + /* * Loop over the multiboot2 tags to access the information needed. * Tags are defined in the header file and are padded so that each @@ -106,19 +117,43 @@ namespace teachos::arch::kernel { switch (tag->type) { - case arch::memory::multi_boot_tag_type::BASIC_MEMORY_INFO: - print_mem_info((arch::memory::memory_info *)t