Skip to content

Commit

Permalink
Implement fsave/frstor
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Dec 22, 2019
1 parent 36396d6 commit 3e33c60
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
case 0xdd0: TRACE("fld mem64"); FLDM(mem_addr_real,64); break;
case 0xdd2: TRACE("fst mem64"); FSTM(mem_addr_real,64); break;
case 0xdd3: TRACE("fstp mem64"); FSTM(mem_addr_real,64); FPOP; break;
case 0xdd4: TRACE("frstor mem32"); FRESTORE(mem_addr,32); break;
case 0xdd6: TRACE("fnsave mem32"); FSAVE(mem_addr,32); break;
case 0xde0: TRACE("fiadd mem16"); FIADD(mem_addr,16); break;
case 0xde1: TRACE("fimul mem16"); FIMUL(mem_addr,16); break;
case 0xde2: TRACE("ficom mem16"); FICOM(mem_addr,16); break;
Expand Down
17 changes: 17 additions & 0 deletions emu/fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,20 @@ void fpu_ldenv32(struct cpu_state *cpu, struct fpu_env32 *env) {
cpu->fcw = env->control;
cpu->fsw = env->status;
}

struct fpu_state32 {
struct fpu_env32 env;
uint8_t regs[8][10];
};

void fpu_save32(struct cpu_state *cpu, struct fpu_state32 *state) {
fpu_stenv32(cpu, &state->env);
for (int i = 0; i < 8; i++)
memcpy(state->regs[i], &ST(i), 10);
}

void fpu_restore32(struct cpu_state *cpu, struct fpu_state32 *state) {
fpu_ldenv32(cpu, &state->env);
for (int i = 0; i < 8; i++)
memcpy(&ST(i), state->regs[i], 10);
}
3 changes: 3 additions & 0 deletions emu/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "emu/float80.h"
struct cpu_state;
struct fpu_env32;
struct fpu_state32;

typedef float float32;
typedef double float64;
Expand Down Expand Up @@ -103,5 +104,7 @@ void fpu_stcw16(struct cpu_state *cpu, uint16_t *i);
void fpu_ldcw16(struct cpu_state *cpu, uint16_t *i);
void fpu_stenv32(struct cpu_state *cpu, struct fpu_env32 *env);
void fpu_ldenv32(struct cpu_state *cpu, struct fpu_env32 *env);
void fpu_save32(struct cpu_state *cpu, struct fpu_state32 *state);
void fpu_restore32(struct cpu_state *cpu, struct fpu_state32 *state);

#endif
2 changes: 2 additions & 0 deletions jit/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ void helper_rdtsc(struct cpu_state *cpu);
#define FLDCW(dst) if (arg_##dst == arg_reg_a) UNDEFINED; else h_read(fpu_ldcw, 16)
#define FSTENV(val,z) h_write(fpu_stenv, z)
#define FLDENV(val,z) h_write(fpu_ldenv, z)
#define FSAVE(val,z) h_write(fpu_save, z)
#define FRESTORE(val,z) h_write(fpu_restore, z)
#define FPOP h(fpu_pop)
#define FADD(src, dst) hhh(fpu_add, src, dst)
#define FIADD(val,z) h_read(fpu_iadd, z)
Expand Down

0 comments on commit 3e33c60

Please sign in to comment.