From patchwork Fri Jan 31 15:45:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 23973 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 543DC202B2 for ; Fri, 31 Jan 2014 15:58:07 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id jt11sf10760119pbb.10 for ; Fri, 31 Jan 2014 07:58:06 -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=w92GGkKIh6oArwbUKmCRM2iqdAeH5QCeOkKO24l9ZLg=; b=Q7hDa3eZ3jmpSORAFk3cnRKl8uoPXCXNL3lYNYQTPSRTOtvCVeGvFaVt1D58lQmS65 uZKdjwjYSA+ju+k5qBlr4syaTX5wqtD4DKNj8bnbDrC8GYmEAhA2MCrp5U6CziTB+Uln qX3kB0+lMaVPO5OSqWhewAaQInMBVwuRS8PHq430rKKslhEOFwGoUBjXz36TSfhQ6wb5 3oemMUZtBb/Jip3OJemaVexWA6S9+oUSubKfDG/rtqBkd6gdL9w36knX8+aiCU/GVND3 zxgHG/wtxxjbV7jNGiW6CF0wPThY+SvBLfGQ1uI51flJzLPMME0YBDyneV0vLA52AY9L mDxw== X-Gm-Message-State: ALoCoQliEDjuDe5bS5JxEhg91X1juR+1xi/XgLk0Prl70FUrZIGfMcEySvGj6XG9HnZpLfcy6924 X-Received: by 10.66.189.163 with SMTP id gj3mr7924859pac.32.1391183886616; Fri, 31 Jan 2014 07:58:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.113 with SMTP id p104ls1016026qga.41.gmail; Fri, 31 Jan 2014 07:58:06 -0800 (PST) X-Received: by 10.220.139.136 with SMTP id e8mr364067vcu.34.1391183886516; Fri, 31 Jan 2014 07:58:06 -0800 (PST) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id sm10si3650516vec.119.2014.01.31.07.58.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Jan 2014 07:58:06 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.181 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.181; Received: by mail-vc0-f181.google.com with SMTP id ie18so3051215vcb.26 for ; Fri, 31 Jan 2014 07:58:06 -0800 (PST) X-Received: by 10.58.90.202 with SMTP id by10mr16412787veb.6.1391183886435; Fri, 31 Jan 2014 07:58:06 -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 u4csp106456vcz; Fri, 31 Jan 2014 07:58:05 -0800 (PST) X-Received: by 10.194.71.47 with SMTP id r15mr14196353wju.19.1391183885430; Fri, 31 Jan 2014 07:58:05 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id x4si5396132wjf.112.2014.01.31.07.58.03 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 31 Jan 2014 07:58:05 -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 1W9GHn-00080b-TQ; Fri, 31 Jan 2014 15:45:43 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Michael Matz , Claudio Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Will Newton , Peter Crosthwaite , Rob Herring Subject: [PATCH v2 09/35] target-arm: A64: Implement MSR (immediate) instructions Date: Fri, 31 Jan 2014 15:45:17 +0000 Message-Id: <1391183143-30724-10-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1391183143-30724-1-git-send-email-peter.maydell@linaro.org> References: <1391183143-30724-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.181 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: , Implement the MSR (immediate) instructions, which can update the PSTATE SP and DAIF fields. Signed-off-by: Peter Maydell --- target-arm/cpu.h | 1 + target-arm/helper.h | 2 ++ target-arm/op_helper.c | 25 +++++++++++++++++++++++++ target-arm/translate-a64.c | 24 +++++++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 385cfcd..e66d464 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -426,6 +426,7 @@ int cpu_arm_handle_mmu_fault (CPUARMState *env, target_ulong address, int rw, #define PSTATE_Z (1U << 30) #define PSTATE_N (1U << 31) #define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V) +#define PSTATE_DAIF (PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F) #define CACHED_PSTATE_BITS (PSTATE_NZCV) /* Mode values for AArch64 */ #define PSTATE_MODE_EL3h 13 diff --git a/target-arm/helper.h b/target-arm/helper.h index 71b8411..93a27ce 100644 --- a/target-arm/helper.h +++ b/target-arm/helper.h @@ -62,6 +62,8 @@ DEF_HELPER_2(get_cp_reg, i32, env, ptr) DEF_HELPER_3(set_cp_reg64, void, env, ptr, i64) DEF_HELPER_2(get_cp_reg64, i64, env, ptr) +DEF_HELPER_3(msr_i_pstate, void, env, i32, i32) + DEF_HELPER_2(get_r13_banked, i32, env, i32) DEF_HELPER_3(set_r13_banked, void, env, i32, i32) diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index a918e5b..c812a9f 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -313,6 +313,31 @@ uint64_t HELPER(get_cp_reg64)(CPUARMState *env, void *rip) return value; } +void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) +{ + /* MSR_i to update PSTATE. This is OK from EL0 only if UMA is set. + * Note that SPSel is never OK from EL0; we rely on handle_msr_i() + * to catch that case at translate time. + */ + if (arm_current_pl(env) == 0 && !(env->cp15.c1_sys & SCTLR_UMA)) { + raise_exception(env, EXCP_UDEF); + } + + switch (op) { + case 0x05: /* SPSel */ + env->pstate = deposit32(env->pstate, 0, 1, imm); + break; + case 0x1e: /* DAIFSet */ + env->pstate |= (imm << 6) & PSTATE_DAIF; + break; + case 0x1f: /* DAIFClear */ + env->pstate &= ~((imm << 6) & PSTATE_DAIF); + break; + default: + g_assert_not_reached(); + } +} + /* ??? Flag setting arithmetic is awkward because we need to do comparisons. The only way to do that in TCG is a conditional branch, which clobbers all our temporaries. For now implement these as helper functions. */ diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index d938e5e..a942609 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -1106,7 +1106,29 @@ static void handle_sync(DisasContext *s, uint32_t insn, static void handle_msr_i(DisasContext *s, uint32_t insn, unsigned int op1, unsigned int op2, unsigned int crm) { - unsupported_encoding(s, insn); + int op = op1 << 3 | op2; + switch (op) { + case 0x05: /* SPSel */ + if (s->current_pl == 0) { + unallocated_encoding(s); + return; + } + /* fall through */ + case 0x1e: /* DAIFSet */ + case 0x1f: /* DAIFClear */ + { + TCGv_i32 tcg_imm = tcg_const_i32(crm); + TCGv_i32 tcg_op = tcg_const_i32(op); + gen_helper_msr_i_pstate(cpu_env, tcg_op, tcg_imm); + tcg_temp_free_i32(tcg_imm); + tcg_temp_free_i32(tcg_op); + s->is_jmp = DISAS_UPDATE; + break; + } + default: + unallocated_encoding(s); + return; + } } static void gen_get_nzcv(TCGv_i64 tcg_rt)