32x: drc: inline dispatcher and irq handling; do write-caused irqs

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@849 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-12-29 22:43:10 +00:00
parent efd100fc0a
commit e05b81fc5b
10 changed files with 535 additions and 246 deletions

View file

@ -155,6 +155,10 @@
#define EOP_C_AM2_IMM(cond,u,b,l,rn,rd,offset_12) \
EMIT(((cond)<<28) | 0x05000000 | ((u)<<23) | ((b)<<22) | ((l)<<20) | ((rn)<<16) | ((rd)<<12) | (offset_12))
#define EOP_C_AM2_REG(cond,u,b,l,rn,rd,shift_imm,shift_op,rm) \
EMIT(((cond)<<28) | 0x07000000 | ((u)<<23) | ((b)<<22) | ((l)<<20) | ((rn)<<16) | ((rd)<<12) | \
((shift_imm)<<7) | ((shift_op)<<5) | (rm))
/* addressing mode 3 */
#define EOP_C_AM3(cond,u,r,l,rn,rd,s,h,immed_reg) \
EMIT(((cond)<<28) | 0x01000090 | ((u)<<23) | ((r)<<22) | ((l)<<20) | ((rn)<<16) | ((rd)<<12) | \
@ -165,12 +169,16 @@
#define EOP_C_AM3_REG(cond,u,l,rn,rd,s,h,rm) EOP_C_AM3(cond,u,0,l,rn,rd,s,h,rm)
/* ldr and str */
#define EOP_LDR_IMM2(cond,rd,rn,offset_12) EOP_C_AM2_IMM(cond,1,0,1,rn,rd,offset_12)
#define EOP_LDR_IMM( rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,1,0,1,rn,rd,offset_12)
#define EOP_LDR_NEGIMM(rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,0,0,1,rn,rd,offset_12)
#define EOP_LDR_SIMPLE(rd,rn) EOP_C_AM2_IMM(A_COND_AL,1,0,1,rn,rd,0)
#define EOP_STR_IMM( rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,1,0,0,rn,rd,offset_12)
#define EOP_STR_SIMPLE(rd,rn) EOP_C_AM2_IMM(A_COND_AL,1,0,0,rn,rd,0)
#define EOP_LDR_REG_LSL(cond,rd,rn,rm,shift_imm) EOP_C_AM2_REG(cond,1,0,1,rn,rd,shift_imm,A_AM1_LSL,rm)
#define EOP_LDRH_IMM( rd,rn,offset_8) EOP_C_AM3_IMM(A_COND_AL,1,1,rn,rd,0,1,offset_8)
#define EOP_LDRH_SIMPLE(rd,rn) EOP_C_AM3_IMM(A_COND_AL,1,1,rn,rd,0,1,0)
#define EOP_LDRH_REG( rd,rn,rm) EOP_C_AM3_REG(A_COND_AL,1,1,rn,rd,0,1,rm)
@ -192,8 +200,6 @@
#define EOP_C_BX(cond,rm) \
EMIT(((cond)<<28) | 0x012fff10 | (rm))
#define EOP_BX(rm) EOP_C_BX(A_COND_AL,rm)
#define EOP_C_B_PTR(ptr,cond,l,signed_immed_24) \
EMIT_PTR(ptr, ((cond)<<28) | 0x0a000000 | ((l)<<24) | (signed_immed_24))
@ -232,6 +238,7 @@
#define EOP_MSR_REG(rm) EOP_C_MSR_REG(A_COND_AL,rm)
// XXX: AND, RSB, *C, MVN will break if 1 insn is not enough
static void emith_op_imm2(int cond, int s, int op, int rd, int rn, unsigned int imm)
{
int ror2;
@ -253,10 +260,9 @@ static void emith_op_imm2(int cond, int s, int op, int rd, int rn, unsigned int
EOP_C_DOP_IMM(cond, op, s, rn, rd, ror2 & 0x0f, v & 0xff);
if (op == A_OP_MOV) {
if (op == A_OP_MOV)
op = A_OP_ORR;
rn = rd;
}
rn = rd;
}
}
@ -461,6 +467,12 @@ static int emith_xbranch(int cond, void *target, int is_call)
#define emith_and_r_r_imm(d, s, imm) \
emith_op_imm2(A_COND_AL, 0, A_OP_AND, d, s, imm)
#define emith_add_r_r_imm(d, s, imm) \
emith_op_imm2(A_COND_AL, 0, A_OP_ADD, d, s, imm)
#define emith_sub_r_r_imm(d, s, imm) \
emith_op_imm2(A_COND_AL, 0, A_OP_SUB, d, s, imm)
#define emith_neg_r_r(d, s) \
EOP_RSB_IMM(d, s, 0, 0)
@ -583,18 +595,12 @@ static int emith_xbranch(int cond, void *target, int is_call)
#define emith_pass_arg_imm(arg, imm) \
emith_move_r_imm(arg, imm)
#define emith_call_cond(cond, target) \
emith_xbranch(cond, target, 1)
#define emith_jump(target) \
emith_jump_cond(A_COND_AL, target)
#define emith_jump_cond(cond, target) \
emith_xbranch(cond, target, 0)
#define emith_call(target) \
emith_call_cond(A_COND_AL, target)
#define emith_jump(target) \
emith_jump_cond(A_COND_AL, target)
#define emith_jump_patchable(cond) \
emith_jump_cond(cond, 0)
@ -604,8 +610,37 @@ static int emith_xbranch(int cond, void *target, int is_call)
*ptr_ = (*ptr_ & 0xff000000) | (val & 0x00ffffff); \
} while (0)
#define emith_jump_reg_c(cond, r) \
EOP_C_BX(cond, r)
#define emith_jump_reg(r) \
EOP_BX(r)
emith_jump_reg_c(A_COND_AL, r)
#define emith_jump_ctx_c(cond, offs) \
EOP_LDR_IMM2(cond,15,CONTEXT_REG,offs)
#define emith_jump_ctx(offs) \
emith_jump_ctx_c(A_COND_AL, offs)
#define emith_call_cond(cond, target) \
emith_xbranch(cond, target, 1)
#define emith_call(target) \
emith_call_cond(A_COND_AL, target)
#define emith_call_ctx(offs) { \
emith_move_r_r(14, 15); \
emith_jump_ctx(offs); \
}
#define emith_ret_c(cond) \
emith_jump_reg_c(cond, 14)
#define emith_ret() \
emith_ret_c(A_COND_AL)
#define emith_ret_to_ctx(offs) \
emith_ctx_write(14, offs)
/* SH2 drc specific */
#define emith_sh2_drc_entry() \
@ -614,6 +649,18 @@ static int emith_xbranch(int cond, void *target, int is_call)
#define emith_sh2_drc_exit() \
EOP_LDMFD_SP(A_R4M|A_R5M|A_R6M|A_R7M|A_R8M|A_R9M|A_R10M|A_R11M|A_R15M)
#define emith_sh2_wcall(a, tab, ret_ptr) { \
int val_ = (char *)(ret_ptr) - (char *)tcache_ptr - 2*4; \
if (val_ >= 0) \
emith_add_r_r_imm(14, 15, val_); \
else if (val_ < 0) \
emith_sub_r_r_imm(14, 15, -val_); \
emith_lsr(12, a, SH2_WRITE_SHIFT); \
EOP_LDR_REG_LSL(A_COND_AL,12,tab,12,2); \
emith_ctx_read(2, offsetof(SH2, is_slave)); \
emith_jump_reg(12); \
}
#define emith_sh2_dtbf_loop() { \
int cr, rn; \
int tmp_ = rcache_get_tmp(); \

View file

@ -239,7 +239,17 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
emith_bic_r_imm(r, imm); \
}
#define emith_jump_reg_c(cond, r) emith_jump_reg(r)
#define emith_jump_ctx_c(cond, offs) emith_jump_ctx(offs)
#define emith_ret_c(cond) emith_ret()
// _r_r_imm
#define emith_add_r_r_imm(d, s, imm) { \
if (d != s) \
emith_move_r_r(d, s); \
emith_add_r_imm(d, imm); \
}
#define emith_and_r_r_imm(d, s, imm) { \
if (d != s) \
emith_move_r_r(d, s); \
@ -279,6 +289,11 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
#define emith_push(r) \
EMIT_OP(0x50 + (r))
#define emith_push_imm(imm) { \
EMIT_OP(0x68); \
EMIT(imm, u32); \
}
#define emith_pop(r) \
EMIT_OP(0x58 + (r))
@ -376,29 +391,41 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
#define emith_rolcf emith_rolc
#define emith_rorcf emith_rorc
// XXX: offs is 8bit only
#define emith_ctx_read(r, offs) do { \
EMIT_OP_MODRM(0x8b, 1, r, xBP); \
EMIT(offs, u8); /* mov tmp, [ebp+#offs] */ \
#define emith_ctx_op(op, r, offs) do { \
/* mov r <-> [ebp+#offs] */ \
if ((offs) >= 0x80) { \
EMIT_OP_MODRM(op, 2, r, xBP); \
EMIT(offs, u32); \
} else { \
EMIT_OP_MODRM(op, 1, r, xBP); \
EMIT(offs, u8); \
} \
} while (0)
#define emith_ctx_read(r, offs) \
emith_ctx_op(0x8b, r, offs)
#define emith_ctx_write(r, offs) \
emith_ctx_op(0x89, r, offs)
#define emith_ctx_read_multiple(r, offs, cnt, tmpr) do { \
int r_ = r, offs_ = offs, cnt_ = cnt; \
for (; cnt_ > 0; r_++, offs_ += 4, cnt_--) \
emith_ctx_read(r_, offs_); \
} while (0)
#define emith_ctx_write(r, offs) do { \
EMIT_OP_MODRM(0x89, 1, r, xBP); \
EMIT(offs, u8); /* mov [ebp+#offs], tmp */ \
} while (0)
#define emith_ctx_write_multiple(r, offs, cnt, tmpr) do { \
int r_ = r, offs_ = offs, cnt_ = cnt; \
for (; cnt_ > 0; r_++, offs_ += 4, cnt_--) \
emith_ctx_write(r_, offs_); \
} while (0)
// assumes EBX is free
#define emith_ret_to_ctx(offs) { \
emith_pop(xBX); \
emith_ctx_write(xBX, offs); \
}
#define emith_jump(ptr) { \
u32 disp = (u32)(ptr) - ((u32)tcache_ptr + 5); \
EMIT_OP(0xe9); \
@ -429,9 +456,25 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
#define emith_call_cond(cond, ptr) \
emith_call(ptr)
#define emith_call_reg(r) \
EMIT_OP_MODRM(0xff, 3, 2, r)
#define emith_call_ctx(offs) { \
EMIT_OP_MODRM(0xff, 2, 2, xBP); \
EMIT(offs, u32); \
}
#define emith_ret() \
EMIT_OP(0xc3)
#define emith_jump_reg(r) \
EMIT_OP_MODRM(0xff, 3, 4, r)
#define emith_jump_ctx(offs) { \
EMIT_OP_MODRM(0xff, 2, 4, xBP); \
EMIT(offs, u32); \
}
#define EMITH_JMP_START(cond) { \
u8 *cond_ptr; \
JMP8_POS(cond_ptr)
@ -476,7 +519,19 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
emith_pop(xSI); \
emith_pop(xBP); \
emith_pop(xBX); \
EMIT_OP(0xc3); /* ret */\
emith_ret(); \
}
// assumes EBX is free temporary
#define emith_sh2_wcall(a, tab, ret_ptr) { \
int arg2_; \
host_arg2reg(arg2_, 2); \
emith_lsr(xBX, a, SH2_WRITE_SHIFT); \
EMIT_OP_MODRM(0x8b, 0, xBX, 4); \
EMIT_SIB(2, xBX, tab); /* mov ebx, [tab + ebx * 4] */ \
emith_ctx_read(arg2_, offsetof(SH2, is_slave)); \
emith_push_imm((long)(ret_ptr)); \
emith_jump_reg(xBX); \
}
#define emith_sh2_dtbf_loop() { \