Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
exception.h
Go to the documentation of this file.
1/* exception.h - automatically selects the correct exception.h file to include */
2
3/*
4 * Copyright (c) 2024 Meta Platforms
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef ZEPHYR_INCLUDE_ARCH_EXCEPTION_H_
9#define ZEPHYR_INCLUDE_ARCH_EXCEPTION_H_
10
11#ifndef _ASMLANGUAGE
12
13#include <stdarg.h>
14#include <zephyr/toolchain.h>
15#include <zephyr/sys/printk.h>
16
18static inline __printf_like(1, 2) void arch_exception_dump_arg_check(const char *fmt, ...)
19{
20 ARG_UNUSED(fmt);
21}
22
23#if defined(CONFIG_EXCEPTION_DUMP_HOOK)
24
25#include <stdbool.h>
26#include <stdarg.h>
27
38typedef void (*arch_exception_dump_hook_t)(const char *format, va_list args);
39
48typedef void (*arch_exception_drain_hook_t)(bool flush);
49
50extern arch_exception_dump_hook_t arch_exception_dump_hook;
51extern arch_exception_drain_hook_t arch_exception_drain_hook;
52
61static inline void arch_exception_set_dump_hook(arch_exception_dump_hook_t dump,
62 arch_exception_drain_hook_t drain)
63{
64 arch_exception_dump_hook = dump;
65 arch_exception_drain_hook = drain;
66}
67
75static inline void arch_exception_call_drain_hook(bool flush)
76{
77 if (arch_exception_drain_hook) {
78 arch_exception_drain_hook(flush);
79 }
80}
81
91static inline void arch_exception_call_dump_hook(const char *format, ...)
92{
93 va_list args;
94
95 if (arch_exception_dump_hook) {
96 va_start(args, format);
97 arch_exception_dump_hook(format, args);
98 va_end(args);
99 }
100}
101
102#if !defined(CONFIG_EXCEPTION_DUMP)
103#define EXCEPTION_DUMP(format, ...) \
104 do { \
105 if (0) { \
106 arch_exception_dump_arg_check(format, ##__VA_ARGS__); \
107 } \
108 } while (false)
109#elif defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY)
110#define EXCEPTION_DUMP(format, ...) \
111 do { \
112 printk_panic(); \
113 arch_exception_call_dump_hook(format "\n", ##__VA_ARGS__); \
114 } while (false)
115#elif defined(CONFIG_LOG)
116#define EXCEPTION_DUMP(format, ...) \
117 do { \
118 printk_panic(); \
119 arch_exception_call_dump_hook(format "\n", ##__VA_ARGS__); \
120 LOG_ERR(format, ##__VA_ARGS__); \
121 } while (false)
122#else
123#define EXCEPTION_DUMP(format, ...) \
124 do { \
125 printk_panic(); \
126 arch_exception_call_dump_hook(format "\n", ##__VA_ARGS__); \
127 printk(format "\n", ##__VA_ARGS__); \
128 } while (false)
129#endif
130
131#else
132
133#if !defined(CONFIG_EXCEPTION_DUMP)
134#define EXCEPTION_DUMP(format, ...) \
135 do { \
136 if (0) { \
137 arch_exception_dump_arg_check(format, ##__VA_ARGS__); \
138 } \
139 } while (false)
140#elif defined(CONFIG_LOG)
141#define EXCEPTION_DUMP(...) \
142 do { \
143 printk_panic(); \
144 LOG_ERR(__VA_ARGS__); \
145 } while (false)
146#else
147#define EXCEPTION_DUMP(format, ...) \
148 do { \
149 printk_panic(); \
150 printk(format "\n", ##__VA_ARGS__); \
151 } while (false)
152#endif
153#endif
154
155#endif /* _ASMLANGUAGE */
156
157#if defined(CONFIG_X86_64)
158#include <zephyr/arch/x86/intel64/exception.h>
159#elif defined(CONFIG_X86)
160#include <zephyr/arch/x86/ia32/exception.h>
161#elif defined(CONFIG_ARM64)
162#include <zephyr/arch/arm64/exception.h>
163#elif defined(CONFIG_ARM)
164#include <zephyr/arch/arm/exception.h>
165#elif defined(CONFIG_ARC)
166#include <zephyr/arch/arc/v2/exception.h>
167#elif defined(CONFIG_RISCV)
168#include <zephyr/arch/riscv/exception.h>
169#elif defined(CONFIG_XTENSA)
170#include <zephyr/arch/xtensa/exception.h>
171#elif defined(CONFIG_MIPS)
172#include <zephyr/arch/mips/exception.h>
173#elif defined(CONFIG_OPENRISC)
174#include <zephyr/arch/openrisc/exception.h>
175#elif defined(CONFIG_ARCH_POSIX)
176#include <zephyr/arch/posix/exception.h>
177#elif defined(CONFIG_SPARC)
178#include <zephyr/arch/sparc/exception.h>
179#elif defined(CONFIG_RX)
180#include <zephyr/arch/rx/exception.h>
181#elif defined(CONFIG_ARCH_IS_SET)
182#error "The selected architecture is missing from this dispatch header"
183#endif
184
185#endif /* ZEPHYR_INCLUDE_ARCH_EXCEPTION_H_ */
static void arch_exception_dump_arg_check(const char *fmt,...)
Dummy function to trigger exception dump argument type checking.
Definition exception.h:18
Macros to abstract toolchain specific capabilities.