0.pre7.56:
[sbcl.git] / src / runtime / purify.c
index 2d1e4f4..eca889c 100644 (file)
 #include "gencgc.h"
 #endif
 
-#undef PRINTNOISE
+#define PRINTNOISE
 
-#if defined(ibmrt) || defined(__i386__)
+#if defined(__i386__)
+/* again, what's so special about the x86 that this is differently
+ * visible there than on other platforms? -dan 20010125 
+ */
 static lispobj *dynamic_space_free_pointer;
 #endif
 
@@ -59,7 +62,8 @@ static lispobj *pscav(lispobj *addr, int nwords, boolean constant);
 #define LATERBLOCKSIZE 1020
 #define LATERMAXCOUNT 10
 
-static struct later {
+static struct
+later {
     struct later *next;
     union {
         lispobj *ptr;
@@ -71,10 +75,11 @@ static int later_count = 0;
 #define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
 #define NWORDS(x,y) (CEILING((x),(y)) / (y))
 
+/* FIXME: (1) Shouldn't this be defined in sbcl.h? */
 #ifdef sparc
-#define RAW_ADDR_OFFSET 0
+#define FUN_RAW_ADDR_OFFSET 0
 #else
-#define RAW_ADDR_OFFSET (6*sizeof(lispobj) - type_FunctionPointer)
+#define FUN_RAW_ADDR_OFFSET (6*sizeof(lispobj) - FUN_POINTER_LOWTAG)
 #endif
 \f
 static boolean
@@ -108,110 +113,9 @@ dynamic_pointer_p(lispobj ptr)
 \f
 #ifdef __i386__
 
-#ifdef WANT_CGC
-/* original x86/CGC stack scavenging code by Paul Werkowski */
-
-static int
-maybe_can_move_p(lispobj thing)
-{
-  lispobj *thingp,header;
-  if (dynamic_pointer_p(thing)) { /* in dynamic space */
-    thingp = (lispobj*)PTR(thing);
-    header = *thingp;
-    if(Pointerp(header) && forwarding_pointer_p(header))
-      return -1;               /* must change it */
-    if(LowtagOf(thing) == type_ListPointer)
-      return type_ListPointer; /* can we check this somehow */
-    else if (thing & 3) {      /* not fixnum */
-      int kind = TypeOf(header);
-      /* printf(" %x %x",header,kind); */
-      switch (kind) {          /* something with a header */
-      case type_Bignum:
-      case type_SingleFloat:
-      case type_DoubleFloat:
-#ifdef type_LongFloat
-      case type_LongFloat:
-#endif
-      case type_Sap:
-      case type_SimpleVector:
-      case type_SimpleString:
-      case type_SimpleBitVector:
-      case type_SimpleArrayUnsignedByte2:
-      case type_SimpleArrayUnsignedByte4:
-      case type_SimpleArrayUnsignedByte8:
-      case type_SimpleArrayUnsignedByte16:
-      case type_SimpleArrayUnsignedByte32:
-#ifdef type_SimpleArraySignedByte8
-      case type_SimpleArraySignedByte8:
-#endif
-#ifdef type_SimpleArraySignedByte16
-      case type_SimpleArraySignedByte16:
-#endif
-#ifdef type_SimpleArraySignedByte30
-      case type_SimpleArraySignedByte30:
-#endif
-#ifdef type_SimpleArraySignedByte32
-      case type_SimpleArraySignedByte32:
-#endif
-      case type_SimpleArraySingleFloat:
-      case type_SimpleArrayDoubleFloat:
-#ifdef type_SimpleArrayLongFloat
-      case type_SimpleArrayLongFloat:
-#endif
-#ifdef type_SimpleArrayComplexSingleFloat
-      case type_SimpleArrayComplexSingleFloat:
-#endif
-#ifdef type_SimpleArrayComplexDoubleFloat
-      case type_SimpleArrayComplexDoubleFloat:
-#endif
-#ifdef type_SimpleArrayComplexLongFloat
-      case type_SimpleArrayComplexLongFloat:
-#endif
-      case type_CodeHeader:
-      case type_FunctionHeader:
-      case type_ClosureFunctionHeader:
-      case type_ReturnPcHeader:
-      case type_ClosureHeader:
-      case type_FuncallableInstanceHeader:
-      case type_InstanceHeader:
-      case type_ValueCellHeader:
-      case type_ByteCodeFunction:
-      case type_ByteCodeClosure:
-      case type_WeakPointer:
-      case type_Fdefn:
-       return kind;
-       break;
-      default:
-       return 0;
-      }}}
-  return 0;
-}
-
-static int pverbose=0;
-#define PVERBOSE pverbose
-static void
-carefully_pscav_stack(lispobj*lowaddr, lispobj*base)
-{
-  lispobj*sp = lowaddr;
-  while (sp < base)
-    { int k;
-      lispobj thing = *sp;
-      if((unsigned)thing & 0x3)        /* may be pointer */
-       {
-         /* need to check for valid float/double? */
-         k = maybe_can_move_p(thing);
-         if(PVERBOSE)printf("%8x %8x %d\n",sp, thing, k);
-         if(k)
-           pscav(sp, 1, 0);
-       }
-      sp++;
-    }
-}
-#endif
-
 #ifdef GENCGC
 /*
- * Enhanced x86/GENCGC stack scavenging by Douglas Crosher.
+ * enhanced x86/GENCGC stack scavenging by Douglas Crosher
  *
  * Scavenging the stack on the i386 is problematic due to conservative
  * roots and raw return addresses. Here it is handled in two passes:
@@ -222,210 +126,217 @@ carefully_pscav_stack(lispobj*lowaddr, lispobj*base)
 
 static unsigned pointer_filter_verbose = 0;
 
+/* FIXME: This is substantially the same code as in gencgc.c. (There
+ * are some differences, at least (1) the gencgc.c code needs to worry
+ * about return addresses on the stack pinning code objects, (2) the
+ * gencgc.c code needs to worry about the GC maybe happening in an
+ * interrupt service routine when the main thread of control was
+ * interrupted just as it had allocated memory and before it
+ * initialized it, while PURIFY needn't worry about that, and (3) the
+ * gencgc.c code has mutated more under maintenance since the fork
+ * from CMU CL than the code here has.) The two versions should be
+ * made to explicitly share common code, instead of just two different
+ * cut-and-pasted versions. */
 static int
 valid_dynamic_space_pointer(lispobj *pointer, lispobj *start_addr)
 {
-  /* If it's not a return address then it needs to be a valid Lisp
-   * pointer. */
-  if (!Pointerp((lispobj)pointer))
-    return 0;
+    /* If it's not a return address then it needs to be a valid Lisp
+     * pointer. */
+    if (!is_lisp_pointer((lispobj)pointer))
+       return 0;
 
-  /* Check that the object pointed to is consistent with the pointer
-   * low tag. */
-  switch (LowtagOf((lispobj)pointer)) {
-  case type_FunctionPointer:
-    /* Start_addr should be the enclosing code object, or a closure
-     * header. */
-    switch (TypeOf(*start_addr)) {
-    case type_CodeHeader:
-      /* This case is probably caught above. */
-      break;
-    case type_ClosureHeader:
-    case type_FuncallableInstanceHeader:
-    case type_ByteCodeFunction:
-    case type_ByteCodeClosure:
-      if ((int)pointer != ((int)start_addr+type_FunctionPointer)) {
-       if (pointer_filter_verbose) {
-         fprintf(stderr,"*Wf2: %x %x %x\n", (unsigned int) pointer, 
-                 (unsigned int) start_addr, *start_addr);
+    /* Check that the object pointed to is consistent with the pointer
+     * low tag. */
+    switch (lowtagof((lispobj)pointer)) {
+    case FUN_POINTER_LOWTAG:
+       /* Start_addr should be the enclosing code object, or a closure
+        * header. */
+       switch (TypeOf(*start_addr)) {
+       case type_CodeHeader:
+           /* This case is probably caught above. */
+           break;
+       case type_ClosureHeader:
+       case type_FuncallableInstanceHeader:
+           if ((int)pointer != ((int)start_addr+FUN_POINTER_LOWTAG)) {
+               if (pointer_filter_verbose) {
+                   fprintf(stderr,"*Wf2: %x %x %x\n", (unsigned int) pointer, 
+                           (unsigned int) start_addr, *start_addr);
+               }
+               return 0;
+           }
+           break;
+       default:
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wf3: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
        }
-       return 0;
-      }
-      break;
-    default:
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wf3: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-    break;
-  case type_ListPointer:
-    if ((int)pointer != ((int)start_addr+type_ListPointer)) {
-      if (pointer_filter_verbose)
-       fprintf(stderr,"*Wl1: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      return 0;
-    }
-    /* Is it plausible cons? */
-    if((Pointerp(start_addr[0])
-       || ((start_addr[0] & 3) == 0) /* fixnum */
-       || (TypeOf(start_addr[0]) == type_BaseChar)
-       || (TypeOf(start_addr[0]) == type_UnboundMarker))
-       && (Pointerp(start_addr[1])
-          || ((start_addr[1] & 3) == 0) /* fixnum */
-          || (TypeOf(start_addr[1]) == type_BaseChar)
-          || (TypeOf(start_addr[1]) == type_UnboundMarker))) {
-      break;
-    } else {
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wl2: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-  case type_InstancePointer:
-    if ((int)pointer != ((int)start_addr+type_InstancePointer)) {
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wi1: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-    if (TypeOf(start_addr[0]) != type_InstanceHeader) {
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wi2: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-    break;
-  case type_OtherPointer:
-    if ((int)pointer != ((int)start_addr+type_OtherPointer)) {
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wo1: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-    /* Is it plausible?  Not a cons. X should check the headers. */
-    if(Pointerp(start_addr[0]) || ((start_addr[0] & 3) == 0)) {
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wo2: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-    switch (TypeOf(start_addr[0])) {
-    case type_UnboundMarker:
-    case type_BaseChar:
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wo3: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-
-      /* only pointed to by function pointers? */
-    case type_ClosureHeader:
-    case type_FuncallableInstanceHeader:
-    case type_ByteCodeFunction:
-    case type_ByteCodeClosure:
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wo4: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-
-    case type_InstanceHeader:
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wo5: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-
-      /* the valid other immediate pointer objects */
-    case type_SimpleVector:
-    case type_Ratio:
-    case type_Complex:
+       break;
+    case LIST_POINTER_LOWTAG:
+       if ((int)pointer != ((int)start_addr+LIST_POINTER_LOWTAG)) {
+           if (pointer_filter_verbose)
+               fprintf(stderr,"*Wl1: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           return 0;
+       }
+       /* Is it plausible cons? */
+       if((is_lisp_pointer(start_addr[0])
+           || ((start_addr[0] & 3) == 0) /* fixnum */
+           || (TypeOf(start_addr[0]) == type_BaseChar)
+           || (TypeOf(start_addr[0]) == type_UnboundMarker))
+          && (is_lisp_pointer(start_addr[1])
+              || ((start_addr[1] & 3) == 0) /* fixnum */
+              || (TypeOf(start_addr[1]) == type_BaseChar)
+              || (TypeOf(start_addr[1]) == type_UnboundMarker))) {
+           break;
+       } else {
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wl2: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+       }
+    case INSTANCE_POINTER_LOWTAG:
+       if ((int)pointer != ((int)start_addr+INSTANCE_POINTER_LOWTAG)) {
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wi1: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+       }
+       if (TypeOf(start_addr[0]) != type_InstanceHeader) {
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wi2: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+       }
+       break;
+    case OTHER_POINTER_LOWTAG:
+       if ((int)pointer != ((int)start_addr+OTHER_POINTER_LOWTAG)) {
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wo1: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+       }
+       /* Is it plausible?  Not a cons. X should check the headers. */
+       if(is_lisp_pointer(start_addr[0]) || ((start_addr[0] & 3) == 0)) {
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wo2: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+       }
+       switch (TypeOf(start_addr[0])) {
+       case type_UnboundMarker:
+       case type_BaseChar:
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wo3: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+
+           /* only pointed to by function pointers? */
+       case type_ClosureHeader:
+       case type_FuncallableInstanceHeader:
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wo4: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+
+       case type_InstanceHeader:
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wo5: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+
+           /* the valid other immediate pointer objects */
+       case type_SimpleVector:
+       case type_Ratio:
+       case type_Complex:
 #ifdef type_ComplexSingleFloat
-    case type_ComplexSingleFloat:
+       case type_ComplexSingleFloat:
 #endif
 #ifdef type_ComplexDoubleFloat
-    case type_ComplexDoubleFloat:
+       case type_ComplexDoubleFloat:
 #endif
 #ifdef type_ComplexLongFloat
-    case type_ComplexLongFloat:
-#endif
-    case type_SimpleArray:
-    case type_ComplexString:
-    case type_ComplexBitVector:
-    case type_ComplexVector:
-    case type_ComplexArray:
-    case type_ValueCellHeader:
-    case type_SymbolHeader:
-    case type_Fdefn:
-    case type_CodeHeader:
-    case type_Bignum:
-    case type_SingleFloat:
-    case type_DoubleFloat:
+       case type_ComplexLongFloat:
+#endif
+       case type_SimpleArray:
+       case type_ComplexString:
+       case type_ComplexBitVector:
+       case type_ComplexVector:
+       case type_ComplexArray:
+       case type_ValueCellHeader:
+       case type_SymbolHeader:
+       case type_Fdefn:
+       case type_CodeHeader:
+       case type_Bignum:
+       case type_SingleFloat:
+       case type_DoubleFloat:
 #ifdef type_LongFloat
-    case type_LongFloat:
-#endif
-    case type_SimpleString:
-    case type_SimpleBitVector:
-    case type_SimpleArrayUnsignedByte2:
-    case type_SimpleArrayUnsignedByte4:
-    case type_SimpleArrayUnsignedByte8:
-    case type_SimpleArrayUnsignedByte16:
-    case type_SimpleArrayUnsignedByte32:
+       case type_LongFloat:
+#endif
+       case type_SimpleString:
+       case type_SimpleBitVector:
+       case type_SimpleArrayUnsignedByte2:
+       case type_SimpleArrayUnsignedByte4:
+       case type_SimpleArrayUnsignedByte8:
+       case type_SimpleArrayUnsignedByte16:
+       case type_SimpleArrayUnsignedByte32:
 #ifdef type_SimpleArraySignedByte8
-    case type_SimpleArraySignedByte8:
+       case type_SimpleArraySignedByte8:
 #endif
 #ifdef type_SimpleArraySignedByte16
-    case type_SimpleArraySignedByte16:
+       case type_SimpleArraySignedByte16:
 #endif
 #ifdef type_SimpleArraySignedByte30
-    case type_SimpleArraySignedByte30:
+       case type_SimpleArraySignedByte30:
 #endif
 #ifdef type_SimpleArraySignedByte32
-    case type_SimpleArraySignedByte32:
+       case type_SimpleArraySignedByte32:
 #endif
-    case type_SimpleArraySingleFloat:
-    case type_SimpleArrayDoubleFloat:
+       case type_SimpleArraySingleFloat:
+       case type_SimpleArrayDoubleFloat:
 #ifdef type_SimpleArrayLongFloat
-    case type_SimpleArrayLongFloat:
+       case type_SimpleArrayLongFloat:
 #endif
 #ifdef type_SimpleArrayComplexSingleFloat
-    case type_SimpleArrayComplexSingleFloat:
+       case type_SimpleArrayComplexSingleFloat:
 #endif
 #ifdef type_SimpleArrayComplexDoubleFloat
-    case type_SimpleArrayComplexDoubleFloat:
+       case type_SimpleArrayComplexDoubleFloat:
 #endif
 #ifdef type_SimpleArrayComplexLongFloat
-    case type_SimpleArrayComplexLongFloat:
-#endif
-    case type_Sap:
-    case type_WeakPointer:
-      break;
-
+       case type_SimpleArrayComplexLongFloat:
+#endif
+       case type_Sap:
+       case type_WeakPointer:
+           break;
+
+       default:
+           if (pointer_filter_verbose) {
+               fprintf(stderr,"*Wo6: %x %x %x\n", (unsigned int) pointer, 
+                       (unsigned int) start_addr, *start_addr);
+           }
+           return 0;
+       }
+       break;
     default:
-      if (pointer_filter_verbose) {
-       fprintf(stderr,"*Wo6: %x %x %x\n", (unsigned int) pointer, 
-               (unsigned int) start_addr, *start_addr);
-      }
-      return 0;
-    }
-    break;
-  default:
-    if (pointer_filter_verbose) {
-      fprintf(stderr,"*W?: %x %x %x\n", (unsigned int) pointer, 
-             (unsigned int) start_addr, *start_addr);
+       if (pointer_filter_verbose) {
+           fprintf(stderr,"*W?: %x %x %x\n", (unsigned int) pointer, 
+                   (unsigned int) start_addr, *start_addr);
+       }
+       return 0;
     }
-    return 0;
-  }
 
-  /* looks good */
-  return 1;
+    /* looks good */
+    return 1;
 }
 
 #define MAX_STACK_POINTERS 256
@@ -441,60 +352,61 @@ unsigned int num_valid_stack_ra_locations;
 static void
 setup_i386_stack_scav(lispobj *lowaddr, lispobj *base)
 {
-  lispobj *sp = lowaddr;
-  num_valid_stack_locations = 0;
-  num_valid_stack_ra_locations = 0;
-  for (sp = lowaddr; sp < base; sp++) {
-    lispobj thing = *sp;
-    /* Find the object start address */
-    lispobj *start_addr = search_dynamic_space((void *)thing);
-    if (start_addr) {
-      /* We need to allow raw pointers into Code objects for return
-       * addresses. This will also pick up pointers to functions in code
-       * objects. */
-      if (TypeOf(*start_addr) == type_CodeHeader) {
-       gc_assert(num_valid_stack_ra_locations < MAX_STACK_RETURN_ADDRESSES);
-       valid_stack_ra_locations[num_valid_stack_ra_locations] = sp;
-       valid_stack_ra_code_objects[num_valid_stack_ra_locations++] =
-         (lispobj *)((int)start_addr + type_OtherPointer);
-      } else {
-       if (valid_dynamic_space_pointer((void *)thing, start_addr)) {
-         gc_assert(num_valid_stack_locations < MAX_STACK_POINTERS);
-         valid_stack_locations[num_valid_stack_locations++] = sp;
+    lispobj *sp = lowaddr;
+    num_valid_stack_locations = 0;
+    num_valid_stack_ra_locations = 0;
+    for (sp = lowaddr; sp < base; sp++) {
+       lispobj thing = *sp;
+       /* Find the object start address */
+       lispobj *start_addr = search_dynamic_space((void *)thing);
+       if (start_addr) {
+           /* We need to allow raw pointers into Code objects for
+            * return addresses. This will also pick up pointers to
+            * functions in code objects. */
+           if (TypeOf(*start_addr) == type_CodeHeader) {
+               gc_assert(num_valid_stack_ra_locations <
+                         MAX_STACK_RETURN_ADDRESSES);
+               valid_stack_ra_locations[num_valid_stack_ra_locations] = sp;
+               valid_stack_ra_code_objects[num_valid_stack_ra_locations++] =
+                   (lispobj *)((int)start_addr + OTHER_POINTER_LOWTAG);
+           } else {
+               if (valid_dynamic_space_pointer((void *)thing, start_addr)) {
+                   gc_assert(num_valid_stack_locations < MAX_STACK_POINTERS);
+                   valid_stack_locations[num_valid_stack_locations++] = sp;
+               }
+           }
        }
-      }
     }
-  }
-  if (pointer_filter_verbose) {
-    fprintf(stderr, "number of valid stack pointers = %d\n",
-           num_valid_stack_locations);
-    fprintf(stderr, "number of stack return addresses = %d\n",
-           num_valid_stack_ra_locations);
-  }
+    if (pointer_filter_verbose) {
+       fprintf(stderr, "number of valid stack pointers = %d\n",
+               num_valid_stack_locations);
+       fprintf(stderr, "number of stack return addresses = %d\n",
+               num_valid_stack_ra_locations);
+    }
 }
 
 static void
 pscav_i386_stack(void)
 {
-  int i;
+    int i;
 
-  for (i = 0; i < num_valid_stack_locations; i++)
-    pscav(valid_stack_locations[i], 1, 0);
+    for (i = 0; i < num_valid_stack_locations; i++)
+       pscav(valid_stack_locations[i], 1, 0);
 
-  for (i = 0; i < num_valid_stack_ra_locations; i++) {
-    lispobj code_obj = (lispobj)valid_stack_ra_code_objects[i];
-    pscav(&code_obj, 1, 0);
-    if (pointer_filter_verbose) {
-      fprintf(stderr,"*C moved RA %x to %x; for code object %x to %x\n",
-             *valid_stack_ra_locations[i],
-             (int)(*valid_stack_ra_locations[i])
-             - ((int)valid_stack_ra_code_objects[i] - (int)code_obj),
-             (unsigned int) valid_stack_ra_code_objects[i], code_obj);
+    for (i = 0; i < num_valid_stack_ra_locations; i++) {
+       lispobj code_obj = (lispobj)valid_stack_ra_code_objects[i];
+       pscav(&code_obj, 1, 0);
+       if (pointer_filter_verbose) {
+           fprintf(stderr,"*C moved RA %x to %x; for code object %x to %x\n",
+                   *valid_stack_ra_locations[i],
+                   (int)(*valid_stack_ra_locations[i])
+                   - ((int)valid_stack_ra_code_objects[i] - (int)code_obj),
+                   (unsigned int) valid_stack_ra_code_objects[i], code_obj);
+       }
+       *valid_stack_ra_locations[i] =
+           ((int)(*valid_stack_ra_locations[i])
+            - ((int)valid_stack_ra_code_objects[i] - (int)code_obj));
     }
-    *valid_stack_ra_locations[i] =
-      ((int)(*valid_stack_ra_locations[i])
-       - ((int)valid_stack_ra_code_objects[i] - (int)code_obj));
-  }
 }
 #endif
 #endif
@@ -529,7 +441,8 @@ pscav_later(lispobj *where, int count)
     }
 }
 
-static lispobj ptrans_boxed(lispobj thing, lispobj header, boolean constant)
+static lispobj
+ptrans_boxed(lispobj thing, lispobj header, boolean constant)
 {
     int nwords;
     lispobj result, *new, *old;
@@ -537,7 +450,7 @@ static lispobj ptrans_boxed(lispobj thing, lispobj header, boolean constant)
     nwords = 1 + HeaderValue(header);
 
     /* Allocate it */
-    old = (lispobj *)PTR(thing);
+    old = (lispobj *)native_pointer(thing);
     if (constant) {
         new = read_only_free;
         read_only_free += CEILING(nwords, 2);
@@ -551,7 +464,7 @@ static lispobj ptrans_boxed(lispobj thing, lispobj header, boolean constant)
     bcopy(old, new, nwords * sizeof(lispobj));
 
     /* Deposit forwarding pointer. */
-    result = (lispobj)new | LowtagOf(thing);
+    result = (lispobj)new | lowtagof(thing);
     *old = result;
 
     /* Scavenge it. */
@@ -561,12 +474,13 @@ static lispobj ptrans_boxed(lispobj thing, lispobj header, boolean constant)
 }
 
 /* We need to look at the layout to see whether it is a pure structure
- * class, and only then can we transport as constant. If it is pure, we can
- * ALWAYS transport as a constant. */
-static lispobj ptrans_instance(lispobj thing, lispobj header, boolean constant)
+ * class, and only then can we transport as constant. If it is pure,
+ * we can ALWAYS transport as a constant. */
+static lispobj
+ptrans_instance(lispobj thing, lispobj header, boolean constant)
 {
-    lispobj layout = ((struct instance *)PTR(thing))->slots[0];
-    lispobj pure = ((struct instance *)PTR(layout))->slots[15];
+    lispobj layout = ((struct instance *)native_pointer(thing))->slots[0];
+    lispobj pure = ((struct instance *)native_pointer(layout))->slots[15];
 
     switch (pure) {
     case T:
@@ -575,17 +489,18 @@ static lispobj ptrans_instance(lispobj thing, lispobj header, boolean constant)
        return (ptrans_boxed(thing, header, 0));
     case 0:
        {
-           /* Substructure: special case for the compact-info-envs, where
-            * the instance may have a point to the dynamic space placed
-            * into it (e.g. the cache-name slot), but the lists and arrays
-            * at the time of a purify can be moved to the RO space. */
+           /* Substructure: special case for the COMPACT-INFO-ENVs,
+            * where the instance may have a point to the dynamic
+            * space placed into it (e.g. the cache-name slot), but
+            * the lists and arrays at the time of a purify can be
+            * moved to the RO space. */
            int nwords;
            lispobj result, *new, *old;
 
            nwords = 1 + HeaderValue(header);
 
            /* Allocate it */
-           old = (lispobj *)PTR(thing);
+           old = (lispobj *)native_pointer(thing);
            new = static_free;
            static_free += CEILING(nwords, 2);
 
@@ -593,7 +508,7 @@ static lispobj ptrans_instance(lispobj thing, lispobj header, boolean constant)
            bcopy(old, new, nwords * sizeof(lispobj));
 
            /* Deposit forwarding pointer. */
-           result = (lispobj)new | LowtagOf(thing);
+           result = (lispobj)new | lowtagof(thing);
            *old = result;
 
            /* Scavenge it. */
@@ -607,7 +522,8 @@ static lispobj ptrans_instance(lispobj thing, lispobj header, boolean constant)
     }
 }
 
-static lispobj ptrans_fdefn(lispobj thing, lispobj header)
+static lispobj
+ptrans_fdefn(lispobj thing, lispobj header)
 {
     int nwords;
     lispobj result, *new, *old, oldfn;
@@ -616,7 +532,7 @@ static lispobj ptrans_fdefn(lispobj thing, lispobj header)
     nwords = 1 + HeaderValue(header);
 
     /* Allocate it */
-    old = (lispobj *)PTR(thing);
+    old = (lispobj *)native_pointer(thing);
     new = static_free;
     static_free += CEILING(nwords, 2);
 
@@ -624,20 +540,21 @@ static lispobj ptrans_fdefn(lispobj thing, lispobj header)
     bcopy(old, new, nwords * sizeof(lispobj));
 
     /* Deposit forwarding pointer. */
-    result = (lispobj)new | LowtagOf(thing);
+    result = (lispobj)new | lowtagof(thing);
     *old = result;
 
     /* Scavenge the function. */
     fdefn = (struct fdefn *)new;
-    oldfn = fdefn->function;
-    pscav(&fdefn->function, 1, 0);
-    if ((char *)oldfn + RAW_ADDR_OFFSET == fdefn->raw_addr)
-        fdefn->raw_addr = (char *)fdefn->function + RAW_ADDR_OFFSET;
+    oldfn = fdefn->fun;
+    pscav(&fdefn->fun, 1, 0);
+    if ((char *)oldfn + FUN_RAW_ADDR_OFFSET == fdefn->raw_addr)
+        fdefn->raw_addr = (char *)fdefn->fun + FUN_RAW_ADDR_OFFSET;
 
     return result;
 }
 
-static lispobj ptrans_unboxed(lispobj thing, lispobj header)
+static lispobj
+ptrans_unboxed(lispobj thing, lispobj header)
 {
     int nwords;
     lispobj result, *new, *old;
@@ -645,7 +562,7 @@ static lispobj ptrans_unboxed(lispobj thing, lispobj header)
     nwords = 1 + HeaderValue(header);
 
     /* Allocate it */
-    old = (lispobj *)PTR(thing);
+    old = (lispobj *)native_pointer(thing);
     new = read_only_free;
     read_only_free += CEILING(nwords, 2);
 
@@ -653,20 +570,21 @@ static lispobj ptrans_unboxed(lispobj thing, lispobj header)
     bcopy(old, new, nwords * sizeof(lispobj));
 
     /* Deposit forwarding pointer. */
-    result = (lispobj)new | LowtagOf(thing);
+    result = (lispobj)new | lowtagof(thing);
     *old = result;
 
     return result;
 }
 
-static lispobj ptrans_vector(lispobj thing, int bits, int extra,
-                            boolean boxed, boolean constant)
+static lispobj
+ptrans_vector(lispobj thing, int bits, int extra,
+             boolean boxed, boolean constant)
 {
     struct vector *vector;
     int nwords;
     lispobj result, *new;
 
-    vector = (struct vector *)PTR(thing);
+    vector = (struct vector *)native_pointer(thing);
     nwords = 2 + (CEILING((fixnum_value(vector->length)+extra)*bits,32)>>5);
 
     if (boxed && !constant) {
@@ -680,7 +598,7 @@ static lispobj ptrans_vector(lispobj thing, int bits, int extra,
 
     bcopy(vector, new, nwords * sizeof(lispobj));
 
-    result = (lispobj)new | LowtagOf(thing);
+    result = (lispobj)new | lowtagof(thing);
     vector->header = result;
 
     if (boxed)
@@ -700,12 +618,6 @@ apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
   unsigned  displacement = (unsigned)new_code - (unsigned)old_code;
   struct vector *fixups_vector;
 
-  /* Byte compiled code has no fixups. The trace table offset will be
-   * a fixnum if it's x86 compiled code - check. */
-  if (new_code->trace_table_offset & 0x3)
-    return;
-
-  /* Else it's x86 machine code. */
   ncode_words = fixnum_value(new_code->code_size);
   nheader_words = HeaderValue(*(lispobj *)new_code);
   nwords = ncode_words + nheader_words;
@@ -721,7 +633,9 @@ apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
 
   /* It will be 0 or the unbound-marker if there are no fixups, and
    * will be an other-pointer to a vector if it is valid. */
-  if ((fixups==0) || (fixups==type_UnboundMarker) || !Pointerp(fixups)) {
+  if ((fixups==0) ||
+      (fixups==type_UnboundMarker) ||
+      !is_lisp_pointer(fixups)) {
 #ifdef GENCGC
     /* Check for a possible errors. */
     sniff_code_object(new_code,displacement);
@@ -729,13 +643,13 @@ apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
     return;
   }
 
-  fixups_vector = (struct vector *)PTR(fixups);
+  fixups_vector = (struct vector *)native_pointer(fixups);
 
   /* Could be pointing to a forwarding pointer. */
-  if (Pointerp(fixups) && (dynamic_pointer_p(fixups))
+  if (is_lisp_pointer(fixups) && (dynamic_pointer_p(fixups))
       && forwarding_pointer_p(*(lispobj *)fixups_vector)) {
     /* If so then follow it. */
-    fixups_vector = (struct vector *)PTR(*(lispobj *)fixups_vector);
+    fixups_vector = (struct vector *)native_pointer(*(lispobj *)fixups_vector);
   }
 
   if (TypeOf(fixups_vector->header) == type_SimpleArrayUnsignedByte32) {
@@ -774,13 +688,14 @@ apply_code_fixups_during_purify(struct code *old_code, struct code *new_code)
 }
 #endif
 
-static lispobj ptrans_code(lispobj thing)
+static lispobj
+ptrans_code(lispobj thing)
 {
     struct code *code, *new;
     int nwords;
     lispobj func, result;
 
-    code = (struct code *)PTR(thing);
+    code = (struct code *)native_pointer(thing);
     nwords = HeaderValue(code->header) + fixnum_value(code->code_size);
 
     new = (struct code *)read_only_free;
@@ -792,7 +707,7 @@ static lispobj ptrans_code(lispobj thing)
     apply_code_fixups_during_purify(code,new);
 #endif
 
-    result = (lispobj)new | type_OtherPointer;
+    result = (lispobj)new | OTHER_POINTER_LOWTAG;
 
     /* Stick in a forwarding pointer for the code object. */
     *(lispobj *)code = result;
@@ -800,11 +715,11 @@ static lispobj ptrans_code(lispobj thing)
     /* Put in forwarding pointers for all the functions. */
     for (func = code->entry_points;
          func != NIL;
-         func = ((struct function *)PTR(func))->next) {
+         func = ((struct simple_fun *)native_pointer(func))->next) {
 
-        gc_assert(LowtagOf(func) == type_FunctionPointer);
+        gc_assert(lowtagof(func) == FUN_POINTER_LOWTAG);
 
-        *(lispobj *)PTR(func) = result + (func - thing);
+        *(lispobj *)native_pointer(func) = result + (func - thing);
     }
 
     /* Arrange to scavenge the debug info later. */
@@ -824,30 +739,32 @@ static lispobj ptrans_code(lispobj thing)
     pscav(&new->entry_points, 1, 1);
     for (func = new->entry_points;
          func != NIL;
-         func = ((struct function *)PTR(func))->next) {
-        gc_assert(LowtagOf(func) == type_FunctionPointer);
+         func = ((struct simple_fun *)native_pointer(func))->next) {
+        gc_assert(lowtagof(func) == FUN_POINTER_LOWTAG);
         gc_assert(!dynamic_pointer_p(func));
 
 #ifdef __i386__
-       /* Temporarly convert the self pointer to a real function
-           pointer. */
-       ((struct function *)PTR(func))->self -= RAW_ADDR_OFFSET;
+       /* Temporarly convert the self pointer to a real function pointer. */
+       ((struct simple_fun *)native_pointer(func))->self
+           -= FUN_RAW_ADDR_OFFSET;
 #endif
-        pscav(&((struct function *)PTR(func))->self, 2, 1);
+        pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
 #ifdef __i386__
-       ((struct function *)PTR(func))->self += RAW_ADDR_OFFSET;
+       ((struct simple_fun *)native_pointer(func))->self
+           += FUN_RAW_ADDR_OFFSET;
 #endif
-        pscav_later(&((struct function *)PTR(func))->name, 3);
+        pscav_later(&((struct simple_fun *)native_pointer(func))->name, 3);
     }
 
     return result;
 }
 
-static lispobj ptrans_func(lispobj thing, lispobj header)
+static lispobj
+ptrans_func(lispobj thing, lispobj header)
 {
     int nwords;
     lispobj code, *new, *old, result;
-    struct function *function;
+    struct simple_fun *function;
 
     /* Thing can either be a function header, a closure function
      * header, a closure, or a funcallable-instance. If it's a closure
@@ -855,16 +772,18 @@ static lispobj ptrans_func(lispobj thing, lispobj header)
      * Otherwise we have to do something strange, 'cause it is buried
      * inside a code object. */
 
-    if (TypeOf(header) == type_FunctionHeader ||
-        TypeOf(header) == type_ClosureFunctionHeader) {
+    if (TypeOf(header) == type_SimpleFunHeader ||
+        TypeOf(header) == type_ClosureFunHeader) {
 
        /* We can only end up here if the code object has not been
          * scavenged, because if it had been scavenged, forwarding pointers
          * would have been left behind for all the entry points. */
 
-        function = (struct function *)PTR(thing);
-        code = (PTR(thing)-(HeaderValue(function->header)*sizeof(lispobj))) |
-            type_OtherPointer;
+        function = (struct simple_fun *)native_pointer(thing);
+        code =
+           (native_pointer(thing) -
+            (HeaderValue(function->header)*sizeof(lispobj))) |
+            OTHER_POINTER_LOWTAG;
 
         /* This will cause the function's header to be replaced with a 
          * forwarding pointer. */
@@ -876,7 +795,7 @@ static lispobj ptrans_func(lispobj thing, lispobj header)
     else {
        /* It's some kind of closure-like thing. */
         nwords = 1 + HeaderValue(header);
-        old = (lispobj *)PTR(thing);
+        old = (lispobj *)native_pointer(thing);
 
        /* Allocate the new one. */
        if (TypeOf(header) == type_FuncallableInstanceHeader) {
@@ -895,7 +814,7 @@ static lispobj ptrans_func(lispobj thing, lispobj header)
         bcopy(old, new, nwords * sizeof(lispobj));
 
         /* Deposit forwarding pointer. */
-        result = (lispobj)new | LowtagOf(thing);
+        result = (lispobj)new | lowtagof(thing);
         *old = result;
 
         /* Scavenge it. */
@@ -905,7 +824,8 @@ static lispobj ptrans_func(lispobj thing, lispobj header)
     }
 }
 
-static lispobj ptrans_returnpc(lispobj thing, lispobj header)
+static lispobj
+ptrans_returnpc(lispobj thing, lispobj header)
 {
     lispobj code, new;
 
@@ -913,7 +833,7 @@ static lispobj ptrans_returnpc(lispobj thing, lispobj header)
     code = thing - HeaderValue(header)*sizeof(lispobj);
 
     /* Make sure it's been transported. */
-    new = *(lispobj *)PTR(code);
+    new = *(lispobj *)native_pointer(code);
     if (!forwarding_pointer_p(new))
         new = ptrans_code(code);
 
@@ -923,7 +843,8 @@ static lispobj ptrans_returnpc(lispobj thing, lispobj header)
 
 #define WORDS_PER_CONS CEILING(sizeof(struct cons) / sizeof(lispobj), 2)
 
-static lispobj ptrans_list(lispobj thing, boolean constant)
+static lispobj
+ptrans_list(lispobj thing, boolean constant)
 {
     struct cons *old, *new, *orig;
     int length;
@@ -936,7 +857,7 @@ static lispobj ptrans_list(lispobj thing, boolean constant)
 
     do {
         /* Allocate a new cons cell. */
-        old = (struct cons *)PTR(thing);
+        old = (struct cons *)native_pointer(thing);
         if (constant) {
             new = (struct cons *)read_only_free;
             read_only_free += WORDS_PER_CONS;
@@ -951,21 +872,22 @@ static lispobj ptrans_list(lispobj thing, boolean constant)
         thing = new->cdr = old->cdr;
 
         /* Set up the forwarding pointer. */
-        *(lispobj *)old = ((lispobj)new) | type_ListPointer;
+        *(lispobj *)old = ((lispobj)new) | LIST_POINTER_LOWTAG;
 
         /* And count this cell. */
         length++;
-    } while (LowtagOf(thing) == type_ListPointer &&
+    } while (lowtagof(thing) == LIST_POINTER_LOWTAG &&
              dynamic_pointer_p(thing) &&
-             !(forwarding_pointer_p(*(lispobj *)PTR(thing))));
+             !(forwarding_pointer_p(*(lispobj *)native_pointer(thing))));
 
     /* Scavenge the list we just copied. */
     pscav((lispobj *)orig, length * WORDS_PER_CONS, constant);
 
-    return ((lispobj)orig) | type_ListPointer;
+    return ((lispobj)orig) | LIST_POINTER_LOWTAG;
 }
 
-static lispobj ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
+static lispobj
+ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
 {
     switch (TypeOf(header)) {
       case type_Bignum:
@@ -1089,15 +1011,16 @@ static lispobj ptrans_otherptr(lispobj thing, lispobj header, boolean constant)
     }
 }
 
-static int pscav_fdefn(struct fdefn *fdefn)
+static int
+pscav_fdefn(struct fdefn *fdefn)
 {
     boolean fix_func;
 
-    fix_func = ((char *)(fdefn->function+RAW_ADDR_OFFSET) == fdefn->raw_addr);
+    fix_func = ((char *)(fdefn->fun+FUN_RAW_ADDR_OFFSET) == fdefn->raw_addr);
     pscav(&fdefn->name, 1, 1);
-    pscav(&fdefn->function, 1, 0);
+    pscav(&fdefn->fun, 1, 0);
     if (fix_func)
-        fdefn->raw_addr = (char *)(fdefn->function + RAW_ADDR_OFFSET);
+        fdefn->raw_addr = (char *)(fdefn->fun + FUN_RAW_ADDR_OFFSET);
     return sizeof(struct fdefn) / sizeof(lispobj);
 }
 
@@ -1110,19 +1033,6 @@ pscav_code(struct code*code)
     lispobj func;
     nwords = HeaderValue(code->header) + fixnum_value(code->code_size);
 
-    /* pw--The trace_table_offset slot can contain a list pointer. This
-     * occurs when the code object is a top level form that initializes
-     * a byte-compiled function. The fact that PURIFY was ignoring this
-     * slot may be a bug unrelated to the x86 port, except that TLF's
-     * normally become unreachable after the loader calls them and
-     * won't be seen by PURIFY at all!! */
-    if(code->trace_table_offset & 0x3)
-#if 0
-      pscav(&code->trace_table_offset, 1, 0);
-#else
-      code->trace_table_offset = NIL; /* limit lifetime */
-#endif
-
     /* Arrange to scavenge the debug info later. */
     pscav_later(&code->debug_info, 1);
 
@@ -1133,27 +1043,30 @@ pscav_code(struct code*code)
     pscav(&code->entry_points, 1, 1);
     for (func = code->entry_points;
          func != NIL;
-         func = ((struct function *)PTR(func))->next) {
-        gc_assert(LowtagOf(func) == type_FunctionPointer);
+         func = ((struct simple_fun *)native_pointer(func))->next) {
+        gc_assert(lowtagof(func) == FUN_POINTER_LOWTAG);
         gc_assert(!dynamic_pointer_p(func));
 
 #ifdef __i386__
        /* Temporarly convert the self pointer to a real function
         * pointer. */
-       ((struct function *)PTR(func))->self -= RAW_ADDR_OFFSET;
+       ((struct simple_fun *)native_pointer(func))->self
+           -= FUN_RAW_ADDR_OFFSET;
 #endif
-        pscav(&((struct function *)PTR(func))->self, 2, 1);
+        pscav(&((struct simple_fun *)native_pointer(func))->self, 2, 1);
 #ifdef __i386__
-       ((struct function *)PTR(func))->self += RAW_ADDR_OFFSET;
+       ((struct simple_fun *)native_pointer(func))->self
+           += FUN_RAW_ADDR_OFFSET;
 #endif
-        pscav_later(&((struct function *)PTR(func))->name, 3);
+        pscav_later(&((struct simple_fun *)native_pointer(func))->name, 3);
     }
 
     return CEILING(nwords,2);
 }
 #endif
 
-static lispobj *pscav(lispobj *addr, int nwords, boolean constant)
+static lispobj *
+pscav(lispobj *addr, int nwords, boolean constant)
 {
     lispobj thing, *thingp, header;
     int count = 0; /* (0 = dummy init value to stop GCC warning) */
@@ -1161,31 +1074,31 @@ static lispobj *pscav(lispobj *addr, int nwords, boolean constant)
 
     while (nwords > 0) {
         thing = *addr;
-        if (Pointerp(thing)) {
+        if (is_lisp_pointer(thing)) {
             /* It's a pointer. Is it something we might have to move? */
             if (dynamic_pointer_p(thing)) {
                 /* Maybe. Have we already moved it? */
-               thingp = (lispobj *)PTR(thing);
+               thingp = (lispobj *)native_pointer(thing);
                 header = *thingp;
-                if (Pointerp(header) && forwarding_pointer_p(header))
+                if (is_lisp_pointer(header) && forwarding_pointer_p(header))
                     /* Yep, so just copy the forwarding pointer. */
                     thing = header;
                 else {
                     /* Nope, copy the object. */
-                    switch (LowtagOf(thing)) {
-                      case type_FunctionPointer:
+                    switch (lowtagof(thing)) {
+                      case FUN_POINTER_LOWTAG:
                         thing = ptrans_func(thing, header);
                         break;
 
-                      case type_ListPointer:
+                      case LIST_POINTER_LOWTAG:
                         thing = ptrans_list(thing, constant);
                         break;
 
-                      case type_InstancePointer:
+                      case INSTANCE_POINTER_LOWTAG:
                         thing = ptrans_instance(thing, header, constant);
                         break;
 
-                      case type_OtherPointer:
+                      case OTHER_POINTER_LOWTAG:
                         thing = ptrans_otherptr(thing, header, constant);
                         break;
 
@@ -1215,7 +1128,7 @@ static lispobj *pscav(lispobj *addr, int nwords, boolean constant)
 
               case type_SimpleVector:
                 if (HeaderValue(thing) == subtype_VectorValidHashing)
-                    *addr = (subtype_VectorMustRehash<<type_Bits) |
+                    *addr = (subtype_VectorMustRehash<<N_TYPE_BITS) |
                         type_SimpleVector;
                 count = 1;
                 break;
@@ -1319,8 +1232,8 @@ static lispobj *pscav(lispobj *addr, int nwords, boolean constant)
 #endif
                 break;
 
-              case type_FunctionHeader:
-              case type_ClosureFunctionHeader:
+              case type_SimpleFunHeader:
+              case type_ClosureFunHeader:
               case type_ReturnPcHeader:
                 /* We should never hit any of these, 'cause they occur
                  * buried in the middle of code objects. */
@@ -1330,15 +1243,13 @@ static lispobj *pscav(lispobj *addr, int nwords, boolean constant)
 #ifdef __i386__
              case type_ClosureHeader:
              case type_FuncallableInstanceHeader:
-             case type_ByteCodeFunction:
-             case type_ByteCodeClosure:
                /* The function self pointer needs special care on the
                 * x86 because it is the real entry point. */
                {
-                 lispobj fun = ((struct closure *)addr)->function
-                   - RAW_ADDR_OFFSET;
+                 lispobj fun = ((struct closure *)addr)->fun
+                   - FUN_RAW_ADDR_OFFSET;
                  pscav(&fun, 1, constant);
-                 ((struct closure *)addr)->function = fun + RAW_ADDR_OFFSET;
+                 ((struct closure *)addr)->fun = fun + FUN_RAW_ADDR_OFFSET;
                }
                count = 2;
                break;
@@ -1374,7 +1285,8 @@ static lispobj *pscav(lispobj *addr, int nwords, boolean constant)
     return addr;
 }
 
-int purify(lispobj static_roots, lispobj read_only_roots)
+int
+purify(lispobj static_roots, lispobj read_only_roots)
 {
     lispobj *clean;
     int count, i;
@@ -1394,7 +1306,7 @@ int purify(lispobj static_roots, lispobj read_only_roots)
         return 0;
     }
 
-#if defined(ibmrt) || defined(__i386__)
+#if defined(__i386__)
     dynamic_space_free_pointer =
       (lispobj*)SymbolValue(ALLOCATION_POINTER);
 #endif
@@ -1430,25 +1342,20 @@ int purify(lispobj static_roots, lispobj read_only_roots)
     fflush(stdout);
 #endif
 #ifndef __i386__
-    pscav((lispobj *)control_stack,
+    pscav((lispobj *)CONTROL_STACK_START,
          current_control_stack_pointer - (lispobj *)CONTROL_STACK_START,
          0);
 #else
 #ifdef GENCGC
     pscav_i386_stack();
 #endif
-#ifdef WANT_CGC
-    gc_assert((lispobj *)control_stack_end > ((&read_only_roots)+1));
-    carefully_pscav_stack(((&read_only_roots)+1),
-                         (lispobj *)CONTROL_STACK_END);
-#endif
 #endif
 
 #ifdef PRINTNOISE
     printf(" bindings");
     fflush(stdout);
 #endif
-#if !defined(ibmrt) && !defined(__i386__)
+#if !defined(__i386__)
     pscav( (lispobj *)BINDING_STACK_START,
          (lispobj *)current_binding_stack_pointer - (lispobj *)BINDING_STACK_START,
          0);
@@ -1459,7 +1366,14 @@ int purify(lispobj static_roots, lispobj read_only_roots)
          0);
 #endif
 
-#ifdef SCAVENGE_READ_ONLY_SPACE
+    /* The original CMU CL code had scavenge-read-only-space code
+     * controlled by the Lisp-level variable
+     * *SCAVENGE-READ-ONLY-SPACE*. It was disabled by default, and it
+     * wasn't documented under what circumstances it was useful or
+     * safe to turn it on, so it's been turned off in SBCL. If you
+     * want/need this functionality, and can test and document it,
+     * please submit a patch. */
+#if 0
     if (SymbolValue(SCAVENGE_READ_ONLY_SPACE) != type_UnboundMarker
        && SymbolValue(SCAVENGE_READ_ONLY_SPACE) != NIL) {
       unsigned  read_only_space_size =
@@ -1507,15 +1421,8 @@ int purify(lispobj static_roots, lispobj read_only_roots)
     fflush(stdout);
 #endif
 
-#if defined(WANT_CGC) && defined(X86_CGC_ACTIVE_P)
-    if(SymbolValue(X86_CGC_ACTIVE_P) != T) {
-       os_zero((os_vm_address_t) DYNAMIC_SPACE_START,
-               (os_vm_size_t) DYNAMIC_SPACE_SIZE);
-    }
-#else
-    os_zero((os_vm_address_t) DYNAMIC_SPACE_START,
+    os_zero((os_vm_address_t) current_dynamic_space,
             (os_vm_size_t) DYNAMIC_SPACE_SIZE);
-#endif
 
     /* Zero the stack. Note that the stack is also zeroed by SUB-GC
      * calling SCRUB-CONTROL-STACK - this zeros the stack on the x86. */
@@ -1527,44 +1434,18 @@ int purify(lispobj static_roots, lispobj read_only_roots)
                              sizeof(lispobj))));
 #endif
 
-#if defined(WANT_CGC) && defined(STATIC_BLUE_BAG)
-    {
-      lispobj bag = SymbolValue(STATIC_BLUE_BAG);
-      struct cons*cons = (struct cons*)static_free;
-      struct cons*pair = cons + 1;
-      static_free += 2*WORDS_PER_CONS;
-      if(bag == type_UnboundMarker)
-       bag = NIL;
-      cons->cdr = bag;
-      cons->car = (lispobj)pair | type_ListPointer;
-      pair->car = (lispobj)static_end;
-      pair->cdr = (lispobj)static_free;
-      bag = (lispobj)cons | type_ListPointer;
-      SetSymbolValue(STATIC_BLUE_BAG, bag);
-    }
-#endif
-
     /* It helps to update the heap free pointers so that free_heap can
      * verify after it's done. */
     SetSymbolValue(READ_ONLY_SPACE_FREE_POINTER, (lispobj)read_only_free);
     SetSymbolValue(STATIC_SPACE_FREE_POINTER, (lispobj)static_free);
 
-#if !defined(ibmrt) && !defined(__i386__)
-    dynamic_space_free_pointer = DYNAMIC_SPACE_START;
-#else
-#if defined(WANT_CGC) && defined(X86_CGC_ACTIVE_P)
-    /* X86 using CGC */
-    if(SymbolValue(X86_CGC_ACTIVE_P) != T)
-       SetSymbolValue(ALLOCATION_POINTER, (lispobj)DYNAMIC_SPACE_START);
-    else
-       cgc_free_heap();
+#if !defined(__i386__)
+    dynamic_space_free_pointer = current_dynamic_space;
 #else
 #if defined GENCGC
     gc_free_heap();
 #else
-    /* ibmrt using GC */
-    SetSymbolValue(ALLOCATION_POINTER, (lispobj)DYNAMIC_SPACE_START);
-#endif
+#error unsupported case /* in CMU CL, was "ibmrt using GC" */
 #endif
 #endif