blob: fb5e437a7a81ea6ad9bee9a55ca08e75e11dd663 [file] [log] [blame]
Øyvind Rønningstadf2c8dad2021-01-15 15:33:33 +01001/*
2 * Copyright (c) 2021, Nordic Semiconductor ASA. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __EXCEPTION_INFO_H__
8#define __EXCEPTION_INFO_H__
9
10#include <stdint.h>
11
12#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
13#define TRUSTZONE_PRESENT
14#endif
15
16#if defined(__ARM_ARCH_8_1M_MAIN__) || defined(__ARM_ARCH_8M_MAIN__) \
17 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
18#define FAULT_STATUS_PRESENT
19#endif
20
21/* Arguments to EXCEPTION_INFO() */
22#define EXCEPTION_TYPE_SECUREFAULT 0
23#define EXCEPTION_TYPE_HARDFAULT 1
24#define EXCEPTION_TYPE_MEMFAULT 2
25#define EXCEPTION_TYPE_BUSFAULT 3
26#define EXCEPTION_TYPE_USAGEFAULT 4
Joakim Anderssona4066d82022-04-06 16:32:09 +020027#define EXCEPTION_TYPE_PLATFORM 5
Øyvind Rønningstadf2c8dad2021-01-15 15:33:33 +010028
29/* This level of indirection is needed to fully resolve exception info when it's
30 * a macro
31 */
32#define _STRINGIFY(exception_info) #exception_info
33
34/* Store context for an exception, and print an error message with the context.
35 *
36 * @param[in] exception_type One of the EXCEPTION_TYPE_* values defined above. Any
37 * other value will result in printing "Unknown".
38 */
39#ifdef TFM_EXCEPTION_INFO_DUMP
40#define EXCEPTION_INFO(exception_type) \
41 __ASM volatile( \
42 "MOV r0, lr\n" \
43 "MRS r1, MSP\n" \
44 "MRS r2, PSP\n" \
45 "MOVS r3, #" _STRINGIFY(exception_type) "\n" \
46 "BL store_and_dump_context\n" \
47 )
48
49/* Store context for an exception, then print the info.
50 * Call EXCEPTION_INFO() instead of calling this directly.
51 */
52void store_and_dump_context(uint32_t LR_in, uint32_t MSP_in, uint32_t PSP_in,
53 uint32_t exception_type);
54#else
55#define EXCEPTION_INFO(exception_type)
56#endif
57
58#endif /* __EXCEPTION_INFO_H__ */