Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 Michal Simek |
| 4 | * |
| 5 | * Michal SIMEK <monstr@monstr.eu> |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 9 | #include <hang.h> |
Michal Simek | 3af398e | 2007-05-08 14:52:52 +0200 | [diff] [blame] | 10 | #include <asm/asm.h> |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 11 | |
| 12 | void _hw_exception_handler (void) |
| 13 | { |
| 14 | int address = 0; |
| 15 | int state = 0; |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 16 | |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 17 | /* loading address of exception EAR */ |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 18 | MFS(address, rear); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 19 | /* loading excetpion state register ESR */ |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 20 | MFS(state, resr); |
| 21 | printf("Hardware exception at 0x%x address\n", address); |
Michal Simek | 924819c | 2015-01-26 14:32:23 +0100 | [diff] [blame] | 22 | R17(address); |
Ovidiu Panait | d1d22c7 | 2022-02-13 10:09:21 +0200 | [diff] [blame] | 23 | |
| 24 | if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_DELAY_SLOT_EXCEP) && |
Ovidiu Panait | fd01d6d | 2022-02-13 10:09:22 +0200 | [diff] [blame] | 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 | |
Ovidiu Panait | d1d22c7 | 2022-02-13 10:09:21 +0200 | [diff] [blame] | 32 | puts("Exception in delay slot\n"); |
Ovidiu Panait | fd01d6d | 2022-02-13 10:09:22 +0200 | [diff] [blame] | 33 | } |
Ovidiu Panait | d1d22c7 | 2022-02-13 10:09:21 +0200 | [diff] [blame] | 34 | |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 35 | switch (state & 0x1f) { /* mask on exception cause */ |
| 36 | case 0x1: |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 37 | puts("Unaligned data access exception\n"); |
Ovidiu Panait | d96eb81 | 2022-02-13 10:09:23 +0200 | [diff] [blame] | 38 | |
| 39 | printf("Unaligned %sword access\n", ((state & 0x800) ? "" : "half")); |
| 40 | printf("Unaligned %s access\n", ((state & 0x400) ? "store" : "load")); |
Ovidiu Panait | 82d2263 | 2022-02-13 10:09:24 +0200 | [diff] [blame] | 41 | printf("Register R%x\n", (state & 0x3E0) >> 5); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 42 | break; |
| 43 | case 0x2: |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 44 | puts("Illegal op-code exception\n"); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 45 | break; |
| 46 | case 0x3: |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 47 | puts("Instruction bus error exception\n"); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 48 | break; |
| 49 | case 0x4: |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 50 | puts("Data bus error exception\n"); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 51 | break; |
| 52 | case 0x5: |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 53 | puts("Divide by zero exception\n"); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 54 | break; |
Michal Simek | 9856529 | 2014-01-20 21:17:07 +0100 | [diff] [blame] | 55 | case 0x7: |
| 56 | puts("Priviledged or stack protection violation exception\n"); |
| 57 | break; |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 58 | default: |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 59 | puts("Undefined cause\n"); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 60 | break; |
| 61 | } |
Ovidiu Panait | fd01d6d | 2022-02-13 10:09:22 +0200 | [diff] [blame] | 62 | |
| 63 | printf("Return address from exception 0x%x\n", address); |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 64 | hang(); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Ovidiu Panait | 39415f7 | 2021-11-30 18:33:54 +0200 | [diff] [blame] | 67 | #if CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USR_EXCEP) |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 68 | void _exception_handler (void) |
| 69 | { |
Michal Simek | f73749b | 2015-01-26 14:36:13 +0100 | [diff] [blame] | 70 | puts("User vector_exception\n"); |
| 71 | hang(); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 72 | } |
| 73 | #endif |