blob: a272061af8f0506111d0ca8f0809df3c2206d8c7 [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
27
28/* This level of indirection is needed to fully resolve exception info when it's
29 * a macro
30 */
31#define _STRINGIFY(exception_info) #exception_info
32
33/* Store context for an exception, and print an error message with the context.
34 *
35 * @param[in] exception_type One of the EXCEPTION_TYPE_* values defined above. Any
36 * other value will result in printing "Unknown".
37 */
38#ifdef TFM_EXCEPTION_INFO_DUMP
39#define EXCEPTION_INFO(exception_type) \
40 __ASM volatile( \
41 "MOV r0, lr\n" \
42 "MRS r1, MSP\n" \
43 "MRS r2, PSP\n" \
44 "MOVS r3, #" _STRINGIFY(exception_type) "\n" \
45 "BL store_and_dump_context\n" \
46 )
47
48/* Store context for an exception, then print the info.
49 * Call EXCEPTION_INFO() instead of calling this directly.
50 */
51void store_and_dump_context(uint32_t LR_in, uint32_t MSP_in, uint32_t PSP_in,
52 uint32_t exception_type);
53#else
54#define EXCEPTION_INFO(exception_type)
55#endif
56
57#endif /* __EXCEPTION_INFO_H__ */