All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu, "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH v4 14/24] linux-user/mips: Improve do_break
Date: Mon, 20 Dec 2021 13:05:18 -0800	[thread overview]
Message-ID: <20211220210529.150423-15-richard.henderson@linaro.org> (raw)
In-Reply-To: <20211220210529.150423-1-richard.henderson@linaro.org>

Rename to do_tr_or_bp, as per the kernel function.
Add a 'trap' argument, akin to the kernel's si_code, but clearer.
The return value is always 0, so change the return value to void.
Use force_sig and force_sig_fault.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/mips/cpu_loop.c | 46 +++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index b735c99a24..7317194cc3 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -40,29 +40,25 @@ enum {
     BRK_DIVZERO = 7
 };
 
-static int do_break(CPUMIPSState *env, target_siginfo_t *info,
-                    unsigned int code)
+static void do_tr_or_bp(CPUMIPSState *env, unsigned int code, bool trap)
 {
-    int ret = -1;
+    target_ulong pc = env->active_tc.PC;
 
     switch (code) {
     case BRK_OVERFLOW:
+        force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, pc);
+        break;
     case BRK_DIVZERO:
-        info->si_signo = TARGET_SIGFPE;
-        info->si_errno = 0;
-        info->si_code = (code == BRK_OVERFLOW) ? FPE_INTOVF : FPE_INTDIV;
-        queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info);
-        ret = 0;
+        force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, pc);
         break;
     default:
-        info->si_signo = TARGET_SIGTRAP;
-        info->si_errno = 0;
-        queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info);
-        ret = 0;
+        if (trap) {
+            force_sig(TARGET_SIGTRAP);
+        } else {
+            force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, pc);
+        }
         break;
     }
-
-    return ret;
 }
 
 void cpu_loop(CPUMIPSState *env)
@@ -205,6 +201,13 @@ done_syscall:
                 abi_ulong trap_instr;
                 unsigned int code;
 
+                /*
+                 * FIXME: It would be better to decode the trap number
+                 * during translate, and store it in error_code while
+                 * raising the exception.  We should not be re-reading
+                 * the opcode here.
+                 */
+
                 if (env->hflags & MIPS_HFLAG_M16) {
                     if (env->insn_flags & ASE_MICROMIPS) {
                         /* microMIPS mode */
@@ -257,9 +260,7 @@ done_syscall:
                     }
                 }
 
-                if (do_break(env, &info, code) != 0) {
-                    goto error;
-                }
+                do_tr_or_bp(env, code, false);
             }
             break;
         case EXCP_TRAP:
@@ -267,6 +268,13 @@ done_syscall:
                 abi_ulong trap_instr;
                 unsigned int code = 0;
 
+                /*
+                 * FIXME: It would be better to decode the trap number
+                 * during translate, and store it in error_code while
+                 * raising the exception.  We should not be re-reading
+                 * the opcode here.
+                 */
+
                 if (env->hflags & MIPS_HFLAG_M16) {
                     /* microMIPS mode */
                     abi_ulong instr[2];
@@ -293,9 +301,7 @@ done_syscall:
                     }
                 }
 
-                if (do_break(env, &info, code) != 0) {
-                    goto error;
-                }
+                do_tr_or_bp(env, code, true);
             }
             break;
         case EXCP_ATOMIC:
-- 
2.25.1



  parent reply	other threads:[~2021-12-20 21:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 21:05 [PATCH v4 00/24] linux-user: Clean up siginfo_t handling Richard Henderson
2021-12-20 21:05 ` [PATCH v4 01/24] linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap Richard Henderson
2021-12-20 21:05 ` [PATCH v4 02/24] linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND Richard Henderson
2021-12-20 21:05 ` [PATCH v4 03/24] linux-user/alpha: Use force_sig_fault Richard Henderson
2021-12-20 21:05 ` [PATCH v4 04/24] linux-user/cris: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 05/24] linux-user/hppa: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 06/24] linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG, OVERFLOW Richard Henderson
2021-12-20 21:05 ` [PATCH v4 07/24] linux-user: Remove TARGET_NSIGFPE Richard Henderson
2021-12-20 22:42   ` Philippe Mathieu-Daudé
2021-12-20 21:05 ` [PATCH v4 08/24] linux-user/hppa: Set FPE_CONDTRAP for COND Richard Henderson
2021-12-20 22:44   ` Philippe Mathieu-Daudé
2021-12-20 21:05 ` [PATCH v4 09/24] linux-user/i386: Split out maybe_handle_vm86_trap Richard Henderson
2021-12-20 21:05 ` [PATCH v4 10/24] linux-user/i386: Use force_sig, force_sig_fault Richard Henderson
2021-12-20 21:05 ` [PATCH v4 11/24] linux-user/m68k: Use force_sig_fault Richard Henderson
2021-12-20 21:05 ` [PATCH v4 12/24] linux-user/microblaze: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 13/24] linux-user/microblaze: Fix SIGFPE si_codes Richard Henderson
2021-12-20 21:05 ` Richard Henderson [this message]
2021-12-20 21:05 ` [PATCH v4 15/24] linux-user/mips: Use force_sig_fault Richard Henderson
2021-12-20 21:05 ` [PATCH v4 16/24] target/mips: Extract break code into env->error_code Richard Henderson
2021-12-20 21:05 ` [PATCH v4 17/24] target/mips: Extract trap " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 18/24] linux-user/openrisc: Use force_sig_fault Richard Henderson
2021-12-20 21:05 ` [PATCH v4 19/24] linux-user/ppc: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 20/24] linux-user/riscv: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 21/24] linux-user/s390x: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 22/24] linux-user/sh4: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 23/24] linux-user/sparc: " Richard Henderson
2021-12-20 21:05 ` [PATCH v4 24/24] linux-user/xtensa: " Richard Henderson

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=20211220210529.150423-15-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=f4bug@amsat.org \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    /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.