aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/src/context_switching/main.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp
index 8d1c019..7db9583 100644
--- a/arch/x86_64/src/context_switching/main.cpp
+++ b/arch/x86_64/src/context_switching/main.cpp
@@ -35,6 +35,16 @@ namespace teachos::arch::context_switching
{
video::vga::text::write("Successfully entered user mode!", video::vga::text::common_attributes::green_on_black);
+ // RFLAGS is saved into R11, RIP of the next instruction into RCX
+ // Required for SYSRETURN to know where to return too.
+ // Additional state needs to be saved by calling convention:
+
+ // Syscall Number: RAX, Return Value: RAX (0 indicating no error, and -1 indicating an error, use as a boolean)
+ // Argument in this order (max 6. no argument on stack): RDI, RSI, RDX, R10, R8, R9
+ // Not used registers: RBX, RSP, R12, R13, R14
+
+ // Actual Source: https://man7.org/linux/man-pages/man2/syscall.2.html More cleare documentation:
+ // https://sys.readthedocs.io/en/latest/doc/05_calling_system_calls.html
uint64_t new_value = 60U;
asm volatile("mov %[input], %%rax"
: /* no output from call */
@@ -70,7 +80,7 @@ namespace teachos::arch::context_switching
{
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, 1 << 9U); // Disable interrupt flag during syscall.
+ 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