aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-04-27 14:07:33 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-04-27 14:07:33 +0000
commit13dd2bd5a88ec7efeadf8586778f2c5a26d8cd9e (patch)
tree9dcf8c9efeaa74f136a796531caee323aceaae37 /arch/x86_64/src
parent187eba4eca3ea46d8c26419168e525242338dae4 (diff)
downloadteachos-13dd2bd5a88ec7efeadf8586778f2c5a26d8cd9e.tar.xz
teachos-13dd2bd5a88ec7efeadf8586778f2c5a26d8cd9e.zip
Move not public methods into anonymous namespace
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/context_switching/main.cpp59
-rw-r--r--arch/x86_64/src/context_switching/syscall_handler.cpp19
-rw-r--r--arch/x86_64/src/kernel/cpu/msr.cpp2
-rw-r--r--arch/x86_64/src/kernel/main.cpp1
4 files changed, 39 insertions, 42 deletions
diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp
index 155d150..f73cb19 100644
--- a/arch/x86_64/src/context_switching/main.cpp
+++ b/arch/x86_64/src/context_switching/main.cpp
@@ -1,7 +1,6 @@
#include "arch/context_switching/main.hpp"
#include "arch/boot/pointers.hpp"
-#include "arch/context_switching/syscall_handler.hpp"
#include "arch/exception_handling/assert.hpp"
#include "arch/kernel/cpu/call.hpp"
#include "arch/kernel/cpu/control_register.hpp"
@@ -30,6 +29,43 @@ namespace teachos::arch::context_switching
auto reload_global_descriptor_table_register() -> void { kernel::cpu::call(KERNEL_CODE_POINTER); }
+ auto user_mode_main() -> void
+ {
+ kernel::cpu::validate_segment_registers(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR);
+
+ video::vga::text::write("Successfully entered user mode!", video::vga::text::common_attributes::green_on_black);
+
+ asm volatile("syscall");
+
+ kernel::cpu::validate_segment_registers(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR);
+
+ video::vga::text::write("Successfully made a SYSCALL and returned back with SYSRET!",
+ video::vga::text::common_attributes::green_on_black);
+ }
+
+ auto syscall_handler() -> void
+ {
+ uint64_t dummy{};
+ switch (dummy)
+ {
+ case 0:
+ break;
+ default:
+ break;
+ }
+
+ asm volatile("sysretq");
+ }
+
+ auto enable_systemcall() -> void
+ {
+ uint64_t const syscall_function = reinterpret_cast<uint64_t>(syscall_handler);
+ kernel::cpu::write_msr(IA32_LSTAR_ADDRESS, syscall_function);
+ kernel::cpu::write_msr(IA32_FMASK_ADDRESS, 0U);
+ kernel::cpu::write_msr(IA32_STAR_ADDRESS, KERNEL_CODE_SEGMENT_SELECTOR);
+ kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::SCE);
+ }
+
} // namespace
auto initialize_descriptor_tables() -> descriptor_tables
@@ -55,17 +91,9 @@ namespace teachos::arch::context_switching
return tables;
}
- auto user_mode_main() -> void
- {
- kernel::cpu::validate_segment_registers(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR);
-
- asm volatile("SYSCALL");
-
- video::vga::text::write("Successfully entered user mode!", video::vga::text::common_attributes::green_on_black);
- }
-
auto switch_to_user_mode() -> void
{
+ enable_systemcall();
switch_context(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR, user_mode_main);
}
@@ -77,15 +105,4 @@ namespace teachos::arch::context_switching
kernel::cpu::set_code_segment_register(data_segment, code_segment, reinterpret_cast<uint64_t>(return_function));
}
- auto setup_syscall() -> void
- {
- uint64_t const syscall_function = reinterpret_cast<uint64_t>(syscall_handler);
- uint64_t const segment_selector = *reinterpret_cast<uint64_t const *>(&KERNEL_CODE_SEGMENT_SELECTOR);
-
- kernel::cpu::write_msr(IA32_LSTAR_ADDRESS, syscall_function);
- kernel::cpu::write_msr(IA32_FMASK_ADDRESS, 0U);
- kernel::cpu::write_msr(IA32_STAR_ADDRESS, segment_selector);
- kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::SCE);
- }
-
} // namespace teachos::arch::context_switching
diff --git a/arch/x86_64/src/context_switching/syscall_handler.cpp b/arch/x86_64/src/context_switching/syscall_handler.cpp
deleted file mode 100644
index 283d297..0000000
--- a/arch/x86_64/src/context_switching/syscall_handler.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "arch/context_switching/syscall_handler.hpp"
-
-#include <cstdint>
-
-namespace teachos::arch::context_switching
-{
- auto syscall_handler() -> void
- {
- uint64_t dummy{};
- switch (dummy)
- {
- case 0:
- break;
- default:
- break;
- }
- asm volatile("SYSRET");
- }
-} // namespace teachos::arch::context_switching \ No newline at end of file
diff --git a/arch/x86_64/src/kernel/cpu/msr.cpp b/arch/x86_64/src/kernel/cpu/msr.cpp
index 6249f8f..9c474a1 100644
--- a/arch/x86_64/src/kernel/cpu/msr.cpp
+++ b/arch/x86_64/src/kernel/cpu/msr.cpp
@@ -16,7 +16,7 @@ namespace teachos::arch::kernel::cpu
auto write_msr(uint32_t msr, uint64_t value) -> void
{
- uint32_t low = value & 0xFFFFFFFF;
+ uint32_t low = value;
uint32_t high = value >> 32;
asm volatile("wrmsr"
: /* no output from call */
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index e737d44..05c879e 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -63,7 +63,6 @@ namespace teachos::arch::kernel
memory::heap::global_heap_allocator::register_heap_allocator(memory::heap::heap_allocator_type::LINKED_LIST);
// heap_test();
- context_switching::setup_syscall();
context_switching::switch_to_user_mode();
}
} // namespace teachos::arch::kernel