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