From patchwork Tue Sep 30 21:49:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 38191 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 97DAF2032C for ; Tue, 30 Sep 2014 21:56:46 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id d1sf1949194wiv.10 for ; Tue, 30 Sep 2014 14:56:45 -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:cc: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=nQC09/IRRuj5t5EMoZTfs8uRH4fGZSarxJgUi+s994E=; b=XGaZRCRyWcAqI19NSghVT+w7WFWEqmB05KH8viWEcjWKR2CULEw1q0ZEIHOzWSp8Mp zlrJJpt2MLrDECLX3XyECMk6IDwA7tI+a6XweTca6J+EDHBepFmsCCZ4UEl5e4VjrIcb qUHescUiZF9+lcqm4GW5Cr5t0qMT7imniNnOregCSOq2g4R94696xaVS9Yk37nx8Qd3B wPoxXPqL+R1jdBhRZEj2UsY43LZ399eYYSFOFEqt8+ROWR9851t9NqjPxsKOAl+kBurw IV9fmaDpBLj6xbICDgzspBT15uOGvQSvNZyPGF5nBOFpxAMirr7GMm9cRhPZuf8/yWSR l7xw== X-Gm-Message-State: ALoCoQmrVJSH3h8DHD63mjm3UftKLrH9+Fu9160EKTj2jFaWEbkc5tftHrF3EAJ7iMhLEXbbYVT6 X-Received: by 10.152.6.195 with SMTP id d3mr21755laa.10.1412114205655; Tue, 30 Sep 2014 14:56:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.233 with SMTP id uh9ls95789lac.70.gmail; Tue, 30 Sep 2014 14:56:45 -0700 (PDT) X-Received: by 10.112.7.101 with SMTP id i5mr2573206lba.57.1412114205377; Tue, 30 Sep 2014 14:56:45 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com [209.85.217.177]) by mx.google.com with ESMTPS id wz5si24560915lbb.59.2014.09.30.14.56.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id w7so3998584lbi.8 for ; Tue, 30 Sep 2014 14:56:45 -0700 (PDT) X-Received: by 10.153.6.36 with SMTP id cr4mr15948340lad.40.1412114205302; Tue, 30 Sep 2014 14:56:45 -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 of9csp429793lbb; Tue, 30 Sep 2014 14:56:44 -0700 (PDT) X-Received: by 10.140.41.228 with SMTP id z91mr19772339qgz.99.1412114204004; Tue, 30 Sep 2014 14:56:44 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id o9si13732752qat.103.2014.09.30.14.56.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:56:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Received: from localhost ([::1]:46581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5PW-00016e-IC for patch@linaro.org; Tue, 30 Sep 2014 17:56:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5JH-0000Q5-Av for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZ5JC-0003kR-BL for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:15 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:47327) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5JB-0003Tb-EL for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:10 -0400 Received: by mail-pd0-f182.google.com with SMTP id y10so8065460pdj.27 for ; Tue, 30 Sep 2014 14:50:03 -0700 (PDT) X-Received: by 10.66.165.36 with SMTP id yv4mr72304074pab.23.1412113803219; Tue, 30 Sep 2014 14:50:03 -0700 (PDT) Received: from gbellows-linaro.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com. [67.52.129.61]) by mx.google.com with ESMTPSA id qy1sm16027662pbc.27.2014.09.30.14.50.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:50:02 -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: Tue, 30 Sep 2014 16:49:18 -0500 Message-Id: <1412113785-21525-7-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1412113785-21525-1-git-send-email-greg.bellows@linaro.org> References: <1412113785-21525-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.192.182 Cc: Sergey Fedorov , Greg Bellows Subject: [Qemu-devel] [PATCH v5 06/33] 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.217.177 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 ---------- v4 -> v5 - Merge pre_smc upstream changes and incorporated ss_advance --- target-arm/helper.c | 11 +++++++++++ target-arm/internals.h | 7 ++++++- target-arm/op_helper.c | 3 +-- target-arm/translate.c | 39 +++++++++++++++++++++++++++++---------- 4 files changed, 47 insertions(+), 13 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..43a2e7d 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -236,7 +236,12 @@ static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_thumb) | (is_thumb ? 0 : ARM_EL_IL); } -static inline uint32_t syn_aa64_bkpt(uint32_t imm16) +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(uint16_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..8ed8ee9 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 f6404be..3f3ddfb 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_pl == 0) { + goto illegal_op; + } + gen_set_pc_im(s, s->pc); + 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_pl == 0) { + goto illegal_op; + } + gen_set_pc_im(s, s->pc); + 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) {