* [PATCH 00/14] linux-user/sparc: Handle missing traps
@ 2023-02-02 0:51 Richard Henderson
2023-02-02 0:51 ` [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps Richard Henderson
` (14 more replies)
0 siblings, 15 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
Lots of missing trap code for cpu_loop().
r~
Richard Henderson (14):
linux-user/sparc: Raise SIGILL for all unhandled software traps
linux-user/sparc: Tidy syscall trap
linux-user/sparc: Use TT_TRAP for flush windows
linux-user/sparc: Tidy window spill/fill traps
linux-user/sparc: Fix sparc64_{get,set}_context traps
linux-user/sparc: Handle software breakpoint trap
linux-user/sparc: Handle division by zero traps
linux-user/sparc: Handle getcc, setcc, getpsr traps
linux-user/sparc: Handle priviledged opcode trap
linux-user/sparc: Handle privilidged action trap
linux-user/sparc: Handle coprocessor disabled trap
linux-user/sparc: Handle unimplemented flush trap
linux-user/sparc: Handle floating-point exceptions
linux-user/sparc: Handle tag overflow traps
linux-user/sparc/target_signal.h | 2 +-
linux-user/syscall_defs.h | 5 +
target/sparc/cpu.h | 3 +-
linux-user/sparc/cpu_loop.c | 170 +++++++++++++++++++++++++------
linux-user/sparc/signal.c | 36 +++----
5 files changed, 167 insertions(+), 49 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 11:56 ` Ilya Leoshkevich
2023-02-02 0:51 ` [PATCH 02/14] linux-user/sparc: Tidy syscall trap Richard Henderson
` (13 subsequent siblings)
14 siblings, 1 reply; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
The linux kernel's trap tables vector all unassigned trap
numbers to BAD_TRAP, which then raises SIGILL.
Reported-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 434c90a55f..c120c42278 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -248,6 +248,14 @@ void cpu_loop (CPUSPARCState *env)
cpu_exec_step_atomic(cs);
break;
default:
+ /*
+ * Most software trap numbers vector to BAD_TRAP.
+ * Handle anything not explicitly matched above.
+ */
+ if (trapnr >= TT_TRAP && trapnr <= TT_TRAP + 0x7f) {
+ force_sig_fault(TARGET_SIGILL, ILL_ILLTRP, env->pc);
+ break;
+ }
fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
cpu_dump_state(cs, stderr, 0);
exit(EXIT_FAILURE);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 02/14] linux-user/sparc: Tidy syscall trap
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
2023-02-02 0:51 ` [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 1:15 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 03/14] linux-user/sparc: Use TT_TRAP for flush windows Richard Henderson
` (12 subsequent siblings)
14 siblings, 1 reply; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
Use TT_TRAP.
For sparc32, 0x88 is the "Slowaris" system call, currently
BAD_TRAP in the kernel's ttable_32.S.
For sparc64, 0x110 is tl0_linux32, the sparc32 trap, as also
seen in the adjacent code. We do not implement multiple abis,
so treat this as !defined(CONFIG_COMPAT), which vectors this
case to BTRAP. This was presumably a typo for 0x111, which is
the "old" linux64 syscall number. Both old and new linux64
syscalls traps vector to LINUX_64BIT_SYSCALL_TRAP.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index c120c42278..18d5c24af1 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -167,12 +167,11 @@ void cpu_loop (CPUSPARCState *env)
}
switch (trapnr) {
-#ifndef TARGET_SPARC64
- case 0x88:
- case 0x90:
+#ifdef TARGET_SPARC64
+ case TT_TRAP + 0x11: /* tl0_oldlinux64 */
+ case TT_TRAP + 0x6d: /* tl0_linux64 */
#else
- case 0x110:
- case 0x16d:
+ case TT_TRAP + 0x10: /* t_linux */
#endif
ret = do_syscall (env, env->gregs[1],
env->regwptr[0], env->regwptr[1],
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 03/14] linux-user/sparc: Use TT_TRAP for flush windows
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
2023-02-02 0:51 ` [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps Richard Henderson
2023-02-02 0:51 ` [PATCH 02/14] linux-user/sparc: Tidy syscall trap Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 04/14] linux-user/sparc: Tidy window spill/fill traps Richard Henderson
` (11 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
The v9 and pre-v9 code can be unified with this macro.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 18d5c24af1..a94bffc583 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -200,15 +200,14 @@ void cpu_loop (CPUSPARCState *env)
env->pc = env->npc;
env->npc = env->npc + 4;
break;
- case 0x83: /* flush windows */
-#ifdef TARGET_ABI32
- case 0x103:
-#endif
+
+ case TT_TRAP + 0x03: /* flush windows */
flush_windows(env);
/* next instruction */
env->pc = env->npc;
env->npc = env->npc + 4;
break;
+
#ifndef TARGET_SPARC64
case TT_WIN_OVF: /* window overflow */
save_window(env);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 04/14] linux-user/sparc: Tidy window spill/fill traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (2 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 03/14] linux-user/sparc: Use TT_TRAP for flush windows Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 05/14] linux-user/sparc: Fix sparc64_{get,set}_context traps Richard Henderson
` (10 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
Add some macros to localize the hw difference between v9 and pre-v9.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index a94bffc583..efc0fa64d5 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -149,6 +149,15 @@ static void flush_windows(CPUSPARCState *env)
#endif
}
+/* Avoid ifdefs below for the v9 and pre-v9 hw traps. */
+#ifdef TARGET_SPARC64
+#define TARGET_TT_SPILL TT_SPILL
+#define TARGET_TT_FILL TT_FILL
+#else
+#define TARGET_TT_SPILL TT_WIN_OVF
+#define TARGET_TT_FILL TT_WIN_UNF
+#endif
+
void cpu_loop (CPUSPARCState *env)
{
CPUState *cs = env_cpu(env);
@@ -208,20 +217,14 @@ void cpu_loop (CPUSPARCState *env)
env->npc = env->npc + 4;
break;
-#ifndef TARGET_SPARC64
- case TT_WIN_OVF: /* window overflow */
+ case TARGET_TT_SPILL: /* window overflow */
save_window(env);
break;
- case TT_WIN_UNF: /* window underflow */
- restore_window(env);
- break;
-#else
- case TT_SPILL: /* window overflow */
- save_window(env);
- break;
- case TT_FILL: /* window underflow */
+ case TARGET_TT_FILL: /* window underflow */
restore_window(env);
break;
+
+#ifdef TARGET_SPARC64
#ifndef TARGET_ABI32
case 0x16e:
flush_windows(env);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 05/14] linux-user/sparc: Fix sparc64_{get,set}_context traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (3 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 04/14] linux-user/sparc: Tidy window spill/fill traps Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 06/14] linux-user/sparc: Handle software breakpoint trap Richard Henderson
` (9 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
These traps are present for sparc64 with ilp32, aka sparc32plus.
Enabling them means adjusting the defines over in signal.c,
and fixing an incorrect usage of abi_ulong when we really meant
the full register, target_ulong.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 23 +++++++++++------------
linux-user/sparc/signal.c | 36 +++++++++++++++++++-----------------
2 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index efc0fa64d5..493845fe76 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -217,6 +217,17 @@ void cpu_loop (CPUSPARCState *env)
env->npc = env->npc + 4;
break;
+#ifdef TARGET_SPARC64
+ case TT_TRAP + 0x6e:
+ flush_windows(env);
+ sparc64_get_context(env);
+ break;
+ case TT_TRAP + 0x6f:
+ flush_windows(env);
+ sparc64_set_context(env);
+ break;
+#endif
+
case TARGET_TT_SPILL: /* window overflow */
save_window(env);
break;
@@ -224,18 +235,6 @@ void cpu_loop (CPUSPARCState *env)
restore_window(env);
break;
-#ifdef TARGET_SPARC64
-#ifndef TARGET_ABI32
- case 0x16e:
- flush_windows(env);
- sparc64_get_context(env);
- break;
- case 0x16f:
- flush_windows(env);
- sparc64_set_context(env);
- break;
-#endif
-#endif
case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */
break;
diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index b501750fe0..2be9000b9e 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -503,7 +503,23 @@ long do_rt_sigreturn(CPUSPARCState *env)
return -QEMU_ESIGRETURN;
}
-#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
+#ifdef TARGET_ABI32
+void setup_sigtramp(abi_ulong sigtramp_page)
+{
+ uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0);
+ assert(tramp != NULL);
+
+ default_sigreturn = sigtramp_page;
+ install_sigtramp(tramp, TARGET_NR_sigreturn);
+
+ default_rt_sigreturn = sigtramp_page + 8;
+ install_sigtramp(tramp + 2, TARGET_NR_rt_sigreturn);
+
+ unlock_user(tramp, sigtramp_page, 2 * 8);
+}
+#endif
+
+#ifdef TARGET_SPARC64
#define SPARC_MC_TSTATE 0
#define SPARC_MC_PC 1
#define SPARC_MC_NPC 2
@@ -575,7 +591,7 @@ void sparc64_set_context(CPUSPARCState *env)
struct target_ucontext *ucp;
target_mc_gregset_t *grp;
target_mc_fpu_t *fpup;
- abi_ulong pc, npc, tstate;
+ target_ulong pc, npc, tstate;
unsigned int i;
unsigned char fenab;
@@ -773,18 +789,4 @@ do_sigsegv:
unlock_user_struct(ucp, ucp_addr, 1);
force_sig(TARGET_SIGSEGV);
}
-#else
-void setup_sigtramp(abi_ulong sigtramp_page)
-{
- uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0);
- assert(tramp != NULL);
-
- default_sigreturn = sigtramp_page;
- install_sigtramp(tramp, TARGET_NR_sigreturn);
-
- default_rt_sigreturn = sigtramp_page + 8;
- install_sigtramp(tramp + 2, TARGET_NR_rt_sigreturn);
-
- unlock_user(tramp, sigtramp_page, 2 * 8);
-}
-#endif
+#endif /* TARGET_SPARC64 */
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 06/14] linux-user/sparc: Handle software breakpoint trap
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (4 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 05/14] linux-user/sparc: Fix sparc64_{get,set}_context traps Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 07/14] linux-user/sparc: Handle division by zero traps Richard Henderson
` (8 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
This is 'ta 1' for both v9 and pre-v9.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 493845fe76..573d97c60b 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -210,6 +210,11 @@ void cpu_loop (CPUSPARCState *env)
env->npc = env->npc + 4;
break;
+ case TT_TRAP + 0x01: /* breakpoint */
+ case EXCP_DEBUG:
+ force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
+ break;
+
case TT_TRAP + 0x03: /* flush windows */
flush_windows(env);
/* next instruction */
@@ -241,9 +246,6 @@ void cpu_loop (CPUSPARCState *env)
case TT_ILL_INSN:
force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
break;
- case EXCP_DEBUG:
- force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
- break;
case EXCP_ATOMIC:
cpu_exec_step_atomic(cs);
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 07/14] linux-user/sparc: Handle division by zero traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (5 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 06/14] linux-user/sparc: Handle software breakpoint trap Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 08/14] linux-user/sparc: Handle getcc, setcc, getpsr traps Richard Henderson
` (7 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
In addition to the hw trap vector, there is a software trap
assigned for older sparc without hw division instructions.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 573d97c60b..398418174f 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -215,6 +215,11 @@ void cpu_loop (CPUSPARCState *env)
force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
break;
+ case TT_TRAP + 0x02: /* div0 */
+ case TT_DIV_ZERO:
+ force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, env->pc);
+ break;
+
case TT_TRAP + 0x03: /* flush windows */
flush_windows(env);
/* next instruction */
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 08/14] linux-user/sparc: Handle getcc, setcc, getpsr traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (6 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 07/14] linux-user/sparc: Handle division by zero traps Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 09/14] linux-user/sparc: Handle priviledged opcode trap Richard Henderson
` (6 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
These are really only meaningful for sparc32, but they're
still present for backward compatibility for sparc64.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 62 +++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 398418174f..370eb4e1a1 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -149,6 +149,51 @@ static void flush_windows(CPUSPARCState *env)
#endif
}
+static void next_instruction(CPUSPARCState *env)
+{
+ env->pc = env->npc;
+ env->npc = env->npc + 4;
+}
+
+static uint32_t do_getcc(CPUSPARCState *env)
+{
+#ifdef TARGET_SPARC64
+ return cpu_get_ccr(env) & 0xf;
+#else
+ return extract32(cpu_get_psr(env), 20, 4);
+#endif
+}
+
+static void do_setcc(CPUSPARCState *env, uint32_t icc)
+{
+#ifdef TARGET_SPARC64
+ cpu_put_ccr(env, (cpu_get_ccr(env) & 0xf0) | (icc & 0xf));
+#else
+ cpu_put_psr(env, deposit32(cpu_get_psr(env), 20, 4, icc));
+#endif
+}
+
+static uint32_t do_getpsr(CPUSPARCState *env)
+{
+#ifdef TARGET_SPARC64
+ const uint64_t TSTATE_CWP = 0x1f;
+ const uint64_t TSTATE_ICC = 0xfull << 32;
+ const uint64_t TSTATE_XCC = 0xfull << 36;
+ const uint32_t PSR_S = 0x00000080u;
+ const uint32_t PSR_V8PLUS = 0xff000000u;
+ uint64_t tstate = sparc64_tstate(env);
+
+ /* See <asm/psrcompat.h>, tstate_to_psr. */
+ return ((tstate & TSTATE_CWP) |
+ PSR_S |
+ ((tstate & TSTATE_ICC) >> 12) |
+ ((tstate & TSTATE_XCC) >> 20) |
+ PSR_V8PLUS);
+#else
+ return (cpu_get_psr(env) & (PSR_ICC | PSR_CWP)) | PSR_S;
+#endif
+}
+
/* Avoid ifdefs below for the v9 and pre-v9 hw traps. */
#ifdef TARGET_SPARC64
#define TARGET_TT_SPILL TT_SPILL
@@ -222,9 +267,20 @@ void cpu_loop (CPUSPARCState *env)
case TT_TRAP + 0x03: /* flush windows */
flush_windows(env);
- /* next instruction */
- env->pc = env->npc;
- env->npc = env->npc + 4;
+ next_instruction(env);
+ break;
+
+ case TT_TRAP + 0x20: /* getcc */
+ env->gregs[1] = do_getcc(env);
+ next_instruction(env);
+ break;
+ case TT_TRAP + 0x21: /* setcc */
+ do_setcc(env, env->gregs[1]);
+ next_instruction(env);
+ break;
+ case TT_TRAP + 0x22: /* getpsr */
+ env->gregs[1] = do_getpsr(env);
+ next_instruction(env);
break;
#ifdef TARGET_SPARC64
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 09/14] linux-user/sparc: Handle priviledged opcode trap
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (7 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 08/14] linux-user/sparc: Handle getcc, setcc, getpsr traps Richard Henderson
@ 2023-02-02 0:51 ` Richard Henderson
2023-02-02 0:52 ` [PATCH 10/14] linux-user/sparc: Handle privilidged action trap Richard Henderson
` (5 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:51 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
For the most part priviledged opcodes are ifdefed out of the
user-only sparc translator, which will then incorrectly produce
illegal opcode traps. But there are some code paths that
properly raise TT_PRIV_INSN, so we must handle it.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 370eb4e1a1..3af791455f 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -307,6 +307,9 @@ void cpu_loop (CPUSPARCState *env)
case TT_ILL_INSN:
force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
break;
+ case TT_PRIV_INSN:
+ force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->pc);
+ break;
case EXCP_ATOMIC:
cpu_exec_step_atomic(cs);
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 10/14] linux-user/sparc: Handle privilidged action trap
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (8 preceding siblings ...)
2023-02-02 0:51 ` [PATCH 09/14] linux-user/sparc: Handle priviledged opcode trap Richard Henderson
@ 2023-02-02 0:52 ` Richard Henderson
2023-02-02 0:52 ` [PATCH 11/14] linux-user/sparc: Handle coprocessor disabled trap Richard Henderson
` (4 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:52 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
This is raised by using an %asi < 0x80 in user-mode.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 3af791455f..42e92ef859 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -310,6 +310,12 @@ void cpu_loop (CPUSPARCState *env)
case TT_PRIV_INSN:
force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->pc);
break;
+#ifdef TARGET_SPARC64
+ case TT_PRIV_ACT:
+ /* Note do_privact defers to do_privop. */
+ force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->pc);
+ break;
+#endif
case EXCP_ATOMIC:
cpu_exec_step_atomic(cs);
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 11/14] linux-user/sparc: Handle coprocessor disabled trap
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (9 preceding siblings ...)
2023-02-02 0:52 ` [PATCH 10/14] linux-user/sparc: Handle privilidged action trap Richard Henderson
@ 2023-02-02 0:52 ` Richard Henderson
2023-02-02 0:52 ` [PATCH 12/14] linux-user/sparc: Handle unimplemented flush trap Richard Henderson
` (3 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:52 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
Since qemu does not implement a sparc coprocessor, all such
instructions raise this trap. Because of that, we never raise
the coprocessor exception trap, which would be vector 0x28.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 42e92ef859..8985d10ba1 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -315,6 +315,10 @@ void cpu_loop (CPUSPARCState *env)
/* Note do_privact defers to do_privop. */
force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->pc);
break;
+#else
+ case TT_NCP_INSN:
+ force_sig_fault(TARGET_SIGILL, TARGET_ILL_COPROC, env->pc);
+ break;
#endif
case EXCP_ATOMIC:
cpu_exec_step_atomic(cs);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 12/14] linux-user/sparc: Handle unimplemented flush trap
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (10 preceding siblings ...)
2023-02-02 0:52 ` [PATCH 11/14] linux-user/sparc: Handle coprocessor disabled trap Richard Henderson
@ 2023-02-02 0:52 ` Richard Henderson
2023-02-02 0:52 ` [PATCH 13/14] linux-user/sparc: Handle floating-point exceptions Richard Henderson
` (2 subsequent siblings)
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:52 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
For sparc64, TT_UNIMP_FLUSH == TT_ILL_INSN, so this is
already handled. For sparc32, the kernel uses SKIP_TRAP.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/cpu_loop.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 8985d10ba1..7ba543983a 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -319,6 +319,9 @@ void cpu_loop (CPUSPARCState *env)
case TT_NCP_INSN:
force_sig_fault(TARGET_SIGILL, TARGET_ILL_COPROC, env->pc);
break;
+ case TT_UNIMP_FLUSH:
+ next_instruction(env);
+ break;
#endif
case EXCP_ATOMIC:
cpu_exec_step_atomic(cs);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 13/14] linux-user/sparc: Handle floating-point exceptions
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (11 preceding siblings ...)
2023-02-02 0:52 ` [PATCH 12/14] linux-user/sparc: Handle unimplemented flush trap Richard Henderson
@ 2023-02-02 0:52 ` Richard Henderson
2023-02-02 0:52 ` [PATCH 14/14] linux-user/sparc: Handle tag overflow traps Richard Henderson
2023-02-05 23:24 ` [PATCH 00/14] linux-user/sparc: Handle missing traps Mark Cave-Ayland
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:52 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
Raise SIGFPE for ieee exceptions.
The other types, such as FSR_FTT_UNIMPFPOP, should not appear,
because we enable normal emulation of missing insns at the
start of sparc_cpu_realizefn().
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/sparc/cpu.h | 3 +--
linux-user/sparc/cpu_loop.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index e478c5eb16..ae8de606d5 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -197,8 +197,7 @@ enum {
#define FSR_FTT2 (1ULL << 16)
#define FSR_FTT1 (1ULL << 15)
#define FSR_FTT0 (1ULL << 14)
-//gcc warns about constant overflow for ~FSR_FTT_MASK
-//#define FSR_FTT_MASK (FSR_FTT2 | FSR_FTT1 | FSR_FTT0)
+#define FSR_FTT_MASK (FSR_FTT2 | FSR_FTT1 | FSR_FTT0)
#ifdef TARGET_SPARC64
#define FSR_FTT_NMASK 0xfffffffffffe3fffULL
#define FSR_FTT_CEXC_NMASK 0xfffffffffffe3fe0ULL
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 7ba543983a..18109f545d 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -301,6 +301,28 @@ void cpu_loop (CPUSPARCState *env)
restore_window(env);
break;
+ case TT_FP_EXCP:
+ {
+ int code = TARGET_FPE_FLTUNK;
+ target_ulong fsr = env->fsr;
+
+ if ((fsr & FSR_FTT_MASK) == FSR_FTT_IEEE_EXCP) {
+ if (fsr & FSR_NVC) {
+ code = TARGET_FPE_FLTINV;
+ } else if (fsr & FSR_OFC) {
+ code = TARGET_FPE_FLTOVF;
+ } else if (fsr & FSR_UFC) {
+ code = TARGET_FPE_FLTUND;
+ } else if (fsr & FSR_DZC) {
+ code = TARGET_FPE_FLTDIV;
+ } else if (fsr & FSR_NXC) {
+ code = TARGET_FPE_FLTRES;
+ }
+ }
+ force_sig_fault(TARGET_SIGFPE, code, env->pc);
+ }
+ break;
+
case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 14/14] linux-user/sparc: Handle tag overflow traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (12 preceding siblings ...)
2023-02-02 0:52 ` [PATCH 13/14] linux-user/sparc: Handle floating-point exceptions Richard Henderson
@ 2023-02-02 0:52 ` Richard Henderson
2023-02-05 23:24 ` [PATCH 00/14] linux-user/sparc: Handle missing traps Mark Cave-Ayland
14 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 0:52 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
This trap is raised by taddcctv and tsubcctv insns.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/sparc/target_signal.h | 2 +-
linux-user/syscall_defs.h | 5 +++++
linux-user/sparc/cpu_loop.c | 3 +++
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/linux-user/sparc/target_signal.h b/linux-user/sparc/target_signal.h
index 87757f0c4e..f223eb4af6 100644
--- a/linux-user/sparc/target_signal.h
+++ b/linux-user/sparc/target_signal.h
@@ -8,7 +8,7 @@
#define TARGET_SIGTRAP 5
#define TARGET_SIGABRT 6
#define TARGET_SIGIOT 6
-#define TARGET_SIGSTKFLT 7 /* actually EMT */
+#define TARGET_SIGEMT 7
#define TARGET_SIGFPE 8
#define TARGET_SIGKILL 9
#define TARGET_SIGBUS 10
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 77864de57f..614a1cbc8e 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -717,6 +717,11 @@ typedef struct target_siginfo {
#define TARGET_TRAP_HWBKPT (4) /* hardware breakpoint/watchpoint */
#define TARGET_TRAP_UNK (5) /* undiagnosed trap */
+/*
+ * SIGEMT si_codes
+ */
+#define TARGET_EMT_TAGOVF 1 /* tag overflow */
+
#include "target_resource.h"
struct target_pollfd {
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 18109f545d..0b19f47876 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -332,6 +332,9 @@ void cpu_loop (CPUSPARCState *env)
case TT_PRIV_INSN:
force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->pc);
break;
+ case TT_TOVF:
+ force_sig_fault(TARGET_SIGEMT, TARGET_EMT_TAGOVF, env->pc);
+ break;
#ifdef TARGET_SPARC64
case TT_PRIV_ACT:
/* Note do_privact defers to do_privop. */
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH 02/14] linux-user/sparc: Tidy syscall trap
2023-02-02 0:51 ` [PATCH 02/14] linux-user/sparc: Tidy syscall trap Richard Henderson
@ 2023-02-02 1:15 ` Richard Henderson
0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-02-02 1:15 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, laurent, iii
On 2/1/23 14:51, Richard Henderson wrote:
> Use TT_TRAP.
>
> For sparc32, 0x88 is the "Slowaris" system call, currently
> BAD_TRAP in the kernel's ttable_32.S.
>
> For sparc64, 0x110 is tl0_linux32, the sparc32 trap, as also
> seen in the adjacent code. We do not implement multiple abis,
> so treat this as !defined(CONFIG_COMPAT), which vectors this
> case to BTRAP. This was presumably a typo for 0x111, which is
> the "old" linux64 syscall number. Both old and new linux64
> syscalls traps vector to LINUX_64BIT_SYSCALL_TRAP.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/sparc/cpu_loop.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
> index c120c42278..18d5c24af1 100644
> --- a/linux-user/sparc/cpu_loop.c
> +++ b/linux-user/sparc/cpu_loop.c
> @@ -167,12 +167,11 @@ void cpu_loop (CPUSPARCState *env)
> }
>
> switch (trapnr) {
> -#ifndef TARGET_SPARC64
> - case 0x88:
> - case 0x90:
> +#ifdef TARGET_SPARC64
> + case TT_TRAP + 0x11: /* tl0_oldlinux64 */
> + case TT_TRAP + 0x6d: /* tl0_linux64 */
> #else
> - case 0x110:
> - case 0x16d:
> + case TT_TRAP + 0x10: /* t_linux */
Bah. I just realized this is wrong. This breaks v8plus.
What's needed is
#ifdef TARGET_ABI32
#define TARGET_TT_SYSCALL TT_TRAP + 0x10
#else
#define TARGET_TT_SYSCALL TT_TRAP + 0x6d
#endif
and ignore tl0_oldlinux64 (0x111), which must be so old
that we've never missed it.
r~
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps
2023-02-02 0:51 ` [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps Richard Henderson
@ 2023-02-02 11:56 ` Ilya Leoshkevich
0 siblings, 0 replies; 18+ messages in thread
From: Ilya Leoshkevich @ 2023-02-02 11:56 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mark.cave-ayland, laurent
On Wed, 2023-02-01 at 14:51 -1000, Richard Henderson wrote:
> The linux kernel's trap tables vector all unassigned trap
> numbers to BAD_TRAP, which then raises SIGILL.
>
> Reported-by: Ilya Leoshkevich <iii@linux.ibm.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/sparc/cpu_loop.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
Thanks!
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 00/14] linux-user/sparc: Handle missing traps
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
` (13 preceding siblings ...)
2023-02-02 0:52 ` [PATCH 14/14] linux-user/sparc: Handle tag overflow traps Richard Henderson
@ 2023-02-05 23:24 ` Mark Cave-Ayland
14 siblings, 0 replies; 18+ messages in thread
From: Mark Cave-Ayland @ 2023-02-05 23:24 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: laurent, iii
On 02/02/2023 00:51, Richard Henderson wrote:
> Lots of missing trap code for cpu_loop().
>
> r~
>
> Richard Henderson (14):
> linux-user/sparc: Raise SIGILL for all unhandled software traps
> linux-user/sparc: Tidy syscall trap
> linux-user/sparc: Use TT_TRAP for flush windows
> linux-user/sparc: Tidy window spill/fill traps
> linux-user/sparc: Fix sparc64_{get,set}_context traps
> linux-user/sparc: Handle software breakpoint trap
> linux-user/sparc: Handle division by zero traps
> linux-user/sparc: Handle getcc, setcc, getpsr traps
> linux-user/sparc: Handle priviledged opcode trap
> linux-user/sparc: Handle privilidged action trap
Minor spelling nit: s/priviledged/privileged/
> linux-user/sparc: Handle coprocessor disabled trap
> linux-user/sparc: Handle unimplemented flush trap
> linux-user/sparc: Handle floating-point exceptions
> linux-user/sparc: Handle tag overflow traps
>
> linux-user/sparc/target_signal.h | 2 +-
> linux-user/syscall_defs.h | 5 +
> target/sparc/cpu.h | 3 +-
> linux-user/sparc/cpu_loop.c | 170 +++++++++++++++++++++++++------
> linux-user/sparc/signal.c | 36 +++----
> 5 files changed, 167 insertions(+), 49 deletions(-)
Alas I'm not overly familiar with the Linux syscall implementation on SPARC (all I
can really do is run a chroot debian ports install for testing), however if all your
local tests pass then I'm happy for this to go via the tcg or linux-user trees.
ATB,
Mark.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2023-02-05 23:24 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-02 0:51 [PATCH 00/14] linux-user/sparc: Handle missing traps Richard Henderson
2023-02-02 0:51 ` [PATCH 01/14] linux-user/sparc: Raise SIGILL for all unhandled software traps Richard Henderson
2023-02-02 11:56 ` Ilya Leoshkevich
2023-02-02 0:51 ` [PATCH 02/14] linux-user/sparc: Tidy syscall trap Richard Henderson
2023-02-02 1:15 ` Richard Henderson
2023-02-02 0:51 ` [PATCH 03/14] linux-user/sparc: Use TT_TRAP for flush windows Richard Henderson
2023-02-02 0:51 ` [PATCH 04/14] linux-user/sparc: Tidy window spill/fill traps Richard Henderson
2023-02-02 0:51 ` [PATCH 05/14] linux-user/sparc: Fix sparc64_{get,set}_context traps Richard Henderson
2023-02-02 0:51 ` [PATCH 06/14] linux-user/sparc: Handle software breakpoint trap Richard Henderson
2023-02-02 0:51 ` [PATCH 07/14] linux-user/sparc: Handle division by zero traps Richard Henderson
2023-02-02 0:51 ` [PATCH 08/14] linux-user/sparc: Handle getcc, setcc, getpsr traps Richard Henderson
2023-02-02 0:51 ` [PATCH 09/14] linux-user/sparc: Handle priviledged opcode trap Richard Henderson
2023-02-02 0:52 ` [PATCH 10/14] linux-user/sparc: Handle privilidged action trap Richard Henderson
2023-02-02 0:52 ` [PATCH 11/14] linux-user/sparc: Handle coprocessor disabled trap Richard Henderson
2023-02-02 0:52 ` [PATCH 12/14] linux-user/sparc: Handle unimplemented flush trap Richard Henderson
2023-02-02 0:52 ` [PATCH 13/14] linux-user/sparc: Handle floating-point exceptions Richard Henderson
2023-02-02 0:52 ` [PATCH 14/14] linux-user/sparc: Handle tag overflow traps Richard Henderson
2023-02-05 23:24 ` [PATCH 00/14] linux-user/sparc: Handle missing traps Mark Cave-Ayland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).