linux-user/riscv: Use force_sig_fault

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.  Fix missing PC from EXCP_DEBUG by
merging the case with EXCP_BREAKPOINT.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220107213243.212806-21-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Richard Henderson 2022-01-07 13:32:39 -08:00 committed by Laurent Vivier
parent d30e60e7b4
commit 8521cc21ad
1 changed files with 5 additions and 26 deletions

View File

@ -30,8 +30,7 @@
void cpu_loop(CPURISCVState *env) void cpu_loop(CPURISCVState *env)
{ {
CPUState *cs = env_cpu(env); CPUState *cs = env_cpu(env);
int trapnr, signum, sigcode; int trapnr;
target_ulong sigaddr;
target_ulong ret; target_ulong ret;
for (;;) { for (;;) {
@ -40,10 +39,6 @@ void cpu_loop(CPURISCVState *env)
cpu_exec_end(cs); cpu_exec_end(cs);
process_queued_cpu_work(cs); process_queued_cpu_work(cs);
signum = 0;
sigcode = 0;
sigaddr = 0;
switch (trapnr) { switch (trapnr) {
case EXCP_INTERRUPT: case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */ /* just indicate that signals should be handled asap */
@ -79,39 +74,23 @@ void cpu_loop(CPURISCVState *env)
} }
break; break;
case RISCV_EXCP_ILLEGAL_INST: case RISCV_EXCP_ILLEGAL_INST:
signum = TARGET_SIGILL; force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
sigcode = TARGET_ILL_ILLOPC;
break; break;
case RISCV_EXCP_BREAKPOINT: case RISCV_EXCP_BREAKPOINT:
signum = TARGET_SIGTRAP; case EXCP_DEBUG:
sigcode = TARGET_TRAP_BRKPT; gdbstep:
sigaddr = env->pc; force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
break; break;
case RISCV_EXCP_SEMIHOST: case RISCV_EXCP_SEMIHOST:
env->gpr[xA0] = do_common_semihosting(cs); env->gpr[xA0] = do_common_semihosting(cs);
env->pc += 4; env->pc += 4;
break; break;
case EXCP_DEBUG:
gdbstep:
signum = TARGET_SIGTRAP;
sigcode = TARGET_TRAP_BRKPT;
break;
default: default:
EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n", EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",
trapnr); trapnr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (signum) {
target_siginfo_t info = {
.si_signo = signum,
.si_errno = 0,
.si_code = sigcode,
._sifields._sigfault._addr = sigaddr
};
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
}
process_pending_signals(env); process_pending_signals(env);
} }
} }