x86_64 cpu: change how the current cpu pointer is found

This commit is contained in:
Matheus
2024-09-15 15:26:40 -03:00
parent 560e3c0aa1
commit 5382a8249b
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -208,7 +208,7 @@ arch_syscall_entry:
; because it's still using the user stack ; because it's still using the user stack
mov cr2, rax mov cr2, rax
; rax can be used just fine now ; 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] ; thread pointer
mov rax, [rax] ; kernel stack top mov rax, [rax] ; kernel stack top
xchg rsp, rax ; switch stack pointers xchg rsp, rax ; switch stack pointers
+3 -3
View File
@@ -17,6 +17,7 @@
typedef struct cpu_t { typedef struct cpu_t {
thread_t *thread; thread_t *thread;
struct cpu_t *self;
uint64_t gdt[7]; uint64_t gdt[7];
ist_t ist; ist_t ist;
long id; long id;
@@ -31,7 +32,6 @@ typedef struct cpu_t {
void *schedulerstack; void *schedulerstack;
isr_t *isrqueue; isr_t *isrqueue;
dpc_t *dpcqueue; dpc_t *dpcqueue;
struct cpu_t *self;
isr_t *dpcisr; isr_t *dpcisr;
} cpu_t; } cpu_t;
@@ -58,13 +58,13 @@ cpu_t *_bsp(void);
static inline cpu_t *_cpu() { static inline cpu_t *_cpu() {
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; return cpu;
} }
static inline void cpu_set(cpu_t *ptr) { static inline void cpu_set(cpu_t *ptr) {
ptr->self = ptr; ptr->self = ptr;
wrmsr(MSR_GSBASE, (uint64_t)&ptr->self); wrmsr(MSR_GSBASE, (uint64_t)ptr);
} }
void cpu_initstate(); void cpu_initstate();