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 /* All facilities are enabled by default. */
45 static unsigned int current_flags
= S390_INSTR_FLAG_FACILITY_MASK
;
46 /* The mode mask default is picked in init_default_arch depending on
48 static unsigned int current_mode_mask
= 0;
50 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
51 for the output file. */
52 static bfd_boolean set_highgprs_p
= FALSE
;
54 /* Whether to use user friendly register names. Default is TRUE. */
55 #ifndef TARGET_REG_NAMES_P
56 #define TARGET_REG_NAMES_P TRUE
59 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
61 /* Set to TRUE if we want to warn about zero base/index registers. */
62 static bfd_boolean warn_areg_zero
= FALSE
;
64 /* Generic assembler global variables which must be defined by all
67 const char comment_chars
[] = "#";
69 /* Characters which start a comment at the beginning of a line. */
70 const char line_comment_chars
[] = "#";
72 /* Characters which may be used to separate multiple commands on a
74 const char line_separator_chars
[] = ";";
76 /* Characters which are used to indicate an exponent in a floating
78 const char EXP_CHARS
[] = "eE";
80 /* Characters which mean that a number is a floating point constant,
82 const char FLT_CHARS
[] = "dD";
84 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
85 int s390_cie_data_alignment
;
87 /* The target specific pseudo-ops which we support. */
89 /* Define the prototypes for the pseudo-ops */
90 static void s390_byte (int);
91 static void s390_elf_cons (int);
92 static void s390_bss (int);
93 static void s390_insn (int);
94 static void s390_literals (int);
95 static void s390_machine (int);
96 static void s390_machinemode (int);
98 const pseudo_typeS md_pseudo_table
[] =
100 { "align", s_align_bytes
, 0 },
101 /* Pseudo-ops which must be defined. */
102 { "bss", s390_bss
, 0 },
103 { "insn", s390_insn
, 0 },
104 /* Pseudo-ops which must be overridden. */
105 { "byte", s390_byte
, 0 },
106 { "short", s390_elf_cons
, 2 },
107 { "long", s390_elf_cons
, 4 },
108 { "quad", s390_elf_cons
, 8 },
109 { "ltorg", s390_literals
, 0 },
110 { "string", stringer
, 8 + 1 },
111 { "machine", s390_machine
, 0 },
112 { "machinemode", s390_machinemode
, 0 },
116 /* Given NAME, find the register number associated with that name, return
117 the integer value associated with the given name or -1 on failure. */
120 reg_name_search (const char *name
)
124 if (strcasecmp (name
, "lit") == 0)
127 if (strcasecmp (name
, "sp") == 0)
130 if (name
[0] != 'a' && name
[0] != 'c' && name
[0] != 'f'
131 && name
[0] != 'r' && name
[0] != 'v')
134 if (ISDIGIT (name
[1]))
137 if (ISDIGIT (name
[2]))
138 val
= val
* 10 + name
[2] - '0';
141 if ((name
[0] != 'v' && val
> 15) || val
> 31)
149 * Summary of register_name().
151 * in: Input_line_pointer points to 1st char of operand.
153 * out: A expressionS.
154 * The operand may have been a register: in this case, X_op == O_register,
155 * X_add_number is set to the register number, and truth is returned.
156 * Input_line_pointer->(next non-blank) char after operand, or is in its
161 register_name (expressionS
*expressionP
)
168 /* Find the spelling of the operand. */
169 start
= name
= input_line_pointer
;
170 if (name
[0] == '%' && ISALPHA (name
[1]))
171 name
= ++input_line_pointer
;
175 c
= get_symbol_name (&name
);
176 reg_number
= reg_name_search (name
);
178 /* Put back the delimiting char. */
179 (void) restore_line_pointer (c
);
181 /* Look to see if it's in the register table. */
184 expressionP
->X_op
= O_register
;
185 expressionP
->X_add_number
= reg_number
;
187 /* Make the rest nice. */
188 expressionP
->X_add_symbol
= NULL
;
189 expressionP
->X_op_symbol
= NULL
;
193 /* Reset the line as if we had not done anything. */
194 input_line_pointer
= start
;
198 /* Local variables. */
200 /* Opformat hash table. */
201 static struct hash_control
*s390_opformat_hash
;
203 /* Opcode hash table. */
204 static struct hash_control
*s390_opcode_hash
= NULL
;
206 /* Flags to set in the elf header */
207 static flagword s390_flags
= 0;
209 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
211 #ifndef WORKING_DOT_WORD
212 int md_short_jump_size
= 4;
213 int md_long_jump_size
= 4;
216 const char *md_shortopts
= "A:m:kVQ:";
217 struct option md_longopts
[] = {
218 {NULL
, no_argument
, NULL
, 0}
220 size_t md_longopts_size
= sizeof (md_longopts
);
222 /* Initialize the default opcode arch and word size from the default
223 architecture name if not specified by an option. */
225 init_default_arch (void)
227 if (strcmp (default_arch
, "s390") == 0)
229 if (s390_arch_size
== 0)
232 else if (strcmp (default_arch
, "s390x") == 0)
234 if (s390_arch_size
== 0)
238 as_fatal (_("Invalid default architecture, broken assembler."));
240 if (current_mode_mask
== 0)
242 /* Default to z/Architecture mode if the CPU supports it. */
243 if (current_cpu
< S390_OPCODE_Z900
)
244 current_mode_mask
= 1 << S390_OPCODE_ESA
;
246 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
250 /* Called by TARGET_FORMAT. */
252 s390_target_format (void)
254 /* We don't get a chance to initialize anything before we're called,
255 so handle that now. */
256 init_default_arch ();
258 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
261 /* Map a cpu string ARG as given with -march= or .machine to the respective
262 enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name
263 can be followed by a list of cpu facility flags each beginning with the
264 character '+'. The active cpu flags are returned through *RET_FLAGS.
265 In case of an error, S390_OPCODE_MAXCPU is returned. */
268 s390_parse_cpu (const char * arg
,
269 unsigned int * ret_flags
,
270 bfd_boolean allow_extensions
)
277 } cpu_table
[S390_OPCODE_MAXCPU
] =
279 { STRING_COMMA_LEN ("g5"), 0 },
280 { STRING_COMMA_LEN ("g6"), 0 },
281 { STRING_COMMA_LEN ("z900"), 0 },
282 { STRING_COMMA_LEN ("z990"), 0 },
283 { STRING_COMMA_LEN ("z9-109"), 0 },
284 { STRING_COMMA_LEN ("z9-ec"), 0 },
285 { STRING_COMMA_LEN ("z10"), 0 },
286 { STRING_COMMA_LEN ("z196"), 0 },
287 { STRING_COMMA_LEN ("zEC12"), S390_INSTR_FLAG_HTM
},
288 { STRING_COMMA_LEN ("z13"), S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
}
297 { "htm", S390_INSTR_FLAG_HTM
, TRUE
},
298 { "nohtm", S390_INSTR_FLAG_HTM
, FALSE
},
299 { "vx", S390_INSTR_FLAG_VX
, TRUE
},
300 { "novx", S390_INSTR_FLAG_VX
, FALSE
}
305 icpu
= S390_OPCODE_MAXCPU
;
306 if (strncmp (arg
, "all", 3) == 0 && (arg
[3] == 0 || arg
[3] == '+'))
308 icpu
= S390_OPCODE_MAXCPU
- 1;
313 for (icpu
= 0; icpu
< S390_OPCODE_MAXCPU
; icpu
++)
317 l
= cpu_table
[icpu
].len
;
318 if (strncmp (arg
, cpu_table
[icpu
].name
, l
) == 0
319 && (arg
[l
] == 0 || arg
[l
] == '+'))
327 ilp_bak
= input_line_pointer
;
328 if (icpu
!= S390_OPCODE_MAXCPU
)
330 input_line_pointer
= (char *) arg
;
331 *ret_flags
= (cpu_table
[icpu
].flags
& S390_INSTR_FLAG_FACILITY_MASK
);
333 while (*input_line_pointer
== '+' && allow_extensions
)
339 input_line_pointer
++;
340 c
= get_symbol_name (&sym
);
341 for (iflag
= 0; iflag
< ARRAY_SIZE (cpu_flags
); iflag
++)
343 if (strcmp (sym
, cpu_flags
[iflag
].name
) == 0)
345 if (cpu_flags
[iflag
].on
)
346 *ret_flags
|= cpu_flags
[iflag
].mask
;
348 *ret_flags
&= ~cpu_flags
[iflag
].mask
;
352 if (iflag
== ARRAY_SIZE (cpu_flags
))
353 as_bad (_("no such machine extension `%s'"), sym
- 1);
354 *input_line_pointer
= c
;
355 if (iflag
== ARRAY_SIZE (cpu_flags
))
362 if (*input_line_pointer
!= 0 && *input_line_pointer
!= '\n')
364 as_bad (_("junk at end of machine string, first unrecognized character"
365 " is `%c'"), *input_line_pointer
);
366 icpu
= S390_OPCODE_MAXCPU
;
368 input_line_pointer
= ilp_bak
;
374 md_parse_option (int c
, const char *arg
)
378 /* -k: Ignore for FreeBSD compatibility. */
382 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
385 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
388 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
389 warn_areg_zero
= TRUE
;
391 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
394 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
397 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
398 current_mode_mask
= 1 << S390_OPCODE_ESA
;
400 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
402 if (s390_arch_size
== 32)
403 set_highgprs_p
= TRUE
;
404 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
407 else if (arg
!= NULL
&& strncmp (arg
, "arch=", 5) == 0)
409 current_cpu
= s390_parse_cpu (arg
+ 5, ¤t_flags
, FALSE
);
410 if (current_cpu
== S390_OPCODE_MAXCPU
)
412 as_bad (_("invalid switch -m%s"), arg
);
419 as_bad (_("invalid switch -m%s"), arg
);
425 /* Option -A is deprecated. Still available for compatibility. */
426 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
427 current_cpu
= S390_OPCODE_G5
;
428 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
429 current_cpu
= S390_OPCODE_Z900
;
431 as_bad (_("invalid architecture -A%s"), arg
);
434 /* -V: SVR4 argument to print version ID. */
439 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
440 should be emitted or not. FIXME: Not implemented. */
452 md_show_usage (FILE *stream
)
454 fprintf (stream
, _("\
456 -mregnames Allow symbolic names for registers\n\
457 -mwarn-areg-zero Warn about zero base/index registers\n\
458 -mno-regnames Do not allow symbolic names for registers\n\
459 -m31 Set file format to 31 bit format\n\
460 -m64 Set file format to 64 bit format\n"));
461 fprintf (stream
, _("\
462 -V print assembler version number\n\
463 -Qy, -Qn ignored\n"));
466 /* Generate the hash table mapping mnemonics to struct s390_opcode.
467 This table is built at startup and whenever the CPU level is
468 changed using .machine. */
471 s390_setup_opcodes (void)
473 const struct s390_opcode
*op
;
474 const struct s390_opcode
*op_end
;
475 bfd_boolean dup_insn
= FALSE
;
478 if (s390_opcode_hash
!= NULL
)
479 hash_die (s390_opcode_hash
);
481 /* Insert the opcodes into a hash table. */
482 s390_opcode_hash
= hash_new ();
484 op_end
= s390_opcodes
+ s390_num_opcodes
;
485 for (op
= s390_opcodes
; op
< op_end
; op
++)
489 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
491 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
496 if ((op
->modes
& current_mode_mask
) == 0)
498 else if ((op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
) == 0)
500 /* Opcodes that do not belong to a specific facility are enabled if
501 present in the selected cpu. */
502 use_opcode
= (op
->min_cpu
<= current_cpu
);
508 /* Opcodes of a specific facility are enabled if the facility is
509 enabled. Note: only some facilities are represented as flags. */
510 f
= (op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
);
511 use_opcode
= ((f
& current_flags
) == f
);
515 retval
= hash_insert (s390_opcode_hash
, op
->name
, (void *) op
);
516 if (retval
!= (const char *) NULL
)
518 as_bad (_("Internal assembler error for instruction %s"),
524 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
532 /* This function is called when the assembler starts up. It is called
533 after the options have been parsed and the output file has been
539 const struct s390_opcode
*op
;
540 const struct s390_opcode
*op_end
;
543 /* Give a warning if the combination -m64-bit and -Aesa is used. */
544 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
545 as_warn (_("The 64 bit file format is used without esame instructions."));
547 s390_cie_data_alignment
= -s390_arch_size
/ 8;
549 /* Set the ELF flags if desired. */
551 bfd_set_private_flags (stdoutput
, s390_flags
);
553 /* Insert the opcode formats into a hash table. */
554 s390_opformat_hash
= hash_new ();
556 op_end
= s390_opformats
+ s390_num_opformats
;
557 for (op
= s390_opformats
; op
< op_end
; op
++)
559 retval
= hash_insert (s390_opformat_hash
, op
->name
, (void *) op
);
560 if (retval
!= (const char *) NULL
)
561 as_bad (_("Internal assembler error for instruction format %s"),
565 s390_setup_opcodes ();
567 record_alignment (text_section
, 2);
568 record_alignment (data_section
, 2);
569 record_alignment (bss_section
, 2);
572 /* Called after all assembly has been done. */
576 if (s390_arch_size
== 64)
577 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
579 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
582 /* Insert an operand value into an instruction. */
585 s390_insert_operand (unsigned char *insn
,
586 const struct s390_operand
*operand
,
594 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
598 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
599 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
600 /* Halve PCREL operands. */
601 if (operand
->flags
& S390_OPERAND_PCREL
)
603 /* Check for underflow / overflow. */
604 if (val
< min
|| val
> max
)
607 _("operand out of range (%s not between %ld and %ld)");
610 if (operand
->flags
& S390_OPERAND_PCREL
)
616 sprint_value (buf
, val
);
617 if (file
== (char *) NULL
)
618 as_bad (err
, buf
, (int) min
, (int) max
);
620 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
623 /* val is ok, now restrict it to operand->bits bits. */
624 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
625 /* val is restrict, now check for special case. */
626 if (operand
->bits
== 20 && operand
->shift
== 20)
627 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
633 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
635 uval
= (addressT
) val
;
637 /* Vector register operands have an additional bit in the RXB
639 if (operand
->flags
& S390_OPERAND_VR
)
640 max
= (max
<< 1) | 1;
642 /* Length x in an instructions has real length x+1. */
643 if (operand
->flags
& S390_OPERAND_LENGTH
)
645 /* Check for underflow / overflow. */
646 if (uval
< min
|| uval
> max
)
648 if (operand
->flags
& S390_OPERAND_LENGTH
)
655 as_bad_value_out_of_range (_("operand"), uval
, (offsetT
) min
, (offsetT
) max
, file
, line
);
661 if (operand
->flags
& S390_OPERAND_VR
)
663 /* Insert the extra bit into the RXB field. */
664 switch (operand
->shift
)
667 insn
[4] |= (uval
& 0x10) >> 1;
670 insn
[4] |= (uval
& 0x10) >> 2;
673 insn
[4] |= (uval
& 0x10) >> 3;
676 insn
[4] |= (uval
& 0x10) >> 4;
682 if (operand
->flags
& S390_OPERAND_OR1
)
684 if (operand
->flags
& S390_OPERAND_OR2
)
686 if (operand
->flags
& S390_OPERAND_OR8
)
689 /* Duplicate the operand at bit pos 12 to 16. */
690 if (operand
->flags
& S390_OPERAND_CP16
)
692 /* Copy VR operand at bit pos 12 to bit pos 16. */
693 insn
[2] |= uval
<< 4;
694 /* Copy the flag in the RXB field. */
695 insn
[4] |= (insn
[4] & 4) >> 1;
698 /* Insert fragments of the operand byte for byte. */
699 offset
= operand
->shift
+ operand
->bits
;
700 uval
<<= (-offset
) & 7;
701 insn
+= (offset
- 1) / 8;
713 bfd_reloc_code_real_type reloc
;
716 /* Parse tls marker and return the desired relocation. */
717 static bfd_reloc_code_real_type
718 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
720 static struct map_tls mapping
[] =
722 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
723 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
724 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
725 { NULL
, 0, BFD_RELOC_UNUSED
}
735 return BFD_RELOC_UNUSED
;
738 while (ISIDNUM (*str
))
742 return BFD_RELOC_UNUSED
;
744 orig_line
= input_line_pointer
;
745 input_line_pointer
= str
;
747 str
= input_line_pointer
;
748 if (&input_line_pointer
!= str_p
)
749 input_line_pointer
= orig_line
;
751 if (exp_p
->X_op
!= O_symbol
)
752 return BFD_RELOC_UNUSED
;
754 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
755 if (len
== ptr
->length
756 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
758 /* Found a matching tls suffix. */
762 return BFD_RELOC_UNUSED
;
765 /* Structure used to hold suffixes. */
776 ELF_SUFFIX_TLS_GOTIE
,
788 elf_suffix_type suffix
;
792 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
793 static elf_suffix_type
794 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
796 static struct map_bfd mapping
[] =
798 { "got", 3, ELF_SUFFIX_GOT
},
799 { "got12", 5, ELF_SUFFIX_GOT
},
800 { "plt", 3, ELF_SUFFIX_PLT
},
801 { "gotent", 6, ELF_SUFFIX_GOTENT
},
802 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
803 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
804 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
805 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
806 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
807 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
808 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
809 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
810 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
811 { NULL
, 0, ELF_SUFFIX_NONE
}
820 return ELF_SUFFIX_NONE
;
823 while (ISALNUM (*str
))
827 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
828 if (len
== ptr
->length
829 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
831 if (exp_p
->X_add_number
!= 0)
832 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
833 ptr
->string
, ptr
->string
);
834 /* Now check for identifier@suffix+constant. */
835 if (*str
== '-' || *str
== '+')
837 char *orig_line
= input_line_pointer
;
840 input_line_pointer
= str
;
841 expression (&new_exp
);
843 switch (new_exp
.X_op
)
845 case O_constant
: /* X_add_number (a constant expression). */
846 exp_p
->X_add_number
+= new_exp
.X_add_number
;
847 str
= input_line_pointer
;
849 case O_symbol
: /* X_add_symbol + X_add_number. */
850 /* this case is used for e.g. xyz@PLT+.Label. */
851 exp_p
->X_add_number
+= new_exp
.X_add_number
;
852 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
854 str
= input_line_pointer
;
856 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
857 /* this case is used for e.g. xyz@PLT-.Label. */
858 exp_p
->X_add_number
+= new_exp
.X_add_number
;
859 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
860 exp_p
->X_op
= O_subtract
;
861 str
= input_line_pointer
;
867 /* If s390_elf_suffix has not been called with
868 &input_line_pointer as first parameter, we have
869 clobbered the input_line_pointer. We have to
871 if (&input_line_pointer
!= str_p
)
872 input_line_pointer
= orig_line
;
878 return BFD_RELOC_UNUSED
;
881 /* Structure used to hold a literal pool entry. */
884 struct s390_lpe
*next
;
886 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
887 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
889 bfd_reloc_code_real_type reloc
;
893 static struct s390_lpe
*lpe_free_list
= NULL
;
894 static struct s390_lpe
*lpe_list
= NULL
;
895 static struct s390_lpe
*lpe_list_tail
= NULL
;
896 static symbolS
*lp_sym
= NULL
;
897 static int lp_count
= 0;
898 static int lpe_count
= 0;
901 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
903 if (exp1
->X_op
!= exp2
->X_op
)
908 case O_constant
: /* X_add_number must be equal. */
910 return exp1
->X_add_number
== exp2
->X_add_number
;
913 as_bad (_("Can't handle O_big in s390_exp_compare"));
915 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
920 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
921 && (exp1
->X_add_number
== exp2
->X_add_number
);
923 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
928 case O_bit_inclusive_or
:
930 case O_bit_exclusive_or
:
942 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
943 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
944 && (exp1
->X_add_number
== exp2
->X_add_number
);
950 /* Test for @lit and if its present make an entry in the literal pool and
951 modify the current expression to be an offset into the literal pool. */
952 static elf_suffix_type
953 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
955 bfd_reloc_code_real_type reloc
;
959 struct s390_lpe
*lpe
;
963 return suffix
; /* No modification. */
965 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
967 while (ISALNUM (*str
))
970 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
971 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
972 return suffix
; /* no modification */
973 nbytes
= ident
[3] - '0';
975 reloc
= BFD_RELOC_UNUSED
;
976 if (suffix
== ELF_SUFFIX_GOT
)
979 reloc
= BFD_RELOC_390_GOT16
;
980 else if (nbytes
== 4)
981 reloc
= BFD_RELOC_32_GOT_PCREL
;
982 else if (nbytes
== 8)
983 reloc
= BFD_RELOC_390_GOT64
;
985 else if (suffix
== ELF_SUFFIX_PLT
)
988 reloc
= BFD_RELOC_390_PLT32
;
989 else if (nbytes
== 8)
990 reloc
= BFD_RELOC_390_PLT64
;
993 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
994 as_bad (_("Invalid suffix for literal pool entry"));
996 /* Search the pool if the new entry is a duplicate. */
997 if (exp_p
->X_op
== O_big
)
999 /* Special processing for big numbers. */
1000 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1002 if (lpe
->ex
.X_op
== O_big
)
1004 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
1006 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
1007 sizeof (FLONUM_TYPE
)) == 0)
1010 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
1012 if (memcmp (generic_bignum
, lpe
->bignum
,
1013 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
1021 /* Processing for 'normal' data types. */
1022 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1023 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
1024 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
1030 /* A new literal. */
1031 if (lpe_free_list
!= NULL
)
1033 lpe
= lpe_free_list
;
1034 lpe_free_list
= lpe_free_list
->next
;
1038 lpe
= XNEW (struct s390_lpe
);
1043 if (exp_p
->X_op
== O_big
)
1045 if (exp_p
->X_add_number
<= 0)
1046 lpe
->floatnum
= generic_floating_point_number
;
1047 else if (exp_p
->X_add_number
<= 4)
1048 memcpy (lpe
->bignum
, generic_bignum
,
1049 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1051 as_bad (_("Big number is too big"));
1054 lpe
->nbytes
= nbytes
;
1056 /* Literal pool name defined ? */
1059 sprintf (tmp_name
, ".L\001%i", lp_count
);
1060 lp_sym
= symbol_make (tmp_name
);
1063 /* Make name for literal pool entry. */
1064 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1066 lpe
->sym
= symbol_make (tmp_name
);
1068 /* Add to literal pool list. */
1070 if (lpe_list_tail
!= NULL
)
1072 lpe_list_tail
->next
= lpe
;
1073 lpe_list_tail
= lpe
;
1076 lpe_list
= lpe_list_tail
= lpe
;
1079 /* Now change exp_p to the offset into the literal pool.
1080 Thats the expression: .L^Ax^By-.L^Ax */
1081 exp_p
->X_add_symbol
= lpe
->sym
;
1082 exp_p
->X_op_symbol
= lp_sym
;
1083 exp_p
->X_op
= O_subtract
;
1084 exp_p
->X_add_number
= 0;
1088 /* We change the suffix type to ELF_SUFFIX_NONE, because
1089 the difference of two local labels is just a number. */
1090 return ELF_SUFFIX_NONE
;
1093 /* Like normal .long/.short/.word, except support @got, etc.
1094 clobbers input_line_pointer, checks end-of-line. */
1096 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
1099 elf_suffix_type suffix
;
1101 if (is_it_end_of_statement ())
1103 demand_empty_rest_of_line ();
1111 if (exp
.X_op
== O_symbol
1112 && *input_line_pointer
== '@'
1113 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1115 bfd_reloc_code_real_type reloc
;
1116 reloc_howto_type
*reloc_howto
;
1122 static bfd_reloc_code_real_type tab2
[] =
1124 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1125 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1126 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1127 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1128 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1129 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1130 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1131 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1132 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1133 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1134 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1135 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1136 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1138 reloc
= tab2
[suffix
];
1140 else if (nbytes
== 4)
1142 static bfd_reloc_code_real_type tab4
[] =
1144 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1145 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1146 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1147 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1148 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1149 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1150 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1151 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1152 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1153 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1154 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1155 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1156 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1158 reloc
= tab4
[suffix
];
1160 else if (nbytes
== 8)
1162 static bfd_reloc_code_real_type tab8
[] =
1164 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1165 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1166 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1167 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1168 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1169 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1170 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1171 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1172 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1173 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1174 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1175 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1176 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1178 reloc
= tab8
[suffix
];
1181 reloc
= BFD_RELOC_UNUSED
;
1183 if (reloc
!= BFD_RELOC_UNUSED
1184 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1186 size
= bfd_get_reloc_size (reloc_howto
);
1188 as_bad (_("%s relocations do not fit in %d bytes"),
1189 reloc_howto
->name
, nbytes
);
1190 where
= frag_more (nbytes
);
1191 md_number_to_chars (where
, 0, size
);
1192 /* To make fixup_segment do the pc relative conversion the
1193 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1194 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1195 size
, &exp
, FALSE
, reloc
);
1198 as_bad (_("relocation not applicable"));
1201 emit_expr (&exp
, (unsigned int) nbytes
);
1203 while (*input_line_pointer
++ == ',');
1205 input_line_pointer
--; /* Put terminator back into stream. */
1206 demand_empty_rest_of_line ();
1209 /* We need to keep a list of fixups. We can't simply generate them as
1210 we go, because that would require us to first create the frag, and
1211 that would screw up references to ``.''. */
1217 bfd_reloc_code_real_type reloc
;
1220 #define MAX_INSN_FIXUPS (4)
1222 /* This routine is called for each instruction to be assembled. */
1225 md_gather_operands (char *str
,
1226 unsigned char *insn
,
1227 const struct s390_opcode
*opcode
)
1229 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1230 const struct s390_operand
*operand
;
1231 const unsigned char *opindex_ptr
;
1233 elf_suffix_type suffix
;
1234 bfd_reloc_code_real_type reloc
;
1239 while (ISSPACE (*str
))
1244 /* Gather the operands. */
1246 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1250 operand
= s390_operands
+ *opindex_ptr
;
1252 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM
) && *str
== '\0')
1254 /* Optional parameters might need to be ORed with a
1255 value so calling s390_insert_operand is needed. */
1256 s390_insert_operand (insn
, operand
, 0, NULL
, 0);
1260 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1262 /* We do an early skip. For D(X,B) constructions the index
1263 register is skipped (X is optional). For D(L,B) the base
1264 register will be the skipped operand, because L is NOT
1270 /* Gather the operand. */
1271 hold
= input_line_pointer
;
1272 input_line_pointer
= str
;
1274 /* Parse the operand. */
1275 if (! register_name (&ex
))
1278 str
= input_line_pointer
;
1279 input_line_pointer
= hold
;
1281 /* Write the operand to the insn. */
1282 if (ex
.X_op
== O_illegal
)
1283 as_bad (_("illegal operand"));
1284 else if (ex
.X_op
== O_absent
)
1286 /* No operands, check if all operands can be skipped. */
1287 while (*opindex_ptr
!= 0 && operand
->flags
& S390_OPERAND_OPTIONAL
)
1289 if (operand
->flags
& S390_OPERAND_DISP
)
1291 /* An optional displacement makes the whole D(X,B)
1292 D(L,B) or D(B) block optional. */
1294 operand
= s390_operands
+ *(++opindex_ptr
);
1295 } while (!(operand
->flags
& S390_OPERAND_BASE
));
1297 operand
= s390_operands
+ *(++opindex_ptr
);
1299 if (opindex_ptr
[0] == '\0')
1301 as_bad (_("missing operand"));
1303 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1305 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1307 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1309 /* We need to generate a fixup for the
1310 expression returned by s390_lit_suffix. */
1311 if (fc
>= MAX_INSN_FIXUPS
)
1312 as_fatal (_("too many fixups"));
1313 fixups
[fc
].exp
= ex
;
1314 fixups
[fc
].opindex
= *opindex_ptr
;
1315 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1320 if ((operand
->flags
& S390_OPERAND_LENGTH
)
1321 && ex
.X_op
!= O_constant
)
1322 as_fatal (_("invalid length field specified"));
1323 if ((operand
->flags
& S390_OPERAND_INDEX
)
1324 && ex
.X_add_number
== 0
1326 as_warn (_("index register specified but zero"));
1327 if ((operand
->flags
& S390_OPERAND_BASE
)
1328 && ex
.X_add_number
== 0
1330 as_warn (_("base register specified but zero"));
1331 if ((operand
->flags
& S390_OPERAND_GPR
)
1332 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1333 && (ex
.X_add_number
& 1))
1334 as_fatal (_("odd numbered general purpose register specified as "
1336 if ((operand
->flags
& S390_OPERAND_FPR
)
1337 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1338 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1339 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1340 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1341 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1342 as_fatal (_("invalid floating point register pair. Valid fp "
1343 "register pair operands are 0, 1, 4, 5, 8, 9, "
1345 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1350 suffix
= s390_elf_suffix (&str
, &ex
);
1351 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1352 reloc
= BFD_RELOC_UNUSED
;
1354 if (suffix
== ELF_SUFFIX_GOT
)
1356 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1357 (operand
->bits
== 12))
1358 reloc
= BFD_RELOC_390_GOT12
;
1359 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1360 (operand
->bits
== 20))
1361 reloc
= BFD_RELOC_390_GOT20
;
1362 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1363 && (operand
->bits
== 16))
1364 reloc
= BFD_RELOC_390_GOT16
;
1365 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1366 && (operand
->bits
== 32))
1367 reloc
= BFD_RELOC_390_GOTENT
;
1369 else if (suffix
== ELF_SUFFIX_PLT
)
1371 if ((operand
->flags
& S390_OPERAND_PCREL
)
1372 && (operand
->bits
== 12))
1373 reloc
= BFD_RELOC_390_PLT12DBL
;
1374 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1375 && (operand
->bits
== 16))
1376 reloc
= BFD_RELOC_390_PLT16DBL
;
1377 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1378 && (operand
->bits
== 24))
1379 reloc
= BFD_RELOC_390_PLT24DBL
;
1380 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1381 && (operand
->bits
== 32))
1382 reloc
= BFD_RELOC_390_PLT32DBL
;
1384 else if (suffix
== ELF_SUFFIX_GOTENT
)
1386 if ((operand
->flags
& S390_OPERAND_PCREL
)
1387 && (operand
->bits
== 32))
1388 reloc
= BFD_RELOC_390_GOTENT
;
1390 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1392 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1393 && (operand
->bits
== 16))
1394 reloc
= BFD_RELOC_16_GOTOFF
;
1396 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1398 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1399 && (operand
->bits
== 16))
1400 reloc
= BFD_RELOC_390_PLTOFF16
;
1402 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1404 if ((operand
->flags
& S390_OPERAND_DISP
)
1405 && (operand
->bits
== 12))
1406 reloc
= BFD_RELOC_390_GOTPLT12
;
1407 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1408 && (operand
->bits
== 16))
1409 reloc
= BFD_RELOC_390_GOTPLT16
;
1410 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1411 && (operand
->bits
== 32))
1412 reloc
= BFD_RELOC_390_GOTPLTENT
;
1414 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1416 if ((operand
->flags
& S390_OPERAND_DISP
)
1417 && (operand
->bits
== 12))
1418 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1419 else if ((operand
->flags
& S390_OPERAND_DISP
)
1420 && (operand
->bits
== 20))
1421 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1423 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1425 if ((operand
->flags
& S390_OPERAND_PCREL
)
1426 && (operand
->bits
== 32))
1427 reloc
= BFD_RELOC_390_TLS_IEENT
;
1430 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1431 as_bad (_("invalid operand suffix"));
1432 /* We need to generate a fixup of type 'reloc' for this
1434 if (fc
>= MAX_INSN_FIXUPS
)
1435 as_fatal (_("too many fixups"));
1436 fixups
[fc
].exp
= ex
;
1437 fixups
[fc
].opindex
= *opindex_ptr
;
1438 fixups
[fc
].reloc
= reloc
;
1442 /* Check the next character. The call to expression has advanced
1443 str past any whitespace. */
1444 if (operand
->flags
& S390_OPERAND_DISP
)
1446 /* After a displacement a block in parentheses can start. */
1449 /* Check if parenthesized block can be skipped. If the next
1450 operand is neiter an optional operand nor a base register
1451 then we have a syntax error. */
1452 operand
= s390_operands
+ *(++opindex_ptr
);
1453 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1454 as_bad (_("syntax error; missing '(' after displacement"));
1456 /* Ok, skip all operands until S390_OPERAND_BASE. */
1457 while (!(operand
->flags
& S390_OPERAND_BASE
))
1458 operand
= s390_operands
+ *(++opindex_ptr
);
1460 /* If there is a next operand it must be separated by a comma. */
1461 if (opindex_ptr
[1] != '\0')
1465 while (opindex_ptr
[1] != '\0')
1467 operand
= s390_operands
+ *(++opindex_ptr
);
1468 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1470 as_bad (_("syntax error; expected ,"));
1480 /* We found an opening parentheses. */
1482 for (f
= str
; *f
!= '\0'; f
++)
1483 if (*f
== ',' || *f
== ')')
1485 /* If there is no comma until the closing parentheses OR
1486 there is a comma right after the opening parentheses,
1487 we have to skip optional operands. */
1488 if (*f
== ',' && f
== str
)
1490 /* comma directly after '(' ? */
1495 skip_optional
= (*f
!= ',');
1498 else if (operand
->flags
& S390_OPERAND_BASE
)
1500 /* After the base register the parenthesed block ends. */
1502 as_bad (_("syntax error; missing ')' after base register"));
1504 /* If there is a next operand it must be separated by a comma. */
1505 if (opindex_ptr
[1] != '\0')
1509 while (opindex_ptr
[1] != '\0')
1511 operand
= s390_operands
+ *(++opindex_ptr
);
1512 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1514 as_bad (_("syntax error; expected ,"));
1524 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1525 of D(L,B). In this case the base register has to be skipped. */
1528 operand
= s390_operands
+ *(++opindex_ptr
);
1530 if (!(operand
->flags
& S390_OPERAND_BASE
))
1531 as_bad (_("syntax error; ')' not allowed here"));
1535 if ((opcode
->flags
& S390_INSTR_FLAG_OPTPARM
) && *str
== '\0')
1538 /* If there is a next operand it must be separated by a comma. */
1539 if (opindex_ptr
[1] != '\0')
1543 while (opindex_ptr
[1] != '\0')
1545 operand
= s390_operands
+ *(++opindex_ptr
);
1546 if (operand
->flags
& S390_OPERAND_OPTIONAL
)
1548 as_bad (_("syntax error; expected ,"));
1558 while (ISSPACE (*str
))
1561 /* Check for tls instruction marker. */
1562 reloc
= s390_tls_suffix (&str
, &ex
);
1563 if (reloc
!= BFD_RELOC_UNUSED
)
1565 /* We need to generate a fixup of type 'reloc' for this
1567 if (fc
>= MAX_INSN_FIXUPS
)
1568 as_fatal (_("too many fixups"));
1569 fixups
[fc
].exp
= ex
;
1570 fixups
[fc
].opindex
= -1;
1571 fixups
[fc
].reloc
= reloc
;
1579 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1581 as_bad (_("junk at end of line: `%s'"), str
);
1582 if (linefeed
!= NULL
)
1586 /* Write out the instruction. */
1587 f
= frag_more (opcode
->oplen
);
1588 memcpy (f
, insn
, opcode
->oplen
);
1589 dwarf2_emit_insn (opcode
->oplen
);
1591 /* Create any fixups. At this point we do not use a
1592 bfd_reloc_code_real_type, but instead just use the
1593 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1594 handle fixups for any operand type, although that is admittedly
1595 not a very exciting feature. We pick a BFD reloc type in
1597 for (i
= 0; i
< fc
; i
++)
1600 if (fixups
[i
].opindex
< 0)
1602 /* Create tls instruction marker relocation. */
1603 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1604 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1608 operand
= s390_operands
+ fixups
[i
].opindex
;
1610 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1612 reloc_howto_type
*reloc_howto
;
1616 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1620 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1622 if (size
< 1 || size
> 4)
1625 fixP
= fix_new_exp (frag_now
,
1626 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1627 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1629 /* Turn off overflow checking in fixup_segment. This is necessary
1630 because fixup_segment will signal an overflow for large 4 byte
1631 quantities for GOT12 relocations. */
1632 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1633 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1634 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1635 fixP
->fx_no_overflow
= 1;
1638 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1639 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1640 ((bfd_reloc_code_real_type
)
1641 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1646 /* This routine is called for each instruction to be assembled. */
1649 md_assemble (char *str
)
1651 const struct s390_opcode
*opcode
;
1652 unsigned char insn
[6];
1655 /* Get the opcode. */
1656 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1661 /* Look up the opcode in the hash table. */
1662 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1663 if (opcode
== (const struct s390_opcode
*) NULL
)
1665 as_bad (_("Unrecognized opcode: `%s'"), str
);
1668 else if (!(opcode
->modes
& current_mode_mask
))
1670 as_bad (_("Opcode %s not available in this mode"), str
);
1673 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1674 md_gather_operands (s
, insn
, opcode
);
1677 #ifndef WORKING_DOT_WORD
1678 /* Handle long and short jumps. We don't support these */
1680 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1682 addressT from_addr
, to_addr
;
1690 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1692 addressT from_addr
, to_addr
;
1701 s390_bss (int ignore ATTRIBUTE_UNUSED
)
1703 /* We don't support putting frags in the BSS segment, we fake it
1704 by marking in_bss, then looking at s_skip for clues. */
1706 subseg_set (bss_section
, 0);
1707 demand_empty_rest_of_line ();
1710 /* Pseudo-op handling. */
1713 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1716 const struct s390_opcode
*opformat
;
1717 unsigned char insn
[6];
1720 /* Get the opcode format. */
1721 s
= input_line_pointer
;
1722 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1725 as_bad (_("Invalid .insn format\n"));
1728 /* Look up the opcode in the hash table. */
1729 opformat
= (struct s390_opcode
*)
1730 hash_find (s390_opformat_hash
, input_line_pointer
);
1731 if (opformat
== (const struct s390_opcode
*) NULL
)
1733 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1736 input_line_pointer
= s
;
1738 if (exp
.X_op
== O_constant
)
1740 if ( ( opformat
->oplen
== 6
1741 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1742 || ( opformat
->oplen
== 4
1743 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1744 || ( opformat
->oplen
== 2
1745 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1746 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1748 as_bad (_("Invalid .insn format\n"));
1750 else if (exp
.X_op
== O_big
)
1752 if (exp
.X_add_number
> 0
1753 && opformat
->oplen
== 6
1754 && generic_bignum
[3] == 0)
1756 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
1757 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
1758 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
1761 as_bad (_("Invalid .insn format\n"));
1764 as_bad (_("second operand of .insn not a constant\n"));
1766 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1767 as_bad (_("missing comma after insn constant\n"));
1769 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1771 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1775 demand_empty_rest_of_line ();
1778 /* The .byte pseudo-op. This is similar to the normal .byte
1779 pseudo-op, but it can also take a single ASCII string. */
1782 s390_byte (int ignore ATTRIBUTE_UNUSED
)
1784 if (*input_line_pointer
!= '\"')
1790 /* Gather characters. A real double quote is doubled. Unusual
1791 characters are not permitted. */
1792 ++input_line_pointer
;
1797 c
= *input_line_pointer
++;
1801 if (*input_line_pointer
!= '\"')
1803 ++input_line_pointer
;
1806 FRAG_APPEND_1_CHAR (c
);
1809 demand_empty_rest_of_line ();
1812 /* The .ltorg pseudo-op.This emits all literals defined since the last
1813 .ltorg or the invocation of gas. Literals are defined with the
1817 s390_literals (int ignore ATTRIBUTE_UNUSED
)
1819 struct s390_lpe
*lpe
;
1821 if (lp_sym
== NULL
|| lpe_count
== 0)
1822 return; /* Nothing to be done. */
1824 /* Emit symbol for start of literal pool. */
1825 S_SET_SEGMENT (lp_sym
, now_seg
);
1826 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1827 lp_sym
->sy_frag
= frag_now
;
1832 lpe_list
= lpe_list
->next
;
1833 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1834 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1835 lpe
->sym
->sy_frag
= frag_now
;
1837 /* Emit literal pool entry. */
1838 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1840 reloc_howto_type
*reloc_howto
=
1841 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1842 int size
= bfd_get_reloc_size (reloc_howto
);
1845 if (size
> lpe
->nbytes
)
1846 as_bad (_("%s relocations do not fit in %d bytes"),
1847 reloc_howto
->name
, lpe
->nbytes
);
1848 where
= frag_more (lpe
->nbytes
);
1849 md_number_to_chars (where
, 0, size
);
1850 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1851 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1855 if (lpe
->ex
.X_op
== O_big
)
1857 if (lpe
->ex
.X_add_number
<= 0)
1858 generic_floating_point_number
= lpe
->floatnum
;
1860 memcpy (generic_bignum
, lpe
->bignum
,
1861 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
1863 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1866 lpe
->next
= lpe_free_list
;
1867 lpe_free_list
= lpe
;
1869 lpe_list_tail
= NULL
;
1875 #define MAX_HISTORY 100
1877 /* The .machine pseudo op allows to switch to a different CPU level in
1878 the asm listing. The current CPU setting can be stored on a stack
1879 with .machine push and restored with .machine pop. */
1882 s390_machine (int ignore ATTRIBUTE_UNUSED
)
1885 static struct cpu_history
1890 static int curr_hist
;
1894 if (*input_line_pointer
== '"')
1897 cpu_string
= demand_copy_C_string (&len
);
1903 cpu_string
= input_line_pointer
;
1908 c
= get_symbol_name (&str
);
1909 c
= restore_line_pointer (c
);
1911 ++ input_line_pointer
;
1915 c
= *input_line_pointer
;
1916 *input_line_pointer
= 0;
1917 cpu_string
= xstrdup (cpu_string
);
1918 (void) restore_line_pointer (c
);
1921 if (cpu_string
!= NULL
)
1923 unsigned int new_cpu
= current_cpu
;
1924 unsigned int new_flags
= current_flags
;
1926 if (strcmp (cpu_string
, "push") == 0)
1928 if (cpu_history
== NULL
)
1929 cpu_history
= XNEWVEC (struct cpu_history
, MAX_HISTORY
);
1931 if (curr_hist
>= MAX_HISTORY
)
1932 as_bad (_(".machine stack overflow"));
1935 cpu_history
[curr_hist
].cpu
= current_cpu
;
1936 cpu_history
[curr_hist
].flags
= current_flags
;
1940 else if (strcmp (cpu_string
, "pop") == 0)
1943 as_bad (_(".machine stack underflow"));
1947 new_cpu
= cpu_history
[curr_hist
].cpu
;
1948 new_flags
= cpu_history
[curr_hist
].flags
;
1952 new_cpu
= s390_parse_cpu (cpu_string
, &new_flags
, TRUE
);
1954 if (new_cpu
== S390_OPCODE_MAXCPU
)
1955 as_bad (_("invalid machine `%s'"), cpu_string
);
1957 if (new_cpu
!= current_cpu
|| new_flags
!= current_flags
)
1959 current_cpu
= new_cpu
;
1960 current_flags
= new_flags
;
1961 s390_setup_opcodes ();
1965 demand_empty_rest_of_line ();
1968 /* The .machinemode pseudo op allows to switch to a different
1969 architecture mode in the asm listing. The current architecture
1970 mode setting can be stored on a stack with .machinemode push and
1971 restored with .machinemode pop. */
1974 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
1977 static unsigned int *mode_history
;
1978 static int curr_hist
;
1985 c
= get_symbol_name (&mode_string
);
1986 mode_string
= xstrdup (mode_string
);
1987 (void) restore_line_pointer (c
);
1990 if (mode_string
!= NULL
)
1992 unsigned int old_mode_mask
= current_mode_mask
;
1995 for (p
= mode_string
; *p
!= 0; p
++)
1998 if (strcmp (mode_string
, "push") == 0)
2000 if (mode_history
== NULL
)
2001 mode_history
= XNEWVEC (unsigned int, MAX_HISTORY
);
2003 if (curr_hist
>= MAX_HISTORY
)
2004 as_bad (_(".machinemode stack overflow"));
2006 mode_history
[curr_hist
++] = current_mode_mask
;
2008 else if (strcmp (mode_string
, "pop") == 0)
2011 as_bad (_(".machinemode stack underflow"));
2013 current_mode_mask
= mode_history
[--curr_hist
];
2017 if (strcmp (mode_string
, "esa") == 0)
2018 current_mode_mask
= 1 << S390_OPCODE_ESA
;
2019 else if (strcmp (mode_string
, "zarch") == 0)
2021 if (s390_arch_size
== 32)
2022 set_highgprs_p
= TRUE
;
2023 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2025 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
2026 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2028 as_bad (_("invalid machine mode `%s'"), mode_string
);
2031 if (current_mode_mask
!= old_mode_mask
)
2032 s390_setup_opcodes ();
2035 demand_empty_rest_of_line ();
2041 md_atof (int type
, char *litp
, int *sizep
)
2043 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
2046 /* Align a section (I don't know why this is machine dependent). */
2049 md_section_align (asection
*seg
, valueT addr
)
2051 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2053 return ((addr
+ (1 << align
) - 1) & -(1 << align
));
2056 /* We don't have any form of relaxing. */
2059 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
2060 asection
*seg ATTRIBUTE_UNUSED
)
2066 /* Convert a machine dependent frag. We never generate these. */
2069 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2070 asection
*sec ATTRIBUTE_UNUSED
,
2071 fragS
*fragp ATTRIBUTE_UNUSED
)
2077 md_undefined_symbol (char *name
)
2079 if (*name
== '_' && *(name
+ 1) == 'G'
2080 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
2084 if (symbol_find (name
))
2085 as_bad (_("GOT already in symbol table"));
2086 GOT_symbol
= symbol_new (name
, undefined_section
,
2087 (valueT
) 0, &zero_address_frag
);
2094 /* Functions concerning relocs. */
2096 /* The location from which a PC relative jump should be calculated,
2097 given a PC relative reloc. */
2100 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2102 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2105 /* Here we decide which fixups can be adjusted to make them relative to
2106 the beginning of the section instead of the symbol. Basically we need
2107 to make sure that the dynamic relocations are done correctly, so in
2108 some cases we force the original symbol to be used. */
2110 tc_s390_fix_adjustable (fixS
*fixP
)
2112 /* Don't adjust references to merge sections. */
2113 if ((S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
2115 /* adjust_reloc_syms doesn't know about the GOT. */
2116 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
2117 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2118 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
2119 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
2120 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
2121 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
2122 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
2123 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
2124 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
2125 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
2126 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
2127 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
2128 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
2129 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2130 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2131 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2132 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2133 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2134 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2135 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2136 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2137 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2138 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2139 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2140 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2141 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2142 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2143 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2144 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2145 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2146 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2147 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2148 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2149 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2150 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2151 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2152 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2153 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2154 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2155 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2156 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2157 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2158 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2159 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2160 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2161 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2162 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2167 /* Return true if we must always emit a reloc for a type and false if
2168 there is some hope of resolving it at assembly time. */
2170 tc_s390_force_relocation (struct fix
*fixp
)
2172 /* Ensure we emit a relocation for every reference to the global
2173 offset table or to the procedure link table. */
2174 switch (fixp
->fx_r_type
)
2176 case BFD_RELOC_390_GOT12
:
2177 case BFD_RELOC_390_GOT20
:
2178 case BFD_RELOC_32_GOT_PCREL
:
2179 case BFD_RELOC_32_GOTOFF
:
2180 case BFD_RELOC_390_GOTOFF64
:
2181 case BFD_RELOC_390_PLTOFF16
:
2182 case BFD_RELOC_390_PLTOFF32
:
2183 case BFD_RELOC_390_PLTOFF64
:
2184 case BFD_RELOC_390_GOTPC
:
2185 case BFD_RELOC_390_GOT16
:
2186 case BFD_RELOC_390_GOTPCDBL
:
2187 case BFD_RELOC_390_GOT64
:
2188 case BFD_RELOC_390_GOTENT
:
2189 case BFD_RELOC_390_PLT32
:
2190 case BFD_RELOC_390_PLT12DBL
:
2191 case BFD_RELOC_390_PLT16DBL
:
2192 case BFD_RELOC_390_PLT24DBL
:
2193 case BFD_RELOC_390_PLT32DBL
:
2194 case BFD_RELOC_390_PLT64
:
2195 case BFD_RELOC_390_GOTPLT12
:
2196 case BFD_RELOC_390_GOTPLT16
:
2197 case BFD_RELOC_390_GOTPLT20
:
2198 case BFD_RELOC_390_GOTPLT32
:
2199 case BFD_RELOC_390_GOTPLT64
:
2200 case BFD_RELOC_390_GOTPLTENT
:
2206 return generic_force_reloc (fixp
);
2209 /* Apply a fixup to the object code. This is called for all the
2210 fixups we generated by the call to fix_new_exp, above. In the call
2211 above we used a reloc code which was the largest legal reloc code
2212 plus the operand index. Here we undo that to recover the operand
2213 index. At this point all symbol values should be fully resolved,
2214 and we attempt to completely resolve the reloc. If we can not do
2215 that, we determine the correct reloc code and put it back in the
2219 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2222 valueT value
= *valP
;
2224 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2226 if (fixP
->fx_subsy
!= NULL
)
2227 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2228 _("cannot emit relocation %s against subsy symbol %s"),
2229 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2230 S_GET_NAME (fixP
->fx_subsy
));
2232 if (fixP
->fx_addsy
!= NULL
)
2235 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2240 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2242 const struct s390_operand
*operand
;
2245 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2246 operand
= &s390_operands
[opindex
];
2250 /* Insert the fully resolved operand value. */
2251 s390_insert_operand ((unsigned char *) where
, operand
,
2252 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
);
2256 /* Determine a BFD reloc value based on the operand information.
2257 We are only prepared to turn a few of the operands into
2259 fixP
->fx_offset
= value
;
2260 if (operand
->bits
== 12 && operand
->shift
== 20)
2263 fixP
->fx_where
+= 2;
2264 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2266 else if (operand
->bits
== 12 && operand
->shift
== 36)
2269 fixP
->fx_where
+= 4;
2270 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2272 else if (operand
->bits
== 20 && operand
->shift
== 20)
2275 fixP
->fx_where
+= 2;
2276 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2278 else if (operand
->bits
== 8 && operand
->shift
== 8)
2281 fixP
->fx_where
+= 1;
2282 fixP
->fx_r_type
= BFD_RELOC_8
;
2284 else if (operand
->bits
== 12 && operand
->shift
== 12
2285 && (operand
->flags
& S390_OPERAND_PCREL
))
2288 fixP
->fx_where
+= 1;
2289 fixP
->fx_offset
+= 1;
2290 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2292 else if (operand
->bits
== 16 && operand
->shift
== 16)
2295 fixP
->fx_where
+= 2;
2296 if (operand
->flags
& S390_OPERAND_PCREL
)
2298 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2299 fixP
->fx_offset
+= 2;
2302 fixP
->fx_r_type
= BFD_RELOC_16
;
2304 else if (operand
->bits
== 24 && operand
->shift
== 24
2305 && (operand
->flags
& S390_OPERAND_PCREL
))
2308 fixP
->fx_where
+= 3;
2309 fixP
->fx_offset
+= 3;
2310 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2312 else if (operand
->bits
== 32 && operand
->shift
== 16
2313 && (operand
->flags
& S390_OPERAND_PCREL
))
2316 fixP
->fx_where
+= 2;
2317 fixP
->fx_offset
+= 2;
2318 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2325 /* Use expr_symbol_where to see if this is an expression
2327 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2328 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2329 _("unresolved expression that must be resolved"));
2331 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2332 _("unsupported relocation type"));
2339 switch (fixP
->fx_r_type
)
2345 md_number_to_chars (where
, value
, 1);
2347 case BFD_RELOC_390_12
:
2348 case BFD_RELOC_390_GOT12
:
2349 case BFD_RELOC_390_GOTPLT12
:
2350 case BFD_RELOC_390_PC12DBL
:
2351 case BFD_RELOC_390_PLT12DBL
:
2362 mop
= bfd_getb16 ((unsigned char *) where
);
2363 mop
|= (unsigned short) (value
& 0xfff);
2364 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2368 case BFD_RELOC_390_20
:
2369 case BFD_RELOC_390_GOT20
:
2370 case BFD_RELOC_390_GOTPLT20
:
2374 mop
= bfd_getb32 ((unsigned char *) where
);
2375 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2376 (value
& 0xff000) >> 12);
2377 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2382 case BFD_RELOC_GPREL16
:
2383 case BFD_RELOC_16_GOT_PCREL
:
2384 case BFD_RELOC_16_GOTOFF
:
2386 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2387 _("cannot emit PC relative %s relocation%s%s"),
2388 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2389 fixP
->fx_addsy
!= NULL
? " against " : "",
2390 (fixP
->fx_addsy
!= NULL
2391 ? S_GET_NAME (fixP
->fx_addsy
)
2394 md_number_to_chars (where
, value
, 2);
2396 case BFD_RELOC_390_GOT16
:
2397 case BFD_RELOC_390_PLTOFF16
:
2398 case BFD_RELOC_390_GOTPLT16
:
2400 md_number_to_chars (where
, value
, 2);
2402 case BFD_RELOC_390_PC16DBL
:
2403 case BFD_RELOC_390_PLT16DBL
:
2406 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2409 case BFD_RELOC_390_PC24DBL
:
2410 case BFD_RELOC_390_PLT24DBL
:
2417 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2418 mop
|= (unsigned int) (value
& 0xffffff);
2419 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2425 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2427 fixP
->fx_r_type
= BFD_RELOC_32
;
2429 md_number_to_chars (where
, value
, 4);
2431 case BFD_RELOC_32_PCREL
:
2432 case BFD_RELOC_32_BASEREL
:
2433 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2435 md_number_to_chars (where
, value
, 4);
2437 case BFD_RELOC_32_GOT_PCREL
:
2438 case BFD_RELOC_390_PLTOFF32
:
2439 case BFD_RELOC_390_PLT32
:
2440 case BFD_RELOC_390_GOTPLT32
:
2442 md_number_to_chars (where
, value
, 4);
2444 case BFD_RELOC_390_PC32DBL
:
2445 case BFD_RELOC_390_PLT32DBL
:
2446 case BFD_RELOC_390_GOTPCDBL
:
2447 case BFD_RELOC_390_GOTENT
:
2448 case BFD_RELOC_390_GOTPLTENT
:
2451 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2454 case BFD_RELOC_32_GOTOFF
:
2456 md_number_to_chars (where
, value
, sizeof (int));
2459 case BFD_RELOC_390_GOTOFF64
:
2461 md_number_to_chars (where
, value
, 8);
2464 case BFD_RELOC_390_GOT64
:
2465 case BFD_RELOC_390_PLTOFF64
:
2466 case BFD_RELOC_390_PLT64
:
2467 case BFD_RELOC_390_GOTPLT64
:
2469 md_number_to_chars (where
, value
, 8);
2474 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2476 fixP
->fx_r_type
= BFD_RELOC_64
;
2478 md_number_to_chars (where
, value
, 8);
2481 case BFD_RELOC_64_PCREL
:
2482 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2484 md_number_to_chars (where
, value
, 8);
2487 case BFD_RELOC_VTABLE_INHERIT
:
2488 case BFD_RELOC_VTABLE_ENTRY
:
2492 case BFD_RELOC_390_TLS_LOAD
:
2493 case BFD_RELOC_390_TLS_GDCALL
:
2494 case BFD_RELOC_390_TLS_LDCALL
:
2495 case BFD_RELOC_390_TLS_GD32
:
2496 case BFD_RELOC_390_TLS_GD64
:
2497 case BFD_RELOC_390_TLS_GOTIE12
:
2498 case BFD_RELOC_390_TLS_GOTIE20
:
2499 case BFD_RELOC_390_TLS_GOTIE32
:
2500 case BFD_RELOC_390_TLS_GOTIE64
:
2501 case BFD_RELOC_390_TLS_LDM32
:
2502 case BFD_RELOC_390_TLS_LDM64
:
2503 case BFD_RELOC_390_TLS_IE32
:
2504 case BFD_RELOC_390_TLS_IE64
:
2505 case BFD_RELOC_390_TLS_LE32
:
2506 case BFD_RELOC_390_TLS_LE64
:
2507 case BFD_RELOC_390_TLS_LDO32
:
2508 case BFD_RELOC_390_TLS_LDO64
:
2509 case BFD_RELOC_390_TLS_DTPMOD
:
2510 case BFD_RELOC_390_TLS_DTPOFF
:
2511 case BFD_RELOC_390_TLS_TPOFF
:
2512 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2513 /* Fully resolved at link time. */
2515 case BFD_RELOC_390_TLS_IEENT
:
2516 /* Fully resolved at link time. */
2517 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2523 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2525 if (reloc_name
!= NULL
)
2526 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2528 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2532 fixP
->fx_offset
= value
;
2536 /* Generate a reloc for a fixup. */
2539 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2541 bfd_reloc_code_real_type code
;
2544 code
= fixp
->fx_r_type
;
2545 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2547 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2548 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2549 code
= BFD_RELOC_390_GOTPC
;
2550 if (code
== BFD_RELOC_390_PC32DBL
)
2551 code
= BFD_RELOC_390_GOTPCDBL
;
2554 reloc
= XNEW (arelent
);
2555 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
2556 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2557 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2558 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2559 if (reloc
->howto
== NULL
)
2561 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2562 _("cannot represent relocation type %s"),
2563 bfd_get_reloc_code_name (code
));
2564 /* Set howto to a garbage value so that we can keep going. */
2565 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2566 gas_assert (reloc
->howto
!= NULL
);
2568 reloc
->addend
= fixp
->fx_offset
;
2574 s390_cfi_frame_initial_instructions (void)
2576 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2580 tc_s390_regname_to_dw2regnum (char *regname
)
2584 if (regname
[0] != 'c' && regname
[0] != 'a')
2586 regnum
= reg_name_search (regname
);
2587 if (regname
[0] == 'f' && regnum
!= -1)
2590 else if (strcmp (regname
, "ap") == 0)
2592 else if (strcmp (regname
, "cc") == 0)
2598 s390_elf_final_processing (void)
2601 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;