cleanup
This commit is contained in:
+16
-10
@@ -8,6 +8,7 @@
|
||||
#include <x86_64/gdt.h>
|
||||
#include <x86_64/hpet.h>
|
||||
#include <x86_64/idt.h>
|
||||
#include <x86_64/percpu.h>
|
||||
#include <x86_64/syscall.h>
|
||||
#include <x86_64/tsc.h>
|
||||
|
||||
@@ -39,11 +40,16 @@ union ia32_star {
|
||||
|
||||
static_assert(sizeof(union ia32_star) == 8);
|
||||
|
||||
[[__percpu]]
|
||||
struct arch_percpu arch_data = {0};
|
||||
|
||||
static void setup_cpu(struct percpu* cpu) {
|
||||
asm_wrmsr(MSR_KERNEL_GS_BASE, 0);
|
||||
asm_wrmsr(MSR_GS_BASE, (uint64_t)cpu);
|
||||
asm_wrmsr(MSR_FS_BASE, 0);
|
||||
|
||||
struct arch_percpu* arch_cpu = percpu_ref(arch_data);
|
||||
|
||||
gdt_load();
|
||||
|
||||
// TODO: not if FRED
|
||||
@@ -88,13 +94,13 @@ static void setup_cpu(struct percpu* cpu) {
|
||||
|
||||
asm_wrxcr(0, xcr0);
|
||||
|
||||
cpu->arch.fpu_size = cpuid13.ecx;
|
||||
cpu->arch.fpu_save = asm_xsave;
|
||||
cpu->arch.fpu_restore = asm_xrstor;
|
||||
arch_cpu->fpu_size = cpuid13.ecx;
|
||||
arch_cpu->fpu_save = asm_xsave;
|
||||
arch_cpu->fpu_restore = asm_xrstor;
|
||||
} else {
|
||||
cpu->arch.fpu_size = 512;
|
||||
cpu->arch.fpu_save = asm_fxsave;
|
||||
cpu->arch.fpu_restore = asm_fxrstor;
|
||||
arch_cpu->fpu_size = 512;
|
||||
arch_cpu->fpu_save = asm_fxsave;
|
||||
arch_cpu->fpu_restore = asm_fxrstor;
|
||||
}
|
||||
|
||||
if (cpuid7.ecx & CPUID_7C_UMIP)
|
||||
@@ -105,16 +111,16 @@ static void setup_cpu(struct percpu* cpu) {
|
||||
|
||||
if (cpuid7.ebx & CPUID_7B_SMAP) {
|
||||
cr4 |= CR4_SMAP;
|
||||
cpu->arch.can_smap = true;
|
||||
arch_cpu->can_smap = true;
|
||||
}
|
||||
|
||||
if (cpuid7.ebx & CPUID_7B_FSGSBASE)
|
||||
cr4 |= CR4_FSGSBASE;
|
||||
|
||||
asm volatile("mov %0, cr0" : "=r"(cr0));
|
||||
asm volatile("mov %0, cr4" : "=r"(cr4));
|
||||
asm volatile("mov cr0, %0" ::"r"(cr0));
|
||||
asm volatile("mov cr4, %0" ::"r"(cr4));
|
||||
|
||||
lapic_init(&cpu->arch.lapic);
|
||||
lapic_init(&arch_cpu->lapic);
|
||||
cpu->online = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user