diff --git a/api/arch/x86/syscall.hpp b/api/arch/x86/syscall.hpp new file mode 100644 index 000000000..011a01453 --- /dev/null +++ b/api/arch/x86/syscall.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace x86 { + void init_syscall_trap(); +} \ No newline at end of file diff --git a/src/arch/x86_64/CMakeLists.txt b/src/arch/x86_64/CMakeLists.txt index ce9be1e0d..90c98314f 100644 --- a/src/arch/x86_64/CMakeLists.txt +++ b/src/arch/x86_64/CMakeLists.txt @@ -11,6 +11,7 @@ set(ARCH_OBJECTS fiber_asm.asm __syscall_entry.asm syscall_entry.cpp + syscall_trap.cpp ist.cpp paging.cpp init_paging.cpp diff --git a/src/arch/x86_64/syscall_trap.cpp b/src/arch/x86_64/syscall_trap.cpp new file mode 100644 index 000000000..a6bcba937 --- /dev/null +++ b/src/arch/x86_64/syscall_trap.cpp @@ -0,0 +1,17 @@ +#include +#include + +extern "C" void __syscall_entry(); + +namespace x86 { + +void init_syscall_trap() +{ + uint64_t star_kernel_cs = 8ull << 32; + uint64_t star_user_cs = 8ull << 48; + uint64_t star = star_kernel_cs | star_user_cs; + CPU::write_msr(IA32_STAR, star); + CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); +} + +} \ No newline at end of file diff --git a/src/platform/x86_pc/apic_revenant.cpp b/src/platform/x86_pc/apic_revenant.cpp index 02cc18aa7..62e56a2c9 100644 --- a/src/platform/x86_pc/apic_revenant.cpp +++ b/src/platform/x86_pc/apic_revenant.cpp @@ -3,6 +3,7 @@ #include "apic_timer.hpp" #include "clocks.hpp" #include "idt.hpp" +#include #include //#include #include @@ -90,6 +91,7 @@ void revenant_main(int cpu) SMP::global_unlock(); // initialize exceptions before asserts x86::idt_initialize_for_cpu(cpu); + x86::init_syscall_trap(); assert(cpu == SMP::cpu_id()); assert(stack >= this_stack_end && stack < this_stack); // relates to [[maybe_unused]] diff --git a/src/platform/x86_pc/init_libc.cpp b/src/platform/x86_pc/init_libc.cpp index ae39c919a..45ad0a7a8 100644 --- a/src/platform/x86_pc/init_libc.cpp +++ b/src/platform/x86_pc/init_libc.cpp @@ -1,6 +1,7 @@ #include "init_libc.hpp" #include +#include #include #include #include @@ -153,18 +154,8 @@ namespace x86 aux[i++].set_long(AT_NULL, 0); #ifdef PLATFORM_x86_pc - // SYSCALL instruction - #if defined(__x86_64__) - KDEBUG("* Initialize syscall MSR (64-bit)\n"); - uint64_t star_kernel_cs = 8ull << 32; - uint64_t star_user_cs = 8ull << 48; - uint64_t star = star_kernel_cs | star_user_cs; - x86::CPU::write_msr(IA32_STAR, star); - x86::CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); - #elif defined(__i386__) - KDEBUG("Initialize syscall intr (32-bit)\n"); - #warning Classical syscall interface missing for 32-bit - #endif + KDEBUG("* Initialize syscall trap\n"); + x86::init_syscall_trap(); #endif // GDB_ENTRY;