blob: d3640d3903b81e6d66e69d6af77180a1c44f7c73 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek952d5142007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
5 * Michal SIMEK <monstr@monstr.eu>
Michal Simek952d5142007-03-11 13:42:58 +01006 */
7
8#include <common.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Michal Simek3af398e2007-05-08 14:52:52 +020010#include <asm/asm.h>
Michal Simek952d5142007-03-11 13:42:58 +010011
12void _hw_exception_handler (void)
13{
14 int address = 0;
15 int state = 0;
Michal Simekf73749b2015-01-26 14:36:13 +010016
Michal Simek952d5142007-03-11 13:42:58 +010017 /* loading address of exception EAR */
Michal Simekf73749b2015-01-26 14:36:13 +010018 MFS(address, rear);
Michal Simek952d5142007-03-11 13:42:58 +010019 /* loading excetpion state register ESR */
Michal Simekf73749b2015-01-26 14:36:13 +010020 MFS(state, resr);
21 printf("Hardware exception at 0x%x address\n", address);
Michal Simek924819c2015-01-26 14:32:23 +010022 R17(address);
Ovidiu Panaitd1d22c72022-02-13 10:09:21 +020023
24 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_DELAY_SLOT_EXCEP) &&
Ovidiu Panaitfd01d6d2022-02-13 10:09:22 +020025 (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
Ovidiu Panaitd1d22c72022-02-13 10:09:21 +020032 puts("Exception in delay slot\n");
Ovidiu Panaitfd01d6d2022-02-13 10:09:22 +020033 }
Ovidiu Panaitd1d22c72022-02-13 10:09:21 +020034
Michal Simek952d5142007-03-11 13:42:58 +010035 switch (state & 0x1f) { /* mask on exception cause */
36 case 0x1:
Michal Simekf73749b2015-01-26 14:36:13 +010037 puts("Unaligned data access exception\n");
Ovidiu Panaitd96eb812022-02-13 10:09:23 +020038
39 printf("Unaligned %sword access\n", ((state & 0x800) ? "" : "half"));
40 printf("Unaligned %s access\n", ((state & 0x400) ? "store" : "load"));
Ovidiu Panait82d22632022-02-13 10:09:24 +020041 printf("Register R%x\n", (state & 0x3E0) >> 5);
Michal Simek952d5142007-03-11 13:42:58 +010042 break;
43 case 0x2:
Michal Simekf73749b2015-01-26 14:36:13 +010044 puts("Illegal op-code exception\n");
Michal Simek952d5142007-03-11 13:42:58 +010045 break;
46 case 0x3:
Michal Simekf73749b2015-01-26 14:36:13 +010047 puts("Instruction bus error exception\n");
Michal Simek952d5142007-03-11 13:42:58 +010048 break;
49 case 0x4:
Michal Simekf73749b2015-01-26 14:36:13 +010050 puts("Data bus error exception\n");
Michal Simek952d5142007-03-11 13:42:58 +010051 break;
52 case 0x5:
Michal Simekf73749b2015-01-26 14:36:13 +010053 puts("Divide by zero exception\n");
Michal Simek952d5142007-03-11 13:42:58 +010054 break;
Michal Simek98565292014-01-20 21:17:07 +010055 case 0x7:
56 puts("Priviledged or stack protection violation exception\n");
57 break;
Michal Simek952d5142007-03-11 13:42:58 +010058 default:
Michal Simekf73749b2015-01-26 14:36:13 +010059 puts("Undefined cause\n");
Michal Simek952d5142007-03-11 13:42:58 +010060 break;
61 }
Ovidiu Panaitfd01d6d2022-02-13 10:09:22 +020062
63 printf("Return address from exception 0x%x\n", address);
Michal Simekf73749b2015-01-26 14:36:13 +010064 hang();
Michal Simek952d5142007-03-11 13:42:58 +010065}
66
Ovidiu Panait39415f72021-11-30 18:33:54 +020067#if CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USR_EXCEP)
Michal Simek952d5142007-03-11 13:42:58 +010068void _exception_handler (void)
69{
Michal Simekf73749b2015-01-26 14:36:13 +010070 puts("User vector_exception\n");
71 hang();
Michal Simek952d5142007-03-11 13:42:58 +010072}
73#endif