Skip to content

Commit

Permalink
FWAIT
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo720 committed Jan 31, 2024
1 parent db47c90 commit 2372903
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib86cpu/core/emitter/x64/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5213,6 +5213,30 @@ lc86_jit::fnstsw(decoded_instr *instr)
}
}

void
lc86_jit::fwait(decoded_instr *instr)
{
if ((m_cpu->cpu_ctx.hflags & (HFLG_CR0_MP | HFLG_CR0_TS)) == (HFLG_CR0_MP | HFLG_CR0_TS)) {
RAISEin0_t(EXP_NM);
}
else {
Label no_exp = m_a.newLabel();
LD_R16(AX, CPU_CTX_FSTATUS);
TEST(AX, FPU_EXP_ALL);
BR_EQ(no_exp);
LD_R16(AX, CPU_CTX_FCTRL);
AND(AX, FPU_EXP_ALL);
CMP(AX, FPU_EXP_ALL);
BR_EQ(no_exp);
static const char *abort_msg = "Unmasked fpu exceptions are not supported";
MOV(RCX, abort_msg);
MOV(RAX, &cpu_runtime_abort);
CALL(RAX); // won't return
INT3();
m_a.bind(no_exp);
}
}

void
lc86_jit::fxrstor(decoded_instr *instr)
{
Expand Down
1 change: 1 addition & 0 deletions lib86cpu/core/emitter/x64/jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class lc86_jit : public Target {
void fld(decoded_instr *instr);
void fninit(decoded_instr *instr);
void fnstsw(decoded_instr *instr);
void fwait(decoded_instr *instr);
void fxrstor(decoded_instr *instr);
void fxsave(decoded_instr *instr);
void hlt(decoded_instr *instr);
Expand Down
4 changes: 4 additions & 0 deletions lib86cpu/core/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,10 @@ cpu_translate(cpu_t *cpu)
cpu->jit->fnstsw(&instr);
break;

case ZYDIS_MNEMONIC_FWAIT:
cpu->jit->fwait(&instr);
break;

case ZYDIS_MNEMONIC_FXRSTOR:
cpu->jit->fxrstor(&instr);
break;
Expand Down

0 comments on commit 2372903

Please sign in to comment.