1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2014 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "safe-ctype.h"
25 #include "struc-symbol.h"
26 #include "dwarf2dbg.h"
27 #include "dw2gencfi.h"
29 #include "opcode/s390.h"
32 /* The default architecture. */
34 #define DEFAULT_ARCH "s390"
36 static char *default_arch
= DEFAULT_ARCH
;
37 /* Either 32 or 64, selects file format. */
38 static int s390_arch_size
= 0;
40 /* If no -march option was given default to the highest available CPU.
41 Since with S/390 a newer CPU always supports everything from its
42 predecessors this will accept every valid asm input. */
43 static unsigned int current_cpu
= S390_OPCODE_MAXCPU
- 1;
44 static unsigned int current_mode_mask
= 0;
46 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
47 for the output file. */
48 static bfd_boolean set_highgprs_p
= FALSE
;
50 /* Whether to use user friendly register names. Default is TRUE. */
51 #ifndef TARGET_REG_NAMES_P
52 #define TARGET_REG_NAMES_P TRUE
55 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
57 /* Set to TRUE if we want to warn about zero base/index registers. */
58 static bfd_boolean warn_areg_zero
= FALSE
;
60 /* Generic assembler global variables which must be defined by all
63 const char comment_chars
[] = "#";
65 /* Characters which start a comment at the beginning of a line. */
66 const char line_comment_chars
[] = "#";
68 /* Characters which may be used to separate multiple commands on a
70 const char line_separator_chars
[] = ";";
72 /* Characters which are used to indicate an exponent in a floating
74 const char EXP_CHARS
[] = "eE";
76 /* Characters which mean that a number is a floating point constant,
78 const char FLT_CHARS
[] = "dD";
80 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
81 int s390_cie_data_alignment
;
83 /* The target specific pseudo-ops which we support. */
85 /* Define the prototypes for the pseudo-ops */
86 static void s390_byte (int);
87 static void s390_elf_cons (int);
88 static void s390_bss (int);
89 static void s390_insn (int);
90 static void s390_literals (int);
91 static void s390_machine (int);
92 static void s390_machinemode (int);
94 const pseudo_typeS md_pseudo_table
[] =
96 { "align", s_align_bytes
, 0 },
97 /* Pseudo-ops which must be defined. */
98 { "bss", s390_bss
, 0 },
99 { "insn", s390_insn
, 0 },
100 /* Pseudo-ops which must be overridden. */
101 { "byte", s390_byte
, 0 },
102 { "short", s390_elf_cons
, 2 },
103 { "long", s390_elf_cons
, 4 },
104 { "quad", s390_elf_cons
, 8 },
105 { "ltorg", s390_literals
, 0 },
106 { "string", stringer
, 8 + 1 },
107 { "machine", s390_machine
, 0 },
108 { "machinemode", s390_machinemode
, 0 },
113 /* Structure to hold information about predefined registers. */
120 /* List of registers that are pre-defined:
122 Each access register has a predefined name of the form:
123 a<reg_num> which has the value <reg_num>.
125 Each control register has a predefined name of the form:
126 c<reg_num> which has the value <reg_num>.
128 Each general register has a predefined name of the form:
129 r<reg_num> which has the value <reg_num>.
131 Each floating point register a has predefined name of the form:
132 f<reg_num> which has the value <reg_num>.
134 There are individual registers as well:
138 The table is sorted. Suitable for searching by a binary search. */
140 static const struct pd_reg pre_defined_registers
[] =
142 { "a0", 0 }, /* Access registers */
159 { "c0", 0 }, /* Control registers */
176 { "f0", 0 }, /* Floating point registers */
193 { "lit", 13 }, /* Pointer to literal pool */
195 { "r0", 0 }, /* General purpose registers */
212 { "sp", 15 }, /* Stack pointer */
216 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
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 (const struct pd_reg
*regs
, int regcount
, const char *name
)
224 int middle
, low
, high
;
232 middle
= (low
+ high
) / 2;
233 cmp
= strcasecmp (name
, regs
[middle
].name
);
239 return regs
[middle
].value
;
248 * Summary of register_name().
250 * in: Input_line_pointer points to 1st char of operand.
252 * out: A expressionS.
253 * The operand may have been a register: in this case, X_op == O_register,
254 * X_add_number is set to the register number, and truth is returned.
255 * Input_line_pointer->(next non-blank) char after operand, or is in its
260 register_name (expressionS
*expressionP
)
267 /* Find the spelling of the operand. */
268 start
= name
= input_line_pointer
;
269 if (name
[0] == '%' && ISALPHA (name
[1]))
270 name
= ++input_line_pointer
;
274 c
= get_symbol_end ();
275 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
277 /* Put back the delimiting char. */
278 *input_line_pointer
= c
;
280 /* Look to see if it's in the register table. */
283 expressionP
->X_op
= O_register
;
284 expressionP
->X_add_number
= reg_number
;
286 /* Make the rest nice. */
287 expressionP
->X_add_symbol
= NULL
;
288 expressionP
->X_op_symbol
= NULL
;
292 /* Reset the line as if we had not done anything. */
293 input_line_pointer
= start
;
297 /* Local variables. */
299 /* Opformat hash table. */
300 static struct hash_control
*s390_opformat_hash
;
302 /* Opcode hash table. */
303 static struct hash_control
*s390_opcode_hash
= NULL
;
305 /* Flags to set in the elf header */
306 static flagword s390_flags
= 0;
308 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
310 #ifndef WORKING_DOT_WORD
311 int md_short_jump_size
= 4;
312 int md_long_jump_size
= 4;
315 const char *md_shortopts
= "A:m:kVQ:";
316 struct option md_longopts
[] = {
317 {NULL
, no_argument
, NULL
, 0}
319 size_t md_longopts_size
= sizeof (md_longopts
);
321 /* Initialize the default opcode arch and word size from the default
322 architecture name if not specified by an option. */
324 init_default_arch (void)
326 if (strcmp (default_arch
, "s390") == 0)
328 if (s390_arch_size
== 0)
331 else if (strcmp (default_arch
, "s390x") == 0)
333 if (s390_arch_size
== 0)
337 as_fatal (_("Invalid default architecture, broken assembler."));
339 if (current_mode_mask
== 0)
341 /* Default to z/Architecture mode if the CPU supports it. */
342 if (current_cpu
< S390_OPCODE_Z900
)
343 current_mode_mask
= 1 << S390_OPCODE_ESA
;
345 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
349 /* Called by TARGET_FORMAT. */
351 s390_target_format (void)
353 /* We don't get a chance to initialize anything before we're called,
354 so handle that now. */
355 init_default_arch ();
357 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
360 /* Map a CPU string as given with -march= or .machine to the
361 respective enum s390_opcode_cpu_val value. 0xffffffff is returned
362 in case of an error. */
365 s390_parse_cpu (char *arg
)
367 if (strcmp (arg
, "g5") == 0)
368 return S390_OPCODE_G5
;
369 else if (strcmp (arg
, "g6") == 0)
370 return S390_OPCODE_G6
;
371 else if (strcmp (arg
, "z900") == 0)
372 return S390_OPCODE_Z900
;
373 else if (strcmp (arg
, "z990") == 0)
374 return S390_OPCODE_Z990
;
375 else if (strcmp (arg
, "z9-109") == 0)
376 return S390_OPCODE_Z9_109
;
377 else if (strcmp (arg
, "z9-ec") == 0)
378 return S390_OPCODE_Z9_EC
;
379 else if (strcmp (arg
, "z10") == 0)
380 return S390_OPCODE_Z10
;
381 else if (strcmp (arg
, "z196") == 0)
382 return S390_OPCODE_Z196
;
383 else if (strcmp (arg
, "zEC12") == 0)
384 return S390_OPCODE_ZEC12
;
385 else if (strcmp (arg
, "all") == 0)
386 return S390_OPCODE_MAXCPU
- 1;
392 md_parse_option (int c
, char *arg
)
396 /* -k: Ignore for FreeBSD compatibility. */
400 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
403 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
406 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
407 warn_areg_zero
= TRUE
;
409 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
412 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
415 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
416 current_mode_mask
= 1 << S390_OPCODE_ESA
;
418 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
420 if (s390_arch_size
== 32)
421 set_highgprs_p
= TRUE
;
422 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
425 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
427 current_cpu
= s390_parse_cpu (arg
+ 5);
429 if (current_cpu
== (unsigned int)-1)
431 as_bad (_("invalid switch -m%s"), arg
);
438 as_bad (_("invalid switch -m%s"), arg
);
444 /* Option -A is deprecated. Still available for compatibility. */
445 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
446 current_cpu
= S390_OPCODE_G5
;
447 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
448 current_cpu
= S390_OPCODE_Z900
;
450 as_bad (_("invalid architecture -A%s"), arg
);
453 /* -V: SVR4 argument to print version ID. */
458 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
459 should be emitted or not. FIXME: Not implemented. */
471 md_show_usage (FILE *stream
)
473 fprintf (stream
, _("\
475 -mregnames Allow symbolic names for registers\n\
476 -mwarn-areg-zero Warn about zero base/index registers\n\
477 -mno-regnames Do not allow symbolic names for registers\n\
478 -m31 Set file format to 31 bit format\n\
479 -m64 Set file format to 64 bit format\n"));
480 fprintf (stream
, _("\
481 -V print assembler version number\n\
482 -Qy, -Qn ignored\n"));
485 /* Generate the hash table mapping mnemonics to struct s390_opcode.
486 This table is built at startup and whenever the CPU level is
487 changed using .machine. */
490 s390_setup_opcodes (void)
492 register const struct s390_opcode
*op
;
493 const struct s390_opcode
*op_end
;
494 bfd_boolean dup_insn
= FALSE
;
497 if (s390_opcode_hash
!= NULL
)
498 hash_die (s390_opcode_hash
);
500 /* Insert the opcodes into a hash table. */
501 s390_opcode_hash
= hash_new ();
503 op_end
= s390_opcodes
+ s390_num_opcodes
;
504 for (op
= s390_opcodes
; op
< op_end
; op
++)
506 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
508 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
513 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
515 retval
= hash_insert (s390_opcode_hash
, op
->name
, (void *) op
);
516 if (retval
!= (const char *) NULL
)
518 as_bad (_("Internal assembler error for instruction %s"),
524 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
532 /* This function is called when the assembler starts up. It is called
533 after the options have been parsed and the output file has been
539 register const struct s390_opcode
*op
;
540 const struct s390_opcode
*op_end
;
543 /* Give a warning if the combination -m64-bit and -Aesa is used. */
544 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
545 as_warn (_("The 64 bit file format is used without esame instructions."));
547 s390_cie_data_alignment
= -s390_arch_size
/ 8;
549 /* Set the ELF flags if desired. */
551 bfd_set_private_flags (stdoutput
, s390_flags
);
553 /* Insert the opcode formats into a hash table. */
554 s390_opformat_hash
= hash_new ();
556 op_end
= s390_opformats
+ s390_num_opformats
;
557 for (op
= s390_opformats
; op
< op_end
; op
++)
559 retval
= hash_insert (s390_opformat_hash
, op
->name
, (void *) op
);
560 if (retval
!= (const char *) NULL
)
561 as_bad (_("Internal assembler error for instruction format %s"),
565 s390_setup_opcodes ();
567 record_alignment (text_section
, 2);
568 record_alignment (data_section
, 2);
569 record_alignment (bss_section
, 2);
572 /* Called after all assembly has been done. */
576 if (s390_arch_size
== 64)
577 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
579 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
582 /* Insert an operand value into an instruction. */
585 s390_insert_operand (unsigned char *insn
,
586 const struct s390_operand
*operand
,
594 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
598 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
599 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
600 /* Halve PCREL operands. */
601 if (operand
->flags
& S390_OPERAND_PCREL
)
603 /* Check for underflow / overflow. */
604 if (val
< min
|| val
> max
)
607 _("operand out of range (%s not between %ld and %ld)");
610 if (operand
->flags
& S390_OPERAND_PCREL
)
616 sprint_value (buf
, val
);
617 if (file
== (char *) NULL
)
618 as_bad (err
, buf
, (int) min
, (int) max
);
620 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
623 /* val is ok, now restrict it to operand->bits bits. */
624 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
625 /* val is restrict, now check for special case. */
626 if (operand
->bits
== 20 && operand
->shift
== 20)
627 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
633 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
635 uval
= (addressT
) val
;
636 /* Length x in an instructions has real length x+1. */
637 if (operand
->flags
& S390_OPERAND_LENGTH
)
639 /* Check for underflow / overflow. */
640 if (uval
< min
|| uval
> max
)
642 if (operand
->flags
& S390_OPERAND_LENGTH
)
649 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
655 /* Insert fragments of the operand byte for byte. */
656 offset
= operand
->shift
+ operand
->bits
;
657 uval
<<= (-offset
) & 7;
658 insn
+= (offset
- 1) / 8;
670 bfd_reloc_code_real_type reloc
;
673 /* Parse tls marker and return the desired relocation. */
674 static bfd_reloc_code_real_type
675 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
677 static struct map_tls mapping
[] =
679 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
680 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
681 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
682 { NULL
, 0, BFD_RELOC_UNUSED
}
692 return BFD_RELOC_UNUSED
;
695 while (ISIDNUM (*str
))
699 return BFD_RELOC_UNUSED
;
701 orig_line
= input_line_pointer
;
702 input_line_pointer
= str
;
704 str
= input_line_pointer
;
705 if (&input_line_pointer
!= str_p
)
706 input_line_pointer
= orig_line
;
708 if (exp_p
->X_op
!= O_symbol
)
709 return BFD_RELOC_UNUSED
;
711 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
712 if (len
== ptr
->length
713 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
715 /* Found a matching tls suffix. */
719 return BFD_RELOC_UNUSED
;
722 /* Structure used to hold suffixes. */
733 ELF_SUFFIX_TLS_GOTIE
,
745 elf_suffix_type suffix
;
749 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
750 static elf_suffix_type
751 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
753 static struct map_bfd mapping
[] =
755 { "got", 3, ELF_SUFFIX_GOT
},
756 { "got12", 5, ELF_SUFFIX_GOT
},
757 { "plt", 3, ELF_SUFFIX_PLT
},
758 { "gotent", 6, ELF_SUFFIX_GOTENT
},
759 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
760 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
761 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
762 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
763 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
764 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
765 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
766 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
767 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
768 { NULL
, 0, ELF_SUFFIX_NONE
}
777 return ELF_SUFFIX_NONE
;
780 while (ISALNUM (*str
))
784 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
785 if (len
== ptr
->length
786 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
788 if (exp_p
->X_add_number
!= 0)
789 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
790 ptr
->string
, ptr
->string
);
791 /* Now check for identifier@suffix+constant. */
792 if (*str
== '-' || *str
== '+')
794 char *orig_line
= input_line_pointer
;
797 input_line_pointer
= str
;
798 expression (&new_exp
);
800 switch (new_exp
.X_op
)
802 case O_constant
: /* X_add_number (a constant expression). */
803 exp_p
->X_add_number
+= new_exp
.X_add_number
;
804 str
= input_line_pointer
;
806 case O_symbol
: /* X_add_symbol + X_add_number. */
807 /* this case is used for e.g. xyz@PLT+.Label. */
808 exp_p
->X_add_number
+= new_exp
.X_add_number
;
809 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
811 str
= input_line_pointer
;
813 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
814 /* this case is used for e.g. xyz@PLT-.Label. */
815 exp_p
->X_add_number
+= new_exp
.X_add_number
;
816 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
817 exp_p
->X_op
= O_subtract
;
818 str
= input_line_pointer
;
824 /* If s390_elf_suffix has not been called with
825 &input_line_pointer as first parameter, we have
826 clobbered the input_line_pointer. We have to
828 if (&input_line_pointer
!= str_p
)
829 input_line_pointer
= orig_line
;
835 return BFD_RELOC_UNUSED
;
838 /* Structure used to hold a literal pool entry. */
841 struct s390_lpe
*next
;
843 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
844 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
846 bfd_reloc_code_real_type reloc
;
850 static struct s390_lpe
*lpe_free_list
= NULL
;
851 static struct s390_lpe
*lpe_list
= NULL
;
852 static struct s390_lpe
*lpe_list_tail
= NULL
;
853 static symbolS
*lp_sym
= NULL
;
854 static int lp_count
= 0;
855 static int lpe_count
= 0;
858 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
860 if (exp1
->X_op
!= exp2
->X_op
)
865 case O_constant
: /* X_add_number must be equal. */
867 return exp1
->X_add_number
== exp2
->X_add_number
;
870 as_bad (_("Can't handle O_big in s390_exp_compare"));
872 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
877 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
878 && (exp1
->X_add_number
== exp2
->X_add_number
);
880 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
885 case O_bit_inclusive_or
:
887 case O_bit_exclusive_or
:
899 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
900 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
901 && (exp1
->X_add_number
== exp2
->X_add_number
);
907 /* Test for @lit and if its present make an entry in the literal pool and
908 modify the current expression to be an offset into the literal pool. */
909 static elf_suffix_type
910 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
912 bfd_reloc_code_real_type reloc
;
916 struct s390_lpe
*lpe
;
920 return suffix
; /* No modification. */
922 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
924 while (ISALNUM (*str
))
927 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
928 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
929 return suffix
; /* no modification */
930 nbytes
= ident
[3] - '0';
932 reloc
= BFD_RELOC_UNUSED
;
933 if (suffix
== ELF_SUFFIX_GOT
)
936 reloc
= BFD_RELOC_390_GOT16
;
937 else if (nbytes
== 4)
938 reloc
= BFD_RELOC_32_GOT_PCREL
;
939 else if (nbytes
== 8)
940 reloc
= BFD_RELOC_390_GOT64
;
942 else if (suffix
== ELF_SUFFIX_PLT
)
945 reloc
= BFD_RELOC_390_PLT32
;
946 else if (nbytes
== 8)
947 reloc
= BFD_RELOC_390_PLT64
;
950 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
951 as_bad (_("Invalid suffix for literal pool entry"));
953 /* Search the pool if the new entry is a duplicate. */
954 if (exp_p
->X_op
== O_big
)
956 /* Special processing for big numbers. */
957 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
959 if (lpe
->ex
.X_op
== O_big
)
961 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
963 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
964 sizeof (FLONUM_TYPE
)) == 0)
967 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
969 if (memcmp (generic_bignum
, lpe
->bignum
,
970 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
978 /* Processing for 'normal' data types. */
979 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
980 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
981 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
988 if (lpe_free_list
!= NULL
)
991 lpe_free_list
= lpe_free_list
->next
;
995 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
1000 if (exp_p
->X_op
== O_big
)
1002 if (exp_p
->X_add_number
<= 0)
1003 lpe
->floatnum
= generic_floating_point_number
;
1004 else if (exp_p
->X_add_number
<= 4)
1005 memcpy (lpe
->bignum
, generic_bignum
,
1006 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1008 as_bad (_("Big number is too big"));
1011 lpe
->nbytes
= nbytes
;
1013 /* Literal pool name defined ? */
1016 sprintf (tmp_name
, ".L\001%i", lp_count
);
1017 lp_sym
= symbol_make (tmp_name
);
1020 /* Make name for literal pool entry. */
1021 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1023 lpe
->sym
= symbol_make (tmp_name
);
1025 /* Add to literal pool list. */
1027 if (lpe_list_tail
!= NULL
)
1029 lpe_list_tail
->next
= lpe
;
1030 lpe_list_tail
= lpe
;
1033 lpe_list
= lpe_list_tail
= lpe
;
1036 /* Now change exp_p to the offset into the literal pool.
1037 Thats the expression: .L^Ax^By-.L^Ax */
1038 exp_p
->X_add_symbol
= lpe
->sym
;
1039 exp_p
->X_op_symbol
= lp_sym
;
1040 exp_p
->X_op
= O_subtract
;
1041 exp_p
->X_add_number
= 0;
1045 /* We change the suffix type to ELF_SUFFIX_NONE, because
1046 the difference of two local labels is just a number. */
1047 return ELF_SUFFIX_NONE
;
1050 /* Like normal .long/.short/.word, except support @got, etc.
1051 clobbers input_line_pointer, checks end-of-line. */
1053 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
1056 elf_suffix_type suffix
;
1058 if (is_it_end_of_statement ())
1060 demand_empty_rest_of_line ();
1068 if (exp
.X_op
== O_symbol
1069 && *input_line_pointer
== '@'
1070 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1072 bfd_reloc_code_real_type reloc
;
1073 reloc_howto_type
*reloc_howto
;
1079 static bfd_reloc_code_real_type tab2
[] =
1081 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1082 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1083 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1084 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1085 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1086 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1087 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1088 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1089 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1090 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1091 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1092 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1093 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1095 reloc
= tab2
[suffix
];
1097 else if (nbytes
== 4)
1099 static bfd_reloc_code_real_type tab4
[] =
1101 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1102 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1103 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1104 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1105 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1106 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1107 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1108 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1109 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1110 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1111 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1112 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1113 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1115 reloc
= tab4
[suffix
];
1117 else if (nbytes
== 8)
1119 static bfd_reloc_code_real_type tab8
[] =
1121 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1122 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1123 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1124 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1125 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1126 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1127 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1128 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1129 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1130 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1131 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1132 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1133 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1135 reloc
= tab8
[suffix
];
1138 reloc
= BFD_RELOC_UNUSED
;
1140 if (reloc
!= BFD_RELOC_UNUSED
1141 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1143 size
= bfd_get_reloc_size (reloc_howto
);
1145 as_bad (_("%s relocations do not fit in %d bytes"),
1146 reloc_howto
->name
, nbytes
);
1147 where
= frag_more (nbytes
);
1148 md_number_to_chars (where
, 0, size
);
1149 /* To make fixup_segment do the pc relative conversion the
1150 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1151 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1152 size
, &exp
, FALSE
, reloc
);
1155 as_bad (_("relocation not applicable"));
1158 emit_expr (&exp
, (unsigned int) nbytes
);
1160 while (*input_line_pointer
++ == ',');
1162 input_line_pointer
--; /* Put terminator back into stream. */
1163 demand_empty_rest_of_line ();
1166 /* We need to keep a list of fixups. We can't simply generate them as
1167 we go, because that would require us to first create the frag, and
1168 that would screw up references to ``.''. */
1174 bfd_reloc_code_real_type reloc
;
1177 #define MAX_INSN_FIXUPS (4)
1179 /* This routine is called for each instruction to be assembled. */
1182 md_gather_operands (char *str
,
1183 unsigned char *insn
,
1184 const struct s390_opcode
*opcode
)
1186 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1187 const struct s390_operand
*operand
;
1188 const unsigned char *opindex_ptr
;
1190 elf_suffix_type suffix
;
1191 bfd_reloc_code_real_type reloc
;
1196 while (ISSPACE (*str
))
1201 /* Gather the operands. */
1203 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1207 operand
= s390_operands
+ *opindex_ptr
;
1209 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1211 /* We do an early skip. For D(X,B) constructions the index
1212 register is skipped (X is optional). For D(L,B) the base
1213 register will be the skipped operand, because L is NOT
1219 /* Gather the operand. */
1220 hold
= input_line_pointer
;
1221 input_line_pointer
= str
;
1223 /* Parse the operand. */
1224 if (! register_name (&ex
))
1227 str
= input_line_pointer
;
1228 input_line_pointer
= hold
;
1230 /* Write the operand to the insn. */
1231 if (ex
.X_op
== O_illegal
)
1232 as_bad (_("illegal operand"));
1233 else if (ex
.X_op
== O_absent
)
1235 /* No operands, check if all operands can be skipped. */
1236 while (*opindex_ptr
!= 0 && operand
->flags
& S390_OPERAND_OPTIONAL
)
1238 if (operand
->flags
& S390_OPERAND_DISP
)
1240 /* An optional displacement makes the whole D(X,B)
1241 D(L,B) or D(B) block optional. */
1243 operand
= s390_operands
+ *(++opindex_ptr
);
1244 } while (!(operand
->flags
& S390_OPERAND_BASE
));
1246 operand
= s390_operands
+ *(++opindex_ptr
);
1248 if (opindex_ptr
[0] == '\0')
1250 as_bad (_("missing operand"));
1252 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1254 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1256 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1258 /* We need to generate a fixup for the
1259 expression returned by s390_lit_suffix. */
1260 if (fc
>= MAX_INSN_FIXUPS
)
1261 as_fatal (_("too many fixups"));
1262 fixups
[fc
].exp
= ex
;
1263 fixups
[fc
].opindex
= *opindex_ptr
;
1264 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1269 if ((operand
->flags
& S390_OPERAND_INDEX
)
1270 && ex
.X_add_number
== 0
1272 as_warn (_("index register specified but zero"));
1273 if ((operand
->flags
& S390_OPERAND_BASE
)
1274 && ex
.X_add_number
== 0
1276 as_warn (_("base register specified but zero"));
1277 if ((operand
->flags
& S390_OPERAND_GPR
)
1278 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1279 && (ex
.X_add_number
& 1))
1280 as_fatal (_("odd numbered general purpose register specified as "
1282 if ((operand
->flags
& S390_OPERAND_FPR
)
1283 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1284 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1285 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1286 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1287 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1288 as_fatal (_("invalid floating point register pair. Valid fp "
1289 "register pair operands are 0, 1, 4, 5, 8, 9, "
1291 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1296 suffix
= s390_elf_suffix (&str
, &ex
);
1297 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1298 reloc
= BFD_RELOC_UNUSED
;
1300 if (suffix
== ELF_SUFFIX_GOT
)
1302 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1303 (operand
->bits
== 12))
1304 reloc
= BFD_RELOC_390_GOT12
;
1305 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1306 (operand
->bits
== 20))
1307 reloc
= BFD_RELOC_390_GOT20
;
1308 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1309 && (operand
->bits
== 16))
1310 reloc
= BFD_RELOC_390_GOT16
;
1311 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1312 && (operand
->bits
== 32))
1313 reloc
= BFD_RELOC_390_GOTENT
;
1315 else if (suffix
== ELF_SUFFIX_PLT
)
1317 if ((operand
->flags
& S390_OPERAND_PCREL
)
1318 && (operand
->bits
== 12))
1319 reloc
= BFD_RELOC_390_PLT12DBL
;
1320 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1321 && (operand
->bits
== 16))
1322 reloc
= BFD_RELOC_390_PLT16DBL
;
1323 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1324 && (operand
->bits
== 24))
1325 reloc
= BFD_RELOC_390_PLT24DBL
;
1326 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1327 && (operand
->bits
== 32))
1328 reloc
= BFD_RELOC_390_PLT32DBL
;
1330 else if (suffix
== ELF_SUFFIX_GOTENT
)
1332 if ((operand
->flags
& S390_OPERAND_PCREL
)
1333 && (operand
->bits
== 32))
1334 reloc
= BFD_RELOC_390_GOTENT
;
1336 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1338 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1339 && (operand
->bits
== 16))
1340 reloc
= BFD_RELOC_16_GOTOFF
;
1342 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1344 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1345 && (operand
->bits
== 16))
1346 reloc
= BFD_RELOC_390_PLTOFF16
;
1348 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1350 if ((operand
->flags
& S390_OPERAND_DISP
)
1351 && (operand
->bits
== 12))
1352 reloc
= BFD_RELOC_390_GOTPLT12
;
1353 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1354 && (operand
->bits
== 16))
1355 reloc
= BFD_RELOC_390_GOTPLT16
;
1356 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1357 && (operand
->bits
== 32))
1358 reloc
= BFD_RELOC_390_GOTPLTENT
;
1360 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1362 if ((operand
->flags
& S390_OPERAND_DISP
)
1363 && (operand
->bits
== 12))
1364 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1365 else if ((operand
->flags
& S390_OPERAND_DISP
)
1366 && (operand
->bits
== 20))
1367 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1369 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1371 if ((operand
->flags
& S390_OPERAND_PCREL
)
1372 && (operand
->bits
== 32))
1373 reloc
= BFD_RELOC_390_TLS_IEENT
;
1376 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1377 as_bad (_("invalid operand suffix"));
1378 /* We need to generate a fixup of type 'reloc' for this
1380 if (fc
>= MAX_INSN_FIXUPS
)
1381 as_fatal (_("too many fixups"));
1382 fixups
[fc
].exp
= ex
;
1383 fixups
[fc
].opindex
= *opindex_ptr
;
1384 fixups
[fc
].reloc
= reloc
;
1388 /* Check the next character. The call to expression has advanced
1389 str past any whitespace. */
1390 if (operand
->flags
& S390_OPERAND_DISP
)
1392 /* After a displacement a block in parentheses can start. */
1395 /* Check if parenthesized block can be skipped. If the next
1396 operand is neiter an optional operand nor a base register
1397 then we have a syntax error. */
1398 operand
= s390_operands
+ *(++opindex_ptr
);
1399 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1400 as_bad (_("syntax error; missing '(' after displacement"));
1402 /* Ok, skip all operands until S390_OPERAND_BASE. */
1403 while (!(operand
->flags
& S390_OPERAND_BASE
))
1404 operand
= s390_operands
+ *(++opindex_ptr
);
1406 /* If there is a next operand it must be separated by a comma. */
1407 if (opindex_ptr
[1] != '\0')
1411 while (opindex_ptr
[1] != '\0')
1413 operand
= s390_operands
+ *(++opindex_ptr
);
1414 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1416 as_bad (_("syntax error; expected ,"));
1426 /* We found an opening parentheses. */
1428 for (f
= str
; *f
!= '\0'; f
++)
1429 if (*f
== ',' || *f
== ')')
1431 /* If there is no comma until the closing parentheses OR
1432 there is a comma right after the opening parentheses,
1433 we have to skip optional operands. */
1434 if (*f
== ',' && f
== str
)
1436 /* comma directly after '(' ? */
1441 skip_optional
= (*f
!= ',');
1444 else if (operand
->flags
& S390_OPERAND_BASE
)
1446 /* After the base register the parenthesed block ends. */
1448 as_bad (_("syntax error; missing ')' after base register"));
1450 /* If there is a next operand it must be separated by a comma. */
1451 if (opindex_ptr
[1] != '\0')
1455 while (opindex_ptr
[1] != '\0')
1457 operand
= s390_operands
+ *(++opindex_ptr
);
1458 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1460 as_bad (_("syntax error; expected ,"));
1470 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1471 of D(L,B). In this case the base register has to be skipped. */
1474 operand
= s390_operands
+ *(++opindex_ptr
);
1476 if (!(operand
->flags
& S390_OPERAND_BASE
))
1477 as_bad (_("syntax error; ')' not allowed here"));
1480 /* If there is a next operand it must be separated by a comma. */
1481 if (opindex_ptr
[1] != '\0')
1485 while (opindex_ptr
[1] != '\0')
1487 operand
= s390_operands
+ *(++opindex_ptr
);
1488 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1490 as_bad (_("syntax error; expected ,"));
1500 while (ISSPACE (*str
))
1503 /* Check for tls instruction marker. */
1504 reloc
= s390_tls_suffix (&str
, &ex
);
1505 if (reloc
!= BFD_RELOC_UNUSED
)
1507 /* We need to generate a fixup of type 'reloc' for this
1509 if (fc
>= MAX_INSN_FIXUPS
)
1510 as_fatal (_("too many fixups"));
1511 fixups
[fc
].exp
= ex
;
1512 fixups
[fc
].opindex
= -1;
1513 fixups
[fc
].reloc
= reloc
;
1521 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1523 as_bad (_("junk at end of line: `%s'"), str
);
1524 if (linefeed
!= NULL
)
1528 /* Write out the instruction. */
1529 f
= frag_more (opcode
->oplen
);
1530 memcpy (f
, insn
, opcode
->oplen
);
1531 dwarf2_emit_insn (opcode
->oplen
);
1533 /* Create any fixups. At this point we do not use a
1534 bfd_reloc_code_real_type, but instead just use the
1535 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1536 handle fixups for any operand type, although that is admittedly
1537 not a very exciting feature. We pick a BFD reloc type in
1539 for (i
= 0; i
< fc
; i
++)
1542 if (fixups
[i
].opindex
< 0)
1544 /* Create tls instruction marker relocation. */
1545 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1546 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1550 operand
= s390_operands
+ fixups
[i
].opindex
;
1552 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1554 reloc_howto_type
*reloc_howto
;
1558 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1562 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1564 if (size
< 1 || size
> 4)
1567 fixP
= fix_new_exp (frag_now
,
1568 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1569 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1571 /* Turn off overflow checking in fixup_segment. This is necessary
1572 because fixup_segment will signal an overflow for large 4 byte
1573 quantities for GOT12 relocations. */
1574 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1575 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1576 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1577 fixP
->fx_no_overflow
= 1;
1580 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1581 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1582 ((bfd_reloc_code_real_type
)
1583 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1588 /* This routine is called for each instruction to be assembled. */
1591 md_assemble (char *str
)
1593 const struct s390_opcode
*opcode
;
1594 unsigned char insn
[6];
1597 /* Get the opcode. */
1598 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1603 /* Look up the opcode in the hash table. */
1604 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1605 if (opcode
== (const struct s390_opcode
*) NULL
)
1607 as_bad (_("Unrecognized opcode: `%s'"), str
);
1610 else if (!(opcode
->modes
& current_mode_mask
))
1612 as_bad (_("Opcode %s not available in this mode"), str
);
1615 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1616 md_gather_operands (s
, insn
, opcode
);
1619 #ifndef WORKING_DOT_WORD
1620 /* Handle long and short jumps. We don't support these */
1622 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1624 addressT from_addr
, to_addr
;
1632 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1634 addressT from_addr
, to_addr
;
1643 s390_bss (int ignore ATTRIBUTE_UNUSED
)
1645 /* We don't support putting frags in the BSS segment, we fake it
1646 by marking in_bss, then looking at s_skip for clues. */
1648 subseg_set (bss_section
, 0);
1649 demand_empty_rest_of_line ();
1652 /* Pseudo-op handling. */
1655 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1658 const struct s390_opcode
*opformat
;
1659 unsigned char insn
[6];
1662 /* Get the opcode format. */
1663 s
= input_line_pointer
;
1664 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1667 as_bad (_("Invalid .insn format\n"));
1670 /* Look up the opcode in the hash table. */
1671 opformat
= (struct s390_opcode
*)
1672 hash_find (s390_opformat_hash
, input_line_pointer
);
1673 if (opformat
== (const struct s390_opcode
*) NULL
)
1675 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1678 input_line_pointer
= s
;
1680 if (exp
.X_op
== O_constant
)
1682 if ( ( opformat
->oplen
== 6
1683 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1684 || ( opformat
->oplen
== 4
1685 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1686 || ( opformat
->oplen
== 2
1687 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1688 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1690 as_bad (_("Invalid .insn format\n"));
1692 else if (exp
.X_op
== O_big
)
1694 if (exp
.X_add_number
> 0
1695 && opformat
->oplen
== 6
1696 && generic_bignum
[3] == 0)
1698 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1699 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1700 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1703 as_bad (_("Invalid .insn format\n"));
1706 as_bad (_("second operand of .insn not a constant\n"));
1708 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1709 as_bad (_("missing comma after insn constant\n"));
1711 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1713 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1717 demand_empty_rest_of_line ();
1720 /* The .byte pseudo-op. This is similar to the normal .byte
1721 pseudo-op, but it can also take a single ASCII string. */
1724 s390_byte (int ignore ATTRIBUTE_UNUSED
)
1726 if (*input_line_pointer
!= '\"')
1732 /* Gather characters. A real double quote is doubled. Unusual
1733 characters are not permitted. */
1734 ++input_line_pointer
;
1739 c
= *input_line_pointer
++;
1743 if (*input_line_pointer
!= '\"')
1745 ++input_line_pointer
;
1748 FRAG_APPEND_1_CHAR (c
);
1751 demand_empty_rest_of_line ();
1754 /* The .ltorg pseudo-op.This emits all literals defined since the last
1755 .ltorg or the invocation of gas. Literals are defined with the
1759 s390_literals (int ignore ATTRIBUTE_UNUSED
)
1761 struct s390_lpe
*lpe
;
1763 if (lp_sym
== NULL
|| lpe_count
== 0)
1764 return; /* Nothing to be done. */
1766 /* Emit symbol for start of literal pool. */
1767 S_SET_SEGMENT (lp_sym
, now_seg
);
1768 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1769 lp_sym
->sy_frag
= frag_now
;
1774 lpe_list
= lpe_list
->next
;
1775 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1776 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1777 lpe
->sym
->sy_frag
= frag_now
;
1779 /* Emit literal pool entry. */
1780 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1782 reloc_howto_type
*reloc_howto
=
1783 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1784 int size
= bfd_get_reloc_size (reloc_howto
);
1787 if (size
> lpe
->nbytes
)
1788 as_bad (_("%s relocations do not fit in %d bytes"),
1789 reloc_howto
->name
, lpe
->nbytes
);
1790 where
= frag_more (lpe
->nbytes
);
1791 md_number_to_chars (where
, 0, size
);
1792 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1793 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1797 if (lpe
->ex
.X_op
== O_big
)
1799 if (lpe
->ex
.X_add_number
<= 0)
1800 generic_floating_point_number
= lpe
->floatnum
;
1802 memcpy (generic_bignum
, lpe
->bignum
,
1803 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1805 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1808 lpe
->next
= lpe_free_list
;
1809 lpe_free_list
= lpe
;
1811 lpe_list_tail
= NULL
;
1817 /* The .machine pseudo op allows to switch to a different CPU level in
1818 the asm listing. The current CPU setting can be stored on a stack
1819 with .machine push and restored with .machine pop. */
1822 s390_machine (int ignore ATTRIBUTE_UNUSED
)
1825 #define MAX_HISTORY 100
1826 static unsigned int *cpu_history
;
1827 static int curr_hist
;
1831 if (*input_line_pointer
== '"')
1834 cpu_string
= demand_copy_C_string (&len
);
1839 cpu_string
= input_line_pointer
;
1840 c
= get_symbol_end ();
1841 cpu_string
= xstrdup (cpu_string
);
1842 *input_line_pointer
= c
;
1845 if (cpu_string
!= NULL
)
1847 unsigned int old_cpu
= current_cpu
;
1848 unsigned int new_cpu
;
1850 if (strcmp (cpu_string
, "push") == 0)
1852 if (cpu_history
== NULL
)
1853 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
1855 if (curr_hist
>= MAX_HISTORY
)
1856 as_bad (_(".machine stack overflow"));
1858 cpu_history
[curr_hist
++] = current_cpu
;
1860 else if (strcmp (cpu_string
, "pop") == 0)
1863 as_bad (_(".machine stack underflow"));
1865 current_cpu
= cpu_history
[--curr_hist
];
1867 else if ((new_cpu
= s390_parse_cpu (cpu_string
)) != (unsigned int)-1)
1868 current_cpu
= new_cpu
;
1870 as_bad (_("invalid machine `%s'"), cpu_string
);
1872 if (current_cpu
!= old_cpu
)
1873 s390_setup_opcodes ();
1876 demand_empty_rest_of_line ();
1879 /* The .machinemode pseudo op allows to switch to a different
1880 architecture mode in the asm listing. The current architecture
1881 mode setting can be stored on a stack with .machinemode push and
1882 restored with .machinemode pop. */
1885 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
1888 #define MAX_HISTORY 100
1889 static unsigned int *mode_history
;
1890 static int curr_hist
;
1894 if (*input_line_pointer
== '"')
1897 mode_string
= demand_copy_C_string (&len
);
1902 mode_string
= input_line_pointer
;
1903 c
= get_symbol_end ();
1904 mode_string
= xstrdup (mode_string
);
1905 *input_line_pointer
= c
;
1908 if (mode_string
!= NULL
)
1910 unsigned int old_mode_mask
= current_mode_mask
;
1913 for (p
= mode_string
; *p
!= 0; p
++)
1916 if (strcmp (mode_string
, "push") == 0)
1918 if (mode_history
== NULL
)
1919 mode_history
= xmalloc (MAX_HISTORY
* sizeof (*mode_history
));
1921 if (curr_hist
>= MAX_HISTORY
)
1922 as_bad (_(".machinemode stack overflow"));
1924 mode_history
[curr_hist
++] = current_mode_mask
;
1926 else if (strcmp (mode_string
, "pop") == 0)
1929 as_bad (_(".machinemode stack underflow"));
1931 current_mode_mask
= mode_history
[--curr_hist
];
1935 if (strcmp (mode_string
, "esa") == 0)
1936 current_mode_mask
= 1 << S390_OPCODE_ESA
;
1937 else if (strcmp (mode_string
, "zarch") == 0)
1939 if (s390_arch_size
== 32)
1940 set_highgprs_p
= TRUE
;
1941 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
1943 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
1944 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
1946 as_bad (_("invalid machine `%s'"), mode_string
);
1949 if (current_mode_mask
!= old_mode_mask
)
1950 s390_setup_opcodes ();
1953 demand_empty_rest_of_line ();
1957 md_atof (int type
, char *litp
, int *sizep
)
1959 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
1962 /* Align a section (I don't know why this is machine dependent). */
1965 md_section_align (asection
*seg
, valueT addr
)
1967 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1969 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1972 /* We don't have any form of relaxing. */
1975 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
1976 asection
*seg ATTRIBUTE_UNUSED
)
1982 /* Convert a machine dependent frag. We never generate these. */
1985 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1986 asection
*sec ATTRIBUTE_UNUSED
,
1987 fragS
*fragp ATTRIBUTE_UNUSED
)
1993 md_undefined_symbol (char *name
)
1995 if (*name
== '_' && *(name
+ 1) == 'G'
1996 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
2000 if (symbol_find (name
))
2001 as_bad (_("GOT already in symbol table"));
2002 GOT_symbol
= symbol_new (name
, undefined_section
,
2003 (valueT
) 0, &zero_address_frag
);
2010 /* Functions concerning relocs. */
2012 /* The location from which a PC relative jump should be calculated,
2013 given a PC relative reloc. */
2016 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2018 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2021 /* Here we decide which fixups can be adjusted to make them relative to
2022 the beginning of the section instead of the symbol. Basically we need
2023 to make sure that the dynamic relocations are done correctly, so in
2024 some cases we force the original symbol to be used. */
2026 tc_s390_fix_adjustable (fixS
*fixP
)
2028 /* Don't adjust references to merge sections. */
2029 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
2031 /* adjust_reloc_syms doesn't know about the GOT. */
2032 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
2033 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2034 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
2035 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
2036 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
2037 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
2038 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
2039 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
2040 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
2041 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
2042 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
2043 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
2044 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
2045 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2046 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2047 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2048 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2049 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2050 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2051 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2052 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2053 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2054 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2055 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2056 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2057 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2058 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2059 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2060 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2061 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2062 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2063 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2064 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2065 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2066 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2067 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2068 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2069 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2070 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2071 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2072 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2073 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2074 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2075 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2076 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2077 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2078 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2083 /* Return true if we must always emit a reloc for a type and false if
2084 there is some hope of resolving it at assembly time. */
2086 tc_s390_force_relocation (struct fix
*fixp
)
2088 /* Ensure we emit a relocation for every reference to the global
2089 offset table or to the procedure link table. */
2090 switch (fixp
->fx_r_type
)
2092 case BFD_RELOC_390_GOT12
:
2093 case BFD_RELOC_390_GOT20
:
2094 case BFD_RELOC_32_GOT_PCREL
:
2095 case BFD_RELOC_32_GOTOFF
:
2096 case BFD_RELOC_390_GOTOFF64
:
2097 case BFD_RELOC_390_PLTOFF16
:
2098 case BFD_RELOC_390_PLTOFF32
:
2099 case BFD_RELOC_390_PLTOFF64
:
2100 case BFD_RELOC_390_GOTPC
:
2101 case BFD_RELOC_390_GOT16
:
2102 case BFD_RELOC_390_GOTPCDBL
:
2103 case BFD_RELOC_390_GOT64
:
2104 case BFD_RELOC_390_GOTENT
:
2105 case BFD_RELOC_390_PLT32
:
2106 case BFD_RELOC_390_PLT12DBL
:
2107 case BFD_RELOC_390_PLT16DBL
:
2108 case BFD_RELOC_390_PLT24DBL
:
2109 case BFD_RELOC_390_PLT32DBL
:
2110 case BFD_RELOC_390_PLT64
:
2111 case BFD_RELOC_390_GOTPLT12
:
2112 case BFD_RELOC_390_GOTPLT16
:
2113 case BFD_RELOC_390_GOTPLT20
:
2114 case BFD_RELOC_390_GOTPLT32
:
2115 case BFD_RELOC_390_GOTPLT64
:
2116 case BFD_RELOC_390_GOTPLTENT
:
2122 return generic_force_reloc (fixp
);
2125 /* Apply a fixup to the object code. This is called for all the
2126 fixups we generated by the call to fix_new_exp, above. In the call
2127 above we used a reloc code which was the largest legal reloc code
2128 plus the operand index. Here we undo that to recover the operand
2129 index. At this point all symbol values should be fully resolved,
2130 and we attempt to completely resolve the reloc. If we can not do
2131 that, we determine the correct reloc code and put it back in the
2135 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2138 valueT value
= *valP
;
2140 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2142 if (fixP
->fx_subsy
!= NULL
)
2143 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2144 _("cannot emit relocation %s against subsy symbol %s"),
2145 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2146 S_GET_NAME (fixP
->fx_subsy
));
2148 if (fixP
->fx_addsy
!= NULL
)
2151 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2156 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2158 const struct s390_operand
*operand
;
2161 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2162 operand
= &s390_operands
[opindex
];
2166 /* Insert the fully resolved operand value. */
2167 s390_insert_operand ((unsigned char *) where
, operand
,
2168 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2172 /* Determine a BFD reloc value based on the operand information.
2173 We are only prepared to turn a few of the operands into
2175 fixP
->fx_offset
= value
;
2176 if (operand
->bits
== 12 && operand
->shift
== 20)
2179 fixP
->fx_where
+= 2;
2180 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2182 else if (operand
->bits
== 12 && operand
->shift
== 36)
2185 fixP
->fx_where
+= 4;
2186 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2188 else if (operand
->bits
== 20 && operand
->shift
== 20)
2191 fixP
->fx_where
+= 2;
2192 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2194 else if (operand
->bits
== 8 && operand
->shift
== 8)
2197 fixP
->fx_where
+= 1;
2198 fixP
->fx_r_type
= BFD_RELOC_8
;
2200 else if (operand
->bits
== 12 && operand
->shift
== 12
2201 && (operand
->flags
& S390_OPERAND_PCREL
))
2204 fixP
->fx_where
+= 1;
2205 fixP
->fx_offset
+= 1;
2206 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2208 else if (operand
->bits
== 16 && operand
->shift
== 16)
2211 fixP
->fx_where
+= 2;
2212 if (operand
->flags
& S390_OPERAND_PCREL
)
2214 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2215 fixP
->fx_offset
+= 2;
2218 fixP
->fx_r_type
= BFD_RELOC_16
;
2220 else if (operand
->bits
== 24 && operand
->shift
== 24
2221 && (operand
->flags
& S390_OPERAND_PCREL
))
2224 fixP
->fx_where
+= 3;
2225 fixP
->fx_offset
+= 3;
2226 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2228 else if (operand
->bits
== 32 && operand
->shift
== 16
2229 && (operand
->flags
& S390_OPERAND_PCREL
))
2232 fixP
->fx_where
+= 2;
2233 fixP
->fx_offset
+= 2;
2234 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2241 /* Use expr_symbol_where to see if this is an expression
2243 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2244 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2245 _("unresolved expression that must be resolved"));
2247 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2248 _("unsupported relocation type"));
2255 switch (fixP
->fx_r_type
)
2261 md_number_to_chars (where
, value
, 1);
2263 case BFD_RELOC_390_12
:
2264 case BFD_RELOC_390_GOT12
:
2265 case BFD_RELOC_390_GOTPLT12
:
2266 case BFD_RELOC_390_PC12DBL
:
2267 case BFD_RELOC_390_PLT12DBL
:
2278 mop
= bfd_getb16 ((unsigned char *) where
);
2279 mop
|= (unsigned short) (value
& 0xfff);
2280 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2284 case BFD_RELOC_390_20
:
2285 case BFD_RELOC_390_GOT20
:
2286 case BFD_RELOC_390_GOTPLT20
:
2290 mop
= bfd_getb32 ((unsigned char *) where
);
2291 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2292 (value
& 0xff000) >> 12);
2293 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2298 case BFD_RELOC_GPREL16
:
2299 case BFD_RELOC_16_GOT_PCREL
:
2300 case BFD_RELOC_16_GOTOFF
:
2302 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2303 _("cannot emit PC relative %s relocation%s%s"),
2304 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2305 fixP
->fx_addsy
!= NULL
? " against " : "",
2306 (fixP
->fx_addsy
!= NULL
2307 ? S_GET_NAME (fixP
->fx_addsy
)
2310 md_number_to_chars (where
, value
, 2);
2312 case BFD_RELOC_390_GOT16
:
2313 case BFD_RELOC_390_PLTOFF16
:
2314 case BFD_RELOC_390_GOTPLT16
:
2316 md_number_to_chars (where
, value
, 2);
2318 case BFD_RELOC_390_PC16DBL
:
2319 case BFD_RELOC_390_PLT16DBL
:
2322 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2325 case BFD_RELOC_390_PC24DBL
:
2326 case BFD_RELOC_390_PLT24DBL
:
2333 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2334 mop
|= (unsigned int) (value
& 0xffffff);
2335 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2341 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2343 fixP
->fx_r_type
= BFD_RELOC_32
;
2345 md_number_to_chars (where
, value
, 4);
2347 case BFD_RELOC_32_PCREL
:
2348 case BFD_RELOC_32_BASEREL
:
2349 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2351 md_number_to_chars (where
, value
, 4);
2353 case BFD_RELOC_32_GOT_PCREL
:
2354 case BFD_RELOC_390_PLTOFF32
:
2355 case BFD_RELOC_390_PLT32
:
2356 case BFD_RELOC_390_GOTPLT32
:
2358 md_number_to_chars (where
, value
, 4);
2360 case BFD_RELOC_390_PC32DBL
:
2361 case BFD_RELOC_390_PLT32DBL
:
2362 case BFD_RELOC_390_GOTPCDBL
:
2363 case BFD_RELOC_390_GOTENT
:
2364 case BFD_RELOC_390_GOTPLTENT
:
2367 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2370 case BFD_RELOC_32_GOTOFF
:
2372 md_number_to_chars (where
, value
, sizeof (int));
2375 case BFD_RELOC_390_GOTOFF64
:
2377 md_number_to_chars (where
, value
, 8);
2380 case BFD_RELOC_390_GOT64
:
2381 case BFD_RELOC_390_PLTOFF64
:
2382 case BFD_RELOC_390_PLT64
:
2383 case BFD_RELOC_390_GOTPLT64
:
2385 md_number_to_chars (where
, value
, 8);
2390 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2392 fixP
->fx_r_type
= BFD_RELOC_64
;
2394 md_number_to_chars (where
, value
, 8);
2397 case BFD_RELOC_64_PCREL
:
2398 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2400 md_number_to_chars (where
, value
, 8);
2403 case BFD_RELOC_VTABLE_INHERIT
:
2404 case BFD_RELOC_VTABLE_ENTRY
:
2408 case BFD_RELOC_390_TLS_LOAD
:
2409 case BFD_RELOC_390_TLS_GDCALL
:
2410 case BFD_RELOC_390_TLS_LDCALL
:
2411 case BFD_RELOC_390_TLS_GD32
:
2412 case BFD_RELOC_390_TLS_GD64
:
2413 case BFD_RELOC_390_TLS_GOTIE12
:
2414 case BFD_RELOC_390_TLS_GOTIE20
:
2415 case BFD_RELOC_390_TLS_GOTIE32
:
2416 case BFD_RELOC_390_TLS_GOTIE64
:
2417 case BFD_RELOC_390_TLS_LDM32
:
2418 case BFD_RELOC_390_TLS_LDM64
:
2419 case BFD_RELOC_390_TLS_IE32
:
2420 case BFD_RELOC_390_TLS_IE64
:
2421 case BFD_RELOC_390_TLS_LE32
:
2422 case BFD_RELOC_390_TLS_LE64
:
2423 case BFD_RELOC_390_TLS_LDO32
:
2424 case BFD_RELOC_390_TLS_LDO64
:
2425 case BFD_RELOC_390_TLS_DTPMOD
:
2426 case BFD_RELOC_390_TLS_DTPOFF
:
2427 case BFD_RELOC_390_TLS_TPOFF
:
2428 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2429 /* Fully resolved at link time. */
2431 case BFD_RELOC_390_TLS_IEENT
:
2432 /* Fully resolved at link time. */
2433 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2439 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2441 if (reloc_name
!= NULL
)
2442 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2444 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2448 fixP
->fx_offset
= value
;
2452 /* Generate a reloc for a fixup. */
2455 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2457 bfd_reloc_code_real_type code
;
2460 code
= fixp
->fx_r_type
;
2461 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2463 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2464 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2465 code
= BFD_RELOC_390_GOTPC
;
2466 if (code
== BFD_RELOC_390_PC32DBL
)
2467 code
= BFD_RELOC_390_GOTPCDBL
;
2470 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2471 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2472 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2473 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2474 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2475 if (reloc
->howto
== NULL
)
2477 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2478 _("cannot represent relocation type %s"),
2479 bfd_get_reloc_code_name (code
));
2480 /* Set howto to a garbage value so that we can keep going. */
2481 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2482 gas_assert (reloc
->howto
!= NULL
);
2484 reloc
->addend
= fixp
->fx_offset
;
2490 s390_cfi_frame_initial_instructions (void)
2492 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2496 tc_s390_regname_to_dw2regnum (char *regname
)
2500 if (regname
[0] != 'c' && regname
[0] != 'a')
2502 regnum
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, regname
);
2503 if (regname
[0] == 'f' && regnum
!= -1)
2506 else if (strcmp (regname
, "ap") == 0)
2508 else if (strcmp (regname
, "cc") == 0)
2514 s390_elf_final_processing (void)
2517 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;