Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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/* Query ID */
12 /*
13 * Returns error code from backend.
14 */
16
17 /*
18 * Check if there is a stored coredump from backend.
19 *
20 * Returns 1 if there is a stored coredump.
21 * 0 if none.
22 * -ENOTSUP if this query is not supported.
23 * Otherwise, error code from backend.
24 */
26
28};
29
30/* Command ID */
32 /*
33 * Clear error code from backend.
34 *
35 * Returns 0 if successful, failed otherwise.
36 */
38
39 /*
40 * Verify that the stored coredump is valid.
41 *
42 * Returns 1 if valid.
43 * 0 if not valid or no stored coredump.
44 * -ENOTSUP if this command is not supported.
45 * Otherwise, error code from backend.
46 */
48
49 /*
50 * Erase the stored coredump.
51 *
52 * Returns 0 if successful.
53 * -ENOTSUP if this command is not supported.
54 * Otherwise, error code from backend.
55 */
57
59};
60
61#ifdef CONFIG_DEBUG_COREDUMP
62
63#include <toolchain.h>
64#include <arch/cpu.h>
65#include <sys/byteorder.h>
66
67#define COREDUMP_HDR_VER 1
68
69#define COREDUMP_ARCH_HDR_ID 'A'
70
71#define COREDUMP_MEM_HDR_ID 'M'
72#define COREDUMP_MEM_HDR_VER 1
73
74/* Target code */
75enum coredump_tgt_code {
76 COREDUMP_TGT_UNKNOWN = 0,
77 COREDUMP_TGT_X86,
78 COREDUMP_TGT_X86_64,
79 COREDUMP_TGT_ARM_CORTEX_M,
80 COREDUMP_TGT_RISC_V,
81 COREDUMP_TGT_XTENSA,
82};
83
84/* Coredump header */
85struct coredump_hdr_t {
86 /* 'Z', 'E' */
87 char id[2];
88
89 /* Header version */
90 uint16_t hdr_version;
91
92 /* Target code */
93 uint16_t tgt_code;
94
95 /* Pointer size in Log2 */
96 uint8_t ptr_size_bits;
97
99
100 /* Coredump Reason given */
101 unsigned int reason;
102} __packed;
103
104/* Architecture-specific block header */
105struct coredump_arch_hdr_t {
106 /* COREDUMP_ARCH_HDR_ID */
107 char id;
108
109 /* Header version */
110 uint16_t hdr_version;
111
112 /* Number of bytes in this block (excluding header) */
113 uint16_t num_bytes;
114} __packed;
115
116/* Memory block header */
117struct coredump_mem_hdr_t {
118 /* COREDUMP_MEM_HDR_ID */
119 char id;
120
121 /* Header version */
122 uint16_t hdr_version;
123
124 /* Address of start of memory region */
125 uintptr_t start;
126
127 /* Address of end of memory region */
128 uintptr_t end;
129} __packed;
130
131typedef void (*coredump_backend_start_t)(void);
132typedef void (*coredump_backend_end_t)(void);
133typedef void (*coredump_backend_buffer_output_t)(uint8_t *buf, size_t buflen);
134typedef int (*coredump_backend_query_t)(enum coredump_query_id query_id,
135 void *arg);
136typedef int (*coredump_backend_cmd_t)(enum coredump_cmd_id cmd_id,
137 void *arg);
138
139struct coredump_backend_api {
140 /* Signal to backend of the start of coredump. */
141 coredump_backend_start_t start;
142
143 /* Signal to backend of the end of coredump. */
144 coredump_backend_end_t end;
145
146 /* Raw buffer output */
147 coredump_backend_buffer_output_t buffer_output;
148
149 /* Perform query on backend */
150 coredump_backend_query_t query;
151
152 /* Perform command on backend */
153 coredump_backend_cmd_t cmd;
154};
155
156void coredump(unsigned int reason, const z_arch_esf_t *esf,
157 struct k_thread *thread);
158void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
159void coredump_buffer_output(uint8_t *buf, size_t buflen);
160
161int coredump_query(enum coredump_query_id query_id, void *arg);
162int coredump_cmd(enum coredump_cmd_id cmd_id, void *arg);
163
164#else
165
166void coredump(unsigned int reason, const z_arch_esf_t *esf,
167 struct k_thread *thread)
168{
169}
170
171void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
172{
173}
174
175void coredump_buffer_output(uint8_t *buf, size_t buflen)
176{
177}
178
179int coredump_query(enum coredump_query_id query_id, void *arg)
180{
181 return -ENOTSUP;
182}
183
184int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
185{
186 return -ENOTSUP;
187}
188
189#endif /* CONFIG_DEBUG_COREDUMP */
190
258#endif /* ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_ */
static struct k_thread thread[2]
Definition: atomic.c:26
Byte order helpers.
coredump_query_id
Definition: coredump.h:11
@ COREDUMP_QUERY_HAS_STORED_DUMP
Definition: coredump.h:25
@ COREDUMP_QUERY_MAX
Definition: coredump.h:27
@ COREDUMP_QUERY_GET_ERROR
Definition: coredump.h:15
coredump_cmd_id
Definition: coredump.h:31
@ COREDUMP_CMD_MAX
Definition: coredump.h:58
@ COREDUMP_CMD_ERASE_STORED_DUMP
Definition: coredump.h:56
@ COREDUMP_CMD_VERIFY_STORED_DUMP
Definition: coredump.h:47
@ COREDUMP_CMD_CLEAR_ERROR
Definition: coredump.h:37
void coredump_buffer_output(uint8_t *buf, size_t buflen)
Output the buffer via coredump.
Definition: coredump.h:175
void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
Dump memory region.
Definition: coredump.h:171
int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
Perform command on coredump subsystem.
Definition: coredump.h:184
void coredump(unsigned int reason, const z_arch_esf_t *esf, struct k_thread *thread)
Perform coredump.
Definition: coredump.h:166
int coredump_query(enum coredump_query_id query_id, void *arg)
Perform query on coredump subsystem.
Definition: coredump.h:179
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition: ft8xx_reference_api.h:153
#define ENOTSUP
Definition: errno.h:115
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:75
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Definition: thread.h:216
static uint32_t flag[3]
Definition: thread_competition.c:23
Macros to abstract toolchain specific capabilities.