1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005
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 2, 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
25 #include "safe-ctype.h"
27 #include "struc-symbol.h"
28 #include "dwarf2dbg.h"
29 #include "dw2gencfi.h"
31 #include "opcode/s390.h"
34 /* The default architecture. */
36 #define DEFAULT_ARCH "s390"
38 static char *default_arch
= DEFAULT_ARCH
;
39 /* Either 32 or 64, selects file format. */
40 static int s390_arch_size
= 0;
42 static unsigned int current_mode_mask
= 0;
43 static unsigned int current_cpu
= -1U;
45 /* Whether to use user friendly register names. Default is TRUE. */
46 #ifndef TARGET_REG_NAMES_P
47 #define TARGET_REG_NAMES_P TRUE
50 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
52 /* Set to TRUE if we want to warn about zero base/index registers. */
53 static bfd_boolean warn_areg_zero
= FALSE
;
55 /* Generic assembler global variables which must be defined by all
58 const char comment_chars
[] = "#";
60 /* Characters which start a comment at the beginning of a line. */
61 const char line_comment_chars
[] = "#";
63 /* Characters which may be used to separate multiple commands on a
65 const char line_separator_chars
[] = ";";
67 /* Characters which are used to indicate an exponent in a floating
69 const char EXP_CHARS
[] = "eE";
71 /* Characters which mean that a number is a floating point constant,
73 const char FLT_CHARS
[] = "dD";
75 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
76 int s390_cie_data_alignment
;
78 /* The target specific pseudo-ops which we support. */
80 /* Define the prototypes for the pseudo-ops */
81 static void s390_byte
PARAMS ((int));
82 static void s390_elf_cons
PARAMS ((int));
83 static void s390_bss
PARAMS ((int));
84 static void s390_insn
PARAMS ((int));
85 static void s390_literals
PARAMS ((int));
87 const pseudo_typeS md_pseudo_table
[] =
89 { "align", s_align_bytes
, 0 },
90 /* Pseudo-ops which must be defined. */
91 { "bss", s390_bss
, 0 },
92 { "insn", s390_insn
, 0 },
93 /* Pseudo-ops which must be overridden. */
94 { "byte", s390_byte
, 0 },
95 { "short", s390_elf_cons
, 2 },
96 { "long", s390_elf_cons
, 4 },
97 { "quad", s390_elf_cons
, 8 },
98 { "ltorg", s390_literals
, 0 },
99 { "string", stringer
, 2 },
104 /* Structure to hold information about predefined registers. */
111 /* List of registers that are pre-defined:
113 Each access register has a predefined name of the form:
114 a<reg_num> which has the value <reg_num>.
116 Each control register has a predefined name of the form:
117 c<reg_num> which has the value <reg_num>.
119 Each general register has a predefined name of the form:
120 r<reg_num> which has the value <reg_num>.
122 Each floating point register a has predefined name of the form:
123 f<reg_num> which has the value <reg_num>.
125 There are individual registers as well:
129 The table is sorted. Suitable for searching by a binary search. */
131 static const struct pd_reg pre_defined_registers
[] =
133 { "a0", 0 }, /* Access registers */
150 { "c0", 0 }, /* Control registers */
167 { "f0", 0 }, /* Floating point registers */
184 { "lit", 13 }, /* Pointer to literal pool */
186 { "r0", 0 }, /* General purpose registers */
203 { "sp", 15 }, /* Stack pointer */
207 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
209 static int reg_name_search
210 PARAMS ((const struct pd_reg
*, int, const char *));
211 static bfd_boolean register_name
PARAMS ((expressionS
*));
212 static void init_default_arch
PARAMS ((void));
213 static void s390_insert_operand
214 PARAMS ((unsigned char *, const struct s390_operand
*, offsetT
, char *,
216 static char *md_gather_operands
217 PARAMS ((char *, unsigned char *, const struct s390_opcode
*));
219 /* Given NAME, find the register number associated with that name, return
220 the integer value associated with the given name or -1 on failure. */
223 reg_name_search (regs
, regcount
, name
)
224 const struct pd_reg
*regs
;
228 int middle
, low
, high
;
236 middle
= (low
+ high
) / 2;
237 cmp
= strcasecmp (name
, regs
[middle
].name
);
243 return regs
[middle
].value
;
252 * Summary of register_name().
254 * in: Input_line_pointer points to 1st char of operand.
256 * out: A expressionS.
257 * The operand may have been a register: in this case, X_op == O_register,
258 * X_add_number is set to the register number, and truth is returned.
259 * Input_line_pointer->(next non-blank) char after operand, or is in its
264 register_name (expressionP
)
265 expressionS
*expressionP
;
272 /* Find the spelling of the operand. */
273 start
= name
= input_line_pointer
;
274 if (name
[0] == '%' && ISALPHA (name
[1]))
275 name
= ++input_line_pointer
;
279 c
= get_symbol_end ();
280 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
282 /* Put back the delimiting char. */
283 *input_line_pointer
= c
;
285 /* Look to see if it's in the register table. */
288 expressionP
->X_op
= O_register
;
289 expressionP
->X_add_number
= reg_number
;
291 /* Make the rest nice. */
292 expressionP
->X_add_symbol
= NULL
;
293 expressionP
->X_op_symbol
= NULL
;
297 /* Reset the line as if we had not done anything. */
298 input_line_pointer
= start
;
302 /* Local variables. */
304 /* Opformat hash table. */
305 static struct hash_control
*s390_opformat_hash
;
307 /* Opcode hash table. */
308 static struct hash_control
*s390_opcode_hash
;
310 /* Flags to set in the elf header */
311 static flagword s390_flags
= 0;
313 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
315 #ifndef WORKING_DOT_WORD
316 int md_short_jump_size
= 4;
317 int md_long_jump_size
= 4;
320 const char *md_shortopts
= "A:m:kVQ:";
321 struct option md_longopts
[] = {
322 {NULL
, no_argument
, NULL
, 0}
324 size_t md_longopts_size
= sizeof (md_longopts
);
326 /* Initialize the default opcode arch and word size from the default
327 architecture name if not specified by an option. */
331 if (strcmp (default_arch
, "s390") == 0)
333 if (s390_arch_size
== 0)
336 else if (strcmp (default_arch
, "s390x") == 0)
338 if (s390_arch_size
== 0)
342 as_fatal ("Invalid default architecture, broken assembler.");
344 if (current_mode_mask
== 0)
346 if (s390_arch_size
== 32)
347 current_mode_mask
= 1 << S390_OPCODE_ESA
;
349 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
351 if (current_cpu
== -1U)
353 if (current_mode_mask
== (1 << S390_OPCODE_ESA
))
354 current_cpu
= S390_OPCODE_G5
;
356 current_cpu
= S390_OPCODE_Z900
;
360 /* Called by TARGET_FORMAT. */
362 s390_target_format ()
364 /* We don't get a chance to initialize anything before we're called,
365 so handle that now. */
366 init_default_arch ();
368 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
372 md_parse_option (c
, arg
)
378 /* -k: Ignore for FreeBSD compatibility. */
382 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
385 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
388 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
389 warn_areg_zero
= TRUE
;
391 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
394 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
397 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
398 current_mode_mask
= 1 << S390_OPCODE_ESA
;
400 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
401 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
403 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
405 if (strcmp (arg
+ 5, "g5") == 0)
406 current_cpu
= S390_OPCODE_G5
;
407 else if (strcmp (arg
+ 5, "g6") == 0)
408 current_cpu
= S390_OPCODE_G6
;
409 else if (strcmp (arg
+ 5, "z900") == 0)
410 current_cpu
= S390_OPCODE_Z900
;
411 else if (strcmp (arg
+ 5, "z990") == 0)
412 current_cpu
= S390_OPCODE_Z990
;
413 else if (strcmp (arg
+ 5, "z9-109") == 0)
414 current_cpu
= S390_OPCODE_Z9_109
;
417 as_bad (_("invalid switch -m%s"), arg
);
424 as_bad (_("invalid switch -m%s"), arg
);
430 /* Option -A is deprecated. Still available for compatibility. */
431 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
432 current_cpu
= S390_OPCODE_G5
;
433 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
434 current_cpu
= S390_OPCODE_Z900
;
436 as_bad ("invalid architecture -A%s", arg
);
439 /* -V: SVR4 argument to print version ID. */
444 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
445 should be emitted or not. FIXME: Not implemented. */
457 md_show_usage (stream
)
460 fprintf (stream
, _("\
462 -mregnames Allow symbolic names for registers\n\
463 -mwarn-areg-zero Warn about zero base/index registers\n\
464 -mno-regnames Do not allow symbolic names for registers\n\
465 -m31 Set file format to 31 bit format\n\
466 -m64 Set file format to 64 bit format\n"));
467 fprintf (stream
, _("\
468 -V print assembler version number\n\
469 -Qy, -Qn ignored\n"));
472 /* This function is called when the assembler starts up. It is called
473 after the options have been parsed and the output file has been
479 register const struct s390_opcode
*op
;
480 const struct s390_opcode
*op_end
;
481 bfd_boolean dup_insn
= FALSE
;
484 /* Give a warning if the combination -m64-bit and -Aesa is used. */
485 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
486 as_warn ("The 64 bit file format is used without esame instructions.");
488 s390_cie_data_alignment
= -s390_arch_size
/ 8;
490 /* Set the ELF flags if desired. */
492 bfd_set_private_flags (stdoutput
, s390_flags
);
494 /* Insert the opcode formats into a hash table. */
495 s390_opformat_hash
= hash_new ();
497 op_end
= s390_opformats
+ s390_num_opformats
;
498 for (op
= s390_opformats
; op
< op_end
; op
++)
500 retval
= hash_insert (s390_opformat_hash
, op
->name
, (PTR
) op
);
501 if (retval
!= (const char *) NULL
)
503 as_bad (_("Internal assembler error for instruction format %s"),
509 /* Insert the opcodes into a hash table. */
510 s390_opcode_hash
= hash_new ();
512 op_end
= s390_opcodes
+ s390_num_opcodes
;
513 for (op
= s390_opcodes
; op
< op_end
; op
++)
514 if (op
->min_cpu
<= current_cpu
)
516 retval
= hash_insert (s390_opcode_hash
, op
->name
, (PTR
) op
);
517 if (retval
!= (const char *) NULL
)
519 as_bad (_("Internal assembler error for instruction %s"),
523 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
530 record_alignment (text_section
, 2);
531 record_alignment (data_section
, 2);
532 record_alignment (bss_section
, 2);
536 /* Called after all assembly has been done. */
540 if (s390_arch_size
== 64)
541 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
543 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
546 /* Insert an operand value into an instruction. */
549 s390_insert_operand (insn
, operand
, val
, file
, line
)
551 const struct s390_operand
*operand
;
559 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
563 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
564 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
565 /* Halve PCREL operands. */
566 if (operand
->flags
& S390_OPERAND_PCREL
)
568 /* Check for underflow / overflow. */
569 if (val
< min
|| val
> max
)
572 "operand out of range (%s not between %ld and %ld)";
575 if (operand
->flags
& S390_OPERAND_PCREL
)
581 sprint_value (buf
, val
);
582 if (file
== (char *) NULL
)
583 as_bad (err
, buf
, (int) min
, (int) max
);
585 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
588 /* val is ok, now restrict it to operand->bits bits. */
589 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
590 /* val is restrict, now check for special case. */
591 if (operand
->bits
== 20 && operand
->shift
== 20)
592 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
598 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
600 uval
= (addressT
) val
;
601 /* Length x in an instructions has real length x+1. */
602 if (operand
->flags
& S390_OPERAND_LENGTH
)
604 /* Check for underflow / overflow. */
605 if (uval
< min
|| uval
> max
)
607 if (operand
->flags
& S390_OPERAND_LENGTH
)
614 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
620 /* Insert fragments of the operand byte for byte. */
621 offset
= operand
->shift
+ operand
->bits
;
622 uval
<<= (-offset
) & 7;
623 insn
+= (offset
- 1) / 8;
635 bfd_reloc_code_real_type reloc
;
638 static bfd_reloc_code_real_type s390_tls_suffix
639 PARAMS ((char **, expressionS
*));
641 /* Parse tls marker and return the desired relocation. */
642 static bfd_reloc_code_real_type
643 s390_tls_suffix (str_p
, exp_p
)
647 static struct map_tls mapping
[] =
649 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
650 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
651 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
652 { NULL
, 0, BFD_RELOC_UNUSED
}
662 return BFD_RELOC_UNUSED
;
665 while (ISIDNUM (*str
))
669 return BFD_RELOC_UNUSED
;
671 orig_line
= input_line_pointer
;
672 input_line_pointer
= str
;
674 str
= input_line_pointer
;
675 if (&input_line_pointer
!= str_p
)
676 input_line_pointer
= orig_line
;
678 if (exp_p
->X_op
!= O_symbol
)
679 return BFD_RELOC_UNUSED
;
681 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
682 if (len
== ptr
->length
683 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
685 /* Found a matching tls suffix. */
689 return BFD_RELOC_UNUSED
;
692 /* Structure used to hold suffixes. */
703 ELF_SUFFIX_TLS_GOTIE
,
715 elf_suffix_type suffix
;
718 static elf_suffix_type s390_elf_suffix
PARAMS ((char **, expressionS
*));
719 static int s390_exp_compare
PARAMS ((expressionS
*exp1
, expressionS
*exp2
));
720 static elf_suffix_type s390_lit_suffix
721 PARAMS ((char **, expressionS
*, elf_suffix_type
));
724 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
725 static elf_suffix_type
726 s390_elf_suffix (str_p
, exp_p
)
730 static struct map_bfd mapping
[] =
732 { "got", 3, ELF_SUFFIX_GOT
},
733 { "got12", 5, ELF_SUFFIX_GOT
},
734 { "plt", 3, ELF_SUFFIX_PLT
},
735 { "gotent", 6, ELF_SUFFIX_GOTENT
},
736 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
737 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
738 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
739 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
740 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
741 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
742 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
743 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
744 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
745 { NULL
, 0, ELF_SUFFIX_NONE
}
754 return ELF_SUFFIX_NONE
;
757 while (ISALNUM (*str
))
761 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
762 if (len
== ptr
->length
763 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
765 if (exp_p
->X_add_number
!= 0)
766 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
767 ptr
->string
, ptr
->string
);
768 /* Now check for identifier@suffix+constant. */
769 if (*str
== '-' || *str
== '+')
771 char *orig_line
= input_line_pointer
;
774 input_line_pointer
= str
;
775 expression (&new_exp
);
777 switch (new_exp
.X_op
)
779 case O_constant
: /* X_add_number (a constant expression). */
780 exp_p
->X_add_number
+= new_exp
.X_add_number
;
781 str
= input_line_pointer
;
783 case O_symbol
: /* X_add_symbol + X_add_number. */
784 /* this case is used for e.g. xyz@PLT+.Label. */
785 exp_p
->X_add_number
+= new_exp
.X_add_number
;
786 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
788 str
= input_line_pointer
;
790 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
791 /* this case is used for e.g. xyz@PLT-.Label. */
792 exp_p
->X_add_number
+= new_exp
.X_add_number
;
793 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
794 exp_p
->X_op
= O_subtract
;
795 str
= input_line_pointer
;
801 /* If s390_elf_suffix has not been called with
802 &input_line_pointer as first parameter, we have
803 clobbered the input_line_pointer. We have to
805 if (&input_line_pointer
!= str_p
)
806 input_line_pointer
= orig_line
;
812 return BFD_RELOC_UNUSED
;
815 /* Structure used to hold a literal pool entry. */
818 struct s390_lpe
*next
;
820 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
821 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
823 bfd_reloc_code_real_type reloc
;
827 static struct s390_lpe
*lpe_free_list
= NULL
;
828 static struct s390_lpe
*lpe_list
= NULL
;
829 static struct s390_lpe
*lpe_list_tail
= NULL
;
830 static symbolS
*lp_sym
= NULL
;
831 static int lp_count
= 0;
832 static int lpe_count
= 0;
835 s390_exp_compare (exp1
, exp2
)
839 if (exp1
->X_op
!= exp2
->X_op
)
844 case O_constant
: /* X_add_number must be equal. */
846 return exp1
->X_add_number
== exp2
->X_add_number
;
849 as_bad (_("Can't handle O_big in s390_exp_compare"));
851 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
856 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
857 && (exp1
->X_add_number
== exp2
->X_add_number
);
859 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
864 case O_bit_inclusive_or
:
866 case O_bit_exclusive_or
:
878 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
879 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
880 && (exp1
->X_add_number
== exp2
->X_add_number
);
886 /* Test for @lit and if its present make an entry in the literal pool and
887 modify the current expression to be an offset into the literal pool. */
888 static elf_suffix_type
889 s390_lit_suffix (str_p
, exp_p
, suffix
)
892 elf_suffix_type suffix
;
894 bfd_reloc_code_real_type reloc
;
898 struct s390_lpe
*lpe
;
902 return suffix
; /* No modification. */
904 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
906 while (ISALNUM (*str
))
909 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
910 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
911 return suffix
; /* no modification */
912 nbytes
= ident
[3] - '0';
914 reloc
= BFD_RELOC_UNUSED
;
915 if (suffix
== ELF_SUFFIX_GOT
)
918 reloc
= BFD_RELOC_390_GOT16
;
919 else if (nbytes
== 4)
920 reloc
= BFD_RELOC_32_GOT_PCREL
;
921 else if (nbytes
== 8)
922 reloc
= BFD_RELOC_390_GOT64
;
924 else if (suffix
== ELF_SUFFIX_PLT
)
927 reloc
= BFD_RELOC_390_PLT32
;
928 else if (nbytes
== 8)
929 reloc
= BFD_RELOC_390_PLT64
;
932 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
933 as_bad (_("Invalid suffix for literal pool entry"));
935 /* Search the pool if the new entry is a duplicate. */
936 if (exp_p
->X_op
== O_big
)
938 /* Special processing for big numbers. */
939 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
941 if (lpe
->ex
.X_op
== O_big
)
943 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
945 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
946 sizeof (FLONUM_TYPE
)) == 0)
949 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
951 if (memcmp (generic_bignum
, lpe
->bignum
,
952 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
960 /* Processing for 'normal' data types. */
961 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
962 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
963 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
970 if (lpe_free_list
!= NULL
)
973 lpe_free_list
= lpe_free_list
->next
;
977 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
982 if (exp_p
->X_op
== O_big
)
984 if (exp_p
->X_add_number
<= 0)
985 lpe
->floatnum
= generic_floating_point_number
;
986 else if (exp_p
->X_add_number
<= 4)
987 memcpy (lpe
->bignum
, generic_bignum
,
988 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
990 as_bad (_("Big number is too big"));
993 lpe
->nbytes
= nbytes
;
995 /* Literal pool name defined ? */
998 sprintf (tmp_name
, ".L\001%i", lp_count
);
999 lp_sym
= symbol_make (tmp_name
);
1002 /* Make name for literal pool entry. */
1003 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1005 lpe
->sym
= symbol_make (tmp_name
);
1007 /* Add to literal pool list. */
1009 if (lpe_list_tail
!= NULL
)
1011 lpe_list_tail
->next
= lpe
;
1012 lpe_list_tail
= lpe
;
1015 lpe_list
= lpe_list_tail
= lpe
;
1018 /* Now change exp_p to the offset into the literal pool.
1019 Thats the expression: .L^Ax^By-.L^Ax */
1020 exp_p
->X_add_symbol
= lpe
->sym
;
1021 exp_p
->X_op_symbol
= lp_sym
;
1022 exp_p
->X_op
= O_subtract
;
1023 exp_p
->X_add_number
= 0;
1027 /* We change the suffix type to ELF_SUFFIX_NONE, because
1028 the difference of two local labels is just a number. */
1029 return ELF_SUFFIX_NONE
;
1032 /* Like normal .long/.short/.word, except support @got, etc.
1033 clobbers input_line_pointer, checks end-of-line. */
1035 s390_elf_cons (nbytes
)
1036 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1039 elf_suffix_type suffix
;
1041 if (is_it_end_of_statement ())
1043 demand_empty_rest_of_line ();
1051 if (exp
.X_op
== O_symbol
1052 && *input_line_pointer
== '@'
1053 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1055 bfd_reloc_code_real_type reloc
;
1056 reloc_howto_type
*reloc_howto
;
1062 static bfd_reloc_code_real_type tab2
[] =
1064 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1065 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1066 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1067 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1068 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1069 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1070 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1071 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1072 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1073 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1074 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1075 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1076 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1078 reloc
= tab2
[suffix
];
1080 else if (nbytes
== 4)
1082 static bfd_reloc_code_real_type tab4
[] =
1084 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1085 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1086 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1087 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1088 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1089 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1090 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1091 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1092 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1093 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1094 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1095 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1096 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1098 reloc
= tab4
[suffix
];
1100 else if (nbytes
== 8)
1102 static bfd_reloc_code_real_type tab8
[] =
1104 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1105 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1106 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1107 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1108 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1109 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1110 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1111 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1112 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1113 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1114 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1115 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1116 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1118 reloc
= tab8
[suffix
];
1121 reloc
= BFD_RELOC_UNUSED
;
1123 if (reloc
!= BFD_RELOC_UNUSED
1124 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1126 size
= bfd_get_reloc_size (reloc_howto
);
1128 as_bad (_("%s relocations do not fit in %d bytes"),
1129 reloc_howto
->name
, nbytes
);
1130 where
= frag_more (nbytes
);
1131 md_number_to_chars (where
, 0, size
);
1132 /* To make fixup_segment do the pc relative conversion the
1133 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1134 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1135 size
, &exp
, FALSE
, reloc
);
1138 as_bad (_("relocation not applicable"));
1141 emit_expr (&exp
, (unsigned int) nbytes
);
1143 while (*input_line_pointer
++ == ',');
1145 input_line_pointer
--; /* Put terminator back into stream. */
1146 demand_empty_rest_of_line ();
1149 /* We need to keep a list of fixups. We can't simply generate them as
1150 we go, because that would require us to first create the frag, and
1151 that would screw up references to ``.''. */
1157 bfd_reloc_code_real_type reloc
;
1160 #define MAX_INSN_FIXUPS (4)
1162 /* This routine is called for each instruction to be assembled. */
1165 md_gather_operands (str
, insn
, opcode
)
1167 unsigned char *insn
;
1168 const struct s390_opcode
*opcode
;
1170 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1171 const struct s390_operand
*operand
;
1172 const unsigned char *opindex_ptr
;
1174 elf_suffix_type suffix
;
1175 bfd_reloc_code_real_type reloc
;
1181 while (ISSPACE (*str
))
1187 /* Gather the operands. */
1189 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1193 operand
= s390_operands
+ *opindex_ptr
;
1195 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1197 /* We do an early skip. For D(X,B) constructions the index
1198 register is skipped (X is optional). For D(L,B) the base
1199 register will be the skipped operand, because L is NOT
1205 /* Gather the operand. */
1206 hold
= input_line_pointer
;
1207 input_line_pointer
= str
;
1209 /* Parse the operand. */
1210 if (! register_name (&ex
))
1213 str
= input_line_pointer
;
1214 input_line_pointer
= hold
;
1216 /* Write the operand to the insn. */
1217 if (ex
.X_op
== O_illegal
)
1218 as_bad (_("illegal operand"));
1219 else if (ex
.X_op
== O_absent
)
1220 as_bad (_("missing operand"));
1221 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1223 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1225 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1227 /* We need to generate a fixup for the
1228 expression returned by s390_lit_suffix. */
1229 if (fc
>= MAX_INSN_FIXUPS
)
1230 as_fatal (_("too many fixups"));
1231 fixups
[fc
].exp
= ex
;
1232 fixups
[fc
].opindex
= *opindex_ptr
;
1233 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1238 if ((operand
->flags
& S390_OPERAND_INDEX
)
1239 && ex
.X_add_number
== 0
1241 as_warn ("index register specified but zero");
1242 if ((operand
->flags
& S390_OPERAND_BASE
)
1243 && ex
.X_add_number
== 0
1245 as_warn ("base register specified but zero");
1246 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1251 suffix
= s390_elf_suffix (&str
, &ex
);
1252 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1253 reloc
= BFD_RELOC_UNUSED
;
1255 if (suffix
== ELF_SUFFIX_GOT
)
1257 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1258 (operand
->bits
== 12))
1259 reloc
= BFD_RELOC_390_GOT12
;
1260 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1261 (operand
->bits
== 20))
1262 reloc
= BFD_RELOC_390_GOT20
;
1263 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1264 && (operand
->bits
== 16))
1265 reloc
= BFD_RELOC_390_GOT16
;
1266 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1267 && (operand
->bits
== 32))
1268 reloc
= BFD_RELOC_390_GOTENT
;
1270 else if (suffix
== ELF_SUFFIX_PLT
)
1272 if ((operand
->flags
& S390_OPERAND_PCREL
)
1273 && (operand
->bits
== 16))
1274 reloc
= BFD_RELOC_390_PLT16DBL
;
1275 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1276 && (operand
->bits
== 32))
1277 reloc
= BFD_RELOC_390_PLT32DBL
;
1279 else if (suffix
== ELF_SUFFIX_GOTENT
)
1281 if ((operand
->flags
& S390_OPERAND_PCREL
)
1282 && (operand
->bits
== 32))
1283 reloc
= BFD_RELOC_390_GOTENT
;
1285 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1287 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1288 && (operand
->bits
== 16))
1289 reloc
= BFD_RELOC_16_GOTOFF
;
1291 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1293 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1294 && (operand
->bits
== 16))
1295 reloc
= BFD_RELOC_390_PLTOFF16
;
1297 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1299 if ((operand
->flags
& S390_OPERAND_DISP
)
1300 && (operand
->bits
== 12))
1301 reloc
= BFD_RELOC_390_GOTPLT12
;
1302 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1303 && (operand
->bits
== 16))
1304 reloc
= BFD_RELOC_390_GOTPLT16
;
1305 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1306 && (operand
->bits
== 32))
1307 reloc
= BFD_RELOC_390_GOTPLTENT
;
1309 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1311 if ((operand
->flags
& S390_OPERAND_DISP
)
1312 && (operand
->bits
== 12))
1313 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1314 else if ((operand
->flags
& S390_OPERAND_DISP
)
1315 && (operand
->bits
== 20))
1316 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1318 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1320 if ((operand
->flags
& S390_OPERAND_PCREL
)
1321 && (operand
->bits
== 32))
1322 reloc
= BFD_RELOC_390_TLS_IEENT
;
1325 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1326 as_bad (_("invalid operand suffix"));
1327 /* We need to generate a fixup of type 'reloc' for this
1329 if (fc
>= MAX_INSN_FIXUPS
)
1330 as_fatal (_("too many fixups"));
1331 fixups
[fc
].exp
= ex
;
1332 fixups
[fc
].opindex
= *opindex_ptr
;
1333 fixups
[fc
].reloc
= reloc
;
1337 /* Check the next character. The call to expression has advanced
1338 str past any whitespace. */
1339 if (operand
->flags
& S390_OPERAND_DISP
)
1341 /* After a displacement a block in parentheses can start. */
1344 /* Check if parenthesized block can be skipped. If the next
1345 operand is neiter an optional operand nor a base register
1346 then we have a syntax error. */
1347 operand
= s390_operands
+ *(++opindex_ptr
);
1348 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1349 as_bad (_("syntax error; missing '(' after displacement"));
1351 /* Ok, skip all operands until S390_OPERAND_BASE. */
1352 while (!(operand
->flags
& S390_OPERAND_BASE
))
1353 operand
= s390_operands
+ *(++opindex_ptr
);
1355 /* If there is a next operand it must be separated by a comma. */
1356 if (opindex_ptr
[1] != '\0')
1360 while (opindex_ptr
[1] != '\0')
1362 operand
= s390_operands
+ *(++opindex_ptr
);
1363 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1365 as_bad (_("syntax error; expected ,"));
1375 /* We found an opening parentheses. */
1377 for (f
= str
; *f
!= '\0'; f
++)
1378 if (*f
== ',' || *f
== ')')
1380 /* If there is no comma until the closing parentheses OR
1381 there is a comma right after the opening parentheses,
1382 we have to skip optional operands. */
1383 if (*f
== ',' && f
== str
)
1385 /* comma directly after '(' ? */
1390 skip_optional
= (*f
!= ',');
1393 else if (operand
->flags
& S390_OPERAND_BASE
)
1395 /* After the base register the parenthesed block ends. */
1397 as_bad (_("syntax error; missing ')' after base register"));
1399 /* If there is a next operand it must be separated by a comma. */
1400 if (opindex_ptr
[1] != '\0')
1404 while (opindex_ptr
[1] != '\0')
1406 operand
= s390_operands
+ *(++opindex_ptr
);
1407 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1409 as_bad (_("syntax error; expected ,"));
1419 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1420 of D(L,B). In this case the base register has to be skipped. */
1423 operand
= s390_operands
+ *(++opindex_ptr
);
1425 if (!(operand
->flags
& S390_OPERAND_BASE
))
1426 as_bad (_("syntax error; ')' not allowed here"));
1429 /* If there is a next operand it must be separated by a comma. */
1430 if (opindex_ptr
[1] != '\0')
1434 while (opindex_ptr
[1] != '\0')
1436 operand
= s390_operands
+ *(++opindex_ptr
);
1437 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1439 as_bad (_("syntax error; expected ,"));
1449 while (ISSPACE (*str
))
1452 /* Check for tls instruction marker. */
1453 reloc
= s390_tls_suffix (&str
, &ex
);
1454 if (reloc
!= BFD_RELOC_UNUSED
)
1456 /* We need to generate a fixup of type 'reloc' for this
1458 if (fc
>= MAX_INSN_FIXUPS
)
1459 as_fatal (_("too many fixups"));
1460 fixups
[fc
].exp
= ex
;
1461 fixups
[fc
].opindex
= -1;
1462 fixups
[fc
].reloc
= reloc
;
1470 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1472 as_bad (_("junk at end of line: `%s'"), str
);
1473 if (linefeed
!= NULL
)
1477 /* Write out the instruction. */
1478 f
= frag_more (opcode
->oplen
);
1479 memcpy (f
, insn
, opcode
->oplen
);
1480 dwarf2_emit_insn (opcode
->oplen
);
1482 /* Create any fixups. At this point we do not use a
1483 bfd_reloc_code_real_type, but instead just use the
1484 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1485 handle fixups for any operand type, although that is admittedly
1486 not a very exciting feature. We pick a BFD reloc type in
1488 for (i
= 0; i
< fc
; i
++)
1491 if (fixups
[i
].opindex
< 0)
1493 /* Create tls instruction marker relocation. */
1494 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1495 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1499 operand
= s390_operands
+ fixups
[i
].opindex
;
1501 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1503 reloc_howto_type
*reloc_howto
;
1507 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1511 size
= bfd_get_reloc_size (reloc_howto
);
1513 if (size
< 1 || size
> 4)
1516 fixP
= fix_new_exp (frag_now
,
1517 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1518 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1520 /* Turn off overflow checking in fixup_segment. This is necessary
1521 because fixup_segment will signal an overflow for large 4 byte
1522 quantities for GOT12 relocations. */
1523 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1524 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1525 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1526 fixP
->fx_no_overflow
= 1;
1529 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1530 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1531 ((bfd_reloc_code_real_type
)
1532 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1537 /* This routine is called for each instruction to be assembled. */
1543 const struct s390_opcode
*opcode
;
1544 unsigned char insn
[6];
1547 /* Get the opcode. */
1548 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1553 /* Look up the opcode in the hash table. */
1554 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1555 if (opcode
== (const struct s390_opcode
*) NULL
)
1557 as_bad (_("Unrecognized opcode: `%s'"), str
);
1560 else if (!(opcode
->modes
& current_mode_mask
))
1562 as_bad ("Opcode %s not available in this mode", str
);
1565 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1566 md_gather_operands (s
, insn
, opcode
);
1569 #ifndef WORKING_DOT_WORD
1570 /* Handle long and short jumps. We don't support these */
1572 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1574 addressT from_addr
, to_addr
;
1582 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1584 addressT from_addr
, to_addr
;
1594 int ignore ATTRIBUTE_UNUSED
;
1596 /* We don't support putting frags in the BSS segment, we fake it
1597 by marking in_bss, then looking at s_skip for clues. */
1599 subseg_set (bss_section
, 0);
1600 demand_empty_rest_of_line ();
1603 /* Pseudo-op handling. */
1607 int ignore ATTRIBUTE_UNUSED
;
1610 const struct s390_opcode
*opformat
;
1611 unsigned char insn
[6];
1614 /* Get the opcode format. */
1615 s
= input_line_pointer
;
1616 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1619 as_bad (_("Invalid .insn format\n"));
1622 /* Look up the opcode in the hash table. */
1623 opformat
= (struct s390_opcode
*)
1624 hash_find (s390_opformat_hash
, input_line_pointer
);
1625 if (opformat
== (const struct s390_opcode
*) NULL
)
1627 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1630 input_line_pointer
= s
;
1632 if (exp
.X_op
== O_constant
)
1634 if ( ( opformat
->oplen
== 6
1635 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1636 || ( opformat
->oplen
== 4
1637 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1638 || ( opformat
->oplen
== 2
1639 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1640 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1642 as_bad (_("Invalid .insn format\n"));
1644 else if (exp
.X_op
== O_big
)
1646 if (exp
.X_add_number
> 0
1647 && opformat
->oplen
== 6
1648 && generic_bignum
[3] == 0)
1650 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1651 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1652 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1655 as_bad (_("Invalid .insn format\n"));
1658 as_bad (_("second operand of .insn not a constant\n"));
1660 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1661 as_bad (_("missing comma after insn constant\n"));
1663 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1665 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1669 demand_empty_rest_of_line ();
1672 /* The .byte pseudo-op. This is similar to the normal .byte
1673 pseudo-op, but it can also take a single ASCII string. */
1677 int ignore ATTRIBUTE_UNUSED
;
1679 if (*input_line_pointer
!= '\"')
1685 /* Gather characters. A real double quote is doubled. Unusual
1686 characters are not permitted. */
1687 ++input_line_pointer
;
1692 c
= *input_line_pointer
++;
1696 if (*input_line_pointer
!= '\"')
1698 ++input_line_pointer
;
1701 FRAG_APPEND_1_CHAR (c
);
1704 demand_empty_rest_of_line ();
1707 /* The .ltorg pseudo-op.This emits all literals defined since the last
1708 .ltorg or the invocation of gas. Literals are defined with the
1712 s390_literals (ignore
)
1713 int ignore ATTRIBUTE_UNUSED
;
1715 struct s390_lpe
*lpe
;
1717 if (lp_sym
== NULL
|| lpe_count
== 0)
1718 return; /* Nothing to be done. */
1720 /* Emit symbol for start of literal pool. */
1721 S_SET_SEGMENT (lp_sym
, now_seg
);
1722 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1723 lp_sym
->sy_frag
= frag_now
;
1728 lpe_list
= lpe_list
->next
;
1729 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1730 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1731 lpe
->sym
->sy_frag
= frag_now
;
1733 /* Emit literal pool entry. */
1734 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1736 reloc_howto_type
*reloc_howto
=
1737 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1738 int size
= bfd_get_reloc_size (reloc_howto
);
1741 if (size
> lpe
->nbytes
)
1742 as_bad (_("%s relocations do not fit in %d bytes"),
1743 reloc_howto
->name
, lpe
->nbytes
);
1744 where
= frag_more (lpe
->nbytes
);
1745 md_number_to_chars (where
, 0, size
);
1746 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1747 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1751 if (lpe
->ex
.X_op
== O_big
)
1753 if (lpe
->ex
.X_add_number
<= 0)
1754 generic_floating_point_number
= lpe
->floatnum
;
1756 memcpy (generic_bignum
, lpe
->bignum
,
1757 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1759 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1762 lpe
->next
= lpe_free_list
;
1763 lpe_free_list
= lpe
;
1765 lpe_list_tail
= NULL
;
1771 /* Turn a string in input_line_pointer into a floating point constant
1772 of type type, and store the appropriate bytes in *litp. The number
1773 of LITTLENUMS emitted is stored in *sizep . An error message is
1774 returned, or NULL on OK. */
1777 md_atof (type
, litp
, sizep
)
1783 LITTLENUM_TYPE words
[4];
1799 return "bad call to md_atof";
1802 t
= atof_ieee (input_line_pointer
, type
, words
);
1804 input_line_pointer
= t
;
1808 for (i
= 0; i
< prec
; i
++)
1810 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1817 /* Align a section (I don't know why this is machine dependent). */
1820 md_section_align (seg
, addr
)
1824 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1826 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1829 /* We don't have any form of relaxing. */
1832 md_estimate_size_before_relax (fragp
, seg
)
1833 fragS
*fragp ATTRIBUTE_UNUSED
;
1834 asection
*seg ATTRIBUTE_UNUSED
;
1840 /* Convert a machine dependent frag. We never generate these. */
1843 md_convert_frag (abfd
, sec
, fragp
)
1844 bfd
*abfd ATTRIBUTE_UNUSED
;
1845 asection
*sec ATTRIBUTE_UNUSED
;
1846 fragS
*fragp ATTRIBUTE_UNUSED
;
1852 md_undefined_symbol (name
)
1855 if (*name
== '_' && *(name
+ 1) == 'G'
1856 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1860 if (symbol_find (name
))
1861 as_bad (_("GOT already in symbol table"));
1862 GOT_symbol
= symbol_new (name
, undefined_section
,
1863 (valueT
) 0, &zero_address_frag
);
1870 /* Functions concerning relocs. */
1872 /* The location from which a PC relative jump should be calculated,
1873 given a PC relative reloc. */
1876 md_pcrel_from_section (fixp
, sec
)
1878 segT sec ATTRIBUTE_UNUSED
;
1880 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1883 /* Here we decide which fixups can be adjusted to make them relative to
1884 the beginning of the section instead of the symbol. Basically we need
1885 to make sure that the dynamic relocations are done correctly, so in
1886 some cases we force the original symbol to be used. */
1888 tc_s390_fix_adjustable (fixP
)
1891 /* Don't adjust references to merge sections. */
1892 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
1894 /* adjust_reloc_syms doesn't know about the GOT. */
1895 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
1896 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1897 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
1898 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
1899 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
1900 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
1901 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1902 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1903 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1904 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1905 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1906 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
1907 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
1908 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
1909 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
1910 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
1911 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
1912 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
1913 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
1914 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
1915 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
1916 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
1917 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
1918 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
1919 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
1920 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
1921 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
1922 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
1923 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
1924 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
1925 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
1926 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
1927 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
1928 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
1929 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
1930 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
1931 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
1932 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
1933 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
1934 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
1935 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
1936 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
1937 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
1938 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1939 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1944 /* Return true if we must always emit a reloc for a type and false if
1945 there is some hope of resolving it at assembly time. */
1947 tc_s390_force_relocation (fixp
)
1950 /* Ensure we emit a relocation for every reference to the global
1951 offset table or to the procedure link table. */
1952 switch (fixp
->fx_r_type
)
1954 case BFD_RELOC_390_GOT12
:
1955 case BFD_RELOC_390_GOT20
:
1956 case BFD_RELOC_32_GOT_PCREL
:
1957 case BFD_RELOC_32_GOTOFF
:
1958 case BFD_RELOC_390_GOTOFF64
:
1959 case BFD_RELOC_390_PLTOFF16
:
1960 case BFD_RELOC_390_PLTOFF32
:
1961 case BFD_RELOC_390_PLTOFF64
:
1962 case BFD_RELOC_390_GOTPC
:
1963 case BFD_RELOC_390_GOT16
:
1964 case BFD_RELOC_390_GOTPCDBL
:
1965 case BFD_RELOC_390_GOT64
:
1966 case BFD_RELOC_390_GOTENT
:
1967 case BFD_RELOC_390_PLT32
:
1968 case BFD_RELOC_390_PLT16DBL
:
1969 case BFD_RELOC_390_PLT32DBL
:
1970 case BFD_RELOC_390_PLT64
:
1971 case BFD_RELOC_390_GOTPLT12
:
1972 case BFD_RELOC_390_GOTPLT16
:
1973 case BFD_RELOC_390_GOTPLT20
:
1974 case BFD_RELOC_390_GOTPLT32
:
1975 case BFD_RELOC_390_GOTPLT64
:
1976 case BFD_RELOC_390_GOTPLTENT
:
1982 return generic_force_reloc (fixp
);
1985 /* Apply a fixup to the object code. This is called for all the
1986 fixups we generated by the call to fix_new_exp, above. In the call
1987 above we used a reloc code which was the largest legal reloc code
1988 plus the operand index. Here we undo that to recover the operand
1989 index. At this point all symbol values should be fully resolved,
1990 and we attempt to completely resolve the reloc. If we can not do
1991 that, we determine the correct reloc code and put it back in the
1995 md_apply_fix (fixP
, valP
, seg
)
1998 segT seg ATTRIBUTE_UNUSED
;
2001 valueT value
= *valP
;
2003 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2005 if (fixP
->fx_subsy
!= NULL
)
2006 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2007 "cannot emit relocation %s against subsy symbol %s",
2008 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2009 S_GET_NAME (fixP
->fx_subsy
));
2011 if (fixP
->fx_addsy
!= NULL
)
2014 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2019 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2021 const struct s390_operand
*operand
;
2024 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2025 operand
= &s390_operands
[opindex
];
2029 /* Insert the fully resolved operand value. */
2030 s390_insert_operand ((unsigned char *) where
, operand
,
2031 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2035 /* Determine a BFD reloc value based on the operand information.
2036 We are only prepared to turn a few of the operands into
2038 fixP
->fx_offset
= value
;
2039 if (operand
->bits
== 12 && operand
->shift
== 20)
2042 fixP
->fx_where
+= 2;
2043 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2045 else if (operand
->bits
== 12 && operand
->shift
== 36)
2048 fixP
->fx_where
+= 4;
2049 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2051 else if (operand
->bits
== 20 && operand
->shift
== 20)
2054 fixP
->fx_where
+= 2;
2055 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2057 else if (operand
->bits
== 8 && operand
->shift
== 8)
2060 fixP
->fx_where
+= 1;
2061 fixP
->fx_r_type
= BFD_RELOC_8
;
2063 else if (operand
->bits
== 16 && operand
->shift
== 16)
2066 fixP
->fx_where
+= 2;
2067 if (operand
->flags
& S390_OPERAND_PCREL
)
2069 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2070 fixP
->fx_offset
+= 2;
2073 fixP
->fx_r_type
= BFD_RELOC_16
;
2075 else if (operand
->bits
== 32 && operand
->shift
== 16
2076 && (operand
->flags
& S390_OPERAND_PCREL
))
2079 fixP
->fx_where
+= 2;
2080 fixP
->fx_offset
+= 2;
2081 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2088 /* Use expr_symbol_where to see if this is an expression
2090 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2091 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2092 _("unresolved expression that must be resolved"));
2094 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2095 _("unsupported relocation type"));
2102 switch (fixP
->fx_r_type
)
2108 md_number_to_chars (where
, value
, 1);
2110 case BFD_RELOC_390_12
:
2111 case BFD_RELOC_390_GOT12
:
2112 case BFD_RELOC_390_GOTPLT12
:
2117 mop
= bfd_getb16 ((unsigned char *) where
);
2118 mop
|= (unsigned short) (value
& 0xfff);
2119 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2123 case BFD_RELOC_390_20
:
2124 case BFD_RELOC_390_GOT20
:
2125 case BFD_RELOC_390_GOTPLT20
:
2129 mop
= bfd_getb32 ((unsigned char *) where
);
2130 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2131 (value
& 0xff000) >> 12);
2132 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2137 case BFD_RELOC_GPREL16
:
2138 case BFD_RELOC_16_GOT_PCREL
:
2139 case BFD_RELOC_16_GOTOFF
:
2141 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2142 "cannot emit PC relative %s relocation%s%s",
2143 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2144 fixP
->fx_addsy
!= NULL
? " against " : "",
2145 (fixP
->fx_addsy
!= NULL
2146 ? S_GET_NAME (fixP
->fx_addsy
)
2149 md_number_to_chars (where
, value
, 2);
2151 case BFD_RELOC_390_GOT16
:
2152 case BFD_RELOC_390_PLTOFF16
:
2153 case BFD_RELOC_390_GOTPLT16
:
2155 md_number_to_chars (where
, value
, 2);
2157 case BFD_RELOC_390_PC16DBL
:
2158 case BFD_RELOC_390_PLT16DBL
:
2161 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2166 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2168 fixP
->fx_r_type
= BFD_RELOC_32
;
2170 md_number_to_chars (where
, value
, 4);
2172 case BFD_RELOC_32_PCREL
:
2173 case BFD_RELOC_32_BASEREL
:
2174 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2176 md_number_to_chars (where
, value
, 4);
2178 case BFD_RELOC_32_GOT_PCREL
:
2179 case BFD_RELOC_390_PLTOFF32
:
2180 case BFD_RELOC_390_PLT32
:
2181 case BFD_RELOC_390_GOTPLT32
:
2183 md_number_to_chars (where
, value
, 4);
2185 case BFD_RELOC_390_PC32DBL
:
2186 case BFD_RELOC_390_PLT32DBL
:
2187 case BFD_RELOC_390_GOTPCDBL
:
2188 case BFD_RELOC_390_GOTENT
:
2189 case BFD_RELOC_390_GOTPLTENT
:
2192 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2195 case BFD_RELOC_32_GOTOFF
:
2197 md_number_to_chars (where
, value
, sizeof (int));
2200 case BFD_RELOC_390_GOTOFF64
:
2202 md_number_to_chars (where
, value
, 8);
2205 case BFD_RELOC_390_GOT64
:
2206 case BFD_RELOC_390_PLTOFF64
:
2207 case BFD_RELOC_390_PLT64
:
2208 case BFD_RELOC_390_GOTPLT64
:
2210 md_number_to_chars (where
, value
, 8);
2215 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2217 fixP
->fx_r_type
= BFD_RELOC_64
;
2219 md_number_to_chars (where
, value
, 8);
2222 case BFD_RELOC_64_PCREL
:
2223 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2225 md_number_to_chars (where
, value
, 8);
2228 case BFD_RELOC_VTABLE_INHERIT
:
2229 case BFD_RELOC_VTABLE_ENTRY
:
2233 case BFD_RELOC_390_TLS_LOAD
:
2234 case BFD_RELOC_390_TLS_GDCALL
:
2235 case BFD_RELOC_390_TLS_LDCALL
:
2236 case BFD_RELOC_390_TLS_GD32
:
2237 case BFD_RELOC_390_TLS_GD64
:
2238 case BFD_RELOC_390_TLS_GOTIE12
:
2239 case BFD_RELOC_390_TLS_GOTIE20
:
2240 case BFD_RELOC_390_TLS_GOTIE32
:
2241 case BFD_RELOC_390_TLS_GOTIE64
:
2242 case BFD_RELOC_390_TLS_LDM32
:
2243 case BFD_RELOC_390_TLS_LDM64
:
2244 case BFD_RELOC_390_TLS_IE32
:
2245 case BFD_RELOC_390_TLS_IE64
:
2246 case BFD_RELOC_390_TLS_LE32
:
2247 case BFD_RELOC_390_TLS_LE64
:
2248 case BFD_RELOC_390_TLS_LDO32
:
2249 case BFD_RELOC_390_TLS_LDO64
:
2250 case BFD_RELOC_390_TLS_DTPMOD
:
2251 case BFD_RELOC_390_TLS_DTPOFF
:
2252 case BFD_RELOC_390_TLS_TPOFF
:
2253 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2254 /* Fully resolved at link time. */
2256 case BFD_RELOC_390_TLS_IEENT
:
2257 /* Fully resolved at link time. */
2258 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2264 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2266 if (reloc_name
!= NULL
)
2267 fprintf (stderr
, "Gas failure, reloc type %s\n", reloc_name
);
2269 fprintf (stderr
, "Gas failure, reloc type #%i\n", fixP
->fx_r_type
);
2275 fixP
->fx_offset
= value
;
2279 /* Generate a reloc for a fixup. */
2282 tc_gen_reloc (seg
, fixp
)
2283 asection
*seg ATTRIBUTE_UNUSED
;
2286 bfd_reloc_code_real_type code
;
2289 code
= fixp
->fx_r_type
;
2290 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2292 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2293 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2294 code
= BFD_RELOC_390_GOTPC
;
2295 if (code
== BFD_RELOC_390_PC32DBL
)
2296 code
= BFD_RELOC_390_GOTPCDBL
;
2299 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2300 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2301 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2302 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2303 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2304 if (reloc
->howto
== NULL
)
2306 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2307 _("cannot represent relocation type %s"),
2308 bfd_get_reloc_code_name (code
));
2309 /* Set howto to a garbage value so that we can keep going. */
2310 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2311 assert (reloc
->howto
!= NULL
);
2313 reloc
->addend
= fixp
->fx_offset
;
2319 s390_cfi_frame_initial_instructions ()
2321 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2325 tc_s390_regname_to_dw2regnum (const char *regname
)
2329 if (regname
[0] != 'c' && regname
[0] != 'a')
2331 regnum
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, regname
);
2332 if (regname
[0] == 'f' && regnum
!= -1)
2335 else if (strcmp (regname
, "ap") == 0)
2337 else if (strcmp (regname
, "cc") == 0)