[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 34/60] AArch64: Add b.cond instruction emulation
From: |
Alexander Graf |
Subject: |
[Qemu-devel] [PATCH 34/60] AArch64: Add b.cond instruction emulation |
Date: |
Fri, 27 Sep 2013 02:48:28 +0200 |
This patch adds emulation for the conditional branch (b.cond) instruction.
Signed-off-by: Alexander Graf <address@hidden>
---
target-arm/helper-a64.c | 41 +++++++++++++++++++++++++++++++++++++++++
target-arm/helper-a64.h | 1 +
target-arm/translate-a64.c | 28 ++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
diff --git a/target-arm/helper-a64.c b/target-arm/helper-a64.c
index bc575a2..9aaf181 100644
--- a/target-arm/helper-a64.c
+++ b/target-arm/helper-a64.c
@@ -146,3 +146,44 @@ uint64_t HELPER(sign_extend)(uint64_t x, uint64_t
is_signed, uint64_t mask)
return x;
}
+
+uint32_t HELPER(cond)(uint32_t pstate, uint32_t cond)
+{
+ uint32_t r;
+
+ switch (cond >> 1) {
+ case 0:
+ r = pstate & PSTATE_Z;
+ break;
+ case 1:
+ r = pstate & PSTATE_C;
+ break;
+ case 2:
+ r = pstate & PSTATE_N;
+ break;
+ case 3:
+ r = pstate & PSTATE_V;
+ break;
+ case 4:
+ r = (pstate & PSTATE_C) && !(pstate & PSTATE_Z);
+ break;
+ case 5:
+ r = (((pstate & PSTATE_N) ? 1 : 0) == ((pstate & PSTATE_V) ? 1 : 0));
+ break;
+ case 6:
+ r = (((pstate & PSTATE_N) ? 1 : 0) == ((pstate & PSTATE_V) ? 1 : 0))
+ && !(pstate & PSTATE_Z);
+ break;
+ case 7:
+ default:
+ /* ALWAYS */
+ r = 1;
+ break;
+ }
+
+ if ((cond & 1) && (cond != 0xf)) {
+ r = !r;
+ }
+
+ return !!r;
+}
diff --git a/target-arm/helper-a64.h b/target-arm/helper-a64.h
index 7c5cdc6..99f4be7 100644
--- a/target-arm/helper-a64.h
+++ b/target-arm/helper-a64.h
@@ -22,3 +22,4 @@ DEF_HELPER_FLAGS_4(pstate_add32, TCG_CALL_NO_RWG_SE, i32,
i32, i64, i64, i64)
DEF_HELPER_FLAGS_4(pstate_sub, TCG_CALL_NO_RWG_SE, i32, i32, i64, i64, i64)
DEF_HELPER_FLAGS_4(pstate_sub32, TCG_CALL_NO_RWG_SE, i32, i32, i64, i64, i64)
DEF_HELPER_FLAGS_3(sign_extend, TCG_CALL_NO_RWG_SE, i64, i64, i64, i64)
+DEF_HELPER_FLAGS_2(cond, TCG_CALL_NO_RWG_SE, i32, i32, i32)
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index 229b467..d5cc199 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -268,6 +268,32 @@ static void handle_cb(DisasContext *s, uint32_t insn)
tcg_temp_free_i64(tcg_zero);
}
+static void handle_condb(DisasContext *s, uint32_t insn)
+{
+ uint64_t addr = s->pc - 4 + (get_sbits(insn, 5, 19) << 2);
+ int cond = get_bits(insn, 0, 4);
+ int no_match;
+ TCGv_i32 tcg_zero = tcg_const_i32(0);
+ TCGv_i32 tcg_cond = tcg_const_i32(cond);
+ TCGv_i32 tcg_condmatch = tcg_temp_new_i32();
+
+ no_match = gen_new_label();
+
+ gen_helper_cond(tcg_condmatch, pstate, tcg_cond);
+ tcg_gen_brcond_i32(TCG_COND_EQ, tcg_condmatch, tcg_zero, no_match);
+
+ gen_goto_tb(s, 0, addr);
+
+ gen_set_label(no_match);
+ gen_goto_tb(s, 1, s->pc);
+
+ tcg_temp_free_i32(tcg_zero);
+ tcg_temp_free_i32(tcg_cond);
+ tcg_temp_free_i32(tcg_condmatch);
+
+ s->is_jmp = DISAS_TB_JUMP;
+}
+
static void ldst_do_vec_int(DisasContext *s, int freg_offs, TCGv_i64 tcg_addr,
int size, bool is_store)
{
@@ -1743,6 +1769,8 @@ void disas_a64_insn(CPUARMState *env, DisasContext *s)
handle_svc(s, insn);
} else if (get_bits(insn, 29, 2) == 0x1) {
handle_cb(s, insn);
+ } else if (get_bits(insn, 29, 3) == 0x2) {
+ handle_condb(s, insn);
} else {
unallocated_encoding(s);
}
--
1.7.12.4
- [Qemu-devel] [PATCH 31/60] AArch64: Add bfm family instruction emulation, (continued)
- [Qemu-devel] [PATCH 31/60] AArch64: Add bfm family instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 32/60] AArch64: Add svc instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 35/60] AArch64: Add mrs instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 33/60] AArch64: Add bc instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 38/60] AArch64: Add stub barrier instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 21/60] AArch64: Convert SIMD load/store to common function, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 36/60] AArch64: Add msr instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 37/60] AArch64: Add hint instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 39/60] AArch64: Add stub sys instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 34/60] AArch64: Add b.cond instruction emulation,
Alexander Graf <=
- [Qemu-devel] [PATCH 43/60] AArch64: Add cinc instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 45/60] AArch64: Add shift instruction family emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 47/60] AArch64: Add clz instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 40/60] AArch64: Add tbz instruction emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 46/60] AArch64: Add rev instruction family emulation, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 48/60] AArch64: Add 0x1a encoding of add instructions, Alexander Graf, 2013/09/26
- [Qemu-devel] [PATCH 44/60] AArch64: Add division instruction family emulation, Alexander Graf, 2013/09/26