From patchwork Thu Dec 5 12:39:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22064 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 691C123FBA for ; Thu, 5 Dec 2013 12:40:00 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id g10sf47753783pdj.9 for ; Thu, 05 Dec 2013 04:39:59 -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=5llSzvSL8Q2baz/RDJfmKtzbztSrIhTAQiocGS4SmRY=; b=KouNUMKnG1RL5VwUnm1jyMzFSvraDk8cGlDrzBXeuTDe1rSeQ+OVdVIIfQ6e6DqD2F Msjb2g2ioKFwpYLSH9H6dHYRB9juhcUc3AYH0EKfKR7b2o0bRPoYgL0WHb/0tCiW2E3+ ldu013mGdS+mHca6n/SWLnJf4PGLxLw7DSH6nchZWBNMzLVQEyEPv0P56E6hvT2WbeY8 EUE+vRTt5GvoIVSLfWNs/QhkHmltXCKAxlDN6cZI4r8Kgn5AqGJCocEYO71+aEYDq/7F 3fOnkKQGSSe924PuSRtZDJOYlvDLO+a8uIQTjIVgnaKlu5KIkwquRVE7twL0bVxDO0DV Svcg== X-Gm-Message-State: ALoCoQnaeky07oOnwRl5DyzlFZL2T8FtFN2hsTd0Lvj4fvcNN2wnp6AZn7u2na0nUmtdZKlNnM/f X-Received: by 10.68.137.163 with SMTP id qj3mr18834271pbb.4.1386247199632; Thu, 05 Dec 2013 04:39:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.81.229 with SMTP id d5ls803188qey.64.gmail; Thu, 05 Dec 2013 04:39:59 -0800 (PST) X-Received: by 10.58.54.69 with SMTP id h5mr12115084vep.25.1386247199488; Thu, 05 Dec 2013 04:39:59 -0800 (PST) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id fc4si5753234vcb.11.2013.12.05.04.39.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 04:39:59 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id oy12so13734519veb.15 for ; Thu, 05 Dec 2013 04:39:59 -0800 (PST) X-Received: by 10.58.75.34 with SMTP id z2mr104484vev.57.1386247199299; Thu, 05 Dec 2013 04:39:59 -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 u4csp11831vcz; Thu, 5 Dec 2013 04:39:58 -0800 (PST) X-Received: by 10.194.170.133 with SMTP id am5mr16561629wjc.42.1386247198368; Thu, 05 Dec 2013 04:39:58 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id i2si527042wie.28.2013.12.05.04.39.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Dec 2013 04:39:58 -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-00072d-9l; 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 12/12] target-arm: A64: add support for compare and branch imm Date: Thu, 5 Dec 2013 12:39:40 +0000 Message-Id: <1386247180-26994-13-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.128.170 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 compare and branch insns, CBZ and CBNZ. Signed-off-by: Alexander Graf [claudio: adapted to new decoder, compare with immediate 0, introduce read_cpu_reg to get the 0 extension on (!sf)] Signed-off-by: Claudio Fontana Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target-arm/translate-a64.c | 46 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index 213a98a..fdc3ed8 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -202,6 +202,25 @@ static TCGv_i64 cpu_reg(DisasContext *s, int reg) } } +/* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64 + * representing the register contents. This TCGv is an auto-freed + * temporary so it need not be explicitly freed, and may be modified. + */ +static TCGv_i64 read_cpu_reg(DisasContext *s, int reg, int sf) +{ + TCGv_i64 v = new_tmp_a64(s); + if (reg != 31) { + if (sf) { + tcg_gen_mov_i64(v, cpu_X[reg]); + } else { + tcg_gen_ext32u_i64(v, cpu_X[reg]); + } + } else { + tcg_gen_movi_i64(v, 0); + } + return v; +} + /* * the instruction disassembly implemented here matches * the instruction encoding classifications in chapter 3 (C3) @@ -227,10 +246,33 @@ static void disas_uncond_b_imm(DisasContext *s, uint32_t insn) gen_goto_tb(s, 0, addr); } -/* Compare & branch (immediate) */ +/* C3.2.1 Compare & branch (immediate) + * 31 30 25 24 23 5 4 0 + * +----+-------------+----+---------------------+--------+ + * | sf | 0 1 1 0 1 0 | op | imm19 | Rt | + * +----+-------------+----+---------------------+--------+ + */ static void disas_comp_b_imm(DisasContext *s, uint32_t insn) { - unsupported_encoding(s, insn); + unsigned int sf, op, rt; + uint64_t addr; + int label_match; + TCGv_i64 tcg_cmp; + + sf = extract32(insn, 31, 1); + op = extract32(insn, 24, 1); /* 0: CBZ; 1: CBNZ */ + rt = extract32(insn, 0, 5); + addr = s->pc + sextract32(insn, 5, 19) * 4 - 4; + + tcg_cmp = read_cpu_reg(s, rt, sf); + label_match = gen_new_label(); + + tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ, + tcg_cmp, 0, label_match); + + gen_goto_tb(s, 0, s->pc); + gen_set_label(label_match); + gen_goto_tb(s, 1, addr); } /* C3.2.5 Test & branch (immediate)