OpenOCD
ecos.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  ***************************************************************************/
5 
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9 
10 #include <helper/time_support.h>
11 #include <jtag/jtag.h>
12 #include "target/target.h"
13 #include "target/armv7m.h"
14 #include "rtos.h"
15 #include "helper/log.h"
16 #include "helper/types.h"
17 #include "helper/bits.h"
19 #include "rtos_ecos_stackings.h"
20 #include "server/gdb_server.h"
21 
22 /* Unfortunately for the moment we are limited to returning the hardwired
23  * register count (ARMV7M_NUM_CORE_REGS for Cortex-M) since the openocd RTOS
24  * support does not yet support accessing all per-thread "stacked"
25  * registers. e.g. For Cortex-M under eCos we have a per-thread BASEPRI, and for
26  * all eCos targets we may have per-thread VFP/FPU register state.
27  *
28  * So, for the moment, we continue to use the hardwired limit for the depth of
29  * the returned register description vector. The current openocd
30  * rtos_standard_stackings.c just provides the main core regs for the Cortex_M*
31  * targets regardless of whether FPU is present/enabled.
32  *
33  * However, this code is written with the expectation that we may eventually be
34  * able to provide more register information ("m-system" and "vfp" for example)
35  * and also with the expectation of supporting different register sets being
36  * returned depending on the per-thread Cortex-M eCos contex_m for
37  * example. Hence the fact that the eCos_stack_layout_*() functions below allow
38  * for the stack context descriptor vector to be returned by those calls
39  * allowing for eventual support where this code will potentially cache
40  * different sets of register descriptors for the different shapes of contexts
41  * in a *single* application/binary run-time.
42  *
43  * TODO: Extend openocd generic RTOS support to allow thread-specific system and
44  * FPU register state to be returned. */
45 
46 struct ecos_params;
47 
48 static bool ecos_detect_rtos(struct target *target);
49 static int ecos_create(struct target *target);
50 static int ecos_update_threads(struct rtos *rtos);
51 static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs);
52 static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]);
53 static int ecos_stack_layout_cortexm(struct rtos *rtos, struct ecos_params *param,
54  int64_t stack_ptr, const struct rtos_register_stacking **si);
55 static int ecos_stack_layout_arm(struct rtos *rtos, struct ecos_params *param,
56  int64_t stack_ptr, const struct rtos_register_stacking **si);
57 
58 /* The current eCos thread IDentifier uses 0 as an unused (not a valid thread
59  * ID) value. Currently the unique_id field is 16-bits, but the eCos SMP support
60  * convention is that only 12-bits of the ID will be used. This
61  * ECOS_MAX_THREAD_COUNT manifest is provided to limit the potential for
62  * interpreting stale/inconsistent thread list state when the debug host scans
63  * the thread list before the target RTOS has completed its initialisation. This
64  * support will need to revisited when eCos is re-engineered to support more
65  * than 16 CPU SMP setups. */
66 #define ECOS_MAX_THREAD_COUNT (4095)
67 
69  int value;
70  const char *desc;
71 };
72 
73 /* The status is actually a logical-OR bitmask of states: */
75  RUNNING = 0, /* explicit no-bits-set value */
76  SLEEPING = BIT(0),
78  SUSPENDED = BIT(2),
79  CREATING = BIT(3),
80  EXITED = BIT(4),
82 };
83 
84 /* Cyg_Thread:: reason codes for wake and sleep fields: */
85 static const struct ecos_thread_state ecos_thread_reasons[] = {
86  { 0, "NONE" }, /* normally indicates "not yet started" */
87  { 1, "WAIT" }, /* wait with no timeout */
88  { 2, "DELAY" }, /* simple time delay */
89  { 3, "TIMEOUT" }, /* wait with timeout *or* timeout expired */
90  { 4, "BREAK" }, /* forced break out of sleep */
91  { 5, "DESTRUCT" }, /* wait on object being destroyed */
92  { 6, "EXIT" }, /* forced termination */
93  { 7, "DONE" } /* wait/delay completed */
94 };
95 
96 static const char * const target_cortex_m[] = {
97  "cortex_m",
98  "hla_target",
99  NULL
100 };
101 
102 static const char * const target_arm[] = {
103  "cortex_a",
104  "arm7tdmi",
105  "arm720t",
106  "arm9tdmi",
107  "arm920t",
108  "arm926ejs",
109  "arm946e",
110  "arm966e",
111  "arm11",
112  NULL
113 };
114 
115 /* Since individual eCos application configurations may have different thread
116  * object structure layouts depending on the actual build-time enabled features
117  * we provide support for applications built containing the relevant symbolic
118  * support to match the actual application binary being debugged, rather than
119  * relying on a set of default/fixed (and potentially incorrect)
120  * offsets. However, for backwards compatibility, we do *NOT* enforce the
121  * requirement for the common extra helper symbols to be present to allow the
122  * fallback to the simple fixed CM3 model to avoid affecting existing users of
123  * older eCos worlds. Similarly we need to provide support for per-thread
124  * register context offsets, as well as for per-application-configurations,
125  * since some targets can have different stacked state on a per-thread basis
126  * (e.g. "cortex_m"). This is why the stacking_info is now set at run-time
127  * rather than being fixed. */
128 
129 struct ecos_params {
130  const char * const *target_names; /* NULL terminated list of targets */
131  int (*target_stack_layout)(struct rtos *rtos, struct ecos_params *param,
132  int64_t stack_ptr, const struct rtos_register_stacking **si);
134  unsigned char pointer_width;
135  unsigned char uid_width;
136  unsigned char state_width;
137  unsigned int thread_stack_offset;
138  unsigned int thread_name_offset;
139  unsigned int thread_state_offset;
140  unsigned int thread_next_offset;
143 };
144 
145 /* As mentioned above we provide default offset values for the "cortex_m"
146  * targets for backwards compatibility with older eCos application builds and
147  * previous users of this RTOS specific support that do not have the
148  * configuration specific offsets provided in the symbol table. The support for
149  * other targets (e.g. "cortex_a") we do expect the application to provide the
150  * required symbolic information. We do not populate the stacking_info reference
151  * until we have had a chance to interrogate the symbol table. */
152 
153 static struct ecos_params ecos_params_list[] = {
154  {
156  .pointer_width = 4,
157  .uid_width = 2,
158  .state_width = 4,
159  .thread_stack_offset = 0x0c,
160  .thread_name_offset = 0x9c,
161  .thread_state_offset = 0x3c,
162  .thread_next_offset = 0xa0,
163  .thread_uniqueid_offset = 0x4c,
164  .target_stack_layout = ecos_stack_layout_cortexm,
165  .stacking_info = NULL
166  },
167  {
168  .target_names = target_arm,
169  .pointer_width = 0,
170  .uid_width = 0,
171  .state_width = 0,
172  .thread_stack_offset = 0,
173  .thread_name_offset = 0,
174  .thread_state_offset = 0,
175  .thread_next_offset = 0,
176  .thread_uniqueid_offset = 0,
177  .target_stack_layout = ecos_stack_layout_arm,
178  .stacking_info = NULL
179  }
180 };
181 
182 #define ECOS_NUM_PARAMS ARRAY_SIZE(ecos_params_list)
183 
184 /* To eventually allow for more than just the ARMV7M_NUM_CORE_REGS to be
185  * returned by the Cortex-M support, and to avoid run-time lookups we manually
186  * maintain our own mapping for the supplied stack register vector entries. This
187  * enum needs to match the rtos_ecos_regoff_cortexm[] vector. Admittedly the
188  * initial indices just match the corresponding ARMV7M_R* definitions, but after
189  * the base registers the ARMV7M_* number space does not match the vector we
190  * wish to populate in this eCos support code. */
208  ECOS_REGLIST_XPSR, /* ARMV7M_NUM_CORE_REGS */
210  ECOS_REGLIST_FPSCR, /* Following for FPU contexts */
227 };
228 
229 #define ECOS_CORTEXM_BASE_NUMREGS (ARMV7M_NUM_CORE_REGS)
230 
231 /* NOTE: The offsets in this vector are overwritten by the architecture specific
232  * layout functions depending on the specific application configuration. The
233  * ordering of this vector MUST match eCos_reglist. */
235  { ARMV7M_R0, -1, 32 }, /* r0 */
236  { ARMV7M_R1, -1, 32 }, /* r1 */
237  { ARMV7M_R2, -1, 32 }, /* r2 */
238  { ARMV7M_R3, -1, 32 }, /* r3 */
239  { ARMV7M_R4, -1, 32 }, /* r4 */
240  { ARMV7M_R5, -1, 32 }, /* r5 */
241  { ARMV7M_R6, -1, 32 }, /* r6 */
242  { ARMV7M_R7, -1, 32 }, /* r7 */
243  { ARMV7M_R8, -1, 32 }, /* r8 */
244  { ARMV7M_R9, -1, 32 }, /* r9 */
245  { ARMV7M_R10, -1, 32 }, /* r10 */
246  { ARMV7M_R11, -1, 32 }, /* r11 */
247  { ARMV7M_R12, -1, 32 }, /* r12 */
248  { ARMV7M_R13, -1, 32 }, /* sp */
249  { ARMV7M_R14, -1, 32 }, /* lr */
250  { ARMV7M_PC, -1, 32 }, /* pc */
251  { ARMV7M_XPSR, -1, 32 }, /* xPSR */
252  { ARMV7M_BASEPRI, -1, 32 }, /* BASEPRI */
253  { ARMV7M_FPSCR, -1, 32 }, /* FPSCR */
254  { ARMV7M_D0, -1, 64 }, /* D0 (S0/S1) */
255  { ARMV7M_D1, -1, 64 }, /* D1 (S2/S3) */
256  { ARMV7M_D2, -1, 64 }, /* D2 (S4/S5) */
257  { ARMV7M_D3, -1, 64 }, /* D3 (S6/S7) */
258  { ARMV7M_D4, -1, 64 }, /* D4 (S8/S9) */
259  { ARMV7M_D5, -1, 64 }, /* D5 (S10/S11) */
260  { ARMV7M_D6, -1, 64 }, /* D6 (S12/S13) */
261  { ARMV7M_D7, -1, 64 }, /* D7 (S14/S15) */
262  { ARMV7M_D8, -1, 64 }, /* D8 (S16/S17) */
263  { ARMV7M_D9, -1, 64 }, /* D9 (S18/S19) */
264  { ARMV7M_D10, -1, 64 }, /* D10 (S20/S21) */
265  { ARMV7M_D11, -1, 64 }, /* D11 (S22/S23) */
266  { ARMV7M_D12, -1, 64 }, /* D12 (S24/S25) */
267  { ARMV7M_D13, -1, 64 }, /* D13 (S26/S27) */
268  { ARMV7M_D14, -1, 64 }, /* D14 (S28/S29) */
269  { ARMV7M_D15, -1, 64 }, /* D15 (S30/S31) */
270 };
271 
273  { 0, -1, 32 }, /* r0 */
274  { 1, -1, 32 }, /* r1 */
275  { 2, -1, 32 }, /* r2 */
276  { 3, -1, 32 }, /* r3 */
277  { 4, -1, 32 }, /* r4 */
278  { 5, -1, 32 }, /* r5 */
279  { 6, -1, 32 }, /* r6 */
280  { 7, -1, 32 }, /* r7 */
281  { 8, -1, 32 }, /* r8 */
282  { 9, -1, 32 }, /* r9 */
283  { 10, -1, 32 }, /* r10 */
284  { 11, -1, 32 }, /* r11 (fp) */
285  { 12, -1, 32 }, /* r12 (ip) */
286  { 13, -1, 32 }, /* sp (r13) */
287  { 14, -1, 32 }, /* lr (r14) */
288  { 15, -1, 32 }, /* pc (r15) */
289  { 16, -1, 32 }, /* xPSR */
290 };
291 
294  .stack_growth_direction = -1,
295  .num_output_registers = 0,
296  .calculate_process_stack = NULL, /* stack_alignment */
297  .register_offsets = NULL
298 };
299 
300 /* To avoid the run-time cost of matching explicit symbol names we push the
301  * lookup offsets to this *manually* maintained enumeration which must match the
302  * ecos_symbol_list[] order below. */
366 };
367 
368 struct symbols {
369  const char *name;
370  const char * const *target_names; /* non-NULL when for a specific architecture */
371  bool optional;
372 };
373 
374 #define ECOSSYM(_n, _o, _t) { .name = _n, .optional = (_o), .target_names = _t }
375 
376 /* Some of offset/size helper symbols are common to all eCos
377  * targets. Unfortunately, for historical reasons, some information is in
378  * architecture specific namespaces leading to some duplication and a larger
379  * vector below. */
380 static const struct symbols ecos_symbol_list[] = {
381  ECOSSYM("Cyg_Thread::thread_list", false, NULL),
382  ECOSSYM("Cyg_Scheduler_Base::current_thread", false, NULL),
383  /* Following symbols *are* required for generic application-specific
384  * configuration support, but we mark as optional for backwards
385  * compatibility with the previous fixed Cortex-M3 only RTOS plugin
386  * implementation. */
387  ECOSSYM("__ecospro_syminfo.off.cyg_thread.list_next", true, NULL),
388  ECOSSYM("__ecospro_syminfo.size.cyg_thread.list_next", true, NULL),
389  ECOSSYM("__ecospro_syminfo.off.cyg_thread.state", true, NULL),
390  ECOSSYM("__ecospro_syminfo.size.cyg_thread.state", true, NULL),
391  ECOSSYM("__ecospro_syminfo.off.cyg_thread.sleep_reason", true, NULL),
392  ECOSSYM("__ecospro_syminfo.size.cyg_thread.sleep_reason", true, NULL),
393  ECOSSYM("__ecospro_syminfo.off.cyg_thread.wake_reason", true, NULL),
394  ECOSSYM("__ecospro_syminfo.size.cyg_thread.wake_reason", true, NULL),
395  ECOSSYM("__ecospro_syminfo.off.cyg_thread.unique_id", true, NULL),
396  ECOSSYM("__ecospro_syminfo.size.cyg_thread.unique_id", true, NULL),
397  ECOSSYM("__ecospro_syminfo.off.cyg_thread.name", true, NULL),
398  ECOSSYM("__ecospro_syminfo.size.cyg_thread.name", true, NULL),
399  ECOSSYM("__ecospro_syminfo.off.cyg_thread.priority", true, NULL),
400  ECOSSYM("__ecospro_syminfo.size.cyg_thread.priority", true, NULL),
401  ECOSSYM("__ecospro_syminfo.off.cyg_thread.stack_ptr", true, NULL),
402  ECOSSYM("__ecospro_syminfo.size.cyg_thread.stack_ptr", true, NULL),
403  /* optional Cortex-M: */
404  ECOSSYM("__ecospro_syminfo.cortexm.thread.saved", true, target_cortex_m),
405  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.Thread", true, target_cortex_m),
406  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.type", true, target_cortex_m),
407  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.type", true, target_cortex_m),
408  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.basepri", true, target_cortex_m),
409  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.basepri", true, target_cortex_m),
410  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.sp", true, target_cortex_m),
411  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.sp", true, target_cortex_m),
412  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.r", true, target_cortex_m),
413  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.r", true, target_cortex_m),
414  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.pc", true, target_cortex_m),
415  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.pc", true, target_cortex_m),
416  ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.EXCEPTION", true, target_cortex_m),
417  ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.THREAD", true, target_cortex_m),
418  ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.INTERRUPT", true, target_cortex_m),
419  /* optional Cortex-M with H/W FPU configured: */
420  ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.WITH_FPU", true, target_cortex_m),
421  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.fpscr", true, target_cortex_m),
422  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.fpscr", true, target_cortex_m),
423  ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.s", true, target_cortex_m),
424  ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.s", true, target_cortex_m),
425  /* optional ARM: */
426  ECOSSYM("ARMREG_SIZE", true, target_arm),
427  ECOSSYM("armreg_r0", true, target_arm),
428  ECOSSYM("armreg_r1", true, target_arm),
429  ECOSSYM("armreg_r2", true, target_arm),
430  ECOSSYM("armreg_r3", true, target_arm),
431  ECOSSYM("armreg_r4", true, target_arm),
432  ECOSSYM("armreg_r5", true, target_arm),
433  ECOSSYM("armreg_r6", true, target_arm),
434  ECOSSYM("armreg_r7", true, target_arm),
435  ECOSSYM("armreg_r8", true, target_arm),
436  ECOSSYM("armreg_r9", true, target_arm),
437  ECOSSYM("armreg_r10", true, target_arm),
438  ECOSSYM("armreg_fp", true, target_arm),
439  ECOSSYM("armreg_ip", true, target_arm),
440  ECOSSYM("armreg_sp", true, target_arm),
441  ECOSSYM("armreg_lr", true, target_arm),
442  ECOSSYM("armreg_pc", true, target_arm),
443  ECOSSYM("armreg_cpsr", true, target_arm),
444  /* optional ARM FPU common: */
445  ECOSSYM("ARMREG_FPUCONTEXT_SIZE", true, target_arm),
446  ECOSSYM("armreg_fpscr", true, target_arm),
447  /* optional ARM FPU single-precision: */
448  ECOSSYM("ARMREG_S_COUNT", true, target_arm),
449  ECOSSYM("armreg_s_vec", true, target_arm),
450  /* optional ARM FPU double-precision: */
451  ECOSSYM("ARMREG_VFP_COUNT", true, target_arm),
452  ECOSSYM("armreg_vfp_vec", true, target_arm),
453 };
454 
455 const struct rtos_type ecos_rtos = {
456  .name = "eCos",
457 
458  .detect_rtos = ecos_detect_rtos,
459  .create = ecos_create,
460  .update_threads = ecos_update_threads,
461  .get_thread_reg_list = ecos_get_thread_reg_list,
462  .get_symbol_list_to_lookup = ecos_get_symbol_list_to_lookup,
463 
464 };
465 
466 static symbol_address_t ecos_value(struct rtos *rtos, unsigned int idx)
467 {
468  if (idx < ARRAY_SIZE(ecos_symbol_list))
469  return rtos->symbols[idx].address;
470 
471  /* We do not terminate, just return 0 in this case. */
472  LOG_ERROR("eCos: Invalid symbol index %u", idx);
473  return 0;
474 }
475 
476 #define XMLENTRY(_c, _s) { .xc = (_c), .rs = (_s), .rlen = (sizeof(_s) - 1) }
477 
478 static const struct {
479  char xc;
480  const char *rs;
481  size_t rlen;
482 } xmlchars[] = {
483  XMLENTRY('<', "&lt;"),
484  XMLENTRY('&', "&amp;"),
485  XMLENTRY('>', "&gt;"),
486  XMLENTRY('\'', "&apos;"),
487  XMLENTRY('"', "&quot;")
488 };
489 
491 static bool ecos_escape_string(const char *raw, char *out, size_t limit)
492 {
493  static const char *tokens = "<&>\'\"";
494  bool escaped = false;
495 
496  if (!out || !limit)
497  return false;
498 
499  (void)memset(out, '\0', limit);
500 
501  while (raw && *raw && limit) {
502  size_t lok = strcspn(raw, tokens);
503  if (lok) {
504  size_t tocopy;
505  tocopy = ((limit < lok) ? limit : lok);
506  (void)memcpy(out, raw, tocopy);
507  limit -= tocopy;
508  out += tocopy;
509  raw += lok;
510  continue;
511  }
512 
513  char *fidx = strchr(tokens, *raw);
514  if (!fidx) {
515  /* Should never happen assuming xmlchars
516  * vector and tokens string match. */
517  LOG_ERROR("eCos: Unexpected XML char %c", *raw);
518  continue;
519  }
520 
521  uint32_t cidx = (fidx - tokens);
522  size_t tocopy = xmlchars[cidx].rlen;
523  if (limit < tocopy)
524  break;
525 
526  escaped = true;
527  (void)memcpy(out, xmlchars[cidx].rs, tocopy);
528  limit -= tocopy;
529  out += tocopy;
530  raw++;
531  }
532 
533  return escaped;
534 }
535 
536 static int ecos_check_app_info(struct rtos *rtos, struct ecos_params *param)
537 {
538  if (!rtos || !param)
539  return -1;
540 
541  if (param->flush_common) {
543  for (unsigned int idx = 0; idx < ARRAY_SIZE(ecos_symbol_list); idx++) {
544  LOG_DEBUG("eCos: %s 0x%016" PRIX64 " %s",
545  rtos->symbols[idx].optional ? "OPTIONAL" : " ",
546  rtos->symbols[idx].address, rtos->symbols[idx].symbol_name);
547  }
548  }
549 
550  /* If "__ecospro_syminfo.size.cyg_thread.list_next" is non-zero then we
551  * expect all of the generic thread structure symbols to have been
552  * provided. */
554  if (thread_next_size != 0) {
555  param->pointer_width = thread_next_size;
563  }
564 
565  if (param->uid_width != sizeof(uint16_t)) {
566  /* Currently all eCos configurations use a 16-bit field to hold the
567  * unique thread ID. */
568  LOG_WARNING("eCos: Unexpected unique_id width %" PRIu8, param->uid_width);
569  param->uid_width = (unsigned char)sizeof(uint16_t);
570  }
571 
572  param->stacking_info = NULL;
573  param->flush_common = false;
574  }
575 
576  return ERROR_OK;
577 }
578 
579 /* The Cortex-M eCosPro "thread" contexts have a "type" indicator, which tracks
580  * the context state of (THREAD | EXCEPTION | INTERRUPT) and whether FPU
581  * registers are saved.
582  *
583  * For thread-aware debugging from GDB we are only interested in THREAD states
584  * and so do not need to implement support for INTERRUPT or EXCEPTION thread
585  * contexts since this code does not expose those stack contexts via the
586  * constructed thread list support. */
588  struct ecos_params *param, int64_t stack_ptr,
589  const struct rtos_register_stacking **si)
590 {
591  int retval = ERROR_OK;
592 
593  /* CONSIDER: We could return
594  * ecos_value(rtos, ECOS_VAL_CORTEXM_THREAD_SAVED) as the actual PC
595  * address of a context switch, with the LR being set to the context PC
596  * field to give a true representation of where the thread switch
597  * occurs. However that would require extending the common
598  * rtos_generic_stack_read() code with suitable support for applying a
599  * supplied value, or just implementing our own version of that code that
600  * can inject data into what is passed onwards to GDB. */
601 
602  /* UPDATE: When we can return VFP register state then we will NOT be
603  * basing the cached state on the single param->stacking_info value,
604  * since we will need a different stacking_info structure returned for
605  * each thread type when FPU support is enabled. The use of the single
606  * param->stacking_info is a holder whilst we are limited to the fixed
607  * ARMV7M_NUM_CORE_REGS set of descriptors. */
608 
609  if (!param->stacking_info &&
612  unsigned char numoutreg = ECOS_CORTEXM_BASE_NUMREGS;
613 
617 
631  /* Rather than using the stacked ECOS_VAL_CORTEXM_CTX_SP_OFF
632  * value we force the reported sp to be after the stacked
633  * register context. */
638 
640 
641  /* Common Cortex-M thread register offsets for the current
642  * symbol table: */
643  if (retval == ERROR_OK && param->stacking_info) {
644  if (numoutreg > ECOS_REGLIST_BASEPRI) {
647  }
648 
650  }
651  }
652 
653  if (si)
654  *si = param->stacking_info;
655 
656  return retval;
657 }
658 
659 static int ecos_stack_layout_arm(struct rtos *rtos, struct ecos_params *param,
660  int64_t stack_ptr, const struct rtos_register_stacking **si)
661 {
663  /* When OpenOCD is extended to allow FPU registers to be returned from a
664  * stacked thread context we can check:
665  * if (0 != ecos_value(rtos, ECOS_VAL_ARM_FPUSIZE)) { FPU }
666  * for presence of FPU registers in the context. */
667 
671 
689 
691  }
692 
693  if (si)
694  *si = param->stacking_info;
695 
696  return ERROR_OK;
697 }
698 
699 /* We see this function called on a new connection, it looks like before and
700  * after the "tar rem"/"tar extended-remote". It might be the only point we can
701  * decide to cache information (to check if the symbol table has changed). */
702 static int ecos_update_threads(struct rtos *rtos)
703 {
704  int retval;
705  int tasks_found = 0;
706  int thread_list_size = 0;
707  struct ecos_params *param;
708 
709  if (!rtos)
710  return -1;
711 
712  /* wipe out previous thread details if any */
714 
716  return -3;
717 
718  param = rtos->rtos_specific_params;
719 
720  if (!rtos->symbols) {
721  /* NOTE: We only see this when connecting from GDB the first
722  * time before the application image is loaded. So it is not a
723  * hook for detecting an application change. */
724  param->flush_common = true;
725  LOG_ERROR("No symbols for eCos");
726  return -4;
727  }
728 
729  retval = ecos_check_app_info(rtos, param);
730  if (retval != ERROR_OK)
731  return retval;
732 
734  LOG_ERROR("Don't have the thread list head");
735  return -2;
736  }
737 
738  /* determine the number of current threads */
739  uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
740  uint32_t thread_index;
742  thread_list_head,
743  param->pointer_width,
744  (uint8_t *) &thread_index);
745  uint32_t first_thread = thread_index;
746 
747  /* Even if 0==first_thread indicates a system with no defined eCos
748  * threads, instead of early exiting here we fall through the code to
749  * allow the creation of a faked "Current Execution" descriptor as
750  * needed. */
751 
752  if (first_thread) {
753  /* Since the OpenOCD RTOS support can attempt to obtain thread
754  * information on initial connection when the system *may* have
755  * undefined memory state it is possible for a simple thread count scan
756  * to produce invalid results. To avoid blocking indefinitely when
757  * encountering an invalid closed loop we limit the number of threads to
758  * the maximum possible, and if we pass that limit then something is
759  * wrong so treat the system as having no threads defined. */
760  do {
761  thread_list_size++;
762  if (thread_list_size > ECOS_MAX_THREAD_COUNT) {
763  /* Treat as "no threads" case: */
764  first_thread = 0;
765  thread_list_size = 0;
766  break;
767  }
768  retval = target_read_buffer(rtos->target,
769  thread_index + param->thread_next_offset,
770  param->pointer_width,
771  (uint8_t *)&thread_index);
772  if (retval != ERROR_OK)
773  return retval;
774  } while (thread_index != first_thread);
775  }
776 
777  /* read the current thread id */
778  rtos->current_thread = 0;
779 
780  uint32_t current_thread_addr;
781  retval = target_read_buffer(rtos->target,
783  param->pointer_width,
784  (uint8_t *)&current_thread_addr);
785  if (retval != ERROR_OK) {
786  LOG_ERROR("Reading active thread address");
787  return retval;
788  }
789 
790  if (current_thread_addr) {
791  uint16_t id = 0;
792  retval = target_read_buffer(rtos->target,
793  current_thread_addr + param->thread_uniqueid_offset,
794  param->uid_width,
795  (uint8_t *)&id);
796  if (retval != ERROR_OK) {
797  LOG_ERROR("Could not read eCos current thread from target");
798  return retval;
799  }
801  }
802 
803  if (thread_list_size == 0 || rtos->current_thread == 0) {
804  /* Either : No RTOS threads - there is always at least the current execution though */
805  /* OR : No current thread - all threads suspended - show the current execution
806  * of idling */
807  static const char tmp_str[] = "Current Execution";
808  thread_list_size++;
809  tasks_found++;
810  rtos->thread_details = malloc(
811  sizeof(struct thread_detail) * thread_list_size);
812  /* 1 is a valid eCos thread id, so we return 0 for this faked
813  * "current" CPU state: */
815  rtos->thread_details->exists = true;
817  rtos->thread_details->thread_name_str = malloc(sizeof(tmp_str));
818  strcpy(rtos->thread_details->thread_name_str, tmp_str);
819 
820  /* Early exit if current CPU state our only "thread": */
821  if (thread_list_size == 1) {
822  rtos->thread_count = 1;
823  return ERROR_OK;
824  }
825  } else {
826  /* create space for new thread details */
827  rtos->thread_details = malloc(
828  sizeof(struct thread_detail) * thread_list_size);
829  }
830 
831  /* loop over all threads */
832  thread_index = first_thread;
833  do {
834  #define ECOS_THREAD_NAME_STR_SIZE (200)
835  char tmp_str[ECOS_THREAD_NAME_STR_SIZE];
836  uint32_t name_ptr = 0;
837  uint32_t prev_thread_ptr;
838 
839  /* Save the thread ID. For eCos the thread has a unique ID distinct from
840  * the thread_index descriptor pointer. We present this scheduler ID
841  * instead of the descriptor memory address. */
842  uint16_t thread_id = 0;
843  retval = target_read_buffer(rtos->target,
844  thread_index + param->thread_uniqueid_offset,
845  param->uid_width,
846  (uint8_t *)&thread_id);
847  if (retval != ERROR_OK) {
848  LOG_ERROR("Could not read eCos thread id from target");
849  return retval;
850  }
851  rtos->thread_details[tasks_found].threadid = thread_id;
852 
853  /* Read the name pointer */
854  retval = target_read_buffer(rtos->target,
855  thread_index + param->thread_name_offset,
856  param->pointer_width,
857  (uint8_t *)&name_ptr);
858  if (retval != ERROR_OK) {
859  LOG_ERROR("Could not read eCos thread name pointer from target");
860  return retval;
861  }
862 
863  /* Read the thread name */
864  retval =
866  name_ptr,
868  (uint8_t *)&tmp_str);
869  if (retval != ERROR_OK) {
870  LOG_ERROR("Error reading thread name from eCos target");
871  return retval;
872  }
873  tmp_str[ECOS_THREAD_NAME_STR_SIZE-1] = '\x00';
874 
875  /* Since eCos can have arbitrary C string names we can sometimes
876  * get an internal warning from GDB about "not well-formed
877  * (invalid token)" since the XML post-processing done by GDB on
878  * the OpenOCD returned response containing the thread strings
879  * is not escaped. For example the eCos kernel testsuite
880  * application tm_basic uses the thread name "<<NULL>>" which
881  * will trigger this failure unless escaped. */
882  if (tmp_str[0] == '\x00') {
883  snprintf(tmp_str, ECOS_THREAD_NAME_STR_SIZE, "NoName:[0x%08" PRIX32 "]", thread_index);
884  } else {
885  /* The following is a workaround to avoid any issues
886  * from arbitrary eCos thread names causing GDB/OpenOCD
887  * issues. We limit the escaped thread name passed to
888  * GDB to the same length as the un-escaped just to
889  * avoid overly long strings. */
890  char esc_str[ECOS_THREAD_NAME_STR_SIZE];
891  bool escaped = ecos_escape_string(tmp_str, esc_str, sizeof(esc_str));
892  if (escaped)
893  strcpy(tmp_str, esc_str);
894  }
895 
896  rtos->thread_details[tasks_found].thread_name_str =
897  malloc(strlen(tmp_str)+1);
898  strcpy(rtos->thread_details[tasks_found].thread_name_str, tmp_str);
899 
900  /* Read the thread status */
901  int64_t thread_status = 0;
902  retval = target_read_buffer(rtos->target,
903  thread_index + param->thread_state_offset,
904  param->state_width,
905  (uint8_t *)&thread_status);
906  if (retval != ERROR_OK) {
907  LOG_ERROR("Error reading thread state from eCos target");
908  return retval;
909  }
910 
911  /* The thread_status is a BITMASK */
912  char state_desc[21]; /* Enough for "suspended+countsleep\0" maximum */
913 
914  if (thread_status & SUSPENDED)
915  strcpy(state_desc, "suspended+");
916  else
917  state_desc[0] = '\0';
918 
919  switch (thread_status & ~SUSPENDED) {
920  case RUNNING:
921  if (thread_index == current_thread_addr)
922  strcat(state_desc, "running");
923  else if (thread_status & SUSPENDED)
924  state_desc[9] = '\0'; /* Drop '+' from "suspended+" */
925  else
926  strcat(state_desc, "ready");
927  break;
928  case SLEEPING:
929  strcat(state_desc, "sleeping");
930  break;
931  case SLEEPSET:
932  case COUNTSLEEP:
933  strcat(state_desc, "counted sleep");
934  break;
935  case CREATING:
936  strcpy(state_desc, "creating");
937  break;
938  case EXITED:
939  strcpy(state_desc, "exited");
940  break;
941  default:
942  strcpy(state_desc, "unknown state");
943  break;
944  }
945 
946  /* For the moment we do not bother decoding the wake reason for the
947  * active "running" thread, but it is useful providing the sleep reason
948  * for stacked threads. */
949  int64_t sleep_reason = 0; /* sleep reason */
950 
951  if (thread_index != current_thread_addr &&
953  retval = target_read_buffer(rtos->target,
956  (uint8_t *)&sleep_reason);
957  if (retval != ERROR_OK) {
958  LOG_ERROR("Error reading thread sleep reason from eCos target");
959  return retval;
960  }
961  if (sleep_reason < 0 ||
962  sleep_reason > (int64_t)ARRAY_SIZE(ecos_thread_reasons)) {
963  sleep_reason = 0;
964  }
965  }
966 
967  /* We do not display anything for the Cyg_Thread::NONE reason */
968  size_t tr_extra = 0;
969  const char *reason_desc = NULL;
970  if (sleep_reason)
971  reason_desc = ecos_thread_reasons[sleep_reason].desc;
972  if (reason_desc)
973  tr_extra = 2 + strlen(reason_desc) + 1;
974 
975  /* Display thread priority if available: */
976  int64_t priority = 0;
977  size_t pri_extra = 0;
979  retval = target_read_buffer(rtos->target,
982  (uint8_t *)&priority);
983  if (retval != ERROR_OK) {
984  LOG_ERROR("Error reading thread priority from eCos target");
985  return retval;
986  }
987  pri_extra = (12 + 20); /* worst-case ", Priority: " */
988  }
989 
990  size_t eilen = (8 + strlen(state_desc) + tr_extra + pri_extra);
991  char *eistr = malloc(eilen);
992  /* We do not need to treat a malloc failure as a fatal error here since
993  * the code below will just not report extra thread information if NULL,
994  * thus allowing all of the threads to be enumerated even with reduced
995  * information when the host is low on memory. However... */
996  if (!eistr) {
997  LOG_ERROR("OOM allocating extra information buffer");
998  return ERROR_FAIL;
999  }
1000 
1001  int soff = snprintf(eistr, eilen, "State: %s", state_desc);
1002  if (tr_extra && reason_desc)
1003  soff += snprintf(&eistr[soff], (eilen - soff), " (%s)", reason_desc);
1004  if (pri_extra)
1005  (void)snprintf(&eistr[soff], (eilen - soff), ", Priority: %" PRId64, priority);
1006  rtos->thread_details[tasks_found].extra_info_str = eistr;
1007 
1008  rtos->thread_details[tasks_found].exists = true;
1009 
1010  tasks_found++;
1011  prev_thread_ptr = thread_index;
1012 
1013  /* Get the location of the next thread structure. */
1014  thread_index = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
1015  retval = target_read_buffer(rtos->target,
1016  prev_thread_ptr + param->thread_next_offset,
1017  param->pointer_width,
1018  (uint8_t *) &thread_index);
1019  if (retval != ERROR_OK) {
1020  LOG_ERROR("Error reading next thread pointer in eCos thread list");
1021  return retval;
1022  }
1023  } while (thread_index != first_thread);
1024 
1025  rtos->thread_count = tasks_found;
1026  return ERROR_OK;
1027 }
1028 
1029 static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
1030  struct rtos_reg **reg_list, int *num_regs)
1031 {
1032  int retval;
1033  struct ecos_params *param;
1034 
1035  if (!rtos)
1036  return -1;
1037 
1038  if (thread_id == 0)
1039  return -2;
1040 
1041  if (!rtos->rtos_specific_params)
1042  return -3;
1043 
1044  param = rtos->rtos_specific_params;
1045 
1046  retval = ecos_check_app_info(rtos, param);
1047  if (retval != ERROR_OK)
1048  return retval;
1049 
1050  /* We can get memory access errors reported by this function on
1051  * re-connecting to a board with stale thread information in memory. The
1052  * initial ecos_update_threads() is called twice and may read
1053  * stale/invalid information depending on the memory state. This happens
1054  * as part of the "target remote" connection so cannot be avoided by GDB
1055  * scripting. It is not critical and allowing the application to run and
1056  * initialise its BSS etc. will allow correct thread and register
1057  * information to be obtained. This really only affects debug sessions
1058  * where "info thr" is used before the initial run-time initialisation
1059  * has occurred. */
1060 
1061  /* Find the thread with that thread id */
1062  uint16_t id = 0;
1063  uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
1064  uint32_t thread_index;
1065  target_read_buffer(rtos->target, thread_list_head, param->pointer_width,
1066  (uint8_t *)&thread_index);
1067  bool done = false;
1068  while (!done) {
1069  retval = target_read_buffer(rtos->target,
1070  thread_index + param->thread_uniqueid_offset,
1071  param->uid_width,
1072  (uint8_t *)&id);
1073  if (retval != ERROR_OK) {
1074  LOG_ERROR("Error reading unique id from eCos thread 0x%08" PRIX32, thread_index);
1075  return retval;
1076  }
1077 
1078  if (id == thread_id) {
1079  done = true;
1080  break;
1081  }
1083  thread_index + param->thread_next_offset,
1084  param->pointer_width,
1085  (uint8_t *) &thread_index);
1086  }
1087 
1088  if (done) {
1089  /* Read the stack pointer */
1090  int64_t stack_ptr = 0;
1091  retval = target_read_buffer(rtos->target,
1092  thread_index + param->thread_stack_offset,
1093  param->pointer_width,
1094  (uint8_t *)&stack_ptr);
1095  if (retval != ERROR_OK) {
1096  LOG_ERROR("Error reading stack frame from eCos thread");
1097  return retval;
1098  }
1099 
1100  if (!stack_ptr) {
1101  LOG_ERROR("NULL stack pointer in thread %" PRIu64, thread_id);
1102  return -5;
1103  }
1104 
1105  const struct rtos_register_stacking *stacking_info = NULL;
1106  if (param->target_stack_layout) {
1107  retval = param->target_stack_layout(rtos, param, stack_ptr, &stacking_info);
1108  if (retval != ERROR_OK) {
1109  LOG_ERROR("Error reading stack layout for eCos thread");
1110  return retval;
1111  }
1112  }
1113  if (!stacking_info)
1115 
1117  stacking_info,
1118  stack_ptr,
1119  reg_list,
1120  num_regs);
1121  }
1122 
1123  return -1;
1124 }
1125 
1126 /* NOTE: This is only called once when the first GDB connection is made to
1127  * OpenOCD and not on subsequent connections (when the application symbol table
1128  * may have changed, affecting the offsets of critical fields and the stacked
1129  * context shape). */
1130 static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
1131 {
1132  unsigned int i;
1133  *symbol_list = calloc(
1134  ARRAY_SIZE(ecos_symbol_list), sizeof(struct symbol_table_elem));
1135 
1136  /* If the target reference was passed into this function we could limit
1137  * the symbols we need to lookup to the target_type_name(target) based
1138  * range. For the moment we need to provide a single vector with all of
1139  * the symbols across all of the supported architectures. */
1140  for (i = 0; i < ARRAY_SIZE(ecos_symbol_list); i++) {
1141  (*symbol_list)[i].symbol_name = ecos_symbol_list[i].name;
1142  (*symbol_list)[i].optional = ecos_symbol_list[i].optional;
1143  }
1144 
1145  return 0;
1146 }
1147 
1148 /* NOTE: Only called by rtos.c:rtos_qsymbol() when auto-detecting the RTOS. If
1149  * the target configuration uses the explicit "-rtos" config option then this
1150  * detection routine is NOT called. */
1151 static bool ecos_detect_rtos(struct target *target)
1152 {
1153  if ((target->rtos->symbols) &&
1155  /* looks like eCos */
1156  return true;
1157  }
1158  return false;
1159 }
1160 
1161 /* Since we should never have 0 as a valid eCos thread ID we use $Hg0 as the
1162  * indicator of a new session as regards flushing any cached state. */
1164  const char *packet, int packet_size)
1165 {
1166  int64_t current_threadid;
1167 
1168  if (packet[0] == 'H' && packet[1] == 'g') {
1169  int numscan = sscanf(packet, "Hg%16" SCNx64, &current_threadid);
1170  if (numscan == 1 && current_threadid == 0) {
1173  struct ecos_params *param;
1174  param = target->rtos->rtos_specific_params;
1175  param->flush_common = true;
1176  }
1177  }
1178  }
1179 
1180  return rtos_thread_packet(connection, packet, packet_size);
1181 }
1182 
1183 /* Called at start of day when eCos detected or specified in config file. */
1184 static int ecos_create(struct target *target)
1185 {
1186  for (unsigned int i = 0; i < ARRAY_SIZE(ecos_params_list); i++) {
1187  const char * const *tnames = ecos_params_list[i].target_names;
1188  while (*tnames) {
1189  if (strcmp(*tnames, target_type_name(target)) == 0) {
1190  /* LOG_DEBUG("eCos: matched target \"%s\"", target_type_name(target)); */
1192  ecos_params_list[i].flush_common = true;
1194  target->rtos->current_thread = 0;
1196 
1197  /* We use the $Hg0 packet as a new GDB connection "start-of-day" hook to
1198  * force a re-cache of information. It is possible for a single OpenOCD
1199  * session to be connected to a target with multiple GDB debug sessions
1200  * started/stopped. With eCos it is possible for those GDB sessions to
1201  * present applications with different offsets within a thread
1202  * descriptor for fields used by this module, and for the stacked
1203  * context within the connected target architecture to differ between
1204  * applications and even between threads in a single application. So we
1205  * need to ensure any information we cache is flushed on an application
1206  * change, and GDB referencing an invalid eCos thread ID (0) is a good
1207  * enough point, since we can accept the re-cache hit if that packet
1208  * appears during an established session, whilst benefiting from not
1209  * re-loading information on every update_threads or get_thread_reg_list
1210  * call. */
1212  /* We do not currently use the target->rtos->gdb_target_for_threadid
1213  * hook. */
1214  return ERROR_OK;
1215  }
1216  tnames++;
1217  }
1218  }
1219 
1220  LOG_ERROR("Could not find target in eCos compatibility list");
1221  return ERROR_FAIL;
1222 }
@ ARMV7M_R1
Definition: armv7m.h:112
@ ARMV7M_D14
Definition: armv7m.h:199
@ ARMV7M_D8
Definition: armv7m.h:193
@ ARMV7M_R6
Definition: armv7m.h:118
@ ARMV7M_R2
Definition: armv7m.h:113
@ ARMV7M_D3
Definition: armv7m.h:188
@ ARMV7M_D1
Definition: armv7m.h:186
@ ARMV7M_D4
Definition: armv7m.h:189
@ ARMV7M_BASEPRI
Definition: armv7m.h:149
@ ARMV7M_D2
Definition: armv7m.h:187
@ ARMV7M_R3
Definition: armv7m.h:114
@ ARMV7M_D11
Definition: armv7m.h:196
@ ARMV7M_D9
Definition: armv7m.h:194
@ ARMV7M_R14
Definition: armv7m.h:128
@ ARMV7M_R9
Definition: armv7m.h:122
@ ARMV7M_D7
Definition: armv7m.h:192
@ ARMV7M_R12
Definition: armv7m.h:126
@ ARMV7M_R0
Definition: armv7m.h:111
@ ARMV7M_D13
Definition: armv7m.h:198
@ ARMV7M_R13
Definition: armv7m.h:127
@ ARMV7M_PC
Definition: armv7m.h:129
@ ARMV7M_R7
Definition: armv7m.h:119
@ ARMV7M_R4
Definition: armv7m.h:116
@ ARMV7M_XPSR
Definition: armv7m.h:131
@ ARMV7M_D0
Definition: armv7m.h:185
@ ARMV7M_R8
Definition: armv7m.h:121
@ ARMV7M_R11
Definition: armv7m.h:124
@ ARMV7M_D12
Definition: armv7m.h:197
@ ARMV7M_D10
Definition: armv7m.h:195
@ ARMV7M_R10
Definition: armv7m.h:123
@ ARMV7M_D15
Definition: armv7m.h:200
@ ARMV7M_FPSCR
Definition: armv7m.h:203
@ ARMV7M_D5
Definition: armv7m.h:190
@ ARMV7M_R5
Definition: armv7m.h:117
@ ARMV7M_D6
Definition: armv7m.h:191
static const char *const target_cortex_m[]
Definition: ecos.c:96
ecos_symbol_values
Definition: ecos.c:303
@ ECOS_VAL_CORTEXM_CTX_S_OFF
Definition: ecos.c:340
@ ECOS_VAL_CORTEXM_CTX_TYPE_OFF
Definition: ecos.c:324
@ ECOS_VAL_ARM_CTX_R2_OFF
Definition: ecos.c:345
@ ECOS_VAL_ARM_SCOUNT
Definition: ecos.c:362
@ ECOS_VAL_COMMON_THREAD_ID_SIZE
Definition: ecos.c:315
@ ECOS_VAL_COMMON_THREAD_SLEEP_SIZE
Definition: ecos.c:311
@ ECOS_VAL_COMMON_THREAD_NEXT_SIZE
Definition: ecos.c:307
@ ECOS_VAL_ARM_CTX_R6_OFF
Definition: ecos.c:349
@ ECOS_VAL_CORTEXM_CTX_REG_OFF
Definition: ecos.c:330
@ ECOS_VAL_CORTEXM_THREAD_SAVED
Definition: ecos.c:322
@ ECOS_VAL_ARM_CTX_LR_OFF
Definition: ecos.c:357
@ ECOS_VAL_ARM_CTX_R4_OFF
Definition: ecos.c:347
@ ECOS_VAL_ARM_CTX_R5_OFF
Definition: ecos.c:348
@ ECOS_VAL_ARM_CTX_VFPVEC_OFF
Definition: ecos.c:365
@ ECOS_VAL_COMMON_THREAD_STATE_SIZE
Definition: ecos.c:309
@ ECOS_VAL_CORTEXM_VAL_THREAD
Definition: ecos.c:335
@ ECOS_VAL_ARM_CTX_R10_OFF
Definition: ecos.c:353
@ ECOS_VAL_COMMON_THREAD_WAKE_OFF
Definition: ecos.c:312
@ ECOS_VAL_COMMON_THREAD_ID_OFF
Definition: ecos.c:314
@ ECOS_VAL_CORTEXM_CTX_S_SIZE
Definition: ecos.c:341
@ ECOS_VAL_ARM_CTX_R3_OFF
Definition: ecos.c:346
@ ECOS_VAL_CORTEXM_CTX_SP_SIZE
Definition: ecos.c:329
@ ECOS_VAL_ARM_CTX_IP_OFF
Definition: ecos.c:355
@ ECOS_VAL_ARM_VFPCOUNT
Definition: ecos.c:364
@ ECOS_VAL_CORTEXM_VAL_INTERRUPT
Definition: ecos.c:336
@ ECOS_VAL_ARM_CTX_FPSCR_OFF
Definition: ecos.c:361
@ ECOS_VAL_CORTEXM_CTX_FPSCR_OFF
Definition: ecos.c:338
@ ECOS_VAL_ARM_CTX_SP_OFF
Definition: ecos.c:356
@ ECOS_VAL_CORTEXM_CTX_THREAD_SIZE
Definition: ecos.c:323
@ ECOS_VAL_ARM_CTX_R8_OFF
Definition: ecos.c:351
@ ECOS_VAL_COMMON_THREAD_STACK_SIZE
Definition: ecos.c:321
@ ECOS_VAL_ARM_CTX_R0_OFF
Definition: ecos.c:343
@ ECOS_VAL_CORTEXM_VAL_EXCEPTION
Definition: ecos.c:334
@ ECOS_VAL_COMMON_THREAD_STACK_OFF
Definition: ecos.c:320
@ ECOS_VAL_COMMON_THREAD_PRI_OFF
Definition: ecos.c:318
@ ECOS_VAL_ARM_CTX_R1_OFF
Definition: ecos.c:344
@ ECOS_VAL_ARM_CTX_R9_OFF
Definition: ecos.c:352
@ ECOS_VAL_ARM_FPUSIZE
Definition: ecos.c:360
@ ECOS_VAL_ARM_CTX_R7_OFF
Definition: ecos.c:350
@ ECOS_VAL_COMMON_THREAD_SLEEP_OFF
Definition: ecos.c:310
@ ECOS_VAL_CORTEXM_CTX_FPSCR_SIZE
Definition: ecos.c:339
@ ECOS_VAL_CORTEXM_CTX_REG_SIZE
Definition: ecos.c:331
@ ECOS_VAL_COMMON_THREAD_PRI_SIZE
Definition: ecos.c:319
@ ECOS_VAL_CORTEXM_CTX_SP_OFF
Definition: ecos.c:328
@ ECOS_VAL_CORTEXM_CTX_PC_OFF
Definition: ecos.c:332
@ ECOS_VAL_ARM_CTX_SVEC_OFF
Definition: ecos.c:363
@ ECOS_VAL_THREAD_LIST
Definition: ecos.c:304
@ ECOS_VAL_ARM_CTX_FP_OFF
Definition: ecos.c:354
@ ECOS_VAL_CORTEXM_CTX_TYPE_SIZE
Definition: ecos.c:325
@ ECOS_VAL_CURRENT_THREAD_PTR
Definition: ecos.c:305
@ ECOS_VAL_CORTEXM_CTX_PC_SIZE
Definition: ecos.c:333
@ ECOS_VAL_COMMON_THREAD_NEXT_OFF
Definition: ecos.c:306
@ ECOS_VAL_CORTEXM_CTX_BASEPRI_OFF
Definition: ecos.c:326
@ ECOS_VAL_ARM_CTX_CPSR_OFF
Definition: ecos.c:359
@ ECOS_VAL_ARM_REGSIZE
Definition: ecos.c:342
@ ECOS_VAL_COMMON_THREAD_NAME_SIZE
Definition: ecos.c:317
@ ECOS_VAL_ARM_CTX_PC_OFF
Definition: ecos.c:358
@ ECOS_VAL_CORTEXM_CTX_BASEPRI_SIZE
Definition: ecos.c:327
@ ECOS_VAL_COMMON_THREAD_NAME_OFF
Definition: ecos.c:316
@ ECOS_VAL_CORTEXM_VAL_FPU
Definition: ecos.c:337
@ ECOS_VAL_COMMON_THREAD_WAKE_SIZE
Definition: ecos.c:313
@ ECOS_VAL_COMMON_THREAD_STATE_OFF
Definition: ecos.c:308
static bool ecos_escape_string(const char *raw, char *out, size_t limit)
Escape any XML reserved characters in a string.
Definition: ecos.c:491
static int ecos_stack_layout_cortexm(struct rtos *rtos, struct ecos_params *param, int64_t stack_ptr, const struct rtos_register_stacking **si)
Definition: ecos.c:587
size_t rlen
Definition: ecos.c:481
#define ECOSSYM(_n, _o, _t)
Definition: ecos.c:374
static symbol_address_t ecos_value(struct rtos *rtos, unsigned int idx)
Definition: ecos.c:466
static struct stack_register_offset rtos_ecos_regoff_cortexm[]
Definition: ecos.c:234
#define XMLENTRY(_c, _s)
Definition: ecos.c:476
const char * rs
Definition: ecos.c:480
static bool ecos_detect_rtos(struct target *target)
Definition: ecos.c:1151
static int ecos_update_threads(struct rtos *rtos)
Definition: ecos.c:702
static struct rtos_register_stacking rtos_ecos_stacking
Definition: ecos.c:292
#define ECOS_THREAD_NAME_STR_SIZE
const struct rtos_type ecos_rtos
Definition: ecos.c:455
char xc
Definition: ecos.c:479
static int ecos_check_app_info(struct rtos *rtos, struct ecos_params *param)
Definition: ecos.c:536
static const struct @58 xmlchars[]
#define ECOS_CORTEXM_BASE_NUMREGS
Definition: ecos.c:229
ecos_reglist_cortexm
Definition: ecos.c:191
@ ECOS_REGLIST_D2
Definition: ecos.c:213
@ ECOS_REGLIST_R11
Definition: ecos.c:203
@ ECOS_REGLIST_R4
Definition: ecos.c:196
@ ECOS_REGLIST_D1
Definition: ecos.c:212
@ ECOS_REGLIST_FPSCR
Definition: ecos.c:210
@ ECOS_REGLIST_R5
Definition: ecos.c:197
@ ECOS_REGLIST_R3
Definition: ecos.c:195
@ ECOS_REGLIST_D15
Definition: ecos.c:226
@ ECOS_REGLIST_D11
Definition: ecos.c:222
@ ECOS_REGLIST_R12
Definition: ecos.c:204
@ ECOS_REGLIST_R0
Definition: ecos.c:192
@ ECOS_REGLIST_D9
Definition: ecos.c:220
@ ECOS_REGLIST_R8
Definition: ecos.c:200
@ ECOS_REGLIST_D7
Definition: ecos.c:218
@ ECOS_REGLIST_R14
Definition: ecos.c:206
@ ECOS_REGLIST_R9
Definition: ecos.c:201
@ ECOS_REGLIST_D13
Definition: ecos.c:224
@ ECOS_REGLIST_D0
Definition: ecos.c:211
@ ECOS_REGLIST_PC
Definition: ecos.c:207
@ ECOS_REGLIST_D5
Definition: ecos.c:216
@ ECOS_REGLIST_D12
Definition: ecos.c:223
@ ECOS_REGLIST_R10
Definition: ecos.c:202
@ ECOS_REGLIST_R6
Definition: ecos.c:198
@ ECOS_REGLIST_XPSR
Definition: ecos.c:208
@ ECOS_REGLIST_R7
Definition: ecos.c:199
@ ECOS_REGLIST_D6
Definition: ecos.c:217
@ ECOS_REGLIST_D10
Definition: ecos.c:221
@ ECOS_REGLIST_R2
Definition: ecos.c:194
@ ECOS_REGLIST_R1
Definition: ecos.c:193
@ ECOS_REGLIST_D3
Definition: ecos.c:214
@ ECOS_REGLIST_BASEPRI
Definition: ecos.c:209
@ ECOS_REGLIST_D4
Definition: ecos.c:215
@ ECOS_REGLIST_R13
Definition: ecos.c:205
@ ECOS_REGLIST_D8
Definition: ecos.c:219
@ ECOS_REGLIST_D14
Definition: ecos.c:225
#define ECOS_MAX_THREAD_COUNT
Definition: ecos.c:66
static const struct ecos_thread_state ecos_thread_reasons[]
Definition: ecos.c:85
static struct stack_register_offset rtos_ecos_regoff_arm[]
Definition: ecos.c:272
static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
Definition: ecos.c:1130
static int ecos_create(struct target *target)
Definition: ecos.c:1184
ecos_thread_state_flags
Definition: ecos.c:74
@ RUNNING
Definition: ecos.c:75
@ SLEEPSET
Definition: ecos.c:81
@ SUSPENDED
Definition: ecos.c:78
@ SLEEPING
Definition: ecos.c:76
@ CREATING
Definition: ecos.c:79
@ COUNTSLEEP
Definition: ecos.c:77
@ EXITED
Definition: ecos.c:80
static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs)
Definition: ecos.c:1029
static struct ecos_params ecos_params_list[]
Definition: ecos.c:153
static int ecos_packet_hook(struct connection *connection, const char *packet, int packet_size)
Definition: ecos.c:1163
static const struct symbols ecos_symbol_list[]
Definition: ecos.c:380
static int ecos_stack_layout_arm(struct rtos *rtos, struct ecos_params *param, int64_t stack_ptr, const struct rtos_register_stacking **si)
Definition: ecos.c:659
static const char *const target_arm[]
Definition: ecos.c:102
static struct target * get_target_from_connection(struct connection *connection)
Definition: gdb_server.h:35
The JTAG interface can be implemented with a software or hardware fifo.
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_LEVEL_IS(FOO)
Definition: log.h:112
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
@ LOG_LVL_DEBUG
Definition: log.h:55
static const struct rtos_register_stacking * stacking_info
Definition: riot.c:72
int rtos_generic_stack_read(struct target *target, const struct rtos_register_stacking *stacking, int64_t stack_ptr, struct rtos_reg **reg_list, int *num_regs)
Definition: rtos.c:655
int rtos_thread_packet(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:355
void rtos_free_threadlist(struct rtos *rtos)
Definition: rtos.c:740
int64_t symbol_address_t
Definition: rtos.h:16
int64_t threadid_t
Definition: rtos.h:15
const struct rtos_register_stacking rtos_ecos_cortex_m3_stacking
target_addr_t rtos_generic_stack_align8(struct target *target, const uint8_t *stack_data, const struct rtos_register_stacking *stacking, target_addr_t stack_ptr)
#define BIT(nr)
Definition: stm32l4x.h:18
unsigned char state_width
Definition: ecos.c:136
bool flush_common
Definition: ecos.c:133
unsigned int thread_stack_offset
Definition: ecos.c:137
unsigned char uid_width
Definition: ecos.c:135
unsigned int thread_next_offset
Definition: ecos.c:140
int(* target_stack_layout)(struct rtos *rtos, struct ecos_params *param, int64_t stack_ptr, const struct rtos_register_stacking **si)
Definition: ecos.c:131
unsigned int thread_name_offset
Definition: ecos.c:138
const char *const * target_names
Definition: ecos.c:130
const struct rtos_register_stacking * stacking_info
Definition: ecos.c:142
unsigned char pointer_width
Definition: ecos.c:134
unsigned int thread_state_offset
Definition: ecos.c:139
unsigned int thread_uniqueid_offset
Definition: ecos.c:141
const char * desc
Definition: ecos.c:70
Definition: rtos.h:53
const struct stack_register_offset * register_offsets
Definition: rtos.h:119
unsigned char num_output_registers
Definition: rtos.h:109
target_addr_t(* calculate_process_stack)(struct target *target, const uint8_t *stack_data, const struct rtos_register_stacking *stacking, target_addr_t stack_ptr)
Definition: rtos.h:115
unsigned char stack_registers_size
Definition: rtos.h:107
Definition: rtos.h:59
const char * name
Definition: rtos.h:60
Definition: rtos.h:36
int thread_count
Definition: rtos.h:47
int(* gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.h:48
struct thread_detail * thread_details
Definition: rtos.h:46
struct symbol_table_elem * symbols
Definition: rtos.h:39
struct target * target
Definition: rtos.h:40
void * rtos_specific_params
Definition: rtos.h:50
threadid_t current_thread
Definition: rtos.h:45
signed short offset
Definition: rtos.h:100
Table should be terminated by an element with NULL in symbol_name.
Definition: rtos.h:23
symbol_address_t address
Definition: rtos.h:25
bool optional
Definition: rtos.h:26
const char * symbol_name
Definition: rtos.h:24
Definition: ecos.c:368
const char * name
Definition: ecos.c:369
const char *const * target_names
Definition: ecos.c:370
bool optional
Definition: ecos.c:371
Definition: target.h:119
struct rtos * rtos
Definition: target.h:193
char * extra_info_str
Definition: rtos.h:33
char * thread_name_str
Definition: rtos.h:32
bool exists
Definition: rtos.h:31
threadid_t threadid
Definition: rtos.h:30
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target.c:2435
const char * target_type_name(const struct target *target)
Get the target type name.
Definition: target.c:748
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define NULL
Definition: usb.h:16