On 10/01/2016 05:05 AM, Artyom Tarasenko wrote:
@@ -1295,10 +1295,9 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong 
addr,

     asi &= 0xff;

-    if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
-        || (cpu_has_hypervisor(env)
-            && asi >= 0x30 && asi < 0x80
-            && !(env->hpstate & HS_PRIV))) {
+    if (((!cpu_hypervisor_mode(env)) && asi < 0x80)
+        && (((env->pstate & PS_PRIV) == 0)
+        || (cpu_has_hypervisor(env) && asi >= 0x30))) {
         helper_raise_exception(env, TT_PRIV_ACT);
     }

You need the same change in get_asi.

And perhaps pull out this check as do_check_asi so that we don't need to replicate it. On top of my sparc tree this becomes the following.


r~
>From 12425652f5cea3453c6fcf728431c73c449c5311 Mon Sep 17 00:00:00 2001
From: Artyom Tarasenko <atar4q...@gmail.com>
Date: Sat, 1 Oct 2016 12:05:19 +0200
Subject: [PATCH 15/31] target-sparc: allow priveleged ASIs in hyperprivileged
 mode

Signed-off-by: Artyom Tarasenko <atar4q...@gmail.com>
Message-Id: <1475316333-9776-16-git-send-email-atar4q...@gmail.com>
---
 target-sparc/ldst_helper.c | 32 ++++++++++++++++----------------
 target-sparc/translate.c   | 15 ++++++++-------
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/target-sparc/ldst_helper.c b/target-sparc/ldst_helper.c
index 612c82d..fec8139 100644
--- a/target-sparc/ldst_helper.c
+++ b/target-sparc/ldst_helper.c
@@ -298,6 +298,20 @@ static inline target_ulong asi_address_mask(CPUSPARCState *env,
         return addr;
     }
 }
+
+static inline void do_check_asi(CPUSPARCState *env, int asi, uintptr_t ra)
+{
+    /* ASIs >= 0x80 are user mode.
+     * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
+     * ASIs <= 0x2f are super mode.
+     */
+    if (asi < 0x80
+        && !cpu_hypervisor_mode(env)
+        && (!cpu_supervisor_mode(env)
+            || (asi >= 0x30 && cpu_has_hypervisor(env)))) {
+        cpu_raise_exception_ra(env, TT_PRIV_ACT, ra);
+    }
+}
 #endif
 
 static void do_check_align(CPUSPARCState *env, target_ulong addr,
@@ -1122,14 +1136,7 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
 #endif
 
     asi &= 0xff;
-
-    if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
-        || (cpu_has_hypervisor(env)
-            && asi >= 0x30 && asi < 0x80
-            && !(env->hpstate & HS_PRIV))) {
-        cpu_raise_exception_ra(env, TT_PRIV_ACT, GETPC());
-    }
-
+    do_check_asi(env, asi, GETPC());
     do_check_align(env, addr, size - 1, GETPC());
     addr = asi_address_mask(env, asi, addr);
 
@@ -1427,14 +1434,7 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val,
 #endif
 
     asi &= 0xff;
-
-    if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
-        || (cpu_has_hypervisor(env)
-            && asi >= 0x30 && asi < 0x80
-            && !(env->hpstate & HS_PRIV))) {
-        cpu_raise_exception_ra(env, TT_PRIV_ACT, GETPC());
-    }
-
+    do_check_asi(env, asi, GETPC());
     do_check_align(env, addr, size - 1, GETPC());
     addr = asi_address_mask(env, asi, addr);
 
diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index cdec52b..29727ac 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -2119,13 +2119,14 @@ static DisasASI get_asi(DisasContext *dc, int insn, TCGMemOp memop)
     if (IS_IMM) {
         asi = dc->asi;
     }
-    /* With v9, all asis below 0x80 are privileged.  */
-    /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
-       down that bit into DisasContext.  For the moment that's ok,
-       since the direct implementations below doesn't have any ASIs
-       in the restricted [0x30, 0x7f] range, and the check will be
-       done properly in the helper.  */
-    if (!supervisor(dc) && asi < 0x80) {
+    /* ASIs >= 0x80 are user mode.
+     * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
+     * ASIs <= 0x2f are super mode.
+     */
+    if (asi < 0x80
+        && !hypervisor(dc)
+        && (!supervisor(dc)
+            || (asi >= 0x30 && (dc->def->features & CPU_FEATURE_HYPV)))) {
         gen_exception(dc, TT_PRIV_ACT);
         type = GET_ASI_EXCP;
     } else {
-- 
2.7.4

Reply via email to