1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2017 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 const 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 /* All facilities are enabled by default. */
45 static unsigned int current_flags
= S390_INSTR_FLAG_FACILITY_MASK
;
46 /* The mode mask default is picked in init_default_arch depending on
48 static unsigned int current_mode_mask
= 0;
50 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
51 for the output file. */
52 static bfd_boolean set_highgprs_p
= FALSE
;
54 /* Whether to use user friendly register names. Default is TRUE. */
55 #ifndef TARGET_REG_NAMES_P
56 #define TARGET_REG_NAMES_P TRUE
59 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
61 /* Set to TRUE if we want to warn about zero base/index registers. */
62 static bfd_boolean warn_areg_zero
= FALSE
;
64 /* Generic assembler global variables which must be defined by all
67 const char comment_chars
[] = "#";
69 /* Characters which start a comment at the beginning of a line. */
70 const char line_comment_chars
[] = "#";
72 /* Characters which may be used to separate multiple commands on a
74 const char line_separator_chars
[] = ";";
76 /* Characters which are used to indicate an exponent in a floating
78 const char EXP_CHARS
[] = "eE";
80 /* Characters which mean that a number is a floating point constant,
82 const char FLT_CHARS
[] = "dD";
84 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
85 int s390_cie_data_alignment
;
87 /* The target specific pseudo-ops which we support. */
89 /* Define the prototypes for the pseudo-ops */
90 static void s390_byte (int);
91 static void s390_elf_cons (int);
92 static void s390_bss (int);
93 static void s390_insn (int);
94 static void s390_literals (int);
95 static void s390_machine (int);
96 static void s390_machinemode (int);
98 const pseudo_typeS md_pseudo_table
[] =
100 { "align", s_align_bytes
, 0 },
101 /* Pseudo-ops which must be defined. */
102 { "bss", s390_bss
, 0 },
103 { "insn", s390_insn
, 0 },
104 /* Pseudo-ops which must be overridden. */
105 { "byte", s390_byte
, 0 },
106 { "short", s390_elf_cons
, 2 },
107 { "long", s390_elf_cons
, 4 },
108 { "quad", s390_elf_cons
, 8 },
109 { "ltorg", s390_literals
, 0 },
110 { "string", stringer
, 8 + 1 },
111 { "machine", s390_machine
, 0 },
112 { "machinemode", s390_machinemode
, 0 },
116 /* Given NAME, find the register number associated with that name, return
117 the integer value associated with the given name or -1 on failure. */
120 reg_name_search (const char *name
)
124 if (strcasecmp (name
, "lit") == 0)
127 if (strcasecmp (name
, "sp") == 0)
130 if (name
[0] != 'a' && name
[0] != 'c' && name
[0] != 'f'
131 && name
[0] != 'r' && name
[0] != 'v')
134 if (ISDIGIT (name
[1]))
137 if (ISDIGIT (name
[2]))
138 val
= val
* 10 + name
[2] - '0';
141 if ((name
[0] != 'v' && val
> 15) || val
> 31)
149 * Summary of register_name().
151 * in: Input_line_pointer points to 1st char of operand.
153 * out: A expressionS.
154 * The operand may have been a register: in this case, X_op == O_register,
155 * X_add_number is set to the register number, and truth is returned.
156 * Input_line_pointer->(next non-blank) char after operand, or is in its
161 register_name (expressionS
*expressionP
)
168 /* Find the spelling of the operand. */
169 start
= name
= input_line_pointer
;
170 if (name
[0] == '%' && ISALPHA (name
[1]))
171 name
= ++input_line_pointer
;
175 c
= get_symbol_name (&name
);
176 reg_number
= reg_name_search (name
);
178 /* Put back the delimiting char. */
179 (void) restore_line_pointer (c
);
181 /* Look to see if it's in the register table. */
184 expressionP
->X_op
= O_register
;
185 expressionP
->X_add_number
= reg_number
;
187 /* Make the rest nice. */
188 expressionP
->X_add_symbol
= NULL
;
189 expressionP
->X_op_symbol
= NULL
;
193 /* Reset the line as if we had not done anything. */
194 input_line_pointer
= start
;
198 /* Local variables. */
200 /* Opformat hash table. */
201 static struct hash_control
*s390_opformat_hash
;
203 /* Opcode hash table. */
204 static struct hash_control
*s390_opcode_hash
= NULL
;
206 /* Flags to set in the elf header */
207 static flagword s390_flags
= 0;
209 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
211 #ifndef WORKING_DOT_WORD
212 int md_short_jump_size
= 4;
213 int md_long_jump_size
= 4;
216 const char *md_shortopts
= "A:m:kVQ:";
217 struct option md_longopts
[] = {
218 {NULL
, no_argument
, NULL
, 0}
220 size_t md_longopts_size
= sizeof (md_longopts
);
222 /* Initialize the default opcode arch and word size from the default
223 architecture name if not specified by an option. */
225 init_default_arch (void)
227 if (strcmp (default_arch
, "s390") == 0)
229 if (s390_arch_size
== 0)
232 else if (strcmp (default_arch
, "s390x") == 0)
234 if (s390_arch_size
== 0)
238 as_fatal (_("Invalid default architecture, broken assembler."));
240 if (current_mode_mask
== 0)
242 /* Default to z/Architecture mode if the CPU supports it. */
243 if (current_cpu
< S390_OPCODE_Z900
)
244 current_mode_mask
= 1 << S390_OPCODE_ESA
;
246 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
250 /* Called by TARGET_FORMAT. */
252 s390_target_format (void)
254 /* We don't get a chance to initialize anything before we're called,
255 so handle that now. */
256 init_default_arch ();
258 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
261 /* Map a cpu string ARG as given with -march= or .machine to the respective
262 enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name
263 can be followed by a list of cpu facility flags each beginning with the
264 character '+'. The active cpu flags are returned through *RET_FLAGS.
265 In case of an error, S390_OPCODE_MAXCPU is returned. */
268 s390_parse_cpu (const char * arg
,
269 unsigned int * ret_flags
,
270 bfd_boolean allow_extensions
)
275 unsigned int name_len
;
276 const char * alt_name
;
277 unsigned int alt_name_len
;
279 } cpu_table
[S390_OPCODE_MAXCPU
] =
281 { STRING_COMMA_LEN ("g5"), STRING_COMMA_LEN ("arch3"), 0 },
282 { STRING_COMMA_LEN ("g6"), STRING_COMMA_LEN (""), 0 },
283 { STRING_COMMA_LEN ("z900"), STRING_COMMA_LEN ("arch5"), 0 },
284 { STRING_COMMA_LEN ("z990"), STRING_COMMA_LEN ("arch6"), 0 },
285 { STRING_COMMA_LEN ("z9-109"), STRING_COMMA_LEN (""), 0 },
286 { STRING_COMMA_LEN ("z9-ec"), STRING_COMMA_LEN ("arch7"), 0 },
287 { STRING_COMMA_LEN ("z10"), STRING_COMMA_LEN ("arch8"), 0 },
288 { STRING_COMMA_LEN ("z196"), STRING_COMMA_LEN ("arch9"), 0 },
289 { STRING_COMMA_LEN ("zEC12"), STRING_COMMA_LEN ("arch10"),
290 S390_INSTR_FLAG_HTM
},
291 { STRING_COMMA_LEN ("z13"), STRING_COMMA_LEN ("arch11"),
292 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
293 { STRING_COMMA_LEN ("arch12"), STRING_COMMA_LEN (""),
294 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
}
303 { "htm", S390_INSTR_FLAG_HTM
, TRUE
},
304 { "nohtm", S390_INSTR_FLAG_HTM
, FALSE
},
305 { "vx", S390_INSTR_FLAG_VX
, TRUE
},
306 { "novx", S390_INSTR_FLAG_VX
, FALSE
}
311 icpu
= S390_OPCODE_MAXCPU
;
312 if (strncmp (arg
, "all", 3) == 0 && (arg
[3] == 0 || arg
[3] == '+'))
314 icpu
= S390_OPCODE_MAXCPU
- 1;
319 for (icpu
= 0; icpu
< S390_OPCODE_MAXCPU
; icpu
++)
321 unsigned int l
, l_alt
;
323 l
= cpu_table
[icpu
].name_len
;
325 if (strncmp (arg
, cpu_table
[icpu
].name
, l
) == 0
326 && (arg
[l
] == 0 || arg
[l
] == '+'))
332 l_alt
= cpu_table
[icpu
].alt_name_len
;
335 && strncmp (arg
, cpu_table
[icpu
].alt_name
, l_alt
) == 0
336 && (arg
[l_alt
] == 0 || arg
[l_alt
] == '+'))
344 if (icpu
== S390_OPCODE_MAXCPU
)
345 return S390_OPCODE_MAXCPU
;
347 ilp_bak
= input_line_pointer
;
348 if (icpu
!= S390_OPCODE_MAXCPU
)
350 input_line_pointer
= (char *) arg
;
351 *ret_flags
= (cpu_table
[icpu
].flags
& S390_INSTR_FLAG_FACILITY_MASK
);
353 while (*input_line_pointer
== '+' && allow_extensions
)
359 input_line_pointer
++;
360 c
= get_symbol_name (&sym
);
361 for (iflag
= 0; iflag
< ARRAY_SIZE (cpu_flags
); iflag
++)
363 if (strcmp (sym
, cpu_flags
[iflag
].name
) == 0)
365 if (cpu_flags
[iflag
].on
)
366 *ret_flags
|= cpu_flags
[iflag
].mask
;
368 *ret_flags
&= ~cpu_flags
[iflag
].mask
;
372 if (iflag
== ARRAY_SIZE (cpu_flags
))
373 as_bad (_("no such machine extension `%s'"), sym
- 1);
374 *input_line_pointer
= c
;
375 if (iflag
== ARRAY_SIZE (cpu_flags
))
382 if (*input_line_pointer
!= 0 && *input_line_pointer
!= '\n')
384 as_bad (_("junk at end of machine string, first unrecognized character"
385 " is `%c'"), *input_line_pointer
);
386 icpu
= S390_OPCODE_MAXCPU
;
388 input_line_pointer
= ilp_bak
;
394 md_parse_option (int c
, const char *arg
)
398 /* -k: Ignore for FreeBSD compatibility. */
402 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
405 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
408 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
409 warn_areg_zero
= TRUE
;
411 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
414 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
417 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
418 current_mode_mask
= 1 << S390_OPCODE_ESA
;
420 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
422 if (s390_arch_size
== 32)
423 set_highgprs_p
= TRUE
;
424 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
427 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
429 current_cpu
= s390_parse_cpu (arg
+ 5, ¤t_flags
, FALSE
);
430 if (current_cpu
== S390_OPCODE_MAXCPU
)
432 as_bad (_("invalid switch -m%s"), arg
);
439 as_bad (_("invalid switch -m%s"), arg
);
445 /* Option -A is deprecated. Still available for compatibility. */
446 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
447 current_cpu
= S390_OPCODE_G5
;
448 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
449 current_cpu
= S390_OPCODE_Z900
;
451 as_bad (_("invalid architecture -A%s"), arg
);
454 /* -V: SVR4 argument to print version ID. */
459 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
460 should be emitted or not. FIXME: Not implemented. */
472 md_show_usage (FILE *stream
)
474 fprintf (stream
, _("\
476 -mregnames Allow symbolic names for registers\n\
477 -mwarn-areg-zero Warn about zero base/index registers\n\
478 -mno-regnames Do not allow symbolic names for registers\n\
479 -m31 Set file format to 31 bit format\n\
480 -m64 Set file format to 64 bit format\n"));
481 fprintf (stream
, _("\
482 -V print assembler version number\n\
483 -Qy, -Qn ignored\n"));
486 /* Generate the hash table mapping mnemonics to struct s390_opcode.
487 This table is built at startup and whenever the CPU level is
488 changed using .machine. */
491 s390_setup_opcodes (void)
493 const struct s390_opcode
*op
;
494 const struct s390_opcode
*op_end
;
495 bfd_boolean dup_insn
= FALSE
;
498 if (s390_opcode_hash
!= NULL
)
499 hash_die (s390_opcode_hash
);
501 /* Insert the opcodes into a hash table. */
502 s390_opcode_hash
= hash_new ();
504 op_end
= s390_opcodes
+ s390_num_opcodes
;
505 for (op
= s390_opcodes
; op
< op_end
; op
++)
509 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
511 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
516 if ((op
->modes
& current_mode_mask
) == 0)
518 else if ((op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
) == 0)
520 /* Opcodes that do not belong to a specific facility are enabled if
521 present in the selected cpu. */
522 use_opcode
= (op
->min_cpu
<= current_cpu
);
528 /* Opcodes of a specific facility are enabled if the facility is
529 enabled. Note: only some facilities are represented as flags. */
530 f
= (op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
);
531 use_opcode
= ((f
& current_flags
) == f
);
535 retval
= hash_insert (s390_opcode_hash
, op
->name
, (void *) op
);
536 if (retval
!= (const char *) NULL
)
538 as_bad (_("Internal assembler error for instruction %s"),
544 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
552 /* This function is called when the assembler starts up. It is called
553 after the options have been parsed and the output file has been
559 const struct s390_opcode
*op
;
560 const struct s390_opcode
*op_end
;
563 /* Give a warning if the combination -m64-bit and -Aesa is used. */
564 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
565 as_warn (_("The 64 bit file format is used without esame instructions."));
567 s390_cie_data_alignment
= -s390_arch_size
/ 8;
569 /* Set the ELF flags if desired. */
571 bfd_set_private_flags (stdoutput
, s390_flags
);
573 /* Insert the opcode formats into a hash table. */
574 s390_opformat_hash
= hash_new ();
576 op_end
= s390_opformats
+ s390_num_opformats
;
577 for (op
= s390_opformats
; op
< op_end
; op
++)
579 retval
= hash_insert (s390_opformat_hash
, op
->name
, (void *) op
);
580 if (retval
!= (const char *) NULL
)
581 as_bad (_("Internal assembler error for instruction format %s"),
585 s390_setup_opcodes ();
587 record_alignment (text_section
, 2);
588 record_alignment (data_section
, 2);
589 record_alignment (bss_section
, 2);
592 /* Called after all assembly has been done. */
596 if (s390_arch_size
== 64)
597 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
599 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
602 /* Insert an operand value into an instruction. */
605 s390_insert_operand (unsigned char *insn
,
606 const struct s390_operand
*operand
,
614 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
618 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
619 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
620 /* Halve PCREL operands. */
621 if (operand
->flags
& S390_OPERAND_PCREL
)
623 /* Check for underflow / overflow. */
624 if (val
< min
|| val
> max
)
627 _("operand out of range (%s not between %ld and %ld)");
630 if (operand
->flags
& S390_OPERAND_PCREL
)
636 sprint_value (buf
, val
);
637 if (file
== (char *) NULL
)
638 as_bad (err
, buf
, (int) min
, (int) max
);
640 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
643 /* val is ok, now restrict it to operand->bits bits. */
644 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
645 /* val is restrict, now check for special case. */
646 if (operand
->bits
== 20 && operand
->shift
== 20)
647 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
653 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
655 uval
= (addressT
) val
;
657 /* Vector register operands have an additional bit in the RXB
659 if (operand
->flags
& S390_OPERAND_VR
)
660 max
= (max
<< 1) | 1;
662 /* Length x in an instructions has real length x+1. */
663 if (operand
->flags
& S390_OPERAND_LENGTH
)
665 /* Check for underflow / overflow. */
666 if (uval
< min
|| uval
> max
)
668 if (operand
->flags
& S390_OPERAND_LENGTH
)
675 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
681 if (operand
->flags
& S390_OPERAND_VR
)
683 /* Insert the extra bit into the RXB field. */
684 switch (operand
->shift
)
687 insn
[4] |= (uval
& 0x10) >> 1;
690 insn
[4] |= (uval
& 0x10) >> 2;
693 insn
[4] |= (uval
& 0x10) >> 3;
696 insn
[4] |= (uval
& 0x10) >> 4;
702 if (operand
->flags
& S390_OPERAND_OR1
)
704 if (operand
->flags
& S390_OPERAND_OR2
)
706 if (operand
->flags
& S390_OPERAND_OR8
)
709 /* Duplicate the operand at bit pos 12 to 16. */
710 if (operand
->flags
& S390_OPERAND_CP16
)
712 /* Copy VR operand at bit pos 12 to bit pos 16. */
713 insn
[2] |= uval
<< 4;
714 /* Copy the flag in the RXB field. */
715 insn
[4] |= (insn
[4] & 4) >> 1;
718 /* Insert fragments of the operand byte for byte. */
719 offset
= operand
->shift
+ operand
->bits
;
720 uval
<<= (-offset
) & 7;
721 insn
+= (offset
- 1) / 8;
733 bfd_reloc_code_real_type reloc
;
736 /* Parse tls marker and return the desired relocation. */
737 static bfd_reloc_code_real_type
738 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
740 static struct map_tls mapping
[] =
742 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
743 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
744 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
745 { NULL
, 0, BFD_RELOC_UNUSED
}
755 return BFD_RELOC_UNUSED
;
758 while (ISIDNUM (*str
))
762 return BFD_RELOC_UNUSED
;
764 orig_line
= input_line_pointer
;
765 input_line_pointer
= str
;
767 str
= input_line_pointer
;
768 if (&input_line_pointer
!= str_p
)
769 input_line_pointer
= orig_line
;
771 if (exp_p
->X_op
!= O_symbol
)
772 return BFD_RELOC_UNUSED
;
774 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
775 if (len
== ptr
->length
776 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
778 /* Found a matching tls suffix. */
782 return BFD_RELOC_UNUSED
;
785 /* Structure used to hold suffixes. */
796 ELF_SUFFIX_TLS_GOTIE
,
808 elf_suffix_type suffix
;
812 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
813 static elf_suffix_type
814 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
816 static struct map_bfd mapping
[] =
818 { "got", 3, ELF_SUFFIX_GOT
},
819 { "got12", 5, ELF_SUFFIX_GOT
},
820 { "plt", 3, ELF_SUFFIX_PLT
},
821 { "gotent", 6, ELF_SUFFIX_GOTENT
},
822 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
823 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
824 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
825 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
826 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
827 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
828 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
829 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
830 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
831 { NULL
, 0, ELF_SUFFIX_NONE
}
840 return ELF_SUFFIX_NONE
;
843 while (ISALNUM (*str
))
847 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
848 if (len
== ptr
->length
849 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
851 if (exp_p
->X_add_number
!= 0)
852 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
853 ptr
->string
, ptr
->string
);
854 /* Now check for identifier@suffix+constant. */
855 if (*str
== '-' || *str
== '+')
857 char *orig_line
= input_line_pointer
;
860 input_line_pointer
= str
;
861 expression (&new_exp
);
863 switch (new_exp
.X_op
)
865 case O_constant
: /* X_add_number (a constant expression). */
866 exp_p
->X_add_number
+= new_exp
.X_add_number
;
867 str
= input_line_pointer
;
869 case O_symbol
: /* X_add_symbol + X_add_number. */
870 /* this case is used for e.g. xyz@PLT+.Label. */
871 exp_p
->X_add_number
+= new_exp
.X_add_number
;
872 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
874 str
= input_line_pointer
;
876 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
877 /* this case is used for e.g. xyz@PLT-.Label. */
878 exp_p
->X_add_number
+= new_exp
.X_add_number
;
879 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
880 exp_p
->X_op
= O_subtract
;
881 str
= input_line_pointer
;
887 /* If s390_elf_suffix has not been called with
888 &input_line_pointer as first parameter, we have
889 clobbered the input_line_pointer. We have to
891 if (&input_line_pointer
!= str_p
)
892 input_line_pointer
= orig_line
;
898 return BFD_RELOC_UNUSED
;
901 /* Structure used to hold a literal pool entry. */
904 struct s390_lpe
*next
;
906 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
907 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
909 bfd_reloc_code_real_type reloc
;
913 static struct s390_lpe
*lpe_free_list
= NULL
;
914 static struct s390_lpe
*lpe_list
= NULL
;
915 static struct s390_lpe
*lpe_list_tail
= NULL
;
916 static symbolS
*lp_sym
= NULL
;
917 static int lp_count
= 0;
918 static int lpe_count
= 0;
921 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
923 if (exp1
->X_op
!= exp2
->X_op
)
928 case O_constant
: /* X_add_number must be equal. */
930 return exp1
->X_add_number
== exp2
->X_add_number
;
933 as_bad (_("Can't handle O_big in s390_exp_compare"));
936 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
941 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
942 && (exp1
->X_add_number
== exp2
->X_add_number
);
944 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
949 case O_bit_inclusive_or
:
951 case O_bit_exclusive_or
:
963 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
964 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
965 && (exp1
->X_add_number
== exp2
->X_add_number
);
971 /* Test for @lit and if it's present make an entry in the literal pool and
972 modify the current expression to be an offset into the literal pool. */
973 static elf_suffix_type
974 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
976 bfd_reloc_code_real_type reloc
;
980 struct s390_lpe
*lpe
;
984 return suffix
; /* No modification. */
986 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
988 while (ISALNUM (*str
))
991 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
992 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
993 return suffix
; /* no modification */
994 nbytes
= ident
[3] - '0';
996 reloc
= BFD_RELOC_UNUSED
;
997 if (suffix
== ELF_SUFFIX_GOT
)
1000 reloc
= BFD_RELOC_390_GOT16
;
1001 else if (nbytes
== 4)
1002 reloc
= BFD_RELOC_32_GOT_PCREL
;
1003 else if (nbytes
== 8)
1004 reloc
= BFD_RELOC_390_GOT64
;
1006 else if (suffix
== ELF_SUFFIX_PLT
)
1009 reloc
= BFD_RELOC_390_PLT32
;
1010 else if (nbytes
== 8)
1011 reloc
= BFD_RELOC_390_PLT64
;
1014 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1015 as_bad (_("Invalid suffix for literal pool entry"));
1017 /* Search the pool if the new entry is a duplicate. */
1018 if (exp_p
->X_op
== O_big
)
1020 /* Special processing for big numbers. */
1021 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1023 if (lpe
->ex
.X_op
== O_big
)
1025 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
1027 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
1028 sizeof (FLONUM_TYPE
)) == 0)
1031 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
1033 if (memcmp (generic_bignum
, lpe
->bignum
,
1034 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
1042 /* Processing for 'normal' data types. */
1043 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1044 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
1045 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
1051 /* A new literal. */
1052 if (lpe_free_list
!= NULL
)
1054 lpe
= lpe_free_list
;
1055 lpe_free_list
= lpe_free_list
->next
;
1059 lpe
= XNEW (struct s390_lpe
);
1064 if (exp_p
->X_op
== O_big
)
1066 if (exp_p
->X_add_number
<= 0)
1067 lpe
->floatnum
= generic_floating_point_number
;
1068 else if (exp_p
->X_add_number
<= 4)
1069 memcpy (lpe
->bignum
, generic_bignum
,
1070 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1072 as_bad (_("Big number is too big"));
1075 lpe
->nbytes
= nbytes
;
1077 /* Literal pool name defined ? */
1080 sprintf (tmp_name
, ".L\001%i", lp_count
);
1081 lp_sym
= symbol_make (tmp_name
);
1084 /* Make name for literal pool entry. */
1085 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1087 lpe
->sym
= symbol_make (tmp_name
);
1089 /* Add to literal pool list. */
1091 if (lpe_list_tail
!= NULL
)
1093 lpe_list_tail
->next
= lpe
;
1094 lpe_list_tail
= lpe
;
1097 lpe_list
= lpe_list_tail
= lpe
;
1100 /* Now change exp_p to the offset into the literal pool.
1101 That's the expression: .L^Ax^By-.L^Ax */
1102 exp_p
->X_add_symbol
= lpe
->sym
;
1103 exp_p
->X_op_symbol
= lp_sym
;
1104 exp_p
->X_op
= O_subtract
;
1105 exp_p
->X_add_number
= 0;
1109 /* We change the suffix type to ELF_SUFFIX_NONE, because
1110 the difference of two local labels is just a number. */
1111 return ELF_SUFFIX_NONE
;
1114 /* Like normal .long/.short/.word, except support @got, etc.
1115 clobbers input_line_pointer, checks end-of-line. */
1117 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
1120 elf_suffix_type suffix
;
1122 if (is_it_end_of_statement ())
1124 demand_empty_rest_of_line ();
1132 if (exp
.X_op
== O_symbol
1133 && *input_line_pointer
== '@'
1134 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1136 bfd_reloc_code_real_type reloc
;
1137 reloc_howto_type
*reloc_howto
;
1143 static bfd_reloc_code_real_type tab2
[] =
1145 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1146 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1147 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1148 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1149 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1150 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1151 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1152 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1153 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1154 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1155 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1156 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1157 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1159 reloc
= tab2
[suffix
];
1161 else if (nbytes
== 4)
1163 static bfd_reloc_code_real_type tab4
[] =
1165 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1166 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1167 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1168 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1169 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1170 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1171 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1172 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1173 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1174 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1175 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1176 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1177 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1179 reloc
= tab4
[suffix
];
1181 else if (nbytes
== 8)
1183 static bfd_reloc_code_real_type tab8
[] =
1185 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1186 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1187 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1188 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1189 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1190 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1191 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1192 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1193 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1194 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1195 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1196 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1197 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1199 reloc
= tab8
[suffix
];
1202 reloc
= BFD_RELOC_UNUSED
;
1204 if (reloc
!= BFD_RELOC_UNUSED
1205 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1207 size
= bfd_get_reloc_size (reloc_howto
);
1209 as_bad (_("%s relocations do not fit in %d bytes"),
1210 reloc_howto
->name
, nbytes
);
1211 where
= frag_more (nbytes
);
1212 md_number_to_chars (where
, 0, size
);
1213 /* To make fixup_segment do the pc relative conversion the
1214 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1215 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1216 size
, &exp
, FALSE
, reloc
);
1219 as_bad (_("relocation not applicable"));
1222 emit_expr (&exp
, (unsigned int) nbytes
);
1224 while (*input_line_pointer
++ == ',');
1226 input_line_pointer
--; /* Put terminator back into stream. */
1227 demand_empty_rest_of_line ();
1230 /* We need to keep a list of fixups. We can't simply generate them as
1231 we go, because that would require us to first create the frag, and
1232 that would screw up references to ``.''. */
1238 bfd_reloc_code_real_type reloc
;
1241 #define MAX_INSN_FIXUPS (4)
1243 /* This routine is called for each instruction to be assembled. */
1246 md_gather_operands (char *str
,
1247 unsigned char *insn
,
1248 const struct s390_opcode
*opcode
)
1250 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1251 const struct s390_operand
*operand
;
1252 const unsigned char *opindex_ptr
;
1254 elf_suffix_type suffix
;
1255 bfd_reloc_code_real_type reloc
;
1260 while (ISSPACE (*str
))
1265 /* Gather the operands. */
1267 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1271 operand
= s390_operands
+ *opindex_ptr
;
1273 if ((opcode
->flags
& (S390_INSTR_FLAG_OPTPARM
| S390_INSTR_FLAG_OPTPARM2
))
1276 /* Optional parameters might need to be ORed with a
1277 value so calling s390_insert_operand is needed. */
1278 s390_insert_operand (insn
, operand
, 0, NULL
, 0);
1282 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1284 /* We do an early skip. For D(X,B) constructions the index
1285 register is skipped (X is optional). For D(L,B) the base
1286 register will be the skipped operand, because L is NOT
1292 /* Gather the operand. */
1293 hold
= input_line_pointer
;
1294 input_line_pointer
= str
;
1296 /* Parse the operand. */
1297 if (! register_name (&ex
))
1300 str
= input_line_pointer
;
1301 input_line_pointer
= hold
;
1303 /* Write the operand to the insn. */
1304 if (ex
.X_op
== O_illegal
)
1305 as_bad (_("illegal operand"));
1306 else if (ex
.X_op
== O_absent
)
1308 if (opindex_ptr
[0] == '\0')
1310 as_bad (_("missing operand"));
1312 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1314 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1316 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1318 /* We need to generate a fixup for the
1319 expression returned by s390_lit_suffix. */
1320 if (fc
>= MAX_INSN_FIXUPS
)
1321 as_fatal (_("too many fixups"));
1322 fixups
[fc
].exp
= ex
;
1323 fixups
[fc
].opindex
= *opindex_ptr
;
1324 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1329 if ((operand
->flags
& S390_OPERAND_LENGTH
)
1330 && ex
.X_op
!= O_constant
)
1331 as_fatal (_("invalid length field specified"));
1332 if ((operand
->flags
& S390_OPERAND_INDEX
)
1333 && ex
.X_add_number
== 0
1335 as_warn (_("index register specified but zero"));
1336 if ((operand
->flags
& S390_OPERAND_BASE
)
1337 && ex
.X_add_number
== 0
1339 as_warn (_("base register specified but zero"));
1340 if ((operand
->flags
& S390_OPERAND_GPR
)
1341 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1342 && (ex
.X_add_number
& 1))
1343 as_fatal (_("odd numbered general purpose register specified as "
1345 if ((operand
->flags
& S390_OPERAND_FPR
)
1346 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1347 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1348 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1349 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1350 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1351 as_fatal (_("invalid floating point register pair. Valid fp "
1352 "register pair operands are 0, 1, 4, 5, 8, 9, "
1354 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1359 suffix
= s390_elf_suffix (&str
, &ex
);
1360 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1361 reloc
= BFD_RELOC_UNUSED
;
1363 if (suffix
== ELF_SUFFIX_GOT
)
1365 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1366 (operand
->bits
== 12))
1367 reloc
= BFD_RELOC_390_GOT12
;
1368 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1369 (operand
->bits
== 20))
1370 reloc
= BFD_RELOC_390_GOT20
;
1371 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1372 && (operand
->bits
== 16))
1373 reloc
= BFD_RELOC_390_GOT16
;
1374 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1375 && (operand
->bits
== 32))
1376 reloc
= BFD_RELOC_390_GOTENT
;
1378 else if (suffix
== ELF_SUFFIX_PLT
)
1380 if ((operand
->flags
& S390_OPERAND_PCREL
)
1381 && (operand
->bits
== 12))
1382 reloc
= BFD_RELOC_390_PLT12DBL
;
1383 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1384 && (operand
->bits
== 16))
1385 reloc
= BFD_RELOC_390_PLT16DBL
;
1386 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1387 && (operand
->bits
== 24))
1388 reloc
= BFD_RELOC_390_PLT24DBL
;
1389 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1390 && (operand
->bits
== 32))
1391 reloc
= BFD_RELOC_390_PLT32DBL
;
1393 else if (suffix
== ELF_SUFFIX_GOTENT
)
1395 if ((operand
->flags
& S390_OPERAND_PCREL
)
1396 && (operand
->bits
== 32))
1397 reloc
= BFD_RELOC_390_GOTENT
;
1399 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1401 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1402 && (operand
->bits
== 16))
1403 reloc
= BFD_RELOC_16_GOTOFF
;
1405 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1407 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1408 && (operand
->bits
== 16))
1409 reloc
= BFD_RELOC_390_PLTOFF16
;
1411 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1413 if ((operand
->flags
& S390_OPERAND_DISP
)
1414 && (operand
->bits
== 12))
1415 reloc
= BFD_RELOC_390_GOTPLT12
;
1416 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1417 && (operand
->bits
== 16))
1418 reloc
= BFD_RELOC_390_GOTPLT16
;
1419 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1420 && (operand
->bits
== 32))
1421 reloc
= BFD_RELOC_390_GOTPLTENT
;
1423 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1425 if ((operand
->flags
& S390_OPERAND_DISP
)
1426 && (operand
->bits
== 12))
1427 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1428 else if ((operand
->flags
& S390_OPERAND_DISP
)
1429 && (operand
->bits
== 20))
1430 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1432 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1434 if ((operand
->flags
& S390_OPERAND_PCREL
)
1435 && (operand
->bits
== 32))
1436 reloc
= BFD_RELOC_390_TLS_IEENT
;
1439 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1440 as_bad (_("invalid operand suffix"));
1441 /* We need to generate a fixup of type 'reloc' for this
1443 if (fc
>= MAX_INSN_FIXUPS
)
1444 as_fatal (_("too many fixups"));
1445 fixups
[fc
].exp
= ex
;
1446 fixups
[fc
].opindex
= *opindex_ptr
;
1447 fixups
[fc
].reloc
= reloc
;
1451 /* Check the next character. The call to expression has advanced
1452 str past any whitespace. */
1453 if (operand
->flags
& S390_OPERAND_DISP
)
1455 /* After a displacement a block in parentheses can start. */
1458 /* Check if parenthesized block can be skipped. If the next
1459 operand is neither an optional operand nor a base register
1460 then we have a syntax error. */
1461 operand
= s390_operands
+ *(++opindex_ptr
);
1462 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1463 as_bad (_("syntax error; missing '(' after displacement"));
1465 /* Ok, skip all operands until S390_OPERAND_BASE. */
1466 while (!(operand
->flags
& S390_OPERAND_BASE
))
1467 operand
= s390_operands
+ *(++opindex_ptr
);
1469 /* If there is a next operand it must be separated by a comma. */
1470 if (opindex_ptr
[1] != '\0')
1474 while (opindex_ptr
[1] != '\0')
1476 operand
= s390_operands
+ *(++opindex_ptr
);
1477 as_bad (_("syntax error; expected ','"));
1487 /* We found an opening parentheses. */
1489 for (f
= str
; *f
!= '\0'; f
++)
1490 if (*f
== ',' || *f
== ')')
1492 /* If there is no comma until the closing parentheses OR
1493 there is a comma right after the opening parentheses,
1494 we have to skip optional operands. */
1495 if (*f
== ',' && f
== str
)
1497 /* comma directly after '(' ? */
1502 skip_optional
= (*f
!= ',');
1505 else if (operand
->flags
& S390_OPERAND_BASE
)
1507 /* After the base register the parenthesised block ends. */
1509 as_bad (_("syntax error; missing ')' after base register"));
1511 /* If there is a next operand it must be separated by a comma. */
1512 if (opindex_ptr
[1] != '\0')
1516 while (opindex_ptr
[1] != '\0')
1518 operand
= s390_operands
+ *(++opindex_ptr
);
1519 as_bad (_("syntax error; expected ','"));
1529 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1530 of D(L,B). In this case the base register has to be skipped. */
1533 operand
= s390_operands
+ *(++opindex_ptr
);
1535 if (!(operand
->flags
& S390_OPERAND_BASE
))
1536 as_bad (_("syntax error; ')' not allowed here"));
1540 if ((opcode
->flags
& (S390_INSTR_FLAG_OPTPARM
1541 | S390_INSTR_FLAG_OPTPARM2
))
1542 && opindex_ptr
[1] != '\0'
1543 && opindex_ptr
[2] == '\0'
1547 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM2
)
1548 && opindex_ptr
[1] != '\0'
1549 && opindex_ptr
[2] != '\0'
1550 && opindex_ptr
[3] == '\0'
1554 /* If there is a next operand it must be separated by a comma. */
1555 if (opindex_ptr
[1] != '\0')
1559 while (opindex_ptr
[1] != '\0')
1561 operand
= s390_operands
+ *(++opindex_ptr
);
1562 as_bad (_("syntax error; expected ','"));
1572 while (ISSPACE (*str
))
1575 /* Check for tls instruction marker. */
1576 reloc
= s390_tls_suffix (&str
, &ex
);
1577 if (reloc
!= BFD_RELOC_UNUSED
)
1579 /* We need to generate a fixup of type 'reloc' for this
1581 if (fc
>= MAX_INSN_FIXUPS
)
1582 as_fatal (_("too many fixups"));
1583 fixups
[fc
].exp
= ex
;
1584 fixups
[fc
].opindex
= -1;
1585 fixups
[fc
].reloc
= reloc
;
1593 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1595 as_bad (_("junk at end of line: `%s'"), str
);
1596 if (linefeed
!= NULL
)
1600 /* Write out the instruction. */
1601 f
= frag_more (opcode
->oplen
);
1602 memcpy (f
, insn
, opcode
->oplen
);
1603 dwarf2_emit_insn (opcode
->oplen
);
1605 /* Create any fixups. At this point we do not use a
1606 bfd_reloc_code_real_type, but instead just use the
1607 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1608 handle fixups for any operand type, although that is admittedly
1609 not a very exciting feature. We pick a BFD reloc type in
1611 for (i
= 0; i
< fc
; i
++)
1614 if (fixups
[i
].opindex
< 0)
1616 /* Create tls instruction marker relocation. */
1617 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1618 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1622 operand
= s390_operands
+ fixups
[i
].opindex
;
1624 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1626 reloc_howto_type
*reloc_howto
;
1630 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1634 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1636 if (size
< 1 || size
> 4)
1639 fixP
= fix_new_exp (frag_now
,
1640 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1641 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1643 /* Turn off overflow checking in fixup_segment. This is necessary
1644 because fixup_segment will signal an overflow for large 4 byte
1645 quantities for GOT12 relocations. */
1646 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1647 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1648 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1649 fixP
->fx_no_overflow
= 1;
1651 if (operand
->flags
& S390_OPERAND_PCREL
)
1652 fixP
->fx_pcrel_adjust
= operand
->shift
/ 8;
1655 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1656 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1657 ((bfd_reloc_code_real_type
)
1658 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1663 /* This routine is called for each instruction to be assembled. */
1666 md_assemble (char *str
)
1668 const struct s390_opcode
*opcode
;
1669 unsigned char insn
[6];
1672 /* Get the opcode. */
1673 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1678 /* Look up the opcode in the hash table. */
1679 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1680 if (opcode
== (const struct s390_opcode
*) NULL
)
1682 as_bad (_("Unrecognized opcode: `%s'"), str
);
1685 else if (!(opcode
->modes
& current_mode_mask
))
1687 as_bad (_("Opcode %s not available in this mode"), str
);
1690 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1691 md_gather_operands (s
, insn
, opcode
);
1694 #ifndef WORKING_DOT_WORD
1695 /* Handle long and short jumps. We don't support these */
1697 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1699 addressT from_addr
, to_addr
;
1707 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1709 addressT from_addr
, to_addr
;
1718 s390_bss (int ignore ATTRIBUTE_UNUSED
)
1720 /* We don't support putting frags in the BSS segment, we fake it
1721 by marking in_bss, then looking at s_skip for clues. */
1723 subseg_set (bss_section
, 0);
1724 demand_empty_rest_of_line ();
1727 /* Pseudo-op handling. */
1730 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1733 const struct s390_opcode
*opformat
;
1734 unsigned char insn
[6];
1737 /* Get the opcode format. */
1738 s
= input_line_pointer
;
1739 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1742 as_bad (_("Invalid .insn format\n"));
1745 /* Look up the opcode in the hash table. */
1746 opformat
= (struct s390_opcode
*)
1747 hash_find (s390_opformat_hash
, input_line_pointer
);
1748 if (opformat
== (const struct s390_opcode
*) NULL
)
1750 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1753 input_line_pointer
= s
;
1755 if (exp
.X_op
== O_constant
)
1757 if ( ( opformat
->oplen
== 6
1758 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1759 || ( opformat
->oplen
== 4
1760 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1761 || ( opformat
->oplen
== 2
1762 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1763 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1765 as_bad (_("Invalid .insn format\n"));
1767 else if (exp
.X_op
== O_big
)
1769 if (exp
.X_add_number
> 0
1770 && opformat
->oplen
== 6
1771 && generic_bignum
[3] == 0)
1773 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1774 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1775 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1778 as_bad (_("Invalid .insn format\n"));
1781 as_bad (_("second operand of .insn not a constant\n"));
1783 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1784 as_bad (_("missing comma after insn constant\n"));
1786 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1788 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1792 demand_empty_rest_of_line ();
1795 /* The .byte pseudo-op. This is similar to the normal .byte
1796 pseudo-op, but it can also take a single ASCII string. */
1799 s390_byte (int ignore ATTRIBUTE_UNUSED
)
1801 if (*input_line_pointer
!= '\"')
1807 /* Gather characters. A real double quote is doubled. Unusual
1808 characters are not permitted. */
1809 ++input_line_pointer
;
1814 c
= *input_line_pointer
++;
1818 if (*input_line_pointer
!= '\"')
1820 ++input_line_pointer
;
1823 FRAG_APPEND_1_CHAR (c
);
1826 demand_empty_rest_of_line ();
1829 /* The .ltorg pseudo-op.This emits all literals defined since the last
1830 .ltorg or the invocation of gas. Literals are defined with the
1834 s390_literals (int ignore ATTRIBUTE_UNUSED
)
1836 struct s390_lpe
*lpe
;
1838 if (lp_sym
== NULL
|| lpe_count
== 0)
1839 return; /* Nothing to be done. */
1841 /* Emit symbol for start of literal pool. */
1842 S_SET_SEGMENT (lp_sym
, now_seg
);
1843 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1844 lp_sym
->sy_frag
= frag_now
;
1849 lpe_list
= lpe_list
->next
;
1850 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1851 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1852 lpe
->sym
->sy_frag
= frag_now
;
1854 /* Emit literal pool entry. */
1855 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1857 reloc_howto_type
*reloc_howto
=
1858 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1859 int size
= bfd_get_reloc_size (reloc_howto
);
1862 if (size
> lpe
->nbytes
)
1863 as_bad (_("%s relocations do not fit in %d bytes"),
1864 reloc_howto
->name
, lpe
->nbytes
);
1865 where
= frag_more (lpe
->nbytes
);
1866 md_number_to_chars (where
, 0, size
);
1867 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1868 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1872 if (lpe
->ex
.X_op
== O_big
)
1874 if (lpe
->ex
.X_add_number
<= 0)
1875 generic_floating_point_number
= lpe
->floatnum
;
1877 memcpy (generic_bignum
, lpe
->bignum
,
1878 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1880 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1883 lpe
->next
= lpe_free_list
;
1884 lpe_free_list
= lpe
;
1886 lpe_list_tail
= NULL
;
1892 #define MAX_HISTORY 100
1894 /* The .machine pseudo op allows to switch to a different CPU level in
1895 the asm listing. The current CPU setting can be stored on a stack
1896 with .machine push and restored with .machine pop. */
1899 s390_machine (int ignore ATTRIBUTE_UNUSED
)
1902 static struct cpu_history
1907 static int curr_hist
;
1911 if (*input_line_pointer
== '"')
1914 cpu_string
= demand_copy_C_string (&len
);
1920 cpu_string
= input_line_pointer
;
1925 c
= get_symbol_name (&str
);
1926 c
= restore_line_pointer (c
);
1928 ++ input_line_pointer
;
1932 c
= *input_line_pointer
;
1933 *input_line_pointer
= 0;
1934 cpu_string
= xstrdup (cpu_string
);
1935 (void) restore_line_pointer (c
);
1938 if (cpu_string
!= NULL
)
1940 unsigned int new_cpu
= current_cpu
;
1941 unsigned int new_flags
= current_flags
;
1943 if (strcmp (cpu_string
, "push") == 0)
1945 if (cpu_history
== NULL
)
1946 cpu_history
= XNEWVEC (struct cpu_history
, MAX_HISTORY
);
1948 if (curr_hist
>= MAX_HISTORY
)
1949 as_bad (_(".machine stack overflow"));
1952 cpu_history
[curr_hist
].cpu
= current_cpu
;
1953 cpu_history
[curr_hist
].flags
= current_flags
;
1957 else if (strcmp (cpu_string
, "pop") == 0)
1960 as_bad (_(".machine stack underflow"));
1964 new_cpu
= cpu_history
[curr_hist
].cpu
;
1965 new_flags
= cpu_history
[curr_hist
].flags
;
1969 new_cpu
= s390_parse_cpu (cpu_string
, &new_flags
, TRUE
);
1971 if (new_cpu
== S390_OPCODE_MAXCPU
)
1972 as_bad (_("invalid machine `%s'"), cpu_string
);
1974 if (new_cpu
!= current_cpu
|| new_flags
!= current_flags
)
1976 current_cpu
= new_cpu
;
1977 current_flags
= new_flags
;
1978 s390_setup_opcodes ();
1982 demand_empty_rest_of_line ();
1985 /* The .machinemode pseudo op allows to switch to a different
1986 architecture mode in the asm listing. The current architecture
1987 mode setting can be stored on a stack with .machinemode push and
1988 restored with .machinemode pop. */
1991 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
1994 static unsigned int *mode_history
;
1995 static int curr_hist
;
2002 c
= get_symbol_name (&mode_string
);
2003 mode_string
= xstrdup (mode_string
);
2004 (void) restore_line_pointer (c
);
2007 if (mode_string
!= NULL
)
2009 unsigned int old_mode_mask
= current_mode_mask
;
2012 for (p
= mode_string
; *p
!= 0; p
++)
2015 if (strcmp (mode_string
, "push") == 0)
2017 if (mode_history
== NULL
)
2018 mode_history
= XNEWVEC (unsigned int, MAX_HISTORY
);
2020 if (curr_hist
>= MAX_HISTORY
)
2021 as_bad (_(".machinemode stack overflow"));
2023 mode_history
[curr_hist
++] = current_mode_mask
;
2025 else if (strcmp (mode_string
, "pop") == 0)
2028 as_bad (_(".machinemode stack underflow"));
2030 current_mode_mask
= mode_history
[--curr_hist
];
2034 if (strcmp (mode_string
, "esa") == 0)
2035 current_mode_mask
= 1 << S390_OPCODE_ESA
;
2036 else if (strcmp (mode_string
, "zarch") == 0)
2038 if (s390_arch_size
== 32)
2039 set_highgprs_p
= TRUE
;
2040 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2042 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
2043 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2045 as_bad (_("invalid machine mode `%s'"), mode_string
);
2048 if (current_mode_mask
!= old_mode_mask
)
2049 s390_setup_opcodes ();
2052 demand_empty_rest_of_line ();
2058 md_atof (int type
, char *litp
, int *sizep
)
2060 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
2063 /* Align a section (I don't know why this is machine dependent). */
2066 md_section_align (asection
*seg
, valueT addr
)
2068 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2070 return ((addr
+ (1 << align
) - 1) & -(1 << align
));
2073 /* We don't have any form of relaxing. */
2076 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
2077 asection
*seg ATTRIBUTE_UNUSED
)
2083 /* Convert a machine dependent frag. We never generate these. */
2086 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2087 asection
*sec ATTRIBUTE_UNUSED
,
2088 fragS
*fragp ATTRIBUTE_UNUSED
)
2094 md_undefined_symbol (char *name
)
2096 if (*name
== '_' && *(name
+ 1) == 'G'
2097 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
2101 if (symbol_find (name
))
2102 as_bad (_("GOT already in symbol table"));
2103 GOT_symbol
= symbol_new (name
, undefined_section
,
2104 (valueT
) 0, &zero_address_frag
);
2111 /* Functions concerning relocs. */
2113 /* The location from which a PC relative jump should be calculated,
2114 given a PC relative reloc. */
2117 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2119 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2122 /* Here we decide which fixups can be adjusted to make them relative to
2123 the beginning of the section instead of the symbol. Basically we need
2124 to make sure that the dynamic relocations are done correctly, so in
2125 some cases we force the original symbol to be used. */
2127 tc_s390_fix_adjustable (fixS
*fixP
)
2129 /* Don't adjust pc-relative references to merge sections. */
2131 && (S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
2134 /* adjust_reloc_syms doesn't know about the GOT. */
2135 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
2136 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2137 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
2138 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
2139 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
2140 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
2141 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
2142 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
2143 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
2144 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
2145 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
2146 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
2147 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
2148 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2149 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2150 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2151 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2152 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2153 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2154 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2155 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2156 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2157 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2158 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2159 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2160 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2161 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2162 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2163 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2164 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2165 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2166 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2167 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2168 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2169 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2170 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2171 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2172 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2173 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2174 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2175 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2176 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2177 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2178 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2179 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2180 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2181 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2186 /* Return true if we must always emit a reloc for a type and false if
2187 there is some hope of resolving it at assembly time. */
2189 tc_s390_force_relocation (struct fix
*fixp
)
2191 /* Ensure we emit a relocation for every reference to the global
2192 offset table or to the procedure link table. */
2193 switch (fixp
->fx_r_type
)
2195 case BFD_RELOC_390_GOT12
:
2196 case BFD_RELOC_390_GOT20
:
2197 case BFD_RELOC_32_GOT_PCREL
:
2198 case BFD_RELOC_32_GOTOFF
:
2199 case BFD_RELOC_390_GOTOFF64
:
2200 case BFD_RELOC_390_PLTOFF16
:
2201 case BFD_RELOC_390_PLTOFF32
:
2202 case BFD_RELOC_390_PLTOFF64
:
2203 case BFD_RELOC_390_GOTPC
:
2204 case BFD_RELOC_390_GOT16
:
2205 case BFD_RELOC_390_GOTPCDBL
:
2206 case BFD_RELOC_390_GOT64
:
2207 case BFD_RELOC_390_GOTENT
:
2208 case BFD_RELOC_390_PLT32
:
2209 case BFD_RELOC_390_PLT12DBL
:
2210 case BFD_RELOC_390_PLT16DBL
:
2211 case BFD_RELOC_390_PLT24DBL
:
2212 case BFD_RELOC_390_PLT32DBL
:
2213 case BFD_RELOC_390_PLT64
:
2214 case BFD_RELOC_390_GOTPLT12
:
2215 case BFD_RELOC_390_GOTPLT16
:
2216 case BFD_RELOC_390_GOTPLT20
:
2217 case BFD_RELOC_390_GOTPLT32
:
2218 case BFD_RELOC_390_GOTPLT64
:
2219 case BFD_RELOC_390_GOTPLTENT
:
2225 return generic_force_reloc (fixp
);
2228 /* Apply a fixup to the object code. This is called for all the
2229 fixups we generated by the call to fix_new_exp, above. In the call
2230 above we used a reloc code which was the largest legal reloc code
2231 plus the operand index. Here we undo that to recover the operand
2232 index. At this point all symbol values should be fully resolved,
2233 and we attempt to completely resolve the reloc. If we can not do
2234 that, we determine the correct reloc code and put it back in the
2238 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2241 valueT value
= *valP
;
2243 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2245 if (fixP
->fx_subsy
!= NULL
)
2246 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2247 _("cannot emit relocation %s against subsy symbol %s"),
2248 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2249 S_GET_NAME (fixP
->fx_subsy
));
2251 if (fixP
->fx_addsy
!= NULL
)
2254 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2259 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2261 const struct s390_operand
*operand
;
2264 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2265 operand
= &s390_operands
[opindex
];
2269 /* Insert the fully resolved operand value. */
2270 s390_insert_operand ((unsigned char *) where
, operand
,
2271 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2275 /* Determine a BFD reloc value based on the operand information.
2276 We are only prepared to turn a few of the operands into
2278 fixP
->fx_offset
= value
;
2279 if (operand
->bits
== 12 && operand
->shift
== 20)
2282 fixP
->fx_where
+= 2;
2283 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2285 else if (operand
->bits
== 12 && operand
->shift
== 36)
2288 fixP
->fx_where
+= 4;
2289 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2291 else if (operand
->bits
== 20 && operand
->shift
== 20)
2294 fixP
->fx_where
+= 2;
2295 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2297 else if (operand
->bits
== 8 && operand
->shift
== 8)
2300 fixP
->fx_where
+= 1;
2301 fixP
->fx_r_type
= BFD_RELOC_8
;
2303 else if (operand
->bits
== 12 && operand
->shift
== 12
2304 && (operand
->flags
& S390_OPERAND_PCREL
))
2307 fixP
->fx_where
+= 1;
2308 fixP
->fx_offset
+= 1;
2309 fixP
->fx_pcrel_adjust
= 1;
2310 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2312 else if (operand
->bits
== 16 && operand
->shift
== 16)
2315 fixP
->fx_where
+= 2;
2316 if (operand
->flags
& S390_OPERAND_PCREL
)
2318 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2319 fixP
->fx_offset
+= 2;
2320 fixP
->fx_pcrel_adjust
= 2;
2323 fixP
->fx_r_type
= BFD_RELOC_16
;
2325 else if (operand
->bits
== 16 && operand
->shift
== 32
2326 && (operand
->flags
& S390_OPERAND_PCREL
))
2329 fixP
->fx_where
+= 4;
2330 fixP
->fx_offset
+= 4;
2331 fixP
->fx_pcrel_adjust
= 4;
2332 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2334 else if (operand
->bits
== 24 && operand
->shift
== 24
2335 && (operand
->flags
& S390_OPERAND_PCREL
))
2338 fixP
->fx_where
+= 3;
2339 fixP
->fx_offset
+= 3;
2340 fixP
->fx_pcrel_adjust
= 3;
2341 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2343 else if (operand
->bits
== 32 && operand
->shift
== 16
2344 && (operand
->flags
& S390_OPERAND_PCREL
))
2347 fixP
->fx_where
+= 2;
2348 fixP
->fx_offset
+= 2;
2349 fixP
->fx_pcrel_adjust
= 2;
2350 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2357 /* Use expr_symbol_where to see if this is an expression
2359 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2360 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2361 _("unresolved expression that must be resolved"));
2363 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2364 _("unsupported relocation type"));
2371 switch (fixP
->fx_r_type
)
2377 md_number_to_chars (where
, value
, 1);
2379 case BFD_RELOC_390_12
:
2380 case BFD_RELOC_390_GOT12
:
2381 case BFD_RELOC_390_GOTPLT12
:
2382 case BFD_RELOC_390_PC12DBL
:
2383 case BFD_RELOC_390_PLT12DBL
:
2385 value
+= fixP
->fx_pcrel_adjust
;
2394 mop
= bfd_getb16 ((unsigned char *) where
);
2395 mop
|= (unsigned short) (value
& 0xfff);
2396 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2400 case BFD_RELOC_390_20
:
2401 case BFD_RELOC_390_GOT20
:
2402 case BFD_RELOC_390_GOTPLT20
:
2406 mop
= bfd_getb32 ((unsigned char *) where
);
2407 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2408 (value
& 0xff000) >> 12);
2409 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2414 case BFD_RELOC_GPREL16
:
2415 case BFD_RELOC_16_GOT_PCREL
:
2416 case BFD_RELOC_16_GOTOFF
:
2418 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2419 _("cannot emit PC relative %s relocation%s%s"),
2420 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2421 fixP
->fx_addsy
!= NULL
? " against " : "",
2422 (fixP
->fx_addsy
!= NULL
2423 ? S_GET_NAME (fixP
->fx_addsy
)
2426 md_number_to_chars (where
, value
, 2);
2428 case BFD_RELOC_390_GOT16
:
2429 case BFD_RELOC_390_PLTOFF16
:
2430 case BFD_RELOC_390_GOTPLT16
:
2432 md_number_to_chars (where
, value
, 2);
2434 case BFD_RELOC_390_PC16DBL
:
2435 case BFD_RELOC_390_PLT16DBL
:
2436 value
+= fixP
->fx_pcrel_adjust
;
2438 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2441 case BFD_RELOC_390_PC24DBL
:
2442 case BFD_RELOC_390_PLT24DBL
:
2443 value
+= fixP
->fx_pcrel_adjust
;
2449 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2450 mop
|= (unsigned int) (value
& 0xffffff);
2451 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2457 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2459 fixP
->fx_r_type
= BFD_RELOC_32
;
2461 md_number_to_chars (where
, value
, 4);
2463 case BFD_RELOC_32_PCREL
:
2464 case BFD_RELOC_32_BASEREL
:
2465 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2467 md_number_to_chars (where
, value
, 4);
2469 case BFD_RELOC_32_GOT_PCREL
:
2470 case BFD_RELOC_390_PLTOFF32
:
2471 case BFD_RELOC_390_PLT32
:
2472 case BFD_RELOC_390_GOTPLT32
:
2474 md_number_to_chars (where
, value
, 4);
2476 case BFD_RELOC_390_PC32DBL
:
2477 case BFD_RELOC_390_PLT32DBL
:
2478 case BFD_RELOC_390_GOTPCDBL
:
2479 case BFD_RELOC_390_GOTENT
:
2480 case BFD_RELOC_390_GOTPLTENT
:
2481 value
+= fixP
->fx_pcrel_adjust
;
2483 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2486 case BFD_RELOC_32_GOTOFF
:
2488 md_number_to_chars (where
, value
, sizeof (int));
2491 case BFD_RELOC_390_GOTOFF64
:
2493 md_number_to_chars (where
, value
, 8);
2496 case BFD_RELOC_390_GOT64
:
2497 case BFD_RELOC_390_PLTOFF64
:
2498 case BFD_RELOC_390_PLT64
:
2499 case BFD_RELOC_390_GOTPLT64
:
2501 md_number_to_chars (where
, value
, 8);
2506 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2508 fixP
->fx_r_type
= BFD_RELOC_64
;
2510 md_number_to_chars (where
, value
, 8);
2513 case BFD_RELOC_64_PCREL
:
2514 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2516 md_number_to_chars (where
, value
, 8);
2519 case BFD_RELOC_VTABLE_INHERIT
:
2520 case BFD_RELOC_VTABLE_ENTRY
:
2524 case BFD_RELOC_390_TLS_LOAD
:
2525 case BFD_RELOC_390_TLS_GDCALL
:
2526 case BFD_RELOC_390_TLS_LDCALL
:
2527 case BFD_RELOC_390_TLS_GD32
:
2528 case BFD_RELOC_390_TLS_GD64
:
2529 case BFD_RELOC_390_TLS_GOTIE12
:
2530 case BFD_RELOC_390_TLS_GOTIE20
:
2531 case BFD_RELOC_390_TLS_GOTIE32
:
2532 case BFD_RELOC_390_TLS_GOTIE64
:
2533 case BFD_RELOC_390_TLS_LDM32
:
2534 case BFD_RELOC_390_TLS_LDM64
:
2535 case BFD_RELOC_390_TLS_IE32
:
2536 case BFD_RELOC_390_TLS_IE64
:
2537 case BFD_RELOC_390_TLS_LE32
:
2538 case BFD_RELOC_390_TLS_LE64
:
2539 case BFD_RELOC_390_TLS_LDO32
:
2540 case BFD_RELOC_390_TLS_LDO64
:
2541 case BFD_RELOC_390_TLS_DTPMOD
:
2542 case BFD_RELOC_390_TLS_DTPOFF
:
2543 case BFD_RELOC_390_TLS_TPOFF
:
2544 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2545 /* Fully resolved at link time. */
2547 case BFD_RELOC_390_TLS_IEENT
:
2548 /* Fully resolved at link time. */
2549 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2555 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2557 if (reloc_name
!= NULL
)
2558 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2560 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2564 fixP
->fx_offset
= value
;
2568 /* Generate a reloc for a fixup. */
2571 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2573 bfd_reloc_code_real_type code
;
2576 code
= fixp
->fx_r_type
;
2577 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2579 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2580 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2581 code
= BFD_RELOC_390_GOTPC
;
2582 if (code
== BFD_RELOC_390_PC32DBL
)
2583 code
= BFD_RELOC_390_GOTPCDBL
;
2586 reloc
= XNEW (arelent
);
2587 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
2588 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2589 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2590 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2591 if (reloc
->howto
== NULL
)
2593 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2594 _("cannot represent relocation type %s"),
2595 bfd_get_reloc_code_name (code
));
2596 /* Set howto to a garbage value so that we can keep going. */
2597 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2598 gas_assert (reloc
->howto
!= NULL
);
2600 reloc
->addend
= fixp
->fx_offset
;
2606 s390_cfi_frame_initial_instructions (void)
2608 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2612 tc_s390_regname_to_dw2regnum (char *regname
)
2616 if (regname
[0] != 'c' && regname
[0] != 'a')
2618 regnum
= reg_name_search (regname
);
2619 if (regname
[0] == 'f' && regnum
!= -1)
2622 else if (strcmp (regname
, "ap") == 0)
2624 else if (strcmp (regname
, "cc") == 0)
2630 s390_elf_final_processing (void)
2633 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;