From patchwork Wed Jan 11 20:19:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 714008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tzM9k51qMz9rxw for ; Thu, 12 Jan 2017 08:15:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vFOCOHtb"; dkim-atps=neutral Received: from localhost ([::1]:57175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRQEq-0004xw-DQ for incoming@patchwork.ozlabs.org; Wed, 11 Jan 2017 16:15:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRPOD-0006d4-Pa for qemu-devel@nongnu.org; Wed, 11 Jan 2017 15:20:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRPOC-00010k-KK for qemu-devel@nongnu.org; Wed, 11 Jan 2017 15:20:57 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33728) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cRPOC-00010c-C5 for qemu-devel@nongnu.org; Wed, 11 Jan 2017 15:20:56 -0500 Received: by mail-wm0-x243.google.com with SMTP id r144so587401wme.0 for ; Wed, 11 Jan 2017 12:20:56 -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 :in-reply-to:references; bh=fvwPRduvFwWes7emBT0InISs8BIIizAcQZbSwGpC02Q=; b=vFOCOHtb3cgq+/rb/QE8DSMf5uFEY31cUjz0uCtBdtUY9YUviajoYhMDeDjLZX37CK lV8Blsp/Mkn4B7fO0w2PeC4FYmVPGlieG+mEAgOUFfZHBlrraeumMAdrRBtsfSpdVmIz J8mH1hngDjnTP5Vw1qkCSUUMaGpq8qt34oZXVVo8n8cRQYfOXS2ZF+tLOxB6NsNAn0h3 IlsOvx9D22lXfvCYAFGXTq39p/A+mi1HkRSRI/MS8t9rAvHa8+OC2We9VM5LyvNKaVsE CAJjlvFKvNPlLbbULeqWxJ2dQAw0lI5WrNarRT+v4m1sfsfW0aREB6uj1XtuayNgY41F Vrpg== 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:in-reply-to:references; bh=fvwPRduvFwWes7emBT0InISs8BIIizAcQZbSwGpC02Q=; b=sR6PRsb3Fv7yOQPqI280X14Cd+udmCldatPr2vRbO8dqj2uR8iOOwvKlSxxOHPSSL8 lpY0e93t7FaXnaMqW21HZyj9qiS+vFQ+uLk9G+7ckdFzgZmWKo1DUgUlgolU+M6Ejmtt v9CJ6lZbXazev2QxoewPqRUZvTc1rvL2NAxsK9gWuzCHIK9kfsVJxSVIGH5mJkz8/+A5 g3MOfIfmGMjKpVIekOpsXNQb2JCtULbgRsTEeflqzexUC62sQ/h4R+ZGx6SrpIugnzac 9XAZ9j5jdECtf692L9lAKu4VDv4yEOTtiGpbAx+JV3ICg2rWfA4JVaZVbnxFBSPkxXTN YbfA== X-Gm-Message-State: AIkVDXIPioUdStqfFbrMjW9toDtDVei5R2hC0+ExNVqwz0yZXH61tAT64lKWumdS81zQxQ== X-Received: by 10.28.6.78 with SMTP id 75mr6865057wmg.81.1484166055303; Wed, 11 Jan 2017 12:20:55 -0800 (PST) Received: from localhost (x55b4b54a.dyn.telefonica.de. [85.180.181.74]) by smtp.gmail.com with ESMTPSA id r7sm10166297wjp.43.2017.01.11.12.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 12:20:54 -0800 (PST) From: Artyom Tarasenko To: qemu-devel@nongnu.org Date: Wed, 11 Jan 2017 21:19:43 +0100 Message-Id: <5e6434c91c40b0acc4a8da12da2edc7a43b1dd7f.1484165352.git.atar4qemu@gmail.com> 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::243 Subject: [Qemu-devel] [PATCH v2 12/30] target-sparc: implement UA2005 GL register 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Artyom Tarasenko --- target/sparc/cpu.c | 13 ++++++++++--- target/sparc/cpu.h | 2 ++ target/sparc/helper.h | 1 + target/sparc/int64_helper.c | 6 ++++++ target/sparc/translate.c | 3 +-- target/sparc/win_helper.c | 40 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index 4e07b92..8f228e8 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -58,9 +58,13 @@ static void sparc_cpu_reset(CPUState *s) env->psrps = 1; #endif #ifdef TARGET_SPARC64 - env->pstate = PS_PRIV|PS_RED|PS_PEF|PS_AG; + env->pstate = PS_PRIV | PS_RED | PS_PEF; + if (!cpu_has_hypervisor(env)) { + env->pstate |= PS_AG; + } env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0; env->tl = env->maxtl; + env->gl = 2; cpu_tsptr(env)->tt = TT_POWER_ON_RESET; env->lsu = 0; #else @@ -745,14 +749,17 @@ void sparc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << PSR_CARRY_SHIFT); cpu_fprintf(f, " xcc: "); cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4)); - cpu_fprintf(f, ") asi: %02x tl: %d pil: %x\n", env->asi, env->tl, - env->psrpil); + cpu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl, + env->psrpil, env->gl); + cpu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: " + TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba); cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d " "cleanwin: %d cwp: %d\n", env->cansave, env->canrestore, env->otherwin, env->wstate, env->cleanwin, env->nwindows - 1 - env->cwp); cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: " TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs); + #else cpu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env)); cpu_print_cc(f, cpu_fprintf, cpu_get_psr(env)); diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h index f26fdcf..6c1607e 100644 --- a/target/sparc/cpu.h +++ b/target/sparc/cpu.h @@ -512,6 +512,7 @@ struct CPUSPARCState { uint64_t bgregs[8]; /* backup for normal global registers */ uint64_t igregs[8]; /* interrupt general registers */ uint64_t mgregs[8]; /* mmu general registers */ + uint64_t glregs[8 * MAXTL_MAX]; uint64_t fprs; uint64_t tick_cmpr, stick_cmpr; CPUTimer *tick, *stick; @@ -612,6 +613,7 @@ void cpu_put_ccr(CPUSPARCState *env1, target_ulong val); target_ulong cpu_get_cwp64(CPUSPARCState *env1); void cpu_put_cwp64(CPUSPARCState *env1, int cwp); void cpu_change_pstate(CPUSPARCState *env1, uint32_t new_pstate); +void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl); #endif int cpu_cwp_inc(CPUSPARCState *env1, int cwp); int cpu_cwp_dec(CPUSPARCState *env1, int cwp); diff --git a/target/sparc/helper.h b/target/sparc/helper.h index 0cf1bfb..fe44e16 100644 --- a/target/sparc/helper.h +++ b/target/sparc/helper.h @@ -5,6 +5,7 @@ DEF_HELPER_1(rdpsr, tl, env) DEF_HELPER_1(power_down, void, env) #else DEF_HELPER_FLAGS_2(wrpil, TCG_CALL_NO_RWG, void, env, tl) +DEF_HELPER_2(wrgl, void, env, tl) DEF_HELPER_2(wrpstate, void, env, tl) DEF_HELPER_1(done, void, env) DEF_HELPER_1(retry, void, env) diff --git a/target/sparc/int64_helper.c b/target/sparc/int64_helper.c index 8300eb4..605747c 100644 --- a/target/sparc/int64_helper.c +++ b/target/sparc/int64_helper.c @@ -146,6 +146,12 @@ void sparc_cpu_do_interrupt(CPUState *cs) } } + if (env->def->features & CPU_FEATURE_GL) { + tsptr->tstate |= (env->gl & 7ULL) << 40; + cpu_gl_switch_gregs(env, env->gl + 1); + env->gl++; + } + switch (intno) { case TT_IVEC: if (!cpu_has_hypervisor(env)) { diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 82f9965..68677d3 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -4558,8 +4558,7 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn) break; case 16: // UA2005 gl CHECK_IU_FEATURE(dc, GL); - tcg_gen_st32_tl(cpu_tmp0, cpu_env, - offsetof(CPUSPARCState, gl)); + gen_helper_wrgl(cpu_env, cpu_tmp0); break; case 26: // UA2005 strand status CHECK_IU_FEATURE(dc, HYPV); diff --git a/target/sparc/win_helper.c b/target/sparc/win_helper.c index 45ee4e6..71b3dd3 100644 --- a/target/sparc/win_helper.c +++ b/target/sparc/win_helper.c @@ -290,6 +290,10 @@ void helper_wrcwp(CPUSPARCState *env, target_ulong new_cwp) static inline uint64_t *get_gregset(CPUSPARCState *env, uint32_t pstate) { + if (env->def->features & CPU_FEATURE_GL) { + return env->glregs + (env->gl & 7) * 8; + } + switch (pstate) { default: trace_win_helper_gregset_error(pstate); @@ -305,14 +309,40 @@ static inline uint64_t *get_gregset(CPUSPARCState *env, uint32_t pstate) } } +static inline uint64_t *get_gl_gregset(CPUSPARCState *env, uint32_t gl) +{ + return env->glregs + (gl & 7) * 8; +} + +/* Switch global register bank */ +void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl) +{ + uint64_t *src, *dst; + src = get_gl_gregset(env, new_gl); + dst = get_gl_gregset(env, env->gl); + + if (src != dst) { + memcpy32(dst, env->gregs); + memcpy32(env->gregs, src); + } +} + +void helper_wrgl(CPUSPARCState *env, target_ulong new_gl) +{ + cpu_gl_switch_gregs(env, new_gl & 7); + env->gl = new_gl & 7; +} + void cpu_change_pstate(CPUSPARCState *env, uint32_t new_pstate) { uint32_t pstate_regs, new_pstate_regs; uint64_t *src, *dst; if (env->def->features & CPU_FEATURE_GL) { - /* PS_AG is not implemented in this case */ - new_pstate &= ~PS_AG; + /* PS_AG, IG and MG are not implemented in this case */ + new_pstate &= ~(PS_AG | PS_IG | PS_MG); + env->pstate = new_pstate; + return; } pstate_regs = env->pstate & 0xc01; @@ -367,7 +397,10 @@ void helper_done(CPUSPARCState *env) cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); cpu_put_cwp64(env, tsptr->tstate & 0xff); if (cpu_has_hypervisor(env)) { + uint32_t new_gl = (tsptr->tstate >> 40) & 7; env->hpstate = env->htstate[env->tl]; + cpu_gl_switch_gregs(env, new_gl); + env->gl = new_gl; } env->tl--; @@ -391,7 +424,10 @@ void helper_retry(CPUSPARCState *env) cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); cpu_put_cwp64(env, tsptr->tstate & 0xff); if (cpu_has_hypervisor(env)) { + uint32_t new_gl = (tsptr->tstate >> 40) & 7; env->hpstate = env->htstate[env->tl]; + cpu_gl_switch_gregs(env, new_gl); + env->gl = new_gl; } env->tl--;