From 5382a8249b49a20229e89f9cf90a36e9ffe254f7 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 15 Sep 2024 15:26:40 -0300 Subject: [PATCH] x86_64 cpu: change how the current cpu pointer is found --- kernel-src/arch/x86-64/syscall.asm | 2 +- kernel-src/include/x86-64/arch/cpu.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index e3e0e3f0..bca42a55 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -208,7 +208,7 @@ arch_syscall_entry: ; because it's still using the user stack mov cr2, rax ; rax can be used just fine now - mov rax, [gs:0x0] ; cpu pointer + mov rax, [gs:0x8] ; cpu pointer mov rax, [rax] ; thread pointer mov rax, [rax] ; kernel stack top xchg rsp, rax ; switch stack pointers diff --git a/kernel-src/include/x86-64/arch/cpu.h b/kernel-src/include/x86-64/arch/cpu.h index 26bda0fb..f6637f57 100644 --- a/kernel-src/include/x86-64/arch/cpu.h +++ b/kernel-src/include/x86-64/arch/cpu.h @@ -17,6 +17,7 @@ typedef struct cpu_t { thread_t *thread; + struct cpu_t *self; uint64_t gdt[7]; ist_t ist; long id; @@ -31,7 +32,6 @@ typedef struct cpu_t { void *schedulerstack; isr_t *isrqueue; dpc_t *dpcqueue; - struct cpu_t *self; isr_t *dpcisr; } cpu_t; @@ -58,13 +58,13 @@ cpu_t *_bsp(void); static inline cpu_t *_cpu() { cpu_t *cpu; - asm volatile ("mov %%gs:0, %%rax" : "=a"(cpu) : : "memory"); + asm volatile ("mov %%gs:8, %%rax" : "=a"(cpu) : : "memory"); return cpu; } static inline void cpu_set(cpu_t *ptr) { ptr->self = ptr; - wrmsr(MSR_GSBASE, (uint64_t)&ptr->self); + wrmsr(MSR_GSBASE, (uint64_t)ptr); } void cpu_initstate();