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
)
605 "operand out of range (%s not between %ld and %ld)";
608 if (operand
->flags
& S390_OPERAND_LENGTH
)
614 sprint_value (buf
, uval
);
615 if (file
== (char *) NULL
)
616 as_bad (err
, buf
, (int) min
, (int) max
);
618 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
623 /* Insert fragments of the operand byte for byte. */
624 offset
= operand
->shift
+ operand
->bits
;
625 uval
<<= (-offset
) & 7;
626 insn
+= (offset
- 1) / 8;
638 bfd_reloc_code_real_type reloc
;
641 static bfd_reloc_code_real_type s390_tls_suffix
642 PARAMS ((char **, expressionS
*));
644 /* Parse tls marker and return the desired relocation. */
645 static bfd_reloc_code_real_type
646 s390_tls_suffix (str_p
, exp_p
)
650 static struct map_tls mapping
[] =
652 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
653 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
654 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
655 { NULL
, 0, BFD_RELOC_UNUSED
}
665 return BFD_RELOC_UNUSED
;
668 while (ISIDNUM (*str
))
672 return BFD_RELOC_UNUSED
;
674 orig_line
= input_line_pointer
;
675 input_line_pointer
= str
;
677 str
= input_line_pointer
;
678 if (&input_line_pointer
!= str_p
)
679 input_line_pointer
= orig_line
;
681 if (exp_p
->X_op
!= O_symbol
)
682 return BFD_RELOC_UNUSED
;
684 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
685 if (len
== ptr
->length
686 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
688 /* Found a matching tls suffix. */
692 return BFD_RELOC_UNUSED
;
695 /* Structure used to hold suffixes. */
706 ELF_SUFFIX_TLS_GOTIE
,
718 elf_suffix_type suffix
;
721 static elf_suffix_type s390_elf_suffix
PARAMS ((char **, expressionS
*));
722 static int s390_exp_compare
PARAMS ((expressionS
*exp1
, expressionS
*exp2
));
723 static elf_suffix_type s390_lit_suffix
724 PARAMS ((char **, expressionS
*, elf_suffix_type
));
727 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
728 static elf_suffix_type
729 s390_elf_suffix (str_p
, exp_p
)
733 static struct map_bfd mapping
[] =
735 { "got", 3, ELF_SUFFIX_GOT
},
736 { "got12", 5, ELF_SUFFIX_GOT
},
737 { "plt", 3, ELF_SUFFIX_PLT
},
738 { "gotent", 6, ELF_SUFFIX_GOTENT
},
739 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
740 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
741 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
742 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
743 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
744 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
745 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
746 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
747 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
748 { NULL
, 0, ELF_SUFFIX_NONE
}
757 return ELF_SUFFIX_NONE
;
760 while (ISALNUM (*str
))
764 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
765 if (len
== ptr
->length
766 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
768 if (exp_p
->X_add_number
!= 0)
769 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
770 ptr
->string
, ptr
->string
);
771 /* Now check for identifier@suffix+constant. */
772 if (*str
== '-' || *str
== '+')
774 char *orig_line
= input_line_pointer
;
777 input_line_pointer
= str
;
778 expression (&new_exp
);
780 switch (new_exp
.X_op
)
782 case O_constant
: /* X_add_number (a constant expression). */
783 exp_p
->X_add_number
+= new_exp
.X_add_number
;
784 str
= input_line_pointer
;
786 case O_symbol
: /* X_add_symbol + X_add_number. */
787 /* this case is used for e.g. xyz@PLT+.Label. */
788 exp_p
->X_add_number
+= new_exp
.X_add_number
;
789 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
791 str
= input_line_pointer
;
793 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
794 /* this case is used for e.g. xyz@PLT-.Label. */
795 exp_p
->X_add_number
+= new_exp
.X_add_number
;
796 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
797 exp_p
->X_op
= O_subtract
;
798 str
= input_line_pointer
;
804 /* If s390_elf_suffix has not been called with
805 &input_line_pointer as first parameter, we have
806 clobbered the input_line_pointer. We have to
808 if (&input_line_pointer
!= str_p
)
809 input_line_pointer
= orig_line
;
815 return BFD_RELOC_UNUSED
;
818 /* Structure used to hold a literal pool entry. */
821 struct s390_lpe
*next
;
823 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
824 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
826 bfd_reloc_code_real_type reloc
;
830 static struct s390_lpe
*lpe_free_list
= NULL
;
831 static struct s390_lpe
*lpe_list
= NULL
;
832 static struct s390_lpe
*lpe_list_tail
= NULL
;
833 static symbolS
*lp_sym
= NULL
;
834 static int lp_count
= 0;
835 static int lpe_count
= 0;
838 s390_exp_compare (exp1
, exp2
)
842 if (exp1
->X_op
!= exp2
->X_op
)
847 case O_constant
: /* X_add_number must be equal. */
849 return exp1
->X_add_number
== exp2
->X_add_number
;
852 as_bad (_("Can't handle O_big in s390_exp_compare"));
854 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
859 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
860 && (exp1
->X_add_number
== exp2
->X_add_number
);
862 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
867 case O_bit_inclusive_or
:
869 case O_bit_exclusive_or
:
881 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
882 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
883 && (exp1
->X_add_number
== exp2
->X_add_number
);
889 /* Test for @lit and if its present make an entry in the literal pool and
890 modify the current expression to be an offset into the literal pool. */
891 static elf_suffix_type
892 s390_lit_suffix (str_p
, exp_p
, suffix
)
895 elf_suffix_type suffix
;
897 bfd_reloc_code_real_type reloc
;
901 struct s390_lpe
*lpe
;
905 return suffix
; /* No modification. */
907 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
909 while (ISALNUM (*str
))
912 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
913 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
914 return suffix
; /* no modification */
915 nbytes
= ident
[3] - '0';
917 reloc
= BFD_RELOC_UNUSED
;
918 if (suffix
== ELF_SUFFIX_GOT
)
921 reloc
= BFD_RELOC_390_GOT16
;
922 else if (nbytes
== 4)
923 reloc
= BFD_RELOC_32_GOT_PCREL
;
924 else if (nbytes
== 8)
925 reloc
= BFD_RELOC_390_GOT64
;
927 else if (suffix
== ELF_SUFFIX_PLT
)
930 reloc
= BFD_RELOC_390_PLT32
;
931 else if (nbytes
== 8)
932 reloc
= BFD_RELOC_390_PLT64
;
935 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
936 as_bad (_("Invalid suffix for literal pool entry"));
938 /* Search the pool if the new entry is a duplicate. */
939 if (exp_p
->X_op
== O_big
)
941 /* Special processing for big numbers. */
942 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
944 if (lpe
->ex
.X_op
== O_big
)
946 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
948 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
949 sizeof (FLONUM_TYPE
)) == 0)
952 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
954 if (memcmp (generic_bignum
, lpe
->bignum
,
955 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
963 /* Processing for 'normal' data types. */
964 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
965 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
966 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
973 if (lpe_free_list
!= NULL
)
976 lpe_free_list
= lpe_free_list
->next
;
980 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
985 if (exp_p
->X_op
== O_big
)
987 if (exp_p
->X_add_number
<= 0)
988 lpe
->floatnum
= generic_floating_point_number
;
989 else if (exp_p
->X_add_number
<= 4)
990 memcpy (lpe
->bignum
, generic_bignum
,
991 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
993 as_bad (_("Big number is too big"));
996 lpe
->nbytes
= nbytes
;
998 /* Literal pool name defined ? */
1001 sprintf (tmp_name
, ".L\001%i", lp_count
);
1002 lp_sym
= symbol_make (tmp_name
);
1005 /* Make name for literal pool entry. */
1006 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1008 lpe
->sym
= symbol_make (tmp_name
);
1010 /* Add to literal pool list. */
1012 if (lpe_list_tail
!= NULL
)
1014 lpe_list_tail
->next
= lpe
;
1015 lpe_list_tail
= lpe
;
1018 lpe_list
= lpe_list_tail
= lpe
;
1021 /* Now change exp_p to the offset into the literal pool.
1022 Thats the expression: .L^Ax^By-.L^Ax */
1023 exp_p
->X_add_symbol
= lpe
->sym
;
1024 exp_p
->X_op_symbol
= lp_sym
;
1025 exp_p
->X_op
= O_subtract
;
1026 exp_p
->X_add_number
= 0;
1030 /* We change the suffix type to ELF_SUFFIX_NONE, because
1031 the difference of two local labels is just a number. */
1032 return ELF_SUFFIX_NONE
;
1035 /* Like normal .long/.short/.word, except support @got, etc.
1036 clobbers input_line_pointer, checks end-of-line. */
1038 s390_elf_cons (nbytes
)
1039 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1042 elf_suffix_type suffix
;
1044 if (is_it_end_of_statement ())
1046 demand_empty_rest_of_line ();
1054 if (exp
.X_op
== O_symbol
1055 && *input_line_pointer
== '@'
1056 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1058 bfd_reloc_code_real_type reloc
;
1059 reloc_howto_type
*reloc_howto
;
1065 static bfd_reloc_code_real_type tab2
[] =
1067 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1068 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1069 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1070 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1071 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1072 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1073 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1074 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1075 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1076 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1077 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1078 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1079 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1081 reloc
= tab2
[suffix
];
1083 else if (nbytes
== 4)
1085 static bfd_reloc_code_real_type tab4
[] =
1087 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1088 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1089 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1090 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1091 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1092 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1093 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1094 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1095 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1096 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1097 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1098 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1099 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1101 reloc
= tab4
[suffix
];
1103 else if (nbytes
== 8)
1105 static bfd_reloc_code_real_type tab8
[] =
1107 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1108 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1109 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1110 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1111 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1112 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1113 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1114 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1115 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1116 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1117 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1118 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1119 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1121 reloc
= tab8
[suffix
];
1124 reloc
= BFD_RELOC_UNUSED
;
1126 if (reloc
!= BFD_RELOC_UNUSED
1127 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1129 size
= bfd_get_reloc_size (reloc_howto
);
1131 as_bad (_("%s relocations do not fit in %d bytes"),
1132 reloc_howto
->name
, nbytes
);
1133 where
= frag_more (nbytes
);
1134 md_number_to_chars (where
, 0, size
);
1135 /* To make fixup_segment do the pc relative conversion the
1136 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1137 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1138 size
, &exp
, FALSE
, reloc
);
1141 as_bad (_("relocation not applicable"));
1144 emit_expr (&exp
, (unsigned int) nbytes
);
1146 while (*input_line_pointer
++ == ',');
1148 input_line_pointer
--; /* Put terminator back into stream. */
1149 demand_empty_rest_of_line ();
1152 /* We need to keep a list of fixups. We can't simply generate them as
1153 we go, because that would require us to first create the frag, and
1154 that would screw up references to ``.''. */
1160 bfd_reloc_code_real_type reloc
;
1163 #define MAX_INSN_FIXUPS (4)
1165 /* This routine is called for each instruction to be assembled. */
1168 md_gather_operands (str
, insn
, opcode
)
1170 unsigned char *insn
;
1171 const struct s390_opcode
*opcode
;
1173 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1174 const struct s390_operand
*operand
;
1175 const unsigned char *opindex_ptr
;
1177 elf_suffix_type suffix
;
1178 bfd_reloc_code_real_type reloc
;
1184 while (ISSPACE (*str
))
1190 /* Gather the operands. */
1192 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1196 operand
= s390_operands
+ *opindex_ptr
;
1198 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1200 /* We do an early skip. For D(X,B) constructions the index
1201 register is skipped (X is optional). For D(L,B) the base
1202 register will be the skipped operand, because L is NOT
1208 /* Gather the operand. */
1209 hold
= input_line_pointer
;
1210 input_line_pointer
= str
;
1212 /* Parse the operand. */
1213 if (! register_name (&ex
))
1216 str
= input_line_pointer
;
1217 input_line_pointer
= hold
;
1219 /* Write the operand to the insn. */
1220 if (ex
.X_op
== O_illegal
)
1221 as_bad (_("illegal operand"));
1222 else if (ex
.X_op
== O_absent
)
1223 as_bad (_("missing operand"));
1224 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1226 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1228 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1230 /* We need to generate a fixup for the
1231 expression returned by s390_lit_suffix. */
1232 if (fc
>= MAX_INSN_FIXUPS
)
1233 as_fatal (_("too many fixups"));
1234 fixups
[fc
].exp
= ex
;
1235 fixups
[fc
].opindex
= *opindex_ptr
;
1236 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1241 if ((operand
->flags
& S390_OPERAND_INDEX
)
1242 && ex
.X_add_number
== 0
1244 as_warn ("index register specified but zero");
1245 if ((operand
->flags
& S390_OPERAND_BASE
)
1246 && ex
.X_add_number
== 0
1248 as_warn ("base register specified but zero");
1249 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1254 suffix
= s390_elf_suffix (&str
, &ex
);
1255 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1256 reloc
= BFD_RELOC_UNUSED
;
1258 if (suffix
== ELF_SUFFIX_GOT
)
1260 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1261 (operand
->bits
== 12))
1262 reloc
= BFD_RELOC_390_GOT12
;
1263 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1264 (operand
->bits
== 20))
1265 reloc
= BFD_RELOC_390_GOT20
;
1266 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1267 && (operand
->bits
== 16))
1268 reloc
= BFD_RELOC_390_GOT16
;
1269 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1270 && (operand
->bits
== 32))
1271 reloc
= BFD_RELOC_390_GOTENT
;
1273 else if (suffix
== ELF_SUFFIX_PLT
)
1275 if ((operand
->flags
& S390_OPERAND_PCREL
)
1276 && (operand
->bits
== 16))
1277 reloc
= BFD_RELOC_390_PLT16DBL
;
1278 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1279 && (operand
->bits
== 32))
1280 reloc
= BFD_RELOC_390_PLT32DBL
;
1282 else if (suffix
== ELF_SUFFIX_GOTENT
)
1284 if ((operand
->flags
& S390_OPERAND_PCREL
)
1285 && (operand
->bits
== 32))
1286 reloc
= BFD_RELOC_390_GOTENT
;
1288 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1290 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1291 && (operand
->bits
== 16))
1292 reloc
= BFD_RELOC_16_GOTOFF
;
1294 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1296 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1297 && (operand
->bits
== 16))
1298 reloc
= BFD_RELOC_390_PLTOFF16
;
1300 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1302 if ((operand
->flags
& S390_OPERAND_DISP
)
1303 && (operand
->bits
== 12))
1304 reloc
= BFD_RELOC_390_GOTPLT12
;
1305 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1306 && (operand
->bits
== 16))
1307 reloc
= BFD_RELOC_390_GOTPLT16
;
1308 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1309 && (operand
->bits
== 32))
1310 reloc
= BFD_RELOC_390_GOTPLTENT
;
1312 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1314 if ((operand
->flags
& S390_OPERAND_DISP
)
1315 && (operand
->bits
== 12))
1316 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1317 else if ((operand
->flags
& S390_OPERAND_DISP
)
1318 && (operand
->bits
== 20))
1319 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1321 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1323 if ((operand
->flags
& S390_OPERAND_PCREL
)
1324 && (operand
->bits
== 32))
1325 reloc
= BFD_RELOC_390_TLS_IEENT
;
1328 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1329 as_bad (_("invalid operand suffix"));
1330 /* We need to generate a fixup of type 'reloc' for this
1332 if (fc
>= MAX_INSN_FIXUPS
)
1333 as_fatal (_("too many fixups"));
1334 fixups
[fc
].exp
= ex
;
1335 fixups
[fc
].opindex
= *opindex_ptr
;
1336 fixups
[fc
].reloc
= reloc
;
1340 /* Check the next character. The call to expression has advanced
1341 str past any whitespace. */
1342 if (operand
->flags
& S390_OPERAND_DISP
)
1344 /* After a displacement a block in parentheses can start. */
1347 /* Check if parenthesized block can be skipped. If the next
1348 operand is neiter an optional operand nor a base register
1349 then we have a syntax error. */
1350 operand
= s390_operands
+ *(++opindex_ptr
);
1351 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1352 as_bad (_("syntax error; missing '(' after displacement"));
1354 /* Ok, skip all operands until S390_OPERAND_BASE. */
1355 while (!(operand
->flags
& S390_OPERAND_BASE
))
1356 operand
= s390_operands
+ *(++opindex_ptr
);
1358 /* If there is a next operand it must be separated by a comma. */
1359 if (opindex_ptr
[1] != '\0')
1362 as_bad (_("syntax error; expected ,"));
1367 /* We found an opening parentheses. */
1369 for (f
= str
; *f
!= '\0'; f
++)
1370 if (*f
== ',' || *f
== ')')
1372 /* If there is no comma until the closing parentheses OR
1373 there is a comma right after the opening parentheses,
1374 we have to skip optional operands. */
1375 if (*f
== ',' && f
== str
)
1377 /* comma directly after '(' ? */
1382 skip_optional
= (*f
!= ',');
1385 else if (operand
->flags
& S390_OPERAND_BASE
)
1387 /* After the base register the parenthesed block ends. */
1389 as_bad (_("syntax error; missing ')' after base register"));
1391 /* If there is a next operand it must be separated by a comma. */
1392 if (opindex_ptr
[1] != '\0')
1395 as_bad (_("syntax error; expected ,"));
1400 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1401 of D(L,B). In this case the base register has to be skipped. */
1404 operand
= s390_operands
+ *(++opindex_ptr
);
1406 if (!(operand
->flags
& S390_OPERAND_BASE
))
1407 as_bad (_("syntax error; ')' not allowed here"));
1410 /* If there is a next operand it must be separated by a comma. */
1411 if (opindex_ptr
[1] != '\0')
1414 as_bad (_("syntax error; expected ,"));
1419 while (ISSPACE (*str
))
1422 /* Check for tls instruction marker. */
1423 reloc
= s390_tls_suffix (&str
, &ex
);
1424 if (reloc
!= BFD_RELOC_UNUSED
)
1426 /* We need to generate a fixup of type 'reloc' for this
1428 if (fc
>= MAX_INSN_FIXUPS
)
1429 as_fatal (_("too many fixups"));
1430 fixups
[fc
].exp
= ex
;
1431 fixups
[fc
].opindex
= -1;
1432 fixups
[fc
].reloc
= reloc
;
1440 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1442 as_bad (_("junk at end of line: `%s'"), str
);
1443 if (linefeed
!= NULL
)
1447 /* Write out the instruction. */
1448 f
= frag_more (opcode
->oplen
);
1449 memcpy (f
, insn
, opcode
->oplen
);
1450 dwarf2_emit_insn (opcode
->oplen
);
1452 /* Create any fixups. At this point we do not use a
1453 bfd_reloc_code_real_type, but instead just use the
1454 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1455 handle fixups for any operand type, although that is admittedly
1456 not a very exciting feature. We pick a BFD reloc type in
1458 for (i
= 0; i
< fc
; i
++)
1461 if (fixups
[i
].opindex
< 0)
1463 /* Create tls instruction marker relocation. */
1464 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1465 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1469 operand
= s390_operands
+ fixups
[i
].opindex
;
1471 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1473 reloc_howto_type
*reloc_howto
;
1477 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1481 size
= bfd_get_reloc_size (reloc_howto
);
1483 if (size
< 1 || size
> 4)
1486 fixP
= fix_new_exp (frag_now
,
1487 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1488 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1490 /* Turn off overflow checking in fixup_segment. This is necessary
1491 because fixup_segment will signal an overflow for large 4 byte
1492 quantities for GOT12 relocations. */
1493 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1494 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1495 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1496 fixP
->fx_no_overflow
= 1;
1499 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1500 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1501 ((bfd_reloc_code_real_type
)
1502 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1507 /* This routine is called for each instruction to be assembled. */
1513 const struct s390_opcode
*opcode
;
1514 unsigned char insn
[6];
1517 /* Get the opcode. */
1518 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1523 /* Look up the opcode in the hash table. */
1524 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1525 if (opcode
== (const struct s390_opcode
*) NULL
)
1527 as_bad (_("Unrecognized opcode: `%s'"), str
);
1530 else if (!(opcode
->modes
& current_mode_mask
))
1532 as_bad ("Opcode %s not available in this mode", str
);
1535 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1536 md_gather_operands (s
, insn
, opcode
);
1539 #ifndef WORKING_DOT_WORD
1540 /* Handle long and short jumps. We don't support these */
1542 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1544 addressT from_addr
, to_addr
;
1552 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1554 addressT from_addr
, to_addr
;
1564 int ignore ATTRIBUTE_UNUSED
;
1566 /* We don't support putting frags in the BSS segment, we fake it
1567 by marking in_bss, then looking at s_skip for clues. */
1569 subseg_set (bss_section
, 0);
1570 demand_empty_rest_of_line ();
1573 /* Pseudo-op handling. */
1577 int ignore ATTRIBUTE_UNUSED
;
1580 const struct s390_opcode
*opformat
;
1581 unsigned char insn
[6];
1584 /* Get the opcode format. */
1585 s
= input_line_pointer
;
1586 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1589 as_bad (_("Invalid .insn format\n"));
1592 /* Look up the opcode in the hash table. */
1593 opformat
= (struct s390_opcode
*)
1594 hash_find (s390_opformat_hash
, input_line_pointer
);
1595 if (opformat
== (const struct s390_opcode
*) NULL
)
1597 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1600 input_line_pointer
= s
;
1602 if (exp
.X_op
== O_constant
)
1604 if ( ( opformat
->oplen
== 6
1605 && exp
.X_add_number
>= 0
1606 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1607 || ( opformat
->oplen
== 4
1608 && exp
.X_add_number
>= 0
1609 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1610 || ( opformat
->oplen
== 2
1611 && exp
.X_add_number
>= 0
1612 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1613 md_number_to_chars (insn
, exp
.X_add_number
, opformat
->oplen
);
1615 as_bad (_("Invalid .insn format\n"));
1617 else if (exp
.X_op
== O_big
)
1619 if (exp
.X_add_number
> 0
1620 && opformat
->oplen
== 6
1621 && generic_bignum
[3] == 0)
1623 md_number_to_chars (insn
, generic_bignum
[2], 2);
1624 md_number_to_chars (&insn
[2], generic_bignum
[1], 2);
1625 md_number_to_chars (&insn
[4], generic_bignum
[0], 2);
1628 as_bad (_("Invalid .insn format\n"));
1631 as_bad (_("second operand of .insn not a constant\n"));
1633 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1634 as_bad (_("missing comma after insn constant\n"));
1636 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1638 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1642 demand_empty_rest_of_line ();
1645 /* The .byte pseudo-op. This is similar to the normal .byte
1646 pseudo-op, but it can also take a single ASCII string. */
1650 int ignore ATTRIBUTE_UNUSED
;
1652 if (*input_line_pointer
!= '\"')
1658 /* Gather characters. A real double quote is doubled. Unusual
1659 characters are not permitted. */
1660 ++input_line_pointer
;
1665 c
= *input_line_pointer
++;
1669 if (*input_line_pointer
!= '\"')
1671 ++input_line_pointer
;
1674 FRAG_APPEND_1_CHAR (c
);
1677 demand_empty_rest_of_line ();
1680 /* The .ltorg pseudo-op.This emits all literals defined since the last
1681 .ltorg or the invocation of gas. Literals are defined with the
1685 s390_literals (ignore
)
1686 int ignore ATTRIBUTE_UNUSED
;
1688 struct s390_lpe
*lpe
;
1690 if (lp_sym
== NULL
|| lpe_count
== 0)
1691 return; /* Nothing to be done. */
1693 /* Emit symbol for start of literal pool. */
1694 S_SET_SEGMENT (lp_sym
, now_seg
);
1695 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1696 lp_sym
->sy_frag
= frag_now
;
1701 lpe_list
= lpe_list
->next
;
1702 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1703 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1704 lpe
->sym
->sy_frag
= frag_now
;
1706 /* Emit literal pool entry. */
1707 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1709 reloc_howto_type
*reloc_howto
=
1710 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1711 int size
= bfd_get_reloc_size (reloc_howto
);
1714 if (size
> lpe
->nbytes
)
1715 as_bad (_("%s relocations do not fit in %d bytes"),
1716 reloc_howto
->name
, lpe
->nbytes
);
1717 where
= frag_more (lpe
->nbytes
);
1718 md_number_to_chars (where
, 0, size
);
1719 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1720 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1724 if (lpe
->ex
.X_op
== O_big
)
1726 if (lpe
->ex
.X_add_number
<= 0)
1727 generic_floating_point_number
= lpe
->floatnum
;
1729 memcpy (generic_bignum
, lpe
->bignum
,
1730 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1732 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1735 lpe
->next
= lpe_free_list
;
1736 lpe_free_list
= lpe
;
1738 lpe_list_tail
= NULL
;
1744 /* Turn a string in input_line_pointer into a floating point constant
1745 of type type, and store the appropriate bytes in *litp. The number
1746 of LITTLENUMS emitted is stored in *sizep . An error message is
1747 returned, or NULL on OK. */
1750 md_atof (type
, litp
, sizep
)
1756 LITTLENUM_TYPE words
[4];
1772 return "bad call to md_atof";
1775 t
= atof_ieee (input_line_pointer
, type
, words
);
1777 input_line_pointer
= t
;
1781 for (i
= 0; i
< prec
; i
++)
1783 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1790 /* Align a section (I don't know why this is machine dependent). */
1793 md_section_align (seg
, addr
)
1797 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1799 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1802 /* We don't have any form of relaxing. */
1805 md_estimate_size_before_relax (fragp
, seg
)
1806 fragS
*fragp ATTRIBUTE_UNUSED
;
1807 asection
*seg ATTRIBUTE_UNUSED
;
1813 /* Convert a machine dependent frag. We never generate these. */
1816 md_convert_frag (abfd
, sec
, fragp
)
1817 bfd
*abfd ATTRIBUTE_UNUSED
;
1818 asection
*sec ATTRIBUTE_UNUSED
;
1819 fragS
*fragp ATTRIBUTE_UNUSED
;
1825 md_undefined_symbol (name
)
1828 if (*name
== '_' && *(name
+ 1) == 'G'
1829 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1833 if (symbol_find (name
))
1834 as_bad (_("GOT already in symbol table"));
1835 GOT_symbol
= symbol_new (name
, undefined_section
,
1836 (valueT
) 0, &zero_address_frag
);
1843 /* Functions concerning relocs. */
1845 /* The location from which a PC relative jump should be calculated,
1846 given a PC relative reloc. */
1849 md_pcrel_from_section (fixp
, sec
)
1851 segT sec ATTRIBUTE_UNUSED
;
1853 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1856 /* Here we decide which fixups can be adjusted to make them relative to
1857 the beginning of the section instead of the symbol. Basically we need
1858 to make sure that the dynamic relocations are done correctly, so in
1859 some cases we force the original symbol to be used. */
1861 tc_s390_fix_adjustable (fixP
)
1864 /* Don't adjust references to merge sections. */
1865 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
1867 /* adjust_reloc_syms doesn't know about the GOT. */
1868 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
1869 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1870 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
1871 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
1872 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
1873 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
1874 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1875 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1876 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1877 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1878 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1879 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
1880 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
1881 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
1882 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
1883 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
1884 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
1885 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
1886 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
1887 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
1888 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
1889 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
1890 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
1891 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
1892 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
1893 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
1894 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
1895 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
1896 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
1897 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
1898 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
1899 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
1900 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
1901 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
1902 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
1903 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
1904 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
1905 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
1906 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
1907 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
1908 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
1909 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
1910 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
1911 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1912 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1917 /* Return true if we must always emit a reloc for a type and false if
1918 there is some hope of resolving it at assembly time. */
1920 tc_s390_force_relocation (fixp
)
1923 /* Ensure we emit a relocation for every reference to the global
1924 offset table or to the procedure link table. */
1925 switch (fixp
->fx_r_type
)
1927 case BFD_RELOC_390_GOT12
:
1928 case BFD_RELOC_390_GOT20
:
1929 case BFD_RELOC_32_GOT_PCREL
:
1930 case BFD_RELOC_32_GOTOFF
:
1931 case BFD_RELOC_390_GOTOFF64
:
1932 case BFD_RELOC_390_PLTOFF16
:
1933 case BFD_RELOC_390_PLTOFF32
:
1934 case BFD_RELOC_390_PLTOFF64
:
1935 case BFD_RELOC_390_GOTPC
:
1936 case BFD_RELOC_390_GOT16
:
1937 case BFD_RELOC_390_GOTPCDBL
:
1938 case BFD_RELOC_390_GOT64
:
1939 case BFD_RELOC_390_GOTENT
:
1940 case BFD_RELOC_390_PLT32
:
1941 case BFD_RELOC_390_PLT16DBL
:
1942 case BFD_RELOC_390_PLT32DBL
:
1943 case BFD_RELOC_390_PLT64
:
1944 case BFD_RELOC_390_GOTPLT12
:
1945 case BFD_RELOC_390_GOTPLT16
:
1946 case BFD_RELOC_390_GOTPLT20
:
1947 case BFD_RELOC_390_GOTPLT32
:
1948 case BFD_RELOC_390_GOTPLT64
:
1949 case BFD_RELOC_390_GOTPLTENT
:
1955 return generic_force_reloc (fixp
);
1958 /* Apply a fixup to the object code. This is called for all the
1959 fixups we generated by the call to fix_new_exp, above. In the call
1960 above we used a reloc code which was the largest legal reloc code
1961 plus the operand index. Here we undo that to recover the operand
1962 index. At this point all symbol values should be fully resolved,
1963 and we attempt to completely resolve the reloc. If we can not do
1964 that, we determine the correct reloc code and put it back in the
1968 md_apply_fix3 (fixP
, valP
, seg
)
1971 segT seg ATTRIBUTE_UNUSED
;
1974 valueT value
= *valP
;
1976 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1978 if (fixP
->fx_subsy
!= NULL
)
1979 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1980 "cannot emit relocation %s against subsy symbol %s",
1981 bfd_get_reloc_code_name (fixP
->fx_r_type
),
1982 S_GET_NAME (fixP
->fx_subsy
));
1984 if (fixP
->fx_addsy
!= NULL
)
1987 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1992 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1994 const struct s390_operand
*operand
;
1997 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1998 operand
= &s390_operands
[opindex
];
2002 /* Insert the fully resolved operand value. */
2003 s390_insert_operand (where
, operand
, (offsetT
) value
,
2004 fixP
->fx_file
, fixP
->fx_line
);
2008 /* Determine a BFD reloc value based on the operand information.
2009 We are only prepared to turn a few of the operands into
2011 fixP
->fx_offset
= value
;
2012 if (operand
->bits
== 12 && operand
->shift
== 20)
2015 fixP
->fx_where
+= 2;
2016 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2018 else if (operand
->bits
== 12 && operand
->shift
== 36)
2021 fixP
->fx_where
+= 4;
2022 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2024 else if (operand
->bits
== 20 && operand
->shift
== 20)
2027 fixP
->fx_where
+= 2;
2028 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2030 else if (operand
->bits
== 8 && operand
->shift
== 8)
2033 fixP
->fx_where
+= 1;
2034 fixP
->fx_r_type
= BFD_RELOC_8
;
2036 else if (operand
->bits
== 16 && operand
->shift
== 16)
2039 fixP
->fx_where
+= 2;
2040 if (operand
->flags
& S390_OPERAND_PCREL
)
2042 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2043 fixP
->fx_offset
+= 2;
2046 fixP
->fx_r_type
= BFD_RELOC_16
;
2048 else if (operand
->bits
== 32 && operand
->shift
== 16
2049 && (operand
->flags
& S390_OPERAND_PCREL
))
2052 fixP
->fx_where
+= 2;
2053 fixP
->fx_offset
+= 2;
2054 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2061 /* Use expr_symbol_where to see if this is an expression
2063 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2064 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2065 _("unresolved expression that must be resolved"));
2067 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2068 _("unsupported relocation type"));
2075 switch (fixP
->fx_r_type
)
2081 md_number_to_chars (where
, value
, 1);
2083 case BFD_RELOC_390_12
:
2084 case BFD_RELOC_390_GOT12
:
2085 case BFD_RELOC_390_GOTPLT12
:
2090 mop
= bfd_getb16 ((unsigned char *) where
);
2091 mop
|= (unsigned short) (value
& 0xfff);
2092 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2096 case BFD_RELOC_390_20
:
2097 case BFD_RELOC_390_GOT20
:
2098 case BFD_RELOC_390_GOTPLT20
:
2102 mop
= bfd_getb32 ((unsigned char *) where
);
2103 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2104 (value
& 0xff000) >> 12);
2105 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2110 case BFD_RELOC_GPREL16
:
2111 case BFD_RELOC_16_GOT_PCREL
:
2112 case BFD_RELOC_16_GOTOFF
:
2114 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2115 "cannot emit PC relative %s relocation%s%s",
2116 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2117 fixP
->fx_addsy
!= NULL
? " against " : "",
2118 (fixP
->fx_addsy
!= NULL
2119 ? S_GET_NAME (fixP
->fx_addsy
)
2122 md_number_to_chars (where
, value
, 2);
2124 case BFD_RELOC_390_GOT16
:
2125 case BFD_RELOC_390_PLTOFF16
:
2126 case BFD_RELOC_390_GOTPLT16
:
2128 md_number_to_chars (where
, value
, 2);
2130 case BFD_RELOC_390_PC16DBL
:
2131 case BFD_RELOC_390_PLT16DBL
:
2134 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2139 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2141 fixP
->fx_r_type
= BFD_RELOC_32
;
2143 md_number_to_chars (where
, value
, 4);
2145 case BFD_RELOC_32_PCREL
:
2146 case BFD_RELOC_32_BASEREL
:
2147 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2149 md_number_to_chars (where
, value
, 4);
2151 case BFD_RELOC_32_GOT_PCREL
:
2152 case BFD_RELOC_390_PLTOFF32
:
2153 case BFD_RELOC_390_PLT32
:
2154 case BFD_RELOC_390_GOTPLT32
:
2156 md_number_to_chars (where
, value
, 4);
2158 case BFD_RELOC_390_PC32DBL
:
2159 case BFD_RELOC_390_PLT32DBL
:
2160 case BFD_RELOC_390_GOTPCDBL
:
2161 case BFD_RELOC_390_GOTENT
:
2162 case BFD_RELOC_390_GOTPLTENT
:
2165 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2168 case BFD_RELOC_32_GOTOFF
:
2170 md_number_to_chars (where
, value
, sizeof (int));
2173 case BFD_RELOC_390_GOTOFF64
:
2175 md_number_to_chars (where
, value
, 8);
2178 case BFD_RELOC_390_GOT64
:
2179 case BFD_RELOC_390_PLTOFF64
:
2180 case BFD_RELOC_390_PLT64
:
2181 case BFD_RELOC_390_GOTPLT64
:
2183 md_number_to_chars (where
, value
, 8);
2188 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2190 fixP
->fx_r_type
= BFD_RELOC_64
;
2192 md_number_to_chars (where
, value
, 8);
2195 case BFD_RELOC_64_PCREL
:
2196 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2198 md_number_to_chars (where
, value
, 8);
2201 case BFD_RELOC_VTABLE_INHERIT
:
2202 case BFD_RELOC_VTABLE_ENTRY
:
2206 case BFD_RELOC_390_TLS_LOAD
:
2207 case BFD_RELOC_390_TLS_GDCALL
:
2208 case BFD_RELOC_390_TLS_LDCALL
:
2209 case BFD_RELOC_390_TLS_GD32
:
2210 case BFD_RELOC_390_TLS_GD64
:
2211 case BFD_RELOC_390_TLS_GOTIE12
:
2212 case BFD_RELOC_390_TLS_GOTIE20
:
2213 case BFD_RELOC_390_TLS_GOTIE32
:
2214 case BFD_RELOC_390_TLS_GOTIE64
:
2215 case BFD_RELOC_390_TLS_LDM32
:
2216 case BFD_RELOC_390_TLS_LDM64
:
2217 case BFD_RELOC_390_TLS_IE32
:
2218 case BFD_RELOC_390_TLS_IE64
:
2219 case BFD_RELOC_390_TLS_LE32
:
2220 case BFD_RELOC_390_TLS_LE64
:
2221 case BFD_RELOC_390_TLS_LDO32
:
2222 case BFD_RELOC_390_TLS_LDO64
:
2223 case BFD_RELOC_390_TLS_DTPMOD
:
2224 case BFD_RELOC_390_TLS_DTPOFF
:
2225 case BFD_RELOC_390_TLS_TPOFF
:
2226 /* Fully resolved at link time. */
2228 case BFD_RELOC_390_TLS_IEENT
:
2229 /* Fully resolved at link time. */
2235 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2237 if (reloc_name
!= NULL
)
2238 fprintf (stderr
, "Gas failure, reloc type %s\n", reloc_name
);
2240 fprintf (stderr
, "Gas failure, reloc type #%i\n", fixP
->fx_r_type
);
2246 fixP
->fx_offset
= value
;
2250 /* Generate a reloc for a fixup. */
2253 tc_gen_reloc (seg
, fixp
)
2254 asection
*seg ATTRIBUTE_UNUSED
;
2257 bfd_reloc_code_real_type code
;
2260 code
= fixp
->fx_r_type
;
2261 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2263 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2264 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2265 code
= BFD_RELOC_390_GOTPC
;
2266 if (code
== BFD_RELOC_390_PC32DBL
)
2267 code
= BFD_RELOC_390_GOTPCDBL
;
2270 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2271 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2272 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2273 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2274 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2275 if (reloc
->howto
== NULL
)
2277 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2278 _("cannot represent relocation type %s"),
2279 bfd_get_reloc_code_name (code
));
2280 /* Set howto to a garbage value so that we can keep going. */
2281 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2282 assert (reloc
->howto
!= NULL
);
2284 reloc
->addend
= fixp
->fx_offset
;
2290 s390_cfi_frame_initial_instructions ()
2292 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2296 tc_s390_regname_to_dw2regnum (const char *regname
)
2300 if (regname
[0] != 'c' && regname
[0] != 'a')
2302 regnum
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, regname
);
2303 if (regname
[0] == 'f' && regnum
!= -1)
2306 else if (strcmp (regname
, "ap") == 0)
2308 else if (strcmp (regname
, "cc") == 0)