From patchwork Fri Oct 10 16:03:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 38602 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3C83B205D8 for ; Fri, 10 Oct 2014 16:09:51 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id b6sf2336419lbj.3 for ; Fri, 10 Oct 2014 09:09:50 -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=DzIB10G8lDeVc1QO2+K06lLAxc/EonndUQRJ6YacFUs=; b=hJGFxbfGufwLOHJ7CQqE9JWCjy3iKIRNQRq+QNN8ySIBpQsoYyCEh9yPRHUppVBzYe I/nunJxXTQ2gg3ghdNXrGr9DdUZwFLnDrli+NGFHTwkHD8KpRxjTa0VpJYqQob5TtUf7 vMSIJW1fbt3t4aI8PNIaQUsg/beBgpjnIDh5/Omzs3NjrwxJb9eyxoprkFTWNnatG9Rq PzY0LwY3mvuRrTkrB4AlDSCmOTVfeFCqVAV+VcYoCiE/QCprhlTAt3zqKs9cvmCP99Gx O7rPoUymUi8U629Ny1qfV7MHpJ8EIjkb5aZe0a/5hPU8v3f9H8c3lmAGuUnY6HX92J6z eejA== X-Gm-Message-State: ALoCoQkCT8zhnWxhEEb9FL0Fu89r1nuo/VUEH7y6j7c8w8o8y+jePKRkIDJ6Yu7BYBtl5y+rwZtD X-Received: by 10.194.100.3 with SMTP id eu3mr348087wjb.6.1412957390084; Fri, 10 Oct 2014 09:09:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.68 with SMTP id p4ls301569laa.52.gmail; Fri, 10 Oct 2014 09:09:49 -0700 (PDT) X-Received: by 10.152.6.137 with SMTP id b9mr5960667laa.84.1412957389876; Fri, 10 Oct 2014 09:09:49 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com [209.85.215.41]) by mx.google.com with ESMTPS id du3si10041312lbc.32.2014.10.10.09.09.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:09:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id pn19so3571245lab.0 for ; Fri, 10 Oct 2014 09:09:49 -0700 (PDT) X-Received: by 10.112.14.34 with SMTP id m2mr5703573lbc.74.1412957389766; Fri, 10 Oct 2014 09:09:49 -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.84.229 with SMTP id c5csp456601lbz; Fri, 10 Oct 2014 09:09:48 -0700 (PDT) X-Received: by 10.224.47.134 with SMTP id n6mr10226259qaf.15.1412957388191; Fri, 10 Oct 2014 09:09:48 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w102si11700888qge.76.2014.10.10.09.09.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:09:48 -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]:49418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcclH-0006kC-5m for patch@linaro.org; Fri, 10 Oct 2014 12:09:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccfm-0006np-9o for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xccfh-0007z9-CS for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:06 -0400 Received: from mail-oi0-f41.google.com ([209.85.218.41]:37453) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccfh-0007yo-7i for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:01 -0400 Received: by mail-oi0-f41.google.com with SMTP id u20so6938469oif.28 for ; Fri, 10 Oct 2014 09:04:00 -0700 (PDT) X-Received: by 10.202.177.7 with SMTP id a7mr5185969oif.23.1412957040780; Fri, 10 Oct 2014 09:04:00 -0700 (PDT) Received: from gbellows-linaro.bellowshome.net (99-179-1-128.lightspeed.austtx.sbcglobal.net. [99.179.1.128]) by mx.google.com with ESMTPSA id d6sm5382455obt.12.2014.10.10.09.03.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:04:00 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch Date: Fri, 10 Oct 2014 11:03:17 -0500 Message-Id: <1412957023-11105-7-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1412957023-11105-1-git-send-email-greg.bellows@linaro.org> References: <1412957023-11105-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.41 Subject: [Qemu-devel] [PATCH v6 06/32] target-arm: A32: Emulate the SMC instruction 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: greg.bellows@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.215.41 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: Fabian Aggeler Implements SMC instruction in AArch32 using the A32 syndrome. When executing SMC instruction from monitor CPU mode SCR.NS bit is reset. Signed-off-by: Sergey Fedorov Signed-off-by: Fabian Aggeler Signed-off-by: Greg Bellows ========== v5 -> v6 - Fixed PC offsetting for presmc - Removed extraneous semi-colon - Fixed merge issue v4 -> v5 - Merge pre_smc upstream changes and incorporated ss_advance --- target-arm/helper.c | 11 +++++++++++ target-arm/internals.h | 5 +++++ target-arm/op_helper.c | 3 +-- target-arm/translate.c | 39 +++++++++++++++++++++++++++++---------- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index 2381e6f..7f3f049 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -4090,6 +4090,12 @@ void arm_cpu_do_interrupt(CPUState *cs) mask = CPSR_A | CPSR_I | CPSR_F; offset = 4; break; + case EXCP_SMC: + new_mode = ARM_CPU_MODE_MON; + addr = 0x08; + mask = CPSR_A | CPSR_I | CPSR_F; + offset = 0; + break; default: cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index); return; /* Never happens. Keep compiler happy. */ @@ -4108,6 +4114,11 @@ void arm_cpu_do_interrupt(CPUState *cs) */ addr += env->cp15.vbar_el[1]; } + + if ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_MON) { + env->cp15.scr_el3 &= ~SCR_NS; + } + switch_mode (env, new_mode); /* For exceptions taken to AArch32 we must clear the SS bit in both * PSTATE and in the old-state value we save to SPSR_, so zero it now. diff --git a/target-arm/internals.h b/target-arm/internals.h index fd69a83..544fb42 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -236,6 +236,11 @@ static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_thumb) | (is_thumb ? 0 : ARM_EL_IL); } +static inline uint32_t syn_aa32_smc(void) +{ + return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL; +} + static inline uint32_t syn_aa64_bkpt(uint32_t imm16) { return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 0809d63..9e38f26 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -419,8 +419,7 @@ void HELPER(pre_hvc)(CPUARMState *env) void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) { int cur_el = arm_current_el(env); - /* FIXME: Use real secure state. */ - bool secure = false; + bool secure = arm_is_secure(env); 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. diff --git a/target-arm/translate.c b/target-arm/translate.c index 617e6a9..60655e1 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -7872,15 +7872,27 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) case 7: { int imm16 = extract32(insn, 0, 4) | (extract32(insn, 8, 12) << 4); - /* SMC instruction (op1 == 3) - and undefined instructions (op1 == 0 || op1 == 2) - will trap */ - if (op1 != 1) { + if (op1 == 1) { + /* bkpt */ + ARCH(5); + gen_exception_insn(s, 4, EXCP_BKPT, + syn_aa32_bkpt(imm16, false)); + } else if (op1 == 3) { + /* smi/smc */ + if (!arm_dc_feature(s, ARM_FEATURE_EL3) || + s->current_el == 0) { + goto illegal_op; + } + gen_set_pc_im(s, s->pc - 4); + tmp = tcg_const_i32(syn_aa32_smc()); + gen_helper_pre_smc(cpu_env, tmp); + tcg_temp_free_i32(tmp); + gen_ss_advance(s); + gen_exception_insn(s, 0, EXCP_SMC, syn_aa32_smc()); + break; + } else { goto illegal_op; } - /* bkpt */ - ARCH(5); - gen_exception_insn(s, 4, EXCP_BKPT, syn_aa32_bkpt(imm16, false)); break; } case 0x8: /* signed multiply */ @@ -9711,9 +9723,16 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw if (insn & (1 << 26)) { /* Secure monitor call (v6Z) */ - qemu_log_mask(LOG_UNIMP, - "arm: unimplemented secure monitor call\n"); - goto illegal_op; /* not implemented. */ + if (!arm_dc_feature(s, ARM_FEATURE_EL3) || + s->current_el == 0) { + goto illegal_op; + } + gen_set_pc_im(s, s->pc - 4); + tmp = tcg_const_i32(syn_aa32_smc()); + gen_helper_pre_smc(cpu_env, tmp); + tcg_temp_free_i32(tmp); + gen_ss_advance(s); + gen_exception_insn(s, 0, EXCP_SMC, syn_aa32_smc()); } else { op = (insn >> 20) & 7; switch (op) {