aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-05-18 13:21:42 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-05-18 13:21:42 +0000
commit1b5a771a34743a2973a82de5ebdfd22da030b841 (patch)
tree19e81ac7c122225efedcab74051a46283723400a /arch/x86_64
parent5c314eef566df2732973e8cb35974ec49748adba (diff)
downloadteachos-1b5a771a34743a2973a82de5ebdfd22da030b841.tar.xz
teachos-1b5a771a34743a2973a82de5ebdfd22da030b841.zip
update linker file and improve section parsing
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp28
-rw-r--r--arch/x86_64/scripts/kernel.ld7
-rw-r--r--arch/x86_64/src/user/main.cpp17
3 files changed, 27 insertions, 25 deletions
diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
index 5bf14fb..977b40d 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -7,6 +7,9 @@
#include "arch/memory/paging/temporary_page.hpp"
#include "arch/video/vga/text.hpp"
+#include <algorithm>
+#include <array>
+
namespace teachos::arch::memory::paging
{
/**
@@ -142,24 +145,17 @@ namespace teachos::arch::memory::paging
entry entry{section.flags};
// Required to be accessible in User Mode:
- // - .boot_bss (Contains statically allocated variables)
- // - .user_text (Contains the actual user code executed)
- // - .user_data (Contains static user variables)
- // - .stl_text (Contains code for custom std implementations and standard library code)
- if (section.physical_address == 0x102000 /* .boot_bss */ ||
- section.physical_address == 0x209000 /* .stl_text */)
- {
- entry.set_user_accessible();
- }
+ constexpr std::array<uint64_t, 6> user_section_bases = {
+ 0x102000, // .boot_bss (Contains statically allocated variables)
+ 0x209000, // .stl_text (Contains code for custom std implementations and standard library code)
+ 0x218000, // .user_text (Contains the actual user code executed)
+ 0x21E000, // .user_data (Contains static user variables)
- // TODO: Can be removed once stl has been completly mapped into stl text
- if (section.physical_address == 0x20A000 /* .text */)
- {
- entry.set_user_accessible();
- }
+ 0x20A000 // .text (Necessary, because symbols for standard library are placed there)
+ };
- if (section.physical_address == 0x218000 /* .user_text */ ||
- section.physical_address == 0x21E000 /* .user_data */)
+ if (std::find(user_section_bases.begin(), user_section_bases.end(), section.physical_address) !=
+ user_section_bases.end())
{
entry.set_user_accessible();
}
diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld
index 23f9681..3d9a7ae 100644
--- a/arch/x86_64/scripts/kernel.ld
+++ b/arch/x86_64/scripts/kernel.ld
@@ -87,9 +87,8 @@ SECTIONS
.stl_text ALIGN(4K) : AT(ADDR (.stl_text))
{
- *(.stl_text)
+ *(.stl_text .stl_text*)
KEEP(*libstdc++.a:*(.text .text.*))
- KEEP(*libatomic.a:*(.text .text.*)) /* TODO: Attempt to move atomic stl into stl_text as well, doesn't work */
}
.text ALIGN(4K) : AT(ADDR (.text))
@@ -99,7 +98,7 @@ SECTIONS
.user_text ALIGN(4K) : AT(ADDR (.user_text))
{
- *(.user_text)
+ *(.user_text .user_text.*)
}
.rodata ALIGN(4K) : AT (ADDR (.rodata))
@@ -137,7 +136,7 @@ SECTIONS
.user_data ALIGN(4K) : AT (ADDR (.user_data))
{
- *(.user_data*)
+ *(.user_data .user_data.*)
}
/***************************************************************************
diff --git a/arch/x86_64/src/user/main.cpp b/arch/x86_64/src/user/main.cpp
index 747a8a4..e621327 100644
--- a/arch/x86_64/src/user/main.cpp
+++ b/arch/x86_64/src/user/main.cpp
@@ -4,22 +4,29 @@
#include "arch/memory/heap/global_heap_allocator.hpp"
#include <algorithm>
+#include <array>
#include <atomic>
+#include <ranges>
namespace teachos::arch::user
{
auto main() -> void
{
+ // Test writing to VGA Buffer
char constexpr syscall_message[] = "Successfully entered user mode and wrote to VGA buffer via syscall!";
context_switching::syscall::syscall(context_switching::syscall::type::WRITE,
{reinterpret_cast<uint64_t>(&syscall_message)});
- int test = std::max(5, 10);
- (void)test;
-
- std::atomic<bool> locked = {false};
- locked.exchange(true);
+ // Test C++ standard library
+ std::array<std::atomic<uint8_t>, 4> array_test = {std::atomic<uint8_t>{5}, std::atomic<uint8_t>{10},
+ std::atomic<uint8_t>{15}, std::atomic<uint8_t>{20}};
+ std::ranges::for_each(array_test, [](auto & item) {
+ auto value = item.load();
+ uint8_t max_value = std::max(value, uint8_t{10});
+ item.exchange(max_value + 2);
+ });
+ // Test user heap
auto address = memory::heap::global_heap_allocator::malloc(8U);
(void)address;