18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
22 #include <linux/stddef.h>
24 #include <linux/ptrace.h>
28 #include <linux/module.h>
32 #include <linux/kexec.h>
40 #include <asm/pgtable.h>
41 #include <asm/uaccess.h>
43 #include <asm/machdep.h>
49 #ifdef CONFIG_PMAC_BACKLIGHT
54 #include <asm/processor.h>
56 #include <asm/kexec.h>
60 #include <asm/switch_to.h>
61 #include <asm/debug.h>
63 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
85 #ifdef CONFIG_PMAC_BACKLIGHT
86 static void pmac_backlight_unblank(
void)
100 static inline void pmac_backlight_unblank(
void) { }
104 static int die_owner = -1;
105 static unsigned int die_nest_count;
106 static int die_counter;
122 if (cpu == die_owner)
131 if (machine_is(powermac))
132 pmac_backlight_unblank();
182 panic(
"Fatal exception in interrupt");
184 panic(
"Fatal exception");
190 printk(
"Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
191 #ifdef CONFIG_PREEMPT
197 #ifdef CONFIG_DEBUG_PAGEALLOC
198 printk(
"DEBUG_PAGEALLOC ");
216 unsigned long flags = oops_begin(regs);
218 if (__die(str, regs, err))
220 oops_end(flags, regs, err);
226 memset(info, 0,
sizeof(*info));
229 info->si_addr = (
void __user *)regs->
nip;
235 const char fmt32[] =
KERN_INFO "%s[%d]: unhandled signal %d " \
236 "at %08lx nip %08lx lr %08lx code %x\n";
237 const char fmt64[] =
KERN_INFO "%s[%d]: unhandled signal %d " \
238 "at %016lx nip %016lx lr %016lx code %x\n";
241 die(
"Exception in kernel mode", regs, signr);
248 addr, regs->
nip, regs->
link, code);
255 memset(&info, 0,
sizeof(info));
258 info.si_addr = (
void __user *) addr;
263 void system_reset_exception(
struct pt_regs *regs)
266 if (
ppc_md.system_reset_exception) {
267 if (
ppc_md.system_reset_exception(regs))
275 panic(
"Unrecoverable System Reset");
291 static inline int check_io_access(
struct pt_regs *regs)
294 unsigned long msr = regs->
msr;
296 unsigned int *nip = (
unsigned int *)regs->
nip;
298 if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
308 if (*nip == 0x60000000)
310 else if (*nip == 0x4c00012c)
312 if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
317 rb = (*nip >> 11) & 0x1f;
319 (*nip & 0x100)?
"OUT to":
"IN from",
330 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
333 #define get_reason(regs) ((regs)->dsisr)
334 #ifndef CONFIG_FSL_BOOKE
335 #define get_mc_reason(regs) ((regs)->dsisr)
337 #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
339 #define REASON_FP ESR_FP
340 #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
341 #define REASON_PRIVILEGED ESR_PPR
342 #define REASON_TRAP ESR_PTR
345 #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
346 #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
351 #define get_reason(regs) ((regs)->msr)
352 #define get_mc_reason(regs) ((regs)->msr)
353 #define REASON_FP 0x100000
354 #define REASON_ILLEGAL 0x80000
355 #define REASON_PRIVILEGED 0x40000
356 #define REASON_TRAP 0x20000
358 #define single_stepping(regs) ((regs)->msr & MSR_SE)
359 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
362 #if defined(CONFIG_4xx)
367 if (reason & ESR_IMCP) {
369 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
372 printk(
" machine check in kernel mode.\n");
381 printk(
"Machine check in kernel mode.\n");
382 if (reason & ESR_IMCP){
383 printk(
"Instruction Synchronous Machine Check exception\n");
384 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
389 printk(
"Instruction Read PLB Error\n");
391 printk(
"Data Read PLB Error\n");
393 printk(
"Data Write PLB Error\n");
394 if (mcsr & MCSR_TLBP)
395 printk(
"TLB Parity Error\n");
396 if (mcsr & MCSR_ICP){
398 printk(
"I-Cache Parity Error\n");
400 if (mcsr & MCSR_DCSP)
401 printk(
"D-Cache Search Parity Error\n");
402 if (mcsr & MCSR_DCFP)
403 printk(
"D-Cache Flush Parity Error\n");
404 if (mcsr & MCSR_IMPE)
405 printk(
"Machine Check exception is imprecise\n");
408 mtspr(SPRN_MCSR, mcsr);
419 if (reason & ESR_IMCP) {
421 "Instruction Synchronous Machine Check exception\n");
422 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
425 mcsr =
mfspr(SPRN_MCSR);
432 if (mcsr & MCSR_TLBP)
434 if (mcsr & MCSR_ICP) {
438 if (mcsr & MCSR_DCSP)
440 if (mcsr & PPC47x_MCSR_GPR)
442 if (mcsr & PPC47x_MCSR_FPR)
444 if (mcsr & PPC47x_MCSR_IPR)
448 mtspr(SPRN_MCSR, mcsr);
452 #elif defined(CONFIG_E500)
455 unsigned long mcsr =
mfspr(SPRN_MCSR);
456 unsigned long reason = mcsr;
459 if (reason & MCSR_LD) {
460 recoverable = fsl_rio_mcheck_exception(regs);
461 if (recoverable == 1)
465 printk(
"Machine check in kernel mode.\n");
466 printk(
"Caused by (from MCSR=%lx): ", reason);
468 if (reason & MCSR_MCP)
469 printk(
"Machine Check Signal\n");
471 if (reason & MCSR_ICPERR) {
472 printk(
"Instruction Cache Parity Error\n");
477 mtspr(SPRN_L1CSR1,
mfspr(SPRN_L1CSR1) | L1CSR1_ICFI);
478 while (
mfspr(SPRN_L1CSR1) & L1CSR1_ICFI)
489 if (reason & MCSR_DCPERR_MC) {
490 printk(
"Data Cache Parity Error\n");
497 if (!(
mfspr(SPRN_L1CSR2) & L1CSR2_DCWS))
501 if (reason & MCSR_L2MMU_MHIT) {
502 printk(
"Hit on multiple TLB entries\n");
506 if (reason & MCSR_NMI)
507 printk(
"Non-maskable interrupt\n");
509 if (reason & MCSR_IF) {
510 printk(
"Instruction Fetch Error Report\n");
514 if (reason & MCSR_LD) {
515 printk(
"Load Error Report\n");
519 if (reason & MCSR_ST) {
520 printk(
"Store Error Report\n");
524 if (reason & MCSR_LDG) {
525 printk(
"Guarded Load Error Report\n");
529 if (reason & MCSR_TLBSYNC)
530 printk(
"Simultaneous tlbsync operations\n");
532 if (reason & MCSR_BSL2_ERR) {
533 printk(
"Level 2 Cache Error\n");
537 if (reason & MCSR_MAV) {
540 addr =
mfspr(SPRN_MCAR);
541 addr |= (
u64)
mfspr(SPRN_MCARU) << 32;
543 printk(
"Machine Check %s Address: %#llx\n",
544 reason & MCSR_MEA ?
"Effective" :
"Physical", addr);
548 mtspr(SPRN_MCSR, mcsr);
549 return mfspr(SPRN_MCSR) == 0 && recoverable;
556 if (reason & MCSR_BUS_RBERR) {
557 if (fsl_rio_mcheck_exception(regs))
561 printk(
"Machine check in kernel mode.\n");
562 printk(
"Caused by (from MCSR=%lx): ", reason);
564 if (reason & MCSR_MCP)
565 printk(
"Machine Check Signal\n");
566 if (reason & MCSR_ICPERR)
567 printk(
"Instruction Cache Parity Error\n");
568 if (reason & MCSR_DCP_PERR)
569 printk(
"Data Cache Push Parity Error\n");
570 if (reason & MCSR_DCPERR)
571 printk(
"Data Cache Parity Error\n");
572 if (reason & MCSR_BUS_IAERR)
573 printk(
"Bus - Instruction Address Error\n");
574 if (reason & MCSR_BUS_RAERR)
575 printk(
"Bus - Read Address Error\n");
576 if (reason & MCSR_BUS_WAERR)
577 printk(
"Bus - Write Address Error\n");
578 if (reason & MCSR_BUS_IBERR)
579 printk(
"Bus - Instruction Data Error\n");
580 if (reason & MCSR_BUS_RBERR)
581 printk(
"Bus - Read Data Bus Error\n");
582 if (reason & MCSR_BUS_WBERR)
583 printk(
"Bus - Read Data Bus Error\n");
584 if (reason & MCSR_BUS_IPERR)
585 printk(
"Bus - Instruction Parity Error\n");
586 if (reason & MCSR_BUS_RPERR)
587 printk(
"Bus - Read Parity Error\n");
596 #elif defined(CONFIG_E200)
601 printk(
"Machine check in kernel mode.\n");
602 printk(
"Caused by (from MCSR=%lx): ", reason);
604 if (reason & MCSR_MCP)
605 printk(
"Machine Check Signal\n");
606 if (reason & MCSR_CP_PERR)
607 printk(
"Cache Push Parity Error\n");
608 if (reason & MCSR_CPERR)
609 printk(
"Cache Parity Error\n");
610 if (reason & MCSR_EXCP_ERR)
611 printk(
"ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
612 if (reason & MCSR_BUS_IRERR)
613 printk(
"Bus - Read Bus Error on instruction fetch\n");
614 if (reason & MCSR_BUS_DRERR)
615 printk(
"Bus - Read Bus Error on data load\n");
616 if (reason & MCSR_BUS_WRERR)
617 printk(
"Bus - Write Bus Error on buffered store or cache line push\n");
626 printk(
"Machine check in kernel mode.\n");
627 printk(
"Caused by (from SRR1=%lx): ", reason);
628 switch (reason & 0x601F0000) {
630 printk(
"Machine check signal\n");
635 printk(
"Transfer error ack signal\n");
638 printk(
"Data parity error signal\n");
641 printk(
"Address parity error signal\n");
644 printk(
"L1 Data Cache error\n");
647 printk(
"L1 Instruction Cache error\n");
650 printk(
"L2 data cache parity error\n");
653 printk(
"Unknown values in msr\n");
671 if (
ppc_md.machine_check_exception)
672 recover =
ppc_md.machine_check_exception(regs);
679 #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
690 if (debugger_fault_handler(regs))
693 if (check_io_access(regs))
700 panic(
"Unrecoverable Machine check");
705 die(
"System Management Interrupt", regs,
SIGABRT);
710 printk(
"Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
718 if (
notify_die(DIE_IABR_MATCH,
"iabr_match", regs, 5,
721 if (debugger_iabr_match(regs))
738 if (debugger_sstep(regs))
750 static void emulate_single_step(
struct pt_regs *regs)
756 static inline int __parse_fpscr(
unsigned long fpscr)
761 if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
765 else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
769 else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
773 else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
777 else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
783 static void parse_fpe(
struct pt_regs *regs)
789 code = __parse_fpscr(
current->thread.fpscr.val);
805 static int emulate_string_inst(
struct pt_regs *regs,
u32 instword)
807 u8 rT = (instword >> 21) & 0x1f;
808 u8 rA = (instword >> 16) & 0x1f;
809 u8 NB_RB = (instword >> 11) & 0x1f;
816 if ((rT == rA) || (rT == NB_RB))
819 EA = (rA == 0) ? 0 : regs->
gpr[rA];
821 switch (instword & PPC_INST_STRING_MASK) {
825 num_bytes = regs->
xer & 0x7f;
829 num_bytes = (NB_RB == 0) ? 32 : NB_RB;
835 while (num_bytes != 0)
838 u32 shift = 8 * (3 - (pos & 0x3));
840 switch ((instword & PPC_INST_STRING_MASK)) {
849 regs->
gpr[rT] |= val << shift;
853 val = regs->
gpr[rT] >> shift;
873 static int emulate_popcntb_inst(
struct pt_regs *regs,
u32 instword)
878 ra = (instword >> 16) & 0x1f;
879 rs = (instword >> 21) & 0x1f;
882 tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
883 tmp = (
tmp & 0x3333333333333333ULL) + ((
tmp >> 2) & 0x3333333333333333ULL);
884 tmp = (
tmp + (
tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
890 static int emulate_isel(
struct pt_regs *regs,
u32 instword)
892 u8 rT = (instword >> 21) & 0x1f;
893 u8 rA = (instword >> 16) & 0x1f;
894 u8 rB = (instword >> 11) & 0x1f;
895 u8 BC = (instword >> 6) & 0x1f;
899 tmp = (rA == 0) ? 0 : regs->
gpr[rA];
900 bit = (regs->
ccr >> (31 - BC)) & 0x1;
902 regs->
gpr[rT] = bit ? tmp : regs->
gpr[rB];
907 static int emulate_instruction(
struct pt_regs *regs)
922 rd = (instword >> 21) & 0x1f;
935 int shift = (instword >> 21) & 0x1c;
936 unsigned long msk = 0xf0000000
UL >> shift;
939 regs->
ccr = (regs->
ccr & ~msk) | ((regs->
xer >> shift) &
msk);
940 regs->
xer &= ~0xf0000000
UL;
947 return emulate_string_inst(regs, instword);
953 return emulate_popcntb_inst(regs, instword);
959 return emulate_isel(regs, instword);
967 rd = (instword >> 21) & 0x1f;
975 rd = (instword >> 21) & 0x1f;
977 current->thread.dscr_inherit = 1;
1007 if (debugger_bpt(regs))
1015 if (!(regs->
msr & MSR_PR) &&
1025 if (!arch_irq_disabled_regs(regs))
1028 #ifdef CONFIG_MATH_EMULATION
1038 emulate_single_step(regs);
1042 code = __parse_fpscr(
current->thread.fpscr.val);
1055 switch (emulate_instruction(regs)) {
1058 emulate_single_step(regs);
1077 if (!arch_irq_disabled_regs(regs))
1086 emulate_single_step(regs);
1110 panic(
"kernel stack overflow");
1118 die(
"nonrecoverable exception", regs,
SIGKILL);
1123 printk(
"Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
1131 "%lx at %lx\n", regs->
trap, regs->
nip);
1132 die(
"Unrecoverable FP Unavailable Exception", regs,
SIGABRT);
1145 "%lx at %lx\n", regs->
trap, regs->
nip);
1146 die(
"Unrecoverable VMX/Altivec Unavailable Exception", regs,
SIGABRT);
1159 "%lx at %lx\n", regs->
trap, regs->
nip);
1160 die(
"Unrecoverable VSX Unavailable Exception", regs,
SIGABRT);
1171 void SoftwareEmulation(
struct pt_regs *regs)
1175 #if defined(CONFIG_MATH_EMULATION) || defined(CONFIG_8XX_MINIMAL_FPEMU)
1183 die(
"Kernel Mode Software FPU Emulation", regs,
SIGFPE);
1186 #ifdef CONFIG_MATH_EMULATION
1193 emulate_single_step(regs);
1197 code = __parse_fpscr(
current->thread.fpscr.val);
1209 #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
1216 emulate_single_step(regs);
1231 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1232 static void handle_debug(
struct pt_regs *regs,
unsigned long debug_status)
1239 if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
1240 dbcr_dac(
current) &= ~(DBCR_DAC1R | DBCR_DAC1W);
1241 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1242 current->thread.dbcr2 &= ~DBCR2_DAC12MODE;
1247 }
else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) {
1248 dbcr_dac(
current) &= ~(DBCR_DAC2R | DBCR_DAC2W);
1252 }
else if (debug_status & DBSR_IAC1) {
1253 current->thread.dbcr0 &= ~DBCR0_IAC1;
1254 dbcr_iac_range(
current) &= ~DBCR_IAC12MODE;
1258 }
else if (debug_status & DBSR_IAC2) {
1259 current->thread.dbcr0 &= ~DBCR0_IAC2;
1263 }
else if (debug_status & DBSR_IAC3) {
1264 current->thread.dbcr0 &= ~DBCR0_IAC3;
1265 dbcr_iac_range(
current) &= ~DBCR_IAC34MODE;
1269 }
else if (debug_status & DBSR_IAC4) {
1270 current->thread.dbcr0 &= ~DBCR0_IAC4;
1280 if (DBCR_ACTIVE_EVENTS(
current->thread.dbcr0,
current->thread.dbcr1))
1281 regs->
msr |= MSR_DE;
1284 current->thread.dbcr0 &= ~DBCR0_IDM;
1290 void __kprobes DebugException(
struct pt_regs *regs,
unsigned long debug_status)
1292 current->thread.dbsr = debug_status;
1299 if (debug_status & DBSR_BT) {
1300 regs->
msr &= ~MSR_DE;
1303 mtspr(SPRN_DBCR0,
mfspr(SPRN_DBCR0) & ~DBCR0_BT);
1305 mtspr(SPRN_DBSR, DBSR_BT);
1309 current->thread.dbcr0 &= ~DBCR0_BT;
1310 current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
1311 regs->
msr |= MSR_DE;
1319 if (debugger_sstep(regs))
1321 }
else if (debug_status & DBSR_IC) {
1322 regs->
msr &= ~MSR_DE;
1325 mtspr(SPRN_DBCR0,
mfspr(SPRN_DBCR0) & ~DBCR0_IC);
1327 mtspr(SPRN_DBSR, DBSR_IC);
1334 if (debugger_sstep(regs))
1338 current->thread.dbcr0 &= ~DBCR0_IC;
1339 if (DBCR_ACTIVE_EVENTS(
current->thread.dbcr0,
1341 regs->
msr |= MSR_DE;
1344 current->thread.dbcr0 &= ~DBCR0_IDM;
1349 handle_debug(regs, debug_status);
1353 #if !defined(CONFIG_TAU_INT)
1356 printk(
"TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
1361 #ifdef CONFIG_ALTIVEC
1362 void altivec_assist_exception(
struct pt_regs *regs)
1368 " at %lx\n", regs->
nip);
1369 die(
"Kernel VMX/Altivec assist exception", regs,
SIGILL);
1372 flush_altivec_to_thread(
current);
1378 emulate_single_step(regs);
1390 current->thread.vscr.u[3] |= 0x10000;
1396 void vsx_assist_exception(
struct pt_regs *regs)
1400 " at %lx\n", regs->
nip);
1401 die(
"Kernel VSX assist exception", regs,
SIGILL);
1410 #ifdef CONFIG_FSL_BOOKE
1411 void CacheLockingException(
struct pt_regs *regs,
unsigned long address,
1418 if (error_code & (ESR_DLK|ESR_ILK))
1425 void SPEFloatingPointException(
struct pt_regs *regs)
1428 unsigned long spefscr;
1435 spefscr =
current->thread.spefscr;
1436 fpexc_mode =
current->thread.fpexc_mode;
1438 if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode &
PR_FP_EXC_OVF)) {
1441 else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode &
PR_FP_EXC_UND)) {
1444 else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode &
PR_FP_EXC_DIV))
1446 else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode &
PR_FP_EXC_INV)) {
1449 else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode &
PR_FP_EXC_RES))
1455 emulate_single_step(regs);
1462 }
else if (err == -
EINVAL) {
1473 void SPEFloatingPointRoundException(
struct pt_regs *regs)
1479 if (regs->
msr & MSR_SPE)
1487 emulate_single_step(regs);
1494 }
else if (err == -
EINVAL) {
1515 die(
"Unrecoverable exception", regs,
SIGABRT);
1518 #ifdef CONFIG_BOOKE_WDT
1530 void WatchdogException(
struct pt_regs *regs)
1533 WatchdogHandler(regs);
1544 regs->
gpr[1], regs->
nip);
1545 die(
"Bad kernel stack pointer", regs,
SIGABRT);
1553 #ifdef CONFIG_PPC_EMULATED_STATS
1555 #define WARN_EMULATED_SETUP(type) .type = { .name = #type }
1557 struct ppc_emulated ppc_emulated = {
1558 #ifdef CONFIG_ALTIVEC
1559 WARN_EMULATED_SETUP(altivec),
1561 WARN_EMULATED_SETUP(dcba),
1562 WARN_EMULATED_SETUP(dcbz),
1563 WARN_EMULATED_SETUP(fp_pair),
1564 WARN_EMULATED_SETUP(isel),
1565 WARN_EMULATED_SETUP(mcrxr),
1566 WARN_EMULATED_SETUP(mfpvr),
1567 WARN_EMULATED_SETUP(multiple),
1568 WARN_EMULATED_SETUP(popcntb),
1569 WARN_EMULATED_SETUP(spe),
1570 WARN_EMULATED_SETUP(
string),
1572 #ifdef CONFIG_MATH_EMULATION
1573 WARN_EMULATED_SETUP(math),
1574 #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
1575 WARN_EMULATED_SETUP(8
xx),
1578 WARN_EMULATED_SETUP(vsx),
1581 WARN_EMULATED_SETUP(mfdscr),
1582 WARN_EMULATED_SETUP(mtdscr),
1586 u32 ppc_warn_emulated;
1588 void ppc_warn_emulated_print(
const char *
type)
1594 static int __init ppc_warn_emulated_init(
void)
1598 struct ppc_emulated_entry *
entries = (
void *)&ppc_emulated;
1600 if (!powerpc_debugfs_root)
1604 powerpc_debugfs_root);
1609 &ppc_warn_emulated);
1613 for (i = 0; i <
sizeof(ppc_emulated)/
sizeof(*entries); i++) {
1615 (
u32 *)&entries[i].val.counter);