-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path1449-Tricore-improvements.patch
More file actions
793 lines (790 loc) · 36.3 KB
/
Copy path1449-Tricore-improvements.patch
File metadata and controls
793 lines (790 loc) · 36.3 KB
1
2
3
4
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
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
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
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
479
480
481
482
483
484
485
486
487
488
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
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
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
792
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: mumbel <22204578+mumbel@users.noreply.github.com>
Date: Sun, 7 Jan 2024 17:36:51 -0600
Subject: [PATCH] 1449: Tricore improvements
tricore analysis
---
.../TRICOREElfRelocationConstants.java | 140 ++++
.../TRICOREElfRelocationHandler.java | 625 ++++++++++++++++++
2 files changed, 765 insertions(+)
create mode 100644 Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationConstants.java
create mode 100644 Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationHandler.java
diff --git a/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationConstants.java b/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationConstants.java
new file mode 100644
index 0000000000..840a351d3a
--- /dev/null
+++ b/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationConstants.java
@@ -0,0 +1,140 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.util.bin.format.elf.relocation;
+
+public class TRICOREElfRelocationConstants {
+
+ // e_flags Identifying TriCore/PCP Derivatives
+ public static final int EF_TRICORE_V1_1 = 0x80000000;
+ public static final int EF_TRICORE_V1_2 = 0x40000000;
+ public static final int EF_TRICORE_V1_3 = 0x20000000;
+ public static final int EF_TRICORE_PCP2 = 0x02000000;
+
+ // TriCore Section Attribute Flags
+ public static final int SHF_TRICORE_ABS = 0x400;
+ public static final int SHF_TRICORE_NOREAD = 0x800;
+
+ public static final int R_TRICORE_NONE = 0; // none none
+ public static final int R_TRICORE_32REL = 1; // word32 S + A - P
+ public static final int R_TRICORE_32ABS = 2; // word32 S + A
+ public static final int R_TRICORE_24REL = 3; // relB S + A - P
+ public static final int R_TRICORE_24ABS = 4; // absB S + A
+ public static final int R_TRICORE_16SM = 5; // BOL S + A - A[0]
+ public static final int R_TRICORE_HI = 6; // RLC S + A + 8000H >> 16
+ public static final int R_TRICORE_LO = 7; // RLC S + A & FFFFH
+ public static final int R_TRICORE_LO2 = 8; // BOL S + A & FFFFH
+ public static final int R_TRICORE_18ABS = 9; // ABS S + A
+ public static final int R_TRICORE_10SM = 10; // BO S + A - A[0]
+ public static final int R_TRICORE_15REL = 11; // BR S + A - P
+
+ /*
+ * GNU extensions
+ */
+ public static final int R_TRICORE_10LI = 12; // BO S + A - A[1]
+ public static final int R_TRICORE_16LI = 13; // BOL S + A - A[1]
+ public static final int R_TRICORE_10A8 = 14; // BO S + A - A[8]
+ public static final int R_TRICORE_16A8 = 15; // BOL S + A - A[8]
+ public static final int R_TRICORE_10A9 = 16; // BO S + A - A[9]
+ public static final int R_TRICORE_16A9 = 17; // BOL S + A - A[9]
+ public static final int R_TRICORE_10OFF = 18; // BO 10 bit data offset
+ public static final int R_TRICORE_16OFF = 19; // bolC 16 bit data offset
+ public static final int R_TRICORE_8ABS = 20; // 8 bit absolute data relocation
+ public static final int R_TRICORE_16ABS = 21; // 16 bit absolute data relocation
+ public static final int R_TRICORE_16BIT = 22; // absBb 1 bit relocation
+ public static final int R_TRICORE_3POS = 23; // absBp 3 bit bit position
+ public static final int R_TRICORE_5POS = 24; // bitP1 5 bit bit position
+
+ /*
+ * PCP relocations
+ */
+ public static final int R_TRICORE_PCPHI = 25; // word16 S + A >> 16
+ public static final int R_TRICORE_PCPLO = 26; // word16 S + A & FFFFH
+ public static final int R_TRICORE_PCPPAGE = 27; // pcpPage S + A & FF00H
+ public static final int R_TRICORE_PCPOFF = 28; // PI (S + A >> 2) & 3FH
+ public static final int R_TRICORE_PCPTEXT = 29; // word16 (S + A >> 1) & FFFFH
+
+ /*
+ * More GNU extensions
+ */
+ public static final int R_TRICORE_5POS2 = 30; // bitP2 5 bit bit position
+ public static final int R_TRICORE_BRCC = 31; // brcC 4 bit signed offset
+ public static final int R_TRICORE_BRCZ = 32; // brcC2 4 bit unsigned offset
+ public static final int R_TRICORE_BRNN = 33; // brnN 5 bit bit position
+ public static final int R_TRICORE_RRN = 34; // rrN 2 bit unsigned constant
+ public static final int R_TRICORE_4CONST = 35; // sbcC 4 bit signed constant
+ public static final int R_TRICORE_4REL = 36; // sbcD/sbrD 5 bit PC-relative, zero-extended displacement
+ public static final int R_TRICORE_4REL2 = 37; // sbrD 5 bit PC-relative, one-extended displacement
+ public static final int R_TRICORE_5POS3 = 38; // sbrN 5 bit bit position
+ public static final int R_TRICORE_4OFF = 39; // slroO 4 bit zero-extended offset
+ public static final int R_TRICORE_4OFF2 = 40; // slroO2 5 bit zero-extended offset
+ public static final int R_TRICORE_4OFF4 = 41; // slroO4 6 bit zero-extended offset
+ public static final int R_TRICORE_42OFF = 42; // sroO 4 bit zero-extended offset
+ public static final int R_TRICORE_42OFF2 = 43; // sroO2 5 bit zero-extended offset
+ public static final int R_TRICORE_42OFF4 = 44; // slroO4 6 bit zero-extended offset
+ public static final int R_TRICORE_2OFF = 45; // srrsN 2 bit zero-extended constant
+ public static final int R_TRICORE_8CONST2 = 46; // scC 8 bit zero-extended offset
+ public static final int R_TRICORE_4POS = 47; // sbrnN 4 bit zero-extended constant
+ public static final int R_TRICORE_16SM2 = 48; // rlcC 16 bit small data section relocation
+ public static final int R_TRICORE_5REL = 49; // sbcD/sbrD 6 bit PC-relative, zero-extended displacement
+
+ /*
+ * GNU extensions to help optimizing virtual tables (C++)
+ */
+ public static final int R_TRICORE_VTENTRY = 50; //
+ public static final int R_TRICORE_VTINHERIT = 51; //
+
+ /*
+ * Support for shared objects
+ */
+ public static final int R_TRICORE_PCREL16 = 52; // 16 bit PC-relative relocation
+ public static final int R_TRICORE_PCREL8 = 53; // 8 bit PC-relative relocation
+ public static final int R_TRICORE_GOT = 54; // rlcC 16 bit GOT symbol entry
+ public static final int R_TRICORE_GOT2 = 55; // bolC 16 bit GOT symbol entry
+ public static final int R_TRICORE_GOTHI = 56; // rlcC 16 bit GOTHI symbol entry
+ public static final int R_TRICORE_GOTLO = 57; // rlcC 16 bit GOTLO symbol entry
+ public static final int R_TRICORE_GOTLO2 = 58; // bolC 16 bit GOTLO symbol entry
+ public static final int R_TRICORE_GOTUP = 59; // rlcC 16 bit GOTUP symbol entry
+ public static final int R_TRICORE_GOTOFF = 60; // rlcC 16 bit GOTOFF symbol entry
+ public static final int R_TRICORE_GOTOFF2 = 61; // bolC 16 bit GOTOFF symbol entry
+ public static final int R_TRICORE_GOTOFFHI = 62; // rlcC 16 bit GOTOFFHI symbol entry
+ public static final int R_TRICORE_GOTOFFLO = 63; // rlcC 16 bit GOTOFFLO symbol entry
+ public static final int R_TRICORE_GOTOFFLO2 = 64; // bolC 16 bit GOTOFFLO symbol entry
+ public static final int R_TRICORE_GOTOFFUP = 65; // rlcC 16 bit GOTOFFUP symbol entry
+ public static final int R_TRICORE_GOTPC = 66; // rlcC 16 bit GOTPC symbol entry
+ public static final int R_TRICORE_GOTPC2 = 67; // bolC 16 bit GOTPC symbol entry
+ public static final int R_TRICORE_GOTPCHI = 68; // rlcC 16 bit GOTPCHI symbol entry
+ public static final int R_TRICORE_GOTPCLO = 69; // rlcC 16 bit GOTPCLO symbol entry
+ public static final int R_TRICORE_GOTPCLO2 = 70; // bolC 16 bit GOTPCLO symbol entry
+ public static final int R_TRICORE_GOTCPUP = 71; // rlcC 16 bit GOTPCUP symbol entry
+ public static final int R_TRICORE_PLT = 72; //relB PLT entry
+ public static final int R_TRICORE_COPY = 73; // COPY
+ public static final int R_TRICORE_GLOB_DAT = 74; // GLOB_DAT
+ public static final int R_TRICORE_JMP_SLOT = 75; // JMP_SLOT
+ public static final int R_TRICORE_RELATIVE = 76; // RELATIVE
+
+ /*
+ * Support for single bit objects
+ */
+ public static final int R_TRICORE_BITPOS = 77; // BITPOS
+
+ /*
+ * Support for small data addressing areas get the base address of a small data
+ * symbol
+ */
+ public static final int R_TRICORE_SBREG_S2 = 78; // SMALL DATA Baseregister operand 2
+ public static final int R_TRICORE_SBREG_S1 = 79; // SMALL DATA Baseregister operand 1
+ public static final int R_TRICORE_SBREG_D = 80; // SMALL DATA Baseregister destination
+}
diff --git a/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationHandler.java b/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationHandler.java
new file mode 100644
index 0000000000..2898cf34e3
--- /dev/null
+++ b/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/TRICOREElfRelocationHandler.java
@@ -0,0 +1,625 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.util.bin.format.elf.relocation;
+
+import ghidra.app.util.bin.format.elf.ElfConstants;
+import ghidra.app.util.bin.format.elf.ElfHeader;
+import ghidra.app.util.bin.format.elf.ElfRelocation;
+import ghidra.app.util.bin.format.elf.ElfSymbol;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.mem.Memory;
+import ghidra.program.model.mem.MemoryAccessException;
+import ghidra.program.model.reloc.RelocationResult;
+import ghidra.program.model.reloc.Relocation.Status;
+import ghidra.util.Msg;
+import ghidra.util.exception.NotFoundException;
+
+public class TRICOREElfRelocationHandler extends ElfRelocationHandler {
+
+ @Override
+ public boolean canRelocate(ElfHeader elf) {
+ return elf.e_machine() == ElfConstants.EM_TRICORE;
+ }
+
+ @Override
+ public RelocationResult relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation,
+ Address relocationAddress) throws MemoryAccessException, NotFoundException {
+
+ ElfHeader elf = elfRelocationContext.getElfHeader();
+ if (!canRelocate(elf)) {
+ return RelocationResult.FAILURE;
+ }
+
+ Program program = elfRelocationContext.getProgram();
+ Memory memory = program.getMemory();
+
+ int type = relocation.getType();
+
+ if (TRICOREElfRelocationConstants.R_TRICORE_NONE == type) {
+ return RelocationResult.SKIPPED;
+ }
+
+ long addend = relocation.hasAddend() ? relocation.getAddend() : memory.getInt(relocationAddress);
+ long offset = relocationAddress.getOffset();
+ int symbolIndex = relocation.getSymbolIndex();
+
+ long symbolValue = 0;
+ String symbolName = null;
+ ElfSymbol symbol = elfRelocationContext.getSymbol(symbolIndex);
+ if (symbol != null) {
+ symbolValue = elfRelocationContext.getSymbolValue(symbol);
+ symbolName = symbol.getNameAsString();
+ }
+
+ long rv = 0;
+ int byteLength = -1;
+
+ /**
+ * Key S indicates the final value assigned to the symbol referenced in the
+ * relocation record. Key A is the addend value specified in the relocation
+ * record. Key P indicates the address of the relocation (for example, the
+ * address being modified). Key A[0] is the content of the small data base
+ * register A[0].
+ */
+ switch (type) {
+ case TRICOREElfRelocationConstants.R_TRICORE_32REL: // word32 S + A - P
+ rv = symbolValue + addend - offset;
+ byteLength = relocate_word32(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_32ABS: // word32 S + A
+ rv = symbolValue + addend;
+ byteLength = relocate_word32(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_24REL: // relB S + A - P
+ rv = symbolValue + addend - offset;
+ byteLength = relocate_relB(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_24ABS: // absB S + A
+ rv = symbolValue + addend;
+ byteLength = relocate_absB(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16SM: // BOL S + A - A[0]
+ //TODO how to get "content of the small data base register A[0]"
+ markAsWarning(program, relocationAddress, "R_TRICORE_16SM", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_HI: // RLC S + A + 8000H >> 16
+ rv = (symbolValue + addend + 0x8000) >> 16;
+ byteLength = relocate_RLC(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_LO: // RLC S + A & FFFFH
+ rv = (symbolValue + addend) & 0xffff;
+ byteLength = relocate_RLC(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_LO2: // BOL S + A & FFFFH
+ rv = (symbolValue + addend) & 0xffff;
+ byteLength = relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_18ABS: // ABS S + A
+ rv = symbolValue + addend;
+ byteLength = relocate_ABS(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_10SM: // BO S + A - A[0]
+ markAsWarning(program, relocationAddress, "R_TRICORE_10SM", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BO(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_15REL: // BR S + A - P
+ rv = symbolValue + addend - offset;
+ byteLength = relocate_BR(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_10LI: // BO S + A - A[1]
+ markAsWarning(program, relocationAddress, "R_TRICORE_10LI", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BO(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16LI: // BOL S + A - A[1]
+ markAsWarning(program, relocationAddress, "R_TRICORE_16LI", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_10A8: // BO S + A - A[8]
+ markAsWarning(program, relocationAddress, "R_TRICORE_10A8", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BO(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16A8: // BOL S + A - A[8]
+ markAsWarning(program, relocationAddress, "R_TRICORE_16A8", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_10A9: // BO S + A - A[9]
+ markAsWarning(program, relocationAddress, "R_TRICORE_16A9", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BO(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16A9: // BOL S + A - A[9]
+ markAsWarning(program, relocationAddress, "R_TRICORE_16A9", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_10OFF:
+ markAsWarning(program, relocationAddress, "R_TRICORE_10OFF", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16OFF:
+ rv = symbolValue + addend;
+ byteLength = relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_8ABS:
+ markAsWarning(program, relocationAddress, "R_TRICORE_8ABS", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16ABS:
+ markAsWarning(program, relocationAddress, "R_TRICORE_16ABS", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16BIT:
+ markAsWarning(program, relocationAddress, "R_TRICORE_16BIT", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_3POS:
+ rv = symbolValue + addend;
+ byteLength = relocate_3POS(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_5POS:
+ rv = symbolValue + addend;
+ byteLength = relocate_5POS(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCPHI: // word16 S + A >> 16
+ rv = (symbolValue + addend) >> 16;
+ byteLength = relocate_word16(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCPLO: // word16 S + A & FFFFH
+ rv = (symbolValue + addend) & 0xffff;
+ byteLength = relocate_word16(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCPPAGE: // pcpPage S + A & FF00H
+ rv = (symbolValue + addend) & 0xff00;
+ byteLength = relocate_pcpPage(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCPOFF: // PI (S + A >> 2) & 3FH
+ rv = ((symbolValue + addend) >> 2) & 0x3f;
+ byteLength = relocate_PI(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCPTEXT: // word16 (S + A >> 1) & FFFFH
+ rv = ((symbolValue + addend) >> 1) & 0xffff;
+ byteLength = relocate_word16(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_5POS2:
+ rv = (symbolValue + addend);
+ byteLength = relocate_5POS2(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_BRCC:
+ markAsWarning(program, relocationAddress, "R_TRICORE_BRCC", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_BRCZ:
+ markAsWarning(program, relocationAddress, "R_TRICORE_BRCZ", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_BRNN:
+ markAsWarning(program, relocationAddress, "R_TRICORE_BRNN", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_RRN:
+ markAsWarning(program, relocationAddress, "R_TRICORE_RRN", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4CONST:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4CONST", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4REL:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4REL", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4REL2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4REL2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_5POS3:
+ markAsWarning(program, relocationAddress, "R_TRICORE_5POS3", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4OFF:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4OFF", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4OFF2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4OFF2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4OFF4:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4OFF4", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_42OFF:
+ markAsWarning(program, relocationAddress, "R_TRICORE_42OFF", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_42OFF2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_42OFF2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_42OFF4:
+ markAsWarning(program, relocationAddress, "R_TRICORE_42OFF4", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_2OFF:
+ markAsWarning(program, relocationAddress, "R_TRICORE_2OFF", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_8CONST2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_8CONST2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_4POS:
+ markAsWarning(program, relocationAddress, "R_TRICORE_4POS", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_16SM2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_16SM2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ // byteLength = relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_5REL:
+ markAsWarning(program, relocationAddress, "R_TRICORE_5REL", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_VTENTRY:
+ markAsWarning(program, relocationAddress, "R_TRICORE_VTENTRY", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_VTINHERIT:
+ markAsWarning(program, relocationAddress, "R_TRICORE_VTINHERIT", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCREL16:
+ markAsWarning(program, relocationAddress, "R_TRICORE_PCREL16", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PCREL8:
+ markAsWarning(program, relocationAddress, "R_TRICORE_PCREL8", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOT:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOT", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOT2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOT2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTHI:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTHI", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTLO:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTLO", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTLO2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTLO2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTUP:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTUP", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTOFF:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTOFF", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTOFF2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTOFF2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTOFFHI:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTOFFHI", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTOFFLO:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTOFFLO", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTOFFLO2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTOFFLO2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTOFFUP:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTOFFUP", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTPC:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTPC", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTPC2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTPC2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTPCHI:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTPCHI", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTPCLO:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTPCLO", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTPCLO2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTPCLO2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GOTCPUP:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GOTCPUP", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_PLT:
+ markAsWarning(program, relocationAddress, "R_TRICORE_PLT", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_COPY:
+ markAsWarning(program, relocationAddress, "R_TRICORE_COPY", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_GLOB_DAT:
+ markAsWarning(program, relocationAddress, "R_TRICORE_GLOB_DAT", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_JMP_SLOT:
+ markAsWarning(program, relocationAddress, "R_TRICORE_JMP_SLOT", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_RELATIVE:
+ markAsWarning(program, relocationAddress, "R_TRICORE_RELATIVE", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_BITPOS:
+ // This reads as a pseudo relocation, possibly do RelocationResult.PARTIAL instead?
+ return RelocationResult.SKIPPED;
+ case TRICOREElfRelocationConstants.R_TRICORE_SBREG_S2:
+ markAsWarning(program, relocationAddress, "R_TRICORE_SBREG_S2", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_SBREG_S1:
+ markAsWarning(program, relocationAddress, "R_TRICORE_SBREG_S1", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ case TRICOREElfRelocationConstants.R_TRICORE_SBREG_D:
+ markAsWarning(program, relocationAddress, "R_TRICORE_SBREG_D", symbolName, symbolIndex,
+ "TODO, needs support ", elfRelocationContext.getLog());
+ break;
+ default:
+ markAsUnhandled(program, relocationAddress, type, symbolIndex, symbolName, elfRelocationContext.getLog());
+ break;
+ }
+ if (byteLength < 0) {
+ return RelocationResult.UNSUPPORTED;
+ }
+ return new RelocationResult(Status.APPLIED, byteLength);
+ }
+
+ // TODO how bad is this approach, not sure how java handles bit manipulation
+ // at this level, or just in a general a class exists that excels at these
+ // operations?
+
+ // RV = Relocation Value. IW = Instruction Word.
+
+ /**
+ * A 32-bit field occupying four bytes. This address is NOT required to be
+ * 4-byte aligned.
+ */
+ private int relocate_word32(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ memory.setInt(relocationAddress, (int) rv);
+ return 4;
+ }
+
+ /**
+ * A 16-bit field occupying two bytes.
+ */
+ private int relocate_word16(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ memory.setShort(relocationAddress, (short) rv);
+ return 2;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 1-16 of the RV go into bits 16-31 of
+ * the IW. - bits 17-24 of the RV go into bits 8-15 of the IW. - the RV must be
+ * in the range [-16777216,16777214]. bit 0 of the RV must be zero.
+ */
+ private int relocate_relB(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ // TODO ff000000..00fffffe?
+ long mask = 0xfffffffeL;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0xff;
+ iw |= ((val & 0x1fffe) << 15);
+ iw |= ((val & 0x1fe0000) >> 9);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 1-16 of the RV go into bits 16-31 of
+ * the IW. - bits 17-20 of the RV go into bits 8-11 of the IW. - bits 0 and 21
+ * to 27 of the RV must be zero. - bits 28-31 of the RV go into bits 12-15 of
+ * the IW.
+ */
+ private int relocate_absB(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0x0fe00001L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0xff;
+ iw |= ((val & 0x1fffe) << 15);
+ iw |= ((val & 0x1e0000) >> 9);
+ iw |= ((val & 0xf0000000) >> 16);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word where: - bits 0-5 of the RV go into bits 16-21 of
+ * the IW. - bits 6-9 of the RV go into bits 28-31 of the IW. - bits 10-31 of
+ * the RV must be zero.
+ */
+ @SuppressWarnings("unused")
+ private int relocate_BO(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xfffffc00L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0xfc0ffff;
+ iw |= ((val & 0x3f) << 16);
+ iw |= ((val & 0x3c0) << 22);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 0-5 of the RV go into bits 16-21 of
+ * the IW. - bits 6-9 of the RV go into bits 28-31 of the IW. - bits 10-15 of
+ * the RV go into bits 22-27 of the IW. - bits 16-31 of the RV must be zero.
+ */
+ private int relocate_BOL(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffff0000L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0xffff;
+ iw |= ((val & 0x3f) << 16);
+ iw |= ((val & 0x3c0) << 22);
+ iw |= ((val & 0xfc00) << 12);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 1-15 of the RV go into bits 16-30 of
+ * the IW. - bits 16-31 of the RV must be zero.
+ */
+ private int relocate_BR(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffff0000L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0x8000ffff;
+ iw |= ((val & 0xfffe) << 15);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 0-15 of the RV go into bits 12-27 of
+ * the IW. - bits 16-31 of the RV must be zero.
+ */
+ private int relocate_RLC(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffff0000L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0xf0000fff;
+ iw |= ((val & 0xffff) << 12);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 0-5 of the RV go into bits 16-21 of
+ * the IW. - bits 6-9 of the RV go into bits 28-31 of the IW. - bits 10-13 of
+ * the RV go into bits 22-25 of the IW. - bits 14-27 of the RV must be zero. -
+ * bits 28-31 of the RV go into bits 12-15 of the IW.
+ */
+ private int relocate_ABS(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0x0fffc000L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress) & 0xc000fff;
+ iw |= ((val & 0x3f) << 16);
+ iw |= ((val & 0x3c0) << 22);
+ iw |= ((val & 0x3c00) << 12);
+ iw |= ((val & 0xf0000000) >> 16);
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ * A 32-bit instruction word, where: - bits 0-3 of the RV go into bits 8-11 of
+ * the IW. - bits 4-32 of the RV must be zero.
+ */
+ @SuppressWarnings("unused")
+ private int relocate_SBR(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException, NotFoundException {
+ long mask = 0xfffffff0L;
+ long val = ~mask & rv;
+
+ // oddly this is defined but not in any relocations
+ throw new NotFoundException();
+ }
+
+ /**
+ * A 16-bit instruction word, where: - bits 8-15 of the RV go into bits 8-15 of
+ * the IW. - bits 0-7 and 16-31 of the RV must be zero.
+ */
+ private int relocate_pcpPage(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffff00ffL;
+ long val = ~mask & rv;
+ int iw = memory.getShort(relocationAddress) & 0xff;
+ iw |= (val & 0xff00);
+ memory.setShort(relocationAddress, (short) iw);
+ return 2;
+ }
+
+ /**
+ * A 16-bit instruction word, where: - bits 0-5 of the RV go into bits 0-5 of
+ * the IW. - bits 6-15 of the RV must be zero.
+ */
+ private int relocate_PI(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffffffc0L;
+ long val = ~mask & rv;
+ int iw = memory.getShort(relocationAddress) & 0xffc0;
+ iw |= (val & 0x3f);
+ memory.setShort(relocationAddress, (short) iw);
+ return 2;
+ }
+
+ /**
+ *
+ */
+ private int relocate_3POS(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xfffffff8L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress);
+ iw |= val << 8;
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ *
+ */
+ private int relocate_5POS(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffffffe0L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress);
+ iw |= val << 16;
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+
+ /**
+ *
+ */
+ private int relocate_5POS2(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ long mask = 0xffffffe0L;
+ long val = ~mask & rv;
+ int iw = memory.getInt(relocationAddress);
+ iw |= val << 23;
+ memory.setInt(relocationAddress, iw);
+ return 4;
+ }
+}
--
2.45.1