tcg/arm: Implement goto_ptr

Backports commit 085c648bef7301eabe7d4a3301c8d012ae4423b8 from qemu
This commit is contained in:
Richard Henderson 2018-03-03 14:18:40 -05:00 committed by Lioncash
parent 3b02642372
commit 1d6c4f1a42
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 22 additions and 7 deletions

View file

@ -124,7 +124,7 @@ extern bool use_idiv_instructions_rt;
#define TCG_TARGET_HAS_mulsh_i32 0 #define TCG_TARGET_HAS_mulsh_i32 0
#define TCG_TARGET_HAS_div_i32 use_idiv_instructions #define TCG_TARGET_HAS_div_i32 use_idiv_instructions
#define TCG_TARGET_HAS_rem_i32 0 #define TCG_TARGET_HAS_rem_i32 0
#define TCG_TARGET_HAS_goto_ptr 0 #define TCG_TARGET_HAS_goto_ptr 1
enum { enum {
TCG_AREG0 = TCG_REG_R6, TCG_AREG0 = TCG_REG_R6,

View file

@ -1664,8 +1664,14 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
switch (opc) { switch (opc) {
case INDEX_op_exit_tb: case INDEX_op_exit_tb:
tcg_out_movi32(s, COND_AL, TCG_REG_R0, args[0]); /* Reuse the zeroing that exists for goto_ptr. */
tcg_out_goto(s, COND_AL, tb_ret_addr); a0 = args[0];
if (a0 == 0) {
tcg_out_goto(s, COND_AL, s->code_gen_epilogue);
} else {
tcg_out_movi32(s, COND_AL, TCG_REG_R0, args[0]);
tcg_out_goto(s, COND_AL, tb_ret_addr);
}
break; break;
case INDEX_op_goto_tb: case INDEX_op_goto_tb:
if (s->tb_jmp_insn_offset) { if (s->tb_jmp_insn_offset) {
@ -1680,6 +1686,9 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
} }
s->tb_jmp_reset_offset[args[0]] = tcg_current_code_size(s); s->tb_jmp_reset_offset[args[0]] = tcg_current_code_size(s);
break; break;
case INDEX_op_goto_ptr:
tcg_out_bx(s, COND_AL, args[0]);
break;
case INDEX_op_br: case INDEX_op_br:
tcg_out_goto_label(s, COND_AL, arg_label(s, args[0])); tcg_out_goto_label(s, COND_AL, arg_label(s, args[0]));
break; break;
@ -1970,6 +1979,7 @@ static const TCGTargetOpDef arm_op_defs[] = {
{ INDEX_op_exit_tb, { } }, { INDEX_op_exit_tb, { } },
{ INDEX_op_goto_tb, { } }, { INDEX_op_goto_tb, { } },
{ INDEX_op_br, { } }, { INDEX_op_br, { } },
{ INDEX_op_goto_ptr, { "r" } },
{ INDEX_op_ld8u_i32, { "r", "r" } }, { INDEX_op_ld8u_i32, { "r", "r" } },
{ INDEX_op_ld8s_i32, { "r", "r" } }, { INDEX_op_ld8s_i32, { "r", "r" } },
@ -2145,11 +2155,16 @@ static void tcg_target_qemu_prologue(TCGContext *s)
tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]); tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
tcg_out_bx(s, COND_AL, tcg_target_call_iarg_regs[1]); tcg_out_bx(s, COND_AL, tcg_target_call_iarg_regs[1]);
tb_ret_addr = s->code_ptr;
/* Epilogue. We branch here via tb_ret_addr. */ /*
tcg_out_dat_rI(s, COND_AL, ARITH_ADD, TCG_REG_CALL_STACK, * Return path for goto_ptr. Set return value to 0, a-la exit_tb,
TCG_REG_CALL_STACK, stack_addend, 1); * and fall through to the rest of the epilogue.
*/
s->code_gen_epilogue = s->code_ptr;
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R0, 0);
/* TB epilogue */
tb_ret_addr = s->code_ptr;
/* ldmia sp!, { r4 - r11, pc } */ /* ldmia sp!, { r4 - r11, pc } */
tcg_out32(s, (COND_AL << 28) | 0x08bd8ff0); tcg_out32(s, (COND_AL << 28) | 0x08bd8ff0);