kernel: fix remaining _cpu() races

This commit is contained in:
Matheus
2024-09-15 18:39:59 -03:00
parent 32392573cc
commit 56d665d5a0
9 changed files with 26 additions and 18 deletions
+7 -1
View File
@@ -19,9 +19,9 @@ typedef struct cpu_t {
thread_t *thread;
struct cpu_t *self;
vmmcontext_t *vmmctx;
long id;
uint64_t gdt[7];
ist_t ist;
long id;
isr_t isr[MAX_ISR_COUNT];
int acpiid;
timer_t *timer;
@@ -78,6 +78,12 @@ static inline void set_current_vmm_context(vmmcontext_t *context) {
asm volatile ("mov %%rax, %%gs:16" : : "a"(context) : "memory");
}
static inline long current_cpu_id(void) {
long id;
asm volatile ("mov %%gs:24, %%rax" : "=a"(id) : : "memory");
return id;
}
static inline void cpu_set(cpu_t *ptr) {
ptr->self = ptr;
wrmsr(MSR_GSBASE, (uint64_t)ptr);
+1 -1
View File
@@ -72,7 +72,7 @@ static void mcfg_write32(int bus, int device, int function, uint32_t offset, uin
static uint64_t msiformatmessage(uint32_t *data, int vector, int edgetrigger, int deassert) {
*data = (edgetrigger ? 0 : (1 << 15)) | (deassert ? 0 : (1 << 14)) | vector;
return 0xfee00000 | (_cpu()->id << 12);
return 0xfee00000 | (current_cpu_id() << 12);
}
// in PCIe, every function has 4096 bytes of config space for it.