Zephyr Project API 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
17static inline __printf_like(1, 2) void arch_exception_dump_arg_check(const char *fmt, ...)
18{
19 ARG_UNUSED(fmt);
20}
21
22#if defined(CONFIG_EXCEPTION_DUMP_HOOK)
23
24#include <stdbool.h>
25#include <stdarg.h>
26
37typedef void (*arch_exception_dump_hook_t)(const char *format, va_list args);
38
47typedef void (*arch_exception_drain_hook_t)(bool flush);
48
49extern arch_exception_dump_hook_t arch_exception_dump_hook;
50extern arch_exception_drain_hook_t arch_exception_drain_hook;
51
60static inline void arch_exception_set_dump_hook(arch_exception_dump_hook_t dump,
61 arch_exception_drain_hook_t drain)
62{
63 arch_exception_dump_hook = dump;
64 arch_exception_drain_hook = drain;
65}
66
74static inline void arch_exception_call_drain_hook(bool flush)
75{
76 if (arch_exception_drain_hook) {
77 arch_exception_drain_hook(flush);
78 }
79}
80
90static inline void arch_exception_call_dump_hook(const char *format, ...)
91{
92 va_list args;
93
94 if (arch_exception_dump_hook) {
95 va_start(args, format);
96 arch_exception_dump_hook(format, args);
97 va_end(args);
98 }
99}
100
101#if !defined(CONFIG_EXCEPTION_DUMP)
102#define EXCEPTION_DUMP(format, ...) \
103 do { \
104 if (0) { \
105 arch_exception_dump_arg_check(format, ##__VA_ARGS__); \
106 } \
107 } while (false)
108#elif defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY)
109#define EXCEPTION_DUMP(format, ...) arch_exception_call_dump_hook(format "\n", ##__VA_ARGS__)
110#elif defined(CONFIG_LOG)
111#define EXCEPTION_DUMP(format, ...) arch_exception_call_dump_hook(format "\n", ##__VA_ARGS__); \
112 LOG_ERR(format, ##__VA_ARGS__)
113#else
114#define EXCEPTION_DUMP(format, ...) arch_exception_call_dump_hook(format "\n", ##__VA_ARGS__); \
115 printk(format "\n", ##__VA_ARGS__)
116#endif
117
118#else
119
120#if !defined(CONFIG_EXCEPTION_DUMP)
121#define EXCEPTION_DUMP(format, ...) \
122 do { \
123 if (0) { \
124 arch_exception_dump_arg_check(format, ##__VA_ARGS__); \
125 } \
126 } while (false)
127#elif defined(CONFIG_LOG)
128#define EXCEPTION_DUMP(...) LOG_ERR(__VA_ARGS__)
129#else
130#define EXCEPTION_DUMP(format, ...) printk(format "\n", ##__VA_ARGS__)
131#endif
132#endif
133
134#endif /* _ASMLANGUAGE */
135
136#if defined(CONFIG_X86_64)
138#elif defined(CONFIG_X86)
140#elif defined(CONFIG_ARM64)
142#elif defined(CONFIG_ARM)
144#elif defined(CONFIG_ARC)
146#elif defined(CONFIG_RISCV)
148#elif defined(CONFIG_XTENSA)
150#elif defined(CONFIG_MIPS)
152#elif defined(CONFIG_OPENRISC)
154#elif defined(CONFIG_ARCH_POSIX)
156#elif defined(CONFIG_SPARC)
158#elif defined(CONFIG_RX)
160#elif defined(CONFIG_ARCH_IS_SET)
161#error "The selected architecture is missing from this dispatch header"
162#endif
163
164#endif /* ZEPHYR_INCLUDE_ARCH_EXCEPTION_H_ */
ARCv2 public exception handling.
Cortex-A public exception handling.
ARM AArch32 public exception handling.
static void arch_exception_dump_arg_check(const char *fmt,...)
Dummy function to trigger exception dump argument type checking.
Definition exception.h:17
OpenRISC public exception handling.
RISCV public exception handling.
Macros to abstract toolchain specific capabilities.
Xtensa public exception handling.