ld: Move the .note.build-id section to near the start of the memory map.
[binutils-gdb.git] / gas / config / tc-s390.c
blob75e1011f67b9ea909dd72c419842544bfe094276
1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
22 #include "as.h"
23 #include "safe-ctype.h"
24 #include "subsegs.h"
25 #include "dwarf2dbg.h"
26 #include "dw2gencfi.h"
28 #include "opcode/s390.h"
29 #include "elf/s390.h"
31 /* The default architecture. */
32 #ifndef DEFAULT_ARCH
33 #define DEFAULT_ARCH "s390"
34 #endif
35 static const char *default_arch = DEFAULT_ARCH;
36 /* Either 32 or 64, selects file format. */
37 static int s390_arch_size = 0;
39 /* If no -march option was given default to the highest available CPU.
40 Since with S/390 a newer CPU always supports everything from its
41 predecessors this will accept every valid asm input. */
42 static unsigned int current_cpu = S390_OPCODE_MAXCPU - 1;
43 /* All facilities are enabled by default. */
44 static unsigned int current_flags = S390_INSTR_FLAG_FACILITY_MASK;
45 /* The mode mask default is picked in init_default_arch depending on
46 the current cpu. */
47 static unsigned int current_mode_mask = 0;
49 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
50 for the output file. The default is picked in init_default_arch(). */
51 static bool set_highgprs_p = false;
53 /* Whether to use user friendly register names. Default is TRUE. */
54 #ifndef TARGET_REG_NAMES_P
55 #define TARGET_REG_NAMES_P true
56 #endif
58 static bool reg_names_p = TARGET_REG_NAMES_P;
60 /* Set to TRUE if we want to warn about zero base/index registers. */
61 static bool warn_areg_zero = false;
63 /* Whether to warn about register name type check mismatches. */
64 #ifndef S390_REGTYPE_CHECK
65 #define S390_REGTYPE_CHECK S390_REGTYPE_CHECK_RELAXED
66 #endif
68 enum s390_regtype_check {
69 S390_REGTYPE_CHECK_NONE = 0, /* No register name type checks. */
70 S390_REGTYPE_CHECK_RELAXED, /* Relaxed register name type checks. */
71 S390_REGTYPE_CHECK_STRICT /* Strict register name type checks. */
74 /* Whether to warn about register name type check mismatches. */
75 static enum s390_regtype_check warn_regtype_mismatch = S390_REGTYPE_CHECK;
77 /* Generic assembler global variables which must be defined by all
78 targets. */
80 const char comment_chars[] = "#";
82 /* Characters which start a comment at the beginning of a line. */
83 const char line_comment_chars[] = "#";
85 /* Characters which may be used to separate multiple commands on a
86 single line. */
87 const char line_separator_chars[] = ";";
89 /* Characters which are used to indicate an exponent in a floating
90 point number. */
91 const char EXP_CHARS[] = "eE";
93 /* Characters which mean that a number is a floating point constant,
94 as in 0d1.0. */
95 const char FLT_CHARS[] = "dD";
97 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
98 int s390_cie_data_alignment;
100 /* The target specific pseudo-ops which we support. */
102 /* Define the prototypes for the pseudo-ops */
103 static void s390_byte (int);
104 static void s390_elf_cons (int);
105 static void s390_insn (int);
106 static void s390_literals (int);
107 static void s390_machine (int);
108 static void s390_machinemode (int);
110 const pseudo_typeS md_pseudo_table[] =
112 { "align", s_align_bytes, 0 },
113 /* Pseudo-ops which must be defined. */
114 { "insn", s390_insn, 0 },
115 /* Pseudo-ops which must be overridden. */
116 { "byte", s390_byte, 0 },
117 { "short", s390_elf_cons, 2 },
118 { "long", s390_elf_cons, 4 },
119 { "quad", s390_elf_cons, 8 },
120 { "ltorg", s390_literals, 0 },
121 { "string", stringer, 8 + 1 },
122 { "machine", s390_machine, 0 },
123 { "machinemode", s390_machinemode, 0 },
124 { NULL, NULL, 0 }
127 /* Register types. */
128 enum s390_register_type
130 S390_REGTYPE_AR, /* Access register. */
131 S390_REGTYPE_CR, /* Control register. */
132 S390_REGTYPE_FPR, /* Floating-point register. */
133 S390_REGTYPE_GR, /* General register. */
134 S390_REGTYPE_VR, /* Vector register. */
137 /* Given NAME, find the register number associated with that name, return
138 the integer value associated with the given name or -1 on failure. */
140 static int
141 reg_name_search (const char *name)
143 int val = -1;
145 if (strcasecmp (name, "lit") == 0)
146 return 13;
148 if (strcasecmp (name, "sp") == 0)
149 return 15;
151 if (name[0] != 'a' && name[0] != 'c' && name[0] != 'f'
152 && name[0] != 'r' && name[0] != 'v')
153 return -1;
155 if (ISDIGIT (name[1]))
157 val = name[1] - '0';
158 if (ISDIGIT (name[2]))
159 val = val * 10 + name[2] - '0';
162 if ((name[0] != 'v' && val > 15) || val > 31)
163 val = -1;
165 return val;
170 * Summary of register_name().
172 * in: Input_line_pointer points to 1st char of operand.
174 * out: A expressionS.
175 * The operand may have been a register: in this case, X_op == O_register,
176 * X_add_number is set to the register number, and truth is returned.
177 * Input_line_pointer->(next non-blank) char after operand, or is in its
178 * original state.
181 static bool
182 register_name (expressionS *expressionP)
184 int reg_number;
185 char *name;
186 char *start;
187 char c;
189 /* Find the spelling of the operand. */
190 start = name = input_line_pointer;
191 if (name[0] == '%' && ISALPHA (name[1]))
192 name = ++input_line_pointer;
193 else
194 return false;
196 c = get_symbol_name (&name);
197 reg_number = reg_name_search (name);
199 /* Put back the delimiting char. */
200 (void) restore_line_pointer (c);
202 /* Look to see if it's in the register table. */
203 if (reg_number >= 0)
205 expressionP->X_op = O_register;
206 expressionP->X_add_number = reg_number;
207 switch (name[0])
209 case 'a':
210 expressionP->X_md = S390_REGTYPE_AR;
211 break;
212 case 'c':
213 expressionP->X_md = S390_REGTYPE_CR;
214 break;
215 case 'f':
216 expressionP->X_md = S390_REGTYPE_FPR;
217 break;
218 case 'r':
219 expressionP->X_md = S390_REGTYPE_GR;
220 break;
221 case 'v':
222 expressionP->X_md = S390_REGTYPE_VR;
223 break;
224 default:
225 expressionP->X_md = 0;
228 /* Make the rest nice. */
229 expressionP->X_add_symbol = NULL;
230 expressionP->X_op_symbol = NULL;
231 return true;
234 /* Reset the line as if we had not done anything. */
235 input_line_pointer = start;
236 return false;
239 /* Local variables. */
241 /* Opformat hash table. */
242 static htab_t s390_opformat_hash;
244 /* Opcode hash table. */
245 static htab_t s390_opcode_hash = NULL;
247 /* Flags to set in the elf header */
248 static flagword s390_flags = 0;
250 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
252 #ifndef WORKING_DOT_WORD
253 int md_short_jump_size = 4;
254 int md_long_jump_size = 4;
255 #endif
257 const char *md_shortopts = "A:m:kVQ:";
258 struct option md_longopts[] = {
259 {NULL, no_argument, NULL, 0}
261 size_t md_longopts_size = sizeof (md_longopts);
263 /* Initialize the default opcode arch and word size from the default
264 architecture name if not specified by an option. */
265 static void
266 init_default_arch (void)
268 /* Default architecture size. */
269 if (strcmp (default_arch, "s390") == 0)
271 if (s390_arch_size == 0)
272 s390_arch_size = 32;
274 else if (strcmp (default_arch, "s390x") == 0)
276 if (s390_arch_size == 0)
277 s390_arch_size = 64;
279 else
280 as_fatal (_("Invalid default architecture, broken assembler."));
282 /* Default current architecture mode. */
283 if (current_mode_mask == 0)
285 /* Default to z/Architecture mode if the CPU supports it. */
286 if (current_cpu < S390_OPCODE_Z900)
287 current_mode_mask = 1 << S390_OPCODE_ESA;
288 else
289 current_mode_mask = 1 << S390_OPCODE_ZARCH;
292 /* Determine whether the highgprs flag in the ELF header needs to be set. */
293 if ((s390_arch_size == 32) && (current_mode_mask & (1 << S390_OPCODE_ZARCH)))
294 set_highgprs_p = true;
297 /* Called by TARGET_FORMAT. */
298 const char *
299 s390_target_format (void)
301 /* We don't get a chance to initialize anything before we're called,
302 so handle that now. */
303 init_default_arch ();
305 return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
308 /* Map a cpu string ARG as given with -march= or .machine to the respective
309 enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name
310 can be followed by a list of cpu facility flags each beginning with the
311 character '+'. The active cpu flags are returned through *RET_FLAGS.
312 In case of an error, S390_OPCODE_MAXCPU is returned. */
314 static unsigned int
315 s390_parse_cpu (const char *arg,
316 unsigned int *ret_flags,
317 bool allow_extensions)
319 static struct
321 const char * name;
322 unsigned int name_len;
323 const char * alt_name;
324 unsigned int alt_name_len;
325 unsigned int flags;
326 } cpu_table[S390_OPCODE_MAXCPU] =
328 { STRING_COMMA_LEN ("g5"), STRING_COMMA_LEN ("arch3"), 0 },
329 { STRING_COMMA_LEN ("g6"), STRING_COMMA_LEN (""), 0 },
330 { STRING_COMMA_LEN ("z900"), STRING_COMMA_LEN ("arch5"), 0 },
331 { STRING_COMMA_LEN ("z990"), STRING_COMMA_LEN ("arch6"), 0 },
332 { STRING_COMMA_LEN ("z9-109"), STRING_COMMA_LEN (""), 0 },
333 { STRING_COMMA_LEN ("z9-ec"), STRING_COMMA_LEN ("arch7"), 0 },
334 { STRING_COMMA_LEN ("z10"), STRING_COMMA_LEN ("arch8"), 0 },
335 { STRING_COMMA_LEN ("z196"), STRING_COMMA_LEN ("arch9"), 0 },
336 { STRING_COMMA_LEN ("zEC12"), STRING_COMMA_LEN ("arch10"),
337 S390_INSTR_FLAG_HTM },
338 { STRING_COMMA_LEN ("z13"), STRING_COMMA_LEN ("arch11"),
339 S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX },
340 { STRING_COMMA_LEN ("z14"), STRING_COMMA_LEN ("arch12"),
341 S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX },
342 { STRING_COMMA_LEN ("z15"), STRING_COMMA_LEN ("arch13"),
343 S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX },
344 { STRING_COMMA_LEN ("z16"), STRING_COMMA_LEN ("arch14"),
345 S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }
347 static struct
349 const char *name;
350 unsigned int mask;
351 bool on;
352 } cpu_flags[] =
354 { "htm", S390_INSTR_FLAG_HTM, true },
355 { "nohtm", S390_INSTR_FLAG_HTM, false },
356 { "vx", S390_INSTR_FLAG_VX, true },
357 { "novx", S390_INSTR_FLAG_VX, false }
359 unsigned int icpu;
360 char *ilp_bak;
362 icpu = S390_OPCODE_MAXCPU;
363 if (startswith (arg, "all") && (arg[3] == 0 || arg[3] == '+'))
365 icpu = S390_OPCODE_MAXCPU - 1;
366 arg += 3;
368 else
370 for (icpu = 0; icpu < S390_OPCODE_MAXCPU; icpu++)
372 unsigned int l, l_alt;
374 l = cpu_table[icpu].name_len;
376 if (strncmp (arg, cpu_table[icpu].name, l) == 0
377 && (arg[l] == 0 || arg[l] == '+'))
379 arg += l;
380 break;
383 l_alt = cpu_table[icpu].alt_name_len;
385 if (l_alt > 0
386 && strncmp (arg, cpu_table[icpu].alt_name, l_alt) == 0
387 && (arg[l_alt] == 0 || arg[l_alt] == '+'))
389 arg += l_alt;
390 break;
395 if (icpu == S390_OPCODE_MAXCPU)
396 return S390_OPCODE_MAXCPU;
398 ilp_bak = input_line_pointer;
399 if (icpu != S390_OPCODE_MAXCPU)
401 input_line_pointer = (char *) arg;
402 *ret_flags = (cpu_table[icpu].flags & S390_INSTR_FLAG_FACILITY_MASK);
404 while (*input_line_pointer == '+' && allow_extensions)
406 unsigned int iflag;
407 char *sym;
408 char c;
410 input_line_pointer++;
411 c = get_symbol_name (&sym);
412 for (iflag = 0; iflag < ARRAY_SIZE (cpu_flags); iflag++)
414 if (strcmp (sym, cpu_flags[iflag].name) == 0)
416 if (cpu_flags[iflag].on)
417 *ret_flags |= cpu_flags[iflag].mask;
418 else
419 *ret_flags &= ~cpu_flags[iflag].mask;
420 break;
423 if (iflag == ARRAY_SIZE (cpu_flags))
424 as_bad (_("no such machine extension `%s'"), sym - 1);
425 *input_line_pointer = c;
426 if (iflag == ARRAY_SIZE (cpu_flags))
427 break;
431 SKIP_WHITESPACE ();
433 if (*input_line_pointer != 0 && *input_line_pointer != '\n')
435 as_bad (_("junk at end of machine string, first unrecognized character"
436 " is `%c'"), *input_line_pointer);
437 icpu = S390_OPCODE_MAXCPU;
439 input_line_pointer = ilp_bak;
441 return icpu;
445 md_parse_option (int c, const char *arg)
447 switch (c)
449 /* -k: Ignore for FreeBSD compatibility. */
450 case 'k':
451 break;
452 case 'm':
453 if (arg != NULL && strcmp (arg, "regnames") == 0)
454 reg_names_p = true;
456 else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
457 reg_names_p = false;
459 else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
460 warn_areg_zero = true;
462 else if (arg != NULL && strcmp (arg, "warn-regtype-mismatch=strict") == 0)
463 warn_regtype_mismatch = S390_REGTYPE_CHECK_STRICT;
465 else if (arg != NULL && strcmp (arg, "warn-regtype-mismatch=relaxed") == 0)
466 warn_regtype_mismatch = S390_REGTYPE_CHECK_RELAXED;
468 else if (arg != NULL && strcmp (arg, "warn-regtype-mismatch=no") == 0)
469 warn_regtype_mismatch = S390_REGTYPE_CHECK_NONE;
471 else if (arg != NULL && strcmp (arg, "no-warn-regtype-mismatch") == 0)
472 warn_regtype_mismatch = S390_REGTYPE_CHECK_NONE;
474 else if (arg != NULL && strcmp (arg, "31") == 0)
475 s390_arch_size = 32;
477 else if (arg != NULL && strcmp (arg, "64") == 0)
478 s390_arch_size = 64;
480 else if (arg != NULL && strcmp (arg, "esa") == 0)
481 current_mode_mask = 1 << S390_OPCODE_ESA;
483 else if (arg != NULL && strcmp (arg, "zarch") == 0)
484 current_mode_mask = 1 << S390_OPCODE_ZARCH;
486 else if (arg != NULL && startswith (arg, "arch="))
488 current_cpu = s390_parse_cpu (arg + 5, &current_flags, false);
489 if (current_cpu == S390_OPCODE_MAXCPU)
491 as_bad (_("invalid switch -m%s"), arg);
492 return 0;
496 else
498 as_bad (_("invalid switch -m%s"), arg);
499 return 0;
501 break;
503 case 'A':
504 /* Option -A is deprecated. Still available for compatibility. */
505 if (arg != NULL && strcmp (arg, "esa") == 0)
506 current_cpu = S390_OPCODE_G5;
507 else if (arg != NULL && strcmp (arg, "esame") == 0)
508 current_cpu = S390_OPCODE_Z900;
509 else
510 as_bad (_("invalid architecture -A%s"), arg);
511 break;
513 /* -V: SVR4 argument to print version ID. */
514 case 'V':
515 print_version_id ();
516 break;
518 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
519 should be emitted or not. FIXME: Not implemented. */
520 case 'Q':
521 break;
523 default:
524 return 0;
527 return 1;
530 void
531 md_show_usage (FILE *stream)
533 fprintf (stream, _("\
534 S390 options:\n\
535 -m31 generate 31-bit file format (31/32 bit word size)\n\
536 -m64 generate 64-bit file format (64 bit word size)\n\
537 -mesa assemble for Enterprise System Architecture/390\n\
538 -mzarch assemble for z/Architecture\n\
539 -march=<processor> assemble for processor <processor>\n\
540 -mregnames allow symbolic names for registers\n\
541 -mno-regnames do not allow symbolic names for registers\n\
542 -mwarn-areg-zero warn about base/index register zero\n\
543 -mwarn-regtype-mismatch=strict\n\
544 warn about register name type mismatches\n\
545 -mwarn-regtype-mismatch=relaxed\n\
546 warn about register name type mismatches,\n\
547 but allow FPR and VR to be used interchangeably\n\
548 -mno-warn-regtype-mismatch\n\
549 do not warn about register name type mismatches\n\
550 "));
551 fprintf (stream, _("\
552 -V print assembler version number\n\
553 -Qy, -Qn ignored\n"));
554 fprintf (stream, _("\
555 Deprecated S390 options:\n\
556 -Aesa assemble for processor IBM S/390 G5 (g5/arch3)\n\
557 -Aesame assemble for processor IBM zSeries 900 (z900/arch5)\n"));
560 /* Generate the hash table mapping mnemonics to struct s390_opcode.
561 This table is built at startup and whenever the CPU level is
562 changed using .machine. */
564 static void
565 s390_setup_opcodes (void)
567 const struct s390_opcode *op;
568 const struct s390_opcode *op_end;
569 bool dup_insn = false;
571 if (s390_opcode_hash != NULL)
572 htab_delete (s390_opcode_hash);
574 /* Insert the opcodes into a hash table. */
575 s390_opcode_hash = str_htab_create ();
577 op_end = s390_opcodes + s390_num_opcodes;
578 for (op = s390_opcodes; op < op_end; op++)
580 int use_opcode;
582 while (op < op_end - 1 && strcmp(op->name, op[1].name) == 0)
584 if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask))
585 break;
586 op++;
589 if ((op->modes & current_mode_mask) == 0)
590 use_opcode = 0;
591 else if ((op->flags & S390_INSTR_FLAG_FACILITY_MASK) == 0)
593 /* Opcodes that do not belong to a specific facility are enabled if
594 present in the selected cpu. */
595 use_opcode = (op->min_cpu <= current_cpu);
597 else
599 unsigned int f;
601 /* Opcodes of a specific facility are enabled if the facility is
602 enabled. Note: only some facilities are represented as flags. */
603 f = (op->flags & S390_INSTR_FLAG_FACILITY_MASK);
604 use_opcode = ((f & current_flags) == f);
606 if (use_opcode
607 && str_hash_insert (s390_opcode_hash, op->name, op, 0) != NULL)
609 as_bad (_("duplicate %s"), op->name);
610 dup_insn = true;
613 while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0)
614 op++;
617 if (dup_insn)
618 abort ();
621 /* This function is called when the assembler starts up. It is called
622 after the options have been parsed and the output file has been
623 opened. */
625 void
626 md_begin (void)
628 const struct s390_opcode *op;
629 const struct s390_opcode *op_end;
631 /* Give a warning if the combination -m64 and -Aesa is used. */
632 if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900)
633 as_warn (_("The 64-bit file format is used without z/Architecture instructions."));
635 s390_cie_data_alignment = -s390_arch_size / 8;
637 /* Set the ELF flags if desired. */
638 if (s390_flags)
639 bfd_set_private_flags (stdoutput, s390_flags);
641 /* Insert the opcode formats into a hash table. */
642 s390_opformat_hash = str_htab_create ();
644 op_end = s390_opformats + s390_num_opformats;
645 for (op = s390_opformats; op < op_end; op++)
646 if (str_hash_insert (s390_opformat_hash, op->name, op, 0) != NULL)
647 as_fatal (_("duplicate %s"), op->name);
649 s390_setup_opcodes ();
651 record_alignment (text_section, 2);
652 record_alignment (data_section, 2);
653 record_alignment (bss_section, 2);
656 /* Called after all assembly has been done. */
657 void
658 s390_md_finish (void)
660 if (s390_arch_size == 64)
661 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
662 else
663 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
666 static void
667 s390_bad_operand_out_of_range (int operand_number,
668 offsetT value,
669 offsetT min,
670 offsetT max,
671 const char *file,
672 unsigned line)
674 const char * err;
676 if (operand_number > 0)
678 /* xgettext:c-format. */
679 err =_("operand %d: operand out of range (%" PRId64
680 " is not between %" PRId64 " and %" PRId64 ")");
681 if (file)
682 as_bad_where (file, line, err, operand_number,
683 (int64_t) value, (int64_t) min, (int64_t) max);
684 else
685 as_bad (err, operand_number,
686 (int64_t) value, (int64_t) min, (int64_t) max);
688 else
690 /* xgettext:c-format. */
691 err = _("operand out of range (%" PRId64
692 " is not between %" PRId64 " and %" PRId64 ")");
693 if (file)
694 as_bad_where (file, line, err,
695 (int64_t) value, (int64_t) min, (int64_t) max);
696 else
697 as_bad (err, (int64_t) value, (int64_t) min, (int64_t) max);
701 /* Insert an operand value into an instruction. */
703 static void
704 s390_insert_operand (unsigned char *insn,
705 const struct s390_operand *operand,
706 offsetT val,
707 const char *file,
708 unsigned int line,
709 int operand_number)
711 addressT uval;
712 int offset;
714 if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
716 offsetT min, max;
718 max = ((offsetT) 1 << (operand->bits - 1)) - 1;
719 min = - ((offsetT) 1 << (operand->bits - 1));
720 /* Halve PCREL operands. */
721 if (operand->flags & S390_OPERAND_PCREL)
722 val >>= 1;
723 /* Check for underflow / overflow. */
724 if (val < min || val > max)
726 if (operand->flags & S390_OPERAND_PCREL)
728 val = (offsetT) ((addressT) val << 1);
729 min = (offsetT) ((addressT) min << 1);
730 max = (offsetT) ((addressT) max << 1);
733 s390_bad_operand_out_of_range (operand_number, val, min, max,
734 file, line);
736 return;
738 /* val is ok, now restrict it to operand->bits bits. */
739 uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
740 /* val is restrict, now check for special case. */
741 if (operand->bits == 20 && operand->shift == 20)
742 uval = (uval >> 12) | ((uval & 0xfff) << 8);
744 else
746 addressT min, max;
748 max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
749 min = (offsetT) 0;
750 uval = (addressT) val;
752 /* Vector register operands have an additional bit in the RXB
753 field. */
754 if (operand->flags & S390_OPERAND_VR)
755 max = (max << 1) | 1;
757 /* Length x in an instructions has real length x+1. */
758 if (operand->flags & S390_OPERAND_LENGTH)
759 uval--;
760 /* Check for underflow / overflow. */
761 if (uval < min || uval > max)
763 if (operand->flags & S390_OPERAND_LENGTH)
765 uval++;
766 min++;
767 max++;
770 s390_bad_operand_out_of_range (operand_number, val, min, max,
771 file, line);
773 return;
777 if (operand->flags & S390_OPERAND_VR)
779 /* Insert the extra bit into the RXB field. */
780 switch (operand->shift)
782 case 8:
783 insn[4] |= (uval & 0x10) >> 1;
784 break;
785 case 12:
786 insn[4] |= (uval & 0x10) >> 2;
787 break;
788 case 16:
789 insn[4] |= (uval & 0x10) >> 3;
790 break;
791 case 32:
792 insn[4] |= (uval & 0x10) >> 4;
793 break;
795 uval &= 0xf;
798 /* Duplicate the GPR/VR operand at bit pos 12 to 16. */
799 if (operand->flags & S390_OPERAND_CP16)
801 /* Copy GPR/VR operand at bit pos 12 to bit pos 16. */
802 insn[2] |= uval << 4;
804 if (operand->flags & S390_OPERAND_VR)
806 /* Copy the VR flag in the RXB field. */
807 insn[4] |= (insn[4] & 4) >> 1;
811 /* Insert fragments of the operand byte for byte. */
812 offset = operand->shift + operand->bits;
813 uval <<= (-offset) & 7;
814 insn += (offset - 1) / 8;
815 while (uval != 0)
817 *insn-- |= uval;
818 uval >>= 8;
822 struct map_tls
824 const char *string;
825 int length;
826 bfd_reloc_code_real_type reloc;
829 /* Parse tls marker and return the desired relocation. */
830 static bfd_reloc_code_real_type
831 s390_tls_suffix (char **str_p, expressionS *exp_p)
833 static struct map_tls mapping[] =
835 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD },
836 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL },
837 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL },
838 { NULL, 0, BFD_RELOC_UNUSED }
840 struct map_tls *ptr;
841 char *orig_line;
842 char *str;
843 char *ident;
844 int len;
846 str = *str_p;
847 if (*str++ != ':')
848 return BFD_RELOC_UNUSED;
850 ident = str;
851 while (ISIDNUM (*str))
852 str++;
853 len = str - ident;
854 if (*str++ != ':')
855 return BFD_RELOC_UNUSED;
857 orig_line = input_line_pointer;
858 input_line_pointer = str;
859 expression (exp_p);
860 str = input_line_pointer;
861 if (&input_line_pointer != str_p)
862 input_line_pointer = orig_line;
864 if (exp_p->X_op != O_symbol)
865 return BFD_RELOC_UNUSED;
867 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
868 if (len == ptr->length
869 && strncasecmp (ident, ptr->string, ptr->length) == 0)
871 /* Found a matching tls suffix. */
872 *str_p = str;
873 return ptr->reloc;
875 return BFD_RELOC_UNUSED;
878 /* Structure used to hold suffixes. */
879 typedef enum
881 ELF_SUFFIX_NONE = 0,
882 ELF_SUFFIX_GOT,
883 ELF_SUFFIX_PLT,
884 ELF_SUFFIX_GOTENT,
885 ELF_SUFFIX_GOTOFF,
886 ELF_SUFFIX_GOTPLT,
887 ELF_SUFFIX_PLTOFF,
888 ELF_SUFFIX_TLS_GD,
889 ELF_SUFFIX_TLS_GOTIE,
890 ELF_SUFFIX_TLS_IE,
891 ELF_SUFFIX_TLS_LDM,
892 ELF_SUFFIX_TLS_LDO,
893 ELF_SUFFIX_TLS_LE
895 elf_suffix_type;
897 struct map_bfd
899 const char *string;
900 int length;
901 elf_suffix_type suffix;
905 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
906 static elf_suffix_type
907 s390_elf_suffix (char **str_p, expressionS *exp_p)
909 static struct map_bfd mapping[] =
911 { "got", 3, ELF_SUFFIX_GOT },
912 { "got12", 5, ELF_SUFFIX_GOT },
913 { "plt", 3, ELF_SUFFIX_PLT },
914 { "gotent", 6, ELF_SUFFIX_GOTENT },
915 { "gotoff", 6, ELF_SUFFIX_GOTOFF },
916 { "gotplt", 6, ELF_SUFFIX_GOTPLT },
917 { "pltoff", 6, ELF_SUFFIX_PLTOFF },
918 { "tlsgd", 5, ELF_SUFFIX_TLS_GD },
919 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE },
920 { "indntpoff", 9, ELF_SUFFIX_TLS_IE },
921 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM },
922 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO },
923 { "ntpoff", 6, ELF_SUFFIX_TLS_LE },
924 { NULL, 0, ELF_SUFFIX_NONE }
927 struct map_bfd *ptr;
928 char *str = *str_p;
929 char *ident;
930 int len;
932 if (*str++ != '@')
933 return ELF_SUFFIX_NONE;
935 ident = str;
936 while (ISALNUM (*str))
937 str++;
938 len = str - ident;
940 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
941 if (len == ptr->length
942 && strncasecmp (ident, ptr->string, ptr->length) == 0)
944 if (exp_p->X_add_number != 0)
945 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
946 ptr->string, ptr->string);
947 /* Now check for identifier@suffix+constant. */
948 if (*str == '-' || *str == '+')
950 char *orig_line = input_line_pointer;
951 expressionS new_exp;
953 input_line_pointer = str;
954 expression (&new_exp);
956 switch (new_exp.X_op)
958 case O_constant: /* X_add_number (a constant expression). */
959 exp_p->X_add_number += new_exp.X_add_number;
960 str = input_line_pointer;
961 break;
962 case O_symbol: /* X_add_symbol + X_add_number. */
963 /* this case is used for e.g. xyz@PLT+.Label. */
964 exp_p->X_add_number += new_exp.X_add_number;
965 exp_p->X_op_symbol = new_exp.X_add_symbol;
966 exp_p->X_op = O_add;
967 str = input_line_pointer;
968 break;
969 case O_uminus: /* (- X_add_symbol) + X_add_number. */
970 /* this case is used for e.g. xyz@PLT-.Label. */
971 exp_p->X_add_number += new_exp.X_add_number;
972 exp_p->X_op_symbol = new_exp.X_add_symbol;
973 exp_p->X_op = O_subtract;
974 str = input_line_pointer;
975 break;
976 default:
977 break;
980 /* If s390_elf_suffix has not been called with
981 &input_line_pointer as first parameter, we have
982 clobbered the input_line_pointer. We have to
983 undo that. */
984 if (&input_line_pointer != str_p)
985 input_line_pointer = orig_line;
987 *str_p = str;
988 return ptr->suffix;
991 return ELF_SUFFIX_NONE;
994 /* Structure used to hold a literal pool entry. */
995 struct s390_lpe
997 struct s390_lpe *next;
998 expressionS ex;
999 FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */
1000 LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */
1001 int nbytes;
1002 bfd_reloc_code_real_type reloc;
1003 symbolS *sym;
1006 static struct s390_lpe *lpe_free_list = NULL;
1007 static struct s390_lpe *lpe_list = NULL;
1008 static struct s390_lpe *lpe_list_tail = NULL;
1009 static symbolS *lp_sym = NULL;
1010 static int lp_count = 0;
1011 static int lpe_count = 0;
1013 static int
1014 s390_exp_compare (expressionS *exp1, expressionS *exp2)
1016 if (exp1->X_op != exp2->X_op)
1017 return 0;
1019 switch (exp1->X_op)
1021 case O_constant: /* X_add_number must be equal. */
1022 case O_register:
1023 return exp1->X_add_number == exp2->X_add_number;
1025 case O_big:
1026 as_bad (_("Can't handle O_big in s390_exp_compare"));
1027 return 0;
1029 case O_symbol: /* X_add_symbol & X_add_number must be equal. */
1030 case O_symbol_rva:
1031 case O_uminus:
1032 case O_bit_not:
1033 case O_logical_not:
1034 return (exp1->X_add_symbol == exp2->X_add_symbol)
1035 && (exp1->X_add_number == exp2->X_add_number);
1037 case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
1038 case O_divide:
1039 case O_modulus:
1040 case O_left_shift:
1041 case O_right_shift:
1042 case O_bit_inclusive_or:
1043 case O_bit_or_not:
1044 case O_bit_exclusive_or:
1045 case O_bit_and:
1046 case O_add:
1047 case O_subtract:
1048 case O_eq:
1049 case O_ne:
1050 case O_lt:
1051 case O_le:
1052 case O_ge:
1053 case O_gt:
1054 case O_logical_and:
1055 case O_logical_or:
1056 return (exp1->X_add_symbol == exp2->X_add_symbol)
1057 && (exp1->X_op_symbol == exp2->X_op_symbol)
1058 && (exp1->X_add_number == exp2->X_add_number);
1059 default:
1060 return 0;
1064 /* Test for @lit and if it's present make an entry in the literal pool and
1065 modify the current expression to be an offset into the literal pool. */
1066 static elf_suffix_type
1067 s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix)
1069 bfd_reloc_code_real_type reloc;
1070 char tmp_name[64];
1071 char *str = *str_p;
1072 char *ident;
1073 struct s390_lpe *lpe;
1074 int nbytes, len;
1076 if (*str++ != ':')
1077 return suffix; /* No modification. */
1079 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
1080 ident = str;
1081 while (ISALNUM (*str))
1082 str++;
1083 len = str - ident;
1084 if (len != 4 || strncasecmp (ident, "lit", 3) != 0
1085 || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
1086 return suffix; /* no modification */
1087 nbytes = ident[3] - '0';
1089 reloc = BFD_RELOC_UNUSED;
1090 if (suffix == ELF_SUFFIX_GOT)
1092 if (nbytes == 2)
1093 reloc = BFD_RELOC_390_GOT16;
1094 else if (nbytes == 4)
1095 reloc = BFD_RELOC_32_GOT_PCREL;
1096 else if (nbytes == 8)
1097 reloc = BFD_RELOC_390_GOT64;
1099 else if (suffix == ELF_SUFFIX_PLT)
1101 if (nbytes == 4)
1102 reloc = BFD_RELOC_390_PLT32;
1103 else if (nbytes == 8)
1104 reloc = BFD_RELOC_390_PLT64;
1107 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1108 as_bad (_("Invalid suffix for literal pool entry"));
1110 /* Search the pool if the new entry is a duplicate. */
1111 if (exp_p->X_op == O_big)
1113 /* Special processing for big numbers. */
1114 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
1116 if (lpe->ex.X_op == O_big)
1118 if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
1120 if (memcmp (&generic_floating_point_number, &lpe->floatnum,
1121 sizeof (FLONUM_TYPE)) == 0)
1122 break;
1124 else if (exp_p->X_add_number == lpe->ex.X_add_number)
1126 if (memcmp (generic_bignum, lpe->bignum,
1127 sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
1128 break;
1133 else
1135 /* Processing for 'normal' data types. */
1136 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
1137 if (lpe->nbytes == nbytes && lpe->reloc == reloc
1138 && s390_exp_compare (exp_p, &lpe->ex) != 0)
1139 break;
1142 if (lpe == NULL)
1144 /* A new literal. */
1145 if (lpe_free_list != NULL)
1147 lpe = lpe_free_list;
1148 lpe_free_list = lpe_free_list->next;
1150 else
1152 lpe = XNEW (struct s390_lpe);
1155 lpe->ex = *exp_p;
1157 if (exp_p->X_op == O_big)
1159 if (exp_p->X_add_number <= 0)
1160 lpe->floatnum = generic_floating_point_number;
1161 else if (exp_p->X_add_number <= 4)
1162 memcpy (lpe->bignum, generic_bignum,
1163 exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
1164 else
1165 as_bad (_("Big number is too big"));
1168 lpe->nbytes = nbytes;
1169 lpe->reloc = reloc;
1170 /* Literal pool name defined ? */
1171 if (lp_sym == NULL)
1173 sprintf (tmp_name, ".L\001%i", lp_count);
1174 lp_sym = symbol_make (tmp_name);
1177 /* Make name for literal pool entry. */
1178 sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
1179 lpe_count++;
1180 lpe->sym = symbol_make (tmp_name);
1182 /* Add to literal pool list. */
1183 lpe->next = NULL;
1184 if (lpe_list_tail != NULL)
1186 lpe_list_tail->next = lpe;
1187 lpe_list_tail = lpe;
1189 else
1190 lpe_list = lpe_list_tail = lpe;
1193 /* Now change exp_p to the offset into the literal pool.
1194 That's the expression: .L^Ax^By-.L^Ax */
1195 exp_p->X_add_symbol = lpe->sym;
1196 exp_p->X_op_symbol = lp_sym;
1197 exp_p->X_op = O_subtract;
1198 exp_p->X_add_number = 0;
1200 *str_p = str;
1202 /* We change the suffix type to ELF_SUFFIX_NONE, because
1203 the difference of two local labels is just a number. */
1204 return ELF_SUFFIX_NONE;
1207 /* Like normal .long/.short/.word, except support @got, etc.
1208 clobbers input_line_pointer, checks end-of-line. */
1209 static void
1210 s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */)
1212 expressionS exp;
1213 elf_suffix_type suffix;
1215 if (is_it_end_of_statement ())
1217 demand_empty_rest_of_line ();
1218 return;
1223 expression (&exp);
1225 if (exp.X_op == O_symbol
1226 && *input_line_pointer == '@'
1227 && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
1229 bfd_reloc_code_real_type reloc;
1230 reloc_howto_type *reloc_howto;
1231 int size;
1232 char *where;
1234 if (nbytes == 2)
1236 static bfd_reloc_code_real_type tab2[] =
1238 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1239 BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */
1240 BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */
1241 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1242 BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1243 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */
1244 BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */
1245 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */
1246 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */
1247 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */
1248 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */
1249 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */
1250 BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */
1252 reloc = tab2[suffix];
1254 else if (nbytes == 4)
1256 static bfd_reloc_code_real_type tab4[] =
1258 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1259 BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */
1260 BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */
1261 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1262 BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1263 BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */
1264 BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */
1265 BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */
1266 BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */
1267 BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */
1268 BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */
1269 BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */
1270 BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */
1272 reloc = tab4[suffix];
1274 else if (nbytes == 8)
1276 static bfd_reloc_code_real_type tab8[] =
1278 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1279 BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */
1280 BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */
1281 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1282 BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */
1283 BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */
1284 BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */
1285 BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */
1286 BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */
1287 BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */
1288 BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */
1289 BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */
1290 BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */
1292 reloc = tab8[suffix];
1294 else
1295 reloc = BFD_RELOC_UNUSED;
1297 if (reloc != BFD_RELOC_UNUSED
1298 && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc)))
1300 size = bfd_get_reloc_size (reloc_howto);
1301 if (size > nbytes)
1302 as_bad (ngettext ("%s relocations do not fit in %d byte",
1303 "%s relocations do not fit in %d bytes",
1304 nbytes),
1305 reloc_howto->name, nbytes);
1306 where = frag_more (nbytes);
1307 md_number_to_chars (where, 0, size);
1308 /* To make fixup_segment do the pc relative conversion the
1309 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1310 fix_new_exp (frag_now, where - frag_now->fr_literal,
1311 size, &exp, false, reloc);
1313 else
1314 as_bad (_("relocation not applicable"));
1316 else
1317 emit_expr (&exp, (unsigned int) nbytes);
1319 while (*input_line_pointer++ == ',');
1321 input_line_pointer--; /* Put terminator back into stream. */
1322 demand_empty_rest_of_line ();
1325 static const char *
1326 operand_type_str(const struct s390_operand * operand)
1328 if (operand->flags & S390_OPERAND_BASE)
1329 return _("base register");
1330 else if (operand->flags & S390_OPERAND_DISP)
1331 return _("displacement");
1332 else if (operand->flags & S390_OPERAND_INDEX)
1334 if (operand->flags & S390_OPERAND_VR)
1335 return _("vector index register");
1336 else
1337 return _("index register");
1339 else if (operand->flags & S390_OPERAND_LENGTH)
1340 return _("length");
1341 else if (operand->flags & S390_OPERAND_AR)
1342 return _("access register");
1343 else if (operand->flags & S390_OPERAND_CR)
1344 return _("control register");
1345 else if (operand->flags & S390_OPERAND_FPR)
1346 return _("floating-point register");
1347 else if (operand->flags & S390_OPERAND_GPR)
1348 return _("general-purpose register");
1349 else if (operand->flags & S390_OPERAND_VR)
1350 return _("vector register");
1351 else
1353 if (operand->flags & S390_OPERAND_SIGNED)
1354 return _("signed number");
1355 else
1356 return _("unsigned number");
1360 /* Return true if all remaining operands in the opcode with
1361 OPCODE_FLAGS can be skipped. */
1362 static bool
1363 skip_optargs_p (unsigned int opcode_flags, const unsigned char *opindex_ptr)
1365 if ((opcode_flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2))
1366 && opindex_ptr[0] != '\0'
1367 && opindex_ptr[1] == '\0')
1368 return true;
1370 if ((opcode_flags & S390_INSTR_FLAG_OPTPARM2)
1371 && opindex_ptr[0] != '\0'
1372 && opindex_ptr[1] != '\0'
1373 && opindex_ptr[2] == '\0')
1374 return true;
1375 return false;
1378 /* We need to keep a list of fixups. We can't simply generate them as
1379 we go, because that would require us to first create the frag, and
1380 that would screw up references to ``.''. */
1382 struct s390_fixup
1384 expressionS exp;
1385 int opindex;
1386 bfd_reloc_code_real_type reloc;
1389 #define MAX_INSN_FIXUPS (4)
1391 /* This routine is called for each instruction to be assembled. */
1393 static char *
1394 md_gather_operands (char *str,
1395 unsigned char *insn,
1396 const struct s390_opcode *opcode)
1398 struct s390_fixup fixups[MAX_INSN_FIXUPS];
1399 const struct s390_operand *operand;
1400 const unsigned char *opindex_ptr;
1401 expressionS ex;
1402 elf_suffix_type suffix;
1403 bfd_reloc_code_real_type reloc;
1404 int omitted_base_or_index;
1405 int operand_number;
1406 char *f;
1407 int fc, i;
1409 while (ISSPACE (*str))
1410 str++;
1412 /* Gather the operands. */
1413 omitted_base_or_index = 0; /* Whether B in D(L,B) or X in D(X,B) were omitted. */
1414 operand_number = 1; /* Current operand number in e.g. R1,I2,M3,D4(B4). */
1415 fc = 0;
1416 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1418 char *hold;
1420 operand = s390_operands + *opindex_ptr;
1422 if ((opcode->flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2))
1423 && *str == '\0')
1425 /* Optional parameters might need to be ORed with a
1426 value so calling s390_insert_operand is needed. */
1427 s390_insert_operand (insn, operand, 0, NULL, 0, operand_number);
1428 break;
1431 if (omitted_base_or_index && (operand->flags & S390_OPERAND_INDEX))
1433 /* Skip omitted optional index register operand in D(X,B) due to
1434 D(,B) or D(B). Skip comma, if D(,B). */
1435 if (*str == ',')
1436 str++;
1437 omitted_base_or_index = 0;
1438 continue;
1441 /* Gather the operand. */
1442 hold = input_line_pointer;
1443 input_line_pointer = str;
1445 /* Parse the operand. */
1446 if (! register_name (&ex))
1448 expression (&ex);
1449 resolve_register (&ex);
1452 str = input_line_pointer;
1453 input_line_pointer = hold;
1455 /* Write the operand to the insn. */
1456 if (ex.X_op == O_illegal)
1457 as_bad (_("operand %d: illegal operand"), operand_number);
1458 else if (ex.X_op == O_absent)
1460 if (opindex_ptr[0] == '\0')
1461 break;
1462 as_bad (_("operand %d: missing %s operand"), operand_number,
1463 operand_type_str(operand));
1465 else if (ex.X_op == O_register || ex.X_op == O_constant)
1467 s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
1469 if (ex.X_op != O_register && ex.X_op != O_constant)
1471 /* We need to generate a fixup for the
1472 expression returned by s390_lit_suffix. */
1473 if (fc >= MAX_INSN_FIXUPS)
1474 as_fatal (_("operand %d: too many fixups"), operand_number);
1475 fixups[fc].exp = ex;
1476 fixups[fc].opindex = *opindex_ptr;
1477 fixups[fc].reloc = BFD_RELOC_UNUSED;
1478 ++fc;
1480 else
1482 if ((operand->flags & S390_OPERAND_LENGTH)
1483 && ex.X_op != O_constant)
1484 as_bad (_("operand %d: invalid length field specified"),
1485 operand_number);
1486 if ((operand->flags & S390_OPERAND_INDEX)
1487 && ex.X_add_number == 0
1488 && warn_areg_zero)
1489 as_warn (_("operand %d: index register specified but zero"),
1490 operand_number);
1491 if ((operand->flags & S390_OPERAND_BASE)
1492 && ex.X_add_number == 0
1493 && warn_areg_zero)
1494 as_warn (_("operand %d: base register specified but zero"),
1495 operand_number);
1496 if ((operand->flags & S390_OPERAND_GPR)
1497 && (operand->flags & S390_OPERAND_REG_PAIR)
1498 && (ex.X_add_number & 1))
1499 as_bad (_("operand %d: odd numbered general purpose register "
1500 "specified as register pair"), operand_number);
1501 if ((operand->flags & S390_OPERAND_FPR)
1502 && (operand->flags & S390_OPERAND_REG_PAIR)
1503 && ex.X_add_number != 0 && ex.X_add_number != 1
1504 && ex.X_add_number != 4 && ex.X_add_number != 5
1505 && ex.X_add_number != 8 && ex.X_add_number != 9
1506 && ex.X_add_number != 12 && ex.X_add_number != 13)
1507 as_bad (_("operand %d: invalid floating-point register (FPR) "
1508 "pair (valid FPR pair operands are 0, 1, 4, 5, 8, 9, "
1509 "12 or 13)"), operand_number);
1510 if (warn_regtype_mismatch && ex.X_op == O_register
1511 && !(opcode->flags & S390_INSTR_FLAG_PSEUDO_MNEMONIC))
1513 const char *expected_regtype = NULL;
1515 if ((operand->flags & S390_OPERAND_AR)
1516 && ex.X_md != S390_REGTYPE_AR)
1517 expected_regtype = _("access register");
1518 else if ((operand->flags & S390_OPERAND_CR)
1519 && ex.X_md != S390_REGTYPE_CR)
1520 expected_regtype = _("control register");
1521 else if ((operand->flags & S390_OPERAND_FPR)
1522 && ex.X_md != S390_REGTYPE_FPR
1523 && (warn_regtype_mismatch == S390_REGTYPE_CHECK_STRICT
1524 || (ex.X_md != S390_REGTYPE_VR)))
1525 expected_regtype = _("floating-point register");
1526 else if ((operand->flags & S390_OPERAND_GPR)
1527 && ex.X_md != S390_REGTYPE_GR)
1528 expected_regtype = _("general register");
1529 else if ((operand->flags & S390_OPERAND_VR)
1530 && ex.X_md != S390_REGTYPE_VR
1531 && (warn_regtype_mismatch == S390_REGTYPE_CHECK_STRICT
1532 || (ex.X_md != S390_REGTYPE_FPR)))
1533 expected_regtype = _("vector register");
1535 if (expected_regtype)
1537 if (operand->flags & S390_OPERAND_BASE)
1538 as_warn (_("operand %d: expected %s name as base register"),
1539 operand_number, expected_regtype);
1540 else if (operand->flags & S390_OPERAND_INDEX)
1541 as_warn (_("operand %d: expected %s name as index register"),
1542 operand_number, expected_regtype);
1543 else
1544 as_warn (_("operand %d: expected %s name"),
1545 operand_number, expected_regtype);
1548 s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0, operand_number);
1551 else
1553 suffix = s390_elf_suffix (&str, &ex);
1554 suffix = s390_lit_suffix (&str, &ex, suffix);
1555 reloc = BFD_RELOC_UNUSED;
1557 if (suffix == ELF_SUFFIX_GOT)
1559 if ((operand->flags & S390_OPERAND_DISP) &&
1560 (operand->bits == 12))
1561 reloc = BFD_RELOC_390_GOT12;
1562 else if ((operand->flags & S390_OPERAND_DISP) &&
1563 (operand->bits == 20))
1564 reloc = BFD_RELOC_390_GOT20;
1565 else if ((operand->flags & S390_OPERAND_SIGNED)
1566 && (operand->bits == 16))
1567 reloc = BFD_RELOC_390_GOT16;
1568 else if ((operand->flags & S390_OPERAND_PCREL)
1569 && (operand->bits == 32))
1570 reloc = BFD_RELOC_390_GOTENT;
1572 else if (suffix == ELF_SUFFIX_PLT)
1574 if ((operand->flags & S390_OPERAND_PCREL)
1575 && (operand->bits == 12))
1576 reloc = BFD_RELOC_390_PLT12DBL;
1577 else if ((operand->flags & S390_OPERAND_PCREL)
1578 && (operand->bits == 16))
1579 reloc = BFD_RELOC_390_PLT16DBL;
1580 else if ((operand->flags & S390_OPERAND_PCREL)
1581 && (operand->bits == 24))
1582 reloc = BFD_RELOC_390_PLT24DBL;
1583 else if ((operand->flags & S390_OPERAND_PCREL)
1584 && (operand->bits == 32))
1585 reloc = BFD_RELOC_390_PLT32DBL;
1587 else if (suffix == ELF_SUFFIX_GOTENT)
1589 if ((operand->flags & S390_OPERAND_PCREL)
1590 && (operand->bits == 32))
1591 reloc = BFD_RELOC_390_GOTENT;
1593 else if (suffix == ELF_SUFFIX_GOTOFF)
1595 if ((operand->flags & S390_OPERAND_SIGNED)
1596 && (operand->bits == 16))
1597 reloc = BFD_RELOC_16_GOTOFF;
1599 else if (suffix == ELF_SUFFIX_PLTOFF)
1601 if ((operand->flags & S390_OPERAND_SIGNED)
1602 && (operand->bits == 16))
1603 reloc = BFD_RELOC_390_PLTOFF16;
1605 else if (suffix == ELF_SUFFIX_GOTPLT)
1607 if ((operand->flags & S390_OPERAND_DISP)
1608 && (operand->bits == 12))
1609 reloc = BFD_RELOC_390_GOTPLT12;
1610 else if ((operand->flags & S390_OPERAND_SIGNED)
1611 && (operand->bits == 16))
1612 reloc = BFD_RELOC_390_GOTPLT16;
1613 else if ((operand->flags & S390_OPERAND_PCREL)
1614 && (operand->bits == 32))
1615 reloc = BFD_RELOC_390_GOTPLTENT;
1617 else if (suffix == ELF_SUFFIX_TLS_GOTIE)
1619 if ((operand->flags & S390_OPERAND_DISP)
1620 && (operand->bits == 12))
1621 reloc = BFD_RELOC_390_TLS_GOTIE12;
1622 else if ((operand->flags & S390_OPERAND_DISP)
1623 && (operand->bits == 20))
1624 reloc = BFD_RELOC_390_TLS_GOTIE20;
1626 else if (suffix == ELF_SUFFIX_TLS_IE)
1628 if ((operand->flags & S390_OPERAND_PCREL)
1629 && (operand->bits == 32))
1630 reloc = BFD_RELOC_390_TLS_IEENT;
1633 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1634 as_bad (_("operand %d: invalid operand suffix"), operand_number);
1635 /* We need to generate a fixup of type 'reloc' for this
1636 expression. */
1637 if (fc >= MAX_INSN_FIXUPS)
1638 as_fatal (_("operand %d: too many fixups"), operand_number);
1639 fixups[fc].exp = ex;
1640 fixups[fc].opindex = *opindex_ptr;
1641 fixups[fc].reloc = reloc;
1642 ++fc;
1645 /* Check the next character. The call to expression has advanced
1646 str past any whitespace. */
1647 if (operand->flags & S390_OPERAND_DISP)
1649 /* After a displacement a block in parentheses can start. */
1650 if (*str != '(')
1652 /* There is no opening parentheses. Check if operands of
1653 parenthesized block can be skipped. Only index and base
1654 register operands as well as optional operands may be
1655 skipped. A length operand may not be skipped. */
1656 operand = s390_operands + *(++opindex_ptr);
1657 if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
1658 as_bad (_("operand %d: syntax error; missing '(' after displacement"),
1659 operand_number);
1661 /* Ok, skip all operands until S390_OPERAND_BASE. */
1662 while (!(operand->flags & S390_OPERAND_BASE))
1663 operand = s390_operands + *(++opindex_ptr);
1665 /* If there is no further input and the remaining operands are
1666 optional then have these optional operands processed. */
1667 if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1]))
1668 continue;
1670 /* If there is a next operand it must be separated by a comma. */
1671 if (opindex_ptr[1] != '\0')
1673 if (*str != ',')
1675 /* There is no comma. Skip all operands and stop. */
1676 while (opindex_ptr[1] != '\0')
1678 operand = s390_operands + *(++opindex_ptr);
1679 as_bad (_("operand %d: syntax error; expected ','"),
1680 operand_number);
1681 break;
1684 else
1686 /* Comma. */
1687 str++;
1688 operand_number++;
1692 else
1694 /* We found an opening parentheses. */
1695 str++;
1696 for (f = str; *f != '\0'; f++)
1697 if (*f == ',' || *f == ')')
1698 break;
1699 /* If there is no comma until the closing parenthesis ')' or
1700 there is a comma right after the opening parenthesis '(',
1701 we have to skip the omitted optional index or base register
1702 operand:
1703 - Index X in D(X,B), when D(,B) or D(B)
1704 - Base B in D(L,B), when D(L) */
1705 if (*f == ',' && f == str)
1707 /* Comma directly after opening parenthesis '(' ? */
1708 omitted_base_or_index = 1;
1710 else
1711 omitted_base_or_index = (*f != ',');
1714 else if (operand->flags & S390_OPERAND_BASE)
1716 /* After the base register the parenthesised block ends. */
1717 if (*str != ')')
1718 as_bad (_("operand %d: syntax error; missing ')' after base register"),
1719 operand_number);
1720 else
1721 str++;
1722 omitted_base_or_index = 0;
1724 /* If there is no further input and the remaining operands are
1725 optional then have these optional operands processed. */
1726 if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1]))
1727 continue;
1729 /* If there is a next operand it must be separated by a comma. */
1730 if (opindex_ptr[1] != '\0')
1732 if (*str != ',')
1734 /* There is no comma. Skip all operands and stop. */
1735 while (opindex_ptr[1] != '\0')
1737 operand = s390_operands + *(++opindex_ptr);
1738 as_bad (_("operand %d: syntax error; expected ','"),
1739 operand_number);
1740 break;
1743 else
1745 /* Comma. */
1746 str++;
1747 operand_number++;
1751 else
1753 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1754 of D(L,B). In this case the base register has to be skipped.
1755 Same if the base register has been explicilty omitted in e.g.
1756 D(X,) or D(L,). */
1757 if (*str == ')' || (str[0] == ',' && str[1] == ')'))
1759 operand = s390_operands + *(++opindex_ptr);
1761 if (!(operand->flags & S390_OPERAND_BASE))
1762 as_bad (_("operand %d: syntax error; '%c' not allowed here"),
1763 operand_number, *str);
1764 if (*str == ',')
1765 str++;
1766 str++;
1769 /* If there is no further input and the remaining operands are
1770 optional then have these optional operands processed. */
1771 if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1]))
1772 continue;
1774 /* If there is a next operand it must be separated by a comma. */
1775 if (opindex_ptr[1] != '\0')
1777 if (*str != ',')
1779 /* There is no comma. Skip all operands and stop. */
1780 while (opindex_ptr[1] != '\0')
1782 operand = s390_operands + *(++opindex_ptr);
1783 as_bad (_("operand %d: syntax error; expected ','"),
1784 operand_number);
1785 break;
1788 else
1790 /* Comma. */
1791 str++;
1792 if (!(operand->flags & (S390_OPERAND_INDEX
1793 | S390_OPERAND_LENGTH)))
1794 operand_number++;
1800 while (ISSPACE (*str))
1801 str++;
1803 /* Check for tls instruction marker. */
1804 reloc = s390_tls_suffix (&str, &ex);
1805 if (reloc != BFD_RELOC_UNUSED)
1807 /* We need to generate a fixup of type 'reloc' for this
1808 instruction. */
1809 if (fc >= MAX_INSN_FIXUPS)
1810 as_fatal (_("too many fixups"));
1811 fixups[fc].exp = ex;
1812 fixups[fc].opindex = -1;
1813 fixups[fc].reloc = reloc;
1814 ++fc;
1817 if (*str != '\0')
1819 char *linefeed;
1821 if ((linefeed = strchr (str, '\n')) != NULL)
1822 *linefeed = '\0';
1823 as_bad (_("junk at end of line: `%s'"), str);
1824 if (linefeed != NULL)
1825 *linefeed = '\n';
1828 /* Write out the instruction. */
1829 f = frag_more (opcode->oplen);
1830 memcpy (f, insn, opcode->oplen);
1831 dwarf2_emit_insn (opcode->oplen);
1833 /* Create any fixups. At this point we do not use a
1834 bfd_reloc_code_real_type, but instead just use the
1835 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1836 handle fixups for any operand type, although that is admittedly
1837 not a very exciting feature. We pick a BFD reloc type in
1838 md_apply_fix. */
1839 for (i = 0; i < fc; i++)
1841 fixS *fixP;
1843 if (fixups[i].opindex < 0)
1845 /* Create tls instruction marker relocation. */
1846 fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen,
1847 &fixups[i].exp, 0, fixups[i].reloc);
1848 continue;
1851 operand = s390_operands + fixups[i].opindex;
1853 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1855 reloc_howto_type *reloc_howto;
1856 int size;
1858 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1859 if (!reloc_howto)
1860 abort ();
1862 size = ((reloc_howto->bitsize - 1) / 8) + 1;
1864 if (size < 1 || size > 4)
1865 abort ();
1867 fixP = fix_new_exp (frag_now,
1868 f - frag_now->fr_literal + (operand->shift/8),
1869 size, &fixups[i].exp, reloc_howto->pc_relative,
1870 fixups[i].reloc);
1871 /* Turn off overflow checking in fixup_segment. This is necessary
1872 because fixup_segment will signal an overflow for large 4 byte
1873 quantities for GOT12 relocations. */
1874 if ( fixups[i].reloc == BFD_RELOC_390_GOT12
1875 || fixups[i].reloc == BFD_RELOC_390_GOT20
1876 || fixups[i].reloc == BFD_RELOC_390_GOT16)
1877 fixP->fx_no_overflow = 1;
1879 if (operand->flags & S390_OPERAND_PCREL)
1880 fixP->fx_pcrel_adjust = operand->shift / 8;
1882 else
1883 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1884 &fixups[i].exp,
1885 (operand->flags & S390_OPERAND_PCREL) != 0,
1886 ((bfd_reloc_code_real_type)
1887 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1888 /* s390_insert_operand () does the range checking. */
1889 if (operand->flags & S390_OPERAND_PCREL)
1890 fixP->fx_no_overflow = 1;
1892 return str;
1895 /* This routine is called for each instruction to be assembled. */
1897 void
1898 md_assemble (char *str)
1900 const struct s390_opcode *opcode;
1901 unsigned char insn[6];
1902 char *s;
1904 /* Get the opcode. */
1905 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1907 if (*s != '\0')
1908 *s++ = '\0';
1910 /* Look up the opcode in the hash table. */
1911 opcode = (struct s390_opcode *) str_hash_find (s390_opcode_hash, str);
1912 if (opcode == (const struct s390_opcode *) NULL)
1914 as_bad (_("Unrecognized opcode: `%s'"), str);
1915 return;
1917 else if (!(opcode->modes & current_mode_mask))
1919 as_bad (_("Opcode %s not available in this mode"), str);
1920 return;
1922 memcpy (insn, opcode->opcode, sizeof (insn));
1923 md_gather_operands (s, insn, opcode);
1926 #ifndef WORKING_DOT_WORD
1927 /* Handle long and short jumps. We don't support these */
1928 void
1929 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1930 char *ptr;
1931 addressT from_addr, to_addr;
1932 fragS *frag;
1933 symbolS *to_symbol;
1935 abort ();
1938 void
1939 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1940 char *ptr;
1941 addressT from_addr, to_addr;
1942 fragS *frag;
1943 symbolS *to_symbol;
1945 abort ();
1947 #endif
1949 /* Pseudo-op handling. */
1951 void
1952 s390_insn (int ignore ATTRIBUTE_UNUSED)
1954 expressionS exp;
1955 const struct s390_opcode *opformat;
1956 unsigned char insn[6];
1957 char *s;
1959 /* Get the opcode format. */
1960 s = input_line_pointer;
1961 while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
1962 s++;
1963 if (*s != ',')
1964 as_bad (_("Invalid .insn format\n"));
1965 *s++ = '\0';
1967 /* Look up the opcode in the hash table. */
1968 opformat = (struct s390_opcode *)
1969 str_hash_find (s390_opformat_hash, input_line_pointer);
1970 if (opformat == (const struct s390_opcode *) NULL)
1972 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
1973 return;
1975 input_line_pointer = s;
1976 expression (&exp);
1977 if (exp.X_op == O_constant)
1979 if ( ( opformat->oplen == 6
1980 && (addressT) exp.X_add_number < (1ULL << 48))
1981 || ( opformat->oplen == 4
1982 && (addressT) exp.X_add_number < (1ULL << 32))
1983 || ( opformat->oplen == 2
1984 && (addressT) exp.X_add_number < (1ULL << 16)))
1985 md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen);
1986 else
1987 as_bad (_("Invalid .insn format\n"));
1989 else if (exp.X_op == O_big)
1991 if (exp.X_add_number > 0
1992 && opformat->oplen == 6
1993 && generic_bignum[3] == 0)
1995 md_number_to_chars ((char *) insn, generic_bignum[2], 2);
1996 md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2);
1997 md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2);
1999 else
2000 as_bad (_("Invalid .insn format\n"));
2002 else
2003 as_bad (_("second operand of .insn not a constant\n"));
2005 if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
2006 as_bad (_("missing comma after insn constant\n"));
2008 if ((s = strchr (input_line_pointer, '\n')) != NULL)
2009 *s = '\0';
2010 input_line_pointer = md_gather_operands (input_line_pointer, insn,
2011 opformat);
2012 if (s != NULL)
2013 *s = '\n';
2014 demand_empty_rest_of_line ();
2017 /* The .byte pseudo-op. This is similar to the normal .byte
2018 pseudo-op, but it can also take a single ASCII string. */
2020 static void
2021 s390_byte (int ignore ATTRIBUTE_UNUSED)
2023 if (*input_line_pointer != '\"')
2025 cons (1);
2026 return;
2029 /* Gather characters. A real double quote is doubled. Unusual
2030 characters are not permitted. */
2031 ++input_line_pointer;
2032 while (1)
2034 char c;
2036 c = *input_line_pointer++;
2038 if (c == '\"')
2040 if (*input_line_pointer != '\"')
2041 break;
2042 ++input_line_pointer;
2045 FRAG_APPEND_1_CHAR (c);
2048 demand_empty_rest_of_line ();
2051 /* The .ltorg pseudo-op.This emits all literals defined since the last
2052 .ltorg or the invocation of gas. Literals are defined with the
2053 @lit suffix. */
2055 static void
2056 s390_literals (int ignore ATTRIBUTE_UNUSED)
2058 struct s390_lpe *lpe;
2060 if (lp_sym == NULL || lpe_count == 0)
2061 return; /* Nothing to be done. */
2063 /* Emit symbol for start of literal pool. */
2064 S_SET_SEGMENT (lp_sym, now_seg);
2065 S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
2066 symbol_set_frag (lp_sym, frag_now);
2068 while (lpe_list)
2070 lpe = lpe_list;
2071 lpe_list = lpe_list->next;
2072 S_SET_SEGMENT (lpe->sym, now_seg);
2073 S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
2074 symbol_set_frag (lpe->sym, frag_now);
2076 /* Emit literal pool entry. */
2077 if (lpe->reloc != BFD_RELOC_UNUSED)
2079 reloc_howto_type *reloc_howto =
2080 bfd_reloc_type_lookup (stdoutput, lpe->reloc);
2081 int size = bfd_get_reloc_size (reloc_howto);
2082 char *where;
2084 if (size > lpe->nbytes)
2085 as_bad (ngettext ("%s relocations do not fit in %d byte",
2086 "%s relocations do not fit in %d bytes",
2087 lpe->nbytes),
2088 reloc_howto->name, lpe->nbytes);
2089 where = frag_more (lpe->nbytes);
2090 md_number_to_chars (where, 0, size);
2091 fix_new_exp (frag_now, where - frag_now->fr_literal,
2092 size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
2094 else
2096 if (lpe->ex.X_op == O_big)
2098 if (lpe->ex.X_add_number <= 0)
2099 generic_floating_point_number = lpe->floatnum;
2100 else
2101 memcpy (generic_bignum, lpe->bignum,
2102 lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
2104 emit_expr (&lpe->ex, lpe->nbytes);
2107 lpe->next = lpe_free_list;
2108 lpe_free_list = lpe;
2110 lpe_list_tail = NULL;
2111 lp_sym = NULL;
2112 lp_count++;
2113 lpe_count = 0;
2116 #define MAX_HISTORY 100
2118 /* The .machine pseudo op allows one to switch to a different CPU level in
2119 the asm listing. The current CPU setting can be stored on a stack
2120 with .machine push and restored with .machine pop. */
2122 static void
2123 s390_machine (int ignore ATTRIBUTE_UNUSED)
2125 char *cpu_string;
2126 static struct cpu_history
2128 unsigned int cpu;
2129 unsigned int flags;
2130 } *cpu_history;
2131 static int curr_hist;
2133 SKIP_WHITESPACE ();
2135 if (*input_line_pointer == '"')
2137 int len;
2138 cpu_string = demand_copy_C_string (&len);
2140 else
2142 char c;
2144 cpu_string = input_line_pointer;
2147 char * str;
2149 c = get_symbol_name (&str);
2150 c = restore_line_pointer (c);
2151 if (c == '+')
2152 ++ input_line_pointer;
2154 while (c == '+');
2156 c = *input_line_pointer;
2157 *input_line_pointer = 0;
2158 cpu_string = xstrdup (cpu_string);
2159 (void) restore_line_pointer (c);
2162 if (cpu_string != NULL)
2164 unsigned int new_cpu = current_cpu;
2165 unsigned int new_flags = current_flags;
2167 if (strcmp (cpu_string, "push") == 0)
2169 if (cpu_history == NULL)
2170 cpu_history = XNEWVEC (struct cpu_history, MAX_HISTORY);
2172 if (curr_hist >= MAX_HISTORY)
2173 as_bad (_(".machine stack overflow"));
2174 else
2176 cpu_history[curr_hist].cpu = current_cpu;
2177 cpu_history[curr_hist].flags = current_flags;
2178 curr_hist++;
2181 else if (strcmp (cpu_string, "pop") == 0)
2183 if (curr_hist <= 0)
2184 as_bad (_(".machine stack underflow"));
2185 else
2187 curr_hist--;
2188 new_cpu = cpu_history[curr_hist].cpu;
2189 new_flags = cpu_history[curr_hist].flags;
2192 else
2193 new_cpu = s390_parse_cpu (cpu_string, &new_flags, true);
2195 if (new_cpu == S390_OPCODE_MAXCPU)
2196 as_bad (_("invalid machine `%s'"), cpu_string);
2198 if (new_cpu != current_cpu || new_flags != current_flags)
2200 current_cpu = new_cpu;
2201 current_flags = new_flags;
2202 s390_setup_opcodes ();
2206 demand_empty_rest_of_line ();
2209 /* The .machinemode pseudo op allows one to switch to a different
2210 architecture mode in the asm listing. The current architecture
2211 mode setting can be stored on a stack with .machinemode push and
2212 restored with .machinemode pop. */
2214 static void
2215 s390_machinemode (int ignore ATTRIBUTE_UNUSED)
2217 char *mode_string;
2218 static unsigned int *mode_history;
2219 static int curr_hist;
2221 SKIP_WHITESPACE ();
2224 char c;
2226 c = get_symbol_name (&mode_string);
2227 mode_string = xstrdup (mode_string);
2228 (void) restore_line_pointer (c);
2231 if (mode_string != NULL)
2233 unsigned int old_mode_mask = current_mode_mask;
2234 char *p;
2236 for (p = mode_string; *p != 0; p++)
2237 *p = TOLOWER (*p);
2239 if (strcmp (mode_string, "push") == 0)
2241 if (mode_history == NULL)
2242 mode_history = XNEWVEC (unsigned int, MAX_HISTORY);
2244 if (curr_hist >= MAX_HISTORY)
2245 as_bad (_(".machinemode stack overflow"));
2246 else
2247 mode_history[curr_hist++] = current_mode_mask;
2249 else if (strcmp (mode_string, "pop") == 0)
2251 if (curr_hist <= 0)
2252 as_bad (_(".machinemode stack underflow"));
2253 else
2254 current_mode_mask = mode_history[--curr_hist];
2256 else
2258 if (strcmp (mode_string, "esa") == 0)
2259 current_mode_mask = 1 << S390_OPCODE_ESA;
2260 else if (strcmp (mode_string, "zarch") == 0)
2262 if (s390_arch_size == 32)
2263 set_highgprs_p = true;
2264 current_mode_mask = 1 << S390_OPCODE_ZARCH;
2266 else if (strcmp (mode_string, "zarch_nohighgprs") == 0)
2267 current_mode_mask = 1 << S390_OPCODE_ZARCH;
2268 else
2269 as_bad (_("invalid machine mode `%s'"), mode_string);
2272 if (current_mode_mask != old_mode_mask)
2273 s390_setup_opcodes ();
2276 demand_empty_rest_of_line ();
2279 #undef MAX_HISTORY
2281 const char *
2282 md_atof (int type, char *litp, int *sizep)
2284 return ieee_md_atof (type, litp, sizep, true);
2287 /* Align a section (I don't know why this is machine dependent). */
2289 valueT
2290 md_section_align (asection *seg, valueT addr)
2292 int align = bfd_section_alignment (seg);
2294 return ((addr + (1 << align) - 1) & -(1 << align));
2297 /* We don't have any form of relaxing. */
2300 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
2301 asection *seg ATTRIBUTE_UNUSED)
2303 abort ();
2304 return 0;
2307 /* Convert a machine dependent frag. We never generate these. */
2309 void
2310 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
2311 asection *sec ATTRIBUTE_UNUSED,
2312 fragS *fragp ATTRIBUTE_UNUSED)
2314 abort ();
2317 symbolS *
2318 md_undefined_symbol (char *name)
2320 if (*name == '_' && *(name + 1) == 'G'
2321 && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
2323 if (!GOT_symbol)
2325 if (symbol_find (name))
2326 as_bad (_("GOT already in symbol table"));
2327 GOT_symbol = symbol_new (name, undefined_section,
2328 &zero_address_frag, 0);
2330 return GOT_symbol;
2332 return 0;
2335 /* Functions concerning relocs. */
2337 /* The location from which a PC relative jump should be calculated,
2338 given a PC relative reloc. */
2340 long
2341 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
2343 return fixp->fx_frag->fr_address + fixp->fx_where;
2346 /* Here we decide which fixups can be adjusted to make them relative to
2347 the beginning of the section instead of the symbol. Basically we need
2348 to make sure that the dynamic relocations are done correctly, so in
2349 some cases we force the original symbol to be used. */
2351 tc_s390_fix_adjustable (fixS *fixP)
2353 /* Don't adjust pc-relative references to merge sections. */
2354 if (fixP->fx_pcrel
2355 && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0)
2356 return 0;
2358 /* adjust_reloc_syms doesn't know about the GOT. */
2359 if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF
2360 || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
2361 || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64
2362 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16
2363 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32
2364 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64
2365 || fixP->fx_r_type == BFD_RELOC_390_PLT12DBL
2366 || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
2367 || fixP->fx_r_type == BFD_RELOC_390_PLT24DBL
2368 || fixP->fx_r_type == BFD_RELOC_390_PLT32
2369 || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
2370 || fixP->fx_r_type == BFD_RELOC_390_PLT64
2371 || fixP->fx_r_type == BFD_RELOC_390_GOT12
2372 || fixP->fx_r_type == BFD_RELOC_390_GOT20
2373 || fixP->fx_r_type == BFD_RELOC_390_GOT16
2374 || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
2375 || fixP->fx_r_type == BFD_RELOC_390_GOT64
2376 || fixP->fx_r_type == BFD_RELOC_390_GOTENT
2377 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
2378 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16
2379 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20
2380 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32
2381 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64
2382 || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT
2383 || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD
2384 || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL
2385 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL
2386 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32
2387 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64
2388 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12
2389 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20
2390 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32
2391 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64
2392 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32
2393 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64
2394 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32
2395 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64
2396 || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT
2397 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32
2398 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64
2399 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32
2400 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64
2401 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD
2402 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF
2403 || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF
2404 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2405 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2406 return 0;
2407 return 1;
2410 /* Return true if we must always emit a reloc for a type and false if
2411 there is some hope of resolving it at assembly time. */
2413 tc_s390_force_relocation (struct fix *fixp)
2415 /* Ensure we emit a relocation for every reference to the global
2416 offset table or to the procedure link table. */
2417 switch (fixp->fx_r_type)
2419 case BFD_RELOC_390_GOT12:
2420 case BFD_RELOC_390_GOT20:
2421 case BFD_RELOC_32_GOT_PCREL:
2422 case BFD_RELOC_32_GOTOFF:
2423 case BFD_RELOC_390_GOTOFF64:
2424 case BFD_RELOC_390_PLTOFF16:
2425 case BFD_RELOC_390_PLTOFF32:
2426 case BFD_RELOC_390_PLTOFF64:
2427 case BFD_RELOC_390_GOTPC:
2428 case BFD_RELOC_390_GOT16:
2429 case BFD_RELOC_390_GOTPCDBL:
2430 case BFD_RELOC_390_GOT64:
2431 case BFD_RELOC_390_GOTENT:
2432 case BFD_RELOC_390_PLT32:
2433 case BFD_RELOC_390_PLT12DBL:
2434 case BFD_RELOC_390_PLT16DBL:
2435 case BFD_RELOC_390_PLT24DBL:
2436 case BFD_RELOC_390_PLT32DBL:
2437 case BFD_RELOC_390_PLT64:
2438 case BFD_RELOC_390_GOTPLT12:
2439 case BFD_RELOC_390_GOTPLT16:
2440 case BFD_RELOC_390_GOTPLT20:
2441 case BFD_RELOC_390_GOTPLT32:
2442 case BFD_RELOC_390_GOTPLT64:
2443 case BFD_RELOC_390_GOTPLTENT:
2444 return 1;
2445 default:
2446 break;
2449 return generic_force_reloc (fixp);
2452 /* Apply a fixup to the object code. This is called for all the
2453 fixups we generated by the call to fix_new_exp, above. In the call
2454 above we used a reloc code which was the largest legal reloc code
2455 plus the operand index. Here we undo that to recover the operand
2456 index. At this point all symbol values should be fully resolved,
2457 and we attempt to completely resolve the reloc. If we can not do
2458 that, we determine the correct reloc code and put it back in the
2459 fixup. */
2461 void
2462 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
2464 char *where;
2465 valueT value = *valP;
2467 where = fixP->fx_frag->fr_literal + fixP->fx_where;
2469 if (fixP->fx_subsy != NULL)
2470 as_bad_subtract (fixP);
2472 if (fixP->fx_addsy != NULL)
2474 if (fixP->fx_pcrel)
2475 value += fixP->fx_frag->fr_address + fixP->fx_where;
2477 else
2478 fixP->fx_done = 1;
2480 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
2482 const struct s390_operand *operand;
2483 int opindex;
2485 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
2486 operand = &s390_operands[opindex];
2488 if (fixP->fx_done)
2490 /* Insert the fully resolved operand value. */
2491 s390_insert_operand ((unsigned char *) where, operand,
2492 (offsetT) value, fixP->fx_file, fixP->fx_line, 0);
2493 return;
2496 /* Determine a BFD reloc value based on the operand information.
2497 We are only prepared to turn a few of the operands into
2498 relocs. */
2499 fixP->fx_offset = value;
2500 if (operand->bits == 12 && operand->shift == 20 && !fixP->fx_pcrel)
2502 fixP->fx_size = 2;
2503 fixP->fx_where += 2;
2504 fixP->fx_r_type = BFD_RELOC_390_12;
2506 else if (operand->bits == 12 && operand->shift == 36 && !fixP->fx_pcrel)
2508 fixP->fx_size = 2;
2509 fixP->fx_where += 4;
2510 fixP->fx_r_type = BFD_RELOC_390_12;
2512 else if (operand->bits == 20 && operand->shift == 20 && !fixP->fx_pcrel)
2514 fixP->fx_size = 4;
2515 fixP->fx_where += 2;
2516 fixP->fx_r_type = BFD_RELOC_390_20;
2518 else if (operand->bits == 8 && operand->shift == 8 && !fixP->fx_pcrel)
2520 fixP->fx_size = 1;
2521 fixP->fx_where += 1;
2522 fixP->fx_r_type = BFD_RELOC_8;
2524 else if (operand->bits == 12 && operand->shift == 12
2525 && (operand->flags & S390_OPERAND_PCREL))
2527 fixP->fx_size = 2;
2528 fixP->fx_where += 1;
2529 fixP->fx_offset += 1;
2530 fixP->fx_pcrel_adjust = 1;
2531 fixP->fx_r_type = BFD_RELOC_390_PC12DBL;
2533 else if (operand->bits == 16 && operand->shift == 16)
2535 fixP->fx_size = 2;
2536 fixP->fx_where += 2;
2537 if (operand->flags & S390_OPERAND_PCREL)
2539 fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2540 fixP->fx_offset += 2;
2541 fixP->fx_pcrel_adjust = 2;
2543 else if (fixP->fx_pcrel)
2545 fixP->fx_r_type = BFD_RELOC_16_PCREL;
2546 fixP->fx_offset += 2;
2547 fixP->fx_pcrel_adjust = 2;
2549 else
2550 fixP->fx_r_type = BFD_RELOC_16;
2552 else if (operand->bits == 16 && operand->shift == 32
2553 && (operand->flags & S390_OPERAND_PCREL))
2555 fixP->fx_size = 2;
2556 fixP->fx_where += 4;
2557 fixP->fx_offset += 4;
2558 fixP->fx_pcrel_adjust = 4;
2559 fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2561 else if (operand->bits == 24 && operand->shift == 24
2562 && (operand->flags & S390_OPERAND_PCREL))
2564 fixP->fx_size = 3;
2565 fixP->fx_where += 3;
2566 fixP->fx_offset += 3;
2567 fixP->fx_pcrel_adjust = 3;
2568 fixP->fx_r_type = BFD_RELOC_390_PC24DBL;
2570 else if (operand->bits == 32 && operand->shift == 16
2571 && (operand->flags & S390_OPERAND_PCREL))
2573 fixP->fx_size = 4;
2574 fixP->fx_where += 2;
2575 fixP->fx_offset += 2;
2576 fixP->fx_pcrel_adjust = 2;
2577 fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
2579 else
2581 const char *sfile;
2582 unsigned int sline;
2584 /* Use expr_symbol_where to see if this is an expression
2585 symbol. */
2586 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
2587 as_bad_where (fixP->fx_file, fixP->fx_line,
2588 _("unresolved expression that must be resolved"));
2589 else
2590 as_bad_where (fixP->fx_file, fixP->fx_line,
2591 _("unsupported relocation type"));
2592 fixP->fx_done = 1;
2593 return;
2596 else
2598 switch (fixP->fx_r_type)
2600 case BFD_RELOC_8:
2601 if (fixP->fx_pcrel)
2602 abort ();
2603 if (fixP->fx_done)
2604 md_number_to_chars (where, value, 1);
2605 break;
2606 case BFD_RELOC_390_12:
2607 case BFD_RELOC_390_GOT12:
2608 case BFD_RELOC_390_GOTPLT12:
2609 case BFD_RELOC_390_PC12DBL:
2610 case BFD_RELOC_390_PLT12DBL:
2611 if (fixP->fx_pcrel)
2612 value += fixP->fx_pcrel_adjust;
2614 if (fixP->fx_done)
2616 unsigned short mop;
2618 if (fixP->fx_pcrel)
2619 value >>= 1;
2621 mop = bfd_getb16 ((unsigned char *) where);
2622 mop |= (unsigned short) (value & 0xfff);
2623 bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
2625 break;
2627 case BFD_RELOC_390_20:
2628 case BFD_RELOC_390_GOT20:
2629 case BFD_RELOC_390_GOTPLT20:
2630 if (fixP->fx_done)
2632 unsigned int mop;
2633 mop = bfd_getb32 ((unsigned char *) where);
2634 mop |= (unsigned int) ((value & 0xfff) << 8 |
2635 (value & 0xff000) >> 12);
2636 bfd_putb32 ((bfd_vma) mop, (unsigned char *) where);
2638 break;
2640 case BFD_RELOC_16:
2641 case BFD_RELOC_GPREL16:
2642 case BFD_RELOC_16_GOT_PCREL:
2643 case BFD_RELOC_16_GOTOFF:
2644 if (fixP->fx_pcrel)
2645 as_bad_where (fixP->fx_file, fixP->fx_line,
2646 _("cannot emit PC relative %s relocation%s%s"),
2647 bfd_get_reloc_code_name (fixP->fx_r_type),
2648 fixP->fx_addsy != NULL ? " against " : "",
2649 (fixP->fx_addsy != NULL
2650 ? S_GET_NAME (fixP->fx_addsy)
2651 : ""));
2652 if (fixP->fx_done)
2653 md_number_to_chars (where, value, 2);
2654 break;
2655 case BFD_RELOC_390_GOT16:
2656 case BFD_RELOC_390_PLTOFF16:
2657 case BFD_RELOC_390_GOTPLT16:
2658 if (fixP->fx_done)
2659 md_number_to_chars (where, value, 2);
2660 break;
2661 case BFD_RELOC_390_PC16DBL:
2662 case BFD_RELOC_390_PLT16DBL:
2663 value += fixP->fx_pcrel_adjust;
2664 if (fixP->fx_done)
2665 md_number_to_chars (where, (offsetT) value >> 1, 2);
2666 break;
2668 case BFD_RELOC_390_PC24DBL:
2669 case BFD_RELOC_390_PLT24DBL:
2670 value += fixP->fx_pcrel_adjust;
2671 if (fixP->fx_done)
2673 unsigned int mop;
2674 value >>= 1;
2676 mop = bfd_getb32 ((unsigned char *) where - 1);
2677 mop |= (unsigned int) (value & 0xffffff);
2678 bfd_putb32 ((bfd_vma) mop, (unsigned char *) where - 1);
2680 break;
2682 case BFD_RELOC_32:
2683 if (fixP->fx_pcrel)
2684 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2685 else
2686 fixP->fx_r_type = BFD_RELOC_32;
2687 if (fixP->fx_done)
2688 md_number_to_chars (where, value, 4);
2689 break;
2690 case BFD_RELOC_32_PCREL:
2691 case BFD_RELOC_32_BASEREL:
2692 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2693 if (fixP->fx_done)
2694 md_number_to_chars (where, value, 4);
2695 break;
2696 case BFD_RELOC_32_GOT_PCREL:
2697 case BFD_RELOC_390_PLTOFF32:
2698 case BFD_RELOC_390_PLT32:
2699 case BFD_RELOC_390_GOTPLT32:
2700 if (fixP->fx_done)
2701 md_number_to_chars (where, value, 4);
2702 break;
2703 case BFD_RELOC_390_PC32DBL:
2704 case BFD_RELOC_390_PLT32DBL:
2705 case BFD_RELOC_390_GOTPCDBL:
2706 case BFD_RELOC_390_GOTENT:
2707 case BFD_RELOC_390_GOTPLTENT:
2708 value += fixP->fx_pcrel_adjust;
2709 if (fixP->fx_done)
2710 md_number_to_chars (where, (offsetT) value >> 1, 4);
2711 break;
2713 case BFD_RELOC_32_GOTOFF:
2714 if (fixP->fx_done)
2715 md_number_to_chars (where, value, sizeof (int));
2716 break;
2718 case BFD_RELOC_390_GOTOFF64:
2719 if (fixP->fx_done)
2720 md_number_to_chars (where, value, 8);
2721 break;
2723 case BFD_RELOC_390_GOT64:
2724 case BFD_RELOC_390_PLTOFF64:
2725 case BFD_RELOC_390_PLT64:
2726 case BFD_RELOC_390_GOTPLT64:
2727 if (fixP->fx_done)
2728 md_number_to_chars (where, value, 8);
2729 break;
2731 case BFD_RELOC_64:
2732 if (fixP->fx_pcrel)
2733 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2734 else
2735 fixP->fx_r_type = BFD_RELOC_64;
2736 if (fixP->fx_done)
2737 md_number_to_chars (where, value, 8);
2738 break;
2740 case BFD_RELOC_64_PCREL:
2741 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2742 if (fixP->fx_done)
2743 md_number_to_chars (where, value, 8);
2744 break;
2746 case BFD_RELOC_VTABLE_INHERIT:
2747 case BFD_RELOC_VTABLE_ENTRY:
2748 fixP->fx_done = 0;
2749 return;
2751 case BFD_RELOC_390_TLS_LOAD:
2752 case BFD_RELOC_390_TLS_GDCALL:
2753 case BFD_RELOC_390_TLS_LDCALL:
2754 case BFD_RELOC_390_TLS_GD32:
2755 case BFD_RELOC_390_TLS_GD64:
2756 case BFD_RELOC_390_TLS_GOTIE12:
2757 case BFD_RELOC_390_TLS_GOTIE20:
2758 case BFD_RELOC_390_TLS_GOTIE32:
2759 case BFD_RELOC_390_TLS_GOTIE64:
2760 case BFD_RELOC_390_TLS_LDM32:
2761 case BFD_RELOC_390_TLS_LDM64:
2762 case BFD_RELOC_390_TLS_IE32:
2763 case BFD_RELOC_390_TLS_IE64:
2764 case BFD_RELOC_390_TLS_LE32:
2765 case BFD_RELOC_390_TLS_LE64:
2766 case BFD_RELOC_390_TLS_LDO32:
2767 case BFD_RELOC_390_TLS_LDO64:
2768 case BFD_RELOC_390_TLS_DTPMOD:
2769 case BFD_RELOC_390_TLS_DTPOFF:
2770 case BFD_RELOC_390_TLS_TPOFF:
2771 S_SET_THREAD_LOCAL (fixP->fx_addsy);
2772 /* Fully resolved at link time. */
2773 break;
2774 case BFD_RELOC_390_TLS_IEENT:
2775 /* Fully resolved at link time. */
2776 S_SET_THREAD_LOCAL (fixP->fx_addsy);
2777 value += 2;
2778 break;
2780 default:
2782 const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
2784 if (reloc_name != NULL)
2785 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name);
2786 else
2787 as_fatal (_("Gas failure, reloc type #%i\n"), fixP->fx_r_type);
2791 fixP->fx_offset = value;
2795 /* Generate a reloc for a fixup. */
2797 arelent *
2798 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
2800 bfd_reloc_code_real_type code;
2801 arelent *reloc;
2803 code = fixp->fx_r_type;
2804 if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
2806 if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
2807 || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
2808 code = BFD_RELOC_390_GOTPC;
2809 if (code == BFD_RELOC_390_PC32DBL)
2810 code = BFD_RELOC_390_GOTPCDBL;
2813 reloc = XNEW (arelent);
2814 reloc->sym_ptr_ptr = XNEW (asymbol *);
2815 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2816 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2817 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2818 if (reloc->howto == NULL)
2820 as_bad_where (fixp->fx_file, fixp->fx_line,
2821 _("cannot represent relocation type %s"),
2822 bfd_get_reloc_code_name (code));
2823 /* Set howto to a garbage value so that we can keep going. */
2824 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2825 gas_assert (reloc->howto != NULL);
2827 reloc->addend = fixp->fx_offset;
2829 return reloc;
2832 void
2833 s390_cfi_frame_initial_instructions (void)
2835 cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96);
2839 tc_s390_regname_to_dw2regnum (char *regname)
2841 int regnum = -1;
2843 if (regname[0] != 'c' && regname[0] != 'a')
2845 regnum = reg_name_search (regname);
2846 if (regname[0] == 'f' && regnum != -1)
2847 regnum += 16;
2849 else if (strcmp (regname, "ap") == 0)
2850 regnum = 32;
2851 else if (strcmp (regname, "cc") == 0)
2852 regnum = 33;
2853 return regnum;
2856 void
2857 s390_elf_final_processing (void)
2859 if (set_highgprs_p)
2860 elf_elfheader (stdoutput)->e_flags |= EF_S390_HIGH_GPRS;