1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, 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 static unsigned int current_mode_mask
= 0;
42 static unsigned int current_cpu
= -1U;
44 /* Whether to use user friendly register names. Default is TRUE. */
45 #ifndef TARGET_REG_NAMES_P
46 #define TARGET_REG_NAMES_P TRUE
49 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
51 /* Set to TRUE if we want to warn about zero base/index registers. */
52 static bfd_boolean warn_areg_zero
= FALSE
;
54 /* Generic assembler global variables which must be defined by all
57 const char comment_chars
[] = "#";
59 /* Characters which start a comment at the beginning of a line. */
60 const char line_comment_chars
[] = "#";
62 /* Characters which may be used to separate multiple commands on a
64 const char line_separator_chars
[] = ";";
66 /* Characters which are used to indicate an exponent in a floating
68 const char EXP_CHARS
[] = "eE";
70 /* Characters which mean that a number is a floating point constant,
72 const char FLT_CHARS
[] = "dD";
74 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
75 int s390_cie_data_alignment
;
77 /* The target specific pseudo-ops which we support. */
79 /* Define the prototypes for the pseudo-ops */
80 static void s390_byte
PARAMS ((int));
81 static void s390_elf_cons
PARAMS ((int));
82 static void s390_bss
PARAMS ((int));
83 static void s390_insn
PARAMS ((int));
84 static void s390_literals
PARAMS ((int));
86 const pseudo_typeS md_pseudo_table
[] =
88 { "align", s_align_bytes
, 0 },
89 /* Pseudo-ops which must be defined. */
90 { "bss", s390_bss
, 0 },
91 { "insn", s390_insn
, 0 },
92 /* Pseudo-ops which must be overridden. */
93 { "byte", s390_byte
, 0 },
94 { "short", s390_elf_cons
, 2 },
95 { "long", s390_elf_cons
, 4 },
96 { "quad", s390_elf_cons
, 8 },
97 { "ltorg", s390_literals
, 0 },
98 { "string", stringer
, 2 },
103 /* Structure to hold information about predefined registers. */
110 /* List of registers that are pre-defined:
112 Each access register has a predefined name of the form:
113 a<reg_num> which has the value <reg_num>.
115 Each control register has a predefined name of the form:
116 c<reg_num> which has the value <reg_num>.
118 Each general register has a predefined name of the form:
119 r<reg_num> which has the value <reg_num>.
121 Each floating point register a has predefined name of the form:
122 f<reg_num> which has the value <reg_num>.
124 There are individual registers as well:
128 The table is sorted. Suitable for searching by a binary search. */
130 static const struct pd_reg pre_defined_registers
[] =
132 { "a0", 0 }, /* Access registers */
149 { "c0", 0 }, /* Control registers */
166 { "f0", 0 }, /* Floating point registers */
183 { "lit", 13 }, /* Pointer to literal pool */
185 { "r0", 0 }, /* General purpose registers */
202 { "sp", 15 }, /* Stack pointer */
206 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
208 static int reg_name_search
209 PARAMS ((const struct pd_reg
*, int, const char *));
210 static bfd_boolean register_name
PARAMS ((expressionS
*));
211 static void init_default_arch
PARAMS ((void));
212 static void s390_insert_operand
213 PARAMS ((unsigned char *, const struct s390_operand
*, offsetT
, char *,
215 static char *md_gather_operands
216 PARAMS ((char *, unsigned char *, const struct s390_opcode
*));
218 /* Given NAME, find the register number associated with that name, return
219 the integer value associated with the given name or -1 on failure. */
222 reg_name_search (regs
, regcount
, name
)
223 const struct pd_reg
*regs
;
227 int middle
, low
, high
;
235 middle
= (low
+ high
) / 2;
236 cmp
= strcasecmp (name
, regs
[middle
].name
);
242 return regs
[middle
].value
;
251 * Summary of register_name().
253 * in: Input_line_pointer points to 1st char of operand.
255 * out: A expressionS.
256 * The operand may have been a register: in this case, X_op == O_register,
257 * X_add_number is set to the register number, and truth is returned.
258 * Input_line_pointer->(next non-blank) char after operand, or is in its
263 register_name (expressionP
)
264 expressionS
*expressionP
;
271 /* Find the spelling of the operand. */
272 start
= name
= input_line_pointer
;
273 if (name
[0] == '%' && ISALPHA (name
[1]))
274 name
= ++input_line_pointer
;
278 c
= get_symbol_end ();
279 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
281 /* Put back the delimiting char. */
282 *input_line_pointer
= c
;
284 /* Look to see if it's in the register table. */
287 expressionP
->X_op
= O_register
;
288 expressionP
->X_add_number
= reg_number
;
290 /* Make the rest nice. */
291 expressionP
->X_add_symbol
= NULL
;
292 expressionP
->X_op_symbol
= NULL
;
296 /* Reset the line as if we had not done anything. */
297 input_line_pointer
= start
;
301 /* Local variables. */
303 /* Opformat hash table. */
304 static struct hash_control
*s390_opformat_hash
;
306 /* Opcode hash table. */
307 static struct hash_control
*s390_opcode_hash
;
309 /* Flags to set in the elf header */
310 static flagword s390_flags
= 0;
312 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
314 #ifndef WORKING_DOT_WORD
315 const int md_short_jump_size
= 4;
316 const int md_long_jump_size
= 4;
319 const char *md_shortopts
= "A:m:kVQ:";
320 struct option md_longopts
[] = {
321 {NULL
, no_argument
, NULL
, 0}
323 size_t md_longopts_size
= sizeof (md_longopts
);
325 /* Initialize the default opcode arch and word size from the default
326 architecture name if not specified by an option. */
330 if (strcmp (default_arch
, "s390") == 0)
332 if (s390_arch_size
== 0)
335 else if (strcmp (default_arch
, "s390x") == 0)
337 if (s390_arch_size
== 0)
341 as_fatal ("Invalid default architecture, broken assembler.");
343 if (current_mode_mask
== 0)
345 if (s390_arch_size
== 32)
346 current_mode_mask
= 1 << S390_OPCODE_ESA
;
348 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
350 if (current_cpu
== -1U)
352 if (current_mode_mask
== (1 << S390_OPCODE_ESA
))
353 current_cpu
= S390_OPCODE_G5
;
355 current_cpu
= S390_OPCODE_Z900
;
359 /* Called by TARGET_FORMAT. */
361 s390_target_format ()
363 /* We don't get a chance to initialize anything before we're called,
364 so handle that now. */
365 init_default_arch ();
367 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
371 md_parse_option (c
, arg
)
377 /* -k: Ignore for FreeBSD compatibility. */
381 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
384 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
387 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
388 warn_areg_zero
= TRUE
;
390 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
393 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
396 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
397 current_mode_mask
= 1 << S390_OPCODE_ESA
;
399 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
400 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
402 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
404 if (strcmp (arg
+ 5, "g5") == 0)
405 current_cpu
= S390_OPCODE_G5
;
406 else if (strcmp (arg
+ 5, "g6") == 0)
407 current_cpu
= S390_OPCODE_G6
;
408 else if (strcmp (arg
+ 5, "z900") == 0)
409 current_cpu
= S390_OPCODE_Z900
;
410 else if (strcmp (arg
+ 5, "z990") == 0)
411 current_cpu
= S390_OPCODE_Z990
;
414 as_bad (_("invalid switch -m%s"), arg
);
421 as_bad (_("invalid switch -m%s"), arg
);
427 /* Option -A is deprecated. Still available for compatibility. */
428 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
429 current_cpu
= S390_OPCODE_G5
;
430 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
431 current_cpu
= S390_OPCODE_Z900
;
433 as_bad ("invalid architecture -A%s", arg
);
436 /* -V: SVR4 argument to print version ID. */
441 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
442 should be emitted or not. FIXME: Not implemented. */
454 md_show_usage (stream
)
457 fprintf (stream
, _("\
459 -mregnames Allow symbolic names for registers\n\
460 -mwarn-areg-zero Warn about zero base/index registers\n\
461 -mno-regnames Do not allow symbolic names for registers\n\
462 -m31 Set file format to 31 bit format\n\
463 -m64 Set file format to 64 bit format\n"));
464 fprintf (stream
, _("\
465 -V print assembler version number\n\
466 -Qy, -Qn ignored\n"));
469 /* This function is called when the assembler starts up. It is called
470 after the options have been parsed and the output file has been
476 register const struct s390_opcode
*op
;
477 const struct s390_opcode
*op_end
;
478 bfd_boolean dup_insn
= FALSE
;
481 /* Give a warning if the combination -m64-bit and -Aesa is used. */
482 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
483 as_warn ("The 64 bit file format is used without esame instructions.");
485 s390_cie_data_alignment
= -s390_arch_size
/ 8;
487 /* Set the ELF flags if desired. */
489 bfd_set_private_flags (stdoutput
, s390_flags
);
491 /* Insert the opcode formats into a hash table. */
492 s390_opformat_hash
= hash_new ();
494 op_end
= s390_opformats
+ s390_num_opformats
;
495 for (op
= s390_opformats
; op
< op_end
; op
++)
497 retval
= hash_insert (s390_opformat_hash
, op
->name
, (PTR
) op
);
498 if (retval
!= (const char *) NULL
)
500 as_bad (_("Internal assembler error for instruction format %s"),
506 /* Insert the opcodes into a hash table. */
507 s390_opcode_hash
= hash_new ();
509 op_end
= s390_opcodes
+ s390_num_opcodes
;
510 for (op
= s390_opcodes
; op
< op_end
; op
++)
511 if (op
->min_cpu
<= current_cpu
)
513 retval
= hash_insert (s390_opcode_hash
, op
->name
, (PTR
) op
);
514 if (retval
!= (const char *) NULL
)
516 as_bad (_("Internal assembler error for instruction %s"),
520 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
527 record_alignment (text_section
, 2);
528 record_alignment (data_section
, 2);
529 record_alignment (bss_section
, 2);
533 /* Called after all assembly has been done. */
537 if (s390_arch_size
== 64)
538 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
540 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
543 /* Insert an operand value into an instruction. */
546 s390_insert_operand (insn
, operand
, val
, file
, line
)
548 const struct s390_operand
*operand
;
556 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
560 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
561 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
562 /* Halve PCREL operands. */
563 if (operand
->flags
& S390_OPERAND_PCREL
)
565 /* Check for underflow / overflow. */
566 if (val
< min
|| val
> max
)
569 "operand out of range (%s not between %ld and %ld)";
572 if (operand
->flags
& S390_OPERAND_PCREL
)
578 sprint_value (buf
, val
);
579 if (file
== (char *) NULL
)
580 as_bad (err
, buf
, (int) min
, (int) max
);
582 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
585 /* val is ok, now restrict it to operand->bits bits. */
586 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
587 /* val is restrict, now check for special case. */
588 if (operand
->bits
== 20 && operand
->shift
== 20)
589 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
595 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
597 uval
= (addressT
) val
;
598 /* Length x in an instructions has real length x+1. */
599 if (operand
->flags
& S390_OPERAND_LENGTH
)
601 /* Check for underflow / overflow. */
602 if (uval
< min
|| uval
> max
)
604 if (operand
->flags
& S390_OPERAND_LENGTH
)
611 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
617 /* Insert fragments of the operand byte for byte. */
618 offset
= operand
->shift
+ operand
->bits
;
619 uval
<<= (-offset
) & 7;
620 insn
+= (offset
- 1) / 8;
632 bfd_reloc_code_real_type reloc
;
635 static bfd_reloc_code_real_type s390_tls_suffix
636 PARAMS ((char **, expressionS
*));
638 /* Parse tls marker and return the desired relocation. */
639 static bfd_reloc_code_real_type
640 s390_tls_suffix (str_p
, exp_p
)
644 static struct map_tls mapping
[] =
646 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
647 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
648 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
649 { NULL
, 0, BFD_RELOC_UNUSED
}
659 return BFD_RELOC_UNUSED
;
662 while (ISIDNUM (*str
))
666 return BFD_RELOC_UNUSED
;
668 orig_line
= input_line_pointer
;
669 input_line_pointer
= str
;
671 str
= input_line_pointer
;
672 if (&input_line_pointer
!= str_p
)
673 input_line_pointer
= orig_line
;
675 if (exp_p
->X_op
!= O_symbol
)
676 return BFD_RELOC_UNUSED
;
678 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
679 if (len
== ptr
->length
680 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
682 /* Found a matching tls suffix. */
686 return BFD_RELOC_UNUSED
;
689 /* Structure used to hold suffixes. */
700 ELF_SUFFIX_TLS_GOTIE
,
712 elf_suffix_type suffix
;
715 static elf_suffix_type s390_elf_suffix
PARAMS ((char **, expressionS
*));
716 static int s390_exp_compare
PARAMS ((expressionS
*exp1
, expressionS
*exp2
));
717 static elf_suffix_type s390_lit_suffix
718 PARAMS ((char **, expressionS
*, elf_suffix_type
));
721 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
722 static elf_suffix_type
723 s390_elf_suffix (str_p
, exp_p
)
727 static struct map_bfd mapping
[] =
729 { "got", 3, ELF_SUFFIX_GOT
},
730 { "got12", 5, ELF_SUFFIX_GOT
},
731 { "plt", 3, ELF_SUFFIX_PLT
},
732 { "gotent", 6, ELF_SUFFIX_GOTENT
},
733 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
734 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
735 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
736 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
737 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
738 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
739 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
740 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
741 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
742 { NULL
, 0, ELF_SUFFIX_NONE
}
751 return ELF_SUFFIX_NONE
;
754 while (ISALNUM (*str
))
758 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
759 if (len
== ptr
->length
760 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
762 if (exp_p
->X_add_number
!= 0)
763 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
764 ptr
->string
, ptr
->string
);
765 /* Now check for identifier@suffix+constant. */
766 if (*str
== '-' || *str
== '+')
768 char *orig_line
= input_line_pointer
;
771 input_line_pointer
= str
;
772 expression (&new_exp
);
774 switch (new_exp
.X_op
)
776 case O_constant
: /* X_add_number (a constant expression). */
777 exp_p
->X_add_number
+= new_exp
.X_add_number
;
778 str
= input_line_pointer
;
780 case O_symbol
: /* X_add_symbol + X_add_number. */
781 /* this case is used for e.g. xyz@PLT+.Label. */
782 exp_p
->X_add_number
+= new_exp
.X_add_number
;
783 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
785 str
= input_line_pointer
;
787 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
788 /* this case is used for e.g. xyz@PLT-.Label. */
789 exp_p
->X_add_number
+= new_exp
.X_add_number
;
790 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
791 exp_p
->X_op
= O_subtract
;
792 str
= input_line_pointer
;
798 /* If s390_elf_suffix has not been called with
799 &input_line_pointer as first parameter, we have
800 clobbered the input_line_pointer. We have to
802 if (&input_line_pointer
!= str_p
)
803 input_line_pointer
= orig_line
;
809 return BFD_RELOC_UNUSED
;
812 /* Structure used to hold a literal pool entry. */
815 struct s390_lpe
*next
;
817 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
818 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
820 bfd_reloc_code_real_type reloc
;
824 static struct s390_lpe
*lpe_free_list
= NULL
;
825 static struct s390_lpe
*lpe_list
= NULL
;
826 static struct s390_lpe
*lpe_list_tail
= NULL
;
827 static symbolS
*lp_sym
= NULL
;
828 static int lp_count
= 0;
829 static int lpe_count
= 0;
832 s390_exp_compare (exp1
, exp2
)
836 if (exp1
->X_op
!= exp2
->X_op
)
841 case O_constant
: /* X_add_number must be equal. */
843 return exp1
->X_add_number
== exp2
->X_add_number
;
846 as_bad (_("Can't handle O_big in s390_exp_compare"));
848 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
853 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
854 && (exp1
->X_add_number
== exp2
->X_add_number
);
856 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
861 case O_bit_inclusive_or
:
863 case O_bit_exclusive_or
:
875 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
876 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
877 && (exp1
->X_add_number
== exp2
->X_add_number
);
883 /* Test for @lit and if its present make an entry in the literal pool and
884 modify the current expression to be an offset into the literal pool. */
885 static elf_suffix_type
886 s390_lit_suffix (str_p
, exp_p
, suffix
)
889 elf_suffix_type suffix
;
891 bfd_reloc_code_real_type reloc
;
895 struct s390_lpe
*lpe
;
899 return suffix
; /* No modification. */
901 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
903 while (ISALNUM (*str
))
906 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
907 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
908 return suffix
; /* no modification */
909 nbytes
= ident
[3] - '0';
911 reloc
= BFD_RELOC_UNUSED
;
912 if (suffix
== ELF_SUFFIX_GOT
)
915 reloc
= BFD_RELOC_390_GOT16
;
916 else if (nbytes
== 4)
917 reloc
= BFD_RELOC_32_GOT_PCREL
;
918 else if (nbytes
== 8)
919 reloc
= BFD_RELOC_390_GOT64
;
921 else if (suffix
== ELF_SUFFIX_PLT
)
924 reloc
= BFD_RELOC_390_PLT32
;
925 else if (nbytes
== 8)
926 reloc
= BFD_RELOC_390_PLT64
;
929 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
930 as_bad (_("Invalid suffix for literal pool entry"));
932 /* Search the pool if the new entry is a duplicate. */
933 if (exp_p
->X_op
== O_big
)
935 /* Special processing for big numbers. */
936 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
938 if (lpe
->ex
.X_op
== O_big
)
940 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
942 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
943 sizeof (FLONUM_TYPE
)) == 0)
946 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
948 if (memcmp (generic_bignum
, lpe
->bignum
,
949 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
957 /* Processing for 'normal' data types. */
958 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
959 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
960 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
967 if (lpe_free_list
!= NULL
)
970 lpe_free_list
= lpe_free_list
->next
;
974 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
979 if (exp_p
->X_op
== O_big
)
981 if (exp_p
->X_add_number
<= 0)
982 lpe
->floatnum
= generic_floating_point_number
;
983 else if (exp_p
->X_add_number
<= 4)
984 memcpy (lpe
->bignum
, generic_bignum
,
985 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
987 as_bad (_("Big number is too big"));
990 lpe
->nbytes
= nbytes
;
992 /* Literal pool name defined ? */
995 sprintf (tmp_name
, ".L\001%i", lp_count
);
996 lp_sym
= symbol_make (tmp_name
);
999 /* Make name for literal pool entry. */
1000 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1002 lpe
->sym
= symbol_make (tmp_name
);
1004 /* Add to literal pool list. */
1006 if (lpe_list_tail
!= NULL
)
1008 lpe_list_tail
->next
= lpe
;
1009 lpe_list_tail
= lpe
;
1012 lpe_list
= lpe_list_tail
= lpe
;
1015 /* Now change exp_p to the offset into the literal pool.
1016 Thats the expression: .L^Ax^By-.L^Ax */
1017 exp_p
->X_add_symbol
= lpe
->sym
;
1018 exp_p
->X_op_symbol
= lp_sym
;
1019 exp_p
->X_op
= O_subtract
;
1020 exp_p
->X_add_number
= 0;
1024 /* We change the suffix type to ELF_SUFFIX_NONE, because
1025 the difference of two local labels is just a number. */
1026 return ELF_SUFFIX_NONE
;
1029 /* Like normal .long/.short/.word, except support @got, etc.
1030 clobbers input_line_pointer, checks end-of-line. */
1032 s390_elf_cons (nbytes
)
1033 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1036 elf_suffix_type suffix
;
1038 if (is_it_end_of_statement ())
1040 demand_empty_rest_of_line ();
1048 if (exp
.X_op
== O_symbol
1049 && *input_line_pointer
== '@'
1050 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1052 bfd_reloc_code_real_type reloc
;
1053 reloc_howto_type
*reloc_howto
;
1059 static bfd_reloc_code_real_type tab2
[] =
1061 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1062 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1063 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1064 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1065 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1066 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1067 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1068 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1069 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1070 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1071 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1072 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1073 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1075 reloc
= tab2
[suffix
];
1077 else if (nbytes
== 4)
1079 static bfd_reloc_code_real_type tab4
[] =
1081 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1082 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1083 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1084 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1085 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1086 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1087 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1088 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1089 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1090 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1091 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1092 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1093 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1095 reloc
= tab4
[suffix
];
1097 else if (nbytes
== 8)
1099 static bfd_reloc_code_real_type tab8
[] =
1101 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1102 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1103 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1104 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1105 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1106 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1107 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1108 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1109 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1110 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1111 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1112 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1113 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1115 reloc
= tab8
[suffix
];
1118 reloc
= BFD_RELOC_UNUSED
;
1120 if (reloc
!= BFD_RELOC_UNUSED
1121 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1123 size
= bfd_get_reloc_size (reloc_howto
);
1125 as_bad (_("%s relocations do not fit in %d bytes"),
1126 reloc_howto
->name
, nbytes
);
1127 where
= frag_more (nbytes
);
1128 md_number_to_chars (where
, 0, size
);
1129 /* To make fixup_segment do the pc relative conversion the
1130 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1131 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1132 size
, &exp
, FALSE
, reloc
);
1135 as_bad (_("relocation not applicable"));
1138 emit_expr (&exp
, (unsigned int) nbytes
);
1140 while (*input_line_pointer
++ == ',');
1142 input_line_pointer
--; /* Put terminator back into stream. */
1143 demand_empty_rest_of_line ();
1146 /* We need to keep a list of fixups. We can't simply generate them as
1147 we go, because that would require us to first create the frag, and
1148 that would screw up references to ``.''. */
1154 bfd_reloc_code_real_type reloc
;
1157 #define MAX_INSN_FIXUPS (4)
1159 /* This routine is called for each instruction to be assembled. */
1162 md_gather_operands (str
, insn
, opcode
)
1164 unsigned char *insn
;
1165 const struct s390_opcode
*opcode
;
1167 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1168 const struct s390_operand
*operand
;
1169 const unsigned char *opindex_ptr
;
1171 elf_suffix_type suffix
;
1172 bfd_reloc_code_real_type reloc
;
1178 while (ISSPACE (*str
))
1184 /* Gather the operands. */
1186 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1190 operand
= s390_operands
+ *opindex_ptr
;
1192 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1194 /* We do an early skip. For D(X,B) constructions the index
1195 register is skipped (X is optional). For D(L,B) the base
1196 register will be the skipped operand, because L is NOT
1202 /* Gather the operand. */
1203 hold
= input_line_pointer
;
1204 input_line_pointer
= str
;
1206 /* Parse the operand. */
1207 if (! register_name (&ex
))
1210 str
= input_line_pointer
;
1211 input_line_pointer
= hold
;
1213 /* Write the operand to the insn. */
1214 if (ex
.X_op
== O_illegal
)
1215 as_bad (_("illegal operand"));
1216 else if (ex
.X_op
== O_absent
)
1217 as_bad (_("missing operand"));
1218 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1220 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1222 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1224 /* We need to generate a fixup for the
1225 expression returned by s390_lit_suffix. */
1226 if (fc
>= MAX_INSN_FIXUPS
)
1227 as_fatal (_("too many fixups"));
1228 fixups
[fc
].exp
= ex
;
1229 fixups
[fc
].opindex
= *opindex_ptr
;
1230 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1235 if ((operand
->flags
& S390_OPERAND_INDEX
)
1236 && ex
.X_add_number
== 0
1238 as_warn ("index register specified but zero");
1239 if ((operand
->flags
& S390_OPERAND_BASE
)
1240 && ex
.X_add_number
== 0
1242 as_warn ("base register specified but zero");
1243 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1248 suffix
= s390_elf_suffix (&str
, &ex
);
1249 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1250 reloc
= BFD_RELOC_UNUSED
;
1252 if (suffix
== ELF_SUFFIX_GOT
)
1254 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1255 (operand
->bits
== 12))
1256 reloc
= BFD_RELOC_390_GOT12
;
1257 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1258 (operand
->bits
== 20))
1259 reloc
= BFD_RELOC_390_GOT20
;
1260 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1261 && (operand
->bits
== 16))
1262 reloc
= BFD_RELOC_390_GOT16
;
1263 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1264 && (operand
->bits
== 32))
1265 reloc
= BFD_RELOC_390_GOTENT
;
1267 else if (suffix
== ELF_SUFFIX_PLT
)
1269 if ((operand
->flags
& S390_OPERAND_PCREL
)
1270 && (operand
->bits
== 16))
1271 reloc
= BFD_RELOC_390_PLT16DBL
;
1272 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1273 && (operand
->bits
== 32))
1274 reloc
= BFD_RELOC_390_PLT32DBL
;
1276 else if (suffix
== ELF_SUFFIX_GOTENT
)
1278 if ((operand
->flags
& S390_OPERAND_PCREL
)
1279 && (operand
->bits
== 32))
1280 reloc
= BFD_RELOC_390_GOTENT
;
1282 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1284 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1285 && (operand
->bits
== 16))
1286 reloc
= BFD_RELOC_16_GOTOFF
;
1288 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1290 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1291 && (operand
->bits
== 16))
1292 reloc
= BFD_RELOC_390_PLTOFF16
;
1294 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1296 if ((operand
->flags
& S390_OPERAND_DISP
)
1297 && (operand
->bits
== 12))
1298 reloc
= BFD_RELOC_390_GOTPLT12
;
1299 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1300 && (operand
->bits
== 16))
1301 reloc
= BFD_RELOC_390_GOTPLT16
;
1302 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1303 && (operand
->bits
== 32))
1304 reloc
= BFD_RELOC_390_GOTPLTENT
;
1306 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1308 if ((operand
->flags
& S390_OPERAND_DISP
)
1309 && (operand
->bits
== 12))
1310 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1311 else if ((operand
->flags
& S390_OPERAND_DISP
)
1312 && (operand
->bits
== 20))
1313 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1315 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1317 if ((operand
->flags
& S390_OPERAND_PCREL
)
1318 && (operand
->bits
== 32))
1319 reloc
= BFD_RELOC_390_TLS_IEENT
;
1322 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1323 as_bad (_("invalid operand suffix"));
1324 /* We need to generate a fixup of type 'reloc' for this
1326 if (fc
>= MAX_INSN_FIXUPS
)
1327 as_fatal (_("too many fixups"));
1328 fixups
[fc
].exp
= ex
;
1329 fixups
[fc
].opindex
= *opindex_ptr
;
1330 fixups
[fc
].reloc
= reloc
;
1334 /* Check the next character. The call to expression has advanced
1335 str past any whitespace. */
1336 if (operand
->flags
& S390_OPERAND_DISP
)
1338 /* After a displacement a block in parentheses can start. */
1341 /* Check if parenthesized block can be skipped. If the next
1342 operand is neiter an optional operand nor a base register
1343 then we have a syntax error. */
1344 operand
= s390_operands
+ *(++opindex_ptr
);
1345 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1346 as_bad (_("syntax error; missing '(' after displacement"));
1348 /* Ok, skip all operands until S390_OPERAND_BASE. */
1349 while (!(operand
->flags
& S390_OPERAND_BASE
))
1350 operand
= s390_operands
+ *(++opindex_ptr
);
1352 /* If there is a next operand it must be separated by a comma. */
1353 if (opindex_ptr
[1] != '\0')
1356 as_bad (_("syntax error; expected ,"));
1361 /* We found an opening parentheses. */
1363 for (f
= str
; *f
!= '\0'; f
++)
1364 if (*f
== ',' || *f
== ')')
1366 /* If there is no comma until the closing parentheses OR
1367 there is a comma right after the opening parentheses,
1368 we have to skip optional operands. */
1369 if (*f
== ',' && f
== str
)
1371 /* comma directly after '(' ? */
1376 skip_optional
= (*f
!= ',');
1379 else if (operand
->flags
& S390_OPERAND_BASE
)
1381 /* After the base register the parenthesed block ends. */
1383 as_bad (_("syntax error; missing ')' after base register"));
1385 /* If there is a next operand it must be separated by a comma. */
1386 if (opindex_ptr
[1] != '\0')
1389 as_bad (_("syntax error; expected ,"));
1394 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1395 of D(L,B). In this case the base register has to be skipped. */
1398 operand
= s390_operands
+ *(++opindex_ptr
);
1400 if (!(operand
->flags
& S390_OPERAND_BASE
))
1401 as_bad (_("syntax error; ')' not allowed here"));
1404 /* If there is a next operand it must be separated by a comma. */
1405 if (opindex_ptr
[1] != '\0')
1408 as_bad (_("syntax error; expected ,"));
1413 while (ISSPACE (*str
))
1416 /* Check for tls instruction marker. */
1417 reloc
= s390_tls_suffix (&str
, &ex
);
1418 if (reloc
!= BFD_RELOC_UNUSED
)
1420 /* We need to generate a fixup of type 'reloc' for this
1422 if (fc
>= MAX_INSN_FIXUPS
)
1423 as_fatal (_("too many fixups"));
1424 fixups
[fc
].exp
= ex
;
1425 fixups
[fc
].opindex
= -1;
1426 fixups
[fc
].reloc
= reloc
;
1434 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1436 as_bad (_("junk at end of line: `%s'"), str
);
1437 if (linefeed
!= NULL
)
1441 /* Write out the instruction. */
1442 f
= frag_more (opcode
->oplen
);
1443 memcpy (f
, insn
, opcode
->oplen
);
1444 dwarf2_emit_insn (opcode
->oplen
);
1446 /* Create any fixups. At this point we do not use a
1447 bfd_reloc_code_real_type, but instead just use the
1448 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1449 handle fixups for any operand type, although that is admittedly
1450 not a very exciting feature. We pick a BFD reloc type in
1452 for (i
= 0; i
< fc
; i
++)
1455 if (fixups
[i
].opindex
< 0)
1457 /* Create tls instruction marker relocation. */
1458 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1459 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1463 operand
= s390_operands
+ fixups
[i
].opindex
;
1465 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1467 reloc_howto_type
*reloc_howto
;
1471 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1475 size
= bfd_get_reloc_size (reloc_howto
);
1477 if (size
< 1 || size
> 4)
1480 fixP
= fix_new_exp (frag_now
,
1481 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1482 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1484 /* Turn off overflow checking in fixup_segment. This is necessary
1485 because fixup_segment will signal an overflow for large 4 byte
1486 quantities for GOT12 relocations. */
1487 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1488 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1489 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1490 fixP
->fx_no_overflow
= 1;
1493 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1494 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1495 ((bfd_reloc_code_real_type
)
1496 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1501 /* This routine is called for each instruction to be assembled. */
1507 const struct s390_opcode
*opcode
;
1508 unsigned char insn
[6];
1511 /* Get the opcode. */
1512 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1517 /* Look up the opcode in the hash table. */
1518 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1519 if (opcode
== (const struct s390_opcode
*) NULL
)
1521 as_bad (_("Unrecognized opcode: `%s'"), str
);
1524 else if (!(opcode
->modes
& current_mode_mask
))
1526 as_bad ("Opcode %s not available in this mode", str
);
1529 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1530 md_gather_operands (s
, insn
, opcode
);
1533 #ifndef WORKING_DOT_WORD
1534 /* Handle long and short jumps. We don't support these */
1536 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1538 addressT from_addr
, to_addr
;
1546 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1548 addressT from_addr
, to_addr
;
1558 int ignore ATTRIBUTE_UNUSED
;
1560 /* We don't support putting frags in the BSS segment, we fake it
1561 by marking in_bss, then looking at s_skip for clues. */
1563 subseg_set (bss_section
, 0);
1564 demand_empty_rest_of_line ();
1567 /* Pseudo-op handling. */
1571 int ignore ATTRIBUTE_UNUSED
;
1574 const struct s390_opcode
*opformat
;
1575 unsigned char insn
[6];
1578 /* Get the opcode format. */
1579 s
= input_line_pointer
;
1580 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1583 as_bad (_("Invalid .insn format\n"));
1586 /* Look up the opcode in the hash table. */
1587 opformat
= (struct s390_opcode
*)
1588 hash_find (s390_opformat_hash
, input_line_pointer
);
1589 if (opformat
== (const struct s390_opcode
*) NULL
)
1591 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1594 input_line_pointer
= s
;
1596 if (exp
.X_op
== O_constant
)
1598 if ( ( opformat
->oplen
== 6
1599 && exp
.X_add_number
>= 0
1600 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1601 || ( opformat
->oplen
== 4
1602 && exp
.X_add_number
>= 0
1603 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1604 || ( opformat
->oplen
== 2
1605 && exp
.X_add_number
>= 0
1606 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1607 md_number_to_chars (insn
, exp
.X_add_number
, opformat
->oplen
);
1609 as_bad (_("Invalid .insn format\n"));
1611 else if (exp
.X_op
== O_big
)
1613 if (exp
.X_add_number
> 0
1614 && opformat
->oplen
== 6
1615 && generic_bignum
[3] == 0)
1617 md_number_to_chars (insn
, generic_bignum
[2], 2);
1618 md_number_to_chars (&insn
[2], generic_bignum
[1], 2);
1619 md_number_to_chars (&insn
[4], generic_bignum
[0], 2);
1622 as_bad (_("Invalid .insn format\n"));
1625 as_bad (_("second operand of .insn not a constant\n"));
1627 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1628 as_bad (_("missing comma after insn constant\n"));
1630 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1632 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1636 demand_empty_rest_of_line ();
1639 /* The .byte pseudo-op. This is similar to the normal .byte
1640 pseudo-op, but it can also take a single ASCII string. */
1644 int ignore ATTRIBUTE_UNUSED
;
1646 if (*input_line_pointer
!= '\"')
1652 /* Gather characters. A real double quote is doubled. Unusual
1653 characters are not permitted. */
1654 ++input_line_pointer
;
1659 c
= *input_line_pointer
++;
1663 if (*input_line_pointer
!= '\"')
1665 ++input_line_pointer
;
1668 FRAG_APPEND_1_CHAR (c
);
1671 demand_empty_rest_of_line ();
1674 /* The .ltorg pseudo-op.This emits all literals defined since the last
1675 .ltorg or the invocation of gas. Literals are defined with the
1679 s390_literals (ignore
)
1680 int ignore ATTRIBUTE_UNUSED
;
1682 struct s390_lpe
*lpe
;
1684 if (lp_sym
== NULL
|| lpe_count
== 0)
1685 return; /* Nothing to be done. */
1687 /* Emit symbol for start of literal pool. */
1688 S_SET_SEGMENT (lp_sym
, now_seg
);
1689 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1690 lp_sym
->sy_frag
= frag_now
;
1695 lpe_list
= lpe_list
->next
;
1696 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1697 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1698 lpe
->sym
->sy_frag
= frag_now
;
1700 /* Emit literal pool entry. */
1701 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1703 reloc_howto_type
*reloc_howto
=
1704 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1705 int size
= bfd_get_reloc_size (reloc_howto
);
1708 if (size
> lpe
->nbytes
)
1709 as_bad (_("%s relocations do not fit in %d bytes"),
1710 reloc_howto
->name
, lpe
->nbytes
);
1711 where
= frag_more (lpe
->nbytes
);
1712 md_number_to_chars (where
, 0, size
);
1713 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1714 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1718 if (lpe
->ex
.X_op
== O_big
)
1720 if (lpe
->ex
.X_add_number
<= 0)
1721 generic_floating_point_number
= lpe
->floatnum
;
1723 memcpy (generic_bignum
, lpe
->bignum
,
1724 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1726 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1729 lpe
->next
= lpe_free_list
;
1730 lpe_free_list
= lpe
;
1732 lpe_list_tail
= NULL
;
1738 /* Turn a string in input_line_pointer into a floating point constant
1739 of type type, and store the appropriate bytes in *litp. The number
1740 of LITTLENUMS emitted is stored in *sizep . An error message is
1741 returned, or NULL on OK. */
1744 md_atof (type
, litp
, sizep
)
1750 LITTLENUM_TYPE words
[4];
1766 return "bad call to md_atof";
1769 t
= atof_ieee (input_line_pointer
, type
, words
);
1771 input_line_pointer
= t
;
1775 for (i
= 0; i
< prec
; i
++)
1777 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1784 /* Align a section (I don't know why this is machine dependent). */
1787 md_section_align (seg
, addr
)
1791 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1793 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1796 /* We don't have any form of relaxing. */
1799 md_estimate_size_before_relax (fragp
, seg
)
1800 fragS
*fragp ATTRIBUTE_UNUSED
;
1801 asection
*seg ATTRIBUTE_UNUSED
;
1807 /* Convert a machine dependent frag. We never generate these. */
1810 md_convert_frag (abfd
, sec
, fragp
)
1811 bfd
*abfd ATTRIBUTE_UNUSED
;
1812 asection
*sec ATTRIBUTE_UNUSED
;
1813 fragS
*fragp ATTRIBUTE_UNUSED
;
1819 md_undefined_symbol (name
)
1822 if (*name
== '_' && *(name
+ 1) == 'G'
1823 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1827 if (symbol_find (name
))
1828 as_bad (_("GOT already in symbol table"));
1829 GOT_symbol
= symbol_new (name
, undefined_section
,
1830 (valueT
) 0, &zero_address_frag
);
1837 /* Functions concerning relocs. */
1839 /* The location from which a PC relative jump should be calculated,
1840 given a PC relative reloc. */
1843 md_pcrel_from_section (fixp
, sec
)
1845 segT sec ATTRIBUTE_UNUSED
;
1847 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1850 /* Here we decide which fixups can be adjusted to make them relative to
1851 the beginning of the section instead of the symbol. Basically we need
1852 to make sure that the dynamic relocations are done correctly, so in
1853 some cases we force the original symbol to be used. */
1855 tc_s390_fix_adjustable (fixP
)
1858 /* Don't adjust references to merge sections. */
1859 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
1861 /* adjust_reloc_syms doesn't know about the GOT. */
1862 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
1863 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1864 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
1865 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
1866 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
1867 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
1868 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1869 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1870 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1871 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1872 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1873 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
1874 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
1875 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
1876 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
1877 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
1878 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
1879 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
1880 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
1881 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
1882 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
1883 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
1884 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
1885 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
1886 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
1887 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
1888 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
1889 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
1890 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
1891 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
1892 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
1893 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
1894 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
1895 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
1896 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
1897 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
1898 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
1899 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
1900 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
1901 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
1902 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
1903 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
1904 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
1905 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1906 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1911 /* Return true if we must always emit a reloc for a type and false if
1912 there is some hope of resolving it at assembly time. */
1914 tc_s390_force_relocation (fixp
)
1917 /* Ensure we emit a relocation for every reference to the global
1918 offset table or to the procedure link table. */
1919 switch (fixp
->fx_r_type
)
1921 case BFD_RELOC_390_GOT12
:
1922 case BFD_RELOC_390_GOT20
:
1923 case BFD_RELOC_32_GOT_PCREL
:
1924 case BFD_RELOC_32_GOTOFF
:
1925 case BFD_RELOC_390_GOTOFF64
:
1926 case BFD_RELOC_390_PLTOFF16
:
1927 case BFD_RELOC_390_PLTOFF32
:
1928 case BFD_RELOC_390_PLTOFF64
:
1929 case BFD_RELOC_390_GOTPC
:
1930 case BFD_RELOC_390_GOT16
:
1931 case BFD_RELOC_390_GOTPCDBL
:
1932 case BFD_RELOC_390_GOT64
:
1933 case BFD_RELOC_390_GOTENT
:
1934 case BFD_RELOC_390_PLT32
:
1935 case BFD_RELOC_390_PLT16DBL
:
1936 case BFD_RELOC_390_PLT32DBL
:
1937 case BFD_RELOC_390_PLT64
:
1938 case BFD_RELOC_390_GOTPLT12
:
1939 case BFD_RELOC_390_GOTPLT16
:
1940 case BFD_RELOC_390_GOTPLT20
:
1941 case BFD_RELOC_390_GOTPLT32
:
1942 case BFD_RELOC_390_GOTPLT64
:
1943 case BFD_RELOC_390_GOTPLTENT
:
1949 return generic_force_reloc (fixp
);
1952 /* Apply a fixup to the object code. This is called for all the
1953 fixups we generated by the call to fix_new_exp, above. In the call
1954 above we used a reloc code which was the largest legal reloc code
1955 plus the operand index. Here we undo that to recover the operand
1956 index. At this point all symbol values should be fully resolved,
1957 and we attempt to completely resolve the reloc. If we can not do
1958 that, we determine the correct reloc code and put it back in the
1962 md_apply_fix3 (fixP
, valP
, seg
)
1965 segT seg ATTRIBUTE_UNUSED
;
1968 valueT value
= *valP
;
1970 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1972 if (fixP
->fx_subsy
!= NULL
)
1973 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1974 "cannot emit relocation %s against subsy symbol %s",
1975 bfd_get_reloc_code_name (fixP
->fx_r_type
),
1976 S_GET_NAME (fixP
->fx_subsy
));
1978 if (fixP
->fx_addsy
!= NULL
)
1981 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1986 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1988 const struct s390_operand
*operand
;
1991 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1992 operand
= &s390_operands
[opindex
];
1996 /* Insert the fully resolved operand value. */
1997 s390_insert_operand (where
, operand
, (offsetT
) value
,
1998 fixP
->fx_file
, fixP
->fx_line
);
2002 /* Determine a BFD reloc value based on the operand information.
2003 We are only prepared to turn a few of the operands into
2005 fixP
->fx_offset
= value
;
2006 if (operand
->bits
== 12 && operand
->shift
== 20)
2009 fixP
->fx_where
+= 2;
2010 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2012 else if (operand
->bits
== 12 && operand
->shift
== 36)
2015 fixP
->fx_where
+= 4;
2016 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2018 else if (operand
->bits
== 20 && operand
->shift
== 20)
2021 fixP
->fx_where
+= 2;
2022 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2024 else if (operand
->bits
== 8 && operand
->shift
== 8)
2027 fixP
->fx_where
+= 1;
2028 fixP
->fx_r_type
= BFD_RELOC_8
;
2030 else if (operand
->bits
== 16 && operand
->shift
== 16)
2033 fixP
->fx_where
+= 2;
2034 if (operand
->flags
& S390_OPERAND_PCREL
)
2036 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2037 fixP
->fx_offset
+= 2;
2040 fixP
->fx_r_type
= BFD_RELOC_16
;
2042 else if (operand
->bits
== 32 && operand
->shift
== 16
2043 && (operand
->flags
& S390_OPERAND_PCREL
))
2046 fixP
->fx_where
+= 2;
2047 fixP
->fx_offset
+= 2;
2048 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2055 /* Use expr_symbol_where to see if this is an expression
2057 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2058 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2059 _("unresolved expression that must be resolved"));
2061 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2062 _("unsupported relocation type"));
2069 switch (fixP
->fx_r_type
)
2075 md_number_to_chars (where
, value
, 1);
2077 case BFD_RELOC_390_12
:
2078 case BFD_RELOC_390_GOT12
:
2079 case BFD_RELOC_390_GOTPLT12
:
2084 mop
= bfd_getb16 ((unsigned char *) where
);
2085 mop
|= (unsigned short) (value
& 0xfff);
2086 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2090 case BFD_RELOC_390_20
:
2091 case BFD_RELOC_390_GOT20
:
2092 case BFD_RELOC_390_GOTPLT20
:
2096 mop
= bfd_getb32 ((unsigned char *) where
);
2097 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2098 (value
& 0xff000) >> 12);
2099 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2104 case BFD_RELOC_GPREL16
:
2105 case BFD_RELOC_16_GOT_PCREL
:
2106 case BFD_RELOC_16_GOTOFF
:
2108 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2109 "cannot emit PC relative %s relocation%s%s",
2110 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2111 fixP
->fx_addsy
!= NULL
? " against " : "",
2112 (fixP
->fx_addsy
!= NULL
2113 ? S_GET_NAME (fixP
->fx_addsy
)
2116 md_number_to_chars (where
, value
, 2);
2118 case BFD_RELOC_390_GOT16
:
2119 case BFD_RELOC_390_PLTOFF16
:
2120 case BFD_RELOC_390_GOTPLT16
:
2122 md_number_to_chars (where
, value
, 2);
2124 case BFD_RELOC_390_PC16DBL
:
2125 case BFD_RELOC_390_PLT16DBL
:
2128 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2133 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2135 fixP
->fx_r_type
= BFD_RELOC_32
;
2137 md_number_to_chars (where
, value
, 4);
2139 case BFD_RELOC_32_PCREL
:
2140 case BFD_RELOC_32_BASEREL
:
2141 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2143 md_number_to_chars (where
, value
, 4);
2145 case BFD_RELOC_32_GOT_PCREL
:
2146 case BFD_RELOC_390_PLTOFF32
:
2147 case BFD_RELOC_390_PLT32
:
2148 case BFD_RELOC_390_GOTPLT32
:
2150 md_number_to_chars (where
, value
, 4);
2152 case BFD_RELOC_390_PC32DBL
:
2153 case BFD_RELOC_390_PLT32DBL
:
2154 case BFD_RELOC_390_GOTPCDBL
:
2155 case BFD_RELOC_390_GOTENT
:
2156 case BFD_RELOC_390_GOTPLTENT
:
2159 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2162 case BFD_RELOC_32_GOTOFF
:
2164 md_number_to_chars (where
, value
, sizeof (int));
2167 case BFD_RELOC_390_GOTOFF64
:
2169 md_number_to_chars (where
, value
, 8);
2172 case BFD_RELOC_390_GOT64
:
2173 case BFD_RELOC_390_PLTOFF64
:
2174 case BFD_RELOC_390_PLT64
:
2175 case BFD_RELOC_390_GOTPLT64
:
2177 md_number_to_chars (where
, value
, 8);
2182 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2184 fixP
->fx_r_type
= BFD_RELOC_64
;
2186 md_number_to_chars (where
, value
, 8);
2189 case BFD_RELOC_64_PCREL
:
2190 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2192 md_number_to_chars (where
, value
, 8);
2195 case BFD_RELOC_VTABLE_INHERIT
:
2196 case BFD_RELOC_VTABLE_ENTRY
:
2200 case BFD_RELOC_390_TLS_LOAD
:
2201 case BFD_RELOC_390_TLS_GDCALL
:
2202 case BFD_RELOC_390_TLS_LDCALL
:
2203 case BFD_RELOC_390_TLS_GD32
:
2204 case BFD_RELOC_390_TLS_GD64
:
2205 case BFD_RELOC_390_TLS_GOTIE12
:
2206 case BFD_RELOC_390_TLS_GOTIE20
:
2207 case BFD_RELOC_390_TLS_GOTIE32
:
2208 case BFD_RELOC_390_TLS_GOTIE64
:
2209 case BFD_RELOC_390_TLS_LDM32
:
2210 case BFD_RELOC_390_TLS_LDM64
:
2211 case BFD_RELOC_390_TLS_IE32
:
2212 case BFD_RELOC_390_TLS_IE64
:
2213 case BFD_RELOC_390_TLS_LE32
:
2214 case BFD_RELOC_390_TLS_LE64
:
2215 case BFD_RELOC_390_TLS_LDO32
:
2216 case BFD_RELOC_390_TLS_LDO64
:
2217 case BFD_RELOC_390_TLS_DTPMOD
:
2218 case BFD_RELOC_390_TLS_DTPOFF
:
2219 case BFD_RELOC_390_TLS_TPOFF
:
2220 /* Fully resolved at link time. */
2222 case BFD_RELOC_390_TLS_IEENT
:
2223 /* Fully resolved at link time. */
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)