blob: b3399974879612532356a6455eee850be82d1a88 [file] [log] [blame]
Stefan Kristiansson952db942011-11-26 19:04:51 +00001/*
2 * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Kristiansson952db942011-11-26 19:04:51 +00006 */
7
8#include <common.h>
9#include <stdio_dev.h>
10#include <asm/system.h>
11
12static 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
30static void (*handlers[32])(void);
31
32void exception_install_handler(int exception, void (*handler)(void))
33{
34 if (exception < 0 || exception > 31)
35 return;
36
37 handlers[exception] = handler;
38}
39
40void exception_free_handler(int exception)
41{
42 if (exception < 0 || exception > 31)
43 return;
44
45 handlers[exception] = 0;
46}
47
48static 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
64void 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}