1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2016 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 static unsigned int current_mode_mask
= 0;
45 static unsigned int current_flags
= 0;
47 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
48 for the output file. */
49 static bfd_boolean set_highgprs_p
= FALSE
;
51 /* Whether to use user friendly register names. Default is TRUE. */
52 #ifndef TARGET_REG_NAMES_P
53 #define TARGET_REG_NAMES_P TRUE
56 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
58 /* Set to TRUE if we want to warn about zero base/index registers. */
59 static bfd_boolean warn_areg_zero
= FALSE
;
61 /* Generic assembler global variables which must be defined by all
64 const char comment_chars
[] = "#";
66 /* Characters which start a comment at the beginning of a line. */
67 const char line_comment_chars
[] = "#";
69 /* Characters which may be used to separate multiple commands on a
71 const char line_separator_chars
[] = ";";
73 /* Characters which are used to indicate an exponent in a floating
75 const char EXP_CHARS
[] = "eE";
77 /* Characters which mean that a number is a floating point constant,
79 const char FLT_CHARS
[] = "dD";
81 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
82 int s390_cie_data_alignment
;
84 /* The target specific pseudo-ops which we support. */
86 /* Define the prototypes for the pseudo-ops */
87 static void s390_byte (int);
88 static void s390_elf_cons (int);
89 static void s390_bss (int);
90 static void s390_insn (int);
91 static void s390_literals (int);
92 static void s390_machine (int);
93 static void s390_machinemode (int);
95 const pseudo_typeS md_pseudo_table
[] =
97 { "align", s_align_bytes
, 0 },
98 /* Pseudo-ops which must be defined. */
99 { "bss", s390_bss
, 0 },
100 { "insn", s390_insn
, 0 },
101 /* Pseudo-ops which must be overridden. */
102 { "byte", s390_byte
, 0 },
103 { "short", s390_elf_cons
, 2 },
104 { "long", s390_elf_cons
, 4 },
105 { "quad", s390_elf_cons
, 8 },
106 { "ltorg", s390_literals
, 0 },
107 { "string", stringer
, 8 + 1 },
108 { "machine", s390_machine
, 0 },
109 { "machinemode", s390_machinemode
, 0 },
113 /* Given NAME, find the register number associated with that name, return
114 the integer value associated with the given name or -1 on failure. */
117 reg_name_search (const char *name
)
121 if (strcasecmp (name
, "lit") == 0)
124 if (strcasecmp (name
, "sp") == 0)
127 if (name
[0] != 'a' && name
[0] != 'c' && name
[0] != 'f'
128 && name
[0] != 'r' && name
[0] != 'v')
131 if (ISDIGIT (name
[1]))
134 if (ISDIGIT (name
[2]))
135 val
= val
* 10 + name
[2] - '0';
138 if ((name
[0] != 'v' && val
> 15) || val
> 31)
146 * Summary of register_name().
148 * in: Input_line_pointer points to 1st char of operand.
150 * out: A expressionS.
151 * The operand may have been a register: in this case, X_op == O_register,
152 * X_add_number is set to the register number, and truth is returned.
153 * Input_line_pointer->(next non-blank) char after operand, or is in its
158 register_name (expressionS
*expressionP
)
165 /* Find the spelling of the operand. */
166 start
= name
= input_line_pointer
;
167 if (name
[0] == '%' && ISALPHA (name
[1]))
168 name
= ++input_line_pointer
;
172 c
= get_symbol_name (&name
);
173 reg_number
= reg_name_search (name
);
175 /* Put back the delimiting char. */
176 (void) restore_line_pointer (c
);
178 /* Look to see if it's in the register table. */
181 expressionP
->X_op
= O_register
;
182 expressionP
->X_add_number
= reg_number
;
184 /* Make the rest nice. */
185 expressionP
->X_add_symbol
= NULL
;
186 expressionP
->X_op_symbol
= NULL
;
190 /* Reset the line as if we had not done anything. */
191 input_line_pointer
= start
;
195 /* Local variables. */
197 /* Opformat hash table. */
198 static struct hash_control
*s390_opformat_hash
;
200 /* Opcode hash table. */
201 static struct hash_control
*s390_opcode_hash
= NULL
;
203 /* Flags to set in the elf header */
204 static flagword s390_flags
= 0;
206 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
208 #ifndef WORKING_DOT_WORD
209 int md_short_jump_size
= 4;
210 int md_long_jump_size
= 4;
213 const char *md_shortopts
= "A:m:kVQ:";
214 struct option md_longopts
[] = {
215 {NULL
, no_argument
, NULL
, 0}
217 size_t md_longopts_size
= sizeof (md_longopts
);
219 /* Initialize the default opcode arch and word size from the default
220 architecture name if not specified by an option. */
222 init_default_arch (void)
224 if (strcmp (default_arch
, "s390") == 0)
226 if (s390_arch_size
== 0)
229 else if (strcmp (default_arch
, "s390x") == 0)
231 if (s390_arch_size
== 0)
235 as_fatal (_("Invalid default architecture, broken assembler."));
237 if (current_mode_mask
== 0)
239 /* Default to z/Architecture mode if the CPU supports it. */
240 if (current_cpu
< S390_OPCODE_Z900
)
241 current_mode_mask
= 1 << S390_OPCODE_ESA
;
243 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
247 /* Called by TARGET_FORMAT. */
249 s390_target_format (void)
251 /* We don't get a chance to initialize anything before we're called,
252 so handle that now. */
253 init_default_arch ();
255 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
258 /* Map a cpu string ARG as given with -march= or .machine to the respective
259 enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name
260 can be followed by a list of cpu facility flags each beginning with the
261 character '+'. The active cpu flags are returned through *RET_FLAGS.
262 In case of an error, S390_OPCODE_MAXCPU is returned. */
265 s390_parse_cpu (const char * arg
,
266 unsigned int * ret_flags
,
267 bfd_boolean allow_extensions
)
274 } cpu_table
[S390_OPCODE_MAXCPU
] =
276 { STRING_COMMA_LEN ("g5"), 0 },
277 { STRING_COMMA_LEN ("g6"), 0 },
278 { STRING_COMMA_LEN ("z900"), 0 },
279 { STRING_COMMA_LEN ("z990"), 0 },
280 { STRING_COMMA_LEN ("z9-109"), 0 },
281 { STRING_COMMA_LEN ("z9-ec"), 0 },
282 { STRING_COMMA_LEN ("z10"), 0 },
283 { STRING_COMMA_LEN ("z196"), 0 },
284 { STRING_COMMA_LEN ("zEC12"), S390_INSTR_FLAG_HTM
},
285 { STRING_COMMA_LEN ("z13"), S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
}
294 { "htm", S390_INSTR_FLAG_HTM
, TRUE
},
295 { "nohtm", S390_INSTR_FLAG_HTM
, FALSE
},
296 { "vx", S390_INSTR_FLAG_VX
, TRUE
},
297 { "novx", S390_INSTR_FLAG_VX
, FALSE
}
302 icpu
= S390_OPCODE_MAXCPU
;
303 if (strncmp (arg
, "all", 3) == 0 && (arg
[3] == 0 || arg
[3] == '+'))
305 icpu
= S390_OPCODE_MAXCPU
- 1;
310 for (icpu
= 0; icpu
< S390_OPCODE_MAXCPU
; icpu
++)
314 l
= cpu_table
[icpu
].len
;
315 if (strncmp (arg
, cpu_table
[icpu
].name
, l
) == 0
316 && (arg
[l
] == 0 || arg
[l
] == '+'))
324 ilp_bak
= input_line_pointer
;
325 if (icpu
!= S390_OPCODE_MAXCPU
)
327 input_line_pointer
= (char *) arg
;
328 *ret_flags
= (cpu_table
[icpu
].flags
& S390_INSTR_FLAG_FACILITY_MASK
);
330 while (*input_line_pointer
== '+' && allow_extensions
)
336 input_line_pointer
++;
337 c
= get_symbol_name (&sym
);
338 for (iflag
= 0; iflag
< ARRAY_SIZE (cpu_flags
); iflag
++)
340 if (strcmp (sym
, cpu_flags
[iflag
].name
) == 0)
342 if (cpu_flags
[iflag
].on
)
343 *ret_flags
|= cpu_flags
[iflag
].mask
;
345 *ret_flags
&= ~cpu_flags
[iflag
].mask
;
349 if (iflag
== ARRAY_SIZE (cpu_flags
))
350 as_bad (_("no such machine extension `%s'"), sym
- 1);
351 *input_line_pointer
= c
;
352 if (iflag
== ARRAY_SIZE (cpu_flags
))
359 if (*input_line_pointer
!= 0 && *input_line_pointer
!= '\n')
361 as_bad (_("junk at end of machine string, first unrecognized character"
362 " is `%c'"), *input_line_pointer
);
363 icpu
= S390_OPCODE_MAXCPU
;
365 input_line_pointer
= ilp_bak
;
371 md_parse_option (int c
, const char *arg
)
375 /* -k: Ignore for FreeBSD compatibility. */
379 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
382 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
385 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
386 warn_areg_zero
= TRUE
;
388 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
391 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
394 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
395 current_mode_mask
= 1 << S390_OPCODE_ESA
;
397 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
399 if (s390_arch_size
== 32)
400 set_highgprs_p
= TRUE
;
401 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
404 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
406 current_cpu
= s390_parse_cpu (arg
+ 5, ¤t_flags
, FALSE
);
407 if (current_cpu
== S390_OPCODE_MAXCPU
)
409 as_bad (_("invalid switch -m%s"), arg
);
416 as_bad (_("invalid switch -m%s"), arg
);
422 /* Option -A is deprecated. Still available for compatibility. */
423 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
424 current_cpu
= S390_OPCODE_G5
;
425 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
426 current_cpu
= S390_OPCODE_Z900
;
428 as_bad (_("invalid architecture -A%s"), arg
);
431 /* -V: SVR4 argument to print version ID. */
436 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
437 should be emitted or not. FIXME: Not implemented. */
449 md_show_usage (FILE *stream
)
451 fprintf (stream
, _("\
453 -mregnames Allow symbolic names for registers\n\
454 -mwarn-areg-zero Warn about zero base/index registers\n\
455 -mno-regnames Do not allow symbolic names for registers\n\
456 -m31 Set file format to 31 bit format\n\
457 -m64 Set file format to 64 bit format\n"));
458 fprintf (stream
, _("\
459 -V print assembler version number\n\
460 -Qy, -Qn ignored\n"));
463 /* Generate the hash table mapping mnemonics to struct s390_opcode.
464 This table is built at startup and whenever the CPU level is
465 changed using .machine. */
468 s390_setup_opcodes (void)
470 const struct s390_opcode
*op
;
471 const struct s390_opcode
*op_end
;
472 bfd_boolean dup_insn
= FALSE
;
475 if (s390_opcode_hash
!= NULL
)
476 hash_die (s390_opcode_hash
);
478 /* Insert the opcodes into a hash table. */
479 s390_opcode_hash
= hash_new ();
481 op_end
= s390_opcodes
+ s390_num_opcodes
;
482 for (op
= s390_opcodes
; op
< op_end
; op
++)
486 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
488 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
493 if ((op
->modes
& current_mode_mask
) == 0)
495 else if ((op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
) == 0)
497 /* Opcodes that do not belong to a specific facility are enabled if
498 present in the selected cpu. */
499 use_opcode
= (op
->min_cpu
<= current_cpu
);
505 /* Opcodes of a specific facility are enabled if the facility is
506 enabled. Note: only some facilities are represented as flags. */
507 f
= (op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
);
508 use_opcode
= ((f
& current_flags
) == f
);
512 retval
= hash_insert (s390_opcode_hash
, op
->name
, (void *) op
);
513 if (retval
!= (const char *) NULL
)
515 as_bad (_("Internal assembler error for instruction %s"),
521 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
529 /* This function is called when the assembler starts up. It is called
530 after the options have been parsed and the output file has been
536 const struct s390_opcode
*op
;
537 const struct s390_opcode
*op_end
;
540 /* Give a warning if the combination -m64-bit and -Aesa is used. */
541 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
542 as_warn (_("The 64 bit file format is used without esame instructions."));
544 s390_cie_data_alignment
= -s390_arch_size
/ 8;
546 /* Set the ELF flags if desired. */
548 bfd_set_private_flags (stdoutput
, s390_flags
);
550 /* Insert the opcode formats into a hash table. */
551 s390_opformat_hash
= hash_new ();
553 op_end
= s390_opformats
+ s390_num_opformats
;
554 for (op
= s390_opformats
; op
< op_end
; op
++)
556 retval
= hash_insert (s390_opformat_hash
, op
->name
, (void *) op
);
557 if (retval
!= (const char *) NULL
)
558 as_bad (_("Internal assembler error for instruction format %s"),
562 s390_setup_opcodes ();
564 record_alignment (text_section
, 2);
565 record_alignment (data_section
, 2);
566 record_alignment (bss_section
, 2);
569 /* Called after all assembly has been done. */
573 if (s390_arch_size
== 64)
574 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
576 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
579 /* Insert an operand value into an instruction. */
582 s390_insert_operand (unsigned char *insn
,
583 const struct s390_operand
*operand
,
591 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
595 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
596 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
597 /* Halve PCREL operands. */
598 if (operand
->flags
& S390_OPERAND_PCREL
)
600 /* Check for underflow / overflow. */
601 if (val
< min
|| val
> max
)
604 _("operand out of range (%s not between %ld and %ld)");
607 if (operand
->flags
& S390_OPERAND_PCREL
)
613 sprint_value (buf
, val
);
614 if (file
== (char *) NULL
)
615 as_bad (err
, buf
, (int) min
, (int) max
);
617 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
620 /* val is ok, now restrict it to operand->bits bits. */
621 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
622 /* val is restrict, now check for special case. */
623 if (operand
->bits
== 20 && operand
->shift
== 20)
624 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
630 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
632 uval
= (addressT
) val
;
634 /* Vector register operands have an additional bit in the RXB
636 if (operand
->flags
& S390_OPERAND_VR
)
637 max
= (max
<< 1) | 1;
639 /* Length x in an instructions has real length x+1. */
640 if (operand
->flags
& S390_OPERAND_LENGTH
)
642 /* Check for underflow / overflow. */
643 if (uval
< min
|| uval
> max
)
645 if (operand
->flags
& S390_OPERAND_LENGTH
)
652 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
658 if (operand
->flags
& S390_OPERAND_VR
)
660 /* Insert the extra bit into the RXB field. */
661 switch (operand
->shift
)
664 insn
[4] |= (uval
& 0x10) >> 1;
667 insn
[4] |= (uval
& 0x10) >> 2;
670 insn
[4] |= (uval
& 0x10) >> 3;
673 insn
[4] |= (uval
& 0x10) >> 4;
679 if (operand
->flags
& S390_OPERAND_OR1
)
681 if (operand
->flags
& S390_OPERAND_OR2
)
683 if (operand
->flags
& S390_OPERAND_OR8
)
686 /* Duplicate the operand at bit pos 12 to 16. */
687 if (operand
->flags
& S390_OPERAND_CP16
)
689 /* Copy VR operand at bit pos 12 to bit pos 16. */
690 insn
[2] |= uval
<< 4;
691 /* Copy the flag in the RXB field. */
692 insn
[4] |= (insn
[4] & 4) >> 1;
695 /* Insert fragments of the operand byte for byte. */
696 offset
= operand
->shift
+ operand
->bits
;
697 uval
<<= (-offset
) & 7;
698 insn
+= (offset
- 1) / 8;
710 bfd_reloc_code_real_type reloc
;
713 /* Parse tls marker and return the desired relocation. */
714 static bfd_reloc_code_real_type
715 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
717 static struct map_tls mapping
[] =
719 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
720 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
721 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
722 { NULL
, 0, BFD_RELOC_UNUSED
}
732 return BFD_RELOC_UNUSED
;
735 while (ISIDNUM (*str
))
739 return BFD_RELOC_UNUSED
;
741 orig_line
= input_line_pointer
;
742 input_line_pointer
= str
;
744 str
= input_line_pointer
;
745 if (&input_line_pointer
!= str_p
)
746 input_line_pointer
= orig_line
;
748 if (exp_p
->X_op
!= O_symbol
)
749 return BFD_RELOC_UNUSED
;
751 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
752 if (len
== ptr
->length
753 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
755 /* Found a matching tls suffix. */
759 return BFD_RELOC_UNUSED
;
762 /* Structure used to hold suffixes. */
773 ELF_SUFFIX_TLS_GOTIE
,
785 elf_suffix_type suffix
;
789 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
790 static elf_suffix_type
791 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
793 static struct map_bfd mapping
[] =
795 { "got", 3, ELF_SUFFIX_GOT
},
796 { "got12", 5, ELF_SUFFIX_GOT
},
797 { "plt", 3, ELF_SUFFIX_PLT
},
798 { "gotent", 6, ELF_SUFFIX_GOTENT
},
799 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
800 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
801 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
802 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
803 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
804 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
805 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
806 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
807 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
808 { NULL
, 0, ELF_SUFFIX_NONE
}
817 return ELF_SUFFIX_NONE
;
820 while (ISALNUM (*str
))
824 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
825 if (len
== ptr
->length
826 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
828 if (exp_p
->X_add_number
!= 0)
829 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
830 ptr
->string
, ptr
->string
);
831 /* Now check for identifier@suffix+constant. */
832 if (*str
== '-' || *str
== '+')
834 char *orig_line
= input_line_pointer
;
837 input_line_pointer
= str
;
838 expression (&new_exp
);
840 switch (new_exp
.X_op
)
842 case O_constant
: /* X_add_number (a constant expression). */
843 exp_p
->X_add_number
+= new_exp
.X_add_number
;
844 str
= input_line_pointer
;
846 case O_symbol
: /* X_add_symbol + X_add_number. */
847 /* this case is used for e.g. xyz@PLT+.Label. */
848 exp_p
->X_add_number
+= new_exp
.X_add_number
;
849 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
851 str
= input_line_pointer
;
853 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
854 /* this case is used for e.g. xyz@PLT-.Label. */
855 exp_p
->X_add_number
+= new_exp
.X_add_number
;
856 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
857 exp_p
->X_op
= O_subtract
;
858 str
= input_line_pointer
;
864 /* If s390_elf_suffix has not been called with
865 &input_line_pointer as first parameter, we have
866 clobbered the input_line_pointer. We have to
868 if (&input_line_pointer
!= str_p
)
869 input_line_pointer
= orig_line
;
875 return BFD_RELOC_UNUSED
;
878 /* Structure used to hold a literal pool entry. */
881 struct s390_lpe
*next
;
883 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
884 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
886 bfd_reloc_code_real_type reloc
;
890 static struct s390_lpe
*lpe_free_list
= NULL
;
891 static struct s390_lpe
*lpe_list
= NULL
;
892 static struct s390_lpe
*lpe_list_tail
= NULL
;
893 static symbolS
*lp_sym
= NULL
;
894 static int lp_count
= 0;
895 static int lpe_count
= 0;
898 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
900 if (exp1
->X_op
!= exp2
->X_op
)
905 case O_constant
: /* X_add_number must be equal. */
907 return exp1
->X_add_number
== exp2
->X_add_number
;
910 as_bad (_("Can't handle O_big in s390_exp_compare"));
912 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
917 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
918 && (exp1
->X_add_number
== exp2
->X_add_number
);
920 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
925 case O_bit_inclusive_or
:
927 case O_bit_exclusive_or
:
939 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
940 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
941 && (exp1
->X_add_number
== exp2
->X_add_number
);
947 /* Test for @lit and if its present make an entry in the literal pool and
948 modify the current expression to be an offset into the literal pool. */
949 static elf_suffix_type
950 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
952 bfd_reloc_code_real_type reloc
;
956 struct s390_lpe
*lpe
;
960 return suffix
; /* No modification. */
962 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
964 while (ISALNUM (*str
))
967 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
968 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
969 return suffix
; /* no modification */
970 nbytes
= ident
[3] - '0';
972 reloc
= BFD_RELOC_UNUSED
;
973 if (suffix
== ELF_SUFFIX_GOT
)
976 reloc
= BFD_RELOC_390_GOT16
;
977 else if (nbytes
== 4)
978 reloc
= BFD_RELOC_32_GOT_PCREL
;
979 else if (nbytes
== 8)
980 reloc
= BFD_RELOC_390_GOT64
;
982 else if (suffix
== ELF_SUFFIX_PLT
)
985 reloc
= BFD_RELOC_390_PLT32
;
986 else if (nbytes
== 8)
987 reloc
= BFD_RELOC_390_PLT64
;
990 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
991 as_bad (_("Invalid suffix for literal pool entry"));
993 /* Search the pool if the new entry is a duplicate. */
994 if (exp_p
->X_op
== O_big
)
996 /* Special processing for big numbers. */
997 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
999 if (lpe
->ex
.X_op
== O_big
)
1001 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
1003 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
1004 sizeof (FLONUM_TYPE
)) == 0)
1007 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
1009 if (memcmp (generic_bignum
, lpe
->bignum
,
1010 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
1018 /* Processing for 'normal' data types. */
1019 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1020 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
1021 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
1027 /* A new literal. */
1028 if (lpe_free_list
!= NULL
)
1030 lpe
= lpe_free_list
;
1031 lpe_free_list
= lpe_free_list
->next
;
1035 lpe
= XNEW (struct s390_lpe
);
1040 if (exp_p
->X_op
== O_big
)
1042 if (exp_p
->X_add_number
<= 0)
1043 lpe
->floatnum
= generic_floating_point_number
;
1044 else if (exp_p
->X_add_number
<= 4)
1045 memcpy (lpe
->bignum
, generic_bignum
,
1046 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1048 as_bad (_("Big number is too big"));
1051 lpe
->nbytes
= nbytes
;
1053 /* Literal pool name defined ? */
1056 sprintf (tmp_name
, ".L\001%i", lp_count
);
1057 lp_sym
= symbol_make (tmp_name
);
1060 /* Make name for literal pool entry. */
1061 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1063 lpe
->sym
= symbol_make (tmp_name
);
1065 /* Add to literal pool list. */
1067 if (lpe_list_tail
!= NULL
)
1069 lpe_list_tail
->next
= lpe
;
1070 lpe_list_tail
= lpe
;
1073 lpe_list
= lpe_list_tail
= lpe
;
1076 /* Now change exp_p to the offset into the literal pool.
1077 Thats the expression: .L^Ax^By-.L^Ax */
1078 exp_p
->X_add_symbol
= lpe
->sym
;
1079 exp_p
->X_op_symbol
= lp_sym
;
1080 exp_p
->X_op
= O_subtract
;
1081 exp_p
->X_add_number
= 0;
1085 /* We change the suffix type to ELF_SUFFIX_NONE, because
1086 the difference of two local labels is just a number. */
1087 return ELF_SUFFIX_NONE
;
1090 /* Like normal .long/.short/.word, except support @got, etc.
1091 clobbers input_line_pointer, checks end-of-line. */
1093 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
1096 elf_suffix_type suffix
;
1098 if (is_it_end_of_statement ())
1100 demand_empty_rest_of_line ();
1108 if (exp
.X_op
== O_symbol
1109 && *input_line_pointer
== '@'
1110 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1112 bfd_reloc_code_real_type reloc
;
1113 reloc_howto_type
*reloc_howto
;
1119 static bfd_reloc_code_real_type tab2
[] =
1121 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1122 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1123 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1124 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1125 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1126 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1127 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1128 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1129 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1130 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1131 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1132 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1133 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1135 reloc
= tab2
[suffix
];
1137 else if (nbytes
== 4)
1139 static bfd_reloc_code_real_type tab4
[] =
1141 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1142 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1143 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1144 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1145 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1146 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1147 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1148 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1149 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1150 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1151 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1152 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1153 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1155 reloc
= tab4
[suffix
];
1157 else if (nbytes
== 8)
1159 static bfd_reloc_code_real_type tab8
[] =
1161 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1162 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1163 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1164 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1165 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1166 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1167 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1168 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1169 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1170 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1171 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1172 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1173 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1175 reloc
= tab8
[suffix
];
1178 reloc
= BFD_RELOC_UNUSED
;
1180 if (reloc
!= BFD_RELOC_UNUSED
1181 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1183 size
= bfd_get_reloc_size (reloc_howto
);
1185 as_bad (_("%s relocations do not fit in %d bytes"),
1186 reloc_howto
->name
, nbytes
);
1187 where
= frag_more (nbytes
);
1188 md_number_to_chars (where
, 0, size
);
1189 /* To make fixup_segment do the pc relative conversion the
1190 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1191 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1192 size
, &exp
, FALSE
, reloc
);
1195 as_bad (_("relocation not applicable"));
1198 emit_expr (&exp
, (unsigned int) nbytes
);
1200 while (*input_line_pointer
++ == ',');
1202 input_line_pointer
--; /* Put terminator back into stream. */
1203 demand_empty_rest_of_line ();
1206 /* We need to keep a list of fixups. We can't simply generate them as
1207 we go, because that would require us to first create the frag, and
1208 that would screw up references to ``.''. */
1214 bfd_reloc_code_real_type reloc
;
1217 #define MAX_INSN_FIXUPS (4)
1219 /* This routine is called for each instruction to be assembled. */
1222 md_gather_operands (char *str
,
1223 unsigned char *insn
,
1224 const struct s390_opcode
*opcode
)
1226 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1227 const struct s390_operand
*operand
;
1228 const unsigned char *opindex_ptr
;
1230 elf_suffix_type suffix
;
1231 bfd_reloc_code_real_type reloc
;
1236 while (ISSPACE (*str
))
1241 /* Gather the operands. */
1243 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1247 operand
= s390_operands
+ *opindex_ptr
;
1249 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM
) && *str
== '\0')
1251 /* Optional parameters might need to be ORed with a
1252 value so calling s390_insert_operand is needed. */
1253 s390_insert_operand (insn
, operand
, 0, NULL
, 0);
1257 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1259 /* We do an early skip. For D(X,B) constructions the index
1260 register is skipped (X is optional). For D(L,B) the base
1261 register will be the skipped operand, because L is NOT
1267 /* Gather the operand. */
1268 hold
= input_line_pointer
;
1269 input_line_pointer
= str
;
1271 /* Parse the operand. */
1272 if (! register_name (&ex
))
1275 str
= input_line_pointer
;
1276 input_line_pointer
= hold
;
1278 /* Write the operand to the insn. */
1279 if (ex
.X_op
== O_illegal
)
1280 as_bad (_("illegal operand"));
1281 else if (ex
.X_op
== O_absent
)
1283 /* No operands, check if all operands can be skipped. */
1284 while (*opindex_ptr
!= 0 && operand
->flags
& S390_OPERAND_OPTIONAL
)
1286 if (operand
->flags
& S390_OPERAND_DISP
)
1288 /* An optional displacement makes the whole D(X,B)
1289 D(L,B) or D(B) block optional. */
1291 operand
= s390_operands
+ *(++opindex_ptr
);
1292 } while (!(operand
->flags
& S390_OPERAND_BASE
));
1294 operand
= s390_operands
+ *(++opindex_ptr
);
1296 if (opindex_ptr
[0] == '\0')
1298 as_bad (_("missing operand"));
1300 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1302 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1304 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1306 /* We need to generate a fixup for the
1307 expression returned by s390_lit_suffix. */
1308 if (fc
>= MAX_INSN_FIXUPS
)
1309 as_fatal (_("too many fixups"));
1310 fixups
[fc
].exp
= ex
;
1311 fixups
[fc
].opindex
= *opindex_ptr
;
1312 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1317 if ((operand
->flags
& S390_OPERAND_LENGTH
)
1318 && ex
.X_op
!= O_constant
)
1319 as_fatal (_("invalid length field specified"));
1320 if ((operand
->flags
& S390_OPERAND_INDEX
)
1321 && ex
.X_add_number
== 0
1323 as_warn (_("index register specified but zero"));
1324 if ((operand
->flags
& S390_OPERAND_BASE
)
1325 && ex
.X_add_number
== 0
1327 as_warn (_("base register specified but zero"));
1328 if ((operand
->flags
& S390_OPERAND_GPR
)
1329 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1330 && (ex
.X_add_number
& 1))
1331 as_fatal (_("odd numbered general purpose register specified as "
1333 if ((operand
->flags
& S390_OPERAND_FPR
)
1334 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1335 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1336 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1337 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1338 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1339 as_fatal (_("invalid floating point register pair. Valid fp "
1340 "register pair operands are 0, 1, 4, 5, 8, 9, "
1342 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1347 suffix
= s390_elf_suffix (&str
, &ex
);
1348 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1349 reloc
= BFD_RELOC_UNUSED
;
1351 if (suffix
== ELF_SUFFIX_GOT
)
1353 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1354 (operand
->bits
== 12))
1355 reloc
= BFD_RELOC_390_GOT12
;
1356 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1357 (operand
->bits
== 20))
1358 reloc
= BFD_RELOC_390_GOT20
;
1359 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1360 && (operand
->bits
== 16))
1361 reloc
= BFD_RELOC_390_GOT16
;
1362 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1363 && (operand
->bits
== 32))
1364 reloc
= BFD_RELOC_390_GOTENT
;
1366 else if (suffix
== ELF_SUFFIX_PLT
)
1368 if ((operand
->flags
& S390_OPERAND_PCREL
)
1369 && (operand
->bits
== 12))
1370 reloc
= BFD_RELOC_390_PLT12DBL
;
1371 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1372 && (operand
->bits
== 16))
1373 reloc
= BFD_RELOC_390_PLT16DBL
;
1374 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1375 && (operand
->bits
== 24))
1376 reloc
= BFD_RELOC_390_PLT24DBL
;
1377 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1378 && (operand
->bits
== 32))
1379 reloc
= BFD_RELOC_390_PLT32DBL
;
1381 else if (suffix
== ELF_SUFFIX_GOTENT
)
1383 if ((operand
->flags
& S390_OPERAND_PCREL
)
1384 && (operand
->bits
== 32))
1385 reloc
= BFD_RELOC_390_GOTENT
;
1387 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1389 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1390 && (operand
->bits
== 16))
1391 reloc
= BFD_RELOC_16_GOTOFF
;
1393 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1395 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1396 && (operand
->bits
== 16))
1397 reloc
= BFD_RELOC_390_PLTOFF16
;
1399 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1401 if ((operand
->flags
& S390_OPERAND_DISP
)
1402 && (operand
->bits
== 12))
1403 reloc
= BFD_RELOC_390_GOTPLT12
;
1404 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1405 && (operand
->bits
== 16))
1406 reloc
= BFD_RELOC_390_GOTPLT16
;
1407 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1408 && (operand
->bits
== 32))
1409 reloc
= BFD_RELOC_390_GOTPLTENT
;
1411 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1413 if ((operand
->flags
& S390_OPERAND_DISP
)
1414 && (operand
->bits
== 12))
1415 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1416 else if ((operand
->flags
& S390_OPERAND_DISP
)
1417 && (operand
->bits
== 20))
1418 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1420 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1422 if ((operand
->flags
& S390_OPERAND_PCREL
)
1423 && (operand
->bits
== 32))
1424 reloc
= BFD_RELOC_390_TLS_IEENT
;
1427 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1428 as_bad (_("invalid operand suffix"));
1429 /* We need to generate a fixup of type 'reloc' for this
1431 if (fc
>= MAX_INSN_FIXUPS
)
1432 as_fatal (_("too many fixups"));
1433 fixups
[fc
].exp
= ex
;
1434 fixups
[fc
].opindex
= *opindex_ptr
;
1435 fixups
[fc
].reloc
= reloc
;
1439 /* Check the next character. The call to expression has advanced
1440 str past any whitespace. */
1441 if (operand
->flags
& S390_OPERAND_DISP
)
1443 /* After a displacement a block in parentheses can start. */
1446 /* Check if parenthesized block can be skipped. If the next
1447 operand is neiter an optional operand nor a base register
1448 then we have a syntax error. */
1449 operand
= s390_operands
+ *(++opindex_ptr
);
1450 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1451 as_bad (_("syntax error; missing '(' after displacement"));
1453 /* Ok, skip all operands until S390_OPERAND_BASE. */
1454 while (!(operand
->flags
& S390_OPERAND_BASE
))
1455 operand
= s390_operands
+ *(++opindex_ptr
);
1457 /* If there is a next operand it must be separated by a comma. */
1458 if (opindex_ptr
[1] != '\0')
1462 while (opindex_ptr
[1] != '\0')
1464 operand
= s390_operands
+ *(++opindex_ptr
);
1465 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1467 as_bad (_("syntax error; expected ,"));
1477 /* We found an opening parentheses. */
1479 for (f
= str
; *f
!= '\0'; f
++)
1480 if (*f
== ',' || *f
== ')')
1482 /* If there is no comma until the closing parentheses OR
1483 there is a comma right after the opening parentheses,
1484 we have to skip optional operands. */
1485 if (*f
== ',' && f
== str
)
1487 /* comma directly after '(' ? */
1492 skip_optional
= (*f
!= ',');
1495 else if (operand
->flags
& S390_OPERAND_BASE
)
1497 /* After the base register the parenthesed block ends. */
1499 as_bad (_("syntax error; missing ')' after base register"));
1501 /* If there is a next operand it must be separated by a comma. */
1502 if (opindex_ptr
[1] != '\0')
1506 while (opindex_ptr
[1] != '\0')
1508 operand
= s390_operands
+ *(++opindex_ptr
);
1509 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1511 as_bad (_("syntax error; expected ,"));
1521 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1522 of D(L,B). In this case the base register has to be skipped. */
1525 operand
= s390_operands
+ *(++opindex_ptr
);
1527 if (!(operand
->flags
& S390_OPERAND_BASE
))
1528 as_bad (_("syntax error; ')' not allowed here"));
1532 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM
) && *str
== '\0')
1535 /* If there is a next operand it must be separated by a comma. */
1536 if (opindex_ptr
[1] != '\0')
1540 while (opindex_ptr
[1] != '\0')
1542 operand
= s390_operands
+ *(++opindex_ptr
);
1543 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1545 as_bad (_("syntax error; expected ,"));
1555 while (ISSPACE (*str
))
1558 /* Check for tls instruction marker. */
1559 reloc
= s390_tls_suffix (&str
, &ex
);
1560 if (reloc
!= BFD_RELOC_UNUSED
)
1562 /* We need to generate a fixup of type 'reloc' for this
1564 if (fc
>= MAX_INSN_FIXUPS
)
1565 as_fatal (_("too many fixups"));
1566 fixups
[fc
].exp
= ex
;
1567 fixups
[fc
].opindex
= -1;
1568 fixups
[fc
].reloc
= reloc
;
1576 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1578 as_bad (_("junk at end of line: `%s'"), str
);
1579 if (linefeed
!= NULL
)
1583 /* Write out the instruction. */
1584 f
= frag_more (opcode
->oplen
);
1585 memcpy (f
, insn
, opcode
->oplen
);
1586 dwarf2_emit_insn (opcode
->oplen
);
1588 /* Create any fixups. At this point we do not use a
1589 bfd_reloc_code_real_type, but instead just use the
1590 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1591 handle fixups for any operand type, although that is admittedly
1592 not a very exciting feature. We pick a BFD reloc type in
1594 for (i
= 0; i
< fc
; i
++)
1597 if (fixups
[i
].opindex
< 0)
1599 /* Create tls instruction marker relocation. */
1600 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1601 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1605 operand
= s390_operands
+ fixups
[i
].opindex
;
1607 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1609 reloc_howto_type
*reloc_howto
;
1613 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1617 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1619 if (size
< 1 || size
> 4)
1622 fixP
= fix_new_exp (frag_now
,
1623 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1624 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1626 /* Turn off overflow checking in fixup_segment. This is necessary
1627 because fixup_segment will signal an overflow for large 4 byte
1628 quantities for GOT12 relocations. */
1629 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1630 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1631 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1632 fixP
->fx_no_overflow
= 1;
1635 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1636 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1637 ((bfd_reloc_code_real_type
)
1638 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1643 /* This routine is called for each instruction to be assembled. */
1646 md_assemble (char *str
)
1648 const struct s390_opcode
*opcode
;
1649 unsigned char insn
[6];
1652 /* Get the opcode. */
1653 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1658 /* Look up the opcode in the hash table. */
1659 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1660 if (opcode
== (const struct s390_opcode
*) NULL
)
1662 as_bad (_("Unrecognized opcode: `%s'"), str
);
1665 else if (!(opcode
->modes
& current_mode_mask
))
1667 as_bad (_("Opcode %s not available in this mode"), str
);
1670 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1671 md_gather_operands (s
, insn
, opcode
);
1674 #ifndef WORKING_DOT_WORD
1675 /* Handle long and short jumps. We don't support these */
1677 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1679 addressT from_addr
, to_addr
;
1687 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1689 addressT from_addr
, to_addr
;
1698 s390_bss (int ignore ATTRIBUTE_UNUSED
)
1700 /* We don't support putting frags in the BSS segment, we fake it
1701 by marking in_bss, then looking at s_skip for clues. */
1703 subseg_set (bss_section
, 0);
1704 demand_empty_rest_of_line ();
1707 /* Pseudo-op handling. */
1710 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1713 const struct s390_opcode
*opformat
;
1714 unsigned char insn
[6];
1717 /* Get the opcode format. */
1718 s
= input_line_pointer
;
1719 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1722 as_bad (_("Invalid .insn format\n"));
1725 /* Look up the opcode in the hash table. */
1726 opformat
= (struct s390_opcode
*)
1727 hash_find (s390_opformat_hash
, input_line_pointer
);
1728 if (opformat
== (const struct s390_opcode
*) NULL
)
1730 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1733 input_line_pointer
= s
;
1735 if (exp
.X_op
== O_constant
)
1737 if ( ( opformat
->oplen
== 6
1738 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1739 || ( opformat
->oplen
== 4
1740 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1741 || ( opformat
->oplen
== 2
1742 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1743 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1745 as_bad (_("Invalid .insn format\n"));
1747 else if (exp
.X_op
== O_big
)
1749 if (exp
.X_add_number
> 0
1750 && opformat
->oplen
== 6
1751 && generic_bignum
[3] == 0)
1753 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1754 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1755 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1758 as_bad (_("Invalid .insn format\n"));
1761 as_bad (_("second operand of .insn not a constant\n"));
1763 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1764 as_bad (_("missing comma after insn constant\n"));
1766 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1768 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1772 demand_empty_rest_of_line ();
1775 /* The .byte pseudo-op. This is similar to the normal .byte
1776 pseudo-op, but it can also take a single ASCII string. */
1779 s390_byte (int ignore ATTRIBUTE_UNUSED
)
1781 if (*input_line_pointer
!= '\"')
1787 /* Gather characters. A real double quote is doubled. Unusual
1788 characters are not permitted. */
1789 ++input_line_pointer
;
1794 c
= *input_line_pointer
++;
1798 if (*input_line_pointer
!= '\"')
1800 ++input_line_pointer
;
1803 FRAG_APPEND_1_CHAR (c
);
1806 demand_empty_rest_of_line ();
1809 /* The .ltorg pseudo-op.This emits all literals defined since the last
1810 .ltorg or the invocation of gas. Literals are defined with the
1814 s390_literals (int ignore ATTRIBUTE_UNUSED
)
1816 struct s390_lpe
*lpe
;
1818 if (lp_sym
== NULL
|| lpe_count
== 0)
1819 return; /* Nothing to be done. */
1821 /* Emit symbol for start of literal pool. */
1822 S_SET_SEGMENT (lp_sym
, now_seg
);
1823 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1824 lp_sym
->sy_frag
= frag_now
;
1829 lpe_list
= lpe_list
->next
;
1830 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1831 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1832 lpe
->sym
->sy_frag
= frag_now
;
1834 /* Emit literal pool entry. */
1835 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1837 reloc_howto_type
*reloc_howto
=
1838 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1839 int size
= bfd_get_reloc_size (reloc_howto
);
1842 if (size
> lpe
->nbytes
)
1843 as_bad (_("%s relocations do not fit in %d bytes"),
1844 reloc_howto
->name
, lpe
->nbytes
);
1845 where
= frag_more (lpe
->nbytes
);
1846 md_number_to_chars (where
, 0, size
);
1847 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1848 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1852 if (lpe
->ex
.X_op
== O_big
)
1854 if (lpe
->ex
.X_add_number
<= 0)
1855 generic_floating_point_number
= lpe
->floatnum
;
1857 memcpy (generic_bignum
, lpe
->bignum
,
1858 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1860 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1863 lpe
->next
= lpe_free_list
;
1864 lpe_free_list
= lpe
;
1866 lpe_list_tail
= NULL
;
1872 #define MAX_HISTORY 100
1874 /* The .machine pseudo op allows to switch to a different CPU level in
1875 the asm listing. The current CPU setting can be stored on a stack
1876 with .machine push and restored with .machine pop. */
1879 s390_machine (int ignore ATTRIBUTE_UNUSED
)
1882 static struct cpu_history
1887 static int curr_hist
;
1891 if (*input_line_pointer
== '"')
1894 cpu_string
= demand_copy_C_string (&len
);
1900 cpu_string
= input_line_pointer
;
1905 c
= get_symbol_name (&str
);
1906 c
= restore_line_pointer (c
);
1908 ++ input_line_pointer
;
1912 c
= *input_line_pointer
;
1913 *input_line_pointer
= 0;
1914 cpu_string
= xstrdup (cpu_string
);
1915 (void) restore_line_pointer (c
);
1918 if (cpu_string
!= NULL
)
1920 unsigned int new_cpu
= current_cpu
;
1921 unsigned int new_flags
= current_flags
;
1923 if (strcmp (cpu_string
, "push") == 0)
1925 if (cpu_history
== NULL
)
1926 cpu_history
= XNEWVEC (struct cpu_history
, MAX_HISTORY
);
1928 if (curr_hist
>= MAX_HISTORY
)
1929 as_bad (_(".machine stack overflow"));
1932 cpu_history
[curr_hist
].cpu
= current_cpu
;
1933 cpu_history
[curr_hist
].flags
= current_flags
;
1937 else if (strcmp (cpu_string
, "pop") == 0)
1940 as_bad (_(".machine stack underflow"));
1944 new_cpu
= cpu_history
[curr_hist
].cpu
;
1945 new_flags
= cpu_history
[curr_hist
].flags
;
1949 new_cpu
= s390_parse_cpu (cpu_string
, &new_flags
, TRUE
);
1951 if (new_cpu
== S390_OPCODE_MAXCPU
)
1952 as_bad (_("invalid machine `%s'"), cpu_string
);
1954 if (new_cpu
!= current_cpu
|| new_flags
!= current_flags
)
1956 current_cpu
= new_cpu
;
1957 current_flags
= new_flags
;
1958 s390_setup_opcodes ();
1962 demand_empty_rest_of_line ();
1965 /* The .machinemode pseudo op allows to switch to a different
1966 architecture mode in the asm listing. The current architecture
1967 mode setting can be stored on a stack with .machinemode push and
1968 restored with .machinemode pop. */
1971 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
1974 static unsigned int *mode_history
;
1975 static int curr_hist
;
1982 c
= get_symbol_name (&mode_string
);
1983 mode_string
= xstrdup (mode_string
);
1984 (void) restore_line_pointer (c
);
1987 if (mode_string
!= NULL
)
1989 unsigned int old_mode_mask
= current_mode_mask
;
1992 for (p
= mode_string
; *p
!= 0; p
++)
1995 if (strcmp (mode_string
, "push") == 0)
1997 if (mode_history
== NULL
)
1998 mode_history
= XNEWVEC (unsigned int, MAX_HISTORY
);
2000 if (curr_hist
>= MAX_HISTORY
)
2001 as_bad (_(".machinemode stack overflow"));
2003 mode_history
[curr_hist
++] = current_mode_mask
;
2005 else if (strcmp (mode_string
, "pop") == 0)
2008 as_bad (_(".machinemode stack underflow"));
2010 current_mode_mask
= mode_history
[--curr_hist
];
2014 if (strcmp (mode_string
, "esa") == 0)
2015 current_mode_mask
= 1 << S390_OPCODE_ESA
;
2016 else if (strcmp (mode_string
, "zarch") == 0)
2018 if (s390_arch_size
== 32)
2019 set_highgprs_p
= TRUE
;
2020 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2022 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
2023 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2025 as_bad (_("invalid machine mode `%s'"), mode_string
);
2028 if (current_mode_mask
!= old_mode_mask
)
2029 s390_setup_opcodes ();
2032 demand_empty_rest_of_line ();
2038 md_atof (int type
, char *litp
, int *sizep
)
2040 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
2043 /* Align a section (I don't know why this is machine dependent). */
2046 md_section_align (asection
*seg
, valueT addr
)
2048 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2050 return ((addr
+ (1 << align
) - 1) & -(1 << align
));
2053 /* We don't have any form of relaxing. */
2056 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
2057 asection
*seg ATTRIBUTE_UNUSED
)
2063 /* Convert a machine dependent frag. We never generate these. */
2066 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2067 asection
*sec ATTRIBUTE_UNUSED
,
2068 fragS
*fragp ATTRIBUTE_UNUSED
)
2074 md_undefined_symbol (char *name
)
2076 if (*name
== '_' && *(name
+ 1) == 'G'
2077 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
2081 if (symbol_find (name
))
2082 as_bad (_("GOT already in symbol table"));
2083 GOT_symbol
= symbol_new (name
, undefined_section
,
2084 (valueT
) 0, &zero_address_frag
);
2091 /* Functions concerning relocs. */
2093 /* The location from which a PC relative jump should be calculated,
2094 given a PC relative reloc. */
2097 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2099 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2102 /* Here we decide which fixups can be adjusted to make them relative to
2103 the beginning of the section instead of the symbol. Basically we need
2104 to make sure that the dynamic relocations are done correctly, so in
2105 some cases we force the original symbol to be used. */
2107 tc_s390_fix_adjustable (fixS
*fixP
)
2109 /* Don't adjust references to merge sections. */
2110 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
2112 /* adjust_reloc_syms doesn't know about the GOT. */
2113 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
2114 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2115 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
2116 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
2117 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
2118 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
2119 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
2120 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
2121 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
2122 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
2123 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
2124 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
2125 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
2126 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2127 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2128 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2129 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2130 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2131 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2132 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2133 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2134 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2135 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2136 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2137 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2138 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2139 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2140 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2141 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2142 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2143 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2144 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2145 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2146 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2147 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2148 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2149 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2150 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2151 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2152 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2153 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2154 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2155 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2156 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2157 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2158 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2159 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2164 /* Return true if we must always emit a reloc for a type and false if
2165 there is some hope of resolving it at assembly time. */
2167 tc_s390_force_relocation (struct fix
*fixp
)
2169 /* Ensure we emit a relocation for every reference to the global
2170 offset table or to the procedure link table. */
2171 switch (fixp
->fx_r_type
)
2173 case BFD_RELOC_390_GOT12
:
2174 case BFD_RELOC_390_GOT20
:
2175 case BFD_RELOC_32_GOT_PCREL
:
2176 case BFD_RELOC_32_GOTOFF
:
2177 case BFD_RELOC_390_GOTOFF64
:
2178 case BFD_RELOC_390_PLTOFF16
:
2179 case BFD_RELOC_390_PLTOFF32
:
2180 case BFD_RELOC_390_PLTOFF64
:
2181 case BFD_RELOC_390_GOTPC
:
2182 case BFD_RELOC_390_GOT16
:
2183 case BFD_RELOC_390_GOTPCDBL
:
2184 case BFD_RELOC_390_GOT64
:
2185 case BFD_RELOC_390_GOTENT
:
2186 case BFD_RELOC_390_PLT32
:
2187 case BFD_RELOC_390_PLT12DBL
:
2188 case BFD_RELOC_390_PLT16DBL
:
2189 case BFD_RELOC_390_PLT24DBL
:
2190 case BFD_RELOC_390_PLT32DBL
:
2191 case BFD_RELOC_390_PLT64
:
2192 case BFD_RELOC_390_GOTPLT12
:
2193 case BFD_RELOC_390_GOTPLT16
:
2194 case BFD_RELOC_390_GOTPLT20
:
2195 case BFD_RELOC_390_GOTPLT32
:
2196 case BFD_RELOC_390_GOTPLT64
:
2197 case BFD_RELOC_390_GOTPLTENT
:
2203 return generic_force_reloc (fixp
);
2206 /* Apply a fixup to the object code. This is called for all the
2207 fixups we generated by the call to fix_new_exp, above. In the call
2208 above we used a reloc code which was the largest legal reloc code
2209 plus the operand index. Here we undo that to recover the operand
2210 index. At this point all symbol values should be fully resolved,
2211 and we attempt to completely resolve the reloc. If we can not do
2212 that, we determine the correct reloc code and put it back in the
2216 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2219 valueT value
= *valP
;
2221 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2223 if (fixP
->fx_subsy
!= NULL
)
2224 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2225 _("cannot emit relocation %s against subsy symbol %s"),
2226 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2227 S_GET_NAME (fixP
->fx_subsy
));
2229 if (fixP
->fx_addsy
!= NULL
)
2232 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2237 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2239 const struct s390_operand
*operand
;
2242 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2243 operand
= &s390_operands
[opindex
];
2247 /* Insert the fully resolved operand value. */
2248 s390_insert_operand ((unsigned char *) where
, operand
,
2249 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2253 /* Determine a BFD reloc value based on the operand information.
2254 We are only prepared to turn a few of the operands into
2256 fixP
->fx_offset
= value
;
2257 if (operand
->bits
== 12 && operand
->shift
== 20)
2260 fixP
->fx_where
+= 2;
2261 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2263 else if (operand
->bits
== 12 && operand
->shift
== 36)
2266 fixP
->fx_where
+= 4;
2267 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2269 else if (operand
->bits
== 20 && operand
->shift
== 20)
2272 fixP
->fx_where
+= 2;
2273 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2275 else if (operand
->bits
== 8 && operand
->shift
== 8)
2278 fixP
->fx_where
+= 1;
2279 fixP
->fx_r_type
= BFD_RELOC_8
;
2281 else if (operand
->bits
== 12 && operand
->shift
== 12
2282 && (operand
->flags
& S390_OPERAND_PCREL
))
2285 fixP
->fx_where
+= 1;
2286 fixP
->fx_offset
+= 1;
2287 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2289 else if (operand
->bits
== 16 && operand
->shift
== 16)
2292 fixP
->fx_where
+= 2;
2293 if (operand
->flags
& S390_OPERAND_PCREL
)
2295 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2296 fixP
->fx_offset
+= 2;
2299 fixP
->fx_r_type
= BFD_RELOC_16
;
2301 else if (operand
->bits
== 24 && operand
->shift
== 24
2302 && (operand
->flags
& S390_OPERAND_PCREL
))
2305 fixP
->fx_where
+= 3;
2306 fixP
->fx_offset
+= 3;
2307 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2309 else if (operand
->bits
== 32 && operand
->shift
== 16
2310 && (operand
->flags
& S390_OPERAND_PCREL
))
2313 fixP
->fx_where
+= 2;
2314 fixP
->fx_offset
+= 2;
2315 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2322 /* Use expr_symbol_where to see if this is an expression
2324 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2325 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2326 _("unresolved expression that must be resolved"));
2328 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2329 _("unsupported relocation type"));
2336 switch (fixP
->fx_r_type
)
2342 md_number_to_chars (where
, value
, 1);
2344 case BFD_RELOC_390_12
:
2345 case BFD_RELOC_390_GOT12
:
2346 case BFD_RELOC_390_GOTPLT12
:
2347 case BFD_RELOC_390_PC12DBL
:
2348 case BFD_RELOC_390_PLT12DBL
:
2359 mop
= bfd_getb16 ((unsigned char *) where
);
2360 mop
|= (unsigned short) (value
& 0xfff);
2361 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2365 case BFD_RELOC_390_20
:
2366 case BFD_RELOC_390_GOT20
:
2367 case BFD_RELOC_390_GOTPLT20
:
2371 mop
= bfd_getb32 ((unsigned char *) where
);
2372 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2373 (value
& 0xff000) >> 12);
2374 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2379 case BFD_RELOC_GPREL16
:
2380 case BFD_RELOC_16_GOT_PCREL
:
2381 case BFD_RELOC_16_GOTOFF
:
2383 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2384 _("cannot emit PC relative %s relocation%s%s"),
2385 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2386 fixP
->fx_addsy
!= NULL
? " against " : "",
2387 (fixP
->fx_addsy
!= NULL
2388 ? S_GET_NAME (fixP
->fx_addsy
)
2391 md_number_to_chars (where
, value
, 2);
2393 case BFD_RELOC_390_GOT16
:
2394 case BFD_RELOC_390_PLTOFF16
:
2395 case BFD_RELOC_390_GOTPLT16
:
2397 md_number_to_chars (where
, value
, 2);
2399 case BFD_RELOC_390_PC16DBL
:
2400 case BFD_RELOC_390_PLT16DBL
:
2403 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2406 case BFD_RELOC_390_PC24DBL
:
2407 case BFD_RELOC_390_PLT24DBL
:
2414 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2415 mop
|= (unsigned int) (value
& 0xffffff);
2416 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2422 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2424 fixP
->fx_r_type
= BFD_RELOC_32
;
2426 md_number_to_chars (where
, value
, 4);
2428 case BFD_RELOC_32_PCREL
:
2429 case BFD_RELOC_32_BASEREL
:
2430 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2432 md_number_to_chars (where
, value
, 4);
2434 case BFD_RELOC_32_GOT_PCREL
:
2435 case BFD_RELOC_390_PLTOFF32
:
2436 case BFD_RELOC_390_PLT32
:
2437 case BFD_RELOC_390_GOTPLT32
:
2439 md_number_to_chars (where
, value
, 4);
2441 case BFD_RELOC_390_PC32DBL
:
2442 case BFD_RELOC_390_PLT32DBL
:
2443 case BFD_RELOC_390_GOTPCDBL
:
2444 case BFD_RELOC_390_GOTENT
:
2445 case BFD_RELOC_390_GOTPLTENT
:
2448 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2451 case BFD_RELOC_32_GOTOFF
:
2453 md_number_to_chars (where
, value
, sizeof (int));
2456 case BFD_RELOC_390_GOTOFF64
:
2458 md_number_to_chars (where
, value
, 8);
2461 case BFD_RELOC_390_GOT64
:
2462 case BFD_RELOC_390_PLTOFF64
:
2463 case BFD_RELOC_390_PLT64
:
2464 case BFD_RELOC_390_GOTPLT64
:
2466 md_number_to_chars (where
, value
, 8);
2471 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2473 fixP
->fx_r_type
= BFD_RELOC_64
;
2475 md_number_to_chars (where
, value
, 8);
2478 case BFD_RELOC_64_PCREL
:
2479 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2481 md_number_to_chars (where
, value
, 8);
2484 case BFD_RELOC_VTABLE_INHERIT
:
2485 case BFD_RELOC_VTABLE_ENTRY
:
2489 case BFD_RELOC_390_TLS_LOAD
:
2490 case BFD_RELOC_390_TLS_GDCALL
:
2491 case BFD_RELOC_390_TLS_LDCALL
:
2492 case BFD_RELOC_390_TLS_GD32
:
2493 case BFD_RELOC_390_TLS_GD64
:
2494 case BFD_RELOC_390_TLS_GOTIE12
:
2495 case BFD_RELOC_390_TLS_GOTIE20
:
2496 case BFD_RELOC_390_TLS_GOTIE32
:
2497 case BFD_RELOC_390_TLS_GOTIE64
:
2498 case BFD_RELOC_390_TLS_LDM32
:
2499 case BFD_RELOC_390_TLS_LDM64
:
2500 case BFD_RELOC_390_TLS_IE32
:
2501 case BFD_RELOC_390_TLS_IE64
:
2502 case BFD_RELOC_390_TLS_LE32
:
2503 case BFD_RELOC_390_TLS_LE64
:
2504 case BFD_RELOC_390_TLS_LDO32
:
2505 case BFD_RELOC_390_TLS_LDO64
:
2506 case BFD_RELOC_390_TLS_DTPMOD
:
2507 case BFD_RELOC_390_TLS_DTPOFF
:
2508 case BFD_RELOC_390_TLS_TPOFF
:
2509 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2510 /* Fully resolved at link time. */
2512 case BFD_RELOC_390_TLS_IEENT
:
2513 /* Fully resolved at link time. */
2514 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2520 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2522 if (reloc_name
!= NULL
)
2523 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2525 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2529 fixP
->fx_offset
= value
;
2533 /* Generate a reloc for a fixup. */
2536 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2538 bfd_reloc_code_real_type code
;
2541 code
= fixp
->fx_r_type
;
2542 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2544 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2545 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2546 code
= BFD_RELOC_390_GOTPC
;
2547 if (code
== BFD_RELOC_390_PC32DBL
)
2548 code
= BFD_RELOC_390_GOTPCDBL
;
2551 reloc
= XNEW (arelent
);
2552 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
2553 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2554 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2555 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2556 if (reloc
->howto
== NULL
)
2558 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2559 _("cannot represent relocation type %s"),
2560 bfd_get_reloc_code_name (code
));
2561 /* Set howto to a garbage value so that we can keep going. */
2562 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2563 gas_assert (reloc
->howto
!= NULL
);
2565 reloc
->addend
= fixp
->fx_offset
;
2571 s390_cfi_frame_initial_instructions (void)
2573 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2577 tc_s390_regname_to_dw2regnum (char *regname
)
2581 if (regname
[0] != 'c' && regname
[0] != 'a')
2583 regnum
= reg_name_search (regname
);
2584 if (regname
[0] == 'f' && regnum
!= -1)
2587 else if (strcmp (regname
, "ap") == 0)
2589 else if (strcmp (regname
, "cc") == 0)
2595 s390_elf_final_processing (void)
2598 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;