1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "safe-ctype.h"
26 #include "struc-symbol.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "opcode/s390.h"
33 /* The default architecture. */
35 #define DEFAULT_ARCH "s390"
37 static char *default_arch
= DEFAULT_ARCH
;
38 /* Either 32 or 64, selects file format. */
39 static int s390_arch_size
= 0;
41 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
, 8 + 1 },
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 int md_short_jump_size
= 4;
316 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
;
412 else if (strcmp (arg
+ 5, "z9-109") == 0)
413 current_cpu
= S390_OPCODE_Z9_109
;
414 else if (strcmp (arg
+ 5, "z9-ec") == 0)
415 current_cpu
= S390_OPCODE_Z9_EC
;
416 else if (strcmp (arg
+ 5, "z10") == 0)
417 current_cpu
= S390_OPCODE_Z10
;
420 as_bad (_("invalid switch -m%s"), arg
);
427 as_bad (_("invalid switch -m%s"), arg
);
433 /* Option -A is deprecated. Still available for compatibility. */
434 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
435 current_cpu
= S390_OPCODE_G5
;
436 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
437 current_cpu
= S390_OPCODE_Z900
;
439 as_bad ("invalid architecture -A%s", arg
);
442 /* -V: SVR4 argument to print version ID. */
447 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
448 should be emitted or not. FIXME: Not implemented. */
460 md_show_usage (stream
)
463 fprintf (stream
, _("\
465 -mregnames Allow symbolic names for registers\n\
466 -mwarn-areg-zero Warn about zero base/index registers\n\
467 -mno-regnames Do not allow symbolic names for registers\n\
468 -m31 Set file format to 31 bit format\n\
469 -m64 Set file format to 64 bit format\n"));
470 fprintf (stream
, _("\
471 -V print assembler version number\n\
472 -Qy, -Qn ignored\n"));
475 /* This function is called when the assembler starts up. It is called
476 after the options have been parsed and the output file has been
482 register const struct s390_opcode
*op
;
483 const struct s390_opcode
*op_end
;
484 bfd_boolean dup_insn
= FALSE
;
487 /* Give a warning if the combination -m64-bit and -Aesa is used. */
488 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
489 as_warn ("The 64 bit file format is used without esame instructions.");
491 s390_cie_data_alignment
= -s390_arch_size
/ 8;
493 /* Set the ELF flags if desired. */
495 bfd_set_private_flags (stdoutput
, s390_flags
);
497 /* Insert the opcode formats into a hash table. */
498 s390_opformat_hash
= hash_new ();
500 op_end
= s390_opformats
+ s390_num_opformats
;
501 for (op
= s390_opformats
; op
< op_end
; op
++)
503 retval
= hash_insert (s390_opformat_hash
, op
->name
, (PTR
) op
);
504 if (retval
!= (const char *) NULL
)
506 as_bad (_("Internal assembler error for instruction format %s"),
512 /* Insert the opcodes into a hash table. */
513 s390_opcode_hash
= hash_new ();
515 op_end
= s390_opcodes
+ s390_num_opcodes
;
516 for (op
= s390_opcodes
; op
< op_end
; op
++)
518 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
520 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
524 retval
= hash_insert (s390_opcode_hash
, op
->name
, (PTR
) op
);
525 if (retval
!= (const char *) NULL
)
527 as_bad (_("Internal assembler error for instruction %s"),
531 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
538 record_alignment (text_section
, 2);
539 record_alignment (data_section
, 2);
540 record_alignment (bss_section
, 2);
544 /* Called after all assembly has been done. */
548 if (s390_arch_size
== 64)
549 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
551 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
554 /* Insert an operand value into an instruction. */
557 s390_insert_operand (insn
, operand
, val
, file
, line
)
559 const struct s390_operand
*operand
;
567 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
571 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
572 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
573 /* Halve PCREL operands. */
574 if (operand
->flags
& S390_OPERAND_PCREL
)
576 /* Check for underflow / overflow. */
577 if (val
< min
|| val
> max
)
580 "operand out of range (%s not between %ld and %ld)";
583 if (operand
->flags
& S390_OPERAND_PCREL
)
589 sprint_value (buf
, val
);
590 if (file
== (char *) NULL
)
591 as_bad (err
, buf
, (int) min
, (int) max
);
593 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
596 /* val is ok, now restrict it to operand->bits bits. */
597 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
598 /* val is restrict, now check for special case. */
599 if (operand
->bits
== 20 && operand
->shift
== 20)
600 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
606 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
608 uval
= (addressT
) val
;
609 /* Length x in an instructions has real length x+1. */
610 if (operand
->flags
& S390_OPERAND_LENGTH
)
612 /* Check for underflow / overflow. */
613 if (uval
< min
|| uval
> max
)
615 if (operand
->flags
& S390_OPERAND_LENGTH
)
622 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
628 /* Insert fragments of the operand byte for byte. */
629 offset
= operand
->shift
+ operand
->bits
;
630 uval
<<= (-offset
) & 7;
631 insn
+= (offset
- 1) / 8;
643 bfd_reloc_code_real_type reloc
;
646 static bfd_reloc_code_real_type s390_tls_suffix
647 PARAMS ((char **, expressionS
*));
649 /* Parse tls marker and return the desired relocation. */
650 static bfd_reloc_code_real_type
651 s390_tls_suffix (str_p
, exp_p
)
655 static struct map_tls mapping
[] =
657 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
658 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
659 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
660 { NULL
, 0, BFD_RELOC_UNUSED
}
670 return BFD_RELOC_UNUSED
;
673 while (ISIDNUM (*str
))
677 return BFD_RELOC_UNUSED
;
679 orig_line
= input_line_pointer
;
680 input_line_pointer
= str
;
682 str
= input_line_pointer
;
683 if (&input_line_pointer
!= str_p
)
684 input_line_pointer
= orig_line
;
686 if (exp_p
->X_op
!= O_symbol
)
687 return BFD_RELOC_UNUSED
;
689 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
690 if (len
== ptr
->length
691 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
693 /* Found a matching tls suffix. */
697 return BFD_RELOC_UNUSED
;
700 /* Structure used to hold suffixes. */
711 ELF_SUFFIX_TLS_GOTIE
,
723 elf_suffix_type suffix
;
726 static elf_suffix_type s390_elf_suffix
PARAMS ((char **, expressionS
*));
727 static int s390_exp_compare
PARAMS ((expressionS
*exp1
, expressionS
*exp2
));
728 static elf_suffix_type s390_lit_suffix
729 PARAMS ((char **, expressionS
*, elf_suffix_type
));
732 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
733 static elf_suffix_type
734 s390_elf_suffix (str_p
, exp_p
)
738 static struct map_bfd mapping
[] =
740 { "got", 3, ELF_SUFFIX_GOT
},
741 { "got12", 5, ELF_SUFFIX_GOT
},
742 { "plt", 3, ELF_SUFFIX_PLT
},
743 { "gotent", 6, ELF_SUFFIX_GOTENT
},
744 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
745 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
746 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
747 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
748 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
749 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
750 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
751 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
752 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
753 { NULL
, 0, ELF_SUFFIX_NONE
}
762 return ELF_SUFFIX_NONE
;
765 while (ISALNUM (*str
))
769 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
770 if (len
== ptr
->length
771 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
773 if (exp_p
->X_add_number
!= 0)
774 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
775 ptr
->string
, ptr
->string
);
776 /* Now check for identifier@suffix+constant. */
777 if (*str
== '-' || *str
== '+')
779 char *orig_line
= input_line_pointer
;
782 input_line_pointer
= str
;
783 expression (&new_exp
);
785 switch (new_exp
.X_op
)
787 case O_constant
: /* X_add_number (a constant expression). */
788 exp_p
->X_add_number
+= new_exp
.X_add_number
;
789 str
= input_line_pointer
;
791 case O_symbol
: /* X_add_symbol + X_add_number. */
792 /* this case is used for e.g. xyz@PLT+.Label. */
793 exp_p
->X_add_number
+= new_exp
.X_add_number
;
794 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
796 str
= input_line_pointer
;
798 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
799 /* this case is used for e.g. xyz@PLT-.Label. */
800 exp_p
->X_add_number
+= new_exp
.X_add_number
;
801 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
802 exp_p
->X_op
= O_subtract
;
803 str
= input_line_pointer
;
809 /* If s390_elf_suffix has not been called with
810 &input_line_pointer as first parameter, we have
811 clobbered the input_line_pointer. We have to
813 if (&input_line_pointer
!= str_p
)
814 input_line_pointer
= orig_line
;
820 return BFD_RELOC_UNUSED
;
823 /* Structure used to hold a literal pool entry. */
826 struct s390_lpe
*next
;
828 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
829 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
831 bfd_reloc_code_real_type reloc
;
835 static struct s390_lpe
*lpe_free_list
= NULL
;
836 static struct s390_lpe
*lpe_list
= NULL
;
837 static struct s390_lpe
*lpe_list_tail
= NULL
;
838 static symbolS
*lp_sym
= NULL
;
839 static int lp_count
= 0;
840 static int lpe_count
= 0;
843 s390_exp_compare (exp1
, exp2
)
847 if (exp1
->X_op
!= exp2
->X_op
)
852 case O_constant
: /* X_add_number must be equal. */
854 return exp1
->X_add_number
== exp2
->X_add_number
;
857 as_bad (_("Can't handle O_big in s390_exp_compare"));
859 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
864 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
865 && (exp1
->X_add_number
== exp2
->X_add_number
);
867 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
872 case O_bit_inclusive_or
:
874 case O_bit_exclusive_or
:
886 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
887 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
888 && (exp1
->X_add_number
== exp2
->X_add_number
);
894 /* Test for @lit and if its present make an entry in the literal pool and
895 modify the current expression to be an offset into the literal pool. */
896 static elf_suffix_type
897 s390_lit_suffix (str_p
, exp_p
, suffix
)
900 elf_suffix_type suffix
;
902 bfd_reloc_code_real_type reloc
;
906 struct s390_lpe
*lpe
;
910 return suffix
; /* No modification. */
912 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
914 while (ISALNUM (*str
))
917 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
918 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
919 return suffix
; /* no modification */
920 nbytes
= ident
[3] - '0';
922 reloc
= BFD_RELOC_UNUSED
;
923 if (suffix
== ELF_SUFFIX_GOT
)
926 reloc
= BFD_RELOC_390_GOT16
;
927 else if (nbytes
== 4)
928 reloc
= BFD_RELOC_32_GOT_PCREL
;
929 else if (nbytes
== 8)
930 reloc
= BFD_RELOC_390_GOT64
;
932 else if (suffix
== ELF_SUFFIX_PLT
)
935 reloc
= BFD_RELOC_390_PLT32
;
936 else if (nbytes
== 8)
937 reloc
= BFD_RELOC_390_PLT64
;
940 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
941 as_bad (_("Invalid suffix for literal pool entry"));
943 /* Search the pool if the new entry is a duplicate. */
944 if (exp_p
->X_op
== O_big
)
946 /* Special processing for big numbers. */
947 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
949 if (lpe
->ex
.X_op
== O_big
)
951 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
953 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
954 sizeof (FLONUM_TYPE
)) == 0)
957 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
959 if (memcmp (generic_bignum
, lpe
->bignum
,
960 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
968 /* Processing for 'normal' data types. */
969 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
970 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
971 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
978 if (lpe_free_list
!= NULL
)
981 lpe_free_list
= lpe_free_list
->next
;
985 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
990 if (exp_p
->X_op
== O_big
)
992 if (exp_p
->X_add_number
<= 0)
993 lpe
->floatnum
= generic_floating_point_number
;
994 else if (exp_p
->X_add_number
<= 4)
995 memcpy (lpe
->bignum
, generic_bignum
,
996 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
998 as_bad (_("Big number is too big"));
1001 lpe
->nbytes
= nbytes
;
1003 /* Literal pool name defined ? */
1006 sprintf (tmp_name
, ".L\001%i", lp_count
);
1007 lp_sym
= symbol_make (tmp_name
);
1010 /* Make name for literal pool entry. */
1011 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1013 lpe
->sym
= symbol_make (tmp_name
);
1015 /* Add to literal pool list. */
1017 if (lpe_list_tail
!= NULL
)
1019 lpe_list_tail
->next
= lpe
;
1020 lpe_list_tail
= lpe
;
1023 lpe_list
= lpe_list_tail
= lpe
;
1026 /* Now change exp_p to the offset into the literal pool.
1027 Thats the expression: .L^Ax^By-.L^Ax */
1028 exp_p
->X_add_symbol
= lpe
->sym
;
1029 exp_p
->X_op_symbol
= lp_sym
;
1030 exp_p
->X_op
= O_subtract
;
1031 exp_p
->X_add_number
= 0;
1035 /* We change the suffix type to ELF_SUFFIX_NONE, because
1036 the difference of two local labels is just a number. */
1037 return ELF_SUFFIX_NONE
;
1040 /* Like normal .long/.short/.word, except support @got, etc.
1041 clobbers input_line_pointer, checks end-of-line. */
1043 s390_elf_cons (nbytes
)
1044 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1047 elf_suffix_type suffix
;
1049 if (is_it_end_of_statement ())
1051 demand_empty_rest_of_line ();
1059 if (exp
.X_op
== O_symbol
1060 && *input_line_pointer
== '@'
1061 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1063 bfd_reloc_code_real_type reloc
;
1064 reloc_howto_type
*reloc_howto
;
1070 static bfd_reloc_code_real_type tab2
[] =
1072 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1073 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1074 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1075 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1076 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1077 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1078 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1079 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1080 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1081 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1082 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1083 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1084 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1086 reloc
= tab2
[suffix
];
1088 else if (nbytes
== 4)
1090 static bfd_reloc_code_real_type tab4
[] =
1092 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1093 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1094 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1095 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1096 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1097 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1098 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1099 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1100 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1101 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1102 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1103 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1104 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1106 reloc
= tab4
[suffix
];
1108 else if (nbytes
== 8)
1110 static bfd_reloc_code_real_type tab8
[] =
1112 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1113 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1114 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1115 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1116 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1117 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1118 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1119 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1120 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1121 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1122 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1123 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1124 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1126 reloc
= tab8
[suffix
];
1129 reloc
= BFD_RELOC_UNUSED
;
1131 if (reloc
!= BFD_RELOC_UNUSED
1132 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1134 size
= bfd_get_reloc_size (reloc_howto
);
1136 as_bad (_("%s relocations do not fit in %d bytes"),
1137 reloc_howto
->name
, nbytes
);
1138 where
= frag_more (nbytes
);
1139 md_number_to_chars (where
, 0, size
);
1140 /* To make fixup_segment do the pc relative conversion the
1141 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1142 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1143 size
, &exp
, FALSE
, reloc
);
1146 as_bad (_("relocation not applicable"));
1149 emit_expr (&exp
, (unsigned int) nbytes
);
1151 while (*input_line_pointer
++ == ',');
1153 input_line_pointer
--; /* Put terminator back into stream. */
1154 demand_empty_rest_of_line ();
1157 /* We need to keep a list of fixups. We can't simply generate them as
1158 we go, because that would require us to first create the frag, and
1159 that would screw up references to ``.''. */
1165 bfd_reloc_code_real_type reloc
;
1168 #define MAX_INSN_FIXUPS (4)
1170 /* This routine is called for each instruction to be assembled. */
1173 md_gather_operands (str
, insn
, opcode
)
1175 unsigned char *insn
;
1176 const struct s390_opcode
*opcode
;
1178 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1179 const struct s390_operand
*operand
;
1180 const unsigned char *opindex_ptr
;
1182 elf_suffix_type suffix
;
1183 bfd_reloc_code_real_type reloc
;
1189 while (ISSPACE (*str
))
1195 /* Gather the operands. */
1197 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1201 operand
= s390_operands
+ *opindex_ptr
;
1203 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1205 /* We do an early skip. For D(X,B) constructions the index
1206 register is skipped (X is optional). For D(L,B) the base
1207 register will be the skipped operand, because L is NOT
1213 /* Gather the operand. */
1214 hold
= input_line_pointer
;
1215 input_line_pointer
= str
;
1217 /* Parse the operand. */
1218 if (! register_name (&ex
))
1221 str
= input_line_pointer
;
1222 input_line_pointer
= hold
;
1224 /* Write the operand to the insn. */
1225 if (ex
.X_op
== O_illegal
)
1226 as_bad (_("illegal operand"));
1227 else if (ex
.X_op
== O_absent
)
1228 as_bad (_("missing operand"));
1229 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1231 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1233 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1235 /* We need to generate a fixup for the
1236 expression returned by s390_lit_suffix. */
1237 if (fc
>= MAX_INSN_FIXUPS
)
1238 as_fatal (_("too many fixups"));
1239 fixups
[fc
].exp
= ex
;
1240 fixups
[fc
].opindex
= *opindex_ptr
;
1241 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1246 if ((operand
->flags
& S390_OPERAND_INDEX
)
1247 && ex
.X_add_number
== 0
1249 as_warn ("index register specified but zero");
1250 if ((operand
->flags
& S390_OPERAND_BASE
)
1251 && ex
.X_add_number
== 0
1253 as_warn ("base register specified but zero");
1254 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1259 suffix
= s390_elf_suffix (&str
, &ex
);
1260 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1261 reloc
= BFD_RELOC_UNUSED
;
1263 if (suffix
== ELF_SUFFIX_GOT
)
1265 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1266 (operand
->bits
== 12))
1267 reloc
= BFD_RELOC_390_GOT12
;
1268 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1269 (operand
->bits
== 20))
1270 reloc
= BFD_RELOC_390_GOT20
;
1271 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1272 && (operand
->bits
== 16))
1273 reloc
= BFD_RELOC_390_GOT16
;
1274 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1275 && (operand
->bits
== 32))
1276 reloc
= BFD_RELOC_390_GOTENT
;
1278 else if (suffix
== ELF_SUFFIX_PLT
)
1280 if ((operand
->flags
& S390_OPERAND_PCREL
)
1281 && (operand
->bits
== 16))
1282 reloc
= BFD_RELOC_390_PLT16DBL
;
1283 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1284 && (operand
->bits
== 32))
1285 reloc
= BFD_RELOC_390_PLT32DBL
;
1287 else if (suffix
== ELF_SUFFIX_GOTENT
)
1289 if ((operand
->flags
& S390_OPERAND_PCREL
)
1290 && (operand
->bits
== 32))
1291 reloc
= BFD_RELOC_390_GOTENT
;
1293 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1295 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1296 && (operand
->bits
== 16))
1297 reloc
= BFD_RELOC_16_GOTOFF
;
1299 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1301 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1302 && (operand
->bits
== 16))
1303 reloc
= BFD_RELOC_390_PLTOFF16
;
1305 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1307 if ((operand
->flags
& S390_OPERAND_DISP
)
1308 && (operand
->bits
== 12))
1309 reloc
= BFD_RELOC_390_GOTPLT12
;
1310 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1311 && (operand
->bits
== 16))
1312 reloc
= BFD_RELOC_390_GOTPLT16
;
1313 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1314 && (operand
->bits
== 32))
1315 reloc
= BFD_RELOC_390_GOTPLTENT
;
1317 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1319 if ((operand
->flags
& S390_OPERAND_DISP
)
1320 && (operand
->bits
== 12))
1321 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1322 else if ((operand
->flags
& S390_OPERAND_DISP
)
1323 && (operand
->bits
== 20))
1324 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1326 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1328 if ((operand
->flags
& S390_OPERAND_PCREL
)
1329 && (operand
->bits
== 32))
1330 reloc
= BFD_RELOC_390_TLS_IEENT
;
1333 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1334 as_bad (_("invalid operand suffix"));
1335 /* We need to generate a fixup of type 'reloc' for this
1337 if (fc
>= MAX_INSN_FIXUPS
)
1338 as_fatal (_("too many fixups"));
1339 fixups
[fc
].exp
= ex
;
1340 fixups
[fc
].opindex
= *opindex_ptr
;
1341 fixups
[fc
].reloc
= reloc
;
1345 /* Check the next character. The call to expression has advanced
1346 str past any whitespace. */
1347 if (operand
->flags
& S390_OPERAND_DISP
)
1349 /* After a displacement a block in parentheses can start. */
1352 /* Check if parenthesized block can be skipped. If the next
1353 operand is neiter an optional operand nor a base register
1354 then we have a syntax error. */
1355 operand
= s390_operands
+ *(++opindex_ptr
);
1356 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1357 as_bad (_("syntax error; missing '(' after displacement"));
1359 /* Ok, skip all operands until S390_OPERAND_BASE. */
1360 while (!(operand
->flags
& S390_OPERAND_BASE
))
1361 operand
= s390_operands
+ *(++opindex_ptr
);
1363 /* If there is a next operand it must be separated by a comma. */
1364 if (opindex_ptr
[1] != '\0')
1368 while (opindex_ptr
[1] != '\0')
1370 operand
= s390_operands
+ *(++opindex_ptr
);
1371 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1373 as_bad (_("syntax error; expected ,"));
1383 /* We found an opening parentheses. */
1385 for (f
= str
; *f
!= '\0'; f
++)
1386 if (*f
== ',' || *f
== ')')
1388 /* If there is no comma until the closing parentheses OR
1389 there is a comma right after the opening parentheses,
1390 we have to skip optional operands. */
1391 if (*f
== ',' && f
== str
)
1393 /* comma directly after '(' ? */
1398 skip_optional
= (*f
!= ',');
1401 else if (operand
->flags
& S390_OPERAND_BASE
)
1403 /* After the base register the parenthesed block ends. */
1405 as_bad (_("syntax error; missing ')' after base register"));
1407 /* If there is a next operand it must be separated by a comma. */
1408 if (opindex_ptr
[1] != '\0')
1412 while (opindex_ptr
[1] != '\0')
1414 operand
= s390_operands
+ *(++opindex_ptr
);
1415 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1417 as_bad (_("syntax error; expected ,"));
1427 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1428 of D(L,B). In this case the base register has to be skipped. */
1431 operand
= s390_operands
+ *(++opindex_ptr
);
1433 if (!(operand
->flags
& S390_OPERAND_BASE
))
1434 as_bad (_("syntax error; ')' not allowed here"));
1437 /* If there is a next operand it must be separated by a comma. */
1438 if (opindex_ptr
[1] != '\0')
1442 while (opindex_ptr
[1] != '\0')
1444 operand
= s390_operands
+ *(++opindex_ptr
);
1445 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1447 as_bad (_("syntax error; expected ,"));
1457 while (ISSPACE (*str
))
1460 /* Check for tls instruction marker. */
1461 reloc
= s390_tls_suffix (&str
, &ex
);
1462 if (reloc
!= BFD_RELOC_UNUSED
)
1464 /* We need to generate a fixup of type 'reloc' for this
1466 if (fc
>= MAX_INSN_FIXUPS
)
1467 as_fatal (_("too many fixups"));
1468 fixups
[fc
].exp
= ex
;
1469 fixups
[fc
].opindex
= -1;
1470 fixups
[fc
].reloc
= reloc
;
1478 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1480 as_bad (_("junk at end of line: `%s'"), str
);
1481 if (linefeed
!= NULL
)
1485 /* Write out the instruction. */
1486 f
= frag_more (opcode
->oplen
);
1487 memcpy (f
, insn
, opcode
->oplen
);
1488 dwarf2_emit_insn (opcode
->oplen
);
1490 /* Create any fixups. At this point we do not use a
1491 bfd_reloc_code_real_type, but instead just use the
1492 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1493 handle fixups for any operand type, although that is admittedly
1494 not a very exciting feature. We pick a BFD reloc type in
1496 for (i
= 0; i
< fc
; i
++)
1499 if (fixups
[i
].opindex
< 0)
1501 /* Create tls instruction marker relocation. */
1502 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1503 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1507 operand
= s390_operands
+ fixups
[i
].opindex
;
1509 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1511 reloc_howto_type
*reloc_howto
;
1515 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1519 size
= bfd_get_reloc_size (reloc_howto
);
1521 if (size
< 1 || size
> 4)
1524 fixP
= fix_new_exp (frag_now
,
1525 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1526 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1528 /* Turn off overflow checking in fixup_segment. This is necessary
1529 because fixup_segment will signal an overflow for large 4 byte
1530 quantities for GOT12 relocations. */
1531 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1532 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1533 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1534 fixP
->fx_no_overflow
= 1;
1537 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1538 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1539 ((bfd_reloc_code_real_type
)
1540 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1545 /* This routine is called for each instruction to be assembled. */
1551 const struct s390_opcode
*opcode
;
1552 unsigned char insn
[6];
1555 /* Get the opcode. */
1556 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1561 /* Look up the opcode in the hash table. */
1562 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1563 if (opcode
== (const struct s390_opcode
*) NULL
)
1565 as_bad (_("Unrecognized opcode: `%s'"), str
);
1568 else if (!(opcode
->modes
& current_mode_mask
))
1570 as_bad ("Opcode %s not available in this mode", str
);
1573 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1574 md_gather_operands (s
, insn
, opcode
);
1577 #ifndef WORKING_DOT_WORD
1578 /* Handle long and short jumps. We don't support these */
1580 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1582 addressT from_addr
, to_addr
;
1590 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1592 addressT from_addr
, to_addr
;
1602 int ignore ATTRIBUTE_UNUSED
;
1604 /* We don't support putting frags in the BSS segment, we fake it
1605 by marking in_bss, then looking at s_skip for clues. */
1607 subseg_set (bss_section
, 0);
1608 demand_empty_rest_of_line ();
1611 /* Pseudo-op handling. */
1615 int ignore ATTRIBUTE_UNUSED
;
1618 const struct s390_opcode
*opformat
;
1619 unsigned char insn
[6];
1622 /* Get the opcode format. */
1623 s
= input_line_pointer
;
1624 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1627 as_bad (_("Invalid .insn format\n"));
1630 /* Look up the opcode in the hash table. */
1631 opformat
= (struct s390_opcode
*)
1632 hash_find (s390_opformat_hash
, input_line_pointer
);
1633 if (opformat
== (const struct s390_opcode
*) NULL
)
1635 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1638 input_line_pointer
= s
;
1640 if (exp
.X_op
== O_constant
)
1642 if ( ( opformat
->oplen
== 6
1643 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1644 || ( opformat
->oplen
== 4
1645 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1646 || ( opformat
->oplen
== 2
1647 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1648 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1650 as_bad (_("Invalid .insn format\n"));
1652 else if (exp
.X_op
== O_big
)
1654 if (exp
.X_add_number
> 0
1655 && opformat
->oplen
== 6
1656 && generic_bignum
[3] == 0)
1658 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1659 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1660 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1663 as_bad (_("Invalid .insn format\n"));
1666 as_bad (_("second operand of .insn not a constant\n"));
1668 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1669 as_bad (_("missing comma after insn constant\n"));
1671 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1673 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1677 demand_empty_rest_of_line ();
1680 /* The .byte pseudo-op. This is similar to the normal .byte
1681 pseudo-op, but it can also take a single ASCII string. */
1685 int ignore ATTRIBUTE_UNUSED
;
1687 if (*input_line_pointer
!= '\"')
1693 /* Gather characters. A real double quote is doubled. Unusual
1694 characters are not permitted. */
1695 ++input_line_pointer
;
1700 c
= *input_line_pointer
++;
1704 if (*input_line_pointer
!= '\"')
1706 ++input_line_pointer
;
1709 FRAG_APPEND_1_CHAR (c
);
1712 demand_empty_rest_of_line ();
1715 /* The .ltorg pseudo-op.This emits all literals defined since the last
1716 .ltorg or the invocation of gas. Literals are defined with the
1720 s390_literals (ignore
)
1721 int ignore ATTRIBUTE_UNUSED
;
1723 struct s390_lpe
*lpe
;
1725 if (lp_sym
== NULL
|| lpe_count
== 0)
1726 return; /* Nothing to be done. */
1728 /* Emit symbol for start of literal pool. */
1729 S_SET_SEGMENT (lp_sym
, now_seg
);
1730 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1731 lp_sym
->sy_frag
= frag_now
;
1736 lpe_list
= lpe_list
->next
;
1737 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1738 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1739 lpe
->sym
->sy_frag
= frag_now
;
1741 /* Emit literal pool entry. */
1742 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1744 reloc_howto_type
*reloc_howto
=
1745 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1746 int size
= bfd_get_reloc_size (reloc_howto
);
1749 if (size
> lpe
->nbytes
)
1750 as_bad (_("%s relocations do not fit in %d bytes"),
1751 reloc_howto
->name
, lpe
->nbytes
);
1752 where
= frag_more (lpe
->nbytes
);
1753 md_number_to_chars (where
, 0, size
);
1754 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1755 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1759 if (lpe
->ex
.X_op
== O_big
)
1761 if (lpe
->ex
.X_add_number
<= 0)
1762 generic_floating_point_number
= lpe
->floatnum
;
1764 memcpy (generic_bignum
, lpe
->bignum
,
1765 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1767 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1770 lpe
->next
= lpe_free_list
;
1771 lpe_free_list
= lpe
;
1773 lpe_list_tail
= NULL
;
1780 md_atof (int type
, char *litp
, int *sizep
)
1782 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
1785 /* Align a section (I don't know why this is machine dependent). */
1788 md_section_align (seg
, addr
)
1792 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1794 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1797 /* We don't have any form of relaxing. */
1800 md_estimate_size_before_relax (fragp
, seg
)
1801 fragS
*fragp ATTRIBUTE_UNUSED
;
1802 asection
*seg ATTRIBUTE_UNUSED
;
1808 /* Convert a machine dependent frag. We never generate these. */
1811 md_convert_frag (abfd
, sec
, fragp
)
1812 bfd
*abfd ATTRIBUTE_UNUSED
;
1813 asection
*sec ATTRIBUTE_UNUSED
;
1814 fragS
*fragp ATTRIBUTE_UNUSED
;
1820 md_undefined_symbol (name
)
1823 if (*name
== '_' && *(name
+ 1) == 'G'
1824 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1828 if (symbol_find (name
))
1829 as_bad (_("GOT already in symbol table"));
1830 GOT_symbol
= symbol_new (name
, undefined_section
,
1831 (valueT
) 0, &zero_address_frag
);
1838 /* Functions concerning relocs. */
1840 /* The location from which a PC relative jump should be calculated,
1841 given a PC relative reloc. */
1844 md_pcrel_from_section (fixp
, sec
)
1846 segT sec ATTRIBUTE_UNUSED
;
1848 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1851 /* Here we decide which fixups can be adjusted to make them relative to
1852 the beginning of the section instead of the symbol. Basically we need
1853 to make sure that the dynamic relocations are done correctly, so in
1854 some cases we force the original symbol to be used. */
1856 tc_s390_fix_adjustable (fixP
)
1859 /* Don't adjust references to merge sections. */
1860 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
1862 /* adjust_reloc_syms doesn't know about the GOT. */
1863 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
1864 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1865 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
1866 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
1867 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
1868 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
1869 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1870 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1871 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1872 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1873 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1874 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
1875 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
1876 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
1877 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
1878 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
1879 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
1880 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
1881 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
1882 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
1883 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
1884 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
1885 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
1886 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
1887 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
1888 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
1889 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
1890 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
1891 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
1892 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
1893 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
1894 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
1895 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
1896 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
1897 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
1898 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
1899 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
1900 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
1901 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
1902 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
1903 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
1904 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
1905 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
1906 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1907 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1912 /* Return true if we must always emit a reloc for a type and false if
1913 there is some hope of resolving it at assembly time. */
1915 tc_s390_force_relocation (fixp
)
1918 /* Ensure we emit a relocation for every reference to the global
1919 offset table or to the procedure link table. */
1920 switch (fixp
->fx_r_type
)
1922 case BFD_RELOC_390_GOT12
:
1923 case BFD_RELOC_390_GOT20
:
1924 case BFD_RELOC_32_GOT_PCREL
:
1925 case BFD_RELOC_32_GOTOFF
:
1926 case BFD_RELOC_390_GOTOFF64
:
1927 case BFD_RELOC_390_PLTOFF16
:
1928 case BFD_RELOC_390_PLTOFF32
:
1929 case BFD_RELOC_390_PLTOFF64
:
1930 case BFD_RELOC_390_GOTPC
:
1931 case BFD_RELOC_390_GOT16
:
1932 case BFD_RELOC_390_GOTPCDBL
:
1933 case BFD_RELOC_390_GOT64
:
1934 case BFD_RELOC_390_GOTENT
:
1935 case BFD_RELOC_390_PLT32
:
1936 case BFD_RELOC_390_PLT16DBL
:
1937 case BFD_RELOC_390_PLT32DBL
:
1938 case BFD_RELOC_390_PLT64
:
1939 case BFD_RELOC_390_GOTPLT12
:
1940 case BFD_RELOC_390_GOTPLT16
:
1941 case BFD_RELOC_390_GOTPLT20
:
1942 case BFD_RELOC_390_GOTPLT32
:
1943 case BFD_RELOC_390_GOTPLT64
:
1944 case BFD_RELOC_390_GOTPLTENT
:
1950 return generic_force_reloc (fixp
);
1953 /* Apply a fixup to the object code. This is called for all the
1954 fixups we generated by the call to fix_new_exp, above. In the call
1955 above we used a reloc code which was the largest legal reloc code
1956 plus the operand index. Here we undo that to recover the operand
1957 index. At this point all symbol values should be fully resolved,
1958 and we attempt to completely resolve the reloc. If we can not do
1959 that, we determine the correct reloc code and put it back in the
1963 md_apply_fix (fixP
, valP
, seg
)
1966 segT seg ATTRIBUTE_UNUSED
;
1969 valueT value
= *valP
;
1971 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1973 if (fixP
->fx_subsy
!= NULL
)
1974 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1975 "cannot emit relocation %s against subsy symbol %s",
1976 bfd_get_reloc_code_name (fixP
->fx_r_type
),
1977 S_GET_NAME (fixP
->fx_subsy
));
1979 if (fixP
->fx_addsy
!= NULL
)
1982 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1987 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1989 const struct s390_operand
*operand
;
1992 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1993 operand
= &s390_operands
[opindex
];
1997 /* Insert the fully resolved operand value. */
1998 s390_insert_operand ((unsigned char *) where
, operand
,
1999 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2003 /* Determine a BFD reloc value based on the operand information.
2004 We are only prepared to turn a few of the operands into
2006 fixP
->fx_offset
= value
;
2007 if (operand
->bits
== 12 && operand
->shift
== 20)
2010 fixP
->fx_where
+= 2;
2011 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2013 else if (operand
->bits
== 12 && operand
->shift
== 36)
2016 fixP
->fx_where
+= 4;
2017 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2019 else if (operand
->bits
== 20 && operand
->shift
== 20)
2022 fixP
->fx_where
+= 2;
2023 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2025 else if (operand
->bits
== 8 && operand
->shift
== 8)
2028 fixP
->fx_where
+= 1;
2029 fixP
->fx_r_type
= BFD_RELOC_8
;
2031 else if (operand
->bits
== 16 && operand
->shift
== 16)
2034 fixP
->fx_where
+= 2;
2035 if (operand
->flags
& S390_OPERAND_PCREL
)
2037 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2038 fixP
->fx_offset
+= 2;
2041 fixP
->fx_r_type
= BFD_RELOC_16
;
2043 else if (operand
->bits
== 32 && operand
->shift
== 16
2044 && (operand
->flags
& S390_OPERAND_PCREL
))
2047 fixP
->fx_where
+= 2;
2048 fixP
->fx_offset
+= 2;
2049 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2056 /* Use expr_symbol_where to see if this is an expression
2058 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2059 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2060 _("unresolved expression that must be resolved"));
2062 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2063 _("unsupported relocation type"));
2070 switch (fixP
->fx_r_type
)
2076 md_number_to_chars (where
, value
, 1);
2078 case BFD_RELOC_390_12
:
2079 case BFD_RELOC_390_GOT12
:
2080 case BFD_RELOC_390_GOTPLT12
:
2085 mop
= bfd_getb16 ((unsigned char *) where
);
2086 mop
|= (unsigned short) (value
& 0xfff);
2087 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2091 case BFD_RELOC_390_20
:
2092 case BFD_RELOC_390_GOT20
:
2093 case BFD_RELOC_390_GOTPLT20
:
2097 mop
= bfd_getb32 ((unsigned char *) where
);
2098 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2099 (value
& 0xff000) >> 12);
2100 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2105 case BFD_RELOC_GPREL16
:
2106 case BFD_RELOC_16_GOT_PCREL
:
2107 case BFD_RELOC_16_GOTOFF
:
2109 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2110 "cannot emit PC relative %s relocation%s%s",
2111 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2112 fixP
->fx_addsy
!= NULL
? " against " : "",
2113 (fixP
->fx_addsy
!= NULL
2114 ? S_GET_NAME (fixP
->fx_addsy
)
2117 md_number_to_chars (where
, value
, 2);
2119 case BFD_RELOC_390_GOT16
:
2120 case BFD_RELOC_390_PLTOFF16
:
2121 case BFD_RELOC_390_GOTPLT16
:
2123 md_number_to_chars (where
, value
, 2);
2125 case BFD_RELOC_390_PC16DBL
:
2126 case BFD_RELOC_390_PLT16DBL
:
2129 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2134 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2136 fixP
->fx_r_type
= BFD_RELOC_32
;
2138 md_number_to_chars (where
, value
, 4);
2140 case BFD_RELOC_32_PCREL
:
2141 case BFD_RELOC_32_BASEREL
:
2142 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2144 md_number_to_chars (where
, value
, 4);
2146 case BFD_RELOC_32_GOT_PCREL
:
2147 case BFD_RELOC_390_PLTOFF32
:
2148 case BFD_RELOC_390_PLT32
:
2149 case BFD_RELOC_390_GOTPLT32
:
2151 md_number_to_chars (where
, value
, 4);
2153 case BFD_RELOC_390_PC32DBL
:
2154 case BFD_RELOC_390_PLT32DBL
:
2155 case BFD_RELOC_390_GOTPCDBL
:
2156 case BFD_RELOC_390_GOTENT
:
2157 case BFD_RELOC_390_GOTPLTENT
:
2160 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2163 case BFD_RELOC_32_GOTOFF
:
2165 md_number_to_chars (where
, value
, sizeof (int));
2168 case BFD_RELOC_390_GOTOFF64
:
2170 md_number_to_chars (where
, value
, 8);
2173 case BFD_RELOC_390_GOT64
:
2174 case BFD_RELOC_390_PLTOFF64
:
2175 case BFD_RELOC_390_PLT64
:
2176 case BFD_RELOC_390_GOTPLT64
:
2178 md_number_to_chars (where
, value
, 8);
2183 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2185 fixP
->fx_r_type
= BFD_RELOC_64
;
2187 md_number_to_chars (where
, value
, 8);
2190 case BFD_RELOC_64_PCREL
:
2191 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2193 md_number_to_chars (where
, value
, 8);
2196 case BFD_RELOC_VTABLE_INHERIT
:
2197 case BFD_RELOC_VTABLE_ENTRY
:
2201 case BFD_RELOC_390_TLS_LOAD
:
2202 case BFD_RELOC_390_TLS_GDCALL
:
2203 case BFD_RELOC_390_TLS_LDCALL
:
2204 case BFD_RELOC_390_TLS_GD32
:
2205 case BFD_RELOC_390_TLS_GD64
:
2206 case BFD_RELOC_390_TLS_GOTIE12
:
2207 case BFD_RELOC_390_TLS_GOTIE20
:
2208 case BFD_RELOC_390_TLS_GOTIE32
:
2209 case BFD_RELOC_390_TLS_GOTIE64
:
2210 case BFD_RELOC_390_TLS_LDM32
:
2211 case BFD_RELOC_390_TLS_LDM64
:
2212 case BFD_RELOC_390_TLS_IE32
:
2213 case BFD_RELOC_390_TLS_IE64
:
2214 case BFD_RELOC_390_TLS_LE32
:
2215 case BFD_RELOC_390_TLS_LE64
:
2216 case BFD_RELOC_390_TLS_LDO32
:
2217 case BFD_RELOC_390_TLS_LDO64
:
2218 case BFD_RELOC_390_TLS_DTPMOD
:
2219 case BFD_RELOC_390_TLS_DTPOFF
:
2220 case BFD_RELOC_390_TLS_TPOFF
:
2221 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2222 /* Fully resolved at link time. */
2224 case BFD_RELOC_390_TLS_IEENT
:
2225 /* Fully resolved at link time. */
2226 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2232 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2234 if (reloc_name
!= NULL
)
2235 fprintf (stderr
, "Gas failure, reloc type %s\n", reloc_name
);
2237 fprintf (stderr
, "Gas failure, reloc type #%i\n", fixP
->fx_r_type
);
2243 fixP
->fx_offset
= value
;
2247 /* Generate a reloc for a fixup. */
2250 tc_gen_reloc (seg
, fixp
)
2251 asection
*seg ATTRIBUTE_UNUSED
;
2254 bfd_reloc_code_real_type code
;
2257 code
= fixp
->fx_r_type
;
2258 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2260 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2261 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2262 code
= BFD_RELOC_390_GOTPC
;
2263 if (code
== BFD_RELOC_390_PC32DBL
)
2264 code
= BFD_RELOC_390_GOTPCDBL
;
2267 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2268 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2269 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2270 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2271 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2272 if (reloc
->howto
== NULL
)
2274 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2275 _("cannot represent relocation type %s"),
2276 bfd_get_reloc_code_name (code
));
2277 /* Set howto to a garbage value so that we can keep going. */
2278 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2279 assert (reloc
->howto
!= NULL
);
2281 reloc
->addend
= fixp
->fx_offset
;
2287 s390_cfi_frame_initial_instructions ()
2289 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2293 tc_s390_regname_to_dw2regnum (char *regname
)
2297 if (regname
[0] != 'c' && regname
[0] != 'a')
2299 regnum
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, regname
);
2300 if (regname
[0] == 'f' && regnum
!= -1)
2303 else if (strcmp (regname
, "ap") == 0)
2305 else if (strcmp (regname
, "cc") == 0)