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