Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
coredump.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
8#define ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
9
10#include <stddef.h>
11#include <stdint.h>
12#include <sys/types.h>
13
14/*
15 * Define COREDUMP_*_STR as public to allow coredump_backend_other to re-use
16 * these strings if necessary
17 */
18#define COREDUMP_BEGIN_STR "BEGIN#"
19#define COREDUMP_END_STR "END#"
20#define COREDUMP_ERROR_STR "ERROR CANNOT DUMP#"
21
22/*
23 * Need to prefix coredump strings to make it easier to parse
24 * as log module adds its own prefixes.
25 */
26#define COREDUMP_PREFIX_STR "#CD:"
27
68
126
138
139#ifdef CONFIG_DEBUG_COREDUMP
140
141#include <zephyr/toolchain.h>
142#include <zephyr/arch/cpu.h>
143#include <zephyr/sys/byteorder.h>
144
145#define COREDUMP_HDR_VER 1
146
147#define COREDUMP_ARCH_HDR_ID 'A'
148
149#define COREDUMP_MEM_HDR_ID 'M'
150#define COREDUMP_MEM_HDR_VER 1
151
152/* Target code */
153enum coredump_tgt_code {
154 COREDUMP_TGT_UNKNOWN = 0,
155 COREDUMP_TGT_X86,
156 COREDUMP_TGT_X86_64,
157 COREDUMP_TGT_ARM_CORTEX_M,
158 COREDUMP_TGT_RISC_V,
159 COREDUMP_TGT_XTENSA,
160 COREDUMP_TGT_ARM64,
161};
162
163/* Coredump header */
164struct coredump_hdr_t {
165 /* 'Z', 'E' */
166 char id[2];
167
168 /* Header version */
169 uint16_t hdr_version;
170
171 /* Target code */
172 uint16_t tgt_code;
173
174 /* Pointer size in Log2 */
175 uint8_t ptr_size_bits;
176
178
179 /* Coredump Reason given */
180 unsigned int reason;
181} __packed;
182
183/* Architecture-specific block header */
184struct coredump_arch_hdr_t {
185 /* COREDUMP_ARCH_HDR_ID */
186 char id;
187
188 /* Header version */
189 uint16_t hdr_version;
190
191 /* Number of bytes in this block (excluding header) */
192 uint16_t num_bytes;
193} __packed;
194
195/* Memory block header */
196struct coredump_mem_hdr_t {
197 /* COREDUMP_MEM_HDR_ID */
198 char id;
199
200 /* Header version */
201 uint16_t hdr_version;
202
203 /* Address of start of memory region */
204 uintptr_t start;
205
206 /* Address of end of memory region */
207 uintptr_t end;
208} __packed;
209
210typedef void (*coredump_backend_start_t)(void);
211typedef void (*coredump_backend_end_t)(void);
212typedef void (*coredump_backend_buffer_output_t)(uint8_t *buf, size_t buflen);
213typedef int (*coredump_backend_query_t)(enum coredump_query_id query_id,
214 void *arg);
215typedef int (*coredump_backend_cmd_t)(enum coredump_cmd_id cmd_id,
216 void *arg);
217
218struct coredump_backend_api {
219 /* Signal to backend of the start of coredump. */
220 coredump_backend_start_t start;
221
222 /* Signal to backend of the end of coredump. */
223 coredump_backend_end_t end;
224
225 /* Raw buffer output */
226 coredump_backend_buffer_output_t buffer_output;
227
228 /* Perform query on backend */
229 coredump_backend_query_t query;
230
231 /* Perform command on backend */
232 coredump_backend_cmd_t cmd;
233};
234
235void coredump(unsigned int reason, const struct arch_esf *esf,
236 struct k_thread *thread);
237void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
238void coredump_buffer_output(uint8_t *buf, size_t buflen);
239
240int coredump_query(enum coredump_query_id query_id, void *arg);
241int coredump_cmd(enum coredump_cmd_id cmd_id, void *arg);
242
243#else
244
245static inline void coredump(unsigned int reason, const struct arch_esf *esf,
246 struct k_thread *thread)
247{
248 ARG_UNUSED(reason);
249 ARG_UNUSED(esf);
250 ARG_UNUSED(thread);
251}
252
253static inline void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
254{
255 ARG_UNUSED(start_addr);
256 ARG_UNUSED(end_addr);
257}
258
259static inline void coredump_buffer_output(uint8_t *buf, size_t buflen)
260{
261 ARG_UNUSED(buf);
262 ARG_UNUSED(buflen);
263}
264
265static inline int coredump_query(enum coredump_query_id query_id, void *arg)
266{
267 ARG_UNUSED(query_id);
268 ARG_UNUSED(arg);
269 return -ENOTSUP;
270}
271
272static inline int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
273{
274 ARG_UNUSED(query_id);
275 ARG_UNUSED(arg);
276 return -ENOTSUP;
277}
278
279#endif /* CONFIG_DEBUG_COREDUMP */
280
342#endif /* ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_ */
static struct k_thread thread[2]
Definition atomic.c:26
static void coredump_buffer_output(uint8_t *buf, size_t buflen)
Output the buffer via coredump.
Definition coredump.h:259
coredump_query_id
Query ID.
Definition coredump.h:39
coredump_cmd_id
Command ID.
Definition coredump.h:70
static void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
Dump memory region.
Definition coredump.h:253
static int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
Perform command on coredump subsystem.
Definition coredump.h:272
static int coredump_query(enum coredump_query_id query_id, void *arg)
Perform query on coredump subsystem.
Definition coredump.h:265
static void coredump(unsigned int reason, const struct arch_esf *esf, struct k_thread *thread)
Perform coredump.
Definition coredump.h:245
@ COREDUMP_QUERY_HAS_STORED_DUMP
Check if there is a stored coredump from backend.
Definition coredump.h:53
@ COREDUMP_QUERY_GET_STORED_DUMP_SIZE
Returns:
Definition coredump.h:61
@ COREDUMP_QUERY_MAX
Max value for query ID.
Definition coredump.h:66
@ COREDUMP_QUERY_GET_ERROR
Returns error code from backend.
Definition coredump.h:43
@ COREDUMP_CMD_COPY_STORED_DUMP
Copy the raw stored coredump.
Definition coredump.h:108
@ COREDUMP_CMD_MAX
Max value for command ID.
Definition coredump.h:124
@ COREDUMP_CMD_INVALIDATE_STORED_DUMP
Invalidate the stored coredump.
Definition coredump.h:119
@ COREDUMP_CMD_ERASE_STORED_DUMP
Erase the stored coredump.
Definition coredump.h:97
@ COREDUMP_CMD_VERIFY_STORED_DUMP
Verify that the stored coredump is valid.
Definition coredump.h:87
@ COREDUMP_CMD_CLEAR_ERROR
Clear error code from backend.
Definition coredump.h:76
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define ENOTSUP
Unsupported value.
Definition errno.h:114
__INTPTR_TYPE__ off_t
Definition types.h:36
static ZTEST_DMEM int flag
Definition main.c:26
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Exception Stack Frame.
Definition exception.h:57
Coredump copy command (COREDUMP_CMD_COPY_STORED_DUMP) argument definition.
Definition coredump.h:128
off_t offset
Copy offset.
Definition coredump.h:130
uint8_t * buffer
Copy destination buffer.
Definition coredump.h:133
size_t length
Copy length.
Definition coredump.h:136
Thread Structure.
Definition thread.h:259
Byte order helpers.
Macros to abstract toolchain specific capabilities.