qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: Fix MIPS16/microMIPS signal handling
@ 2013-04-30 14:57 Kwok Cheung Yeung
  0 siblings, 0 replies; 3+ messages in thread
From: Kwok Cheung Yeung @ 2013-04-30 14:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, Kwok Cheung Yeung

Signal handlers written using a compressed MIPS instruction
set will segfault when invoked.  This patch fixes this.

Switch the ISA mode on cores supporting the MIPS16/microMIPS
ISAs according to bit 0 of the signal handler address.  Clear
bit 0 of the address assigned to the PC.

Signed-off-by: Kwok Cheung Yeung <kcy@codesourcery.com>
---
 linux-user/signal.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 1055507..abfb382 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -2662,6 +2662,11 @@ static void setup_frame(int sig, struct target_sigaction * ka,
     * since it returns to userland using eret
     * we cannot do this here, and we must set PC directly */
     regs->active_tc.PC = regs->active_tc.gpr[25] = ka->_sa_handler;
+    if (regs->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        regs->hflags &= ~MIPS_HFLAG_M16;
+        regs->hflags |= (ka->_sa_handler & 1) << MIPS_HFLAG_M16_SHIFT;
+        regs->active_tc.PC &= ~(target_ulong) 1;
+    }
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
@@ -2771,6 +2776,11 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
     * since it returns to userland using eret
     * we cannot do this here, and we must set PC directly */
     env->active_tc.PC = env->active_tc.gpr[25] = ka->_sa_handler;
+    if (env->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        env->hflags &= ~MIPS_HFLAG_M16;
+        env->hflags |= (ka->_sa_handler & 1) << MIPS_HFLAG_M16_SHIFT;
+        env->active_tc.PC &= ~(target_ulong) 1;
+    }
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
-- 
1.8.2.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH] linux-user: Fix MIPS16/microMIPS signal handling
@ 2013-04-30 18:09 Kwok Cheung Yeung
  2013-05-01 10:56 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Kwok Cheung Yeung @ 2013-04-30 18:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, Kwok Cheung Yeung

Signal handlers written using a compressed MIPS instruction
set will segfault when invoked.  This patch fixes this.

Switch the ISA mode on cores supporting the MIPS16/microMIPS
ISAs according to bit 0 of the signal handler address.  Clear
bit 0 of the address assigned to the PC.

Signed-off-by: Kwok Cheung Yeung <kcy@codesourcery.com>
---
 linux-user/signal.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 1055507..abfb382 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -2662,6 +2662,11 @@ static void setup_frame(int sig, struct target_sigaction * ka,
     * since it returns to userland using eret
     * we cannot do this here, and we must set PC directly */
     regs->active_tc.PC = regs->active_tc.gpr[25] = ka->_sa_handler;
+    if (regs->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        regs->hflags &= ~MIPS_HFLAG_M16;
+        regs->hflags |= (ka->_sa_handler & 1) << MIPS_HFLAG_M16_SHIFT;
+        regs->active_tc.PC &= ~(target_ulong) 1;
+    }
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
@@ -2771,6 +2776,11 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
     * since it returns to userland using eret
     * we cannot do this here, and we must set PC directly */
     env->active_tc.PC = env->active_tc.gpr[25] = ka->_sa_handler;
+    if (env->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        env->hflags &= ~MIPS_HFLAG_M16;
+        env->hflags |= (ka->_sa_handler & 1) << MIPS_HFLAG_M16_SHIFT;
+        env->active_tc.PC &= ~(target_ulong) 1;
+    }
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
-- 
1.8.2.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-01 10:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-30 14:57 [Qemu-devel] [PATCH] linux-user: Fix MIPS16/microMIPS signal handling Kwok Cheung Yeung
  -- strict thread matches above, loose matches on Subject: below --
2013-04-30 18:09 Kwok Cheung Yeung
2013-05-01 10:56 ` Peter Maydell

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).