diff mbox series

target/hppa: Fix diag instructions to set/restore shadow registers

Message ID ZgH1w6tF6wo4GJiO@p100
State New
Headers show
Series target/hppa: Fix diag instructions to set/restore shadow registers | expand

Commit Message

Helge Deller March 25, 2024, 10:08 p.m. UTC
The 32-bit 7300LC CPU and the 64-bit PCX-W 8500 CPU use different
diag instructions to save or restore the CPU registers to/from
the shadow registers.

Implement those per-CPU architecture diag instructions to fix those
parts of the HP ODE testcases (L2DIAG and WDIAG, section 1) which test
the shadow registers.

Signed-off-by: Helge Deller <deller@gmx.de>
diff mbox series

Patch

diff --git a/target/hppa/helper.h b/target/hppa/helper.h
index 8fd7ba65d8..2c5d58bec9 100644
--- a/target/hppa/helper.h
+++ b/target/hppa/helper.h
@@ -86,6 +86,7 @@  DEF_HELPER_FLAGS_0(read_interval_timer, TCG_CALL_NO_RWG, tl)
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_1(halt, noreturn, env)
 DEF_HELPER_1(reset, noreturn, env)
+DEF_HELPER_1(putshadowregs, void, env)
 DEF_HELPER_1(getshadowregs, void, env)
 DEF_HELPER_1(rfi, void, env)
 DEF_HELPER_1(rfi_r, void, env)
diff --git a/target/hppa/sys_helper.c b/target/hppa/sys_helper.c
index 4a31748342..3727f4ce8b 100644
--- a/target/hppa/sys_helper.c
+++ b/target/hppa/sys_helper.c
@@ -95,6 +95,17 @@  void HELPER(rfi)(CPUHPPAState *env)
     cpu_hppa_put_psw(env, env->cr[CR_IPSW]);
 }
 
+void HELPER(putshadowregs)(CPUHPPAState *env)
+{
+    env->shadow[0] = env->gr[1];
+    env->shadow[1] = env->gr[8];
+    env->shadow[2] = env->gr[9];
+    env->shadow[3] = env->gr[16];
+    env->shadow[4] = env->gr[17];
+    env->shadow[5] = env->gr[24];
+    env->shadow[6] = env->gr[25];
+}
+
 void HELPER(getshadowregs)(CPUHPPAState *env)
 {
     env->gr[1] = env->shadow[0];
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index 99c5c4cbca..40f1cbe7ed 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -4533,6 +4533,18 @@  static bool trans_diag(DisasContext *ctx, arg_diag *a)
         gen_helper_diag_console_output(tcg_env);
         return nullify_end(ctx);
     }
+    if ((ctx->is_pa20 && a->i == 0x701840) ||
+        (!ctx->is_pa20 && a->i == 0x1a40)) {
+        /* save shadow registers */
+        nullify_over(ctx);
+        gen_helper_putshadowregs(tcg_env);
+        return nullify_end(ctx);
+    }
+    if ((ctx->is_pa20 && a->i == 0x781840) ||
+        (!ctx->is_pa20 && a->i == 0x1a00)) {
+        /* restore shadow registers */
+        return trans_getshadowregs(ctx, NULL);
+    }
 #endif
     qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i);
     return true;