target/arm: Convert Table Branch

Backports commit 808092bbe356eef0897476be50193d0778596877 from qemu
This commit is contained in:
Richard Henderson 2019-11-20 11:48:02 -05:00 committed by Lioncash
parent e6b4480ca9
commit 0afb6ab7af
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 42 additions and 24 deletions

View file

@ -489,7 +489,7 @@ LDRD_ri_t32 1110 1001 .101 .... .... .... ........ @ldstd_ri8 w=0 p=1
STRD_ri_t32 1110 1001 .110 .... .... .... ........ @ldstd_ri8 w=1 p=1
LDRD_ri_t32 1110 1001 .111 .... .... .... ........ @ldstd_ri8 w=1 p=1
# Load/Store Exclusive and Load-Acquire/Store-Release
# Load/Store Exclusive, Load-Acquire/Store-Release, and Table Branch
@strex_i .... .... .... rn:4 rt:4 rd:4 .... .... \
&strex rt2=15 imm=%imm8x4
@ -533,6 +533,12 @@ LDA 1110 1000 1101 .... .... 1111 1010 1111 @ldrex_0
LDAB 1110 1000 1101 .... .... 1111 1000 1111 @ldrex_0
LDAH 1110 1000 1101 .... .... 1111 1001 1111 @ldrex_0
&tbranch rn rm
@tbranch .... .... .... rn:4 .... .... .... rm:4 &tbranch
TBB 1110 1000 1101 .... 1111 0000 0000 .... @tbranch
TBH 1110 1000 1101 .... 1111 0000 0001 .... @tbranch
# Parallel addition and subtraction
SADD8 1111 1010 1000 .... 1111 .... 0000 .... @rndm

View file

@ -10417,6 +10417,38 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a)
return true;
}
static bool op_tbranch(DisasContext *s, arg_tbranch *a, bool half)
{
TCGContext *tcg_ctx = s->uc->tcg_ctx;
TCGv_i32 addr, tmp;
tmp = load_reg(s, a->rm);
if (half) {
tcg_gen_add_i32(tcg_ctx, tmp, tmp, tmp);
}
addr = load_reg(s, a->rn);
tcg_gen_add_i32(tcg_ctx, addr, addr, tmp);
gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s),
half ? MO_UW | s->be_data : MO_UB);
tcg_temp_free_i32(tcg_ctx, addr);
tcg_gen_add_i32(tcg_ctx, tmp, tmp, tmp);
tcg_gen_addi_i32(tcg_ctx, tmp, tmp, read_pc(s));
store_reg(s, 15, tmp);
return true;
}
static bool trans_TBB(DisasContext *s, arg_tbranch *a)
{
return op_tbranch(s, a, false);
}
static bool trans_TBH(DisasContext *s, arg_tbranch *a)
{
return op_tbranch(s, a, true);
}
/*
* Supervisor call
*/
@ -10818,9 +10850,7 @@ static bool thumb_insn_is_16bit(DisasContext *s, uint32_t pc, uint32_t insn)
static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
{
TCGContext *tcg_ctx = s->uc->tcg_ctx;
uint32_t rd, rn, rm, rs;
TCGv_i32 tmp;
TCGv_i32 addr;
uint32_t rd, rn, rs;
int op;
/*
@ -10866,7 +10896,6 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
rn = (insn >> 16) & 0xf;
rs = (insn >> 12) & 0xf;
rd = (insn >> 8) & 0xf;
rm = insn & 0xf;
switch ((insn >> 25) & 0xf) {
case 0: case 1: case 2: case 3:
/* 16-bit instructions. Should never happen. */
@ -10939,25 +10968,8 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
/* Load/store exclusive, in decodetree */
goto illegal_op;
} else if ((insn & (7 << 5)) == 0) {
/* Table Branch. */
addr = load_reg(s, rn);
tmp = load_reg(s, rm);
tcg_gen_add_i32(tcg_ctx, addr, addr, tmp);
if (insn & (1 << 4)) {
/* tbh */
tcg_gen_add_i32(tcg_ctx, addr, addr, tmp);
tcg_temp_free_i32(tcg_ctx, tmp);
tmp = tcg_temp_new_i32(tcg_ctx);
gen_aa32_ld16u(s, tmp, addr, get_mem_index(s));
} else { /* tbb */
tcg_temp_free_i32(tcg_ctx, tmp);
tmp = tcg_temp_new_i32(tcg_ctx);
gen_aa32_ld8u(s, tmp, addr, get_mem_index(s));
}
tcg_temp_free_i32(tcg_ctx, addr);
tcg_gen_shli_i32(tcg_ctx, tmp, tmp, 1);
tcg_gen_addi_i32(tcg_ctx, tmp, tmp, read_pc(s));
store_reg(s, 15, tmp);
/* Table Branch, in decodetree */
goto illegal_op;
} else {
/* Load/store exclusive, load-acq/store-rel, in decodetree */
goto illegal_op;