All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kwok Cheung Yeung <kcy@codesourcery.com>
To: qemu-devel@nongnu.org
Cc: Kwok Cheung Yeung <kcy@codesourcery.com>,
	peter.maydell@linaro.org, riku.voipio@iki.fi,
	aurelien@aurel32.net
Subject: [Qemu-devel] [PATCH v2 1/2] linux-user: Fix MIPS ISA transitions during signal handling
Date: Fri, 17 May 2013 14:51:20 -0700	[thread overview]
Message-ID: <1368827481-20434-2-git-send-email-kcy@codesourcery.com> (raw)
In-Reply-To: <1368827481-20434-1-git-send-email-kcy@codesourcery.com>

Processors supporting the MIPS16 or microMIPS ISAs set bit 0 in target
addresses to indicate that the target is written using a compressed ISA.

During signal handling, when jumping to or returning from a signal
handler, bit 0 of the destination PC is inspected and MIPS_HFLAG_M16 in
hflags cleared or set accordingly.  Bit 0 of the PC is then cleared.

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

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 1055507..dc34ae7 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -2620,6 +2620,15 @@ get_sigframe(struct target_sigaction *ka, CPUMIPSState *regs, size_t frame_size)
     return (sp - frame_size) & ~7;
 }
 
+static void mips_set_hflags_isa_mode_from_pc(CPUMIPSState *env)
+{
+    if (env->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {
+        env->hflags &= ~MIPS_HFLAG_M16;
+        env->hflags |= (env->active_tc.PC & 1) << MIPS_HFLAG_M16_SHIFT;
+        env->active_tc.PC &= ~(target_ulong) 1;
+    }
+}
+
 # if defined(TARGET_ABI_MIPSO32)
 /* compare linux/arch/mips/kernel/signal.c:setup_frame() */
 static void setup_frame(int sig, struct target_sigaction * ka,
@@ -2662,6 +2671,7 @@ 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;
+    mips_set_hflags_isa_mode_from_pc(regs);
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
@@ -2709,6 +2719,7 @@ long do_sigreturn(CPUMIPSState *regs)
 #endif
 
     regs->active_tc.PC = regs->CP0_EPC;
+    mips_set_hflags_isa_mode_from_pc(regs);
     /* I am not sure this is right, but it seems to work
     * maybe a problem with nested signals ? */
     regs->CP0_EPC = 0;
@@ -2771,6 +2782,7 @@ 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;
+    mips_set_hflags_isa_mode_from_pc(env);
     unlock_user_struct(frame, frame_addr, 1);
     return;
 
@@ -2804,6 +2816,7 @@ long do_rt_sigreturn(CPUMIPSState *env)
         goto badframe;
 
     env->active_tc.PC = env->CP0_EPC;
+    mips_set_hflags_isa_mode_from_pc(env);
     /* I am not sure this is right, but it seems to work
     * maybe a problem with nested signals ? */
     env->CP0_EPC = 0;
-- 
1.8.1.2

  reply	other threads:[~2013-05-17 21:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-17 21:51 [Qemu-devel] [PATCH v2 0/2] linux-user: Fix MIPS16/microMIPS signal handling Kwok Cheung Yeung
2013-05-17 21:51 ` Kwok Cheung Yeung [this message]
2013-05-17 21:51 ` [Qemu-devel] [PATCH v2 2/2] linux-user: Save the correct resume address for MIPS " Kwok Cheung Yeung
2013-05-19 21:42 ` [Qemu-devel] [PATCH v2 0/2] linux-user: Fix MIPS16/microMIPS " Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1368827481-20434-2-git-send-email-kcy@codesourcery.com \
    --to=kcy@codesourcery.com \
    --cc=aurelien@aurel32.net \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.