mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
x86-64: properly set up x87 state
This commit is contained in:
@@ -40,4 +40,13 @@ void cpu_initstate() {
|
||||
"or $0b11000000000, %%rax;"
|
||||
"mov %%rax, %%cr4;"
|
||||
: : : "rax");
|
||||
|
||||
// set NE in cr0 and reset x87 fpu
|
||||
asm volatile(
|
||||
"fninit;"
|
||||
"mov %%cr0, %%rax;"
|
||||
"or $0b100000, %%rax;"
|
||||
"mov %%rax, %%cr0;"
|
||||
: : : "rax"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,14 @@ typedef struct {
|
||||
} \
|
||||
(x)->rflags = 0x200;
|
||||
|
||||
#define CTX_XINIT(x, u) \
|
||||
(x)->mxcsr = 0x1F80; // all exceptions masked
|
||||
// all sse exceptions masked
|
||||
// initialise the x87 FPU state as it would be after the FNINIT instruction
|
||||
#define CTX_XINIT(x, u) {\
|
||||
(x)->mxcsr = 0x1F80; \
|
||||
*((uint16_t *)&(x)->fx[0]) = 0x37f; \
|
||||
*((uint16_t *)&(x)->fx[2]) = 0; \
|
||||
(x)->fx[4] = 0; \
|
||||
}
|
||||
|
||||
#define CTX_SP(x) (x)->rsp
|
||||
#define CTX_IP(x) (x)->rip
|
||||
|
||||
Reference in New Issue
Block a user