1
From ecfe89ee74b09369f70d9e6320bd7e7fd6f7f430 Mon Sep 17 00:00:00 2001
2
From: Alexander Graf <agraf@suse.de>
3
Date: Tue, 17 Dec 2013 19:42:33 +0000
4
Subject: [PATCH 35/49] target-arm: A64: add support for compare and branch imm
6
This patch adds emulation for the compare and branch insns,
9
Signed-off-by: Alexander Graf <agraf@suse.de>
10
[claudio: adapted to new decoder,
11
compare with immediate 0,
12
introduce read_cpu_reg to get the 0 extension on (!sf)]
13
Signed-off-by: Claudio Fontana <claudio.fontana@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Richard Henderson <rth@twiddle.net>
17
target-arm/translate-a64.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
18
1 file changed, 44 insertions(+), 2 deletions(-)
20
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
21
index 1d04303..5ae3a85 100644
22
--- a/target-arm/translate-a64.c
23
+++ b/target-arm/translate-a64.c
24
@@ -202,6 +202,25 @@ static TCGv_i64 cpu_reg(DisasContext *s, int reg)
28
+/* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
29
+ * representing the register contents. This TCGv is an auto-freed
30
+ * temporary so it need not be explicitly freed, and may be modified.
32
+static TCGv_i64 read_cpu_reg(DisasContext *s, int reg, int sf)
34
+ TCGv_i64 v = new_tmp_a64(s);
37
+ tcg_gen_mov_i64(v, cpu_X[reg]);
39
+ tcg_gen_ext32u_i64(v, cpu_X[reg]);
42
+ tcg_gen_movi_i64(v, 0);
48
* the instruction disassembly implemented here matches
49
* the instruction encoding classifications in chapter 3 (C3)
50
@@ -227,10 +246,33 @@ static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
51
gen_goto_tb(s, 0, addr);
54
-/* Compare & branch (immediate) */
55
+/* C3.2.1 Compare & branch (immediate)
56
+ * 31 30 25 24 23 5 4 0
57
+ * +----+-------------+----+---------------------+--------+
58
+ * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
59
+ * +----+-------------+----+---------------------+--------+
61
static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
63
- unsupported_encoding(s, insn);
64
+ unsigned int sf, op, rt;
69
+ sf = extract32(insn, 31, 1);
70
+ op = extract32(insn, 24, 1); /* 0: CBZ; 1: CBNZ */
71
+ rt = extract32(insn, 0, 5);
72
+ addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
74
+ tcg_cmp = read_cpu_reg(s, rt, sf);
75
+ label_match = gen_new_label();
77
+ tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
78
+ tcg_cmp, 0, label_match);
80
+ gen_goto_tb(s, 0, s->pc);
81
+ gen_set_label(label_match);
82
+ gen_goto_tb(s, 1, addr);
85
/* C3.2.5 Test & branch (immediate)