1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2007 Michal Simek
4 *
5 * Michal SIMEK <monstr@monstr.eu>
6 */
7
8 #include <common.h>
9 #include <hang.h>
10 #include <asm/asm.h>
11
_hw_exception_handler(void)12 void _hw_exception_handler (void)
13 {
14 int address = 0;
15 int state = 0;
16
17 /* loading address of exception EAR */
18 MFS(address, rear);
19 /* loading exception state register ESR */
20 MFS(state, resr);
21 printf("Hardware exception at 0x%x address\n", address);
22 R17(address);
23
24 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_DELAY_SLOT_EXCEP) &&
25 (state & 0x1000)) {
26 /*
27 * For exceptions in delay slots, the return address is stored
28 * in the Branch Target Register (BTR), rather than R17.
29 */
30 MFS(address, rbtr);
31
32 puts("Exception in delay slot\n");
33 }
34
35 switch (state & 0x1f) { /* mask on exception cause */
36 case 0x1:
37 puts("Unaligned data access exception\n");
38
39 printf("Unaligned %sword access\n", ((state & 0x800) ? "" : "half"));
40 printf("Unaligned %s access\n", ((state & 0x400) ? "store" : "load"));
41 printf("Register R%x\n", (state & 0x3E0) >> 5);
42 break;
43 case 0x2:
44 puts("Illegal op-code exception\n");
45 break;
46 case 0x3:
47 puts("Instruction bus error exception\n");
48 break;
49 case 0x4:
50 puts("Data bus error exception\n");
51 break;
52 case 0x5:
53 puts("Divide by zero exception\n");
54 break;
55 case 0x7:
56 puts("Priviledged or stack protection violation exception\n");
57 break;
58 default:
59 puts("Undefined cause\n");
60 break;
61 }
62
63 printf("Return address from exception 0x%x\n", address);
64 hang();
65 }
66
67 #if CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USR_EXCEP)
_exception_handler(void)68 void _exception_handler (void)
69 {
70 puts("User vector_exception\n");
71 hang();
72 }
73 #endif
74