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