X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/43866e378188c25dd1e2208016ab3cbeb086ae6c..55e303ae13a4cf49d70f2294092726f2fffb9ef2:/osfmk/ppc/model_dep.c?ds=sidebyside diff --git a/osfmk/ppc/model_dep.c b/osfmk/ppc/model_dep.c index 90d8a05d9..962058728 100644 --- a/osfmk/ppc/model_dep.c +++ b/osfmk/ppc/model_dep.c @@ -86,6 +86,7 @@ #include #include #include +#include #include #include @@ -155,6 +156,8 @@ void lock_debugger(void); void dump_backtrace(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 +188,7 @@ char *failNames[] = { "No saveareas", /* failNoSavearea */ "Savearea corruption", /* failSaveareaCorr */ "Invalid live context", /* failBadLiveContext */ + "Unaligned stack", /* failUnalignedStk */ "Unknown failure code" /* Unknown failure code - must always be last */ }; @@ -192,7 +196,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); @@ -276,6 +279,11 @@ machine_startup(boot_args *args) sched_poll_yield_shift = boot_arg; } + if (PE_parse_boot_arg("refunn", &boot_arg)) { + extern int refunnel_hint_enabled; + + refunnel_hint_enabled = boot_arg; + } machine_conf(); @@ -302,13 +310,14 @@ 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) @@ -363,6 +372,7 @@ print_backtrace(struct savearea *ssp) 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,7 +380,7 @@ 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 */ } @@ -380,7 +390,7 @@ print_backtrace(struct savearea *ssp) if(current_thread()) sv = (savearea *)current_act()->mact.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()); @@ -395,8 +405,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 +425,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 +438,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 +468,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((unsigned int)sv->save_r1, fence); /* Dump the stack back trace from here if not user state */ } return; @@ -481,23 +494,23 @@ void dump_backtrace(unsigned int stackptr, unsigned int fence) { 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 */ @@ -555,7 +568,33 @@ 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; @@ -619,11 +658,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,7 +683,8 @@ 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; @@ -676,13 +716,16 @@ int Call_DebuggerC( my_cpu, debugger_is_slave[my_cpu], 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 */ @@ -857,4 +900,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)); +}