]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ppc/model_dep.c
xnu-792.2.4.tar.gz
[apple/xnu.git] / osfmk / ppc / model_dep.c
index 90d8a05d914b91f00a4f92a25a882fecf97959fe..db35a19ae30a826172398521e84f46d2c4c22cf0 100644 (file)
@@ -1,24 +1,21 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License").  You may not use this file except in compliance with the
+ * License.  Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
  * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
 #include <mach_kdb.h>
 #include <mach_kdp.h>
 #include <db_machine_commands.h>
-#include <cpus.h>
 
 #include <kern/thread.h>
 #include <machine/pmap.h>
-#include <machine/mach_param.h>
 #include <device/device_types.h>
 
 #include <mach/vm_param.h>
 #include <ppc/low_trace.h>
 #include <ppc/mappings.h>
 #include <ppc/FirmwareCalls.h>
-#include <ppc/setjmp.h>
+#include <ppc/cpu_internal.h>
 #include <ppc/exception.h>
+#include <ppc/hw_perfmon.h>
+#include <ppc/lowglobals.h>
 
 #include <kern/clock.h>
 #include <kern/debug.h>
 #include <machine/trap.h>
 #include <kern/spl.h>
 #include <pexpert/pexpert.h>
-#include <ppc/mp.h>
 
 #include <IOKit/IOPlatformExpert.h>
 
@@ -133,10 +129,6 @@ hw_lock_data_t pbtlock;            /* backtrace print lock */
 
 int                    debugger_cpu = -1;                      /* current cpu running debugger */
 int                    debugger_debug = 0;                     /* Debug debugger */
-int                    debugger_is_slave[NCPUS];       /* Show that we were entered via sigp */
-int                    debugger_active[NCPUS];         /* Debugger active on CPU */
-int                    debugger_pending[NCPUS];        /* Debugger entry pending on CPU (this is a HACK) */
-int                    debugger_holdoff[NCPUS];        /* Holdoff debugger entry on this CPU (this is a HACK) */
 int            db_run_mode;                            /* Debugger run mode */
 unsigned int debugger_sync = 0;                        /* Cross processor debugger entry sync */
 extern                 unsigned int NMIss;                     /* NMI debounce switch */
@@ -147,14 +139,17 @@ volatile unsigned int pbtcpu = -1;
 
 unsigned int lastTrace;                                        /* Value of low-level exception trace controls */
 
+
 volatile unsigned int  cpus_holding_bkpts;     /* counter for number of cpus holding
                                                                                           breakpoints (ie: cpus that did not
                                                                                           insert back breakpoints) */
 void unlock_debugger(void);
 void lock_debugger(void);
-void dump_backtrace(unsigned int stackptr, unsigned int fence);
+void dump_backtrace(savearea *sv, unsigned int stackptr, unsigned int fence);
 void dump_savearea(savearea *sv, unsigned int fence);
 
+int packAsc (unsigned char *inbuf, unsigned int length);
+
 #if !MACH_KDB
 boolean_t      db_breakpoints_inserted = TRUE;
 jmp_buf_t *db_recover = 0;
@@ -185,6 +180,10 @@ char *failNames[] = {
        "No saveareas",                         /* failNoSavearea */
        "Savearea corruption",          /* failSaveareaCorr */
        "Invalid live context",         /* failBadLiveContext */
+       "Corrupt skip lists",           /* failSkipLists */
+       "Unaligned stack",                      /* failUnalignedStk */
+       "Invalid pmap",                         /* failPmap */
+       "Lock timeout",                         /* failTimeout */
        "Unknown failure code"          /* Unknown failure code - must always be last */
 };
 
@@ -192,7 +191,6 @@ char *invxcption = "Unknown code";
 
 extern const char version[];
 extern char *trap_type[];
-extern vm_offset_t mem_actual;
 
 #if !MACH_KDB
 void kdb_trap(int type, struct savearea *regs);
@@ -212,12 +210,13 @@ void
 machine_startup(boot_args *args)
 {
        int     boot_arg;
+       unsigned int wncpu;
+       unsigned int vmm_arg;
 
        if (PE_parse_boot_arg("cpus", &wncpu)) {
-               if (!((wncpu > 0) && (wncpu < NCPUS)))
-                        wncpu = NCPUS;
-       } else 
-               wncpu = NCPUS;
+               if ((wncpu > 0) && (wncpu < MAX_CPUS))
+                        max_ncpus = wncpu;
+       }
 
        if( PE_get_hotkey( kPEControlKey ))
             halt_in_debugger = halt_in_debugger ? 0 : 1;
@@ -229,6 +228,8 @@ machine_startup(boot_args *args)
                if (boot_arg & DB_NMI) panicDebugging=TRUE; 
                if (boot_arg & DB_LOG_PI_SCRN) logPanicDataToScreen=TRUE; 
        }
+       
+       PE_parse_boot_arg("vmmforce", &lowGlo.lgVMMforcedFeats);
 
        hw_lock_init(&debugger_lock);                           /* initialize debugger lock */
        hw_lock_init(&pbtlock);                                         /* initialize print backtrace lock */
@@ -279,14 +280,11 @@ machine_startup(boot_args *args)
 
        machine_conf();
 
-       ml_thrm_init();                                                 /* Start thermal monitoring on this processor */
-
        /*
-        * Start the system.
+        * Kick off the kernel bootstrap.
         */
-       setup_main();
-
-       /* Should never return */
+       kernel_bootstrap();
+       /*NOTREACHED*/
 }
 
 char *
@@ -300,22 +298,20 @@ machine_boot_info(
 void
 machine_conf(void)
 {
-       machine_info.max_cpus = NCPUS;
-       machine_info.avail_cpus = 1;
-       machine_info.memory_size = mem_size;
+       machine_info.memory_size = mem_size;    /* Note that this will be 2 GB for >= 2 GB machines */
 }
 
 void
 machine_init(void)
 {
        clock_config();
+       perfmon_init();
 }
 
 void slave_machine_init(void)
 {
-       (void) ml_set_interrupts_enabled(FALSE);        /* Make sure we are disabled */
-       clock_init();                           /* Init the clock */
        cpu_machine_init();                     /* Initialize the processor */
+       clock_init();                           /* Init the clock */
 }                               
 
 void
@@ -360,9 +356,9 @@ print_backtrace(struct savearea *ssp)
        int i, frames_cnt, skip_top_frames, frames_max;
        unsigned int store[8];                  /* Buffer for real storage reads */
        vm_offset_t backtrace_entries[32];
-       thread_act_t *act;
        savearea *sv, *svssp;
        int cpu;
+       savearea *psv;
 
 /*
  *     We need this lock to make sure we don't hang up when we double panic on an MP.
@@ -370,22 +366,22 @@ print_backtrace(struct savearea *ssp)
 
        cpu  = cpu_number();                                    /* Just who are we anyways? */
        if(pbtcpu != cpu) {                                             /* Allow recursion */
-               hw_atomic_add(&pbtcnt, 1);                      /* Remember we are trying */
+               hw_atomic_add((uint32_t *)&pbtcnt, 1); /* Remember we are trying */
                while(!hw_lock_try(&pbtlock));          /* Spin here until we can get in. If we never do, well, we're crashing anyhow... */     
                pbtcpu = cpu;                                           /* Mark it as us */     
        }       
 
        svssp = (savearea *)ssp;                                /* Make this easier */
        sv = 0;
-       if(current_thread()) sv = (savearea *)current_act()->mact.pcb;  /* Find most current savearea if system has started */
+       if(current_thread()) sv = (savearea *)current_thread()->machine.pcb;    /* Find most current savearea if system has started */
 
        fence = 0xFFFFFFFF;                                             /* Show we go all the way */
-       if(sv) fence = sv->save_r1;                             /* Stop at previous exception point */
+       if(sv) fence = (unsigned int)sv->save_r1;       /* Stop at previous exception point */
        
        if(!svssp) {                                                    /* Should we start from stack? */
                kdb_printf("Latest stack backtrace for cpu %d:\n", cpu_number());
                __asm__ volatile("mr %0,r1" : "=r" (stackptr)); /* Get current stack */
-               dump_backtrace(stackptr, fence);        /* Dump the backtrace */
+               dump_backtrace((savearea *)0,stackptr, fence);  /* Dump the backtrace */
                if(!sv) {                                                       /* Leave if no saveareas */
                        kdb_printf("\nKernel version:\n%s\n",version);  /* Print kernel version */
                        hw_lock_unlock(&pbtlock);               /* Allow another back trace to happen */
@@ -395,8 +391,9 @@ print_backtrace(struct savearea *ssp)
        else {                                                                  /* Were we passed an exception? */
                fence = 0xFFFFFFFF;                                     /* Show we go all the way */
                if(svssp->save_hdr.save_prev) {
-                       if((svssp->save_hdr.save_prev <= VM_MAX_KERNEL_ADDRESS) && ((unsigned int)LRA(PPC_SID_KERNEL, (void *)svssp->save_hdr.save_prev))) {    /* Valid address? */    
-                               fence = svssp->save_hdr.save_prev->save_r1;     /* Stop at previous exception point */
+                       if((svssp->save_hdr.save_prev <= vm_last_addr) && ((unsigned int)pmap_find_phys(kernel_pmap, (addr64_t)svssp->save_hdr.save_prev))) {   /* Valid address? */    
+                               psv = (savearea *)((unsigned int)svssp->save_hdr.save_prev);    /* Get the 64-bit back chain converted to a regualr pointer */
+                               fence = (unsigned int)psv->save_r1;     /* Stop at previous exception point */
                        }
                }
        
@@ -414,7 +411,8 @@ print_backtrace(struct savearea *ssp)
        kdb_printf("Proceeding back via exception chain:\n");
 
        while(sv) {                                                             /* Do them all... */
-               if(!((sv <= VM_MAX_KERNEL_ADDRESS) && (unsigned int)LRA(PPC_SID_KERNEL, (void *)sv))) { /* Valid address? */    
+               if(!(((addr64_t)((uintptr_t)sv) <= vm_last_addr) && 
+                       (unsigned int)pmap_find_phys(kernel_pmap, (addr64_t)((uintptr_t)sv)))) {        /* Valid address? */    
                        kdb_printf("   Exception state (sv=0x%08X) Not mapped or invalid. stopping...\n", sv);
                        break;
                }
@@ -426,21 +424,22 @@ print_backtrace(struct savearea *ssp)
                else {
                        fence = 0xFFFFFFFF;                             /* Show we go all the way */
                        if(sv->save_hdr.save_prev) {
-                               if((sv->save_hdr.save_prev <= VM_MAX_KERNEL_ADDRESS) && ((unsigned int)LRA(PPC_SID_KERNEL, (void *)sv->save_hdr.save_prev))) {  /* Valid address? */    
-                                       fence = sv->save_hdr.save_prev->save_r1;        /* Stop at previous exception point */
+                               if((sv->save_hdr.save_prev <= vm_last_addr) && ((unsigned int)pmap_find_phys(kernel_pmap, (addr64_t)sv->save_hdr.save_prev))) { /* Valid address? */    
+                                       psv = (savearea *)((unsigned int)sv->save_hdr.save_prev);       /* Get the 64-bit back chain converted to a regualr pointer */
+                                       fence = (unsigned int)psv->save_r1;     /* Stop at previous exception point */
                                }
                        }
                        dump_savearea(sv, fence);               /* Dump this savearea */        
                }       
                
-               sv = sv->save_hdr.save_prev;            /* Back chain */
+               sv = CAST_DOWN(savearea *, sv->save_hdr.save_prev);     /* Back chain */ 
        }
        
        kdb_printf("\nKernel version:\n%s\n",version);  /* Print kernel version */
 
        pbtcpu = -1;                                                    /* Mark as unowned */
        hw_lock_unlock(&pbtlock);                               /* Allow another back trace to happen */
-       hw_atomic_sub(&pbtcnt, 1);                              /* Show we are done */
+       hw_atomic_sub((uint32_t *) &pbtcnt, 1);  /* Show we are done */
 
        while(pbtcnt);                                                  /* Wait for completion */
 
@@ -455,11 +454,11 @@ void dump_savearea(savearea *sv, unsigned int fence) {
        else xcode = trap_type[sv->save_exception / 4];         /* Point to the type */
        
        kdb_printf("      PC=0x%08X; MSR=0x%08X; DAR=0x%08X; DSISR=0x%08X; LR=0x%08X; R1=0x%08X; XCP=0x%08X (%s)\n",
-               sv->save_srr0, sv->save_srr1, sv->save_dar, sv->save_dsisr,
-               sv->save_lr, sv->save_r1, sv->save_exception, xcode);
+               (unsigned int)sv->save_srr0, (unsigned int)sv->save_srr1, (unsigned int)sv->save_dar, sv->save_dsisr,
+               (unsigned int)sv->save_lr, (unsigned int)sv->save_r1, sv->save_exception, xcode);
        
        if(!(sv->save_srr1 & MASK(MSR_PR))) {           /* Are we in the kernel? */
-               dump_backtrace(sv->save_r1, fence);             /* Dump the stack back trace from  here if not user state */
+               dump_backtrace(sv, (unsigned int)sv->save_r1, fence);   /* Dump the stack back trace from  here if not user state */
        }
        
        return;
@@ -467,37 +466,42 @@ void dump_savearea(savearea *sv, unsigned int fence) {
 
 
 
-#define DUMPFRAMES 32
+#define DUMPFRAMES 34
 #define LRindex 2
 
-void dump_backtrace(unsigned int stackptr, unsigned int fence) {
+void dump_backtrace(savearea *sv, unsigned int stackptr, unsigned int fence) {
 
        unsigned int bframes[DUMPFRAMES];
        unsigned int  sframe[8], raddr, dumbo;
-       int i;
+       int i, index=0;
        
        kdb_printf("      Backtrace:\n");
-       for(i = 0; i < DUMPFRAMES; i++) {                       /* Dump up to max frames */
+       if (sv != (savearea *)0) {
+               bframes[0] = (unsigned int)sv->save_srr0;
+               bframes[1] = (unsigned int)sv->save_lr;
+               index = 2;
+       }
+       for(i = index; i < DUMPFRAMES; i++) {                   /* Dump up to max frames */
        
                if(!stackptr || (stackptr == fence)) break;             /* Hit stop point or end... */
                
-               if(stackptr & 0x0000000f) {                             /* Is stack pointer valid? */
+               if(stackptr & 0x0000000F) {                             /* Is stack pointer valid? */
                        kdb_printf("\n         backtrace terminated - unaligned frame address: 0x%08X\n", stackptr);    /* No, tell 'em */
                        break;
                }
 
-               raddr = (unsigned int)LRA(PPC_SID_KERNEL, (void *)stackptr);    /* Get physical frame address */
-               if(!raddr || (stackptr > VM_MAX_KERNEL_ADDRESS)) {              /* Is it mapped? */
+               raddr = (unsigned int)pmap_find_phys(kernel_pmap, (addr64_t)stackptr);  /* Get physical frame address */
+               if(!raddr || (stackptr > vm_last_addr)) {               /* Is it mapped? */
                        kdb_printf("\n         backtrace terminated - frame not mapped or invalid: 0x%08X\n", stackptr);        /* No, tell 'em */
                        break;
                }
        
-               if(raddr >= mem_actual) {                                       /* Is it within physical RAM? */
+               if(!mapping_phys_lookup(raddr, &dumbo)) {       /* Is it within physical RAM? */
                        kdb_printf("\n         backtrace terminated - frame outside of RAM: v=0x%08X, p=%08X\n", stackptr, raddr);      /* No, tell 'em */
                        break;
                }
        
-               ReadReal(raddr, &sframe[0]);                            /* Fetch the stack frame */
+               ReadReal((addr64_t)((raddr << 12) | (stackptr & 4095)), &sframe[0]);    /* Fetch the stack frame */
 
                bframes[i] = sframe[LRindex];                           /* Save the link register */
                
@@ -538,7 +542,7 @@ Debugger(const char *message) {
                }
        }
        
-       if (debug_mode && debugger_active[cpu_number()]) {      /* Are we already on debugger on this processor? */
+       if (debug_mode && getPerProc()->debugger_active) {      /* Are we already on debugger on this processor? */
                splx(spl);
                return;                                                                         /* Yeah, don't do it again... */
        }
@@ -555,20 +559,46 @@ Debugger(const char       *message) {
                /* everything should be printed now so copy to NVRAM
                */
                if( debug_buf_size > 0)
-                       pi_size = PESavePanicInfo( debug_buf, debug_buf_ptr - debug_buf);
+
+                 {
+                   /* Do not compress the panic log unless kernel debugging 
+                    * is disabled - the panic log isn't synced to NVRAM if 
+                    * debugging is enabled, and the panic log is valuable 
+                    * whilst debugging
+                    */
+                   if (!panicDebugging)
+                     {
+                       unsigned int bufpos;
+                       
+                       /* Now call the compressor */
+                       bufpos = packAsc (debug_buf, (unsigned int) (debug_buf_ptr - debug_buf) );
+                       /* If compression was successful, use the compressed length                */
+                       if (bufpos)
+                         {
+                           debug_buf_ptr = debug_buf + bufpos;
+                         }
+                     }
+                   /* Truncate if the buffer is larger than a certain magic 
+                    * size - this really ought to be some appropriate fraction
+                    * of the NVRAM image buffer, and is best done in the 
+                    * savePanicInfo() or PESavePanicInfo() calls 
+                    */
+                   pi_size = debug_buf_ptr - debug_buf;
+                   pi_size = PESavePanicInfo( debug_buf, ((pi_size > 2040) ? 2040 : pi_size));
+                 }
                        
                if( !panicDebugging && (pi_size != 0) ) {
-                       int     my_cpu, debugger_cpu;
+                       int     my_cpu;
                        int     tcpu;
 
                        my_cpu = cpu_number();
                        debugger_cpu = my_cpu;
 
                        hw_atomic_add(&debug_mode, 1);
-                       debugger_active[my_cpu]++;
+                       PerProcTable[my_cpu].ppe_vaddr->debugger_active++;
                        lock_debugger();
 
-                       for(tcpu = 0; tcpu < NCPUS; tcpu++) {
+                       for(tcpu = 0; tcpu < real_ncpus; tcpu++) {
                                if(tcpu == my_cpu) continue;
                                hw_atomic_add(&debugger_sync, 1);
                                (void)cpu_signal(tcpu, SIGPdebug, 0 ,0);
@@ -619,11 +649,11 @@ void SysChoked(int type, savearea *sv) {                  /* The system is bad dead */
        disableDebugOuput = FALSE;
        debug_mode = TRUE;
 
-       failcode = sv->save_r3;                                                 /* Get the failure code */
+       failcode = (unsigned int)sv->save_r3;                   /* Get the failure code */
        if(failcode > failUnknown) failcode = failUnknown;      /* Set unknown code code */
        
-       kprintf("System Failure: cpu=%d; code=%08X (%s)\n", cpu_number(), sv->save_r3, failNames[failcode]);
-       kdb_printf("System Failure: cpu=%d; code=%08X (%s)\n", cpu_number(), sv->save_r3, failNames[failcode]);
+       kprintf("System Failure: cpu=%d; code=%08X (%s)\n", cpu_number(), (unsigned int)sv->save_r3, failNames[failcode]);
+       kdb_printf("System Failure: cpu=%d; code=%08X (%s)\n", cpu_number(), (unsigned int)sv->save_r3, failNames[failcode]);
 
        print_backtrace(sv);                                                    /* Attempt to print backtrace */
        Call_DebuggerC(type, sv);                                               /* Attempt to get into debugger */
@@ -644,15 +674,18 @@ int Call_DebuggerC(
         struct savearea *saved_state)
 {
        int                             directcall, wait;
-       vm_offset_t             instr_ptr;
+       addr64_t                instr_ptr;
+       ppnum_t                 instr_pp;
        unsigned int    instr;
-       int                     my_cpu, tcpu;
+       int                     my_cpu, tcpu, wasdebugger;
+       struct per_proc_info *pp;
+       uint64_t nowtime, poptime;
 
        my_cpu = cpu_number();                                                          /* Get our CPU */
 
 #if    MACH_KDB
        if((debugger_cpu == my_cpu) &&                                          /* Do we already own debugger? */
-         debugger_active[my_cpu] &&                                            /* and are we really active? */
+         PerProcTable[my_cpu].ppe_vaddr->debugger_active &&                                            /* and are we really active? */
          db_recover &&                                                                         /* and have we set up recovery? */
          (current_debugger == KDB_CUR_DB)) {                           /* and are we in KDB (only it handles recovery) */
                kdb_trap(type, saved_state);                                    /* Then reenter it... */
@@ -660,7 +693,8 @@ int Call_DebuggerC(
 #endif
        
        hw_atomic_add(&debug_mode, 1);                                          /* Indicate we are in debugger */
-       debugger_active[my_cpu]++;                                                      /* Show active on our CPU */
+       PerProcTable[my_cpu].ppe_vaddr->debugger_active++;      /* Show active on our CPU */
+       
        lock_debugger();                                                                        /* Insure that only one CPU is in debugger */
 
        if(db_im_stepping == my_cpu) {                                          /* Are we just back from a step? */
@@ -673,27 +707,32 @@ int Call_DebuggerC(
                kprintf("Call_DebuggerC(%d): %08X %08X, debact = %d\n", my_cpu, type, saved_state, debug_mode); /* (TEST/DEBUG) */
 #endif
                printf("Call_Debugger: enter - cpu %d, is_slave %d, debugger_cpu %d, pc %08X\n",
-                  my_cpu, debugger_is_slave[my_cpu], debugger_cpu, saved_state->save_srr0);
+                  my_cpu, PerProcTable[my_cpu].ppe_vaddr->debugger_is_slave, debugger_cpu, saved_state->save_srr0);
        }
        
-       if (instr_ptr = (vm_offset_t)LRA(PPC_SID_KERNEL, (void *)(saved_state->save_srr0))) {
-               instr = ml_phys_read(instr_ptr);                                /* Get the trap that caused entry */
+       instr_pp = (vm_offset_t)pmap_find_phys(kernel_pmap, (addr64_t)(saved_state->save_srr0));
+
+       if (instr_pp) {
+               instr_ptr = (addr64_t)(((addr64_t)instr_pp << 12) | (saved_state->save_srr0 & 0xFFF));  /* Make physical address */
+               instr = ml_phys_read_64(instr_ptr);                             /* Get the trap that caused entry */
        } 
        else instr = 0;
 
 #if 0
-       if (debugger_debug) kprintf("Call_DebuggerC(%d): instr_ptr = %08X, instr = %08X\n", my_cpu, instr_ptr, instr);  /* (TEST/DEBUG) */
+       if (debugger_debug) kprintf("Call_DebuggerC(%d): instr_pp = %08X, instr_ptr = %016llX, instr = %08X\n", my_cpu, instr_pp, instr_ptr, instr);    /* (TEST/DEBUG) */
 #endif
 
        if (db_breakpoints_inserted) cpus_holding_bkpts++;      /* Bump up the holding count */
-       if (debugger_cpu == -1 && !debugger_is_slave[my_cpu]) {
+       if (debugger_cpu == -1 && !PerProcTable[my_cpu].ppe_vaddr->debugger_is_slave) {
 #if 0
                if (debugger_debug) kprintf("Call_DebuggerC(%d): lasttrace = %08X\n", my_cpu, lastTrace);       /* (TEST/DEBUG) */
 #endif
                debugger_cpu = my_cpu;                                                  /* Show that we are debugger */
+
+
                lastTrace = LLTraceSet(0);                                              /* Disable low-level tracing */
 
-               for(tcpu = 0; tcpu < NCPUS; tcpu++) {                   /* Stop all the other guys */
+               for(tcpu = 0; tcpu < real_ncpus; tcpu++) {              /* Stop all the other guys */
                        if(tcpu == my_cpu) continue;                            /* Don't diddle ourselves */
                        hw_atomic_add(&debugger_sync, 1);                       /* Count signal sent */
                        (void)cpu_signal(tcpu, SIGPdebug, 0 ,0);        /* Tell 'em to enter debugger */
@@ -796,14 +835,18 @@ debugger_exit:
        if ((instr == TRAP_DEBUGGER_INST) ||                            /* Did we trap to enter debugger? */
                (instr == TRAP_DIRECT_INST)) saved_state->save_srr0 += TRAP_INST_SIZE;  /* Yes, point past trap */
 
-       if(debugger_cpu == my_cpu) LLTraceSet(lastTrace);       /* Enable tracing on the way out if we are debugger */
+       wasdebugger = 0;                                                                        /* Assume not debugger */
+       if(debugger_cpu == my_cpu) {                                            /* Are the debugger processor? */
+               wasdebugger = 1;                                                                /* Remember that we were the debugger */
+               LLTraceSet(lastTrace);                                                  /* Enable tracing on the way out if we are debugger */
+       }
 
        wait = FALSE;                                                                           /* Assume we are not going to wait */
        if (db_run_mode == STEP_CONTINUE) {                                     /* Are we going to run? */
                wait = TRUE;                                                                    /* Yeah, remember to wait for breakpoints to clear */
                debugger_cpu = -1;                                                              /* Release other processor's debuggers */
-               debugger_pending[0] = 0;                                                /* Release request (this is a HACK) */
-               debugger_pending[1] = 0;                                                /* Release request (this is a HACK) */
+               for(tcpu = 0; tcpu < real_ncpus; tcpu++)
+                       PerProcTable[tcpu].ppe_vaddr->debugger_pending = 0;     /* Release request (this is a HACK) */
                NMIss = 0;                                                                              /* Let NMI bounce */
        }
        
@@ -813,17 +856,18 @@ debugger_exit:
        }
 
        if (db_breakpoints_inserted) cpus_holding_bkpts--;      /* If any breakpoints, back off count */
-       if (debugger_is_slave[my_cpu]) debugger_is_slave[my_cpu]--;     /* If we were a slove, uncount us */
+       if (PerProcTable[my_cpu].ppe_vaddr->debugger_is_slave) PerProcTable[my_cpu].ppe_vaddr->debugger_is_slave--;     /* If we were a slove, uncount us */
        if (debugger_debug)
                printf("Call_Debugger: exit - cpu %d, debugger_cpu %d, run_mode %d holds %d\n",
                          my_cpu, debugger_cpu, db_run_mode,
                          cpus_holding_bkpts);
 
        unlock_debugger();                                                                      /* Release the lock */
-       debugger_active[my_cpu]--;                                                      /* Say we aren't active anymore */
+       PerProcTable[my_cpu].ppe_vaddr->debugger_active--;      /* Say we aren't active anymore */
 
        if (wait) while(cpus_holding_bkpts);                            /* Wait for breakpoints to clear */
 
+
        hw_atomic_sub(&debug_mode, 1);                                          /* Set out of debug now */
 
        return(1);                                                                                      /* Exit debugger normally */
@@ -857,4 +901,38 @@ void unlock_debugger(void) {
 
 }
 
+struct pasc {
+  unsigned a: 7;
+  unsigned b: 7;
+  unsigned c: 7;
+  unsigned d: 7;
+  unsigned e: 7;
+  unsigned f: 7;
+  unsigned g: 7;
+  unsigned h: 7;
+}  __attribute__((packed));
+
+typedef struct pasc pasc_t;
 
+int packAsc (unsigned char *inbuf, unsigned int length)
+{
+  unsigned int i, j = 0;
+  pasc_t pack;
+
+  for (i = 0; i < length; i+=8)
+    {
+      pack.a = inbuf[i];
+      pack.b = inbuf[i+1];
+      pack.c = inbuf[i+2];
+      pack.d = inbuf[i+3];
+      pack.e = inbuf[i+4];
+      pack.f = inbuf[i+5];
+      pack.g = inbuf[i+6];
+      pack.h = inbuf[i+7];
+      bcopy ((char *) &pack, inbuf + j, 7);
+      j += 7;
+    }
+  if (0 != (i - length))
+    inbuf[j - (i - length)] &= 0xFF << (8-(i - length));
+  return j-(((i-length) == 7) ? 6 : (i - length));
+}