regs: set up mxcsr properly; arch_regs_firsttimesetup()

This commit is contained in:
Matheus
2022-09-23 21:37:04 -03:00
parent bedd2f625e
commit 9cca7891b9
3 changed files with 12 additions and 1 deletions
+4
View File
@@ -9,6 +9,7 @@ typedef uint64_t arch_reg;
typedef struct{
uint64_t gsbase, fsbase;
uint8_t fx[512];
uint32_t mxcsr;
} arch_extraregs;
typedef struct{
@@ -16,6 +17,9 @@ typedef struct{
} arch_regs;
void arch_regs_saveextra(arch_extraregs* regs);
void arch_regs_setupextra(arch_extraregs* regs);
void arch_regs_firsttimesetup(arch_regs* regs, arch_extraregs* xregs);
void arch_regs_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrupts);
void arch_regs_setupuser(arch_regs* regs, void* ip, void* stack, bool interrupts);
+6 -1
View File
@@ -1,12 +1,16 @@
#include <arch/regs.h>
#include <arch/msr.h>
void arch_regs_firsttimesetup(arch_regs* regs, arch_extraregs* xregs){
xregs->mxcsr = 0x1F80; // all exceptions masked
}
void arch_regs_saveextra(arch_extraregs* regs){
// user gs was swapped
regs->gsbase = rdmsr(MSR_KERNELGSBASE);
regs->fsbase = rdmsr(MSR_FSBASE);
asm("fxsave (%%rax)" : : "a"(&regs->fx[0]));
asm("stmxcsr (%%rax)" : : "a"(&regs->mxcsr));
}
void arch_regs_setupextra(arch_extraregs* regs){
@@ -14,6 +18,7 @@ void arch_regs_setupextra(arch_extraregs* regs){
wrmsr(MSR_KERNELGSBASE, regs->gsbase);
wrmsr(MSR_FSBASE, regs->fsbase);
asm("fxrstor (%%rax)" : : "a"(&regs->fx[0]));
asm("ldmxcsr (%%rax)" : : "a"(&regs->mxcsr));
}
void arch_regs_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrupts){
+2
View File
@@ -98,6 +98,8 @@ static thread_t* allocthread(proc_t* proc, state_t state, pid_t tid, size_t ksta
thread->kernelstack = thread->kernelstackbase + kstacksize;
thread->stacksize = kstacksize;
arch_regs_firsttimesetup(thread->regs, &thread->extraregs);
return thread;
}