blob: d6991f6668d3326bfaf205719f9f421bbfff7f25 [file] [log] [blame]
Wolfgang Denk72a087e2006-10-24 14:27:35 +02001/*
2 * Copyright (C) 2005-2006 Atmel Corporation
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denk72a087e2006-10-24 14:27:35 +02005 */
6#include <common.h>
7
8#include <asm/sysreg.h>
9#include <asm/ptrace.h>
10
Haavard Skinnemoen1f4f2122006-11-20 15:53:10 +010011DECLARE_GLOBAL_DATA_PTR;
12
Wolfgang Denk72a087e2006-10-24 14:27:35 +020013static 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
18static 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
42void do_unknown_exception(unsigned int ecr, struct pt_regs *regs)
43{
44 unsigned int mode;
45
Haavard Skinnemoen8d1334a2010-08-12 13:52:52 +070046 printf("\n *** Unhandled exception %u at PC=0x%08lx [%08lx]\n",
47 ecr, regs->pc, regs->pc - gd->reloc_off);
Wolfgang Denk72a087e2006-10-24 14:27:35 +020048
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 */
Andreas Bießmann4db89622015-02-06 23:06:44 +010099 if (regs->sp < (gd->start_addr_sp - CONFIG_STACKSIZE) ||
100 regs->sp >= gd->start_addr_sp)
Wolfgang Denk72a087e2006-10-24 14:27:35 +0200101 printf("\nStack pointer seems bogus, won't do stack dump\n");
102 else
Andreas Bießmann4db89622015-02-06 23:06:44 +0100103 dump_mem("\nStack: ", regs->sp, gd->start_addr_sp);
Wolfgang Denk72a087e2006-10-24 14:27:35 +0200104
105 panic("Unhandled exception\n");
106}