syscall fixes

This commit is contained in:
2026-10-12 19:05:42 +02:00
parent bc5f01dab6
commit 060983bbf6
5 changed files with 16 additions and 9 deletions
+1
View File
@@ -117,6 +117,7 @@
#define CPUID_7D_AMX_INT8 (1 << 25)
#define RFLAGS_CF (1u << 0)
#define RFLAGS_BRKI (1u << 1)
#define RFLAGS_PF (1u << 2)
#define RFLAGS_AF (1u << 4)
#define RFLAGS_ZF (1u << 6)
+3 -2
View File
@@ -66,10 +66,11 @@ void x86_64_cpu_setup(struct percpu* cpu) {
asm_wrmsr(MSR_EFER, asm_rdmsr(MSR_EFER) | MSR_EFER_SCE);
union ia32_star star = {0};
star.kernel_cs_ss = offsetof(struct gdt, kernel_code64);
star.user_cs_ss = offsetof(struct gdt, user_code32);
star.user_cs_ss = offsetof(struct gdt, user_code32) | CPL_USER;
asm_wrmsr(MSR_STAR, star.value);
asm_wrmsr(MSR_LSTAR, (uint64_t)arch_syscall_stub);
asm_wrmsr(MSR_SFMASK, RFLAGS_AC | RFLAGS_DF | RFLAGS_IF);
// Mask all RFLAGS except for BRKI which is reserved.
asm_wrmsr(MSR_SFMASK, ~RFLAGS_BRKI);
// TODO: FRED
+4 -2
View File
@@ -58,8 +58,10 @@ void arch_syscall_stub() {
" pop rbx\n"
" pop rax\n"
" add rsp, 0x10\n" // Skip .error and .isr fields
"2:\n"
" mov rsp, gs:%c[user_stack]\n"
" pop rcx\n" // rip
" add rsp, 0x08\n" // Skip cs
" pop r11\n" // rflags
" pop rsp\n" // rsp
" swapgs\n"
" sysretq\n"
: