From patchwork Wed Jan 18 22:38:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 9524855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0D8876020B for ; Wed, 18 Jan 2017 22:40:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2DB628540 for ; Wed, 18 Jan 2017 22:40:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E787E28639; Wed, 18 Jan 2017 22:40:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C65528540 for ; Wed, 18 Jan 2017 22:40:09 +0000 (UTC) Received: from localhost ([::1]:44777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTytk-0006c3-DB for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Jan 2017 17:40:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTyt6-0006Wg-Hq for qemu-devel@nongnu.org; Wed, 18 Jan 2017 17:39:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cTyt5-0002iG-Pj for qemu-devel@nongnu.org; Wed, 18 Jan 2017 17:39:28 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35666) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cTyt5-0002hY-Jd for qemu-devel@nongnu.org; Wed, 18 Jan 2017 17:39:27 -0500 Received: by mail-wm0-x243.google.com with SMTP id d140so7556405wmd.2 for ; Wed, 18 Jan 2017 14:39:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W8qzwEgc9Ynzhp3p5/1QEFUtO6cgBO1bJUKfWjK74VY=; b=EDzEzWQmjIqJ6lYhUMRSCZx25A+QxMxL1uKLvxWK4yrKC3trMJxIhPN0NO7LNu5kZG NMM/EGICWMrbik89eE16d68NjZDxCVC8/bV7rxsNsJCN5u4yckOvy5dqTVB8tK3MbTo5 3TgVp4K3obe5kcgEz+c76pS59G1bfMMTU135NGj2tKGL2ipAM9e1/CKyChiS18f66VMB byoaCRi2ZV/c8C0Mgl7x3MiGf6d0dEiVXgQQNAGT5yLrGzCn7N/aWVmKGEqyiqbpPEFf MdbwY0ExjspqxLQWzADg1qbdWoxQE3CQleLvxkaVtdOlHenKQMgU1vbRzGkU0HTowZh7 Rm4g== 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=W8qzwEgc9Ynzhp3p5/1QEFUtO6cgBO1bJUKfWjK74VY=; b=j7lPexM53IRnP4UjqQuOT+fRnRD5PYyS2fZqrwJKdWFAJfqcuKZ8kPIweZRByQLXsN Teg7haESevsJBNDpdpw+mx81qrp2YIdrMWpRayQrx/ReiPucdKLk6qjSl5n1tWykMVj8 4HkaSnDimITveKHwm/DqjdDrWxL7pajrYeq87bh0BA8yerL+7p5DDcFV/oPFJj8YN1bw M+cOiuptxOQyFaizWZ/2z60oUwc8LGsSLHj6PWkbIlvSpAcXRzBxRR1qjWPfIQq7Swoh B+tEKD6zkaHzihLTY6kydQ+pVjld3dXPDi2tQMl+HiMb0tXV6FH63lFLTrcDQkDt/WfY YC/Q== X-Gm-Message-State: AIkVDXJFMrdpSDDT2dgL8snmFHQyPmcsA7VyLzWo9F73WkDtMsZxK+ElvL/JLzL6VMr8tQ== X-Received: by 10.223.172.107 with SMTP id v98mr4691306wrc.77.1484779166531; Wed, 18 Jan 2017 14:39:26 -0800 (PST) Received: from localhost (x4e33e2b8.dyn.telefonica.de. [78.51.226.184]) by smtp.gmail.com with ESMTPSA id 135sm7946166wmh.14.2017.01.18.14.39.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jan 2017 14:39:26 -0800 (PST) From: Artyom Tarasenko To: peter.maydell@linaro.org Date: Wed, 18 Jan 2017 23:38:24 +0100 Message-Id: <1484779123-18968-12-git-send-email-atar4qemu@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1484779123-18968-1-git-send-email-atar4qemu@gmail.com> References: <1484779123-18968-1-git-send-email-atar4qemu@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 11/30] target-sparc: implement UA2005 hypervisor traps 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: mark.cave-ayland@ilande.co.uk, qemu-devel@nongnu.org, Artyom Tarasenko , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Artyom Tarasenko --- target/sparc/cpu.h | 1 + target/sparc/int64_helper.c | 37 ++++++++++++++++++++++++++++++++----- target/sparc/win_helper.c | 6 ++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h index 00fbb4e..f173dd6 100644 --- a/target/sparc/cpu.h +++ b/target/sparc/cpu.h @@ -79,6 +79,7 @@ #define TT_FILL 0xc0 #define TT_WOTHER (1 << 5) #define TT_TRAP 0x100 +#define TT_HTRAP 0x180 #endif #define PSR_NEG_SHIFT 23 diff --git a/target/sparc/int64_helper.c b/target/sparc/int64_helper.c index 29360fa..8300eb4 100644 --- a/target/sparc/int64_helper.c +++ b/target/sparc/int64_helper.c @@ -78,8 +78,10 @@ void sparc_cpu_do_interrupt(CPUState *cs) static int count; const char *name; - if (intno < 0 || intno >= 0x180) { + if (intno < 0 || intno >= 0x1ff) { name = "Unknown"; + } else if (intno >= 0x180) { + name = "Hyperprivileged Trap Instruction"; } else if (intno >= 0x100) { name = "Trap Instruction"; } else if (intno >= 0xc0) { @@ -135,16 +137,36 @@ void sparc_cpu_do_interrupt(CPUState *cs) tsptr->tnpc = env->npc; tsptr->tt = intno; + if (cpu_has_hypervisor(env)) { + env->htstate[env->tl] = env->hpstate; + /* XXX OpenSPARC T1 - UltraSPARC T3 have MAXPTL=2 + but this may change in the future */ + if (env->tl > 2) { + env->hpstate |= HS_PRIV; + } + } + switch (intno) { case TT_IVEC: - cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_IG); + if (!cpu_has_hypervisor(env)) { + cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_IG); + } break; case TT_TFAULT: case TT_DFAULT: case TT_TMISS ... TT_TMISS + 3: case TT_DMISS ... TT_DMISS + 3: case TT_DPROT ... TT_DPROT + 3: - cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_MG); + if (cpu_has_hypervisor(env)) { + env->hpstate |= HS_PRIV; + env->pstate = PS_PEF | PS_PRIV; + } else { + cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_MG); + } + break; + case TT_INSN_REAL_TRANSLATION_MISS ... TT_DATA_REAL_TRANSLATION_MISS: + case TT_HTRAP ... TT_HTRAP + 127: + env->hpstate |= HS_PRIV; break; default: cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_AG); @@ -158,8 +180,13 @@ void sparc_cpu_do_interrupt(CPUState *cs) } else if ((intno & 0x1c0) == TT_FILL) { cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1)); } - env->pc = env->tbr & ~0x7fffULL; - env->pc |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5); + + if (cpu_hypervisor_mode(env)) { + env->pc = (env->htba & ~0x3fffULL) | (intno << 5); + } else { + env->pc = env->tbr & ~0x7fffULL; + env->pc |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5); + } env->npc = env->pc + 4; cs->exception_index = -1; } diff --git a/target/sparc/win_helper.c b/target/sparc/win_helper.c index 2d5b546..45ee4e6 100644 --- a/target/sparc/win_helper.c +++ b/target/sparc/win_helper.c @@ -366,6 +366,9 @@ void helper_done(CPUSPARCState *env) env->asi = (tsptr->tstate >> 24) & 0xff; cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); cpu_put_cwp64(env, tsptr->tstate & 0xff); + if (cpu_has_hypervisor(env)) { + env->hpstate = env->htstate[env->tl]; + } env->tl--; trace_win_helper_done(env->tl); @@ -387,6 +390,9 @@ void helper_retry(CPUSPARCState *env) env->asi = (tsptr->tstate >> 24) & 0xff; cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); cpu_put_cwp64(env, tsptr->tstate & 0xff); + if (cpu_has_hypervisor(env)) { + env->hpstate = env->htstate[env->tl]; + } env->tl--; trace_win_helper_retry(env->tl);