Skip to contentSkip to conversation

Linux user patches

GIT PULL Applied Helge Deller 2 participants 5 messages Aug 7 – Aug 11

lore
Share & tools
lore
#1 lore raw

[PULL 2/3] linux-user/sh4: Initialize the FPSCR register on signal

In reply to Helge Deller

From: Mikulas Patocka <[email protected]>

On the SH4 architecture, the instructions that perform single precision and double precision floating point operations are encoded in the same way. The bit PR in the FPSCR register determines if the CPU performs single or double operation.

According to the ABI, the PR bit must be set at function entry and function exit.

GCC generates code that flips this bit as needed during function execution. If we get a signal, we must set the PR bit, so that the signal handler finds the bit in the expected state. Qemu lacked this logic, so that if the signal interrupts single-precision floating point calculation, the PR bit would be incorrectly clear at signal handler entry. If the signal handler performed some floating-point calculation, it would get incorrect result.

This patch fixes the bug, by initializing the FPSCR register at signal entry. Note that we initialize the whole register, because the Linux kernel initializes the whole register too.

---
 linux-user/sh4/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/sh4/signal.c +4 -0
index 00290d6e40..7f246e750d 100644
@@ -206,6 +206,8 @@ void setup_frame(int sig, struct target_sigaction *ka,
         __put_user(set->sig[i + 1], &frame->extramask[i]);
     }
 
+    regs->fpscr = FPSCR_PR;
+
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */
     if (ka->sa_flags & TARGET_SA_RESTORER) {
@@ -258,6 +260,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
         __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
     }
 
+    regs->fpscr = FPSCR_PR;
+
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */
     if (ka->sa_flags & TARGET_SA_RESTORER) {
Signature · 1 line
2.54.0
#2 lore raw

[PULL 1/3] linux-user/sh4: Deliver SIGILL on invalid instruction

In reply to Helge Deller

From: Mikulas Patocka <[email protected]>

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

---
 linux-user/sh4/cpu_loop.c | 7 +++++++
 1 file changed, 7 insertions(+)
linux-user/sh4/cpu_loop.c +7 -0
index ee2958d0d9..0815b9c9bf 100644
@@ -64,6 +64,13 @@ void cpu_loop(CPUSH4State *env)
             cpu_exec_step_atomic(cs);
             arch_interrupt = false;
             break;
+        case 0x180:
+            /* Illegal instruction */
+            /* fallthrough */
+        case 0x1a0:
+            /* Illegal instruction in delay slot */
+            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
2.54.0
#0 lore raw

From: Helge Deller <[email protected]>

The following changes since commit 3e3ccab106f879b1512f8e0d51a827dd4de30e22:

Update version for v11.1.0-rc3 release (2026-08-04 15:36:08 -0400)

are available in the Git repository at:

https://github.com/hdeller/qemu-hppa.git tags/linux-user-pull-request

for you to fetch changes up to f7ad7b1f8c8148f39bc1f2c984bfc7b7c9c59041:

linux-user/sh4: Fix crashes on signal delivery in conditional delay slot (2026-08-07 15:13:36 +0200)

----------------------------------------------------------------
linux-user sh4 signal patches

Three important small signal handling fixes for the sh4 architecture from Mikulas Patocka.

----------------------------------------------------------------

Mikulas Patocka (3):
linux-user/sh4: Deliver SIGILL on invalid instruction linux-user/sh4: Initialize the FPSCR register on signal linux-user/sh4: Fix crashes on signal delivery in conditional delay
slot

 linux-user/sh4/cpu_loop.c | 7 +++++++
 linux-user/sh4/signal.c   | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0
#3 lore raw

[PULL 3/3] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot

From: Mikulas Patocka <[email protected]>

If we get a signal in the delay slot, we must roll-back the PC to the jump instruction. This was already fixed by the commit 3b894b699c9a ("linux-user/sh4: Fix crashes on signal delivery"), however this fix omits a test for TB_FLAG_DELAY_SLOT_COND. TB_FLAG_DELAY_SLOT_COND is set by the conditional delayed branches bf/s and bt/s. Qemu did not roll-back the PC in this case, resulting in incorrect program execution.

This patch fixes it.

---
 linux-user/sh4/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/sh4/signal.c +1 -1
index 7f246e750d..047174ac8f 100644
@@ -109,7 +109,7 @@ static void unwind_gusa(CPUSH4State *regs)
            the SP, otherwise we would be pushing the signal context to
            invalid memory.  */
         regs->gregs[15] = regs->gregs[1];
-    } else if (regs->flags & TB_FLAG_DELAY_SLOT) {
+    } else if (regs->flags & (TB_FLAG_DELAY_SLOT | TB_FLAG_DELAY_SLOT_COND)) {
         /* If we are in a delay slot, push the previous instruction.  */
         regs->pc -= 2;
     }
Signature · 1 line
2.54.0