aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src')
-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
3 files changed, 43 insertions, 42 deletions
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;
}