aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/context_switching/main.cpp
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-05-01 12:25:40 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-05-01 12:25:40 +0000
commit7c045d8ded72017ff11fd4b9b02148987b944caf (patch)
tree5976c4420178cb3e7a4a992f7679ceedd1bb2b34 /arch/x86_64/src/context_switching/main.cpp
parent5eb8d63a6ece530cb1d56217a046553b4b96245d (diff)
downloadteachos-7c045d8ded72017ff11fd4b9b02148987b944caf.tar.xz
teachos-7c045d8ded72017ff11fd4b9b02148987b944caf.zip
WIP experiment with converting GDT to 8-Byte entries
Diffstat (limited to 'arch/x86_64/src/context_switching/main.cpp')
-rw-r--r--arch/x86_64/src/context_switching/main.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp
index 7db9583..5901998 100644
--- a/arch/x86_64/src/context_switching/main.cpp
+++ b/arch/x86_64/src/context_switching/main.cpp
@@ -29,7 +29,19 @@ namespace teachos::arch::context_switching
constexpr context_switching::interrupt_descriptor_table::segment_selector USER_DATA_SEGMENT_SELECTOR{
4U, context_switching::interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_USER};
- auto reload_global_descriptor_table_register() -> void { kernel::cpu::call(KERNEL_CODE_POINTER); }
+ auto reload_gdtr() -> void
+ {
+ // asm volatile("pushq $0x8\n\t" // Push new CS
+ // "lea 1f(%%rip), %%rax\n\t" // Get address of label 1 into RAX
+ // "pushq %%rax\n\t" // Push return address
+ // "lretq\n" // Far return (loads CS:RIP)
+ // "1:\n\t" // Label to return to
+ // :
+ // :
+ // : "rax", "memory");
+
+ kernel::cpu::call(KERNEL_CODE_POINTER);
+ }
auto user_mode_main() -> void
{
@@ -83,9 +95,7 @@ namespace teachos::arch::context_switching
kernel::cpu::write_msr(IA32_FMASK_ADDRESS, 0U);
uint64_t kernel_cs = KERNEL_CODE_SEGMENT_SELECTOR;
- // We want to provide the user code segment, but the instruction calculates + 0x10 to fill the
- // cs register (See https://www.felixcloutier.com/x86/sysret).
- uint64_t user_cs = USER_CODE_SEGMENT_SELECTOR - 0x10;
+ uint64_t user_cs = KERNEL_CODE_SEGMENT_SELECTOR;
uint64_t star_value = (kernel_cs << 32) | (user_cs << 48);
kernel::cpu::write_msr(IA32_STAR_ADDRESS, star_value);
@@ -102,17 +112,17 @@ namespace teachos::arch::context_switching
{
kernel::cpu::clear_interrupt_flag();
- segment_descriptor_table::update_global_descriptor_table_register();
+ segment_descriptor_table::update_gdtr();
interrupt_descriptor_table::update_interrupt_descriptor_table_register();
- reload_global_descriptor_table_register();
+ reload_gdtr();
segment_descriptor_table::update_task_state_segment_register();
kernel::cpu::set_interrupt_flag();
initalized = true;
}
- descriptor_tables tables = {segment_descriptor_table::get_or_create_global_descriptor_table(),
+ descriptor_tables tables = {segment_descriptor_table::get_or_create_gdt(),
interrupt_descriptor_table::get_or_create_interrupt_descriptor_table()};
return tables;
}