1
2
3
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
347
348
349
350
351
352
353
354
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
388
389
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
419
420
421
422
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
490
491
492
493
494
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
577
578
579
580
581
591
592
593
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
615
616
617
618
619
620
621
622
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
650
651
652
653
654
655
656
657
658
659
660
664
665
666
667
668
669
670
671
675
676
677
678
679
680
681
682
683
684
685
686
687
691
692
693
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
721
722
723
724
725
726
727
728
729
730
731
732
733
737
738
739
740
741
742
743
744
745
746
747
748
749
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
795
796
797
798
799
800
801
802
803
804
805
809
810
811
812
813
817
818
819
820
821
822
823
824
825
826
827
828
829
830
834
835
836
837
838
839
840
844
845
846
847
848
849
859
860
861
862
866
867
868
869
870
871
872
873
874
875
884
885
886
887
888
889
890
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
954
955
956
957
958
959
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
993
994
995
996
997
998
1002
1003
1004
1005
1006
1007
1012
1013
1014
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1032
1033
1034
1038
1039
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1059
1060
1061
1065
1066
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1085
1086
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1137
1138
1139
1140
1141
1142
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1196
1197
1198
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1225
1226
1227
1228
1229
1230
1231
1235
1236
1237
1238
1239
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <jtag/jtag.h>
#include <target/register.h>
#include <target/target.h>
#include <target/breakpoints.h>
#include <target/target_type.h>
#include <helper/time_support.h>
#include <helper/fileio.h>
#include "or1k_tap.h"
#include "or1k.h"
#include "or1k_du.h"
10 includes
LIST_HEAD(tap_list);
LIST_HEAD(du_list);
static int or1k_remove_breakpoint(struct target *target,
struct breakpoint *breakpoint);
static int or1k_read_core_reg(struct target *target, int num);
static int or1k_write_core_reg(struct target *target, int num);
static struct or1k_core_reg *or1k_core_reg_list_arch_info;
static const struct or1k_core_reg_init or1k_init_reg_list[] = {
{"r0", GROUP0 + 1024, "org.gnu.gdb.or1k.group0", NULL},
{"r1", GROUP0 + 1025, "org.gnu.gdb.or1k.group0", NULL},
{"r2", GROUP0 + 1026, "org.gnu.gdb.or1k.group0", NULL},
{"r3", GROUP0 + 1027, "org.gnu.gdb.or1k.group0", NULL},
{"r4", GROUP0 + 1028, "org.gnu.gdb.or1k.group0", NULL},
{"r5", GROUP0 + 1029, "org.gnu.gdb.or1k.group0", NULL},
{"r6", GROUP0 + 1030, "org.gnu.gdb.or1k.group0", NULL},
{"r7", GROUP0 + 1031, "org.gnu.gdb.or1k.group0", NULL},
{"r8", GROUP0 + 1032, "org.gnu.gdb.or1k.group0", NULL},
{"r9", GROUP0 + 1033, "org.gnu.gdb.or1k.group0", NULL},
{"r10", GROUP0 + 1034, "org.gnu.gdb.or1k.group0", NULL},
{"r11", GROUP0 + 1035, "org.gnu.gdb.or1k.group0", NULL},
{"r12", GROUP0 + 1036, "org.gnu.gdb.or1k.group0", NULL},
{"r13", GROUP0 + 1037, "org.gnu.gdb.or1k.group0", NULL},
{"r14", GROUP0 + 1038, "org.gnu.gdb.or1k.group0", NULL},
{"r15", GROUP0 + 1039, "org.gnu.gdb.or1k.group0", NULL},
{"r16", GROUP0 + 1040, "org.gnu.gdb.or1k.group0", NULL},
{"r17", GROUP0 + 1041, "org.gnu.gdb.or1k.group0", NULL},
{"r18", GROUP0 + 1042, "org.gnu.gdb.or1k.group0", NULL},
{"r19", GROUP0 + 1043, "org.gnu.gdb.or1k.group0", NULL},
{"r20", GROUP0 + 1044, "org.gnu.gdb.or1k.group0", NULL},
{"r21", GROUP0 + 1045, "org.gnu.gdb.or1k.group0", NULL},
{"r22", GROUP0 + 1046, "org.gnu.gdb.or1k.group0", NULL},
{"r23", GROUP0 + 1047, "org.gnu.gdb.or1k.group0", NULL},
{"r24", GROUP0 + 1048, "org.gnu.gdb.or1k.group0", NULL},
{"r25", GROUP0 + 1049, "org.gnu.gdb.or1k.group0", NULL},
{"r26", GROUP0 + 1050, "org.gnu.gdb.or1k.group0", NULL},
{"r27", GROUP0 + 1051, "org.gnu.gdb.or1k.group0", NULL},
{"r28", GROUP0 + 1052, "org.gnu.gdb.or1k.group0", NULL},
{"r29", GROUP0 + 1053, "org.gnu.gdb.or1k.group0", NULL},
{"r30", GROUP0 + 1054, "org.gnu.gdb.or1k.group0", NULL},
{"r31", GROUP0 + 1055, "org.gnu.gdb.or1k.group0", NULL},
{"ppc", GROUP0 + 18, "org.gnu.gdb.or1k.group0", NULL},
{"npc", GROUP0 + 16, "org.gnu.gdb.or1k.group0", NULL},
{"sr", GROUP0 + 17, "org.gnu.gdb.or1k.group0", NULL},
{"vr", GROUP0 + 0, "org.gnu.gdb.or1k.group0", "system"},
{"upr", GROUP0 + 1, "org.gnu.gdb.or1k.group0", "system"},
{"cpucfgr", GROUP0 + 2, "org.gnu.gdb.or1k.group0", "system"},
{"dmmucfgr", GROUP0 + 3, "org.gnu.gdb.or1k.group0", "system"},
{"immucfgr", GROUP0 + 4, "org.gnu.gdb.or1k.group0", "system"},
{"dccfgr", GROUP0 + 5, "org.gnu.gdb.or1k.group0", "system"},
{"iccfgr", GROUP0 + 6, "org.gnu.gdb.or1k.group0", "system"},
{"dcfgr", GROUP0 + 7, "org.gnu.gdb.or1k.group0", "system"},
{"pccfgr", GROUP0 + 8, "org.gnu.gdb.or1k.group0", "system"},
{"fpcsr", GROUP0 + 20, "org.gnu.gdb.or1k.group0", "system"},
{"epcr0", GROUP0 + 32, "org.gnu.gdb.or1k.group0", "system"},
{"epcr1", GROUP0 + 33, "org.gnu.gdb.or1k.group0", "system"},
{"epcr2", GROUP0 + 34, "org.gnu.gdb.or1k.group0", "system"},
{"epcr3", GROUP0 + 35, "org.gnu.gdb.or1k.group0", "system"},
{"epcr4", GROUP0 + 36, "org.gnu.gdb.or1k.group0", "system"},
{"epcr5", GROUP0 + 37, "org.gnu.gdb.or1k.group0", "system"},
{"epcr6", GROUP0 + 38, "org.gnu.gdb.or1k.group0", "system"},
{"epcr7", GROUP0 + 39, "org.gnu.gdb.or1k.group0", "system"},
{"epcr8", GROUP0 + 40, "org.gnu.gdb.or1k.group0", "system"},
{"epcr9", GROUP0 + 41, "org.gnu.gdb.or1k.group0", "system"},
{"epcr10", GROUP0 + 42, "org.gnu.gdb.or1k.group0", "system"},
{"epcr11", GROUP0 + 43, "org.gnu.gdb.or1k.group0", "system"},
{"epcr12", GROUP0 + 44, "org.gnu.gdb.or1k.group0", "system"},
{"epcr13", GROUP0 + 45, "org.gnu.gdb.or1k.group0", "system"},
{"epcr14", GROUP0 + 46, "org.gnu.gdb.or1k.group0", "system"},
{"epcr15", GROUP0 + 47, "org.gnu.gdb.or1k.group0", "system"},
{"eear0", GROUP0 + 48, "org.gnu.gdb.or1k.group0", "system"},
{"eear1", GROUP0 + 49, "org.gnu.gdb.or1k.group0", "system"},
{"eear2", GROUP0 + 50, "org.gnu.gdb.or1k.group0", "system"},
{"eear3", GROUP0 + 51, "org.gnu.gdb.or1k.group0", "system"},
{"eear4", GROUP0 + 52, "org.gnu.gdb.or1k.group0", "system"},
{"eear5", GROUP0 + 53, "org.gnu.gdb.or1k.group0", "system"},
{"eear6", GROUP0 + 54, "org.gnu.gdb.or1k.group0", "system"},
{"eear7", GROUP0 + 55, "org.gnu.gdb.or1k.group0", "system"},
{"eear8", GROUP0 + 56, "org.gnu.gdb.or1k.group0", "system"},
{"eear9", GROUP0 + 57, "org.gnu.gdb.or1k.group0", "system"},
{"eear10", GROUP0 + 58, "org.gnu.gdb.or1k.group0", "system"},
{"eear11", GROUP0 + 59, "org.gnu.gdb.or1k.group0", "system"},
{"eear12", GROUP0 + 60, "org.gnu.gdb.or1k.group0", "system"},
{"eear13", GROUP0 + 61, "org.gnu.gdb.or1k.group0", "system"},
{"eear14", GROUP0 + 62, "org.gnu.gdb.or1k.group0", "system"},
{"eear15", GROUP0 + 63, "org.gnu.gdb.or1k.group0", "system"},
{"esr0", GROUP0 + 64, "org.gnu.gdb.or1k.group0", "system"},
{"esr1", GROUP0 + 65, "org.gnu.gdb.or1k.group0", "system"},
{"esr2", GROUP0 + 66, "org.gnu.gdb.or1k.group0", "system"},
{"esr3", GROUP0 + 67, "org.gnu.gdb.or1k.group0", "system"},
{"esr4", GROUP0 + 68, "org.gnu.gdb.or1k.group0", "system"},
{"esr5", GROUP0 + 69, "org.gnu.gdb.or1k.group0", "system"},
{"esr6", GROUP0 + 70, "org.gnu.gdb.or1k.group0", "system"},
{"esr7", GROUP0 + 71, "org.gnu.gdb.or1k.group0", "system"},
{"esr8", GROUP0 + 72, "org.gnu.gdb.or1k.group0", "system"},
{"esr9", GROUP0 + 73, "org.gnu.gdb.or1k.group0", "system"},
{"esr10", GROUP0 + 74, "org.gnu.gdb.or1k.group0", "system"},
{"esr11", GROUP0 + 75, "org.gnu.gdb.or1k.group0", "system"},
{"esr12", GROUP0 + 76, "org.gnu.gdb.or1k.group0", "system"},
{"esr13", GROUP0 + 77, "org.gnu.gdb.or1k.group0", "system"},
{"esr14", GROUP0 + 78, "org.gnu.gdb.or1k.group0", "system"},
{"esr15", GROUP0 + 79, "org.gnu.gdb.or1k.group0", "system"},
{"dmmuucr", GROUP1 + 0, "org.gnu.gdb.or1k.group1", "dmmu"},
{"dmmuupr", GROUP1 + 1, "org.gnu.gdb.or1k.group1", "dmmu"},
{"dtlbeir", GROUP1 + 2, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbmr0", GROUP1 + 4, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbmr1", GROUP1 + 5, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbmr2", GROUP1 + 6, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbmr3", GROUP1 + 7, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbtr0", GROUP1 + 8, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbtr1", GROUP1 + 9, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbtr2", GROUP1 + 10, "org.gnu.gdb.or1k.group1", "dmmu"},
{"datbtr3", GROUP1 + 11, "org.gnu.gdb.or1k.group1", "dmmu"},
{"immucr", GROUP2 + 0, "org.gnu.gdb.or1k.group2", "immu"},
{"immupr", GROUP2 + 1, "org.gnu.gdb.or1k.group2", "immu"},
{"itlbeir", GROUP2 + 2, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbmr0", GROUP2 + 4, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbmr1", GROUP2 + 5, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbmr2", GROUP2 + 6, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbmr3", GROUP2 + 7, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbtr0", GROUP2 + 8, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbtr1", GROUP2 + 9, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbtr2", GROUP2 + 10, "org.gnu.gdb.or1k.group2", "immu"},
{"iatbtr3", GROUP2 + 11, "org.gnu.gdb.or1k.group2", "immu"},
{"dccr", GROUP3 + 0, "org.gnu.gdb.or1k.group3", "dcache"},
{"dcbpr", GROUP3 + 1, "org.gnu.gdb.or1k.group3", "dcache"},
{"dcbfr", GROUP3 + 2, "org.gnu.gdb.or1k.group3", "dcache"},
{"dcbir", GROUP3 + 3, "org.gnu.gdb.or1k.group3", "dcache"},
{"dcbwr", GROUP3 + 4, "org.gnu.gdb.or1k.group3", "dcache"},
{"dcblr", GROUP3 + 5, "org.gnu.gdb.or1k.group3", "dcache"},
{"iccr", GROUP4 + 0, "org.gnu.gdb.or1k.group4", "icache"},
{"icbpr", GROUP4 + 1, "org.gnu.gdb.or1k.group4", "icache"},
{"icbir", GROUP4 + 2, "org.gnu.gdb.or1k.group4", "icache"},
{"icblr", GROUP4 + 3, "org.gnu.gdb.or1k.group4", "icache"},
{"maclo", GROUP5 + 0, "org.gnu.gdb.or1k.group5", "mac"},
{"machi", GROUP5 + 1, "org.gnu.gdb.or1k.group5", "mac"},
{"dvr0", GROUP6 + 0, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr1", GROUP6 + 1, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr2", GROUP6 + 2, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr3", GROUP6 + 3, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr4", GROUP6 + 4, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr5", GROUP6 + 5, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr6", GROUP6 + 6, "org.gnu.gdb.or1k.group6", "debug"},
{"dvr7", GROUP6 + 7, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr0", GROUP6 + 8, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr1", GROUP6 + 9, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr2", GROUP6 + 10, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr3", GROUP6 + 11, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr4", GROUP6 + 12, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr5", GROUP6 + 13, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr6", GROUP6 + 14, "org.gnu.gdb.or1k.group6", "debug"},
{"dcr7", GROUP6 + 15, "org.gnu.gdb.or1k.group6", "debug"},
{"dmr1", GROUP6 + 16, "org.gnu.gdb.or1k.group6", "debug"},
{"dmr2", GROUP6 + 17, "org.gnu.gdb.or1k.group6", "debug"},
{"dcwr0", GROUP6 + 18, "org.gnu.gdb.or1k.group6", "debug"},
{"dcwr1", GROUP6 + 19, "org.gnu.gdb.or1k.group6", "debug"},
{"dsr", GROUP6 + 20, "org.gnu.gdb.or1k.group6", "debug"},
{"drr", GROUP6 + 21, "org.gnu.gdb.or1k.group6", "debug"},
{"pccr0", GROUP7 + 0, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr1", GROUP7 + 1, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr2", GROUP7 + 2, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr3", GROUP7 + 3, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr4", GROUP7 + 4, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr5", GROUP7 + 5, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr6", GROUP7 + 6, "org.gnu.gdb.or1k.group7", "perf"},
{"pccr7", GROUP7 + 7, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr0", GROUP7 + 8, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr1", GROUP7 + 9, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr2", GROUP7 + 10, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr3", GROUP7 + 11, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr4", GROUP7 + 12, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr5", GROUP7 + 13, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr6", GROUP7 + 14, "org.gnu.gdb.or1k.group7", "perf"},
{"pcmr7", GROUP7 + 15, "org.gnu.gdb.or1k.group7", "perf"},
{"pmr", GROUP8 + 0, "org.gnu.gdb.or1k.group8", "power"},
{"picmr", GROUP9 + 0, "org.gnu.gdb.or1k.group9", "pic"},
{"picsr", GROUP9 + 2, "org.gnu.gdb.or1k.group9", "pic"},
{"ttmr", GROUP10 + 0, "org.gnu.gdb.or1k.group10", "timer"},
{"ttcr", GROUP10 + 1, "org.gnu.gdb.or1k.group10", "timer"},
...};
static int or1k_add_reg(struct target *target, struct or1k_core_reg *new_reg)
{
struct or1k_common *or1k = target_to_or1k(target);
int reg_list_size = or1k->nb_regs * sizeof(struct or1k_core_reg);
or1k_core_reg_list_arch_info = realloc(or1k_core_reg_list_arch_info,
reg_list_size + sizeof(struct or1k_core_reg));
memcpy(&or1k_core_reg_list_arch_info[or1k->nb_regs], new_reg,
sizeof(struct or1k_core_reg));
or1k_core_reg_list_arch_info[or1k->nb_regs].list_num = or1k->nb_regs;
or1k->nb_regs++;
return ERROR_OK;
}{ ... }
static int or1k_create_reg_list(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
LOG_DEBUG("-");
or1k_core_reg_list_arch_info = malloc(ARRAY_SIZE(or1k_init_reg_list) *
sizeof(struct or1k_core_reg));
for (int i = 0; i < (int)ARRAY_SIZE(or1k_init_reg_list); i++) {
or1k_core_reg_list_arch_info[i].name = or1k_init_reg_list[i].name;
or1k_core_reg_list_arch_info[i].spr_num = or1k_init_reg_list[i].spr_num;
or1k_core_reg_list_arch_info[i].group = or1k_init_reg_list[i].group;
or1k_core_reg_list_arch_info[i].feature = or1k_init_reg_list[i].feature;
or1k_core_reg_list_arch_info[i].list_num = i;
or1k_core_reg_list_arch_info[i].target = NULL;
or1k_core_reg_list_arch_info[i].or1k_common = NULL;
}for (int i = 0; i < (int)ARRAY_SIZE(or1k_init_reg_list); i++) { ... }
or1k->nb_regs = ARRAY_SIZE(or1k_init_reg_list);
struct or1k_core_reg new_reg;
new_reg.target = NULL;
new_reg.or1k_common = NULL;
char name[32];
for (int way = 0; way < 4; way++) {
for (int i = 0; i < 128; i++) {
sprintf(name, "dtlbw%dmr%d", way, i);
new_reg.name = strdup(name);
new_reg.spr_num = GROUP1 + 512 + i + (way * 256);
new_reg.feature = "org.gnu.gdb.or1k.group1";
new_reg.group = "dmmu";
or1k_add_reg(target, &new_reg);
sprintf(name, "dtlbw%dtr%d", way, i);
new_reg.name = strdup(name);
new_reg.spr_num = GROUP1 + 640 + i + (way * 256);
new_reg.feature = "org.gnu.gdb.or1k.group1";
new_reg.group = "dmmu";
or1k_add_reg(target, &new_reg);
sprintf(name, "itlbw%dmr%d", way, i);
new_reg.name = strdup(name);
new_reg.spr_num = GROUP2 + 512 + i + (way * 256);
new_reg.feature = "org.gnu.gdb.or1k.group2";
new_reg.group = "immu";
or1k_add_reg(target, &new_reg);
sprintf(name, "itlbw%dtr%d", way, i);
new_reg.name = strdup(name);
new_reg.spr_num = GROUP2 + 640 + i + (way * 256);
new_reg.feature = "org.gnu.gdb.or1k.group2";
new_reg.group = "immu";
or1k_add_reg(target, &new_reg);
}for (int i = 0; i < 128; i++) { ... }
}for (int way = 0; way < 4; way++) { ... }
return ERROR_OK;
}{ ... }
static int or1k_jtag_read_regs(struct or1k_common *or1k, uint32_t *regs)
{
struct or1k_du *du_core = or1k_jtag_to_du(&or1k->jtag);
LOG_DEBUG("-");
return du_core->or1k_jtag_read_cpu(&or1k->jtag,
or1k->arch_info[OR1K_REG_R0].spr_num, OR1K_REG_R31 + 1,
regs + OR1K_REG_R0);
}{ ... }
static int or1k_jtag_write_regs(struct or1k_common *or1k, uint32_t *regs)
{
struct or1k_du *du_core = or1k_jtag_to_du(&or1k->jtag);
LOG_DEBUG("-");
return du_core->or1k_jtag_write_cpu(&or1k->jtag,
or1k->arch_info[OR1K_REG_R0].spr_num, OR1K_REG_R31 + 1,
®s[OR1K_REG_R0]);
}{ ... }
static int or1k_save_context(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
int regs_read = 0;
int retval;
LOG_DEBUG("-");
for (int i = 0; i < OR1KNUMCOREREGS; i++) {
if (!or1k->core_cache->reg_list[i].valid) {
if (i == OR1K_REG_PPC || i == OR1K_REG_NPC || i == OR1K_REG_SR) {
retval = du_core->or1k_jtag_read_cpu(&or1k->jtag,
or1k->arch_info[i].spr_num, 1,
&or1k->core_regs[i]);
if (retval != ERROR_OK)
return retval;
}if (i == OR1K_REG_PPC || i == OR1K_REG_NPC || i == OR1K_REG_SR) { ... } else if (!regs_read) {
retval = or1k_jtag_read_regs(or1k, or1k->core_regs);
if (retval != ERROR_OK)
return retval;
regs_read = 1;
}else if (!regs_read) { ... }
/* ... */
or1k_read_core_reg(target, i);
}if (!or1k->core_cache->reg_list[i].valid) { ... }
}for (int i = 0; i < OR1KNUMCOREREGS; i++) { ... }
return ERROR_OK;
}{ ... }
static int or1k_restore_context(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
int reg_write = 0;
int retval;
LOG_DEBUG("-");
for (int i = 0; i < OR1KNUMCOREREGS; i++) {
if (or1k->core_cache->reg_list[i].dirty) {
or1k_write_core_reg(target, i);
if (i == OR1K_REG_PPC || i == OR1K_REG_NPC || i == OR1K_REG_SR) {
retval = du_core->or1k_jtag_write_cpu(&or1k->jtag,
or1k->arch_info[i].spr_num, 1,
&or1k->core_regs[i]);
if (retval != ERROR_OK) {
LOG_ERROR("Error while restoring context");
return retval;
}if (retval != ERROR_OK) { ... }
}if (i == OR1K_REG_PPC || i == OR1K_REG_NPC || i == OR1K_REG_SR) { ... } else
reg_write = 1;
}if (or1k->core_cache->reg_list[i].dirty) { ... }
}for (int i = 0; i < OR1KNUMCOREREGS; i++) { ... }
if (reg_write) {
retval = or1k_jtag_write_regs(or1k, or1k->core_regs);
if (retval != ERROR_OK) {
LOG_ERROR("Error while restoring context");
return retval;
}if (retval != ERROR_OK) { ... }
}if (reg_write) { ... }
return ERROR_OK;
}{ ... }
static int or1k_read_core_reg(struct target *target, int num)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
uint32_t reg_value;
LOG_DEBUG("-");
if ((num < 0) || (num >= or1k->nb_regs))
return ERROR_COMMAND_SYNTAX_ERROR;
if ((num >= 0) && (num < OR1KNUMCOREREGS)) {
reg_value = or1k->core_regs[num];
buf_set_u32(or1k->core_cache->reg_list[num].value, 0, 32, reg_value);
LOG_DEBUG("Read core reg %i value 0x%08" PRIx32, num, reg_value);
or1k->core_cache->reg_list[num].valid = true;
or1k->core_cache->reg_list[num].dirty = false;
}if ((num >= 0) && (num < OR1KNUMCOREREGS)) { ... } else {
int retval = du_core->or1k_jtag_read_cpu(&or1k->jtag,
or1k->arch_info[num].spr_num, 1, ®_value);
if (retval != ERROR_OK) {
LOG_ERROR("Error while reading spr 0x%08" PRIx32, or1k->arch_info[num].spr_num);
return retval;
}if (retval != ERROR_OK) { ... }
buf_set_u32(or1k->core_cache->reg_list[num].value, 0, 32, reg_value);
LOG_DEBUG("Read spr reg %i value 0x%08" PRIx32, num, reg_value);
}else { ... }
return ERROR_OK;
}{ ... }
static int or1k_write_core_reg(struct target *target, int num)
{
struct or1k_common *or1k = target_to_or1k(target);
LOG_DEBUG("-");
if ((num < 0) || (num >= OR1KNUMCOREREGS))
return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t reg_value = buf_get_u32(or1k->core_cache->reg_list[num].value, 0, 32);
or1k->core_regs[num] = reg_value;
LOG_DEBUG("Write core reg %i value 0x%08" PRIx32, num, reg_value);
or1k->core_cache->reg_list[num].valid = true;
or1k->core_cache->reg_list[num].dirty = false;
return ERROR_OK;
}{ ... }
static int or1k_get_core_reg(struct reg *reg)
{
struct or1k_core_reg *or1k_reg = reg->arch_info;
struct target *target = or1k_reg->target;
LOG_DEBUG("-");
if (target->state != TARGET_HALTED)
return ERROR_TARGET_NOT_HALTED;
return or1k_read_core_reg(target, or1k_reg->list_num);
}{ ... }
static int or1k_set_core_reg(struct reg *reg, uint8_t *buf)
{
struct or1k_core_reg *or1k_reg = reg->arch_info;
struct target *target = or1k_reg->target;
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
uint32_t value = buf_get_u32(buf, 0, 32);
LOG_DEBUG("-");
if (target->state != TARGET_HALTED)
return ERROR_TARGET_NOT_HALTED;
if (or1k_reg->list_num < OR1KNUMCOREREGS) {
buf_set_u32(reg->value, 0, 32, value);
reg->dirty = true;
reg->valid = true;
}if (or1k_reg->list_num < OR1KNUMCOREREGS) { ... } else {
int retval = du_core->or1k_jtag_write_cpu(&or1k->jtag,
or1k_reg->spr_num, 1, &value);
if (retval != ERROR_OK) {
LOG_ERROR("Error while writing spr 0x%08" PRIx32, or1k_reg->spr_num);
return retval;
}if (retval != ERROR_OK) { ... }
}else { ... }
return ERROR_OK;
}{ ... }
static const struct reg_arch_type or1k_reg_type = {
.get = or1k_get_core_reg,
.set = or1k_set_core_reg,
...};
static struct reg_cache *or1k_build_reg_cache(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
struct reg_cache *cache = malloc(sizeof(struct reg_cache));
struct reg *reg_list = calloc(or1k->nb_regs, sizeof(struct reg));
struct or1k_core_reg *arch_info =
malloc((or1k->nb_regs) * sizeof(struct or1k_core_reg));
struct reg_feature *feature;
LOG_DEBUG("-");
cache->name = "OpenRISC 1000 registers";
cache->next = NULL;
cache->reg_list = reg_list;
cache->num_regs = or1k->nb_regs;
(*cache_p) = cache;
or1k->core_cache = cache;
or1k->arch_info = arch_info;
for (int i = 0; i < or1k->nb_regs; i++) {
arch_info[i] = or1k_core_reg_list_arch_info[i];
arch_info[i].target = target;
arch_info[i].or1k_common = or1k;
reg_list[i].name = or1k_core_reg_list_arch_info[i].name;
feature = malloc(sizeof(struct reg_feature));
feature->name = or1k_core_reg_list_arch_info[i].feature;
reg_list[i].feature = feature;
reg_list[i].group = or1k_core_reg_list_arch_info[i].group;
reg_list[i].size = 32;
reg_list[i].value = calloc(1, 4);
reg_list[i].dirty = false;
reg_list[i].valid = false;
reg_list[i].type = &or1k_reg_type;
reg_list[i].arch_info = &arch_info[i];
reg_list[i].number = i;
reg_list[i].exist = true;
}for (int i = 0; i < or1k->nb_regs; i++) { ... }
return cache;
}{ ... }
static int or1k_debug_entry(struct target *target)
{
LOG_DEBUG("-");
int retval = or1k_save_context(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_save_context");
return retval;
}if (retval != ERROR_OK) { ... }
struct or1k_common *or1k = target_to_or1k(target);
uint32_t addr = or1k->core_regs[OR1K_REG_NPC];
if (breakpoint_find(target, addr))
retval = or1k_set_core_reg(&or1k->core_cache->reg_list[OR1K_REG_NPC],
(uint8_t *)&addr);
return retval;
}{ ... }
static int or1k_halt(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("target->state: %s",
target_state_name(target));
if (target->state == TARGET_HALTED) {
LOG_DEBUG("Target was already halted");
return ERROR_OK;
}if (target->state == TARGET_HALTED) { ... }
if (target->state == TARGET_UNKNOWN)
LOG_WARNING("Target was in unknown state when halt was requested");
if (target->state == TARGET_RESET) {
if ((jtag_get_reset_config() & RESET_SRST_PULLS_TRST) &&
jtag_get_srst()) {
LOG_ERROR("Can't request a halt while in reset if nSRST pulls nTRST");
return ERROR_TARGET_FAILURE;
}if ((jtag_get_reset_config() & RESET_SRST_PULLS_TRST) && jtag_get_srst()) { ... } else {
target->debug_reason = DBG_REASON_DBGRQ;
return ERROR_OK;
}else { ... }
}if (target->state == TARGET_RESET) { ... }
int retval = du_core->or1k_cpu_stall(&or1k->jtag, CPU_STALL);
if (retval != ERROR_OK) {
LOG_ERROR("Impossible to stall the CPU");
return retval;
}if (retval != ERROR_OK) { ... }
target->debug_reason = DBG_REASON_DBGRQ;
return ERROR_OK;
}{ ... }
static int or1k_is_cpu_running(struct target *target, int *running)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
int retval;
int tries = 0;
const int RETRIES_MAX = 5;
/* ... */
while (tries < RETRIES_MAX) {
tries++;
retval = du_core->or1k_is_cpu_running(&or1k->jtag, running);
if (retval != ERROR_OK) {
LOG_WARNING("Debug IF CPU control reg read failure.");
/* ... */
LOG_WARNING("Resetting JTAG TAP state and reconnecting to debug IF.");
du_core->or1k_jtag_init(&or1k->jtag);
LOG_WARNING("...attempt %d of %d", tries, RETRIES_MAX);
alive_sleep(2);
continue;
}if (retval != ERROR_OK) { ... } else
return ERROR_OK;
}while (tries < RETRIES_MAX) { ... }
LOG_ERROR("Could not re-establish communication with target");
return retval;
}{ ... }
static int or1k_poll(struct target *target)
{
int retval;
int running;
retval = or1k_is_cpu_running(target, &running);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_is_cpu_running");
return retval;
}if (retval != ERROR_OK) { ... }
if (!running) {
if ((target->state == TARGET_RUNNING) ||
(target->state == TARGET_RESET)) {
target->state = TARGET_HALTED;
retval = or1k_debug_entry(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_debug_entry");
return retval;
}if (retval != ERROR_OK) { ... }
target_call_event_callbacks(target,
TARGET_EVENT_HALTED);
}if ((target->state == TARGET_RUNNING) || (target->state == TARGET_RESET)) { ... } else if (target->state == TARGET_DEBUG_RUNNING) {
target->state = TARGET_HALTED;
retval = or1k_debug_entry(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_debug_entry");
return retval;
}if (retval != ERROR_OK) { ... }
target_call_event_callbacks(target,
TARGET_EVENT_DEBUG_HALTED);
}else if (target->state == TARGET_DEBUG_RUNNING) { ... }
}if (!running) { ... } else {
if (target->state == TARGET_HALTED) {
target->state = TARGET_RUNNING;
retval = or1k_halt(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_halt");
return retval;
}if (retval != ERROR_OK) { ... }
retval = or1k_debug_entry(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_debug_entry");
return retval;
}if (retval != ERROR_OK) { ... }
target_call_event_callbacks(target,
TARGET_EVENT_DEBUG_HALTED);
}if (target->state == TARGET_HALTED) { ... }
target->state = TARGET_RUNNING;
}else { ... }
return ERROR_OK;
}{ ... }
static int or1k_assert_reset(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("-");
int retval = du_core->or1k_cpu_reset(&or1k->jtag, CPU_RESET);
if (retval != ERROR_OK) {
LOG_ERROR("Error while asserting RESET");
return retval;
}if (retval != ERROR_OK) { ... }
return ERROR_OK;
}{ ... }
static int or1k_deassert_reset(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("-");
int retval = du_core->or1k_cpu_reset(&or1k->jtag, CPU_NOT_RESET);
if (retval != ERROR_OK) {
LOG_ERROR("Error while deasserting RESET");
return retval;
}if (retval != ERROR_OK) { ... }
return ERROR_OK;
}{ ... }
static int or1k_soft_reset_halt(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("-");
int retval = du_core->or1k_cpu_stall(&or1k->jtag, CPU_STALL);
if (retval != ERROR_OK) {
LOG_ERROR("Error while stalling the CPU");
return retval;
}if (retval != ERROR_OK) { ... }
retval = or1k_assert_reset(target);
if (retval != ERROR_OK)
return retval;
retval = or1k_deassert_reset(target);
if (retval != ERROR_OK)
return retval;
return ERROR_OK;
}{ ... }
static bool is_any_soft_breakpoint(struct target *target)
{
struct breakpoint *breakpoint = target->breakpoints;
LOG_DEBUG("-");
while (breakpoint)
if (breakpoint->type == BKPT_SOFT)
return true;
return false;
}{ ... }
static int or1k_resume_or_step(struct target *target, int current,
uint32_t address, int handle_breakpoints,
int debug_execution, int step)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
struct breakpoint *breakpoint = NULL;
uint32_t resume_pc;
uint32_t debug_reg_list[OR1K_DEBUG_REG_NUM];
LOG_DEBUG("Addr: 0x%" PRIx32 ", stepping: %s, handle breakpoints %s\n",
address, step ? "yes" : "no", handle_breakpoints ? "yes" : "no");
if (target->state != TARGET_HALTED) {
LOG_TARGET_ERROR(target, "not halted");
return ERROR_TARGET_NOT_HALTED;
}if (target->state != TARGET_HALTED) { ... }
if (!debug_execution)
target_free_all_working_areas(target);
if (!current)
buf_set_u32(or1k->core_cache->reg_list[OR1K_REG_NPC].value, 0,
32, address);
int retval = or1k_restore_context(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_restore_context");
return retval;
}if (retval != ERROR_OK) { ... }
retval = du_core->or1k_jtag_read_cpu(&or1k->jtag, OR1K_DMR1_CPU_REG_ADD,
OR1K_DEBUG_REG_NUM, debug_reg_list);
if (retval != ERROR_OK) {
LOG_ERROR("Error while reading debug registers");
return retval;
}if (retval != ERROR_OK) { ... }
debug_reg_list[OR1K_DEBUG_REG_DRR] = 0;
debug_reg_list[OR1K_DEBUG_REG_DMR2] &= ~OR1K_DMR2_WGB;
if (step)
debug_reg_list[OR1K_DEBUG_REG_DMR1] |= OR1K_DMR1_ST | OR1K_DMR1_BT;
else
debug_reg_list[OR1K_DEBUG_REG_DMR1] &= ~(OR1K_DMR1_ST | OR1K_DMR1_BT);
/* ... */
if (is_any_soft_breakpoint(target) == true)
debug_reg_list[OR1K_DEBUG_REG_DSR] |= OR1K_DSR_TE;
retval = du_core->or1k_jtag_write_cpu(&or1k->jtag, OR1K_DMR1_CPU_REG_ADD,
OR1K_DEBUG_REG_NUM, debug_reg_list);
if (retval != ERROR_OK) {
LOG_ERROR("Error while writing back debug registers");
return retval;
}if (retval != ERROR_OK) { ... }
resume_pc = buf_get_u32(or1k->core_cache->reg_list[OR1K_REG_NPC].value,
0, 32);
if (handle_breakpoints) {
breakpoint = breakpoint_find(target, resume_pc);
if (breakpoint) {
LOG_DEBUG("Unset breakpoint at 0x%08" TARGET_PRIxADDR, breakpoint->address);
retval = or1k_remove_breakpoint(target, breakpoint);
if (retval != ERROR_OK)
return retval;
}if (breakpoint) { ... }
}if (handle_breakpoints) { ... }
retval = du_core->or1k_cpu_stall(&or1k->jtag, CPU_UNSTALL);
if (retval != ERROR_OK) {
LOG_ERROR("Error while unstalling the CPU");
return retval;
}if (retval != ERROR_OK) { ... }
if (step)
target->debug_reason = DBG_REASON_SINGLESTEP;
else
target->debug_reason = DBG_REASON_NOTHALTED;
register_cache_invalidate(or1k->core_cache);
if (!debug_execution) {
target->state = TARGET_RUNNING;
target_call_event_callbacks(target, TARGET_EVENT_RESUMED);
LOG_DEBUG("Target resumed at 0x%08" PRIx32, resume_pc);
}if (!debug_execution) { ... } else {
target->state = TARGET_DEBUG_RUNNING;
target_call_event_callbacks(target, TARGET_EVENT_DEBUG_RESUMED);
LOG_DEBUG("Target debug resumed at 0x%08" PRIx32, resume_pc);
}else { ... }
return ERROR_OK;
}{ ... }
static int or1k_resume(struct target *target, int current,
target_addr_t address, int handle_breakpoints,
int debug_execution)
{
return or1k_resume_or_step(target, current, address,
handle_breakpoints,
debug_execution,
NO_SINGLE_STEP);
}{ ... }
static int or1k_step(struct target *target, int current,
target_addr_t address, int handle_breakpoints)
{
return or1k_resume_or_step(target, current, address,
handle_breakpoints,
0,
SINGLE_STEP);
}{ ... }
static int or1k_add_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
uint8_t data;
LOG_DEBUG("Adding breakpoint: addr 0x%08" TARGET_PRIxADDR ", len %d, type %d, id: %" PRIu32,
breakpoint->address, breakpoint->length, breakpoint->type,
breakpoint->unique_id);
if (breakpoint->type == BKPT_HARD)
LOG_ERROR("HW breakpoints not supported for now. Doing SW breakpoint.");
int retval = du_core->or1k_jtag_read_memory(&or1k->jtag,
breakpoint->address,
4,
1,
&data);
if (retval != ERROR_OK) {
LOG_ERROR("Error while reading the instruction at 0x%08" TARGET_PRIxADDR,
breakpoint->address);
return retval;
}if (retval != ERROR_OK) { ... }
free(breakpoint->orig_instr);
breakpoint->orig_instr = malloc(breakpoint->length);
memcpy(breakpoint->orig_instr, &data, breakpoint->length);
uint8_t or1k_trap_insn[4];
target_buffer_set_u32(target, or1k_trap_insn, OR1K_TRAP_INSTR);
retval = du_core->or1k_jtag_write_memory(&or1k->jtag,
breakpoint->address,
4,
1,
or1k_trap_insn);
if (retval != ERROR_OK) {
LOG_ERROR("Error while writing OR1K_TRAP_INSTR at 0x%08" TARGET_PRIxADDR,
breakpoint->address);
return retval;
}if (retval != ERROR_OK) { ... }
uint32_t addr = breakpoint->address;
retval = du_core->or1k_jtag_write_cpu(&or1k->jtag,
OR1K_ICBIR_CPU_REG_ADD, 1, &addr);
if (retval != ERROR_OK) {
LOG_ERROR("Error while invalidating the ICACHE");
return retval;
}if (retval != ERROR_OK) { ... }
return ERROR_OK;
}{ ... }
static int or1k_remove_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("Removing breakpoint: addr 0x%08" TARGET_PRIxADDR ", len %d, type %d, id: %" PRIu32,
breakpoint->address, breakpoint->length, breakpoint->type,
breakpoint->unique_id);
if (breakpoint->type == BKPT_HARD)
LOG_ERROR("HW breakpoints not supported for now. Doing SW breakpoint.");
int retval = du_core->or1k_jtag_write_memory(&or1k->jtag,
breakpoint->address,
4,
1,
breakpoint->orig_instr);
if (retval != ERROR_OK) {
LOG_ERROR("Error while writing back the instruction at 0x%08" TARGET_PRIxADDR,
breakpoint->address);
return retval;
}if (retval != ERROR_OK) { ... }
uint32_t addr = breakpoint->address;
retval = du_core->or1k_jtag_write_cpu(&or1k->jtag,
OR1K_ICBIR_CPU_REG_ADD, 1, &addr);
if (retval != ERROR_OK) {
LOG_ERROR("Error while invalidating the ICACHE");
return retval;
}if (retval != ERROR_OK) { ... }
return ERROR_OK;
}{ ... }
static int or1k_add_watchpoint(struct target *target,
struct watchpoint *watchpoint)
{
LOG_ERROR("%s: implement me", __func__);
return ERROR_OK;
}{ ... }
static int or1k_remove_watchpoint(struct target *target,
struct watchpoint *watchpoint)
{
LOG_ERROR("%s: implement me", __func__);
return ERROR_OK;
}{ ... }
static int or1k_read_memory(struct target *target, target_addr_t address,
uint32_t size, uint32_t count, uint8_t *buffer)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("Read memory at 0x%08" TARGET_PRIxADDR ", size: %" PRIu32 ", count: 0x%08" PRIx32, address, size, count);
if (target->state != TARGET_HALTED) {
LOG_TARGET_ERROR(target, "not halted");
return ERROR_TARGET_NOT_HALTED;
}if (target->state != TARGET_HALTED) { ... }
if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !buffer) {
LOG_ERROR("Bad arguments");
return ERROR_COMMAND_SYNTAX_ERROR;
}if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !buffer) { ... }
if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u))) {
LOG_ERROR("Can't handle unaligned memory access");
return ERROR_TARGET_UNALIGNED_ACCESS;
}if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u))) { ... }
return du_core->or1k_jtag_read_memory(&or1k->jtag, address, size, count, buffer);
}{ ... }
static int or1k_write_memory(struct target *target, target_addr_t address,
uint32_t size, uint32_t count, const uint8_t *buffer)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
LOG_DEBUG("Write memory at 0x%08" TARGET_PRIxADDR ", size: %" PRIu32 ", count: 0x%08" PRIx32, address, size, count);
if (target->state != TARGET_HALTED) {
LOG_TARGET_ERROR(target, "not halted");
return ERROR_TARGET_NOT_HALTED;
}if (target->state != TARGET_HALTED) { ... }
if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !buffer) {
LOG_ERROR("Bad arguments");
return ERROR_COMMAND_SYNTAX_ERROR;
}if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !buffer) { ... }
if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u))) {
LOG_ERROR("Can't handle unaligned memory access");
return ERROR_TARGET_UNALIGNED_ACCESS;
}if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u))) { ... }
return du_core->or1k_jtag_write_memory(&or1k->jtag, address, size, count, buffer);
}{ ... }
static int or1k_init_target(struct command_context *cmd_ctx,
struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
struct or1k_jtag *jtag = &or1k->jtag;
if (!du_core) {
LOG_ERROR("No debug unit selected");
return ERROR_FAIL;
}if (!du_core) { ... }
if (!jtag->tap_ip) {
LOG_ERROR("No tap selected");
return ERROR_FAIL;
}if (!jtag->tap_ip) { ... }
or1k->jtag.tap = target->tap;
or1k->jtag.or1k_jtag_inited = 0;
or1k->jtag.or1k_jtag_module_selected = -1;
or1k->jtag.target = target;
or1k_build_reg_cache(target);
return ERROR_OK;
}{ ... }
static int or1k_target_create(struct target *target, Jim_Interp *interp)
{
if (!target->tap)
return ERROR_FAIL;
struct or1k_common *or1k = calloc(1, sizeof(struct or1k_common));
target->arch_info = or1k;
or1k_create_reg_list(target);
or1k_tap_vjtag_register();
or1k_tap_xilinx_bscan_register();
or1k_tap_mohor_register();
or1k_du_adv_register();
return ERROR_OK;
}{ ... }
static int or1k_examine(struct target *target)
{
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
if (!target_was_examined(target)) {
target_set_examined(target);
int running;
int retval = du_core->or1k_is_cpu_running(&or1k->jtag, &running);
if (retval != ERROR_OK) {
LOG_ERROR("Couldn't read the CPU state");
return retval;
}if (retval != ERROR_OK) { ... } else {
if (running)
target->state = TARGET_RUNNING;
else {
LOG_DEBUG("Target is halted");
/* ... */
if (target->state == TARGET_UNKNOWN)
target->debug_reason = DBG_REASON_DBGRQ;
target->state = TARGET_HALTED;
}else { ... }
}else { ... }
}if (!target_was_examined(target)) { ... }
return ERROR_OK;
}{ ... }
static int or1k_arch_state(struct target *target)
{
return ERROR_OK;
}{ ... }
static int or1k_get_gdb_reg_list(struct target *target, struct reg **reg_list[],
int *reg_list_size, enum target_register_class reg_class)
{
struct or1k_common *or1k = target_to_or1k(target);
if (reg_class == REG_CLASS_GENERAL) {
int retval = or1k_save_context(target);
if (retval != ERROR_OK) {
LOG_ERROR("Error while calling or1k_save_context");
return retval;
}if (retval != ERROR_OK) { ... }
*reg_list_size = OR1KNUMCOREREGS;
*reg_list = malloc((*reg_list_size) * sizeof(struct reg *));
for (int i = 0; i < OR1KNUMCOREREGS; i++)
(*reg_list)[i] = &or1k->core_cache->reg_list[i];
}if (reg_class == REG_CLASS_GENERAL) { ... } else {
*reg_list_size = or1k->nb_regs;
*reg_list = malloc((*reg_list_size) * sizeof(struct reg *));
for (int i = 0; i < or1k->nb_regs; i++)
(*reg_list)[i] = &or1k->core_cache->reg_list[i];
}else { ... }
return ERROR_OK;
}{ ... }
static int or1k_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
{
return ERROR_FAIL;
}{ ... }
static int or1k_checksum_memory(struct target *target, target_addr_t address,
uint32_t count, uint32_t *checksum)
{
return ERROR_FAIL;
}{ ... }
static int or1k_profiling(struct target *target, uint32_t *samples,
uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
{
struct timeval timeout, now;
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_du *du_core = or1k_to_du(or1k);
int retval = ERROR_OK;
gettimeofday(&timeout, NULL);
timeval_add_time(&timeout, seconds, 0);
LOG_INFO("Starting or1k profiling. Sampling npc as fast as we can...");
target_poll(target);
if (target->state == TARGET_HALTED)
retval = target_resume(target, 1, 0, 0, 0);
if (retval != ERROR_OK) {
LOG_ERROR("Error while resuming target");
return retval;
}if (retval != ERROR_OK) { ... }
uint32_t sample_count = 0;
for (;;) {
uint32_t reg_value;
retval = du_core->or1k_jtag_read_cpu(&or1k->jtag, GROUP0 + 16 , 1, ®_value);
if (retval != ERROR_OK) {
LOG_ERROR("Error while reading NPC");
return retval;
}if (retval != ERROR_OK) { ... }
samples[sample_count++] = reg_value;
gettimeofday(&now, NULL);
if ((sample_count >= max_num_samples) || timeval_compare(&now, &timeout) > 0) {
LOG_INFO("Profiling completed. %" PRIu32 " samples.", sample_count);
break;
}if ((sample_count >= max_num_samples) || timeval_compare(&now, &timeout) > 0) { ... }
}for (;;) { ... }
*num_samples = sample_count;
return retval;
}{ ... }
COMMAND_HANDLER(or1k_tap_select_command_handler)
{
struct target *target = get_current_target(CMD_CTX);
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_jtag *jtag = &or1k->jtag;
struct or1k_tap_ip *or1k_tap;
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(or1k_tap, &tap_list, list) {
if (or1k_tap->name) {
if (!strcmp(CMD_ARGV[0], or1k_tap->name)) {
jtag->tap_ip = or1k_tap;
LOG_INFO("%s tap selected", or1k_tap->name);
return ERROR_OK;
}if (!strcmp(CMD_ARGV[0], or1k_tap->name)) { ... }
}if (or1k_tap->name) { ... }
}list_for_each_entry (or1k_tap, &tap_list, list) { ... }
LOG_ERROR("%s unknown, no tap selected", CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
}{ ... }
COMMAND_HANDLER(or1k_tap_list_command_handler)
{
struct or1k_tap_ip *or1k_tap;
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(or1k_tap, &tap_list, list) {
if (or1k_tap->name)
command_print(CMD, "%s", or1k_tap->name);
}list_for_each_entry (or1k_tap, &tap_list, list) { ... }
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(or1k_du_select_command_handler)
{
struct target *target = get_current_target(CMD_CTX);
struct or1k_common *or1k = target_to_or1k(target);
struct or1k_jtag *jtag = &or1k->jtag;
struct or1k_du *or1k_du;
if (CMD_ARGC > 2)
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(or1k_du, &du_list, list) {
if (or1k_du->name) {
if (!strcmp(CMD_ARGV[0], or1k_du->name)) {
jtag->du_core = or1k_du;
LOG_INFO("%s debug unit selected", or1k_du->name);
if (CMD_ARGC == 2) {
int options;
COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], options);
or1k_du->options = options;
LOG_INFO("Option %x is passed to %s debug unit"
, options, or1k_du->name);
}if (CMD_ARGC == 2) { ... }
return ERROR_OK;
}if (!strcmp(CMD_ARGV[0], or1k_du->name)) { ... }
}if (or1k_du->name) { ... }
}list_for_each_entry (or1k_du, &du_list, list) { ... }
LOG_ERROR("%s unknown, no debug unit selected", CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
}{ ... }
COMMAND_HANDLER(or1k_du_list_command_handler)
{
struct or1k_du *or1k_du;
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(or1k_du, &du_list, list) {
if (or1k_du->name)
command_print(CMD, "%s", or1k_du->name);
}list_for_each_entry (or1k_du, &du_list, list) { ... }
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(or1k_addreg_command_handler)
{
struct target *target = get_current_target(CMD_CTX);
struct or1k_core_reg new_reg;
if (CMD_ARGC != 4)
return ERROR_COMMAND_SYNTAX_ERROR;
new_reg.target = NULL;
new_reg.or1k_common = NULL;
uint32_t addr;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], addr);
new_reg.name = strdup(CMD_ARGV[0]);
new_reg.spr_num = addr;
new_reg.feature = strdup(CMD_ARGV[2]);
new_reg.group = strdup(CMD_ARGV[3]);
or1k_add_reg(target, &new_reg);
LOG_DEBUG("Add reg \"%s\" @ 0x%08" PRIx32 ", group \"%s\", feature \"%s\"",
new_reg.name, addr, new_reg.group, new_reg.feature);
return ERROR_OK;
}{ ... }
static const struct command_registration or1k_hw_ip_command_handlers[] = {
{
.name = "tap_select",
.handler = or1k_tap_select_command_handler,
.mode = COMMAND_ANY,
.usage = "name",
.help = "Select the TAP core to use",
...},
{
.name = "tap_list",
.handler = or1k_tap_list_command_handler,
.mode = COMMAND_ANY,
.usage = "",
.help = "Display available TAP core",
...},
{
.name = "du_select",
.handler = or1k_du_select_command_handler,
.mode = COMMAND_ANY,
.usage = "name",
.help = "Select the Debug Unit core to use",
...},
{
.name = "du_list",
.handler = or1k_du_list_command_handler,
.mode = COMMAND_ANY,
.usage = "select_tap name",
.help = "Display available Debug Unit core",
...},
COMMAND_REGISTRATION_DONE
...};
static const struct command_registration or1k_reg_command_handlers[] = {
{
.name = "addreg",
.handler = or1k_addreg_command_handler,
.mode = COMMAND_ANY,
.usage = "name addr feature group",
.help = "Add a register to the register list",
...},
COMMAND_REGISTRATION_DONE
...};
static const struct command_registration or1k_command_handlers[] = {
{
.chain = or1k_reg_command_handlers,
...},
{
.chain = or1k_hw_ip_command_handlers,
...},
COMMAND_REGISTRATION_DONE
...};
struct target_type or1k_target = {
.name = "or1k",
.poll = or1k_poll,
.arch_state = or1k_arch_state,
.target_request_data = NULL,
.halt = or1k_halt,
.resume = or1k_resume,
.step = or1k_step,
.assert_reset = or1k_assert_reset,
.deassert_reset = or1k_deassert_reset,
.soft_reset_halt = or1k_soft_reset_halt,
.get_gdb_reg_list = or1k_get_gdb_reg_list,
.read_memory = or1k_read_memory,
.write_memory = or1k_write_memory,
.checksum_memory = or1k_checksum_memory,
.commands = or1k_command_handlers,
.add_breakpoint = or1k_add_breakpoint,
.remove_breakpoint = or1k_remove_breakpoint,
.add_watchpoint = or1k_add_watchpoint,
.remove_watchpoint = or1k_remove_watchpoint,
.target_create = or1k_target_create,
.init_target = or1k_init_target,
.examine = or1k_examine,
.get_gdb_fileio_info = or1k_get_gdb_fileio_info,
.profiling = or1k_profiling,
...};