From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, laurent@vivier.eu
Subject: [PATCH v3 16/27] linux-user/nios2: Properly emulate EXCP_TRAP
Date: Fri, 24 Sep 2021 12:59:15 -0400 [thread overview]
Message-ID: <20210924165926.752809-17-richard.henderson@linaro.org> (raw)
In-Reply-To: <20210924165926.752809-1-richard.henderson@linaro.org>
The real kernel has to load the instruction and extract
the imm5 field; for qemu, modify the translator to do this.
The use of R_AT for this in cpu_loop was a bug. Handle
the other trap numbers as per the kernel's trap_table.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/nios2/cpu.h | 5 +++--
linux-user/nios2/cpu_loop.c | 35 ++++++++++++++++++-----------------
target/nios2/translate.c | 17 ++++++++++++++++-
3 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 2ab82fdc71..395e4d3281 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -158,9 +158,10 @@ struct Nios2CPUClass {
struct CPUNios2State {
uint32_t regs[NUM_CORE_REGS];
-#if !defined(CONFIG_USER_ONLY)
+#ifdef CONFIG_USER_ONLY
+ int trap_code;
+#else
Nios2MMU mmu;
-
uint32_t irq_pending;
#endif
};
diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index 34290fb3b5..246293a501 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -39,9 +39,10 @@ void cpu_loop(CPUNios2State *env)
case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */
break;
+
case EXCP_TRAP:
- if (env->regs[R_AT] == 0) {
- abi_long ret;
+ switch (env->trap_code) {
+ case 0:
qemu_log_mask(CPU_LOG_INT, "\nSyscall\n");
ret = do_syscall(env, env->regs[2],
@@ -55,26 +56,26 @@ void cpu_loop(CPUNios2State *env)
env->regs[2] = abs(ret);
/* Return value is 0..4096 */
- env->regs[7] = (ret > 0xfffffffffffff000ULL);
- env->regs[CR_ESTATUS] = env->regs[CR_STATUS];
- env->regs[CR_STATUS] &= ~0x3;
- env->regs[R_EA] = env->regs[R_PC] + 4;
+ env->regs[7] = ret > 0xfffff000u;
env->regs[R_PC] += 4;
break;
- } else {
- qemu_log_mask(CPU_LOG_INT, "\nTrap\n");
- env->regs[CR_ESTATUS] = env->regs[CR_STATUS];
- env->regs[CR_STATUS] &= ~0x3;
- env->regs[R_EA] = env->regs[R_PC] + 4;
- env->regs[R_PC] = cpu->exception_addr;
-
- info.si_signo = TARGET_SIGTRAP;
- info.si_errno = 0;
- info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+ case 1:
+ qemu_log_mask(CPU_LOG_INT, "\nTrap 1\n");
+ force_sig_fault(TARGET_SIGUSR1, 0, env->regs[R_PC]);
+ break;
+ case 2:
+ qemu_log_mask(CPU_LOG_INT, "\nTrap 2\n");
+ force_sig_fault(TARGET_SIGUSR2, 0, env->regs[R_PC]);
+ break;
+ default:
+ qemu_log_mask(CPU_LOG_INT, "\nTrap %d\n", env->trap_code);
+ force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLTRP,
+ env->regs[R_PC]);
break;
}
+ break;
+
case EXCP_DEBUG:
info.si_signo = TARGET_SIGTRAP;
info.si_errno = 0;
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index 08d7ac5398..485b487665 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -636,6 +636,21 @@ static void divu(DisasContext *dc, uint32_t code, uint32_t flags)
tcg_temp_free(t0);
}
+static void trap(DisasContext *dc, uint32_t code, uint32_t flags)
+{
+#ifdef CONFIG_USER_ONLY
+ /*
+ * The imm5 field is not stored anywhere on real hw; the kernel
+ * has to load the insn and extract the field. But we can make
+ * things easier for cpu_loop if we pop this into env->trap_code.
+ */
+ R_TYPE(instr, code);
+ tcg_gen_st_i32(tcg_constant_i32(instr.imm5), cpu_env,
+ offsetof(CPUNios2State, trap_code));
+#endif
+ t_gen_helper_raise_exception(dc, EXCP_TRAP);
+}
+
static const Nios2Instruction r_type_instructions[] = {
INSTRUCTION_ILLEGAL(),
INSTRUCTION(eret), /* eret */
@@ -682,7 +697,7 @@ static const Nios2Instruction r_type_instructions[] = {
INSTRUCTION_ILLEGAL(),
INSTRUCTION_ILLEGAL(),
INSTRUCTION_ILLEGAL(),
- INSTRUCTION_FLG(gen_excp, EXCP_TRAP), /* trap */
+ INSTRUCTION(trap), /* trap */
INSTRUCTION(wrctl), /* wrctl */
INSTRUCTION_ILLEGAL(),
INSTRUCTION_FLG(gen_cmpxx, TCG_COND_LTU), /* cmpltu */
--
2.25.1
next prev parent reply other threads:[~2021-09-24 17:01 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-24 16:58 [PATCH v3 00/27] linux-user: Move signal trampolines to new page Richard Henderson
2021-09-24 16:59 ` [PATCH v3 01/27] linux-user: Add infrastructure for a signal trampoline page Richard Henderson
2021-09-24 16:59 ` [PATCH v3 02/27] linux-user/aarch64: Implement setup_sigtramp Richard Henderson
2021-09-24 16:59 ` [PATCH v3 03/27] linux-user/arm: Drop v1 signal frames Richard Henderson
2021-09-24 16:59 ` [PATCH v3 04/27] linux-user/arm: Drop "_v2" from symbols in signal.c Richard Henderson
2021-09-24 16:59 ` [PATCH v3 05/27] linux-user/arm: Implement setup_sigtramp Richard Henderson
2021-09-27 11:06 ` Peter Maydell
2021-09-24 16:59 ` [PATCH v3 06/27] linux-user/alpha: " Richard Henderson
2021-09-24 16:59 ` [PATCH v3 07/27] linux-user/cris: " Richard Henderson
2021-09-24 16:59 ` [PATCH v3 08/27] linux-user/hexagon: " Richard Henderson
2021-09-24 18:49 ` Taylor Simpson
2021-09-24 16:59 ` [PATCH v3 09/27] linux-user/hppa: Document non-use of setup_sigtramp Richard Henderson
2021-09-24 16:59 ` [PATCH v3 10/27] linux-user/i386: Implement setup_sigtramp Richard Henderson
2021-09-24 18:01 ` Philippe Mathieu-Daudé
2021-09-28 1:42 ` Richard Henderson
2021-09-28 6:50 ` Philippe Mathieu-Daudé
2021-09-24 16:59 ` [PATCH v3 11/27] linux-user/x86_64: Raise SIGSEGV if SA_RESTORER not set Richard Henderson
2021-09-27 13:01 ` Peter Maydell
2021-09-24 16:59 ` [PATCH v3 12/27] linux-user/m68k: Implement setup_sigtramp Richard Henderson
2021-09-24 16:59 ` [PATCH v3 13/27] linux-user/microblaze: " Richard Henderson
2021-09-24 16:59 ` [PATCH v3 14/27] linux-user/mips: Tidy install_sigtramp Richard Henderson
2021-09-24 16:59 ` [PATCH v3 15/27] linux-user/mips: Implement setup_sigtramp Richard Henderson
2021-09-24 16:59 ` Richard Henderson [this message]
2021-09-27 13:23 ` [PATCH v3 16/27] linux-user/nios2: Properly emulate EXCP_TRAP Peter Maydell
2021-09-27 14:30 ` Richard Henderson
2021-09-24 16:59 ` [PATCH v3 17/27] linux-user/nios2: Map a real kuser page Richard Henderson
2021-09-27 13:26 ` Peter Maydell
2021-09-27 13:59 ` Richard Henderson
2021-09-24 16:59 ` [PATCH v3 18/27] linux-user/nios2: Fixes for signal frame setup Richard Henderson
2021-09-27 13:28 ` Peter Maydell
2021-09-24 16:59 ` [PATCH v3 19/27] linux-user/openrisc: Implement setup_sigtramp Richard Henderson
2021-09-24 16:59 ` [PATCH v3 20/27] linux-user/ppc: Simplify encode_trampoline Richard Henderson
2021-09-24 17:55 ` Philippe Mathieu-Daudé
2021-09-24 16:59 ` [PATCH v3 21/27] linux-user/ppc: Implement setup_sigtramp Richard Henderson
2021-09-27 13:34 ` Peter Maydell
2021-09-24 16:59 ` [PATCH v3 22/27] linux-user/riscv: " Richard Henderson
2021-09-24 16:59 ` [PATCH v3 23/27] linux-user/s390x: " Richard Henderson
2021-09-24 16:59 ` [PATCH v3 24/27] linux-user/sh4: " Richard Henderson
2021-09-24 16:59 ` [PATCH v3 25/27] linux-user/sparc: " Richard Henderson
2021-09-27 13:30 ` Peter Maydell
2021-09-24 16:59 ` [PATCH v3 26/27] linux-user/xtensa: " Richard Henderson
2021-09-24 17:53 ` Philippe Mathieu-Daudé
2021-09-24 16:59 ` [PATCH v3 27/27] linux-user: Remove default for TARGET_ARCH_HAS_SIGTRAMP_PAGE 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=20210924165926.752809-17-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=peter.maydell@linaro.org \
--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).