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