2 * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #include <stdio_dev.h>
23 #include <asm/system.h>
25 static const char * const excp_table[] = {
30 "Instruction Page Fault",
33 "Illegal Instruction",
43 static void (*handlers[32])(void);
45 void exception_install_handler(int exception, void (*handler)(void))
47 if (exception < 0 || exception > 31)
50 handlers[exception] = handler;
53 void exception_free_handler(int exception)
55 if (exception < 0 || exception > 31)
58 handlers[exception] = 0;
61 static void exception_hang(int vect)
63 printf("Unhandled exception at 0x%x ", vect & 0xff00);
65 vect = ((vect >> 8) & 0xff);
66 if (vect < ARRAY_SIZE(excp_table))
67 printf("(%s)\n", excp_table[vect]);
69 printf("(%s)\n", excp_table[0]);
71 printf("EPCR: 0x%08lx\n", mfspr(SPR_EPCR_BASE));
72 printf("EEAR: 0x%08lx\n", mfspr(SPR_EEAR_BASE));
73 printf("ESR: 0x%08lx\n", mfspr(SPR_ESR_BASE));
77 void exception_handler(int vect)
79 int exception = vect >> 8;
81 if (handlers[exception])
82 handlers[exception]();