1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2015 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 },
112 /* Given NAME, find the register number associated with that name, return
113 the integer value associated with the given name or -1 on failure. */
116 reg_name_search (const char *name
)
120 if (strcasecmp (name
, "lit") == 0)
123 if (strcasecmp (name
, "sp") == 0)
126 if (name
[0] != 'a' && name
[0] != 'c' && name
[0] != 'f'
127 && name
[0] != 'r' && name
[0] != 'v')
130 if (ISDIGIT (name
[1]))
133 if (ISDIGIT (name
[2]))
134 val
= val
* 10 + name
[2] - '0';
137 if ((name
[0] != 'v' && val
> 15) || val
> 31)
145 * Summary of register_name().
147 * in: Input_line_pointer points to 1st char of operand.
149 * out: A expressionS.
150 * The operand may have been a register: in this case, X_op == O_register,
151 * X_add_number is set to the register number, and truth is returned.
152 * Input_line_pointer->(next non-blank) char after operand, or is in its
157 register_name (expressionS
*expressionP
)
164 /* Find the spelling of the operand. */
165 start
= name
= input_line_pointer
;
166 if (name
[0] == '%' && ISALPHA (name
[1]))
167 name
= ++input_line_pointer
;
171 c
= get_symbol_end ();
172 reg_number
= reg_name_search (name
);
174 /* Put back the delimiting char. */
175 *input_line_pointer
= c
;
177 /* Look to see if it's in the register table. */
180 expressionP
->X_op
= O_register
;
181 expressionP
->X_add_number
= reg_number
;
183 /* Make the rest nice. */
184 expressionP
->X_add_symbol
= NULL
;
185 expressionP
->X_op_symbol
= NULL
;
189 /* Reset the line as if we had not done anything. */
190 input_line_pointer
= start
;
194 /* Local variables. */
196 /* Opformat hash table. */
197 static struct hash_control
*s390_opformat_hash
;
199 /* Opcode hash table. */
200 static struct hash_control
*s390_opcode_hash
= NULL
;
202 /* Flags to set in the elf header */
203 static flagword s390_flags
= 0;
205 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
207 #ifndef WORKING_DOT_WORD
208 int md_short_jump_size
= 4;
209 int md_long_jump_size
= 4;
212 const char *md_shortopts
= "A:m:kVQ:";
213 struct option md_longopts
[] = {
214 {NULL
, no_argument
, NULL
, 0}
216 size_t md_longopts_size
= sizeof (md_longopts
);
218 /* Initialize the default opcode arch and word size from the default
219 architecture name if not specified by an option. */
221 init_default_arch (void)
223 if (strcmp (default_arch
, "s390") == 0)
225 if (s390_arch_size
== 0)
228 else if (strcmp (default_arch
, "s390x") == 0)
230 if (s390_arch_size
== 0)
234 as_fatal (_("Invalid default architecture, broken assembler."));
236 if (current_mode_mask
== 0)
238 /* Default to z/Architecture mode if the CPU supports it. */
239 if (current_cpu
< S390_OPCODE_Z900
)
240 current_mode_mask
= 1 << S390_OPCODE_ESA
;
242 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
246 /* Called by TARGET_FORMAT. */
248 s390_target_format (void)
250 /* We don't get a chance to initialize anything before we're called,
251 so handle that now. */
252 init_default_arch ();
254 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
257 /* Map a CPU string as given with -march= or .machine to the
258 respective enum s390_opcode_cpu_val value. 0xffffffff is returned
259 in case of an error. */
262 s390_parse_cpu (char *arg
)
264 if (strcmp (arg
, "g5") == 0)
265 return S390_OPCODE_G5
;
266 else if (strcmp (arg
, "g6") == 0)
267 return S390_OPCODE_G6
;
268 else if (strcmp (arg
, "z900") == 0)
269 return S390_OPCODE_Z900
;
270 else if (strcmp (arg
, "z990") == 0)
271 return S390_OPCODE_Z990
;
272 else if (strcmp (arg
, "z9-109") == 0)
273 return S390_OPCODE_Z9_109
;
274 else if (strcmp (arg
, "z9-ec") == 0)
275 return S390_OPCODE_Z9_EC
;
276 else if (strcmp (arg
, "z10") == 0)
277 return S390_OPCODE_Z10
;
278 else if (strcmp (arg
, "z196") == 0)
279 return S390_OPCODE_Z196
;
280 else if (strcmp (arg
, "zEC12") == 0)
281 return S390_OPCODE_ZEC12
;
282 else if (strcmp (arg
, "z13") == 0)
283 return S390_OPCODE_Z13
;
284 else if (strcmp (arg
, "all") == 0)
285 return S390_OPCODE_MAXCPU
- 1;
291 md_parse_option (int c
, char *arg
)
295 /* -k: Ignore for FreeBSD compatibility. */
299 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
302 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
305 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
306 warn_areg_zero
= TRUE
;
308 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
311 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
314 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
315 current_mode_mask
= 1 << S390_OPCODE_ESA
;
317 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
319 if (s390_arch_size
== 32)
320 set_highgprs_p
= TRUE
;
321 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
324 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
326 current_cpu
= s390_parse_cpu (arg
+ 5);
328 if (current_cpu
== (unsigned int)-1)
330 as_bad (_("invalid switch -m%s"), arg
);
337 as_bad (_("invalid switch -m%s"), arg
);
343 /* Option -A is deprecated. Still available for compatibility. */
344 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
345 current_cpu
= S390_OPCODE_G5
;
346 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
347 current_cpu
= S390_OPCODE_Z900
;
349 as_bad (_("invalid architecture -A%s"), arg
);
352 /* -V: SVR4 argument to print version ID. */
357 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
358 should be emitted or not. FIXME: Not implemented. */
370 md_show_usage (FILE *stream
)
372 fprintf (stream
, _("\
374 -mregnames Allow symbolic names for registers\n\
375 -mwarn-areg-zero Warn about zero base/index registers\n\
376 -mno-regnames Do not allow symbolic names for registers\n\
377 -m31 Set file format to 31 bit format\n\
378 -m64 Set file format to 64 bit format\n"));
379 fprintf (stream
, _("\
380 -V print assembler version number\n\
381 -Qy, -Qn ignored\n"));
384 /* Generate the hash table mapping mnemonics to struct s390_opcode.
385 This table is built at startup and whenever the CPU level is
386 changed using .machine. */
389 s390_setup_opcodes (void)
391 const struct s390_opcode
*op
;
392 const struct s390_opcode
*op_end
;
393 bfd_boolean dup_insn
= FALSE
;
396 if (s390_opcode_hash
!= NULL
)
397 hash_die (s390_opcode_hash
);
399 /* Insert the opcodes into a hash table. */
400 s390_opcode_hash
= hash_new ();
402 op_end
= s390_opcodes
+ s390_num_opcodes
;
403 for (op
= s390_opcodes
; op
< op_end
; op
++)
405 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
407 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
412 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
414 retval
= hash_insert (s390_opcode_hash
, op
->name
, (void *) op
);
415 if (retval
!= (const char *) NULL
)
417 as_bad (_("Internal assembler error for instruction %s"),
423 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
431 /* This function is called when the assembler starts up. It is called
432 after the options have been parsed and the output file has been
438 const struct s390_opcode
*op
;
439 const struct s390_opcode
*op_end
;
442 /* Give a warning if the combination -m64-bit and -Aesa is used. */
443 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
444 as_warn (_("The 64 bit file format is used without esame instructions."));
446 s390_cie_data_alignment
= -s390_arch_size
/ 8;
448 /* Set the ELF flags if desired. */
450 bfd_set_private_flags (stdoutput
, s390_flags
);
452 /* Insert the opcode formats into a hash table. */
453 s390_opformat_hash
= hash_new ();
455 op_end
= s390_opformats
+ s390_num_opformats
;
456 for (op
= s390_opformats
; op
< op_end
; op
++)
458 retval
= hash_insert (s390_opformat_hash
, op
->name
, (void *) op
);
459 if (retval
!= (const char *) NULL
)
460 as_bad (_("Internal assembler error for instruction format %s"),
464 s390_setup_opcodes ();
466 record_alignment (text_section
, 2);
467 record_alignment (data_section
, 2);
468 record_alignment (bss_section
, 2);
471 /* Called after all assembly has been done. */
475 if (s390_arch_size
== 64)
476 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
478 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
481 /* Insert an operand value into an instruction. */
484 s390_insert_operand (unsigned char *insn
,
485 const struct s390_operand
*operand
,
493 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
497 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
498 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
499 /* Halve PCREL operands. */
500 if (operand
->flags
& S390_OPERAND_PCREL
)
502 /* Check for underflow / overflow. */
503 if (val
< min
|| val
> max
)
506 _("operand out of range (%s not between %ld and %ld)");
509 if (operand
->flags
& S390_OPERAND_PCREL
)
515 sprint_value (buf
, val
);
516 if (file
== (char *) NULL
)
517 as_bad (err
, buf
, (int) min
, (int) max
);
519 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
522 /* val is ok, now restrict it to operand->bits bits. */
523 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
524 /* val is restrict, now check for special case. */
525 if (operand
->bits
== 20 && operand
->shift
== 20)
526 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
532 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
534 uval
= (addressT
) val
;
536 /* Vector register operands have an additional bit in the RXB
538 if (operand
->flags
& S390_OPERAND_VR
)
539 max
= (max
<< 1) | 1;
541 /* Length x in an instructions has real length x+1. */
542 if (operand
->flags
& S390_OPERAND_LENGTH
)
544 /* Check for underflow / overflow. */
545 if (uval
< min
|| uval
> max
)
547 if (operand
->flags
& S390_OPERAND_LENGTH
)
554 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
560 if (operand
->flags
& S390_OPERAND_VR
)
562 /* Insert the extra bit into the RXB field. */
563 switch (operand
->shift
)
566 insn
[4] |= (uval
& 0x10) >> 1;
569 insn
[4] |= (uval
& 0x10) >> 2;
572 insn
[4] |= (uval
& 0x10) >> 3;
575 insn
[4] |= (uval
& 0x10) >> 4;
581 if (operand
->flags
& S390_OPERAND_OR1
)
583 if (operand
->flags
& S390_OPERAND_OR2
)
585 if (operand
->flags
& S390_OPERAND_OR8
)
588 /* Duplicate the operand at bit pos 12 to 16. */
589 if (operand
->flags
& S390_OPERAND_CP16
)
591 /* Copy VR operand at bit pos 12 to bit pos 16. */
592 insn
[2] |= uval
<< 4;
593 /* Copy the flag in the RXB field. */
594 insn
[4] |= (insn
[4] & 4) >> 1;
597 /* Insert fragments of the operand byte for byte. */
598 offset
= operand
->shift
+ operand
->bits
;
599 uval
<<= (-offset
) & 7;
600 insn
+= (offset
- 1) / 8;
612 bfd_reloc_code_real_type reloc
;
615 /* Parse tls marker and return the desired relocation. */
616 static bfd_reloc_code_real_type
617 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
619 static struct map_tls mapping
[] =
621 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
622 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
623 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
624 { NULL
, 0, BFD_RELOC_UNUSED
}
634 return BFD_RELOC_UNUSED
;
637 while (ISIDNUM (*str
))
641 return BFD_RELOC_UNUSED
;
643 orig_line
= input_line_pointer
;
644 input_line_pointer
= str
;
646 str
= input_line_pointer
;
647 if (&input_line_pointer
!= str_p
)
648 input_line_pointer
= orig_line
;
650 if (exp_p
->X_op
!= O_symbol
)
651 return BFD_RELOC_UNUSED
;
653 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
654 if (len
== ptr
->length
655 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
657 /* Found a matching tls suffix. */
661 return BFD_RELOC_UNUSED
;
664 /* Structure used to hold suffixes. */
675 ELF_SUFFIX_TLS_GOTIE
,
687 elf_suffix_type suffix
;
691 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
692 static elf_suffix_type
693 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
695 static struct map_bfd mapping
[] =
697 { "got", 3, ELF_SUFFIX_GOT
},
698 { "got12", 5, ELF_SUFFIX_GOT
},
699 { "plt", 3, ELF_SUFFIX_PLT
},
700 { "gotent", 6, ELF_SUFFIX_GOTENT
},
701 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
702 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
703 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
704 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
705 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
706 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
707 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
708 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
709 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
710 { NULL
, 0, ELF_SUFFIX_NONE
}
719 return ELF_SUFFIX_NONE
;
722 while (ISALNUM (*str
))
726 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
727 if (len
== ptr
->length
728 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
730 if (exp_p
->X_add_number
!= 0)
731 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
732 ptr
->string
, ptr
->string
);
733 /* Now check for identifier@suffix+constant. */
734 if (*str
== '-' || *str
== '+')
736 char *orig_line
= input_line_pointer
;
739 input_line_pointer
= str
;
740 expression (&new_exp
);
742 switch (new_exp
.X_op
)
744 case O_constant
: /* X_add_number (a constant expression). */
745 exp_p
->X_add_number
+= new_exp
.X_add_number
;
746 str
= input_line_pointer
;
748 case O_symbol
: /* X_add_symbol + X_add_number. */
749 /* this case is used for e.g. xyz@PLT+.Label. */
750 exp_p
->X_add_number
+= new_exp
.X_add_number
;
751 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
753 str
= input_line_pointer
;
755 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
756 /* this case is used for e.g. xyz@PLT-.Label. */
757 exp_p
->X_add_number
+= new_exp
.X_add_number
;
758 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
759 exp_p
->X_op
= O_subtract
;
760 str
= input_line_pointer
;
766 /* If s390_elf_suffix has not been called with
767 &input_line_pointer as first parameter, we have
768 clobbered the input_line_pointer. We have to
770 if (&input_line_pointer
!= str_p
)
771 input_line_pointer
= orig_line
;
777 return BFD_RELOC_UNUSED
;
780 /* Structure used to hold a literal pool entry. */
783 struct s390_lpe
*next
;
785 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
786 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
788 bfd_reloc_code_real_type reloc
;
792 static struct s390_lpe
*lpe_free_list
= NULL
;
793 static struct s390_lpe
*lpe_list
= NULL
;
794 static struct s390_lpe
*lpe_list_tail
= NULL
;
795 static symbolS
*lp_sym
= NULL
;
796 static int lp_count
= 0;
797 static int lpe_count
= 0;
800 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
802 if (exp1
->X_op
!= exp2
->X_op
)
807 case O_constant
: /* X_add_number must be equal. */
809 return exp1
->X_add_number
== exp2
->X_add_number
;
812 as_bad (_("Can't handle O_big in s390_exp_compare"));
814 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
819 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
820 && (exp1
->X_add_number
== exp2
->X_add_number
);
822 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
827 case O_bit_inclusive_or
:
829 case O_bit_exclusive_or
:
841 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
842 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
843 && (exp1
->X_add_number
== exp2
->X_add_number
);
849 /* Test for @lit and if its present make an entry in the literal pool and
850 modify the current expression to be an offset into the literal pool. */
851 static elf_suffix_type
852 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
854 bfd_reloc_code_real_type reloc
;
858 struct s390_lpe
*lpe
;
862 return suffix
; /* No modification. */
864 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
866 while (ISALNUM (*str
))
869 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
870 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
871 return suffix
; /* no modification */
872 nbytes
= ident
[3] - '0';
874 reloc
= BFD_RELOC_UNUSED
;
875 if (suffix
== ELF_SUFFIX_GOT
)
878 reloc
= BFD_RELOC_390_GOT16
;
879 else if (nbytes
== 4)
880 reloc
= BFD_RELOC_32_GOT_PCREL
;
881 else if (nbytes
== 8)
882 reloc
= BFD_RELOC_390_GOT64
;
884 else if (suffix
== ELF_SUFFIX_PLT
)
887 reloc
= BFD_RELOC_390_PLT32
;
888 else if (nbytes
== 8)
889 reloc
= BFD_RELOC_390_PLT64
;
892 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
893 as_bad (_("Invalid suffix for literal pool entry"));
895 /* Search the pool if the new entry is a duplicate. */
896 if (exp_p
->X_op
== O_big
)
898 /* Special processing for big numbers. */
899 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
901 if (lpe
->ex
.X_op
== O_big
)
903 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
905 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
906 sizeof (FLONUM_TYPE
)) == 0)
909 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
911 if (memcmp (generic_bignum
, lpe
->bignum
,
912 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
920 /* Processing for 'normal' data types. */
921 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
922 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
923 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
930 if (lpe_free_list
!= NULL
)
933 lpe_free_list
= lpe_free_list
->next
;
937 lpe
= (struct s390_lpe
*) xmalloc (sizeof (struct s390_lpe
));
942 if (exp_p
->X_op
== O_big
)
944 if (exp_p
->X_add_number
<= 0)
945 lpe
->floatnum
= generic_floating_point_number
;
946 else if (exp_p
->X_add_number
<= 4)
947 memcpy (lpe
->bignum
, generic_bignum
,
948 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
950 as_bad (_("Big number is too big"));
953 lpe
->nbytes
= nbytes
;
955 /* Literal pool name defined ? */
958 sprintf (tmp_name
, ".L\001%i", lp_count
);
959 lp_sym
= symbol_make (tmp_name
);
962 /* Make name for literal pool entry. */
963 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
965 lpe
->sym
= symbol_make (tmp_name
);
967 /* Add to literal pool list. */
969 if (lpe_list_tail
!= NULL
)
971 lpe_list_tail
->next
= lpe
;
975 lpe_list
= lpe_list_tail
= lpe
;
978 /* Now change exp_p to the offset into the literal pool.
979 Thats the expression: .L^Ax^By-.L^Ax */
980 exp_p
->X_add_symbol
= lpe
->sym
;
981 exp_p
->X_op_symbol
= lp_sym
;
982 exp_p
->X_op
= O_subtract
;
983 exp_p
->X_add_number
= 0;
987 /* We change the suffix type to ELF_SUFFIX_NONE, because
988 the difference of two local labels is just a number. */
989 return ELF_SUFFIX_NONE
;
992 /* Like normal .long/.short/.word, except support @got, etc.
993 clobbers input_line_pointer, checks end-of-line. */
995 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
998 elf_suffix_type suffix
;
1000 if (is_it_end_of_statement ())
1002 demand_empty_rest_of_line ();
1010 if (exp
.X_op
== O_symbol
1011 && *input_line_pointer
== '@'
1012 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1014 bfd_reloc_code_real_type reloc
;
1015 reloc_howto_type
*reloc_howto
;
1021 static bfd_reloc_code_real_type tab2
[] =
1023 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1024 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1025 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1026 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1027 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1028 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1029 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1030 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1031 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1032 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1033 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1034 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1035 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1037 reloc
= tab2
[suffix
];
1039 else if (nbytes
== 4)
1041 static bfd_reloc_code_real_type tab4
[] =
1043 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1044 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1045 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1046 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1047 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1048 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1049 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1050 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1051 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1052 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1053 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1054 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1055 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1057 reloc
= tab4
[suffix
];
1059 else if (nbytes
== 8)
1061 static bfd_reloc_code_real_type tab8
[] =
1063 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1064 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1065 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1066 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1067 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1068 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1069 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1070 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1071 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1072 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1073 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1074 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1075 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1077 reloc
= tab8
[suffix
];
1080 reloc
= BFD_RELOC_UNUSED
;
1082 if (reloc
!= BFD_RELOC_UNUSED
1083 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1085 size
= bfd_get_reloc_size (reloc_howto
);
1087 as_bad (_("%s relocations do not fit in %d bytes"),
1088 reloc_howto
->name
, nbytes
);
1089 where
= frag_more (nbytes
);
1090 md_number_to_chars (where
, 0, size
);
1091 /* To make fixup_segment do the pc relative conversion the
1092 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1093 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1094 size
, &exp
, FALSE
, reloc
);
1097 as_bad (_("relocation not applicable"));
1100 emit_expr (&exp
, (unsigned int) nbytes
);
1102 while (*input_line_pointer
++ == ',');
1104 input_line_pointer
--; /* Put terminator back into stream. */
1105 demand_empty_rest_of_line ();
1108 /* We need to keep a list of fixups. We can't simply generate them as
1109 we go, because that would require us to first create the frag, and
1110 that would screw up references to ``.''. */
1116 bfd_reloc_code_real_type reloc
;
1119 #define MAX_INSN_FIXUPS (4)
1121 /* This routine is called for each instruction to be assembled. */
1124 md_gather_operands (char *str
,
1125 unsigned char *insn
,
1126 const struct s390_opcode
*opcode
)
1128 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1129 const struct s390_operand
*operand
;
1130 const unsigned char *opindex_ptr
;
1132 elf_suffix_type suffix
;
1133 bfd_reloc_code_real_type reloc
;
1138 while (ISSPACE (*str
))
1143 /* Gather the operands. */
1145 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1149 operand
= s390_operands
+ *opindex_ptr
;
1151 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM
) && *str
== '\0')
1153 /* Optional parameters might need to be ORed with a
1154 value so calling s390_insert_operand is needed. */
1155 s390_insert_operand (insn
, operand
, 0, NULL
, 0);
1159 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1161 /* We do an early skip. For D(X,B) constructions the index
1162 register is skipped (X is optional). For D(L,B) the base
1163 register will be the skipped operand, because L is NOT
1169 /* Gather the operand. */
1170 hold
= input_line_pointer
;
1171 input_line_pointer
= str
;
1173 /* Parse the operand. */
1174 if (! register_name (&ex
))
1177 str
= input_line_pointer
;
1178 input_line_pointer
= hold
;
1180 /* Write the operand to the insn. */
1181 if (ex
.X_op
== O_illegal
)
1182 as_bad (_("illegal operand"));
1183 else if (ex
.X_op
== O_absent
)
1185 /* No operands, check if all operands can be skipped. */
1186 while (*opindex_ptr
!= 0 && operand
->flags
& S390_OPERAND_OPTIONAL
)
1188 if (operand
->flags
& S390_OPERAND_DISP
)
1190 /* An optional displacement makes the whole D(X,B)
1191 D(L,B) or D(B) block optional. */
1193 operand
= s390_operands
+ *(++opindex_ptr
);
1194 } while (!(operand
->flags
& S390_OPERAND_BASE
));
1196 operand
= s390_operands
+ *(++opindex_ptr
);
1198 if (opindex_ptr
[0] == '\0')
1200 as_bad (_("missing operand"));
1202 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1204 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1206 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1208 /* We need to generate a fixup for the
1209 expression returned by s390_lit_suffix. */
1210 if (fc
>= MAX_INSN_FIXUPS
)
1211 as_fatal (_("too many fixups"));
1212 fixups
[fc
].exp
= ex
;
1213 fixups
[fc
].opindex
= *opindex_ptr
;
1214 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1219 if ((operand
->flags
& S390_OPERAND_INDEX
)
1220 && ex
.X_add_number
== 0
1222 as_warn (_("index register specified but zero"));
1223 if ((operand
->flags
& S390_OPERAND_BASE
)
1224 && ex
.X_add_number
== 0
1226 as_warn (_("base register specified but zero"));
1227 if ((operand
->flags
& S390_OPERAND_GPR
)
1228 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1229 && (ex
.X_add_number
& 1))
1230 as_fatal (_("odd numbered general purpose register specified as "
1232 if ((operand
->flags
& S390_OPERAND_FPR
)
1233 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1234 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1235 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1236 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1237 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1238 as_fatal (_("invalid floating point register pair. Valid fp "
1239 "register pair operands are 0, 1, 4, 5, 8, 9, "
1241 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1246 suffix
= s390_elf_suffix (&str
, &ex
);
1247 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1248 reloc
= BFD_RELOC_UNUSED
;
1250 if (suffix
== ELF_SUFFIX_GOT
)
1252 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1253 (operand
->bits
== 12))
1254 reloc
= BFD_RELOC_390_GOT12
;
1255 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1256 (operand
->bits
== 20))
1257 reloc
= BFD_RELOC_390_GOT20
;
1258 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1259 && (operand
->bits
== 16))
1260 reloc
= BFD_RELOC_390_GOT16
;
1261 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1262 && (operand
->bits
== 32))
1263 reloc
= BFD_RELOC_390_GOTENT
;
1265 else if (suffix
== ELF_SUFFIX_PLT
)
1267 if ((operand
->flags
& S390_OPERAND_PCREL
)
1268 && (operand
->bits
== 12))
1269 reloc
= BFD_RELOC_390_PLT12DBL
;
1270 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1271 && (operand
->bits
== 16))
1272 reloc
= BFD_RELOC_390_PLT16DBL
;
1273 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1274 && (operand
->bits
== 24))
1275 reloc
= BFD_RELOC_390_PLT24DBL
;
1276 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1277 && (operand
->bits
== 32))
1278 reloc
= BFD_RELOC_390_PLT32DBL
;
1280 else if (suffix
== ELF_SUFFIX_GOTENT
)
1282 if ((operand
->flags
& S390_OPERAND_PCREL
)
1283 && (operand
->bits
== 32))
1284 reloc
= BFD_RELOC_390_GOTENT
;
1286 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1288 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1289 && (operand
->bits
== 16))
1290 reloc
= BFD_RELOC_16_GOTOFF
;
1292 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1294 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1295 && (operand
->bits
== 16))
1296 reloc
= BFD_RELOC_390_PLTOFF16
;
1298 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1300 if ((operand
->flags
& S390_OPERAND_DISP
)
1301 && (operand
->bits
== 12))
1302 reloc
= BFD_RELOC_390_GOTPLT12
;
1303 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1304 && (operand
->bits
== 16))
1305 reloc
= BFD_RELOC_390_GOTPLT16
;
1306 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1307 && (operand
->bits
== 32))
1308 reloc
= BFD_RELOC_390_GOTPLTENT
;
1310 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1312 if ((operand
->flags
& S390_OPERAND_DISP
)
1313 && (operand
->bits
== 12))
1314 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1315 else if ((operand
->flags
& S390_OPERAND_DISP
)
1316 && (operand
->bits
== 20))
1317 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1319 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1321 if ((operand
->flags
& S390_OPERAND_PCREL
)
1322 && (operand
->bits
== 32))
1323 reloc
= BFD_RELOC_390_TLS_IEENT
;
1326 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1327 as_bad (_("invalid operand suffix"));
1328 /* We need to generate a fixup of type 'reloc' for this
1330 if (fc
>= MAX_INSN_FIXUPS
)
1331 as_fatal (_("too many fixups"));
1332 fixups
[fc
].exp
= ex
;
1333 fixups
[fc
].opindex
= *opindex_ptr
;
1334 fixups
[fc
].reloc
= reloc
;
1338 /* Check the next character. The call to expression has advanced
1339 str past any whitespace. */
1340 if (operand
->flags
& S390_OPERAND_DISP
)
1342 /* After a displacement a block in parentheses can start. */
1345 /* Check if parenthesized block can be skipped. If the next
1346 operand is neiter an optional operand nor a base register
1347 then we have a syntax error. */
1348 operand
= s390_operands
+ *(++opindex_ptr
);
1349 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1350 as_bad (_("syntax error; missing '(' after displacement"));
1352 /* Ok, skip all operands until S390_OPERAND_BASE. */
1353 while (!(operand
->flags
& S390_OPERAND_BASE
))
1354 operand
= s390_operands
+ *(++opindex_ptr
);
1356 /* If there is a next operand it must be separated by a comma. */
1357 if (opindex_ptr
[1] != '\0')
1361 while (opindex_ptr
[1] != '\0')
1363 operand
= s390_operands
+ *(++opindex_ptr
);
1364 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1366 as_bad (_("syntax error; expected ,"));
1376 /* We found an opening parentheses. */
1378 for (f
= str
; *f
!= '\0'; f
++)
1379 if (*f
== ',' || *f
== ')')
1381 /* If there is no comma until the closing parentheses OR
1382 there is a comma right after the opening parentheses,
1383 we have to skip optional operands. */
1384 if (*f
== ',' && f
== str
)
1386 /* comma directly after '(' ? */
1391 skip_optional
= (*f
!= ',');
1394 else if (operand
->flags
& S390_OPERAND_BASE
)
1396 /* After the base register the parenthesed block ends. */
1398 as_bad (_("syntax error; missing ')' after base register"));
1400 /* If there is a next operand it must be separated by a comma. */
1401 if (opindex_ptr
[1] != '\0')
1405 while (opindex_ptr
[1] != '\0')
1407 operand
= s390_operands
+ *(++opindex_ptr
);
1408 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1410 as_bad (_("syntax error; expected ,"));
1420 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1421 of D(L,B). In this case the base register has to be skipped. */
1424 operand
= s390_operands
+ *(++opindex_ptr
);
1426 if (!(operand
->flags
& S390_OPERAND_BASE
))
1427 as_bad (_("syntax error; ')' not allowed here"));
1431 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM
) && *str
== '\0')
1434 /* If there is a next operand it must be separated by a comma. */
1435 if (opindex_ptr
[1] != '\0')
1439 while (opindex_ptr
[1] != '\0')
1441 operand
= s390_operands
+ *(++opindex_ptr
);
1442 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1444 as_bad (_("syntax error; expected ,"));
1454 while (ISSPACE (*str
))
1457 /* Check for tls instruction marker. */
1458 reloc
= s390_tls_suffix (&str
, &ex
);
1459 if (reloc
!= BFD_RELOC_UNUSED
)
1461 /* We need to generate a fixup of type 'reloc' for this
1463 if (fc
>= MAX_INSN_FIXUPS
)
1464 as_fatal (_("too many fixups"));
1465 fixups
[fc
].exp
= ex
;
1466 fixups
[fc
].opindex
= -1;
1467 fixups
[fc
].reloc
= reloc
;
1475 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1477 as_bad (_("junk at end of line: `%s'"), str
);
1478 if (linefeed
!= NULL
)
1482 /* Write out the instruction. */
1483 f
= frag_more (opcode
->oplen
);
1484 memcpy (f
, insn
, opcode
->oplen
);
1485 dwarf2_emit_insn (opcode
->oplen
);
1487 /* Create any fixups. At this point we do not use a
1488 bfd_reloc_code_real_type, but instead just use the
1489 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1490 handle fixups for any operand type, although that is admittedly
1491 not a very exciting feature. We pick a BFD reloc type in
1493 for (i
= 0; i
< fc
; i
++)
1496 if (fixups
[i
].opindex
< 0)
1498 /* Create tls instruction marker relocation. */
1499 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1500 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1504 operand
= s390_operands
+ fixups
[i
].opindex
;
1506 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1508 reloc_howto_type
*reloc_howto
;
1512 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1516 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1518 if (size
< 1 || size
> 4)
1521 fixP
= fix_new_exp (frag_now
,
1522 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1523 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1525 /* Turn off overflow checking in fixup_segment. This is necessary
1526 because fixup_segment will signal an overflow for large 4 byte
1527 quantities for GOT12 relocations. */
1528 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1529 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1530 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1531 fixP
->fx_no_overflow
= 1;
1534 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1535 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1536 ((bfd_reloc_code_real_type
)
1537 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1542 /* This routine is called for each instruction to be assembled. */
1545 md_assemble (char *str
)
1547 const struct s390_opcode
*opcode
;
1548 unsigned char insn
[6];
1551 /* Get the opcode. */
1552 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1557 /* Look up the opcode in the hash table. */
1558 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1559 if (opcode
== (const struct s390_opcode
*) NULL
)
1561 as_bad (_("Unrecognized opcode: `%s'"), str
);
1564 else if (!(opcode
->modes
& current_mode_mask
))
1566 as_bad (_("Opcode %s not available in this mode"), str
);
1569 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1570 md_gather_operands (s
, insn
, opcode
);
1573 #ifndef WORKING_DOT_WORD
1574 /* Handle long and short jumps. We don't support these */
1576 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1578 addressT from_addr
, to_addr
;
1586 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1588 addressT from_addr
, to_addr
;
1597 s390_bss (int ignore ATTRIBUTE_UNUSED
)
1599 /* We don't support putting frags in the BSS segment, we fake it
1600 by marking in_bss, then looking at s_skip for clues. */
1602 subseg_set (bss_section
, 0);
1603 demand_empty_rest_of_line ();
1606 /* Pseudo-op handling. */
1609 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1612 const struct s390_opcode
*opformat
;
1613 unsigned char insn
[6];
1616 /* Get the opcode format. */
1617 s
= input_line_pointer
;
1618 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1621 as_bad (_("Invalid .insn format\n"));
1624 /* Look up the opcode in the hash table. */
1625 opformat
= (struct s390_opcode
*)
1626 hash_find (s390_opformat_hash
, input_line_pointer
);
1627 if (opformat
== (const struct s390_opcode
*) NULL
)
1629 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1632 input_line_pointer
= s
;
1634 if (exp
.X_op
== O_constant
)
1636 if ( ( opformat
->oplen
== 6
1637 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1638 || ( opformat
->oplen
== 4
1639 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1640 || ( opformat
->oplen
== 2
1641 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1642 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1644 as_bad (_("Invalid .insn format\n"));
1646 else if (exp
.X_op
== O_big
)
1648 if (exp
.X_add_number
> 0
1649 && opformat
->oplen
== 6
1650 && generic_bignum
[3] == 0)
1652 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1653 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1654 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1657 as_bad (_("Invalid .insn format\n"));
1660 as_bad (_("second operand of .insn not a constant\n"));
1662 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1663 as_bad (_("missing comma after insn constant\n"));
1665 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1667 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1671 demand_empty_rest_of_line ();
1674 /* The .byte pseudo-op. This is similar to the normal .byte
1675 pseudo-op, but it can also take a single ASCII string. */
1678 s390_byte (int ignore ATTRIBUTE_UNUSED
)
1680 if (*input_line_pointer
!= '\"')
1686 /* Gather characters. A real double quote is doubled. Unusual
1687 characters are not permitted. */
1688 ++input_line_pointer
;
1693 c
= *input_line_pointer
++;
1697 if (*input_line_pointer
!= '\"')
1699 ++input_line_pointer
;
1702 FRAG_APPEND_1_CHAR (c
);
1705 demand_empty_rest_of_line ();
1708 /* The .ltorg pseudo-op.This emits all literals defined since the last
1709 .ltorg or the invocation of gas. Literals are defined with the
1713 s390_literals (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 /* The .machine pseudo op allows to switch to a different CPU level in
1772 the asm listing. The current CPU setting can be stored on a stack
1773 with .machine push and restored with .machine pop. */
1776 s390_machine (int ignore ATTRIBUTE_UNUSED
)
1779 #define MAX_HISTORY 100
1780 static unsigned int *cpu_history
;
1781 static int curr_hist
;
1785 if (*input_line_pointer
== '"')
1788 cpu_string
= demand_copy_C_string (&len
);
1793 cpu_string
= input_line_pointer
;
1794 c
= get_symbol_end ();
1795 cpu_string
= xstrdup (cpu_string
);
1796 *input_line_pointer
= c
;
1799 if (cpu_string
!= NULL
)
1801 unsigned int old_cpu
= current_cpu
;
1802 unsigned int new_cpu
;
1804 if (strcmp (cpu_string
, "push") == 0)
1806 if (cpu_history
== NULL
)
1807 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
1809 if (curr_hist
>= MAX_HISTORY
)
1810 as_bad (_(".machine stack overflow"));
1812 cpu_history
[curr_hist
++] = current_cpu
;
1814 else if (strcmp (cpu_string
, "pop") == 0)
1817 as_bad (_(".machine stack underflow"));
1819 current_cpu
= cpu_history
[--curr_hist
];
1821 else if ((new_cpu
= s390_parse_cpu (cpu_string
)) != (unsigned int)-1)
1822 current_cpu
= new_cpu
;
1824 as_bad (_("invalid machine `%s'"), cpu_string
);
1826 if (current_cpu
!= old_cpu
)
1827 s390_setup_opcodes ();
1830 demand_empty_rest_of_line ();
1833 /* The .machinemode pseudo op allows to switch to a different
1834 architecture mode in the asm listing. The current architecture
1835 mode setting can be stored on a stack with .machinemode push and
1836 restored with .machinemode pop. */
1839 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
1842 #define MAX_HISTORY 100
1843 static unsigned int *mode_history
;
1844 static int curr_hist
;
1848 if (*input_line_pointer
== '"')
1851 mode_string
= demand_copy_C_string (&len
);
1856 mode_string
= input_line_pointer
;
1857 c
= get_symbol_end ();
1858 mode_string
= xstrdup (mode_string
);
1859 *input_line_pointer
= c
;
1862 if (mode_string
!= NULL
)
1864 unsigned int old_mode_mask
= current_mode_mask
;
1867 for (p
= mode_string
; *p
!= 0; p
++)
1870 if (strcmp (mode_string
, "push") == 0)
1872 if (mode_history
== NULL
)
1873 mode_history
= xmalloc (MAX_HISTORY
* sizeof (*mode_history
));
1875 if (curr_hist
>= MAX_HISTORY
)
1876 as_bad (_(".machinemode stack overflow"));
1878 mode_history
[curr_hist
++] = current_mode_mask
;
1880 else if (strcmp (mode_string
, "pop") == 0)
1883 as_bad (_(".machinemode stack underflow"));
1885 current_mode_mask
= mode_history
[--curr_hist
];
1889 if (strcmp (mode_string
, "esa") == 0)
1890 current_mode_mask
= 1 << S390_OPCODE_ESA
;
1891 else if (strcmp (mode_string
, "zarch") == 0)
1893 if (s390_arch_size
== 32)
1894 set_highgprs_p
= TRUE
;
1895 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
1897 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
1898 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
1900 as_bad (_("invalid machine `%s'"), mode_string
);
1903 if (current_mode_mask
!= old_mode_mask
)
1904 s390_setup_opcodes ();
1907 demand_empty_rest_of_line ();
1911 md_atof (int type
, char *litp
, int *sizep
)
1913 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
1916 /* Align a section (I don't know why this is machine dependent). */
1919 md_section_align (asection
*seg
, valueT addr
)
1921 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1923 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1926 /* We don't have any form of relaxing. */
1929 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
1930 asection
*seg ATTRIBUTE_UNUSED
)
1936 /* Convert a machine dependent frag. We never generate these. */
1939 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1940 asection
*sec ATTRIBUTE_UNUSED
,
1941 fragS
*fragp ATTRIBUTE_UNUSED
)
1947 md_undefined_symbol (char *name
)
1949 if (*name
== '_' && *(name
+ 1) == 'G'
1950 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1954 if (symbol_find (name
))
1955 as_bad (_("GOT already in symbol table"));
1956 GOT_symbol
= symbol_new (name
, undefined_section
,
1957 (valueT
) 0, &zero_address_frag
);
1964 /* Functions concerning relocs. */
1966 /* The location from which a PC relative jump should be calculated,
1967 given a PC relative reloc. */
1970 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
1972 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1975 /* Here we decide which fixups can be adjusted to make them relative to
1976 the beginning of the section instead of the symbol. Basically we need
1977 to make sure that the dynamic relocations are done correctly, so in
1978 some cases we force the original symbol to be used. */
1980 tc_s390_fix_adjustable (fixS
*fixP
)
1982 /* Don't adjust references to merge sections. */
1983 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
1985 /* adjust_reloc_syms doesn't know about the GOT. */
1986 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
1987 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1988 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
1989 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
1990 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
1991 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
1992 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
1993 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1994 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
1995 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1996 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1997 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1998 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1999 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2000 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2001 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2002 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2003 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2004 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2005 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2006 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2007 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2008 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2009 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2010 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2011 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2012 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2013 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2014 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2015 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2016 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2017 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2018 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2019 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2020 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2021 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2022 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2023 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2024 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2025 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2026 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2027 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2028 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2029 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2030 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2031 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2032 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2037 /* Return true if we must always emit a reloc for a type and false if
2038 there is some hope of resolving it at assembly time. */
2040 tc_s390_force_relocation (struct fix
*fixp
)
2042 /* Ensure we emit a relocation for every reference to the global
2043 offset table or to the procedure link table. */
2044 switch (fixp
->fx_r_type
)
2046 case BFD_RELOC_390_GOT12
:
2047 case BFD_RELOC_390_GOT20
:
2048 case BFD_RELOC_32_GOT_PCREL
:
2049 case BFD_RELOC_32_GOTOFF
:
2050 case BFD_RELOC_390_GOTOFF64
:
2051 case BFD_RELOC_390_PLTOFF16
:
2052 case BFD_RELOC_390_PLTOFF32
:
2053 case BFD_RELOC_390_PLTOFF64
:
2054 case BFD_RELOC_390_GOTPC
:
2055 case BFD_RELOC_390_GOT16
:
2056 case BFD_RELOC_390_GOTPCDBL
:
2057 case BFD_RELOC_390_GOT64
:
2058 case BFD_RELOC_390_GOTENT
:
2059 case BFD_RELOC_390_PLT32
:
2060 case BFD_RELOC_390_PLT12DBL
:
2061 case BFD_RELOC_390_PLT16DBL
:
2062 case BFD_RELOC_390_PLT24DBL
:
2063 case BFD_RELOC_390_PLT32DBL
:
2064 case BFD_RELOC_390_PLT64
:
2065 case BFD_RELOC_390_GOTPLT12
:
2066 case BFD_RELOC_390_GOTPLT16
:
2067 case BFD_RELOC_390_GOTPLT20
:
2068 case BFD_RELOC_390_GOTPLT32
:
2069 case BFD_RELOC_390_GOTPLT64
:
2070 case BFD_RELOC_390_GOTPLTENT
:
2076 return generic_force_reloc (fixp
);
2079 /* Apply a fixup to the object code. This is called for all the
2080 fixups we generated by the call to fix_new_exp, above. In the call
2081 above we used a reloc code which was the largest legal reloc code
2082 plus the operand index. Here we undo that to recover the operand
2083 index. At this point all symbol values should be fully resolved,
2084 and we attempt to completely resolve the reloc. If we can not do
2085 that, we determine the correct reloc code and put it back in the
2089 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2092 valueT value
= *valP
;
2094 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2096 if (fixP
->fx_subsy
!= NULL
)
2097 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2098 _("cannot emit relocation %s against subsy symbol %s"),
2099 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2100 S_GET_NAME (fixP
->fx_subsy
));
2102 if (fixP
->fx_addsy
!= NULL
)
2105 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2110 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2112 const struct s390_operand
*operand
;
2115 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2116 operand
= &s390_operands
[opindex
];
2120 /* Insert the fully resolved operand value. */
2121 s390_insert_operand ((unsigned char *) where
, operand
,
2122 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2126 /* Determine a BFD reloc value based on the operand information.
2127 We are only prepared to turn a few of the operands into
2129 fixP
->fx_offset
= value
;
2130 if (operand
->bits
== 12 && operand
->shift
== 20)
2133 fixP
->fx_where
+= 2;
2134 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2136 else if (operand
->bits
== 12 && operand
->shift
== 36)
2139 fixP
->fx_where
+= 4;
2140 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2142 else if (operand
->bits
== 20 && operand
->shift
== 20)
2145 fixP
->fx_where
+= 2;
2146 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2148 else if (operand
->bits
== 8 && operand
->shift
== 8)
2151 fixP
->fx_where
+= 1;
2152 fixP
->fx_r_type
= BFD_RELOC_8
;
2154 else if (operand
->bits
== 12 && operand
->shift
== 12
2155 && (operand
->flags
& S390_OPERAND_PCREL
))
2158 fixP
->fx_where
+= 1;
2159 fixP
->fx_offset
+= 1;
2160 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2162 else if (operand
->bits
== 16 && operand
->shift
== 16)
2165 fixP
->fx_where
+= 2;
2166 if (operand
->flags
& S390_OPERAND_PCREL
)
2168 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2169 fixP
->fx_offset
+= 2;
2172 fixP
->fx_r_type
= BFD_RELOC_16
;
2174 else if (operand
->bits
== 24 && operand
->shift
== 24
2175 && (operand
->flags
& S390_OPERAND_PCREL
))
2178 fixP
->fx_where
+= 3;
2179 fixP
->fx_offset
+= 3;
2180 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2182 else if (operand
->bits
== 32 && operand
->shift
== 16
2183 && (operand
->flags
& S390_OPERAND_PCREL
))
2186 fixP
->fx_where
+= 2;
2187 fixP
->fx_offset
+= 2;
2188 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2195 /* Use expr_symbol_where to see if this is an expression
2197 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2198 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2199 _("unresolved expression that must be resolved"));
2201 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2202 _("unsupported relocation type"));
2209 switch (fixP
->fx_r_type
)
2215 md_number_to_chars (where
, value
, 1);
2217 case BFD_RELOC_390_12
:
2218 case BFD_RELOC_390_GOT12
:
2219 case BFD_RELOC_390_GOTPLT12
:
2220 case BFD_RELOC_390_PC12DBL
:
2221 case BFD_RELOC_390_PLT12DBL
:
2232 mop
= bfd_getb16 ((unsigned char *) where
);
2233 mop
|= (unsigned short) (value
& 0xfff);
2234 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2238 case BFD_RELOC_390_20
:
2239 case BFD_RELOC_390_GOT20
:
2240 case BFD_RELOC_390_GOTPLT20
:
2244 mop
= bfd_getb32 ((unsigned char *) where
);
2245 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2246 (value
& 0xff000) >> 12);
2247 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2252 case BFD_RELOC_GPREL16
:
2253 case BFD_RELOC_16_GOT_PCREL
:
2254 case BFD_RELOC_16_GOTOFF
:
2256 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2257 _("cannot emit PC relative %s relocation%s%s"),
2258 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2259 fixP
->fx_addsy
!= NULL
? " against " : "",
2260 (fixP
->fx_addsy
!= NULL
2261 ? S_GET_NAME (fixP
->fx_addsy
)
2264 md_number_to_chars (where
, value
, 2);
2266 case BFD_RELOC_390_GOT16
:
2267 case BFD_RELOC_390_PLTOFF16
:
2268 case BFD_RELOC_390_GOTPLT16
:
2270 md_number_to_chars (where
, value
, 2);
2272 case BFD_RELOC_390_PC16DBL
:
2273 case BFD_RELOC_390_PLT16DBL
:
2276 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2279 case BFD_RELOC_390_PC24DBL
:
2280 case BFD_RELOC_390_PLT24DBL
:
2287 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2288 mop
|= (unsigned int) (value
& 0xffffff);
2289 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2295 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2297 fixP
->fx_r_type
= BFD_RELOC_32
;
2299 md_number_to_chars (where
, value
, 4);
2301 case BFD_RELOC_32_PCREL
:
2302 case BFD_RELOC_32_BASEREL
:
2303 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2305 md_number_to_chars (where
, value
, 4);
2307 case BFD_RELOC_32_GOT_PCREL
:
2308 case BFD_RELOC_390_PLTOFF32
:
2309 case BFD_RELOC_390_PLT32
:
2310 case BFD_RELOC_390_GOTPLT32
:
2312 md_number_to_chars (where
, value
, 4);
2314 case BFD_RELOC_390_PC32DBL
:
2315 case BFD_RELOC_390_PLT32DBL
:
2316 case BFD_RELOC_390_GOTPCDBL
:
2317 case BFD_RELOC_390_GOTENT
:
2318 case BFD_RELOC_390_GOTPLTENT
:
2321 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2324 case BFD_RELOC_32_GOTOFF
:
2326 md_number_to_chars (where
, value
, sizeof (int));
2329 case BFD_RELOC_390_GOTOFF64
:
2331 md_number_to_chars (where
, value
, 8);
2334 case BFD_RELOC_390_GOT64
:
2335 case BFD_RELOC_390_PLTOFF64
:
2336 case BFD_RELOC_390_PLT64
:
2337 case BFD_RELOC_390_GOTPLT64
:
2339 md_number_to_chars (where
, value
, 8);
2344 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2346 fixP
->fx_r_type
= BFD_RELOC_64
;
2348 md_number_to_chars (where
, value
, 8);
2351 case BFD_RELOC_64_PCREL
:
2352 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2354 md_number_to_chars (where
, value
, 8);
2357 case BFD_RELOC_VTABLE_INHERIT
:
2358 case BFD_RELOC_VTABLE_ENTRY
:
2362 case BFD_RELOC_390_TLS_LOAD
:
2363 case BFD_RELOC_390_TLS_GDCALL
:
2364 case BFD_RELOC_390_TLS_LDCALL
:
2365 case BFD_RELOC_390_TLS_GD32
:
2366 case BFD_RELOC_390_TLS_GD64
:
2367 case BFD_RELOC_390_TLS_GOTIE12
:
2368 case BFD_RELOC_390_TLS_GOTIE20
:
2369 case BFD_RELOC_390_TLS_GOTIE32
:
2370 case BFD_RELOC_390_TLS_GOTIE64
:
2371 case BFD_RELOC_390_TLS_LDM32
:
2372 case BFD_RELOC_390_TLS_LDM64
:
2373 case BFD_RELOC_390_TLS_IE32
:
2374 case BFD_RELOC_390_TLS_IE64
:
2375 case BFD_RELOC_390_TLS_LE32
:
2376 case BFD_RELOC_390_TLS_LE64
:
2377 case BFD_RELOC_390_TLS_LDO32
:
2378 case BFD_RELOC_390_TLS_LDO64
:
2379 case BFD_RELOC_390_TLS_DTPMOD
:
2380 case BFD_RELOC_390_TLS_DTPOFF
:
2381 case BFD_RELOC_390_TLS_TPOFF
:
2382 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2383 /* Fully resolved at link time. */
2385 case BFD_RELOC_390_TLS_IEENT
:
2386 /* Fully resolved at link time. */
2387 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2393 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2395 if (reloc_name
!= NULL
)
2396 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2398 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2402 fixP
->fx_offset
= value
;
2406 /* Generate a reloc for a fixup. */
2409 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2411 bfd_reloc_code_real_type code
;
2414 code
= fixp
->fx_r_type
;
2415 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2417 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2418 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2419 code
= BFD_RELOC_390_GOTPC
;
2420 if (code
== BFD_RELOC_390_PC32DBL
)
2421 code
= BFD_RELOC_390_GOTPCDBL
;
2424 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2425 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2426 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2427 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2428 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2429 if (reloc
->howto
== NULL
)
2431 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2432 _("cannot represent relocation type %s"),
2433 bfd_get_reloc_code_name (code
));
2434 /* Set howto to a garbage value so that we can keep going. */
2435 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2436 gas_assert (reloc
->howto
!= NULL
);
2438 reloc
->addend
= fixp
->fx_offset
;
2444 s390_cfi_frame_initial_instructions (void)
2446 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2450 tc_s390_regname_to_dw2regnum (char *regname
)
2454 if (regname
[0] != 'c' && regname
[0] != 'a')
2456 regnum
= reg_name_search (regname
);
2457 if (regname
[0] == 'f' && regnum
!= -1)
2460 else if (strcmp (regname
, "ap") == 0)
2462 else if (strcmp (regname
, "cc") == 0)
2468 s390_elf_final_processing (void)
2471 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;