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 static int ecos_check_app_info(struct rtos *rtos, struct ecos_params *param)
477 {
478  if (!rtos || !param)
479  return -1;
480 
481  if (param->flush_common) {
483  for (unsigned int idx = 0; idx < ARRAY_SIZE(ecos_symbol_list); idx++) {
484  LOG_DEBUG("eCos: %s 0x%016" PRIX64 " %s",
485  rtos->symbols[idx].optional ? "OPTIONAL" : " ",
486  rtos->symbols[idx].address, rtos->symbols[idx].symbol_name);
487  }
488  }
489 
490  /* If "__ecospro_syminfo.size.cyg_thread.list_next" is non-zero then we
491  * expect all of the generic thread structure symbols to have been
492  * provided. */
494  if (thread_next_size != 0) {
495  param->pointer_width = thread_next_size;
503  }
504 
505  if (param->uid_width != sizeof(uint16_t)) {
506  /* Currently all eCos configurations use a 16-bit field to hold the
507  * unique thread ID. */
508  LOG_WARNING("eCos: Unexpected unique_id width %" PRIu8, param->uid_width);
509  param->uid_width = (unsigned char)sizeof(uint16_t);
510  }
511 
512  param->stacking_info = NULL;
513  param->flush_common = false;
514  }
515 
516  return ERROR_OK;
517 }
518 
519 /* The Cortex-M eCosPro "thread" contexts have a "type" indicator, which tracks
520  * the context state of (THREAD | EXCEPTION | INTERRUPT) and whether FPU
521  * registers are saved.
522  *
523  * For thread-aware debugging from GDB we are only interested in THREAD states
524  * and so do not need to implement support for INTERRUPT or EXCEPTION thread
525  * contexts since this code does not expose those stack contexts via the
526  * constructed thread list support. */
528  struct ecos_params *param, int64_t stack_ptr,
529  const struct rtos_register_stacking **si)
530 {
531  int retval = ERROR_OK;
532 
533  /* CONSIDER: We could return
534  * ecos_value(rtos, ECOS_VAL_CORTEXM_THREAD_SAVED) as the actual PC
535  * address of a context switch, with the LR being set to the context PC
536  * field to give a true representation of where the thread switch
537  * occurs. However that would require extending the common
538  * rtos_generic_stack_read() code with suitable support for applying a
539  * supplied value, or just implementing our own version of that code that
540  * can inject data into what is passed onwards to GDB. */
541 
542  /* UPDATE: When we can return VFP register state then we will NOT be
543  * basing the cached state on the single param->stacking_info value,
544  * since we will need a different stacking_info structure returned for
545  * each thread type when FPU support is enabled. The use of the single
546  * param->stacking_info is a holder whilst we are limited to the fixed
547  * ARMV7M_NUM_CORE_REGS set of descriptors. */
548 
549  if (!param->stacking_info &&
552  unsigned char numoutreg = ECOS_CORTEXM_BASE_NUMREGS;
553 
557 
571  /* Rather than using the stacked ECOS_VAL_CORTEXM_CTX_SP_OFF
572  * value we force the reported sp to be after the stacked
573  * register context. */
578 
580 
581  /* Common Cortex-M thread register offsets for the current
582  * symbol table: */
583  if (retval == ERROR_OK && param->stacking_info) {
584  if (numoutreg > ECOS_REGLIST_BASEPRI) {
587  }
588 
590  }
591  }
592 
593  if (si)
594  *si = param->stacking_info;
595 
596  return retval;
597 }
598 
599 static int ecos_stack_layout_arm(struct rtos *rtos, struct ecos_params *param,
600  int64_t stack_ptr, const struct rtos_register_stacking **si)
601 {
603  /* When OpenOCD is extended to allow FPU registers to be returned from a
604  * stacked thread context we can check:
605  * if (0 != ecos_value(rtos, ECOS_VAL_ARM_FPUSIZE)) { FPU }
606  * for presence of FPU registers in the context. */
607 
611 
629 
631  }
632 
633  if (si)
634  *si = param->stacking_info;
635 
636  return ERROR_OK;
637 }
638 
639 /* We see this function called on a new connection, it looks like before and
640  * after the "tar rem"/"tar extended-remote". It might be the only point we can
641  * decide to cache information (to check if the symbol table has changed). */
642 static int ecos_update_threads(struct rtos *rtos)
643 {
644  int retval;
645  int tasks_found = 0;
646  int thread_list_size = 0;
647  struct ecos_params *param;
648 
649  if (!rtos)
650  return -1;
651 
652  /* wipe out previous thread details if any */
654 
656  return -3;
657 
658  param = rtos->rtos_specific_params;
659 
660  if (!rtos->symbols) {
661  /* NOTE: We only see this when connecting from GDB the first
662  * time before the application image is loaded. So it is not a
663  * hook for detecting an application change. */
664  param->flush_common = true;
665  LOG_ERROR("No symbols for eCos");
666  return -4;
667  }
668 
669  retval = ecos_check_app_info(rtos, param);
670  if (retval != ERROR_OK)
671  return retval;
672 
674  LOG_ERROR("Don't have the thread list head");
675  return -2;
676  }
677 
678  /* determine the number of current threads */
679  uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
680  uint32_t thread_index;
682  thread_list_head,
683  param->pointer_width,
684  (uint8_t *) &thread_index);
685  uint32_t first_thread = thread_index;
686 
687  /* Even if 0==first_thread indicates a system with no defined eCos
688  * threads, instead of early exiting here we fall through the code to
689  * allow the creation of a faked "Current Execution" descriptor as
690  * needed. */
691 
692  if (first_thread) {
693  /* Since the OpenOCD RTOS support can attempt to obtain thread
694  * information on initial connection when the system *may* have
695  * undefined memory state it is possible for a simple thread count scan
696  * to produce invalid results. To avoid blocking indefinitely when
697  * encountering an invalid closed loop we limit the number of threads to
698  * the maximum possible, and if we pass that limit then something is
699  * wrong so treat the system as having no threads defined. */
700  do {
701  thread_list_size++;
702  if (thread_list_size > ECOS_MAX_THREAD_COUNT) {
703  /* Treat as "no threads" case: */
704  first_thread = 0;
705  thread_list_size = 0;
706  break;
707  }
708  retval = target_read_buffer(rtos->target,
709  thread_index + param->thread_next_offset,
710  param->pointer_width,
711  (uint8_t *)&thread_index);
712  if (retval != ERROR_OK)
713  return retval;
714  } while (thread_index != first_thread);
715  }
716 
717  /* read the current thread id */
718  rtos->current_thread = 0;
719 
720  uint32_t current_thread_addr;
721  retval = target_read_buffer(rtos->target,
723  param->pointer_width,
724  (uint8_t *)&current_thread_addr);
725  if (retval != ERROR_OK) {
726  LOG_ERROR("Reading active thread address");
727  return retval;
728  }
729 
730  if (current_thread_addr) {
731  uint16_t id = 0;
732  retval = target_read_buffer(rtos->target,
733  current_thread_addr + param->thread_uniqueid_offset,
734  param->uid_width,
735  (uint8_t *)&id);
736  if (retval != ERROR_OK) {
737  LOG_ERROR("Could not read eCos current thread from target");
738  return retval;
739  }
741  }
742 
743  if (thread_list_size == 0 || rtos->current_thread == 0) {
744  /* Either : No RTOS threads - there is always at least the current execution though */
745  /* OR : No current thread - all threads suspended - show the current execution
746  * of idling */
747  static const char tmp_str[] = "Current Execution";
748  thread_list_size++;
749  tasks_found++;
750  rtos->thread_details = malloc(
751  sizeof(struct thread_detail) * thread_list_size);
752  /* 1 is a valid eCos thread id, so we return 0 for this faked
753  * "current" CPU state: */
755  rtos->thread_details->exists = true;
757  rtos->thread_details->thread_name_str = malloc(sizeof(tmp_str));
758  strcpy(rtos->thread_details->thread_name_str, tmp_str);
759 
760  /* Early exit if current CPU state our only "thread": */
761  if (thread_list_size == 1) {
762  rtos->thread_count = 1;
763  return ERROR_OK;
764  }
765  } else {
766  /* create space for new thread details */
767  rtos->thread_details = malloc(
768  sizeof(struct thread_detail) * thread_list_size);
769  }
770 
771  /* loop over all threads */
772  thread_index = first_thread;
773  do {
774  #define ECOS_THREAD_NAME_STR_SIZE (200)
775  char tmp_str[ECOS_THREAD_NAME_STR_SIZE];
776  uint32_t name_ptr = 0;
777  uint32_t prev_thread_ptr;
778 
779  /* Save the thread ID. For eCos the thread has a unique ID distinct from
780  * the thread_index descriptor pointer. We present this scheduler ID
781  * instead of the descriptor memory address. */
782  uint16_t thread_id = 0;
783  retval = target_read_buffer(rtos->target,
784  thread_index + param->thread_uniqueid_offset,
785  param->uid_width,
786  (uint8_t *)&thread_id);
787  if (retval != ERROR_OK) {
788  LOG_ERROR("Could not read eCos thread id from target");
789  return retval;
790  }
791  rtos->thread_details[tasks_found].threadid = thread_id;
792 
793  /* Read the name pointer */
794  retval = target_read_buffer(rtos->target,
795  thread_index + param->thread_name_offset,
796  param->pointer_width,
797  (uint8_t *)&name_ptr);
798  if (retval != ERROR_OK) {
799  LOG_ERROR("Could not read eCos thread name pointer from target");
800  return retval;
801  }
802 
803  /* Read the thread name */
804  retval =
806  name_ptr,
808  (uint8_t *)&tmp_str);
809  if (retval != ERROR_OK) {
810  LOG_ERROR("Error reading thread name from eCos target");
811  return retval;
812  }
813  tmp_str[ECOS_THREAD_NAME_STR_SIZE-1] = '\x00';
814 
815  if (tmp_str[0] == '\x00')
816  snprintf(tmp_str, ECOS_THREAD_NAME_STR_SIZE, "NoName:[0x%08" PRIX32 "]", thread_index);
817 
818  rtos->thread_details[tasks_found].thread_name_str =
819  malloc(strlen(tmp_str)+1);
820  strcpy(rtos->thread_details[tasks_found].thread_name_str, tmp_str);
821 
822  /* Read the thread status */
823  int64_t thread_status = 0;
824  retval = target_read_buffer(rtos->target,
825  thread_index + param->thread_state_offset,
826  param->state_width,
827  (uint8_t *)&thread_status);
828  if (retval != ERROR_OK) {
829  LOG_ERROR("Error reading thread state from eCos target");
830  return retval;
831  }
832 
833  /* The thread_status is a BITMASK */
834  char state_desc[21]; /* Enough for "suspended+countsleep\0" maximum */
835 
836  if (thread_status & SUSPENDED)
837  strcpy(state_desc, "suspended+");
838  else
839  state_desc[0] = '\0';
840 
841  switch (thread_status & ~SUSPENDED) {
842  case RUNNING:
843  if (thread_index == current_thread_addr)
844  strcat(state_desc, "running");
845  else if (thread_status & SUSPENDED)
846  state_desc[9] = '\0'; /* Drop '+' from "suspended+" */
847  else
848  strcat(state_desc, "ready");
849  break;
850  case SLEEPING:
851  strcat(state_desc, "sleeping");
852  break;
853  case SLEEPSET:
854  case COUNTSLEEP:
855  strcat(state_desc, "counted sleep");
856  break;
857  case CREATING:
858  strcpy(state_desc, "creating");
859  break;
860  case EXITED:
861  strcpy(state_desc, "exited");
862  break;
863  default:
864  strcpy(state_desc, "unknown state");
865  break;
866  }
867 
868  /* For the moment we do not bother decoding the wake reason for the
869  * active "running" thread, but it is useful providing the sleep reason
870  * for stacked threads. */
871  int64_t sleep_reason = 0; /* sleep reason */
872 
873  if (thread_index != current_thread_addr &&
875  retval = target_read_buffer(rtos->target,
878  (uint8_t *)&sleep_reason);
879  if (retval != ERROR_OK) {
880  LOG_ERROR("Error reading thread sleep reason from eCos target");
881  return retval;
882  }
883  if (sleep_reason < 0 ||
884  sleep_reason > (int64_t)ARRAY_SIZE(ecos_thread_reasons)) {
885  sleep_reason = 0;
886  }
887  }
888 
889  /* We do not display anything for the Cyg_Thread::NONE reason */
890  size_t tr_extra = 0;
891  const char *reason_desc = NULL;
892  if (sleep_reason)
893  reason_desc = ecos_thread_reasons[sleep_reason].desc;
894  if (reason_desc)
895  tr_extra = 2 + strlen(reason_desc) + 1;
896 
897  /* Display thread priority if available: */
898  int64_t priority = 0;
899  size_t pri_extra = 0;
901  retval = target_read_buffer(rtos->target,
904  (uint8_t *)&priority);
905  if (retval != ERROR_OK) {
906  LOG_ERROR("Error reading thread priority from eCos target");
907  return retval;
908  }
909  pri_extra = (12 + 20); /* worst-case ", Priority: " */
910  }
911 
912  size_t eilen = (8 + strlen(state_desc) + tr_extra + pri_extra);
913  char *eistr = malloc(eilen);
914  /* We do not need to treat a malloc failure as a fatal error here since
915  * the code below will just not report extra thread information if NULL,
916  * thus allowing all of the threads to be enumerated even with reduced
917  * information when the host is low on memory. However... */
918  if (!eistr) {
919  LOG_ERROR("OOM allocating extra information buffer");
920  return ERROR_FAIL;
921  }
922 
923  int soff = snprintf(eistr, eilen, "State: %s", state_desc);
924  if (tr_extra && reason_desc)
925  soff += snprintf(&eistr[soff], (eilen - soff), " (%s)", reason_desc);
926  if (pri_extra)
927  (void)snprintf(&eistr[soff], (eilen - soff), ", Priority: %" PRId64, priority);
928  rtos->thread_details[tasks_found].extra_info_str = eistr;
929 
930  rtos->thread_details[tasks_found].exists = true;
931 
932  tasks_found++;
933  prev_thread_ptr = thread_index;
934 
935  /* Get the location of the next thread structure. */
936  thread_index = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
937  retval = target_read_buffer(rtos->target,
938  prev_thread_ptr + param->thread_next_offset,
939  param->pointer_width,
940  (uint8_t *) &thread_index);
941  if (retval != ERROR_OK) {
942  LOG_ERROR("Error reading next thread pointer in eCos thread list");
943  return retval;
944  }
945  } while (thread_index != first_thread);
946 
947  rtos->thread_count = tasks_found;
948  return ERROR_OK;
949 }
950 
951 static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
952  struct rtos_reg **reg_list, int *num_regs)
953 {
954  int retval;
955  struct ecos_params *param;
956 
957  if (!rtos)
958  return -1;
959 
960  if (thread_id == 0)
961  return -2;
962 
964  return -3;
965 
966  param = rtos->rtos_specific_params;
967 
968  retval = ecos_check_app_info(rtos, param);
969  if (retval != ERROR_OK)
970  return retval;
971 
972  /* We can get memory access errors reported by this function on
973  * re-connecting to a board with stale thread information in memory. The
974  * initial ecos_update_threads() is called twice and may read
975  * stale/invalid information depending on the memory state. This happens
976  * as part of the "target remote" connection so cannot be avoided by GDB
977  * scripting. It is not critical and allowing the application to run and
978  * initialise its BSS etc. will allow correct thread and register
979  * information to be obtained. This really only affects debug sessions
980  * where "info thr" is used before the initial run-time initialisation
981  * has occurred. */
982 
983  /* Find the thread with that thread id */
984  uint16_t id = 0;
985  uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
986  uint32_t thread_index;
987  target_read_buffer(rtos->target, thread_list_head, param->pointer_width,
988  (uint8_t *)&thread_index);
989  bool done = false;
990  while (!done) {
991  retval = target_read_buffer(rtos->target,
992  thread_index + param->thread_uniqueid_offset,
993  param->uid_width,
994  (uint8_t *)&id);
995  if (retval != ERROR_OK) {
996  LOG_ERROR("Error reading unique id from eCos thread 0x%08" PRIX32, thread_index);
997  return retval;
998  }
999 
1000  if (id == thread_id) {
1001  done = true;
1002  break;
1003  }
1005  thread_index + param->thread_next_offset,
1006  param->pointer_width,
1007  (uint8_t *) &thread_index);
1008  }
1009 
1010  if (done) {
1011  /* Read the stack pointer */
1012  int64_t stack_ptr = 0;
1013  retval = target_read_buffer(rtos->target,
1014  thread_index + param->thread_stack_offset,
1015  param->pointer_width,
1016  (uint8_t *)&stack_ptr);
1017  if (retval != ERROR_OK) {
1018  LOG_ERROR("Error reading stack frame from eCos thread");
1019  return retval;
1020  }
1021 
1022  if (!stack_ptr) {
1023  LOG_ERROR("NULL stack pointer in thread %" PRIu64, thread_id);
1024  return -5;
1025  }
1026 
1027  const struct rtos_register_stacking *stacking_info = NULL;
1028  if (param->target_stack_layout) {
1029  retval = param->target_stack_layout(rtos, param, stack_ptr, &stacking_info);
1030  if (retval != ERROR_OK) {
1031  LOG_ERROR("Error reading stack layout for eCos thread");
1032  return retval;
1033  }
1034  }
1035  if (!stacking_info)
1037 
1039  stacking_info,
1040  stack_ptr,
1041  reg_list,
1042  num_regs);
1043  }
1044 
1045  return -1;
1046 }
1047 
1048 /* NOTE: This is only called once when the first GDB connection is made to
1049  * OpenOCD and not on subsequent connections (when the application symbol table
1050  * may have changed, affecting the offsets of critical fields and the stacked
1051  * context shape). */
1052 static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
1053 {
1054  unsigned int i;
1055  *symbol_list = calloc(
1056  ARRAY_SIZE(ecos_symbol_list), sizeof(struct symbol_table_elem));
1057 
1058  /* If the target reference was passed into this function we could limit
1059  * the symbols we need to lookup to the target_type_name(target) based
1060  * range. For the moment we need to provide a single vector with all of
1061  * the symbols across all of the supported architectures. */
1062  for (i = 0; i < ARRAY_SIZE(ecos_symbol_list); i++) {
1063  (*symbol_list)[i].symbol_name = ecos_symbol_list[i].name;
1064  (*symbol_list)[i].optional = ecos_symbol_list[i].optional;
1065  }
1066 
1067  return 0;
1068 }
1069 
1070 /* NOTE: Only called by rtos.c:rtos_qsymbol() when auto-detecting the RTOS. If
1071  * the target configuration uses the explicit "-rtos" config option then this
1072  * detection routine is NOT called. */
1073 static bool ecos_detect_rtos(struct target *target)
1074 {
1075  if ((target->rtos->symbols) &&
1077  /* looks like eCos */
1078  return true;
1079  }
1080  return false;
1081 }
1082 
1083 /* Since we should never have 0 as a valid eCos thread ID we use $Hg0 as the
1084  * indicator of a new session as regards flushing any cached state. */
1086  const char *packet, int packet_size)
1087 {
1088  int64_t current_threadid;
1089 
1090  if (packet[0] == 'H' && packet[1] == 'g') {
1091  int numscan = sscanf(packet, "Hg%16" SCNx64, &current_threadid);
1092  if (numscan == 1 && current_threadid == 0) {
1095  struct ecos_params *param;
1096  param = target->rtos->rtos_specific_params;
1097  param->flush_common = true;
1098  }
1099  }
1100  }
1101 
1102  return rtos_thread_packet(connection, packet, packet_size);
1103 }
1104 
1105 /* Called at start of day when eCos detected or specified in config file. */
1106 static int ecos_create(struct target *target)
1107 {
1108  for (unsigned int i = 0; i < ARRAY_SIZE(ecos_params_list); i++) {
1109  const char * const *tnames = ecos_params_list[i].target_names;
1110  while (*tnames) {
1111  if (strcmp(*tnames, target_type_name(target)) == 0) {
1112  /* LOG_DEBUG("eCos: matched target \"%s\"", target_type_name(target)); */
1114  ecos_params_list[i].flush_common = true;
1116  target->rtos->current_thread = 0;
1118 
1119  /* We use the $Hg0 packet as a new GDB connection "start-of-day" hook to
1120  * force a re-cache of information. It is possible for a single OpenOCD
1121  * session to be connected to a target with multiple GDB debug sessions
1122  * started/stopped. With eCos it is possible for those GDB sessions to
1123  * present applications with different offsets within a thread
1124  * descriptor for fields used by this module, and for the stacked
1125  * context within the connected target architecture to differ between
1126  * applications and even between threads in a single application. So we
1127  * need to ensure any information we cache is flushed on an application
1128  * change, and GDB referencing an invalid eCos thread ID (0) is a good
1129  * enough point, since we can accept the re-cache hit if that packet
1130  * appears during an established session, whilst benefiting from not
1131  * re-loading information on every update_threads or get_thread_reg_list
1132  * call. */
1134  /* We do not currently use the target->rtos->gdb_target_for_threadid
1135  * hook. */
1136  return ERROR_OK;
1137  }
1138  tnames++;
1139  }
1140  }
1141 
1142  LOG_ERROR("Could not find target in eCos compatibility list");
1143  return ERROR_FAIL;
1144 }
@ 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 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:527
#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
static bool ecos_detect_rtos(struct target *target)
Definition: ecos.c:1073
static int ecos_update_threads(struct rtos *rtos)
Definition: ecos.c:642
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
static int ecos_check_app_info(struct rtos *rtos, struct ecos_params *param)
Definition: ecos.c:476
#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:1052
static int ecos_create(struct target *target)
Definition: ecos.c:1106
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:951
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:1085
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:599
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:2475
const char * target_type_name(const struct target *target)
Get the target type name.
Definition: target.c:750
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define NULL
Definition: usb.h:16