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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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/main.cpp') 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 *)tag); - break; case arch::memory::multi_boot_tag_type::ELF_SECTIONS: - print_elf_sections((arch::memory::elf_symbols_section *)tag); + process_elf_sections((arch::memory::elf_symbols_section *)tag, &kernel_start, &kernel_end); break; case arch::memory::multi_boot_tag_type::MEMORY_MAP: - print_memory_map((arch::memory::memory_map *)tag); + process_memory_map((arch::memory::memory_map *)tag, &memory_areas, &area_count); break; default: // All other cases are not important and can be ignored break; } } + + // Kernel start 0x100000 + // Kernel end 0x23E943 + // Kernel Size 0x13E943 -> 1'304'899 + // Multiboot start 0x241AA0 + // Multiboot end 0x242280 + // Multiboot Size 0x7E0 -> 2'016 + // Memory area start 0x241b10 + // + // Address of Frame: 0x203F00 + auto allocator = arch::memory::area_frame_allocator(kernel_start, kernel_end, multiboot_start, multiboot_end, + memory_areas, area_count); + std::optional allocated = allocator.allocate_frame(); + + // WATCH OUT: using optional::value() crashes the build... I think its because of missing exception handling + if (allocated.has_value()) + { + video::vga::text::write("Allocated Frame address: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(reinterpret_cast(&allocated->frame_number), + video::vga::text::common_attributes::green_on_black); + video::vga::text::write("Allocated Frame number: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(allocated->frame_number, video::vga::text::common_attributes::green_on_black); + } + else + { + video::vga::text::write("NO VALUE", video::vga::text::common_attributes::green_on_black); + } } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 8beb8b758c33cf1ac5357b31296927e7df8cf971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 14 Oct 2024 08:15:16 +0000 Subject: Fix typos, implementation in header and missing doxygen --- arch/x86_64/src/kernel/main.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 3fa44d3..1289eb6 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -16,24 +16,28 @@ namespace teachos::arch::kernel // 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. + // for more information. asm volatile("" : "+g"(condition)); } } - auto process_memory_map(arch::memory::memory_map * mminfo, arch::memory::memory_area ** memory_areas, - uint8_t * area_count) -> void + auto process_memory_map(arch::memory::memory_map * mminfo, arch::memory::memory_area *& memory_areas, + uint8_t & area_count) -> void { auto expected_entry_size = mminfo->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); assert(expected_entry_size == actual_entry_size); - *memory_areas = &mminfo->entries; - *area_count = sizeof(mminfo->entries) / mminfo->entry_size; + auto total_size = mminfo->tag.size; + auto total_entries_size = total_size - sizeof(arch::memory::memory_map) + actual_entry_size; + auto number_of_entries = total_entries_size / actual_entry_size; + + memory_areas = &mminfo->entries; + area_count = number_of_entries; } - auto process_elf_sections(arch::memory::elf_symbols_section * symbol, uint64_t * kernel_start, - uint64_t * kernel_end) -> void + auto process_elf_sections(arch::memory::elf_symbols_section * symbol, uint64_t & kernel_start, + uint64_t & kernel_end) -> void { // Validate ELF sections auto expected_entry_size = symbol->entry_size; @@ -58,14 +62,14 @@ namespace teachos::arch::kernel switch (section->type) { case arch::memory::elf_section_type::PROGRAMM: - if (section->virtual_address < *kernel_start) + if (section->virtual_address < kernel_start) { - *kernel_start = section->virtual_address; + kernel_start = section->virtual_address; } - if (section->virtual_address + section->section_size > *kernel_end) + if (section->virtual_address + section->section_size > kernel_end) { - *kernel_end = section->virtual_address + section->section_size; + kernel_end = section->virtual_address + section->section_size; } break; case arch::memory::elf_section_type::DYNAMIC_SYMBOL_TABLE: @@ -73,7 +77,6 @@ namespace teachos::arch::kernel symbol_table_section_count++; break; case arch::memory::elf_section_type::DYNAMIC: - symbol_table_section_count++; dynamic_section_count++; break; default: @@ -94,8 +97,8 @@ namespace teachos::arch::kernel 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_information_pointer = + reinterpret_cast(arch::boot::multiboot_information_pointer); auto multiboot_tag = &(multiboot_information_pointer->tags); uint64_t kernel_start = UINT64_MAX; @@ -113,15 +116,17 @@ namespace teachos::arch::kernel * 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))) + tag = reinterpret_cast((reinterpret_cast(tag)) + + ((tag->size + 7) & ~7))) { switch (tag->type) { case arch::memory::multi_boot_tag_type::ELF_SECTIONS: - process_elf_sections((arch::memory::elf_symbols_section *)tag, &kernel_start, &kernel_end); + process_elf_sections(reinterpret_cast(tag), kernel_start, + kernel_end); break; case arch::memory::multi_boot_tag_type::MEMORY_MAP: - process_memory_map((arch::memory::memory_map *)tag, &memory_areas, &area_count); + process_memory_map(reinterpret_cast(tag), memory_areas, area_count); break; default: // All other cases are not important and can be ignored @@ -140,7 +145,7 @@ namespace teachos::arch::kernel // Address of Frame: 0x203F00 auto allocator = arch::memory::area_frame_allocator(kernel_start, kernel_end, multiboot_start, multiboot_end, memory_areas, area_count); - std::optional allocated = allocator.allocate_frame(); + auto allocated = allocator.allocate_frame(); // WATCH OUT: using optional::value() crashes the build... I think its because of missing exception handling if (allocated.has_value()) -- cgit v1.2.3 From 7fc99d55ffff20b49dc4088efc95b68b3d33a45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 14 Oct 2024 09:47:49 +0000 Subject: Use scoped switch statements to extract calculations to variables --- arch/x86_64/src/kernel/main.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 1289eb6..1c6aa55 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -9,8 +9,13 @@ namespace teachos::arch::kernel { auto assert(bool condition) -> void { + if (condition) + { + return; + } + video::vga::text::write("Assert failed", video::vga::text::common_attributes::green_on_black); - while (!condition) + for (;;) { // Trick the compiler into thinking the variable is changes at run time, // to prevent the while loop being optimized away @@ -39,7 +44,6 @@ namespace teachos::arch::kernel auto process_elf_sections(arch::memory::elf_symbols_section * symbol, uint64_t & kernel_start, uint64_t & kernel_end) -> void { - // 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); @@ -61,17 +65,18 @@ namespace teachos::arch::kernel { switch (section->type) { - case arch::memory::elf_section_type::PROGRAMM: + 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) + auto virtual_address_end = section->virtual_address + section->section_size; + if (virtual_address_end > kernel_end) { - kernel_end = section->virtual_address + section->section_size; + kernel_end = virtual_address_end; } break; + } case arch::memory::elf_section_type::DYNAMIC_SYMBOL_TABLE: case arch::memory::elf_section_type::SYMBOL_TABLE: symbol_table_section_count++; @@ -121,13 +126,16 @@ namespace teachos::arch::kernel { switch (tag->type) { - case arch::memory::multi_boot_tag_type::ELF_SECTIONS: - process_elf_sections(reinterpret_cast(tag), kernel_start, - kernel_end); + case arch::memory::multi_boot_tag_type::ELF_SECTIONS: { + auto symbol = reinterpret_cast(tag); + process_elf_sections(symbol, kernel_start, kernel_end); break; - case arch::memory::multi_boot_tag_type::MEMORY_MAP: - process_memory_map(reinterpret_cast(tag), memory_areas, area_count); + } + case arch::memory::multi_boot_tag_type::MEMORY_MAP: { + auto mminfo = reinterpret_cast(tag); + process_memory_map(mminfo, memory_areas, area_count); break; + } default: // All other cases are not important and can be ignored break; -- cgit v1.2.3 From e9dd8ea4343b943032f2af87fbae9f46fe1f9328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 14 Oct 2024 09:55:11 +0000 Subject: Move 8 byte alignment into seperate method --- arch/x86_64/src/kernel/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 1c6aa55..106ca2a 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -94,6 +94,13 @@ namespace teachos::arch::kernel assert(dynamic_section_count <= 1U); } + template + requires std::is_pointer::value + auto align_to_8_byte_boundary(T ptr, uint32_t size) -> T + { + return reinterpret_cast(reinterpret_cast(ptr) + ((size + 7) & ~7)); + } + auto main() -> void { using namespace video::vga; @@ -121,8 +128,7 @@ namespace teachos::arch::kernel * 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 = reinterpret_cast((reinterpret_cast(tag)) + - ((tag->size + 7) & ~7))) + tag = align_to_8_byte_boundary(tag, tag->size)) { switch (tag->type) { -- cgit v1.2.3 From 563a3dcbc1f2d26adcd6761358c45d635738f3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 14 Oct 2024 12:42:54 +0000 Subject: Add more info on which elf flag means which objdump flag --- arch/x86_64/src/kernel/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 106ca2a..bdf530c 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -63,6 +63,29 @@ namespace teachos::arch::kernel for (auto section = begin; section != end; ++section) { + bool const writeable = section->flags.writeable(); + bool const occupies_memory = section->flags.occupies_memory(); + bool const is_executable = section->flags.is_executable(); + bool const contains_duplicate_data = section->flags.contains_duplicate_data(); + bool const contains_strings = section->flags.contains_strings(); + bool const section_header_info_is_section_header_table_index = + section->flags.section_header_info_is_section_header_table_index(); + bool const preserve_ordering_after_combination = section->flags.preserve_ordering_after_combination(); + bool const requires_special_os_processing = section->flags.requires_special_os_processing(); + bool const is_section_group_member = section->flags.is_section_group_member(); + bool const holds_thread_local_data = section->flags.holds_thread_local_data(); + bool const is_compressed = section->flags.is_compressed(); + bool const has_special_ordering_requirements = section->flags.has_special_ordering_requirements(); + bool const is_excluded_unless_referenced_or_allocated = + section->flags.is_excluded_unless_referenced_or_allocated(); + + if (writeable && occupies_memory && is_executable && contains_duplicate_data && contains_strings && + section_header_info_is_section_header_table_index && preserve_ordering_after_combination && + requires_special_os_processing && is_section_group_member && holds_thread_local_data && is_compressed && + has_special_ordering_requirements && is_excluded_unless_referenced_or_allocated) + { + } + switch (section->type) { case arch::memory::elf_section_type::PROGRAMM: { -- cgit v1.2.3 From 38e0b13ab9a4997fdf9f311fd125825919d2e6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 14 Oct 2024 14:03:27 +0000 Subject: Start developing paging --- arch/x86_64/src/kernel/main.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index bdf530c..7e4a336 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -5,6 +5,8 @@ #include "arch/memory/multiboot.hpp" #include "arch/video/vga/text.hpp" +#include + namespace teachos::arch::kernel { auto assert(bool condition) -> void @@ -63,7 +65,7 @@ namespace teachos::arch::kernel for (auto section = begin; section != end; ++section) { - bool const writeable = section->flags.writeable(); + bool const writable = section->flags.writable(); bool const occupies_memory = section->flags.occupies_memory(); bool const is_executable = section->flags.is_executable(); bool const contains_duplicate_data = section->flags.contains_duplicate_data(); @@ -79,7 +81,7 @@ namespace teachos::arch::kernel bool const is_excluded_unless_referenced_or_allocated = section->flags.is_excluded_unless_referenced_or_allocated(); - if (writeable && occupies_memory && is_executable && contains_duplicate_data && contains_strings && + if (writable && occupies_memory && is_executable && contains_duplicate_data && contains_strings && section_header_info_is_section_header_table_index && preserve_ordering_after_combination && requires_special_os_processing && is_section_group_member && holds_thread_local_data && is_compressed && has_special_ordering_requirements && is_excluded_unless_referenced_or_allocated) @@ -182,20 +184,16 @@ namespace teachos::arch::kernel // Address of Frame: 0x203F00 auto allocator = arch::memory::area_frame_allocator(kernel_start, kernel_end, multiboot_start, multiboot_end, memory_areas, area_count); - auto allocated = allocator.allocate_frame(); // WATCH OUT: using optional::value() crashes the build... I think its because of missing exception handling - if (allocated.has_value()) - { - video::vga::text::write("Allocated Frame address: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(reinterpret_cast(&allocated->frame_number), - video::vga::text::common_attributes::green_on_black); - video::vga::text::write("Allocated Frame number: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(allocated->frame_number, video::vga::text::common_attributes::green_on_black); - } - else + auto last_allocated = allocator.allocate_frame(); + auto allocated = last_allocated; + do { - video::vga::text::write("NO VALUE", video::vga::text::common_attributes::green_on_black); - } + last_allocated = allocated; + allocated = allocator.allocate_frame(); + } while (allocated.has_value()); + video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(allocated->frame_number, video::vga::text::common_attributes::green_on_black); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 205934ca45d591924b4be6e7ae5a8849958e0cf6 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Tue, 15 Oct 2024 08:23:39 +0000 Subject: continue implementing paging --- arch/x86_64/src/kernel/main.cpp | 42 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 7e4a336..c8981a8 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/exception_handling/assert.hpp" #include "arch/memory/frame_allocator.hpp" #include "arch/memory/multiboot.hpp" #include "arch/video/vga/text.hpp" @@ -9,31 +10,12 @@ namespace teachos::arch::kernel { - auto assert(bool condition) -> void - { - if (condition) - { - return; - } - - video::vga::text::write("Assert failed", video::vga::text::common_attributes::green_on_black); - for (;;) - { - // 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 more information. - asm volatile("" : "+g"(condition)); - } - } - auto process_memory_map(arch::memory::memory_map * mminfo, arch::memory::memory_area *& memory_areas, uint8_t & area_count) -> void { auto expected_entry_size = mminfo->entry_size; constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); - assert(expected_entry_size == actual_entry_size); + arch::exception_handling::assert(expected_entry_size == actual_entry_size, "Unexpected memoryarea entry size"); auto total_size = mminfo->tag.size; auto total_entries_size = total_size - sizeof(arch::memory::memory_map) + actual_entry_size; @@ -48,17 +30,18 @@ namespace teachos::arch::kernel { 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); + arch::exception_handling::assert(expected_entry_size == actual_entry_size, + "Unexpected elf_section_header 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) - sizeof(uint32_t); auto actual_total_size = actual_total_entry_size + actual_total_section_size; - assert(expected_total_size == actual_total_size); + arch::exception_handling::assert(expected_total_size == actual_total_size, "Unexpected elf_symbols total size"); auto begin = reinterpret_cast(&symbol->end); auto end = begin + symbol->number_of_sections; - assert(begin->is_null()); + arch::exception_handling::assert(begin->is_null(), "Missing elf_section_header begin"); std::size_t symbol_table_section_count = 0U; std::size_t dynamic_section_count = 0U; @@ -115,8 +98,8 @@ namespace teachos::arch::kernel } } - assert(symbol_table_section_count == 1U); - assert(dynamic_section_count <= 1U); + arch::exception_handling::assert(symbol_table_section_count == 1U, "Unexpected symbol_table_count value"); + arch::exception_handling::assert(dynamic_section_count <= 1U, "Unexpected dynamic_section_count value"); } template @@ -173,15 +156,6 @@ namespace teachos::arch::kernel } } - // Kernel start 0x100000 - // Kernel end 0x23E943 - // Kernel Size 0x13E943 -> 1'304'899 - // Multiboot start 0x241AA0 - // Multiboot end 0x242280 - // Multiboot Size 0x7E0 -> 2'016 - // Memory area start 0x241b10 - // - // Address of Frame: 0x203F00 auto allocator = arch::memory::area_frame_allocator(kernel_start, kernel_end, multiboot_start, multiboot_end, memory_areas, area_count); -- cgit v1.2.3 From 11f9c91e602bd0231e6bc402418dedf445e47402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 15 Oct 2024 08:45:29 +0000 Subject: Adding enum flags --- arch/x86_64/src/kernel/main.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index c8981a8..12498d0 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -48,21 +48,27 @@ namespace teachos::arch::kernel for (auto section = begin; section != end; ++section) { - bool const writable = section->flags.writable(); - bool const occupies_memory = section->flags.occupies_memory(); - bool const is_executable = section->flags.is_executable(); - bool const contains_duplicate_data = section->flags.contains_duplicate_data(); - bool const contains_strings = section->flags.contains_strings(); - bool const section_header_info_is_section_header_table_index = - section->flags.section_header_info_is_section_header_table_index(); - bool const preserve_ordering_after_combination = section->flags.preserve_ordering_after_combination(); - bool const requires_special_os_processing = section->flags.requires_special_os_processing(); - bool const is_section_group_member = section->flags.is_section_group_member(); - bool const holds_thread_local_data = section->flags.holds_thread_local_data(); - bool const is_compressed = section->flags.is_compressed(); - bool const has_special_ordering_requirements = section->flags.has_special_ordering_requirements(); + bool const writable = section->flags.contains_flags(arch::memory::elf_section_flags::WRITABLE); + bool const occupies_memory = section->flags.contains_flags(arch::memory::elf_section_flags::OCCUPIES_MEMORY); + bool const is_executable = section->flags.contains_flags(arch::memory::elf_section_flags::EXECUTABLE_CODE); + bool const contains_duplicate_data = + section->flags.contains_flags(arch::memory::elf_section_flags::DUPLICATE_DATA); + bool const contains_strings = section->flags.contains_flags(arch::memory::elf_section_flags::CONTAINS_STRING); + bool const section_header_info_is_section_header_table_index = section->flags.contains_flags( + arch::memory::elf_section_flags::SECTION_HEADER_INFO_IS_SECTION_HEADER_TABLE_INDEX); + bool const preserve_ordering_after_combination = + section->flags.contains_flags(arch::memory::elf_section_flags::PRESERVE_ORDERING_AFTER_COMBINATION); + bool const requires_special_os_processing = + section->flags.contains_flags(arch::memory::elf_section_flags::REQUIRES_SPECIAL_OS_PROCESSING); + bool const is_section_group_member = + section->flags.contains_flags(arch::memory::elf_section_flags::SECTION_GROUP_MEMBER); + bool const holds_thread_local_data = + section->flags.contains_flags(arch::memory::elf_section_flags::HOLDS_THREAD_LOCAL_DATA); + bool const is_compressed = section->flags.contains_flags(arch::memory::elf_section_flags::COMPRESSED); + bool const has_special_ordering_requirements = + section->flags.contains_flags(arch::memory::elf_section_flags::SPECIAL_ORDERING_REQUIREMENTS); bool const is_excluded_unless_referenced_or_allocated = - section->flags.is_excluded_unless_referenced_or_allocated(); + section->flags.contains_flags(arch::memory::elf_section_flags::EXCLUDED_UNLESS_REFERENCED_OR_ALLOCATED); if (writable && occupies_memory && is_executable && contains_duplicate_data && contains_strings && section_header_info_is_section_header_table_index && preserve_ordering_after_combination && -- cgit v1.2.3 From b865b36b38d951de28cc4df5fa67338b8245a1c3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 17 Oct 2024 13:12:29 +0200 Subject: Implement support for `std::terminate` via `::abort` --- arch/x86_64/src/kernel/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 12498d0..babe251 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -165,7 +165,6 @@ namespace teachos::arch::kernel auto allocator = arch::memory::area_frame_allocator(kernel_start, kernel_end, multiboot_start, multiboot_end, memory_areas, area_count); - // WATCH OUT: using optional::value() crashes the build... I think its because of missing exception handling auto last_allocated = allocator.allocate_frame(); auto allocated = last_allocated; do @@ -174,6 +173,6 @@ namespace teachos::arch::kernel allocated = allocator.allocate_frame(); } while (allocated.has_value()); video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(allocated->frame_number, video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(allocated.value().frame_number, video::vga::text::common_attributes::green_on_black); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From a2fdcea0d7615f8933401e45e0c64a2f618bb730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 19 Oct 2024 13:15:45 +0000 Subject: Move compelte multiboot2 code into seperate files and behaviour into seperate static class --- arch/x86_64/src/kernel/main.cpp | 151 +--------------------------------------- 1 file changed, 3 insertions(+), 148 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index babe251..c0d4aed 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,120 +1,14 @@ #include "arch/kernel/main.hpp" -#include "arch/boot/pointers.hpp" #include "arch/exception_handling/assert.hpp" #include "arch/memory/frame_allocator.hpp" -#include "arch/memory/multiboot.hpp" +#include "arch/memory/multiboot/reader.hpp" #include "arch/video/vga/text.hpp" #include namespace teachos::arch::kernel { - auto process_memory_map(arch::memory::memory_map * mminfo, arch::memory::memory_area *& memory_areas, - uint8_t & area_count) -> void - { - auto expected_entry_size = mminfo->entry_size; - constexpr auto actual_entry_size = sizeof(arch::memory::memory_area); - arch::exception_handling::assert(expected_entry_size == actual_entry_size, "Unexpected memoryarea entry size"); - - auto total_size = mminfo->tag.size; - auto total_entries_size = total_size - sizeof(arch::memory::memory_map) + actual_entry_size; - auto number_of_entries = total_entries_size / actual_entry_size; - - memory_areas = &mminfo->entries; - area_count = number_of_entries; - } - - auto process_elf_sections(arch::memory::elf_symbols_section * symbol, uint64_t & kernel_start, - uint64_t & kernel_end) -> void - { - auto expected_entry_size = symbol->entry_size; - constexpr auto actual_entry_size = sizeof(arch::memory::elf_section_header); - arch::exception_handling::assert(expected_entry_size == actual_entry_size, - "Unexpected elf_section_header 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) - sizeof(uint32_t); - auto actual_total_size = actual_total_entry_size + actual_total_section_size; - arch::exception_handling::assert(expected_total_size == actual_total_size, "Unexpected elf_symbols total size"); - - auto begin = reinterpret_cast(&symbol->end); - auto end = begin + symbol->number_of_sections; - arch::exception_handling::assert(begin->is_null(), "Missing elf_section_header begin"); - - std::size_t symbol_table_section_count = 0U; - std::size_t dynamic_section_count = 0U; - - for (auto section = begin; section != end; ++section) - { - bool const writable = section->flags.contains_flags(arch::memory::elf_section_flags::WRITABLE); - bool const occupies_memory = section->flags.contains_flags(arch::memory::elf_section_flags::OCCUPIES_MEMORY); - bool const is_executable = section->flags.contains_flags(arch::memory::elf_section_flags::EXECUTABLE_CODE); - bool const contains_duplicate_data = - section->flags.contains_flags(arch::memory::elf_section_flags::DUPLICATE_DATA); - bool const contains_strings = section->flags.contains_flags(arch::memory::elf_section_flags::CONTAINS_STRING); - bool const section_header_info_is_section_header_table_index = section->flags.contains_flags( - arch::memory::elf_section_flags::SECTION_HEADER_INFO_IS_SECTION_HEADER_TABLE_INDEX); - bool const preserve_ordering_after_combination = - section->flags.contains_flags(arch::memory::elf_section_flags::PRESERVE_ORDERING_AFTER_COMBINATION); - bool const requires_special_os_processing = - section->flags.contains_flags(arch::memory::elf_section_flags::REQUIRES_SPECIAL_OS_PROCESSING); - bool const is_section_group_member = - section->flags.contains_flags(arch::memory::elf_section_flags::SECTION_GROUP_MEMBER); - bool const holds_thread_local_data = - section->flags.contains_flags(arch::memory::elf_section_flags::HOLDS_THREAD_LOCAL_DATA); - bool const is_compressed = section->flags.contains_flags(arch::memory::elf_section_flags::COMPRESSED); - bool const has_special_ordering_requirements = - section->flags.contains_flags(arch::memory::elf_section_flags::SPECIAL_ORDERING_REQUIREMENTS); - bool const is_excluded_unless_referenced_or_allocated = - section->flags.contains_flags(arch::memory::elf_section_flags::EXCLUDED_UNLESS_REFERENCED_OR_ALLOCATED); - - if (writable && occupies_memory && is_executable && contains_duplicate_data && contains_strings && - section_header_info_is_section_header_table_index && preserve_ordering_after_combination && - requires_special_os_processing && is_section_group_member && holds_thread_local_data && is_compressed && - has_special_ordering_requirements && is_excluded_unless_referenced_or_allocated) - { - } - - switch (section->type) - { - case arch::memory::elf_section_type::PROGRAMM: { - if (section->virtual_address < kernel_start) - { - kernel_start = section->virtual_address; - } - auto virtual_address_end = section->virtual_address + section->section_size; - if (virtual_address_end > kernel_end) - { - kernel_end = virtual_address_end; - } - 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: - dynamic_section_count++; - break; - default: - // All other cases are not important and can be ignored - break; - } - } - - arch::exception_handling::assert(symbol_table_section_count == 1U, "Unexpected symbol_table_count value"); - arch::exception_handling::assert(dynamic_section_count <= 1U, "Unexpected dynamic_section_count value"); - } - - template - requires std::is_pointer::value - auto align_to_8_byte_boundary(T ptr, uint32_t size) -> T - { - return reinterpret_cast(reinterpret_cast(ptr) + ((size + 7) & ~7)); - } - auto main() -> void { using namespace video::vga; @@ -123,47 +17,8 @@ namespace teachos::arch::kernel text::cursor(false); text::write("TeachOS is starting up...", text::common_attributes::green_on_black); - auto * multiboot_information_pointer = - reinterpret_cast(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 - * 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 = align_to_8_byte_boundary(tag, tag->size)) - { - switch (tag->type) - { - case arch::memory::multi_boot_tag_type::ELF_SECTIONS: { - auto symbol = reinterpret_cast(tag); - process_elf_sections(symbol, kernel_start, kernel_end); - break; - } - case arch::memory::multi_boot_tag_type::MEMORY_MAP: { - auto mminfo = reinterpret_cast(tag); - process_memory_map(mminfo, memory_areas, area_count); - break; - } - default: - // All other cases are not important and can be ignored - break; - } - } - - auto allocator = arch::memory::area_frame_allocator(kernel_start, kernel_end, multiboot_start, multiboot_end, - memory_areas, area_count); + auto memory_information = memory::multiboot::read_multiboot2(); + auto allocator = memory::area_frame_allocator(memory_information); auto last_allocated = allocator.allocate_frame(); auto allocated = last_allocated; -- cgit v1.2.3 From 675f38d6733fb19b4ffc7e9fbddb93acdd1d1e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 19 Oct 2024 14:40:25 +0000 Subject: Seperate allocation and paging code into multiple files as well --- arch/x86_64/src/kernel/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index c0d4aed..09fc2a2 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,7 +1,7 @@ #include "arch/kernel/main.hpp" #include "arch/exception_handling/assert.hpp" -#include "arch/memory/frame_allocator.hpp" +#include "arch/memory/allocator/area_frame_allocator.hpp" #include "arch/memory/multiboot/reader.hpp" #include "arch/video/vga/text.hpp" @@ -18,7 +18,7 @@ namespace teachos::arch::kernel text::write("TeachOS is starting up...", text::common_attributes::green_on_black); auto memory_information = memory::multiboot::read_multiboot2(); - auto allocator = memory::area_frame_allocator(memory_information); + memory::allocator::area_frame_allocator allocator(memory_information); auto last_allocated = allocator.allocate_frame(); auto allocated = last_allocated; -- cgit v1.2.3 From 779154223c6d220bbfe56b5b14e5fafcccb55781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 19 Oct 2024 14:48:25 +0000 Subject: Fix printing of wrong allocated frame --- arch/x86_64/src/kernel/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 09fc2a2..40dd117 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 allocated = allocator.allocate_frame(); } while (allocated.has_value()); video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(allocated.value().frame_number, video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(last_allocated.value().frame_number, + video::vga::text::common_attributes::green_on_black); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From f171efed99684bf03c315405efda34e36d7db82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 21 Oct 2024 09:31:58 +0000 Subject: Ensure only one instance of global page table can exist --- arch/x86_64/src/kernel/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 40dd117..db0a9ef 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -26,7 +26,7 @@ namespace teachos::arch::kernel { last_allocated = allocated; allocated = allocator.allocate_frame(); - } while (allocated.has_value()); + } while (allocated); video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black); video::vga::text::write_number(last_allocated.value().frame_number, video::vga::text::common_attributes::green_on_black); -- cgit v1.2.3 From 72cb015567cb65527e9105e653c001be3c04eab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 21 Oct 2024 12:03:21 +0000 Subject: Use handle struct to ensure next_table is not called on page table level 1 --- arch/x86_64/src/kernel/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index db0a9ef..88f6329 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -11,11 +11,9 @@ namespace teachos::arch::kernel { auto main() -> void { - using namespace video::vga; - - text::clear(); - text::cursor(false); - text::write("TeachOS is starting up...", text::common_attributes::green_on_black); + video::vga::text::clear(); + video::vga::text::cursor(false); + video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); auto memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); -- cgit v1.2.3 From 039f12eb2f5785357ab1745201c8d420ab644165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 21 Oct 2024 13:35:10 +0000 Subject: Adding more mapping methods --- arch/x86_64/src/kernel/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 88f6329..8e5aa05 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -3,6 +3,7 @@ #include "arch/exception_handling/assert.hpp" #include "arch/memory/allocator/area_frame_allocator.hpp" #include "arch/memory/multiboot/reader.hpp" +#include "arch/memory/paging/page_mapper.hpp" #include "arch/video/vga/text.hpp" #include @@ -28,5 +29,9 @@ namespace teachos::arch::kernel video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black); video::vga::text::write_number(last_allocated.value().frame_number, video::vga::text::common_attributes::green_on_black); + memory::paging::map_page_to_frame(allocator, memory::paging::virtual_page{0U}, last_allocated.value(), 0U); + memory::paging::map_next_free_page_to_frame(allocator, memory::paging::virtual_page{0U}, 0U); + memory::paging::identity_map(allocator, last_allocated.value(), 0U); + memory::paging::unmap_page(allocator, memory::paging::virtual_page{0U}); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 8502cc9b19a9e934e3a4c0b3190b690ee0407a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 21 Oct 2024 14:48:03 +0000 Subject: =?UTF-8?q?Fix=20linker=20error=20using=20friend=20method=20?= =?UTF-8?q?=F0=9F=91=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arch/x86_64/src/kernel/main.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 8e5aa05..3e25d2d 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -10,6 +10,7 @@ namespace teachos::arch::kernel { + auto main() -> void { video::vga::text::clear(); @@ -19,6 +20,25 @@ namespace teachos::arch::kernel auto memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); + size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * + memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry + auto page = memory::paging::virtual_page::containing_address(address); + auto frame = allocator.allocate_frame(); + exception_handling::assert(frame.has_value(), "[Main] Out of memory exception"); + auto optional_frame = memory::paging::translate_page(page); + memory::paging::map_page_to_frame(allocator, page, frame.value(), 0U); + optional_frame = memory::paging::translate_page(page); + video::vga::text::newline(); + video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(optional_frame.value().frame_number, + video::vga::text::common_attributes::green_on_black); + + memory::paging::unmap_page(allocator, page); + video::vga::text::write("Unapped physical page: ", video::vga::text::common_attributes::green_on_black); + optional_frame = memory::paging::translate_page(page); + exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); + video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); + auto last_allocated = allocator.allocate_frame(); auto allocated = last_allocated; do @@ -26,12 +46,9 @@ namespace teachos::arch::kernel last_allocated = allocated; allocated = allocator.allocate_frame(); } while (allocated); - video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black); + video::vga::text::newline(); + video::vga::text::write("Allocated Frames: ", video::vga::text::common_attributes::green_on_black); video::vga::text::write_number(last_allocated.value().frame_number, video::vga::text::common_attributes::green_on_black); - memory::paging::map_page_to_frame(allocator, memory::paging::virtual_page{0U}, last_allocated.value(), 0U); - memory::paging::map_next_free_page_to_frame(allocator, memory::paging::virtual_page{0U}, 0U); - memory::paging::identity_map(allocator, last_allocated.value(), 0U); - memory::paging::unmap_page(allocator, memory::paging::virtual_page{0U}); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From ba054441f93a30e2042a71d632a6a5fb04007d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 22 Oct 2024 06:16:51 +0000 Subject: Adjust all briefs --- arch/x86_64/src/kernel/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 3e25d2d..ad1eb39 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -10,7 +10,6 @@ namespace teachos::arch::kernel { - auto main() -> void { video::vga::text::clear(); -- cgit v1.2.3 From a29e823c6ead21fa7c8f6445411d52f57c4518fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 27 Oct 2024 09:21:25 +0000 Subject: Attempt to start using C++20 algorithm calls. --- arch/x86_64/src/kernel/main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index ad1eb39..3f768ee 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -19,14 +19,19 @@ namespace teachos::arch::kernel auto memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); + auto test2 = allocator.allocate_frame(); + auto test1 = test2.value().start_address(); + auto test3 = test2.value().frame_number; + + if (test1 > test3) + { + } + size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry auto page = memory::paging::virtual_page::containing_address(address); - auto frame = allocator.allocate_frame(); - exception_handling::assert(frame.has_value(), "[Main] Out of memory exception"); + memory::paging::map_next_free_page_to_frame(allocator, page, 0U); auto optional_frame = memory::paging::translate_page(page); - memory::paging::map_page_to_frame(allocator, page, frame.value(), 0U); - optional_frame = memory::paging::translate_page(page); video::vga::text::newline(); video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); video::vga::text::write_number(optional_frame.value().frame_number, -- cgit v1.2.3 From f8b1a0d9e8431393e1b47af87780c96729100a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 27 Oct 2024 11:23:33 +0000 Subject: Remove redundant code --- arch/x86_64/src/kernel/main.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 3f768ee..5186c21 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -19,14 +19,6 @@ namespace teachos::arch::kernel auto memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); - auto test2 = allocator.allocate_frame(); - auto test1 = test2.value().start_address(); - auto test3 = test2.value().frame_number; - - if (test1 > test3) - { - } - size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry auto page = memory::paging::virtual_page::containing_address(address); -- cgit v1.2.3 From e5925df93411429340d2887594004aaa690d2ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 13:32:09 +0000 Subject: Adjust constant and make all possible variables const --- arch/x86_64/src/kernel/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 5186c21..e067b48 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -16,12 +16,12 @@ namespace teachos::arch::kernel video::vga::text::cursor(false); video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); - auto memory_information = memory::multiboot::read_multiboot2(); + auto const memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry - auto page = memory::paging::virtual_page::containing_address(address); + auto const page = memory::paging::virtual_page::containing_address(address); memory::paging::map_next_free_page_to_frame(allocator, page, 0U); auto optional_frame = memory::paging::translate_page(page); video::vga::text::newline(); -- cgit v1.2.3 From aa981cad951c4aa2a5e2f7a7f8f1b7b9a0ff4bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 28 Oct 2024 14:41:31 +0000 Subject: Fix lost updates, because of writing into copies instead of references --- arch/x86_64/src/kernel/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index e067b48..5c55213 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -28,9 +28,13 @@ namespace teachos::arch::kernel video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); video::vga::text::write_number(optional_frame.value().frame_number, video::vga::text::common_attributes::green_on_black); + video::vga::text::write(" to virtual page: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); memory::paging::unmap_page(allocator, page); - video::vga::text::write("Unapped physical page: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::newline(); + video::vga::text::write("Unapped virtual page from physical frame: ", + video::vga::text::common_attributes::green_on_black); optional_frame = memory::paging::translate_page(page); exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); -- cgit v1.2.3 From 29c51a2cc30060bd904b06cbe6913755352c48c7 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Fri, 1 Nov 2024 10:08:50 +0000 Subject: create temporary page implementation --- arch/x86_64/src/kernel/main.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 5c55213..a27631f 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -4,6 +4,7 @@ #include "arch/memory/allocator/area_frame_allocator.hpp" #include "arch/memory/multiboot/reader.hpp" #include "arch/memory/paging/page_mapper.hpp" +#include "arch/memory/paging/temporary_page.hpp" #include "arch/video/vga/text.hpp" #include @@ -22,22 +23,26 @@ namespace teachos::arch::kernel size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry auto const page = memory::paging::virtual_page::containing_address(address); - memory::paging::map_next_free_page_to_frame(allocator, page, 0U); - auto optional_frame = memory::paging::translate_page(page); - video::vga::text::newline(); - video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(optional_frame.value().frame_number, - video::vga::text::common_attributes::green_on_black); - video::vga::text::write(" to virtual page: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); - memory::paging::unmap_page(allocator, page); - video::vga::text::newline(); - video::vga::text::write("Unapped virtual page from physical frame: ", - video::vga::text::common_attributes::green_on_black); - optional_frame = memory::paging::translate_page(page); - exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); - video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); + memory::paging::temporary_page temp_page{page, allocator}; + temp_page.zero_entries(); + + // memory::paging::map_next_free_page_to_frame(allocator, page, 0U); + // auto optional_frame = memory::paging::translate_page(page); + // video::vga::text::newline(); + // video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); + // video::vga::text::write_number(optional_frame.value().frame_number, + // video::vga::text::common_attributes::green_on_black); + // video::vga::text::write(" to virtual page: ", video::vga::text::common_attributes::green_on_black); + // video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); + + // memory::paging::unmap_page(allocator, page); + // video::vga::text::newline(); + // video::vga::text::write("Unapped virtual page from physical frame: ", + // video::vga::text::common_attributes::green_on_black); + // optional_frame = memory::paging::translate_page(page); + // exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); + // video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); auto last_allocated = allocator.allocate_frame(); auto allocated = last_allocated; -- cgit v1.2.3 From b0d917bc8ad95e282f25949c489dfc1c06b91b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 1 Nov 2024 13:02:14 +0000 Subject: Adjust temporary page to changes --- arch/x86_64/src/kernel/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index a27631f..22335d1 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -24,8 +24,9 @@ namespace teachos::arch::kernel memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry auto const page = memory::paging::virtual_page::containing_address(address); + auto & active_table = memory::paging::active_page_table::create_or_get(); memory::paging::temporary_page temp_page{page, allocator}; - temp_page.zero_entries(); + temp_page.zero_entries(active_table); // memory::paging::map_next_free_page_to_frame(allocator, page, 0U); // auto optional_frame = memory::paging::translate_page(page); -- cgit v1.2.3 From 31e1ac359eb4b84bdd81f768b2de327193976a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 1 Nov 2024 13:22:02 +0000 Subject: Remove static page mapper and replace with unique active and inactive page table classes. --- arch/x86_64/src/kernel/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 22335d1..f1d6496 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -3,7 +3,7 @@ #include "arch/exception_handling/assert.hpp" #include "arch/memory/allocator/area_frame_allocator.hpp" #include "arch/memory/multiboot/reader.hpp" -#include "arch/memory/paging/page_mapper.hpp" +#include "arch/memory/paging/active_page_table.hpp" #include "arch/memory/paging/temporary_page.hpp" #include "arch/video/vga/text.hpp" -- cgit v1.2.3 From 08875c9c42c94dd23b16baa70b2be60cf35eb253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 1 Nov 2024 14:53:31 +0000 Subject: Fix circular dependency issue --- arch/x86_64/src/kernel/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index f1d6496..c89ae44 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -3,7 +3,6 @@ #include "arch/exception_handling/assert.hpp" #include "arch/memory/allocator/area_frame_allocator.hpp" #include "arch/memory/multiboot/reader.hpp" -#include "arch/memory/paging/active_page_table.hpp" #include "arch/memory/paging/temporary_page.hpp" #include "arch/video/vga/text.hpp" -- cgit v1.2.3 From 5ffe7d69545bf098efdd70f105a5df83304b211a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 2 Nov 2024 11:49:38 +0000 Subject: Add physical frame iterator and continue implementing kernel mapping. --- arch/x86_64/src/kernel/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index c89ae44..59e453a 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -3,6 +3,7 @@ #include "arch/exception_handling/assert.hpp" #include "arch/memory/allocator/area_frame_allocator.hpp" #include "arch/memory/multiboot/reader.hpp" +#include "arch/memory/paging/kernel_mapper.hpp" #include "arch/memory/paging/temporary_page.hpp" #include "arch/video/vga/text.hpp" @@ -27,6 +28,9 @@ namespace teachos::arch::kernel memory::paging::temporary_page temp_page{page, allocator}; temp_page.zero_entries(active_table); + memory::paging::kernel_mapper kernel(allocator, memory_information); + kernel.remap_kernel(); + // memory::paging::map_next_free_page_to_frame(allocator, page, 0U); // auto optional_frame = memory::paging::translate_page(page); // video::vga::text::newline(); -- cgit v1.2.3 From 4d76f412b071a05f0aae1d1307f2b58cb2778569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sat, 2 Nov 2024 14:08:55 +0000 Subject: Attempt to fix crashes --- arch/x86_64/src/kernel/main.cpp | 76 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 59e453a..5cfd9b3 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -20,44 +20,42 @@ namespace teachos::arch::kernel auto const memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); - size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * - memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry - auto const page = memory::paging::virtual_page::containing_address(address); - - auto & active_table = memory::paging::active_page_table::create_or_get(); - memory::paging::temporary_page temp_page{page, allocator}; - temp_page.zero_entries(active_table); - - memory::paging::kernel_mapper kernel(allocator, memory_information); - kernel.remap_kernel(); - - // memory::paging::map_next_free_page_to_frame(allocator, page, 0U); - // auto optional_frame = memory::paging::translate_page(page); - // video::vga::text::newline(); - // video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); - // video::vga::text::write_number(optional_frame.value().frame_number, - // video::vga::text::common_attributes::green_on_black); - // video::vga::text::write(" to virtual page: ", video::vga::text::common_attributes::green_on_black); - // video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); - - // memory::paging::unmap_page(allocator, page); - // video::vga::text::newline(); - // video::vga::text::write("Unapped virtual page from physical frame: ", - // video::vga::text::common_attributes::green_on_black); - // optional_frame = memory::paging::translate_page(page); - // exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); - // video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); - - auto last_allocated = allocator.allocate_frame(); - auto allocated = last_allocated; - do - { - last_allocated = allocated; - allocated = allocator.allocate_frame(); - } while (allocated); - video::vga::text::newline(); - video::vga::text::write("Allocated Frames: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(last_allocated.value().frame_number, - video::vga::text::common_attributes::green_on_black); + memory::paging::kernel_mapper kernel(memory_information); + kernel.remap_kernel(allocator); + video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); + + /* + size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * + memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry + auto const page = memory::paging::virtual_page::containing_address(address); + memory::paging::map_next_free_page_to_frame(allocator, page, 0U); + auto optional_frame = memory::paging::translate_page(page); + video::vga::text::newline(); + video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(optional_frame.value().frame_number, + video::vga::text::common_attributes::green_on_black); + video::vga::text::write(" to virtual page: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); + + memory::paging::unmap_page(allocator, page); + video::vga::text::newline(); + video::vga::text::write("Unapped virtual page from physical frame: ", + video::vga::text::common_attributes::green_on_black); + optional_frame = memory::paging::translate_page(page); + exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); + video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); + + auto last_allocated = allocator.allocate_frame(); + auto allocated = last_allocated; + do + { + last_allocated = allocated; + allocated = allocator.allocate_frame(); + } while (allocated); + video::vga::text::newline(); + video::vga::text::write("Allocated Frames: ", video::vga::text::common_attributes::green_on_black); + video::vga::text::write_number(last_allocated.value().frame_number, + video::vga::text::common_attributes::green_on_black); + */ } } // namespace teachos::arch::kernel -- cgit v1.2.3 From d4b1b8a85212f07df47217fe13d86956c7eb064f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 3 Nov 2024 10:47:33 +0000 Subject: Use passed allocator in inactive page instead of tiny. --- arch/x86_64/src/kernel/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 5cfd9b3..c111f22 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -20,8 +20,8 @@ namespace teachos::arch::kernel auto const memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); - memory::paging::kernel_mapper kernel(memory_information); - kernel.remap_kernel(allocator); + memory::paging::kernel_mapper kernel(allocator, memory_information); + kernel.remap_kernel(); video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); /* -- cgit v1.2.3 From 8eb68ccb8837ba867550d16f967d9ef21921abe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 10 Nov 2024 12:08:02 +0000 Subject: Finish control register and adjust msr --- arch/x86_64/src/kernel/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index c111f22..ea1a157 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -2,6 +2,7 @@ #include "arch/exception_handling/assert.hpp" #include "arch/memory/allocator/area_frame_allocator.hpp" +#include "arch/memory/cpu/msr.hpp" #include "arch/memory/multiboot/reader.hpp" #include "arch/memory/paging/kernel_mapper.hpp" #include "arch/memory/paging/temporary_page.hpp" @@ -20,6 +21,9 @@ namespace teachos::arch::kernel auto const memory_information = memory::multiboot::read_multiboot2(); memory::allocator::area_frame_allocator allocator(memory_information); + memory::cpu::set_cr2_bit(memory::cpu::cr2_flags::WRITE_PROTECT); + memory::cpu::set_efer_bit(memory::cpu::efer_flags::NXE); + memory::paging::kernel_mapper kernel(allocator, memory_information); kernel.remap_kernel(); video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); -- cgit v1.2.3 From 0ca0c40c197c214288ad2ed1179ae9ae28c50194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 11 Nov 2024 14:16:18 +0000 Subject: Improve calculation of kernel end and start address. --- arch/x86_64/src/kernel/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index ea1a157..f9b252d 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -25,9 +25,11 @@ namespace teachos::arch::kernel memory::cpu::set_efer_bit(memory::cpu::efer_flags::NXE); memory::paging::kernel_mapper kernel(allocator, memory_information); - kernel.remap_kernel(); + auto & active_table = kernel.remap_kernel(); video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); + // TODO: Map heap virtual pages with active table + /* size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry -- cgit v1.2.3 From f45fdae9913a9d8e003cf681621e71516b2054b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 12 Nov 2024 08:50:05 +0000 Subject: Add notes on why system crashes --- arch/x86_64/src/kernel/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index f9b252d..679fb8d 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -25,7 +25,7 @@ namespace teachos::arch::kernel memory::cpu::set_efer_bit(memory::cpu::efer_flags::NXE); memory::paging::kernel_mapper kernel(allocator, memory_information); - auto & active_table = kernel.remap_kernel(); + kernel.remap_kernel(); video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); // TODO: Map heap virtual pages with active table -- cgit v1.2.3 From 9507633f04e672b3dadf1385b1562fb3101d0ea3 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Tue, 12 Nov 2024 10:41:23 +0000 Subject: add debug statements --- arch/x86_64/src/kernel/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 679fb8d..92d277d 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -25,7 +25,21 @@ namespace teachos::arch::kernel memory::cpu::set_efer_bit(memory::cpu::efer_flags::NXE); memory::paging::kernel_mapper kernel(allocator, memory_information); - kernel.remap_kernel(); + auto & active_table = kernel.remap_kernel(); + auto x = active_table.active_handle.next_table(0); + if (x.has_value()) + { + auto y = x.value().next_table(0); + + if (y.has_value()) + { + auto z = y.value().next_table(0); + if (z.has_value()) + { + } + } + } + video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); // TODO: Map heap virtual pages with active table -- cgit v1.2.3 From 266c01528fdc994e4e326de37f99d67f9a0eb3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 12 Nov 2024 11:00:08 +0000 Subject: Remove duplicate method --- arch/x86_64/src/kernel/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 92d277d..60fa145 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -40,7 +40,6 @@ namespace teachos::arch::kernel } } video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); - video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); // TODO: Map heap virtual pages with active table -- cgit v1.2.3 From d32130f8a81247e450490d31074ec6501dd4aeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 13 Nov 2024 12:37:08 +0000 Subject: Note that mapping seems to be working --- arch/x86_64/src/kernel/main.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 60fa145..6c0faf4 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -27,19 +27,15 @@ namespace teachos::arch::kernel memory::paging::kernel_mapper kernel(allocator, memory_information); auto & active_table = kernel.remap_kernel(); auto x = active_table.active_handle.next_table(0); - if (x.has_value()) + auto y = x.value().next_table(0); + auto z = y.value().next_table(0); + if (z.has_value()) { - auto y = x.value().next_table(0); - - if (y.has_value()) - { - auto z = y.value().next_table(0); - if (z.has_value()) - { - } - } + video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } - video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); + + // TODO: Seems to work correctly, Level 4 Index 0, Level 3 Index 0, Level 2 Index 0, Level 1 Index 184 = 753667 from + // mapping vga is still mapped // TODO: Map heap virtual pages with active table -- cgit v1.2.3 From 52c1979b22c5e66459659a9cda8d69a2c9b148ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Wed, 13 Nov 2024 14:59:12 +0000 Subject: Add note on possible options to enable PIC / PIE --- arch/x86_64/src/kernel/main.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 6c0faf4..5b0f2c3 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -36,6 +36,9 @@ namespace teachos::arch::kernel // TODO: Seems to work correctly, Level 4 Index 0, Level 3 Index 0, Level 2 Index 0, Level 1 Index 184 = 753667 from // mapping vga is still mapped + // set(CMAKE_POSITION_INDEPENDENT_CODE ON), should enable position independent code, but mapping still does not work + // with same error? + // Can we change the gcc call? gcc -fPIC -c mylibrary.cpp // TODO: Map heap virtual pages with active table -- cgit v1.2.3 From 1cd666241b59b800818812220e28b8b8572e4263 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 19 Nov 2024 17:32:02 +0100 Subject: paging: de-templetize implementation --- arch/x86_64/src/kernel/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 5b0f2c3..8c68a49 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -2,6 +2,7 @@ #include "arch/exception_handling/assert.hpp" #include "arch/memory/allocator/area_frame_allocator.hpp" +#include "arch/memory/cpu/control_register.hpp" #include "arch/memory/cpu/msr.hpp" #include "arch/memory/multiboot/reader.hpp" #include "arch/memory/paging/kernel_mapper.hpp" -- cgit v1.2.3 From 77146c6e2dbd02661636d9424b7e51562eac30c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 24 Nov 2024 09:44:41 +0000 Subject: Add notes on missing features for kernel remapping --- arch/x86_64/src/kernel/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 8c68a49..8a73630 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -35,11 +35,10 @@ namespace teachos::arch::kernel video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } - // TODO: Seems to work correctly, Level 4 Index 0, Level 3 Index 0, Level 2 Index 0, Level 1 Index 184 = 753667 from - // mapping vga is still mapped - // set(CMAKE_POSITION_INDEPENDENT_CODE ON), should enable position independent code, but mapping still does not work - // with same error? - // Can we change the gcc call? gcc -fPIC -c mylibrary.cpp + // TODO: Why is identity mapping multiboot2 information structure with new kernel not required and + // allocator.allocate_frame still works? + // TODO: Fix unmapping old level 4 page table and turn it into guard page, use Stack Probes for stack allocation if + // possible. // TODO: Map heap virtual pages with active table -- cgit v1.2.3 From 55f32173e97fdcf4a45006b66cc4b20329a5c7af Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 24 Nov 2024 13:10:21 +0000 Subject: implement basic heap and remap it --- arch/x86_64/src/kernel/main.cpp | 68 ++++++----------------------------------- 1 file changed, 10 insertions(+), 58 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 8a73630..cbd6e68 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,16 +1,8 @@ #include "arch/kernel/main.hpp" -#include "arch/exception_handling/assert.hpp" -#include "arch/memory/allocator/area_frame_allocator.hpp" -#include "arch/memory/cpu/control_register.hpp" -#include "arch/memory/cpu/msr.hpp" -#include "arch/memory/multiboot/reader.hpp" -#include "arch/memory/paging/kernel_mapper.hpp" -#include "arch/memory/paging/temporary_page.hpp" +#include "arch/memory/main.hpp" #include "arch/video/vga/text.hpp" -#include - namespace teachos::arch::kernel { auto main() -> void @@ -19,61 +11,21 @@ namespace teachos::arch::kernel video::vga::text::cursor(false); video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); - auto const memory_information = memory::multiboot::read_multiboot2(); - memory::allocator::area_frame_allocator allocator(memory_information); + memory::initialize_memory_management(); + + // heap::bump_allocator heap_allocator{memory::heap::HEAP_START, heap::HEAP_START + memory::heap::HEAP_SIZE}; + // auto test = heap_allocator.allocate(1024); - memory::cpu::set_cr2_bit(memory::cpu::cr2_flags::WRITE_PROTECT); - memory::cpu::set_efer_bit(memory::cpu::efer_flags::NXE); + // auto test2 = new (test) multiboot::memory_information{}; - memory::paging::kernel_mapper kernel(allocator, memory_information); - auto & active_table = kernel.remap_kernel(); - auto x = active_table.active_handle.next_table(0); - auto y = x.value().next_table(0); - auto z = y.value().next_table(0); - if (z.has_value()) - { - video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); - } + // if (test || test2) + // { + // video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); + // } // TODO: Why is identity mapping multiboot2 information structure with new kernel not required and // allocator.allocate_frame still works? // TODO: Fix unmapping old level 4 page table and turn it into guard page, use Stack Probes for stack allocation if // possible. - - // TODO: Map heap virtual pages with active table - - /* - size_t address = 42 * memory::paging::PAGE_TABLE_ENTRY_COUNT * memory::paging::PAGE_TABLE_ENTRY_COUNT * - memory::allocator::PAGE_FRAME_SIZE; // 42th P3 entry - auto const page = memory::paging::virtual_page::containing_address(address); - memory::paging::map_next_free_page_to_frame(allocator, page, 0U); - auto optional_frame = memory::paging::translate_page(page); - video::vga::text::newline(); - video::vga::text::write("Mapped physical frame: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(optional_frame.value().frame_number, - video::vga::text::common_attributes::green_on_black); - video::vga::text::write(" to virtual page: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); - - memory::paging::unmap_page(allocator, page); - video::vga::text::newline(); - video::vga::text::write("Unapped virtual page from physical frame: ", - video::vga::text::common_attributes::green_on_black); - optional_frame = memory::paging::translate_page(page); - exception_handling::assert(!optional_frame.has_value(), "[Main] Ummapping failed"); - video::vga::text::write_number(page.page_number, video::vga::text::common_attributes::green_on_black); - - auto last_allocated = allocator.allocate_frame(); - auto allocated = last_allocated; - do - { - last_allocated = allocated; - allocated = allocator.allocate_frame(); - } while (allocated); - video::vga::text::newline(); - video::vga::text::write("Allocated Frames: ", video::vga::text::common_attributes::green_on_black); - video::vga::text::write_number(last_allocated.value().frame_number, - video::vga::text::common_attributes::green_on_black); - */ } } // namespace teachos::arch::kernel -- cgit v1.2.3 From c291e1ed629489c418049f6c4116433636717636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 24 Nov 2024 13:51:12 +0000 Subject: Add comments and rename file --- arch/x86_64/src/kernel/main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index cbd6e68..ce13723 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -1,6 +1,9 @@ #include "arch/kernel/main.hpp" +#include "arch/memory/heap/bump_allocator.hpp" +#include "arch/memory/heap/concept.hpp" #include "arch/memory/main.hpp" +#include "arch/memory/multiboot/reader.hpp" #include "arch/video/vga/text.hpp" namespace teachos::arch::kernel @@ -13,15 +16,16 @@ namespace teachos::arch::kernel memory::initialize_memory_management(); - // heap::bump_allocator heap_allocator{memory::heap::HEAP_START, heap::HEAP_START + memory::heap::HEAP_SIZE}; - // auto test = heap_allocator.allocate(1024); + memory::heap::bump_allocator heap_allocator{memory::heap::HEAP_START, + memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; + auto test = heap_allocator.allocate(1024); - // auto test2 = new (test) multiboot::memory_information{}; + auto test2 = new (test) memory::multiboot::memory_information{}; - // if (test || test2) - // { - // video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); - // } + if (test || test2) + { + video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); + } // TODO: Why is identity mapping multiboot2 information structure with new kernel not required and // allocator.allocate_frame still works? -- cgit v1.2.3 From 82cfe7fe12626a3bdf1bdf9efcbc7911051ebddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 24 Nov 2024 13:55:00 +0000 Subject: Read and write in allocated memory area --- arch/x86_64/src/kernel/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index ce13723..f4eb033 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -19,10 +19,10 @@ namespace teachos::arch::kernel memory::heap::bump_allocator heap_allocator{memory::heap::HEAP_START, memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; auto test = heap_allocator.allocate(1024); - auto test2 = new (test) memory::multiboot::memory_information{}; - - if (test || test2) + test2->kernel_end = 5000; + auto test3 = test2->kernel_end; + if (test || test2 || test3) { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } -- cgit v1.2.3 From eada7bbb150fd81e6fbf71b1df28c8dc19393cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 24 Nov 2024 15:19:29 +0000 Subject: Adjust bump allocator comment --- arch/x86_64/src/kernel/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index f4eb033..13526f4 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -31,5 +31,7 @@ namespace teachos::arch::kernel // allocator.allocate_frame still works? // TODO: Fix unmapping old level 4 page table and turn it into guard page, use Stack Probes for stack allocation if // possible. + + // TODO: Align up and down for the bump allocator. https://os.phil-opp.com/kernel-heap/#a-bump-allocator } } // namespace teachos::arch::kernel -- cgit v1.2.3 From d2aa4fbf948a56df5328e0f1b8ec3dfd52b16e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 26 Nov 2024 09:49:06 +0000 Subject: Make bump allocator atomic and therefore thread safe --- arch/x86_64/src/kernel/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 13526f4..023327e 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -20,9 +20,10 @@ namespace teachos::arch::kernel memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; auto test = heap_allocator.allocate(1024); auto test2 = new (test) memory::multiboot::memory_information{}; - test2->kernel_end = 5000; - auto test3 = test2->kernel_end; - if (test || test2 || test3) + auto test3 = *test2; + test3.kernel_end = 5000; + auto test4 = test3.kernel_end; + if (test || test2 || test3.kernel_end || test4) { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } @@ -31,7 +32,5 @@ namespace teachos::arch::kernel // allocator.allocate_frame still works? // TODO: Fix unmapping old level 4 page table and turn it into guard page, use Stack Probes for stack allocation if // possible. - - // TODO: Align up and down for the bump allocator. https://os.phil-opp.com/kernel-heap/#a-bump-allocator } } // namespace teachos::arch::kernel -- cgit v1.2.3 From e8bbb1ad850a362dfa25ba1ea7bdd838a379def8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 1 Dec 2024 07:46:20 +0000 Subject: Move heap virtual location and allocate multiple variables to test heap. --- arch/x86_64/src/kernel/main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 023327e..dd0a1d8 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -20,10 +20,15 @@ namespace teachos::arch::kernel memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; auto test = heap_allocator.allocate(1024); auto test2 = new (test) memory::multiboot::memory_information{}; - auto test3 = *test2; - test3.kernel_end = 5000; - auto test4 = test3.kernel_end; - if (test || test2 || test3.kernel_end || test4) + test = static_cast(static_cast(test) + 1); + auto test3 = new (test) memory::multiboot::memory_information{}; + auto test4 = *test2; + auto test5 = *test3; + test4.kernel_end = 5000; + test5.kernel_end = 3000; + auto test6 = test4.kernel_end; + auto test7 = test5.kernel_end; + if (test6 && test7) { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } -- cgit v1.2.3 From c1e7edabc1dfbe387546297720fc495837d38d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 1 Dec 2024 09:46:37 +0000 Subject: Fix guard page and ensure it crashes even if guard page is skipped altogether --- arch/x86_64/src/kernel/main.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index dd0a1d8..7463fc4 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -8,14 +8,19 @@ namespace teachos::arch::kernel { - auto main() -> void + auto stack_overflow_test(int count) -> int { - video::vga::text::clear(); - video::vga::text::cursor(false); - video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); - - memory::initialize_memory_management(); + int test[5000] = {}; + if (test[0] == 0xFFFF) + { + return count; + } + count = stack_overflow_test(count); + return count++; + } + auto heap_test() -> void + { memory::heap::bump_allocator heap_allocator{memory::heap::HEAP_START, memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; auto test = heap_allocator.allocate(1024); @@ -28,14 +33,22 @@ namespace teachos::arch::kernel test5.kernel_end = 3000; auto test6 = test4.kernel_end; auto test7 = test5.kernel_end; - if (test6 && test7) + auto test8 = memory::multiboot::read_multiboot2(); + if (test6 && test7 && test8.kernel_end) { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } + } + + auto main() -> void + { + video::vga::text::clear(); + video::vga::text::cursor(false); + video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); + + memory::initialize_memory_management(); - // TODO: Why is identity mapping multiboot2 information structure with new kernel not required and - // allocator.allocate_frame still works? - // TODO: Fix unmapping old level 4 page table and turn it into guard page, use Stack Probes for stack allocation if - // possible. + // stack_overflow_test(0); + // heap_test(); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 2671b9522db44418536559524a22c95d3575569e Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 1 Dec 2024 12:07:42 +0000 Subject: enable heap test --- arch/x86_64/src/kernel/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 7463fc4..ea18232 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -2,6 +2,7 @@ #include "arch/memory/heap/bump_allocator.hpp" #include "arch/memory/heap/concept.hpp" +#include "arch/memory/heap/linked_list_allocator.hpp" #include "arch/memory/main.hpp" #include "arch/memory/multiboot/reader.hpp" #include "arch/video/vga/text.hpp" @@ -21,8 +22,8 @@ namespace teachos::arch::kernel auto heap_test() -> void { - memory::heap::bump_allocator heap_allocator{memory::heap::HEAP_START, - memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; + memory::heap::linked_list_allocator heap_allocator{memory::heap::HEAP_START, + memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; auto test = heap_allocator.allocate(1024); auto test2 = new (test) memory::multiboot::memory_information{}; test = static_cast(static_cast(test) + 1); @@ -49,6 +50,6 @@ namespace teachos::arch::kernel memory::initialize_memory_management(); // stack_overflow_test(0); - // heap_test(); + heap_test(); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From 9072c2a277c0da298b977cf4fb3dbebb5481abd0 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 1 Dec 2024 13:34:46 +0000 Subject: implement clear_memory_block_header --- arch/x86_64/src/kernel/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index ea18232..a4f138c 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -26,8 +26,8 @@ namespace teachos::arch::kernel memory::heap::HEAP_START + memory::heap::HEAP_SIZE}; auto test = heap_allocator.allocate(1024); auto test2 = new (test) memory::multiboot::memory_information{}; - test = static_cast(static_cast(test) + 1); - auto test3 = new (test) memory::multiboot::memory_information{}; + auto test3 = new (static_cast(static_cast(test) + 1)) + memory::multiboot::memory_information{}; auto test4 = *test2; auto test5 = *test3; test4.kernel_end = 5000; @@ -39,6 +39,8 @@ namespace teachos::arch::kernel { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } + + heap_allocator.deallocate(test, 1024); } auto main() -> void @@ -50,6 +52,6 @@ namespace teachos::arch::kernel memory::initialize_memory_management(); // stack_overflow_test(0); - heap_test(); + // heap_test(); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From a5e5eabd32872f81a7190589aa648dc0e1963888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 2 Dec 2024 10:17:36 +0000 Subject: Fix algorithm issues with linked list allocator --- arch/x86_64/src/kernel/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index a4f138c..7992b34 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -41,6 +41,15 @@ namespace teachos::arch::kernel } heap_allocator.deallocate(test, 1024); + + heap_allocator.allocate(1024); // test 9 + auto test10 = heap_allocator.allocate(1024); + auto test11 = heap_allocator.allocate(1024); + auto test12 = heap_allocator.allocate(1024); + heap_allocator.allocate(1024); // test 13 + heap_allocator.deallocate(test11, 1024); + heap_allocator.deallocate(test10, 1024); + heap_allocator.deallocate(test12, 1024); } auto main() -> void @@ -52,6 +61,6 @@ namespace teachos::arch::kernel memory::initialize_memory_management(); // stack_overflow_test(0); - // heap_test(); + heap_test(); } } // namespace teachos::arch::kernel -- cgit v1.2.3 From aa4de534ec7bf0b609aff032c4649484aa49823c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 2 Dec 2024 11:14:43 +0000 Subject: Add check to detect double free in linked list allocator --- arch/x86_64/src/kernel/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index 7992b34..e68f0fe 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -42,9 +42,10 @@ namespace teachos::arch::kernel heap_allocator.deallocate(test, 1024); - heap_allocator.allocate(1024); // test 9 + auto test9 = heap_allocator.allocate(1024); auto test10 = heap_allocator.allocate(1024); auto test11 = heap_allocator.allocate(1024); + heap_allocator.deallocate(test9, 1024); auto test12 = heap_allocator.allocate(1024); heap_allocator.allocate(1024); // test 13 heap_allocator.deallocate(test11, 1024); -- cgit v1.2.3 From 37de7b3b395a4b9cdf46a8b20ce6bb6a7d481354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 2 Dec 2024 12:17:51 +0000 Subject: Finish testing (dealloc recombines correctly) --- arch/x86_64/src/kernel/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index e68f0fe..a29c947 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -39,7 +39,6 @@ namespace teachos::arch::kernel { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } - heap_allocator.deallocate(test, 1024); auto test9 = heap_allocator.allocate(1024); @@ -47,9 +46,10 @@ namespace teachos::arch::kernel auto test11 = heap_allocator.allocate(1024); heap_allocator.deallocate(test9, 1024); auto test12 = heap_allocator.allocate(1024); - heap_allocator.allocate(1024); // test 13 + auto test13 = heap_allocator.allocate(1024); heap_allocator.deallocate(test11, 1024); heap_allocator.deallocate(test10, 1024); + heap_allocator.deallocate(test13, 1024); heap_allocator.deallocate(test12, 1024); } -- cgit v1.2.3 From 888ae9e053973125551729ff787b8f3c4cf4e1be Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Tue, 3 Dec 2024 09:15:46 +0000 Subject: add additional tests to heap_test --- arch/x86_64/src/kernel/main.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index a29c947..c0fcc27 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -39,6 +39,9 @@ namespace teachos::arch::kernel { video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); } + test2->kernel_end = 2000; + test2->kernel_start = 1000; + test2->multiboot_start = 2000; heap_allocator.deallocate(test, 1024); auto test9 = heap_allocator.allocate(1024); -- cgit v1.2.3 From 568d0fd25f4ab12b183e230210d68252031bfa18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 17 Dec 2024 08:24:15 +0000 Subject: Improve log messages --- arch/x86_64/src/kernel/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index c0fcc27..a8cdc3a 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -37,7 +37,7 @@ namespace teachos::arch::kernel auto test8 = memory::multiboot::read_multiboot2(); if (test6 && test7 && test8.kernel_end) { - video::vga::text::write("Kernel remapping successfull", video::vga::text::common_attributes::green_on_black); + video::vga::text::write("Heap test successfull", video::vga::text::common_attributes::green_on_black); } test2->kernel_end = 2000; test2->kernel_start = 1000; @@ -61,6 +61,7 @@ namespace teachos::arch::kernel video::vga::text::clear(); video::vga::text::cursor(false); video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); + video::vga::text::newline(); memory::initialize_memory_management(); -- cgit v1.2.3 From 3d488e53a1d15fcc01a7b1d23b9585ca7a724864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Tue, 17 Dec 2024 09:36:31 +0000 Subject: Fix typo --- arch/x86_64/src/kernel/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64/src/kernel/main.cpp') diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp index a8cdc3a..681f960 100644 --- a/arch/x86_64/src/kernel/main.cpp +++ b/arch/x86_64/src/kernel/main.cpp @@ -37,7 +37,7 @@ namespace teachos::arch::kernel auto test8 = memory::multiboot::read_multiboot2(); if (test6 && test7 && test8.kernel_end) { - video::vga::text::write("Heap test successfull", video::vga::text::common_attributes::green_on_black); + video::vga::text::write("Heap test successful", video::vga::text::common_attributes::green_on_black); } test2->kernel_end = 2000; test2->kernel_start = 1000; -- cgit v1.2.3