1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003 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
);
544 s390_align_code (fragP
, count
)
548 /* We use nop pattern 0x0707. */
551 memset (fragP
->fr_literal
+ fragP
->fr_fix
, 0x07, count
);
552 fragP
->fr_var
= count
;
556 /* Insert an operand value into an instruction. */
559 s390_insert_operand (insn
, operand
, val
, file
, line
)
561 const struct s390_operand
*operand
;
569 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
573 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
574 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
575 /* Halve PCREL operands. */
576 if (operand
->flags
& S390_OPERAND_PCREL
)
578 /* Check for underflow / overflow. */
579 if (val
< min
|| val
> max
)
582 "operand out of range (%s not between %ld and %ld)";
585 if (operand
->flags
& S390_OPERAND_PCREL
)
591 sprint_value (buf
, val
);
592 if (file
== (char *) NULL
)
593 as_bad (err
, buf
, (int) min
, (int) max
);
595 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
598 /* val is ok, now restrict it to operand->bits bits. */
599 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
600 /* val is restrict, now check for special case. */
601 if (operand
->bits
== 20 && operand
->shift
== 20)
602 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
608 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
610 uval
= (addressT
) val
;
611 /* Length x in an instructions has real length x+1. */
612 if (operand
->flags
& S390_OPERAND_LENGTH
)
614 /* Check for underflow / overflow. */
615 if (uval
< min
|| uval
> max
)
618 "operand out of range (%s not between %ld and %ld)";
621 if (operand
->flags
& S390_OPERAND_LENGTH
)
627 sprint_value (buf
, uval
);
628 if (file
== (char *) NULL
)
629 as_bad (err
, buf
, (int) min
, (int) max
);
631 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
636 /* Insert fragments of the operand byte for byte. */
637 offset
= operand
->shift
+ operand
->bits
;
638 uval
<<= (-offset
) & 7;
639 insn
+= (offset
- 1) / 8;
651 bfd_reloc_code_real_type reloc
;
654 static bfd_reloc_code_real_type s390_tls_suffix
655 PARAMS ((char **, expressionS
*));
657 /* Parse tls marker and return the desired relocation. */
658 static bfd_reloc_code_real_type
659 s390_tls_suffix (str_p
, exp_p
)
663 static struct map_tls mapping
[] =
665 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
666 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
667 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
668 { NULL
, 0, BFD_RELOC_UNUSED
}
678 return BFD_RELOC_UNUSED
;
681 while (ISIDNUM (*str
))
685 return BFD_RELOC_UNUSED
;
687 orig_line
= input_line_pointer
;
688 input_line_pointer
= str
;
690 str
= input_line_pointer
;
691 if (&input_line_pointer
!= str_p
)
692 input_line_pointer
= orig_line
;
694 if (exp_p
->X_op
!= O_symbol
)
695 return BFD_RELOC_UNUSED
;
697 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
698 if (len
== ptr
->length
699 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
701 /* Found a matching tls suffix. */
705 return BFD_RELOC_UNUSED
;
708 /* Structure used to hold suffixes. */
719 ELF_SUFFIX_TLS_GOTIE
,
731 elf_suffix_type suffix
;
734 static elf_suffix_type s390_elf_suffix
PARAMS ((char **, expressionS
*));
735 static int s390_exp_compare
PARAMS ((expressionS
*exp1
, expressionS
*exp2
));
736 static elf_suffix_type s390_lit_suffix
737 PARAMS ((char **, expressionS
*, elf_suffix_type
));
740 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
741 static elf_suffix_type
742 s390_elf_suffix (str_p
, exp_p
)
746 static struct map_bfd mapping
[] =
748 { "got", 3, ELF_SUFFIX_GOT
},
749 { "got12", 5, ELF_SUFFIX_GOT
},
750 { "plt", 3, ELF_SUFFIX_PLT
},
751 { "gotent", 6, ELF_SUFFIX_GOTENT
},
752 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
753 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
754 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
755 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
756 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
757 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
758 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
759 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
760 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
761 { NULL
, 0, ELF_SUFFIX_NONE
}
770 return ELF_SUFFIX_NONE
;
773 while (ISALNUM (*str
))
777 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
778 if (len
== ptr
->length
779 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
781 if (exp_p
->X_add_number
!= 0)
782 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
783 ptr
->string
, ptr
->string
);
784 /* Now check for identifier@suffix+constant. */
785 if (*str
== '-' || *str
== '+')
787 char *orig_line
= input_line_pointer
;
790 input_line_pointer
= str
;
791 expression (&new_exp
);
793 switch (new_exp
.X_op
)
795 case O_constant
: /* X_add_number (a constant expression). */
796 exp_p
->X_add_number
+= new_exp
.X_add_number
;
797 str
= input_line_pointer
;
799 case O_symbol
: /* X_add_symbol + X_add_number. */
800 /* this case is used for e.g. xyz@PLT+.Label. */
801 exp_p
->X_add_number
+= new_exp
.X_add_number
;
802 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
804 str
= input_line_pointer
;
806 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
807 /* this case is used for e.g. xyz@PLT-.Label. */
808 exp_p
->X_add_number
+= new_exp
.X_add_number
;
809 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
810 exp_p
->X_op
= O_subtract
;
811 str
= input_line_pointer
;
817 /* If s390_elf_suffix has not been called with
818 &input_line_pointer as first parameter, we have
819 clobbered the input_line_pointer. We have to
821 if (&input_line_pointer
!= str_p
)
822 input_line_pointer
= orig_line
;
828 return BFD_RELOC_UNUSED
;
831 /* Structure used to hold a literal pool entry. */
834 struct s390_lpe
*next
;
836 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
837 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
839 bfd_reloc_code_real_type reloc
;
843 static struct s390_lpe
*lpe_free_list
= NULL
;
844 static struct s390_lpe
*lpe_list
= NULL
;
845 static struct s390_lpe
*lpe_list_tail
= NULL
;
846 static symbolS
*lp_sym
= NULL
;
847 static int lp_count
= 0;
848 static int lpe_count
= 0;
851 s390_exp_compare (exp1
, exp2
)
855 if (exp1
->X_op
!= exp2
->X_op
)
860 case O_constant
: /* X_add_number must be equal. */
862 return exp1
->X_add_number
== exp2
->X_add_number
;
865 as_bad (_("Can't handle O_big in s390_exp_compare"));
867 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
872 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
873 && (exp1
->X_add_number
== exp2
->X_add_number
);
875 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
880 case O_bit_inclusive_or
:
882 case O_bit_exclusive_or
:
894 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
895 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
896 && (exp1
->X_add_number
== exp2
->X_add_number
);
902 /* Test for @lit and if its present make an entry in the literal pool and
903 modify the current expression to be an offset into the literal pool. */
904 static elf_suffix_type
905 s390_lit_suffix (str_p
, exp_p
, suffix
)
908 elf_suffix_type suffix
;
910 bfd_reloc_code_real_type reloc
;
914 struct s390_lpe
*lpe
;
918 return suffix
; /* No modification. */
920 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
922 while (ISALNUM (*str
))
925 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
926 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
927 return suffix
; /* no modification */
928 nbytes
= ident
[3] - '0';
930 reloc
= BFD_RELOC_UNUSED
;
931 if (suffix
== ELF_SUFFIX_GOT
)
934 reloc
= BFD_RELOC_390_GOT16
;
935 else if (nbytes
== 4)
936 reloc
= BFD_RELOC_32_GOT_PCREL
;
937 else if (nbytes
== 8)
938 reloc
= BFD_RELOC_390_GOT64
;
940 else if (suffix
== ELF_SUFFIX_PLT
)
943 reloc
= BFD_RELOC_390_PLT32
;
944 else if (nbytes
== 8)
945 reloc
= BFD_RELOC_390_PLT64
;
948 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
949 as_bad (_("Invalid suffix for literal pool entry"));
951 /* Search the pool if the new entry is a duplicate. */
952 if (exp_p
->X_op
== O_big
)
954 /* Special processing for big numbers. */
955 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
957 if (lpe
->ex
.X_op
== O_big
)
959 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
961 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
962 sizeof (FLONUM_TYPE
)) == 0)
965 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
967 if (memcmp (generic_bignum
, lpe
->bignum
,
968 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
976 /* Processing for 'normal' data types. */
977 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
978 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
979 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
986 if (lpe_free_list
!= NULL
)
989 lpe_free_list
= lpe_free_list
->next
;
993 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
998 if (exp_p
->X_op
== O_big
)
1000 if (exp_p
->X_add_number
<= 0)
1001 lpe
->floatnum
= generic_floating_point_number
;
1002 else if (exp_p
->X_add_number
<= 4)
1003 memcpy (lpe
->bignum
, generic_bignum
,
1004 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1006 as_bad (_("Big number is too big"));
1009 lpe
->nbytes
= nbytes
;
1011 /* Literal pool name defined ? */
1014 sprintf (tmp_name
, ".L\001%i", lp_count
);
1015 lp_sym
= symbol_make (tmp_name
);
1018 /* Make name for literal pool entry. */
1019 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1021 lpe
->sym
= symbol_make (tmp_name
);
1023 /* Add to literal pool list. */
1025 if (lpe_list_tail
!= NULL
)
1027 lpe_list_tail
->next
= lpe
;
1028 lpe_list_tail
= lpe
;
1031 lpe_list
= lpe_list_tail
= lpe
;
1034 /* Now change exp_p to the offset into the literal pool.
1035 Thats the expression: .L^Ax^By-.L^Ax */
1036 exp_p
->X_add_symbol
= lpe
->sym
;
1037 exp_p
->X_op_symbol
= lp_sym
;
1038 exp_p
->X_op
= O_subtract
;
1039 exp_p
->X_add_number
= 0;
1043 /* We change the suffix type to ELF_SUFFIX_NONE, because
1044 the difference of two local labels is just a number. */
1045 return ELF_SUFFIX_NONE
;
1048 /* Like normal .long/.short/.word, except support @got, etc.
1049 clobbers input_line_pointer, checks end-of-line. */
1051 s390_elf_cons (nbytes
)
1052 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1055 elf_suffix_type suffix
;
1057 if (is_it_end_of_statement ())
1059 demand_empty_rest_of_line ();
1067 if (exp
.X_op
== O_symbol
1068 && *input_line_pointer
== '@'
1069 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1071 bfd_reloc_code_real_type reloc
;
1072 reloc_howto_type
*reloc_howto
;
1078 static bfd_reloc_code_real_type tab2
[] =
1080 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1081 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1082 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1083 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1084 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1085 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1086 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1087 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1088 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1089 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1090 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1091 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1092 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1094 reloc
= tab2
[suffix
];
1096 else if (nbytes
== 4)
1098 static bfd_reloc_code_real_type tab4
[] =
1100 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1101 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1102 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1103 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1104 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1105 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1106 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1107 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1108 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1109 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1110 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1111 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1112 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1114 reloc
= tab4
[suffix
];
1116 else if (nbytes
== 8)
1118 static bfd_reloc_code_real_type tab8
[] =
1120 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1121 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1122 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1123 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1124 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1125 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1126 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1127 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1128 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1129 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1130 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1131 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1132 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1134 reloc
= tab8
[suffix
];
1137 reloc
= BFD_RELOC_UNUSED
;
1139 if (reloc
!= BFD_RELOC_UNUSED
1140 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1142 size
= bfd_get_reloc_size (reloc_howto
);
1144 as_bad (_("%s relocations do not fit in %d bytes"),
1145 reloc_howto
->name
, nbytes
);
1146 where
= frag_more (nbytes
);
1147 md_number_to_chars (where
, 0, size
);
1148 /* To make fixup_segment do the pc relative conversion the
1149 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1150 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1151 size
, &exp
, FALSE
, reloc
);
1154 as_bad (_("relocation not applicable"));
1157 emit_expr (&exp
, (unsigned int) nbytes
);
1159 while (*input_line_pointer
++ == ',');
1161 input_line_pointer
--; /* Put terminator back into stream. */
1162 demand_empty_rest_of_line ();
1165 /* We need to keep a list of fixups. We can't simply generate them as
1166 we go, because that would require us to first create the frag, and
1167 that would screw up references to ``.''. */
1173 bfd_reloc_code_real_type reloc
;
1176 #define MAX_INSN_FIXUPS (4)
1178 /* This routine is called for each instruction to be assembled. */
1181 md_gather_operands (str
, insn
, opcode
)
1183 unsigned char *insn
;
1184 const struct s390_opcode
*opcode
;
1186 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1187 const struct s390_operand
*operand
;
1188 const unsigned char *opindex_ptr
;
1190 elf_suffix_type suffix
;
1191 bfd_reloc_code_real_type reloc
;
1197 while (ISSPACE (*str
))
1203 /* Gather the operands. */
1205 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1209 operand
= s390_operands
+ *opindex_ptr
;
1211 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1213 /* We do an early skip. For D(X,B) constructions the index
1214 register is skipped (X is optional). For D(L,B) the base
1215 register will be the skipped operand, because L is NOT
1221 /* Gather the operand. */
1222 hold
= input_line_pointer
;
1223 input_line_pointer
= str
;
1225 /* Parse the operand. */
1226 if (! register_name (&ex
))
1229 str
= input_line_pointer
;
1230 input_line_pointer
= hold
;
1232 /* Write the operand to the insn. */
1233 if (ex
.X_op
== O_illegal
)
1234 as_bad (_("illegal operand"));
1235 else if (ex
.X_op
== O_absent
)
1236 as_bad (_("missing operand"));
1237 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1239 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1241 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1243 /* We need to generate a fixup for the
1244 expression returned by s390_lit_suffix. */
1245 if (fc
>= MAX_INSN_FIXUPS
)
1246 as_fatal (_("too many fixups"));
1247 fixups
[fc
].exp
= ex
;
1248 fixups
[fc
].opindex
= *opindex_ptr
;
1249 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1254 if ((operand
->flags
& S390_OPERAND_INDEX
)
1255 && ex
.X_add_number
== 0
1257 as_warn ("index register specified but zero");
1258 if ((operand
->flags
& S390_OPERAND_BASE
)
1259 && ex
.X_add_number
== 0
1261 as_warn ("base register specified but zero");
1262 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1267 suffix
= s390_elf_suffix (&str
, &ex
);
1268 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1269 reloc
= BFD_RELOC_UNUSED
;
1271 if (suffix
== ELF_SUFFIX_GOT
)
1273 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1274 (operand
->bits
== 12))
1275 reloc
= BFD_RELOC_390_GOT12
;
1276 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1277 (operand
->bits
== 20))
1278 reloc
= BFD_RELOC_390_GOT20
;
1279 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1280 && (operand
->bits
== 16))
1281 reloc
= BFD_RELOC_390_GOT16
;
1282 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1283 && (operand
->bits
== 32))
1284 reloc
= BFD_RELOC_390_GOTENT
;
1286 else if (suffix
== ELF_SUFFIX_PLT
)
1288 if ((operand
->flags
& S390_OPERAND_PCREL
)
1289 && (operand
->bits
== 16))
1290 reloc
= BFD_RELOC_390_PLT16DBL
;
1291 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1292 && (operand
->bits
== 32))
1293 reloc
= BFD_RELOC_390_PLT32DBL
;
1295 else if (suffix
== ELF_SUFFIX_GOTENT
)
1297 if ((operand
->flags
& S390_OPERAND_PCREL
)
1298 && (operand
->bits
== 32))
1299 reloc
= BFD_RELOC_390_GOTENT
;
1301 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1303 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1304 && (operand
->bits
== 16))
1305 reloc
= BFD_RELOC_16_GOTOFF
;
1307 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1309 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1310 && (operand
->bits
== 16))
1311 reloc
= BFD_RELOC_390_PLTOFF16
;
1313 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1315 if ((operand
->flags
& S390_OPERAND_DISP
)
1316 && (operand
->bits
== 12))
1317 reloc
= BFD_RELOC_390_GOTPLT12
;
1318 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1319 && (operand
->bits
== 16))
1320 reloc
= BFD_RELOC_390_GOTPLT16
;
1321 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1322 && (operand
->bits
== 32))
1323 reloc
= BFD_RELOC_390_GOTPLTENT
;
1325 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1327 if ((operand
->flags
& S390_OPERAND_DISP
)
1328 && (operand
->bits
== 12))
1329 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1330 else if ((operand
->flags
& S390_OPERAND_DISP
)
1331 && (operand
->bits
== 20))
1332 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1334 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1336 if ((operand
->flags
& S390_OPERAND_PCREL
)
1337 && (operand
->bits
== 32))
1338 reloc
= BFD_RELOC_390_TLS_IEENT
;
1341 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1342 as_bad (_("invalid operand suffix"));
1343 /* We need to generate a fixup of type 'reloc' for this
1345 if (fc
>= MAX_INSN_FIXUPS
)
1346 as_fatal (_("too many fixups"));
1347 fixups
[fc
].exp
= ex
;
1348 fixups
[fc
].opindex
= *opindex_ptr
;
1349 fixups
[fc
].reloc
= reloc
;
1353 /* Check the next character. The call to expression has advanced
1354 str past any whitespace. */
1355 if (operand
->flags
& S390_OPERAND_DISP
)
1357 /* After a displacement a block in parentheses can start. */
1360 /* Check if parenthesized block can be skipped. If the next
1361 operand is neiter an optional operand nor a base register
1362 then we have a syntax error. */
1363 operand
= s390_operands
+ *(++opindex_ptr
);
1364 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1365 as_bad (_("syntax error; missing '(' after displacement"));
1367 /* Ok, skip all operands until S390_OPERAND_BASE. */
1368 while (!(operand
->flags
& S390_OPERAND_BASE
))
1369 operand
= s390_operands
+ *(++opindex_ptr
);
1371 /* If there is a next operand it must be separated by a comma. */
1372 if (opindex_ptr
[1] != '\0')
1375 as_bad (_("syntax error; expected ,"));
1380 /* We found an opening parentheses. */
1382 for (f
= str
; *f
!= '\0'; f
++)
1383 if (*f
== ',' || *f
== ')')
1385 /* If there is no comma until the closing parentheses OR
1386 there is a comma right after the opening parentheses,
1387 we have to skip optional operands. */
1388 if (*f
== ',' && f
== str
)
1390 /* comma directly after '(' ? */
1395 skip_optional
= (*f
!= ',');
1398 else if (operand
->flags
& S390_OPERAND_BASE
)
1400 /* After the base register the parenthesed block ends. */
1402 as_bad (_("syntax error; missing ')' after base register"));
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 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1414 of D(L,B). In this case the base register has to be skipped. */
1417 operand
= s390_operands
+ *(++opindex_ptr
);
1419 if (!(operand
->flags
& S390_OPERAND_BASE
))
1420 as_bad (_("syntax error; ')' not allowed here"));
1423 /* If there is a next operand it must be separated by a comma. */
1424 if (opindex_ptr
[1] != '\0')
1427 as_bad (_("syntax error; expected ,"));
1432 while (ISSPACE (*str
))
1435 /* Check for tls instruction marker. */
1436 reloc
= s390_tls_suffix (&str
, &ex
);
1437 if (reloc
!= BFD_RELOC_UNUSED
)
1439 /* We need to generate a fixup of type 'reloc' for this
1441 if (fc
>= MAX_INSN_FIXUPS
)
1442 as_fatal (_("too many fixups"));
1443 fixups
[fc
].exp
= ex
;
1444 fixups
[fc
].opindex
= -1;
1445 fixups
[fc
].reloc
= reloc
;
1453 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1455 as_bad (_("junk at end of line: `%s'"), str
);
1456 if (linefeed
!= NULL
)
1460 /* Write out the instruction. */
1461 f
= frag_more (opcode
->oplen
);
1462 memcpy (f
, insn
, opcode
->oplen
);
1463 dwarf2_emit_insn (opcode
->oplen
);
1465 /* Create any fixups. At this point we do not use a
1466 bfd_reloc_code_real_type, but instead just use the
1467 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1468 handle fixups for any operand type, although that is admittedly
1469 not a very exciting feature. We pick a BFD reloc type in
1471 for (i
= 0; i
< fc
; i
++)
1474 if (fixups
[i
].opindex
< 0)
1476 /* Create tls instruction marker relocation. */
1477 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1478 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1482 operand
= s390_operands
+ fixups
[i
].opindex
;
1484 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1486 reloc_howto_type
*reloc_howto
;
1490 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1494 size
= bfd_get_reloc_size (reloc_howto
);
1496 if (size
< 1 || size
> 4)
1499 fixP
= fix_new_exp (frag_now
,
1500 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1501 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1503 /* Turn off overflow checking in fixup_segment. This is necessary
1504 because fixup_segment will signal an overflow for large 4 byte
1505 quantities for GOT12 relocations. */
1506 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1507 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1508 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1509 fixP
->fx_no_overflow
= 1;
1512 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1513 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1514 ((bfd_reloc_code_real_type
)
1515 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1520 /* This routine is called for each instruction to be assembled. */
1526 const struct s390_opcode
*opcode
;
1527 unsigned char insn
[6];
1530 /* Get the opcode. */
1531 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1536 /* Look up the opcode in the hash table. */
1537 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1538 if (opcode
== (const struct s390_opcode
*) NULL
)
1540 as_bad (_("Unrecognized opcode: `%s'"), str
);
1543 else if (!(opcode
->modes
& current_mode_mask
))
1545 as_bad ("Opcode %s not available in this mode", str
);
1548 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1549 md_gather_operands (s
, insn
, opcode
);
1552 #ifndef WORKING_DOT_WORD
1553 /* Handle long and short jumps. We don't support these */
1555 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1557 addressT from_addr
, to_addr
;
1565 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1567 addressT from_addr
, to_addr
;
1577 int ignore ATTRIBUTE_UNUSED
;
1579 /* We don't support putting frags in the BSS segment, we fake it
1580 by marking in_bss, then looking at s_skip for clues. */
1582 subseg_set (bss_section
, 0);
1583 demand_empty_rest_of_line ();
1586 /* Pseudo-op handling. */
1590 int ignore ATTRIBUTE_UNUSED
;
1593 const struct s390_opcode
*opformat
;
1594 unsigned char insn
[6];
1597 /* Get the opcode format. */
1598 s
= input_line_pointer
;
1599 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1602 as_bad (_("Invalid .insn format\n"));
1605 /* Look up the opcode in the hash table. */
1606 opformat
= (struct s390_opcode
*)
1607 hash_find (s390_opformat_hash
, input_line_pointer
);
1608 if (opformat
== (const struct s390_opcode
*) NULL
)
1610 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1613 input_line_pointer
= s
;
1615 if (exp
.X_op
== O_constant
)
1617 if ( (opformat
->oplen
== 6 && exp
.X_op
> 0 && exp
.X_op
< (1ULL << 48))
1618 || (opformat
->oplen
== 4 && exp
.X_op
> 0 && exp
.X_op
< (1ULL << 32))
1619 || (opformat
->oplen
== 2 && exp
.X_op
> 0 && exp
.X_op
< (1ULL << 16)))
1620 md_number_to_chars (insn
, exp
.X_add_number
, opformat
->oplen
);
1622 as_bad (_("Invalid .insn format\n"));
1624 else if (exp
.X_op
== O_big
)
1626 if (exp
.X_add_number
> 0
1627 && opformat
->oplen
== 6
1628 && generic_bignum
[3] == 0)
1630 md_number_to_chars (insn
, generic_bignum
[2], 2);
1631 md_number_to_chars (&insn
[2], generic_bignum
[1], 2);
1632 md_number_to_chars (&insn
[4], generic_bignum
[0], 2);
1635 as_bad (_("Invalid .insn format\n"));
1638 as_bad (_("second operand of .insn not a constant\n"));
1640 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1641 as_bad (_("missing comma after insn constant\n"));
1643 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1645 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1649 demand_empty_rest_of_line ();
1652 /* The .byte pseudo-op. This is similar to the normal .byte
1653 pseudo-op, but it can also take a single ASCII string. */
1657 int ignore ATTRIBUTE_UNUSED
;
1659 if (*input_line_pointer
!= '\"')
1665 /* Gather characters. A real double quote is doubled. Unusual
1666 characters are not permitted. */
1667 ++input_line_pointer
;
1672 c
= *input_line_pointer
++;
1676 if (*input_line_pointer
!= '\"')
1678 ++input_line_pointer
;
1681 FRAG_APPEND_1_CHAR (c
);
1684 demand_empty_rest_of_line ();
1687 /* The .ltorg pseudo-op.This emits all literals defined since the last
1688 .ltorg or the invocation of gas. Literals are defined with the
1692 s390_literals (ignore
)
1693 int ignore ATTRIBUTE_UNUSED
;
1695 struct s390_lpe
*lpe
;
1697 if (lp_sym
== NULL
|| lpe_count
== 0)
1698 return; /* Nothing to be done. */
1700 /* Emit symbol for start of literal pool. */
1701 S_SET_SEGMENT (lp_sym
, now_seg
);
1702 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1703 lp_sym
->sy_frag
= frag_now
;
1708 lpe_list
= lpe_list
->next
;
1709 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1710 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1711 lpe
->sym
->sy_frag
= frag_now
;
1713 /* Emit literal pool entry. */
1714 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1716 reloc_howto_type
*reloc_howto
=
1717 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1718 int size
= bfd_get_reloc_size (reloc_howto
);
1721 if (size
> lpe
->nbytes
)
1722 as_bad (_("%s relocations do not fit in %d bytes"),
1723 reloc_howto
->name
, lpe
->nbytes
);
1724 where
= frag_more (lpe
->nbytes
);
1725 md_number_to_chars (where
, 0, size
);
1726 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1727 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1731 if (lpe
->ex
.X_op
== O_big
)
1733 if (lpe
->ex
.X_add_number
<= 0)
1734 generic_floating_point_number
= lpe
->floatnum
;
1736 memcpy (generic_bignum
, lpe
->bignum
,
1737 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1739 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1742 lpe
->next
= lpe_free_list
;
1743 lpe_free_list
= lpe
;
1745 lpe_list_tail
= NULL
;
1751 /* Turn a string in input_line_pointer into a floating point constant
1752 of type type, and store the appropriate bytes in *litp. The number
1753 of LITTLENUMS emitted is stored in *sizep . An error message is
1754 returned, or NULL on OK. */
1757 md_atof (type
, litp
, sizep
)
1763 LITTLENUM_TYPE words
[4];
1779 return "bad call to md_atof";
1782 t
= atof_ieee (input_line_pointer
, type
, words
);
1784 input_line_pointer
= t
;
1788 for (i
= 0; i
< prec
; i
++)
1790 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1797 /* Align a section (I don't know why this is machine dependent). */
1800 md_section_align (seg
, addr
)
1804 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1806 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1809 /* We don't have any form of relaxing. */
1812 md_estimate_size_before_relax (fragp
, seg
)
1813 fragS
*fragp ATTRIBUTE_UNUSED
;
1814 asection
*seg ATTRIBUTE_UNUSED
;
1820 /* Convert a machine dependent frag. We never generate these. */
1823 md_convert_frag (abfd
, sec
, fragp
)
1824 bfd
*abfd ATTRIBUTE_UNUSED
;
1825 asection
*sec ATTRIBUTE_UNUSED
;
1826 fragS
*fragp ATTRIBUTE_UNUSED
;
1832 md_undefined_symbol (name
)
1835 if (*name
== '_' && *(name
+ 1) == 'G'
1836 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1840 if (symbol_find (name
))
1841 as_bad (_("GOT already in symbol table"));
1842 GOT_symbol
= symbol_new (name
, undefined_section
,
1843 (valueT
) 0, &zero_address_frag
);
1850 /* Functions concerning relocs. */
1852 /* The location from which a PC relative jump should be calculated,
1853 given a PC relative reloc. */
1856 md_pcrel_from_section (fixp
, sec
)
1858 segT sec ATTRIBUTE_UNUSED
;
1860 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1863 /* Here we decide which fixups can be adjusted to make them relative to
1864 the beginning of the section instead of the symbol. Basically we need
1865 to make sure that the dynamic relocations are done correctly, so in
1866 some cases we force the original symbol to be used. */
1868 tc_s390_fix_adjustable (fixP
)
1871 /* Don't adjust references to merge sections. */
1872 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
1874 /* adjust_reloc_syms doesn't know about the GOT. */
1875 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
1876 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1877 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
1878 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
1879 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
1880 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
1881 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1882 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1883 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1884 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1885 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1886 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
1887 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
1888 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
1889 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
1890 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
1891 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
1892 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
1893 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
1894 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
1895 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
1896 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
1897 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
1898 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
1899 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
1900 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
1901 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
1902 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
1903 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
1904 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
1905 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
1906 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
1907 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
1908 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
1909 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
1910 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
1911 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
1912 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
1913 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
1914 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
1915 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
1916 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
1917 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
1918 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1919 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1924 /* Return true if we must always emit a reloc for a type and false if
1925 there is some hope of resolving it at assembly time. */
1927 tc_s390_force_relocation (fixp
)
1930 /* Ensure we emit a relocation for every reference to the global
1931 offset table or to the procedure link table. */
1932 switch (fixp
->fx_r_type
)
1934 case BFD_RELOC_390_GOT12
:
1935 case BFD_RELOC_390_GOT20
:
1936 case BFD_RELOC_32_GOT_PCREL
:
1937 case BFD_RELOC_32_GOTOFF
:
1938 case BFD_RELOC_390_GOTOFF64
:
1939 case BFD_RELOC_390_PLTOFF16
:
1940 case BFD_RELOC_390_PLTOFF32
:
1941 case BFD_RELOC_390_PLTOFF64
:
1942 case BFD_RELOC_390_GOTPC
:
1943 case BFD_RELOC_390_GOT16
:
1944 case BFD_RELOC_390_GOTPCDBL
:
1945 case BFD_RELOC_390_GOT64
:
1946 case BFD_RELOC_390_GOTENT
:
1947 case BFD_RELOC_390_PLT32
:
1948 case BFD_RELOC_390_PLT16DBL
:
1949 case BFD_RELOC_390_PLT32DBL
:
1950 case BFD_RELOC_390_PLT64
:
1951 case BFD_RELOC_390_GOTPLT12
:
1952 case BFD_RELOC_390_GOTPLT16
:
1953 case BFD_RELOC_390_GOTPLT20
:
1954 case BFD_RELOC_390_GOTPLT32
:
1955 case BFD_RELOC_390_GOTPLT64
:
1956 case BFD_RELOC_390_GOTPLTENT
:
1962 return generic_force_reloc (fixp
);
1965 /* Apply a fixup to the object code. This is called for all the
1966 fixups we generated by the call to fix_new_exp, above. In the call
1967 above we used a reloc code which was the largest legal reloc code
1968 plus the operand index. Here we undo that to recover the operand
1969 index. At this point all symbol values should be fully resolved,
1970 and we attempt to completely resolve the reloc. If we can not do
1971 that, we determine the correct reloc code and put it back in the
1975 md_apply_fix3 (fixP
, valP
, seg
)
1978 segT seg ATTRIBUTE_UNUSED
;
1981 valueT value
= *valP
;
1983 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1985 if (fixP
->fx_subsy
!= NULL
)
1986 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1987 "cannot emit relocation %s against subsy symbol %s",
1988 bfd_get_reloc_code_name (fixP
->fx_r_type
),
1989 S_GET_NAME (fixP
->fx_subsy
));
1991 if (fixP
->fx_addsy
!= NULL
)
1994 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1999 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2001 const struct s390_operand
*operand
;
2004 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2005 operand
= &s390_operands
[opindex
];
2009 /* Insert the fully resolved operand value. */
2010 s390_insert_operand (where
, operand
, (offsetT
) value
,
2011 fixP
->fx_file
, fixP
->fx_line
);
2015 /* Determine a BFD reloc value based on the operand information.
2016 We are only prepared to turn a few of the operands into
2018 fixP
->fx_offset
= value
;
2019 if (operand
->bits
== 12 && operand
->shift
== 20)
2022 fixP
->fx_where
+= 2;
2023 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2025 else if (operand
->bits
== 12 && operand
->shift
== 36)
2028 fixP
->fx_where
+= 4;
2029 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2031 else if (operand
->bits
== 20 && operand
->shift
== 20)
2034 fixP
->fx_where
+= 2;
2035 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2037 else if (operand
->bits
== 8 && operand
->shift
== 8)
2040 fixP
->fx_where
+= 1;
2041 fixP
->fx_r_type
= BFD_RELOC_8
;
2043 else if (operand
->bits
== 16 && operand
->shift
== 16)
2046 fixP
->fx_where
+= 2;
2047 if (operand
->flags
& S390_OPERAND_PCREL
)
2049 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2050 fixP
->fx_offset
+= 2;
2053 fixP
->fx_r_type
= BFD_RELOC_16
;
2055 else if (operand
->bits
== 32 && operand
->shift
== 16
2056 && (operand
->flags
& S390_OPERAND_PCREL
))
2059 fixP
->fx_where
+= 2;
2060 fixP
->fx_offset
+= 2;
2061 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2068 /* Use expr_symbol_where to see if this is an expression
2070 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2071 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2072 _("unresolved expression that must be resolved"));
2074 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2075 _("unsupported relocation type"));
2082 switch (fixP
->fx_r_type
)
2088 md_number_to_chars (where
, value
, 1);
2090 case BFD_RELOC_390_12
:
2091 case BFD_RELOC_390_GOT12
:
2092 case BFD_RELOC_390_GOTPLT12
:
2097 mop
= bfd_getb16 ((unsigned char *) where
);
2098 mop
|= (unsigned short) (value
& 0xfff);
2099 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2103 case BFD_RELOC_390_20
:
2104 case BFD_RELOC_390_GOT20
:
2105 case BFD_RELOC_390_GOTPLT20
:
2109 mop
= bfd_getb32 ((unsigned char *) where
);
2110 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2111 (value
& 0xff000) >> 12);
2112 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2117 case BFD_RELOC_GPREL16
:
2118 case BFD_RELOC_16_GOT_PCREL
:
2119 case BFD_RELOC_16_GOTOFF
:
2121 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2122 "cannot emit PC relative %s relocation%s%s",
2123 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2124 fixP
->fx_addsy
!= NULL
? " against " : "",
2125 (fixP
->fx_addsy
!= NULL
2126 ? S_GET_NAME (fixP
->fx_addsy
)
2129 md_number_to_chars (where
, value
, 2);
2131 case BFD_RELOC_390_GOT16
:
2132 case BFD_RELOC_390_PLTOFF16
:
2133 case BFD_RELOC_390_GOTPLT16
:
2135 md_number_to_chars (where
, value
, 2);
2137 case BFD_RELOC_390_PC16DBL
:
2138 case BFD_RELOC_390_PLT16DBL
:
2141 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2146 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2148 fixP
->fx_r_type
= BFD_RELOC_32
;
2150 md_number_to_chars (where
, value
, 4);
2152 case BFD_RELOC_32_PCREL
:
2153 case BFD_RELOC_32_BASEREL
:
2154 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2156 md_number_to_chars (where
, value
, 4);
2158 case BFD_RELOC_32_GOT_PCREL
:
2159 case BFD_RELOC_390_PLTOFF32
:
2160 case BFD_RELOC_390_PLT32
:
2161 case BFD_RELOC_390_GOTPLT32
:
2163 md_number_to_chars (where
, value
, 4);
2165 case BFD_RELOC_390_PC32DBL
:
2166 case BFD_RELOC_390_PLT32DBL
:
2167 case BFD_RELOC_390_GOTPCDBL
:
2168 case BFD_RELOC_390_GOTENT
:
2169 case BFD_RELOC_390_GOTPLTENT
:
2172 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2175 case BFD_RELOC_32_GOTOFF
:
2177 md_number_to_chars (where
, value
, sizeof (int));
2180 case BFD_RELOC_390_GOTOFF64
:
2182 md_number_to_chars (where
, value
, 8);
2185 case BFD_RELOC_390_GOT64
:
2186 case BFD_RELOC_390_PLTOFF64
:
2187 case BFD_RELOC_390_PLT64
:
2188 case BFD_RELOC_390_GOTPLT64
:
2190 md_number_to_chars (where
, value
, 8);
2195 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2197 fixP
->fx_r_type
= BFD_RELOC_64
;
2199 md_number_to_chars (where
, value
, 8);
2202 case BFD_RELOC_64_PCREL
:
2203 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2205 md_number_to_chars (where
, value
, 8);
2208 case BFD_RELOC_VTABLE_INHERIT
:
2209 case BFD_RELOC_VTABLE_ENTRY
:
2213 case BFD_RELOC_390_TLS_LOAD
:
2214 case BFD_RELOC_390_TLS_GDCALL
:
2215 case BFD_RELOC_390_TLS_LDCALL
:
2216 case BFD_RELOC_390_TLS_GD32
:
2217 case BFD_RELOC_390_TLS_GD64
:
2218 case BFD_RELOC_390_TLS_GOTIE12
:
2219 case BFD_RELOC_390_TLS_GOTIE20
:
2220 case BFD_RELOC_390_TLS_GOTIE32
:
2221 case BFD_RELOC_390_TLS_GOTIE64
:
2222 case BFD_RELOC_390_TLS_LDM32
:
2223 case BFD_RELOC_390_TLS_LDM64
:
2224 case BFD_RELOC_390_TLS_IE32
:
2225 case BFD_RELOC_390_TLS_IE64
:
2226 case BFD_RELOC_390_TLS_LE32
:
2227 case BFD_RELOC_390_TLS_LE64
:
2228 case BFD_RELOC_390_TLS_LDO32
:
2229 case BFD_RELOC_390_TLS_LDO64
:
2230 case BFD_RELOC_390_TLS_DTPMOD
:
2231 case BFD_RELOC_390_TLS_DTPOFF
:
2232 case BFD_RELOC_390_TLS_TPOFF
:
2233 /* Fully resolved at link time. */
2235 case BFD_RELOC_390_TLS_IEENT
:
2236 /* Fully resolved at link time. */
2242 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2244 if (reloc_name
!= NULL
)
2245 fprintf (stderr
, "Gas failure, reloc type %s\n", reloc_name
);
2247 fprintf (stderr
, "Gas failure, reloc type #%i\n", fixP
->fx_r_type
);
2253 fixP
->fx_offset
= value
;
2257 /* Generate a reloc for a fixup. */
2260 tc_gen_reloc (seg
, fixp
)
2261 asection
*seg ATTRIBUTE_UNUSED
;
2264 bfd_reloc_code_real_type code
;
2267 code
= fixp
->fx_r_type
;
2268 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2270 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2271 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2272 code
= BFD_RELOC_390_GOTPC
;
2273 if (code
== BFD_RELOC_390_PC32DBL
)
2274 code
= BFD_RELOC_390_GOTPCDBL
;
2277 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2278 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2279 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2280 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2281 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2282 if (reloc
->howto
== NULL
)
2284 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2285 _("cannot represent relocation type %s"),
2286 bfd_get_reloc_code_name (code
));
2287 /* Set howto to a garbage value so that we can keep going. */
2288 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2289 assert (reloc
->howto
!= NULL
);
2291 reloc
->addend
= fixp
->fx_offset
;
2297 s390_cfi_frame_initial_instructions ()
2299 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2303 tc_s390_regname_to_dw2regnum (const char *regname
)
2307 if (regname
[0] != 'c' && regname
[0] != 'a')
2309 regnum
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, regname
);
2310 if (regname
[0] == 'f' && regnum
!= -1)
2313 else if (strcmp (regname
, "ap") == 0)
2315 else if (strcmp (regname
, "cc") == 0)