2 * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/system.h>
12 static const char * const excp_table[] = {
17 "Instruction Page Fault",
20 "Illegal Instruction",
30 static void (*handlers[32])(void);
32 void exception_install_handler(int exception, void (*handler)(void))
34 if (exception < 0 || exception > 31)
37 handlers[exception] = handler;
40 void exception_free_handler(int exception)
42 if (exception < 0 || exception > 31)
45 handlers[exception] = 0;
48 static void exception_hang(int vect)
50 printf("Unhandled exception at 0x%x ", vect & 0xff00);
52 vect = ((vect >> 8) & 0xff);
53 if (vect < ARRAY_SIZE(excp_table))
54 printf("(%s)\n", excp_table[vect]);
56 printf("(%s)\n", excp_table[0]);
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));
64 void exception_handler(int vect)
66 int exception = vect >> 8;
68 if (handlers[exception])
69 handlers[exception]();