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