1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010 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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "safe-ctype.h"
26 #include "struc-symbol.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "opcode/s390.h"
33 /* The default architecture. */
35 #define DEFAULT_ARCH "s390"
37 static char *default_arch = DEFAULT_ARCH;
38 /* Either 32 or 64, selects file format. */
39 static int s390_arch_size = 0;
41 /* If no -march option was given default to the highest available CPU.
42 Since with S/390 a newer CPU always supports everything from its
43 predecessors this will accept every valid asm input. */
44 static unsigned int current_cpu = S390_OPCODE_MAXCPU - 1;
45 static unsigned int current_mode_mask = 0;
47 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
48 for the output file. */
49 static bfd_boolean set_highgprs_p = FALSE;
51 /* Whether to use user friendly register names. Default is TRUE. */
52 #ifndef TARGET_REG_NAMES_P
53 #define TARGET_REG_NAMES_P TRUE
56 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
58 /* Set to TRUE if we want to warn about zero base/index registers. */
59 static bfd_boolean warn_areg_zero = FALSE;
61 /* Generic assembler global variables which must be defined by all
64 const char comment_chars[] = "#";
66 /* Characters which start a comment at the beginning of a line. */
67 const char line_comment_chars[] = "#";
69 /* Characters which may be used to separate multiple commands on a
71 const char line_separator_chars[] = ";";
73 /* Characters which are used to indicate an exponent in a floating
75 const char EXP_CHARS[] = "eE";
77 /* Characters which mean that a number is a floating point constant,
79 const char FLT_CHARS[] = "dD";
81 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
82 int s390_cie_data_alignment;
84 /* The target specific pseudo-ops which we support. */
86 /* Define the prototypes for the pseudo-ops */
87 static void s390_byte (int);
88 static void s390_elf_cons (int);
89 static void s390_bss (int);
90 static void s390_insn (int);
91 static void s390_literals (int);
92 static void s390_machine (int);
93 static void s390_machinemode (int);
95 const pseudo_typeS md_pseudo_table[] =
97 { "align", s_align_bytes, 0 },
98 /* Pseudo-ops which must be defined. */
99 { "bss", s390_bss, 0 },
100 { "insn", s390_insn, 0 },
101 /* Pseudo-ops which must be overridden. */
102 { "byte", s390_byte, 0 },
103 { "short", s390_elf_cons, 2 },
104 { "long", s390_elf_cons, 4 },
105 { "quad", s390_elf_cons, 8 },
106 { "ltorg", s390_literals, 0 },
107 { "string", stringer, 8 + 1 },
108 { "machine", s390_machine, 0 },
109 { "machinemode", s390_machinemode, 0 },
114 /* Structure to hold information about predefined registers. */
121 /* List of registers that are pre-defined:
123 Each access register has a predefined name of the form:
124 a<reg_num> which has the value <reg_num>.
126 Each control register has a predefined name of the form:
127 c<reg_num> which has the value <reg_num>.
129 Each general register has a predefined name of the form:
130 r<reg_num> which has the value <reg_num>.
132 Each floating point register a has predefined name of the form:
133 f<reg_num> which has the value <reg_num>.
135 There are individual registers as well:
139 The table is sorted. Suitable for searching by a binary search. */
141 static const struct pd_reg pre_defined_registers[] =
143 { "a0", 0 }, /* Access registers */
160 { "c0", 0 }, /* Control registers */
177 { "f0", 0 }, /* Floating point registers */
194 { "lit", 13 }, /* Pointer to literal pool */
196 { "r0", 0 }, /* General purpose registers */
213 { "sp", 15 }, /* Stack pointer */
217 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
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 (const struct pd_reg *regs, int regcount, const char *name)
225 int middle, low, high;
233 middle = (low + high) / 2;
234 cmp = strcasecmp (name, regs[middle].name);
240 return regs[middle].value;
249 * Summary of register_name().
251 * in: Input_line_pointer points to 1st char of operand.
253 * out: A expressionS.
254 * The operand may have been a register: in this case, X_op == O_register,
255 * X_add_number is set to the register number, and truth is returned.
256 * Input_line_pointer->(next non-blank) char after operand, or is in its
261 register_name (expressionS *expressionP)
268 /* Find the spelling of the operand. */
269 start = name = input_line_pointer;
270 if (name[0] == '%' && ISALPHA (name[1]))
271 name = ++input_line_pointer;
275 c = get_symbol_end ();
276 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
278 /* Put back the delimiting char. */
279 *input_line_pointer = c;
281 /* Look to see if it's in the register table. */
284 expressionP->X_op = O_register;
285 expressionP->X_add_number = reg_number;
287 /* Make the rest nice. */
288 expressionP->X_add_symbol = NULL;
289 expressionP->X_op_symbol = NULL;
293 /* Reset the line as if we had not done anything. */
294 input_line_pointer = start;
298 /* Local variables. */
300 /* Opformat hash table. */
301 static struct hash_control *s390_opformat_hash;
303 /* Opcode hash table. */
304 static struct hash_control *s390_opcode_hash = NULL;
306 /* Flags to set in the elf header */
307 static flagword s390_flags = 0;
309 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
311 #ifndef WORKING_DOT_WORD
312 int md_short_jump_size = 4;
313 int md_long_jump_size = 4;
316 const char *md_shortopts = "A:m:kVQ:";
317 struct option md_longopts[] = {
318 {NULL, no_argument, NULL, 0}
320 size_t md_longopts_size = sizeof (md_longopts);
322 /* Initialize the default opcode arch and word size from the default
323 architecture name if not specified by an option. */
325 init_default_arch (void)
327 if (strcmp (default_arch, "s390") == 0)
329 if (s390_arch_size == 0)
332 else if (strcmp (default_arch, "s390x") == 0)
334 if (s390_arch_size == 0)
338 as_fatal (_("Invalid default architecture, broken assembler."));
340 if (current_mode_mask == 0)
342 /* Default to z/Architecture mode if the CPU supports it. */
343 if (current_cpu < S390_OPCODE_Z900)
344 current_mode_mask = 1 << S390_OPCODE_ESA;
346 current_mode_mask = 1 << S390_OPCODE_ZARCH;
350 /* Called by TARGET_FORMAT. */
352 s390_target_format (void)
354 /* We don't get a chance to initialize anything before we're called,
355 so handle that now. */
356 init_default_arch ();
358 return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
361 /* Map a CPU string as given with -march= or .machine to the
362 respective enum s390_opcode_cpu_val value. 0xffffffff is returned
363 in case of an error. */
366 s390_parse_cpu (char *arg)
368 if (strcmp (arg, "g5") == 0)
369 return S390_OPCODE_G5;
370 else if (strcmp (arg, "g6") == 0)
371 return S390_OPCODE_G6;
372 else if (strcmp (arg, "z900") == 0)
373 return S390_OPCODE_Z900;
374 else if (strcmp (arg, "z990") == 0)
375 return S390_OPCODE_Z990;
376 else if (strcmp (arg, "z9-109") == 0)
377 return S390_OPCODE_Z9_109;
378 else if (strcmp (arg, "z9-ec") == 0)
379 return S390_OPCODE_Z9_EC;
380 else if (strcmp (arg, "z10") == 0)
381 return S390_OPCODE_Z10;
382 else if (strcmp (arg, "z196") == 0)
383 return S390_OPCODE_Z196;
384 else if (strcmp (arg, "all") == 0)
385 return S390_OPCODE_MAXCPU - 1;
391 md_parse_option (int c, char *arg)
395 /* -k: Ignore for FreeBSD compatibility. */
399 if (arg != NULL && strcmp (arg, "regnames") == 0)
402 else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
405 else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
406 warn_areg_zero = TRUE;
408 else if (arg != NULL && strcmp (arg, "31") == 0)
411 else if (arg != NULL && strcmp (arg, "64") == 0)
414 else if (arg != NULL && strcmp (arg, "esa") == 0)
415 current_mode_mask = 1 << S390_OPCODE_ESA;
417 else if (arg != NULL && strcmp (arg, "zarch") == 0)
419 if (s390_arch_size == 32)
420 set_highgprs_p = TRUE;
421 current_mode_mask = 1 << S390_OPCODE_ZARCH;
424 else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
426 current_cpu = s390_parse_cpu (arg + 5);
428 if (current_cpu == (unsigned int)-1)
430 as_bad (_("invalid switch -m%s"), arg);
437 as_bad (_("invalid switch -m%s"), arg);
443 /* Option -A is deprecated. Still available for compatibility. */
444 if (arg != NULL && strcmp (arg, "esa") == 0)
445 current_cpu = S390_OPCODE_G5;
446 else if (arg != NULL && strcmp (arg, "esame") == 0)
447 current_cpu = S390_OPCODE_Z900;
449 as_bad (_("invalid architecture -A%s"), arg);
452 /* -V: SVR4 argument to print version ID. */
457 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
458 should be emitted or not. FIXME: Not implemented. */
470 md_show_usage (FILE *stream)
472 fprintf (stream, _("\
474 -mregnames Allow symbolic names for registers\n\
475 -mwarn-areg-zero Warn about zero base/index registers\n\
476 -mno-regnames Do not allow symbolic names for registers\n\
477 -m31 Set file format to 31 bit format\n\
478 -m64 Set file format to 64 bit format\n"));
479 fprintf (stream, _("\
480 -V print assembler version number\n\
481 -Qy, -Qn ignored\n"));
484 /* Generate the hash table mapping mnemonics to struct s390_opcode.
485 This table is built at startup and whenever the CPU level is
486 changed using .machine. */
489 s390_setup_opcodes (void)
491 register const struct s390_opcode *op;
492 const struct s390_opcode *op_end;
493 bfd_boolean dup_insn = FALSE;
496 if (s390_opcode_hash != NULL)
497 hash_die (s390_opcode_hash);
499 /* Insert the opcodes into a hash table. */
500 s390_opcode_hash = hash_new ();
502 op_end = s390_opcodes + s390_num_opcodes;
503 for (op = s390_opcodes; op < op_end; op++)
505 while (op < op_end - 1 && strcmp(op->name, op[1].name) == 0)
507 if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask))
512 if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask))
514 retval = hash_insert (s390_opcode_hash, op->name, (void *) op);
515 if (retval != (const char *) NULL)
517 as_bad (_("Internal assembler error for instruction %s"),
523 while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0)
531 /* This function is called when the assembler starts up. It is called
532 after the options have been parsed and the output file has been
538 register const struct s390_opcode *op;
539 const struct s390_opcode *op_end;
542 /* Give a warning if the combination -m64-bit and -Aesa is used. */
543 if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900)
544 as_warn (_("The 64 bit file format is used without esame instructions."));
546 s390_cie_data_alignment = -s390_arch_size / 8;
548 /* Set the ELF flags if desired. */
550 bfd_set_private_flags (stdoutput, s390_flags);
552 /* Insert the opcode formats into a hash table. */
553 s390_opformat_hash = hash_new ();
555 op_end = s390_opformats + s390_num_opformats;
556 for (op = s390_opformats; op < op_end; op++)
558 retval = hash_insert (s390_opformat_hash, op->name, (void *) op);
559 if (retval != (const char *) NULL)
560 as_bad (_("Internal assembler error for instruction format %s"),
564 s390_setup_opcodes ();
566 record_alignment (text_section, 2);
567 record_alignment (data_section, 2);
568 record_alignment (bss_section, 2);
571 /* Called after all assembly has been done. */
575 if (s390_arch_size == 64)
576 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
578 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
581 /* Insert an operand value into an instruction. */
584 s390_insert_operand (unsigned char *insn,
585 const struct s390_operand *operand,
593 if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
597 max = ((offsetT) 1 << (operand->bits - 1)) - 1;
598 min = - ((offsetT) 1 << (operand->bits - 1));
599 /* Halve PCREL operands. */
600 if (operand->flags & S390_OPERAND_PCREL)
602 /* Check for underflow / overflow. */
603 if (val < min || val > max)
606 _("operand out of range (%s not between %ld and %ld)");
609 if (operand->flags & S390_OPERAND_PCREL)
615 sprint_value (buf, val);
616 if (file == (char *) NULL)
617 as_bad (err, buf, (int) min, (int) max);
619 as_bad_where (file, line, err, buf, (int) min, (int) max);
622 /* val is ok, now restrict it to operand->bits bits. */
623 uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
624 /* val is restrict, now check for special case. */
625 if (operand->bits == 20 && operand->shift == 20)
626 uval = (uval >> 12) | ((uval & 0xfff) << 8);
632 max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
634 uval = (addressT) val;
635 /* Length x in an instructions has real length x+1. */
636 if (operand->flags & S390_OPERAND_LENGTH)
638 /* Check for underflow / overflow. */
639 if (uval < min || uval > max)
641 if (operand->flags & S390_OPERAND_LENGTH)
648 as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line);
654 /* Insert fragments of the operand byte for byte. */
655 offset = operand->shift + operand->bits;
656 uval <<= (-offset) & 7;
657 insn += (offset - 1) / 8;
669 bfd_reloc_code_real_type reloc;
672 /* Parse tls marker and return the desired relocation. */
673 static bfd_reloc_code_real_type
674 s390_tls_suffix (char **str_p, expressionS *exp_p)
676 static struct map_tls mapping[] =
678 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD },
679 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL },
680 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL },
681 { NULL, 0, BFD_RELOC_UNUSED }
691 return BFD_RELOC_UNUSED;
694 while (ISIDNUM (*str))
698 return BFD_RELOC_UNUSED;
700 orig_line = input_line_pointer;
701 input_line_pointer = str;
703 str = input_line_pointer;
704 if (&input_line_pointer != str_p)
705 input_line_pointer = orig_line;
707 if (exp_p->X_op != O_symbol)
708 return BFD_RELOC_UNUSED;
710 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
711 if (len == ptr->length
712 && strncasecmp (ident, ptr->string, ptr->length) == 0)
714 /* Found a matching tls suffix. */
718 return BFD_RELOC_UNUSED;
721 /* Structure used to hold suffixes. */
732 ELF_SUFFIX_TLS_GOTIE,
744 elf_suffix_type suffix;
748 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
749 static elf_suffix_type
750 s390_elf_suffix (char **str_p, expressionS *exp_p)
752 static struct map_bfd mapping[] =
754 { "got", 3, ELF_SUFFIX_GOT },
755 { "got12", 5, ELF_SUFFIX_GOT },
756 { "plt", 3, ELF_SUFFIX_PLT },
757 { "gotent", 6, ELF_SUFFIX_GOTENT },
758 { "gotoff", 6, ELF_SUFFIX_GOTOFF },
759 { "gotplt", 6, ELF_SUFFIX_GOTPLT },
760 { "pltoff", 6, ELF_SUFFIX_PLTOFF },
761 { "tlsgd", 5, ELF_SUFFIX_TLS_GD },
762 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE },
763 { "indntpoff", 9, ELF_SUFFIX_TLS_IE },
764 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM },
765 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO },
766 { "ntpoff", 6, ELF_SUFFIX_TLS_LE },
767 { NULL, 0, ELF_SUFFIX_NONE }
776 return ELF_SUFFIX_NONE;
779 while (ISALNUM (*str))
783 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
784 if (len == ptr->length
785 && strncasecmp (ident, ptr->string, ptr->length) == 0)
787 if (exp_p->X_add_number != 0)
788 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
789 ptr->string, ptr->string);
790 /* Now check for identifier@suffix+constant. */
791 if (*str == '-' || *str == '+')
793 char *orig_line = input_line_pointer;
796 input_line_pointer = str;
797 expression (&new_exp);
799 switch (new_exp.X_op)
801 case O_constant: /* X_add_number (a constant expression). */
802 exp_p->X_add_number += new_exp.X_add_number;
803 str = input_line_pointer;
805 case O_symbol: /* X_add_symbol + X_add_number. */
806 /* this case is used for e.g. xyz@PLT+.Label. */
807 exp_p->X_add_number += new_exp.X_add_number;
808 exp_p->X_op_symbol = new_exp.X_add_symbol;
810 str = input_line_pointer;
812 case O_uminus: /* (- X_add_symbol) + X_add_number. */
813 /* this case is used for e.g. xyz@PLT-.Label. */
814 exp_p->X_add_number += new_exp.X_add_number;
815 exp_p->X_op_symbol = new_exp.X_add_symbol;
816 exp_p->X_op = O_subtract;
817 str = input_line_pointer;
823 /* If s390_elf_suffix has not been called with
824 &input_line_pointer as first parameter, we have
825 clobbered the input_line_pointer. We have to
827 if (&input_line_pointer != str_p)
828 input_line_pointer = orig_line;
834 return BFD_RELOC_UNUSED;
837 /* Structure used to hold a literal pool entry. */
840 struct s390_lpe *next;
842 FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */
843 LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */
845 bfd_reloc_code_real_type reloc;
849 static struct s390_lpe *lpe_free_list = NULL;
850 static struct s390_lpe *lpe_list = NULL;
851 static struct s390_lpe *lpe_list_tail = NULL;
852 static symbolS *lp_sym = NULL;
853 static int lp_count = 0;
854 static int lpe_count = 0;
857 s390_exp_compare (expressionS *exp1, expressionS *exp2)
859 if (exp1->X_op != exp2->X_op)
864 case O_constant: /* X_add_number must be equal. */
866 return exp1->X_add_number == exp2->X_add_number;
869 as_bad (_("Can't handle O_big in s390_exp_compare"));
871 case O_symbol: /* X_add_symbol & X_add_number must be equal. */
876 return (exp1->X_add_symbol == exp2->X_add_symbol)
877 && (exp1->X_add_number == exp2->X_add_number);
879 case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
884 case O_bit_inclusive_or:
886 case O_bit_exclusive_or:
898 return (exp1->X_add_symbol == exp2->X_add_symbol)
899 && (exp1->X_op_symbol == exp2->X_op_symbol)
900 && (exp1->X_add_number == exp2->X_add_number);
906 /* Test for @lit and if its present make an entry in the literal pool and
907 modify the current expression to be an offset into the literal pool. */
908 static elf_suffix_type
909 s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix)
911 bfd_reloc_code_real_type reloc;
915 struct s390_lpe *lpe;
919 return suffix; /* No modification. */
921 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
923 while (ISALNUM (*str))
926 if (len != 4 || strncasecmp (ident, "lit", 3) != 0
927 || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
928 return suffix; /* no modification */
929 nbytes = ident[3] - '0';
931 reloc = BFD_RELOC_UNUSED;
932 if (suffix == ELF_SUFFIX_GOT)
935 reloc = BFD_RELOC_390_GOT16;
936 else if (nbytes == 4)
937 reloc = BFD_RELOC_32_GOT_PCREL;
938 else if (nbytes == 8)
939 reloc = BFD_RELOC_390_GOT64;
941 else if (suffix == ELF_SUFFIX_PLT)
944 reloc = BFD_RELOC_390_PLT32;
945 else if (nbytes == 8)
946 reloc = BFD_RELOC_390_PLT64;
949 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
950 as_bad (_("Invalid suffix for literal pool entry"));
952 /* Search the pool if the new entry is a duplicate. */
953 if (exp_p->X_op == O_big)
955 /* Special processing for big numbers. */
956 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
958 if (lpe->ex.X_op == O_big)
960 if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
962 if (memcmp (&generic_floating_point_number, &lpe->floatnum,
963 sizeof (FLONUM_TYPE)) == 0)
966 else if (exp_p->X_add_number == lpe->ex.X_add_number)
968 if (memcmp (generic_bignum, lpe->bignum,
969 sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
977 /* Processing for 'normal' data types. */
978 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
979 if (lpe->nbytes == nbytes && lpe->reloc == reloc
980 && s390_exp_compare (exp_p, &lpe->ex) != 0)
987 if (lpe_free_list != NULL)
990 lpe_free_list = lpe_free_list->next;
994 lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe));
999 if (exp_p->X_op == O_big)
1001 if (exp_p->X_add_number <= 0)
1002 lpe->floatnum = generic_floating_point_number;
1003 else if (exp_p->X_add_number <= 4)
1004 memcpy (lpe->bignum, generic_bignum,
1005 exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
1007 as_bad (_("Big number is too big"));
1010 lpe->nbytes = nbytes;
1012 /* Literal pool name defined ? */
1015 sprintf (tmp_name, ".L\001%i", lp_count);
1016 lp_sym = symbol_make (tmp_name);
1019 /* Make name for literal pool entry. */
1020 sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
1022 lpe->sym = symbol_make (tmp_name);
1024 /* Add to literal pool list. */
1026 if (lpe_list_tail != NULL)
1028 lpe_list_tail->next = lpe;
1029 lpe_list_tail = lpe;
1032 lpe_list = lpe_list_tail = lpe;
1035 /* Now change exp_p to the offset into the literal pool.
1036 Thats the expression: .L^Ax^By-.L^Ax */
1037 exp_p->X_add_symbol = lpe->sym;
1038 exp_p->X_op_symbol = lp_sym;
1039 exp_p->X_op = O_subtract;
1040 exp_p->X_add_number = 0;
1044 /* We change the suffix type to ELF_SUFFIX_NONE, because
1045 the difference of two local labels is just a number. */
1046 return ELF_SUFFIX_NONE;
1049 /* Like normal .long/.short/.word, except support @got, etc.
1050 clobbers input_line_pointer, checks end-of-line. */
1052 s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */)
1055 elf_suffix_type suffix;
1057 if (is_it_end_of_statement ())
1059 demand_empty_rest_of_line ();
1067 if (exp.X_op == O_symbol
1068 && *input_line_pointer == '@'
1069 && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
1071 bfd_reloc_code_real_type reloc;
1072 reloc_howto_type *reloc_howto;
1078 static bfd_reloc_code_real_type tab2[] =
1080 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1081 BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */
1082 BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */
1083 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1084 BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1085 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */
1086 BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */
1087 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */
1088 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */
1089 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */
1090 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */
1091 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */
1092 BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */
1094 reloc = tab2[suffix];
1096 else if (nbytes == 4)
1098 static bfd_reloc_code_real_type tab4[] =
1100 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1101 BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */
1102 BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */
1103 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1104 BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1105 BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */
1106 BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */
1107 BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */
1108 BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */
1109 BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */
1110 BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */
1111 BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */
1112 BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */
1114 reloc = tab4[suffix];
1116 else if (nbytes == 8)
1118 static bfd_reloc_code_real_type tab8[] =
1120 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1121 BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */
1122 BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */
1123 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1124 BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */
1125 BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */
1126 BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */
1127 BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */
1128 BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */
1129 BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */
1130 BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */
1131 BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */
1132 BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */
1134 reloc = tab8[suffix];
1137 reloc = BFD_RELOC_UNUSED;
1139 if (reloc != BFD_RELOC_UNUSED
1140 && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc)))
1142 size = bfd_get_reloc_size (reloc_howto);
1144 as_bad (_("%s relocations do not fit in %d bytes"),
1145 reloc_howto->name, nbytes);
1146 where = frag_more (nbytes);
1147 md_number_to_chars (where, 0, size);
1148 /* To make fixup_segment do the pc relative conversion the
1149 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1150 fix_new_exp (frag_now, where - frag_now->fr_literal,
1151 size, &exp, FALSE, reloc);
1154 as_bad (_("relocation not applicable"));
1157 emit_expr (&exp, (unsigned int) nbytes);
1159 while (*input_line_pointer++ == ',');
1161 input_line_pointer--; /* Put terminator back into stream. */
1162 demand_empty_rest_of_line ();
1165 /* We need to keep a list of fixups. We can't simply generate them as
1166 we go, because that would require us to first create the frag, and
1167 that would screw up references to ``.''. */
1173 bfd_reloc_code_real_type reloc;
1176 #define MAX_INSN_FIXUPS (4)
1178 /* This routine is called for each instruction to be assembled. */
1181 md_gather_operands (char *str,
1182 unsigned char *insn,
1183 const struct s390_opcode *opcode)
1185 struct s390_fixup fixups[MAX_INSN_FIXUPS];
1186 const struct s390_operand *operand;
1187 const unsigned char *opindex_ptr;
1189 elf_suffix_type suffix;
1190 bfd_reloc_code_real_type reloc;
1195 while (ISSPACE (*str))
1200 /* Gather the operands. */
1202 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1206 operand = s390_operands + *opindex_ptr;
1208 if (skip_optional && (operand->flags & S390_OPERAND_INDEX))
1210 /* We do an early skip. For D(X,B) constructions the index
1211 register is skipped (X is optional). For D(L,B) the base
1212 register will be the skipped operand, because L is NOT
1218 /* Gather the operand. */
1219 hold = input_line_pointer;
1220 input_line_pointer = str;
1222 /* Parse the operand. */
1223 if (! register_name (&ex))
1226 str = input_line_pointer;
1227 input_line_pointer = hold;
1229 /* Write the operand to the insn. */
1230 if (ex.X_op == O_illegal)
1231 as_bad (_("illegal operand"));
1232 else if (ex.X_op == O_absent)
1234 /* No operands, check if all operands can be skipped. */
1235 while (*opindex_ptr != 0 && operand->flags & S390_OPERAND_OPTIONAL)
1237 if (operand->flags & S390_OPERAND_DISP)
1239 /* An optional displacement makes the whole D(X,B)
1240 D(L,B) or D(B) block optional. */
1242 operand = s390_operands + *(++opindex_ptr);
1243 } while (!(operand->flags & S390_OPERAND_BASE));
1245 operand = s390_operands + *(++opindex_ptr);
1247 if (opindex_ptr[0] == '\0')
1249 as_bad (_("missing operand"));
1251 else if (ex.X_op == O_register || ex.X_op == O_constant)
1253 s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
1255 if (ex.X_op != O_register && ex.X_op != O_constant)
1257 /* We need to generate a fixup for the
1258 expression returned by s390_lit_suffix. */
1259 if (fc >= MAX_INSN_FIXUPS)
1260 as_fatal (_("too many fixups"));
1261 fixups[fc].exp = ex;
1262 fixups[fc].opindex = *opindex_ptr;
1263 fixups[fc].reloc = BFD_RELOC_UNUSED;
1268 if ((operand->flags & S390_OPERAND_INDEX)
1269 && ex.X_add_number == 0
1271 as_warn (_("index register specified but zero"));
1272 if ((operand->flags & S390_OPERAND_BASE)
1273 && ex.X_add_number == 0
1275 as_warn (_("base register specified but zero"));
1276 if ((operand->flags & S390_OPERAND_GPR)
1277 && (operand->flags & S390_OPERAND_REG_PAIR)
1278 && (ex.X_add_number & 1))
1279 as_fatal (_("odd numbered general purpose register specified as "
1281 if ((operand->flags & S390_OPERAND_FPR)
1282 && (operand->flags & S390_OPERAND_REG_PAIR)
1283 && ex.X_add_number != 0 && ex.X_add_number != 1
1284 && ex.X_add_number != 4 && ex.X_add_number != 5
1285 && ex.X_add_number != 8 && ex.X_add_number != 9
1286 && ex.X_add_number != 12 && ex.X_add_number != 13)
1287 as_fatal (_("invalid floating point register pair. Valid fp "
1288 "register pair operands are 0, 1, 4, 5, 8, 9, "
1290 s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0);
1295 suffix = s390_elf_suffix (&str, &ex);
1296 suffix = s390_lit_suffix (&str, &ex, suffix);
1297 reloc = BFD_RELOC_UNUSED;
1299 if (suffix == ELF_SUFFIX_GOT)
1301 if ((operand->flags & S390_OPERAND_DISP) &&
1302 (operand->bits == 12))
1303 reloc = BFD_RELOC_390_GOT12;
1304 else if ((operand->flags & S390_OPERAND_DISP) &&
1305 (operand->bits == 20))
1306 reloc = BFD_RELOC_390_GOT20;
1307 else if ((operand->flags & S390_OPERAND_SIGNED)
1308 && (operand->bits == 16))
1309 reloc = BFD_RELOC_390_GOT16;
1310 else if ((operand->flags & S390_OPERAND_PCREL)
1311 && (operand->bits == 32))
1312 reloc = BFD_RELOC_390_GOTENT;
1314 else if (suffix == ELF_SUFFIX_PLT)
1316 if ((operand->flags & S390_OPERAND_PCREL)
1317 && (operand->bits == 16))
1318 reloc = BFD_RELOC_390_PLT16DBL;
1319 else if ((operand->flags & S390_OPERAND_PCREL)
1320 && (operand->bits == 32))
1321 reloc = BFD_RELOC_390_PLT32DBL;
1323 else if (suffix == ELF_SUFFIX_GOTENT)
1325 if ((operand->flags & S390_OPERAND_PCREL)
1326 && (operand->bits == 32))
1327 reloc = BFD_RELOC_390_GOTENT;
1329 else if (suffix == ELF_SUFFIX_GOTOFF)
1331 if ((operand->flags & S390_OPERAND_SIGNED)
1332 && (operand->bits == 16))
1333 reloc = BFD_RELOC_16_GOTOFF;
1335 else if (suffix == ELF_SUFFIX_PLTOFF)
1337 if ((operand->flags & S390_OPERAND_SIGNED)
1338 && (operand->bits == 16))
1339 reloc = BFD_RELOC_390_PLTOFF16;
1341 else if (suffix == ELF_SUFFIX_GOTPLT)
1343 if ((operand->flags & S390_OPERAND_DISP)
1344 && (operand->bits == 12))
1345 reloc = BFD_RELOC_390_GOTPLT12;
1346 else if ((operand->flags & S390_OPERAND_SIGNED)
1347 && (operand->bits == 16))
1348 reloc = BFD_RELOC_390_GOTPLT16;
1349 else if ((operand->flags & S390_OPERAND_PCREL)
1350 && (operand->bits == 32))
1351 reloc = BFD_RELOC_390_GOTPLTENT;
1353 else if (suffix == ELF_SUFFIX_TLS_GOTIE)
1355 if ((operand->flags & S390_OPERAND_DISP)
1356 && (operand->bits == 12))
1357 reloc = BFD_RELOC_390_TLS_GOTIE12;
1358 else if ((operand->flags & S390_OPERAND_DISP)
1359 && (operand->bits == 20))
1360 reloc = BFD_RELOC_390_TLS_GOTIE20;
1362 else if (suffix == ELF_SUFFIX_TLS_IE)
1364 if ((operand->flags & S390_OPERAND_PCREL)
1365 && (operand->bits == 32))
1366 reloc = BFD_RELOC_390_TLS_IEENT;
1369 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1370 as_bad (_("invalid operand suffix"));
1371 /* We need to generate a fixup of type 'reloc' for this
1373 if (fc >= MAX_INSN_FIXUPS)
1374 as_fatal (_("too many fixups"));
1375 fixups[fc].exp = ex;
1376 fixups[fc].opindex = *opindex_ptr;
1377 fixups[fc].reloc = reloc;
1381 /* Check the next character. The call to expression has advanced
1382 str past any whitespace. */
1383 if (operand->flags & S390_OPERAND_DISP)
1385 /* After a displacement a block in parentheses can start. */
1388 /* Check if parenthesized block can be skipped. If the next
1389 operand is neiter an optional operand nor a base register
1390 then we have a syntax error. */
1391 operand = s390_operands + *(++opindex_ptr);
1392 if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
1393 as_bad (_("syntax error; missing '(' after displacement"));
1395 /* Ok, skip all operands until S390_OPERAND_BASE. */
1396 while (!(operand->flags & S390_OPERAND_BASE))
1397 operand = s390_operands + *(++opindex_ptr);
1399 /* If there is a next operand it must be separated by a comma. */
1400 if (opindex_ptr[1] != '\0')
1404 while (opindex_ptr[1] != '\0')
1406 operand = s390_operands + *(++opindex_ptr);
1407 if (operand->flags & S390_OPERAND_OPTIONAL)
1409 as_bad (_("syntax error; expected ,"));
1419 /* We found an opening parentheses. */
1421 for (f = str; *f != '\0'; f++)
1422 if (*f == ',' || *f == ')')
1424 /* If there is no comma until the closing parentheses OR
1425 there is a comma right after the opening parentheses,
1426 we have to skip optional operands. */
1427 if (*f == ',' && f == str)
1429 /* comma directly after '(' ? */
1434 skip_optional = (*f != ',');
1437 else if (operand->flags & S390_OPERAND_BASE)
1439 /* After the base register the parenthesed block ends. */
1441 as_bad (_("syntax error; missing ')' after base register"));
1443 /* If there is a next operand it must be separated by a comma. */
1444 if (opindex_ptr[1] != '\0')
1448 while (opindex_ptr[1] != '\0')
1450 operand = s390_operands + *(++opindex_ptr);
1451 if (operand->flags & S390_OPERAND_OPTIONAL)
1453 as_bad (_("syntax error; expected ,"));
1463 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1464 of D(L,B). In this case the base register has to be skipped. */
1467 operand = s390_operands + *(++opindex_ptr);
1469 if (!(operand->flags & S390_OPERAND_BASE))
1470 as_bad (_("syntax error; ')' not allowed here"));
1473 /* If there is a next operand it must be separated by a comma. */
1474 if (opindex_ptr[1] != '\0')
1478 while (opindex_ptr[1] != '\0')
1480 operand = s390_operands + *(++opindex_ptr);
1481 if (operand->flags & S390_OPERAND_OPTIONAL)
1483 as_bad (_("syntax error; expected ,"));
1493 while (ISSPACE (*str))
1496 /* Check for tls instruction marker. */
1497 reloc = s390_tls_suffix (&str, &ex);
1498 if (reloc != BFD_RELOC_UNUSED)
1500 /* We need to generate a fixup of type 'reloc' for this
1502 if (fc >= MAX_INSN_FIXUPS)
1503 as_fatal (_("too many fixups"));
1504 fixups[fc].exp = ex;
1505 fixups[fc].opindex = -1;
1506 fixups[fc].reloc = reloc;
1514 if ((linefeed = strchr (str, '\n')) != NULL)
1516 as_bad (_("junk at end of line: `%s'"), str);
1517 if (linefeed != NULL)
1521 /* Write out the instruction. */
1522 f = frag_more (opcode->oplen);
1523 memcpy (f, insn, opcode->oplen);
1524 dwarf2_emit_insn (opcode->oplen);
1526 /* Create any fixups. At this point we do not use a
1527 bfd_reloc_code_real_type, but instead just use the
1528 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1529 handle fixups for any operand type, although that is admittedly
1530 not a very exciting feature. We pick a BFD reloc type in
1532 for (i = 0; i < fc; i++)
1535 if (fixups[i].opindex < 0)
1537 /* Create tls instruction marker relocation. */
1538 fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen,
1539 &fixups[i].exp, 0, fixups[i].reloc);
1543 operand = s390_operands + fixups[i].opindex;
1545 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1547 reloc_howto_type *reloc_howto;
1551 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1555 size = bfd_get_reloc_size (reloc_howto);
1557 if (size < 1 || size > 4)
1560 fixP = fix_new_exp (frag_now,
1561 f - frag_now->fr_literal + (operand->shift/8),
1562 size, &fixups[i].exp, reloc_howto->pc_relative,
1564 /* Turn off overflow checking in fixup_segment. This is necessary
1565 because fixup_segment will signal an overflow for large 4 byte
1566 quantities for GOT12 relocations. */
1567 if ( fixups[i].reloc == BFD_RELOC_390_GOT12
1568 || fixups[i].reloc == BFD_RELOC_390_GOT20
1569 || fixups[i].reloc == BFD_RELOC_390_GOT16)
1570 fixP->fx_no_overflow = 1;
1573 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp,
1574 (operand->flags & S390_OPERAND_PCREL) != 0,
1575 ((bfd_reloc_code_real_type)
1576 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1581 /* This routine is called for each instruction to be assembled. */
1584 md_assemble (char *str)
1586 const struct s390_opcode *opcode;
1587 unsigned char insn[6];
1590 /* Get the opcode. */
1591 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1596 /* Look up the opcode in the hash table. */
1597 opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str);
1598 if (opcode == (const struct s390_opcode *) NULL)
1600 as_bad (_("Unrecognized opcode: `%s'"), str);
1603 else if (!(opcode->modes & current_mode_mask))
1605 as_bad (_("Opcode %s not available in this mode"), str);
1608 memcpy (insn, opcode->opcode, sizeof (insn));
1609 md_gather_operands (s, insn, opcode);
1612 #ifndef WORKING_DOT_WORD
1613 /* Handle long and short jumps. We don't support these */
1615 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1617 addressT from_addr, to_addr;
1625 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1627 addressT from_addr, to_addr;
1636 s390_bss (int ignore ATTRIBUTE_UNUSED)
1638 /* We don't support putting frags in the BSS segment, we fake it
1639 by marking in_bss, then looking at s_skip for clues. */
1641 subseg_set (bss_section, 0);
1642 demand_empty_rest_of_line ();
1645 /* Pseudo-op handling. */
1648 s390_insn (int ignore ATTRIBUTE_UNUSED)
1651 const struct s390_opcode *opformat;
1652 unsigned char insn[6];
1655 /* Get the opcode format. */
1656 s = input_line_pointer;
1657 while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
1660 as_bad (_("Invalid .insn format\n"));
1663 /* Look up the opcode in the hash table. */
1664 opformat = (struct s390_opcode *)
1665 hash_find (s390_opformat_hash, input_line_pointer);
1666 if (opformat == (const struct s390_opcode *) NULL)
1668 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
1671 input_line_pointer = s;
1673 if (exp.X_op == O_constant)
1675 if ( ( opformat->oplen == 6
1676 && (addressT) exp.X_add_number < (1ULL << 48))
1677 || ( opformat->oplen == 4
1678 && (addressT) exp.X_add_number < (1ULL << 32))
1679 || ( opformat->oplen == 2
1680 && (addressT) exp.X_add_number < (1ULL << 16)))
1681 md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen);
1683 as_bad (_("Invalid .insn format\n"));
1685 else if (exp.X_op == O_big)
1687 if (exp.X_add_number > 0
1688 && opformat->oplen == 6
1689 && generic_bignum[3] == 0)
1691 md_number_to_chars ((char *) insn, generic_bignum[2], 2);
1692 md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2);
1693 md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2);
1696 as_bad (_("Invalid .insn format\n"));
1699 as_bad (_("second operand of .insn not a constant\n"));
1701 if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
1702 as_bad (_("missing comma after insn constant\n"));
1704 if ((s = strchr (input_line_pointer, '\n')) != NULL)
1706 input_line_pointer = md_gather_operands (input_line_pointer, insn,
1710 demand_empty_rest_of_line ();
1713 /* The .byte pseudo-op. This is similar to the normal .byte
1714 pseudo-op, but it can also take a single ASCII string. */
1717 s390_byte (int ignore ATTRIBUTE_UNUSED)
1719 if (*input_line_pointer != '\"')
1725 /* Gather characters. A real double quote is doubled. Unusual
1726 characters are not permitted. */
1727 ++input_line_pointer;
1732 c = *input_line_pointer++;
1736 if (*input_line_pointer != '\"')
1738 ++input_line_pointer;
1741 FRAG_APPEND_1_CHAR (c);
1744 demand_empty_rest_of_line ();
1747 /* The .ltorg pseudo-op.This emits all literals defined since the last
1748 .ltorg or the invocation of gas. Literals are defined with the
1752 s390_literals (int ignore ATTRIBUTE_UNUSED)
1754 struct s390_lpe *lpe;
1756 if (lp_sym == NULL || lpe_count == 0)
1757 return; /* Nothing to be done. */
1759 /* Emit symbol for start of literal pool. */
1760 S_SET_SEGMENT (lp_sym, now_seg);
1761 S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
1762 lp_sym->sy_frag = frag_now;
1767 lpe_list = lpe_list->next;
1768 S_SET_SEGMENT (lpe->sym, now_seg);
1769 S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
1770 lpe->sym->sy_frag = frag_now;
1772 /* Emit literal pool entry. */
1773 if (lpe->reloc != BFD_RELOC_UNUSED)
1775 reloc_howto_type *reloc_howto =
1776 bfd_reloc_type_lookup (stdoutput, lpe->reloc);
1777 int size = bfd_get_reloc_size (reloc_howto);
1780 if (size > lpe->nbytes)
1781 as_bad (_("%s relocations do not fit in %d bytes"),
1782 reloc_howto->name, lpe->nbytes);
1783 where = frag_more (lpe->nbytes);
1784 md_number_to_chars (where, 0, size);
1785 fix_new_exp (frag_now, where - frag_now->fr_literal,
1786 size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
1790 if (lpe->ex.X_op == O_big)
1792 if (lpe->ex.X_add_number <= 0)
1793 generic_floating_point_number = lpe->floatnum;
1795 memcpy (generic_bignum, lpe->bignum,
1796 lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
1798 emit_expr (&lpe->ex, lpe->nbytes);
1801 lpe->next = lpe_free_list;
1802 lpe_free_list = lpe;
1804 lpe_list_tail = NULL;
1810 /* The .machine pseudo op allows to switch to a different CPU level in
1811 the asm listing. The current CPU setting can be stored on a stack
1812 with .machine push and restored with .machine pop. */
1815 s390_machine (int ignore ATTRIBUTE_UNUSED)
1818 #define MAX_HISTORY 100
1819 static unsigned int *cpu_history;
1820 static int curr_hist;
1824 if (*input_line_pointer == '"')
1827 cpu_string = demand_copy_C_string (&len);
1832 cpu_string = input_line_pointer;
1833 c = get_symbol_end ();
1834 cpu_string = xstrdup (cpu_string);
1835 *input_line_pointer = c;
1838 if (cpu_string != NULL)
1840 unsigned int old_cpu = current_cpu;
1841 unsigned int new_cpu;
1844 for (p = cpu_string; *p != 0; p++)
1847 if (strcmp (cpu_string, "push") == 0)
1849 if (cpu_history == NULL)
1850 cpu_history = xmalloc (MAX_HISTORY * sizeof (*cpu_history));
1852 if (curr_hist >= MAX_HISTORY)
1853 as_bad (_(".machine stack overflow"));
1855 cpu_history[curr_hist++] = current_cpu;
1857 else if (strcmp (cpu_string, "pop") == 0)
1860 as_bad (_(".machine stack underflow"));
1862 current_cpu = cpu_history[--curr_hist];
1864 else if ((new_cpu = s390_parse_cpu (cpu_string)) != (unsigned int)-1)
1865 current_cpu = new_cpu;
1867 as_bad (_("invalid machine `%s'"), cpu_string);
1869 if (current_cpu != old_cpu)
1870 s390_setup_opcodes ();
1873 demand_empty_rest_of_line ();
1876 /* The .machinemode pseudo op allows to switch to a different
1877 architecture mode in the asm listing. The current architecture
1878 mode setting can be stored on a stack with .machinemode push and
1879 restored with .machinemode pop. */
1882 s390_machinemode (int ignore ATTRIBUTE_UNUSED)
1885 #define MAX_HISTORY 100
1886 static unsigned int *mode_history;
1887 static int curr_hist;
1891 if (*input_line_pointer == '"')
1894 mode_string = demand_copy_C_string (&len);
1899 mode_string = input_line_pointer;
1900 c = get_symbol_end ();
1901 mode_string = xstrdup (mode_string);
1902 *input_line_pointer = c;
1905 if (mode_string != NULL)
1907 unsigned int old_mode_mask = current_mode_mask;
1910 for (p = mode_string; *p != 0; p++)
1913 if (strcmp (mode_string, "push") == 0)
1915 if (mode_history == NULL)
1916 mode_history = xmalloc (MAX_HISTORY * sizeof (*mode_history));
1918 if (curr_hist >= MAX_HISTORY)
1919 as_bad (_(".machinemode stack overflow"));
1921 mode_history[curr_hist++] = current_mode_mask;
1923 else if (strcmp (mode_string, "pop") == 0)
1926 as_bad (_(".machinemode stack underflow"));
1928 current_mode_mask = mode_history[--curr_hist];
1932 if (strcmp (mode_string, "esa") == 0)
1933 current_mode_mask = 1 << S390_OPCODE_ESA;
1934 else if (strcmp (mode_string, "zarch") == 0)
1936 if (s390_arch_size == 32)
1937 set_highgprs_p = TRUE;
1938 current_mode_mask = 1 << S390_OPCODE_ZARCH;
1940 else if (strcmp (mode_string, "zarch_nohighgprs") == 0)
1941 current_mode_mask = 1 << S390_OPCODE_ZARCH;
1943 as_bad (_("invalid machine `%s'"), mode_string);
1946 if (current_mode_mask != old_mode_mask)
1947 s390_setup_opcodes ();
1950 demand_empty_rest_of_line ();
1954 md_atof (int type, char *litp, int *sizep)
1956 return ieee_md_atof (type, litp, sizep, TRUE);
1959 /* Align a section (I don't know why this is machine dependent). */
1962 md_section_align (asection *seg, valueT addr)
1964 int align = bfd_get_section_alignment (stdoutput, seg);
1966 return ((addr + (1 << align) - 1) & (-1 << align));
1969 /* We don't have any form of relaxing. */
1972 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
1973 asection *seg ATTRIBUTE_UNUSED)
1979 /* Convert a machine dependent frag. We never generate these. */
1982 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1983 asection *sec ATTRIBUTE_UNUSED,
1984 fragS *fragp ATTRIBUTE_UNUSED)
1990 md_undefined_symbol (char *name)
1992 if (*name == '_' && *(name + 1) == 'G'
1993 && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
1997 if (symbol_find (name))
1998 as_bad (_("GOT already in symbol table"));
1999 GOT_symbol = symbol_new (name, undefined_section,
2000 (valueT) 0, &zero_address_frag);
2007 /* Functions concerning relocs. */
2009 /* The location from which a PC relative jump should be calculated,
2010 given a PC relative reloc. */
2013 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
2015 return fixp->fx_frag->fr_address + fixp->fx_where;
2018 /* Here we decide which fixups can be adjusted to make them relative to
2019 the beginning of the section instead of the symbol. Basically we need
2020 to make sure that the dynamic relocations are done correctly, so in
2021 some cases we force the original symbol to be used. */
2023 tc_s390_fix_adjustable (fixS *fixP)
2025 /* Don't adjust references to merge sections. */
2026 if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0)
2028 /* adjust_reloc_syms doesn't know about the GOT. */
2029 if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF
2030 || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
2031 || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64
2032 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16
2033 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32
2034 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64
2035 || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
2036 || fixP->fx_r_type == BFD_RELOC_390_PLT32
2037 || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
2038 || fixP->fx_r_type == BFD_RELOC_390_PLT64
2039 || fixP->fx_r_type == BFD_RELOC_390_GOT12
2040 || fixP->fx_r_type == BFD_RELOC_390_GOT20
2041 || fixP->fx_r_type == BFD_RELOC_390_GOT16
2042 || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
2043 || fixP->fx_r_type == BFD_RELOC_390_GOT64
2044 || fixP->fx_r_type == BFD_RELOC_390_GOTENT
2045 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
2046 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16
2047 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20
2048 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32
2049 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64
2050 || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT
2051 || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD
2052 || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL
2053 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL
2054 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32
2055 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64
2056 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12
2057 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20
2058 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32
2059 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64
2060 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32
2061 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64
2062 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32
2063 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64
2064 || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT
2065 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32
2066 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64
2067 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32
2068 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64
2069 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD
2070 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF
2071 || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF
2072 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2073 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2078 /* Return true if we must always emit a reloc for a type and false if
2079 there is some hope of resolving it at assembly time. */
2081 tc_s390_force_relocation (struct fix *fixp)
2083 /* Ensure we emit a relocation for every reference to the global
2084 offset table or to the procedure link table. */
2085 switch (fixp->fx_r_type)
2087 case BFD_RELOC_390_GOT12:
2088 case BFD_RELOC_390_GOT20:
2089 case BFD_RELOC_32_GOT_PCREL:
2090 case BFD_RELOC_32_GOTOFF:
2091 case BFD_RELOC_390_GOTOFF64:
2092 case BFD_RELOC_390_PLTOFF16:
2093 case BFD_RELOC_390_PLTOFF32:
2094 case BFD_RELOC_390_PLTOFF64:
2095 case BFD_RELOC_390_GOTPC:
2096 case BFD_RELOC_390_GOT16:
2097 case BFD_RELOC_390_GOTPCDBL:
2098 case BFD_RELOC_390_GOT64:
2099 case BFD_RELOC_390_GOTENT:
2100 case BFD_RELOC_390_PLT32:
2101 case BFD_RELOC_390_PLT16DBL:
2102 case BFD_RELOC_390_PLT32DBL:
2103 case BFD_RELOC_390_PLT64:
2104 case BFD_RELOC_390_GOTPLT12:
2105 case BFD_RELOC_390_GOTPLT16:
2106 case BFD_RELOC_390_GOTPLT20:
2107 case BFD_RELOC_390_GOTPLT32:
2108 case BFD_RELOC_390_GOTPLT64:
2109 case BFD_RELOC_390_GOTPLTENT:
2115 return generic_force_reloc (fixp);
2118 /* Apply a fixup to the object code. This is called for all the
2119 fixups we generated by the call to fix_new_exp, above. In the call
2120 above we used a reloc code which was the largest legal reloc code
2121 plus the operand index. Here we undo that to recover the operand
2122 index. At this point all symbol values should be fully resolved,
2123 and we attempt to completely resolve the reloc. If we can not do
2124 that, we determine the correct reloc code and put it back in the
2128 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
2131 valueT value = *valP;
2133 where = fixP->fx_frag->fr_literal + fixP->fx_where;
2135 if (fixP->fx_subsy != NULL)
2136 as_bad_where (fixP->fx_file, fixP->fx_line,
2137 _("cannot emit relocation %s against subsy symbol %s"),
2138 bfd_get_reloc_code_name (fixP->fx_r_type),
2139 S_GET_NAME (fixP->fx_subsy));
2141 if (fixP->fx_addsy != NULL)
2144 value += fixP->fx_frag->fr_address + fixP->fx_where;
2149 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
2151 const struct s390_operand *operand;
2154 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
2155 operand = &s390_operands[opindex];
2159 /* Insert the fully resolved operand value. */
2160 s390_insert_operand ((unsigned char *) where, operand,
2161 (offsetT) value, fixP->fx_file, fixP->fx_line);
2165 /* Determine a BFD reloc value based on the operand information.
2166 We are only prepared to turn a few of the operands into
2168 fixP->fx_offset = value;
2169 if (operand->bits == 12 && operand->shift == 20)
2172 fixP->fx_where += 2;
2173 fixP->fx_r_type = BFD_RELOC_390_12;
2175 else if (operand->bits == 12 && operand->shift == 36)
2178 fixP->fx_where += 4;
2179 fixP->fx_r_type = BFD_RELOC_390_12;
2181 else if (operand->bits == 20 && operand->shift == 20)
2184 fixP->fx_where += 2;
2185 fixP->fx_r_type = BFD_RELOC_390_20;
2187 else if (operand->bits == 8 && operand->shift == 8)
2190 fixP->fx_where += 1;
2191 fixP->fx_r_type = BFD_RELOC_8;
2193 else if (operand->bits == 16 && operand->shift == 16)
2196 fixP->fx_where += 2;
2197 if (operand->flags & S390_OPERAND_PCREL)
2199 fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2200 fixP->fx_offset += 2;
2203 fixP->fx_r_type = BFD_RELOC_16;
2205 else if (operand->bits == 32 && operand->shift == 16
2206 && (operand->flags & S390_OPERAND_PCREL))
2209 fixP->fx_where += 2;
2210 fixP->fx_offset += 2;
2211 fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
2218 /* Use expr_symbol_where to see if this is an expression
2220 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
2221 as_bad_where (fixP->fx_file, fixP->fx_line,
2222 _("unresolved expression that must be resolved"));
2224 as_bad_where (fixP->fx_file, fixP->fx_line,
2225 _("unsupported relocation type"));
2232 switch (fixP->fx_r_type)
2238 md_number_to_chars (where, value, 1);
2240 case BFD_RELOC_390_12:
2241 case BFD_RELOC_390_GOT12:
2242 case BFD_RELOC_390_GOTPLT12:
2247 mop = bfd_getb16 ((unsigned char *) where);
2248 mop |= (unsigned short) (value & 0xfff);
2249 bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
2253 case BFD_RELOC_390_20:
2254 case BFD_RELOC_390_GOT20:
2255 case BFD_RELOC_390_GOTPLT20:
2259 mop = bfd_getb32 ((unsigned char *) where);
2260 mop |= (unsigned int) ((value & 0xfff) << 8 |
2261 (value & 0xff000) >> 12);
2262 bfd_putb32 ((bfd_vma) mop, (unsigned char *) where);
2267 case BFD_RELOC_GPREL16:
2268 case BFD_RELOC_16_GOT_PCREL:
2269 case BFD_RELOC_16_GOTOFF:
2271 as_bad_where (fixP->fx_file, fixP->fx_line,
2272 _("cannot emit PC relative %s relocation%s%s"),
2273 bfd_get_reloc_code_name (fixP->fx_r_type),
2274 fixP->fx_addsy != NULL ? " against " : "",
2275 (fixP->fx_addsy != NULL
2276 ? S_GET_NAME (fixP->fx_addsy)
2279 md_number_to_chars (where, value, 2);
2281 case BFD_RELOC_390_GOT16:
2282 case BFD_RELOC_390_PLTOFF16:
2283 case BFD_RELOC_390_GOTPLT16:
2285 md_number_to_chars (where, value, 2);
2287 case BFD_RELOC_390_PC16DBL:
2288 case BFD_RELOC_390_PLT16DBL:
2291 md_number_to_chars (where, (offsetT) value >> 1, 2);
2296 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2298 fixP->fx_r_type = BFD_RELOC_32;
2300 md_number_to_chars (where, value, 4);
2302 case BFD_RELOC_32_PCREL:
2303 case BFD_RELOC_32_BASEREL:
2304 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2306 md_number_to_chars (where, value, 4);
2308 case BFD_RELOC_32_GOT_PCREL:
2309 case BFD_RELOC_390_PLTOFF32:
2310 case BFD_RELOC_390_PLT32:
2311 case BFD_RELOC_390_GOTPLT32:
2313 md_number_to_chars (where, value, 4);
2315 case BFD_RELOC_390_PC32DBL:
2316 case BFD_RELOC_390_PLT32DBL:
2317 case BFD_RELOC_390_GOTPCDBL:
2318 case BFD_RELOC_390_GOTENT:
2319 case BFD_RELOC_390_GOTPLTENT:
2322 md_number_to_chars (where, (offsetT) value >> 1, 4);
2325 case BFD_RELOC_32_GOTOFF:
2327 md_number_to_chars (where, value, sizeof (int));
2330 case BFD_RELOC_390_GOTOFF64:
2332 md_number_to_chars (where, value, 8);
2335 case BFD_RELOC_390_GOT64:
2336 case BFD_RELOC_390_PLTOFF64:
2337 case BFD_RELOC_390_PLT64:
2338 case BFD_RELOC_390_GOTPLT64:
2340 md_number_to_chars (where, value, 8);
2345 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2347 fixP->fx_r_type = BFD_RELOC_64;
2349 md_number_to_chars (where, value, 8);
2352 case BFD_RELOC_64_PCREL:
2353 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2355 md_number_to_chars (where, value, 8);
2358 case BFD_RELOC_VTABLE_INHERIT:
2359 case BFD_RELOC_VTABLE_ENTRY:
2363 case BFD_RELOC_390_TLS_LOAD:
2364 case BFD_RELOC_390_TLS_GDCALL:
2365 case BFD_RELOC_390_TLS_LDCALL:
2366 case BFD_RELOC_390_TLS_GD32:
2367 case BFD_RELOC_390_TLS_GD64:
2368 case BFD_RELOC_390_TLS_GOTIE12:
2369 case BFD_RELOC_390_TLS_GOTIE20:
2370 case BFD_RELOC_390_TLS_GOTIE32:
2371 case BFD_RELOC_390_TLS_GOTIE64:
2372 case BFD_RELOC_390_TLS_LDM32:
2373 case BFD_RELOC_390_TLS_LDM64:
2374 case BFD_RELOC_390_TLS_IE32:
2375 case BFD_RELOC_390_TLS_IE64:
2376 case BFD_RELOC_390_TLS_LE32:
2377 case BFD_RELOC_390_TLS_LE64:
2378 case BFD_RELOC_390_TLS_LDO32:
2379 case BFD_RELOC_390_TLS_LDO64:
2380 case BFD_RELOC_390_TLS_DTPMOD:
2381 case BFD_RELOC_390_TLS_DTPOFF:
2382 case BFD_RELOC_390_TLS_TPOFF:
2383 S_SET_THREAD_LOCAL (fixP->fx_addsy);
2384 /* Fully resolved at link time. */
2386 case BFD_RELOC_390_TLS_IEENT:
2387 /* Fully resolved at link time. */
2388 S_SET_THREAD_LOCAL (fixP->fx_addsy);
2394 const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
2396 if (reloc_name != NULL)
2397 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name);
2399 as_fatal (_("Gas failure, reloc type #%i\n"), fixP->fx_r_type);
2403 fixP->fx_offset = value;
2407 /* Generate a reloc for a fixup. */
2410 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
2412 bfd_reloc_code_real_type code;
2415 code = fixp->fx_r_type;
2416 if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
2418 if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
2419 || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
2420 code = BFD_RELOC_390_GOTPC;
2421 if (code == BFD_RELOC_390_PC32DBL)
2422 code = BFD_RELOC_390_GOTPCDBL;
2425 reloc = (arelent *) xmalloc (sizeof (arelent));
2426 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2427 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2428 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2429 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2430 if (reloc->howto == NULL)
2432 as_bad_where (fixp->fx_file, fixp->fx_line,
2433 _("cannot represent relocation type %s"),
2434 bfd_get_reloc_code_name (code));
2435 /* Set howto to a garbage value so that we can keep going. */
2436 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2437 gas_assert (reloc->howto != NULL);
2439 reloc->addend = fixp->fx_offset;
2445 s390_cfi_frame_initial_instructions (void)
2447 cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96);
2451 tc_s390_regname_to_dw2regnum (char *regname)
2455 if (regname[0] != 'c' && regname[0] != 'a')
2457 regnum = reg_name_search (pre_defined_registers, REG_NAME_CNT, regname);
2458 if (regname[0] == 'f' && regnum != -1)
2461 else if (strcmp (regname, "ap") == 0)
2463 else if (strcmp (regname, "cc") == 0)
2469 s390_elf_final_processing (void)
2472 elf_elfheader (stdoutput)->e_flags |= EF_S390_HIGH_GPRS;