Commit | Line | Data |
---|---|---|
a85d7ed0 | 1 | /* tc-s390.c -- Assemble for the S390 |
20203fb9 | 2 | Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
87975d2a | 3 | 2009, 2010 Free Software Foundation, Inc. |
a85d7ed0 NC |
4 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). |
5 | ||
6 | This file is part of GAS, the GNU Assembler. | |
7 | ||
8 | GAS is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 10 | the Free Software Foundation; either version 3, or (at your option) |
a85d7ed0 NC |
11 | any later version. |
12 | ||
13 | GAS is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
20 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
21 | 02110-1301, USA. */ | |
a85d7ed0 | 22 | |
a85d7ed0 | 23 | #include "as.h" |
3882b010 | 24 | #include "safe-ctype.h" |
a85d7ed0 NC |
25 | #include "subsegs.h" |
26 | #include "struc-symbol.h" | |
a161fe53 | 27 | #include "dwarf2dbg.h" |
75e21f08 | 28 | #include "dw2gencfi.h" |
a85d7ed0 NC |
29 | |
30 | #include "opcode/s390.h" | |
31 | #include "elf/s390.h" | |
32 | ||
16a419ba | 33 | /* The default architecture. */ |
a85d7ed0 NC |
34 | #ifndef DEFAULT_ARCH |
35 | #define DEFAULT_ARCH "s390" | |
36 | #endif | |
37 | static char *default_arch = DEFAULT_ARCH; | |
38 | /* Either 32 or 64, selects file format. */ | |
37a58793 MS |
39 | static int s390_arch_size = 0; |
40 | ||
41 | static unsigned int current_mode_mask = 0; | |
42 | static unsigned int current_cpu = -1U; | |
a85d7ed0 | 43 | |
b34976b6 | 44 | /* Whether to use user friendly register names. Default is TRUE. */ |
a85d7ed0 | 45 | #ifndef TARGET_REG_NAMES_P |
b34976b6 | 46 | #define TARGET_REG_NAMES_P TRUE |
a85d7ed0 NC |
47 | #endif |
48 | ||
b34976b6 | 49 | static bfd_boolean reg_names_p = TARGET_REG_NAMES_P; |
a85d7ed0 | 50 | |
16a419ba | 51 | /* Set to TRUE if we want to warn about zero base/index registers. */ |
b34976b6 | 52 | static bfd_boolean warn_areg_zero = FALSE; |
16a419ba | 53 | |
a85d7ed0 NC |
54 | /* Generic assembler global variables which must be defined by all |
55 | targets. */ | |
56 | ||
57 | const char comment_chars[] = "#"; | |
58 | ||
59 | /* Characters which start a comment at the beginning of a line. */ | |
60 | const char line_comment_chars[] = "#"; | |
61 | ||
62 | /* Characters which may be used to separate multiple commands on a | |
63 | single line. */ | |
64 | const char line_separator_chars[] = ";"; | |
65 | ||
66 | /* Characters which are used to indicate an exponent in a floating | |
67 | point number. */ | |
68 | const char EXP_CHARS[] = "eE"; | |
69 | ||
70 | /* Characters which mean that a number is a floating point constant, | |
71 | as in 0d1.0. */ | |
72 | const char FLT_CHARS[] = "dD"; | |
73 | ||
75e21f08 JJ |
74 | /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */ |
75 | int s390_cie_data_alignment; | |
76 | ||
a85d7ed0 NC |
77 | /* The target specific pseudo-ops which we support. */ |
78 | ||
79 | /* Define the prototypes for the pseudo-ops */ | |
5a49b8ac AM |
80 | static void s390_byte (int); |
81 | static void s390_elf_cons (int); | |
82 | static void s390_bss (int); | |
83 | static void s390_insn (int); | |
84 | static void s390_literals (int); | |
a85d7ed0 NC |
85 | |
86 | const pseudo_typeS md_pseudo_table[] = | |
87 | { | |
88 | { "align", s_align_bytes, 0 }, | |
98d3f06f | 89 | /* Pseudo-ops which must be defined. */ |
198ce79b | 90 | { "bss", s390_bss, 0 }, |
a85d7ed0 NC |
91 | { "insn", s390_insn, 0 }, |
92 | /* Pseudo-ops which must be overridden. */ | |
93 | { "byte", s390_byte, 0 }, | |
94 | { "short", s390_elf_cons, 2 }, | |
95 | { "long", s390_elf_cons, 4 }, | |
96 | { "quad", s390_elf_cons, 8 }, | |
97 | { "ltorg", s390_literals, 0 }, | |
38a57ae7 | 98 | { "string", stringer, 8 + 1 }, |
a85d7ed0 NC |
99 | { NULL, NULL, 0 } |
100 | }; | |
101 | ||
102 | ||
103 | /* Structure to hold information about predefined registers. */ | |
104 | struct pd_reg | |
105 | { | |
106 | char *name; | |
107 | int value; | |
108 | }; | |
109 | ||
110 | /* List of registers that are pre-defined: | |
111 | ||
112 | Each access register has a predefined name of the form: | |
113 | a<reg_num> which has the value <reg_num>. | |
114 | ||
115 | Each control register has a predefined name of the form: | |
116 | c<reg_num> which has the value <reg_num>. | |
117 | ||
118 | Each general register has a predefined name of the form: | |
119 | r<reg_num> which has the value <reg_num>. | |
120 | ||
121 | Each floating point register a has predefined name of the form: | |
122 | f<reg_num> which has the value <reg_num>. | |
123 | ||
124 | There are individual registers as well: | |
125 | sp has the value 15 | |
126 | lit has the value 12 | |
127 | ||
98d3f06f | 128 | The table is sorted. Suitable for searching by a binary search. */ |
a85d7ed0 NC |
129 | |
130 | static const struct pd_reg pre_defined_registers[] = | |
131 | { | |
132 | { "a0", 0 }, /* Access registers */ | |
133 | { "a1", 1 }, | |
134 | { "a10", 10 }, | |
135 | { "a11", 11 }, | |
136 | { "a12", 12 }, | |
137 | { "a13", 13 }, | |
138 | { "a14", 14 }, | |
139 | { "a15", 15 }, | |
140 | { "a2", 2 }, | |
141 | { "a3", 3 }, | |
142 | { "a4", 4 }, | |
143 | { "a5", 5 }, | |
144 | { "a6", 6 }, | |
145 | { "a7", 7 }, | |
146 | { "a8", 8 }, | |
147 | { "a9", 9 }, | |
148 | ||
149 | { "c0", 0 }, /* Control registers */ | |
150 | { "c1", 1 }, | |
151 | { "c10", 10 }, | |
152 | { "c11", 11 }, | |
153 | { "c12", 12 }, | |
154 | { "c13", 13 }, | |
155 | { "c14", 14 }, | |
156 | { "c15", 15 }, | |
157 | { "c2", 2 }, | |
158 | { "c3", 3 }, | |
159 | { "c4", 4 }, | |
160 | { "c5", 5 }, | |
161 | { "c6", 6 }, | |
162 | { "c7", 7 }, | |
163 | { "c8", 8 }, | |
164 | { "c9", 9 }, | |
165 | ||
166 | { "f0", 0 }, /* Floating point registers */ | |
198ce79b AJ |
167 | { "f1", 1 }, |
168 | { "f10", 10 }, | |
169 | { "f11", 11 }, | |
170 | { "f12", 12 }, | |
171 | { "f13", 13 }, | |
172 | { "f14", 14 }, | |
173 | { "f15", 15 }, | |
174 | { "f2", 2 }, | |
175 | { "f3", 3 }, | |
176 | { "f4", 4 }, | |
177 | { "f5", 5 }, | |
178 | { "f6", 6 }, | |
179 | { "f7", 7 }, | |
180 | { "f8", 8 }, | |
181 | { "f9", 9 }, | |
a85d7ed0 NC |
182 | |
183 | { "lit", 13 }, /* Pointer to literal pool */ | |
184 | ||
185 | { "r0", 0 }, /* General purpose registers */ | |
186 | { "r1", 1 }, | |
187 | { "r10", 10 }, | |
188 | { "r11", 11 }, | |
189 | { "r12", 12 }, | |
190 | { "r13", 13 }, | |
191 | { "r14", 14 }, | |
192 | { "r15", 15 }, | |
193 | { "r2", 2 }, | |
194 | { "r3", 3 }, | |
195 | { "r4", 4 }, | |
196 | { "r5", 5 }, | |
197 | { "r6", 6 }, | |
198 | { "r7", 7 }, | |
199 | { "r8", 8 }, | |
200 | { "r9", 9 }, | |
201 | ||
202 | { "sp", 15 }, /* Stack pointer */ | |
203 | ||
204 | }; | |
205 | ||
07726851 | 206 | #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg)) |
a85d7ed0 NC |
207 | |
208 | /* Given NAME, find the register number associated with that name, return | |
209 | the integer value associated with the given name or -1 on failure. */ | |
210 | ||
211 | static int | |
5a49b8ac | 212 | reg_name_search (const struct pd_reg *regs, int regcount, const char *name) |
a85d7ed0 NC |
213 | { |
214 | int middle, low, high; | |
215 | int cmp; | |
216 | ||
217 | low = 0; | |
218 | high = regcount - 1; | |
219 | ||
220 | do | |
221 | { | |
222 | middle = (low + high) / 2; | |
223 | cmp = strcasecmp (name, regs[middle].name); | |
224 | if (cmp < 0) | |
225 | high = middle - 1; | |
226 | else if (cmp > 0) | |
227 | low = middle + 1; | |
228 | else | |
229 | return regs[middle].value; | |
230 | } | |
231 | while (low <= high); | |
232 | ||
233 | return -1; | |
234 | } | |
235 | ||
236 | ||
237 | /* | |
238 | * Summary of register_name(). | |
239 | * | |
240 | * in: Input_line_pointer points to 1st char of operand. | |
241 | * | |
242 | * out: A expressionS. | |
243 | * The operand may have been a register: in this case, X_op == O_register, | |
244 | * X_add_number is set to the register number, and truth is returned. | |
245 | * Input_line_pointer->(next non-blank) char after operand, or is in its | |
246 | * original state. | |
247 | */ | |
248 | ||
b34976b6 | 249 | static bfd_boolean |
5a49b8ac | 250 | register_name (expressionS *expressionP) |
a85d7ed0 NC |
251 | { |
252 | int reg_number; | |
253 | char *name; | |
254 | char *start; | |
255 | char c; | |
256 | ||
468cced8 | 257 | /* Find the spelling of the operand. */ |
a85d7ed0 | 258 | start = name = input_line_pointer; |
3882b010 | 259 | if (name[0] == '%' && ISALPHA (name[1])) |
a85d7ed0 NC |
260 | name = ++input_line_pointer; |
261 | else | |
b34976b6 | 262 | return FALSE; |
a85d7ed0 NC |
263 | |
264 | c = get_symbol_end (); | |
265 | reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name); | |
266 | ||
468cced8 AM |
267 | /* Put back the delimiting char. */ |
268 | *input_line_pointer = c; | |
269 | ||
270 | /* Look to see if it's in the register table. */ | |
198ce79b | 271 | if (reg_number >= 0) |
a85d7ed0 NC |
272 | { |
273 | expressionP->X_op = O_register; | |
274 | expressionP->X_add_number = reg_number; | |
198ce79b | 275 | |
468cced8 | 276 | /* Make the rest nice. */ |
a85d7ed0 NC |
277 | expressionP->X_add_symbol = NULL; |
278 | expressionP->X_op_symbol = NULL; | |
b34976b6 | 279 | return TRUE; |
a85d7ed0 | 280 | } |
468cced8 AM |
281 | |
282 | /* Reset the line as if we had not done anything. */ | |
283 | input_line_pointer = start; | |
b34976b6 | 284 | return FALSE; |
a85d7ed0 NC |
285 | } |
286 | ||
287 | /* Local variables. */ | |
288 | ||
289 | /* Opformat hash table. */ | |
290 | static struct hash_control *s390_opformat_hash; | |
291 | ||
292 | /* Opcode hash table. */ | |
293 | static struct hash_control *s390_opcode_hash; | |
294 | ||
295 | /* Flags to set in the elf header */ | |
296 | static flagword s390_flags = 0; | |
297 | ||
298 | symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ | |
299 | ||
300 | #ifndef WORKING_DOT_WORD | |
2b4f075a HPN |
301 | int md_short_jump_size = 4; |
302 | int md_long_jump_size = 4; | |
a85d7ed0 NC |
303 | #endif |
304 | ||
5a38dc70 | 305 | const char *md_shortopts = "A:m:kVQ:"; |
a85d7ed0 NC |
306 | struct option md_longopts[] = { |
307 | {NULL, no_argument, NULL, 0} | |
308 | }; | |
07726851 | 309 | size_t md_longopts_size = sizeof (md_longopts); |
a85d7ed0 NC |
310 | |
311 | /* Initialize the default opcode arch and word size from the default | |
37a58793 | 312 | architecture name if not specified by an option. */ |
a85d7ed0 | 313 | static void |
5a49b8ac | 314 | init_default_arch (void) |
a85d7ed0 | 315 | { |
07726851 | 316 | if (strcmp (default_arch, "s390") == 0) |
07855bec | 317 | { |
37a58793 MS |
318 | if (s390_arch_size == 0) |
319 | s390_arch_size = 32; | |
07855bec | 320 | } |
07726851 | 321 | else if (strcmp (default_arch, "s390x") == 0) |
07855bec | 322 | { |
37a58793 MS |
323 | if (s390_arch_size == 0) |
324 | s390_arch_size = 64; | |
07855bec NC |
325 | } |
326 | else | |
20203fb9 | 327 | as_fatal (_("Invalid default architecture, broken assembler.")); |
df9a398f MS |
328 | |
329 | if (current_mode_mask == 0) | |
330 | { | |
331 | if (s390_arch_size == 32) | |
332 | current_mode_mask = 1 << S390_OPCODE_ESA; | |
333 | else | |
334 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
335 | } | |
336 | if (current_cpu == -1U) | |
337 | { | |
338 | if (current_mode_mask == (1 << S390_OPCODE_ESA)) | |
339 | current_cpu = S390_OPCODE_G5; | |
340 | else | |
341 | current_cpu = S390_OPCODE_Z900; | |
342 | } | |
a85d7ed0 NC |
343 | } |
344 | ||
345 | /* Called by TARGET_FORMAT. */ | |
346 | const char * | |
5a49b8ac | 347 | s390_target_format (void) |
a85d7ed0 NC |
348 | { |
349 | /* We don't get a chance to initialize anything before we're called, | |
350 | so handle that now. */ | |
2ebb4b88 | 351 | init_default_arch (); |
a85d7ed0 NC |
352 | |
353 | return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390"; | |
354 | } | |
355 | ||
356 | int | |
5a49b8ac | 357 | md_parse_option (int c, char *arg) |
a85d7ed0 | 358 | { |
07855bec NC |
359 | switch (c) |
360 | { | |
361 | /* -k: Ignore for FreeBSD compatibility. */ | |
362 | case 'k': | |
363 | break; | |
364 | case 'm': | |
365 | if (arg != NULL && strcmp (arg, "regnames") == 0) | |
b34976b6 | 366 | reg_names_p = TRUE; |
198ce79b | 367 | |
07855bec | 368 | else if (arg != NULL && strcmp (arg, "no-regnames") == 0) |
b34976b6 | 369 | reg_names_p = FALSE; |
198ce79b | 370 | |
16a419ba NC |
371 | else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0) |
372 | warn_areg_zero = TRUE; | |
373 | ||
ff0fb565 | 374 | else if (arg != NULL && strcmp (arg, "31") == 0) |
75504fed | 375 | s390_arch_size = 32; |
ff0fb565 MS |
376 | |
377 | else if (arg != NULL && strcmp (arg, "64") == 0) | |
378 | s390_arch_size = 64; | |
379 | ||
37a58793 MS |
380 | else if (arg != NULL && strcmp (arg, "esa") == 0) |
381 | current_mode_mask = 1 << S390_OPCODE_ESA; | |
382 | ||
383 | else if (arg != NULL && strcmp (arg, "zarch") == 0) | |
384 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
385 | ||
386 | else if (arg != NULL && strncmp (arg, "arch=", 5) == 0) | |
387 | { | |
388 | if (strcmp (arg + 5, "g5") == 0) | |
389 | current_cpu = S390_OPCODE_G5; | |
390 | else if (strcmp (arg + 5, "g6") == 0) | |
391 | current_cpu = S390_OPCODE_G6; | |
392 | else if (strcmp (arg + 5, "z900") == 0) | |
393 | current_cpu = S390_OPCODE_Z900; | |
933fbc29 MS |
394 | else if (strcmp (arg + 5, "z990") == 0) |
395 | current_cpu = S390_OPCODE_Z990; | |
6c639ef9 MS |
396 | else if (strcmp (arg + 5, "z9-109") == 0) |
397 | current_cpu = S390_OPCODE_Z9_109; | |
b5639b37 MS |
398 | else if (strcmp (arg + 5, "z9-ec") == 0) |
399 | current_cpu = S390_OPCODE_Z9_EC; | |
5746fb46 AK |
400 | else if (strcmp (arg + 5, "z10") == 0) |
401 | current_cpu = S390_OPCODE_Z10; | |
d9aee5d7 AK |
402 | else if (strcmp (arg + 5, "z196") == 0) |
403 | current_cpu = S390_OPCODE_Z196; | |
37a58793 MS |
404 | else |
405 | { | |
406 | as_bad (_("invalid switch -m%s"), arg); | |
407 | return 0; | |
408 | } | |
409 | } | |
410 | ||
07855bec NC |
411 | else |
412 | { | |
413 | as_bad (_("invalid switch -m%s"), arg); | |
414 | return 0; | |
415 | } | |
416 | break; | |
198ce79b | 417 | |
07855bec | 418 | case 'A': |
67c1ffbe | 419 | /* Option -A is deprecated. Still available for compatibility. */ |
07855bec | 420 | if (arg != NULL && strcmp (arg, "esa") == 0) |
37a58793 | 421 | current_cpu = S390_OPCODE_G5; |
07855bec | 422 | else if (arg != NULL && strcmp (arg, "esame") == 0) |
37a58793 | 423 | current_cpu = S390_OPCODE_Z900; |
07855bec | 424 | else |
20203fb9 | 425 | as_bad (_("invalid architecture -A%s"), arg); |
07855bec NC |
426 | break; |
427 | ||
428 | /* -V: SVR4 argument to print version ID. */ | |
429 | case 'V': | |
430 | print_version_id (); | |
431 | break; | |
198ce79b | 432 | |
07855bec NC |
433 | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section |
434 | should be emitted or not. FIXME: Not implemented. */ | |
435 | case 'Q': | |
436 | break; | |
198ce79b | 437 | |
07855bec NC |
438 | default: |
439 | return 0; | |
440 | } | |
198ce79b | 441 | |
a85d7ed0 NC |
442 | return 1; |
443 | } | |
444 | ||
445 | void | |
5a49b8ac | 446 | md_show_usage (FILE *stream) |
a85d7ed0 | 447 | { |
07855bec | 448 | fprintf (stream, _("\ |
16a419ba NC |
449 | S390 options:\n\ |
450 | -mregnames Allow symbolic names for registers\n\ | |
451 | -mwarn-areg-zero Warn about zero base/index registers\n\ | |
ff0fb565 MS |
452 | -mno-regnames Do not allow symbolic names for registers\n\ |
453 | -m31 Set file format to 31 bit format\n\ | |
454 | -m64 Set file format to 64 bit format\n")); | |
07855bec | 455 | fprintf (stream, _("\ |
16a419ba NC |
456 | -V print assembler version number\n\ |
457 | -Qy, -Qn ignored\n")); | |
a85d7ed0 NC |
458 | } |
459 | ||
460 | /* This function is called when the assembler starts up. It is called | |
461 | after the options have been parsed and the output file has been | |
16a419ba | 462 | opened. */ |
a85d7ed0 NC |
463 | |
464 | void | |
5a49b8ac | 465 | md_begin (void) |
a85d7ed0 NC |
466 | { |
467 | register const struct s390_opcode *op; | |
468 | const struct s390_opcode *op_end; | |
b34976b6 | 469 | bfd_boolean dup_insn = FALSE; |
a85d7ed0 NC |
470 | const char *retval; |
471 | ||
ff0fb565 | 472 | /* Give a warning if the combination -m64-bit and -Aesa is used. */ |
37a58793 | 473 | if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900) |
20203fb9 | 474 | as_warn (_("The 64 bit file format is used without esame instructions.")); |
ff0fb565 | 475 | |
75e21f08 JJ |
476 | s390_cie_data_alignment = -s390_arch_size / 8; |
477 | ||
16a419ba | 478 | /* Set the ELF flags if desired. */ |
a85d7ed0 NC |
479 | if (s390_flags) |
480 | bfd_set_private_flags (stdoutput, s390_flags); | |
481 | ||
482 | /* Insert the opcode formats into a hash table. */ | |
483 | s390_opformat_hash = hash_new (); | |
484 | ||
485 | op_end = s390_opformats + s390_num_opformats; | |
07855bec NC |
486 | for (op = s390_opformats; op < op_end; op++) |
487 | { | |
5a49b8ac | 488 | retval = hash_insert (s390_opformat_hash, op->name, (void *) op); |
07855bec NC |
489 | if (retval != (const char *) NULL) |
490 | { | |
491 | as_bad (_("Internal assembler error for instruction format %s"), | |
492 | op->name); | |
b34976b6 | 493 | dup_insn = TRUE; |
07855bec NC |
494 | } |
495 | } | |
a85d7ed0 NC |
496 | |
497 | /* Insert the opcodes into a hash table. */ | |
498 | s390_opcode_hash = hash_new (); | |
499 | ||
500 | op_end = s390_opcodes + s390_num_opcodes; | |
07855bec | 501 | for (op = s390_opcodes; op < op_end; op++) |
e6181b6a MS |
502 | { |
503 | while (op < op_end - 1 && strcmp(op->name, op[1].name) == 0) | |
504 | { | |
505 | if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask)) | |
506 | break; | |
933fbc29 | 507 | op++; |
e6181b6a | 508 | } |
be7a250d AK |
509 | |
510 | if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask)) | |
511 | { | |
512 | retval = hash_insert (s390_opcode_hash, op->name, (void *) op); | |
513 | if (retval != (const char *) NULL) | |
514 | { | |
515 | as_bad (_("Internal assembler error for instruction %s"), | |
516 | op->name); | |
517 | dup_insn = TRUE; | |
518 | } | |
e6181b6a | 519 | } |
be7a250d | 520 | |
e6181b6a MS |
521 | while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0) |
522 | op++; | |
933fbc29 | 523 | } |
07855bec | 524 | |
a85d7ed0 NC |
525 | if (dup_insn) |
526 | abort (); | |
527 | ||
528 | record_alignment (text_section, 2); | |
529 | record_alignment (data_section, 2); | |
530 | record_alignment (bss_section, 2); | |
531 | ||
532 | } | |
533 | ||
534 | /* Called after all assembly has been done. */ | |
535 | void | |
5a49b8ac | 536 | s390_md_end (void) |
a85d7ed0 | 537 | { |
07855bec | 538 | if (s390_arch_size == 64) |
ff0fb565 | 539 | bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64); |
07855bec | 540 | else |
ff0fb565 | 541 | bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31); |
a85d7ed0 NC |
542 | } |
543 | ||
a85d7ed0 NC |
544 | /* Insert an operand value into an instruction. */ |
545 | ||
546 | static void | |
5a49b8ac AM |
547 | s390_insert_operand (unsigned char *insn, |
548 | const struct s390_operand *operand, | |
549 | offsetT val, | |
550 | char *file, | |
551 | unsigned int line) | |
a85d7ed0 NC |
552 | { |
553 | addressT uval; | |
554 | int offset; | |
555 | ||
07855bec NC |
556 | if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL)) |
557 | { | |
558 | offsetT min, max; | |
559 | ||
560 | max = ((offsetT) 1 << (operand->bits - 1)) - 1; | |
561 | min = - ((offsetT) 1 << (operand->bits - 1)); | |
562 | /* Halve PCREL operands. */ | |
563 | if (operand->flags & S390_OPERAND_PCREL) | |
564 | val >>= 1; | |
565 | /* Check for underflow / overflow. */ | |
566 | if (val < min || val > max) | |
567 | { | |
568 | const char *err = | |
20203fb9 | 569 | _("operand out of range (%s not between %ld and %ld)"); |
07855bec NC |
570 | char buf[100]; |
571 | ||
572 | if (operand->flags & S390_OPERAND_PCREL) | |
573 | { | |
574 | val <<= 1; | |
575 | min <<= 1; | |
576 | max <<= 1; | |
577 | } | |
578 | sprint_value (buf, val); | |
579 | if (file == (char *) NULL) | |
580 | as_bad (err, buf, (int) min, (int) max); | |
581 | else | |
582 | as_bad_where (file, line, err, buf, (int) min, (int) max); | |
583 | return; | |
584 | } | |
585 | /* val is ok, now restrict it to operand->bits bits. */ | |
586 | uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1); | |
933fbc29 MS |
587 | /* val is restrict, now check for special case. */ |
588 | if (operand->bits == 20 && operand->shift == 20) | |
589 | uval = (uval >> 12) | ((uval & 0xfff) << 8); | |
a85d7ed0 | 590 | } |
07855bec NC |
591 | else |
592 | { | |
593 | addressT min, max; | |
198ce79b | 594 | |
98d3f06f | 595 | max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1; |
07855bec NC |
596 | min = (offsetT) 0; |
597 | uval = (addressT) val; | |
598 | /* Length x in an instructions has real length x+1. */ | |
599 | if (operand->flags & S390_OPERAND_LENGTH) | |
600 | uval--; | |
601 | /* Check for underflow / overflow. */ | |
602 | if (uval < min || uval > max) | |
603 | { | |
07855bec NC |
604 | if (operand->flags & S390_OPERAND_LENGTH) |
605 | { | |
606 | uval++; | |
607 | min++; | |
608 | max++; | |
609 | } | |
e5976317 NC |
610 | |
611 | as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line); | |
612 | ||
07855bec NC |
613 | return; |
614 | } | |
a85d7ed0 | 615 | } |
a85d7ed0 NC |
616 | |
617 | /* Insert fragments of the operand byte for byte. */ | |
618 | offset = operand->shift + operand->bits; | |
619 | uval <<= (-offset) & 7; | |
98d3f06f | 620 | insn += (offset - 1) / 8; |
07855bec NC |
621 | while (uval != 0) |
622 | { | |
623 | *insn-- |= uval; | |
624 | uval >>= 8; | |
625 | } | |
a85d7ed0 NC |
626 | } |
627 | ||
1971b29d MS |
628 | struct map_tls |
629 | { | |
630 | char *string; | |
631 | int length; | |
632 | bfd_reloc_code_real_type reloc; | |
633 | }; | |
634 | ||
1971b29d MS |
635 | /* Parse tls marker and return the desired relocation. */ |
636 | static bfd_reloc_code_real_type | |
5a49b8ac | 637 | s390_tls_suffix (char **str_p, expressionS *exp_p) |
1971b29d MS |
638 | { |
639 | static struct map_tls mapping[] = | |
640 | { | |
641 | { "tls_load", 8, BFD_RELOC_390_TLS_LOAD }, | |
642 | { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL }, | |
643 | { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL }, | |
644 | { NULL, 0, BFD_RELOC_UNUSED } | |
645 | }; | |
646 | struct map_tls *ptr; | |
647 | char *orig_line; | |
648 | char *str; | |
649 | char *ident; | |
650 | int len; | |
651 | ||
652 | str = *str_p; | |
653 | if (*str++ != ':') | |
654 | return BFD_RELOC_UNUSED; | |
655 | ||
656 | ident = str; | |
657 | while (ISIDNUM (*str)) | |
658 | str++; | |
659 | len = str - ident; | |
660 | if (*str++ != ':') | |
661 | return BFD_RELOC_UNUSED; | |
662 | ||
663 | orig_line = input_line_pointer; | |
664 | input_line_pointer = str; | |
665 | expression (exp_p); | |
666 | str = input_line_pointer; | |
667 | if (&input_line_pointer != str_p) | |
668 | input_line_pointer = orig_line; | |
669 | ||
670 | if (exp_p->X_op != O_symbol) | |
671 | return BFD_RELOC_UNUSED; | |
672 | ||
673 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
674 | if (len == ptr->length | |
675 | && strncasecmp (ident, ptr->string, ptr->length) == 0) | |
676 | { | |
677 | /* Found a matching tls suffix. */ | |
678 | *str_p = str; | |
679 | return ptr->reloc; | |
680 | } | |
681 | return BFD_RELOC_UNUSED; | |
682 | } | |
683 | ||
a85d7ed0 | 684 | /* Structure used to hold suffixes. */ |
07855bec NC |
685 | typedef enum |
686 | { | |
687 | ELF_SUFFIX_NONE = 0, | |
688 | ELF_SUFFIX_GOT, | |
689 | ELF_SUFFIX_PLT, | |
2a19f73f MS |
690 | ELF_SUFFIX_GOTENT, |
691 | ELF_SUFFIX_GOTOFF, | |
692 | ELF_SUFFIX_GOTPLT, | |
1971b29d MS |
693 | ELF_SUFFIX_PLTOFF, |
694 | ELF_SUFFIX_TLS_GD, | |
695 | ELF_SUFFIX_TLS_GOTIE, | |
696 | ELF_SUFFIX_TLS_IE, | |
697 | ELF_SUFFIX_TLS_LDM, | |
698 | ELF_SUFFIX_TLS_LDO, | |
699 | ELF_SUFFIX_TLS_LE | |
07855bec NC |
700 | } |
701 | elf_suffix_type; | |
702 | ||
703 | struct map_bfd | |
704 | { | |
705 | char *string; | |
706 | int length; | |
707 | elf_suffix_type suffix; | |
708 | }; | |
a85d7ed0 | 709 | |
9d654c1c | 710 | |
a85d7ed0 NC |
711 | /* Parse @got/@plt/@gotoff. and return the desired relocation. */ |
712 | static elf_suffix_type | |
5a49b8ac | 713 | s390_elf_suffix (char **str_p, expressionS *exp_p) |
a85d7ed0 | 714 | { |
07855bec NC |
715 | static struct map_bfd mapping[] = |
716 | { | |
a85d7ed0 NC |
717 | { "got", 3, ELF_SUFFIX_GOT }, |
718 | { "got12", 5, ELF_SUFFIX_GOT }, | |
719 | { "plt", 3, ELF_SUFFIX_PLT }, | |
720 | { "gotent", 6, ELF_SUFFIX_GOTENT }, | |
2a19f73f MS |
721 | { "gotoff", 6, ELF_SUFFIX_GOTOFF }, |
722 | { "gotplt", 6, ELF_SUFFIX_GOTPLT }, | |
723 | { "pltoff", 6, ELF_SUFFIX_PLTOFF }, | |
1971b29d MS |
724 | { "tlsgd", 5, ELF_SUFFIX_TLS_GD }, |
725 | { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE }, | |
726 | { "indntpoff", 9, ELF_SUFFIX_TLS_IE }, | |
727 | { "tlsldm", 6, ELF_SUFFIX_TLS_LDM }, | |
728 | { "dtpoff", 6, ELF_SUFFIX_TLS_LDO }, | |
729 | { "ntpoff", 6, ELF_SUFFIX_TLS_LE }, | |
a85d7ed0 NC |
730 | { NULL, 0, ELF_SUFFIX_NONE } |
731 | }; | |
732 | ||
733 | struct map_bfd *ptr; | |
734 | char *str = *str_p; | |
735 | char *ident; | |
736 | int len; | |
737 | ||
738 | if (*str++ != '@') | |
739 | return ELF_SUFFIX_NONE; | |
740 | ||
741 | ident = str; | |
3882b010 | 742 | while (ISALNUM (*str)) |
a85d7ed0 NC |
743 | str++; |
744 | len = str - ident; | |
745 | ||
746 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
16a419ba NC |
747 | if (len == ptr->length |
748 | && strncasecmp (ident, ptr->string, ptr->length) == 0) | |
07855bec NC |
749 | { |
750 | if (exp_p->X_add_number != 0) | |
751 | as_warn (_("identifier+constant@%s means identifier@%s+constant"), | |
752 | ptr->string, ptr->string); | |
753 | /* Now check for identifier@suffix+constant. */ | |
754 | if (*str == '-' || *str == '+') | |
755 | { | |
756 | char *orig_line = input_line_pointer; | |
757 | expressionS new_exp; | |
758 | ||
759 | input_line_pointer = str; | |
760 | expression (&new_exp); | |
761 | ||
762 | switch (new_exp.X_op) | |
763 | { | |
764 | case O_constant: /* X_add_number (a constant expression). */ | |
765 | exp_p->X_add_number += new_exp.X_add_number; | |
766 | str = input_line_pointer; | |
767 | break; | |
768 | case O_symbol: /* X_add_symbol + X_add_number. */ | |
769 | /* this case is used for e.g. xyz@PLT+.Label. */ | |
770 | exp_p->X_add_number += new_exp.X_add_number; | |
771 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
772 | exp_p->X_op = O_add; | |
773 | str = input_line_pointer; | |
774 | break; | |
775 | case O_uminus: /* (- X_add_symbol) + X_add_number. */ | |
776 | /* this case is used for e.g. xyz@PLT-.Label. */ | |
777 | exp_p->X_add_number += new_exp.X_add_number; | |
778 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
779 | exp_p->X_op = O_subtract; | |
780 | str = input_line_pointer; | |
781 | break; | |
782 | default: | |
783 | break; | |
784 | } | |
785 | ||
786 | /* If s390_elf_suffix has not been called with | |
787 | &input_line_pointer as first parameter, we have | |
788 | clobbered the input_line_pointer. We have to | |
789 | undo that. */ | |
790 | if (&input_line_pointer != str_p) | |
791 | input_line_pointer = orig_line; | |
a85d7ed0 | 792 | } |
07855bec NC |
793 | *str_p = str; |
794 | return ptr->suffix; | |
a85d7ed0 | 795 | } |
a85d7ed0 NC |
796 | |
797 | return BFD_RELOC_UNUSED; | |
798 | } | |
799 | ||
800 | /* Structure used to hold a literal pool entry. */ | |
07855bec NC |
801 | struct s390_lpe |
802 | { | |
803 | struct s390_lpe *next; | |
804 | expressionS ex; | |
805 | FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */ | |
806 | LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */ | |
807 | int nbytes; | |
808 | bfd_reloc_code_real_type reloc; | |
809 | symbolS *sym; | |
810 | }; | |
a85d7ed0 NC |
811 | |
812 | static struct s390_lpe *lpe_free_list = NULL; | |
813 | static struct s390_lpe *lpe_list = NULL; | |
814 | static struct s390_lpe *lpe_list_tail = NULL; | |
815 | static symbolS *lp_sym = NULL; | |
816 | static int lp_count = 0; | |
817 | static int lpe_count = 0; | |
818 | ||
819 | static int | |
5a49b8ac | 820 | s390_exp_compare (expressionS *exp1, expressionS *exp2) |
a85d7ed0 NC |
821 | { |
822 | if (exp1->X_op != exp2->X_op) | |
823 | return 0; | |
824 | ||
07855bec NC |
825 | switch (exp1->X_op) |
826 | { | |
827 | case O_constant: /* X_add_number must be equal. */ | |
828 | case O_register: | |
829 | return exp1->X_add_number == exp2->X_add_number; | |
830 | ||
831 | case O_big: | |
198ce79b | 832 | as_bad (_("Can't handle O_big in s390_exp_compare")); |
07855bec NC |
833 | |
834 | case O_symbol: /* X_add_symbol & X_add_number must be equal. */ | |
835 | case O_symbol_rva: | |
836 | case O_uminus: | |
837 | case O_bit_not: | |
838 | case O_logical_not: | |
16a419ba NC |
839 | return (exp1->X_add_symbol == exp2->X_add_symbol) |
840 | && (exp1->X_add_number == exp2->X_add_number); | |
07855bec NC |
841 | |
842 | case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */ | |
843 | case O_divide: | |
844 | case O_modulus: | |
845 | case O_left_shift: | |
846 | case O_right_shift: | |
847 | case O_bit_inclusive_or: | |
848 | case O_bit_or_not: | |
849 | case O_bit_exclusive_or: | |
850 | case O_bit_and: | |
851 | case O_add: | |
852 | case O_subtract: | |
853 | case O_eq: | |
854 | case O_ne: | |
855 | case O_lt: | |
856 | case O_le: | |
857 | case O_ge: | |
858 | case O_gt: | |
859 | case O_logical_and: | |
860 | case O_logical_or: | |
16a419ba NC |
861 | return (exp1->X_add_symbol == exp2->X_add_symbol) |
862 | && (exp1->X_op_symbol == exp2->X_op_symbol) | |
863 | && (exp1->X_add_number == exp2->X_add_number); | |
07855bec | 864 | default: |
98d3f06f KH |
865 | return 0; |
866 | } | |
a85d7ed0 NC |
867 | } |
868 | ||
869 | /* Test for @lit and if its present make an entry in the literal pool and | |
870 | modify the current expression to be an offset into the literal pool. */ | |
871 | static elf_suffix_type | |
5a49b8ac | 872 | s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix) |
a85d7ed0 NC |
873 | { |
874 | bfd_reloc_code_real_type reloc; | |
875 | char tmp_name[64]; | |
876 | char *str = *str_p; | |
877 | char *ident; | |
878 | struct s390_lpe *lpe; | |
879 | int nbytes, len; | |
880 | ||
881 | if (*str++ != ':') | |
882 | return suffix; /* No modification. */ | |
198ce79b | 883 | |
a85d7ed0 NC |
884 | /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */ |
885 | ident = str; | |
3882b010 | 886 | while (ISALNUM (*str)) |
a85d7ed0 NC |
887 | str++; |
888 | len = str - ident; | |
16a419ba NC |
889 | if (len != 4 || strncasecmp (ident, "lit", 3) != 0 |
890 | || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8')) | |
a85d7ed0 NC |
891 | return suffix; /* no modification */ |
892 | nbytes = ident[3] - '0'; | |
893 | ||
894 | reloc = BFD_RELOC_UNUSED; | |
07855bec NC |
895 | if (suffix == ELF_SUFFIX_GOT) |
896 | { | |
897 | if (nbytes == 2) | |
898 | reloc = BFD_RELOC_390_GOT16; | |
899 | else if (nbytes == 4) | |
900 | reloc = BFD_RELOC_32_GOT_PCREL; | |
901 | else if (nbytes == 8) | |
902 | reloc = BFD_RELOC_390_GOT64; | |
903 | } | |
904 | else if (suffix == ELF_SUFFIX_PLT) | |
905 | { | |
906 | if (nbytes == 4) | |
907 | reloc = BFD_RELOC_390_PLT32; | |
908 | else if (nbytes == 8) | |
909 | reloc = BFD_RELOC_390_PLT64; | |
910 | } | |
a85d7ed0 | 911 | |
07855bec | 912 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) |
a85d7ed0 | 913 | as_bad (_("Invalid suffix for literal pool entry")); |
a85d7ed0 NC |
914 | |
915 | /* Search the pool if the new entry is a duplicate. */ | |
07855bec NC |
916 | if (exp_p->X_op == O_big) |
917 | { | |
918 | /* Special processing for big numbers. */ | |
919 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
920 | { | |
921 | if (lpe->ex.X_op == O_big) | |
922 | { | |
923 | if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0) | |
924 | { | |
925 | if (memcmp (&generic_floating_point_number, &lpe->floatnum, | |
926 | sizeof (FLONUM_TYPE)) == 0) | |
927 | break; | |
928 | } | |
929 | else if (exp_p->X_add_number == lpe->ex.X_add_number) | |
930 | { | |
931 | if (memcmp (generic_bignum, lpe->bignum, | |
932 | sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0) | |
933 | break; | |
934 | } | |
935 | } | |
936 | } | |
a85d7ed0 | 937 | } |
07855bec NC |
938 | else |
939 | { | |
940 | /* Processing for 'normal' data types. */ | |
941 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
16a419ba | 942 | if (lpe->nbytes == nbytes && lpe->reloc == reloc |
98d3f06f | 943 | && s390_exp_compare (exp_p, &lpe->ex) != 0) |
07855bec | 944 | break; |
a85d7ed0 | 945 | } |
07855bec NC |
946 | |
947 | if (lpe == NULL) | |
948 | { | |
949 | /* A new literal. */ | |
950 | if (lpe_free_list != NULL) | |
951 | { | |
952 | lpe = lpe_free_list; | |
953 | lpe_free_list = lpe_free_list->next; | |
954 | } | |
a85d7ed0 | 955 | else |
07855bec | 956 | { |
98d3f06f | 957 | lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe)); |
07855bec NC |
958 | } |
959 | ||
960 | lpe->ex = *exp_p; | |
961 | ||
962 | if (exp_p->X_op == O_big) | |
963 | { | |
964 | if (exp_p->X_add_number <= 0) | |
965 | lpe->floatnum = generic_floating_point_number; | |
966 | else if (exp_p->X_add_number <= 4) | |
967 | memcpy (lpe->bignum, generic_bignum, | |
98d3f06f | 968 | exp_p->X_add_number * sizeof (LITTLENUM_TYPE)); |
07855bec NC |
969 | else |
970 | as_bad (_("Big number is too big")); | |
971 | } | |
972 | ||
973 | lpe->nbytes = nbytes; | |
974 | lpe->reloc = reloc; | |
975 | /* Literal pool name defined ? */ | |
976 | if (lp_sym == NULL) | |
977 | { | |
07726851 | 978 | sprintf (tmp_name, ".L\001%i", lp_count); |
98d3f06f | 979 | lp_sym = symbol_make (tmp_name); |
07855bec | 980 | } |
a85d7ed0 | 981 | |
07855bec | 982 | /* Make name for literal pool entry. */ |
07726851 | 983 | sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count); |
07855bec | 984 | lpe_count++; |
98d3f06f | 985 | lpe->sym = symbol_make (tmp_name); |
07855bec NC |
986 | |
987 | /* Add to literal pool list. */ | |
988 | lpe->next = NULL; | |
989 | if (lpe_list_tail != NULL) | |
990 | { | |
991 | lpe_list_tail->next = lpe; | |
992 | lpe_list_tail = lpe; | |
993 | } | |
994 | else | |
995 | lpe_list = lpe_list_tail = lpe; | |
996 | } | |
198ce79b | 997 | |
a85d7ed0 NC |
998 | /* Now change exp_p to the offset into the literal pool. |
999 | Thats the expression: .L^Ax^By-.L^Ax */ | |
1000 | exp_p->X_add_symbol = lpe->sym; | |
1001 | exp_p->X_op_symbol = lp_sym; | |
1002 | exp_p->X_op = O_subtract; | |
1003 | exp_p->X_add_number = 0; | |
1004 | ||
1005 | *str_p = str; | |
1006 | ||
1007 | /* We change the suffix type to ELF_SUFFIX_NONE, because | |
1008 | the difference of two local labels is just a number. */ | |
1009 | return ELF_SUFFIX_NONE; | |
1010 | } | |
1011 | ||
1012 | /* Like normal .long/.short/.word, except support @got, etc. | |
1013 | clobbers input_line_pointer, checks end-of-line. */ | |
1014 | static void | |
5a49b8ac | 1015 | s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */) |
a85d7ed0 NC |
1016 | { |
1017 | expressionS exp; | |
1018 | elf_suffix_type suffix; | |
1019 | ||
07855bec NC |
1020 | if (is_it_end_of_statement ()) |
1021 | { | |
1022 | demand_empty_rest_of_line (); | |
1023 | return; | |
1024 | } | |
a85d7ed0 | 1025 | |
07855bec NC |
1026 | do |
1027 | { | |
1028 | expression (&exp); | |
1029 | ||
1030 | if (exp.X_op == O_symbol | |
1031 | && *input_line_pointer == '@' | |
1032 | && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE) | |
1033 | { | |
1034 | bfd_reloc_code_real_type reloc; | |
1035 | reloc_howto_type *reloc_howto; | |
1036 | int size; | |
1037 | char *where; | |
1038 | ||
1971b29d MS |
1039 | if (nbytes == 2) |
1040 | { | |
1041 | static bfd_reloc_code_real_type tab2[] = | |
1042 | { | |
5cfbfc2b MS |
1043 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1044 | BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */ | |
1045 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */ | |
1046 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1047 | BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */ | |
1048 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */ | |
1049 | BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */ | |
1050 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */ | |
1051 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */ | |
1052 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */ | |
1053 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */ | |
1054 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */ | |
1055 | BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1056 | }; |
1057 | reloc = tab2[suffix]; | |
1058 | } | |
1059 | else if (nbytes == 4) | |
1060 | { | |
1061 | static bfd_reloc_code_real_type tab4[] = | |
1062 | { | |
5cfbfc2b MS |
1063 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1064 | BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */ | |
1065 | BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */ | |
1066 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1067 | BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */ | |
1068 | BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */ | |
1069 | BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */ | |
1070 | BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */ | |
1071 | BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */ | |
1072 | BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */ | |
1073 | BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */ | |
1074 | BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */ | |
1075 | BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1076 | }; |
1077 | reloc = tab4[suffix]; | |
1078 | } | |
1079 | else if (nbytes == 8) | |
1080 | { | |
1081 | static bfd_reloc_code_real_type tab8[] = | |
1082 | { | |
5cfbfc2b MS |
1083 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1084 | BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */ | |
1085 | BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */ | |
1086 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1087 | BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */ | |
1088 | BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */ | |
1089 | BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */ | |
1090 | BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */ | |
1091 | BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */ | |
1092 | BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */ | |
1093 | BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */ | |
1094 | BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */ | |
1095 | BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1096 | }; |
1097 | reloc = tab8[suffix]; | |
1098 | } | |
07855bec NC |
1099 | else |
1100 | reloc = BFD_RELOC_UNUSED; | |
1101 | ||
1971b29d MS |
1102 | if (reloc != BFD_RELOC_UNUSED |
1103 | && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc))) | |
07855bec | 1104 | { |
07855bec NC |
1105 | size = bfd_get_reloc_size (reloc_howto); |
1106 | if (size > nbytes) | |
1107 | as_bad (_("%s relocations do not fit in %d bytes"), | |
1108 | reloc_howto->name, nbytes); | |
07726851 | 1109 | where = frag_more (nbytes); |
07855bec | 1110 | md_number_to_chars (where, 0, size); |
198ce79b | 1111 | /* To make fixup_segment do the pc relative conversion the |
b34976b6 | 1112 | pcrel parameter on the fix_new_exp call needs to be FALSE. */ |
198ce79b | 1113 | fix_new_exp (frag_now, where - frag_now->fr_literal, |
b34976b6 | 1114 | size, &exp, FALSE, reloc); |
07855bec NC |
1115 | } |
1116 | else | |
1117 | as_bad (_("relocation not applicable")); | |
1118 | } | |
a85d7ed0 | 1119 | else |
07855bec NC |
1120 | emit_expr (&exp, (unsigned int) nbytes); |
1121 | } | |
1122 | while (*input_line_pointer++ == ','); | |
a85d7ed0 | 1123 | |
98d3f06f | 1124 | input_line_pointer--; /* Put terminator back into stream. */ |
a85d7ed0 NC |
1125 | demand_empty_rest_of_line (); |
1126 | } | |
1127 | ||
1128 | /* We need to keep a list of fixups. We can't simply generate them as | |
1129 | we go, because that would require us to first create the frag, and | |
1130 | that would screw up references to ``.''. */ | |
1131 | ||
1132 | struct s390_fixup | |
07855bec NC |
1133 | { |
1134 | expressionS exp; | |
1135 | int opindex; | |
1136 | bfd_reloc_code_real_type reloc; | |
1137 | }; | |
a85d7ed0 NC |
1138 | |
1139 | #define MAX_INSN_FIXUPS (4) | |
1140 | ||
1141 | /* This routine is called for each instruction to be assembled. */ | |
1142 | ||
9d654c1c | 1143 | static char * |
5a49b8ac AM |
1144 | md_gather_operands (char *str, |
1145 | unsigned char *insn, | |
1146 | const struct s390_opcode *opcode) | |
a85d7ed0 NC |
1147 | { |
1148 | struct s390_fixup fixups[MAX_INSN_FIXUPS]; | |
1149 | const struct s390_operand *operand; | |
1150 | const unsigned char *opindex_ptr; | |
1971b29d | 1151 | expressionS ex; |
a85d7ed0 NC |
1152 | elf_suffix_type suffix; |
1153 | bfd_reloc_code_real_type reloc; | |
1154 | int skip_optional; | |
a85d7ed0 NC |
1155 | char *f; |
1156 | int fc, i; | |
1157 | ||
98d3f06f KH |
1158 | while (ISSPACE (*str)) |
1159 | str++; | |
a85d7ed0 | 1160 | |
a85d7ed0 NC |
1161 | skip_optional = 0; |
1162 | ||
1163 | /* Gather the operands. */ | |
1164 | fc = 0; | |
07855bec NC |
1165 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) |
1166 | { | |
07855bec NC |
1167 | char *hold; |
1168 | ||
1169 | operand = s390_operands + *opindex_ptr; | |
198ce79b | 1170 | |
07855bec NC |
1171 | if (skip_optional && (operand->flags & S390_OPERAND_INDEX)) |
1172 | { | |
1173 | /* We do an early skip. For D(X,B) constructions the index | |
198ce79b | 1174 | register is skipped (X is optional). For D(L,B) the base |
07855bec NC |
1175 | register will be the skipped operand, because L is NOT |
1176 | optional. */ | |
1177 | skip_optional = 0; | |
1178 | continue; | |
1179 | } | |
198ce79b | 1180 | |
07855bec NC |
1181 | /* Gather the operand. */ |
1182 | hold = input_line_pointer; | |
1183 | input_line_pointer = str; | |
1184 | ||
98d3f06f KH |
1185 | /* Parse the operand. */ |
1186 | if (! register_name (&ex)) | |
07855bec | 1187 | expression (&ex); |
198ce79b | 1188 | |
07855bec NC |
1189 | str = input_line_pointer; |
1190 | input_line_pointer = hold; | |
198ce79b | 1191 | |
07855bec NC |
1192 | /* Write the operand to the insn. */ |
1193 | if (ex.X_op == O_illegal) | |
1194 | as_bad (_("illegal operand")); | |
1195 | else if (ex.X_op == O_absent) | |
5e7c27a6 MS |
1196 | { |
1197 | /* No operands, check if all operands can be skipped. */ | |
1198 | while (*opindex_ptr != 0 && operand->flags & S390_OPERAND_OPTIONAL) | |
1199 | { | |
1200 | if (operand->flags & S390_OPERAND_DISP) | |
1201 | { | |
1202 | /* An optional displacement makes the whole D(X,B) | |
1203 | D(L,B) or D(B) block optional. */ | |
1204 | do { | |
1205 | operand = s390_operands + *(++opindex_ptr); | |
1206 | } while (!(operand->flags & S390_OPERAND_BASE)); | |
1207 | } | |
1208 | operand = s390_operands + *(++opindex_ptr); | |
1209 | } | |
1210 | if (opindex_ptr[0] == '\0') | |
1211 | break; | |
1212 | as_bad (_("missing operand")); | |
1213 | } | |
07855bec NC |
1214 | else if (ex.X_op == O_register || ex.X_op == O_constant) |
1215 | { | |
1216 | s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE); | |
1217 | ||
1218 | if (ex.X_op != O_register && ex.X_op != O_constant) | |
1219 | { | |
1220 | /* We need to generate a fixup for the | |
1221 | expression returned by s390_lit_suffix. */ | |
1222 | if (fc >= MAX_INSN_FIXUPS) | |
1223 | as_fatal (_("too many fixups")); | |
1224 | fixups[fc].exp = ex; | |
1225 | fixups[fc].opindex = *opindex_ptr; | |
1226 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
1227 | ++fc; | |
1228 | } | |
1229 | else | |
1230 | { | |
16a419ba NC |
1231 | if ((operand->flags & S390_OPERAND_INDEX) |
1232 | && ex.X_add_number == 0 | |
b34976b6 | 1233 | && warn_areg_zero) |
20203fb9 | 1234 | as_warn (_("index register specified but zero")); |
16a419ba NC |
1235 | if ((operand->flags & S390_OPERAND_BASE) |
1236 | && ex.X_add_number == 0 | |
b34976b6 | 1237 | && warn_areg_zero) |
20203fb9 | 1238 | as_warn (_("base register specified but zero")); |
07855bec NC |
1239 | s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0); |
1240 | } | |
1241 | } | |
1242 | else | |
1243 | { | |
1244 | suffix = s390_elf_suffix (&str, &ex); | |
1245 | suffix = s390_lit_suffix (&str, &ex, suffix); | |
1246 | reloc = BFD_RELOC_UNUSED; | |
1247 | ||
1248 | if (suffix == ELF_SUFFIX_GOT) | |
1249 | { | |
933fbc29 MS |
1250 | if ((operand->flags & S390_OPERAND_DISP) && |
1251 | (operand->bits == 12)) | |
07855bec | 1252 | reloc = BFD_RELOC_390_GOT12; |
933fbc29 MS |
1253 | else if ((operand->flags & S390_OPERAND_DISP) && |
1254 | (operand->bits == 20)) | |
1255 | reloc = BFD_RELOC_390_GOT20; | |
16a419ba NC |
1256 | else if ((operand->flags & S390_OPERAND_SIGNED) |
1257 | && (operand->bits == 16)) | |
07855bec | 1258 | reloc = BFD_RELOC_390_GOT16; |
16a419ba NC |
1259 | else if ((operand->flags & S390_OPERAND_PCREL) |
1260 | && (operand->bits == 32)) | |
07855bec NC |
1261 | reloc = BFD_RELOC_390_GOTENT; |
1262 | } | |
1263 | else if (suffix == ELF_SUFFIX_PLT) | |
1264 | { | |
16a419ba NC |
1265 | if ((operand->flags & S390_OPERAND_PCREL) |
1266 | && (operand->bits == 16)) | |
07855bec | 1267 | reloc = BFD_RELOC_390_PLT16DBL; |
16a419ba NC |
1268 | else if ((operand->flags & S390_OPERAND_PCREL) |
1269 | && (operand->bits == 32)) | |
07855bec NC |
1270 | reloc = BFD_RELOC_390_PLT32DBL; |
1271 | } | |
1272 | else if (suffix == ELF_SUFFIX_GOTENT) | |
1273 | { | |
16a419ba NC |
1274 | if ((operand->flags & S390_OPERAND_PCREL) |
1275 | && (operand->bits == 32)) | |
07855bec NC |
1276 | reloc = BFD_RELOC_390_GOTENT; |
1277 | } | |
2a19f73f MS |
1278 | else if (suffix == ELF_SUFFIX_GOTOFF) |
1279 | { | |
1280 | if ((operand->flags & S390_OPERAND_SIGNED) | |
1281 | && (operand->bits == 16)) | |
1282 | reloc = BFD_RELOC_16_GOTOFF; | |
1283 | } | |
1284 | else if (suffix == ELF_SUFFIX_PLTOFF) | |
1285 | { | |
1286 | if ((operand->flags & S390_OPERAND_SIGNED) | |
1287 | && (operand->bits == 16)) | |
1288 | reloc = BFD_RELOC_390_PLTOFF16; | |
1289 | } | |
1290 | else if (suffix == ELF_SUFFIX_GOTPLT) | |
1291 | { | |
1292 | if ((operand->flags & S390_OPERAND_DISP) | |
1293 | && (operand->bits == 12)) | |
1294 | reloc = BFD_RELOC_390_GOTPLT12; | |
1295 | else if ((operand->flags & S390_OPERAND_SIGNED) | |
1296 | && (operand->bits == 16)) | |
1297 | reloc = BFD_RELOC_390_GOTPLT16; | |
1298 | else if ((operand->flags & S390_OPERAND_PCREL) | |
1299 | && (operand->bits == 32)) | |
1300 | reloc = BFD_RELOC_390_GOTPLTENT; | |
1301 | } | |
1971b29d MS |
1302 | else if (suffix == ELF_SUFFIX_TLS_GOTIE) |
1303 | { | |
1304 | if ((operand->flags & S390_OPERAND_DISP) | |
1305 | && (operand->bits == 12)) | |
1306 | reloc = BFD_RELOC_390_TLS_GOTIE12; | |
933fbc29 MS |
1307 | else if ((operand->flags & S390_OPERAND_DISP) |
1308 | && (operand->bits == 20)) | |
1309 | reloc = BFD_RELOC_390_TLS_GOTIE20; | |
1971b29d MS |
1310 | } |
1311 | else if (suffix == ELF_SUFFIX_TLS_IE) | |
1312 | { | |
1313 | if ((operand->flags & S390_OPERAND_PCREL) | |
1314 | && (operand->bits == 32)) | |
1315 | reloc = BFD_RELOC_390_TLS_IEENT; | |
1316 | } | |
07855bec NC |
1317 | |
1318 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) | |
1319 | as_bad (_("invalid operand suffix")); | |
1320 | /* We need to generate a fixup of type 'reloc' for this | |
1321 | expression. */ | |
a85d7ed0 NC |
1322 | if (fc >= MAX_INSN_FIXUPS) |
1323 | as_fatal (_("too many fixups")); | |
1324 | fixups[fc].exp = ex; | |
1325 | fixups[fc].opindex = *opindex_ptr; | |
07855bec | 1326 | fixups[fc].reloc = reloc; |
a85d7ed0 | 1327 | ++fc; |
07855bec | 1328 | } |
198ce79b | 1329 | |
07855bec NC |
1330 | /* Check the next character. The call to expression has advanced |
1331 | str past any whitespace. */ | |
1332 | if (operand->flags & S390_OPERAND_DISP) | |
1333 | { | |
1334 | /* After a displacement a block in parentheses can start. */ | |
1335 | if (*str != '(') | |
1336 | { | |
67c1ffbe | 1337 | /* Check if parenthesized block can be skipped. If the next |
07855bec NC |
1338 | operand is neiter an optional operand nor a base register |
1339 | then we have a syntax error. */ | |
1340 | operand = s390_operands + *(++opindex_ptr); | |
1341 | if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE))) | |
1342 | as_bad (_("syntax error; missing '(' after displacement")); | |
1343 | ||
1344 | /* Ok, skip all operands until S390_OPERAND_BASE. */ | |
1345 | while (!(operand->flags & S390_OPERAND_BASE)) | |
1346 | operand = s390_operands + *(++opindex_ptr); | |
198ce79b | 1347 | |
67c1ffbe | 1348 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1349 | if (opindex_ptr[1] != '\0') |
1350 | { | |
6c639ef9 MS |
1351 | if (*str != ',') |
1352 | { | |
1353 | while (opindex_ptr[1] != '\0') | |
1354 | { | |
1355 | operand = s390_operands + *(++opindex_ptr); | |
1356 | if (operand->flags & S390_OPERAND_OPTIONAL) | |
1357 | continue; | |
1358 | as_bad (_("syntax error; expected ,")); | |
1359 | break; | |
1360 | } | |
1361 | } | |
1362 | else | |
1363 | str++; | |
07855bec NC |
1364 | } |
1365 | } | |
1366 | else | |
1367 | { | |
1368 | /* We found an opening parentheses. */ | |
1369 | str++; | |
1370 | for (f = str; *f != '\0'; f++) | |
1371 | if (*f == ',' || *f == ')') | |
1372 | break; | |
1373 | /* If there is no comma until the closing parentheses OR | |
1374 | there is a comma right after the opening parentheses, | |
1375 | we have to skip optional operands. */ | |
1376 | if (*f == ',' && f == str) | |
1377 | { | |
1378 | /* comma directly after '(' ? */ | |
1379 | skip_optional = 1; | |
1380 | str++; | |
1381 | } | |
1382 | else | |
1383 | skip_optional = (*f != ','); | |
1384 | } | |
1385 | } | |
1386 | else if (operand->flags & S390_OPERAND_BASE) | |
1387 | { | |
1388 | /* After the base register the parenthesed block ends. */ | |
1389 | if (*str++ != ')') | |
1390 | as_bad (_("syntax error; missing ')' after base register")); | |
1391 | skip_optional = 0; | |
67c1ffbe | 1392 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1393 | if (opindex_ptr[1] != '\0') |
1394 | { | |
6c639ef9 MS |
1395 | if (*str != ',') |
1396 | { | |
1397 | while (opindex_ptr[1] != '\0') | |
1398 | { | |
1399 | operand = s390_operands + *(++opindex_ptr); | |
1400 | if (operand->flags & S390_OPERAND_OPTIONAL) | |
1401 | continue; | |
1402 | as_bad (_("syntax error; expected ,")); | |
1403 | break; | |
1404 | } | |
1405 | } | |
1406 | else | |
1407 | str++; | |
07855bec NC |
1408 | } |
1409 | } | |
1410 | else | |
1411 | { | |
1412 | /* We can find an 'early' closing parentheses in e.g. D(L) instead | |
1413 | of D(L,B). In this case the base register has to be skipped. */ | |
1414 | if (*str == ')') | |
1415 | { | |
1416 | operand = s390_operands + *(++opindex_ptr); | |
1417 | ||
1418 | if (!(operand->flags & S390_OPERAND_BASE)) | |
1419 | as_bad (_("syntax error; ')' not allowed here")); | |
1420 | str++; | |
1421 | } | |
67c1ffbe | 1422 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1423 | if (opindex_ptr[1] != '\0') |
1424 | { | |
6c639ef9 MS |
1425 | if (*str != ',') |
1426 | { | |
1427 | while (opindex_ptr[1] != '\0') | |
1428 | { | |
1429 | operand = s390_operands + *(++opindex_ptr); | |
1430 | if (operand->flags & S390_OPERAND_OPTIONAL) | |
1431 | continue; | |
1432 | as_bad (_("syntax error; expected ,")); | |
1433 | break; | |
1434 | } | |
1435 | } | |
1436 | else | |
1437 | str++; | |
07855bec | 1438 | } |
a85d7ed0 | 1439 | } |
a85d7ed0 | 1440 | } |
a85d7ed0 | 1441 | |
3882b010 | 1442 | while (ISSPACE (*str)) |
a85d7ed0 NC |
1443 | ++str; |
1444 | ||
1971b29d MS |
1445 | /* Check for tls instruction marker. */ |
1446 | reloc = s390_tls_suffix (&str, &ex); | |
1447 | if (reloc != BFD_RELOC_UNUSED) | |
1448 | { | |
1449 | /* We need to generate a fixup of type 'reloc' for this | |
1450 | instruction. */ | |
1451 | if (fc >= MAX_INSN_FIXUPS) | |
1452 | as_fatal (_("too many fixups")); | |
1453 | fixups[fc].exp = ex; | |
1454 | fixups[fc].opindex = -1; | |
1455 | fixups[fc].reloc = reloc; | |
1456 | ++fc; | |
1457 | } | |
1458 | ||
07855bec NC |
1459 | if (*str != '\0') |
1460 | { | |
1461 | char *linefeed; | |
a85d7ed0 | 1462 | |
07726851 | 1463 | if ((linefeed = strchr (str, '\n')) != NULL) |
07855bec NC |
1464 | *linefeed = '\0'; |
1465 | as_bad (_("junk at end of line: `%s'"), str); | |
1466 | if (linefeed != NULL) | |
1467 | *linefeed = '\n'; | |
1468 | } | |
a85d7ed0 NC |
1469 | |
1470 | /* Write out the instruction. */ | |
1471 | f = frag_more (opcode->oplen); | |
07855bec | 1472 | memcpy (f, insn, opcode->oplen); |
8f5b2891 | 1473 | dwarf2_emit_insn (opcode->oplen); |
a85d7ed0 NC |
1474 | |
1475 | /* Create any fixups. At this point we do not use a | |
1476 | bfd_reloc_code_real_type, but instead just use the | |
1477 | BFD_RELOC_UNUSED plus the operand index. This lets us easily | |
1478 | handle fixups for any operand type, although that is admittedly | |
1479 | not a very exciting feature. We pick a BFD reloc type in | |
55cf6793 | 1480 | md_apply_fix. */ |
07855bec NC |
1481 | for (i = 0; i < fc; i++) |
1482 | { | |
1971b29d MS |
1483 | |
1484 | if (fixups[i].opindex < 0) | |
1485 | { | |
1486 | /* Create tls instruction marker relocation. */ | |
1487 | fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen, | |
1488 | &fixups[i].exp, 0, fixups[i].reloc); | |
1489 | continue; | |
1490 | } | |
1491 | ||
07855bec | 1492 | operand = s390_operands + fixups[i].opindex; |
a85d7ed0 | 1493 | |
07855bec NC |
1494 | if (fixups[i].reloc != BFD_RELOC_UNUSED) |
1495 | { | |
1496 | reloc_howto_type *reloc_howto; | |
1497 | fixS *fixP; | |
1498 | int size; | |
198ce79b | 1499 | |
07855bec NC |
1500 | reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); |
1501 | if (!reloc_howto) | |
1502 | abort (); | |
198ce79b | 1503 | |
07855bec NC |
1504 | size = bfd_get_reloc_size (reloc_howto); |
1505 | ||
1506 | if (size < 1 || size > 4) | |
1507 | abort (); | |
198ce79b AJ |
1508 | |
1509 | fixP = fix_new_exp (frag_now, | |
1510 | f - frag_now->fr_literal + (operand->shift/8), | |
07855bec NC |
1511 | size, &fixups[i].exp, reloc_howto->pc_relative, |
1512 | fixups[i].reloc); | |
1513 | /* Turn off overflow checking in fixup_segment. This is necessary | |
1514 | because fixup_segment will signal an overflow for large 4 byte | |
1515 | quantities for GOT12 relocations. */ | |
16a419ba | 1516 | if ( fixups[i].reloc == BFD_RELOC_390_GOT12 |
933fbc29 | 1517 | || fixups[i].reloc == BFD_RELOC_390_GOT20 |
16a419ba | 1518 | || fixups[i].reloc == BFD_RELOC_390_GOT16) |
07855bec NC |
1519 | fixP->fx_no_overflow = 1; |
1520 | } | |
1521 | else | |
1522 | fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp, | |
1523 | (operand->flags & S390_OPERAND_PCREL) != 0, | |
1524 | ((bfd_reloc_code_real_type) | |
1525 | (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); | |
1526 | } | |
a85d7ed0 NC |
1527 | return str; |
1528 | } | |
1529 | ||
1530 | /* This routine is called for each instruction to be assembled. */ | |
1531 | ||
1532 | void | |
5a49b8ac | 1533 | md_assemble (char *str) |
a85d7ed0 NC |
1534 | { |
1535 | const struct s390_opcode *opcode; | |
1536 | unsigned char insn[6]; | |
1537 | char *s; | |
1538 | ||
1539 | /* Get the opcode. */ | |
3882b010 | 1540 | for (s = str; *s != '\0' && ! ISSPACE (*s); s++) |
a85d7ed0 NC |
1541 | ; |
1542 | if (*s != '\0') | |
1543 | *s++ = '\0'; | |
1544 | ||
1545 | /* Look up the opcode in the hash table. */ | |
1546 | opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str); | |
07855bec NC |
1547 | if (opcode == (const struct s390_opcode *) NULL) |
1548 | { | |
1549 | as_bad (_("Unrecognized opcode: `%s'"), str); | |
1550 | return; | |
1551 | } | |
37a58793 MS |
1552 | else if (!(opcode->modes & current_mode_mask)) |
1553 | { | |
20203fb9 | 1554 | as_bad (_("Opcode %s not available in this mode"), str); |
37a58793 MS |
1555 | return; |
1556 | } | |
07726851 | 1557 | memcpy (insn, opcode->opcode, sizeof (insn)); |
07855bec | 1558 | md_gather_operands (s, insn, opcode); |
a85d7ed0 NC |
1559 | } |
1560 | ||
1561 | #ifndef WORKING_DOT_WORD | |
1562 | /* Handle long and short jumps. We don't support these */ | |
1563 | void | |
1564 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1565 | char *ptr; | |
1566 | addressT from_addr, to_addr; | |
1567 | fragS *frag; | |
1568 | symbolS *to_symbol; | |
1569 | { | |
1570 | abort (); | |
1571 | } | |
1572 | ||
1573 | void | |
1574 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1575 | char *ptr; | |
1576 | addressT from_addr, to_addr; | |
1577 | fragS *frag; | |
1578 | symbolS *to_symbol; | |
1579 | { | |
1580 | abort (); | |
1581 | } | |
1582 | #endif | |
1583 | ||
1584 | void | |
5a49b8ac | 1585 | s390_bss (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1586 | { |
1587 | /* We don't support putting frags in the BSS segment, we fake it | |
1588 | by marking in_bss, then looking at s_skip for clues. */ | |
1589 | ||
1590 | subseg_set (bss_section, 0); | |
1591 | demand_empty_rest_of_line (); | |
1592 | } | |
1593 | ||
1594 | /* Pseudo-op handling. */ | |
1595 | ||
1596 | void | |
5a49b8ac | 1597 | s390_insn (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1598 | { |
1599 | expressionS exp; | |
1600 | const struct s390_opcode *opformat; | |
1601 | unsigned char insn[6]; | |
1602 | char *s; | |
1603 | ||
1604 | /* Get the opcode format. */ | |
1605 | s = input_line_pointer; | |
3882b010 | 1606 | while (*s != '\0' && *s != ',' && ! ISSPACE (*s)) |
a85d7ed0 NC |
1607 | s++; |
1608 | if (*s != ',') | |
1609 | as_bad (_("Invalid .insn format\n")); | |
1610 | *s++ = '\0'; | |
1611 | ||
1612 | /* Look up the opcode in the hash table. */ | |
1613 | opformat = (struct s390_opcode *) | |
1614 | hash_find (s390_opformat_hash, input_line_pointer); | |
07855bec NC |
1615 | if (opformat == (const struct s390_opcode *) NULL) |
1616 | { | |
1617 | as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer); | |
1618 | return; | |
1619 | } | |
a85d7ed0 NC |
1620 | input_line_pointer = s; |
1621 | expression (&exp); | |
07855bec NC |
1622 | if (exp.X_op == O_constant) |
1623 | { | |
1d6d62a4 | 1624 | if ( ( opformat->oplen == 6 |
1d6d62a4 MS |
1625 | && (addressT) exp.X_add_number < (1ULL << 48)) |
1626 | || ( opformat->oplen == 4 | |
1d6d62a4 MS |
1627 | && (addressT) exp.X_add_number < (1ULL << 32)) |
1628 | || ( opformat->oplen == 2 | |
1d6d62a4 | 1629 | && (addressT) exp.X_add_number < (1ULL << 16))) |
2132e3a3 | 1630 | md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen); |
07855bec | 1631 | else |
07726851 | 1632 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1633 | } |
1634 | else if (exp.X_op == O_big) | |
1635 | { | |
16a419ba NC |
1636 | if (exp.X_add_number > 0 |
1637 | && opformat->oplen == 6 | |
1638 | && generic_bignum[3] == 0) | |
07855bec | 1639 | { |
2132e3a3 AM |
1640 | md_number_to_chars ((char *) insn, generic_bignum[2], 2); |
1641 | md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2); | |
1642 | md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2); | |
07855bec NC |
1643 | } |
1644 | else | |
07726851 | 1645 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1646 | } |
1647 | else | |
a85d7ed0 | 1648 | as_bad (_("second operand of .insn not a constant\n")); |
a85d7ed0 | 1649 | |
b6849f55 NC |
1650 | if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',') |
1651 | as_bad (_("missing comma after insn constant\n")); | |
98d3f06f | 1652 | |
07726851 | 1653 | if ((s = strchr (input_line_pointer, '\n')) != NULL) |
a85d7ed0 | 1654 | *s = '\0'; |
b6849f55 NC |
1655 | input_line_pointer = md_gather_operands (input_line_pointer, insn, |
1656 | opformat); | |
a85d7ed0 NC |
1657 | if (s != NULL) |
1658 | *s = '\n'; | |
1659 | demand_empty_rest_of_line (); | |
1660 | } | |
1661 | ||
1662 | /* The .byte pseudo-op. This is similar to the normal .byte | |
1663 | pseudo-op, but it can also take a single ASCII string. */ | |
1664 | ||
1665 | static void | |
5a49b8ac | 1666 | s390_byte (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1667 | { |
1668 | if (*input_line_pointer != '\"') | |
1669 | { | |
1670 | cons (1); | |
1671 | return; | |
1672 | } | |
1673 | ||
1674 | /* Gather characters. A real double quote is doubled. Unusual | |
1675 | characters are not permitted. */ | |
1676 | ++input_line_pointer; | |
1677 | while (1) | |
1678 | { | |
1679 | char c; | |
1680 | ||
1681 | c = *input_line_pointer++; | |
1682 | ||
1683 | if (c == '\"') | |
1684 | { | |
1685 | if (*input_line_pointer != '\"') | |
1686 | break; | |
1687 | ++input_line_pointer; | |
1688 | } | |
1689 | ||
1690 | FRAG_APPEND_1_CHAR (c); | |
1691 | } | |
1692 | ||
1693 | demand_empty_rest_of_line (); | |
1694 | } | |
1695 | ||
1696 | /* The .ltorg pseudo-op.This emits all literals defined since the last | |
198ce79b | 1697 | .ltorg or the invocation of gas. Literals are defined with the |
a85d7ed0 NC |
1698 | @lit suffix. */ |
1699 | ||
1700 | static void | |
5a49b8ac | 1701 | s390_literals (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1702 | { |
1703 | struct s390_lpe *lpe; | |
1704 | ||
1705 | if (lp_sym == NULL || lpe_count == 0) | |
98d3f06f | 1706 | return; /* Nothing to be done. */ |
a85d7ed0 NC |
1707 | |
1708 | /* Emit symbol for start of literal pool. */ | |
1709 | S_SET_SEGMENT (lp_sym, now_seg); | |
1710 | S_SET_VALUE (lp_sym, (valueT) frag_now_fix ()); | |
1711 | lp_sym->sy_frag = frag_now; | |
1712 | ||
07855bec NC |
1713 | while (lpe_list) |
1714 | { | |
1715 | lpe = lpe_list; | |
1716 | lpe_list = lpe_list->next; | |
1717 | S_SET_SEGMENT (lpe->sym, now_seg); | |
1718 | S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ()); | |
1719 | lpe->sym->sy_frag = frag_now; | |
1720 | ||
1721 | /* Emit literal pool entry. */ | |
1722 | if (lpe->reloc != BFD_RELOC_UNUSED) | |
1723 | { | |
198ce79b | 1724 | reloc_howto_type *reloc_howto = |
07855bec NC |
1725 | bfd_reloc_type_lookup (stdoutput, lpe->reloc); |
1726 | int size = bfd_get_reloc_size (reloc_howto); | |
1727 | char *where; | |
1728 | ||
1729 | if (size > lpe->nbytes) | |
1730 | as_bad (_("%s relocations do not fit in %d bytes"), | |
1731 | reloc_howto->name, lpe->nbytes); | |
07726851 | 1732 | where = frag_more (lpe->nbytes); |
07855bec NC |
1733 | md_number_to_chars (where, 0, size); |
1734 | fix_new_exp (frag_now, where - frag_now->fr_literal, | |
1735 | size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc); | |
1736 | } | |
1737 | else | |
1738 | { | |
1739 | if (lpe->ex.X_op == O_big) | |
1740 | { | |
1741 | if (lpe->ex.X_add_number <= 0) | |
1742 | generic_floating_point_number = lpe->floatnum; | |
1743 | else | |
1744 | memcpy (generic_bignum, lpe->bignum, | |
98d3f06f | 1745 | lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE)); |
07855bec NC |
1746 | } |
1747 | emit_expr (&lpe->ex, lpe->nbytes); | |
1748 | } | |
a85d7ed0 | 1749 | |
07855bec NC |
1750 | lpe->next = lpe_free_list; |
1751 | lpe_free_list = lpe; | |
1752 | } | |
a85d7ed0 NC |
1753 | lpe_list_tail = NULL; |
1754 | lp_sym = NULL; | |
1755 | lp_count++; | |
1756 | lpe_count = 0; | |
1757 | } | |
1758 | ||
a85d7ed0 | 1759 | char * |
499ac353 | 1760 | md_atof (int type, char *litp, int *sizep) |
a85d7ed0 | 1761 | { |
499ac353 | 1762 | return ieee_md_atof (type, litp, sizep, TRUE); |
a85d7ed0 NC |
1763 | } |
1764 | ||
1765 | /* Align a section (I don't know why this is machine dependent). */ | |
1766 | ||
1767 | valueT | |
5a49b8ac | 1768 | md_section_align (asection *seg, valueT addr) |
a85d7ed0 NC |
1769 | { |
1770 | int align = bfd_get_section_alignment (stdoutput, seg); | |
1771 | ||
1772 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
1773 | } | |
1774 | ||
1775 | /* We don't have any form of relaxing. */ | |
1776 | ||
1777 | int | |
5a49b8ac AM |
1778 | md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED, |
1779 | asection *seg ATTRIBUTE_UNUSED) | |
a85d7ed0 NC |
1780 | { |
1781 | abort (); | |
1782 | return 0; | |
1783 | } | |
1784 | ||
1785 | /* Convert a machine dependent frag. We never generate these. */ | |
1786 | ||
1787 | void | |
5a49b8ac AM |
1788 | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, |
1789 | asection *sec ATTRIBUTE_UNUSED, | |
1790 | fragS *fragp ATTRIBUTE_UNUSED) | |
a85d7ed0 NC |
1791 | { |
1792 | abort (); | |
1793 | } | |
1794 | ||
1795 | symbolS * | |
5a49b8ac | 1796 | md_undefined_symbol (char *name) |
a85d7ed0 | 1797 | { |
98d3f06f | 1798 | if (*name == '_' && *(name + 1) == 'G' |
07726851 | 1799 | && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) |
98d3f06f KH |
1800 | { |
1801 | if (!GOT_symbol) | |
1802 | { | |
1803 | if (symbol_find (name)) | |
1804 | as_bad (_("GOT already in symbol table")); | |
1805 | GOT_symbol = symbol_new (name, undefined_section, | |
1806 | (valueT) 0, &zero_address_frag); | |
1807 | } | |
1808 | return GOT_symbol; | |
1809 | } | |
a85d7ed0 NC |
1810 | return 0; |
1811 | } | |
1812 | ||
1813 | /* Functions concerning relocs. */ | |
1814 | ||
1815 | /* The location from which a PC relative jump should be calculated, | |
1816 | given a PC relative reloc. */ | |
1817 | ||
1818 | long | |
5a49b8ac | 1819 | md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1820 | { |
1821 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
1822 | } | |
1823 | ||
1824 | /* Here we decide which fixups can be adjusted to make them relative to | |
1825 | the beginning of the section instead of the symbol. Basically we need | |
1826 | to make sure that the dynamic relocations are done correctly, so in | |
1827 | some cases we force the original symbol to be used. */ | |
1828 | int | |
5a49b8ac | 1829 | tc_s390_fix_adjustable (fixS *fixP) |
a85d7ed0 | 1830 | { |
0a00dd48 MS |
1831 | /* Don't adjust references to merge sections. */ |
1832 | if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0) | |
1833 | return 0; | |
a85d7ed0 | 1834 | /* adjust_reloc_syms doesn't know about the GOT. */ |
2a19f73f MS |
1835 | if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF |
1836 | || fixP->fx_r_type == BFD_RELOC_32_GOTOFF | |
1837 | || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64 | |
1838 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16 | |
1839 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32 | |
1840 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64 | |
a85d7ed0 NC |
1841 | || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL |
1842 | || fixP->fx_r_type == BFD_RELOC_390_PLT32 | |
1843 | || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL | |
1844 | || fixP->fx_r_type == BFD_RELOC_390_PLT64 | |
1845 | || fixP->fx_r_type == BFD_RELOC_390_GOT12 | |
933fbc29 | 1846 | || fixP->fx_r_type == BFD_RELOC_390_GOT20 |
a85d7ed0 NC |
1847 | || fixP->fx_r_type == BFD_RELOC_390_GOT16 |
1848 | || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL | |
1849 | || fixP->fx_r_type == BFD_RELOC_390_GOT64 | |
07855bec | 1850 | || fixP->fx_r_type == BFD_RELOC_390_GOTENT |
2a19f73f MS |
1851 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12 |
1852 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16 | |
933fbc29 | 1853 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20 |
2a19f73f MS |
1854 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32 |
1855 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64 | |
1856 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT | |
1971b29d MS |
1857 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD |
1858 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL | |
1859 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL | |
1860 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32 | |
1861 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64 | |
1862 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12 | |
933fbc29 | 1863 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20 |
1971b29d MS |
1864 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32 |
1865 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64 | |
1866 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32 | |
1867 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64 | |
1868 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32 | |
1869 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64 | |
1870 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT | |
1871 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32 | |
1872 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64 | |
1873 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32 | |
1874 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64 | |
1875 | || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD | |
1876 | || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF | |
1877 | || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF | |
a85d7ed0 NC |
1878 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
1879 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
1880 | return 0; | |
1881 | return 1; | |
1882 | } | |
1883 | ||
b8edc45c | 1884 | /* Return true if we must always emit a reloc for a type and false if |
c03099e6 | 1885 | there is some hope of resolving it at assembly time. */ |
b8edc45c | 1886 | int |
5a49b8ac | 1887 | tc_s390_force_relocation (struct fix *fixp) |
b8edc45c MS |
1888 | { |
1889 | /* Ensure we emit a relocation for every reference to the global | |
1890 | offset table or to the procedure link table. */ | |
1891 | switch (fixp->fx_r_type) | |
1892 | { | |
1893 | case BFD_RELOC_390_GOT12: | |
933fbc29 | 1894 | case BFD_RELOC_390_GOT20: |
b8edc45c MS |
1895 | case BFD_RELOC_32_GOT_PCREL: |
1896 | case BFD_RELOC_32_GOTOFF: | |
2a19f73f MS |
1897 | case BFD_RELOC_390_GOTOFF64: |
1898 | case BFD_RELOC_390_PLTOFF16: | |
1899 | case BFD_RELOC_390_PLTOFF32: | |
1900 | case BFD_RELOC_390_PLTOFF64: | |
b8edc45c MS |
1901 | case BFD_RELOC_390_GOTPC: |
1902 | case BFD_RELOC_390_GOT16: | |
1903 | case BFD_RELOC_390_GOTPCDBL: | |
1904 | case BFD_RELOC_390_GOT64: | |
1905 | case BFD_RELOC_390_GOTENT: | |
1906 | case BFD_RELOC_390_PLT32: | |
1907 | case BFD_RELOC_390_PLT16DBL: | |
1908 | case BFD_RELOC_390_PLT32DBL: | |
1909 | case BFD_RELOC_390_PLT64: | |
2a19f73f MS |
1910 | case BFD_RELOC_390_GOTPLT12: |
1911 | case BFD_RELOC_390_GOTPLT16: | |
933fbc29 | 1912 | case BFD_RELOC_390_GOTPLT20: |
2a19f73f MS |
1913 | case BFD_RELOC_390_GOTPLT32: |
1914 | case BFD_RELOC_390_GOTPLT64: | |
1915 | case BFD_RELOC_390_GOTPLTENT: | |
b8edc45c MS |
1916 | return 1; |
1917 | default: | |
a161fe53 | 1918 | break;; |
b8edc45c | 1919 | } |
a161fe53 | 1920 | |
ae6063d4 | 1921 | return generic_force_reloc (fixp); |
b8edc45c MS |
1922 | } |
1923 | ||
a85d7ed0 NC |
1924 | /* Apply a fixup to the object code. This is called for all the |
1925 | fixups we generated by the call to fix_new_exp, above. In the call | |
1926 | above we used a reloc code which was the largest legal reloc code | |
1927 | plus the operand index. Here we undo that to recover the operand | |
1928 | index. At this point all symbol values should be fully resolved, | |
1929 | and we attempt to completely resolve the reloc. If we can not do | |
1930 | that, we determine the correct reloc code and put it back in the | |
1931 | fixup. */ | |
1932 | ||
94f592af | 1933 | void |
5a49b8ac | 1934 | md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1935 | { |
1936 | char *where; | |
98d3f06f | 1937 | valueT value = *valP; |
a85d7ed0 | 1938 | |
94f592af | 1939 | where = fixP->fx_frag->fr_literal + fixP->fx_where; |
a85d7ed0 | 1940 | |
98d3f06f | 1941 | if (fixP->fx_subsy != NULL) |
f1fc51da | 1942 | as_bad_where (fixP->fx_file, fixP->fx_line, |
20203fb9 | 1943 | _("cannot emit relocation %s against subsy symbol %s"), |
f1fc51da MS |
1944 | bfd_get_reloc_code_name (fixP->fx_r_type), |
1945 | S_GET_NAME (fixP->fx_subsy)); | |
98d3f06f KH |
1946 | |
1947 | if (fixP->fx_addsy != NULL) | |
07855bec | 1948 | { |
94f592af NC |
1949 | if (fixP->fx_pcrel) |
1950 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
07855bec NC |
1951 | } |
1952 | else | |
94f592af | 1953 | fixP->fx_done = 1; |
a85d7ed0 | 1954 | |
94f592af | 1955 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
07855bec NC |
1956 | { |
1957 | const struct s390_operand *operand; | |
1958 | int opindex; | |
198ce79b | 1959 | |
94f592af | 1960 | opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
07855bec | 1961 | operand = &s390_operands[opindex]; |
198ce79b | 1962 | |
94f592af | 1963 | if (fixP->fx_done) |
07855bec NC |
1964 | { |
1965 | /* Insert the fully resolved operand value. */ | |
2132e3a3 AM |
1966 | s390_insert_operand ((unsigned char *) where, operand, |
1967 | (offsetT) value, fixP->fx_file, fixP->fx_line); | |
94f592af | 1968 | return; |
07855bec | 1969 | } |
198ce79b | 1970 | |
07855bec NC |
1971 | /* Determine a BFD reloc value based on the operand information. |
1972 | We are only prepared to turn a few of the operands into | |
1973 | relocs. */ | |
94f592af | 1974 | fixP->fx_offset = value; |
07855bec NC |
1975 | if (operand->bits == 12 && operand->shift == 20) |
1976 | { | |
94f592af NC |
1977 | fixP->fx_size = 2; |
1978 | fixP->fx_where += 2; | |
1979 | fixP->fx_r_type = BFD_RELOC_390_12; | |
07855bec NC |
1980 | } |
1981 | else if (operand->bits == 12 && operand->shift == 36) | |
1982 | { | |
94f592af NC |
1983 | fixP->fx_size = 2; |
1984 | fixP->fx_where += 4; | |
1985 | fixP->fx_r_type = BFD_RELOC_390_12; | |
07855bec | 1986 | } |
933fbc29 MS |
1987 | else if (operand->bits == 20 && operand->shift == 20) |
1988 | { | |
1989 | fixP->fx_size = 2; | |
1990 | fixP->fx_where += 2; | |
1991 | fixP->fx_r_type = BFD_RELOC_390_20; | |
1992 | } | |
07855bec NC |
1993 | else if (operand->bits == 8 && operand->shift == 8) |
1994 | { | |
94f592af NC |
1995 | fixP->fx_size = 1; |
1996 | fixP->fx_where += 1; | |
1997 | fixP->fx_r_type = BFD_RELOC_8; | |
07855bec NC |
1998 | } |
1999 | else if (operand->bits == 16 && operand->shift == 16) | |
2000 | { | |
94f592af NC |
2001 | fixP->fx_size = 2; |
2002 | fixP->fx_where += 2; | |
07855bec NC |
2003 | if (operand->flags & S390_OPERAND_PCREL) |
2004 | { | |
94f592af NC |
2005 | fixP->fx_r_type = BFD_RELOC_390_PC16DBL; |
2006 | fixP->fx_offset += 2; | |
07855bec NC |
2007 | } |
2008 | else | |
94f592af | 2009 | fixP->fx_r_type = BFD_RELOC_16; |
07855bec | 2010 | } |
16a419ba NC |
2011 | else if (operand->bits == 32 && operand->shift == 16 |
2012 | && (operand->flags & S390_OPERAND_PCREL)) | |
07855bec | 2013 | { |
94f592af NC |
2014 | fixP->fx_size = 4; |
2015 | fixP->fx_where += 2; | |
2016 | fixP->fx_offset += 2; | |
2017 | fixP->fx_r_type = BFD_RELOC_390_PC32DBL; | |
07855bec | 2018 | } |
a85d7ed0 | 2019 | else |
07855bec NC |
2020 | { |
2021 | char *sfile; | |
2022 | unsigned int sline; | |
198ce79b | 2023 | |
07855bec NC |
2024 | /* Use expr_symbol_where to see if this is an expression |
2025 | symbol. */ | |
94f592af NC |
2026 | if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) |
2027 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
07855bec NC |
2028 | _("unresolved expression that must be resolved")); |
2029 | else | |
94f592af | 2030 | as_bad_where (fixP->fx_file, fixP->fx_line, |
07855bec | 2031 | _("unsupported relocation type")); |
94f592af NC |
2032 | fixP->fx_done = 1; |
2033 | return; | |
07855bec | 2034 | } |
a85d7ed0 | 2035 | } |
07855bec NC |
2036 | else |
2037 | { | |
94f592af | 2038 | switch (fixP->fx_r_type) |
07855bec NC |
2039 | { |
2040 | case BFD_RELOC_8: | |
94f592af | 2041 | if (fixP->fx_pcrel) |
07855bec | 2042 | abort (); |
94f592af | 2043 | if (fixP->fx_done) |
07855bec NC |
2044 | md_number_to_chars (where, value, 1); |
2045 | break; | |
2046 | case BFD_RELOC_390_12: | |
2047 | case BFD_RELOC_390_GOT12: | |
2a19f73f | 2048 | case BFD_RELOC_390_GOTPLT12: |
94f592af | 2049 | if (fixP->fx_done) |
07855bec NC |
2050 | { |
2051 | unsigned short mop; | |
2052 | ||
2053 | mop = bfd_getb16 ((unsigned char *) where); | |
2054 | mop |= (unsigned short) (value & 0xfff); | |
2055 | bfd_putb16 ((bfd_vma) mop, (unsigned char *) where); | |
198ce79b | 2056 | } |
07855bec | 2057 | break; |
198ce79b | 2058 | |
933fbc29 MS |
2059 | case BFD_RELOC_390_20: |
2060 | case BFD_RELOC_390_GOT20: | |
2061 | case BFD_RELOC_390_GOTPLT20: | |
2062 | if (fixP->fx_done) | |
2063 | { | |
2064 | unsigned int mop; | |
2065 | mop = bfd_getb32 ((unsigned char *) where); | |
2066 | mop |= (unsigned int) ((value & 0xfff) << 8 | | |
2067 | (value & 0xff000) >> 12); | |
2068 | bfd_putb32 ((bfd_vma) mop, (unsigned char *) where); | |
2069 | } | |
2070 | break; | |
2071 | ||
07855bec NC |
2072 | case BFD_RELOC_16: |
2073 | case BFD_RELOC_GPREL16: | |
2074 | case BFD_RELOC_16_GOT_PCREL: | |
2075 | case BFD_RELOC_16_GOTOFF: | |
94f592af NC |
2076 | if (fixP->fx_pcrel) |
2077 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20203fb9 | 2078 | _("cannot emit PC relative %s relocation%s%s"), |
94f592af NC |
2079 | bfd_get_reloc_code_name (fixP->fx_r_type), |
2080 | fixP->fx_addsy != NULL ? " against " : "", | |
2081 | (fixP->fx_addsy != NULL | |
2082 | ? S_GET_NAME (fixP->fx_addsy) | |
07855bec | 2083 | : "")); |
94f592af | 2084 | if (fixP->fx_done) |
07855bec NC |
2085 | md_number_to_chars (where, value, 2); |
2086 | break; | |
2087 | case BFD_RELOC_390_GOT16: | |
2a19f73f MS |
2088 | case BFD_RELOC_390_PLTOFF16: |
2089 | case BFD_RELOC_390_GOTPLT16: | |
94f592af | 2090 | if (fixP->fx_done) |
07855bec NC |
2091 | md_number_to_chars (where, value, 2); |
2092 | break; | |
2093 | case BFD_RELOC_390_PC16DBL: | |
2094 | case BFD_RELOC_390_PLT16DBL: | |
2095 | value += 2; | |
94f592af | 2096 | if (fixP->fx_done) |
07855bec NC |
2097 | md_number_to_chars (where, (offsetT) value >> 1, 2); |
2098 | break; | |
2099 | ||
2100 | case BFD_RELOC_32: | |
94f592af NC |
2101 | if (fixP->fx_pcrel) |
2102 | fixP->fx_r_type = BFD_RELOC_32_PCREL; | |
07855bec | 2103 | else |
94f592af NC |
2104 | fixP->fx_r_type = BFD_RELOC_32; |
2105 | if (fixP->fx_done) | |
07855bec NC |
2106 | md_number_to_chars (where, value, 4); |
2107 | break; | |
2108 | case BFD_RELOC_32_PCREL: | |
2109 | case BFD_RELOC_32_BASEREL: | |
94f592af NC |
2110 | fixP->fx_r_type = BFD_RELOC_32_PCREL; |
2111 | if (fixP->fx_done) | |
07855bec NC |
2112 | md_number_to_chars (where, value, 4); |
2113 | break; | |
2114 | case BFD_RELOC_32_GOT_PCREL: | |
2a19f73f | 2115 | case BFD_RELOC_390_PLTOFF32: |
07855bec | 2116 | case BFD_RELOC_390_PLT32: |
2a19f73f | 2117 | case BFD_RELOC_390_GOTPLT32: |
94f592af | 2118 | if (fixP->fx_done) |
07855bec NC |
2119 | md_number_to_chars (where, value, 4); |
2120 | break; | |
2121 | case BFD_RELOC_390_PC32DBL: | |
2122 | case BFD_RELOC_390_PLT32DBL: | |
2123 | case BFD_RELOC_390_GOTPCDBL: | |
2124 | case BFD_RELOC_390_GOTENT: | |
2a19f73f | 2125 | case BFD_RELOC_390_GOTPLTENT: |
07855bec | 2126 | value += 2; |
94f592af | 2127 | if (fixP->fx_done) |
07855bec NC |
2128 | md_number_to_chars (where, (offsetT) value >> 1, 4); |
2129 | break; | |
2130 | ||
2131 | case BFD_RELOC_32_GOTOFF: | |
94f592af | 2132 | if (fixP->fx_done) |
07726851 | 2133 | md_number_to_chars (where, value, sizeof (int)); |
07855bec NC |
2134 | break; |
2135 | ||
2a19f73f MS |
2136 | case BFD_RELOC_390_GOTOFF64: |
2137 | if (fixP->fx_done) | |
2138 | md_number_to_chars (where, value, 8); | |
2139 | break; | |
2140 | ||
07855bec | 2141 | case BFD_RELOC_390_GOT64: |
2a19f73f | 2142 | case BFD_RELOC_390_PLTOFF64: |
07855bec | 2143 | case BFD_RELOC_390_PLT64: |
2a19f73f | 2144 | case BFD_RELOC_390_GOTPLT64: |
94f592af | 2145 | if (fixP->fx_done) |
07855bec NC |
2146 | md_number_to_chars (where, value, 8); |
2147 | break; | |
2148 | ||
2149 | case BFD_RELOC_64: | |
94f592af NC |
2150 | if (fixP->fx_pcrel) |
2151 | fixP->fx_r_type = BFD_RELOC_64_PCREL; | |
07855bec | 2152 | else |
94f592af NC |
2153 | fixP->fx_r_type = BFD_RELOC_64; |
2154 | if (fixP->fx_done) | |
07855bec NC |
2155 | md_number_to_chars (where, value, 8); |
2156 | break; | |
2157 | ||
2158 | case BFD_RELOC_64_PCREL: | |
94f592af NC |
2159 | fixP->fx_r_type = BFD_RELOC_64_PCREL; |
2160 | if (fixP->fx_done) | |
07855bec NC |
2161 | md_number_to_chars (where, value, 8); |
2162 | break; | |
2163 | ||
2164 | case BFD_RELOC_VTABLE_INHERIT: | |
2165 | case BFD_RELOC_VTABLE_ENTRY: | |
94f592af NC |
2166 | fixP->fx_done = 0; |
2167 | return; | |
07855bec | 2168 | |
1971b29d MS |
2169 | case BFD_RELOC_390_TLS_LOAD: |
2170 | case BFD_RELOC_390_TLS_GDCALL: | |
2171 | case BFD_RELOC_390_TLS_LDCALL: | |
2172 | case BFD_RELOC_390_TLS_GD32: | |
2173 | case BFD_RELOC_390_TLS_GD64: | |
2174 | case BFD_RELOC_390_TLS_GOTIE12: | |
933fbc29 | 2175 | case BFD_RELOC_390_TLS_GOTIE20: |
1971b29d MS |
2176 | case BFD_RELOC_390_TLS_GOTIE32: |
2177 | case BFD_RELOC_390_TLS_GOTIE64: | |
2178 | case BFD_RELOC_390_TLS_LDM32: | |
2179 | case BFD_RELOC_390_TLS_LDM64: | |
2180 | case BFD_RELOC_390_TLS_IE32: | |
2181 | case BFD_RELOC_390_TLS_IE64: | |
2182 | case BFD_RELOC_390_TLS_LE32: | |
2183 | case BFD_RELOC_390_TLS_LE64: | |
2184 | case BFD_RELOC_390_TLS_LDO32: | |
2185 | case BFD_RELOC_390_TLS_LDO64: | |
2186 | case BFD_RELOC_390_TLS_DTPMOD: | |
2187 | case BFD_RELOC_390_TLS_DTPOFF: | |
2188 | case BFD_RELOC_390_TLS_TPOFF: | |
7c1d0959 | 2189 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
1971b29d MS |
2190 | /* Fully resolved at link time. */ |
2191 | break; | |
2192 | case BFD_RELOC_390_TLS_IEENT: | |
2193 | /* Fully resolved at link time. */ | |
7c1d0959 | 2194 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
1971b29d MS |
2195 | value += 2; |
2196 | break; | |
2197 | ||
07855bec NC |
2198 | default: |
2199 | { | |
94f592af | 2200 | const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type); |
198ce79b | 2201 | |
07855bec | 2202 | if (reloc_name != NULL) |
20203fb9 | 2203 | as_fatal (_("Gas failure, reloc type %s\n"), reloc_name); |
07855bec | 2204 | else |
20203fb9 | 2205 | as_fatal (_("Gas failure, reloc type #%i\n"), fixP->fx_r_type); |
07855bec NC |
2206 | } |
2207 | } | |
a85d7ed0 | 2208 | |
94f592af | 2209 | fixP->fx_offset = value; |
07855bec | 2210 | } |
a85d7ed0 NC |
2211 | } |
2212 | ||
2213 | /* Generate a reloc for a fixup. */ | |
2214 | ||
2215 | arelent * | |
5a49b8ac | 2216 | tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) |
a85d7ed0 NC |
2217 | { |
2218 | bfd_reloc_code_real_type code; | |
2219 | arelent *reloc; | |
2220 | ||
2221 | code = fixp->fx_r_type; | |
07855bec NC |
2222 | if (GOT_symbol && fixp->fx_addsy == GOT_symbol) |
2223 | { | |
16a419ba NC |
2224 | if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL) |
2225 | || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL)) | |
07855bec NC |
2226 | code = BFD_RELOC_390_GOTPC; |
2227 | if (code == BFD_RELOC_390_PC32DBL) | |
2228 | code = BFD_RELOC_390_GOTPCDBL; | |
2229 | } | |
a85d7ed0 NC |
2230 | |
2231 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
2232 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
2233 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
2234 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
2235 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
2236 | if (reloc->howto == NULL) | |
2237 | { | |
2238 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
98d3f06f KH |
2239 | _("cannot represent relocation type %s"), |
2240 | bfd_get_reloc_code_name (code)); | |
a85d7ed0 NC |
2241 | /* Set howto to a garbage value so that we can keep going. */ |
2242 | reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); | |
9c2799c2 | 2243 | gas_assert (reloc->howto != NULL); |
a85d7ed0 NC |
2244 | } |
2245 | reloc->addend = fixp->fx_offset; | |
2246 | ||
2247 | return reloc; | |
2248 | } | |
75e21f08 JJ |
2249 | |
2250 | void | |
5a49b8ac | 2251 | s390_cfi_frame_initial_instructions (void) |
75e21f08 JJ |
2252 | { |
2253 | cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96); | |
2254 | } | |
2255 | ||
2256 | int | |
1df69f4f | 2257 | tc_s390_regname_to_dw2regnum (char *regname) |
75e21f08 JJ |
2258 | { |
2259 | int regnum = -1; | |
2260 | ||
2261 | if (regname[0] != 'c' && regname[0] != 'a') | |
2262 | { | |
2263 | regnum = reg_name_search (pre_defined_registers, REG_NAME_CNT, regname); | |
2264 | if (regname[0] == 'f' && regnum != -1) | |
2265 | regnum += 16; | |
2266 | } | |
2267 | else if (strcmp (regname, "ap") == 0) | |
2268 | regnum = 32; | |
2269 | else if (strcmp (regname, "cc") == 0) | |
2270 | regnum = 33; | |
2271 | return regnum; | |
2272 | } | |
55786da2 AK |
2273 | |
2274 | void | |
2275 | s390_elf_final_processing (void) | |
2276 | { | |
2277 | if (s390_arch_size == 32 && (current_mode_mask & (1 << S390_OPCODE_ZARCH))) | |
2278 | elf_elfheader (stdoutput)->e_flags |= EF_S390_HIGH_GPRS; | |
2279 | } |