From patchwork Mon Sep 29 18:26:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 38088 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6C9FD201F1 for ; Mon, 29 Sep 2014 18:28:21 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id t60sf8563356wes.10 for ; Mon, 29 Sep 2014 11:28:20 -0700 (PDT) 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:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ewpHfsgglh819hAq1d3Irk7TGlsyLnrKHf0hBrQVYWo=; b=Md03nfYwXHLy/VHI3Pbmrv/6Px44cOnNT6oCzK+eTWakU8C7YKMPD0rX/KHEa8vqJn XaMpP5P2JaWbLhxv+PHkyZF+LuJlxYosSVtzhKb/uMJwgqUuexldfgkZIsiMnKxL3m3W vAaLG8THFUH5wtEkOD+KK86hiOPJIWUBivwJ3TEGw1E8qzt7GBfs0qU0xkpKHFV+ZxHO pbnMoKYPDutKfMBVjl916nNZrUQ8JO1jQNS87R9FRGd4cMz28ZRhYXd30vPer2EB8ZrT efSxFme6BNq8N0PiaCR/p2nC13zTLq5jQ43T+UeGr0NmcYyvLwRbeqyOZV/tHhOJlMAT tJlg== X-Gm-Message-State: ALoCoQkHeDubouOU2IjKtvMLSl6JycdKO3MbpunNpPIdcICnvsWkSmkNmIlVTeqsVJmw0//0Qvqo X-Received: by 10.112.17.3 with SMTP id k3mr3176651lbd.3.1412015300533; Mon, 29 Sep 2014 11:28:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.226 with SMTP id q2ls39506lae.15.gmail; Mon, 29 Sep 2014 11:28:20 -0700 (PDT) X-Received: by 10.152.6.228 with SMTP id e4mr11481720laa.12.1412015300263; Mon, 29 Sep 2014 11:28:20 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com [209.85.217.178]) by mx.google.com with ESMTPS id be20si19474860lab.17.2014.09.29.11.28.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Sep 2014 11:28:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id w7so1741613lbi.9 for ; Mon, 29 Sep 2014 11:28:19 -0700 (PDT) X-Received: by 10.152.88.16 with SMTP id bc16mr21633640lab.56.1412015299934; Mon, 29 Sep 2014 11:28:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp224604lbb; Mon, 29 Sep 2014 11:28:19 -0700 (PDT) X-Received: by 10.224.47.130 with SMTP id n2mr11437174qaf.87.1412015298570; Mon, 29 Sep 2014 11:28:18 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q79si1752673qgq.91.2014.09.29.11.28.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 29 Sep 2014 11:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:38303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYfgH-0000yt-M8 for patch@linaro.org; Mon, 29 Sep 2014 14:28:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYffA-0008DY-KX for qemu-devel@nongnu.org; Mon, 29 Sep 2014 14:27:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYff9-0007VR-16 for qemu-devel@nongnu.org; Mon, 29 Sep 2014 14:27:08 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:54082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYff8-0007L2-Q4 for qemu-devel@nongnu.org; Mon, 29 Sep 2014 14:27:06 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XYfew-0005oz-Ku for qemu-devel@nongnu.org; Mon, 29 Sep 2014 19:26:54 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 29 Sep 2014 19:26:51 +0100 Message-Id: <1412015213-22268-18-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1412015213-22268-1-git-send-email-peter.maydell@linaro.org> References: <1412015213-22268-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 17/19] target-arm: A64: Emulate the SMC insn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: "Edgar E. Iglesias" Signed-off-by: Edgar E. Iglesias Message-id: 1411718914-6608-10-git-send-email-edgar.iglesias@gmail.com Signed-off-by: Peter Maydell --- target-arm/cpu.h | 1 + target-arm/helper-a64.c | 1 + target-arm/helper.c | 3 +++ target-arm/helper.h | 1 + target-arm/internals.h | 6 ++++++ target-arm/op_helper.c | 26 ++++++++++++++++++++++++++ target-arm/translate-a64.c | 13 +++++++++++++ 7 files changed, 51 insertions(+) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 98610f0..d104a7d 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -53,6 +53,7 @@ #define EXCP_STREX 10 #define EXCP_HVC 11 /* HyperVisor Call */ #define EXCP_HYP_TRAP 12 +#define EXCP_SMC 13 /* Secure Monitor Call */ #define ARMV7M_EXCP_RESET 1 #define ARMV7M_EXCP_NMI 2 diff --git a/target-arm/helper-a64.c b/target-arm/helper-a64.c index 0a7c155..0011488 100644 --- a/target-arm/helper-a64.c +++ b/target-arm/helper-a64.c @@ -478,6 +478,7 @@ void aarch64_cpu_do_interrupt(CPUState *cs) case EXCP_SWI: case EXCP_HVC: case EXCP_HYP_TRAP: + case EXCP_SMC: env->cp15.esr_el[new_el] = env->exception.syndrome; break; case EXCP_IRQ: diff --git a/target-arm/helper.c b/target-arm/helper.c index 48f549a..af2d2e6 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3784,6 +3784,9 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx) case EXCP_HYP_TRAP: target_el = 2; break; + case EXCP_SMC: + target_el = 3; + break; default: target_el = MAX(cur_el, 1); break; diff --git a/target-arm/helper.h b/target-arm/helper.h index 75fc1b3..dec3728 100644 --- a/target-arm/helper.h +++ b/target-arm/helper.h @@ -51,6 +51,7 @@ DEF_HELPER_3(exception_with_syndrome, void, env, i32, i32) DEF_HELPER_1(wfi, void, env) DEF_HELPER_1(wfe, void, env) DEF_HELPER_1(pre_hvc, void, env) +DEF_HELPER_2(pre_smc, void, env, i32) DEF_HELPER_3(cpsr_write, void, env, i32, i32) DEF_HELPER_1(cpsr_read, i32, env) diff --git a/target-arm/internals.h b/target-arm/internals.h index 203c423..1486595 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -55,6 +55,7 @@ static const char * const excnames[] = { [EXCP_STREX] = "QEMU intercept of STREX", [EXCP_HVC] = "Hypervisor Call", [EXCP_HYP_TRAP] = "Hypervisor Trap", + [EXCP_SMC] = "Secure Monitor Call", }; static inline void arm_log_exception(int idx) @@ -222,6 +223,11 @@ static inline uint32_t syn_aa64_hvc(uint32_t imm16) return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); } +static inline uint32_t syn_aa64_smc(uint32_t imm16) +{ + return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); +} + static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_thumb) { return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index e5cb690..03ac92a 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -416,6 +416,32 @@ void HELPER(pre_hvc)(CPUARMState *env) } } +void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) +{ + int cur_el = arm_current_pl(env); + /* FIXME: Use real secure state. */ + bool secure = false; + bool smd = env->cp15.scr_el3 & SCR_SMD; + /* On ARMv8 AArch32, SMD only applies to NS state. + * On ARMv7 SMD only applies to NS state and only if EL2 is available. + * For ARMv7 non EL2, we force SMD to zero so we don't need to re-check + * the EL2 condition here. + */ + bool undef = is_a64(env) ? smd : (!secure && smd); + + /* In NS EL1, HCR controlled routing to EL2 has priority over SMD. */ + if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) { + env->exception.syndrome = syndrome; + raise_exception(env, EXCP_HYP_TRAP); + } + + /* We've already checked that EL3 exists at translation time. */ + if (undef) { + env->exception.syndrome = syn_uncategorized(); + raise_exception(env, EXCP_UDEF); + } +} + void HELPER(exception_return)(CPUARMState *env) { int cur_el = arm_current_pl(env); diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index f4cb56e..35ae3ea 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -1470,6 +1470,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) int opc = extract32(insn, 21, 3); int op2_ll = extract32(insn, 0, 5); int imm16 = extract32(insn, 5, 16); + TCGv_i32 tmp; switch (opc) { case 0: @@ -1496,6 +1497,18 @@ static void disas_exc(DisasContext *s, uint32_t insn) gen_ss_advance(s); gen_exception_insn(s, 0, EXCP_HVC, syn_aa64_hvc(imm16)); break; + case 3: + if (!arm_dc_feature(s, ARM_FEATURE_EL3) || s->current_pl == 0) { + unallocated_encoding(s); + break; + } + gen_a64_set_pc_im(s->pc - 4); + tmp = tcg_const_i32(syn_aa64_smc(imm16)); + gen_helper_pre_smc(cpu_env, tmp); + tcg_temp_free_i32(tmp); + gen_ss_advance(s); + gen_exception_insn(s, 0, EXCP_SMC, syn_aa64_smc(imm16)); + break; default: unallocated_encoding(s); break;