From 9dcff02ed5ae1d8fa31728e84b0d017337f75446 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Thu, 26 Jan 2012 18:11:28 -0800
Subject: [PATCH] Check in changes needed to build ppc.  Yay!  Very likely
 broke other builds, though.

---
 src/code/debug-int.lisp |  19 +++---
 src/lisp/Darwin-os.c    | 147 +++++++++++++---------------------------
 src/lisp/Darwin-os.h    |   8 +--
 src/lisp/gencgc.c       |  30 ++++----
 src/lisp/ppc-lispregs.h |   2 +-
 5 files changed, 81 insertions(+), 125 deletions(-)

diff --git a/src/code/debug-int.lisp b/src/code/debug-int.lisp
index 9c1201723..32977253b 100644
--- a/src/code/debug-int.lisp
+++ b/src/code/debug-int.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: src/code/debug-int.lisp $")
+  "$Header: /project/cmucl/cvsroot/src/code/debug-int.lisp,v 1.142 2010-07-14 23:08:59 rtoy Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -1180,7 +1180,7 @@
 	      frame)))))
 
 
-#+(or sparc (and x86 (or darwin solaris netbsd)) (and (or x86 amd64) linux))
+#+(or sparc (and x86 darwin) (and (or x86 amd64) linux))
 (defun find-foreign-function-name (address)
   "Return a string describing the foreign function near ADDRESS"
   (let ((addr (sys:sap-int address)))
@@ -1203,7 +1203,7 @@
 		       (alien:slot info 'filename)
 		       )))))))
 
-#-(or sparc (and x86 (or darwin solaris netbsd)) (and (or x86 amd64) linux))
+#-(or sparc (and x86 darwin) (and (or x86 amd64) linux))
 (defun find-foreign-function-name (ra)
   (declare (ignore ra))
   "Foreign function call land")
@@ -1253,7 +1253,7 @@ The result is a symbol or nil if the routine cannot be found."
 ;;; LRA, and the LRA is the word offset.
 ;;;
 #-(or gengc x86 amd64)
-(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4")
+(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4" #+ppc "cmucl-ppc")
 (defun compute-calling-frame (caller lra up-frame)
   (declare (type system:system-area-pointer caller))
   (when (cstack-pointer-valid-p caller)
@@ -1362,7 +1362,7 @@ The result is a symbol or nil if the routine cannot be found."
 			       escaped))))))
 
 #-(or gengc x86 amd64)
-(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4")
+(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4" #+ppc "cmucl-ppc")
 (defun find-escaped-frame (frame-pointer)
   (declare (type system:system-area-pointer frame-pointer))
   (dotimes (index lisp::*free-interrupt-context-index* (values nil 0 nil))
@@ -1455,7 +1455,7 @@ The result is a symbol or nil if the routine cannot be found."
 		 (values code pc-offset scp)))))))))))
 
 #-(or gengc x86 amd64)
-(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4")
+(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4" #+ppc "cmucl-ppc")
 (defun find-pc-from-assembly-fun (code scp)
   "find the PC"
   (let ((return-machine-address
@@ -3079,7 +3079,7 @@ The result is a symbol or nil if the routine cannot be found."
 ;;; SUB-ACCESS-DEBUG-VAR-SLOT -- Internal.
 ;;;
 #-(or x86 amd64)
-(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4")
+(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4" #+ppc "cmucl-ppc")
 (defun sub-access-debug-var-slot (fp sc-offset &optional escaped)
   (macrolet ((with-escaped-value ((var) &body forms)
 	       `(if escaped
@@ -3505,7 +3505,7 @@ The result is a symbol or nil if the routine cannot be found."
 ;;; SUB-SET-DEBUG-VAR-SLOT -- Internal.
 ;;;
 #-(or x86 amd64)
-(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4")
+(intl:with-textdomain ("cmucl" #+sparc "cmucl-sparc-svr4" #+ppc "cmucl-ppc")
 (defun sub-set-debug-var-slot (fp sc-offset value &optional escaped)
   (macrolet ((set-escaped-value (val)
 	       `(if escaped
@@ -4501,7 +4501,8 @@ The result is a symbol or nil if the routine cannot be found."
 ;;; This handles code-location and debug-function :function-start breakpoints.
 ;;;
 (intl:with-textdomain ("cmucl" #+(or x86 amd64) "cmucl-x86-vm"
-			       #+sparc "cmucl-sparc-svr4")
+			       #+sparc "cmucl-sparc-svr4"
+			       #+ppc "cmucl-ppc")
 (defun handle-breakpoint-aux (breakpoints data offset component signal-context)
   (unless breakpoints
     (error (intl:gettext "Breakpoint that nobody wants?")))
diff --git a/src/lisp/Darwin-os.c b/src/lisp/Darwin-os.c
index 9cd0aa6fc..cceaa55f6 100644
--- a/src/lisp/Darwin-os.c
+++ b/src/lisp/Darwin-os.c
@@ -14,7 +14,7 @@
  * Frobbed for OpenBSD by Pierre R. Mai, 2001.
  * Frobbed for Darwin by Pierre R. Mai, 2003.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.35 2011/09/03 04:46:34 rtoy Exp $
+ * $Header: /project/cmucl/cvsroot/src/lisp/Darwin-os.c,v 1.16.4.3 2009-03-18 15:37:29 rtoy Exp $
  *
  */
 
@@ -99,9 +99,6 @@ timebase_init(void)
 }
 #endif
 
-void
-os_init0(const char *argv[], const char *envp[])
-{}
 
 void
 os_init(const char *argv[], const char *envp[])
@@ -113,91 +110,91 @@ os_init(const char *argv[], const char *envp[])
 }
 
 #if defined(__ppc__)
-int *
+unsigned long *
 sc_reg(os_context_t * context, int offset)
 {
-    ppc_saved_state_t *state = &context->uc_mcontext->ss;
+    _STRUCT_PPC_THREAD_STATE *state = &context->uc_mcontext->__ss;
 
     switch (offset) {
       case 0:
-	  return &state->r0;
+	  return &state->__r0;
       case 1:
-	  return &state->r1;
+	  return &state->__r1;
       case 2:
-	  return &state->r2;
+	  return &state->__r2;
       case 3:
-	  return &state->r3;
+	  return &state->__r3;
       case 4:
-	  return &state->r4;
+	  return &state->__r4;
       case 5:
-	  return &state->r5;
+	  return &state->__r5;
       case 6:
-	  return &state->r6;
+	  return &state->__r6;
       case 7:
-	  return &state->r7;
+	  return &state->__r7;
       case 8:
-	  return &state->r8;
+	  return &state->__r8;
       case 9:
-	  return &state->r9;
+	  return &state->__r9;
       case 10:
-	  return &state->r10;
+	  return &state->__r10;
       case 11:
-	  return &state->r11;
+	  return &state->__r11;
       case 12:
-	  return &state->r12;
+	  return &state->__r12;
       case 13:
-	  return &state->r13;
+	  return &state->__r13;
       case 14:
-	  return &state->r14;
+	  return &state->__r14;
       case 15:
-	  return &state->r15;
+	  return &state->__r15;
       case 16:
-	  return &state->r16;
+	  return &state->__r16;
       case 17:
-	  return &state->r17;
+	  return &state->__r17;
       case 18:
-	  return &state->r18;
+	  return &state->__r18;
       case 19:
-	  return &state->r19;
+	  return &state->__r19;
       case 20:
-	  return &state->r20;
+	  return &state->__r20;
       case 21:
-	  return &state->r21;
+	  return &state->__r21;
       case 22:
-	  return &state->r22;
+	  return &state->__r22;
       case 23:
-	  return &state->r23;
+	  return &state->__r23;
       case 24:
-	  return &state->r24;
+	  return &state->__r24;
       case 25:
-	  return &state->r25;
+	  return &state->__r25;
       case 26:
-	  return &state->r26;
+	  return &state->__r26;
       case 27:
-	  return &state->r27;
+	  return &state->__r27;
       case 28:
-	  return &state->r28;
+	  return &state->__r28;
       case 29:
-	  return &state->r29;
+	  return &state->__r29;
       case 30:
-	  return &state->r30;
+	  return &state->__r30;
       case 31:
-	  return &state->r31;
+	  return &state->__r31;
       case 34:
 	  /*
 	   * Not sure if this is really defined anywhere, but after
 	   * r31 is cr, xer, lr, and ctr.  So we let 34 be lr.
 	   */
-	  return &state->lr;
+	  return &state->__lr;
       case 35:
-	  return &state->ctr;
+	  return &state->__ctr;
       case 41:
-	  return &context->uc_mcontext->es.dar;
+	  return &context->uc_mcontext->__es.__dar;
       case 42:
-	  return &context->uc_mcontext->es.dsisr;
+	  return &context->uc_mcontext->__es.__dsisr;
     }
 
-    return (int *) 0;
+    return (unsigned long *) 0;
 }
 #elif defined(__i386__)
 #if __DARWIN_UNIX03
@@ -226,16 +223,6 @@ sc_reg(os_context_t * context, int offset)
 #define __fpu_fcw   fpu_fcw
 #define __fpu_fsw   fpu_fsw
 #define __fpu_mxcsr fpu_mxcsr
-#ifdef FEATURE_SSE2
-#define __fpu_xmm0 fpu_xmm0
-#define __fpu_xmm1 fpu_xmm1
-#define __fpu_xmm2 fpu_xmm2
-#define __fpu_xmm3 fpu_xmm3
-#define __fpu_xmm4 fpu_xmm4
-#define __fpu_xmm5 fpu_xmm5
-#define __fpu_xmm6 fpu_xmm6
-#define __fpu_xmm7 fpu_xmm7
-#endif
 #endif
 
 unsigned long *
@@ -288,24 +275,6 @@ os_sigcontext_fpu_reg(ucontext_t *scp, int index)
 	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_stmm6;
     case 7:
 	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_stmm7;
-#ifdef FEATURE_SSE2
-    case 8:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm0;
-    case 9:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm1;
-    case 10:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm2;
-    case 11:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm3;
-    case 12:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm4;
-    case 13:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm5;
-    case 14:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_xmm6;
-    case 15:
-	return (unsigned char *) &scp->uc_mcontext->__fs.__fpu_stmm7;
-#endif
     }
     return NULL;
 }
@@ -444,23 +413,18 @@ valid_addr(os_vm_address_t addr)
 
     newaddr = os_trunc_to_page(addr);
 
-    if (in_range_p(addr, READ_ONLY_SPACE_START, read_only_space_size)
-	|| in_range_p(addr, STATIC_SPACE_START, static_space_size)
+    if (in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)
+	|| in_range_p(addr, STATIC_SPACE_START, STATIC_SPACE_SIZE)
 	|| in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size)
 #ifndef GENCGC
 	|| in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
 #endif
-	|| in_range_p(addr, CONTROL_STACK_START, control_stack_size)
-	|| in_range_p(addr, BINDING_STACK_START, binding_stack_size))
+	|| in_range_p(addr, CONTROL_STACK_START, CONTROL_STACK_SIZE)
+	|| in_range_p(addr, BINDING_STACK_START, BINDING_STACK_SIZE))
 	return TRUE;
     return FALSE;
 }
 
-static void
-sigbus_handle_now(HANDLER_ARGS)
-{
-    interrupt_handle_now(signal, code, context);
-}
 
 static void
 sigbus_handler(HANDLER_ARGS)
@@ -469,11 +433,6 @@ sigbus_handler(HANDLER_ARGS)
     caddr_t fault_addr = code->si_addr;
 #endif
     
-#ifdef RED_ZONE_HIT
-    if (os_control_stack_overflow((void *) fault_addr, context))
-	return;
-#endif
-
 #ifdef __ppc__
     DPRINTF(0, (stderr, "sigbus:\n"));
     DPRINTF(0, (stderr, " PC       = %p\n", SC_PC(context)));
@@ -487,8 +446,8 @@ sigbus_handler(HANDLER_ARGS)
     
 #if defined(GENCGC)
 #if defined(SIGSEGV_VERBOSE)
-    fprintf(stderr, "Signal %d, fault_addr=%x\n",
-	    signal, fault_addr);
+    fprintf(stderr, "Signal %d, fault_addr=%x, page_index=%d:\n",
+	    signal, fault_addr, page_index);
 #endif
     if (gc_write_barrier(code->si_addr))
 	 return;
@@ -496,11 +455,9 @@ sigbus_handler(HANDLER_ARGS)
     if (interrupt_maybe_gc(signal, code, context))
 	return;
 #endif
-
     /* a *real* protection fault */
-    fprintf(stderr, "sigbus_handler: Real protection violation at %p, PC = %p\n",
-            fault_addr, (void *) SC_PC(context));
-    sigbus_handle_now(signal, code, context);
+    fprintf(stderr, "sigbus_handler: Real protection violation: %p\n", fault_addr);
+    interrupt_handle_now(signal, code, context);
 #ifdef __ppc__
     /* Work around G5 bug; fix courtesy gbyers via chandler */
     sigreturn(context);
@@ -538,11 +495,3 @@ os_dlsym(const char *sym_name, lispobj lib_list)
 
     return sym_addr;
 }
-
-#ifdef i386
-boolean
-os_support_sse2()
-{
-    return TRUE;
-}
-#endif
diff --git a/src/lisp/Darwin-os.h b/src/lisp/Darwin-os.h
index 180e686d0..fb84f1c3d 100644
--- a/src/lisp/Darwin-os.h
+++ b/src/lisp/Darwin-os.h
@@ -1,6 +1,6 @@
 /*
 
- $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.h,v 1.8 2011/01/09 00:12:36 rtoy Exp $
+ $Header: /project/cmucl/cvsroot/src/lisp/Darwin-os.h,v 1.7 2008-01-03 11:41:54 cshapiro Exp $
 
  This code was written as part of the CMU Common Lisp project at
  Carnegie Mellon University, and has been placed in the public domain.
@@ -14,7 +14,7 @@
 #include <sys/mman.h>
 #include <sys/signal.h>
 #include <signal.h>
-#include <sys/ucontext.h>
+#include <ucontext.h>
 #include <mach/vm_types.h>
 
 typedef caddr_t os_vm_address_t;
@@ -28,14 +28,14 @@ typedef int os_vm_prot_t;
 
 #define OS_VM_DEFAULT_PAGESIZE	4096
 
-#define HANDLER_ARGS int signal, siginfo_t *code, void *context
+#define HANDLER_ARGS int signal, siginfo_t *code, os_context_t *context
 #define CODE(code)  ((code) ? code->si_code : 0)
 #define os_context_t ucontext_t
 #ifdef __i386__
 #define RESTORE_FPU(context) restore_fpu(context)
 #endif
 
-int *sc_reg(os_context_t *, int);
+unsigned long *sc_reg(os_context_t *, int);
 void restore_fpu(ucontext_t *);
 
 #define PROTECTION_VIOLATION_SIGNAL SIGBUS
diff --git a/src/lisp/gencgc.c b/src/lisp/gencgc.c
index 423cc9ca9..36683a1f2 100644
--- a/src/lisp/gencgc.c
+++ b/src/lisp/gencgc.c
@@ -7,7 +7,7 @@
  *
  * Douglas Crosher, 1996, 1997, 1998, 1999.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/gencgc.c,v 1.112 2011/01/09 00:12:36 rtoy Exp $
+ * $Header: /project/cmucl/cvsroot/src/lisp/gencgc.c,v 1.112 2011-01-09 00:12:36 rtoy Exp $
  *
  */
 
@@ -169,20 +169,20 @@ check_escaped_stack_object(lispobj * where, lispobj obj)
     if (Pointerp(obj)
 	&& (p = (void *) PTR(obj),
 	    (p >= (void *) CONTROL_STACK_START
-	     && p < (void *) control_stack_end))) {
+	     && p < (void *) CONTROL_STACK_END))) {
 	char *space;
 
 	if (where >= (lispobj *) DYNAMIC_0_SPACE_START
-	    && where < (lispobj *) (DYNAMIC_0_SPACE_START + dynamic_space_size))
+	    && where < (lispobj *) (DYNAMIC_0_SPACE_START + DYNAMIC_SPACE_SIZE))
 	    space = "dynamic space";
 	else if (where >= (lispobj *) STATIC_SPACE_START
 		 && where <
-		 (lispobj *) (STATIC_SPACE_START + static_space_size)) space =
+		 (lispobj *) (STATIC_SPACE_START + STATIC_SPACE_SIZE)) space =
 		"static space";
 	else if (where >= (lispobj *) READ_ONLY_SPACE_START
 		 && where <
 		 (lispobj *) (READ_ONLY_SPACE_START +
-			      read_only_space_size)) space = "read-only space";
+			      READ_ONLY_SPACE_SIZE)) space = "read-only space";
 	else
 	    space = NULL;
 
@@ -198,7 +198,7 @@ check_escaped_stack_object(lispobj * where, lispobj obj)
 		 (unsigned long) obj, where, space);
 #ifndef i386
 	else if ((where >= (lispobj *) CONTROL_STACK_START
-		  && where < (lispobj *) (control_stack_end))
+		  && where < (lispobj *) (CONTROL_STACK_END))
 		 || (space == NULL)) {
 	    /* Do nothing if it the reference is from the control stack,
 	       because that will happen, and that's ok.  Or if it's from
@@ -2003,7 +2003,7 @@ read_only_space_p(lispobj obj)
 static inline boolean
 control_stack_space_p(lispobj obj)
 {
-    lispobj end = CONTROL_STACK_START + control_stack_size;
+    lispobj end = CONTROL_STACK_START + CONTROL_STACK_SIZE;
 
     return (obj >= CONTROL_STACK_START) && (obj < end);
 }
@@ -2011,7 +2011,7 @@ control_stack_space_p(lispobj obj)
 static inline boolean
 binding_stack_space_p(lispobj obj)
 {
-    lispobj end = BINDING_STACK_START + binding_stack_size;
+    lispobj end = BINDING_STACK_START + BINDING_STACK_SIZE;
 
     return (obj >= BINDING_STACK_START) && (obj < end);
 }
@@ -2077,6 +2077,12 @@ other_space_p(lispobj obj)
     if (obj == (lispobj) 0xffffffe9) {
         in_space = TRUE;
     }
+#elif defined(__ppc__)
+     /*
+    */
+    if (obj <= (lispobj) &fpu_restore) {
+        in_space = TRUE;
+    }
 #endif
 #endif  
 
@@ -2710,11 +2716,11 @@ scavenge_interrupt_context(os_context_t * context)
 #endif    
 
 #ifdef reg_LR
-    PAIR_INTERIOR_POINTER(pc, SC_REG(context, reg_LR));
+    PAIR_INTERIOR_POINTER(lr, SC_REG(context, reg_LR));
 #endif
 
 #ifdef reg_CTR
-    PAIR_INTERIOR_POINTER(pc, SC_REG(context, reg_CTR));
+    PAIR_INTERIOR_POINTER(ctr, SC_REG(context, reg_CTR));
 #endif    
     
     /* Scanvenge all boxed registers in the context. */
@@ -7321,7 +7327,7 @@ garbage_collect_generation(int generation, int raise)
     invalid_stack_end = (void *) &raise;
 #else /* not i386 */
     invalid_stack_start = (void *) &raise;
-    invalid_stack_end = (void *) control_stack_end;
+    invalid_stack_end = (void *) CONTROL_STACK_END;
 #endif /* not i386 */
 #endif /* GC_ASSERTIONS */
 
@@ -7381,7 +7387,7 @@ garbage_collect_generation(int generation, int raise)
     {
 	lispobj **ptr;
 
-	for (ptr = (lispobj **) control_stack_end - 1;
+	for (ptr = (lispobj **) CONTROL_STACK_END - 1;
 	     ptr > (lispobj **) (void *) &raise; ptr--)
 	    preserve_pointer(*ptr);
     }
diff --git a/src/lisp/ppc-lispregs.h b/src/lisp/ppc-lispregs.h
index 2b79bacc4..b593c1fa1 100644
--- a/src/lisp/ppc-lispregs.h
+++ b/src/lisp/ppc-lispregs.h
@@ -107,7 +107,7 @@
 #ifndef LANGUAGE_ASSEMBLY
 #if defined DARWIN
 #define SC_REG(sc,reg) (*sc_reg(sc,reg))
-#define SC_PC(sc) (sc->uc_mcontext->ss.srr0)
+#define SC_PC(sc) (sc->uc_mcontext->__ss.__srr0)
 #else
 #define SC_REG(sc,reg) (((unsigned long *)(sc->regs))[(reg)])
 #define SC_PC(sc) (((unsigned long *)(sc->regs))[PT_NIP])
-- 
GitLab