]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/openrisc/cpu/exceptions.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / openrisc / cpu / exceptions.c
1 /*
2 * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8 #include <common.h>
9 #include <stdio_dev.h>
10 #include <asm/system.h>
11
12 static const char * const excp_table[] = {
13 "Unknown exception",
14 "Reset",
15 "Bus Error",
16 "Data Page Fault",
17 "Instruction Page Fault",
18 "Tick Timer",
19 "Alignment",
20 "Illegal Instruction",
21 "External Interrupt",
22 "D-TLB Miss",
23 "I-TLB Miss",
24 "Range",
25 "System Call",
26 "Floating Point",
27 "Trap",
28 };
29
30 static void (*handlers[32])(void);
31
32 void exception_install_handler(int exception, void (*handler)(void))
33 {
34 if (exception < 0 || exception > 31)
35 return;
36
37 handlers[exception] = handler;
38 }
39
40 void exception_free_handler(int exception)
41 {
42 if (exception < 0 || exception > 31)
43 return;
44
45 handlers[exception] = 0;
46 }
47
48 static void exception_hang(int vect)
49 {
50 printf("Unhandled exception at 0x%x ", vect & 0xff00);
51
52 vect = ((vect >> 8) & 0xff);
53 if (vect < ARRAY_SIZE(excp_table))
54 printf("(%s)\n", excp_table[vect]);
55 else
56 printf("(%s)\n", excp_table[0]);
57
58 printf("EPCR: 0x%08lx\n", mfspr(SPR_EPCR_BASE));
59 printf("EEAR: 0x%08lx\n", mfspr(SPR_EEAR_BASE));
60 printf("ESR: 0x%08lx\n", mfspr(SPR_ESR_BASE));
61 hang();
62 }
63
64 void exception_handler(int vect)
65 {
66 int exception = vect >> 8;
67
68 if (handlers[exception])
69 handlers[exception]();
70 else
71 exception_hang(vect);
72 }