aboutsummaryrefslogtreecommitdiffstats
path: root/meta-xilinx-bsp/recipes-microblaze/binutils/binutils-2.31/0018-Added-relocations-for-MB-X.patch
blob: d401cdd39f6ad5f2f41e9d8fde43235c7366484b (plain)
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
From a1961dbfa4324335116f84494396ce9801688f18 Mon Sep 17 00:00:00 2001
From: Nagaraju Mekala <nmekala@xilix.com>
Date: Tue, 11 Sep 2018 17:30:17 +0530
Subject: [PATCH 18/31] Added relocations for MB-X

Signed-off-by: Mahesh Bodapati <mbodapat@xilinx.com>
Signed-off-by: Nagaraju Mekala <nagaraju.mekala@xilinx.com>
---
 bfd/bfd-in2.h              | 11 ++++--
 bfd/libbfd.h               |  4 +--
 bfd/reloc.c                | 26 +++++++-------
 gas/config/tc-microblaze.c | 90 ++++++++++++++++++++--------------------------
 4 files changed, 62 insertions(+), 69 deletions(-)

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 44cddc2..44e719b 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -5796,16 +5796,21 @@ done here - only used for relaxing  */
   BFD_RELOC_MICROBLAZE_32_NONE,
 
 /* This is a 64 bit reloc that stores the 32 bit pc relative
- *  +value in two words (with an imm instruction).  No relocation is
+ *  +value in two words (with an imml instruction).  No relocation is
  *   +done here - only used for relaxing  */
-    BFD_RELOC_MICROBLAZE_64_NONE,
+    BFD_RELOC_MICROBLAZE_64_PCREL,
 
-/* This is a 64 bit reloc that stores the 32 bit pc relative
+/* This is a 64 bit reloc that stores the 32 bit relative
  *  +value in two words (with an imml instruction).  No relocation is
  *   +done here - only used for relaxing  */
     BFD_RELOC_MICROBLAZE_64,
 
 /* This is a 64 bit reloc that stores the 32 bit pc relative
+ *  +value in two words (with an imm instruction).  No relocation is
+ *   +done here - only used for relaxing  */
+    BFD_RELOC_MICROBLAZE_64_NONE,
+
+/* This is a 64 bit reloc that stores the 32 bit pc relative
 value in two words (with an imm instruction).  The relocation is
 PC-relative GOT offset  */
   BFD_RELOC_MICROBLAZE_64_GOTPC,
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index d7892a6..bb8fb42 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -2864,14 +2864,14 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM",
   "BFD_RELOC_MICROBLAZE_32_NONE",
   "BFD_RELOC_MICROBLAZE_64_NONE",
-  "BFD_RELOC_MICROBLAZE_64",
   "BFD_RELOC_MICROBLAZE_64_GOTPC",
-  "BFD_RELOC_MICROBLAZE_64_GPC",
   "BFD_RELOC_MICROBLAZE_64_GOT",
   "BFD_RELOC_MICROBLAZE_64_PLT",
   "BFD_RELOC_MICROBLAZE_64_GOTOFF",
   "BFD_RELOC_MICROBLAZE_32_GOTOFF",
   "BFD_RELOC_MICROBLAZE_COPY",
+  "BFD_RELOC_MICROBLAZE_64",
+  "BFD_RELOC_MICROBLAZE_64_PCREL",
   "BFD_RELOC_MICROBLAZE_64_TLS",
   "BFD_RELOC_MICROBLAZE_64_TLSGD",
   "BFD_RELOC_MICROBLAZE_64_TLSLD",
diff --git a/bfd/reloc.c b/bfd/reloc.c
index 60eac77..2d73154 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -6873,12 +6873,6 @@ ENUMDOC
 ENUM
   BFD_RELOC_MICROBLAZE_64_NONE
 ENUMDOC
-  This is a 32 bit reloc that stores the 32 bit pc relative
-  value in two words (with an imml instruction).  No relocation is
-  done here - only used for relaxing
-ENUM
-  BFD_RELOC_MICROBLAZE_64
-ENUMDOC
   This is a 64 bit reloc that stores the 32 bit pc relative
   value in two words (with an imm instruction).  No relocation is
   done here - only used for relaxing
@@ -6886,12 +6880,6 @@ ENUM
   BFD_RELOC_MICROBLAZE_64_GOTPC
 ENUMDOC
   This is a 64 bit reloc that stores the 32 bit pc relative
-  value in two words (with an imml instruction).  No relocation is
-  done here - only used for relaxing
-ENUM
-  BFD_RELOC_MICROBLAZE_64_GPC
-ENUMDOC
-  This is a 64 bit reloc that stores the 32 bit pc relative
   value in two words (with an imm instruction).  The relocation is
   PC-relative GOT offset
 ENUM
@@ -6975,6 +6963,20 @@ ENUMDOC
   value in two words (with an imm instruction).  The relocation is
   relative offset from start of TEXT.
 
+  This is a 64 bit reloc that stores 64-bit thread pointer relative offset
+  to two words (uses imml instruction).
+ENUM
+BFD_RELOC_MICROBLAZE_64,
+ENUMDOC
+ This is a 64 bit reloc that stores the 64 bit pc relative
+ value in two words (with an imml instruction).  No relocation is
+ done here - only used for relaxing
+ENUM
+BFD_RELOC_MICROBLAZE_64_PCREL,
+ENUMDOC
+ This is a 32 bit reloc that stores the 32 bit pc relative
+ value in two words (with an imml instruction).  No relocation is
+ done here - only used for relaxing
 ENUM
   BFD_RELOC_AARCH64_RELOC_START
 ENUMDOC
diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
index 680a794..663e1a6 100644
--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -95,6 +95,7 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP";
 #define TEXT_OFFSET	     17
 #define TEXT_PC_OFFSET       18
 #define DEFINED_64_OFFSET   19
+#define DEFINED_64_PC_OFFSET 20 
 
 /* Initialize the relax table.  */
 const relax_typeS md_relax_table[] =
@@ -119,7 +120,8 @@ const relax_typeS md_relax_table[] =
   { 0x7fffffff, 0x80000000, INST_WORD_SIZE*2, 0 },  /* 17: TEXT_OFFSET.  */
   { 0x7fffffff, 0x80000000, INST_WORD_SIZE*2, 0 }   /* 18: TEXT_PC_OFFSET.  */
 //  { 0x7fffffff, 0x80000000, INST_WORD_SIZE*2, 0 }   /* 16: TLSTPREL_OFFSET.  */
-  { 0x7fffffffffffffff, 0x8000000000000000, INST_WORD_SIZE, 0 }   /* 17: DEFINED_64_OFFSET.  */
+  { 0x7fffffffffffffff, 0x8000000000000000, INST_WORD_SIZE, 0 }   /* 19: DEFINED_64_OFFSET.  */
+  { 0x7fffffffffffffff, 0x8000000000000000, INST_WORD_SIZE*2, 0 }   /* 20: DEFINED_64_PC_OFFSET.  */
 };
 
 static struct hash_control * opcode_hash_control;	/* Opcode mnemonics.  */
@@ -1180,33 +1182,6 @@ md_assemble (char * str)
               inst |= (immed << IMM_LOW) & IMM_MASK;
             }
 	}
-#if 0 //revisit
-      else if (streq (name, "lli") || streq (name, "sli"))
-	{
-          temp = immed & 0xFFFFFFFFFFFF8000;
-          if ((temp != 0) && (temp != 0xFFFFFFFFFFFF8000))
-	    {
-              /* Needs an immediate inst.  */
-              opcode1 = (struct op_code_struct *) hash_find (opcode_hash_control, "imml");
-              if (opcode1 == NULL)
-                {
-                  as_bad (_("unknown opcode \"%s\""), "imml");
-                  return;
-                }
-
-              inst1 = opcode1->bit_sequence;
-	      inst1 |= ((immedl & 0xFFFFFFFFFFFF0000L) >> 16) & IMML_MASK;
-              output[0] = INST_BYTE0 (inst1);
-              output[1] = INST_BYTE1 (inst1);
-              output[2] = INST_BYTE2 (inst1);
-              output[3] = INST_BYTE3 (inst1);
-              output = frag_more (isize);
-	    }
-	  inst |= (reg1 << RD_LOW) & RD_MASK;
-	  inst |= (reg2 << RA_LOW) & RA_MASK;
-	  inst |= (immed << IMM_LOW) & IMM_MASK;
-        }
-#endif
       else
 	{
           temp = immed & 0xFFFF8000;
@@ -1958,8 +1933,8 @@ md_assemble (char * str)
 
       if (exp.X_op != O_constant)
 	{
-	  char *opc = NULL;
-	  //char *opc = str_microblaze_64;
+	  //char *opc = NULL;
+	  char *opc = str_microblaze_64;
 	  relax_substateT subtype;
 
 	  if (exp.X_md != 0)
@@ -2221,13 +2196,19 @@ md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
       fragP->fr_fix += INST_WORD_SIZE * 2;
       fragP->fr_var = 0;
       break;
+    case DEFINED_64_PC_OFFSET:
+      fix_new (fragP, fragP->fr_fix, INST_WORD_SIZE, fragP->fr_symbol,
+	         fragP->fr_offset, TRUE, BFD_RELOC_MICROBLAZE_64_PCREL);
+      fragP->fr_fix += INST_WORD_SIZE * 2;
+      fragP->fr_var = 0;
+      break;
     case DEFINED_64_OFFSET:
       if (fragP->fr_symbol == GOT_symbol)
         fix_new (fragP, fragP->fr_fix, INST_WORD_SIZE, fragP->fr_symbol,
-	         fragP->fr_offset, TRUE, BFD_RELOC_MICROBLAZE_64_GPC);
+	         fragP->fr_offset, FALSE, BFD_RELOC_MICROBLAZE_64_GPC);
       else
         fix_new (fragP, fragP->fr_fix, INST_WORD_SIZE, fragP->fr_symbol,
-	         fragP->fr_offset, TRUE, BFD_RELOC_MICROBLAZE_64);
+	         fragP->fr_offset, FALSE, BFD_RELOC_MICROBLAZE_64);
       fragP->fr_fix += INST_WORD_SIZE * 2;
       fragP->fr_var = 0;
       break;
@@ -2237,7 +2218,7 @@ md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
 	         fragP->fr_offset, TRUE, BFD_RELOC_MICROBLAZE_64_GOTPC);
       else
         fix_new (fragP, fragP->fr_fix, INST_WORD_SIZE * 2, fragP->fr_symbol,
-	         fragP->fr_offset, TRUE, BFD_RELOC_64);
+	         fragP->fr_offset, FALSE, BFD_RELOC_64);
       fragP->fr_fix += INST_WORD_SIZE * 2;
       fragP->fr_var = 0;
       break;
@@ -2457,14 +2438,17 @@ md_apply_fix (fixS *   fixP,
 	    }
 	}
       break;
+
     case BFD_RELOC_64_PCREL:
     case BFD_RELOC_64:
     case BFD_RELOC_MICROBLAZE_64_TEXTREL:
     case BFD_RELOC_MICROBLAZE_64:
+    case BFD_RELOC_MICROBLAZE_64_PCREL:
       /* Add an imm instruction.  First save the current instruction.  */
       for (i = 0; i < INST_WORD_SIZE; i++)
 	buf[i + INST_WORD_SIZE] = buf[i];
-      if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64)
+      if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64
+            || fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64_PCREL)
         {
           /* Generate the imm instruction.  */
           opcode1 = (struct op_code_struct *) hash_find (opcode_hash_control, "imml");
@@ -2477,6 +2461,10 @@ md_apply_fix (fixS *   fixP,
            inst1 = opcode1->bit_sequence;
            if (fixP->fx_addsy == NULL || S_IS_DEFINED (fixP->fx_addsy))
 	     inst1 |= ((val & 0xFFFFFFFFFFFF0000L) >> 16) & IMML_MASK;
+           if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64)
+             fixP->fx_r_type = BFD_RELOC_64; 
+           if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64_PCREL)
+             fixP->fx_r_type = BFD_RELOC_64_PCREL; 
          }
       else
         {
@@ -2487,7 +2475,7 @@ md_apply_fix (fixS *   fixP,
 	      as_bad (_("unknown opcode \"%s\""), "imm");
 	      return;
 	    }
-     
+
           inst1 = opcode1->bit_sequence;
           if (fixP->fx_addsy == NULL || S_IS_DEFINED (fixP->fx_addsy))
 	    inst1 |= ((val & 0xFFFF0000) >> 16) & IMM_MASK;
@@ -2534,7 +2522,7 @@ md_apply_fix (fixS *   fixP,
         opcode1 = (struct op_code_struct *) hash_find (opcode_hash_control, "imm");
       if (opcode1 == NULL)
 	{
-      	  if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64_GPC)
+          if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64_GPC)
 	    as_bad (_("unknown opcode \"%s\""), "imml");
           else
 	    as_bad (_("unknown opcode \"%s\""), "imm");
@@ -2561,8 +2549,6 @@ md_apply_fix (fixS *   fixP,
 	 moves code around due to relaxing.  */
       if (fixP->fx_r_type == BFD_RELOC_64_PCREL)
 	    fixP->fx_r_type = BFD_RELOC_MICROBLAZE_64_NONE;
-      if (fixP->fx_r_type == BFD_RELOC_MICROBLAZE_64)
-	    fixP->fx_r_type = BFD_RELOC_MICROBLAZE_64_NONE;
       else if (fixP->fx_r_type == BFD_RELOC_32)
         fixP->fx_r_type = BFD_RELOC_MICROBLAZE_32_NONE;
       else
@@ -2613,33 +2599,24 @@ md_estimate_size_before_relax (fragS * fragP,
 	     if(streq (fragP->fr_opcode, str_microblaze_64)) 
              {
                /* Used as an absolute value.  */
-              fragP->fr_subtype = DEFINED_64_OFFSET;
+              fragP->fr_subtype = DEFINED_64_PC_OFFSET;
                /* Variable part does not change.  */
-              fragP->fr_var = INST_WORD_SIZE;
+              fragP->fr_var = INST_WORD_SIZE*2;
 	     }
 	   else
 	     {
                fragP->fr_subtype = DEFINED_PC_OFFSET;
-      	       /* Don't know now whether we need an imm instruction.  */
+               /* Don't know now whether we need an imm instruction.  */
                fragP->fr_var = INST_WORD_SIZE;
 	     }
 	   }  
 	   else
 	     {
                fragP->fr_subtype = DEFINED_PC_OFFSET;
-      	       /* Don't know now whether we need an imm instruction.  */
+               /* Don't know now whether we need an imm instruction.  */
                fragP->fr_var = INST_WORD_SIZE;
 	     }
         }
-    #if 0
-      else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type &&
-               !S_IS_WEAK (fragP->fr_symbol))
-        {
-          fragP->fr_subtype = DEFINED_PC_OFFSET;
-          /* Don't know now whether we need an imm instruction.  */
-          fragP->fr_var = INST_WORD_SIZE;
-        }
-#endif
       else if (S_IS_DEFINED (fragP->fr_symbol)
 	       && (((S_GET_SEGMENT (fragP->fr_symbol))->flags & SEC_CODE) == 0))
         {
@@ -2669,6 +2646,13 @@ md_estimate_size_before_relax (fragS * fragP,
 	      /* Variable part does not change.  */
 	      fragP->fr_var = INST_WORD_SIZE*2;
 	    }
+	  else if (streq (fragP->fr_opcode, str_microblaze_64))
+	    {
+              /* Used as an absolute value.  */
+              fragP->fr_subtype = DEFINED_64_OFFSET;
+              /* Variable part does not change.  */
+              fragP->fr_var = INST_WORD_SIZE;
+            }
 	  else if (streq (fragP->fr_opcode, str_microblaze_ro_anchor))
 	    {
               /* It is accessed using the small data read only anchor.  */
@@ -2743,6 +2727,7 @@ md_estimate_size_before_relax (fragS * fragP,
     case TLSTPREL_OFFSET:
     case TLSDTPREL_OFFSET:
     case DEFINED_64_OFFSET:
+    case DEFINED_64_PC_OFFSET:
       fragP->fr_var = INST_WORD_SIZE*2;
       break;
     case DEFINED_RO_SEGMENT:
@@ -2796,7 +2781,7 @@ md_pcrel_from_section (fixS * fixp, segT sec ATTRIBUTE_UNUSED)
   else
     {
       /* The case where we are going to resolve things... */
-      if (fixp->fx_r_type == BFD_RELOC_64_PCREL ||fixp->fx_r_type == BFD_RELOC_MICROBLAZE_64)
+      if (fixp->fx_r_type == BFD_RELOC_64_PCREL ||fixp->fx_r_type == BFD_RELOC_MICROBLAZE_64_PCREL)
         return  fixp->fx_where + fixp->fx_frag->fr_address + INST_WORD_SIZE;
       else
         return  fixp->fx_where + fixp->fx_frag->fr_address;
@@ -2831,6 +2816,7 @@ tc_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
     case BFD_RELOC_MICROBLAZE_64_GOTPC:
     case BFD_RELOC_MICROBLAZE_64_GPC:
     case BFD_RELOC_MICROBLAZE_64:
+    case BFD_RELOC_MICROBLAZE_64_PCREL:
     case BFD_RELOC_MICROBLAZE_64_GOT:
     case BFD_RELOC_MICROBLAZE_64_PLT:
     case BFD_RELOC_MICROBLAZE_64_GOTOFF:
-- 
2.7.4