1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2022 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 "dwarf2dbg.h"
26 #include "dw2gencfi.h"
28 #include "opcode/s390.h"
31 /* The default architecture. */
33 #define DEFAULT_ARCH "s390"
35 static const char *default_arch
= DEFAULT_ARCH
;
36 /* Either 32 or 64, selects file format. */
37 static int s390_arch_size
= 0;
39 /* If no -march option was given default to the highest available CPU.
40 Since with S/390 a newer CPU always supports everything from its
41 predecessors this will accept every valid asm input. */
42 static unsigned int current_cpu
= S390_OPCODE_MAXCPU
- 1;
43 /* All facilities are enabled by default. */
44 static unsigned int current_flags
= S390_INSTR_FLAG_FACILITY_MASK
;
45 /* The mode mask default is picked in init_default_arch depending on
47 static unsigned int current_mode_mask
= 0;
49 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
50 for the output file. */
51 static bool set_highgprs_p
= false;
53 /* Whether to use user friendly register names. Default is TRUE. */
54 #ifndef TARGET_REG_NAMES_P
55 #define TARGET_REG_NAMES_P true
58 static bool reg_names_p
= TARGET_REG_NAMES_P
;
60 /* Set to TRUE if we want to warn about zero base/index registers. */
61 static bool warn_areg_zero
= false;
63 /* Generic assembler global variables which must be defined by all
66 const char comment_chars
[] = "#";
68 /* Characters which start a comment at the beginning of a line. */
69 const char line_comment_chars
[] = "#";
71 /* Characters which may be used to separate multiple commands on a
73 const char line_separator_chars
[] = ";";
75 /* Characters which are used to indicate an exponent in a floating
77 const char EXP_CHARS
[] = "eE";
79 /* Characters which mean that a number is a floating point constant,
81 const char FLT_CHARS
[] = "dD";
83 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
84 int s390_cie_data_alignment
;
86 /* The target specific pseudo-ops which we support. */
88 /* Define the prototypes for the pseudo-ops */
89 static void s390_byte (int);
90 static void s390_elf_cons (int);
91 static void s390_bss (int);
92 static void s390_insn (int);
93 static void s390_literals (int);
94 static void s390_machine (int);
95 static void s390_machinemode (int);
97 const pseudo_typeS md_pseudo_table
[] =
99 { "align", s_align_bytes
, 0 },
100 /* Pseudo-ops which must be defined. */
101 { "bss", s390_bss
, 0 },
102 { "insn", s390_insn
, 0 },
103 /* Pseudo-ops which must be overridden. */
104 { "byte", s390_byte
, 0 },
105 { "short", s390_elf_cons
, 2 },
106 { "long", s390_elf_cons
, 4 },
107 { "quad", s390_elf_cons
, 8 },
108 { "ltorg", s390_literals
, 0 },
109 { "string", stringer
, 8 + 1 },
110 { "machine", s390_machine
, 0 },
111 { "machinemode", s390_machinemode
, 0 },
115 /* Given NAME, find the register number associated with that name, return
116 the integer value associated with the given name or -1 on failure. */
119 reg_name_search (const char *name
)
123 if (strcasecmp (name
, "lit") == 0)
126 if (strcasecmp (name
, "sp") == 0)
129 if (name
[0] != 'a' && name
[0] != 'c' && name
[0] != 'f'
130 && name
[0] != 'r' && name
[0] != 'v')
133 if (ISDIGIT (name
[1]))
136 if (ISDIGIT (name
[2]))
137 val
= val
* 10 + name
[2] - '0';
140 if ((name
[0] != 'v' && val
> 15) || val
> 31)
148 * Summary of register_name().
150 * in: Input_line_pointer points to 1st char of operand.
152 * out: A expressionS.
153 * The operand may have been a register: in this case, X_op == O_register,
154 * X_add_number is set to the register number, and truth is returned.
155 * Input_line_pointer->(next non-blank) char after operand, or is in its
160 register_name (expressionS
*expressionP
)
167 /* Find the spelling of the operand. */
168 start
= name
= input_line_pointer
;
169 if (name
[0] == '%' && ISALPHA (name
[1]))
170 name
= ++input_line_pointer
;
174 c
= get_symbol_name (&name
);
175 reg_number
= reg_name_search (name
);
177 /* Put back the delimiting char. */
178 (void) restore_line_pointer (c
);
180 /* Look to see if it's in the register table. */
183 expressionP
->X_op
= O_register
;
184 expressionP
->X_add_number
= reg_number
;
186 /* Make the rest nice. */
187 expressionP
->X_add_symbol
= NULL
;
188 expressionP
->X_op_symbol
= NULL
;
192 /* Reset the line as if we had not done anything. */
193 input_line_pointer
= start
;
197 /* Local variables. */
199 /* Opformat hash table. */
200 static htab_t s390_opformat_hash
;
202 /* Opcode hash table. */
203 static htab_t s390_opcode_hash
= NULL
;
205 /* Flags to set in the elf header */
206 static flagword s390_flags
= 0;
208 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
210 #ifndef WORKING_DOT_WORD
211 int md_short_jump_size
= 4;
212 int md_long_jump_size
= 4;
215 const char *md_shortopts
= "A:m:kVQ:";
216 struct option md_longopts
[] = {
217 {NULL
, no_argument
, NULL
, 0}
219 size_t md_longopts_size
= sizeof (md_longopts
);
221 /* Initialize the default opcode arch and word size from the default
222 architecture name if not specified by an option. */
224 init_default_arch (void)
226 if (strcmp (default_arch
, "s390") == 0)
228 if (s390_arch_size
== 0)
231 else if (strcmp (default_arch
, "s390x") == 0)
233 if (s390_arch_size
== 0)
237 as_fatal (_("Invalid default architecture, broken assembler."));
239 if (current_mode_mask
== 0)
241 /* Default to z/Architecture mode if the CPU supports it. */
242 if (current_cpu
< S390_OPCODE_Z900
)
243 current_mode_mask
= 1 << S390_OPCODE_ESA
;
245 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
249 /* Called by TARGET_FORMAT. */
251 s390_target_format (void)
253 /* We don't get a chance to initialize anything before we're called,
254 so handle that now. */
255 init_default_arch ();
257 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
260 /* Map a cpu string ARG as given with -march= or .machine to the respective
261 enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name
262 can be followed by a list of cpu facility flags each beginning with the
263 character '+'. The active cpu flags are returned through *RET_FLAGS.
264 In case of an error, S390_OPCODE_MAXCPU is returned. */
267 s390_parse_cpu (const char *arg
,
268 unsigned int *ret_flags
,
269 bool allow_extensions
)
274 unsigned int name_len
;
275 const char * alt_name
;
276 unsigned int alt_name_len
;
278 } cpu_table
[S390_OPCODE_MAXCPU
] =
280 { STRING_COMMA_LEN ("g5"), STRING_COMMA_LEN ("arch3"), 0 },
281 { STRING_COMMA_LEN ("g6"), STRING_COMMA_LEN (""), 0 },
282 { STRING_COMMA_LEN ("z900"), STRING_COMMA_LEN ("arch5"), 0 },
283 { STRING_COMMA_LEN ("z990"), STRING_COMMA_LEN ("arch6"), 0 },
284 { STRING_COMMA_LEN ("z9-109"), STRING_COMMA_LEN (""), 0 },
285 { STRING_COMMA_LEN ("z9-ec"), STRING_COMMA_LEN ("arch7"), 0 },
286 { STRING_COMMA_LEN ("z10"), STRING_COMMA_LEN ("arch8"), 0 },
287 { STRING_COMMA_LEN ("z196"), STRING_COMMA_LEN ("arch9"), 0 },
288 { STRING_COMMA_LEN ("zEC12"), STRING_COMMA_LEN ("arch10"),
289 S390_INSTR_FLAG_HTM
},
290 { STRING_COMMA_LEN ("z13"), STRING_COMMA_LEN ("arch11"),
291 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
292 { STRING_COMMA_LEN ("z14"), STRING_COMMA_LEN ("arch12"),
293 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
294 { STRING_COMMA_LEN ("z15"), STRING_COMMA_LEN ("arch13"),
295 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
296 { STRING_COMMA_LEN ("z16"), STRING_COMMA_LEN ("arch14"),
297 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
}
306 { "htm", S390_INSTR_FLAG_HTM
, true },
307 { "nohtm", S390_INSTR_FLAG_HTM
, false },
308 { "vx", S390_INSTR_FLAG_VX
, true },
309 { "novx", S390_INSTR_FLAG_VX
, false }
314 icpu
= S390_OPCODE_MAXCPU
;
315 if (startswith (arg
, "all") && (arg
[3] == 0 || arg
[3] == '+'))
317 icpu
= S390_OPCODE_MAXCPU
- 1;
322 for (icpu
= 0; icpu
< S390_OPCODE_MAXCPU
; icpu
++)
324 unsigned int l
, l_alt
;
326 l
= cpu_table
[icpu
].name_len
;
328 if (strncmp (arg
, cpu_table
[icpu
].name
, l
) == 0
329 && (arg
[l
] == 0 || arg
[l
] == '+'))
335 l_alt
= cpu_table
[icpu
].alt_name_len
;
338 && strncmp (arg
, cpu_table
[icpu
].alt_name
, l_alt
) == 0
339 && (arg
[l_alt
] == 0 || arg
[l_alt
] == '+'))
347 if (icpu
== S390_OPCODE_MAXCPU
)
348 return S390_OPCODE_MAXCPU
;
350 ilp_bak
= input_line_pointer
;
351 if (icpu
!= S390_OPCODE_MAXCPU
)
353 input_line_pointer
= (char *) arg
;
354 *ret_flags
= (cpu_table
[icpu
].flags
& S390_INSTR_FLAG_FACILITY_MASK
);
356 while (*input_line_pointer
== '+' && allow_extensions
)
362 input_line_pointer
++;
363 c
= get_symbol_name (&sym
);
364 for (iflag
= 0; iflag
< ARRAY_SIZE (cpu_flags
); iflag
++)
366 if (strcmp (sym
, cpu_flags
[iflag
].name
) == 0)
368 if (cpu_flags
[iflag
].on
)
369 *ret_flags
|= cpu_flags
[iflag
].mask
;
371 *ret_flags
&= ~cpu_flags
[iflag
].mask
;
375 if (iflag
== ARRAY_SIZE (cpu_flags
))
376 as_bad (_("no such machine extension `%s'"), sym
- 1);
377 *input_line_pointer
= c
;
378 if (iflag
== ARRAY_SIZE (cpu_flags
))
385 if (*input_line_pointer
!= 0 && *input_line_pointer
!= '\n')
387 as_bad (_("junk at end of machine string, first unrecognized character"
388 " is `%c'"), *input_line_pointer
);
389 icpu
= S390_OPCODE_MAXCPU
;
391 input_line_pointer
= ilp_bak
;
397 md_parse_option (int c
, const char *arg
)
401 /* -k: Ignore for FreeBSD compatibility. */
405 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
408 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
411 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
412 warn_areg_zero
= true;
414 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
417 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
420 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
421 current_mode_mask
= 1 << S390_OPCODE_ESA
;
423 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
425 if (s390_arch_size
== 32)
426 set_highgprs_p
= true;
427 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
430 else if (arg
!= NULL
&& startswith (arg
, "arch="))
432 current_cpu
= s390_parse_cpu (arg
+ 5, ¤t_flags
, false);
433 if (current_cpu
== S390_OPCODE_MAXCPU
)
435 as_bad (_("invalid switch -m%s"), arg
);
442 as_bad (_("invalid switch -m%s"), arg
);
448 /* Option -A is deprecated. Still available for compatibility. */
449 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
450 current_cpu
= S390_OPCODE_G5
;
451 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
452 current_cpu
= S390_OPCODE_Z900
;
454 as_bad (_("invalid architecture -A%s"), arg
);
457 /* -V: SVR4 argument to print version ID. */
462 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
463 should be emitted or not. FIXME: Not implemented. */
475 md_show_usage (FILE *stream
)
477 fprintf (stream
, _("\
479 -mregnames Allow symbolic names for registers\n\
480 -mwarn-areg-zero Warn about zero base/index registers\n\
481 -mno-regnames Do not allow symbolic names for registers\n\
482 -m31 Set file format to 31 bit format\n\
483 -m64 Set file format to 64 bit format\n"));
484 fprintf (stream
, _("\
485 -V print assembler version number\n\
486 -Qy, -Qn ignored\n"));
489 /* Generate the hash table mapping mnemonics to struct s390_opcode.
490 This table is built at startup and whenever the CPU level is
491 changed using .machine. */
494 s390_setup_opcodes (void)
496 const struct s390_opcode
*op
;
497 const struct s390_opcode
*op_end
;
498 bool dup_insn
= false;
500 if (s390_opcode_hash
!= NULL
)
501 htab_delete (s390_opcode_hash
);
503 /* Insert the opcodes into a hash table. */
504 s390_opcode_hash
= str_htab_create ();
506 op_end
= s390_opcodes
+ s390_num_opcodes
;
507 for (op
= s390_opcodes
; op
< op_end
; op
++)
511 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
513 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
518 if ((op
->modes
& current_mode_mask
) == 0)
520 else if ((op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
) == 0)
522 /* Opcodes that do not belong to a specific facility are enabled if
523 present in the selected cpu. */
524 use_opcode
= (op
->min_cpu
<= current_cpu
);
530 /* Opcodes of a specific facility are enabled if the facility is
531 enabled. Note: only some facilities are represented as flags. */
532 f
= (op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
);
533 use_opcode
= ((f
& current_flags
) == f
);
536 && str_hash_insert (s390_opcode_hash
, op
->name
, op
, 0) != NULL
)
538 as_bad (_("duplicate %s"), op
->name
);
542 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
550 /* This function is called when the assembler starts up. It is called
551 after the options have been parsed and the output file has been
557 const struct s390_opcode
*op
;
558 const struct s390_opcode
*op_end
;
560 /* Give a warning if the combination -m64-bit and -Aesa is used. */
561 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
562 as_warn (_("The 64 bit file format is used without esame instructions."));
564 s390_cie_data_alignment
= -s390_arch_size
/ 8;
566 /* Set the ELF flags if desired. */
568 bfd_set_private_flags (stdoutput
, s390_flags
);
570 /* Insert the opcode formats into a hash table. */
571 s390_opformat_hash
= str_htab_create ();
573 op_end
= s390_opformats
+ s390_num_opformats
;
574 for (op
= s390_opformats
; op
< op_end
; op
++)
575 if (str_hash_insert (s390_opformat_hash
, op
->name
, op
, 0) != NULL
)
576 as_fatal (_("duplicate %s"), op
->name
);
578 s390_setup_opcodes ();
580 record_alignment (text_section
, 2);
581 record_alignment (data_section
, 2);
582 record_alignment (bss_section
, 2);
585 /* Called after all assembly has been done. */
589 if (s390_arch_size
== 64)
590 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
592 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
595 /* Insert an operand value into an instruction. */
598 s390_insert_operand (unsigned char *insn
,
599 const struct s390_operand
*operand
,
607 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
611 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
612 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
613 /* Halve PCREL operands. */
614 if (operand
->flags
& S390_OPERAND_PCREL
)
616 /* Check for underflow / overflow. */
617 if (val
< min
|| val
> max
)
620 _("operand out of range (%" PRId64
" not between %" PRId64
621 " and %" PRId64
")");
623 if (operand
->flags
& S390_OPERAND_PCREL
)
625 val
= (offsetT
) ((addressT
) val
<< 1);
626 min
= (offsetT
) ((addressT
) min
<< 1);
627 max
= (offsetT
) ((addressT
) max
<< 1);
629 if (file
== (char *) NULL
)
630 as_bad (err
, (int64_t) val
, (int64_t) min
, (int64_t) max
);
632 as_bad_where (file
, line
,
633 err
, (int64_t) val
, (int64_t) min
, (int64_t) max
);
636 /* val is ok, now restrict it to operand->bits bits. */
637 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
638 /* val is restrict, now check for special case. */
639 if (operand
->bits
== 20 && operand
->shift
== 20)
640 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
646 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
648 uval
= (addressT
) val
;
650 /* Vector register operands have an additional bit in the RXB
652 if (operand
->flags
& S390_OPERAND_VR
)
653 max
= (max
<< 1) | 1;
655 /* Length x in an instructions has real length x+1. */
656 if (operand
->flags
& S390_OPERAND_LENGTH
)
658 /* Check for underflow / overflow. */
659 if (uval
< min
|| uval
> max
)
661 if (operand
->flags
& S390_OPERAND_LENGTH
)
668 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
674 if (operand
->flags
& S390_OPERAND_VR
)
676 /* Insert the extra bit into the RXB field. */
677 switch (operand
->shift
)
680 insn
[4] |= (uval
& 0x10) >> 1;
683 insn
[4] |= (uval
& 0x10) >> 2;
686 insn
[4] |= (uval
& 0x10) >> 3;
689 insn
[4] |= (uval
& 0x10) >> 4;
695 if (operand
->flags
& S390_OPERAND_OR1
)
697 if (operand
->flags
& S390_OPERAND_OR2
)
699 if (operand
->flags
& S390_OPERAND_OR8
)
702 /* Duplicate the operand at bit pos 12 to 16. */
703 if (operand
->flags
& S390_OPERAND_CP16
)
705 /* Copy VR operand at bit pos 12 to bit pos 16. */
706 insn
[2] |= uval
<< 4;
707 /* Copy the flag in the RXB field. */
708 insn
[4] |= (insn
[4] & 4) >> 1;
711 /* Insert fragments of the operand byte for byte. */
712 offset
= operand
->shift
+ operand
->bits
;
713 uval
<<= (-offset
) & 7;
714 insn
+= (offset
- 1) / 8;
726 bfd_reloc_code_real_type reloc
;
729 /* Parse tls marker and return the desired relocation. */
730 static bfd_reloc_code_real_type
731 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
733 static struct map_tls mapping
[] =
735 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
736 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
737 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
738 { NULL
, 0, BFD_RELOC_UNUSED
}
748 return BFD_RELOC_UNUSED
;
751 while (ISIDNUM (*str
))
755 return BFD_RELOC_UNUSED
;
757 orig_line
= input_line_pointer
;
758 input_line_pointer
= str
;
760 str
= input_line_pointer
;
761 if (&input_line_pointer
!= str_p
)
762 input_line_pointer
= orig_line
;
764 if (exp_p
->X_op
!= O_symbol
)
765 return BFD_RELOC_UNUSED
;
767 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
768 if (len
== ptr
->length
769 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
771 /* Found a matching tls suffix. */
775 return BFD_RELOC_UNUSED
;
778 /* Structure used to hold suffixes. */
789 ELF_SUFFIX_TLS_GOTIE
,
801 elf_suffix_type suffix
;
805 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
806 static elf_suffix_type
807 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
809 static struct map_bfd mapping
[] =
811 { "got", 3, ELF_SUFFIX_GOT
},
812 { "got12", 5, ELF_SUFFIX_GOT
},
813 { "plt", 3, ELF_SUFFIX_PLT
},
814 { "gotent", 6, ELF_SUFFIX_GOTENT
},
815 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
816 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
817 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
818 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
819 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
820 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
821 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
822 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
823 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
824 { NULL
, 0, ELF_SUFFIX_NONE
}
833 return ELF_SUFFIX_NONE
;
836 while (ISALNUM (*str
))
840 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
841 if (len
== ptr
->length
842 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
844 if (exp_p
->X_add_number
!= 0)
845 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
846 ptr
->string
, ptr
->string
);
847 /* Now check for identifier@suffix+constant. */
848 if (*str
== '-' || *str
== '+')
850 char *orig_line
= input_line_pointer
;
853 input_line_pointer
= str
;
854 expression (&new_exp
);
856 switch (new_exp
.X_op
)
858 case O_constant
: /* X_add_number (a constant expression). */
859 exp_p
->X_add_number
+= new_exp
.X_add_number
;
860 str
= input_line_pointer
;
862 case O_symbol
: /* X_add_symbol + X_add_number. */
863 /* this case is used for e.g. xyz@PLT+.Label. */
864 exp_p
->X_add_number
+= new_exp
.X_add_number
;
865 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
867 str
= input_line_pointer
;
869 case O_uminus
: /* (- 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
;
873 exp_p
->X_op
= O_subtract
;
874 str
= input_line_pointer
;
880 /* If s390_elf_suffix has not been called with
881 &input_line_pointer as first parameter, we have
882 clobbered the input_line_pointer. We have to
884 if (&input_line_pointer
!= str_p
)
885 input_line_pointer
= orig_line
;
891 return ELF_SUFFIX_NONE
;
894 /* Structure used to hold a literal pool entry. */
897 struct s390_lpe
*next
;
899 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
900 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
902 bfd_reloc_code_real_type reloc
;
906 static struct s390_lpe
*lpe_free_list
= NULL
;
907 static struct s390_lpe
*lpe_list
= NULL
;
908 static struct s390_lpe
*lpe_list_tail
= NULL
;
909 static symbolS
*lp_sym
= NULL
;
910 static int lp_count
= 0;
911 static int lpe_count
= 0;
914 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
916 if (exp1
->X_op
!= exp2
->X_op
)
921 case O_constant
: /* X_add_number must be equal. */
923 return exp1
->X_add_number
== exp2
->X_add_number
;
926 as_bad (_("Can't handle O_big in s390_exp_compare"));
929 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
934 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
935 && (exp1
->X_add_number
== exp2
->X_add_number
);
937 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
942 case O_bit_inclusive_or
:
944 case O_bit_exclusive_or
:
956 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
957 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
958 && (exp1
->X_add_number
== exp2
->X_add_number
);
964 /* Test for @lit and if it's present make an entry in the literal pool and
965 modify the current expression to be an offset into the literal pool. */
966 static elf_suffix_type
967 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
969 bfd_reloc_code_real_type reloc
;
973 struct s390_lpe
*lpe
;
977 return suffix
; /* No modification. */
979 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
981 while (ISALNUM (*str
))
984 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
985 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
986 return suffix
; /* no modification */
987 nbytes
= ident
[3] - '0';
989 reloc
= BFD_RELOC_UNUSED
;
990 if (suffix
== ELF_SUFFIX_GOT
)
993 reloc
= BFD_RELOC_390_GOT16
;
994 else if (nbytes
== 4)
995 reloc
= BFD_RELOC_32_GOT_PCREL
;
996 else if (nbytes
== 8)
997 reloc
= BFD_RELOC_390_GOT64
;
999 else if (suffix
== ELF_SUFFIX_PLT
)
1002 reloc
= BFD_RELOC_390_PLT32
;
1003 else if (nbytes
== 8)
1004 reloc
= BFD_RELOC_390_PLT64
;
1007 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1008 as_bad (_("Invalid suffix for literal pool entry"));
1010 /* Search the pool if the new entry is a duplicate. */
1011 if (exp_p
->X_op
== O_big
)
1013 /* Special processing for big numbers. */
1014 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1016 if (lpe
->ex
.X_op
== O_big
)
1018 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
1020 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
1021 sizeof (FLONUM_TYPE
)) == 0)
1024 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
1026 if (memcmp (generic_bignum
, lpe
->bignum
,
1027 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
1035 /* Processing for 'normal' data types. */
1036 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1037 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
1038 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
1044 /* A new literal. */
1045 if (lpe_free_list
!= NULL
)
1047 lpe
= lpe_free_list
;
1048 lpe_free_list
= lpe_free_list
->next
;
1052 lpe
= XNEW (struct s390_lpe
);
1057 if (exp_p
->X_op
== O_big
)
1059 if (exp_p
->X_add_number
<= 0)
1060 lpe
->floatnum
= generic_floating_point_number
;
1061 else if (exp_p
->X_add_number
<= 4)
1062 memcpy (lpe
->bignum
, generic_bignum
,
1063 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1065 as_bad (_("Big number is too big"));
1068 lpe
->nbytes
= nbytes
;
1070 /* Literal pool name defined ? */
1073 sprintf (tmp_name
, ".L\001%i", lp_count
);
1074 lp_sym
= symbol_make (tmp_name
);
1077 /* Make name for literal pool entry. */
1078 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1080 lpe
->sym
= symbol_make (tmp_name
);
1082 /* Add to literal pool list. */
1084 if (lpe_list_tail
!= NULL
)
1086 lpe_list_tail
->next
= lpe
;
1087 lpe_list_tail
= lpe
;
1090 lpe_list
= lpe_list_tail
= lpe
;
1093 /* Now change exp_p to the offset into the literal pool.
1094 That's the expression: .L^Ax^By-.L^Ax */
1095 exp_p
->X_add_symbol
= lpe
->sym
;
1096 exp_p
->X_op_symbol
= lp_sym
;
1097 exp_p
->X_op
= O_subtract
;
1098 exp_p
->X_add_number
= 0;
1102 /* We change the suffix type to ELF_SUFFIX_NONE, because
1103 the difference of two local labels is just a number. */
1104 return ELF_SUFFIX_NONE
;
1107 /* Like normal .long/.short/.word, except support @got, etc.
1108 clobbers input_line_pointer, checks end-of-line. */
1110 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
1113 elf_suffix_type suffix
;
1115 if (is_it_end_of_statement ())
1117 demand_empty_rest_of_line ();
1125 if (exp
.X_op
== O_symbol
1126 && *input_line_pointer
== '@'
1127 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1129 bfd_reloc_code_real_type reloc
;
1130 reloc_howto_type
*reloc_howto
;
1136 static bfd_reloc_code_real_type tab2
[] =
1138 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1139 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1140 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1141 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1142 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1143 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1144 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1145 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1146 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1147 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1148 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1149 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1150 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1152 reloc
= tab2
[suffix
];
1154 else if (nbytes
== 4)
1156 static bfd_reloc_code_real_type tab4
[] =
1158 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1159 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1160 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1161 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1162 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1163 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1164 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1165 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1166 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1167 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1168 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1169 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1170 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1172 reloc
= tab4
[suffix
];
1174 else if (nbytes
== 8)
1176 static bfd_reloc_code_real_type tab8
[] =
1178 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1179 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1180 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1181 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1182 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1183 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1184 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1185 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1186 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1187 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1188 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1189 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1190 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1192 reloc
= tab8
[suffix
];
1195 reloc
= BFD_RELOC_UNUSED
;
1197 if (reloc
!= BFD_RELOC_UNUSED
1198 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1200 size
= bfd_get_reloc_size (reloc_howto
);
1202 as_bad (ngettext ("%s relocations do not fit in %d byte",
1203 "%s relocations do not fit in %d bytes",
1205 reloc_howto
->name
, nbytes
);
1206 where
= frag_more (nbytes
);
1207 md_number_to_chars (where
, 0, size
);
1208 /* To make fixup_segment do the pc relative conversion the
1209 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1210 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1211 size
, &exp
, false, reloc
);
1214 as_bad (_("relocation not applicable"));
1217 emit_expr (&exp
, (unsigned int) nbytes
);
1219 while (*input_line_pointer
++ == ',');
1221 input_line_pointer
--; /* Put terminator back into stream. */
1222 demand_empty_rest_of_line ();
1225 /* Return true if all remaining operands in the opcode with
1226 OPCODE_FLAGS can be skipped. */
1228 skip_optargs_p (unsigned int opcode_flags
, const unsigned char *opindex_ptr
)
1230 if ((opcode_flags
& (S390_INSTR_FLAG_OPTPARM
| S390_INSTR_FLAG_OPTPARM2
))
1231 && opindex_ptr
[0] != '\0'
1232 && opindex_ptr
[1] == '\0')
1235 if ((opcode_flags
& S390_INSTR_FLAG_OPTPARM2
)
1236 && opindex_ptr
[0] != '\0'
1237 && opindex_ptr
[1] != '\0'
1238 && opindex_ptr
[2] == '\0')
1243 /* We need to keep a list of fixups. We can't simply generate them as
1244 we go, because that would require us to first create the frag, and
1245 that would screw up references to ``.''. */
1251 bfd_reloc_code_real_type reloc
;
1254 #define MAX_INSN_FIXUPS (4)
1256 /* This routine is called for each instruction to be assembled. */
1259 md_gather_operands (char *str
,
1260 unsigned char *insn
,
1261 const struct s390_opcode
*opcode
)
1263 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1264 const struct s390_operand
*operand
;
1265 const unsigned char *opindex_ptr
;
1267 elf_suffix_type suffix
;
1268 bfd_reloc_code_real_type reloc
;
1273 while (ISSPACE (*str
))
1278 /* Gather the operands. */
1280 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1284 operand
= s390_operands
+ *opindex_ptr
;
1286 if ((opcode
->flags
& (S390_INSTR_FLAG_OPTPARM
| S390_INSTR_FLAG_OPTPARM2
))
1289 /* Optional parameters might need to be ORed with a
1290 value so calling s390_insert_operand is needed. */
1291 s390_insert_operand (insn
, operand
, 0, NULL
, 0);
1295 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1297 /* We do an early skip. For D(X,B) constructions the index
1298 register is skipped (X is optional). For D(L,B) the base
1299 register will be the skipped operand, because L is NOT
1305 /* Gather the operand. */
1306 hold
= input_line_pointer
;
1307 input_line_pointer
= str
;
1309 /* Parse the operand. */
1310 if (! register_name (&ex
))
1313 str
= input_line_pointer
;
1314 input_line_pointer
= hold
;
1316 /* Write the operand to the insn. */
1317 if (ex
.X_op
== O_illegal
)
1318 as_bad (_("illegal operand"));
1319 else if (ex
.X_op
== O_absent
)
1321 if (opindex_ptr
[0] == '\0')
1323 as_bad (_("missing operand"));
1325 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1327 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1329 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1331 /* We need to generate a fixup for the
1332 expression returned by s390_lit_suffix. */
1333 if (fc
>= MAX_INSN_FIXUPS
)
1334 as_fatal (_("too many fixups"));
1335 fixups
[fc
].exp
= ex
;
1336 fixups
[fc
].opindex
= *opindex_ptr
;
1337 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1342 if ((operand
->flags
& S390_OPERAND_LENGTH
)
1343 && ex
.X_op
!= O_constant
)
1344 as_fatal (_("invalid length field specified"));
1345 if ((operand
->flags
& S390_OPERAND_INDEX
)
1346 && ex
.X_add_number
== 0
1348 as_warn (_("index register specified but zero"));
1349 if ((operand
->flags
& S390_OPERAND_BASE
)
1350 && ex
.X_add_number
== 0
1352 as_warn (_("base register specified but zero"));
1353 if ((operand
->flags
& S390_OPERAND_GPR
)
1354 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1355 && (ex
.X_add_number
& 1))
1356 as_fatal (_("odd numbered general purpose register specified as "
1358 if ((operand
->flags
& S390_OPERAND_FPR
)
1359 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1360 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1361 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1362 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1363 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1364 as_fatal (_("invalid floating point register pair. Valid fp "
1365 "register pair operands are 0, 1, 4, 5, 8, 9, "
1367 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1372 suffix
= s390_elf_suffix (&str
, &ex
);
1373 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1374 reloc
= BFD_RELOC_UNUSED
;
1376 if (suffix
== ELF_SUFFIX_GOT
)
1378 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1379 (operand
->bits
== 12))
1380 reloc
= BFD_RELOC_390_GOT12
;
1381 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1382 (operand
->bits
== 20))
1383 reloc
= BFD_RELOC_390_GOT20
;
1384 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1385 && (operand
->bits
== 16))
1386 reloc
= BFD_RELOC_390_GOT16
;
1387 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1388 && (operand
->bits
== 32))
1389 reloc
= BFD_RELOC_390_GOTENT
;
1391 else if (suffix
== ELF_SUFFIX_PLT
)
1393 if ((operand
->flags
& S390_OPERAND_PCREL
)
1394 && (operand
->bits
== 12))
1395 reloc
= BFD_RELOC_390_PLT12DBL
;
1396 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1397 && (operand
->bits
== 16))
1398 reloc
= BFD_RELOC_390_PLT16DBL
;
1399 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1400 && (operand
->bits
== 24))
1401 reloc
= BFD_RELOC_390_PLT24DBL
;
1402 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1403 && (operand
->bits
== 32))
1404 reloc
= BFD_RELOC_390_PLT32DBL
;
1406 else if (suffix
== ELF_SUFFIX_GOTENT
)
1408 if ((operand
->flags
& S390_OPERAND_PCREL
)
1409 && (operand
->bits
== 32))
1410 reloc
= BFD_RELOC_390_GOTENT
;
1412 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1414 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1415 && (operand
->bits
== 16))
1416 reloc
= BFD_RELOC_16_GOTOFF
;
1418 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1420 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1421 && (operand
->bits
== 16))
1422 reloc
= BFD_RELOC_390_PLTOFF16
;
1424 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1426 if ((operand
->flags
& S390_OPERAND_DISP
)
1427 && (operand
->bits
== 12))
1428 reloc
= BFD_RELOC_390_GOTPLT12
;
1429 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1430 && (operand
->bits
== 16))
1431 reloc
= BFD_RELOC_390_GOTPLT16
;
1432 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1433 && (operand
->bits
== 32))
1434 reloc
= BFD_RELOC_390_GOTPLTENT
;
1436 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1438 if ((operand
->flags
& S390_OPERAND_DISP
)
1439 && (operand
->bits
== 12))
1440 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1441 else if ((operand
->flags
& S390_OPERAND_DISP
)
1442 && (operand
->bits
== 20))
1443 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1445 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1447 if ((operand
->flags
& S390_OPERAND_PCREL
)
1448 && (operand
->bits
== 32))
1449 reloc
= BFD_RELOC_390_TLS_IEENT
;
1452 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1453 as_bad (_("invalid operand suffix"));
1454 /* We need to generate a fixup of type 'reloc' for this
1456 if (fc
>= MAX_INSN_FIXUPS
)
1457 as_fatal (_("too many fixups"));
1458 fixups
[fc
].exp
= ex
;
1459 fixups
[fc
].opindex
= *opindex_ptr
;
1460 fixups
[fc
].reloc
= reloc
;
1464 /* Check the next character. The call to expression has advanced
1465 str past any whitespace. */
1466 if (operand
->flags
& S390_OPERAND_DISP
)
1468 /* After a displacement a block in parentheses can start. */
1471 /* Check if parenthesized block can be skipped. If the next
1472 operand is neither an optional operand nor a base register
1473 then we have a syntax error. */
1474 operand
= s390_operands
+ *(++opindex_ptr
);
1475 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1476 as_bad (_("syntax error; missing '(' after displacement"));
1478 /* Ok, skip all operands until S390_OPERAND_BASE. */
1479 while (!(operand
->flags
& S390_OPERAND_BASE
))
1480 operand
= s390_operands
+ *(++opindex_ptr
);
1482 if (*str
== '\0' && skip_optargs_p (opcode
->flags
, &opindex_ptr
[1]))
1485 /* If there is a next operand it must be separated by a comma. */
1486 if (opindex_ptr
[1] != '\0')
1490 while (opindex_ptr
[1] != '\0')
1492 operand
= s390_operands
+ *(++opindex_ptr
);
1493 as_bad (_("syntax error; expected ','"));
1503 /* We found an opening parentheses. */
1505 for (f
= str
; *f
!= '\0'; f
++)
1506 if (*f
== ',' || *f
== ')')
1508 /* If there is no comma until the closing parentheses OR
1509 there is a comma right after the opening parentheses,
1510 we have to skip optional operands. */
1511 if (*f
== ',' && f
== str
)
1513 /* comma directly after '(' ? */
1518 skip_optional
= (*f
!= ',');
1521 else if (operand
->flags
& S390_OPERAND_BASE
)
1523 /* After the base register the parenthesised block ends. */
1525 as_bad (_("syntax error; missing ')' after base register"));
1528 if (*str
== '\0' && skip_optargs_p (opcode
->flags
, &opindex_ptr
[1]))
1531 /* If there is a next operand it must be separated by a comma. */
1532 if (opindex_ptr
[1] != '\0')
1536 while (opindex_ptr
[1] != '\0')
1538 operand
= s390_operands
+ *(++opindex_ptr
);
1539 as_bad (_("syntax error; expected ','"));
1549 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1550 of D(L,B). In this case the base register has to be skipped. */
1553 operand
= s390_operands
+ *(++opindex_ptr
);
1555 if (!(operand
->flags
& S390_OPERAND_BASE
))
1556 as_bad (_("syntax error; ')' not allowed here"));
1560 if (*str
== '\0' && skip_optargs_p (opcode
->flags
, &opindex_ptr
[1]))
1563 /* If there is a next operand it must be separated by a comma. */
1564 if (opindex_ptr
[1] != '\0')
1568 while (opindex_ptr
[1] != '\0')
1570 operand
= s390_operands
+ *(++opindex_ptr
);
1571 as_bad (_("syntax error; expected ','"));
1581 while (ISSPACE (*str
))
1584 /* Check for tls instruction marker. */
1585 reloc
= s390_tls_suffix (&str
, &ex
);
1586 if (reloc
!= BFD_RELOC_UNUSED
)
1588 /* We need to generate a fixup of type 'reloc' for this
1590 if (fc
>= MAX_INSN_FIXUPS
)
1591 as_fatal (_("too many fixups"));
1592 fixups
[fc
].exp
= ex
;
1593 fixups
[fc
].opindex
= -1;
1594 fixups
[fc
].reloc
= reloc
;
1602 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1604 as_bad (_("junk at end of line: `%s'"), str
);
1605 if (linefeed
!= NULL
)
1609 /* Write out the instruction. */
1610 f
= frag_more (opcode
->oplen
);
1611 memcpy (f
, insn
, opcode
->oplen
);
1612 dwarf2_emit_insn (opcode
->oplen
);
1614 /* Create any fixups. At this point we do not use a
1615 bfd_reloc_code_real_type, but instead just use the
1616 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1617 handle fixups for any operand type, although that is admittedly
1618 not a very exciting feature. We pick a BFD reloc type in
1620 for (i
= 0; i
< fc
; i
++)
1624 if (fixups
[i
].opindex
< 0)
1626 /* Create tls instruction marker relocation. */
1627 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1628 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1632 operand
= s390_operands
+ fixups
[i
].opindex
;
1634 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1636 reloc_howto_type
*reloc_howto
;
1639 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1643 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1645 if (size
< 1 || size
> 4)
1648 fixP
= fix_new_exp (frag_now
,
1649 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1650 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1652 /* Turn off overflow checking in fixup_segment. This is necessary
1653 because fixup_segment will signal an overflow for large 4 byte
1654 quantities for GOT12 relocations. */
1655 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1656 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1657 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1658 fixP
->fx_no_overflow
= 1;
1660 if (operand
->flags
& S390_OPERAND_PCREL
)
1661 fixP
->fx_pcrel_adjust
= operand
->shift
/ 8;
1664 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1666 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1667 ((bfd_reloc_code_real_type
)
1668 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1669 /* s390_insert_operand () does the range checking. */
1670 if (operand
->flags
& S390_OPERAND_PCREL
)
1671 fixP
->fx_no_overflow
= 1;
1676 /* This routine is called for each instruction to be assembled. */
1679 md_assemble (char *str
)
1681 const struct s390_opcode
*opcode
;
1682 unsigned char insn
[6];
1685 /* Get the opcode. */
1686 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1691 /* Look up the opcode in the hash table. */
1692 opcode
= (struct s390_opcode
*) str_hash_find (s390_opcode_hash
, str
);
1693 if (opcode
== (const struct s390_opcode
*) NULL
)
1695 as_bad (_("Unrecognized opcode: `%s'"), str
);
1698 else if (!(opcode
->modes
& current_mode_mask
))
1700 as_bad (_("Opcode %s not available in this mode"), str
);
1703 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1704 md_gather_operands (s
, insn
, opcode
);
1707 #ifndef WORKING_DOT_WORD
1708 /* Handle long and short jumps. We don't support these */
1710 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1712 addressT from_addr
, to_addr
;
1720 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1722 addressT from_addr
, to_addr
;
1731 s390_bss (int ignore ATTRIBUTE_UNUSED
)
1733 /* We don't support putting frags in the BSS segment, we fake it
1734 by marking in_bss, then looking at s_skip for clues. */
1736 subseg_set (bss_section
, 0);
1737 demand_empty_rest_of_line ();
1740 /* Pseudo-op handling. */
1743 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1746 const struct s390_opcode
*opformat
;
1747 unsigned char insn
[6];
1750 /* Get the opcode format. */
1751 s
= input_line_pointer
;
1752 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1755 as_bad (_("Invalid .insn format\n"));
1758 /* Look up the opcode in the hash table. */
1759 opformat
= (struct s390_opcode
*)
1760 str_hash_find (s390_opformat_hash
, input_line_pointer
);
1761 if (opformat
== (const struct s390_opcode
*) NULL
)
1763 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1766 input_line_pointer
= s
;
1768 if (exp
.X_op
== O_constant
)
1770 if ( ( opformat
->oplen
== 6
1771 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1772 || ( opformat
->oplen
== 4
1773 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1774 || ( opformat
->oplen
== 2
1775 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1776 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1778 as_bad (_("Invalid .insn format\n"));
1780 else if (exp
.X_op
== O_big
)
1782 if (exp
.X_add_number
> 0
1783 && opformat
->oplen
== 6
1784 && generic_bignum
[3] == 0)
1786 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1787 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1788 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1791 as_bad (_("Invalid .insn format\n"));
1794 as_bad (_("second operand of .insn not a constant\n"));
1796 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1797 as_bad (_("missing comma after insn constant\n"));
1799 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1801 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1805 demand_empty_rest_of_line ();
1808 /* The .byte pseudo-op. This is similar to the normal .byte
1809 pseudo-op, but it can also take a single ASCII string. */
1812 s390_byte (int ignore ATTRIBUTE_UNUSED
)
1814 if (*input_line_pointer
!= '\"')
1820 /* Gather characters. A real double quote is doubled. Unusual
1821 characters are not permitted. */
1822 ++input_line_pointer
;
1827 c
= *input_line_pointer
++;
1831 if (*input_line_pointer
!= '\"')
1833 ++input_line_pointer
;
1836 FRAG_APPEND_1_CHAR (c
);
1839 demand_empty_rest_of_line ();
1842 /* The .ltorg pseudo-op.This emits all literals defined since the last
1843 .ltorg or the invocation of gas. Literals are defined with the
1847 s390_literals (int ignore ATTRIBUTE_UNUSED
)
1849 struct s390_lpe
*lpe
;
1851 if (lp_sym
== NULL
|| lpe_count
== 0)
1852 return; /* Nothing to be done. */
1854 /* Emit symbol for start of literal pool. */
1855 S_SET_SEGMENT (lp_sym
, now_seg
);
1856 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1857 symbol_set_frag (lp_sym
, frag_now
);
1862 lpe_list
= lpe_list
->next
;
1863 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1864 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1865 symbol_set_frag (lpe
->sym
, frag_now
);
1867 /* Emit literal pool entry. */
1868 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1870 reloc_howto_type
*reloc_howto
=
1871 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1872 int size
= bfd_get_reloc_size (reloc_howto
);
1875 if (size
> lpe
->nbytes
)
1876 as_bad (ngettext ("%s relocations do not fit in %d byte",
1877 "%s relocations do not fit in %d bytes",
1879 reloc_howto
->name
, lpe
->nbytes
);
1880 where
= frag_more (lpe
->nbytes
);
1881 md_number_to_chars (where
, 0, size
);
1882 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1883 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1887 if (lpe
->ex
.X_op
== O_big
)
1889 if (lpe
->ex
.X_add_number
<= 0)
1890 generic_floating_point_number
= lpe
->floatnum
;
1892 memcpy (generic_bignum
, lpe
->bignum
,
1893 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1895 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1898 lpe
->next
= lpe_free_list
;
1899 lpe_free_list
= lpe
;
1901 lpe_list_tail
= NULL
;
1907 #define MAX_HISTORY 100
1909 /* The .machine pseudo op allows one to switch to a different CPU level in
1910 the asm listing. The current CPU setting can be stored on a stack
1911 with .machine push and restored with .machine pop. */
1914 s390_machine (int ignore ATTRIBUTE_UNUSED
)
1917 static struct cpu_history
1922 static int curr_hist
;
1926 if (*input_line_pointer
== '"')
1929 cpu_string
= demand_copy_C_string (&len
);
1935 cpu_string
= input_line_pointer
;
1940 c
= get_symbol_name (&str
);
1941 c
= restore_line_pointer (c
);
1943 ++ input_line_pointer
;
1947 c
= *input_line_pointer
;
1948 *input_line_pointer
= 0;
1949 cpu_string
= xstrdup (cpu_string
);
1950 (void) restore_line_pointer (c
);
1953 if (cpu_string
!= NULL
)
1955 unsigned int new_cpu
= current_cpu
;
1956 unsigned int new_flags
= current_flags
;
1958 if (strcmp (cpu_string
, "push") == 0)
1960 if (cpu_history
== NULL
)
1961 cpu_history
= XNEWVEC (struct cpu_history
, MAX_HISTORY
);
1963 if (curr_hist
>= MAX_HISTORY
)
1964 as_bad (_(".machine stack overflow"));
1967 cpu_history
[curr_hist
].cpu
= current_cpu
;
1968 cpu_history
[curr_hist
].flags
= current_flags
;
1972 else if (strcmp (cpu_string
, "pop") == 0)
1975 as_bad (_(".machine stack underflow"));
1979 new_cpu
= cpu_history
[curr_hist
].cpu
;
1980 new_flags
= cpu_history
[curr_hist
].flags
;
1984 new_cpu
= s390_parse_cpu (cpu_string
, &new_flags
, true);
1986 if (new_cpu
== S390_OPCODE_MAXCPU
)
1987 as_bad (_("invalid machine `%s'"), cpu_string
);
1989 if (new_cpu
!= current_cpu
|| new_flags
!= current_flags
)
1991 current_cpu
= new_cpu
;
1992 current_flags
= new_flags
;
1993 s390_setup_opcodes ();
1997 demand_empty_rest_of_line ();
2000 /* The .machinemode pseudo op allows one to switch to a different
2001 architecture mode in the asm listing. The current architecture
2002 mode setting can be stored on a stack with .machinemode push and
2003 restored with .machinemode pop. */
2006 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
2009 static unsigned int *mode_history
;
2010 static int curr_hist
;
2017 c
= get_symbol_name (&mode_string
);
2018 mode_string
= xstrdup (mode_string
);
2019 (void) restore_line_pointer (c
);
2022 if (mode_string
!= NULL
)
2024 unsigned int old_mode_mask
= current_mode_mask
;
2027 for (p
= mode_string
; *p
!= 0; p
++)
2030 if (strcmp (mode_string
, "push") == 0)
2032 if (mode_history
== NULL
)
2033 mode_history
= XNEWVEC (unsigned int, MAX_HISTORY
);
2035 if (curr_hist
>= MAX_HISTORY
)
2036 as_bad (_(".machinemode stack overflow"));
2038 mode_history
[curr_hist
++] = current_mode_mask
;
2040 else if (strcmp (mode_string
, "pop") == 0)
2043 as_bad (_(".machinemode stack underflow"));
2045 current_mode_mask
= mode_history
[--curr_hist
];
2049 if (strcmp (mode_string
, "esa") == 0)
2050 current_mode_mask
= 1 << S390_OPCODE_ESA
;
2051 else if (strcmp (mode_string
, "zarch") == 0)
2053 if (s390_arch_size
== 32)
2054 set_highgprs_p
= true;
2055 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2057 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
2058 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2060 as_bad (_("invalid machine mode `%s'"), mode_string
);
2063 if (current_mode_mask
!= old_mode_mask
)
2064 s390_setup_opcodes ();
2067 demand_empty_rest_of_line ();
2073 md_atof (int type
, char *litp
, int *sizep
)
2075 return ieee_md_atof (type
, litp
, sizep
, true);
2078 /* Align a section (I don't know why this is machine dependent). */
2081 md_section_align (asection
*seg
, valueT addr
)
2083 int align
= bfd_section_alignment (seg
);
2085 return ((addr
+ (1 << align
) - 1) & -(1 << align
));
2088 /* We don't have any form of relaxing. */
2091 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
2092 asection
*seg ATTRIBUTE_UNUSED
)
2098 /* Convert a machine dependent frag. We never generate these. */
2101 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2102 asection
*sec ATTRIBUTE_UNUSED
,
2103 fragS
*fragp ATTRIBUTE_UNUSED
)
2109 md_undefined_symbol (char *name
)
2111 if (*name
== '_' && *(name
+ 1) == 'G'
2112 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
2116 if (symbol_find (name
))
2117 as_bad (_("GOT already in symbol table"));
2118 GOT_symbol
= symbol_new (name
, undefined_section
,
2119 &zero_address_frag
, 0);
2126 /* Functions concerning relocs. */
2128 /* The location from which a PC relative jump should be calculated,
2129 given a PC relative reloc. */
2132 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2134 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2137 /* Here we decide which fixups can be adjusted to make them relative to
2138 the beginning of the section instead of the symbol. Basically we need
2139 to make sure that the dynamic relocations are done correctly, so in
2140 some cases we force the original symbol to be used. */
2142 tc_s390_fix_adjustable (fixS
*fixP
)
2144 /* Don't adjust pc-relative references to merge sections. */
2146 && (S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
2149 /* adjust_reloc_syms doesn't know about the GOT. */
2150 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
2151 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2152 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
2153 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
2154 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
2155 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
2156 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
2157 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
2158 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
2159 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
2160 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
2161 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
2162 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
2163 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2164 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2165 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2166 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2167 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2168 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2169 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2170 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2171 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2172 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2173 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2174 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2175 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2176 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2177 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2178 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2179 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2180 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2181 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2182 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2183 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2184 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2185 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2186 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2187 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2188 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2189 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2190 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2191 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2192 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2193 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2194 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2195 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2196 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2201 /* Return true if we must always emit a reloc for a type and false if
2202 there is some hope of resolving it at assembly time. */
2204 tc_s390_force_relocation (struct fix
*fixp
)
2206 /* Ensure we emit a relocation for every reference to the global
2207 offset table or to the procedure link table. */
2208 switch (fixp
->fx_r_type
)
2210 case BFD_RELOC_390_GOT12
:
2211 case BFD_RELOC_390_GOT20
:
2212 case BFD_RELOC_32_GOT_PCREL
:
2213 case BFD_RELOC_32_GOTOFF
:
2214 case BFD_RELOC_390_GOTOFF64
:
2215 case BFD_RELOC_390_PLTOFF16
:
2216 case BFD_RELOC_390_PLTOFF32
:
2217 case BFD_RELOC_390_PLTOFF64
:
2218 case BFD_RELOC_390_GOTPC
:
2219 case BFD_RELOC_390_GOT16
:
2220 case BFD_RELOC_390_GOTPCDBL
:
2221 case BFD_RELOC_390_GOT64
:
2222 case BFD_RELOC_390_GOTENT
:
2223 case BFD_RELOC_390_PLT32
:
2224 case BFD_RELOC_390_PLT12DBL
:
2225 case BFD_RELOC_390_PLT16DBL
:
2226 case BFD_RELOC_390_PLT24DBL
:
2227 case BFD_RELOC_390_PLT32DBL
:
2228 case BFD_RELOC_390_PLT64
:
2229 case BFD_RELOC_390_GOTPLT12
:
2230 case BFD_RELOC_390_GOTPLT16
:
2231 case BFD_RELOC_390_GOTPLT20
:
2232 case BFD_RELOC_390_GOTPLT32
:
2233 case BFD_RELOC_390_GOTPLT64
:
2234 case BFD_RELOC_390_GOTPLTENT
:
2240 return generic_force_reloc (fixp
);
2243 /* Apply a fixup to the object code. This is called for all the
2244 fixups we generated by the call to fix_new_exp, above. In the call
2245 above we used a reloc code which was the largest legal reloc code
2246 plus the operand index. Here we undo that to recover the operand
2247 index. At this point all symbol values should be fully resolved,
2248 and we attempt to completely resolve the reloc. If we can not do
2249 that, we determine the correct reloc code and put it back in the
2253 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2256 valueT value
= *valP
;
2258 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2260 if (fixP
->fx_subsy
!= NULL
)
2261 as_bad_subtract (fixP
);
2263 if (fixP
->fx_addsy
!= NULL
)
2266 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2271 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2273 const struct s390_operand
*operand
;
2276 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2277 operand
= &s390_operands
[opindex
];
2281 /* Insert the fully resolved operand value. */
2282 s390_insert_operand ((unsigned char *) where
, operand
,
2283 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2287 /* Determine a BFD reloc value based on the operand information.
2288 We are only prepared to turn a few of the operands into
2290 fixP
->fx_offset
= value
;
2291 if (operand
->bits
== 12 && operand
->shift
== 20)
2294 fixP
->fx_where
+= 2;
2295 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2297 else if (operand
->bits
== 12 && operand
->shift
== 36)
2300 fixP
->fx_where
+= 4;
2301 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2303 else if (operand
->bits
== 20 && operand
->shift
== 20)
2306 fixP
->fx_where
+= 2;
2307 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2309 else if (operand
->bits
== 8 && operand
->shift
== 8)
2312 fixP
->fx_where
+= 1;
2313 fixP
->fx_r_type
= BFD_RELOC_8
;
2315 else if (operand
->bits
== 12 && operand
->shift
== 12
2316 && (operand
->flags
& S390_OPERAND_PCREL
))
2319 fixP
->fx_where
+= 1;
2320 fixP
->fx_offset
+= 1;
2321 fixP
->fx_pcrel_adjust
= 1;
2322 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2324 else if (operand
->bits
== 16 && operand
->shift
== 16)
2327 fixP
->fx_where
+= 2;
2328 if (operand
->flags
& S390_OPERAND_PCREL
)
2330 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2331 fixP
->fx_offset
+= 2;
2332 fixP
->fx_pcrel_adjust
= 2;
2335 fixP
->fx_r_type
= BFD_RELOC_16
;
2337 else if (operand
->bits
== 16 && operand
->shift
== 32
2338 && (operand
->flags
& S390_OPERAND_PCREL
))
2341 fixP
->fx_where
+= 4;
2342 fixP
->fx_offset
+= 4;
2343 fixP
->fx_pcrel_adjust
= 4;
2344 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2346 else if (operand
->bits
== 24 && operand
->shift
== 24
2347 && (operand
->flags
& S390_OPERAND_PCREL
))
2350 fixP
->fx_where
+= 3;
2351 fixP
->fx_offset
+= 3;
2352 fixP
->fx_pcrel_adjust
= 3;
2353 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2355 else if (operand
->bits
== 32 && operand
->shift
== 16
2356 && (operand
->flags
& S390_OPERAND_PCREL
))
2359 fixP
->fx_where
+= 2;
2360 fixP
->fx_offset
+= 2;
2361 fixP
->fx_pcrel_adjust
= 2;
2362 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2369 /* Use expr_symbol_where to see if this is an expression
2371 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2372 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2373 _("unresolved expression that must be resolved"));
2375 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2376 _("unsupported relocation type"));
2383 switch (fixP
->fx_r_type
)
2389 md_number_to_chars (where
, value
, 1);
2391 case BFD_RELOC_390_12
:
2392 case BFD_RELOC_390_GOT12
:
2393 case BFD_RELOC_390_GOTPLT12
:
2394 case BFD_RELOC_390_PC12DBL
:
2395 case BFD_RELOC_390_PLT12DBL
:
2397 value
+= fixP
->fx_pcrel_adjust
;
2406 mop
= bfd_getb16 ((unsigned char *) where
);
2407 mop
|= (unsigned short) (value
& 0xfff);
2408 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2412 case BFD_RELOC_390_20
:
2413 case BFD_RELOC_390_GOT20
:
2414 case BFD_RELOC_390_GOTPLT20
:
2418 mop
= bfd_getb32 ((unsigned char *) where
);
2419 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2420 (value
& 0xff000) >> 12);
2421 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2426 case BFD_RELOC_GPREL16
:
2427 case BFD_RELOC_16_GOT_PCREL
:
2428 case BFD_RELOC_16_GOTOFF
:
2430 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2431 _("cannot emit PC relative %s relocation%s%s"),
2432 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2433 fixP
->fx_addsy
!= NULL
? " against " : "",
2434 (fixP
->fx_addsy
!= NULL
2435 ? S_GET_NAME (fixP
->fx_addsy
)
2438 md_number_to_chars (where
, value
, 2);
2440 case BFD_RELOC_390_GOT16
:
2441 case BFD_RELOC_390_PLTOFF16
:
2442 case BFD_RELOC_390_GOTPLT16
:
2444 md_number_to_chars (where
, value
, 2);
2446 case BFD_RELOC_390_PC16DBL
:
2447 case BFD_RELOC_390_PLT16DBL
:
2448 value
+= fixP
->fx_pcrel_adjust
;
2450 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2453 case BFD_RELOC_390_PC24DBL
:
2454 case BFD_RELOC_390_PLT24DBL
:
2455 value
+= fixP
->fx_pcrel_adjust
;
2461 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2462 mop
|= (unsigned int) (value
& 0xffffff);
2463 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2469 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2471 fixP
->fx_r_type
= BFD_RELOC_32
;
2473 md_number_to_chars (where
, value
, 4);
2475 case BFD_RELOC_32_PCREL
:
2476 case BFD_RELOC_32_BASEREL
:
2477 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2479 md_number_to_chars (where
, value
, 4);
2481 case BFD_RELOC_32_GOT_PCREL
:
2482 case BFD_RELOC_390_PLTOFF32
:
2483 case BFD_RELOC_390_PLT32
:
2484 case BFD_RELOC_390_GOTPLT32
:
2486 md_number_to_chars (where
, value
, 4);
2488 case BFD_RELOC_390_PC32DBL
:
2489 case BFD_RELOC_390_PLT32DBL
:
2490 case BFD_RELOC_390_GOTPCDBL
:
2491 case BFD_RELOC_390_GOTENT
:
2492 case BFD_RELOC_390_GOTPLTENT
:
2493 value
+= fixP
->fx_pcrel_adjust
;
2495 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2498 case BFD_RELOC_32_GOTOFF
:
2500 md_number_to_chars (where
, value
, sizeof (int));
2503 case BFD_RELOC_390_GOTOFF64
:
2505 md_number_to_chars (where
, value
, 8);
2508 case BFD_RELOC_390_GOT64
:
2509 case BFD_RELOC_390_PLTOFF64
:
2510 case BFD_RELOC_390_PLT64
:
2511 case BFD_RELOC_390_GOTPLT64
:
2513 md_number_to_chars (where
, value
, 8);
2518 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2520 fixP
->fx_r_type
= BFD_RELOC_64
;
2522 md_number_to_chars (where
, value
, 8);
2525 case BFD_RELOC_64_PCREL
:
2526 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2528 md_number_to_chars (where
, value
, 8);
2531 case BFD_RELOC_VTABLE_INHERIT
:
2532 case BFD_RELOC_VTABLE_ENTRY
:
2536 case BFD_RELOC_390_TLS_LOAD
:
2537 case BFD_RELOC_390_TLS_GDCALL
:
2538 case BFD_RELOC_390_TLS_LDCALL
:
2539 case BFD_RELOC_390_TLS_GD32
:
2540 case BFD_RELOC_390_TLS_GD64
:
2541 case BFD_RELOC_390_TLS_GOTIE12
:
2542 case BFD_RELOC_390_TLS_GOTIE20
:
2543 case BFD_RELOC_390_TLS_GOTIE32
:
2544 case BFD_RELOC_390_TLS_GOTIE64
:
2545 case BFD_RELOC_390_TLS_LDM32
:
2546 case BFD_RELOC_390_TLS_LDM64
:
2547 case BFD_RELOC_390_TLS_IE32
:
2548 case BFD_RELOC_390_TLS_IE64
:
2549 case BFD_RELOC_390_TLS_LE32
:
2550 case BFD_RELOC_390_TLS_LE64
:
2551 case BFD_RELOC_390_TLS_LDO32
:
2552 case BFD_RELOC_390_TLS_LDO64
:
2553 case BFD_RELOC_390_TLS_DTPMOD
:
2554 case BFD_RELOC_390_TLS_DTPOFF
:
2555 case BFD_RELOC_390_TLS_TPOFF
:
2556 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2557 /* Fully resolved at link time. */
2559 case BFD_RELOC_390_TLS_IEENT
:
2560 /* Fully resolved at link time. */
2561 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2567 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2569 if (reloc_name
!= NULL
)
2570 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2572 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2576 fixP
->fx_offset
= value
;
2580 /* Generate a reloc for a fixup. */
2583 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2585 bfd_reloc_code_real_type code
;
2588 code
= fixp
->fx_r_type
;
2589 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2591 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2592 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2593 code
= BFD_RELOC_390_GOTPC
;
2594 if (code
== BFD_RELOC_390_PC32DBL
)
2595 code
= BFD_RELOC_390_GOTPCDBL
;
2598 reloc
= XNEW (arelent
);
2599 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
2600 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2601 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2602 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2603 if (reloc
->howto
== NULL
)
2605 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2606 _("cannot represent relocation type %s"),
2607 bfd_get_reloc_code_name (code
));
2608 /* Set howto to a garbage value so that we can keep going. */
2609 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2610 gas_assert (reloc
->howto
!= NULL
);
2612 reloc
->addend
= fixp
->fx_offset
;
2618 s390_cfi_frame_initial_instructions (void)
2620 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2624 tc_s390_regname_to_dw2regnum (char *regname
)
2628 if (regname
[0] != 'c' && regname
[0] != 'a')
2630 regnum
= reg_name_search (regname
);
2631 if (regname
[0] == 'f' && regnum
!= -1)
2634 else if (strcmp (regname
, "ap") == 0)
2636 else if (strcmp (regname
, "cc") == 0)
2642 s390_elf_final_processing (void)
2645 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;