Skip to contentSkip to conversation

few fixes for hppa target

PATCH In review Sven Schnelle 2 participants 8 messages Mar 19, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover few fixes for hppa target

Hi,

here are a few fixes for the hppa target i made while debugging some wide mode issues.

Changes in v2:

- use Richards version for access id matching
- add trans_fic()

Sven Schnelle (6):
target/hppa: ldcw,s uses static shift of 3 target/hppa: fix shrp for wide mode target/hppa: fix access_id check target/hppa: exit tb on flush cache instructions target/hppa: mask privilege bits in mfia target/hppa: fix do_stdby_e()

 target/hppa/insns.decode |  6 ++--
 target/hppa/mem_helper.c | 59 +++++++++++++++++++++++++++++++++-------
 target/hppa/op_helper.c  | 10 +++----
 target/hppa/translate.c  | 19 ++++++++++---
 4 files changed, 72 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.2
#1 lore raw

PATCH v2 1/6 target/hppa: ldcw,s uses static shift of 3

Fixes 96d6407f363 ("target-hppa: Implement loads and stores")
---
 target/hppa/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/translate.c +1 -1
index eb2046c5ad..6a513d7d5c 100644
@@ -3085,7 +3085,7 @@ static bool trans_ldc(DisasContext *ctx, arg_ldst *a)
         dest = dest_gpr(ctx, a->t);
     }
 
-    form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? a->size : 0,
+    form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? 3 : 0,
              a->disp, a->sp, a->m, MMU_DISABLED(ctx));
 
     /*
Signature · 1 line
2.43.2
#2 lore raw

PATCH v2 2/6 target/hppa: fix shrp for wide mode

In reply to Sven Schnelle
Fixes f7b775a9c075 ("target/hppa: Implement SHRPD")
---
 target/hppa/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/hppa/translate.c +2 -2
index 6a513d7d5c..8ba31567e8 100644
@@ -3462,7 +3462,7 @@ static bool trans_shrp_sar(DisasContext *ctx, arg_shrp_sar *a)
     /* Install the new nullification.  */
     cond_free(&ctx->null_cond);
     if (a->c) {
-        ctx->null_cond = do_sed_cond(ctx, a->c, false, dest);
+        ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
     }
     return nullify_end(ctx);
 }
@@ -3505,7 +3505,7 @@ static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a)
     /* Install the new nullification.  */
     cond_free(&ctx->null_cond);
     if (a->c) {
-        ctx->null_cond = do_sed_cond(ctx, a->c, false, dest);
+        ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
     }
     return nullify_end(ctx);
 }
Signature · 1 line
2.43.2
#3 lore raw

PATCH v2 3/6 target/hppa: fix access_id check

In reply to Sven Schnelle

PA2.0 provides 8 instead of 4 PID registers.

---
 target/hppa/mem_helper.c | 59 +++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 10 deletions(-)
target/hppa/mem_helper.c +49 -10
index 80f51e753f..f89ba91b20 100644
@@ -152,6 +152,49 @@ static HPPATLBEntry *hppa_alloc_tlb_ent(CPUHPPAState *env)
     return ent;
 }
 
+#define ACCESS_ID_MASK 0xffff
+
+/* Return the set of protections allowed by a PID match. */
+static int match_prot_id_1(uint32_t access_id, uint32_t prot_id)
+{
+    if (((access_id ^ (prot_id >> 1)) & ACCESS_ID_MASK) == 0) {
+            return (prot_id & 1
+                    ? PROT_EXEC | PROT_READ
+                    : PROT_EXEC | PROT_READ | PROT_WRITE);
+    }
+    return 0;
+}
+
+static int match_prot_id32(CPUHPPAState *env, uint32_t access_id)
+{
+    int r, i;
+
+    for (i = CR_PID1; i <= CR_PID4; ++i) {
+        r = match_prot_id_1(access_id, env->cr[i]);
+        if (r) {
+            return r;
+        }
+    }
+    return 0;
+}
+
+static int match_prot_id64(CPUHPPAState *env, uint32_t access_id)
+{
+    int r, i;
+
+    for (i = CR_PID1; i <= CR_PID4; ++i) {
+        r = match_prot_id_1(access_id, env->cr[i]);
+        if (r) {
+            return r;
+        }
+        r = match_prot_id_1(access_id, env->cr[i] >> 32);
+        if (r) {
+            return r;
+        }
+    }
+    return 0;
+}
+
 int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx,
                               int type, hwaddr *pphys, int *pprot,
                               HPPATLBEntry **tlb_entry)
@@ -226,16 +269,12 @@ int hppa_get_physical_address(CPUHPPAState *env, vaddr addr, int mmu_idx,
 
     /* access_id == 0 means public page and no check is performed */
     if (ent->access_id && MMU_IDX_TO_P(mmu_idx)) {
-        /* If bits [31:1] match, and bit 0 is set, suppress write.  */
-        int match = ent->access_id * 2 + 1;
-
-        if (match == env->cr[CR_PID1] || match == env->cr[CR_PID2] ||
-            match == env->cr[CR_PID3] || match == env->cr[CR_PID4]) {
-            prot &= PAGE_READ | PAGE_EXEC;
-            if (type == PAGE_WRITE) {
-                ret = EXCP_DMPI;
-                goto egress;
-            }
+        int access_prot = (hppa_is_pa20(env)
+                           ? match_prot_id64(env, ent->access_id)
+                           : match_prot_id32(env, ent->access_id));
+        if (prot & ~access_prot) {
+            ret = type & PAGE_EXEC ? EXCP_IMP : EXCP_DMPI;
+            goto egress;
         }
     }
 
Signature · 1 line
2.43.2
Reviewed-by on v2 3/6
#4 lore raw

Re: [PATCH v2 3/6] target/hppa: fix access_id check

Quoted 6 lines · Sven Schnelle

PA2.0 provides 8 instead of 4 PID registers.

---
  target/hppa/mem_helper.c | 59 +++++++++++++++++++++++++++++++++-------
  1 file changed, 49 insertions(+), 10 deletions(-)

target/hppa/mem_helper.c static HPPATLBEntry *hppa_alloc_tlb_ent(CPUHPPAState *env) · line 163

Quoted 7 lines
target/hppa/mem_helper.c +7 -0
+/* Return the set of protections allowed by a PID match. */
+static int match_prot_id_1(uint32_t access_id, uint32_t prot_id)
+{
+    if (((access_id ^ (prot_id >> 1)) & ACCESS_ID_MASK) == 0) {
+            return (prot_id & 1
+                    ? PROT_EXEC | PROT_READ
+                    : PROT_EXEC | PROT_READ | PROT_WRITE);

Tabs? Anyway, weird indentation...

r~

#5 lore raw

PATCH v2 4/6 target/hppa: exit tb on flush cache instructions

In reply to Sven Schnelle

When the guest modifies the tb it is currently executing from, it executes a fic instruction. Exit the tb on such instruction, otherwise we might execute stale code.

---
 target/hppa/insns.decode |  6 +++---
 target/hppa/translate.c  | 11 +++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
target/hppa/insns.decode +3 -3
index f5a3f02fd1..409e3ea9c9 100644
@@ -143,9 +143,9 @@ getshadowregs   1111 1111 1111 1101 1110 1010 1101 0010
 nop             000001 ----- ----- -- 11001010 0 -----         # fdc, disp
 nop_addrx       000001 ..... ..... -- 01001010 . -----  @addrx # fdc, index
 nop_addrx       000001 ..... ..... -- 01001011 . -----  @addrx # fdce
-nop_addrx       000001 ..... ..... --- 0001010 . -----  @addrx # fic 0x0a
-nop_addrx       000001 ..... ..... -- 01001111 . 00000  @addrx # fic 0x4f
-nop_addrx       000001 ..... ..... --- 0001011 . -----  @addrx # fice
+fic             000001 ..... ..... --- 0001010 . -----  @addrx # fic 0x0a
+fic             000001 ..... ..... -- 01001111 . 00000  @addrx # fic 0x4f
+fic             000001 ..... ..... --- 0001011 . -----  @addrx # fice
 nop_addrx       000001 ..... ..... -- 01001110 . 00000  @addrx # pdc
 
 probe           000001 b:5 ri:5 sp:2 imm:1 100011 write:1 0 t:5
target/hppa/translate.c +11 -0
index 8ba31567e8..46da546eb9 100644
@@ -2293,6 +2293,17 @@ static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a)
     return true;
 }
 
+static bool trans_fic(DisasContext *ctx, arg_fic *a)
+{
+    arg_ldst b;
+
+    b.b = a->b;
+    b.x = a->x;
+    b.m = a->m;
+    ctx->base.is_jmp = DISAS_IAQ_N_STALE;
+    return trans_nop_addrx(ctx, &b);
+}
+
 static bool trans_probe(DisasContext *ctx, arg_probe *a)
 {
     TCGv_i64 dest, ofs;
Signature · 1 line
2.43.2
#6 lore raw

PATCH v2 5/6 target/hppa: mask privilege bits in mfia

In reply to Sven Schnelle

mfia should return only the iaoq bits without privilege bits.

Fixes 98a9cb792c8 ("target-hppa: Implement system and memory-management insns")
---
 target/hppa/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/translate.c +1 -1
index 46da546eb9..51bf1b06c9 100644
@@ -1961,7 +1961,7 @@ static bool trans_mfia(DisasContext *ctx, arg_mfia *a)
 {
     unsigned rt = a->t;
     TCGv_i64 tmp = dest_gpr(ctx, rt);
-    tcg_gen_movi_i64(tmp, ctx->iaoq_f);
+    tcg_gen_movi_i64(tmp, ctx->iaoq_f & ~3ULL);
     save_gpr(ctx, rt, tmp);
 
     cond_free(&ctx->null_cond);
Signature · 1 line
2.43.2
#7 lore raw

PATCH v2 6/6 target/hppa: fix do_stdby_e()

In reply to Sven Schnelle

stdby,e,m was writing data from the wrong half of the register into memory for cases 0-3.

Fixes 25460fc5a71 ("target/hppa: Implement STDBY")
---
 target/hppa/op_helper.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
target/hppa/op_helper.c +5 -5
index 480fe80844..6cf49f33b7 100644
@@ -281,17 +281,17 @@ static void do_stdby_e(CPUHPPAState *env, target_ulong addr, uint64_t val,
     case 3:
         /* The 3 byte store must appear atomic.  */
         if (parallel) {
-            atomic_store_mask32(env, addr - 3, val, 0xffffff00u, ra);
+            atomic_store_mask32(env, addr - 3, val >> 32, 0xffffff00u, ra);
         } else {
-            cpu_stw_data_ra(env, addr - 3, val >> 16, ra);
-            cpu_stb_data_ra(env, addr - 1, val >> 8, ra);
+            cpu_stw_data_ra(env, addr - 3, val >> 48, ra);
+            cpu_stb_data_ra(env, addr - 1, val >> 40, ra);
         }
         break;
     case 2:
-        cpu_stw_data_ra(env, addr - 2, val >> 16, ra);
+        cpu_stw_data_ra(env, addr - 2, val >> 48, ra);
         break;
     case 1:
-        cpu_stb_data_ra(env, addr - 1, val >> 24, ra);
+        cpu_stb_data_ra(env, addr - 1, val >> 56, ra);
         break;
     default:
         /* Nothing is stored, but protection is checked and the
Signature · 1 line
2.43.2