From patchwork Mon Jun 30 23:09:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 32833 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0EC94203F4 for ; Tue, 1 Jul 2014 00:46:44 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id lx4sf57130793iec.4 for ; Mon, 30 Jun 2014 17:46:43 -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=HD4vXJRhZTUy0p62VoI7jKYA/TNq3puOlcMlksuZDrs=; b=NnVm+ajZPIK19x4nvboGwzvnZ+6HEJYQoB8YV/PsqRVCg2RdSdS2XbjGpCHTZLFuVl rR3/0hWJ0+Ox2ceVZX/0iwQ+VnwYoZUoKDgRTZK6mlz7r4OgMagyWNjJ1GxECzYmdZix 2NeX31RoGshgg7oRerzHADQ0cnv5lYjJs2wyTmmWPgDmYf5PUDeaZjlOz3ui9lQr+h6N y3DynR0UxLzign2aBkCkBifqmFnT+xFqsasghiovumKJJ5nIiz/qT6uW1OLMUpN5soAn wZX07YelhddvV6wpjfLe58wjKNpS4pQwWVagyuJOamx4ZHPdYu5N23UT+9I9lpQ4v994 aVtQ== X-Gm-Message-State: ALoCoQkk2h3M21m5NyplaiSmy1UY6makJTjbCWA4Wwbd9F8nf4GKesiWROEbSA77nsLvmhWWsc1z X-Received: by 10.182.120.129 with SMTP id lc1mr22901180obb.21.1404175603593; Mon, 30 Jun 2014 17:46:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.107 with SMTP id f98ls526212qge.65.gmail; Mon, 30 Jun 2014 17:46:43 -0700 (PDT) X-Received: by 10.52.121.112 with SMTP id lj16mr34568608vdb.29.1404175603487; Mon, 30 Jun 2014 17:46:43 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id ju5si10794638veb.53.2014.06.30.17.46.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 17:46:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id il7so8224211vcb.40 for ; Mon, 30 Jun 2014 17:46:43 -0700 (PDT) X-Received: by 10.52.72.39 with SMTP id a7mr34382523vdv.13.1404175603356; Mon, 30 Jun 2014 17:46:43 -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.221.37.5 with SMTP id tc5csp179062vcb; Mon, 30 Jun 2014 17:46:43 -0700 (PDT) X-Received: by 10.224.123.202 with SMTP id q10mr65703281qar.79.1404175602940; Mon, 30 Jun 2014 17:46:42 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s3si303455qar.74.2014.06.30.17.46.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Jun 2014 17:46:42 -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]:37034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1klo-0000Iw-3K for patch@linaro.org; Mon, 30 Jun 2014 19:13:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1kij-0005Z5-61 for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1kid-0003C7-5h for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:44 -0400 Received: from mail-ob0-f176.google.com ([209.85.214.176]:36765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1kic-0003Br-TC for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:39 -0400 Received: by mail-ob0-f176.google.com with SMTP id wm4so9533856obc.21 for ; Mon, 30 Jun 2014 16:10:38 -0700 (PDT) X-Received: by 10.60.142.169 with SMTP id rx9mr45450193oeb.1.1404169838598; Mon, 30 Jun 2014 16:10:38 -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 cu7sm76370192oec.12.2014.06.30.16.10.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 16:10:37 -0700 (PDT) From: greg.bellows@linaro.org To: qemu-devel@nongnu.org Date: Mon, 30 Jun 2014 18:09:08 -0500 Message-Id: <1404169773-20264-9-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404169773-20264-1-git-send-email-greg.bellows@linaro.org> References: <1404169773-20264-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.214.176 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, Sergey Fedorov , Fabian Aggeler , Greg Bellows , serge.fdrv@gmail.com, edgar.iglesias@gmail.com, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v4 08/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.220.181 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 --- target-arm/helper.c | 11 +++++++++++ target-arm/internals.h | 5 +++++ target-arm/translate.c | 35 +++++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index ed1e3c7..2e285ab 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3603,6 +3603,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. */ @@ -3621,6 +3627,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); env->spsr = cpsr_read(env); /* Clear IT bits. */ diff --git a/target-arm/internals.h b/target-arm/internals.h index 8815f7c..cda049a 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -224,6 +224,11 @@ static inline uint32_t syn_aa32_svc(uint16_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(uint16_t imm16) { return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | imm16; diff --git a/target-arm/translate.c b/target-arm/translate.c index bf17952..f657389 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -7840,15 +7840,25 @@ 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; + } + tmp = tcg_const_i32(syn_aa32_smc()); + gen_set_pc_im(s, s->pc); + gen_helper_smc(cpu_env, tmp); + tcg_temp_free_i32(tmp); + 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 */ @@ -9679,9 +9689,14 @@ 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; + } + tmp = tcg_const_i32(syn_aa32_smc()); + gen_set_pc_im(s, s->pc); + gen_helper_smc(cpu_env, tmp); + tcg_temp_free_i32(tmp); } else { op = (insn >> 20) & 7; switch (op) {