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) {
542  if (debug_level >= LOG_LVL_DEBUG) {
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 {
662  int retval = ERROR_OK;
663 
665  /* When OpenOCD is extended to allow FPU registers to be returned from a
666  * stacked thread context we can check:
667  * if (0 != ecos_value(rtos, ECOS_VAL_ARM_FPUSIZE)) { FPU }
668  * for presence of FPU registers in the context. */
669 
673 
691 
693  }
694 
695  if (si)
696  *si = param->stacking_info;
697 
698  return retval;
699 }
700 
701 /* We see this function called on a new connection, it looks like before and
702  * after the "tar rem"/"tar extended-remote". It might be the only point we can
703  * decide to cache information (to check if the symbol table has changed). */
704 static int ecos_update_threads(struct rtos *rtos)
705 {
706  int retval;
707  int tasks_found = 0;
708  int thread_list_size = 0;
709  struct ecos_params *param;
710 
711  if (!rtos)
712  return -1;
713 
714  /* wipe out previous thread details if any */
716 
718  return -3;
719 
720  param = rtos->rtos_specific_params;
721 
722  if (!rtos->symbols) {
723  /* NOTE: We only see this when connecting from GDB the first
724  * time before the application image is loaded. So it is not a
725  * hook for detecting an application change. */
726  param->flush_common = true;
727  LOG_ERROR("No symbols for eCos");
728  return -4;
729  }
730 
731  retval = ecos_check_app_info(rtos, param);
732  if (retval != ERROR_OK)
733  return retval;
734 
736  LOG_ERROR("Don't have the thread list head");
737  return -2;
738  }
739 
740  /* determine the number of current threads */
741  uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
742  uint32_t thread_index;
744  thread_list_head,
745  param->pointer_width,
746  (uint8_t *) &thread_index);
747  uint32_t first_thread = thread_index;
748 
749  /* Even if 0==first_thread indicates a system with no defined eCos
750  * threads, instead of early exiting here we fall through the code to
751  * allow the creation of a faked "Current Execution" descriptor as
752  * needed. */
753 
754  if (first_thread) {
755  /* Since the OpenOCD RTOS support can attempt to obtain thread
756  * information on initial connection when the system *may* have
757  * undefined memory state it is possible for a simple thread count scan
758  * to produce invalid results. To avoid blocking indefinitely when
759  * encountering an invalid closed loop we limit the number of threads to
760  * the maximum possible, and if we pass that limit then something is
761  * wrong so treat the system as having no threads defined. */
762  do {
763  thread_list_size++;
764  if (thread_list_size > ECOS_MAX_THREAD_COUNT) {
765  /* Treat as "no threads" case: */
766  first_thread = 0;
767  thread_list_size = 0;
768  break;
769  }
770  retval = target_read_buffer(rtos->target,
771  thread_index + param->thread_next_offset,
772  param->pointer_width,
773  (uint8_t *)&thread_index);
774  if (retval != ERROR_OK)
775  return retval;
776  } while (thread_index != first_thread);
777  }
778 
779  /* read the current thread id */
780  rtos->current_thread = 0;
781 
782  uint32_t current_thread_addr;
783  retval = target_read_buffer(rtos->target,
785  param->pointer_width,
786  (uint8_t *)&current_thread_addr);
787  if (retval != ERROR_OK) {
788  LOG_ERROR("Reading active thread address");
789  return retval;
790  }
791 
792  if (current_thread_addr) {
793  uint16_t id = 0;
794  retval = target_read_buffer(rtos->target,
795  current_thread_addr + param->thread_uniqueid_offset,
796  param->uid_width,
797  (uint8_t *)&id);
798  if (retval != ERROR_OK) {
799  LOG_ERROR("Could not read eCos current thread from target");
800  return retval;
801  }
803  }
804 
805  if (thread_list_size == 0 || rtos->current_thread == 0) {
806  /* Either : No RTOS threads - there is always at least the current execution though */
807  /* OR : No current thread - all threads suspended - show the current execution
808  * of idling */
809  static const char tmp_str[] = "Current Execution";
810  thread_list_size++;
811  tasks_found++;
812  rtos->thread_details = malloc(
813  sizeof(struct thread_detail) * thread_list_size);
814  /* 1 is a valid eCos thread id, so we return 0 for this faked
815  * "current" CPU state: */
817  rtos->thread_details->exists = true;
819  rtos->thread_details->thread_name_str = malloc(sizeof(tmp_str));
820  strcpy(rtos->thread_details->thread_name_str, tmp_str);
821 
822  /* Early exit if current CPU state our only "thread": */
823  if (thread_list_size == 1) {
824  rtos->thread_count = 1;
825  return ERROR_OK;
826  }
827  } else {
828  /* create space for new thread details */
829  rtos->thread_details = malloc(
830  sizeof(struct thread_detail) * thread_list_size);
831  }
832 
833  /* loop over all threads */
834  thread_index = first_thread;
835  do {
836  #define ECOS_THREAD_NAME_STR_SIZE (200)
837  char tmp_str[ECOS_THREAD_NAME_STR_SIZE];
838  uint32_t name_ptr = 0;
839  uint32_t prev_thread_ptr;
840 
841  /* Save the thread ID. For eCos the thread has a unique ID distinct from
842  * the thread_index descriptor pointer. We present this scheduler ID
843  * instead of the descriptor memory address. */
844  uint16_t thread_id = 0;
845  retval = target_read_buffer(rtos->target,
846  thread_index + param->thread_uniqueid_offset,
847  param->uid_width,
848  (uint8_t *)&thread_id);
849  if (retval != ERROR_OK) {
850  LOG_ERROR("Could not read eCos thread id from target");
851  return retval;
852  }
853  rtos->thread_details[tasks_found].threadid = thread_id;
854 
855  /* Read the name pointer */
856  retval = target_read_buffer(rtos->target,
857  thread_index + param->thread_name_offset,
858  param->pointer_width,
859  (uint8_t *)&name_ptr);
860  if (retval != ERROR_OK) {
861  LOG_ERROR("Could not read eCos thread name pointer from target");
862  return retval;
863  }
864 
865  /* Read the thread name */
866  retval =
868  name_ptr,
870  (uint8_t *)&tmp_str);
871  if (retval != ERROR_OK) {
872  LOG_ERROR("Error reading thread name from eCos target");
873  return retval;
874  }
875  tmp_str[ECOS_THREAD_NAME_STR_SIZE-1] = '\x00';
876 
877  /* Since eCos can have arbitrary C string names we can sometimes
878  * get an internal warning from GDB about "not well-formed
879  * (invalid token)" since the XML post-processing done by GDB on
880  * the OpenOCD returned response containing the thread strings
881  * is not escaped. For example the eCos kernel testsuite
882  * application tm_basic uses the thread name "<<NULL>>" which
883  * will trigger this failure unless escaped. */
884  if (tmp_str[0] == '\x00') {
885  snprintf(tmp_str, ECOS_THREAD_NAME_STR_SIZE, "NoName:[0x%08" PRIX32 "]", thread_index);
886  } else {
887  /* The following is a workaround to avoid any issues
888  * from arbitrary eCos thread names causing GDB/OpenOCD
889  * issues. We limit the escaped thread name passed to
890  * GDB to the same length as the un-escaped just to
891  * avoid overly long strings. */
892  char esc_str[ECOS_THREAD_NAME_STR_SIZE];
893  bool escaped = ecos_escape_string(tmp_str, esc_str, sizeof(esc_str));
894  if (escaped)
895  strcpy(tmp_str, esc_str);
896  }
897 
898  rtos->thread_details[tasks_found].thread_name_str =
899  malloc(strlen(tmp_str)+1);
900  strcpy(rtos->thread_details[tasks_found].thread_name_str, tmp_str);
901 
902  /* Read the thread status */
903  int64_t thread_status = 0;
904  retval = target_read_buffer(rtos->target,
905  thread_index + param->thread_state_offset,
906  param->state_width,
907  (uint8_t *)&thread_status);
908  if (retval != ERROR_OK) {
909  LOG_ERROR("Error reading thread state from eCos target");
910  return retval;
911  }
912 
913  /* The thread_status is a BITMASK */
914  char state_desc[21]; /* Enough for "suspended+countsleep\0" maximum */
915 
916  if (thread_status & SUSPENDED)
917  strcpy(state_desc, "suspended+");
918  else
919  state_desc[0] = '\0';
920 
921  switch (thread_status & ~SUSPENDED) {
922  case RUNNING:
923  if (thread_index == current_thread_addr)
924  strcat(state_desc, "running");
925  else if (thread_status & SUSPENDED)
926  state_desc[9] = '\0'; /* Drop '+' from "suspended+" */
927  else
928  strcat(state_desc, "ready");
929  break;
930  case SLEEPING:
931  strcat(state_desc, "sleeping");
932  break;
933  case SLEEPSET:
934  case COUNTSLEEP:
935  strcat(state_desc, "counted sleep");
936  break;
937  case CREATING:
938  strcpy(state_desc, "creating");
939  break;
940  case EXITED:
941  strcpy(state_desc, "exited");
942  break;
943  default:
944  strcpy(state_desc, "unknown state");
945  break;
946  }
947 
948  /* For the moment we do not bother decoding the wake reason for the
949  * active "running" thread, but it is useful providing the sleep reason
950  * for stacked threads. */
951  int64_t sleep_reason = 0; /* sleep reason */
952 
953  if (thread_index != current_thread_addr &&
955  retval = target_read_buffer(rtos->target,
958  (uint8_t *)&sleep_reason);
959  if (retval != ERROR_OK) {
960  LOG_ERROR("Error reading thread sleep reason from eCos target");
961  return retval;
962  }
963  if (sleep_reason < 0 ||
964  sleep_reason > (int64_t)ARRAY_SIZE(ecos_thread_reasons)) {
965  sleep_reason = 0;
966  }
967  }
968 
969  /* We do not display anything for the Cyg_Thread::NONE reason */
970  size_t tr_extra = 0;
971  const char *reason_desc = NULL;
972  if (sleep_reason)
973  reason_desc = ecos_thread_reasons[sleep_reason].desc;
974  if (reason_desc)
975  tr_extra = 2 + strlen(reason_desc) + 1;
976 
977  /* Display thread priority if available: */
978  int64_t priority = 0;
979  size_t pri_extra = 0;
981  retval = target_read_buffer(rtos->target,
984  (uint8_t *)&priority);
985  if (retval != ERROR_OK) {
986  LOG_ERROR("Error reading thread priority from eCos target");
987  return retval;
988  }
989  pri_extra = (12 + 20); /* worst-case ", Priority: " */
990  }
991 
992  size_t eilen = (8 + strlen(state_desc) + tr_extra + pri_extra);
993  char *eistr = malloc(eilen);
994  /* We do not need to treat a malloc failure as a fatal error here since
995  * the code below will just not report extra thread information if NULL,
996  * thus allowing all of the threads to be enumerated even with reduced
997  * information when the host is low on memory. However... */
998  if (!eistr) {
999  LOG_ERROR("OOM allocating extra information buffer");
1000  return ERROR_FAIL;
1001  }
1002 
1003  int soff = snprintf(eistr, eilen, "State: %s", state_desc);
1004  if (tr_extra && reason_desc)
1005  soff += snprintf(&eistr[soff], (eilen - soff), " (%s)", reason_desc);
1006  if (pri_extra)
1007  (void)snprintf(&eistr[soff], (eilen - soff), ", Priority: %" PRId64 "", priority);
1008  rtos->thread_details[tasks_found].extra_info_str = eistr;
1009 
1010  rtos->thread_details[tasks_found].exists = true;
1011 
1012  tasks_found++;
1013  prev_thread_ptr = thread_index;
1014 
1015  /* Get the location of the next thread structure. */
1016  thread_index = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
1017  retval = target_read_buffer(rtos->target,
1018  prev_thread_ptr + param->thread_next_offset,
1019  param->pointer_width,
1020  (uint8_t *) &thread_index);
1021  if (retval != ERROR_OK) {
1022  LOG_ERROR("Error reading next thread pointer in eCos thread list");
1023  return retval;
1024  }
1025  } while (thread_index != first_thread);
1026 
1027  rtos->thread_count = tasks_found;
1028  return ERROR_OK;
1029 }
1030 
1031 static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
1032  struct rtos_reg **reg_list, int *num_regs)
1033 {
1034  int retval;
1035  struct ecos_params *param;
1036 
1037  if (!rtos)
1038  return -1;
1039 
1040  if (thread_id == 0)
1041  return -2;
1042 
1043  if (!rtos->rtos_specific_params)
1044  return -3;
1045 
1046  param = rtos->rtos_specific_params;
1047 
1048  retval = ecos_check_app_info(rtos, param);
1049  if (retval != ERROR_OK)
1050  return retval;
1051 
1052  /* We can get memory access errors reported by this function on
1053  * re-connecting to a board with stale thread information in memory. The
1054  * initial ecos_update_threads() is called twice and may read
1055  * stale/invalid information depending on the memory state. This happens
1056  * as part of the "target remote" connection so cannot be avoided by GDB
1057  * scripting. It is not critical and allowing the application to run and
1058  * initialise its BSS etc. will allow correct thread and register
1059  * information to be obtained. This really only affects debug sessions
1060  * where "info thr" is used before the initial run-time initialisation
1061  * has occurred. */
1062 
1063  /* Find the thread with that thread id */
1064  uint16_t id = 0;
1065  uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
1066  uint32_t thread_index;
1067  target_read_buffer(rtos->target, thread_list_head, param->pointer_width,
1068  (uint8_t *)&thread_index);
1069  bool done = false;
1070  while (!done) {
1071  retval = target_read_buffer(rtos->target,
1072  thread_index + param->thread_uniqueid_offset,
1073  param->uid_width,
1074  (uint8_t *)&id);
1075  if (retval != ERROR_OK) {
1076  LOG_ERROR("Error reading unique id from eCos thread 0x%08" PRIX32 "", thread_index);
1077  return retval;
1078  }
1079 
1080  if (id == thread_id) {
1081  done = true;
1082  break;
1083  }
1085  thread_index + param->thread_next_offset,
1086  param->pointer_width,
1087  (uint8_t *) &thread_index);
1088  }
1089 
1090  if (done) {
1091  /* Read the stack pointer */
1092  int64_t stack_ptr = 0;
1093  retval = target_read_buffer(rtos->target,
1094  thread_index + param->thread_stack_offset,
1095  param->pointer_width,
1096  (uint8_t *)&stack_ptr);
1097  if (retval != ERROR_OK) {
1098  LOG_ERROR("Error reading stack frame from eCos thread");
1099  return retval;
1100  }
1101 
1102  if (!stack_ptr) {
1103  LOG_ERROR("NULL stack pointer in thread %" PRIu64, thread_id);
1104  return -5;
1105  }
1106 
1107  const struct rtos_register_stacking *stacking_info = NULL;
1108  if (param->target_stack_layout) {
1109  retval = param->target_stack_layout(rtos, param, stack_ptr, &stacking_info);
1110  if (retval != ERROR_OK) {
1111  LOG_ERROR("Error reading stack layout for eCos thread");
1112  return retval;
1113  }
1114  }
1115  if (!stacking_info)
1117 
1119  stacking_info,
1120  stack_ptr,
1121  reg_list,
1122  num_regs);
1123  }
1124 
1125  return -1;
1126 }
1127 
1128 /* NOTE: This is only called once when the first GDB connection is made to
1129  * OpenOCD and not on subsequent connections (when the application symbol table
1130  * may have changed, affecting the offsets of critical fields and the stacked
1131  * context shape). */
1132 static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
1133 {
1134  unsigned int i;
1135  *symbol_list = calloc(
1136  ARRAY_SIZE(ecos_symbol_list), sizeof(struct symbol_table_elem));
1137 
1138  /* If the target reference was passed into this function we could limit
1139  * the symbols we need to lookup to the target_type_name(target) based
1140  * range. For the moment we need to provide a single vector with all of
1141  * the symbols across all of the supported architectures. */
1142  for (i = 0; i < ARRAY_SIZE(ecos_symbol_list); i++) {
1143  (*symbol_list)[i].symbol_name = ecos_symbol_list[i].name;
1144  (*symbol_list)[i].optional = ecos_symbol_list[i].optional;
1145  }
1146 
1147  return 0;
1148 }
1149 
1150 /* NOTE: Only called by rtos.c:rtos_qsymbol() when auto-detecting the RTOS. If
1151  * the target configuration uses the explicit "-rtos" config option then this
1152  * detection routine is NOT called. */
1153 static bool ecos_detect_rtos(struct target *target)
1154 {
1155  if ((target->rtos->symbols) &&
1157  /* looks like eCos */
1158  return true;
1159  }
1160  return false;
1161 }
1162 
1163 /* Since we should never have 0 as a valid eCos thread ID we use $Hg0 as the
1164  * indicator of a new session as regards flushing any cached state. */
1166  const char *packet, int packet_size)
1167 {
1168  int64_t current_threadid;
1169 
1170  if (packet[0] == 'H' && packet[1] == 'g') {
1171  int numscan = sscanf(packet, "Hg%16" SCNx64, &current_threadid);
1172  if (numscan == 1 && current_threadid == 0) {
1175  struct ecos_params *param;
1176  param = target->rtos->rtos_specific_params;
1177  param->flush_common = true;
1178  }
1179  }
1180  }
1181 
1182  return rtos_thread_packet(connection, packet, packet_size);
1183 }
1184 
1185 /* Called at start of day when eCos detected or specified in config file. */
1186 static int ecos_create(struct target *target)
1187 {
1188  for (unsigned int i = 0; i < ARRAY_SIZE(ecos_params_list); i++) {
1189  const char * const *tnames = ecos_params_list[i].target_names;
1190  while (*tnames) {
1191  if (strcmp(*tnames, target_type_name(target)) == 0) {
1192  /* LOG_DEBUG("eCos: matched target \"%s\"", target_type_name(target)); */
1194  ecos_params_list[i].flush_common = true;
1196  target->rtos->current_thread = 0;
1198 
1199  /* We use the $Hg0 packet as a new GDB connection "start-of-day" hook to
1200  * force a re-cache of information. It is possible for a single OpenOCD
1201  * session to be connected to a target with multiple GDB debug sessions
1202  * started/stopped. With eCos it is possible for those GDB sessions to
1203  * present applications with different offsets within a thread
1204  * descriptor for fields used by this module, and for the stacked
1205  * context within the connected target architecture to differ between
1206  * applications and even between threads in a single application. So we
1207  * need to ensure any information we cache is flushed on an application
1208  * change, and GDB referencing an invalid eCos thread ID (0) is a good
1209  * enough point, since we can accept the re-cache hit if that packet
1210  * appears during an established session, whilst benefiting from not
1211  * re-loading information on every update_threads or get_thread_reg_list
1212  * call. */
1214  /* We do not currently use the target->rtos->gdb_target_for_threadid
1215  * hook. */
1216  return 0;
1217  }
1218  tnames++;
1219  }
1220  }
1221 
1222  LOG_ERROR("Could not find target in eCos compatibility list");
1223  return -1;
1224 }
@ ARMV7M_R1
Definition: armv7m.h:108
@ ARMV7M_D14
Definition: armv7m.h:193
@ ARMV7M_D8
Definition: armv7m.h:187
@ ARMV7M_R6
Definition: armv7m.h:114
@ ARMV7M_R2
Definition: armv7m.h:109
@ ARMV7M_D3
Definition: armv7m.h:182
@ ARMV7M_D1
Definition: armv7m.h:180
@ ARMV7M_D4
Definition: armv7m.h:183
@ ARMV7M_BASEPRI
Definition: armv7m.h:145
@ ARMV7M_D2
Definition: armv7m.h:181
@ ARMV7M_R3
Definition: armv7m.h:110
@ ARMV7M_D11
Definition: armv7m.h:190
@ ARMV7M_D9
Definition: armv7m.h:188
@ ARMV7M_R14
Definition: armv7m.h:124
@ ARMV7M_R9
Definition: armv7m.h:118
@ ARMV7M_D7
Definition: armv7m.h:186
@ ARMV7M_R12
Definition: armv7m.h:122
@ ARMV7M_R0
Definition: armv7m.h:107
@ ARMV7M_D13
Definition: armv7m.h:192
@ ARMV7M_R13
Definition: armv7m.h:123
@ ARMV7M_PC
Definition: armv7m.h:125
@ ARMV7M_R7
Definition: armv7m.h:115
@ ARMV7M_R4
Definition: armv7m.h:112
@ ARMV7M_XPSR
Definition: armv7m.h:127
@ ARMV7M_D0
Definition: armv7m.h:179
@ ARMV7M_R8
Definition: armv7m.h:117
@ ARMV7M_R11
Definition: armv7m.h:120
@ ARMV7M_D12
Definition: armv7m.h:191
@ ARMV7M_D10
Definition: armv7m.h:189
@ ARMV7M_R10
Definition: armv7m.h:119
@ ARMV7M_D15
Definition: armv7m.h:194
@ ARMV7M_FPSCR
Definition: armv7m.h:197
@ ARMV7M_D5
Definition: armv7m.h:184
@ ARMV7M_R5
Definition: armv7m.h:113
@ ARMV7M_D6
Definition: armv7m.h:185
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:1153
static int ecos_update_threads(struct rtos *rtos)
Definition: eCos.c:704
static const struct @54 xmlchars[]
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
#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:1132
static int ecos_create(struct target *target)
Definition: eCos.c:1186
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:1031
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:1165
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.
int debug_level
Definition: log.c:35
#define LOG_WARNING(expr ...)
Definition: log.h:129
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
@ LOG_LVL_DEBUG
Definition: log.h:47
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:602
int rtos_thread_packet(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:331
void rtos_free_threadlist(struct rtos *rtos)
Definition: rtos.c:695
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:104
unsigned char num_output_registers
Definition: rtos.h:94
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:100
unsigned char stack_registers_size
Definition: rtos.h:92
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:85
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:116
struct rtos * rtos
Definition: target.h:183
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:2407
const char * target_type_name(const struct target *target)
Get the target type name.
Definition: target.c:736
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define NULL
Definition: usb.h:16