qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [PATCH v2 2/2] linux-user/m68k: Handle EXCP_ADDRESS in cpu_loop
Date: Thu,  9 Mar 2023 12:16:04 -0800	[thread overview]
Message-ID: <20230309201604.3885359-3-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230309201604.3885359-1-richard.henderson@linaro.org>

This exception can be raised by illegal instructions.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/m68k/cpu_loop.c     |  5 ++++-
 tests/tcg/m68k/excp-address.c  | 32 ++++++++++++++++++++++++++++++++
 tests/tcg/m68k/Makefile.target |  1 +
 3 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/m68k/excp-address.c

diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c
index caead1cb74..84b5d290c0 100644
--- a/linux-user/m68k/cpu_loop.c
+++ b/linux-user/m68k/cpu_loop.c
@@ -35,7 +35,10 @@ void cpu_loop(CPUM68KState *env)
         cpu_exec_end(cs);
         process_queued_cpu_work(cs);
 
-        switch(trapnr) {
+        switch (trapnr) {
+        case EXCP_ADDRESS:
+            force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, env->pc);
+            break;
         case EXCP_ILLEGAL:
         case EXCP_LINEA:
         case EXCP_LINEF:
diff --git a/tests/tcg/m68k/excp-address.c b/tests/tcg/m68k/excp-address.c
new file mode 100644
index 0000000000..1dbdddef58
--- /dev/null
+++ b/tests/tcg/m68k/excp-address.c
@@ -0,0 +1,32 @@
+/*
+ * Test m68k address exception
+ */
+
+#define _GNU_SOURCE 1
+#include <signal.h>
+#include <stdlib.h>
+
+static void sig_handler(int sig, siginfo_t *si, void *puc)
+{
+    exit(0);
+}
+
+int main(int argc, char **argv)
+{
+    struct sigaction act = {
+        .sa_sigaction = sig_handler,
+        .sa_flags = SA_SIGINFO
+    };
+
+    sigaction(SIGBUS, &act, NULL);
+
+    /*
+     * addl %d0,#0 -- with immediate as destination is illegal.
+     * Buggy qemu interpreted the insn as 5 words: 2 for immediate source
+     * and another 2 for immediate destination.  Provide all that padding
+     * so that abort gets called.
+     */
+    asm volatile(".word 0xd1bc,0,0,0,0");
+
+    abort();
+}
diff --git a/tests/tcg/m68k/Makefile.target b/tests/tcg/m68k/Makefile.target
index 1163c7ef03..d3b0bc48a3 100644
--- a/tests/tcg/m68k/Makefile.target
+++ b/tests/tcg/m68k/Makefile.target
@@ -4,6 +4,7 @@
 #
 
 VPATH += $(SRC_PATH)/tests/tcg/m68k
+TESTS += excp-address
 TESTS += trap
 
 # On m68k Linux supports 4k and 8k pages (but 8k is currently broken)
-- 
2.34.1



  parent reply	other threads:[~2023-03-09 20:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 20:16 [PATCH v2 0/2] target/m68k: Reject immediate as destination Richard Henderson
2023-03-09 20:16 ` [PATCH v2 1/2] target/m68k: Reject immediate as destination in gen_ea_mode Richard Henderson
2023-03-10 10:03   ` Laurent Vivier
2023-03-15 16:41   ` Laurent Vivier
2023-03-09 20:16 ` Richard Henderson [this message]
2023-03-15 18:16   ` [PATCH v2 2/2] linux-user/m68k: Handle EXCP_ADDRESS in cpu_loop Laurent Vivier
2023-03-16 14:23     ` 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=20230309201604.3885359-3-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.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 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).