]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/avr32/cpu/exception.c
stm32: Correct positioning of declaration
[people/ms/u-boot.git] / arch / avr32 / cpu / exception.c
1 /*
2 * Copyright (C) 2005-2006 Atmel Corporation
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6 #include <common.h>
7
8 #include <asm/sysreg.h>
9 #include <asm/ptrace.h>
10
11 DECLARE_GLOBAL_DATA_PTR;
12
13 #define STACKSIZE 2048
14
15 static 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
20 static 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
44 void do_unknown_exception(unsigned int ecr, struct pt_regs *regs)
45 {
46 unsigned int mode;
47
48 printf("\n *** Unhandled exception %u at PC=0x%08lx [%08lx]\n",
49 ecr, regs->pc, regs->pc - gd->reloc_off);
50
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 */
101 if (regs->sp < (gd->start_addr_sp - STACKSIZE) ||
102 regs->sp >= gd->start_addr_sp)
103 printf("\nStack pointer seems bogus, won't do stack dump\n");
104 else
105 dump_mem("\nStack: ", regs->sp, gd->start_addr_sp);
106
107 panic("Unhandled exception\n");
108 }