Skip to contentSkip to conversation

linux-user/sh4: Deliver SIGILL on invalid instruction

PATCH Superseded Mikulas Patocka 3 participants 4 messages Aug 3 – Aug 5

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/sh4: Deliver SIGILL on invalid instruction

On invalid instruction, deliver SIGILL rather than crashing the whole process unconditionally.

---
 linux-user/sh4/cpu_loop.c |    4 ++++
 1 file changed, 4 insertions(+)
linux-user/sh4/cpu_loop.c +4 -0
Index: qemu/linux-user/sh4/cpu_loop.c
===================================================================
@@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
             cpu_exec_step_atomic(cs);
             arch_interrupt = false;
             break;
+        case 0x180:
+            /* Illegal instruction */
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
+            break;
         default:
             fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, 0);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Mikulas Patocka

On invalid instruction, deliver SIGILL rather than crashing the whole process unconditionally.

---
 linux-user/sh4/cpu_loop.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: qemu/linux-user/sh4/cpu_loop.c
===================================================================

linux-user/sh4/cpu_loop.c void cpu_loop(CPUSH4State *env) · line 73

Quoted 10 lines
linux-user/sh4/cpu_loop.c +4 -0
@@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
             cpu_exec_step_atomic(cs);
             arch_interrupt = false;
             break;
+        case 0x180:
+            /* Illegal instruction */
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
+            break;
         default:
             fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, 0);
Signature · 1 line
Yosinori Sato
#2 lore raw
In reply to Mikulas Patocka
Quoted 16 lines · Mikulas Patocka

On invalid instruction, deliver SIGILL rather than crashing the whole process unconditionally.

---
  linux-user/sh4/cpu_loop.c |    4 ++++
  1 file changed, 4 insertions(+)

Index: qemu/linux-user/sh4/cpu_loop.c
===================================================================

linux-user/sh4/cpu_loop.c void cpu_loop(CPUSH4State *env) · line 73

Quoted 10 lines
linux-user/sh4/cpu_loop.c +4 -0
@@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
              cpu_exec_step_atomic(cs);
              arch_interrupt = false;
              break;
+        case 0x180:
+            /* Illegal instruction */
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
+            break;
          default:
              fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
              cpu_dump_state(cs, stderr, 0);

Missing 0x1a0, from helper_raise_slot_illegal_instruction.

r~

#3 lore raw
Quoted 31 lines · Richard Henderson
Quoted 17 lines · Mikulas Patocka

On invalid instruction, deliver SIGILL rather than crashing the whole process unconditionally.

---
  linux-user/sh4/cpu_loop.c |    4 ++++
  1 file changed, 4 insertions(+)

Index: qemu/linux-user/sh4/cpu_loop.c
===================================================================
--- qemu.orig/linux-user/sh4/cpu_loop.c 2026-08-02 19:02:25.000000000
+0200
+++ qemu/linux-user/sh4/cpu_loop.c 2026-08-02 19:06:40.000000000 +0200

linux-user/sh4/cpu_loop.c void cpu_loop(CPUSH4State *env) · line 73

Quoted 10 lines
linux-user/sh4/cpu_loop.c +4 -0
@@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
              cpu_exec_step_atomic(cs);
              arch_interrupt = false;
              break;
+        case 0x180:
+            /* Illegal instruction */
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
+            break;
          default:
              fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
              cpu_dump_state(cs, stderr, 0);

Missing 0x1a0, from helper_raise_slot_illegal_instruction.

Quoted 1 line

r~

OK, I'm sending version 2 of the patch.

Mikulas