From patchwork Fri Mar 1 20:04:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 159516 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp1148163jad; Fri, 1 Mar 2019 12:12:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxpQY8nGjj1lRh7FcIdpjBoqi34sU5Epx88up79d4Ig9gxiooCtB9gIgY0xsmlfSFC0NTy3 X-Received: by 2002:a81:11d7:: with SMTP id 206mr5208938ywr.267.1551471176741; Fri, 01 Mar 2019 12:12:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551471176; cv=none; d=google.com; s=arc-20160816; b=c3YOGRUkATXu0PvNXsfa3H8uNadVI5997/IoYItUeON1jKswWC+FQF8Q1YWz0mRRti UTImlq7Vwu6hre4qRssjslUIaSvupY16nFBejn7Pxyj+kMnGtqCEF2xeZJEbKuzixaFW q0WT7TlURbgtkxl8iNICIXjOYJcesau1wKQUxOXVWFZuFMMDBW/VD/8nDs/SBl1xuwjf wSRB2QfafYDBYwG4Vrp7tdLLN3ycI0XCXacji8rErdqTcnAx1lyzJXM0KvQtEhEVTc8f FmVhVnBdlmYubBdLpbHUD0X1ZPwMikXroP6uN1maMFcVXVRi+vlhOSHOnloZ/fLFyu1Q ZuYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SVxej404JeqYSoeOtDsixmlnz9jOeVJ+T9kAKItyhFs=; b=PsEozFezSAgFp6cccMBtRQA25mYuBP/WK1AifGAoyb0skejakbZDLD/UoXrQ3jq/iF lgo05brStsxqns/1zJb9xLHNkIT7a4+72NdywoF9OQAtg5zC9mgZG6+DrcKwmJlasq/t YgRM0tCWJ7jjyJ8iSjtYHm3fyn/85qDngaFHcIuoTPFHFmhbD/SlvdcJyeo6ZoJfkg5Y ABfx6yJogsLUOgUALikSCI5fnrnpFFu1tTEZnlWjhmbsEK9ayI1Iz0TitD7bv7F2Cy+M dZmC4QmPIuSWnfMUYtsUFfoA8V7rhl8aU8OUdyu7VNMHVLqkE7MYO2v7/aAQ2UDZqPh5 SUWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B8+RVJx1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h12si13326376ywc.46.2019.03.01.12.12.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Mar 2019 12:12:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B8+RVJx1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:43558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzoWe-0005Sa-8u for patch@linaro.org; Fri, 01 Mar 2019 15:12:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzoPM-0004IZ-DE for qemu-devel@nongnu.org; Fri, 01 Mar 2019 15:05:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzoPJ-0001o2-U2 for qemu-devel@nongnu.org; Fri, 01 Mar 2019 15:05:23 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:36776) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzoPH-0001fE-Oh for qemu-devel@nongnu.org; Fri, 01 Mar 2019 15:05:20 -0500 Received: by mail-pf1-x444.google.com with SMTP id n22so11916254pfa.3 for ; Fri, 01 Mar 2019 12:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SVxej404JeqYSoeOtDsixmlnz9jOeVJ+T9kAKItyhFs=; b=B8+RVJx1di4Z6gnfT5wsl+WXyIedlNuoPefZ1vDcpQN4muzBA1/c0aqaPKJKR1NjYx bXugzOJzs5vVv1rJ7LvI6PQnbJVi25CCyKM6BI7GFMteyJ/sCzZPPkf+U75oelfhxViH 2jPkXA4jFQ4ChAZtvI+VXRVHTGdhOZXTv1lzfkQm2Fc4g6exU/EleAUOSkjfnNnee7WX qC7HOzZkQtH3TTKIKZTTPZXifB5N9vhl3F0mxr2zmeXAlsJfIIGAo49JMP4R2mDULEfK j0C9Mk/1Wvw0nkHltL9Iky1zvRc+D14OFcWktkaqDWCTYaG5KfZwSqLlFpNhj87rqIL6 iDaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SVxej404JeqYSoeOtDsixmlnz9jOeVJ+T9kAKItyhFs=; b=AQJj2frw5cEIhOJD0US6DG6hPBAIlwd1ySSwegVX2x+PD+45Ne+5hkSZEfkaUck4h0 vbcJb/ni5RgvbbsOwzW3bBpemqI+rCfQRk/DoK+H7rdxC5d1LzG0i3zFsuXpjuaXC0mu 3jSpZ3LLILYHCWP+vNVOVyJ5OVnLNrrtpmAbnr3dI93Gwkmr/ueeOLawrfqB7bXLXQbJ bRGaNYHXAFWH4XRePdKM61sijSIW0p2hpfwPeR25LeiXsICTXZ8oj+3tIxZrokABcGMq rQICibzCmmUl47VMGvMi5T6XeA5ajQYWtljAiTGmZPhkdzVD3x9aEEapd20SrjfrvYmp lG1g== X-Gm-Message-State: APjAAAVYb3r7WTJuHS0LDgBRZD0CN3Uk0ek0x0Xy6YL45rNQrt5x7w3o Uq65SPtPlAPhj8LlzCM+c7YZ0EtBOMQ= X-Received: by 2002:a62:4287:: with SMTP id h7mr7527105pfd.110.1551470709837; Fri, 01 Mar 2019 12:05:09 -0800 (PST) Received: from cloudburst.twiddle.net (cpe-72-132-238-51.dc.res.rr.com. [72.132.238.51]) by smtp.gmail.com with ESMTPSA id x8sm31869206pfn.137.2019.03.01.12.05.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2019 12:05:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 1 Mar 2019 12:04:55 -0800 Message-Id: <20190301200501.16533-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190301200501.16533-1-richard.henderson@linaro.org> References: <20190301200501.16533-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v3 04/10] target/arm: Split helper_msr_i_pstate into 3 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The EL0+UMA check is unique to DAIF. While SPSel had avoided the check by nature of already checking EL >= 1, the other post v8.0 extensions to MSR (imm) allow EL0 and do not require UMA. Avoid the unconditional write to pc and use raise_exception_ra to unwind. Signed-off-by: Richard Henderson --- target/arm/helper-a64.h | 3 +++ target/arm/helper.h | 1 - target/arm/internals.h | 15 ++++++++++++++ target/arm/helper-a64.c | 30 +++++++++++++++++++++++++++ target/arm/op_helper.c | 42 -------------------------------------- target/arm/translate-a64.c | 41 ++++++++++++++++++++++--------------- 6 files changed, 73 insertions(+), 59 deletions(-) -- 2.17.2 diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index aff8d6c9f3..a915c1247f 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -19,6 +19,9 @@ DEF_HELPER_FLAGS_2(udiv64, TCG_CALL_NO_RWG_SE, i64, i64, i64) DEF_HELPER_FLAGS_2(sdiv64, TCG_CALL_NO_RWG_SE, s64, s64, s64) DEF_HELPER_FLAGS_1(rbit64, TCG_CALL_NO_RWG_SE, i64, i64) +DEF_HELPER_2(msr_i_spsel, void, env, i32) +DEF_HELPER_2(msr_i_daifset, void, env, i32) +DEF_HELPER_2(msr_i_daifclear, void, env, i32) DEF_HELPER_3(vfp_cmph_a64, i64, f16, f16, ptr) DEF_HELPER_3(vfp_cmpeh_a64, i64, f16, f16, ptr) DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr) diff --git a/target/arm/helper.h b/target/arm/helper.h index d363904278..6f0f386926 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -77,7 +77,6 @@ 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_1(clear_pstate_ss, void, env) DEF_HELPER_2(get_r13_banked, i32, env, i32) diff --git a/target/arm/internals.h b/target/arm/internals.h index a4bd1becb7..587a1ddf58 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -968,4 +968,19 @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, ARMMMUIdx mmu_idx, bool data); +static inline int exception_target_el(CPUARMState *env) +{ + int target_el = MAX(1, arm_current_el(env)); + + /* + * No such thing as secure EL1 if EL3 is aarch32, + * so update the target EL to EL3 in this case. + */ + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3) && target_el == 1) { + target_el = 3; + } + + return target_el; +} + #endif diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 70850e564d..796ef34b55 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -61,6 +61,36 @@ uint64_t HELPER(rbit64)(uint64_t x) return revbit64(x); } +void HELPER(msr_i_spsel)(CPUARMState *env, uint32_t imm) +{ + update_spsel(env, imm); +} + +static void daif_check(CPUARMState *env, uint32_t op, + uint32_t imm, uintptr_t ra) +{ + /* DAIF update to PSTATE. This is OK from EL0 only if UMA is set. */ + if (arm_current_el(env) == 0 && !(env->cp15.sctlr_el[1] & SCTLR_UMA)) { + raise_exception_ra(env, EXCP_UDEF, + syn_aa64_sysregtrap(0, extract32(op, 0, 3), + extract32(op, 3, 3), 4, + imm, 0x1f, 0), + exception_target_el(env), ra); + } +} + +void HELPER(msr_i_daifset)(CPUARMState *env, uint32_t imm) +{ + daif_check(env, 0x1e, imm, GETPC()); + env->daif |= (imm << 6) & PSTATE_DAIF; +} + +void HELPER(msr_i_daifclear)(CPUARMState *env, uint32_t imm) +{ + daif_check(env, 0x1f, imm, GETPC()); + env->daif &= ~((imm << 6) & PSTATE_DAIF); +} + /* Convert a softfloat float_relation_ (as returned by * the float*_compare functions) to the correct ARM * NZCV flag state. diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index c998eadfaa..c5721a866d 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -68,20 +68,6 @@ void raise_exception_ra(CPUARMState *env, uint32_t excp, uint32_t syndrome, cpu_loop_exit_restore(cs, ra); } -static int exception_target_el(CPUARMState *env) -{ - int target_el = MAX(1, arm_current_el(env)); - - /* No such thing as secure EL1 if EL3 is aarch32, so update the target EL - * to EL3 in this case. - */ - if (arm_is_secure(env) && !arm_el_is_aa64(env, 3) && target_el == 1) { - target_el = 3; - } - - return target_el; -} - uint32_t HELPER(neon_tbl)(uint32_t ireg, uint32_t def, void *vn, uint32_t maxindex) { @@ -875,34 +861,6 @@ uint64_t HELPER(get_cp_reg64)(CPUARMState *env, void *rip) return res; } -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_el(env) == 0 && !(env->cp15.sctlr_el[1] & SCTLR_UMA)) { - uint32_t syndrome = syn_aa64_sysregtrap(0, extract32(op, 0, 3), - extract32(op, 3, 3), 4, - imm, 0x1f, 0); - raise_exception(env, EXCP_UDEF, syndrome, exception_target_el(env)); - } - - switch (op) { - case 0x05: /* SPSel */ - update_spsel(env, imm); - break; - case 0x1e: /* DAIFSet */ - env->daif |= (imm << 6) & PSTATE_DAIF; - break; - case 0x1f: /* DAIFClear */ - env->daif &= ~((imm << 6) & PSTATE_DAIF); - break; - default: - g_assert_not_reached(); - } -} - void HELPER(clear_pstate_ss)(CPUARMState *env) { env->pstate &= ~PSTATE_SS; diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 4aa5a307e4..1e49d33365 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1661,29 +1661,38 @@ 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) { + TCGv_i32 t1; int op = op1 << 3 | op2; + + /* End the TB by default, chaining is ok. */ + s->base.is_jmp = DISAS_TOO_MANY; + switch (op) { case 0x05: /* SPSel */ if (s->current_el == 0) { - unallocated_encoding(s); - return; + goto do_unallocated; } - /* 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_a64_set_pc_im(s->pc - 4); - gen_helper_msr_i_pstate(cpu_env, tcg_op, tcg_imm); - tcg_temp_free_i32(tcg_imm); - tcg_temp_free_i32(tcg_op); - /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */ - gen_a64_set_pc_im(s->pc); - s->base.is_jmp = (op == 0x1f ? DISAS_EXIT : DISAS_JUMP); + t1 = tcg_const_i32(crm & PSTATE_SP); + gen_helper_msr_i_spsel(cpu_env, t1); + tcg_temp_free_i32(t1); break; - } + + case 0x1e: /* DAIFSet */ + t1 = tcg_const_i32(crm); + gen_helper_msr_i_daifset(cpu_env, t1); + tcg_temp_free_i32(t1); + break; + + case 0x1f: /* DAIFClear */ + t1 = tcg_const_i32(crm); + gen_helper_msr_i_daifclear(cpu_env, t1); + tcg_temp_free_i32(t1); + /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */ + s->base.is_jmp = DISAS_UPDATE; + break; + default: + do_unallocated: unallocated_encoding(s); return; }