diff -urN mpd.1.0.1-orig/Systems mpd.1.0.1/Systems
--- mpd.1.0.1-orig/Systems	2004-01-20 23:13:18.000000000 +0100
+++ mpd.1.0.1/Systems	2005-02-10 00:00:33.612373408 +0100
@@ -145,6 +145,17 @@
     The assembly language code was slightly modified for SR V2 and has
     not been tested.
 
+Darwin (Mac OS X) PowerPC:
+
+    The powerpc code included was based on rs6000.s and is shared
+    with Linux PowerPC. It is necessary to use CFLAGS=-traditional-cpp 
+    if you are compiling with the patched gcc distributed by Apple.
+
+    Tested on: Power Macintosh G4/466 running Mac OS X 10.1.5, and
+    Apple's prerelease version of gcc3.
+
+    Vsuite failures: none (but mpdv only works using bash rather
+    than /bin/sh).
 
 Data General AViiON:
 
@@ -310,6 +321,22 @@
 	invoke/ref, io/read, misc/exprs, misc/fa, misc/getarg,
 	misc/swap, quick/jumble, real/array, real/external
 
+PowerPC (Linux):
+
+    Existing rs6000 code was modified for the GNU assembler, and code to
+    check for stack overflows and corruption was added. This code is
+    also used on Darwin (Mac OS X).
+
+    Tested on: Power Macintosh G4/466 running an early version of Debian
+    sarge/testing and gcc 2.94.4 20011002 (Debian prerelease).
+    
+    Vsuite failures:
+    
+         io/scanf fails due to tests running in the wrong order, apparently
+	 a bug in the shell or io/scanf/run.sh.
+
+	 examples/chap15/vm fails due to an unexpected "Killed by signal 2."
+	 message after producing the correct output.
 
 Sequent Symmetry:
 
diff -urN mpd.1.0.1-orig/arch.h mpd.1.0.1/arch.h
--- mpd.1.0.1-orig/arch.h	2000-10-31 23:53:40.000000000 +0100
+++ mpd.1.0.1/arch.h	2005-02-10 00:00:33.614373104 +0100
@@ -105,6 +105,16 @@
 #define SFILE	"rs6000.s"
 #endif
 
+#ifdef __PPC__
+#define ARCH	"Linux PowerPC"
+#define SFILE	"powerpc.s"
+#endif
+
+#ifdef __APPLE__
+#define ARCH	"Darwin PowerPC"
+#define SFILE	"powerpc.s"
+#endif
+
 #ifdef sparc
 #define ARCH	"SPARC"
 #define SFILE	"sparc.s"
diff -urN mpd.1.0.1-orig/csw/powerpc.s mpd.1.0.1/csw/powerpc.s
--- mpd.1.0.1-orig/csw/powerpc.s	1970-01-01 01:00:00.000000000 +0100
+++ mpd.1.0.1/csw/powerpc.s	2005-02-10 00:00:28.703119728 +0100
@@ -0,0 +1,273 @@
+/*  powerpc.s -- MPD assembly code for the PPC architecture
+ *  Adapted from rs6000.s
+ *
+ *  Jon Crowcroft, 1991, 1993
+ *  Gregg Townsend, 1994
+ *  Philip Derrin <philipd@cse.unsw.edu.au>, 2002
+ *
+ *  The RS6000 stack grows from high address to low.
+ *  A context array is laid out like this:
+ *
+ *	TOP (stack address + stack size)
+ *	--------------------------------------------
+ *	  -4	saved SP
+ *	  -8	TOC
+ *	 -12	LR
+ *	 -16	CR
+ *	 -20	unused
+ *	 -88	GP 13 - 31  (68 bytes)
+ *	-232	FP 14 - 31  (144 bytes)
+ *	-288	callee's save area (56 bytes)
+ * 	 ...
+ * 	room for growth
+ * 	 ...
+ *	  +4	magic word  (should be stored and checked here)
+ *	  +0	stack size  (stored here)
+ *	--------------------------------------------
+ *	BOTTOM (stack address points here)
+ */
+
+/*
+ * The following macros are to allow this file to compile with
+ * both GNU as (which requires register numbers) and Apple as
+ * (which requires register names).
+ */
+#ifdef __APPLE__
+#define		r(x)	r ## x
+#define		f(x)	f ## x
+#define		cr(x)	cr ## x
+#else
+#define		r(x)	x
+#define		f(x)	x
+#define		cr(x)	x
+#endif
+
+/*
+ * The following macros compensate for differences between
+ * the ELF and Mach-O linkers.
+ */
+#ifdef __APPLE__
+#define mpd_build_context	_mpd_build_context
+#define mpd_check_stk		_mpd_check_stk
+#define mpd_chg_context		_mpd_chg_context
+#define mpd_stk_corrupted	_mpd_stk_corrupted
+#define mpd_stk_overflow	_mpd_stk_overflow
+#define mpd_stk_underflow	_mpd_stk_underflow
+#endif
+
+#define MAGIC 7979 /* an unlikely integer */
+
+	.file	"powerpc.s"
+	.set	stkoff, 288		/* starting stack offset */
+
+#ifdef __APPLE__
+	.text
+	
+	.reference	mpd_stk_overflow
+	.reference	mpd_stk_underflow
+	.reference	mpd_stk_corrupted
+#else
+	.section	".text"
+
+	.extern	mpd_stk_overflow
+	.extern	mpd_stk_underflow
+	.extern	mpd_stk_corrupted
+#endif
+
+/* stack problem handlers  (these calls do not return) */
+
+over:	b	mpd_stk_overflow
+under:	b	mpd_stk_underflow
+bad:	b	mpd_stk_corrupted
+
+/*  mpd_build_context(code,context,stksize,arg1,arg2,arg3,arg4)
+ *               GPR:  3     4       5      6    7    8    9
+ *
+ *  code	entry point of the code to be executed in the context
+ *  context	buffer for holding the context array
+ *  stksize	size of this buffer
+ *  arg1..arg4	four int-sized arguments to be passed to the code
+ *
+ */
+
+	.globl	mpd_build_context	/* the program segment */
+#ifndef __APPLE__
+	.type	mpd_build_context,@function
+#endif
+mpd_build_context:
+
+	.align	2
+
+	lis	r(10), MAGIC		/* save magic number */
+	ori	r(10), r(10), MAGIC
+	stw	r(10), 4(r(4))
+	stw	r(5), 0(r(4))		/* save stack size */
+	add	r(4), r(4), r(5)	/* adjust GP 4 to point to stack TOP */
+
+	/* save code address and args in GP 13 - 17 of context */
+
+	or	r(13), r(3), r(3)	/* code */
+	or	r(14), r(6), r(6)	/* args 1 */
+	or	r(15), r(7), r(7)	/* args 2 */
+	or	r(16), r(8), r(8)	/* args 3 */
+	or	r(17), r(9), r(9)	/* args 4 */
+	stmw	r(13), -88(r(4))	/* save GP registers */
+
+	/* save miscellaneous registers */
+
+	subi	r(5), r(4), stkoff	/* safe first stk offset */
+	stw	r(5), -4(r(4))	/* SP */
+
+	stw	r(2), -8(r(4))	/* TOC */
+
+#ifdef __APPLE__
+	lis	r5, hi16(mpd_startup_context)
+	ori	r5, r5, lo16(mpd_startup_context)
+#else
+	lis	5, mpd_startup_context@ha	
+	la	5, mpd_startup_context@l(5)
+#endif
+	stw	r(5), -12(r(4))	/* startup code -> LR slot  */
+
+	mfcr	r(0)
+	stw	r(0), -16(r(4))	/* CR */
+
+	blr			/* ret */
+
+/* on entry here, r3 has context, r13 new Link Reg - don't touch r13-31 */
+	.globl mpd_startup_context
+#ifndef __APPLE__
+	.type mpd_startup_context,@function
+#endif
+mpd_startup_context: /* only need args first time proc starts */
+	mtlr	r(13)			/* code start -> link reg */
+	or	r(3), r(14), r(14)	/* args 1 */
+	or	r(4), r(15), r(15)	/* args 2 */
+	or	r(5), r(16), r(16)	/* args 3 */
+	or	r(6), r(17), r(17)	/* args 4 */
+	blrl
+	b	mpd_stk_underflow 	/* if anyone returns - underflow! */
+/* end mpd_build_context */
+
+
+
+/*
+ * mpd_chg_context(newctx, oldctx)
+ *                GPR 3    GPR 4
+ *
+ *  a bit like Called Routines job - see Ch 4 - 13 in Assembler Ref
+ */
+	.globl	mpd_chg_context	/* runtime linkage space */
+#ifndef __APPLE__
+	.type	mpd_chg_context,@function
+#endif
+mpd_chg_context:
+
+	cmpi	cr(0), 0, r(4), 0
+	beq	load
+
+
+	lis	r(10), MAGIC
+	ori	r(10), r(10), MAGIC
+	lwz	r(11), 4(r(4))	/* old magic word */
+	lwz	r(12), 4(r(3))	/* new magic word */
+	cmp	cr(0), r(1), r(4)
+	blt	over
+	cmp	cr(0), r(11), r(10)
+	bne	over
+	cmp	cr(0), r(12), r(10)
+	bne	bad
+
+	lwz	r(5), 0(r(4))		/* to top */
+	add	r(4), r(4), r(5)		/* get to top of stk */
+
+	/*
+	 * Save Old Context
+	 */
+	stw	r(1), -4(r(4))	/* SP */
+	stw	r(2), -8(r(4))	/* TOC */
+	mflr	r(0)
+	stw	r(0), -12(r(4))	/* LR (return address) */
+	mfcr	r(0)
+	stw	r(0), -16(r(4))	/* CR */
+
+	stmw	r(13), -88(r(4))	/* GPRs 13-31 */
+
+	stfd	f(14), -232(r(4))	/* FPRs */
+	stfd	f(15), -224(r(4))
+	stfd	f(16), -216(r(4))
+	stfd	f(17), -208(r(4))
+	stfd	f(18), -200(r(4))
+	stfd	f(19), -192(r(4))
+	stfd	f(20), -184(r(4))
+	stfd	f(21), -176(r(4))
+	stfd	f(22), -168(r(4))
+	stfd	f(23), -160(r(4))
+	stfd	f(24), -152(r(4))
+	stfd	f(25), -144(r(4))
+	stfd	f(26), -136(r(4))
+	stfd	f(27), -128(r(4))
+	stfd	f(28), -120(r(4))
+	stfd	f(29), -112(r(4))
+	stfd	f(30), -104(r(4))
+	stfd	f(31), -96(r(4))
+
+	/*
+	 * Restore New Context
+	 */
+load:
+	lwz	r(5), 0(r(3))
+	add	r(3), r(3), r(5)
+	lwz	r(1), -4(r(3))	/* sp from newcontext -> sp */
+
+	lmw	r(13), -88(r(3))	/* restore GPRs 13-31 -> context */
+
+	lfd	f(14), -232(r(3))	/* FPRs */
+	lfd	f(15), -224(r(3))
+	lfd	f(16), -216(r(3))
+	lfd	f(17), -208(r(3))
+	lfd	f(18), -200(r(3))
+	lfd	f(19), -192(r(3))
+	lfd	f(20), -184(r(3))
+	lfd	f(21), -176(r(3))
+	lfd	f(22), -168(r(3))
+	lfd	f(23), -160(r(3))
+	lfd	f(24), -152(r(3))
+	lfd	f(25), -144(r(3))
+	lfd	f(26), -136(r(3))
+	lfd	f(27), -128(r(3))
+	lfd	f(28), -120(r(3))
+	lfd	f(29), -112(r(3))
+	lfd	f(30), -104(r(3))
+	lfd	f(31), -96(r(3))
+
+/* don't touch 13-31 */
+	lwz	r(2), -8(r(3))	/* TOC -> context */
+	lwz	r(0), -12(r(3))	/* LR -> context */
+	mtlr	r(0)		/* get LR */
+	lwz	r(0), -16(r(3))	/* CR -> context */
+	mtcr	r(0)		/* get CR */
+	blr			/* execute new context */
+	/* blr */			/* ?? -- seems necessary */
+/* I'm not sure why the second blr seemed necessary. It doesn't appear
+ * to be now. It may be because they were originally brl (blrl),
+ * rather than just br (blr). See rs6000.s for the original code.
+ */
+/* end mpd_chg_context */
+
+
+
+/*
+ * mpd_check_stk() -- check that the stack is not overflowing
+ */
+	.globl	mpd_check_stk
+#ifndef __APPLE__
+	.type	mpd_check_stk,@function
+#endif
+mpd_check_stk:
+
+	cmp	cr(0), r(1), r(3)
+	blt	over
+	blr			/* return */
+
+/* end	mpd_check_stk */
diff -urN mpd.1.0.1-orig/mpd/elabels.awk mpd.1.0.1/mpd/elabels.awk
--- mpd.1.0.1-orig/mpd/elabels.awk	2000-10-31 23:53:42.000000000 +0100
+++ mpd.1.0.1/mpd/elabels.awk	2005-02-10 00:00:28.916087352 +0100
@@ -3,7 +3,7 @@
 		printf("/*SUPPRESS 763*/  /*(for CodeCenter)*/\n") }
 
 /enum e_/  {	s = substr($0,index($0,"_")+1)
-		s = substr(s,0,index(s," ")-1)
+		s = substr(s,1,index(s," ")-1)
 		printf("static char * %s_names[] = {\n",s)
 		running = 1
 		next
diff -urN mpd.1.0.1-orig/mpdl/gen.c mpd.1.0.1/mpdl/gen.c
--- mpd.1.0.1-orig/mpdl/gen.c	2000-10-31 23:53:42.000000000 +0100
+++ mpd.1.0.1/mpdl/gen.c	2005-02-10 00:00:29.216041752 +0100
@@ -116,8 +116,13 @@
     if (dbx)
 	*argp++ = "-g";
 
+#ifdef __APPLE__
+    if (!dbx)
+	*argp++ = "-Wl,-x";		/* strip non-extern symbols from output */
+#else
     if (!dbx)
 	*argp++ = "-s";		/* strip symbols from output if not debugging */
+#endif
 
 #ifdef MULTI_CC_OPT		/* if need special cc option for MultiMPD */
     *argp++ = MULTI_CC_OPT;
diff -urN mpd.1.0.1-orig/rts/io.c mpd.1.0.1/rts/io.c
--- mpd.1.0.1-orig/rts/io.c	2003-11-21 21:49:14.000000000 +0100
+++ mpd.1.0.1/rts/io.c	2005-02-10 00:00:29.384016216 +0100
@@ -169,7 +169,7 @@
     if ((fp->_flags & (_S_NO_READS & _S_NO_WRITES)) == 0)
 	flushout (locn, fp);
 #else
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__APPLE__)
     if (fp->_flags & __SWR)
 	flushout (locn, fp);
 #else
@@ -712,7 +712,7 @@
     int c, rtn;
 
 #ifndef __linux__
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__APPLE__)
     fp->_r++;			/* reset count clobbered by INCH macro */
 #else
     fp->_cnt++;			/* reset count clobbered by INCH macro */
@@ -751,7 +751,7 @@
     if (fp->_pptr == fp->_pbase)	/* only need to select () once */
 	wready (fp, OUTPUT);		/* wait for output file ready */
 #else
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__APPLE__)
     fp->_w++;				/* reset count clobbered by OUCH macro*/
     if (fp->_p == fp->_bf._base)	/* only need to select () once */
 	wready (fp, OUTPUT);		/* wait for output file ready */
@@ -785,7 +785,7 @@
     if (fp->_pptr == fp->_pbase)	/* if buffer empty, return */
 	return;
 #else
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__APPLE__)
     if (fp->_p == fp->_bf._base)	/* if buffer empty, return */
 	return;
 #else
diff -urN mpd.1.0.1-orig/rts/macros.h mpd.1.0.1/rts/macros.h
--- mpd.1.0.1-orig/rts/macros.h	2002-08-27 00:04:15.000000000 +0200
+++ mpd.1.0.1/rts/macros.h	2005-02-10 00:00:29.389015456 +0100
@@ -1,6 +1,5 @@
 /*  macros.h -- macro definitions  */
 
-
 /*  Trace runtime event.  */
 
 #define TRACE(label,locn,v) (mpd_trc_flag ? mpd_trace(label,locn,(Ptr)v) : 0)
@@ -59,7 +58,7 @@
 
 #else
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
 
 #define ISOPEN(f) \
     ((fp)->_flags & (__SRD | __SWR | __SRW))

