blob: f79e465e1fb5faf6d3b55a153176222e3c410cc5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek76316a32007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
5 * Michal SIMEK <monstr@monstr.eu>
Michal Simek76316a32007-03-11 13:42:58 +01006 */
7
8#include <common.h>
Simon Glassdb41d652019-12-28 10:45:07 -07009#include <hang.h>
Michal Simek1a50f1642007-05-08 14:52:52 +020010#include <asm/asm.h>
Michal Simek76316a32007-03-11 13:42:58 +010011
12void _hw_exception_handler (void)
13{
14 int address = 0;
15 int state = 0;
Michal Simek5e2fc802015-01-26 14:36:13 +010016
Michal Simek76316a32007-03-11 13:42:58 +010017 /* loading address of exception EAR */
Michal Simek5e2fc802015-01-26 14:36:13 +010018 MFS(address, rear);
Michal Simek76316a32007-03-11 13:42:58 +010019 /* loading excetpion state register ESR */
Michal Simek5e2fc802015-01-26 14:36:13 +010020 MFS(state, resr);
21 printf("Hardware exception at 0x%x address\n", address);
Michal Simek1c424d22015-01-26 14:32:23 +010022 R17(address);
Ovidiu Panait7422b412022-02-13 10:09:21 +020023
24 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_DELAY_SLOT_EXCEP) &&
Ovidiu Panaitee8161f2022-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 Panait7422b412022-02-13 10:09:21 +020032 puts("Exception in delay slot\n");
Ovidiu Panaitee8161f2022-02-13 10:09:22 +020033 }
Ovidiu Panait7422b412022-02-13 10:09:21 +020034
Michal Simek76316a32007-03-11 13:42:58 +010035 switch (state & 0x1f) { /* mask on exception cause */
36 case 0x1:
Michal Simek5e2fc802015-01-26 14:36:13 +010037 puts("Unaligned data access exception\n");
Michal Simek76316a32007-03-11 13:42:58 +010038 break;
39 case 0x2:
Michal Simek5e2fc802015-01-26 14:36:13 +010040 puts("Illegal op-code exception\n");
Michal Simek76316a32007-03-11 13:42:58 +010041 break;
42 case 0x3:
Michal Simek5e2fc802015-01-26 14:36:13 +010043 puts("Instruction bus error exception\n");
Michal Simek76316a32007-03-11 13:42:58 +010044 break;
45 case 0x4:
Michal Simek5e2fc802015-01-26 14:36:13 +010046 puts("Data bus error exception\n");
Michal Simek76316a32007-03-11 13:42:58 +010047 break;
48 case 0x5:
Michal Simek5e2fc802015-01-26 14:36:13 +010049 puts("Divide by zero exception\n");
Michal Simek76316a32007-03-11 13:42:58 +010050 break;
Michal Simekef2c1d82014-01-20 21:17:07 +010051 case 0x7:
52 puts("Priviledged or stack protection violation exception\n");
53 break;
Michal Simek76316a32007-03-11 13:42:58 +010054 default:
Michal Simek5e2fc802015-01-26 14:36:13 +010055 puts("Undefined cause\n");
Michal Simek76316a32007-03-11 13:42:58 +010056 break;
57 }
Ovidiu Panaitee8161f2022-02-13 10:09:22 +020058
59 printf("Return address from exception 0x%x\n", address);
Michal Simek5e2fc802015-01-26 14:36:13 +010060 printf("Unaligned %sword access\n", ((state & 0x800) ? "" : "half"));
61 printf("Unaligned %s access\n", ((state & 0x400) ? "store" : "load"));
62 printf("Register R%x\n", (state & 0x3E) >> 5);
63 hang();
Michal Simek76316a32007-03-11 13:42:58 +010064}
65
Ovidiu Panait83b175b2021-11-30 18:33:54 +020066#if CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USR_EXCEP)
Michal Simek76316a32007-03-11 13:42:58 +010067void _exception_handler (void)
68{
Michal Simek5e2fc802015-01-26 14:36:13 +010069 puts("User vector_exception\n");
70 hang();
Michal Simek76316a32007-03-11 13:42:58 +010071}
72#endif