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