Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include "esp_gdbstub_common.h"
#include "soc/soc_memory_layout.h"
#include "xtensa/config/specreg.h"
#include "sdkconfig.h"
#include "esp_cpu.h"
#include "esp_ipc_isr.h"
#include "esp_private/crosscore_int.h"
#include <xtensa_context.h>
init_regfile(esp_gdbstub_gdb_regfile_t *)
update_regfile_common(esp_gdbstub_gdb_regfile_t *)
gdbstub_read_fpu_regs(void *)
esp_gdbstub_frame_to_regfile(const esp_gdbstub_frame_t *, esp_gdbstub_gdb_regfile_t *)
dummy_tcb_t
esp_gdbstub_tcb_frame_to_regfile(dummy_tcb_t *, esp_gdbstub_gdb_regfile_t *)
solicited_frame_to_regfile(const XtSolFrame *, esp_gdbstub_gdb_regfile_t *)
esp_gdbstub_tcb_to_regfile(TaskHandle_t, esp_gdbstub_gdb_regfile_t *)
esp_gdbstub_get_signal(const esp_gdbstub_frame_t *)
esp_gdbstub_init_dports()
esp_gdbstub_stall_other_cpus_start()
esp_gdbstub_stall_other_cpus_end()
esp_gdbstub_clear_step()
esp_gdbstub_do_step(esp_gdbstub_frame_t *)
esp_gdbstub_trigger_cpu()
esp_gdbstub_set_register(esp_gdbstub_frame_t *, uint32_t, uint32_t)
Files
loading (3/5)...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_gdbstub/src/port/xtensa/gdbstub_xtensa.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include "esp_gdbstub_common.h" #include "soc/soc_memory_layout.h" #include "xtensa/config/specreg.h" #include "sdkconfig.h" #include "esp_cpu.h" #include "esp_ipc_isr.h" #include "esp_private/crosscore_int.h" #include <xtensa_context.h>9 includes #if !XCHAL_HAVE_WINDOWED #warning "gdbstub_xtensa: revisit the implementation for Call0 ABI" #endif extern int _invalid_pc_placeholder; static inline void init_regfile(esp_gdbstub_gdb_regfile_t *dst) { memset(dst, 0, sizeof(*dst)); }{ ... } static void update_regfile_common(esp_gdbstub_gdb_regfile_t *dst) { if (dst->a[0] & 0x8000000U) { dst->a[0] = (uint32_t)esp_cpu_pc_to_addr(dst->a[0]); }{...} if (!esp_stack_ptr_is_sane(dst->a[1])) { dst->a[1] = 0xDEADBEEF; }{...} dst->windowbase = 0; dst->windowstart = 0x1; RSR(CONFIGID0, dst->configid0); RSR(CONFIGID1, dst->configid1); }{ ... } #if XCHAL_HAVE_FP /** @brief Read FPU registers to memory *//* ... */ static void gdbstub_read_fpu_regs(void *data) { float *ptr0; void *ptr1; asm volatile ("mov %0, %1" : "=a" (ptr0) : "a" (data)); asm volatile ("rur.FCR %0" : "=a" (ptr1)); asm volatile ("s32i %0, %1, 64" : "=a" (ptr1) : "a" (ptr0)); asm volatile ("rur.FSR %0" : "=a" (ptr1)); asm volatile ("s32i %0, %1, 68" : "=a" (ptr1) : "a" (ptr0)); asm volatile ("ssi f0, %0, 0" :: "a" (ptr0)); //*(ptr0 + 0) = f0; asm volatile ("ssi f1, %0, 4" :: "a" (ptr0)); //*(ptr0 + 4) = f1; asm volatile ("ssi f2, %0, 8" :: "a" (ptr0)); //... asm volatile ("ssi f3, %0, 12" :: "a" (ptr0)); asm volatile ("ssi f4, %0, 16" :: "a" (ptr0)); asm volatile ("ssi f5, %0, 20" :: "a" (ptr0)); asm volatile ("ssi f6, %0, 24" :: "a" (ptr0)); asm volatile ("ssi f7, %0, 28" :: "a" (ptr0)); asm volatile ("ssi f8, %0, 32" :: "a" (ptr0)); asm volatile ("ssi f9, %0, 36" :: "a" (ptr0)); asm volatile ("ssi f10, %0, 40" :: "a" (ptr0)); asm volatile ("ssi f11, %0, 44" :: "a" (ptr0)); asm volatile ("ssi f12, %0, 48" :: "a" (ptr0)); asm volatile ("ssi f13, %0, 52" :: "a" (ptr0)); asm volatile ("ssi f14, %0, 56" :: "a" (ptr0)); asm volatile ("ssi f15, %0, 60" :: "a" (ptr0)); }{ ... } #endif/* ... */ // XCHAL_HAVE_FP extern const uint32_t offset_pxEndOfStack; extern const uint32_t offset_cpsa; /* Offset to start of the CPSA area on the stack. See uxInitialiseStackCPSA(). */ extern uint32_t _xt_coproc_owner_sa[2]; void esp_gdbstub_frame_to_regfile(const esp_gdbstub_frame_t *frame, esp_gdbstub_gdb_regfile_t *dst) { init_regfile(dst); const uint32_t *a_regs = (const uint32_t *) &frame->a0; if (!(esp_ptr_executable(esp_cpu_pc_to_addr(frame->pc)) && (frame->pc & 0xC0000000U))) { /* Xtensa ABI sets the 2 MSBs of the PC according to the windowed call size * In case the PC is invalid, GDB will fail to translate addresses to function names * Hence replacing the PC to a placeholder address in case of invalid PC *//* ... */ dst->pc = (uint32_t)&_invalid_pc_placeholder; }{...} else { dst->pc = (uint32_t)esp_cpu_pc_to_addr(frame->pc); }{...} for (int i = 0; i < 16; i++) { dst->a[i] = a_regs[i]; }{...} for (int i = 16; i < 64; i++) { dst->a[i] = 0xDEADBEEF; }{...} #if XCHAL_HAVE_FP extern void *pxCurrentTCBs[2]; void *current_tcb_ptr = pxCurrentTCBs[0]; uint32_t *current_fpu_ptr = NULL; #if !CONFIG_FREERTOS_UNICORE current_tcb_ptr = pxCurrentTCBs[esp_cpu_get_core_id()]; #endif uint32_t cp_enabled; RSR(CPENABLE, cp_enabled); // Check if the co-processor is enabled if (cp_enabled) { gdbstub_read_fpu_regs(dst->f); }{...} else { current_tcb_ptr += offset_pxEndOfStack; current_tcb_ptr = *(void **)current_tcb_ptr; current_tcb_ptr -= offset_cpsa; // Operation (&~0xf) required in .macro get_cpsa_from_tcb reg_A reg_B current_tcb_ptr = (void*)((uint32_t)current_tcb_ptr&~0xf); current_fpu_ptr = *(uint32_t **)(current_tcb_ptr + XT_CP_ASA); dst->fcr = current_fpu_ptr[0]; dst->fsr = current_fpu_ptr[1]; for (int i = 0; i < 16; i++) { dst->f[i] = current_fpu_ptr[i + 2]; }{...} }{...} #endif/* ... */ //XCHAL_HAVE_FP #if XCHAL_HAVE_LOOPS dst->lbeg = frame->lbeg; dst->lend = frame->lend; dst->lcount = frame->lcount;/* ... */ #endif dst->ps = (frame->ps & PS_UM) ? (frame->ps & ~PS_EXCM) : frame->ps; dst->sar = frame->sar; update_regfile_common(dst); }{ ... } #ifdef CONFIG_ESP_GDBSTUB_SUPPORT_TASKS /* Represents FreeRTOS TCB structure */ typedef struct { uint8_t *top_of_stack; /* Other members aren't needed */ }{ ... } dummy_tcb_t; void esp_gdbstub_tcb_frame_to_regfile(dummy_tcb_t *tcb, esp_gdbstub_gdb_regfile_t *dst) { const XtExcFrame *frame = (XtExcFrame *) tcb->top_of_stack; init_regfile(dst); const uint32_t *a_regs = (const uint32_t *) &frame->a0; if (!(esp_ptr_executable(esp_cpu_pc_to_addr(frame->pc)) && (frame->pc & 0xC0000000U))) { /* Xtensa ABI sets the 2 MSBs of the PC according to the windowed call size * In case the PC is invalid, GDB will fail to translate addresses to function names * Hence replacing the PC to a placeholder address in case of invalid PC *//* ... */ dst->pc = (uint32_t)&_invalid_pc_placeholder; }{...} else { dst->pc = (uint32_t)esp_cpu_pc_to_addr(frame->pc); }{...} for (int i = 0; i < 16; i++) { dst->a[i] = a_regs[i]; }{...} for (int i = 16; i < 64; i++) { dst->a[i] = 0xDEADBEEF; }{...} #if XCHAL_HAVE_FP uint32_t *current_xt_coproc_owner_sa = (uint32_t *)_xt_coproc_owner_sa[0]; #if !CONFIG_FREERTOS_UNICORE current_xt_coproc_owner_sa = (uint32_t *)_xt_coproc_owner_sa[esp_cpu_get_core_id()]; #endif uint32_t cp_enabled; RSR(CPENABLE, cp_enabled); void *current_tcb_ptr = tcb; uint32_t *current_fpu_ptr = NULL; { current_tcb_ptr += offset_pxEndOfStack; current_tcb_ptr = *(void **)current_tcb_ptr; current_tcb_ptr -= offset_cpsa; // Operation (&~0xf) required in .macro get_cpsa_from_tcb reg_A reg_B current_tcb_ptr = (void*)((uint32_t)current_tcb_ptr&~0xf); current_fpu_ptr = *(uint32_t **)(current_tcb_ptr + XT_CP_ASA); bool use_fpu_regs = ((false == cp_enabled) && (current_xt_coproc_owner_sa[0] == 1) && (current_fpu_ptr == (uint32_t*)current_xt_coproc_owner_sa[2])); dst->fcr = current_fpu_ptr[0]; dst->fsr = current_fpu_ptr[1]; for (int i = 0; i < 16; i++) { dst->f[i] = current_fpu_ptr[i + 2]; }{...} /* We have situation when FPU is in use, but the context not stored to the memory, and we have to read from CPU registers. *//* ... */ if (use_fpu_regs) { gdbstub_read_fpu_regs(dst->f); }{...} }{...} /* ... */#endif // XCHAL_HAVE_FP #if XCHAL_HAVE_LOOPS dst->lbeg = frame->lbeg; dst->lend = frame->lend; dst->lcount = frame->lcount;/* ... */ #endif dst->ps = (frame->ps & PS_UM) ? (frame->ps & ~PS_EXCM) : frame->ps; dst->sar = frame->sar; update_regfile_common(dst); }{ ... } static void solicited_frame_to_regfile(const XtSolFrame *frame, esp_gdbstub_gdb_regfile_t *dst) { init_regfile(dst); const uint32_t *a_regs = (const uint32_t *) &frame->a0; if (!(esp_ptr_executable(esp_cpu_pc_to_addr(frame->pc)) && (frame->pc & 0xC0000000U))) { dst->pc = (uint32_t)&_invalid_pc_placeholder; }{...} else { dst->pc = (uint32_t)esp_cpu_pc_to_addr(frame->pc); }{...} /* only 4 registers saved in the solicited frame */ for (int i = 0; i < 4; i++) { dst->a[i] = a_regs[i]; }{...} for (int i = 4; i < 64; i++) { dst->a[i] = 0xDEADBEEF; }{...} dst->ps = (frame->ps & PS_UM) ? (frame->ps & ~PS_EXCM) : frame->ps; update_regfile_common(dst); }{ ... } void esp_gdbstub_tcb_to_regfile(TaskHandle_t tcb, esp_gdbstub_gdb_regfile_t *dst) { dummy_tcb_t *dummy_tcb = (dummy_tcb_t *) tcb; const XtExcFrame *frame = (XtExcFrame *) dummy_tcb->top_of_stack; if (frame->exit != 0) { esp_gdbstub_tcb_frame_to_regfile(dummy_tcb, dst); }{...} else { const XtSolFrame *taskFrame = (const XtSolFrame *) dummy_tcb->top_of_stack; solicited_frame_to_regfile(taskFrame, dst); }{...} }{ ... } /* ... */#endif // CONFIG_ESP_GDBSTUB_SUPPORT_TASKS int esp_gdbstub_get_signal(const esp_gdbstub_frame_t *frame) { const char exccause_to_signal[] = {4, 31, 11, 11, 2, 6, 8, 0, 6, 7, 0, 0, 7, 7, 7, 7}; if (frame->exccause >= sizeof(exccause_to_signal)) { return 11; }{...} return (int) exccause_to_signal[frame->exccause]; }{ ... } /** @brief Init dport for GDB * Init dport for iterprocessor communications * *//* ... */ void esp_gdbstub_init_dports(void) { }{ ... } #if CONFIG_IDF_TARGET_ARCH_XTENSA && (!CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) && CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME static bool stall_started = false; #endif /** @brief GDB stall other CPU * GDB stall other CPU * *//* ... */ void esp_gdbstub_stall_other_cpus_start(void) { #if CONFIG_IDF_TARGET_ARCH_XTENSA && (!CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) && CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME if (stall_started == false) { esp_ipc_isr_stall_other_cpu(); stall_started = true; }{...} #endif/* ... */ }{ ... } /** @brief GDB end stall other CPU * GDB end stall other CPU * *//* ... */ void esp_gdbstub_stall_other_cpus_end(void) { #if CONFIG_IDF_TARGET_ARCH_XTENSA && (!CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) && CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME if (stall_started == true) { esp_ipc_isr_release_other_cpu(); stall_started = false; }{...} #endif/* ... */ }{ ... } /** @brief GDB clear step * GDB clear step registers * *//* ... */ void esp_gdbstub_clear_step(void) { WSR(ICOUNT, 0); WSR(ICOUNTLEVEL, 0); }{ ... } /** @brief GDB do step * GDB do one step * *//* ... */ void esp_gdbstub_do_step( esp_gdbstub_frame_t *frame) { // We have gdbstub uart interrupt, and if we will call step, with ICOUNTLEVEL=2 or higher, from uart interrupt, the // application will hang because it will try to step uart interrupt. That's why we have to set ICOUNTLEVEL=1 // If we will stop by the breakpoint inside interrupt, we will handle this interrupt with ICOUNTLEVEL=ps.intlevel+1 uint32_t level = s_scratch.regfile.ps; level &= 0x7; level += 1; WSR(ICOUNTLEVEL, level); WSR(ICOUNT, -2); }{ ... } /** @brief GDB trigger other CPU * GDB trigger other CPU * *//* ... */ void esp_gdbstub_trigger_cpu(void) { #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE if (0 == esp_cpu_get_core_id()) { esp_crosscore_int_send_gdb_call(1); }{...} else { esp_crosscore_int_send_gdb_call(0); }{...} #endif/* ... */ }{ ... } /** @brief GDB set register in frame * Set register in frame with address to value * * *//* ... */ void esp_gdbstub_set_register(esp_gdbstub_frame_t *frame, uint32_t reg_index, uint32_t value) { uint32_t temp_fpu_value = value; float *ptr0; asm volatile ("mov %0, %1" : "=a" (ptr0) : "a" (&temp_fpu_value)); if (reg_index == 0) { frame->pc = value; }{...} else if (reg_index > 0 && (reg_index <= 27)) { (&frame->a0)[reg_index - 1] = value; }{...} #if XCHAL_HAVE_FP void *ptr1; uint32_t cp_enabled; RSR(CPENABLE, cp_enabled); if (cp_enabled != 0) { if (reg_index == 87) { asm volatile ("lsi f0, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 88) { asm volatile ("lsi f1, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 89) { asm volatile ("lsi f2, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 90) { asm volatile ("lsi f3, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 91) { asm volatile ("lsi f4, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 92) { asm volatile ("lsi f5, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 93) { asm volatile ("lsi f6, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 94) { asm volatile ("lsi f7, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 95) { asm volatile ("lsi f8, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 96) { asm volatile ("lsi f9, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 97) { asm volatile ("lsi f10, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 98) { asm volatile ("lsi f11, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 99) { asm volatile ("lsi f12, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 100) { asm volatile ("lsi f13, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 101) { asm volatile ("lsi f14, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 102) { asm volatile ("lsi f15, %0, 0" :: "a" (ptr0)); }{...} if (reg_index == 103) { asm volatile ("l32i %0, %1, 0" : "=a" (ptr1) : "a" (ptr0)); asm volatile ("wur.FCR %0" : "=a" (ptr1)); }{...} if (reg_index == 104) { asm volatile ("l32i %0, %1, 0" : "=a" (ptr1) : "a" (ptr0)); asm volatile ("wur.FSR %0" : "=a" (ptr1)); }{...} }{...} /* ... */#endif // XCHAL_HAVE_FP }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.