Wolfgang Denk | 72a087e | 2006-10-24 14:27:35 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2006 Atmel Corporation |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | #include <common.h> |
| 23 | |
| 24 | #include <asm/sysreg.h> |
| 25 | #include <asm/ptrace.h> |
| 26 | |
| 27 | static const char * const cpu_modes[8] = { |
| 28 | "Application", "Supervisor", "Interrupt level 0", "Interrupt level 1", |
| 29 | "Interrupt level 2", "Interrupt level 3", "Exception", "NMI" |
| 30 | }; |
| 31 | |
| 32 | static void dump_mem(const char *str, unsigned long bottom, unsigned long top) |
| 33 | { |
| 34 | unsigned long p; |
| 35 | int i; |
| 36 | |
| 37 | printf("%s(0x%08lx to 0x%08lx)\n", str, bottom, top); |
| 38 | |
| 39 | for (p = bottom & ~31; p < top; ) { |
| 40 | printf("%04lx: ", p & 0xffff); |
| 41 | |
| 42 | for (i = 0; i < 8; i++, p += 4) { |
| 43 | unsigned int val; |
| 44 | |
| 45 | if (p < bottom || p >= top) |
| 46 | printf(" "); |
| 47 | else { |
| 48 | val = *(unsigned long *)p; |
| 49 | printf("%08x ", val); |
| 50 | } |
| 51 | } |
| 52 | printf("\n"); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void do_unknown_exception(unsigned int ecr, struct pt_regs *regs) |
| 57 | { |
| 58 | unsigned int mode; |
| 59 | |
| 60 | printf("\n *** Unhandled exception %u at PC=0x%08lx\n", ecr, regs->pc); |
| 61 | |
| 62 | switch (ecr) { |
| 63 | case ECR_BUS_ERROR_WRITE: |
| 64 | case ECR_BUS_ERROR_READ: |
| 65 | printf("Bus error at address 0x%08lx\n", |
| 66 | sysreg_read(BEAR)); |
| 67 | break; |
| 68 | case ECR_TLB_MULTIPLE: |
| 69 | case ECR_ADDR_ALIGN_X: |
| 70 | case ECR_PROTECTION_X: |
| 71 | case ECR_ADDR_ALIGN_R: |
| 72 | case ECR_ADDR_ALIGN_W: |
| 73 | case ECR_PROTECTION_R: |
| 74 | case ECR_PROTECTION_W: |
| 75 | case ECR_DTLB_MODIFIED: |
| 76 | case ECR_TLB_MISS_X: |
| 77 | case ECR_TLB_MISS_R: |
| 78 | case ECR_TLB_MISS_W: |
| 79 | printf("MMU exception at address 0x%08lx\n", |
| 80 | sysreg_read(TLBEAR)); |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | printf(" pc: %08lx lr: %08lx sp: %08lx r12: %08lx\n", |
| 85 | regs->pc, regs->lr, regs->sp, regs->r12); |
| 86 | printf(" r11: %08lx r10: %08lx r9: %08lx r8: %08lx\n", |
| 87 | regs->r11, regs->r10, regs->r9, regs->r8); |
| 88 | printf(" r7: %08lx r6: %08lx r5: %08lx r4: %08lx\n", |
| 89 | regs->r7, regs->r6, regs->r5, regs->r4); |
| 90 | printf(" r3: %08lx r2: %08lx r1: %08lx r0: %08lx\n", |
| 91 | regs->r3, regs->r2, regs->r1, regs->r0); |
| 92 | printf("Flags: %c%c%c%c%c\n", |
| 93 | regs->sr & SR_Q ? 'Q' : 'q', |
| 94 | regs->sr & SR_V ? 'V' : 'v', |
| 95 | regs->sr & SR_N ? 'N' : 'n', |
| 96 | regs->sr & SR_Z ? 'Z' : 'z', |
| 97 | regs->sr & SR_C ? 'C' : 'c'); |
| 98 | printf("Mode bits: %c%c%c%c%c%c%c%c%c\n", |
| 99 | regs->sr & SR_H ? 'H' : 'h', |
| 100 | regs->sr & SR_R ? 'R' : 'r', |
| 101 | regs->sr & SR_J ? 'J' : 'j', |
| 102 | regs->sr & SR_EM ? 'E' : 'e', |
| 103 | regs->sr & SR_I3M ? '3' : '.', |
| 104 | regs->sr & SR_I2M ? '2' : '.', |
| 105 | regs->sr & SR_I1M ? '1' : '.', |
| 106 | regs->sr & SR_I0M ? '0' : '.', |
| 107 | regs->sr & SR_GM ? 'G' : 'g'); |
| 108 | mode = (regs->sr >> SYSREG_M0_OFFSET) & 7; |
| 109 | printf("CPU Mode: %s\n", cpu_modes[mode]); |
| 110 | |
| 111 | /* Avoid exception loops */ |
| 112 | if (regs->sp >= CFG_INIT_SP_ADDR |
| 113 | || regs->sp < (CFG_INIT_SP_ADDR - CONFIG_STACKSIZE)) |
| 114 | printf("\nStack pointer seems bogus, won't do stack dump\n"); |
| 115 | else |
| 116 | dump_mem("\nStack: ", regs->sp, CFG_INIT_SP_ADDR); |
| 117 | |
| 118 | panic("Unhandled exception\n"); |
| 119 | } |