--- ac_clean/arch/um/Makefile-ppc	Tue May 29 15:15:39 2001
+++ ac/arch/um/Makefile-ppc	Sun May 27 15:58:57 2001
@@ -1,2 +1,5 @@
 START_ADDR = 0x20000000
-ARCH_CFLAGS = -U__powerpc__
+ARCH_CFLAGS = -U__powerpc__ -D__UM_PPC__
+
+# The arch is ppc, but the elf32 name is powerpc
+ELF_SUBARCH = powerpc
--- ac_clean/arch/um/include/sysdep-i386/ptrace.h	Tue May 29 15:15:39 2001
+++ ac/arch/um/include/sysdep-i386/ptrace.h	Sun May 27 19:39:58 2001
@@ -6,11 +6,14 @@
 #ifndef __SYSDEP_I386_PTRACE_H
 #define __SYSDEP_I386_PTRACE_H
 
+#define UM_MAX_REG (17)
+#define UM_MAX_REG_OFFSET (UM_MAX_REG * sizeof(long))
+
 struct sys_pt_regs {
-  unsigned long regs[17];
+  unsigned long regs[UM_MAX_REG];
 };
 
-#define EMPTY_REGS { { [ 0 ... 16 ] = 0 } }
+#define EMPTY_REGS { { [ 0 ... UM_MAX_REG - 1 ] = 0 } }
 
 #define UM_REG(r, n) ((r)->regs[n])
 
@@ -41,6 +44,10 @@
 #define UM_SYSCALL_ARG4_OFFSET (ESI * sizeof(long))
 #define UM_SYSCALL_ARG5_OFFSET (EDI * sizeof(long))
 #define UM_SYSCALL_ARG6_OFFSET (EBP * sizeof(long))
+
+#define UM_SET_SYSCALL_RETURN(r, result) UM_REG(r, EAX) = (result)
+
+#define UM_FIX_EXEC_STACK(sp) do ; while(0)
 
 #endif
 
--- ac_clean/arch/um/include/sysdep-ppc/ptrace.h	Tue May 29 15:15:39 2001
+++ ac/arch/um/include/sysdep-ppc/ptrace.h	Sun May 27 15:49:30 2001
@@ -5,6 +5,9 @@
 #ifndef __SYS_PTRACE_PPC_H
 #define __SYS_PTRACE_PPC_H
 
+#include "linux/config.h"
+#include "linux/types.h"
+
 /* the following taken from <asm-ppc/ptrace.h> */
 
 #ifdef CONFIG_PPC64
@@ -29,29 +32,55 @@
 	PPC_REG result; 	/* Result of a system call */
 };
 
+#define NUM_REGS (sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG))
+
 struct sys_pt_regs {
-	union {
-		struct sys_pt_regs_s s;
-		PPC_REG regs[sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG)];
-	} u;
+    PPC_REG regs[sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG)];
 };
 
-#define EMPTY_REGS { { { { [ 0 ... 31 ] = 0 }, \
-                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } }
+#define UM_MAX_REG (PT_FPR0)
+#define UM_MAX_REG_OFFSET (UM_MAX_REG * sizeof(PPC_REG))
+
+#define EMPTY_REGS { { [ 0 ... NUM_REGS ] = 0 } }
 
-#define UM_SYSCALL_RET(r) ((r)->u.s.gpr[3])
-#define UM_SP(r) ((r)->u.s.gpr[1])
-#define UM_SYSCALL_NR(r) ((r)->u.s.gpr[3])
-#define UM_SYSCALL_ARG1(r) ((r)->u.s.gpr[4])
-#define UM_SYSCALL_ARG2(r) ((r)->u.s.gpr[5])
-#define UM_SYSCALL_ARG3(r) ((r)->u.s.gpr[7])
-#define UM_SYSCALL_ARG4(r) ((r)->u.s.gpr[8])
-#define UM_SYSCALL_ARG5(r) ((r)->u.s.gpr[9])
-#define UM_SYSCALL_ARG6(r) ((r)->u.s.gpr[10])
+#define UM_REG(r, n) ((r)->regs[n])
 
-#define UM_SYSCALL_NR_OFFSET (PT_R3 * sizeof(PPC_REG))
+#define UM_SYSCALL_RET(r) UM_REG(r, PT_R3)
+#define UM_SP(r) UM_REG(r, PT_R1)
+#define UM_IP(r) UM_REG(r, PT_NIP)
+#define UM_ELF_ZERO(r) UM_REG(r, PT_FPSCR)
+#define UM_SYSCALL_NR(r) UM_REG(r, PT_R0)
+#define UM_SYSCALL_ARG1(r) UM_REG(r, PT_ORIG_R3)
+#define UM_SYSCALL_ARG2(r) UM_REG(r, PT_R4)
+#define UM_SYSCALL_ARG3(r) UM_REG(r, PT_R5)
+#define UM_SYSCALL_ARG4(r) UM_REG(r, PT_R6)
+#define UM_SYSCALL_ARG5(r) UM_REG(r, PT_R7)
+#define UM_SYSCALL_ARG6(r) UM_REG(r, PT_R8)
+
+#define UM_SYSCALL_NR_OFFSET (PT_R0 * sizeof(PPC_REG))
+#define UM_SYSCALL_RET_OFFSET (PT_R3 * sizeof(PPC_REG))
+#define UM_SYSCALL_ARG1_OFFSET (PT_R3 * sizeof(PPC_REG))
+#define UM_SYSCALL_ARG2_OFFSET (PT_R4 * sizeof(PPC_REG))
+#define UM_SYSCALL_ARG3_OFFSET (PT_R5 * sizeof(PPC_REG))
+#define UM_SYSCALL_ARG4_OFFSET (PT_R6 * sizeof(PPC_REG))
+#define UM_SYSCALL_ARG5_OFFSET (PT_R7 * sizeof(PPC_REG))
+#define UM_SYSCALL_ARG6_OFFSET (PT_R8 * sizeof(PPC_REG))
 #define UM_SP_OFFSET (PT_R1 * sizeof(PPC_REG))
 #define UM_IP_OFFSET (PT_NIP * sizeof(PPC_REG))
+#define UM_ELF_ZERO_OFFSET (PT_R3 * sizeof(PPC_REG))
+
+#define UM_SET_SYSCALL_RETURN(_regs, result)	        \
+do {                                                    \
+        if (result < 0) {				\
+		(_regs)->regs[PT_CCR] |= 0x10000000;	\
+		UM_SYSCALL_RET((_regs)) = -result;	\
+        } else {					\
+		UM_SYSCALL_RET((_regs)) = result;	\
+        }                                               \
+while(0)
+
+extern void shove_aux_table(unsigned long sp);
+#define UM_FIX_EXEC_STACK(sp) shove_aux_table(sp);
 
 #endif
 
--- ac_clean/arch/um/kernel/trap_user.c	Tue May 29 15:15:39 2001
+++ ac/arch/um/kernel/trap_user.c	Tue May 29 15:10:47 2001
@@ -84,10 +84,6 @@
 
 extern void signal_usr1(int sig);
 
-struct timeval last_exit;
-int last_status;
-int last_pid;
-
 int tracing_pid;
 
 int signals(int (*init_proc)(void *), void *sp)
@@ -131,9 +127,6 @@
 		}
 		nsignals++;
 		if(WIFEXITED(status)){
-			gettimeofday(&last_exit, NULL);
-			last_status = WIFEXITED(status);
-			last_pid = pid;
 		}
 #ifdef notdef
 		{
--- ac_clean/arch/um/sys-ppc/Makefile	Tue May 29 15:15:39 2001
+++ ac/arch/um/sys-ppc/Makefile	Sun May 27 15:49:42 2001
@@ -1,9 +1,16 @@
 OBJ = sys.o
 
-OBJS = ptrace.o sigcontext.o checksum.o miscthings.o bitops.o
+.S.o:
+	$(CC) $(AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
 
-USER_CFLAGS = $(patsubst -I%,,$(CFLAGS))
-USER_CFLAGS += -I../include -I$(TOPDIR)/include
+OBJS = ptrace.o sigcontext.o semaphore.o checksum.o miscthings.o misc.o \
+	ptrace_user.o
+#bitops.o
+
+EXTRA_CFLAGS = -I../include -I$(TOPDIR)/include
+
+USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
+USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(EXTRA_CFLAGS)
 
 all: $(OBJ)
 
@@ -12,10 +19,70 @@
 	$(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@
 
 ptrace.o: ptrace.c
-	$(CC) -D__KERNEL__ $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
+	$(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
+
+miscthings.o: miscthings.c
+	$(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
+
+semaphore.c:
+	rm -f $@
+	ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+
+checksum.S:
+	rm -f $@
+	ln -s $(TOPDIR)/arch/ppc/lib/$@ $@
+
+#misc.S:
+#	rm -f $@
+#	ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+
+../kernel/ppc_asm.tmpl:
+	rm -f $@
+	ln -s $(TOPDIR)/arch/ppc/lib/$@ $@
+	ln -s $(TOPDIR)/arch/ppc/lib/$@ ./
+
+ppc_asm.h:
+	rm -f $@
+	ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+
+mk_defs.c:
+	rm -f $@
+	ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+
+ppc_defs.head:
+	rm -f $@
+	ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@
+
+ppc_defs.h: mk_defs.c ppc_defs.head \
+		$(TOPDIR)/include/asm-ppc/mmu.h \
+		$(TOPDIR)/include/asm-ppc/processor.h \
+		$(TOPDIR)/include/asm-ppc/pgtable.h \
+		$(TOPDIR)/include/asm-ppc/ptrace.h
+#	$(CC) $(CFLAGS) -S mk_defs.c
+	cp ppc_defs.head ppc_defs.h
+# for bk, this way we can write to the file even if it's not checked out
+	echo '#define THREAD 608' >> ppc_defs.h
+	echo '#define PT_REGS 8' >> ppc_defs.h
+	echo '#define CLONE_VM 256' >> ppc_defs.h
+#	chmod u+w ppc_defs.h
+#	grep '^#define' mk_defs.s >> ppc_defs.h
+#	rm mk_defs.s
+
+asm:
+	rm -f $@
+	ln -s $(TOPDIR)/include/asm-ppc $@
+
+checksum.o: checksum.S ../kernel/ppc_asm.tmpl
+	rm -f asm
+	ln -s $(TOPDIR)/include/asm-ppc $@
+	$(CC) -I. $(AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
+	rm -f asm
 
-sigcontext.o: sigcontext.c
-	$(CC) -D__KERNEL__ $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
+misc.o: misc.S ../kernel/ppc_asm.tmpl ppc_asm.h ppc_defs.h
+	rm -f asm
+	ln -s $(TOPDIR)/include/asm-ppc asm
+	$(CC) -I. $(AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o
+	rm -f asm
 
 clean:
 	rm -f $(OBJS)
--- ac_clean/arch/um/sys-ppc/miscthings.c	Tue May 29 15:15:39 2001
+++ ac/arch/um/sys-ppc/miscthings.c	Sun May 27 15:49:42 2001
@@ -1,8 +1,51 @@
-#include <linux/config.h>
-#include <linux/threads.h>
+#include "linux/threads.h"
+#include "asm/uaccess.h"
+#include "linux/config.h"
+#include "linux/threads.h"
+#include "linux/stddef.h"
+#include "linux/elf.h"
 
-unsigned int local_bh_count[NR_CPUS];
+/* unsigned int local_bh_count[NR_CPUS]; */
 unsigned long isa_io_base = 0;
+
+
+/* The following function nicked from arch/ppc/kernel/process.c and
+ * adapted slightly */
+/*
+ * XXX ld.so expects the auxiliary table to start on
+ * a 16-byte boundary, so we have to find it and
+ * move it up. :-(
+ */
+void shove_aux_table(unsigned long sp)
+{
+	int argc;
+	char *p;
+	unsigned long e;
+	unsigned long aux_start, offset;
+
+	argc = *(int *)sp;
+	sp += sizeof(int) + (argc + 1) * sizeof(char *);
+	/* skip over the environment pointers */
+	do {
+		p = *(char **)sp;
+		sp += sizeof(char *);
+	} while (p != NULL);
+	aux_start = sp;
+	/* skip to the end of the auxiliary table */
+	do {
+		e = *(unsigned long *)sp;
+		sp += 2 * sizeof(unsigned long);
+	} while (e != AT_NULL);
+	offset = ((aux_start + 15) & ~15) - aux_start;
+	if (offset != 0) {
+		do {
+			sp -= sizeof(unsigned long);
+			e = *(unsigned long *)sp;
+			*(unsigned long *)(sp + offset) = e;
+		} while (sp > aux_start);
+	}
+}
+/* END stuff taken from arch/ppc/kernel/process.c */
 
 /*
  * Overrides for Emacs so that we follow Linus's tabbing style.
--- ac_clean/arch/um/sys-ppc/ptrace.c	Tue May 29 15:15:39 2001
+++ ac/arch/um/sys-ppc/ptrace.c	Sun May 27 15:49:42 2001
@@ -4,7 +4,7 @@
 int putreg(struct task_struct *child, unsigned long regno, 
 		  unsigned long value)
 {
-	child->thread.process_regs.u.regs[regno >> 2] = value;
+	child->thread.process_regs.regs[regno >> 2] = value;
 	return 0;
 }
 
@@ -12,7 +12,7 @@
 {
 	unsigned long retval = ~0UL;
 
-	retval &= child->thread.process_regs.u.regs[regno >> 2];
+	retval &= child->thread.process_regs.regs[regno >> 2];
 	return retval;
 }