Skip to content

Commit

Permalink
alpha-linux-user: Implement signals.
Browse files Browse the repository at this point in the history
Move userland PALcode handling into linux-user main loop so that
we can send signals from there.  This also makes alpha_palcode.c
system-level only, so don't build it for userland.  Add defines
for GENTRAP PALcall mapping to signals.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
  • Loading branch information
rth7680 authored and aurel32 committed Feb 28, 2010
1 parent f24518b commit 6049f4f
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 117 deletions.
3 changes: 2 additions & 1 deletion Makefile.target
Expand Up @@ -51,7 +51,6 @@ libobj-$(CONFIG_NOSOFTFLOAT) += fpu/softfloat-native.o
libobj-y += op_helper.o helper.o
libobj-$(CONFIG_NEED_MMU) += mmu.o
libobj-$(TARGET_ARM) += neon_helper.o iwmmxt_helper.o
libobj-$(TARGET_ALPHA) += alpha_palcode.o

# NOTE: the disassembler code is only needed for debugging
libobj-y += disas.o
Expand Down Expand Up @@ -312,6 +311,8 @@ obj-m68k-y += m68k-semi.o dummy_m68k.o

obj-s390x-y = s390-virtio-bus.o s390-virtio.o

obj-alpha-y = alpha_palcode.o

main.o vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)

vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
Expand Down
81 changes: 3 additions & 78 deletions hw/alpha_palcode.c
Expand Up @@ -21,11 +21,9 @@
#include <stdlib.h>
#include <stdio.h>

#include "qemu.h"
#include "cpu.h"
#include "exec-all.h"

#if !defined (CONFIG_USER_ONLY)
/* Shared handlers */
static void pal_reset (CPUState *env);
/* Console handlers */
Expand Down Expand Up @@ -997,12 +995,9 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
uint64_t physical, page_size, end;
int prot, zbits, ret;

#if defined(CONFIG_USER_ONLY)
ret = 2;
#else
ret = virtual_to_physical(env, &physical, &zbits, &prot,
address, mmu_idx, rw);
#endif
ret = virtual_to_physical(env, &physical, &zbits, &prot,
address, mmu_idx, rw);

switch (ret) {
case 0:
/* No fault */
Expand Down Expand Up @@ -1050,73 +1045,3 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
return ret;
}
#endif

#else /* !defined (CONFIG_USER_ONLY) */
void pal_init (CPUState *env)
{
}

void call_pal (CPUState *env, int palcode)
{
target_long ret;

switch (palcode) {
case 0x80:
/* BPT */
qemu_log("BPT\n");
/* FIXME: Sends SIGTRAP, si_code=TRAP_BRKPT. */
exit(1);
case 0x81:
/* BUGCHK */
qemu_log("BUGCHK\n");
/* FIXME: Sends SIGTRAP, si_code=SI_FAULT. */
exit(1);
case 0x83:
/* CALLSYS */
qemu_log("CALLSYS n " TARGET_FMT_ld "\n", env->ir[0]);
ret = do_syscall(env, env->ir[IR_V0], env->ir[IR_A0], env->ir[IR_A1],
env->ir[IR_A2], env->ir[IR_A3], env->ir[IR_A4],
env->ir[IR_A5]);
if (ret >= 0) {
env->ir[IR_A3] = 0;
env->ir[IR_V0] = ret;
} else {
env->ir[IR_A3] = 1;
env->ir[IR_V0] = -ret;
}
break;
case 0x86:
/* IMB */
qemu_log("IMB\n");
/* ??? We can probably elide the code using page_unprotect that is
checking for self-modifying code. Instead we could simply call
tb_flush here. Until we work out the changes required to turn
off the extra write protection, this can be a no-op. */
break;
case 0x9E:
/* RDUNIQUE */
qemu_log("RDUNIQUE: " TARGET_FMT_lx "\n", env->unique);
/* Handled in the translator for usermode. */
abort();
case 0x9F:
/* WRUNIQUE */
qemu_log("WRUNIQUE: " TARGET_FMT_lx "\n", env->ir[IR_A0]);
/* Handled in the translator for usermode. */
abort();
case 0xAA:
/* GENTRAP */
qemu_log("GENTRAP: " TARGET_FMT_lx "\n", env->ir[IR_A0]);
/* FIXME: This is supposed to send a signal:
SIGFPE:
GEN_INTOVF, GEN_INTDIV, GEN_FLTOVF, GEN_FLTDIV,
GEN_FLTUND, GEN_FLTINV, GEN_FLTINE, GEN_ROPRAND
SIGTRAP:
others
with various settings of si_code. */
exit(1);
default:
qemu_log("%s: unhandled palcode %02x\n", __func__, palcode);
exit(1);
}
}
#endif
27 changes: 27 additions & 0 deletions linux-user/alpha/target_signal.h
Expand Up @@ -26,4 +26,31 @@ static inline abi_ulong get_sp_from_cpustate(CPUAlphaState *state)
return state->ir[IR_SP];
}

/* From <asm/gentrap.h>. */
#define TARGET_GEN_INTOVF -1 /* integer overflow */
#define TARGET_GEN_INTDIV -2 /* integer division by zero */
#define TARGET_GEN_FLTOVF -3 /* fp overflow */
#define TARGET_GEN_FLTDIV -4 /* fp division by zero */
#define TARGET_GEN_FLTUND -5 /* fp underflow */
#define TARGET_GEN_FLTINV -6 /* invalid fp operand */
#define TARGET_GEN_FLTINE -7 /* inexact fp operand */
#define TARGET_GEN_DECOVF -8 /* decimal overflow (for COBOL??) */
#define TARGET_GEN_DECDIV -9 /* decimal division by zero */
#define TARGET_GEN_DECINV -10 /* invalid decimal operand */
#define TARGET_GEN_ROPRAND -11 /* reserved operand */
#define TARGET_GEN_ASSERTERR -12 /* assertion error */
#define TARGET_GEN_NULPTRERR -13 /* null pointer error */
#define TARGET_GEN_STKOVF -14 /* stack overflow */
#define TARGET_GEN_STRLENERR -15 /* string length error */
#define TARGET_GEN_SUBSTRERR -16 /* substring error */
#define TARGET_GEN_RANGERR -17 /* range error */
#define TARGET_GEN_SUBRNG -18
#define TARGET_GEN_SUBRNG1 -19
#define TARGET_GEN_SUBRNG2 -20
#define TARGET_GEN_SUBRNG3 -21
#define TARGET_GEN_SUBRNG4 -22
#define TARGET_GEN_SUBRNG5 -23
#define TARGET_GEN_SUBRNG6 -24
#define TARGET_GEN_SUBRNG7 -25

#endif /* TARGET_SIGNAL_H */
137 changes: 112 additions & 25 deletions linux-user/main.c
Expand Up @@ -2351,6 +2351,7 @@ void cpu_loop (CPUState *env)
{
int trapnr;
target_siginfo_t info;
abi_long sysret;

while (1) {
trapnr = cpu_alpha_exec (env);
Expand All @@ -2365,16 +2366,22 @@ void cpu_loop (CPUState *env)
exit(1);
break;
case EXCP_ARITH:
fprintf(stderr, "Arithmetic trap.\n");
exit(1);
info.si_signo = TARGET_SIGFPE;
info.si_errno = 0;
info.si_code = TARGET_FPE_FLTINV;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case EXCP_HW_INTERRUPT:
fprintf(stderr, "External interrupt. Exit\n");
exit(1);
break;
case EXCP_DFAULT:
fprintf(stderr, "MMU data fault\n");
exit(1);
info.si_signo = TARGET_SIGSEGV;
info.si_errno = 0;
info.si_code = 0; /* ??? SEGV_MAPERR vs SEGV_ACCERR. */
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case EXCP_DTB_MISS_PAL:
fprintf(stderr, "MMU data TLB miss in PALcode\n");
Expand All @@ -2393,36 +2400,116 @@ void cpu_loop (CPUState *env)
exit(1);
break;
case EXCP_UNALIGN:
fprintf(stderr, "Unaligned access\n");
exit(1);
info.si_signo = TARGET_SIGBUS;
info.si_errno = 0;
info.si_code = TARGET_BUS_ADRALN;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case EXCP_OPCDEC:
fprintf(stderr, "Invalid instruction\n");
exit(1);
do_sigill:
info.si_signo = TARGET_SIGILL;
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPC;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case EXCP_FEN:
fprintf(stderr, "Floating-point not allowed\n");
exit(1);
/* No-op. Linux simply re-enables the FPU. */
break;
case EXCP_CALL_PAL ... (EXCP_CALL_PALP - 1):
call_pal(env, (trapnr >> 6) | 0x80);
switch ((trapnr >> 6) | 0x80) {
case 0x80:
/* BPT */
info.si_signo = TARGET_SIGTRAP;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case 0x81:
/* BUGCHK */
info.si_signo = TARGET_SIGTRAP;
info.si_errno = 0;
info.si_code = 0;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
case 0x83:
/* CALLSYS */
trapnr = env->ir[IR_V0];
sysret = do_syscall(env, trapnr,
env->ir[IR_A0], env->ir[IR_A1],
env->ir[IR_A2], env->ir[IR_A3],
env->ir[IR_A4], env->ir[IR_A5]);
if (trapnr != TARGET_NR_sigreturn
&& trapnr != TARGET_NR_rt_sigreturn) {
env->ir[IR_V0] = (sysret < 0 ? -sysret : sysret);
env->ir[IR_A3] = (sysret < 0);
}
break;
case 0x86:
/* IMB */
/* ??? We can probably elide the code using page_unprotect
that is checking for self-modifying code. Instead we
could simply call tb_flush here. Until we work out the
changes required to turn off the extra write protection,
this can be a no-op. */
break;
case 0x9E:
/* RDUNIQUE */
/* Handled in the translator for usermode. */
abort();
case 0x9F:
/* WRUNIQUE */
/* Handled in the translator for usermode. */
abort();
case 0xAA:
/* GENTRAP */
info.si_signo = TARGET_SIGFPE;
switch (env->ir[IR_A0]) {
case TARGET_GEN_INTOVF:
info.si_code = TARGET_FPE_INTOVF;
break;
case TARGET_GEN_INTDIV:
info.si_code = TARGET_FPE_INTDIV;
break;
case TARGET_GEN_FLTOVF:
info.si_code = TARGET_FPE_FLTOVF;
break;
case TARGET_GEN_FLTUND:
info.si_code = TARGET_FPE_FLTUND;
break;
case TARGET_GEN_FLTINV:
info.si_code = TARGET_FPE_FLTINV;
break;
case TARGET_GEN_FLTINE:
info.si_code = TARGET_FPE_FLTRES;
break;
case TARGET_GEN_ROPRAND:
info.si_code = 0;
break;
default:
info.si_signo = TARGET_SIGTRAP;
info.si_code = 0;
break;
}
info.si_errno = 0;
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, &info);
break;
default:
goto do_sigill;
}
break;
case EXCP_CALL_PALP ... (EXCP_CALL_PALE - 1):
fprintf(stderr, "Privileged call to PALcode\n");
exit(1);
break;
goto do_sigill;
case EXCP_DEBUG:
{
int sig;

sig = gdb_handlesig (env, TARGET_SIGTRAP);
if (sig)
{
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
queue_signal(env, info.si_signo, &info);
}
info.si_signo = gdb_handlesig (env, TARGET_SIGTRAP);
if (info.si_signo) {
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
queue_signal(env, info.si_signo, &info);
}
break;
default:
Expand Down

0 comments on commit 6049f4f

Please sign in to comment.