Added code generation for RMW versions of ADD/SUB/OR/XOR/AND
This commit is contained in:
parent
a174a88c49
commit
0985952317
8 changed files with 2126 additions and 169 deletions
|
|
@ -79,19 +79,38 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin
|
|||
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; \
|
||||
\
|
||||
if ((fetchdat & 0xc0) != 0xc0) \
|
||||
return 0; \
|
||||
\
|
||||
dst_reg = LOAD_REG_B(fetchdat & 7); \
|
||||
if ((fetchdat & 0xc0) == 0xc0) \
|
||||
{ \
|
||||
dst_reg = LOAD_REG_B(fetchdat & 7); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
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); \
|
||||
SAVE_EA(); \
|
||||
MEM_CHECK_WRITE(target_seg); \
|
||||
dst_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg); \
|
||||
} \
|
||||
STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 8); \
|
||||
src_reg = LOAD_REG_B((fetchdat >> 3) & 7); \
|
||||
STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, dst_reg); \
|
||||
STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op2, src_reg); \
|
||||
op ## _HOST_REG_B(dst_reg, src_reg); \
|
||||
STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, dst_reg); \
|
||||
if (writeback) STORE_REG_B_RELEASE(dst_reg); \
|
||||
else RELEASE_REG(dst_reg); \
|
||||
if (writeback) \
|
||||
{ \
|
||||
if ((fetchdat & 0xc0) == 0xc0) \
|
||||
STORE_REG_B_RELEASE(dst_reg); \
|
||||
else \
|
||||
{ \
|
||||
LOAD_EA(); \
|
||||
MEM_STORE_ADDR_EA_B_NO_ABRT(target_seg, dst_reg); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
RELEASE_REG(dst_reg); \
|
||||
RELEASE_REG(src_reg); \
|
||||
\
|
||||
codegen_flags_changed = 1; \
|
||||
|
|
@ -100,19 +119,38 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin
|
|||
static uint32_t rop ## name ## _w_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; \
|
||||
\
|
||||
if ((fetchdat & 0xc0) != 0xc0) \
|
||||
return 0; \
|
||||
\
|
||||
dst_reg = LOAD_REG_W(fetchdat & 7); \
|
||||
if ((fetchdat & 0xc0) == 0xc0) \
|
||||
{ \
|
||||
dst_reg = LOAD_REG_W(fetchdat & 7); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
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); \
|
||||
SAVE_EA(); \
|
||||
MEM_CHECK_WRITE_W(target_seg); \
|
||||
dst_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg); \
|
||||
} \
|
||||
STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 16); \
|
||||
src_reg = LOAD_REG_W((fetchdat >> 3) & 7); \
|
||||
STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, dst_reg); \
|
||||
STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op2, src_reg); \
|
||||
op ## _HOST_REG_W(dst_reg, src_reg); \
|
||||
STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, dst_reg); \
|
||||
if (writeback) STORE_REG_W_RELEASE(dst_reg); \
|
||||
else RELEASE_REG(dst_reg); \
|
||||
if (writeback) \
|
||||
{ \
|
||||
if ((fetchdat & 0xc0) == 0xc0) \
|
||||
STORE_REG_W_RELEASE(dst_reg); \
|
||||
else \
|
||||
{ \
|
||||
LOAD_EA(); \
|
||||
MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, dst_reg); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
RELEASE_REG(dst_reg); \
|
||||
RELEASE_REG(src_reg); \
|
||||
\
|
||||
codegen_flags_changed = 1; \
|
||||
|
|
@ -121,19 +159,38 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin
|
|||
static uint32_t rop ## name ## _l_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; \
|
||||
\
|
||||
if ((fetchdat & 0xc0) != 0xc0) \
|
||||
return 0; \
|
||||
\
|
||||
dst_reg = LOAD_REG_L(fetchdat & 7); \
|
||||
if ((fetchdat & 0xc0) == 0xc0) \
|
||||
{ \
|
||||
dst_reg = LOAD_REG_L(fetchdat & 7); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
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); \
|
||||
SAVE_EA(); \
|
||||
MEM_CHECK_WRITE_L(target_seg); \
|
||||
dst_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg); \
|
||||
} \
|
||||
STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 32); \
|
||||
src_reg = LOAD_REG_L((fetchdat >> 3) & 7); \
|
||||
STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, dst_reg); \
|
||||
STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op2, src_reg); \
|
||||
op ## _HOST_REG_L(dst_reg, src_reg); \
|
||||
STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, dst_reg); \
|
||||
if (writeback) STORE_REG_L_RELEASE(dst_reg); \
|
||||
else RELEASE_REG(dst_reg); \
|
||||
if (writeback) \
|
||||
{ \
|
||||
if ((fetchdat & 0xc0) == 0xc0) \
|
||||
STORE_REG_L_RELEASE(dst_reg); \
|
||||
else \
|
||||
{ \
|
||||
LOAD_EA(); \
|
||||
MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, dst_reg); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
RELEASE_REG(dst_reg); \
|
||||
RELEASE_REG(src_reg); \
|
||||
\
|
||||
codegen_flags_changed = 1; \
|
||||
|
|
@ -541,12 +598,33 @@ static uint32_t rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_
|
|||
{
|
||||
int host_reg;
|
||||
uint32_t imm;
|
||||
x86seg *target_seg;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10 || (fetchdat & 0xc0) != 0xc0)
|
||||
if ((fetchdat & 0x30) == 0x10)
|
||||
return 0;
|
||||
|
||||
host_reg = LOAD_REG_B(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xff;
|
||||
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
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 & 0x38) == 0x38)
|
||||
{
|
||||
MEM_LOAD_ADDR_EA_B(target_seg);
|
||||
host_reg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAVE_EA();
|
||||
MEM_CHECK_WRITE(target_seg);
|
||||
host_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg);
|
||||
}
|
||||
imm = fastreadb(cs + op_pc + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
host_reg = LOAD_REG_B(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xff;
|
||||
}
|
||||
|
||||
switch (fetchdat & 0x38)
|
||||
{
|
||||
|
|
@ -584,7 +662,17 @@ static uint32_t rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_
|
|||
|
||||
STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg);
|
||||
if ((fetchdat & 0x38) != 0x38)
|
||||
STORE_REG_B_RELEASE(host_reg);
|
||||
{
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
LOAD_EA();
|
||||
MEM_STORE_ADDR_EA_B_NO_ABRT(target_seg, host_reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
STORE_REG_B_RELEASE(host_reg);
|
||||
}
|
||||
}
|
||||
else
|
||||
RELEASE_REG(host_reg);
|
||||
|
||||
|
|
@ -596,12 +684,33 @@ static uint32_t rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
{
|
||||
int host_reg;
|
||||
uint32_t imm;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10 || (fetchdat & 0xc0) != 0xc0)
|
||||
x86seg *target_seg;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10)
|
||||
return 0;
|
||||
|
||||
host_reg = LOAD_REG_W(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xffff;
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
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 & 0x38) == 0x38)
|
||||
{
|
||||
MEM_LOAD_ADDR_EA_W(target_seg);
|
||||
host_reg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAVE_EA();
|
||||
MEM_CHECK_WRITE_W(target_seg);
|
||||
host_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg);
|
||||
}
|
||||
imm = fastreadw(cs + op_pc + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
host_reg = LOAD_REG_W(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xffff;
|
||||
}
|
||||
|
||||
switch (fetchdat & 0x38)
|
||||
{
|
||||
|
|
@ -639,7 +748,17 @@ static uint32_t rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
|
||||
STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg);
|
||||
if ((fetchdat & 0x38) != 0x38)
|
||||
STORE_REG_W_RELEASE(host_reg);
|
||||
{
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
LOAD_EA();
|
||||
MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, host_reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
STORE_REG_W_RELEASE(host_reg);
|
||||
}
|
||||
}
|
||||
else
|
||||
RELEASE_REG(host_reg);
|
||||
|
||||
|
|
@ -650,13 +769,32 @@ static uint32_t rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
{
|
||||
int host_reg;
|
||||
uint32_t imm;
|
||||
x86seg *target_seg;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10 || (fetchdat & 0xc0) != 0xc0)
|
||||
if ((fetchdat & 0x30) == 0x10)
|
||||
return 0;
|
||||
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
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 & 0x38) == 0x38)
|
||||
{
|
||||
MEM_LOAD_ADDR_EA_L(target_seg);
|
||||
host_reg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAVE_EA();
|
||||
MEM_CHECK_WRITE(target_seg);
|
||||
host_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
host_reg = LOAD_REG_L(fetchdat & 7);
|
||||
}
|
||||
imm = fastreadl(cs + op_pc + 1);
|
||||
|
||||
host_reg = LOAD_REG_L(fetchdat & 7);
|
||||
|
||||
switch (fetchdat & 0x38)
|
||||
{
|
||||
|
|
@ -694,7 +832,17 @@ static uint32_t rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
|
||||
STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg);
|
||||
if ((fetchdat & 0x38) != 0x38)
|
||||
STORE_REG_L_RELEASE(host_reg);
|
||||
{
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
LOAD_EA();
|
||||
MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, host_reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
STORE_REG_L_RELEASE(host_reg);
|
||||
}
|
||||
}
|
||||
else
|
||||
RELEASE_REG(host_reg);
|
||||
|
||||
|
|
@ -706,12 +854,34 @@ static uint32_t rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
{
|
||||
int host_reg;
|
||||
uint32_t imm;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10 || (fetchdat & 0xc0) != 0xc0)
|
||||
x86seg *target_seg;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10)
|
||||
return 0;
|
||||
|
||||
host_reg = LOAD_REG_W(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xff;
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
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 & 0x38) == 0x38)
|
||||
{
|
||||
MEM_LOAD_ADDR_EA_W(target_seg);
|
||||
host_reg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAVE_EA();
|
||||
MEM_CHECK_WRITE_W(target_seg);
|
||||
host_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg);
|
||||
}
|
||||
imm = fastreadb(cs + op_pc + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
host_reg = LOAD_REG_W(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xff;
|
||||
}
|
||||
|
||||
if (imm & 0x80)
|
||||
imm |= 0xff80;
|
||||
|
||||
|
|
@ -751,7 +921,17 @@ static uint32_t rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
|
||||
STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg);
|
||||
if ((fetchdat & 0x38) != 0x38)
|
||||
STORE_REG_W_RELEASE(host_reg);
|
||||
{
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
LOAD_EA();
|
||||
MEM_STORE_ADDR_EA_W_NO_ABRT(target_seg, host_reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
STORE_REG_W_RELEASE(host_reg);
|
||||
}
|
||||
}
|
||||
else
|
||||
RELEASE_REG(host_reg);
|
||||
|
||||
|
|
@ -762,12 +942,34 @@ static uint32_t rop83_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
{
|
||||
int host_reg;
|
||||
uint32_t imm;
|
||||
x86seg *target_seg;
|
||||
|
||||
if ((fetchdat & 0x30) == 0x10 || (fetchdat & 0xc0) != 0xc0)
|
||||
if ((fetchdat & 0x30) == 0x10)
|
||||
return 0;
|
||||
|
||||
host_reg = LOAD_REG_L(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xff;
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
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 & 0x38) == 0x38)
|
||||
{
|
||||
MEM_LOAD_ADDR_EA_L(target_seg);
|
||||
host_reg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAVE_EA();
|
||||
MEM_CHECK_WRITE_L(target_seg);
|
||||
host_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg);
|
||||
}
|
||||
imm = fastreadb(cs + op_pc + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
host_reg = LOAD_REG_L(fetchdat & 7);
|
||||
imm = (fetchdat >> 8) & 0xff;
|
||||
}
|
||||
|
||||
if (imm & 0x80)
|
||||
imm |= 0xffffff80;
|
||||
|
||||
|
|
@ -807,10 +1009,20 @@ static uint32_t rop83_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3
|
|||
|
||||
STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg);
|
||||
if ((fetchdat & 0x38) != 0x38)
|
||||
STORE_REG_L_RELEASE(host_reg);
|
||||
{
|
||||
if ((fetchdat & 0xc0) != 0xc0)
|
||||
{
|
||||
LOAD_EA();
|
||||
MEM_STORE_ADDR_EA_L_NO_ABRT(target_seg, host_reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
STORE_REG_L_RELEASE(host_reg);
|
||||
}
|
||||
}
|
||||
else
|
||||
RELEASE_REG(host_reg);
|
||||
|
||||
|
||||
codegen_flags_changed = 1;
|
||||
return op_pc + 2;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue