More linting in src/codegen

This commit is contained in:
Jasmine Iwanek
2023-08-22 13:33:49 -04:00
parent 66854089c0
commit c4bb670901
14 changed files with 694 additions and 613 deletions

View File

@@ -33,6 +33,8 @@ int codegen_in_recompile;
void void
codegen_set_rounding_mode(int mode) codegen_set_rounding_mode(int mode)
{ {
/* cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (cpu_state.npxc & 0xc00); */ #if 0
cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (cpu_state.npxc & 0xc00);
#endif
cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (mode << 10); cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (mode << 10);
} }

View File

@@ -74,19 +74,25 @@
*/ */
typedef struct codeblock_t { typedef struct codeblock_t {
uint64_t page_mask, page_mask2; uint64_t page_mask;
uint64_t *dirty_mask, *dirty_mask2; uint64_t page_mask2;
uint64_t *dirty_mask;
uint64_t *dirty_mask2;
uint64_t cmp; uint64_t cmp;
/*Previous and next pointers, for the codeblock list associated with /*Previous and next pointers, for the codeblock list associated with
each physical page. Two sets of pointers, as a codeblock can be each physical page. Two sets of pointers, as a codeblock can be
present in two pages.*/ present in two pages.*/
struct codeblock_t *prev, *next; struct codeblock_t *prev;
struct codeblock_t *prev_2, *next_2; struct codeblock_t *next;
struct codeblock_t *prev_2;
struct codeblock_t *next_2;
/*Pointers for codeblock tree, used to search for blocks when hash lookup /*Pointers for codeblock tree, used to search for blocks when hash lookup
fails.*/ fails.*/
struct codeblock_t *parent, *left, *right; struct codeblock_t *parent;
struct codeblock_t *left;
struct codeblock_t *right;
int pnt; int pnt;
int ins; int ins;

View File

@@ -5,6 +5,7 @@
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/mem.h> #include <86box/mem.h>
#include <86box/plat_unused.h>
#include "cpu.h" #include "cpu.h"
#include "x86.h" #include "x86.h"
#include "x86_ops.h" #include "x86_ops.h"

View File

@@ -8,7 +8,9 @@ ropINC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod
host_reg = LOAD_REG_W(opcode & 7); host_reg = LOAD_REG_W(opcode & 7);
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, host_reg); STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, host_reg);
// ADD_HOST_REG_IMM_W(host_reg, 1); #if 0
ADD_HOST_REG_IMM_W(host_reg, 1);
#endif
INC_HOST_REG_W(host_reg); INC_HOST_REG_W(host_reg);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_INC16); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_INC16);
@@ -29,7 +31,9 @@ ropINC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod
host_reg = LOAD_REG_L(opcode & 7); host_reg = LOAD_REG_L(opcode & 7);
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, host_reg); STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, host_reg);
// ADD_HOST_REG_IMM(host_reg, 1); #if 0
ADD_HOST_REG_IMM(host_reg, 1);
#endif
INC_HOST_REG(host_reg); INC_HOST_REG(host_reg);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_INC32); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_INC32);
@@ -50,7 +54,9 @@ ropDEC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod
host_reg = LOAD_REG_W(opcode & 7); host_reg = LOAD_REG_W(opcode & 7);
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, host_reg); STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, host_reg);
// SUB_HOST_REG_IMM_W(host_reg, 1); #if 0
SUB_HOST_REG_IMM_W(host_reg, 1);
#endif
DEC_HOST_REG_W(host_reg); DEC_HOST_REG_W(host_reg);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_DEC16); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_DEC16);
@@ -71,7 +77,9 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod
host_reg = LOAD_REG_L(opcode & 7); host_reg = LOAD_REG_L(opcode & 7);
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, host_reg); STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, host_reg);
// SUB_HOST_REG_IMM(host_reg, 1); #if 0
SUB_HOST_REG_IMM(host_reg, 1);
#endif
DEC_HOST_REG(host_reg); DEC_HOST_REG(host_reg);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op2, 1);
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_DEC32); STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_DEC32);
@@ -83,194 +91,206 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod
return op_pc; return op_pc;
} }
#define ROP_ARITH_RMW(name, op, writeback) \ #define ROP_ARITH_RMW(name, op, writeback) \
static uint32_t rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int src_reg, dst_reg; \ { \
x86seg *target_seg; \ int src_reg; \
\ int dst_reg; \
if ((fetchdat & 0xc0) == 0xc0) { \ x86seg *target_seg; \
dst_reg = LOAD_REG_B(fetchdat & 7); \ \
} else { \ if ((fetchdat & 0xc0) == 0xc0) { \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ dst_reg = LOAD_REG_B(fetchdat & 7); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ } else { \
SAVE_EA(); \ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
MEM_CHECK_WRITE(target_seg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
dst_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg); \ SAVE_EA(); \
} \ MEM_CHECK_WRITE(target_seg); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##8); \ dst_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg); \
src_reg = LOAD_REG_B((fetchdat >> 3) & 7); \ } \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op1, dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##8); \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op2, src_reg); \ src_reg = LOAD_REG_B((fetchdat >> 3) & 7); \
op##_HOST_REG_B(dst_reg, src_reg); \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op1, dst_reg); \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op2, src_reg); \
if (writeback) { \ op##_HOST_REG_B(dst_reg, src_reg); \
if ((fetchdat & 0xc0) == 0xc0) \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \
STORE_REG_B_RELEASE(dst_reg); \ if (writeback) { \
else { \ if ((fetchdat & 0xc0) == 0xc0) \
LOAD_EA(); \ STORE_REG_B_RELEASE(dst_reg); \
MEM_STORE_ADDR_EA_B_NO_ABRT(target_seg, dst_reg); \ else { \
} \ LOAD_EA(); \
} else \ MEM_STORE_ADDR_EA_B_NO_ABRT(target_seg, dst_reg); \
RELEASE_REG(dst_reg); \ } \
RELEASE_REG(src_reg); \ } else \
\ RELEASE_REG(dst_reg); \
codegen_flags_changed = 1; \ RELEASE_REG(src_reg); \
return op_pc + 1; \ \
} \ codegen_flags_changed = 1; \
static uint32_t rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ return op_pc + 1; \
{ \ } \
int src_reg, dst_reg; \ static uint32_t \
x86seg *target_seg; \ rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
\ { \
if ((fetchdat & 0xc0) == 0xc0) { \ int src_reg; \
dst_reg = LOAD_REG_W(fetchdat & 7); \ int dst_reg; \
} else { \ x86seg *target_seg; \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ if ((fetchdat & 0xc0) == 0xc0) { \
SAVE_EA(); \ dst_reg = LOAD_REG_W(fetchdat & 7); \
MEM_CHECK_WRITE_W(target_seg); \ } else { \
dst_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg); \ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
} \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##16); \ SAVE_EA(); \
src_reg = LOAD_REG_W((fetchdat >> 3) & 7); \ MEM_CHECK_WRITE_W(target_seg); \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, dst_reg); \ dst_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg); \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op2, src_reg); \ } \
op##_HOST_REG_W(dst_reg, src_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##16); \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \ src_reg = LOAD_REG_W((fetchdat >> 3) & 7); \
if (writeback) { \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, dst_reg); \
if ((fetchdat & 0xc0) == 0xc0) \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op2, src_reg); \
STORE_REG_W_RELEASE(dst_reg); \ op##_HOST_REG_W(dst_reg, src_reg); \
else { \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \
LOAD_EA(); \ if (writeback) { \
MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, dst_reg); \ if ((fetchdat & 0xc0) == 0xc0) \
} \ STORE_REG_W_RELEASE(dst_reg); \
} else \ else { \
RELEASE_REG(dst_reg); \ LOAD_EA(); \
RELEASE_REG(src_reg); \ MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, dst_reg); \
\ } \
codegen_flags_changed = 1; \ } else \
return op_pc + 1; \ RELEASE_REG(dst_reg); \
} \ RELEASE_REG(src_reg); \
static uint32_t rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ \
{ \ codegen_flags_changed = 1; \
int src_reg, dst_reg; \ return op_pc + 1; \
x86seg *target_seg; \ } \
\ static uint32_t \
if ((fetchdat & 0xc0) == 0xc0) { \ rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
dst_reg = LOAD_REG_L(fetchdat & 7); \ { \
} else { \ int src_reg; \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ int dst_reg; \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ x86seg *target_seg; \
SAVE_EA(); \ \
MEM_CHECK_WRITE_L(target_seg); \ if ((fetchdat & 0xc0) == 0xc0) { \
dst_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg); \ dst_reg = LOAD_REG_L(fetchdat & 7); \
} \ } else { \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##32); \ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
src_reg = LOAD_REG_L((fetchdat >> 3) & 7); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, dst_reg); \ SAVE_EA(); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op2, src_reg); \ MEM_CHECK_WRITE_L(target_seg); \
op##_HOST_REG_L(dst_reg, src_reg); \ dst_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \ } \
if (writeback) { \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##32); \
if ((fetchdat & 0xc0) == 0xc0) \ src_reg = LOAD_REG_L((fetchdat >> 3) & 7); \
STORE_REG_L_RELEASE(dst_reg); \ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, dst_reg); \
else { \ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op2, src_reg); \
LOAD_EA(); \ op##_HOST_REG_L(dst_reg, src_reg); \
MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, dst_reg); \ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \
} \ if (writeback) { \
} else \ if ((fetchdat & 0xc0) == 0xc0) \
RELEASE_REG(dst_reg); \ STORE_REG_L_RELEASE(dst_reg); \
RELEASE_REG(src_reg); \ else { \
\ LOAD_EA(); \
codegen_flags_changed = 1; \ MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, dst_reg); \
return op_pc + 1; \ } \
} else \
RELEASE_REG(dst_reg); \
RELEASE_REG(src_reg); \
\
codegen_flags_changed = 1; \
return op_pc + 1; \
} }
#define ROP_ARITH_RM(name, op, writeback) \ #define ROP_ARITH_RM(name, op, writeback) \
static uint32_t rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int src_reg, dst_reg; \ { \
\ int src_reg; \
if ((fetchdat & 0xc0) == 0xc0) { \ int dst_reg; \
src_reg = LOAD_REG_B(fetchdat & 7); \ \
} else { \ if ((fetchdat & 0xc0) == 0xc0) { \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ src_reg = LOAD_REG_B(fetchdat & 7); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ } else { \
MEM_LOAD_ADDR_EA_B(target_seg); \ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
src_reg = 0; \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
} \ MEM_LOAD_ADDR_EA_B(target_seg); \
\ src_reg = 0; \
dst_reg = LOAD_REG_B((fetchdat >> 3) & 7); \ } \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##8); \ \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op1, dst_reg); \ dst_reg = LOAD_REG_B((fetchdat >> 3) & 7); \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op2, src_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##8); \
op##_HOST_REG_B(dst_reg, src_reg); \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op1, dst_reg); \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_op2, src_reg); \
if (writeback) \ op##_HOST_REG_B(dst_reg, src_reg); \
STORE_REG_B_RELEASE(dst_reg); \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \
else \ if (writeback) \
RELEASE_REG(dst_reg); \ STORE_REG_B_RELEASE(dst_reg); \
RELEASE_REG(src_reg); \ else \
\ RELEASE_REG(dst_reg); \
codegen_flags_changed = 1; \ RELEASE_REG(src_reg); \
return op_pc + 1; \ \
} \ codegen_flags_changed = 1; \
static uint32_t rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ return op_pc + 1; \
{ \ } \
int src_reg, dst_reg; \ static uint32_t \
\ rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
if ((fetchdat & 0xc0) == 0xc0) { \ { \
src_reg = LOAD_REG_W(fetchdat & 7); \ int src_reg; \
} else { \ int dst_reg; \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ if ((fetchdat & 0xc0) == 0xc0) { \
MEM_LOAD_ADDR_EA_W(target_seg); \ src_reg = LOAD_REG_W(fetchdat & 7); \
src_reg = 0; \ } else { \
} \ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
\ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
dst_reg = LOAD_REG_W((fetchdat >> 3) & 7); \ MEM_LOAD_ADDR_EA_W(target_seg); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##16); \ src_reg = 0; \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, dst_reg); \ } \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op2, src_reg); \ \
op##_HOST_REG_W(dst_reg, src_reg); \ dst_reg = LOAD_REG_W((fetchdat >> 3) & 7); \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##16); \
if (writeback) \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op1, dst_reg); \
STORE_REG_W_RELEASE(dst_reg); \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_op2, src_reg); \
else \ op##_HOST_REG_W(dst_reg, src_reg); \
RELEASE_REG(dst_reg); \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \
RELEASE_REG(src_reg); \ if (writeback) \
\ STORE_REG_W_RELEASE(dst_reg); \
codegen_flags_changed = 1; \ else \
return op_pc + 1; \ RELEASE_REG(dst_reg); \
} \ RELEASE_REG(src_reg); \
static uint32_t rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ \
{ \ codegen_flags_changed = 1; \
int src_reg, dst_reg; \ return op_pc + 1; \
\ } \
if ((fetchdat & 0xc0) == 0xc0) { \ static uint32_t \
src_reg = LOAD_REG_L(fetchdat & 7); \ rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
} else { \ { \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ int src_reg; \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ int dst_reg; \
MEM_LOAD_ADDR_EA_L(target_seg); \ \
src_reg = 0; \ if ((fetchdat & 0xc0) == 0xc0) { \
} \ src_reg = LOAD_REG_L(fetchdat & 7); \
\ } else { \
dst_reg = LOAD_REG_L((fetchdat >> 3) & 7); \ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##32); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, dst_reg); \ MEM_LOAD_ADDR_EA_L(target_seg); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op2, src_reg); \ src_reg = 0; \
op##_HOST_REG_L(dst_reg, src_reg); \ } \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \ \
if (writeback) \ dst_reg = LOAD_REG_L((fetchdat >> 3) & 7); \
STORE_REG_L_RELEASE(dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_##op##32); \
else \ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op1, dst_reg); \
RELEASE_REG(dst_reg); \ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_op2, src_reg); \
RELEASE_REG(src_reg); \ op##_HOST_REG_L(dst_reg, src_reg); \
\ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \
codegen_flags_changed = 1; \ if (writeback) \
return op_pc + 1; \ STORE_REG_L_RELEASE(dst_reg); \
else \
RELEASE_REG(dst_reg); \
RELEASE_REG(src_reg); \
\
codegen_flags_changed = 1; \
return op_pc + 1; \
} }
ROP_ARITH_RMW(ADD, ADD, 1) ROP_ARITH_RMW(ADD, ADD, 1)

View File

@@ -194,23 +194,24 @@ ropFSTPd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code
return new_pc; return new_pc;
} }
#define ropFarith(name, size, load, op) \ #define ropFarith(name, size, load, op) \
static uint32_t ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
x86seg *target_seg; \ { \
\ x86seg *target_seg; \
FP_ENTER(); \ \
op_pc--; \ FP_ENTER(); \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ op_pc--; \
\ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ \
\ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
CHECK_SEG_READ(target_seg); \ \
load(target_seg); \ CHECK_SEG_READ(target_seg); \
\ load(target_seg); \
op(FPU_##name); \ \
\ op(FPU_##name); \
return op_pc + 1; \ \
return op_pc + 1; \
} }
ropFarith(ADD, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); ropFarith(ADD, s, MEM_LOAD_ADDR_EA_L, FP_OP_S);
@@ -239,7 +240,8 @@ ropFarith(SUB, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL);
ropFarith(SUBR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); ropFarith(SUBR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL);
#define ropFcompare(name, size, load, op) \ #define ropFcompare(name, size, load, op) \
static uint32_t ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
{ \ { \
x86seg *target_seg; \ x86seg *target_seg; \
\ \
@@ -270,74 +272,80 @@ ropFcompare(COM, d, MEM_LOAD_ADDR_EA_Q, FP_COMPARE_D);
ropFcompare(COM, iw, MEM_LOAD_ADDR_EA_W, FP_COMPARE_IW); ropFcompare(COM, iw, MEM_LOAD_ADDR_EA_W, FP_COMPARE_IW);
ropFcompare(COM, il, MEM_LOAD_ADDR_EA_L, FP_COMPARE_IL); ropFcompare(COM, il, MEM_LOAD_ADDR_EA_L, FP_COMPARE_IL);
/*static uint32_t ropFADDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) #if 0
static uint32_t
ropFADDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block)
{ {
x86seg *target_seg; x86seg *target_seg;
FP_ENTER(); FP_ENTER();
op_pc--; op_pc--;
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32);
STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc);
CHECK_SEG_READ(target_seg); CHECK_SEG_READ(target_seg);
MEM_LOAD_ADDR_EA_L(target_seg); MEM_LOAD_ADDR_EA_L(target_seg);
FP_OP_S(FPU_ADD); FP_OP_S(FPU_ADD);
return op_pc + 1; return op_pc + 1;
} }
static uint32_t ropFDIVs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) static uint32_t
ropFDIVs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block)
{ {
x86seg *target_seg; x86seg *target_seg;
FP_ENTER(); FP_ENTER();
op_pc--; op_pc--;
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32);
STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc);
CHECK_SEG_READ(target_seg); CHECK_SEG_READ(target_seg);
MEM_LOAD_ADDR_EA_L(target_seg); MEM_LOAD_ADDR_EA_L(target_seg);
FP_OP_S(FPU_DIV); FP_OP_S(FPU_DIV);
return op_pc + 1; return op_pc + 1;
} }
static uint32_t ropFMULs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) static uint32_t
ropFMULs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block)
{ {
x86seg *target_seg; x86seg *target_seg;
FP_ENTER(); FP_ENTER();
op_pc--; op_pc--;
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32);
STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc);
CHECK_SEG_READ(target_seg); CHECK_SEG_READ(target_seg);
MEM_LOAD_ADDR_EA_L(target_seg); MEM_LOAD_ADDR_EA_L(target_seg);
FP_OP_S(FPU_MUL); FP_OP_S(FPU_MUL);
return op_pc + 1; return op_pc + 1;
} }
static uint32_t ropFSUBs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) static uint32_t
ropFSUBs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block)
{ {
x86seg *target_seg; x86seg *target_seg;
FP_ENTER(); FP_ENTER();
op_pc--; op_pc--;
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32);
STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc);
CHECK_SEG_READ(target_seg); CHECK_SEG_READ(target_seg);
MEM_LOAD_ADDR_EA_L(target_seg); MEM_LOAD_ADDR_EA_L(target_seg);
FP_OP_S(FPU_SUB); FP_OP_S(FPU_SUB);
return op_pc + 1; return op_pc + 1;
}*/ }
#endif
static uint32_t static uint32_t
ropFADD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) ropFADD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block)
@@ -658,15 +666,16 @@ ropFCHS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb
return op_pc; return op_pc;
} }
#define opFLDimm(name, v) \ #define opFLDimm(name, v) \
static uint32_t ropFLD##name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ ropFLD##name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
static double fp_imm = v; \ { \
\ static double fp_imm = v; \
FP_ENTER(); \ \
FP_LOAD_IMM_Q(*(uint64_t *) &fp_imm); \ FP_ENTER(); \
\ FP_LOAD_IMM_Q(*(uint64_t *) &fp_imm); \
return op_pc; \ \
return op_pc; \
} }
// clang-format off // clang-format off
@@ -678,7 +687,8 @@ opFLDimm(EG2, 0.3010299956639812);
opFLDimm(Z, 0.0) opFLDimm(Z, 0.0)
// clang-format on // clang-format on
static uint32_t ropFLDLN2(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) static uint32_t
ropFLDLN2(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block))
{ {
FP_ENTER(); FP_ENTER();
FP_LOAD_IMM_Q(0x3fe62e42fefa39f0ULL); FP_LOAD_IMM_Q(0x3fe62e42fefa39f0ULL);

View File

@@ -214,42 +214,45 @@ BRANCH_COND_S(int pc_offset, uint32_t op_pc, uint32_t offset, int not )
} }
} }
#define ropBRANCH(name, func, not ) \ #define ropBRANCH(name, func, not ) \
static uint32_t rop##name(uint8_t opcode, uint32_t fetchdat, \ static uint32_t \
uint32_t op_32, uint32_t op_pc, \ rop##name(uint8_t opcode, uint32_t fetchdat, \
codeblock_t *block) \ uint32_t op_32, uint32_t op_pc, \
{ \ codeblock_t *block) \
uint32_t offset = fetchdat & 0xff; \ { \
\ uint32_t offset = fetchdat & 0xff; \
if (offset & 0x80) \ \
offset |= 0xffffff00; \ if (offset & 0x80) \
\ offset |= 0xffffff00; \
func(1, op_pc, offset, not ); \ \
\ func(1, op_pc, offset, not ); \
return op_pc + 1; \ \
} \ return op_pc + 1; \
static uint32_t rop##name##_w(uint8_t opcode, \ } \
uint32_t fetchdat, uint32_t op_32, \ static uint32_t \
uint32_t op_pc, codeblock_t *block) \ rop##name##_w(uint8_t opcode, \
{ \ uint32_t fetchdat, uint32_t op_32, \
uint32_t offset = fetchdat & 0xffff; \ uint32_t op_pc, codeblock_t *block) \
\ { \
if (offset & 0x8000) \ uint32_t offset = fetchdat & 0xffff; \
offset |= 0xffff0000; \ \
\ if (offset & 0x8000) \
func(2, op_pc, offset, not ); \ offset |= 0xffff0000; \
\ \
return op_pc + 2; \ func(2, op_pc, offset, not ); \
} \ \
static uint32_t rop##name##_l(uint8_t opcode, \ return op_pc + 2; \
uint32_t fetchdat, uint32_t op_32, \ } \
uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ rop##name##_l(uint8_t opcode, \
uint32_t offset = fastreadl(cs + op_pc); \ uint32_t fetchdat, uint32_t op_32, \
\ uint32_t op_pc, codeblock_t *block) \
func(4, op_pc, offset, not ); \ { \
\ uint32_t offset = fastreadl(cs + op_pc); \
return op_pc + 4; \ \
func(4, op_pc, offset, not ); \
\
return op_pc + 4; \
} }
// clang-format off // clang-format off

View File

@@ -1,171 +1,183 @@
#define ROP_LOGIC(name, op, writeback) \ #define ROP_LOGIC(name, op, writeback) \
static uint32_t rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int src_reg, dst_reg; \ { \
x86seg *target_seg; \ int src_reg; \
\ int dst_reg; \
if ((fetchdat & 0xc0) == 0xc0) { \ x86seg *target_seg; \
dst_reg = LOAD_REG_B(fetchdat & 7); \ \
} else { \ if ((fetchdat & 0xc0) == 0xc0) { \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ dst_reg = LOAD_REG_B(fetchdat & 7); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ } else { \
SAVE_EA(); \ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
MEM_CHECK_WRITE(target_seg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
dst_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg); \ SAVE_EA(); \
} \ MEM_CHECK_WRITE(target_seg); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN8); \ dst_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg); \
src_reg = LOAD_REG_B((fetchdat >> 3) & 7); \ } \
op##_HOST_REG_B(dst_reg, src_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN8); \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \ src_reg = LOAD_REG_B((fetchdat >> 3) & 7); \
if (writeback) { \ op##_HOST_REG_B(dst_reg, src_reg); \
if ((fetchdat & 0xc0) == 0xc0) \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \
STORE_REG_B_RELEASE(dst_reg); \ if (writeback) { \
else { \ if ((fetchdat & 0xc0) == 0xc0) \
LOAD_EA(); \ STORE_REG_B_RELEASE(dst_reg); \
MEM_STORE_ADDR_EA_B_NO_ABRT(target_seg, dst_reg); \ else { \
} \ LOAD_EA(); \
} else \ MEM_STORE_ADDR_EA_B_NO_ABRT(target_seg, dst_reg); \
RELEASE_REG(dst_reg); \ } \
RELEASE_REG(src_reg); \ } else \
\ RELEASE_REG(dst_reg); \
return op_pc + 1; \ RELEASE_REG(src_reg); \
} \ \
static uint32_t rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ return op_pc + 1; \
{ \ } \
int src_reg, dst_reg; \ static uint32_t \
x86seg *target_seg; \ rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
\ { \
if ((fetchdat & 0xc0) == 0xc0) { \ int src_reg; \
dst_reg = LOAD_REG_W(fetchdat & 7); \ int dst_reg; \
} else { \ x86seg *target_seg; \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ if ((fetchdat & 0xc0) == 0xc0) { \
SAVE_EA(); \ dst_reg = LOAD_REG_W(fetchdat & 7); \
MEM_CHECK_WRITE_W(target_seg); \ } else { \
dst_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg); \ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
} \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN16); \ SAVE_EA(); \
src_reg = LOAD_REG_W((fetchdat >> 3) & 7); \ MEM_CHECK_WRITE_W(target_seg); \
op##_HOST_REG_W(dst_reg, src_reg); \ dst_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg); \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \ } \
if (writeback) { \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN16); \
if ((fetchdat & 0xc0) == 0xc0) \ src_reg = LOAD_REG_W((fetchdat >> 3) & 7); \
STORE_REG_W_RELEASE(dst_reg); \ op##_HOST_REG_W(dst_reg, src_reg); \
else { \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \
LOAD_EA(); \ if (writeback) { \
MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, dst_reg); \ if ((fetchdat & 0xc0) == 0xc0) \
} \ STORE_REG_W_RELEASE(dst_reg); \
} else \ else { \
RELEASE_REG(dst_reg); \ LOAD_EA(); \
RELEASE_REG(src_reg); \ MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, dst_reg); \
\ } \
return op_pc + 1; \ } else \
} \ RELEASE_REG(dst_reg); \
static uint32_t rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ RELEASE_REG(src_reg); \
{ \ \
int src_reg, dst_reg; \ return op_pc + 1; \
x86seg *target_seg; \ } \
\ static uint32_t \
if ((fetchdat & 0xc0) == 0xc0) { \ rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
dst_reg = LOAD_REG_L(fetchdat & 7); \ { \
} else { \ int src_reg; \
target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ int dst_reg; \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ x86seg *target_seg; \
SAVE_EA(); \ \
MEM_CHECK_WRITE_L(target_seg); \ if ((fetchdat & 0xc0) == 0xc0) { \
dst_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg); \ dst_reg = LOAD_REG_L(fetchdat & 7); \
} \ } else { \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN32); \ target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
src_reg = LOAD_REG_L((fetchdat >> 3) & 7); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
op##_HOST_REG_L(dst_reg, src_reg); \ SAVE_EA(); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \ MEM_CHECK_WRITE_L(target_seg); \
if (writeback) { \ dst_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg); \
if ((fetchdat & 0xc0) == 0xc0) \ } \
STORE_REG_L_RELEASE(dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN32); \
else { \ src_reg = LOAD_REG_L((fetchdat >> 3) & 7); \
LOAD_EA(); \ op##_HOST_REG_L(dst_reg, src_reg); \
MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, dst_reg); \ STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \
} \ if (writeback) { \
} else \ if ((fetchdat & 0xc0) == 0xc0) \
RELEASE_REG(dst_reg); \ STORE_REG_L_RELEASE(dst_reg); \
RELEASE_REG(src_reg); \ else { \
\ LOAD_EA(); \
return op_pc + 1; \ MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, dst_reg); \
} \ } \
static uint32_t rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ } else \
{ \ RELEASE_REG(dst_reg); \
int src_reg, dst_reg; \ RELEASE_REG(src_reg); \
\ \
if ((fetchdat & 0xc0) == 0xc0) { \ return op_pc + 1; \
src_reg = LOAD_REG_B(fetchdat & 7); \ } \
} else { \ static uint32_t \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ { \
MEM_LOAD_ADDR_EA_B(target_seg); \ int src_reg; \
src_reg = 0; \ int dst_reg; \
} \ \
\ if ((fetchdat & 0xc0) == 0xc0) { \
dst_reg = LOAD_REG_B((fetchdat >> 3) & 7); \ src_reg = LOAD_REG_B(fetchdat & 7); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN8); \ } else { \
op##_HOST_REG_B(dst_reg, src_reg); \ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
if (writeback) \ MEM_LOAD_ADDR_EA_B(target_seg); \
STORE_REG_B_RELEASE(dst_reg); \ src_reg = 0; \
else \ } \
RELEASE_REG(dst_reg); \ \
RELEASE_REG(src_reg); \ dst_reg = LOAD_REG_B((fetchdat >> 3) & 7); \
\ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN8); \
return op_pc + 1; \ op##_HOST_REG_B(dst_reg, src_reg); \
} \ STORE_HOST_REG_ADDR_BL((uintptr_t) &cpu_state.flags_res, dst_reg); \
static uint32_t rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ if (writeback) \
{ \ STORE_REG_B_RELEASE(dst_reg); \
int src_reg, dst_reg; \ else \
\ RELEASE_REG(dst_reg); \
if ((fetchdat & 0xc0) == 0xc0) { \ RELEASE_REG(src_reg); \
src_reg = LOAD_REG_W(fetchdat & 7); \ \
} else { \ return op_pc + 1; \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ } \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ static uint32_t \
MEM_LOAD_ADDR_EA_W(target_seg); \ rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
src_reg = 0; \ { \
} \ int src_reg; \
\ int dst_reg; \
dst_reg = LOAD_REG_W((fetchdat >> 3) & 7); \ \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN16); \ if ((fetchdat & 0xc0) == 0xc0) { \
op##_HOST_REG_W(dst_reg, src_reg); \ src_reg = LOAD_REG_W(fetchdat & 7); \
STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \ } else { \
if (writeback) \ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
STORE_REG_W_RELEASE(dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
else \ MEM_LOAD_ADDR_EA_W(target_seg); \
RELEASE_REG(dst_reg); \ src_reg = 0; \
RELEASE_REG(src_reg); \ } \
\ \
return op_pc + 1; \ dst_reg = LOAD_REG_W((fetchdat >> 3) & 7); \
} \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN16); \
static uint32_t rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ op##_HOST_REG_W(dst_reg, src_reg); \
{ \ STORE_HOST_REG_ADDR_WL((uintptr_t) &cpu_state.flags_res, dst_reg); \
int src_reg, dst_reg; \ if (writeback) \
\ STORE_REG_W_RELEASE(dst_reg); \
if ((fetchdat & 0xc0) == 0xc0) { \ else \
src_reg = LOAD_REG_L(fetchdat & 7); \ RELEASE_REG(dst_reg); \
} else { \ RELEASE_REG(src_reg); \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ return op_pc + 1; \
MEM_LOAD_ADDR_EA_L(target_seg); \ } \
src_reg = 0; \ static uint32_t \
} \ rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
\ { \
dst_reg = LOAD_REG_L((fetchdat >> 3) & 7); \ int src_reg; \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN32); \ int dst_reg; \
op##_HOST_REG_L(dst_reg, src_reg); \ \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \ if ((fetchdat & 0xc0) == 0xc0) { \
if (writeback) \ src_reg = LOAD_REG_L(fetchdat & 7); \
STORE_REG_L_RELEASE(dst_reg); \ } else { \
else \ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
RELEASE_REG(dst_reg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
RELEASE_REG(src_reg); \ MEM_LOAD_ADDR_EA_L(target_seg); \
\ src_reg = 0; \
return op_pc + 1; \ } \
\
dst_reg = LOAD_REG_L((fetchdat >> 3) & 7); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.flags_op, FLAGS_ZN32); \
op##_HOST_REG_L(dst_reg, src_reg); \
STORE_HOST_REG_ADDR((uintptr_t) &cpu_state.flags_res, dst_reg); \
if (writeback) \
STORE_REG_L_RELEASE(dst_reg); \
else \
RELEASE_REG(dst_reg); \
RELEASE_REG(src_reg); \
\
return op_pc + 1; \
} }
ROP_LOGIC(AND, AND, 1) ROP_LOGIC(AND, AND, 1)

View File

@@ -95,33 +95,36 @@ ropMOVD_mm_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc,
return op_pc + 1; return op_pc + 1;
} }
#define MMX_OP(name, func) \ #define MMX_OP(name, func) \
static uint32_t name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int src_reg1, src_reg2; \ { \
int xmm_src, xmm_dst; \ int src_reg1; \
\ int src_reg2; \
MMX_ENTER(); \ int xmm_src; \
\ int xmm_dst; \
if ((fetchdat & 0xc0) == 0xc0) { \ \
xmm_src = LOAD_MMX_Q_MMX(fetchdat & 7); \ MMX_ENTER(); \
} else { \ \
x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ if ((fetchdat & 0xc0) == 0xc0) { \
\ xmm_src = LOAD_MMX_Q_MMX(fetchdat & 7); \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ } else { \
\ x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \
CHECK_SEG_READ(target_seg); \ \
\ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
MEM_LOAD_ADDR_EA_Q(target_seg); \ \
src_reg1 = LOAD_Q_REG_1; \ CHECK_SEG_READ(target_seg); \
src_reg2 = LOAD_Q_REG_2; \ \
xmm_src = LOAD_INT_TO_MMX(src_reg1, src_reg2); \ MEM_LOAD_ADDR_EA_Q(target_seg); \
} \ src_reg1 = LOAD_Q_REG_1; \
xmm_dst = LOAD_MMX_Q_MMX((fetchdat >> 3) & 7); \ src_reg2 = LOAD_Q_REG_2; \
func(xmm_dst, xmm_src); \ xmm_src = LOAD_INT_TO_MMX(src_reg1, src_reg2); \
STORE_MMX_Q_MMX((fetchdat >> 3) & 7, xmm_dst); \ } \
\ xmm_dst = LOAD_MMX_Q_MMX((fetchdat >> 3) & 7); \
return op_pc + 1; \ func(xmm_dst, xmm_src); \
STORE_MMX_Q_MMX((fetchdat >> 3) & 7, xmm_dst); \
\
return op_pc + 1; \
} }
MMX_OP(ropPAND, MMX_AND) MMX_OP(ropPAND, MMX_AND)

View File

@@ -224,30 +224,32 @@ ropLEAVE_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c
return op_pc; return op_pc;
} }
#define ROP_PUSH_SEG(seg) \ #define ROP_PUSH_SEG(seg) \
static uint32_t ropPUSH_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ ropPUSH_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int host_reg; \ { \
\ int host_reg; \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ \
LOAD_STACK_TO_EA(-2); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
host_reg = LOAD_VAR_W((uintptr_t) &seg); \ LOAD_STACK_TO_EA(-2); \
MEM_STORE_ADDR_EA_W(&cpu_state.seg_ss, host_reg); \ host_reg = LOAD_VAR_W((uintptr_t) &seg); \
SP_MODIFY(-2); \ MEM_STORE_ADDR_EA_W(&cpu_state.seg_ss, host_reg); \
\ SP_MODIFY(-2); \
return op_pc; \ \
} \ return op_pc; \
static uint32_t ropPUSH_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ } \
{ \ static uint32_t \
int host_reg; \ ropPUSH_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
\ { \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ int host_reg; \
LOAD_STACK_TO_EA(-4); \ \
host_reg = LOAD_VAR_W((uintptr_t) &seg); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
MEM_STORE_ADDR_EA_L(&cpu_state.seg_ss, host_reg); \ LOAD_STACK_TO_EA(-4); \
SP_MODIFY(-4); \ host_reg = LOAD_VAR_W((uintptr_t) &seg); \
\ MEM_STORE_ADDR_EA_L(&cpu_state.seg_ss, host_reg); \
return op_pc; \ SP_MODIFY(-4); \
\
return op_pc; \
} }
ROP_PUSH_SEG(CS) ROP_PUSH_SEG(CS)
@@ -257,26 +259,28 @@ ROP_PUSH_SEG(FS)
ROP_PUSH_SEG(GS) ROP_PUSH_SEG(GS)
ROP_PUSH_SEG(SS) ROP_PUSH_SEG(SS)
#define ROP_POP_SEG(seg, rseg) \ #define ROP_POP_SEG(seg, rseg) \
static uint32_t ropPOP_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ ropPOP_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ { \
LOAD_STACK_TO_EA(0); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ LOAD_STACK_TO_EA(0); \
LOAD_SEG(0, &rseg); \ MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \
SP_MODIFY(2); \ LOAD_SEG(0, &rseg); \
\ SP_MODIFY(2); \
return op_pc; \ \
} \ return op_pc; \
static uint32_t ropPOP_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ } \
{ \ static uint32_t \
STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ ropPOP_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
LOAD_STACK_TO_EA(0); \ { \
MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \
LOAD_SEG(0, &rseg); \ LOAD_STACK_TO_EA(0); \
SP_MODIFY(4); \ MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \
\ LOAD_SEG(0, &rseg); \
return op_pc; \ SP_MODIFY(4); \
\
return op_pc; \
} }
ROP_POP_SEG(DS, cpu_state.seg_ds) ROP_POP_SEG(DS, cpu_state.seg_ds)

View File

@@ -219,8 +219,9 @@ CALL_FUNC(uintptr_t func)
} }
static __inline void static __inline void
RELEASE_REG(int host_reg) RELEASE_REG(UNUSED(int host_reg))
{ {
//
} }
static __inline int static __inline int
@@ -536,7 +537,7 @@ FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc)
addlong((fetchdat >> 8) & 0xffff); addlong((fetchdat >> 8) & 0xffff);
(*op_pc) += 2; (*op_pc) += 2;
} else { } else {
int base_reg = 0; int base_reg = 0;
int index_reg = 0; int index_reg = 0;
switch (rm) { switch (rm) {
@@ -3949,7 +3950,8 @@ FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2)
static __inline int64_t static __inline int64_t
x87_fround16_64(double b) x87_fround16_64(double b)
{ {
int16_t a, c; int16_t a;
int16_t c;
switch ((cpu_state.npxc >> 10) & 3) { switch ((cpu_state.npxc >> 10) & 3) {
case 0: /*Nearest*/ case 0: /*Nearest*/
@@ -3974,7 +3976,8 @@ x87_fround16_64(double b)
static __inline int64_t static __inline int64_t
x87_fround32_64(double b) x87_fround32_64(double b)
{ {
int32_t a, c; int32_t a;
int32_t c;
switch ((cpu_state.npxc >> 10) & 3) { switch ((cpu_state.npxc >> 10) & 3) {
case 0: /*Nearest*/ case 0: /*Nearest*/
@@ -3999,7 +4002,8 @@ x87_fround32_64(double b)
static __inline int64_t static __inline int64_t
x87_fround(double b) x87_fround(double b)
{ {
int64_t a, c; int64_t a;
int64_t c;
switch ((cpu_state.npxc >> 10) & 3) { switch ((cpu_state.npxc >> 10) & 3) {
case 0: /*Nearest*/ case 0: /*Nearest*/
@@ -4550,8 +4554,9 @@ FP_COMPARE_IL(void)
} }
static __inline void static __inline void
UPDATE_NPXC(int reg) UPDATE_NPXC(UNUSED(int reg))
{ {
//
} }
static __inline void static __inline void
@@ -4775,13 +4780,14 @@ STORE_MMX_Q_MMX(int guest_reg, int host_reg)
addbyte((uint8_t) cpu_state_offset(MM[guest_reg].q)); addbyte((uint8_t) cpu_state_offset(MM[guest_reg].q));
} }
#define MMX_x86_OP(name, opcode) \ #define MMX_x86_OP(name, opcode) \
static __inline void MMX_##name(int dst_reg, int src_reg) \ static __inline void \
{ \ MMX_##name(int dst_reg, int src_reg) \
addbyte(0x66); /*op dst_reg, src_reg*/ \ { \
addbyte(0x0f); \ addbyte(0x66); /*op dst_reg, src_reg*/ \
addbyte(opcode); \ addbyte(0x0f); \
addbyte(0xc0 | (dst_reg << 3) | src_reg); \ addbyte(opcode); \
addbyte(0xc0 | (dst_reg << 3) | src_reg); \
} }
MMX_x86_OP(AND, 0xdb) MMX_x86_OP(AND, 0xdb)
@@ -5014,7 +5020,9 @@ LOAD_EA(void)
static __inline void static __inline void
MEM_CHECK_WRITE(x86seg *seg) MEM_CHECK_WRITE(x86seg *seg)
{ {
uint8_t *jump1, *jump2, *jump3 = NULL; uint8_t *jump1 = NULL;
uint8_t *jump2 = NULL;
uint8_t *jump3 = NULL;
CHECK_SEG_WRITE(seg); CHECK_SEG_WRITE(seg);
@@ -5115,7 +5123,10 @@ MEM_CHECK_WRITE(x86seg *seg)
static __inline void static __inline void
MEM_CHECK_WRITE_W(x86seg *seg) MEM_CHECK_WRITE_W(x86seg *seg)
{ {
uint8_t *jump1, *jump2, *jump3, *jump4 = NULL; uint8_t *jump1 = NULL;
uint8_t *jump2 = NULL;
uint8_t *jump3 = NULL;
uint8_t *jump4 = NULL;
int jump_pos; int jump_pos;
CHECK_SEG_WRITE(seg); CHECK_SEG_WRITE(seg);
@@ -5248,7 +5259,10 @@ MEM_CHECK_WRITE_W(x86seg *seg)
static __inline void static __inline void
MEM_CHECK_WRITE_L(x86seg *seg) MEM_CHECK_WRITE_L(x86seg *seg)
{ {
uint8_t *jump1, *jump2, *jump3, *jump4 = NULL; uint8_t *jump1 = NULL;
uint8_t *jump2 = NULL;
uint8_t *jump3 = NULL;
uint8_t *jump4 = NULL;
int jump_pos; int jump_pos;
CHECK_SEG_WRITE(seg); CHECK_SEG_WRITE(seg);

View File

@@ -3619,37 +3619,39 @@ STORE_MMX_Q_MMX(int guest_reg, int host_reg)
addbyte((uint8_t) cpu_state_offset(MM[guest_reg].q)); addbyte((uint8_t) cpu_state_offset(MM[guest_reg].q));
} }
#define MMX_x86_OP(name, opcode) \ #define MMX_x86_OP(name, opcode) \
static __inline void MMX_##name(int dst_reg, int src_reg) \ static \
{ \ __inline void MMX_##name(int dst_reg, int src_reg) \
addbyte(0x66); /*op dst_reg, src_reg*/ \ { \
addbyte(0x0f); \ addbyte(0x66); /*op dst_reg, src_reg*/ \
addbyte(opcode); \ addbyte(0x0f); \
addbyte(0xc0 | (dst_reg << 3) | src_reg); \ addbyte(opcode); \
addbyte(0xc0 | (dst_reg << 3) | src_reg); \
} }
// clang-format off
MMX_x86_OP(AND, 0xdb) MMX_x86_OP(AND, 0xdb)
MMX_x86_OP(ANDN, 0xdf) MMX_x86_OP(ANDN, 0xdf)
MMX_x86_OP(OR, 0xeb) MMX_x86_OP(OR, 0xeb)
MMX_x86_OP(XOR, 0xef) MMX_x86_OP(XOR, 0xef)
MMX_x86_OP(ADDB, 0xfc) MMX_x86_OP(ADDB, 0xfc)
MMX_x86_OP(ADDW, 0xfd) MMX_x86_OP(ADDW, 0xfd)
MMX_x86_OP(ADDD, 0xfe) MMX_x86_OP(ADDD, 0xfe)
MMX_x86_OP(ADDSB, 0xec) MMX_x86_OP(ADDSB, 0xec)
MMX_x86_OP(ADDSW, 0xed) MMX_x86_OP(ADDSW, 0xed)
MMX_x86_OP(ADDUSB, 0xdc) MMX_x86_OP(ADDUSB, 0xdc)
MMX_x86_OP(ADDUSW, 0xdd) MMX_x86_OP(ADDUSW, 0xdd)
MMX_x86_OP(SUBB, 0xf8) MMX_x86_OP(SUBB, 0xf8)
MMX_x86_OP(SUBW, 0xf9) MMX_x86_OP(SUBW, 0xf9)
MMX_x86_OP(SUBD, 0xfa) MMX_x86_OP(SUBD, 0xfa)
MMX_x86_OP(SUBSB, 0xe8) MMX_x86_OP(SUBSB, 0xe8)
MMX_x86_OP(SUBSW, 0xe9) MMX_x86_OP(SUBSW, 0xe9)
MMX_x86_OP(SUBUSB, 0xd8) MMX_x86_OP(SUBUSB, 0xd8)
MMX_x86_OP(SUBUSW, 0xd9) MMX_x86_OP(SUBUSW, 0xd9)
MMX_x86_OP(PUNPCKLBW, 0x60); MMX_x86_OP(PUNPCKLBW, 0x60);
MMX_x86_OP(PUNPCKLWD, 0x61); MMX_x86_OP(PUNPCKLWD, 0x61);
MMX_x86_OP(PUNPCKLDQ, 0x62); MMX_x86_OP(PUNPCKLDQ, 0x62);
MMX_x86_OP(PCMPGTB, 0x64); MMX_x86_OP(PCMPGTB, 0x64);
@@ -3672,6 +3674,7 @@ MMX_x86_OP(PSLLQ, 0xf3);
MMX_x86_OP(PMULLW, 0xd5); MMX_x86_OP(PMULLW, 0xd5);
MMX_x86_OP(PMULHW, 0xe5); MMX_x86_OP(PMULHW, 0xe5);
MMX_x86_OP(PMADDWD, 0xf5); MMX_x86_OP(PMADDWD, 0xf5);
// clang-format on
static __inline void static __inline void
MMX_PACKSSWB(int dst_reg, int src_reg) MMX_PACKSSWB(int dst_reg, int src_reg)

View File

@@ -1,15 +1,16 @@
#define OP_XCHG_AX_(reg) \ #define OP_XCHG_AX_(reg) \
static uint32_t ropXCHG_AX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ ropXCHG_AX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int ax_reg, host_reg, temp_reg; \ { \
\ int ax_reg, host_reg, temp_reg; \
ax_reg = LOAD_REG_W(REG_AX); \ \
host_reg = LOAD_REG_W(REG_##reg); \ ax_reg = LOAD_REG_W(REG_AX); \
temp_reg = COPY_REG(host_reg); \ host_reg = LOAD_REG_W(REG_##reg); \
STORE_REG_TARGET_W_RELEASE(ax_reg, REG_##reg); \ temp_reg = COPY_REG(host_reg); \
STORE_REG_TARGET_W_RELEASE(temp_reg, REG_AX); \ STORE_REG_TARGET_W_RELEASE(ax_reg, REG_##reg); \
\ STORE_REG_TARGET_W_RELEASE(temp_reg, REG_AX); \
return op_pc; \ \
return op_pc; \
} }
OP_XCHG_AX_(BX) OP_XCHG_AX_(BX)
@@ -20,18 +21,19 @@ OP_XCHG_AX_(DI)
OP_XCHG_AX_(SP) OP_XCHG_AX_(SP)
OP_XCHG_AX_(BP) OP_XCHG_AX_(BP)
#define OP_XCHG_EAX_(reg) \ #define OP_XCHG_EAX_(reg) \
static uint32_t ropXCHG_EAX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ static uint32_t \
{ \ ropXCHG_EAX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \
int eax_reg, host_reg, temp_reg; \ { \
\ int eax_reg, host_reg, temp_reg; \
eax_reg = LOAD_REG_L(REG_EAX); \ \
host_reg = LOAD_REG_L(REG_##reg); \ eax_reg = LOAD_REG_L(REG_EAX); \
temp_reg = COPY_REG(host_reg); \ host_reg = LOAD_REG_L(REG_##reg); \
STORE_REG_TARGET_L_RELEASE(eax_reg, REG_##reg); \ temp_reg = COPY_REG(host_reg); \
STORE_REG_TARGET_L_RELEASE(temp_reg, REG_EAX); \ STORE_REG_TARGET_L_RELEASE(eax_reg, REG_##reg); \
\ STORE_REG_TARGET_L_RELEASE(temp_reg, REG_EAX); \
return op_pc; \ \
return op_pc; \
} }
OP_XCHG_EAX_(EBX) OP_XCHG_EAX_(EBX)

View File

@@ -15,6 +15,7 @@
# include "x86seg.h" # include "x86seg.h"
# include "x87.h" # include "x87.h"
# include <86box/mem.h> # include <86box/mem.h>
# include <86box/plat_unused.h>
# include "386_common.h" # include "386_common.h"
@@ -31,7 +32,8 @@
# include <windows.h> # include <windows.h>
# endif # endif
int codegen_flat_ds, codegen_flat_ss; int codegen_flat_ds;
int codegen_flat_ss;
int codegen_flags_changed = 0; int codegen_flags_changed = 0;
int codegen_fpu_entered = 0; int codegen_fpu_entered = 0;
int codegen_fpu_loaded_iq[8]; int codegen_fpu_loaded_iq[8];
@@ -65,8 +67,6 @@ static int last_ssegs;
void void
codegen_init(void) codegen_init(void)
{ {
int c;
# if _WIN64 # if _WIN64
codeblock = VirtualAlloc(NULL, BLOCK_SIZE * sizeof(codeblock_t), MEM_COMMIT, PAGE_EXECUTE_READWRITE); codeblock = VirtualAlloc(NULL, BLOCK_SIZE * sizeof(codeblock_t), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
# elif defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__) # elif defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
@@ -79,26 +79,25 @@ codegen_init(void)
memset(codeblock, 0, BLOCK_SIZE * sizeof(codeblock_t)); memset(codeblock, 0, BLOCK_SIZE * sizeof(codeblock_t));
memset(codeblock_hash, 0, HASH_SIZE * sizeof(codeblock_t *)); memset(codeblock_hash, 0, HASH_SIZE * sizeof(codeblock_t *));
for (c = 0; c < BLOCK_SIZE; c++) for (int c = 0; c < BLOCK_SIZE; c++)
codeblock[c].valid = 0; codeblock[c].valid = 0;
} }
void void
codegen_reset(void) codegen_reset(void)
{ {
int c;
memset(codeblock, 0, BLOCK_SIZE * sizeof(codeblock_t)); memset(codeblock, 0, BLOCK_SIZE * sizeof(codeblock_t));
memset(codeblock_hash, 0, HASH_SIZE * sizeof(codeblock_t *)); memset(codeblock_hash, 0, HASH_SIZE * sizeof(codeblock_t *));
mem_reset_page_blocks(); mem_reset_page_blocks();
for (c = 0; c < BLOCK_SIZE; c++) for (int c = 0; c < BLOCK_SIZE; c++)
codeblock[c].valid = 0; codeblock[c].valid = 0;
} }
void void
dump_block(void) dump_block(void)
{ {
//
} }
static void static void
@@ -536,6 +535,7 @@ int opcode_0f_modrm[256] = {
void void
codegen_debug(void) codegen_debug(void)
{ {
//
} }
static x86seg * static x86seg *

View File

@@ -1258,7 +1258,7 @@ codegen_init(void)
# else # else
__asm __asm
{ {
fstcw cpu_state.old_npxc fstcw cpu_state.old_npxc
} }
# endif # endif
} }
@@ -1679,6 +1679,7 @@ int opcode_0f_modrm[256] = {
void void
codegen_debug(void) codegen_debug(void)
{ {
//
} }
static x86seg * static x86seg *