Liam Barry | 7a8f44d | 2022-03-01 10:43:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" |
| 19 | { |
| 20 | #endif |
| 21 | |
Kshitij Sisodia | 2aa3132 | 2022-03-03 13:59:19 +0000 | [diff] [blame^] | 22 | #include "RTE_Components.h" |
Liam Barry | 7a8f44d | 2022-03-01 10:43:31 +0000 | [diff] [blame] | 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <inttypes.h> |
| 26 | |
| 27 | /** |
| 28 | * @brief Dump core registers on stdout |
| 29 | */ |
| 30 | static void LogCoreCPURegisters(void) |
| 31 | { |
| 32 | printf("CTRL : 0x%08" PRIx32 "\n", __get_CONTROL()); |
| 33 | printf("IPSR : 0x%08" PRIx32 "\n", __get_IPSR()); |
| 34 | printf("APSR : 0x%08" PRIx32 "\n", __get_APSR()); |
| 35 | printf("xPSR : 0x%08" PRIx32 "\n", __get_xPSR()); |
| 36 | printf("PSP : 0x%08" PRIx32 "\n", __get_PSP()); |
| 37 | printf("MSP : 0x%08" PRIx32 "\n", __get_MSP()); |
| 38 | printf("PRIMASK : 0x%08" PRIx32 "\n", __get_PRIMASK()); |
| 39 | printf("BASEPRI : 0x%08" PRIx32 "\n", __get_BASEPRI()); |
| 40 | printf("FAULTMSK: 0x%08" PRIx32 "\n", __get_FAULTMASK()); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @brief Default interrupt handler - an infinite loop. |
| 45 | **/ |
| 46 | __attribute__((noreturn)) static void DefaultHandler(void) |
| 47 | { |
| 48 | LogCoreCPURegisters(); |
| 49 | while (1) { |
| 50 | /* Without the following line, armclang may optimize away the |
| 51 | * infinite loop because it'd be without side effects and thus |
| 52 | * undefined behaviour. */ |
| 53 | __ASM volatile(""); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | #define DEFAULT_HANDLER_CALL(type) \ |
| 58 | do { \ |
| 59 | printf("\n"); \ |
| 60 | printf("%s caught by function %s\n", \ |
| 61 | type, __FUNCTION__); \ |
| 62 | DefaultHandler(); \ |
| 63 | } while (0) |
| 64 | |
| 65 | #define DEFAULT_ERROR_HANDLER_CALL() \ |
| 66 | DEFAULT_HANDLER_CALL("Exception") |
| 67 | |
| 68 | #define DEFAULT_IRQ_HANDLER_CALL() \ |
| 69 | DEFAULT_HANDLER_CALL("Interrupt") |
| 70 | |
| 71 | /** |
| 72 | * Placeholder Exception Handlers for core interrupts. |
| 73 | * |
| 74 | * Weak definitions provided to be used if the user chooses not |
| 75 | * to override them. |
| 76 | **/ |
| 77 | |
| 78 | /** |
| 79 | * @brief Non maskable interrupt handler. |
| 80 | **/ |
| 81 | __attribute__((weak)) void NMI_Handler(void) |
| 82 | { |
| 83 | DEFAULT_ERROR_HANDLER_CALL(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @brief Hardfault interrupt handler. |
| 88 | **/ |
| 89 | __attribute__((weak)) void HardFault_Handler(void) |
| 90 | { |
| 91 | DEFAULT_ERROR_HANDLER_CALL(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @brief Memory management interrupt handler. |
| 96 | **/ |
| 97 | __attribute__((weak)) void MemManage_Handler(void) |
| 98 | { |
| 99 | DEFAULT_IRQ_HANDLER_CALL(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @brief Bus fault interrupt handler. |
| 104 | **/ |
| 105 | __attribute__((weak)) void BusFault_Handler(void) |
| 106 | { |
| 107 | DEFAULT_ERROR_HANDLER_CALL(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @brief Usage fault interrupt handler. |
| 112 | **/ |
| 113 | __attribute__((weak)) void UsageFault_Handler(void) |
| 114 | { |
| 115 | DEFAULT_ERROR_HANDLER_CALL(); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @brief Secure access fault interrupt handler. |
| 120 | **/ |
| 121 | __attribute__((weak)) void SecureFault_Handler(void) |
| 122 | { |
| 123 | DEFAULT_ERROR_HANDLER_CALL(); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @brief Supervisor call interrupt handler. |
| 128 | **/ |
| 129 | __attribute__((weak)) void SVC_Handler(void) |
| 130 | { |
| 131 | DEFAULT_IRQ_HANDLER_CALL(); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @brief Debug monitor interrupt handler. |
| 136 | **/ |
| 137 | __attribute__((weak)) void DebugMon_Handler(void) |
| 138 | { |
| 139 | DEFAULT_IRQ_HANDLER_CALL(); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @brief Pending SV call interrupt handler. |
| 144 | */ |
| 145 | __attribute__((weak)) void PendSV_Handler(void) |
| 146 | { |
| 147 | DEFAULT_IRQ_HANDLER_CALL(); |
| 148 | } |
| 149 | |
| 150 | #ifdef __cplusplus |
| 151 | } |
| 152 | #endif |