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