Skip to contentSkip to conversation

linux-user/sparc64: Translate flushw opcode

PATCH In review LemonBoy 5 participants 7 messages Apr 10, 2020 – Jun 8, 2020

lore
Share & tools
lore

LemonBoy

author
#0 lore raw

PATCH 1/1 linux-user/sparc64: Translate flushw opcode

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

---
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
bsd-user/main.c +3 -1
index 770c2b267a..d6b1c997e3 100644
@@ -413,7 +413,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
linux-user/sparc/cpu_loop.c +3 -1
index 7645cc04ca..20a7401126 100644
@@ -69,7 +69,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);
Signature · 1 line
2.20.1
author
#1 lore raw

Ping, I forgot to CC the SPARC mantainers in the previous mail.

Quoted 62 lines · LemonBoy

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

---
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
bsd-user/main.c +3 -1
index 770c2b267a..d6b1c997e3 100644
@@ -413,7 +413,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
linux-user/sparc/cpu_loop.c +3 -1
index 7645cc04ca..20a7401126 100644
@@ -69,7 +69,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);
#2 lore raw

Hi,

could someone with SPARC knowledge review this patch? I'd like to add it to linux-user queue.

Thanks,
Laurent

Le 17/04/2020 à 13:06, LemonBoy a écrit :

Quoted 66 lines

Ping, I forgot to CC the SPARC mantainers in the previous mail.

Quoted 62 lines · LemonBoy

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

---
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
bsd-user/main.c +3 -1
index 770c2b267a..d6b1c997e3 100644
@@ -413,7 +413,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
linux-user/sparc/cpu_loop.c +3 -1
index 7645cc04ca..20a7401126 100644
@@ -69,7 +69,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);
#3 lore raw
Quoted 6 lines · Laurent Vivier

Hi,

could someone with SPARC knowledge review this patch? I'd like to add it to linux-user queue.

Since it's TCG, I'd really preferred a review from Richard.

Regards,
Artyom

Quoted 69 lines · LemonBoy
Quoted 66 lines

Ping, I forgot to CC the SPARC mantainers in the previous mail.

Quoted 62 lines · LemonBoy

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

---
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
bsd-user/main.c +3 -1
index 770c2b267a..d6b1c997e3 100644
@@ -413,7 +413,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
linux-user/sparc/cpu_loop.c +3 -1
index 7645cc04ca..20a7401126 100644
@@ -69,7 +69,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);
Signature · 4 lines
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu
#4 lore raw
In reply to LemonBoy
Quoted 10 lines · LemonBoy

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

This is two separate fixes and should be two separate patches.

Quoted 2 lines
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-

First patch,

Quoted 2 lines
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

Second patch.

Review

Quoted 2 lines
(quoted diff) +2 -0
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */

Format the comment like so:

/*
* cansave is zero...
* nonzero if ...
*/

Quoted 1 line

+ save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));

But this does match the implementation in sparc_cpu_do_interrupt, so the change is good.

target/sparc/translate.c static void disas_sparc_insn(DisasContext * dc, unsigned int insn) · line 3670

Quoted 13 lines
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);

Look ok here too.

r~

#5 lore raw
In reply to LemonBoy

LemonBoy,

could you resend a series of two patches modified as said by Richard?

Changes should be only cosmetic.

Thanks,
Laurent

Le 10/04/2020 à 23:14, LemonBoy a écrit :

Quoted 62 lines

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

---
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
bsd-user/main.c +3 -1
index 770c2b267a..d6b1c997e3 100644
@@ -413,7 +413,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
linux-user/sparc/cpu_loop.c +3 -1
index 7645cc04ca..20a7401126 100644
@@ -69,7 +69,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);
#6 lore raw
In reply to LemonBoy

Hello Giuseppe,

Quoted 10 lines · LemonBoy

From 11d0cfe58d12e0f191b435ade88622cfceb2098a Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 10 Apr 2020 22:55:26 +0200
Subject: [PATCH] linux-user/sparc64: Translate flushw opcode

The ifdef logic should unconditionally compile in the xop == 0x2b case when targeting sparc64.

Fix the handling of window spill traps by keeping cansave into account when calculating the new CWP.

Thanks for the fix.

Do you mind addressing the comment Richard suggested?

Thanks!

Phil.

Quoted 52 lines
---
 bsd-user/main.c             | 4 +++-
 linux-user/sparc/cpu_loop.c | 4 +++-
 target/sparc/translate.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
bsd-user/main.c +3 -1
index 770c2b267a..d6b1c997e3 100644
@@ -413,7 +413,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
linux-user/sparc/cpu_loop.c +3 -1
index 7645cc04ca..20a7401126 100644
@@ -69,7 +69,9 @@ static void save_window(CPUSPARCState *env)
     save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
     env->wim = new_wim;
 #else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    /* cansave is zero if the spill trap handler is triggered by `save` and */
+    /* nonzero if triggered by a `flushw` */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
     env->cansave++;
     env->canrestore--;
 #endif
target/sparc/translate.c +2 -0
index 9416a551cf..1a4efd4ed6 100644
@@ -3663,6 +3663,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
 #endif
                 gen_store_gpr(dc, rd, cpu_tmp0);
                 break;
+#endif
+#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
             } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
 #ifdef TARGET_SPARC64
                 gen_helper_flushw(cpu_env);