cpu: dont access cpu local storage using rdmsr

This commit is contained in:
Matheus
2024-04-29 21:26:47 -03:00
parent 43b209666f
commit 27d24f3e20
2 changed files with 8 additions and 3 deletions
+2 -1
View File
@@ -130,7 +130,8 @@ 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] ; thread pointer
mov rax, [gs:0x0] ; cpu pointer
mov rax, [rax] ; thread pointer
mov rax, [rax] ; kernel stack top
xchg rsp, rax ; switch stack pointers
+6 -2
View File
@@ -31,6 +31,7 @@ typedef struct cpu_t {
void *schedulerstack;
isr_t *isrqueue;
dpc_t *dpcqueue;
struct cpu_t *self;
} cpu_t;
#define CPU_HALT() asm volatile("hlt")
@@ -53,11 +54,14 @@ static inline uint16_t be_to_cpu_w(uint16_t w) {
}
static inline cpu_t *_cpu() {
return (cpu_t *)rdmsr(MSR_GSBASE);
volatile cpu_t *cpu;
asm volatile ("mov %%gs:0, %%rax" : "=a"(cpu));
return cpu->self;
}
static inline void cpu_set(cpu_t *ptr) {
wrmsr(MSR_GSBASE, (uint64_t)ptr);
ptr->self = ptr;
wrmsr(MSR_GSBASE, (uint64_t)&ptr->self);
}
void cpu_initstate();