Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2006 Atmel Corporation |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | |
| 8 | #include <asm/sysreg.h> |
| 9 | #include <asm/ptrace.h> |
| 10 | |
Haavard Skinnemoen | 1f4f212 | 2006-11-20 15:53:10 +0100 | [diff] [blame] | 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 13 | static const char * const cpu_modes[8] = { |
| 14 | "Application", "Supervisor", "Interrupt level 0", "Interrupt level 1", |
| 15 | "Interrupt level 2", "Interrupt level 3", "Exception", "NMI" |
| 16 | }; |
| 17 | |
| 18 | static void dump_mem(const char *str, unsigned long bottom, unsigned long top) |
| 19 | { |
| 20 | unsigned long p; |
| 21 | int i; |
| 22 | |
| 23 | printf("%s(0x%08lx to 0x%08lx)\n", str, bottom, top); |
| 24 | |
| 25 | for (p = bottom & ~31; p < top; ) { |
| 26 | printf("%04lx: ", p & 0xffff); |
| 27 | |
| 28 | for (i = 0; i < 8; i++, p += 4) { |
| 29 | unsigned int val; |
| 30 | |
| 31 | if (p < bottom || p >= top) |
| 32 | printf(" "); |
| 33 | else { |
| 34 | val = *(unsigned long *)p; |
| 35 | printf("%08x ", val); |
| 36 | } |
| 37 | } |
| 38 | printf("\n"); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void do_unknown_exception(unsigned int ecr, struct pt_regs *regs) |
| 43 | { |
| 44 | unsigned int mode; |
| 45 | |
Haavard Skinnemoen | 8d1334a | 2010-08-12 13:52:52 +0700 | [diff] [blame] | 46 | printf("\n *** Unhandled exception %u at PC=0x%08lx [%08lx]\n", |
| 47 | ecr, regs->pc, regs->pc - gd->reloc_off); |
Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 48 | |
| 49 | switch (ecr) { |
| 50 | case ECR_BUS_ERROR_WRITE: |
| 51 | case ECR_BUS_ERROR_READ: |
| 52 | printf("Bus error at address 0x%08lx\n", |
| 53 | sysreg_read(BEAR)); |
| 54 | break; |
| 55 | case ECR_TLB_MULTIPLE: |
| 56 | case ECR_ADDR_ALIGN_X: |
| 57 | case ECR_PROTECTION_X: |
| 58 | case ECR_ADDR_ALIGN_R: |
| 59 | case ECR_ADDR_ALIGN_W: |
| 60 | case ECR_PROTECTION_R: |
| 61 | case ECR_PROTECTION_W: |
| 62 | case ECR_DTLB_MODIFIED: |
| 63 | case ECR_TLB_MISS_X: |
| 64 | case ECR_TLB_MISS_R: |
| 65 | case ECR_TLB_MISS_W: |
| 66 | printf("MMU exception at address 0x%08lx\n", |
| 67 | sysreg_read(TLBEAR)); |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | printf(" pc: %08lx lr: %08lx sp: %08lx r12: %08lx\n", |
| 72 | regs->pc, regs->lr, regs->sp, regs->r12); |
| 73 | printf(" r11: %08lx r10: %08lx r9: %08lx r8: %08lx\n", |
| 74 | regs->r11, regs->r10, regs->r9, regs->r8); |
| 75 | printf(" r7: %08lx r6: %08lx r5: %08lx r4: %08lx\n", |
| 76 | regs->r7, regs->r6, regs->r5, regs->r4); |
| 77 | printf(" r3: %08lx r2: %08lx r1: %08lx r0: %08lx\n", |
| 78 | regs->r3, regs->r2, regs->r1, regs->r0); |
| 79 | printf("Flags: %c%c%c%c%c\n", |
| 80 | regs->sr & SR_Q ? 'Q' : 'q', |
| 81 | regs->sr & SR_V ? 'V' : 'v', |
| 82 | regs->sr & SR_N ? 'N' : 'n', |
| 83 | regs->sr & SR_Z ? 'Z' : 'z', |
| 84 | regs->sr & SR_C ? 'C' : 'c'); |
| 85 | printf("Mode bits: %c%c%c%c%c%c%c%c%c\n", |
| 86 | regs->sr & SR_H ? 'H' : 'h', |
| 87 | regs->sr & SR_R ? 'R' : 'r', |
| 88 | regs->sr & SR_J ? 'J' : 'j', |
| 89 | regs->sr & SR_EM ? 'E' : 'e', |
| 90 | regs->sr & SR_I3M ? '3' : '.', |
| 91 | regs->sr & SR_I2M ? '2' : '.', |
| 92 | regs->sr & SR_I1M ? '1' : '.', |
| 93 | regs->sr & SR_I0M ? '0' : '.', |
| 94 | regs->sr & SR_GM ? 'G' : 'g'); |
| 95 | mode = (regs->sr >> SYSREG_M0_OFFSET) & 7; |
| 96 | printf("CPU Mode: %s\n", cpu_modes[mode]); |
| 97 | |
| 98 | /* Avoid exception loops */ |
Simon Glass | 1c865d5 | 2012-12-13 20:49:09 +0000 | [diff] [blame] | 99 | if (regs->sp < (gd->arch.stack_end - CONFIG_STACKSIZE) |
| 100 | || regs->sp >= gd->arch.stack_end) |
Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 101 | printf("\nStack pointer seems bogus, won't do stack dump\n"); |
| 102 | else |
Simon Glass | 1c865d5 | 2012-12-13 20:49:09 +0000 | [diff] [blame] | 103 | dump_mem("\nStack: ", regs->sp, gd->arch.stack_end); |
Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 104 | |
| 105 | panic("Unhandled exception\n"); |
| 106 | } |