[PATCH] sparc/linux: rewrite to use asm/ptrace.h

Mike Frysinger vapier at gentoo.org
Mon Oct 12 15:05:14 UTC 2009


The current sparc/linux code uses asm/reg.h, but recent Linux kernels
dropped that header completely.  So switch over to the ptrace headers as
those should stick around indefinitely as part of the ABI.

* defs.h (U_REG_G1, U_REG_O0, U_REG_O1): Define.
* process.c: Drop asm/regs.h include.
(change_syscall): Change struct regs to struct pt_regs.
* signal.c: Drop asm/regs.h include.
(m_siginfo_t): Unify sparc/mips versions.
(sys_sigreturn): Change struct regs to struct pt_regs.
* syscall.c: Drop asm/regs.h include.
(internal_syscall): Change struct regs to struct pt_regs.
(get_scno, get_error, force_result, syscall_enter): Likewise.
* util.c: Drop asm/regs.h include.
(_hack_syscall5, _ptrace): Delete.
(getpc): Change struct regs to struct pt_regs.
(printcall, arg_setup_state): Likewise.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
 defs.h    |    5 +++
 process.c |   18 +-----------
 signal.c  |   25 ++----------------
 syscall.c |   65 +++++++++++++++++++----------------------------
 util.c    |   83 +++++++++++++-----------------------------------------------
 5 files changed, 54 insertions(+), 142 deletions(-)

diff --git a/defs.h b/defs.h
index 9fd6122..e5e920b 100644
--- a/defs.h
+++ b/defs.h
@@ -218,6 +218,11 @@ extern int ptrace();
 #define DEFAULT_PERSONALITY 0
 
 #ifdef LINUXSPARC
+/* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off
+ * by 1 and use Ix instead of Ox.  These work for both 32 and 64 bit Linux. */
+#define U_REG_G1 0
+#define U_REG_O0 7
+#define U_REG_O1 8
 #define PERSONALITY0_WORDSIZE 4
 #define PERSONALITY1_WORDSIZE 4
 #undef  SUPPORTED_PERSONALITIES
diff --git a/process.c b/process.c
index 5d956b0..551e1bb 100644
--- a/process.c
+++ b/process.c
@@ -56,20 +56,6 @@
 #include <sys/ptrace.h>
 #endif
 
-#if HAVE_ASM_REG_H
-#if defined (SPARC) || defined (SPARC64)
-#  define fpq kernel_fpq
-#  define fq kernel_fq
-#  define fpu kernel_fpu
-#endif /* SPARC || SPARC64 */
-#include <asm/reg.h>
-#if defined (SPARC) || defined (SPARC64)
-#  undef fpq
-#  undef fq
-#  undef fpu
-#endif /* SPARC || SPARC64 */
-#endif /* HAVE_ASM_REG_H */
-
 #ifdef HAVE_SYS_REG_H
 # include <sys/reg.h>
 #ifndef PTRACE_PEEKUSR
@@ -726,10 +712,10 @@ change_syscall(struct tcb *tcp, int new)
 		return -1;
 	return 0;
 #elif defined(SPARC) || defined(SPARC64)
-	struct regs regs;
+	struct pt_regs regs;
 	if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
 		return -1;
-	regs.r_g1=new;
+	regs.u_regs[U_REG_G1] = new;
 	if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
 		return -1;
 	return 0;
diff --git a/signal.c b/signal.c
index 4f3111a..6cfdeb2 100644
--- a/signal.c
+++ b/signal.c
@@ -72,33 +72,14 @@
 # include <asm/ptrace_offsets.h>
 #endif /* !IA64 */
 
-#if HAVE_ASM_REG_H
-# if defined (SPARC) || defined (SPARC64)
-#  define fpq kernel_fpq
-#  define fq kernel_fq
-#  define fpu kernel_fpu
-# endif
-# include <asm/reg.h>
-# if defined (SPARC) || defined (SPARC64)
-#  undef fpq
-#  undef fq
-#  undef fpu
-# endif
 #if defined (LINUX) && defined (SPARC64)
-# define r_pc r_tpc
 # undef PTRACE_GETREGS
 # define PTRACE_GETREGS PTRACE_GETREGS64
 # undef PTRACE_SETREGS
 # define PTRACE_SETREGS PTRACE_SETREGS64
 #endif /* LINUX && SPARC64 */
-#endif /* HAVE_ASM_REG_H */
 
-#if defined (SPARC) || defined (SPARC64)
-typedef struct {
-	struct regs		si_regs;
-	int			si_mask;
-} m_siginfo_t;
-#elif defined (MIPS)
+#if defined (SPARC) || defined (SPARC64) || defined (MIPS)
 typedef struct {
 	struct pt_regs		si_regs;
 	int			si_mask;
@@ -1408,7 +1389,7 @@ sys_sigreturn(struct tcb *tcp)
 	return 0;
 #elif defined (SPARC) || defined (SPARC64)
 	long i1;
-	struct regs regs;
+	struct pt_regs regs;
 	m_siginfo_t si;
 
 	if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
@@ -1417,7 +1398,7 @@ sys_sigreturn(struct tcb *tcp)
 	}
 	if(entering(tcp)) {
 		tcp->u_arg[0] = 0;
-		i1 = regs.r_o1;
+		i1 = regs.u_regs[U_REG_O1];
 		if(umove(tcp, i1, &si) < 0) {
 			perror("sigreturn: umove ");
 			return 0;
diff --git a/syscall.c b/syscall.c
index 6a75c70..3f551cd 100644
--- a/syscall.c
+++ b/syscall.c
@@ -42,20 +42,6 @@
 #include <sys/syscall.h>
 #include <sys/param.h>
 
-#if HAVE_ASM_REG_H
-#if defined (SPARC) || defined (SPARC64)
-#  define fpq kernel_fpq
-#  define fq kernel_fq
-#  define fpu kernel_fpu
-#endif
-#include <asm/reg.h>
-#if defined (SPARC) || defined (SPARC64)
-#  undef fpq
-#  undef fq
-#  undef fpu
-#endif
-#endif
-
 #ifdef HAVE_SYS_REG_H
 #include <sys/reg.h>
 #ifndef PTRACE_PEEKUSR
@@ -75,7 +61,6 @@
 #endif
 
 #if defined (LINUX) && defined (SPARC64)
-# define r_pc r_tpc
 # undef PTRACE_GETREGS
 # define PTRACE_GETREGS PTRACE_GETREGS64
 # undef PTRACE_SETREGS
@@ -755,7 +740,7 @@ internal_syscall(struct tcb *tcp)
 #elif defined(AVR32)
 	static struct pt_regs regs;
 #elif defined (SPARC) || defined (SPARC64)
-	static struct regs regs;
+	static struct pt_regs regs;
 	static unsigned long trap;
 #elif defined(LINUX_MIPSN32)
 	static long long a3;
@@ -1186,9 +1171,11 @@ get_scno(struct tcb *tcp)
 	if (!(tcp->flags & TCB_INSYSCALL)) {
 		/* Retrieve the syscall trap instruction. */
 		errno = 0;
-		trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.r_pc, 0);
 #  if defined(SPARC64)
+		trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.tpc, 0);
 		trap >>= 32;
+#  else
+		trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.pc, 0);
 #  endif
 		if (errno)
 			return -1;
@@ -1226,9 +1213,9 @@ get_scno(struct tcb *tcp)
 				return 0;
 			}
 #  if defined (SPARC64)
-			fprintf(stderr,"syscall: unknown syscall trap %08lx %016lx\n", trap, regs.r_tpc);
+			fprintf(stderr,"syscall: unknown syscall trap %08lx %016lx\n", trap, regs.tpc);
 #  else
-			fprintf(stderr,"syscall: unknown syscall trap %08x %08x\n", trap, regs.r_pc);
+			fprintf(stderr,"syscall: unknown syscall trap %08lx %08lx\n", trap, regs.pc);
 #  endif
 			return -1;
 		}
@@ -1237,10 +1224,10 @@ get_scno(struct tcb *tcp)
 		if (trap == 0x91d02027)
 			scno = 156;
 		else
-			scno = regs.r_g1;
+			scno = regs.u_regs[U_REG_G1];
 		if (scno == 0) {
-			scno = regs.r_o0;
-			memmove (&regs.r_o0, &regs.r_o1, 7*sizeof(regs.r_o0));
+			scno = regs.u_regs[U_REG_O0];
+			memmove (&regs.u_regs[U_REG_O0], &regs.u_regs[U_REG_O1], 7*sizeof(regs.u_regs[0]));
 		}
 	}
 # elif defined(HPPA)
@@ -1646,21 +1633,21 @@ get_error(struct tcb *tcp)
 			u_error = 0;
 		}
 # elif defined(SPARC)
-		if (regs.r_psr & PSR_C) {
+		if (regs.psr & PSR_C) {
 			tcp->u_rval = -1;
-			u_error = regs.r_o0;
+			u_error = regs.u_regs[U_REG_O0];
 		}
 		else {
-			tcp->u_rval = regs.r_o0;
+			tcp->u_rval = regs.u_regs[U_REG_O0];
 			u_error = 0;
 		}
 # elif defined(SPARC64)
-		if (regs.r_tstate & 0x1100000000UL) {
+		if (regs.tstate & 0x1100000000UL) {
 			tcp->u_rval = -1;
-			u_error = regs.r_o0;
+			u_error = regs.u_regs[U_REG_O0];
 		}
 		else {
-			tcp->u_rval = regs.r_o0;
+			tcp->u_rval = regs.u_regs[U_REG_O0];
 			u_error = 0;
 		}
 # elif defined(HPPA)
@@ -1875,12 +1862,12 @@ force_result(tcp, error, rval)
 	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0)
 		return -1;
 	if (error) {
-		regs.r_psr |= PSR_C;
-		regs.r_o0 = error;
+		regs.psr |= PSR_C;
+		regs.u_regs[U_REG_O0] = error;
 	}
 	else {
-		regs.r_psr &= ~PSR_C;
-		regs.r_o0 = rval;
+		regs.psr &= ~PSR_C;
+		regs.u_regs[U_REG_O0] = rval;
 	}
 	if (ptrace(PTRACE_SETREGS, tcp->pid, (char *)&regs, 0) < 0)
 		return -1;
@@ -1888,12 +1875,12 @@ force_result(tcp, error, rval)
 	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0)
 		return -1;
 	if (error) {
-		regs.r_tstate |= 0x1100000000UL;
-		regs.r_o0 = error;
+		regs.tstate |= 0x1100000000UL;
+		regs.u_regs[U_REG_O0] = error;
 	}
 	else {
-		regs.r_tstate &= ~0x1100000000UL;
-		regs.r_o0 = rval;
+		regs.tstate &= ~0x1100000000UL;
+		regs.u_regs[U_REG_O0] = rval;
 	}
 	if (ptrace(PTRACE_SETREGS, tcp->pid, (char *)&regs, 0) < 0)
 		return -1;
@@ -2110,7 +2097,7 @@ syscall_enter(struct tcb *tcp)
 		else
 			tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++)
-			tcp->u_arg[i] = *((&regs.r_o0) + i);
+			tcp->u_arg[i] = regs.u_regs[U_REG_O0 + i];
 	}
 #elif defined (HPPA)
 	{
@@ -2680,10 +2667,10 @@ struct tcb *tcp;
 
 #ifdef LINUX
 #if defined (SPARC) || defined (SPARC64)
-	struct regs regs;
+	struct pt_regs regs;
 	if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,0) < 0)
 		return -1;
-	val = regs.r_o1;
+	val = regs.u_regs[U_REG_O1];
 #elif defined(SH)
 	if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
 		return -1;
diff --git a/util.c b/util.c
index c96eb0a..84baf7a 100644
--- a/util.c
+++ b/util.c
@@ -78,66 +78,11 @@
 #include <sys/utsname.h>
 #endif /* SUNOS4_KERNEL_ARCH_KLUDGE */
 
-#if defined(LINUXSPARC)
-
-# define fpq kernel_fpq
-# define fq kernel_fq
-# define fpu kernel_fpu
-# include <asm/reg.h>
-# undef fpq
-# undef fq
-# undef fpu
-
-#if defined (SPARC64)
-# define r_pc r_tpc
+#if defined(LINUXSPARC) && defined (SPARC64)
 # undef PTRACE_GETREGS
 # define PTRACE_GETREGS PTRACE_GETREGS64
 # undef PTRACE_SETREGS
 # define PTRACE_SETREGS PTRACE_SETREGS64
-#endif /* SPARC64 */
-
-#if !defined(__GLIBC__)
-
-#include <linux/unistd.h>
-
-#define _hack_syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,\
-          type5,arg5,syscall) \
-type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
-{ \
-      long __res; \
-\
-__asm__ volatile ("or %%g0, %1, %%o0\n\t" \
-                  "or %%g0, %2, %%o1\n\t" \
-                  "or %%g0, %3, %%o2\n\t" \
-                  "or %%g0, %4, %%o3\n\t" \
-                  "or %%g0, %5, %%o4\n\t" \
-                  "or %%g0, %6, %%g1\n\t" \
-#if defined (SPARC64)
-                  "t 0x6d\n\t" \
-#else
-                  "t 0x10\n\t" \
-#endif
-                  "bcc 1f\n\t" \
-                  "or %%g0, %%o0, %0\n\t" \
-                  "sub %%g0, %%o0, %0\n\t" \
-                  "1:\n\t" \
-                  : "=r" (__res) \
-                  : "0" ((long)(arg1)),"1" ((long)(arg2)), \
-                    "2" ((long)(arg3)),"3" ((long)(arg4)),"4" ((long)(arg5)), \
-                    "i" (__NR_##syscall)  \
-                  : "g1", "o0", "o1", "o2", "o3", "o4"); \
-if (__res>=0) \
-	return (type) __res; \
-errno = -__res; \
-return -1; \
-}
-
-static _hack_syscall5(int,_ptrace,int,__request,int,__pid,int,__addr,int,__data,int,__addr2,ptrace)
-
-#define _ptrace
-
-#endif
-
 #endif
 
 /* macros */
@@ -1180,10 +1125,14 @@ getpc(struct tcb *tcp)
 	if (upeek(tcp, REG_EPC, &pc) < 0)
 		return -1;
 # elif defined(SPARC) || defined(SPARC64)
-	struct regs regs;
+	struct pt_regs regs;
 	if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,0) < 0)
 		return -1;
-	pc = regs.r_pc;
+#  if defined(SPARC64)
+	pc = regs.tpc;
+#  else
+	pc = regs.pc;
+#  endif
 # elif defined(S390) || defined(S390X)
 	if(upeek(tcp,PT_PSWADDR,&pc) < 0)
 		return -1;
@@ -1297,12 +1246,16 @@ printcall(struct tcb *tcp)
 	}
 	tprintf("[%08lx] ", pc);
 # elif defined(SPARC) || defined(SPARC64)
-	struct regs regs;
+	struct pt_regs regs;
 	if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,0) < 0) {
 		PRINTBADPC;
 		return;
 	}
-	tprintf("[%08lx] ", regs.r_pc);
+#  if defined(SPARC64)
+	tprintf("[%08lx] ", regs.tpc);
+#  else
+	tprintf("[%08lx] ", regs.pc);
+#  endif
 # elif defined(HPPA)
 	long pc;
 
@@ -1532,17 +1485,17 @@ set_arg1 (struct tcb *tcp, arg_setup_state *state, long val)
 
 #  elif defined (SPARC) || defined (SPARC64)
 
-typedef struct regs arg_setup_state;
+typedef struct pt_regs arg_setup_state;
 
 #   define arg_setup(tcp, state) \
     (ptrace (PTRACE_GETREGS, tcp->pid, (char *) (state), 0))
 #   define arg_finish_change(tcp, state) \
     (ptrace (PTRACE_SETREGS, tcp->pid, (char *) (state), 0))
 
-#   define get_arg0(tcp, state, valp) (*(valp) = (state)->r_o0, 0)
-#   define get_arg1(tcp, state, valp) (*(valp) = (state)->r_o1, 0)
-#   define set_arg0(tcp, state, val) ((state)->r_o0 = (val), 0)
-#   define set_arg1(tcp, state, val) ((state)->r_o1 = (val), 0)
+#   define get_arg0(tcp, state, valp) (*(valp) = (state)->u_regs[U_REG_O0], 0)
+#   define get_arg1(tcp, state, valp) (*(valp) = (state)->u_regs[U_REG_O1], 0)
+#   define set_arg0(tcp, state, val) ((state)->u_regs[U_REG_O0] = (val), 0)
+#   define set_arg1(tcp, state, val) ((state)->u_regs[U_REG_O1] = (val), 0)
 #   define restore_arg0(tcp, state, val) 0
 
 #  else /* other architectures */
-- 
1.6.5.rc2





More information about the Strace-devel mailing list