1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
6 This file is part of GAS, the GNU Assembler.
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
10 the Free Software Foundation; either version 2, or (at your option)
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.
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
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "safe-ctype.h"
27 #include "struc-symbol.h"
28 #include "dwarf2dbg.h"
29 #include "dw2gencfi.h"
31 #include "opcode/s390.h"
34 /* The default architecture. */
36 #define DEFAULT_ARCH "s390"
38 static char *default_arch = DEFAULT_ARCH;
39 /* Either 32 or 64, selects file format. */
40 static int s390_arch_size = 0;
42 static unsigned int current_mode_mask = 0;
43 static unsigned int current_cpu = -1U;
45 /* Whether to use user friendly register names. Default is TRUE. */
46 #ifndef TARGET_REG_NAMES_P
47 #define TARGET_REG_NAMES_P TRUE
50 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
52 /* Set to TRUE if we want to warn about zero base/index registers. */
53 static bfd_boolean warn_areg_zero = FALSE;
55 /* Generic assembler global variables which must be defined by all
58 const char comment_chars[] = "#";
60 /* Characters which start a comment at the beginning of a line. */
61 const char line_comment_chars[] = "#";
63 /* Characters which may be used to separate multiple commands on a
65 const char line_separator_chars[] = ";";
67 /* Characters which are used to indicate an exponent in a floating
69 const char EXP_CHARS[] = "eE";
71 /* Characters which mean that a number is a floating point constant,
73 const char FLT_CHARS[] = "dD";
75 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
76 int s390_cie_data_alignment;
78 /* The target specific pseudo-ops which we support. */
80 /* Define the prototypes for the pseudo-ops */
81 static void s390_byte PARAMS ((int));
82 static void s390_elf_cons PARAMS ((int));
83 static void s390_bss PARAMS ((int));
84 static void s390_insn PARAMS ((int));
85 static void s390_literals PARAMS ((int));
87 const pseudo_typeS md_pseudo_table[] =
89 { "align", s_align_bytes, 0 },
90 /* Pseudo-ops which must be defined. */
91 { "bss", s390_bss, 0 },
92 { "insn", s390_insn, 0 },
93 /* Pseudo-ops which must be overridden. */
94 { "byte", s390_byte, 0 },
95 { "short", s390_elf_cons, 2 },
96 { "long", s390_elf_cons, 4 },
97 { "quad", s390_elf_cons, 8 },
98 { "ltorg", s390_literals, 0 },
99 { "string", stringer, 2 },
104 /* Structure to hold information about predefined registers. */
111 /* List of registers that are pre-defined:
113 Each access register has a predefined name of the form:
114 a<reg_num> which has the value <reg_num>.
116 Each control register has a predefined name of the form:
117 c<reg_num> which has the value <reg_num>.
119 Each general register has a predefined name of the form:
120 r<reg_num> which has the value <reg_num>.
122 Each floating point register a has predefined name of the form:
123 f<reg_num> which has the value <reg_num>.
125 There are individual registers as well:
129 The table is sorted. Suitable for searching by a binary search. */
131 static const struct pd_reg pre_defined_registers[] =
133 { "a0", 0 }, /* Access registers */
150 { "c0", 0 }, /* Control registers */
167 { "f0", 0 }, /* Floating point registers */
184 { "lit", 13 }, /* Pointer to literal pool */
186 { "r0", 0 }, /* General purpose registers */
203 { "sp", 15 }, /* Stack pointer */
207 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
209 static int reg_name_search
210 PARAMS ((const struct pd_reg *, int, const char *));
211 static bfd_boolean register_name PARAMS ((expressionS *));
212 static void init_default_arch PARAMS ((void));
213 static void s390_insert_operand
214 PARAMS ((unsigned char *, const struct s390_operand *, offsetT, char *,
216 static char *md_gather_operands
217 PARAMS ((char *, unsigned char *, const struct s390_opcode *));
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. */
223 reg_name_search (regs, regcount, name)
224 const struct pd_reg *regs;
228 int middle, low, high;
236 middle = (low + high) / 2;
237 cmp = strcasecmp (name, regs[middle].name);
243 return regs[middle].value;
252 * Summary of register_name().
254 * in: Input_line_pointer points to 1st char of operand.
256 * out: A expressionS.
257 * The operand may have been a register: in this case, X_op == O_register,
258 * X_add_number is set to the register number, and truth is returned.
259 * Input_line_pointer->(next non-blank) char after operand, or is in its
264 register_name (expressionP)
265 expressionS *expressionP;
272 /* Find the spelling of the operand. */
273 start = name = input_line_pointer;
274 if (name[0] == '%' && ISALPHA (name[1]))
275 name = ++input_line_pointer;
279 c = get_symbol_end ();
280 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
282 /* Put back the delimiting char. */
283 *input_line_pointer = c;
285 /* Look to see if it's in the register table. */
288 expressionP->X_op = O_register;
289 expressionP->X_add_number = reg_number;
291 /* Make the rest nice. */
292 expressionP->X_add_symbol = NULL;
293 expressionP->X_op_symbol = NULL;
297 /* Reset the line as if we had not done anything. */
298 input_line_pointer = start;
302 /* Local variables. */
304 /* Opformat hash table. */
305 static struct hash_control *s390_opformat_hash;
307 /* Opcode hash table. */
308 static struct hash_control *s390_opcode_hash;
310 /* Flags to set in the elf header */
311 static flagword s390_flags = 0;
313 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
315 #ifndef WORKING_DOT_WORD
316 int md_short_jump_size = 4;
317 int md_long_jump_size = 4;
320 const char *md_shortopts = "A:m:kVQ:";
321 struct option md_longopts[] = {
322 {NULL, no_argument, NULL, 0}
324 size_t md_longopts_size = sizeof (md_longopts);
326 /* Initialize the default opcode arch and word size from the default
327 architecture name if not specified by an option. */
331 if (strcmp (default_arch, "s390") == 0)
333 if (s390_arch_size == 0)
336 else if (strcmp (default_arch, "s390x") == 0)
338 if (s390_arch_size == 0)
342 as_fatal ("Invalid default architecture, broken assembler.");
344 if (current_mode_mask == 0)
346 if (s390_arch_size == 32)
347 current_mode_mask = 1 << S390_OPCODE_ESA;
349 current_mode_mask = 1 << S390_OPCODE_ZARCH;
351 if (current_cpu == -1U)
353 if (current_mode_mask == (1 << S390_OPCODE_ESA))
354 current_cpu = S390_OPCODE_G5;
356 current_cpu = S390_OPCODE_Z900;
360 /* Called by TARGET_FORMAT. */
362 s390_target_format ()
364 /* We don't get a chance to initialize anything before we're called,
365 so handle that now. */
366 init_default_arch ();
368 return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
372 md_parse_option (c, arg)
378 /* -k: Ignore for FreeBSD compatibility. */
382 if (arg != NULL && strcmp (arg, "regnames") == 0)
385 else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
388 else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
389 warn_areg_zero = TRUE;
391 else if (arg != NULL && strcmp (arg, "31") == 0)
394 else if (arg != NULL && strcmp (arg, "64") == 0)
397 else if (arg != NULL && strcmp (arg, "esa") == 0)
398 current_mode_mask = 1 << S390_OPCODE_ESA;
400 else if (arg != NULL && strcmp (arg, "zarch") == 0)
401 current_mode_mask = 1 << S390_OPCODE_ZARCH;
403 else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
405 if (strcmp (arg + 5, "g5") == 0)
406 current_cpu = S390_OPCODE_G5;
407 else if (strcmp (arg + 5, "g6") == 0)
408 current_cpu = S390_OPCODE_G6;
409 else if (strcmp (arg + 5, "z900") == 0)
410 current_cpu = S390_OPCODE_Z900;
411 else if (strcmp (arg + 5, "z990") == 0)
412 current_cpu = S390_OPCODE_Z990;
415 as_bad (_("invalid switch -m%s"), arg);
422 as_bad (_("invalid switch -m%s"), arg);
428 /* Option -A is deprecated. Still available for compatibility. */
429 if (arg != NULL && strcmp (arg, "esa") == 0)
430 current_cpu = S390_OPCODE_G5;
431 else if (arg != NULL && strcmp (arg, "esame") == 0)
432 current_cpu = S390_OPCODE_Z900;
434 as_bad ("invalid architecture -A%s", arg);
437 /* -V: SVR4 argument to print version ID. */
442 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
443 should be emitted or not. FIXME: Not implemented. */
455 md_show_usage (stream)
458 fprintf (stream, _("\
460 -mregnames Allow symbolic names for registers\n\
461 -mwarn-areg-zero Warn about zero base/index registers\n\
462 -mno-regnames Do not allow symbolic names for registers\n\
463 -m31 Set file format to 31 bit format\n\
464 -m64 Set file format to 64 bit format\n"));
465 fprintf (stream, _("\
466 -V print assembler version number\n\
467 -Qy, -Qn ignored\n"));
470 /* This function is called when the assembler starts up. It is called
471 after the options have been parsed and the output file has been
477 register const struct s390_opcode *op;
478 const struct s390_opcode *op_end;
479 bfd_boolean dup_insn = FALSE;
482 /* Give a warning if the combination -m64-bit and -Aesa is used. */
483 if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900)
484 as_warn ("The 64 bit file format is used without esame instructions.");
486 s390_cie_data_alignment = -s390_arch_size / 8;
488 /* Set the ELF flags if desired. */
490 bfd_set_private_flags (stdoutput, s390_flags);
492 /* Insert the opcode formats into a hash table. */
493 s390_opformat_hash = hash_new ();
495 op_end = s390_opformats + s390_num_opformats;
496 for (op = s390_opformats; op < op_end; op++)
498 retval = hash_insert (s390_opformat_hash, op->name, (PTR) op);
499 if (retval != (const char *) NULL)
501 as_bad (_("Internal assembler error for instruction format %s"),
507 /* Insert the opcodes into a hash table. */
508 s390_opcode_hash = hash_new ();
510 op_end = s390_opcodes + s390_num_opcodes;
511 for (op = s390_opcodes; op < op_end; op++)
512 if (op->min_cpu <= current_cpu)
514 retval = hash_insert (s390_opcode_hash, op->name, (PTR) op);
515 if (retval != (const char *) NULL)
517 as_bad (_("Internal assembler error for instruction %s"),
521 while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0)
528 record_alignment (text_section, 2);
529 record_alignment (data_section, 2);
530 record_alignment (bss_section, 2);
534 /* Called after all assembly has been done. */
538 if (s390_arch_size == 64)
539 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
541 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
544 /* Insert an operand value into an instruction. */
547 s390_insert_operand (insn, operand, val, file, line)
549 const struct s390_operand *operand;
557 if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
561 max = ((offsetT) 1 << (operand->bits - 1)) - 1;
562 min = - ((offsetT) 1 << (operand->bits - 1));
563 /* Halve PCREL operands. */
564 if (operand->flags & S390_OPERAND_PCREL)
566 /* Check for underflow / overflow. */
567 if (val < min || val > max)
570 "operand out of range (%s not between %ld and %ld)";
573 if (operand->flags & S390_OPERAND_PCREL)
579 sprint_value (buf, val);
580 if (file == (char *) NULL)
581 as_bad (err, buf, (int) min, (int) max);
583 as_bad_where (file, line, err, buf, (int) min, (int) max);
586 /* val is ok, now restrict it to operand->bits bits. */
587 uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
588 /* val is restrict, now check for special case. */
589 if (operand->bits == 20 && operand->shift == 20)
590 uval = (uval >> 12) | ((uval & 0xfff) << 8);
596 max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
598 uval = (addressT) val;
599 /* Length x in an instructions has real length x+1. */
600 if (operand->flags & S390_OPERAND_LENGTH)
602 /* Check for underflow / overflow. */
603 if (uval < min || uval > max)
605 if (operand->flags & S390_OPERAND_LENGTH)
612 as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line);
618 /* Insert fragments of the operand byte for byte. */
619 offset = operand->shift + operand->bits;
620 uval <<= (-offset) & 7;
621 insn += (offset - 1) / 8;
633 bfd_reloc_code_real_type reloc;
636 static bfd_reloc_code_real_type s390_tls_suffix
637 PARAMS ((char **, expressionS *));
639 /* Parse tls marker and return the desired relocation. */
640 static bfd_reloc_code_real_type
641 s390_tls_suffix (str_p, exp_p)
645 static struct map_tls mapping[] =
647 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD },
648 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL },
649 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL },
650 { NULL, 0, BFD_RELOC_UNUSED }
660 return BFD_RELOC_UNUSED;
663 while (ISIDNUM (*str))
667 return BFD_RELOC_UNUSED;
669 orig_line = input_line_pointer;
670 input_line_pointer = str;
672 str = input_line_pointer;
673 if (&input_line_pointer != str_p)
674 input_line_pointer = orig_line;
676 if (exp_p->X_op != O_symbol)
677 return BFD_RELOC_UNUSED;
679 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
680 if (len == ptr->length
681 && strncasecmp (ident, ptr->string, ptr->length) == 0)
683 /* Found a matching tls suffix. */
687 return BFD_RELOC_UNUSED;
690 /* Structure used to hold suffixes. */
701 ELF_SUFFIX_TLS_GOTIE,
713 elf_suffix_type suffix;
716 static elf_suffix_type s390_elf_suffix PARAMS ((char **, expressionS *));
717 static int s390_exp_compare PARAMS ((expressionS *exp1, expressionS *exp2));
718 static elf_suffix_type s390_lit_suffix
719 PARAMS ((char **, expressionS *, elf_suffix_type));
722 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
723 static elf_suffix_type
724 s390_elf_suffix (str_p, exp_p)
728 static struct map_bfd mapping[] =
730 { "got", 3, ELF_SUFFIX_GOT },
731 { "got12", 5, ELF_SUFFIX_GOT },
732 { "plt", 3, ELF_SUFFIX_PLT },
733 { "gotent", 6, ELF_SUFFIX_GOTENT },
734 { "gotoff", 6, ELF_SUFFIX_GOTOFF },
735 { "gotplt", 6, ELF_SUFFIX_GOTPLT },
736 { "pltoff", 6, ELF_SUFFIX_PLTOFF },
737 { "tlsgd", 5, ELF_SUFFIX_TLS_GD },
738 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE },
739 { "indntpoff", 9, ELF_SUFFIX_TLS_IE },
740 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM },
741 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO },
742 { "ntpoff", 6, ELF_SUFFIX_TLS_LE },
743 { NULL, 0, ELF_SUFFIX_NONE }
752 return ELF_SUFFIX_NONE;
755 while (ISALNUM (*str))
759 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
760 if (len == ptr->length
761 && strncasecmp (ident, ptr->string, ptr->length) == 0)
763 if (exp_p->X_add_number != 0)
764 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
765 ptr->string, ptr->string);
766 /* Now check for identifier@suffix+constant. */
767 if (*str == '-' || *str == '+')
769 char *orig_line = input_line_pointer;
772 input_line_pointer = str;
773 expression (&new_exp);
775 switch (new_exp.X_op)
777 case O_constant: /* X_add_number (a constant expression). */
778 exp_p->X_add_number += new_exp.X_add_number;
779 str = input_line_pointer;
781 case O_symbol: /* X_add_symbol + X_add_number. */
782 /* this case is used for e.g. xyz@PLT+.Label. */
783 exp_p->X_add_number += new_exp.X_add_number;
784 exp_p->X_op_symbol = new_exp.X_add_symbol;
786 str = input_line_pointer;
788 case O_uminus: /* (- X_add_symbol) + X_add_number. */
789 /* this case is used for e.g. xyz@PLT-.Label. */
790 exp_p->X_add_number += new_exp.X_add_number;
791 exp_p->X_op_symbol = new_exp.X_add_symbol;
792 exp_p->X_op = O_subtract;
793 str = input_line_pointer;
799 /* If s390_elf_suffix has not been called with
800 &input_line_pointer as first parameter, we have
801 clobbered the input_line_pointer. We have to
803 if (&input_line_pointer != str_p)
804 input_line_pointer = orig_line;
810 return BFD_RELOC_UNUSED;
813 /* Structure used to hold a literal pool entry. */
816 struct s390_lpe *next;
818 FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */
819 LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */
821 bfd_reloc_code_real_type reloc;
825 static struct s390_lpe *lpe_free_list = NULL;
826 static struct s390_lpe *lpe_list = NULL;
827 static struct s390_lpe *lpe_list_tail = NULL;
828 static symbolS *lp_sym = NULL;
829 static int lp_count = 0;
830 static int lpe_count = 0;
833 s390_exp_compare (exp1, exp2)
837 if (exp1->X_op != exp2->X_op)
842 case O_constant: /* X_add_number must be equal. */
844 return exp1->X_add_number == exp2->X_add_number;
847 as_bad (_("Can't handle O_big in s390_exp_compare"));
849 case O_symbol: /* X_add_symbol & X_add_number must be equal. */
854 return (exp1->X_add_symbol == exp2->X_add_symbol)
855 && (exp1->X_add_number == exp2->X_add_number);
857 case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
862 case O_bit_inclusive_or:
864 case O_bit_exclusive_or:
876 return (exp1->X_add_symbol == exp2->X_add_symbol)
877 && (exp1->X_op_symbol == exp2->X_op_symbol)
878 && (exp1->X_add_number == exp2->X_add_number);
884 /* Test for @lit and if its present make an entry in the literal pool and
885 modify the current expression to be an offset into the literal pool. */
886 static elf_suffix_type
887 s390_lit_suffix (str_p, exp_p, suffix)
890 elf_suffix_type suffix;
892 bfd_reloc_code_real_type reloc;
896 struct s390_lpe *lpe;
900 return suffix; /* No modification. */
902 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
904 while (ISALNUM (*str))
907 if (len != 4 || strncasecmp (ident, "lit", 3) != 0
908 || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
909 return suffix; /* no modification */
910 nbytes = ident[3] - '0';
912 reloc = BFD_RELOC_UNUSED;
913 if (suffix == ELF_SUFFIX_GOT)
916 reloc = BFD_RELOC_390_GOT16;
917 else if (nbytes == 4)
918 reloc = BFD_RELOC_32_GOT_PCREL;
919 else if (nbytes == 8)
920 reloc = BFD_RELOC_390_GOT64;
922 else if (suffix == ELF_SUFFIX_PLT)
925 reloc = BFD_RELOC_390_PLT32;
926 else if (nbytes == 8)
927 reloc = BFD_RELOC_390_PLT64;
930 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
931 as_bad (_("Invalid suffix for literal pool entry"));
933 /* Search the pool if the new entry is a duplicate. */
934 if (exp_p->X_op == O_big)
936 /* Special processing for big numbers. */
937 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
939 if (lpe->ex.X_op == O_big)
941 if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
943 if (memcmp (&generic_floating_point_number, &lpe->floatnum,
944 sizeof (FLONUM_TYPE)) == 0)
947 else if (exp_p->X_add_number == lpe->ex.X_add_number)
949 if (memcmp (generic_bignum, lpe->bignum,
950 sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
958 /* Processing for 'normal' data types. */
959 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
960 if (lpe->nbytes == nbytes && lpe->reloc == reloc
961 && s390_exp_compare (exp_p, &lpe->ex) != 0)
968 if (lpe_free_list != NULL)
971 lpe_free_list = lpe_free_list->next;
975 lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe));
980 if (exp_p->X_op == O_big)
982 if (exp_p->X_add_number <= 0)
983 lpe->floatnum = generic_floating_point_number;
984 else if (exp_p->X_add_number <= 4)
985 memcpy (lpe->bignum, generic_bignum,
986 exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
988 as_bad (_("Big number is too big"));
991 lpe->nbytes = nbytes;
993 /* Literal pool name defined ? */
996 sprintf (tmp_name, ".L\001%i", lp_count);
997 lp_sym = symbol_make (tmp_name);
1000 /* Make name for literal pool entry. */
1001 sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
1003 lpe->sym = symbol_make (tmp_name);
1005 /* Add to literal pool list. */
1007 if (lpe_list_tail != NULL)
1009 lpe_list_tail->next = lpe;
1010 lpe_list_tail = lpe;
1013 lpe_list = lpe_list_tail = lpe;
1016 /* Now change exp_p to the offset into the literal pool.
1017 Thats the expression: .L^Ax^By-.L^Ax */
1018 exp_p->X_add_symbol = lpe->sym;
1019 exp_p->X_op_symbol = lp_sym;
1020 exp_p->X_op = O_subtract;
1021 exp_p->X_add_number = 0;
1025 /* We change the suffix type to ELF_SUFFIX_NONE, because
1026 the difference of two local labels is just a number. */
1027 return ELF_SUFFIX_NONE;
1030 /* Like normal .long/.short/.word, except support @got, etc.
1031 clobbers input_line_pointer, checks end-of-line. */
1033 s390_elf_cons (nbytes)
1034 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1037 elf_suffix_type suffix;
1039 if (is_it_end_of_statement ())
1041 demand_empty_rest_of_line ();
1049 if (exp.X_op == O_symbol
1050 && *input_line_pointer == '@'
1051 && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
1053 bfd_reloc_code_real_type reloc;
1054 reloc_howto_type *reloc_howto;
1060 static bfd_reloc_code_real_type tab2[] =
1062 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1063 BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */
1064 BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */
1065 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1066 BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1067 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */
1068 BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */
1069 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */
1070 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */
1071 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */
1072 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */
1073 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */
1074 BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */
1076 reloc = tab2[suffix];
1078 else if (nbytes == 4)
1080 static bfd_reloc_code_real_type tab4[] =
1082 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1083 BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */
1084 BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */
1085 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1086 BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1087 BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */
1088 BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */
1089 BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */
1090 BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */
1091 BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */
1092 BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */
1093 BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */
1094 BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */
1096 reloc = tab4[suffix];
1098 else if (nbytes == 8)
1100 static bfd_reloc_code_real_type tab8[] =
1102 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1103 BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */
1104 BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */
1105 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1106 BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */
1107 BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */
1108 BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */
1109 BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */
1110 BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */
1111 BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */
1112 BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */
1113 BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */
1114 BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */
1116 reloc = tab8[suffix];
1119 reloc = BFD_RELOC_UNUSED;
1121 if (reloc != BFD_RELOC_UNUSED
1122 && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc)))
1124 size = bfd_get_reloc_size (reloc_howto);
1126 as_bad (_("%s relocations do not fit in %d bytes"),
1127 reloc_howto->name, nbytes);
1128 where = frag_more (nbytes);
1129 md_number_to_chars (where, 0, size);
1130 /* To make fixup_segment do the pc relative conversion the
1131 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1132 fix_new_exp (frag_now, where - frag_now->fr_literal,
1133 size, &exp, FALSE, reloc);
1136 as_bad (_("relocation not applicable"));
1139 emit_expr (&exp, (unsigned int) nbytes);
1141 while (*input_line_pointer++ == ',');
1143 input_line_pointer--; /* Put terminator back into stream. */
1144 demand_empty_rest_of_line ();
1147 /* We need to keep a list of fixups. We can't simply generate them as
1148 we go, because that would require us to first create the frag, and
1149 that would screw up references to ``.''. */
1155 bfd_reloc_code_real_type reloc;
1158 #define MAX_INSN_FIXUPS (4)
1160 /* This routine is called for each instruction to be assembled. */
1163 md_gather_operands (str, insn, opcode)
1165 unsigned char *insn;
1166 const struct s390_opcode *opcode;
1168 struct s390_fixup fixups[MAX_INSN_FIXUPS];
1169 const struct s390_operand *operand;
1170 const unsigned char *opindex_ptr;
1172 elf_suffix_type suffix;
1173 bfd_reloc_code_real_type reloc;
1179 while (ISSPACE (*str))
1185 /* Gather the operands. */
1187 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1191 operand = s390_operands + *opindex_ptr;
1193 if (skip_optional && (operand->flags & S390_OPERAND_INDEX))
1195 /* We do an early skip. For D(X,B) constructions the index
1196 register is skipped (X is optional). For D(L,B) the base
1197 register will be the skipped operand, because L is NOT
1203 /* Gather the operand. */
1204 hold = input_line_pointer;
1205 input_line_pointer = str;
1207 /* Parse the operand. */
1208 if (! register_name (&ex))
1211 str = input_line_pointer;
1212 input_line_pointer = hold;
1214 /* Write the operand to the insn. */
1215 if (ex.X_op == O_illegal)
1216 as_bad (_("illegal operand"));
1217 else if (ex.X_op == O_absent)
1218 as_bad (_("missing operand"));
1219 else if (ex.X_op == O_register || ex.X_op == O_constant)
1221 s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
1223 if (ex.X_op != O_register && ex.X_op != O_constant)
1225 /* We need to generate a fixup for the
1226 expression returned by s390_lit_suffix. */
1227 if (fc >= MAX_INSN_FIXUPS)
1228 as_fatal (_("too many fixups"));
1229 fixups[fc].exp = ex;
1230 fixups[fc].opindex = *opindex_ptr;
1231 fixups[fc].reloc = BFD_RELOC_UNUSED;
1236 if ((operand->flags & S390_OPERAND_INDEX)
1237 && ex.X_add_number == 0
1239 as_warn ("index register specified but zero");
1240 if ((operand->flags & S390_OPERAND_BASE)
1241 && ex.X_add_number == 0
1243 as_warn ("base register specified but zero");
1244 s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0);
1249 suffix = s390_elf_suffix (&str, &ex);
1250 suffix = s390_lit_suffix (&str, &ex, suffix);
1251 reloc = BFD_RELOC_UNUSED;
1253 if (suffix == ELF_SUFFIX_GOT)
1255 if ((operand->flags & S390_OPERAND_DISP) &&
1256 (operand->bits == 12))
1257 reloc = BFD_RELOC_390_GOT12;
1258 else if ((operand->flags & S390_OPERAND_DISP) &&
1259 (operand->bits == 20))
1260 reloc = BFD_RELOC_390_GOT20;
1261 else if ((operand->flags & S390_OPERAND_SIGNED)
1262 && (operand->bits == 16))
1263 reloc = BFD_RELOC_390_GOT16;
1264 else if ((operand->flags & S390_OPERAND_PCREL)
1265 && (operand->bits == 32))
1266 reloc = BFD_RELOC_390_GOTENT;
1268 else if (suffix == ELF_SUFFIX_PLT)
1270 if ((operand->flags & S390_OPERAND_PCREL)
1271 && (operand->bits == 16))
1272 reloc = BFD_RELOC_390_PLT16DBL;
1273 else if ((operand->flags & S390_OPERAND_PCREL)
1274 && (operand->bits == 32))
1275 reloc = BFD_RELOC_390_PLT32DBL;
1277 else if (suffix == ELF_SUFFIX_GOTENT)
1279 if ((operand->flags & S390_OPERAND_PCREL)
1280 && (operand->bits == 32))
1281 reloc = BFD_RELOC_390_GOTENT;
1283 else if (suffix == ELF_SUFFIX_GOTOFF)
1285 if ((operand->flags & S390_OPERAND_SIGNED)
1286 && (operand->bits == 16))
1287 reloc = BFD_RELOC_16_GOTOFF;
1289 else if (suffix == ELF_SUFFIX_PLTOFF)
1291 if ((operand->flags & S390_OPERAND_SIGNED)
1292 && (operand->bits == 16))
1293 reloc = BFD_RELOC_390_PLTOFF16;
1295 else if (suffix == ELF_SUFFIX_GOTPLT)
1297 if ((operand->flags & S390_OPERAND_DISP)
1298 && (operand->bits == 12))
1299 reloc = BFD_RELOC_390_GOTPLT12;
1300 else if ((operand->flags & S390_OPERAND_SIGNED)
1301 && (operand->bits == 16))
1302 reloc = BFD_RELOC_390_GOTPLT16;
1303 else if ((operand->flags & S390_OPERAND_PCREL)
1304 && (operand->bits == 32))
1305 reloc = BFD_RELOC_390_GOTPLTENT;
1307 else if (suffix == ELF_SUFFIX_TLS_GOTIE)
1309 if ((operand->flags & S390_OPERAND_DISP)
1310 && (operand->bits == 12))
1311 reloc = BFD_RELOC_390_TLS_GOTIE12;
1312 else if ((operand->flags & S390_OPERAND_DISP)
1313 && (operand->bits == 20))
1314 reloc = BFD_RELOC_390_TLS_GOTIE20;
1316 else if (suffix == ELF_SUFFIX_TLS_IE)
1318 if ((operand->flags & S390_OPERAND_PCREL)
1319 && (operand->bits == 32))
1320 reloc = BFD_RELOC_390_TLS_IEENT;
1323 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1324 as_bad (_("invalid operand suffix"));
1325 /* We need to generate a fixup of type 'reloc' for this
1327 if (fc >= MAX_INSN_FIXUPS)
1328 as_fatal (_("too many fixups"));
1329 fixups[fc].exp = ex;
1330 fixups[fc].opindex = *opindex_ptr;
1331 fixups[fc].reloc = reloc;
1335 /* Check the next character. The call to expression has advanced
1336 str past any whitespace. */
1337 if (operand->flags & S390_OPERAND_DISP)
1339 /* After a displacement a block in parentheses can start. */
1342 /* Check if parenthesized block can be skipped. If the next
1343 operand is neiter an optional operand nor a base register
1344 then we have a syntax error. */
1345 operand = s390_operands + *(++opindex_ptr);
1346 if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
1347 as_bad (_("syntax error; missing '(' after displacement"));
1349 /* Ok, skip all operands until S390_OPERAND_BASE. */
1350 while (!(operand->flags & S390_OPERAND_BASE))
1351 operand = s390_operands + *(++opindex_ptr);
1353 /* If there is a next operand it must be separated by a comma. */
1354 if (opindex_ptr[1] != '\0')
1357 as_bad (_("syntax error; expected ,"));
1362 /* We found an opening parentheses. */
1364 for (f = str; *f != '\0'; f++)
1365 if (*f == ',' || *f == ')')
1367 /* If there is no comma until the closing parentheses OR
1368 there is a comma right after the opening parentheses,
1369 we have to skip optional operands. */
1370 if (*f == ',' && f == str)
1372 /* comma directly after '(' ? */
1377 skip_optional = (*f != ',');
1380 else if (operand->flags & S390_OPERAND_BASE)
1382 /* After the base register the parenthesed block ends. */
1384 as_bad (_("syntax error; missing ')' after base register"));
1386 /* If there is a next operand it must be separated by a comma. */
1387 if (opindex_ptr[1] != '\0')
1390 as_bad (_("syntax error; expected ,"));
1395 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1396 of D(L,B). In this case the base register has to be skipped. */
1399 operand = s390_operands + *(++opindex_ptr);
1401 if (!(operand->flags & S390_OPERAND_BASE))
1402 as_bad (_("syntax error; ')' not allowed here"));
1405 /* If there is a next operand it must be separated by a comma. */
1406 if (opindex_ptr[1] != '\0')
1409 as_bad (_("syntax error; expected ,"));
1414 while (ISSPACE (*str))
1417 /* Check for tls instruction marker. */
1418 reloc = s390_tls_suffix (&str, &ex);
1419 if (reloc != BFD_RELOC_UNUSED)
1421 /* We need to generate a fixup of type 'reloc' for this
1423 if (fc >= MAX_INSN_FIXUPS)
1424 as_fatal (_("too many fixups"));
1425 fixups[fc].exp = ex;
1426 fixups[fc].opindex = -1;
1427 fixups[fc].reloc = reloc;
1435 if ((linefeed = strchr (str, '\n')) != NULL)
1437 as_bad (_("junk at end of line: `%s'"), str);
1438 if (linefeed != NULL)
1442 /* Write out the instruction. */
1443 f = frag_more (opcode->oplen);
1444 memcpy (f, insn, opcode->oplen);
1445 dwarf2_emit_insn (opcode->oplen);
1447 /* Create any fixups. At this point we do not use a
1448 bfd_reloc_code_real_type, but instead just use the
1449 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1450 handle fixups for any operand type, although that is admittedly
1451 not a very exciting feature. We pick a BFD reloc type in
1453 for (i = 0; i < fc; i++)
1456 if (fixups[i].opindex < 0)
1458 /* Create tls instruction marker relocation. */
1459 fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen,
1460 &fixups[i].exp, 0, fixups[i].reloc);
1464 operand = s390_operands + fixups[i].opindex;
1466 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1468 reloc_howto_type *reloc_howto;
1472 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1476 size = bfd_get_reloc_size (reloc_howto);
1478 if (size < 1 || size > 4)
1481 fixP = fix_new_exp (frag_now,
1482 f - frag_now->fr_literal + (operand->shift/8),
1483 size, &fixups[i].exp, reloc_howto->pc_relative,
1485 /* Turn off overflow checking in fixup_segment. This is necessary
1486 because fixup_segment will signal an overflow for large 4 byte
1487 quantities for GOT12 relocations. */
1488 if ( fixups[i].reloc == BFD_RELOC_390_GOT12
1489 || fixups[i].reloc == BFD_RELOC_390_GOT20
1490 || fixups[i].reloc == BFD_RELOC_390_GOT16)
1491 fixP->fx_no_overflow = 1;
1494 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp,
1495 (operand->flags & S390_OPERAND_PCREL) != 0,
1496 ((bfd_reloc_code_real_type)
1497 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1502 /* This routine is called for each instruction to be assembled. */
1508 const struct s390_opcode *opcode;
1509 unsigned char insn[6];
1512 /* Get the opcode. */
1513 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1518 /* Look up the opcode in the hash table. */
1519 opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str);
1520 if (opcode == (const struct s390_opcode *) NULL)
1522 as_bad (_("Unrecognized opcode: `%s'"), str);
1525 else if (!(opcode->modes & current_mode_mask))
1527 as_bad ("Opcode %s not available in this mode", str);
1530 memcpy (insn, opcode->opcode, sizeof (insn));
1531 md_gather_operands (s, insn, opcode);
1534 #ifndef WORKING_DOT_WORD
1535 /* Handle long and short jumps. We don't support these */
1537 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1539 addressT from_addr, to_addr;
1547 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1549 addressT from_addr, to_addr;
1559 int ignore ATTRIBUTE_UNUSED;
1561 /* We don't support putting frags in the BSS segment, we fake it
1562 by marking in_bss, then looking at s_skip for clues. */
1564 subseg_set (bss_section, 0);
1565 demand_empty_rest_of_line ();
1568 /* Pseudo-op handling. */
1572 int ignore ATTRIBUTE_UNUSED;
1575 const struct s390_opcode *opformat;
1576 unsigned char insn[6];
1579 /* Get the opcode format. */
1580 s = input_line_pointer;
1581 while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
1584 as_bad (_("Invalid .insn format\n"));
1587 /* Look up the opcode in the hash table. */
1588 opformat = (struct s390_opcode *)
1589 hash_find (s390_opformat_hash, input_line_pointer);
1590 if (opformat == (const struct s390_opcode *) NULL)
1592 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
1595 input_line_pointer = s;
1597 if (exp.X_op == O_constant)
1599 if ( ( opformat->oplen == 6
1600 && (addressT) exp.X_add_number < (1ULL << 48))
1601 || ( opformat->oplen == 4
1602 && (addressT) exp.X_add_number < (1ULL << 32))
1603 || ( opformat->oplen == 2
1604 && (addressT) exp.X_add_number < (1ULL << 16)))
1605 md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen);
1607 as_bad (_("Invalid .insn format\n"));
1609 else if (exp.X_op == O_big)
1611 if (exp.X_add_number > 0
1612 && opformat->oplen == 6
1613 && generic_bignum[3] == 0)
1615 md_number_to_chars ((char *) insn, generic_bignum[2], 2);
1616 md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2);
1617 md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2);
1620 as_bad (_("Invalid .insn format\n"));
1623 as_bad (_("second operand of .insn not a constant\n"));
1625 if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
1626 as_bad (_("missing comma after insn constant\n"));
1628 if ((s = strchr (input_line_pointer, '\n')) != NULL)
1630 input_line_pointer = md_gather_operands (input_line_pointer, insn,
1634 demand_empty_rest_of_line ();
1637 /* The .byte pseudo-op. This is similar to the normal .byte
1638 pseudo-op, but it can also take a single ASCII string. */
1642 int ignore ATTRIBUTE_UNUSED;
1644 if (*input_line_pointer != '\"')
1650 /* Gather characters. A real double quote is doubled. Unusual
1651 characters are not permitted. */
1652 ++input_line_pointer;
1657 c = *input_line_pointer++;
1661 if (*input_line_pointer != '\"')
1663 ++input_line_pointer;
1666 FRAG_APPEND_1_CHAR (c);
1669 demand_empty_rest_of_line ();
1672 /* The .ltorg pseudo-op.This emits all literals defined since the last
1673 .ltorg or the invocation of gas. Literals are defined with the
1677 s390_literals (ignore)
1678 int ignore ATTRIBUTE_UNUSED;
1680 struct s390_lpe *lpe;
1682 if (lp_sym == NULL || lpe_count == 0)
1683 return; /* Nothing to be done. */
1685 /* Emit symbol for start of literal pool. */
1686 S_SET_SEGMENT (lp_sym, now_seg);
1687 S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
1688 lp_sym->sy_frag = frag_now;
1693 lpe_list = lpe_list->next;
1694 S_SET_SEGMENT (lpe->sym, now_seg);
1695 S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
1696 lpe->sym->sy_frag = frag_now;
1698 /* Emit literal pool entry. */
1699 if (lpe->reloc != BFD_RELOC_UNUSED)
1701 reloc_howto_type *reloc_howto =
1702 bfd_reloc_type_lookup (stdoutput, lpe->reloc);
1703 int size = bfd_get_reloc_size (reloc_howto);
1706 if (size > lpe->nbytes)
1707 as_bad (_("%s relocations do not fit in %d bytes"),
1708 reloc_howto->name, lpe->nbytes);
1709 where = frag_more (lpe->nbytes);
1710 md_number_to_chars (where, 0, size);
1711 fix_new_exp (frag_now, where - frag_now->fr_literal,
1712 size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
1716 if (lpe->ex.X_op == O_big)
1718 if (lpe->ex.X_add_number <= 0)
1719 generic_floating_point_number = lpe->floatnum;
1721 memcpy (generic_bignum, lpe->bignum,
1722 lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
1724 emit_expr (&lpe->ex, lpe->nbytes);
1727 lpe->next = lpe_free_list;
1728 lpe_free_list = lpe;
1730 lpe_list_tail = NULL;
1736 /* Turn a string in input_line_pointer into a floating point constant
1737 of type type, and store the appropriate bytes in *litp. The number
1738 of LITTLENUMS emitted is stored in *sizep . An error message is
1739 returned, or NULL on OK. */
1742 md_atof (type, litp, sizep)
1748 LITTLENUM_TYPE words[4];
1764 return "bad call to md_atof";
1767 t = atof_ieee (input_line_pointer, type, words);
1769 input_line_pointer = t;
1773 for (i = 0; i < prec; i++)
1775 md_number_to_chars (litp, (valueT) words[i], 2);
1782 /* Align a section (I don't know why this is machine dependent). */
1785 md_section_align (seg, addr)
1789 int align = bfd_get_section_alignment (stdoutput, seg);
1791 return ((addr + (1 << align) - 1) & (-1 << align));
1794 /* We don't have any form of relaxing. */
1797 md_estimate_size_before_relax (fragp, seg)
1798 fragS *fragp ATTRIBUTE_UNUSED;
1799 asection *seg ATTRIBUTE_UNUSED;
1805 /* Convert a machine dependent frag. We never generate these. */
1808 md_convert_frag (abfd, sec, fragp)
1809 bfd *abfd ATTRIBUTE_UNUSED;
1810 asection *sec ATTRIBUTE_UNUSED;
1811 fragS *fragp ATTRIBUTE_UNUSED;
1817 md_undefined_symbol (name)
1820 if (*name == '_' && *(name + 1) == 'G'
1821 && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
1825 if (symbol_find (name))
1826 as_bad (_("GOT already in symbol table"));
1827 GOT_symbol = symbol_new (name, undefined_section,
1828 (valueT) 0, &zero_address_frag);
1835 /* Functions concerning relocs. */
1837 /* The location from which a PC relative jump should be calculated,
1838 given a PC relative reloc. */
1841 md_pcrel_from_section (fixp, sec)
1843 segT sec ATTRIBUTE_UNUSED;
1845 return fixp->fx_frag->fr_address + fixp->fx_where;
1848 /* Here we decide which fixups can be adjusted to make them relative to
1849 the beginning of the section instead of the symbol. Basically we need
1850 to make sure that the dynamic relocations are done correctly, so in
1851 some cases we force the original symbol to be used. */
1853 tc_s390_fix_adjustable (fixP)
1856 /* Don't adjust references to merge sections. */
1857 if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0)
1859 /* adjust_reloc_syms doesn't know about the GOT. */
1860 if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF
1861 || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
1862 || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64
1863 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16
1864 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32
1865 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64
1866 || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
1867 || fixP->fx_r_type == BFD_RELOC_390_PLT32
1868 || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
1869 || fixP->fx_r_type == BFD_RELOC_390_PLT64
1870 || fixP->fx_r_type == BFD_RELOC_390_GOT12
1871 || fixP->fx_r_type == BFD_RELOC_390_GOT20
1872 || fixP->fx_r_type == BFD_RELOC_390_GOT16
1873 || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
1874 || fixP->fx_r_type == BFD_RELOC_390_GOT64
1875 || fixP->fx_r_type == BFD_RELOC_390_GOTENT
1876 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
1877 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16
1878 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20
1879 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32
1880 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64
1881 || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT
1882 || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD
1883 || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL
1884 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL
1885 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32
1886 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64
1887 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12
1888 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20
1889 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32
1890 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64
1891 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32
1892 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64
1893 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32
1894 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64
1895 || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT
1896 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32
1897 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64
1898 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32
1899 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64
1900 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD
1901 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF
1902 || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF
1903 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1904 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1909 /* Return true if we must always emit a reloc for a type and false if
1910 there is some hope of resolving it at assembly time. */
1912 tc_s390_force_relocation (fixp)
1915 /* Ensure we emit a relocation for every reference to the global
1916 offset table or to the procedure link table. */
1917 switch (fixp->fx_r_type)
1919 case BFD_RELOC_390_GOT12:
1920 case BFD_RELOC_390_GOT20:
1921 case BFD_RELOC_32_GOT_PCREL:
1922 case BFD_RELOC_32_GOTOFF:
1923 case BFD_RELOC_390_GOTOFF64:
1924 case BFD_RELOC_390_PLTOFF16:
1925 case BFD_RELOC_390_PLTOFF32:
1926 case BFD_RELOC_390_PLTOFF64:
1927 case BFD_RELOC_390_GOTPC:
1928 case BFD_RELOC_390_GOT16:
1929 case BFD_RELOC_390_GOTPCDBL:
1930 case BFD_RELOC_390_GOT64:
1931 case BFD_RELOC_390_GOTENT:
1932 case BFD_RELOC_390_PLT32:
1933 case BFD_RELOC_390_PLT16DBL:
1934 case BFD_RELOC_390_PLT32DBL:
1935 case BFD_RELOC_390_PLT64:
1936 case BFD_RELOC_390_GOTPLT12:
1937 case BFD_RELOC_390_GOTPLT16:
1938 case BFD_RELOC_390_GOTPLT20:
1939 case BFD_RELOC_390_GOTPLT32:
1940 case BFD_RELOC_390_GOTPLT64:
1941 case BFD_RELOC_390_GOTPLTENT:
1947 return generic_force_reloc (fixp);
1950 /* Apply a fixup to the object code. This is called for all the
1951 fixups we generated by the call to fix_new_exp, above. In the call
1952 above we used a reloc code which was the largest legal reloc code
1953 plus the operand index. Here we undo that to recover the operand
1954 index. At this point all symbol values should be fully resolved,
1955 and we attempt to completely resolve the reloc. If we can not do
1956 that, we determine the correct reloc code and put it back in the
1960 md_apply_fix3 (fixP, valP, seg)
1963 segT seg ATTRIBUTE_UNUSED;
1966 valueT value = *valP;
1968 where = fixP->fx_frag->fr_literal + fixP->fx_where;
1970 if (fixP->fx_subsy != NULL)
1971 as_bad_where (fixP->fx_file, fixP->fx_line,
1972 "cannot emit relocation %s against subsy symbol %s",
1973 bfd_get_reloc_code_name (fixP->fx_r_type),
1974 S_GET_NAME (fixP->fx_subsy));
1976 if (fixP->fx_addsy != NULL)
1979 value += fixP->fx_frag->fr_address + fixP->fx_where;
1984 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
1986 const struct s390_operand *operand;
1989 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
1990 operand = &s390_operands[opindex];
1994 /* Insert the fully resolved operand value. */
1995 s390_insert_operand ((unsigned char *) where, operand,
1996 (offsetT) value, fixP->fx_file, fixP->fx_line);
2000 /* Determine a BFD reloc value based on the operand information.
2001 We are only prepared to turn a few of the operands into
2003 fixP->fx_offset = value;
2004 if (operand->bits == 12 && operand->shift == 20)
2007 fixP->fx_where += 2;
2008 fixP->fx_r_type = BFD_RELOC_390_12;
2010 else if (operand->bits == 12 && operand->shift == 36)
2013 fixP->fx_where += 4;
2014 fixP->fx_r_type = BFD_RELOC_390_12;
2016 else if (operand->bits == 20 && operand->shift == 20)
2019 fixP->fx_where += 2;
2020 fixP->fx_r_type = BFD_RELOC_390_20;
2022 else if (operand->bits == 8 && operand->shift == 8)
2025 fixP->fx_where += 1;
2026 fixP->fx_r_type = BFD_RELOC_8;
2028 else if (operand->bits == 16 && operand->shift == 16)
2031 fixP->fx_where += 2;
2032 if (operand->flags & S390_OPERAND_PCREL)
2034 fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2035 fixP->fx_offset += 2;
2038 fixP->fx_r_type = BFD_RELOC_16;
2040 else if (operand->bits == 32 && operand->shift == 16
2041 && (operand->flags & S390_OPERAND_PCREL))
2044 fixP->fx_where += 2;
2045 fixP->fx_offset += 2;
2046 fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
2053 /* Use expr_symbol_where to see if this is an expression
2055 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
2056 as_bad_where (fixP->fx_file, fixP->fx_line,
2057 _("unresolved expression that must be resolved"));
2059 as_bad_where (fixP->fx_file, fixP->fx_line,
2060 _("unsupported relocation type"));
2067 switch (fixP->fx_r_type)
2073 md_number_to_chars (where, value, 1);
2075 case BFD_RELOC_390_12:
2076 case BFD_RELOC_390_GOT12:
2077 case BFD_RELOC_390_GOTPLT12:
2082 mop = bfd_getb16 ((unsigned char *) where);
2083 mop |= (unsigned short) (value & 0xfff);
2084 bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
2088 case BFD_RELOC_390_20:
2089 case BFD_RELOC_390_GOT20:
2090 case BFD_RELOC_390_GOTPLT20:
2094 mop = bfd_getb32 ((unsigned char *) where);
2095 mop |= (unsigned int) ((value & 0xfff) << 8 |
2096 (value & 0xff000) >> 12);
2097 bfd_putb32 ((bfd_vma) mop, (unsigned char *) where);
2102 case BFD_RELOC_GPREL16:
2103 case BFD_RELOC_16_GOT_PCREL:
2104 case BFD_RELOC_16_GOTOFF:
2106 as_bad_where (fixP->fx_file, fixP->fx_line,
2107 "cannot emit PC relative %s relocation%s%s",
2108 bfd_get_reloc_code_name (fixP->fx_r_type),
2109 fixP->fx_addsy != NULL ? " against " : "",
2110 (fixP->fx_addsy != NULL
2111 ? S_GET_NAME (fixP->fx_addsy)
2114 md_number_to_chars (where, value, 2);
2116 case BFD_RELOC_390_GOT16:
2117 case BFD_RELOC_390_PLTOFF16:
2118 case BFD_RELOC_390_GOTPLT16:
2120 md_number_to_chars (where, value, 2);
2122 case BFD_RELOC_390_PC16DBL:
2123 case BFD_RELOC_390_PLT16DBL:
2126 md_number_to_chars (where, (offsetT) value >> 1, 2);
2131 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2133 fixP->fx_r_type = BFD_RELOC_32;
2135 md_number_to_chars (where, value, 4);
2137 case BFD_RELOC_32_PCREL:
2138 case BFD_RELOC_32_BASEREL:
2139 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2141 md_number_to_chars (where, value, 4);
2143 case BFD_RELOC_32_GOT_PCREL:
2144 case BFD_RELOC_390_PLTOFF32:
2145 case BFD_RELOC_390_PLT32:
2146 case BFD_RELOC_390_GOTPLT32:
2148 md_number_to_chars (where, value, 4);
2150 case BFD_RELOC_390_PC32DBL:
2151 case BFD_RELOC_390_PLT32DBL:
2152 case BFD_RELOC_390_GOTPCDBL:
2153 case BFD_RELOC_390_GOTENT:
2154 case BFD_RELOC_390_GOTPLTENT:
2157 md_number_to_chars (where, (offsetT) value >> 1, 4);
2160 case BFD_RELOC_32_GOTOFF:
2162 md_number_to_chars (where, value, sizeof (int));
2165 case BFD_RELOC_390_GOTOFF64:
2167 md_number_to_chars (where, value, 8);
2170 case BFD_RELOC_390_GOT64:
2171 case BFD_RELOC_390_PLTOFF64:
2172 case BFD_RELOC_390_PLT64:
2173 case BFD_RELOC_390_GOTPLT64:
2175 md_number_to_chars (where, value, 8);
2180 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2182 fixP->fx_r_type = BFD_RELOC_64;
2184 md_number_to_chars (where, value, 8);
2187 case BFD_RELOC_64_PCREL:
2188 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2190 md_number_to_chars (where, value, 8);
2193 case BFD_RELOC_VTABLE_INHERIT:
2194 case BFD_RELOC_VTABLE_ENTRY:
2198 case BFD_RELOC_390_TLS_LOAD:
2199 case BFD_RELOC_390_TLS_GDCALL:
2200 case BFD_RELOC_390_TLS_LDCALL:
2201 case BFD_RELOC_390_TLS_GD32:
2202 case BFD_RELOC_390_TLS_GD64:
2203 case BFD_RELOC_390_TLS_GOTIE12:
2204 case BFD_RELOC_390_TLS_GOTIE20:
2205 case BFD_RELOC_390_TLS_GOTIE32:
2206 case BFD_RELOC_390_TLS_GOTIE64:
2207 case BFD_RELOC_390_TLS_LDM32:
2208 case BFD_RELOC_390_TLS_LDM64:
2209 case BFD_RELOC_390_TLS_IE32:
2210 case BFD_RELOC_390_TLS_IE64:
2211 case BFD_RELOC_390_TLS_LE32:
2212 case BFD_RELOC_390_TLS_LE64:
2213 case BFD_RELOC_390_TLS_LDO32:
2214 case BFD_RELOC_390_TLS_LDO64:
2215 case BFD_RELOC_390_TLS_DTPMOD:
2216 case BFD_RELOC_390_TLS_DTPOFF:
2217 case BFD_RELOC_390_TLS_TPOFF:
2218 S_SET_THREAD_LOCAL (fixP->fx_addsy);
2219 /* Fully resolved at link time. */
2221 case BFD_RELOC_390_TLS_IEENT:
2222 /* Fully resolved at link time. */
2223 S_SET_THREAD_LOCAL (fixP->fx_addsy);
2229 const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
2231 if (reloc_name != NULL)
2232 fprintf (stderr, "Gas failure, reloc type %s\n", reloc_name);
2234 fprintf (stderr, "Gas failure, reloc type #%i\n", fixP->fx_r_type);
2240 fixP->fx_offset = value;
2244 /* Generate a reloc for a fixup. */
2247 tc_gen_reloc (seg, fixp)
2248 asection *seg ATTRIBUTE_UNUSED;
2251 bfd_reloc_code_real_type code;
2254 code = fixp->fx_r_type;
2255 if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
2257 if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
2258 || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
2259 code = BFD_RELOC_390_GOTPC;
2260 if (code == BFD_RELOC_390_PC32DBL)
2261 code = BFD_RELOC_390_GOTPCDBL;
2264 reloc = (arelent *) xmalloc (sizeof (arelent));
2265 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2266 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2267 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2268 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2269 if (reloc->howto == NULL)
2271 as_bad_where (fixp->fx_file, fixp->fx_line,
2272 _("cannot represent relocation type %s"),
2273 bfd_get_reloc_code_name (code));
2274 /* Set howto to a garbage value so that we can keep going. */
2275 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2276 assert (reloc->howto != NULL);
2278 reloc->addend = fixp->fx_offset;
2284 s390_cfi_frame_initial_instructions ()
2286 cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96);
2290 tc_s390_regname_to_dw2regnum (const char *regname)
2294 if (regname[0] != 'c' && regname[0] != 'a')
2296 regnum = reg_name_search (pre_defined_registers, REG_NAME_CNT, regname);
2297 if (regname[0] == 'f' && regnum != -1)
2300 else if (strcmp (regname, "ap") == 0)
2302 else if (strcmp (regname, "cc") == 0)