Skip to content

Commit

Permalink
Actually build strace for RISC-V
Browse files Browse the repository at this point in the history
It turns out the other port wasn't actually sufficient to do anything
with the strace port, it was just enough to get a RISC-V port built
with no actual support.
  • Loading branch information
palmer-dabbelt committed Sep 1, 2015
1 parent 29e1dd4 commit f320e18
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Makefile.am
Expand Up @@ -155,6 +155,12 @@ EXTRA_DIST = \
linux/powerpc/syscallent1.h \
linux/ptp_clock.h \
linux/reboot.h \
linux/riscv/errnoent1.h \
linux/riscv/ioctlent.h.in \
linux/riscv/ioctlent1.h \
linux/riscv/signalent1.h \
linux/riscv/syscallent.h \
linux/riscv/syscallent1.h \
linux/s390/ioctlent.h.in \
linux/s390/syscallent.h \
linux/s390x/ioctlent.h.in \
Expand Down
6 changes: 6 additions & 0 deletions Makefile.in
Expand Up @@ -643,6 +643,12 @@ EXTRA_DIST = \
linux/powerpc/syscallent1.h \
linux/ptp_clock.h \
linux/reboot.h \
linux/riscv/errnoent1.h \
linux/riscv/ioctlent.h.in \
linux/riscv/ioctlent1.h \
linux/riscv/signalent1.h \
linux/riscv/syscallent.h \
linux/riscv/syscallent1.h \
linux/s390/ioctlent.h.in \
linux/s390/syscallent.h \
linux/s390x/ioctlent.h.in \
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Expand Up @@ -1686,6 +1686,9 @@
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE

/* Define for the RISC-V architecture */
#undef RISCV

/* Define for the S390 architecture. */
#undef S390

Expand Down
1 change: 1 addition & 0 deletions defs.h
Expand Up @@ -611,6 +611,7 @@ extern void call_summary(FILE *);
|| defined(X86_64) || defined(X32) \
|| defined(AARCH64) \
|| defined(ARM) \
|| defined(RISCV) \
|| defined(SPARC) || defined(SPARC64) \
|| defined(TILE) \
|| defined(OR1K) \
Expand Down
2 changes: 1 addition & 1 deletion linux/riscv/errnoent1.h
@@ -1,2 +1,2 @@
/* tilegx32/tilepro */
/* RISC-V rv32 and rv64 */
#include "../errnoent.h"
2 changes: 1 addition & 1 deletion linux/riscv/ioctlent1.h
@@ -1,2 +1,2 @@
/* tilegx32/tilepro */
/* RISC-V rv32 and rv64 */
#include "ioctlent.h"
2 changes: 1 addition & 1 deletion linux/riscv/signalent1.h
@@ -1,2 +1,2 @@
/* tilegx32/tilepro */
/* RISC-V rv32 and rv64 */
#include "../signalent.h"
9 changes: 8 additions & 1 deletion process.c
Expand Up @@ -319,7 +319,7 @@ extern void print_user_desc(struct tcb *, long);
# define ARG_PTID 2
# define ARG_CTID ((current_personality != 1) ? 3 : 4)
# define ARG_TLS ((current_personality != 1) ? 4 : 3)
#elif defined ALPHA || defined TILE || defined OR1K
#elif defined ALPHA || defined TILE || defined OR1K || defined RISCV
# define ARG_FLAGS 0
# define ARG_STACK 1
# define ARG_PTID 2
Expand Down Expand Up @@ -1096,6 +1096,10 @@ const struct xlat struct_user_offsets[] = {
{ PT_IEEE_IP, "ieee_exception_ip" },
#elif defined(SPARC)
/* XXX No support for these offsets yet. */
#elif defined(RISCV)
/* FIXME: RISCV: Figure these out, maybe they're just a
* ucontext offset? I certainly hope so... */
/* XXX No support for these offsets yet. */
#elif defined(HPPA)
/* XXX No support for these offsets yet. */
#elif defined(POWERPC)
Expand Down Expand Up @@ -2095,6 +2099,9 @@ const struct xlat struct_user_offsets[] = {
/* nothing */
#elif defined(ARC)
/* nothing */
#elif defined(RISCV)
/* FIXME: RISCV: Is there really nothing here? */
/* nothing */
#endif
XLAT_END
};
Expand Down
3 changes: 3 additions & 0 deletions signal.c
Expand Up @@ -938,6 +938,9 @@ sys_sigreturn(struct tcb *tcp)
/* Xtensa only has rt_sys_sigreturn */
#elif defined(ARC)
/* ARC syscall ABI only supports rt_sys_sigreturn */
#elif defined(RISCV)
/* FIXME: RISCV: I think this is true? */
/* RISC-V only has rt_sys_sigreturn */
#else
# warning No sys_sigreturn() for this architecture
# warning (no problem, just a reminder :-)
Expand Down
34 changes: 33 additions & 1 deletion syscall.c
Expand Up @@ -81,6 +81,10 @@
# include <asm/ptrace.h>
#endif

#if defined(RISCV)
# include <asm/ptrace.h>
#endif

#ifndef NSIG
# warning: NSIG is not defined, using 32
# define NSIG 32
Expand Down Expand Up @@ -782,6 +786,9 @@ static long xtensa_a2;
# elif defined(ARC)
static struct user_regs_struct arc_regs;
# define ARCH_REGS_FOR_GETREGSET arc_regs
#elif defined(RISCV)
#define ARCH_REGS_FOR_GETREGSET riscv_regs
static struct user_regs_struct riscv_regs;
#endif

void
Expand Down Expand Up @@ -924,6 +931,12 @@ print_pc(struct tcb *tcp)
tprintf("[%08lx] ", pc);
#elif defined(ARC)
tprintf("[%08lx] ", arc_regs.efa);
#elif defined(RISCV)
# ifdef _LP64
tprintf("[%016lx] ", riscv_regs.pc);
# else
tprintf("[%08lx] ", riscv_regs.pc);
# endif
#endif /* architecture */
}

Expand Down Expand Up @@ -1021,6 +1034,7 @@ static void get_regset(pid_t pid)
|| defined(METAG) \
|| defined(OR1K) \
|| defined(ARC)
|| defined(RISCV)
static struct iovec io = {
.iov_base = &ARCH_REGS_FOR_GETREGSET,
.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET)
Expand All @@ -1046,7 +1060,7 @@ void
get_regs(pid_t pid)
{
/* PTRACE_GETREGSET only */
# if defined(METAG) || defined(OR1K) || defined(X32) || defined(AARCH64) || defined(ARC)
# if defined(METAG) || defined(OR1K) || defined(X32) || defined(AARCH64) || defined(ARC) || defined (RISCV)
get_regset(pid);

/* PTRACE_GETREGS only */
Expand Down Expand Up @@ -1556,6 +1570,8 @@ get_scno(struct tcb *tcp)
return -1;
# elif defined(ARC)
scno = arc_regs.scratch.r8;
#elif defined(RISCV)
scno = riscv_regs.a7;
#endif

tcp->scno = scno;
Expand Down Expand Up @@ -1950,6 +1966,13 @@ get_syscall_args(struct tcb *tcp)
for (i = 0; i < nargs; ++i)
tcp->u_arg[i] = *arc_args--;

#elif defined(RISCV)
tcp->u_arg[0] = riscv_regs.a0;
tcp->u_arg[1] = riscv_regs.a1;
tcp->u_arg[2] = riscv_regs.a2;
tcp->u_arg[3] = riscv_regs.a3;
tcp->u_arg[4] = riscv_regs.a4;
tcp->u_arg[5] = riscv_regs.a5;
#else /* Other architecture (32bits specific) */
for (i = 0; i < nargs; ++i)
if (upeek(tcp->pid, i*4, &tcp->u_arg[i]) < 0)
Expand Down Expand Up @@ -2156,6 +2179,8 @@ get_syscall_result(struct tcb *tcp)
if (upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0)
return -1;
#elif defined(ARC)
#elif defined(RISCV)
/* FIXME: Is this true? I think in the new ABI it is? */
/* already done by get_regs */
#endif
return 1;
Expand Down Expand Up @@ -2470,6 +2495,13 @@ get_error(struct tcb *tcp)
else {
tcp->u_rval = arc_regs.scratch.r0;
}
#elif defined(RISCV)
if (check_errno && is_negated_errno(riscv_regs.a0)) {
tcp->u_rval = -1;
u_error = -riscv_regs.a0;
} else {
tcp->u_rval = riscv_regs.a0;
}
#endif
tcp->u_error = u_error;
}
Expand Down
3 changes: 3 additions & 0 deletions util.c
Expand Up @@ -1457,6 +1457,9 @@ change_syscall(struct tcb *tcp, arg_setup_state *state, int new)
#elif defined(ARC)
/* setbpt/clearbpt never used: */
/* ARC only supported since 3.9 */
#elif defined(RISCV)
/* setbpt/clearbpt never used: */
/* RISC-V CPUs are only supported since about linux-3.14 */
#else
#warning Do not know how to handle change_syscall for this architecture
#endif /* architecture */
Expand Down

0 comments on commit f320e18

Please sign in to comment.