mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
regs: set up mxcsr properly; arch_regs_firsttimesetup()
This commit is contained in:
@@ -9,6 +9,7 @@ typedef uint64_t arch_reg;
|
|||||||
typedef struct{
|
typedef struct{
|
||||||
uint64_t gsbase, fsbase;
|
uint64_t gsbase, fsbase;
|
||||||
uint8_t fx[512];
|
uint8_t fx[512];
|
||||||
|
uint32_t mxcsr;
|
||||||
} arch_extraregs;
|
} arch_extraregs;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
@@ -16,6 +17,9 @@ typedef struct{
|
|||||||
} arch_regs;
|
} arch_regs;
|
||||||
void arch_regs_saveextra(arch_extraregs* regs);
|
void arch_regs_saveextra(arch_extraregs* regs);
|
||||||
void arch_regs_setupextra(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_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrupts);
|
||||||
void arch_regs_setupuser(arch_regs* regs, void* ip, void* stack, bool interrupts);
|
void arch_regs_setupuser(arch_regs* regs, void* ip, void* stack, bool interrupts);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#include <arch/regs.h>
|
#include <arch/regs.h>
|
||||||
#include <arch/msr.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){
|
void arch_regs_saveextra(arch_extraregs* regs){
|
||||||
// user gs was swapped
|
// user gs was swapped
|
||||||
regs->gsbase = rdmsr(MSR_KERNELGSBASE);
|
regs->gsbase = rdmsr(MSR_KERNELGSBASE);
|
||||||
regs->fsbase = rdmsr(MSR_FSBASE);
|
regs->fsbase = rdmsr(MSR_FSBASE);
|
||||||
asm("fxsave (%%rax)" : : "a"(®s->fx[0]));
|
asm("fxsave (%%rax)" : : "a"(®s->fx[0]));
|
||||||
|
asm("stmxcsr (%%rax)" : : "a"(®s->mxcsr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void arch_regs_setupextra(arch_extraregs* regs){
|
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_KERNELGSBASE, regs->gsbase);
|
||||||
wrmsr(MSR_FSBASE, regs->fsbase);
|
wrmsr(MSR_FSBASE, regs->fsbase);
|
||||||
asm("fxrstor (%%rax)" : : "a"(®s->fx[0]));
|
asm("fxrstor (%%rax)" : : "a"(®s->fx[0]));
|
||||||
|
asm("ldmxcsr (%%rax)" : : "a"(®s->mxcsr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void arch_regs_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrupts){
|
void arch_regs_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrupts){
|
||||||
|
|||||||
@@ -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->kernelstack = thread->kernelstackbase + kstacksize;
|
||||||
thread->stacksize = kstacksize;
|
thread->stacksize = kstacksize;
|
||||||
|
|
||||||
|
arch_regs_firsttimesetup(thread->regs, &thread->extraregs);
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user