2002-10-07  Michal Ludvig  <mludvig@suse.cz>

        Merged s390x port by Heiko Carstens <Heiko.Carstens@de.ibm.com>
        and bugfixes to s390 by D.J. Barrow.
diff --git a/ChangeLog b/ChangeLog
index 7065d38..d88c81e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-10-07  Michal Ludvig  <mludvig@suse.cz>
+
+	Merged s390x port by Heiko Carstens <Heiko.Carstens@de.ibm.com>
+	and bugfixes to s390 by D.J. Barrow.
+
 2002-09-23  Michal Ludvig  <mludvig@suse.cz>
 
 	Merged x86-64 port by Andi Kleen <ak@suse.de> 
diff --git a/Makefile.in b/Makefile.in
index 70d09b8..cfa7d46 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -50,7 +50,8 @@
 			-I$(srcdir)/$(OS)
 SUBDIRS		= $(OSARCH)
 
-ALL_SUBDIRS	= test linux linux/alpha linux/powerpc sunos4 svr4 freebsd/i386
+ALL_SUBDIRS	= test linux linux/alpha linux/powerpc sunos4 svr4 \
+			linux/s390 linux/s390x freebsd/i386
 OBJ		= strace.o version.o syscall.o util.o desc.o file.o ipc.o \
 			io.o ioctl.o mem.o net.o process.o bjm.o \
 			resource.o signal.o sock.o system.o term.o time.o \
diff --git a/acconfig.h b/acconfig.h
index 5b64d39..a3939b6 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -51,6 +51,9 @@
 /* Define if this is a x86-64 architecture.  */
 #undef X86_64
 
+/* Define if this is a S390X architecture.  */
+#undef S390X
+
 /* Define if you have a SVR4 MP type procfs.  I.E. /dev/xxx/ctl,
    /dev/xxx/status.  Also implies that you have the pr_lwp
    member in prstatus. */
diff --git a/config.sub b/config.sub
index fdcc42b..7d96cb6 100755
--- a/config.sub
+++ b/config.sub
@@ -756,6 +756,12 @@
 		basic_machine=a29k-amd
 		os=-udi
 		;;
+	s390)
+		basic_machine=s390-ibm
+		;;
+	s390x)
+		basic_machine=s390x-ibm
+		;;
 	sequent)
 		basic_machine=i386-sequent
 		;;
diff --git a/configure.in b/configure.in
index ec1be26..34ef1bc 100644
--- a/configure.in
+++ b/configure.in
@@ -64,6 +64,9 @@
 s390)
 	arch=s390
 	;;
+s390x)
+	arch=s390x
+	;;
 hppa*|parisc*)
 	arch=hppa
 	;;
@@ -81,7 +84,7 @@
 
 # Autoheader trick.  Heh, heh.
 arch_list='
-@@@syms="$syms I386 IA64 M68K SPARC MIPS ALPHA ARM POWERPC S390 HPPA SH X86_64"@@@
+@@@syms="$syms I386 IA64 M68K SPARC MIPS ALPHA ARM POWERPC S390 S390X HPPA SH X86_64"@@@
 '
 
 osarch="$opsys"
diff --git a/file.c b/file.c
index 1ae9fe5..5b30eba 100644
--- a/file.c
+++ b/file.c
@@ -40,6 +40,7 @@
 #include <linux/types.h>
 #include <linux/dirent.h>
 #undef dirent
+#undef dirent64
 #else
 #define kernel_dirent dirent
 #endif
@@ -889,7 +890,8 @@
 }
 #endif /* HAVE_STAT64 */
 
-#if defined(LINUX) && !defined(IA64) && !defined(HPPA) && !defined(X86_64)
+#if defined(LINUX) && !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
+    && !defined(S390) && !defined(S390X)
 static void
 convertoldstat(oldbuf, newbuf)
 const struct __old_kernel_stat *oldbuf;
@@ -942,7 +944,7 @@
 	convertoldstat(&statbuf, &newstatbuf);
 	realprintstat(tcp, &newstatbuf);
 }
-#endif /* LINUX && !IA64 */
+#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
 
 #ifndef HAVE_LONG_LONG_OFF_T
 int
@@ -977,7 +979,8 @@
 }
 
 #ifdef LINUX
-# if !defined(IA64) && !defined(HPPA) && !defined(X86_64)
+# if !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
+     && !defined(S390) && !defined(S390X)
 int
 sys_oldstat(tcp)
 struct tcb *tcp;
@@ -1024,7 +1027,8 @@
 }
 
 #ifdef LINUX
-# if !defined(IA64) && !defined(HPPA) && !defined(X86_64)
+# if !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
+     && !defined(S390) && !defined(S390X)
 int
 sys_oldfstat(tcp)
 struct tcb *tcp;
@@ -1036,7 +1040,7 @@
 	}
 	return 0;
 }
-# endif /* !IA64 && !HPPA*/
+# endif /* !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
 #endif
 
 #ifndef HAVE_LONG_LONG_OFF_T
@@ -1072,7 +1076,8 @@
 }
 
 #ifdef LINUX
-# if !defined(IA64) && !defined(HPPA) && !defined(X86_64)
+# if !defined(IA64) && !defined(HPPA) && !defined(X86_64) \
+     && !defined(S390) && !defined(S390X)
 int
 sys_oldlstat(tcp)
 struct tcb *tcp;
@@ -1085,7 +1090,7 @@
 	}
 	return 0;
 }
-# endif /* !IA64 && !HPPA */
+# endif /* !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
 #endif
 
 
diff --git a/linux/syscall.h b/linux/syscall.h
index 0eff5ed..c7af41a 100644
--- a/linux/syscall.h
+++ b/linux/syscall.h
@@ -96,6 +96,7 @@
 /* new ones */
 int sys_query_module();
 int sys_poll();
+int sys_mincore();
 
 /* architecture-specific calls */
 #ifdef ALPHA
@@ -137,11 +138,11 @@
 #  undef SYS_sendmsg
 #  undef SYS_recvmsg
 #endif /* IA64 */
-#ifdef POWERPC
+#if defined(POWERPC) || defined(S390) || defined(S390X)
 #  define SYS_socket_subcall	256
 #else
 #  define SYS_socket_subcall	230
-#endif
+#endif /* (POWERPC || S390 || S390X) */
 #define SYS_socket		(SYS_socket_subcall + 1)
 #define SYS_bind		(SYS_socket_subcall + 2)
 #define SYS_connect		(SYS_socket_subcall + 3)
@@ -192,11 +193,11 @@
 #  undef SYS_shmget
 #  undef SYS_shmctl
 # endif /* IA64 */
-#ifdef POWERPC
+#if defined(POWERPC) || defined(S390) || defined(S390X)
 #  define SYS_ipc_subcall		((SYS_socket_subcall)+(SYS_socket_nsubcalls))
 #else
 #  define SYS_ipc_subcall		250
-#endif
+#endif /* (POWERPC || S390 || S390X) */
 #define SYS_semop		(SYS_ipc_subcall + 1)
 #define SYS_semget		(SYS_ipc_subcall + 2)
 #define SYS_semctl		(SYS_ipc_subcall + 3)
diff --git a/process.c b/process.c
index ed5d2a8..8c90651 100644
--- a/process.c
+++ b/process.c
@@ -503,12 +503,10 @@
 #elif defined(POWERPC)
 	if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
 		return -1;
-#elif defined(S390)
-	long	pc;
-	if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
-	    	return -1;
-	if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
-	    	return -1;
+#elif defined(S390) || defined(S390X)
+	/* s390 linux after 2.4.7 has a hook in entry.S to allow this */
+	if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
+	        return -1;
 	return 0;
 #elif defined(M68K)
 	if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
@@ -598,6 +596,18 @@
 		if (errno)
 			return -1;
 	}
+#elif defined(S390) || defined(S390X)
+        {
+		if(argnum <= 5)
+			ptrace(PTRACE_POKEUSER, tcp->pid,
+			       (char *) (argnum==0 ? PT_ORIGGPR2 : 
+			       PT_GPR2 + argnum*sizeof(long)), 
+			       tcp->u_arg[argnum]);
+		else
+			return -E2BIG;
+		if (errno)
+			return -1;
+        }
 #else
 # warning Sorry, setargs not implemented for this architecture.
 #endif
@@ -1769,7 +1779,7 @@
 #endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
 struct xlat struct_user_offsets[] = {
 #ifdef LINUX
-#ifdef S390
+#if defined(S390) || defined(S390X)
 	{ PT_PSWMASK,		"psw_mask"				},
 	{ PT_PSWADDR,		"psw_addr"				},
 	{ PT_GPR0,		"gpr0"					},
@@ -1806,6 +1816,7 @@
 	{ PT_ACR15,		"acr15"					},
 	{ PT_ORIGGPR2,		"orig_gpr2"				},
 	{ PT_FPC,		"fpc"					},
+#if defined(S390)
 	{ PT_FPR0_HI,		"fpr0.hi"				},
 	{ PT_FPR0_LO,		"fpr0.lo"				},
 	{ PT_FPR1_HI,		"fpr1.hi"				},
@@ -1838,9 +1849,29 @@
 	{ PT_FPR14_LO,		"fpr14.lo"				},
 	{ PT_FPR15_HI,		"fpr15.hi"				},
 	{ PT_FPR15_LO,		"fpr15.lo"				},
+#endif
+#if defined(S390X)
+	{ PT_FPR0,		"fpr0"					},
+	{ PT_FPR1,		"fpr1"					},
+	{ PT_FPR2,		"fpr2"					},
+	{ PT_FPR3,		"fpr3"					},
+	{ PT_FPR4,		"fpr4"					},
+	{ PT_FPR5,		"fpr5"					},
+	{ PT_FPR6,		"fpr6"					},
+	{ PT_FPR7,		"fpr7"					},
+	{ PT_FPR8,		"fpr8"					},
+	{ PT_FPR9,		"fpr9"					},
+	{ PT_FPR10,		"fpr10"					},
+	{ PT_FPR11,		"fpr11"					},
+	{ PT_FPR12,		"fpr12"					},
+	{ PT_FPR13,		"fpr13"					},
+	{ PT_FPR14,		"fpr14"					},
+	{ PT_FPR15,		"fpr15"					},
+#endif
 	{ PT_CR_9,		"cr9"					},
 	{ PT_CR_10,		"cr10"					},
 	{ PT_CR_11,		"cr11"					},
+	{ PT_IEEE_IP,           "ieee_exception_ip"                     },
 #endif
 #if defined(SPARC)
 	/* XXX No support for these offsets yet. */
@@ -2147,7 +2178,7 @@
        { 4*REG_FPSCR,          "4*REG_FPSCR"                           },
 #endif /* SH */
 
-#if !defined(S390) && !defined(MIPS)
+#if !defined(S390) && !defined(S390X) && !defined(MIPS)
 	{ uoff(u_fpvalid),	"offsetof(struct user, u_fpvalid)"	},
 #endif
 #if  defined(I386) || defined(X86_64)
@@ -2163,11 +2194,11 @@
 	{ uoff(start_code),	"offsetof(struct user, start_code)"	},
 	{ uoff(start_stack),	"offsetof(struct user, start_stack)"	},
 	{ uoff(signal),		"offsetof(struct user, signal)"		},
-#if !defined(S390) && !defined(MIPS) && !defined(SH)
+#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH)
 	{ uoff(reserved),	"offsetof(struct user, reserved)"	},
 #endif
 	{ uoff(u_ar0),		"offsetof(struct user, u_ar0)"		},
-#if !defined(ARM) && !defined(MIPS) && !defined(S390)
+#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X)
 	{ uoff(u_fpstate),	"offsetof(struct user, u_fpstate)"	},
 #endif
 	{ uoff(magic),		"offsetof(struct user, magic)"		},
diff --git a/signal.c b/signal.c
index 5621795..7f39fe9 100644
--- a/signal.c
+++ b/signal.c
@@ -1163,7 +1163,7 @@
 sys_sigreturn(tcp)
 struct tcb *tcp;
 {
-#ifdef S390
+#if defined(S390) || defined(S390X)
     long usp;
     struct sigcontext_struct sc;
 
@@ -1179,7 +1179,7 @@
 	    tcp->u_rval = tcp->u_error = 0;
 	    if (tcp->u_arg[0] == 0)
 		    return 0;
-	    tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1]);
+	    tcp->auxstr = sprintsigmask("mask now ",(sigset_t *)&tcp->u_arg[1],0);
 	    return RVAL_NONE | RVAL_STR;
     }
     return 0;
diff --git a/stream.c b/stream.c
index 42bfcc8..c8a6beb 100644
--- a/stream.c
+++ b/stream.c
@@ -1054,7 +1054,7 @@
 		break;
 #endif /* SI_GETUDATA */
 	default:
-		printstr(tcp, (int) si.ic_dp, si.ic_len);
+		printstr(tcp, (long) si.ic_dp, si.ic_len);
 		break;
 	}
 	if (exiting(tcp)) {
diff --git a/syscall.c b/syscall.c
index ff86032..5119668 100644
--- a/syscall.c
+++ b/syscall.c
@@ -506,7 +506,8 @@
 int nsubcalls;
 enum subcall_style style;
 {
-	int i, addr, mask, arg;
+	long addr, mask, arg;
+	int i;
 
 	switch (style) {
 	case shift_style:
@@ -679,7 +680,7 @@
 #elif defined(MIPS)
 	static long a3;
 	static long r2;
-#elif defined(S390)
+#elif defined(S390) || defined(S390X)
 	static long gpr2;
 	static long pc;
 #elif defined(HPPA)
@@ -705,10 +706,10 @@
 #endif /* !PROCFS */	
 
 #ifdef LINUX
-#if defined(S390)
-	if (upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
+#if defined(S390) || defined(S390X)
+	if (upeek(pid,PT_PSWADDR,&pc) < 0)
 		return -1;
-	scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-4),0);
+	scno = ptrace(PTRACE_PEEKTEXT, pid, (char *)(pc-sizeof(long)),0);
 	if (errno)
 		return -1;
 	scno&=0xFF;
@@ -1098,7 +1099,7 @@
 			fprintf(stderr, "stray syscall exit: rax = %ld\n", rax);
 		return 0;
 	}
-#elif defined (S390)
+#elif defined (S390) || defined (S390X)
 	if (upeek(pid, PT_GPR2, &gpr2) < 0)
 		return -1;
 	if (gpr2 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
@@ -1154,7 +1155,7 @@
 {
 	int u_error = 0;
 #ifdef LINUX
-#ifdef S390
+#if defined(S390) || defined(S390X)
 		if (gpr2 && (unsigned) -gpr2 < nerrnos) {
 			tcp->u_rval = -1;
 			u_error = -gpr2;
@@ -1163,7 +1164,7 @@
 			tcp->u_rval = gpr2;
 			u_error = 0;
 		}
-#else /* !S390 */
+#else /* !S390 && !S390X */
 #ifdef I386
 		if (eax < 0 && -eax < nerrnos) {
 			tcp->u_rval = -1;
@@ -1297,7 +1298,7 @@
 #endif /* IA64 */
 #endif /* X86_64 */
 #endif /* I386 */
-#endif /* S390 */
+#endif /* S390 || S390X */
 #endif /* LINUX */
 #ifdef SUNOS4
 		/* get error code from user struct */
@@ -1381,7 +1382,7 @@
 	int pid = tcp->pid;
 #endif /* !USE_PROCFS */	
 #ifdef LINUX
-#if defined(S390)
+#if defined(S390) || defined(S390X)
 	{
 		int i;
 		if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
@@ -1389,7 +1390,7 @@
 		else 
      	        	tcp->u_nargs = MAX_ARGS;
 		for (i = 0; i < tcp->u_nargs; i++) {
-			if (upeek(pid,i==0 ? PT_ORIGGPR2:PT_GPR2+(i<<2), &tcp->u_arg[i]) < 0)
+			if (upeek(pid,i==0 ? PT_ORIGGPR2:PT_GPR2+i*sizeof(long), &tcp->u_arg[i]) < 0)
 				return -1;
 		}
 	}
diff --git a/util.c b/util.c
index d34a66d..5c8a6a5 100644
--- a/util.c
+++ b/util.c
@@ -955,8 +955,9 @@
 	if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,0) < 0)
 		return -1;
 	pc = regs.r_pc;
-#elif defined(S390)
+#elif defined(S390) || defined(S390X)
 	if(upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
+		return -1;
 #elif defined(HPPA)
 	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0)
 		return -1;
@@ -1239,6 +1240,8 @@
 #define LOOP	0x1000ffff
 #elif defined(S390)
 #define LOOP	0xa7f40000	/* BRC 15,0 */
+#elif defined(S390X)
+#define LOOP   0xa7f4000000000000UL /* BRC 15,0 */
 #elif defined(HPPA)
 #define LOOP	0xe81f1ff7	/* b,l,n <loc>,r0 */
 #elif defined(SH)
@@ -1273,7 +1276,7 @@
 #elif defined (POWERPC)
 	if (upeek(tcp->pid, 4*PT_NIP, &tcp->baddr) < 0)
 		return -1;
-#elif defined(S390)
+#elif defined(S390) || defined(S390X)
 	if (upeek(tcp->pid,PT_PSWADDR, &tcp->baddr) < 0)
 		return -1;
 #elif defined(HPPA)