From patchwork Thu Dec 5 12:39:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22062 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB6FF24002 for ; Thu, 5 Dec 2013 12:39:51 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id id10sf36923208vcb.0 for ; Thu, 05 Dec 2013 04:39:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=elY1+XSnddGgKzR6iCKoZLlDI0PCF9rTkxeGCAgTOdo=; b=XEoVyvkfLvkhnXTRVp0JtdbF++i9IsxQ56TUy/NidRbCVDpSe/Y1obZy7yqOjby3BP yI8fltVtcgDwLXK16bvUcmAQfJCKcN1LyEqPqKpbMyjoj7JFt9pB6RwBeeMMKvSZmqIr nHsfsyascWi2+tubM/Y97hOMxmb/pBlvfEF5E6YHvtXd9GoUHVyL3IVS/0lk77xEuLTC BClb7jn7rNIIzLCMo+t5mrhf2109r1mwuiT7tBdfizfSadW+X4MopUuFoxHFhNRP/FvL wasTZ7CrriBJlqyYha3WEsWTcYrjWTjXXRQi83sj7ICf74k1A3ZR/6LpEXQp+paxbb0n xISQ== X-Gm-Message-State: ALoCoQnQmOf6/X3glaGabSAR+Hjy5ZDE5ezfTJIr5I8tbT+wbJddDG6s8+e4H5nKC+7MXP4gj4Y0 X-Received: by 10.236.203.99 with SMTP id e63mr7630238yho.0.1386247191754; Thu, 05 Dec 2013 04:39:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.81.229 with SMTP id d5ls803166qey.64.gmail; Thu, 05 Dec 2013 04:39:51 -0800 (PST) X-Received: by 10.58.50.35 with SMTP id z3mr102729ven.61.1386247191655; Thu, 05 Dec 2013 04:39:51 -0800 (PST) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id t2si34420322vem.66.2013.12.05.04.39.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 04:39:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hu19so12871768vcb.14 for ; Thu, 05 Dec 2013 04:39:51 -0800 (PST) X-Received: by 10.220.17.131 with SMTP id s3mr12933121vca.20.1386247191434; Thu, 05 Dec 2013 04:39:51 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp11821vcz; Thu, 5 Dec 2013 04:39:50 -0800 (PST) X-Received: by 10.204.122.137 with SMTP id l9mr11038992bkr.23.1386247188673; Thu, 05 Dec 2013 04:39:48 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id kh1si5137692bkb.125.2013.12.05.04.39.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Dec 2013 04:39:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VoYDV-00072V-6H; Thu, 05 Dec 2013 12:39:41 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Michael Matz , C Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v3 10/12] target-arm: A64: add support for conditional branches Date: Thu, 5 Dec 2013 12:39:38 +0000 Message-Id: <1386247180-26994-11-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1386247180-26994-1-git-send-email-peter.maydell@linaro.org> References: <1386247180-26994-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Alexander Graf This patch adds emulation for the conditional branch (b.cond) instruction. Signed-off-by: Alexander Graf [claudio: adapted to new decoder structure, reused arm infrastructure for checking the flags] Signed-off-by: Claudio Fontana Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target-arm/translate-a64.c | 29 +++++++++++++++++++++++++++-- target-arm/translate.c | 14 +++++++++----- target-arm/translate.h | 2 ++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index ce2f841..a6a1973 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -239,10 +239,35 @@ static void disas_test_b_imm(DisasContext *s, uint32_t insn) unsupported_encoding(s, insn); } -/* Conditional branch (immediate) */ +/* C3.2.2 / C5.6.19 Conditional branch (immediate) + * 31 25 24 23 5 4 3 0 + * +---------------+----+---------------------+----+------+ + * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond | + * +---------------+----+---------------------+----+------+ + */ static void disas_cond_b_imm(DisasContext *s, uint32_t insn) { - unsupported_encoding(s, insn); + unsigned int cond; + uint64_t addr; + + if ((insn & (1 << 4)) || (insn & (1 << 24))) { + unallocated_encoding(s); + return; + } + addr = s->pc + sextract32(insn, 5, 19) * 4 - 4; + cond = extract32(insn, 0, 4); + + if (cond < 0x0e) { + /* genuinely conditional branches */ + int label_match = gen_new_label(); + arm_gen_test_cc(cond, label_match); + gen_goto_tb(s, 0, s->pc); + gen_set_label(label_match); + gen_goto_tb(s, 1, addr); + } else { + /* 0xe and 0xf are both "always" conditions */ + gen_goto_tb(s, 0, addr); + } } /* C5.6.68 HINT */ diff --git a/target-arm/translate.c b/target-arm/translate.c index 553bded..9e2d1eb 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -671,7 +671,11 @@ static void gen_thumb2_parallel_addsub(int op1, int op2, TCGv_i32 a, TCGv_i32 b) } #undef PAS_OP -static void gen_test_cc(int cc, int label) +/* + * generate a conditional branch based on ARM condition code cc. + * This is common between ARM and Aarch64 targets. + */ +void arm_gen_test_cc(int cc, int label) { TCGv_i32 tmp; int inv; @@ -6903,7 +6907,7 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) /* if not always execute, we generate a conditional jump to next instruction */ s->condlabel = gen_new_label(); - gen_test_cc(cond ^ 1, s->condlabel); + arm_gen_test_cc(cond ^ 1, s->condlabel); s->condjmp = 1; } if ((insn & 0x0f900000) == 0x03000000) { @@ -8910,7 +8914,7 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw op = (insn >> 22) & 0xf; /* Generate a conditional jump to next instruction. */ s->condlabel = gen_new_label(); - gen_test_cc(op ^ 1, s->condlabel); + arm_gen_test_cc(op ^ 1, s->condlabel); s->condjmp = 1; /* offset[11:1] = insn[10:0] */ @@ -9267,7 +9271,7 @@ static void disas_thumb_insn(CPUARMState *env, DisasContext *s) cond = s->condexec_cond; if (cond != 0x0e) { /* Skip conditional when condition is AL. */ s->condlabel = gen_new_label(); - gen_test_cc(cond ^ 1, s->condlabel); + arm_gen_test_cc(cond ^ 1, s->condlabel); s->condjmp = 1; } } @@ -9940,7 +9944,7 @@ static void disas_thumb_insn(CPUARMState *env, DisasContext *s) } /* generate a conditional jump to next instruction */ s->condlabel = gen_new_label(); - gen_test_cc(cond ^ 1, s->condlabel); + arm_gen_test_cc(cond ^ 1, s->condlabel); s->condjmp = 1; /* jump to the offset */ diff --git a/target-arm/translate.h b/target-arm/translate.h index 23a45da..a6f6b3e 100644 --- a/target-arm/translate.h +++ b/target-arm/translate.h @@ -65,4 +65,6 @@ static inline void gen_a64_set_pc_im(uint64_t val) } #endif +void arm_gen_test_cc(int cc, int label); + #endif /* TARGET_ARM_TRANSLATE_H */