From patchwork Fri Nov 4 20:50:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 9413219 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 EBB0360573 for ; Fri, 4 Nov 2016 21:05:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDFED2AF10 for ; Fri, 4 Nov 2016 21:05:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D16682AF6F; Fri, 4 Nov 2016 21:05:24 +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 663242AF10 for ; Fri, 4 Nov 2016 21:05:24 +0000 (UTC) Received: from localhost ([::1]:40772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2lfv-00040e-JT for patchwork-qemu-devel@patchwork.kernel.org; Fri, 04 Nov 2016 17:05:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2lSU-0000r3-8t for qemu-devel@nongnu.org; Fri, 04 Nov 2016 16:51:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c2lST-0003zL-2i for qemu-devel@nongnu.org; Fri, 04 Nov 2016 16:51:30 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33521) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c2lSS-0003yC-SQ for qemu-devel@nongnu.org; Fri, 04 Nov 2016 16:51:29 -0400 Received: by mail-wm0-x241.google.com with SMTP id u144so5627980wmu.0 for ; Fri, 04 Nov 2016 13:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2PK2XeUrEchC23SVapiohA0XtoLwuNBWnNyzjTOxstY=; b=lbDRTTGTU4GgogZXraQLuSNjSYDiWnEytofbbf3A2xpFkCYTgEdyGXA0SMFNzYIzYd lnwwZCwnSNqI+TBlsWMvJM7wJqTqk2pRphtXwfqVxDgWY7PePam2AzytkoqYBxOR71+N hLgGl/L/E6qnBnUUo9kDInS+WpMX53XVbrowoAv9Vn4fGfqRUgWV/nQQZVI1axs4hxcC va7uLbBkOnHiRrv/NSZMC/CNOKXCNUfDEpxsT9q3cADee15zBF4VWS3WzpUP0eVxUhpX mt9DXvRoh9jhHXAAOxmHKHC8jCNjPd86bRbWsr8cl6oRrJeV8s0/MK/YJvjAZ6Dp10o0 01Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=2PK2XeUrEchC23SVapiohA0XtoLwuNBWnNyzjTOxstY=; b=Xgqf5NACy3ydZXJTMptUX3hq1oLEFoKy6X2nx6ao+VrZbXvwVFX4U7bd8ZGpjFgbeV 8LrRaEwj8SoEyRLpdNjvGeNoa3LnV3X5tdwM2E41NNhm11/aGoNpHa/ktSOiz6cx/Zo7 JY6lOG5ESwRdLODRiX6qZGbYq//U+Y84Wl30E2ygQACMCldi3GAUjmkdiABKv9fVrVy5 K6vcNMYxcCxEa7u0d8fN+/CMftGTWMG465XYR5EtciWzddzKF8LsSq2pGA/o8DA94ACM MSm+FA4ZVSPXuA4D3yY6b4MLvMI3kL++mqbF+NjHgx1dZJStDC7G2QPY0ysT7koY2T4l h92w== X-Gm-Message-State: ABUngvd7Y+C4dXZOQmLo2NV3JD9XYqsOsl1bQzYbXVDpkXMJcAGisBhQ84xeyuE0omZD5g== X-Received: by 10.28.68.195 with SMTP id r186mr177387wma.105.1478292687762; Fri, 04 Nov 2016 13:51:27 -0700 (PDT) Received: from localhost (x55b4b5cf.dyn.telefonica.de. [85.180.181.207]) by smtp.gmail.com with ESMTPSA id hb5sm16141851wjc.5.2016.11.04.13.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Nov 2016 13:51:26 -0700 (PDT) From: Artyom Tarasenko To: qemu-devel@nongnu.org Date: Fri, 4 Nov 2016 21:50:12 +0100 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH v1 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 , Artyom Tarasenko , Richard Henderson 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 4f709e1..f26fdcf 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);