diff options
| author | Fabian Imhof <fabian.imhof@ost.ch> | 2025-04-27 10:21:29 +0000 |
|---|---|---|
| committer | Fabian Imhof <fabian.imhof@ost.ch> | 2025-04-27 10:21:29 +0000 |
| commit | c865eff02ae1978b4f665432d853374d1ffacecf (patch) | |
| tree | 210f93b7092d11f72018c2b7999f31555eef2968 | |
| parent | 5f149faeb9d41bb56733075b0e56908b3731d38d (diff) | |
| download | teachos-c865eff02ae1978b4f665432d853374d1ffacecf.tar.xz teachos-c865eff02ae1978b4f665432d853374d1ffacecf.zip | |
create trampoline for syscall
| -rw-r--r-- | arch/x86_64/include/arch/boot/pointers.hpp | 2 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/boot.s | 25 | ||||
| -rw-r--r-- | arch/x86_64/src/context_switching/main.cpp | 4 |
3 files changed, 30 insertions, 1 deletions
diff --git a/arch/x86_64/include/arch/boot/pointers.hpp b/arch/x86_64/include/arch/boot/pointers.hpp index fe9c657..d9a7ab7 100644 --- a/arch/x86_64/include/arch/boot/pointers.hpp +++ b/arch/x86_64/include/arch/boot/pointers.hpp @@ -10,6 +10,8 @@ namespace teachos::arch::boot */ extern "C" size_t const multiboot_information_pointer; + extern "C" void syscall_trampoline(); + } // namespace teachos::arch::boot #endif // TEACHOS_ARCH_X86_64_BOOT_POINTERS_HPP diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s index 7932045..24b38ca 100644 --- a/arch/x86_64/src/boot/boot.s +++ b/arch/x86_64/src/boot/boot.s @@ -352,6 +352,31 @@ prepare_page_maps: .section .boot_text, "ax", @progbits .code64 +syscall_target: + iretq + +.global syscall_trampoline +syscall_trampoline: + /* Write target function pointer in IA32_LSTAR MSR */ + mov $0xC0000082, %ecx /* IA32_LSTAR MSR */ + lea [syscall_target], %rax + lea [syscall_target], %rdx + shr $32, %rdx + wrmsr + + /* Write ... in IA32_LSTAR MSR */ + mov $0xC0000084, %ecx /* IA32_FMASK MSR */ + mov $0x0, %rax /* ... lower 32 bits */ + mov $0x0, %rdx /* ... upper 32 bits */ + wrmsr + + /* Write Segment selector in IA32_STAR MSR */ + mov $0xC0000081, %ecx /* IA32_STAR MSR */ + mov $0x10, %rax /* SS lower 32 bits */ + mov $0x0, %rdx /* SS upper 32 bits */ + wrmsr + + _transition_to_long_mode: xor %rax, %rax mov %rax, %ss diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp index faaf831..c949488 100644 --- a/arch/x86_64/src/context_switching/main.cpp +++ b/arch/x86_64/src/context_switching/main.cpp @@ -1,5 +1,6 @@ #include "arch/context_switching/main.hpp" +#include "arch/boot/pointers.hpp" #include "arch/exception_handling/assert.hpp" #include "arch/kernel/cpu/call.hpp" #include "arch/kernel/cpu/control_register.hpp" @@ -59,7 +60,8 @@ namespace teachos::arch::context_switching // People claim that SYSENTER is for 32-Bit, while SYSCALL is for 64-Bit! // asm volatile("INT $0x80"); - asm volatile("SYSCALL"); + // asm volatile("SYSCALL"); + boot::syscall_trampoline(); video::vga::text::write("Successfully entered user mode!", video::vga::text::common_attributes::green_on_black); } |
