1
2
3
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
66
67
68
72
73
74
83
84
85
86
87
88
89
90
91
92
93
94
95
96
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
299
300
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
373
374
375
376
380
381
382
383
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
549
550
553
554
555
556
557
558
559
560
561
562
563
564
565
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
634
635
636
637
638
639
640
641
643
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
730
731
732
733
734
735
739
740
741
742
743
744
745
746
747
748
749
753
754
755
762
763
764
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
791
792
793
794
795
796
797
798
802
803
804
805
806
807
809
810
811
812
813
814
816
817
818
819
820
821
822
823
827
832
833
834
835
836
837
838
839
840
841
844
845
846
847
848
849
853
854
855
856
857
858
859
860
864
865
866
867
868
869
870
871
875
876
877
884
897
898
899
900
901
902
903
904
905
906
907
908
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
933
934
937
940
943
946
947
948
951
952
953
954
955
956
957
958
959
963
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
989
990
991
992
993
994
998
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1079
1080
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1101
1102
1106
1107
1108
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1132
1133
1134
1135
1136
1137
1138
1142
1146
1147
1148
1149
1150
1153
1162
1163
1165
1166
1167
1168
1169
1170
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1216
1217
1218
1219
1220
1221
1222
1223
1224
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <helper/time_support.h>
#include <jtag/jtag.h>
#include "target/target.h"
#include "target/armv7m.h"
#include "rtos.h"
#include "helper/log.h"
#include "helper/types.h"
#include "helper/bits.h"
#include "rtos_standard_stackings.h"
#include "rtos_ecos_stackings.h"
#include "server/gdb_server.h"
11 includes
/* ... */
struct ecos_params;
static bool ecos_detect_rtos(struct target *target);
static int ecos_create(struct target *target);
static int ecos_update_threads(struct rtos *rtos);
static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs);
static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]);
static int ecos_stack_layout_cortexm(struct rtos *rtos, struct ecos_params *param,
int64_t stack_ptr, const struct rtos_register_stacking **si);
static int ecos_stack_layout_arm(struct rtos *rtos, struct ecos_params *param,
int64_t stack_ptr, const struct rtos_register_stacking **si);
/* ... */
#define ECOS_MAX_THREAD_COUNT (4095)
struct ecos_thread_state {
int value;
const char *desc;
...};
enum ecos_thread_state_flags {
RUNNING = 0,
SLEEPING = BIT(0),
COUNTSLEEP = BIT(1),
SUSPENDED = BIT(2),
CREATING = BIT(3),
EXITED = BIT(4),
SLEEPSET = (SLEEPING | COUNTSLEEP)
...};
static const struct ecos_thread_state ecos_thread_reasons[] = {
{ 0, "NONE" },
{ 1, "WAIT" },
{ 2, "DELAY" },
{ 3, "TIMEOUT" },
{ 4, "BREAK" },
{ 5, "DESTRUCT" },
{ 6, "EXIT" },
{ 7, "DONE" }
...};
static const char * const target_cortex_m[] = {
"cortex_m",
"hla_target",
NULL
...};
static const char * const target_arm[] = {
"cortex_a",
"arm7tdmi",
"arm720t",
"arm9tdmi",
"arm920t",
"arm926ejs",
"arm946e",
"arm966e",
"arm11",
NULL
...};
/* ... */
struct ecos_params {
const char * const *target_names;
int (*target_stack_layout)(struct rtos *rtos, struct ecos_params *param,
int64_t stack_ptr, const struct rtos_register_stacking **si);
bool flush_common;
unsigned char pointer_width;
unsigned char uid_width;
unsigned char state_width;
unsigned int thread_stack_offset;
unsigned int thread_name_offset;
unsigned int thread_state_offset;
unsigned int thread_next_offset;
unsigned int thread_uniqueid_offset;
const struct rtos_register_stacking *stacking_info;
...};
/* ... */
static struct ecos_params ecos_params_list[] = {
{
.target_names = target_cortex_m,
.pointer_width = 4,
.uid_width = 2,
.state_width = 4,
.thread_stack_offset = 0x0c,
.thread_name_offset = 0x9c,
.thread_state_offset = 0x3c,
.thread_next_offset = 0xa0,
.thread_uniqueid_offset = 0x4c,
.target_stack_layout = ecos_stack_layout_cortexm,
.stacking_info = NULL
...},
{
.target_names = target_arm,
.pointer_width = 0,
.uid_width = 0,
.state_width = 0,
.thread_stack_offset = 0,
.thread_name_offset = 0,
.thread_state_offset = 0,
.thread_next_offset = 0,
.thread_uniqueid_offset = 0,
.target_stack_layout = ecos_stack_layout_arm,
.stacking_info = NULL
...}
...};
#define ECOS_NUM_PARAMS ARRAY_SIZE(ecos_params_list)
/* ... */
enum ecos_reglist_cortexm {
ECOS_REGLIST_R0 = 0,
ECOS_REGLIST_R1,
ECOS_REGLIST_R2,
ECOS_REGLIST_R3,
ECOS_REGLIST_R4,
ECOS_REGLIST_R5,
ECOS_REGLIST_R6,
ECOS_REGLIST_R7,
ECOS_REGLIST_R8,
ECOS_REGLIST_R9,
ECOS_REGLIST_R10,
ECOS_REGLIST_R11,
ECOS_REGLIST_R12,
ECOS_REGLIST_R13,
ECOS_REGLIST_R14,
ECOS_REGLIST_PC,
ECOS_REGLIST_XPSR,
ECOS_REGLIST_BASEPRI,
ECOS_REGLIST_FPSCR,
ECOS_REGLIST_D0,
ECOS_REGLIST_D1,
ECOS_REGLIST_D2,
ECOS_REGLIST_D3,
ECOS_REGLIST_D4,
ECOS_REGLIST_D5,
ECOS_REGLIST_D6,
ECOS_REGLIST_D7,
ECOS_REGLIST_D8,
ECOS_REGLIST_D9,
ECOS_REGLIST_D10,
ECOS_REGLIST_D11,
ECOS_REGLIST_D12,
ECOS_REGLIST_D13,
ECOS_REGLIST_D14,
ECOS_REGLIST_D15
...};
#define ECOS_CORTEXM_BASE_NUMREGS (ARMV7M_NUM_CORE_REGS)
/* ... */
static struct stack_register_offset rtos_ecos_regoff_cortexm[] = {
{ ARMV7M_R0, -1, 32 },
{ ARMV7M_R1, -1, 32 },
{ ARMV7M_R2, -1, 32 },
{ ARMV7M_R3, -1, 32 },
{ ARMV7M_R4, -1, 32 },
{ ARMV7M_R5, -1, 32 },
{ ARMV7M_R6, -1, 32 },
{ ARMV7M_R7, -1, 32 },
{ ARMV7M_R8, -1, 32 },
{ ARMV7M_R9, -1, 32 },
{ ARMV7M_R10, -1, 32 },
{ ARMV7M_R11, -1, 32 },
{ ARMV7M_R12, -1, 32 },
{ ARMV7M_R13, -1, 32 },
{ ARMV7M_R14, -1, 32 },
{ ARMV7M_PC, -1, 32 },
{ ARMV7M_XPSR, -1, 32 },
{ ARMV7M_BASEPRI, -1, 32 },
{ ARMV7M_FPSCR, -1, 32 },
{ ARMV7M_D0, -1, 64 },
{ ARMV7M_D1, -1, 64 },
{ ARMV7M_D2, -1, 64 },
{ ARMV7M_D3, -1, 64 },
{ ARMV7M_D4, -1, 64 },
{ ARMV7M_D5, -1, 64 },
{ ARMV7M_D6, -1, 64 },
{ ARMV7M_D7, -1, 64 },
{ ARMV7M_D8, -1, 64 },
{ ARMV7M_D9, -1, 64 },
{ ARMV7M_D10, -1, 64 },
{ ARMV7M_D11, -1, 64 },
{ ARMV7M_D12, -1, 64 },
{ ARMV7M_D13, -1, 64 },
{ ARMV7M_D14, -1, 64 },
{ ARMV7M_D15, -1, 64 },
...};
static struct stack_register_offset rtos_ecos_regoff_arm[] = {
{ 0, -1, 32 },
{ 1, -1, 32 },
{ 2, -1, 32 },
{ 3, -1, 32 },
{ 4, -1, 32 },
{ 5, -1, 32 },
{ 6, -1, 32 },
{ 7, -1, 32 },
{ 8, -1, 32 },
{ 9, -1, 32 },
{ 10, -1, 32 },
{ 11, -1, 32 },
{ 12, -1, 32 },
{ 13, -1, 32 },
{ 14, -1, 32 },
{ 15, -1, 32 },
{ 16, -1, 32 },
...};
static struct rtos_register_stacking rtos_ecos_stacking = {
.stack_registers_size = 0,
.stack_growth_direction = -1,
.num_output_registers = 0,
.calculate_process_stack = NULL,
.register_offsets = NULL
...};
/* ... */
enum ecos_symbol_values {
ECOS_VAL_THREAD_LIST = 0,
ECOS_VAL_CURRENT_THREAD_PTR,
ECOS_VAL_COMMON_THREAD_NEXT_OFF,
ECOS_VAL_COMMON_THREAD_NEXT_SIZE,
ECOS_VAL_COMMON_THREAD_STATE_OFF,
ECOS_VAL_COMMON_THREAD_STATE_SIZE,
ECOS_VAL_COMMON_THREAD_SLEEP_OFF,
ECOS_VAL_COMMON_THREAD_SLEEP_SIZE,
ECOS_VAL_COMMON_THREAD_WAKE_OFF,
ECOS_VAL_COMMON_THREAD_WAKE_SIZE,
ECOS_VAL_COMMON_THREAD_ID_OFF,
ECOS_VAL_COMMON_THREAD_ID_SIZE,
ECOS_VAL_COMMON_THREAD_NAME_OFF,
ECOS_VAL_COMMON_THREAD_NAME_SIZE,
ECOS_VAL_COMMON_THREAD_PRI_OFF,
ECOS_VAL_COMMON_THREAD_PRI_SIZE,
ECOS_VAL_COMMON_THREAD_STACK_OFF,
ECOS_VAL_COMMON_THREAD_STACK_SIZE,
ECOS_VAL_CORTEXM_THREAD_SAVED,
ECOS_VAL_CORTEXM_CTX_THREAD_SIZE,
ECOS_VAL_CORTEXM_CTX_TYPE_OFF,
ECOS_VAL_CORTEXM_CTX_TYPE_SIZE,
ECOS_VAL_CORTEXM_CTX_BASEPRI_OFF,
ECOS_VAL_CORTEXM_CTX_BASEPRI_SIZE,
ECOS_VAL_CORTEXM_CTX_SP_OFF,
ECOS_VAL_CORTEXM_CTX_SP_SIZE,
ECOS_VAL_CORTEXM_CTX_REG_OFF,
ECOS_VAL_CORTEXM_CTX_REG_SIZE,
ECOS_VAL_CORTEXM_CTX_PC_OFF,
ECOS_VAL_CORTEXM_CTX_PC_SIZE,
ECOS_VAL_CORTEXM_VAL_EXCEPTION,
ECOS_VAL_CORTEXM_VAL_THREAD,
ECOS_VAL_CORTEXM_VAL_INTERRUPT,
ECOS_VAL_CORTEXM_VAL_FPU,
ECOS_VAL_CORTEXM_CTX_FPSCR_OFF,
ECOS_VAL_CORTEXM_CTX_FPSCR_SIZE,
ECOS_VAL_CORTEXM_CTX_S_OFF,
ECOS_VAL_CORTEXM_CTX_S_SIZE,
ECOS_VAL_ARM_REGSIZE,
ECOS_VAL_ARM_CTX_R0_OFF,
ECOS_VAL_ARM_CTX_R1_OFF,
ECOS_VAL_ARM_CTX_R2_OFF,
ECOS_VAL_ARM_CTX_R3_OFF,
ECOS_VAL_ARM_CTX_R4_OFF,
ECOS_VAL_ARM_CTX_R5_OFF,
ECOS_VAL_ARM_CTX_R6_OFF,
ECOS_VAL_ARM_CTX_R7_OFF,
ECOS_VAL_ARM_CTX_R8_OFF,
ECOS_VAL_ARM_CTX_R9_OFF,
ECOS_VAL_ARM_CTX_R10_OFF,
ECOS_VAL_ARM_CTX_FP_OFF,
ECOS_VAL_ARM_CTX_IP_OFF,
ECOS_VAL_ARM_CTX_SP_OFF,
ECOS_VAL_ARM_CTX_LR_OFF,
ECOS_VAL_ARM_CTX_PC_OFF,
ECOS_VAL_ARM_CTX_CPSR_OFF,
ECOS_VAL_ARM_FPUSIZE,
ECOS_VAL_ARM_CTX_FPSCR_OFF,
ECOS_VAL_ARM_SCOUNT,
ECOS_VAL_ARM_CTX_SVEC_OFF,
ECOS_VAL_ARM_VFPCOUNT,
ECOS_VAL_ARM_CTX_VFPVEC_OFF
...};
struct symbols {
const char *name;
const char * const *target_names;
bool optional;
...};
#define ECOSSYM(_n, _o, _t) { .name = _n, .optional = (_o), .target_names = _t }
/* ... */
static const struct symbols ecos_symbol_list[] = {
ECOSSYM("Cyg_Thread::thread_list", false, NULL),
ECOSSYM("Cyg_Scheduler_Base::current_thread", false, NULL),
/* ... */
ECOSSYM("__ecospro_syminfo.off.cyg_thread.list_next", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.list_next", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.state", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.state", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.sleep_reason", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.sleep_reason", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.wake_reason", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.wake_reason", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.unique_id", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.unique_id", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.name", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.name", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.priority", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.priority", true, NULL),
ECOSSYM("__ecospro_syminfo.off.cyg_thread.stack_ptr", true, NULL),
ECOSSYM("__ecospro_syminfo.size.cyg_thread.stack_ptr", true, NULL),
ECOSSYM("__ecospro_syminfo.cortexm.thread.saved", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.Thread", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.type", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.type", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.basepri", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.basepri", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.sp", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.sp", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.r", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.r", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.pc", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.pc", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.EXCEPTION", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.THREAD", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.INTERRUPT", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.value.HAL_SAVEDREGISTERS.WITH_FPU", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.fpscr", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.fpscr", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.off.HAL_SavedRegisters.u.thread.s", true, target_cortex_m),
ECOSSYM("__ecospro_syminfo.size.HAL_SavedRegisters.u.thread.s", true, target_cortex_m),
ECOSSYM("ARMREG_SIZE", true, target_arm),
ECOSSYM("armreg_r0", true, target_arm),
ECOSSYM("armreg_r1", true, target_arm),
ECOSSYM("armreg_r2", true, target_arm),
ECOSSYM("armreg_r3", true, target_arm),
ECOSSYM("armreg_r4", true, target_arm),
ECOSSYM("armreg_r5", true, target_arm),
ECOSSYM("armreg_r6", true, target_arm),
ECOSSYM("armreg_r7", true, target_arm),
ECOSSYM("armreg_r8", true, target_arm),
ECOSSYM("armreg_r9", true, target_arm),
ECOSSYM("armreg_r10", true, target_arm),
ECOSSYM("armreg_fp", true, target_arm),
ECOSSYM("armreg_ip", true, target_arm),
ECOSSYM("armreg_sp", true, target_arm),
ECOSSYM("armreg_lr", true, target_arm),
ECOSSYM("armreg_pc", true, target_arm),
ECOSSYM("armreg_cpsr", true, target_arm),
ECOSSYM("ARMREG_FPUCONTEXT_SIZE", true, target_arm),
ECOSSYM("armreg_fpscr", true, target_arm),
ECOSSYM("ARMREG_S_COUNT", true, target_arm),
ECOSSYM("armreg_s_vec", true, target_arm),
ECOSSYM("ARMREG_VFP_COUNT", true, target_arm),
ECOSSYM("armreg_vfp_vec", true, target_arm),
...};
const struct rtos_type ecos_rtos = {
.name = "eCos",
.detect_rtos = ecos_detect_rtos,
.create = ecos_create,
.update_threads = ecos_update_threads,
.get_thread_reg_list = ecos_get_thread_reg_list,
.get_symbol_list_to_lookup = ecos_get_symbol_list_to_lookup,
...};
static symbol_address_t ecos_value(struct rtos *rtos, unsigned int idx)
{
if (idx < ARRAY_SIZE(ecos_symbol_list))
return rtos->symbols[idx].address;
LOG_ERROR("eCos: Invalid symbol index %u", idx);
return 0;
}{ ... }
#define XMLENTRY(_c, _s) { .xc = (_c), .rs = (_s), .rlen = (sizeof(_s) - 1) }
static const struct {
char xc;
const char *rs;
size_t rlen;
...} xmlchars[] = {
XMLENTRY('<', "<"),
XMLENTRY('&', "&"),
XMLENTRY('>', ">"),
XMLENTRY('\'', "'"),
XMLENTRY('"', """)
...};
static bool ecos_escape_string(const char *raw, char *out, size_t limit)
{
static const char *tokens = "<&>\'\"";
bool escaped = false;
if (!out || !limit)
return false;
(void)memset(out, '\0', limit);
while (raw && *raw && limit) {
size_t lok = strcspn(raw, tokens);
if (lok) {
size_t tocopy;
tocopy = ((limit < lok) ? limit : lok);
(void)memcpy(out, raw, tocopy);
limit -= tocopy;
out += tocopy;
raw += lok;
continue;
}if (lok) { ... }
char *fidx = strchr(tokens, *raw);
if (!fidx) {
/* ... */
LOG_ERROR("eCos: Unexpected XML char %c", *raw);
continue;
}if (!fidx) { ... }
uint32_t cidx = (fidx - tokens);
size_t tocopy = xmlchars[cidx].rlen;
if (limit < tocopy)
break;
escaped = true;
(void)memcpy(out, xmlchars[cidx].rs, tocopy);
limit -= tocopy;
out += tocopy;
raw++;
}while (raw && *raw && limit) { ... }
return escaped;
}{ ... }
static int ecos_check_app_info(struct rtos *rtos, struct ecos_params *param)
{
if (!rtos || !param)
return -1;
if (param->flush_common) {
if (debug_level >= LOG_LVL_DEBUG) {
for (unsigned int idx = 0; idx < ARRAY_SIZE(ecos_symbol_list); idx++) {
LOG_DEBUG("eCos: %s 0x%016" PRIX64 " %s",
rtos->symbols[idx].optional ? "OPTIONAL" : " ",
rtos->symbols[idx].address, rtos->symbols[idx].symbol_name);
}for (unsigned int idx = 0; idx < ARRAY_SIZE(ecos_symbol_list); idx++) { ... }
}if (debug_level >= LOG_LVL_DEBUG) { ... }
/* ... */
symbol_address_t thread_next_size = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_NEXT_SIZE);
if (thread_next_size != 0) {
param->pointer_width = thread_next_size;
param->uid_width = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_ID_SIZE);
param->state_width = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_STATE_SIZE);
param->thread_stack_offset = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_STACK_OFF);
param->thread_name_offset = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_NAME_OFF);
param->thread_state_offset = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_STATE_OFF);
param->thread_next_offset = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_NEXT_OFF);
param->thread_uniqueid_offset = ecos_value(rtos, ECOS_VAL_COMMON_THREAD_ID_OFF);
}if (thread_next_size != 0) { ... }
if (param->uid_width != sizeof(uint16_t)) {
/* ... */
LOG_WARNING("eCos: Unexpected unique_id width %" PRIu8, param->uid_width);
param->uid_width = (unsigned char)sizeof(uint16_t);
}if (param->uid_width != sizeof(uint16_t)) { ... }
param->stacking_info = NULL;
param->flush_common = false;
}if (param->flush_common) { ... }
return ERROR_OK;
}{ ... }
/* ... */
static int ecos_stack_layout_cortexm(struct rtos *rtos,
struct ecos_params *param, int64_t stack_ptr,
const struct rtos_register_stacking **si)
{
int retval = ERROR_OK;
/* ... */
/* ... */
if (!param->stacking_info &&
ecos_value(rtos, ECOS_VAL_CORTEXM_THREAD_SAVED) &&
ecos_value(rtos, ECOS_VAL_CORTEXM_VAL_THREAD)) {
unsigned char numoutreg = ECOS_CORTEXM_BASE_NUMREGS;
rtos_ecos_stacking.stack_registers_size = ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_THREAD_SIZE);
rtos_ecos_stacking.calculate_process_stack = rtos_generic_stack_align8;
rtos_ecos_stacking.register_offsets = rtos_ecos_regoff_cortexm;
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R0].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x00);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R1].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x04);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R2].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x08);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R3].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x0C);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R4].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x10);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R5].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x14);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R6].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x18);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R7].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x1C);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R8].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x20);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R9].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x24);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R10].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x28);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R11].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x2C);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R12].offset = (ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_REG_OFF) + 0x30);
/* ... */
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R13].offset = -2;
rtos_ecos_regoff_cortexm[ECOS_REGLIST_R14].offset = -1;
rtos_ecos_regoff_cortexm[ECOS_REGLIST_PC].offset = ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_PC_OFF);
rtos_ecos_regoff_cortexm[ECOS_REGLIST_XPSR].offset = -1;
param->stacking_info = &rtos_ecos_stacking;
/* ... */
if (retval == ERROR_OK && param->stacking_info) {
if (numoutreg > ECOS_REGLIST_BASEPRI) {
rtos_ecos_regoff_cortexm[ECOS_REGLIST_BASEPRI].offset =
ecos_value(rtos, ECOS_VAL_CORTEXM_CTX_BASEPRI_OFF);
}if (numoutreg > ECOS_REGLIST_BASEPRI) { ... }
rtos_ecos_stacking.num_output_registers = numoutreg;
}if (retval == ERROR_OK && param->stacking_info) { ... }
}if (!param->stacking_info && ecos_value(rtos, ECOS_VAL_CORTEXM_THREAD_SAVED) && ecos_value(rtos, ECOS_VAL_CORTEXM_VAL_THREAD)) { ... }
if (si)
*si = param->stacking_info;
return retval;
}{ ... }
static int ecos_stack_layout_arm(struct rtos *rtos, struct ecos_params *param,
int64_t stack_ptr, const struct rtos_register_stacking **si)
{
int retval = ERROR_OK;
if (!param->stacking_info && ecos_value(rtos, ECOS_VAL_ARM_REGSIZE)) {
/* ... */
rtos_ecos_stacking.stack_registers_size = ecos_value(rtos, ECOS_VAL_ARM_REGSIZE);
rtos_ecos_stacking.num_output_registers = ARRAY_SIZE(rtos_ecos_regoff_arm);
rtos_ecos_stacking.register_offsets = rtos_ecos_regoff_arm;
rtos_ecos_regoff_arm[0].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R0_OFF);
rtos_ecos_regoff_arm[1].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R1_OFF);
rtos_ecos_regoff_arm[2].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R2_OFF);
rtos_ecos_regoff_arm[3].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R3_OFF);
rtos_ecos_regoff_arm[4].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R4_OFF);
rtos_ecos_regoff_arm[5].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R5_OFF);
rtos_ecos_regoff_arm[6].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R6_OFF);
rtos_ecos_regoff_arm[7].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R7_OFF);
rtos_ecos_regoff_arm[8].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R8_OFF);
rtos_ecos_regoff_arm[9].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R9_OFF);
rtos_ecos_regoff_arm[10].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_R10_OFF);
rtos_ecos_regoff_arm[11].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_FP_OFF);
rtos_ecos_regoff_arm[12].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_IP_OFF);
rtos_ecos_regoff_arm[13].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_SP_OFF);
rtos_ecos_regoff_arm[14].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_LR_OFF);
rtos_ecos_regoff_arm[15].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_PC_OFF);
rtos_ecos_regoff_arm[16].offset = ecos_value(rtos, ECOS_VAL_ARM_CTX_CPSR_OFF);
param->stacking_info = &rtos_ecos_stacking;
}if (!param->stacking_info && ecos_value(rtos, ECOS_VAL_ARM_REGSIZE)) { ... }
if (si)
*si = param->stacking_info;
return retval;
}{ ... }
/* ... */
static int ecos_update_threads(struct rtos *rtos)
{
int retval;
int tasks_found = 0;
int thread_list_size = 0;
struct ecos_params *param;
if (!rtos)
return -1;
rtos_free_threadlist(rtos);
if (!rtos->rtos_specific_params)
return -3;
param = rtos->rtos_specific_params;
if (!rtos->symbols) {
/* ... */
param->flush_common = true;
LOG_ERROR("No symbols for eCos");
return -4;
}if (!rtos->symbols) { ... }
retval = ecos_check_app_info(rtos, param);
if (retval != ERROR_OK)
return retval;
if (rtos->symbols[ECOS_VAL_THREAD_LIST].address == 0) {
LOG_ERROR("Don't have the thread list head");
return -2;
}if (rtos->symbols[ECOS_VAL_THREAD_LIST].address == 0) { ... }
uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
uint32_t thread_index;
target_read_buffer(rtos->target,
thread_list_head,
param->pointer_width,
(uint8_t *) &thread_index);
uint32_t first_thread = thread_index;
/* ... */
if (first_thread) {
/* ... */
do {
thread_list_size++;
if (thread_list_size > ECOS_MAX_THREAD_COUNT) {
first_thread = 0;
thread_list_size = 0;
break;
}if (thread_list_size > ECOS_MAX_THREAD_COUNT) { ... }
retval = target_read_buffer(rtos->target,
thread_index + param->thread_next_offset,
param->pointer_width,
(uint8_t *)&thread_index);
if (retval != ERROR_OK)
return retval;
...} while (thread_index != first_thread);
}if (first_thread) { ... }
rtos->current_thread = 0;
uint32_t current_thread_addr;
retval = target_read_buffer(rtos->target,
rtos->symbols[ECOS_VAL_CURRENT_THREAD_PTR].address,
param->pointer_width,
(uint8_t *)¤t_thread_addr);
if (retval != ERROR_OK) {
LOG_ERROR("Reading active thread address");
return retval;
}if (retval != ERROR_OK) { ... }
if (current_thread_addr) {
uint16_t id = 0;
retval = target_read_buffer(rtos->target,
current_thread_addr + param->thread_uniqueid_offset,
param->uid_width,
(uint8_t *)&id);
if (retval != ERROR_OK) {
LOG_ERROR("Could not read eCos current thread from target");
return retval;
}if (retval != ERROR_OK) { ... }
rtos->current_thread = (threadid_t)id;
}if (current_thread_addr) { ... }
if (thread_list_size == 0 || rtos->current_thread == 0) {
/* ... */
static const char tmp_str[] = "Current Execution";
thread_list_size++;
tasks_found++;
rtos->thread_details = malloc(
sizeof(struct thread_detail) * thread_list_size);
/* ... */
rtos->thread_details->threadid = 0;
rtos->thread_details->exists = true;
rtos->thread_details->extra_info_str = NULL;
rtos->thread_details->thread_name_str = malloc(sizeof(tmp_str));
strcpy(rtos->thread_details->thread_name_str, tmp_str);
if (thread_list_size == 1) {
rtos->thread_count = 1;
return ERROR_OK;
}if (thread_list_size == 1) { ... }
}if (thread_list_size == 0 || rtos->current_thread == 0) { ... } else {
rtos->thread_details = malloc(
sizeof(struct thread_detail) * thread_list_size);
}else { ... }
thread_index = first_thread;
do {
#define ECOS_THREAD_NAME_STR_SIZE (200)
char tmp_str[ECOS_THREAD_NAME_STR_SIZE];
uint32_t name_ptr = 0;
uint32_t prev_thread_ptr;
/* ... */
uint16_t thread_id = 0;
retval = target_read_buffer(rtos->target,
thread_index + param->thread_uniqueid_offset,
param->uid_width,
(uint8_t *)&thread_id);
if (retval != ERROR_OK) {
LOG_ERROR("Could not read eCos thread id from target");
return retval;
}if (retval != ERROR_OK) { ... }
rtos->thread_details[tasks_found].threadid = thread_id;
retval = target_read_buffer(rtos->target,
thread_index + param->thread_name_offset,
param->pointer_width,
(uint8_t *)&name_ptr);
if (retval != ERROR_OK) {
LOG_ERROR("Could not read eCos thread name pointer from target");
return retval;
}if (retval != ERROR_OK) { ... }
retval =
target_read_buffer(rtos->target,
name_ptr,
ECOS_THREAD_NAME_STR_SIZE,
(uint8_t *)&tmp_str);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading thread name from eCos target");
return retval;
}if (retval != ERROR_OK) { ... }
tmp_str[ECOS_THREAD_NAME_STR_SIZE-1] = '\x00';
/* ... */
if (tmp_str[0] == '\x00') {
snprintf(tmp_str, ECOS_THREAD_NAME_STR_SIZE, "NoName:[0x%08" PRIX32 "]", thread_index);
}if (tmp_str[0] == '\x00') { ... } else {
/* ... */
char esc_str[ECOS_THREAD_NAME_STR_SIZE];
bool escaped = ecos_escape_string(tmp_str, esc_str, sizeof(esc_str));
if (escaped)
strcpy(tmp_str, esc_str);
}else { ... }
rtos->thread_details[tasks_found].thread_name_str =
malloc(strlen(tmp_str)+1);
strcpy(rtos->thread_details[tasks_found].thread_name_str, tmp_str);
int64_t thread_status = 0;
retval = target_read_buffer(rtos->target,
thread_index + param->thread_state_offset,
param->state_width,
(uint8_t *)&thread_status);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading thread state from eCos target");
return retval;
}if (retval != ERROR_OK) { ... }
char state_desc[21];
if (thread_status & SUSPENDED)
strcpy(state_desc, "suspended+");
else
state_desc[0] = '\0';
switch (thread_status & ~SUSPENDED) {
case RUNNING:
if (thread_index == current_thread_addr)
strcat(state_desc, "running");
else if (thread_status & SUSPENDED)
state_desc[9] = '\0';
else
strcat(state_desc, "ready");
break;case RUNNING:
case SLEEPING:
strcat(state_desc, "sleeping");
break;case SLEEPING:
case SLEEPSET:
case COUNTSLEEP:
strcat(state_desc, "counted sleep");
break;case COUNTSLEEP:
case CREATING:
strcpy(state_desc, "creating");
break;case CREATING:
case EXITED:
strcpy(state_desc, "exited");
break;case EXITED:
default:
strcpy(state_desc, "unknown state");
break;default
}switch (thread_status & ~SUSPENDED) { ... }
/* ... */
int64_t sleep_reason = 0;
if (thread_index != current_thread_addr &&
ecos_value(rtos, ECOS_VAL_COMMON_THREAD_SLEEP_SIZE)) {
retval = target_read_buffer(rtos->target,
(thread_index + ecos_value(rtos, ECOS_VAL_COMMON_THREAD_SLEEP_OFF)),
ecos_value(rtos, ECOS_VAL_COMMON_THREAD_SLEEP_SIZE),
(uint8_t *)&sleep_reason);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading thread sleep reason from eCos target");
return retval;
}if (retval != ERROR_OK) { ... }
if (sleep_reason < 0 ||
sleep_reason > (int64_t)ARRAY_SIZE(ecos_thread_reasons)) {
sleep_reason = 0;
}if (sleep_reason < 0 || sleep_reason > (int64_t)ARRAY_SIZE(ecos_thread_reasons)) { ... }
}if (thread_index != current_thread_addr && ecos_value(rtos, ECOS_VAL_COMMON_THREAD_SLEEP_SIZE)) { ... }
size_t tr_extra = 0;
const char *reason_desc = NULL;
if (sleep_reason)
reason_desc = ecos_thread_reasons[sleep_reason].desc;
if (reason_desc)
tr_extra = 2 + strlen(reason_desc) + 1;
int64_t priority = 0;
size_t pri_extra = 0;
if (ecos_value(rtos, ECOS_VAL_COMMON_THREAD_PRI_SIZE)) {
retval = target_read_buffer(rtos->target,
(thread_index + ecos_value(rtos, ECOS_VAL_COMMON_THREAD_PRI_OFF)),
ecos_value(rtos, ECOS_VAL_COMMON_THREAD_PRI_SIZE),
(uint8_t *)&priority);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading thread priority from eCos target");
return retval;
}if (retval != ERROR_OK) { ... }
pri_extra = (12 + 20);
}if (ecos_value(rtos, ECOS_VAL_COMMON_THREAD_PRI_SIZE)) { ... }
size_t eilen = (8 + strlen(state_desc) + tr_extra + pri_extra);
char *eistr = malloc(eilen);
/* ... */
if (!eistr) {
LOG_ERROR("OOM allocating extra information buffer");
return ERROR_FAIL;
}if (!eistr) { ... }
int soff = snprintf(eistr, eilen, "State: %s", state_desc);
if (tr_extra && reason_desc)
soff += snprintf(&eistr[soff], (eilen - soff), " (%s)", reason_desc);
if (pri_extra)
(void)snprintf(&eistr[soff], (eilen - soff), ", Priority: %" PRId64 "", priority);
rtos->thread_details[tasks_found].extra_info_str = eistr;
rtos->thread_details[tasks_found].exists = true;
tasks_found++;
prev_thread_ptr = thread_index;
thread_index = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
retval = target_read_buffer(rtos->target,
prev_thread_ptr + param->thread_next_offset,
param->pointer_width,
(uint8_t *) &thread_index);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading next thread pointer in eCos thread list");
return retval;
}if (retval != ERROR_OK) { ... }
...} while (thread_index != first_thread);
rtos->thread_count = tasks_found;
return ERROR_OK;
}{ ... }
static int ecos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
struct rtos_reg **reg_list, int *num_regs)
{
int retval;
struct ecos_params *param;
if (!rtos)
return -1;
if (thread_id == 0)
return -2;
if (!rtos->rtos_specific_params)
return -3;
param = rtos->rtos_specific_params;
retval = ecos_check_app_info(rtos, param);
if (retval != ERROR_OK)
return retval;
/* ... */
uint16_t id = 0;
uint32_t thread_list_head = rtos->symbols[ECOS_VAL_THREAD_LIST].address;
uint32_t thread_index;
target_read_buffer(rtos->target, thread_list_head, param->pointer_width,
(uint8_t *)&thread_index);
bool done = false;
while (!done) {
retval = target_read_buffer(rtos->target,
thread_index + param->thread_uniqueid_offset,
param->uid_width,
(uint8_t *)&id);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading unique id from eCos thread 0x%08" PRIX32 "", thread_index);
return retval;
}if (retval != ERROR_OK) { ... }
if (id == thread_id) {
done = true;
break;
}if (id == thread_id) { ... }
target_read_buffer(rtos->target,
thread_index + param->thread_next_offset,
param->pointer_width,
(uint8_t *) &thread_index);
}while (!done) { ... }
if (done) {
int64_t stack_ptr = 0;
retval = target_read_buffer(rtos->target,
thread_index + param->thread_stack_offset,
param->pointer_width,
(uint8_t *)&stack_ptr);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading stack frame from eCos thread");
return retval;
}if (retval != ERROR_OK) { ... }
if (!stack_ptr) {
LOG_ERROR("NULL stack pointer in thread %" PRIu64, thread_id);
return -5;
}if (!stack_ptr) { ... }
const struct rtos_register_stacking *stacking_info = NULL;
if (param->target_stack_layout) {
retval = param->target_stack_layout(rtos, param, stack_ptr, &stacking_info);
if (retval != ERROR_OK) {
LOG_ERROR("Error reading stack layout for eCos thread");
return retval;
}if (retval != ERROR_OK) { ... }
}if (param->target_stack_layout) { ... }
if (!stacking_info)
stacking_info = &rtos_ecos_cortex_m3_stacking;
return rtos_generic_stack_read(rtos->target,
stacking_info,
stack_ptr,
reg_list,
num_regs);
}if (done) { ... }
return -1;
}{ ... }
/* ... */
static int ecos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
{
unsigned int i;
*symbol_list = calloc(
ARRAY_SIZE(ecos_symbol_list), sizeof(struct symbol_table_elem));
/* ... */
for (i = 0; i < ARRAY_SIZE(ecos_symbol_list); i++) {
(*symbol_list)[i].symbol_name = ecos_symbol_list[i].name;
(*symbol_list)[i].optional = ecos_symbol_list[i].optional;
}for (i = 0; i < ARRAY_SIZE(ecos_symbol_list); i++) { ... }
return 0;
}{ ... }
/* ... */
static bool ecos_detect_rtos(struct target *target)
{
if ((target->rtos->symbols) &&
(target->rtos->symbols[ECOS_VAL_THREAD_LIST].address != 0)) {
return true;
}if ((target->rtos->symbols) && (target->rtos->symbols[ECOS_VAL_THREAD_LIST].address != 0)) { ... }
return false;
}{ ... }
/* ... */
static int ecos_packet_hook(struct connection *connection,
const char *packet, int packet_size)
{
int64_t current_threadid;
if (packet[0] == 'H' && packet[1] == 'g') {
int numscan = sscanf(packet, "Hg%16" SCNx64, ¤t_threadid);
if (numscan == 1 && current_threadid == 0) {
struct target *target = get_target_from_connection(connection);
if (target && target->rtos && target->rtos->rtos_specific_params) {
struct ecos_params *param;
param = target->rtos->rtos_specific_params;
param->flush_common = true;
}if (target && target->rtos && target->rtos->rtos_specific_params) { ... }
}if (numscan == 1 && current_threadid == 0) { ... }
}if (packet[0] == 'H' && packet[1] == 'g') { ... }
return rtos_thread_packet(connection, packet, packet_size);
}{ ... }
static int ecos_create(struct target *target)
{
for (unsigned int i = 0; i < ARRAY_SIZE(ecos_params_list); i++) {
const char * const *tnames = ecos_params_list[i].target_names;
while (*tnames) {
if (strcmp(*tnames, target_type_name(target)) == 0) {
target->rtos->rtos_specific_params = (void *)&ecos_params_list[i];
ecos_params_list[i].flush_common = true;
ecos_params_list[i].stacking_info = NULL;
target->rtos->current_thread = 0;
target->rtos->thread_details = NULL;
/* ... */
target->rtos->gdb_thread_packet = ecos_packet_hook;
/* ... */
return 0;
}if (strcmp(*tnames, target_type_name(target)) == 0) { ... }
tnames++;
}while (*tnames) { ... }
}for (unsigned int i = 0; i < ARRAY_SIZE(ecos_params_list); i++) { ... }
LOG_ERROR("Could not find target in eCos compatibility list");
return -1;
}{ ... }