aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-13 08:28:30 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-13 08:28:30 +0000
commit553f3a824511bb8107982b2b2737f5b1dff59855 (patch)
treecaec969baa899969e1171813a028fa50aab8b2a6
parentb28082b1642f049fcf171a85c7d6841093b0682a (diff)
downloadteachos-553f3a824511bb8107982b2b2737f5b1dff59855.tar.xz
teachos-553f3a824511bb8107982b2b2737f5b1dff59855.zip
Add missing cpp files to cmake and fix elf alignment issues
-rw-r--r--CMakeLists.txt8
-rw-r--r--arch/x86_64/CMakeLists.txt9
-rw-r--r--arch/x86_64/include/arch/memory/frame_allocator.hpp8
-rw-r--r--arch/x86_64/include/arch/memory/multiboot.hpp11
-rw-r--r--arch/x86_64/include/arch/video/vga/text.hpp1
-rw-r--r--arch/x86_64/src/kernel/main.cpp15
-rw-r--r--arch/x86_64/src/memory/frame_allocator.cpp66
-rw-r--r--arch/x86_64/src/memory/multiboot.cpp4
8 files changed, 70 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f780d3..f5cc7ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,6 +101,13 @@ add_library("_video" OBJECT)
add_library("teachos::video" ALIAS "_video")
#[============================================================================[
+# The memory Library
+#]============================================================================]
+
+add_library("_memory" OBJECT)
+add_library("teachos::memory" ALIAS "_memory")
+
+#[============================================================================[
# The Kernel
#]============================================================================]
@@ -112,6 +119,7 @@ add_executable("teachos::kernel" ALIAS "_kernel")
target_link_libraries("_kernel" PRIVATE
"teachos::boot"
"teachos::video"
+ "teachos::memory"
)
#[============================================================================[
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index 6ff1332..882ea9a 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -37,6 +37,15 @@ target_sources("_video" PRIVATE
)
#[============================================================================[
+# The Memory Library
+#]============================================================================]
+
+target_sources("_memory" PRIVATE
+ "src/memory/multiboot.cpp"
+ "src/memory/frame_allocator.cpp"
+)
+
+#[============================================================================[
# The Bootable ISO Image
#]============================================================================]
diff --git a/arch/x86_64/include/arch/memory/frame_allocator.hpp b/arch/x86_64/include/arch/memory/frame_allocator.hpp
index 3989cdf..a52cc46 100644
--- a/arch/x86_64/include/arch/memory/frame_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/frame_allocator.hpp
@@ -52,8 +52,8 @@ namespace teachos::arch::memory
template<typename T>
concept FrameAllocator = requires(T t) {
- { t.allocate_frame() } -> std::optional<frame>;
- { t.deallocate_frame() } -> void;
+ { t.allocate_frame() } -> std::same_as<std::optional<frame>>;
+ { t.deallocate_frame() } -> std::same_as<void>;
};
/**
@@ -81,11 +81,11 @@ namespace teachos::arch::memory
*/
area_frame_allocator(std::size_t kernel_start, std::size_t kernel_end, std::size_t multiboot_start,
std::size_t multiboot_end, memory_area * memory_areas)
- : kernel_start(frame{kernel_start})
+ : areas(memory_areas)
+ , kernel_start(frame{kernel_start})
, kernel_end(frame{kernel_end})
, multiboot_start(frame{multiboot_start})
, multiboot_end(frame{multiboot_end})
- , areas(memory_areas)
{
choose_next_area();
}
diff --git a/arch/x86_64/include/arch/memory/multiboot.hpp b/arch/x86_64/include/arch/memory/multiboot.hpp
index c049a29..d66ca35 100644
--- a/arch/x86_64/include/arch/memory/multiboot.hpp
+++ b/arch/x86_64/include/arch/memory/multiboot.hpp
@@ -307,11 +307,12 @@ namespace teachos::arch::memory
*/
struct elf_symbols_section
{
- multi_boot_tag tag; ///< Basic multi_boot_tag information
- uint32_t number_of_sections; ///< Number of sections in the sections array
- uint32_t entry_size; ///< Size of each entry in the sections array
- uint32_t section_index; ///< Index to the string table used for symbol names
- alignas(8) struct elf_section_header sections; ///< Specific sectons
+ multi_boot_tag tag; ///< Basic multi_boot_tag information
+ uint32_t number_of_sections; ///< Number of sections in the sections array
+ uint32_t entry_size; ///< Size of each entry in the sections array
+ uint32_t section_index; ///< Index to the string table used for symbol names
+ std::byte end; ///< Marks the end of the tag, used to mark the beginning of any additional data
+ ///< contained in the section, to ensure byte alignment is actually 4 byte
};
} // namespace teachos::arch::memory
diff --git a/arch/x86_64/include/arch/video/vga/text.hpp b/arch/x86_64/include/arch/video/vga/text.hpp
index 9c4c701..79ec7be 100644
--- a/arch/x86_64/include/arch/video/vga/text.hpp
+++ b/arch/x86_64/include/arch/video/vga/text.hpp
@@ -121,7 +121,6 @@ namespace teachos::arch::video::vga::text
*/
auto write_char(char code_point, attribute attribute) -> void;
- // TODO: Move concepts to their own file/folder
template<typename T>
concept Integral = std::is_integral_v<T>;
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<arch::memory::elf_section_header *>(&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
diff --git a/arch/x86_64/src/memory/frame_allocator.cpp b/arch/x86_64/src/memory/frame_allocator.cpp
index b8f53be..3793ac6 100644
--- a/arch/x86_64/src/memory/frame_allocator.cpp
+++ b/arch/x86_64/src/memory/frame_allocator.cpp
@@ -2,6 +2,37 @@
namespace teachos::arch::memory
{
+ auto area_frame_allocator::choose_next_area() -> void
+ {
+ current_area = std::nullopt;
+ auto begin = areas;
+ auto end = areas + 5;
+
+ // TODO: Fix this loop as soon as you've created an area iterator
+ for (auto area = begin; area != end; ++area)
+ {
+ std::size_t address = area->base_address + area->area_length - 1;
+ if (frame::containing_address(address) >= next_free_frame)
+ {
+ // The `next_free_frame` address is smaller than the last address of the current area
+ if (!current_area || area->base_address < current_area->base_address)
+ {
+ current_area = *area;
+ }
+ }
+ }
+
+ if (current_area)
+ {
+ // Update the `next_free_frame` according to the new memory area
+ frame start_frame = frame::containing_address(current_area->base_address);
+ if (next_free_frame < start_frame)
+ {
+ next_free_frame = start_frame;
+ }
+ }
+ }
+
auto area_frame_allocator::allocate_frame() -> std::optional<frame>
{
/*
@@ -40,38 +71,11 @@ namespace teachos::arch::memory
return std::nullopt;
}
- auto area_frame_allocator::deallocate_frame(frame frame) -> void {}
-
- namespace
+ auto area_frame_allocator::deallocate_frame(frame frame) -> void
{
- auto area_frame_allocator::choose_next_area() -> void
+ // TODO: Fix, simply done because compiler will complain if frame is unused and not compile
+ if (frame.frame_number == 3)
{
- current_area = std::nullopt;
-
- // TODO: Fix this loop as soon as you've created an area iterator
- for (const auto & area : areas)
- {
- std::size_t address = area.base_addr + area.length - 1;
- if (frame::containing_address(address) >= next_free_frame)
- {
- // The `next_free_frame` address is smaller than the last address of the current area
- if (!current_area || area.base_addr < current_area->base_address)
- {
- current_area = area;
- }
- }
- }
-
- if (current_area)
- {
- // Update the `next_free_frame` according to the new memory area
- frame start_frame = frame::containing_address(current_area->base_address);
- if (next_free_frame < start_frame)
- {
- next_free_frame = start_frame;
- }
- }
}
-
- } // namespace
+ }
} // namespace teachos::arch::memory
diff --git a/arch/x86_64/src/memory/multiboot.cpp b/arch/x86_64/src/memory/multiboot.cpp
index 91e7550..3f6248d 100644
--- a/arch/x86_64/src/memory/multiboot.cpp
+++ b/arch/x86_64/src/memory/multiboot.cpp
@@ -1,4 +1,4 @@
-#include "multiboot.hpp"
+#include "arch/memory/multiboot.hpp"
namespace teachos::arch::memory
{
@@ -34,7 +34,7 @@ namespace teachos::arch::memory
auto elf_section_header::is_null() const -> bool
{
- return name_table_index == 0U && type == elf_section_type::UNSPECIFIED &&
+ return name_table_index == 0U && type == elf_section_type::INACTIVE &&
flags == teachos::arch::memory::elf_section_flags{0U} && virtual_address == 0U && file_offset == 0U &&
additional_information == 0U && address_alignment == 0U && fixed_table_entry_size == 0U;
}