blob: d44414436d4e1b2753d4cb6cafa3e709edc38c2b [file] [log] [blame]
Andrew Geissler84ad7c52020-06-27 00:00:16 -05001From 92419bfa472c29b96ff85a9769b9301539867364 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Sun, 30 Sep 2018 16:31:26 +0530
4Subject: [PATCH 16/43] MB-X initial commit code cleanup is needed.
5
6---
7 bfd/bfd-in2.h | 10 +++
8 bfd/elf32-microblaze.c | 65 +++++++++++++++-
9 bfd/elf64-microblaze.c | 61 ++++++++++++++-
10 bfd/libbfd.h | 2 +
11 bfd/reloc.c | 12 +++
12 include/elf/microblaze.h | 2 +
13 opcodes/microblaze-opc.h | 4 +-
14 opcodes/microblaze-opcm.h | 4 +-
15 9 files changed, 277 insertions(+), 35 deletions(-)
16
17diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
18index 721531886a..4f777059d8 100644
19--- a/bfd/bfd-in2.h
20+++ b/bfd/bfd-in2.h
21@@ -5876,11 +5876,21 @@ done here - only used for relaxing */
22 * +done here - only used for relaxing */
23 BFD_RELOC_MICROBLAZE_64_NONE,
24
25+/* This is a 64 bit reloc that stores the 32 bit pc relative
26+ * +value in two words (with an imml instruction). No relocation is
27+ * +done here - only used for relaxing */
28+ BFD_RELOC_MICROBLAZE_64,
29+
30 /* This is a 64 bit reloc that stores the 32 bit pc relative
31 value in two words (with an imm instruction). The relocation is
32 PC-relative GOT offset */
33 BFD_RELOC_MICROBLAZE_64_GOTPC,
34
35+/* This is a 64 bit reloc that stores the 32 bit pc relative
36+value in two words (with an imml instruction). The relocation is
37+PC-relative GOT offset */
38+ BFD_RELOC_MICROBLAZE_64_GPC,
39+
40 /* This is a 64 bit reloc that stores the 32 bit pc relative
41 value in two words (with an imm instruction). The relocation is
42 GOT offset */
43diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
44index d001437b3f..035e71f311 100644
45--- a/bfd/elf32-microblaze.c
46+++ b/bfd/elf32-microblaze.c
47@@ -116,6 +116,20 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
48 0x0000ffff, /* Dest Mask. */
49 TRUE), /* PC relative offset? */
50
51+ HOWTO (R_MICROBLAZE_IMML_64, /* Type. */
52+ 0, /* Rightshift. */
53+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
54+ 16, /* Bitsize. */
55+ TRUE, /* PC_relative. */
56+ 0, /* Bitpos. */
57+ complain_overflow_dont, /* Complain on overflow. */
58+ bfd_elf_generic_reloc,/* Special Function. */
59+ "R_MICROBLAZE_IMML_64", /* Name. */
60+ FALSE, /* Partial Inplace. */
61+ 0, /* Source Mask. */
62+ 0x0000ffff, /* Dest Mask. */
63+ FALSE), /* PC relative offset? */
64+
65 /* A 64 bit relocation. Table entry not really used. */
66 HOWTO (R_MICROBLAZE_64, /* Type. */
67 0, /* Rightshift. */
68@@ -280,6 +294,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
69 0x0000ffff, /* Dest Mask. */
70 TRUE), /* PC relative offset? */
71
72+ /* A 64 bit GOTPC relocation. Table-entry not really used. */
73+ HOWTO (R_MICROBLAZE_GPC_64, /* Type. */
74+ 0, /* Rightshift. */
75+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
76+ 16, /* Bitsize. */
77+ TRUE, /* PC_relative. */
78+ 0, /* Bitpos. */
79+ complain_overflow_dont, /* Complain on overflow. */
80+ bfd_elf_generic_reloc, /* Special Function. */
81+ "R_MICROBLAZE_GPC_64", /* Name. */
82+ FALSE, /* Partial Inplace. */
83+ 0, /* Source Mask. */
84+ 0x0000ffff, /* Dest Mask. */
85+ TRUE), /* PC relative offset? */
86+
87 /* A 64 bit GOT relocation. Table-entry not really used. */
88 HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
89 0, /* Rightshift. */
90@@ -619,9 +648,15 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
91 case BFD_RELOC_VTABLE_ENTRY:
92 microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
93 break;
94+ case BFD_RELOC_MICROBLAZE_64:
95+ microblaze_reloc = R_MICROBLAZE_IMML_64;
96+ break;
97 case BFD_RELOC_MICROBLAZE_64_GOTPC:
98 microblaze_reloc = R_MICROBLAZE_GOTPC_64;
99 break;
100+ case BFD_RELOC_MICROBLAZE_64_GPC:
101+ microblaze_reloc = R_MICROBLAZE_GPC_64;
102+ break;
103 case BFD_RELOC_MICROBLAZE_64_GOT:
104 microblaze_reloc = R_MICROBLAZE_GOT_64;
105 break;
106@@ -1467,7 +1502,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
107 if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
108 {
109 relocation += addend;
110- if (r_type == R_MICROBLAZE_32)
111+ if (r_type == R_MICROBLAZE_32)// || r_type == R_MICROBLAZE_IMML_64)
112 bfd_put_32 (input_bfd, relocation, contents + offset);
113 else
114 {
115@@ -1933,6 +1968,28 @@ microblaze_elf_relax_section (bfd *abfd,
116 irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
117 }
118 break;
119+ case R_MICROBLAZE_IMML_64:
120+ {
121+ /* This was a PC-relative instruction that was
122+ completely resolved. */
123+ int sfix, efix;
124+ unsigned int val;
125+ bfd_vma target_address;
126+ target_address = irel->r_addend + irel->r_offset;
127+ sfix = calc_fixup (irel->r_offset, 0, sec);
128+ efix = calc_fixup (target_address, 0, sec);
129+
130+ /* Validate the in-band val. */
131+ val = bfd_get_32 (abfd, contents + irel->r_offset);
132+ if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
133+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
134+ }
135+ irel->r_addend -= (efix - sfix);
136+ /* Should use HOWTO. */
137+ microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset,
138+ irel->r_addend);
139+ }
140+ break;
141 case R_MICROBLAZE_NONE:
142 case R_MICROBLAZE_32_NONE:
143 {
144@@ -2037,9 +2094,9 @@ microblaze_elf_relax_section (bfd *abfd,
145 microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
146 irelscan->r_addend);
147 }
148- if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
149- {
150- isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
151+ if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)// || ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_IMML_64)
152+ {
153+ isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
154
155 /* Look at the reloc only if the value has been resolved. */
156 if (isym->st_shndx == shndx
157diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
158index 0f43ae6ea8..56a45f2a05 100644
159--- a/bfd/elf64-microblaze.c
160+++ b/bfd/elf64-microblaze.c
161@@ -116,6 +116,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
162 0x0000ffff, /* Dest Mask. */
163 TRUE), /* PC relative offset? */
164
165+ /* A 64 bit relocation. Table entry not really used. */
166+ HOWTO (R_MICROBLAZE_IMML_64, /* Type. */
167+ 0, /* Rightshift. */
168+ 4, /* Size (0 = byte, 1 = short, 2 = long). */
169+ 64, /* Bitsize. */
170+ TRUE, /* PC_relative. */
171+ 0, /* Bitpos. */
172+ complain_overflow_dont, /* Complain on overflow. */
173+ bfd_elf_generic_reloc,/* Special Function. */
174+ "R_MICROBLAZE_IMML_64", /* Name. */
175+ FALSE, /* Partial Inplace. */
176+ 0, /* Source Mask. */
177+ 0x0000ffff, /* Dest Mask. */
178+ TRUE), /* PC relative offset? */
179+
180 /* A 64 bit relocation. Table entry not really used. */
181 HOWTO (R_MICROBLAZE_64, /* Type. */
182 0, /* Rightshift. */
183@@ -265,6 +280,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
184 0x0000ffff, /* Dest Mask. */
185 TRUE), /* PC relative offset? */
186
187+ /* A 64 bit GOTPC relocation. Table-entry not really used. */
188+ HOWTO (R_MICROBLAZE_GPC_64, /* Type. */
189+ 0, /* Rightshift. */
190+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
191+ 16, /* Bitsize. */
192+ TRUE, /* PC_relative. */
193+ 0, /* Bitpos. */
194+ complain_overflow_dont, /* Complain on overflow. */
195+ bfd_elf_generic_reloc, /* Special Function. */
196+ "R_MICROBLAZE_GPC_64", /* Name. */
197+ FALSE, /* Partial Inplace. */
198+ 0, /* Source Mask. */
199+ 0x0000ffff, /* Dest Mask. */
200+ TRUE), /* PC relative offset? */
201+
202 /* A 64 bit GOT relocation. Table-entry not really used. */
203 HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
204 0, /* Rightshift. */
205@@ -589,9 +619,15 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
206 case BFD_RELOC_VTABLE_ENTRY:
207 microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
208 break;
209+ case BFD_RELOC_MICROBLAZE_64:
210+ microblaze_reloc = R_MICROBLAZE_IMML_64;
211+ break;
212 case BFD_RELOC_MICROBLAZE_64_GOTPC:
213 microblaze_reloc = R_MICROBLAZE_GOTPC_64;
214 break;
215+ case BFD_RELOC_MICROBLAZE_64_GPC:
216+ microblaze_reloc = R_MICROBLAZE_GPC_64;
217+ break;
218 case BFD_RELOC_MICROBLAZE_64_GOT:
219 microblaze_reloc = R_MICROBLAZE_GOT_64;
220 break;
221@@ -1161,6 +1197,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
222 break; /* Do nothing. */
223
224 case (int) R_MICROBLAZE_GOTPC_64:
225+ case (int) R_MICROBLAZE_GPC_64:
226 relocation = htab->sgotplt->output_section->vma
227 + htab->sgotplt->output_offset;
228 relocation -= (input_section->output_section->vma
229@@ -1431,7 +1468,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
230 if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
231 {
232 relocation += addend;
233- if (r_type == R_MICROBLAZE_32)
234+ if (r_type == R_MICROBLAZE_32)// || r_type == R_MICROBLAZE_IMML_64)
235 bfd_put_32 (input_bfd, relocation, contents + offset);
236 else
237 {
238@@ -1876,6 +1913,28 @@ microblaze_elf_relax_section (bfd *abfd,
239 irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
240 }
241 break;
242+ case R_MICROBLAZE_IMML_64:
243+ {
244+ /* This was a PC-relative instruction that was
245+ completely resolved. */
246+ int sfix, efix;
247+ unsigned int val;
248+ bfd_vma target_address;
249+ target_address = irel->r_addend + irel->r_offset;
250+ sfix = calc_fixup (irel->r_offset, 0, sec);
251+ efix = calc_fixup (target_address, 0, sec);
252+
253+ /* Validate the in-band val. */
254+ val = bfd_get_32 (abfd, contents + irel->r_offset);
255+ if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
256+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
257+ }
258+ irel->r_addend -= (efix - sfix);
259+ /* Should use HOWTO. */
260+ microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset,
261+ irel->r_addend);
262+ }
263+ break;
264 case R_MICROBLAZE_NONE:
265 case R_MICROBLAZE_32_NONE:
266 {
267diff --git a/bfd/libbfd.h b/bfd/libbfd.h
268index feb9fada1e..450653f2d8 100644
269--- a/bfd/libbfd.h
270+++ b/bfd/libbfd.h
271@@ -2903,7 +2903,9 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
272 "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM",
273 "BFD_RELOC_MICROBLAZE_32_NONE",
274 "BFD_RELOC_MICROBLAZE_64_NONE",
275+ "BFD_RELOC_MICROBLAZE_64",
276 "BFD_RELOC_MICROBLAZE_64_GOTPC",
277+ "BFD_RELOC_MICROBLAZE_64_GPC",
278 "BFD_RELOC_MICROBLAZE_64_GOT",
279 "BFD_RELOC_MICROBLAZE_64_PLT",
280 "BFD_RELOC_MICROBLAZE_64_GOTOFF",
281diff --git a/bfd/reloc.c b/bfd/reloc.c
282index 87753ae4f0..ccf29f54cf 100644
283--- a/bfd/reloc.c
284+++ b/bfd/reloc.c
285@@ -6803,12 +6803,24 @@ ENUMDOC
286 done here - only used for relaxing
287 ENUM
288 BFD_RELOC_MICROBLAZE_64_NONE
289+ENUMDOC
290+ This is a 32 bit reloc that stores the 32 bit pc relative
291+ value in two words (with an imml instruction). No relocation is
292+ done here - only used for relaxing
293+ENUM
294+ BFD_RELOC_MICROBLAZE_64
295 ENUMDOC
296 This is a 64 bit reloc that stores the 32 bit pc relative
297 value in two words (with an imm instruction). No relocation is
298 done here - only used for relaxing
299 ENUM
300 BFD_RELOC_MICROBLAZE_64_GOTPC
301+ENUMDOC
302+ This is a 64 bit reloc that stores the 32 bit pc relative
303+ value in two words (with an imml instruction). No relocation is
304+ done here - only used for relaxing
305+ENUM
306+ BFD_RELOC_MICROBLAZE_64_GPC
307 ENUMDOC
308 This is a 64 bit reloc that stores the 32 bit pc relative
309 value in two words (with an imm instruction). The relocation is
310diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h
311index 6ee0966444..16b2736577 100644
312--- a/include/elf/microblaze.h
313+++ b/include/elf/microblaze.h
314@@ -62,6 +62,8 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type)
315 RELOC_NUMBER (R_MICROBLAZE_TEXTREL_64, 31) /* TEXT Entry offset 64-bit. */
316 RELOC_NUMBER (R_MICROBLAZE_TEXTREL_32_LO, 32) /* TEXT Entry offset 32-bit. */
317 RELOC_NUMBER (R_MICROBLAZE_32_NONE, 33)
318+ RELOC_NUMBER (R_MICROBLAZE_IMML_64, 34)
319+ RELOC_NUMBER (R_MICROBLAZE_GPC_64, 35) /* GOT entry offset. */
320
321 END_RELOC_NUMBERS (R_MICROBLAZE_max)
322
323diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
324index 985834b8df..9b6264b61c 100644
325--- a/opcodes/microblaze-opc.h
326+++ b/opcodes/microblaze-opc.h
327@@ -538,8 +538,8 @@ struct op_code_struct
328 {"llr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000300, OPCODE_MASK_H4, llr, memory_load_inst },
329 {"sl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000100, OPCODE_MASK_H4, sl, memory_store_inst },
330 {"slr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000300, OPCODE_MASK_H4, slr, memory_store_inst },
331- {"lli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */
332- {"sli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */
333+ {"lli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xEC000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */
334+ {"sli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xFC000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */
335 {"lla", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* lla translates to addlik */
336 {"dadd", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000400, OPCODE_MASK_H4, dadd, arithmetic_inst },
337 {"drsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000480, OPCODE_MASK_H4, drsub, arithmetic_inst },
338diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
339index 076dbcd0b3..5f2e190d23 100644
340--- a/opcodes/microblaze-opcm.h
341+++ b/opcodes/microblaze-opcm.h
342@@ -40,8 +40,8 @@ enum microblaze_instr
343 imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid,
344 brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti,
345 bgtid, bgei, bgeid, lbu, lbuea, lbur, lhu, lhuea, lhur, lw, lwea, lwr, lwx,
346- sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi,
347- sbi, shi, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
348+ sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi, lli,
349+ sbi, shi, sli, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
350 fcmp_lt, fcmp_eq, fcmp_le, fcmp_gt, fcmp_ne, fcmp_ge, fcmp_un, flt,
351 fint, fsqrt,
352 tget, tcget, tnget, tncget, tput, tcput, tnput, tncput,
353--
3542.17.1
355