aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <rth@twiddle.net>2015-09-27 14:26:04 -0700
committerRichard Henderson <rth@twiddle.net>2015-10-07 20:03:15 +1100
commita0577d2aa9bd42d5d584fa03649a166ba45c2f3d (patch)
tree3aefc90eb42de4c32213479c96d94bdfc2115dd1
parentdd8070d865ad1b32876931f812a80645f97112ff (diff)
target-tilegx: Use TILEGX_EXCP_SIGNAL instead of TILEGX_EXCP_SEGV
Consolidate signal handling under a single exception. Signed-off-by: Richard Henderson <rth@twiddle.net>
-rw-r--r--linux-user/main.c41
-rw-r--r--target-tilegx/cpu.c7
-rw-r--r--target-tilegx/cpu.h3
3 files changed, 30 insertions, 21 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index 9e8b92b03c..1f60ff2a1f 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3414,17 +3414,6 @@ void cpu_loop(CPUS390XState *env)
#ifdef TARGET_TILEGX
-static void gen_sigsegv_maperr(CPUTLGState *env, target_ulong addr)
-{
- target_siginfo_t info;
-
- info.si_signo = TARGET_SIGSEGV;
- info.si_errno = 0;
- info.si_code = TARGET_SEGV_MAPERR;
- info._sifields._sigfault._addr = addr;
- queue_signal(env, info.si_signo, &info);
-}
-
static void gen_sigill_reg(CPUTLGState *env)
{
target_siginfo_t info;
@@ -3436,17 +3425,36 @@ static void gen_sigill_reg(CPUTLGState *env)
queue_signal(env, info.si_signo, &info);
}
-static void do_signal(CPUTLGState *env)
+static void do_signal(CPUTLGState *env, int signo, int sigcode)
{
target_siginfo_t info;
- info.si_signo = env->signo;
+ info.si_signo = signo;
info.si_errno = 0;
- info.si_code = env->sigcode;
info._sifields._sigfault._addr = env->pc;
+
+ if (signo == TARGET_SIGSEGV) {
+ /* The passed in sigcode is a dummy; check for a page mapping
+ and pass either MAPERR or ACCERR. */
+ target_ulong addr = env->excaddr;
+ info._sifields._sigfault._addr = addr;
+ if (page_check_range(addr, 1, PAGE_VALID) < 0) {
+ sigcode = TARGET_SEGV_MAPERR;
+ } else {
+ sigcode = TARGET_SEGV_ACCERR;
+ }
+ }
+ info.si_code = sigcode;
+
queue_signal(env, info.si_signo, &info);
}
+static void gen_sigsegv_maperr(CPUTLGState *env, target_ulong addr)
+{
+ env->excaddr = addr;
+ do_signal(env, TARGET_SIGSEGV, 0);
+}
+
static void set_regval(CPUTLGState *env, uint8_t reg, uint64_t val)
{
if (unlikely(reg >= TILEGX_R_COUNT)) {
@@ -3634,15 +3642,12 @@ void cpu_loop(CPUTLGState *env)
do_fetch(env, trapnr, false);
break;
case TILEGX_EXCP_SIGNAL:
- do_signal(env);
+ do_signal(env, env->signo, env->sigcode);
break;
case TILEGX_EXCP_REG_IDN_ACCESS:
case TILEGX_EXCP_REG_UDN_ACCESS:
gen_sigill_reg(env);
break;
- case TILEGX_EXCP_SEGV:
- gen_sigsegv_maperr(env, env->excaddr);
- break;
default:
fprintf(stderr, "trapnr is %d[0x%x].\n", trapnr, trapnr);
g_assert_not_reached();
diff --git a/target-tilegx/cpu.c b/target-tilegx/cpu.c
index 78b73e45c4..3c5481d443 100644
--- a/target-tilegx/cpu.c
+++ b/target-tilegx/cpu.c
@@ -22,6 +22,7 @@
#include "qemu-common.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
+#include "linux-user/syscall_defs.h"
static void tilegx_cpu_dump_state(CPUState *cs, FILE *f,
fprintf_function cpu_fprintf, int flags)
@@ -121,8 +122,12 @@ static int tilegx_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
{
TileGXCPU *cpu = TILEGX_CPU(cs);
- cs->exception_index = TILEGX_EXCP_SEGV;
+ /* The sigcode field will be filled in by do_signal in main.c. */
+ cs->exception_index = TILEGX_EXCP_SIGNAL;
cpu->env.excaddr = address;
+ cpu->env.signo = TARGET_SIGSEGV;
+ cpu->env.sigcode = 0;
+
return 1;
}
diff --git a/target-tilegx/cpu.h b/target-tilegx/cpu.h
index 023ccd4735..6f04fe7fb2 100644
--- a/target-tilegx/cpu.h
+++ b/target-tilegx/cpu.h
@@ -60,8 +60,7 @@ enum {
typedef enum {
TILEGX_EXCP_NONE = 0,
TILEGX_EXCP_SYSCALL = 1,
- TILEGX_EXCP_SEGV = 2,
- TILEGX_EXCP_SIGNAL = 3,
+ TILEGX_EXCP_SIGNAL = 2,
TILEGX_EXCP_OPCODE_UNKNOWN = 0x101,
TILEGX_EXCP_OPCODE_UNIMPLEMENTED = 0x102,
TILEGX_EXCP_OPCODE_CMPEXCH = 0x103,