1 /* tc-s390.c -- Assemble for the S390
2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "safe-ctype.h"
25 #include "dwarf2dbg.h"
26 #include "dw2gencfi.h"
28 #include "opcode/s390.h"
31 /* The default architecture. */
33 #define DEFAULT_ARCH "s390"
35 static const char *default_arch
= DEFAULT_ARCH
;
36 /* Either 32 or 64, selects file format. */
37 static int s390_arch_size
= 0;
39 /* If no -march option was given default to the highest available CPU.
40 Since with S/390 a newer CPU always supports everything from its
41 predecessors this will accept every valid asm input. */
42 static unsigned int current_cpu
= S390_OPCODE_MAXCPU
- 1;
43 /* All facilities are enabled by default. */
44 static unsigned int current_flags
= S390_INSTR_FLAG_FACILITY_MASK
;
45 /* The mode mask default is picked in init_default_arch depending on
47 static unsigned int current_mode_mask
= 0;
49 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
50 for the output file. The default is picked in init_default_arch(). */
51 static bool set_highgprs_p
= false;
53 /* Whether to use user friendly register names. Default is TRUE. */
54 #ifndef TARGET_REG_NAMES_P
55 #define TARGET_REG_NAMES_P true
58 static bool reg_names_p
= TARGET_REG_NAMES_P
;
60 /* Set to TRUE if we want to warn about zero base/index registers. */
61 static bool warn_areg_zero
= false;
63 /* Whether to warn about register name type check mismatches. */
64 #ifndef S390_REGTYPE_CHECK
65 #define S390_REGTYPE_CHECK S390_REGTYPE_CHECK_RELAXED
68 enum s390_regtype_check
{
69 S390_REGTYPE_CHECK_NONE
= 0, /* No register name type checks. */
70 S390_REGTYPE_CHECK_RELAXED
, /* Relaxed register name type checks. */
71 S390_REGTYPE_CHECK_STRICT
/* Strict register name type checks. */
74 /* Whether to warn about register name type check mismatches. */
75 static enum s390_regtype_check warn_regtype_mismatch
= S390_REGTYPE_CHECK
;
77 /* Generic assembler global variables which must be defined by all
80 const char comment_chars
[] = "#";
82 /* Characters which start a comment at the beginning of a line. */
83 const char line_comment_chars
[] = "#";
85 /* Characters which may be used to separate multiple commands on a
87 const char line_separator_chars
[] = ";";
89 /* Characters which are used to indicate an exponent in a floating
91 const char EXP_CHARS
[] = "eE";
93 /* Characters which mean that a number is a floating point constant,
95 const char FLT_CHARS
[] = "dD";
97 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
98 int s390_cie_data_alignment
;
100 /* The target specific pseudo-ops which we support. */
102 /* Define the prototypes for the pseudo-ops */
103 static void s390_byte (int);
104 static void s390_elf_cons (int);
105 static void s390_insn (int);
106 static void s390_literals (int);
107 static void s390_machine (int);
108 static void s390_machinemode (int);
110 const pseudo_typeS md_pseudo_table
[] =
112 { "align", s_align_bytes
, 0 },
113 /* Pseudo-ops which must be defined. */
114 { "insn", s390_insn
, 0 },
115 /* Pseudo-ops which must be overridden. */
116 { "byte", s390_byte
, 0 },
117 { "short", s390_elf_cons
, 2 },
118 { "long", s390_elf_cons
, 4 },
119 { "quad", s390_elf_cons
, 8 },
120 { "ltorg", s390_literals
, 0 },
121 { "string", stringer
, 8 + 1 },
122 { "machine", s390_machine
, 0 },
123 { "machinemode", s390_machinemode
, 0 },
127 /* Register types. */
128 enum s390_register_type
130 S390_REGTYPE_AR
, /* Access register. */
131 S390_REGTYPE_CR
, /* Control register. */
132 S390_REGTYPE_FPR
, /* Floating-point register. */
133 S390_REGTYPE_GR
, /* General register. */
134 S390_REGTYPE_VR
, /* Vector register. */
137 /* Given NAME, find the register number associated with that name, return
138 the integer value associated with the given name or -1 on failure. */
141 reg_name_search (const char *name
)
145 if (strcasecmp (name
, "lit") == 0)
148 if (strcasecmp (name
, "sp") == 0)
151 if (name
[0] != 'a' && name
[0] != 'c' && name
[0] != 'f'
152 && name
[0] != 'r' && name
[0] != 'v')
155 if (ISDIGIT (name
[1]))
158 if (ISDIGIT (name
[2]))
159 val
= val
* 10 + name
[2] - '0';
162 if ((name
[0] != 'v' && val
> 15) || val
> 31)
170 * Summary of register_name().
172 * in: Input_line_pointer points to 1st char of operand.
174 * out: A expressionS.
175 * The operand may have been a register: in this case, X_op == O_register,
176 * X_add_number is set to the register number, and truth is returned.
177 * Input_line_pointer->(next non-blank) char after operand, or is in its
182 register_name (expressionS
*expressionP
)
189 /* Find the spelling of the operand. */
190 start
= name
= input_line_pointer
;
191 if (name
[0] == '%' && ISALPHA (name
[1]))
192 name
= ++input_line_pointer
;
196 c
= get_symbol_name (&name
);
197 reg_number
= reg_name_search (name
);
199 /* Put back the delimiting char. */
200 (void) restore_line_pointer (c
);
202 /* Look to see if it's in the register table. */
205 expressionP
->X_op
= O_register
;
206 expressionP
->X_add_number
= reg_number
;
210 expressionP
->X_md
= S390_REGTYPE_AR
;
213 expressionP
->X_md
= S390_REGTYPE_CR
;
216 expressionP
->X_md
= S390_REGTYPE_FPR
;
219 expressionP
->X_md
= S390_REGTYPE_GR
;
222 expressionP
->X_md
= S390_REGTYPE_VR
;
225 expressionP
->X_md
= 0;
228 /* Make the rest nice. */
229 expressionP
->X_add_symbol
= NULL
;
230 expressionP
->X_op_symbol
= NULL
;
234 /* Reset the line as if we had not done anything. */
235 input_line_pointer
= start
;
239 /* Local variables. */
241 /* Opformat hash table. */
242 static htab_t s390_opformat_hash
;
244 /* Opcode hash table. */
245 static htab_t s390_opcode_hash
= NULL
;
247 /* Flags to set in the elf header */
248 static flagword s390_flags
= 0;
250 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
252 #ifndef WORKING_DOT_WORD
253 int md_short_jump_size
= 4;
254 int md_long_jump_size
= 4;
257 const char *md_shortopts
= "A:m:kVQ:";
258 struct option md_longopts
[] = {
259 {NULL
, no_argument
, NULL
, 0}
261 size_t md_longopts_size
= sizeof (md_longopts
);
263 /* Initialize the default opcode arch and word size from the default
264 architecture name if not specified by an option. */
266 init_default_arch (void)
268 /* Default architecture size. */
269 if (strcmp (default_arch
, "s390") == 0)
271 if (s390_arch_size
== 0)
274 else if (strcmp (default_arch
, "s390x") == 0)
276 if (s390_arch_size
== 0)
280 as_fatal (_("Invalid default architecture, broken assembler."));
282 /* Default current architecture mode. */
283 if (current_mode_mask
== 0)
285 /* Default to z/Architecture mode if the CPU supports it. */
286 if (current_cpu
< S390_OPCODE_Z900
)
287 current_mode_mask
= 1 << S390_OPCODE_ESA
;
289 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
292 /* Determine whether the highgprs flag in the ELF header needs to be set. */
293 if ((s390_arch_size
== 32) && (current_mode_mask
& (1 << S390_OPCODE_ZARCH
)))
294 set_highgprs_p
= true;
297 /* Called by TARGET_FORMAT. */
299 s390_target_format (void)
301 /* We don't get a chance to initialize anything before we're called,
302 so handle that now. */
303 init_default_arch ();
305 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
308 /* Map a cpu string ARG as given with -march= or .machine to the respective
309 enum s390_opcode_cpu_val value. If ALLOW_EXTENSIONS is TRUE, the cpu name
310 can be followed by a list of cpu facility flags each beginning with the
311 character '+'. The active cpu flags are returned through *RET_FLAGS.
312 In case of an error, S390_OPCODE_MAXCPU is returned. */
315 s390_parse_cpu (const char *arg
,
316 unsigned int *ret_flags
,
317 bool allow_extensions
)
322 unsigned int name_len
;
323 const char * alt_name
;
324 unsigned int alt_name_len
;
326 } cpu_table
[S390_OPCODE_MAXCPU
] =
328 { STRING_COMMA_LEN ("g5"), STRING_COMMA_LEN ("arch3"), 0 },
329 { STRING_COMMA_LEN ("g6"), STRING_COMMA_LEN (""), 0 },
330 { STRING_COMMA_LEN ("z900"), STRING_COMMA_LEN ("arch5"), 0 },
331 { STRING_COMMA_LEN ("z990"), STRING_COMMA_LEN ("arch6"), 0 },
332 { STRING_COMMA_LEN ("z9-109"), STRING_COMMA_LEN (""), 0 },
333 { STRING_COMMA_LEN ("z9-ec"), STRING_COMMA_LEN ("arch7"), 0 },
334 { STRING_COMMA_LEN ("z10"), STRING_COMMA_LEN ("arch8"), 0 },
335 { STRING_COMMA_LEN ("z196"), STRING_COMMA_LEN ("arch9"), 0 },
336 { STRING_COMMA_LEN ("zEC12"), STRING_COMMA_LEN ("arch10"),
337 S390_INSTR_FLAG_HTM
},
338 { STRING_COMMA_LEN ("z13"), STRING_COMMA_LEN ("arch11"),
339 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
340 { STRING_COMMA_LEN ("z14"), STRING_COMMA_LEN ("arch12"),
341 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
342 { STRING_COMMA_LEN ("z15"), STRING_COMMA_LEN ("arch13"),
343 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
},
344 { STRING_COMMA_LEN ("z16"), STRING_COMMA_LEN ("arch14"),
345 S390_INSTR_FLAG_HTM
| S390_INSTR_FLAG_VX
}
354 { "htm", S390_INSTR_FLAG_HTM
, true },
355 { "nohtm", S390_INSTR_FLAG_HTM
, false },
356 { "vx", S390_INSTR_FLAG_VX
, true },
357 { "novx", S390_INSTR_FLAG_VX
, false }
362 icpu
= S390_OPCODE_MAXCPU
;
363 if (startswith (arg
, "all") && (arg
[3] == 0 || arg
[3] == '+'))
365 icpu
= S390_OPCODE_MAXCPU
- 1;
370 for (icpu
= 0; icpu
< S390_OPCODE_MAXCPU
; icpu
++)
372 unsigned int l
, l_alt
;
374 l
= cpu_table
[icpu
].name_len
;
376 if (strncmp (arg
, cpu_table
[icpu
].name
, l
) == 0
377 && (arg
[l
] == 0 || arg
[l
] == '+'))
383 l_alt
= cpu_table
[icpu
].alt_name_len
;
386 && strncmp (arg
, cpu_table
[icpu
].alt_name
, l_alt
) == 0
387 && (arg
[l_alt
] == 0 || arg
[l_alt
] == '+'))
395 if (icpu
== S390_OPCODE_MAXCPU
)
396 return S390_OPCODE_MAXCPU
;
398 ilp_bak
= input_line_pointer
;
399 if (icpu
!= S390_OPCODE_MAXCPU
)
401 input_line_pointer
= (char *) arg
;
402 *ret_flags
= (cpu_table
[icpu
].flags
& S390_INSTR_FLAG_FACILITY_MASK
);
404 while (*input_line_pointer
== '+' && allow_extensions
)
410 input_line_pointer
++;
411 c
= get_symbol_name (&sym
);
412 for (iflag
= 0; iflag
< ARRAY_SIZE (cpu_flags
); iflag
++)
414 if (strcmp (sym
, cpu_flags
[iflag
].name
) == 0)
416 if (cpu_flags
[iflag
].on
)
417 *ret_flags
|= cpu_flags
[iflag
].mask
;
419 *ret_flags
&= ~cpu_flags
[iflag
].mask
;
423 if (iflag
== ARRAY_SIZE (cpu_flags
))
424 as_bad (_("no such machine extension `%s'"), sym
- 1);
425 *input_line_pointer
= c
;
426 if (iflag
== ARRAY_SIZE (cpu_flags
))
433 if (*input_line_pointer
!= 0 && *input_line_pointer
!= '\n')
435 as_bad (_("junk at end of machine string, first unrecognized character"
436 " is `%c'"), *input_line_pointer
);
437 icpu
= S390_OPCODE_MAXCPU
;
439 input_line_pointer
= ilp_bak
;
445 md_parse_option (int c
, const char *arg
)
449 /* -k: Ignore for FreeBSD compatibility. */
453 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
456 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
459 else if (arg
!= NULL
&& strcmp (arg
, "warn-areg-zero") == 0)
460 warn_areg_zero
= true;
462 else if (arg
!= NULL
&& strcmp (arg
, "warn-regtype-mismatch=strict") == 0)
463 warn_regtype_mismatch
= S390_REGTYPE_CHECK_STRICT
;
465 else if (arg
!= NULL
&& strcmp (arg
, "warn-regtype-mismatch=relaxed") == 0)
466 warn_regtype_mismatch
= S390_REGTYPE_CHECK_RELAXED
;
468 else if (arg
!= NULL
&& strcmp (arg
, "warn-regtype-mismatch=no") == 0)
469 warn_regtype_mismatch
= S390_REGTYPE_CHECK_NONE
;
471 else if (arg
!= NULL
&& strcmp (arg
, "no-warn-regtype-mismatch") == 0)
472 warn_regtype_mismatch
= S390_REGTYPE_CHECK_NONE
;
474 else if (arg
!= NULL
&& strcmp (arg
, "31") == 0)
477 else if (arg
!= NULL
&& strcmp (arg
, "64") == 0)
480 else if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
481 current_mode_mask
= 1 << S390_OPCODE_ESA
;
483 else if (arg
!= NULL
&& strcmp (arg
, "zarch") == 0)
484 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
486 else if (arg
!= NULL
&& startswith (arg
, "arch="))
488 current_cpu
= s390_parse_cpu (arg
+ 5, ¤t_flags
, false);
489 if (current_cpu
== S390_OPCODE_MAXCPU
)
491 as_bad (_("invalid switch -m%s"), arg
);
498 as_bad (_("invalid switch -m%s"), arg
);
504 /* Option -A is deprecated. Still available for compatibility. */
505 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
506 current_cpu
= S390_OPCODE_G5
;
507 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
508 current_cpu
= S390_OPCODE_Z900
;
510 as_bad (_("invalid architecture -A%s"), arg
);
513 /* -V: SVR4 argument to print version ID. */
518 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
519 should be emitted or not. FIXME: Not implemented. */
531 md_show_usage (FILE *stream
)
533 fprintf (stream
, _("\
535 -m31 generate 31-bit file format (31/32 bit word size)\n\
536 -m64 generate 64-bit file format (64 bit word size)\n\
537 -mesa assemble for Enterprise System Architecture/390\n\
538 -mzarch assemble for z/Architecture\n\
539 -march=<processor> assemble for processor <processor>\n\
540 -mregnames allow symbolic names for registers\n\
541 -mno-regnames do not allow symbolic names for registers\n\
542 -mwarn-areg-zero warn about base/index register zero\n\
543 -mwarn-regtype-mismatch=strict\n\
544 warn about register name type mismatches\n\
545 -mwarn-regtype-mismatch=relaxed\n\
546 warn about register name type mismatches,\n\
547 but allow FPR and VR to be used interchangeably\n\
548 -mno-warn-regtype-mismatch\n\
549 do not warn about register name type mismatches\n\
551 fprintf (stream
, _("\
552 -V print assembler version number\n\
553 -Qy, -Qn ignored\n"));
554 fprintf (stream
, _("\
555 Deprecated S390 options:\n\
556 -Aesa assemble for processor IBM S/390 G5 (g5/arch3)\n\
557 -Aesame assemble for processor IBM zSeries 900 (z900/arch5)\n"));
560 /* Generate the hash table mapping mnemonics to struct s390_opcode.
561 This table is built at startup and whenever the CPU level is
562 changed using .machine. */
565 s390_setup_opcodes (void)
567 const struct s390_opcode
*op
;
568 const struct s390_opcode
*op_end
;
569 bool dup_insn
= false;
571 if (s390_opcode_hash
!= NULL
)
572 htab_delete (s390_opcode_hash
);
574 /* Insert the opcodes into a hash table. */
575 s390_opcode_hash
= str_htab_create ();
577 op_end
= s390_opcodes
+ s390_num_opcodes
;
578 for (op
= s390_opcodes
; op
< op_end
; op
++)
582 while (op
< op_end
- 1 && strcmp(op
->name
, op
[1].name
) == 0)
584 if (op
->min_cpu
<= current_cpu
&& (op
->modes
& current_mode_mask
))
589 if ((op
->modes
& current_mode_mask
) == 0)
591 else if ((op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
) == 0)
593 /* Opcodes that do not belong to a specific facility are enabled if
594 present in the selected cpu. */
595 use_opcode
= (op
->min_cpu
<= current_cpu
);
601 /* Opcodes of a specific facility are enabled if the facility is
602 enabled. Note: only some facilities are represented as flags. */
603 f
= (op
->flags
& S390_INSTR_FLAG_FACILITY_MASK
);
604 use_opcode
= ((f
& current_flags
) == f
);
607 && str_hash_insert (s390_opcode_hash
, op
->name
, op
, 0) != NULL
)
609 as_bad (_("duplicate %s"), op
->name
);
613 while (op
< op_end
- 1 && strcmp (op
->name
, op
[1].name
) == 0)
621 /* This function is called when the assembler starts up. It is called
622 after the options have been parsed and the output file has been
628 const struct s390_opcode
*op
;
629 const struct s390_opcode
*op_end
;
631 /* Give a warning if the combination -m64 and -Aesa is used. */
632 if (s390_arch_size
== 64 && current_cpu
< S390_OPCODE_Z900
)
633 as_warn (_("The 64-bit file format is used without z/Architecture instructions."));
635 s390_cie_data_alignment
= -s390_arch_size
/ 8;
637 /* Set the ELF flags if desired. */
639 bfd_set_private_flags (stdoutput
, s390_flags
);
641 /* Insert the opcode formats into a hash table. */
642 s390_opformat_hash
= str_htab_create ();
644 op_end
= s390_opformats
+ s390_num_opformats
;
645 for (op
= s390_opformats
; op
< op_end
; op
++)
646 if (str_hash_insert (s390_opformat_hash
, op
->name
, op
, 0) != NULL
)
647 as_fatal (_("duplicate %s"), op
->name
);
649 s390_setup_opcodes ();
651 record_alignment (text_section
, 2);
652 record_alignment (data_section
, 2);
653 record_alignment (bss_section
, 2);
656 /* Called after all assembly has been done. */
658 s390_md_finish (void)
660 if (s390_arch_size
== 64)
661 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_64
);
663 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_31
);
667 s390_bad_operand_out_of_range (int operand_number
,
676 if (operand_number
> 0)
678 /* xgettext:c-format. */
679 err
=_("operand %d: operand out of range (%" PRId64
680 " is not between %" PRId64
" and %" PRId64
")");
682 as_bad_where (file
, line
, err
, operand_number
,
683 (int64_t) value
, (int64_t) min
, (int64_t) max
);
685 as_bad (err
, operand_number
,
686 (int64_t) value
, (int64_t) min
, (int64_t) max
);
690 /* xgettext:c-format. */
691 err
= _("operand out of range (%" PRId64
692 " is not between %" PRId64
" and %" PRId64
")");
694 as_bad_where (file
, line
, err
,
695 (int64_t) value
, (int64_t) min
, (int64_t) max
);
697 as_bad (err
, (int64_t) value
, (int64_t) min
, (int64_t) max
);
701 /* Insert an operand value into an instruction. */
704 s390_insert_operand (unsigned char *insn
,
705 const struct s390_operand
*operand
,
714 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
718 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
719 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
720 /* Halve PCREL operands. */
721 if (operand
->flags
& S390_OPERAND_PCREL
)
723 /* Check for underflow / overflow. */
724 if (val
< min
|| val
> max
)
726 if (operand
->flags
& S390_OPERAND_PCREL
)
728 val
= (offsetT
) ((addressT
) val
<< 1);
729 min
= (offsetT
) ((addressT
) min
<< 1);
730 max
= (offsetT
) ((addressT
) max
<< 1);
733 s390_bad_operand_out_of_range (operand_number
, val
, min
, max
,
738 /* val is ok, now restrict it to operand->bits bits. */
739 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
740 /* val is restrict, now check for special case. */
741 if (operand
->bits
== 20 && operand
->shift
== 20)
742 uval
= (uval
>> 12) | ((uval
& 0xfff) << 8);
748 max
= (((addressT
) 1 << (operand
->bits
- 1)) << 1) - 1;
750 uval
= (addressT
) val
;
752 /* Vector register operands have an additional bit in the RXB
754 if (operand
->flags
& S390_OPERAND_VR
)
755 max
= (max
<< 1) | 1;
757 /* Length x in an instructions has real length x+1. */
758 if (operand
->flags
& S390_OPERAND_LENGTH
)
760 /* Check for underflow / overflow. */
761 if (uval
< min
|| uval
> max
)
763 if (operand
->flags
& S390_OPERAND_LENGTH
)
770 s390_bad_operand_out_of_range (operand_number
, val
, min
, max
,
777 if (operand
->flags
& S390_OPERAND_VR
)
779 /* Insert the extra bit into the RXB field. */
780 switch (operand
->shift
)
783 insn
[4] |= (uval
& 0x10) >> 1;
786 insn
[4] |= (uval
& 0x10) >> 2;
789 insn
[4] |= (uval
& 0x10) >> 3;
792 insn
[4] |= (uval
& 0x10) >> 4;
798 if (operand
->flags
& S390_OPERAND_OR1
)
800 if (operand
->flags
& S390_OPERAND_OR2
)
802 if (operand
->flags
& S390_OPERAND_OR8
)
805 /* Duplicate the GPR/VR operand at bit pos 12 to 16. */
806 if (operand
->flags
& S390_OPERAND_CP16
)
808 /* Copy GPR/VR operand at bit pos 12 to bit pos 16. */
809 insn
[2] |= uval
<< 4;
811 if (operand
->flags
& S390_OPERAND_VR
)
813 /* Copy the VR flag in the RXB field. */
814 insn
[4] |= (insn
[4] & 4) >> 1;
818 /* Insert fragments of the operand byte for byte. */
819 offset
= operand
->shift
+ operand
->bits
;
820 uval
<<= (-offset
) & 7;
821 insn
+= (offset
- 1) / 8;
833 bfd_reloc_code_real_type reloc
;
836 /* Parse tls marker and return the desired relocation. */
837 static bfd_reloc_code_real_type
838 s390_tls_suffix (char **str_p
, expressionS
*exp_p
)
840 static struct map_tls mapping
[] =
842 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD
},
843 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL
},
844 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL
},
845 { NULL
, 0, BFD_RELOC_UNUSED
}
855 return BFD_RELOC_UNUSED
;
858 while (ISIDNUM (*str
))
862 return BFD_RELOC_UNUSED
;
864 orig_line
= input_line_pointer
;
865 input_line_pointer
= str
;
867 str
= input_line_pointer
;
868 if (&input_line_pointer
!= str_p
)
869 input_line_pointer
= orig_line
;
871 if (exp_p
->X_op
!= O_symbol
)
872 return BFD_RELOC_UNUSED
;
874 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
875 if (len
== ptr
->length
876 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
878 /* Found a matching tls suffix. */
882 return BFD_RELOC_UNUSED
;
885 /* Structure used to hold suffixes. */
896 ELF_SUFFIX_TLS_GOTIE
,
908 elf_suffix_type suffix
;
912 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
913 static elf_suffix_type
914 s390_elf_suffix (char **str_p
, expressionS
*exp_p
)
916 static struct map_bfd mapping
[] =
918 { "got", 3, ELF_SUFFIX_GOT
},
919 { "got12", 5, ELF_SUFFIX_GOT
},
920 { "plt", 3, ELF_SUFFIX_PLT
},
921 { "gotent", 6, ELF_SUFFIX_GOTENT
},
922 { "gotoff", 6, ELF_SUFFIX_GOTOFF
},
923 { "gotplt", 6, ELF_SUFFIX_GOTPLT
},
924 { "pltoff", 6, ELF_SUFFIX_PLTOFF
},
925 { "tlsgd", 5, ELF_SUFFIX_TLS_GD
},
926 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE
},
927 { "indntpoff", 9, ELF_SUFFIX_TLS_IE
},
928 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM
},
929 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO
},
930 { "ntpoff", 6, ELF_SUFFIX_TLS_LE
},
931 { NULL
, 0, ELF_SUFFIX_NONE
}
940 return ELF_SUFFIX_NONE
;
943 while (ISALNUM (*str
))
947 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
948 if (len
== ptr
->length
949 && strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
951 if (exp_p
->X_add_number
!= 0)
952 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
953 ptr
->string
, ptr
->string
);
954 /* Now check for identifier@suffix+constant. */
955 if (*str
== '-' || *str
== '+')
957 char *orig_line
= input_line_pointer
;
960 input_line_pointer
= str
;
961 expression (&new_exp
);
963 switch (new_exp
.X_op
)
965 case O_constant
: /* X_add_number (a constant expression). */
966 exp_p
->X_add_number
+= new_exp
.X_add_number
;
967 str
= input_line_pointer
;
969 case O_symbol
: /* X_add_symbol + X_add_number. */
970 /* this case is used for e.g. xyz@PLT+.Label. */
971 exp_p
->X_add_number
+= new_exp
.X_add_number
;
972 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
974 str
= input_line_pointer
;
976 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
977 /* this case is used for e.g. xyz@PLT-.Label. */
978 exp_p
->X_add_number
+= new_exp
.X_add_number
;
979 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
980 exp_p
->X_op
= O_subtract
;
981 str
= input_line_pointer
;
987 /* If s390_elf_suffix has not been called with
988 &input_line_pointer as first parameter, we have
989 clobbered the input_line_pointer. We have to
991 if (&input_line_pointer
!= str_p
)
992 input_line_pointer
= orig_line
;
998 return ELF_SUFFIX_NONE
;
1001 /* Structure used to hold a literal pool entry. */
1004 struct s390_lpe
*next
;
1006 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
1007 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
1009 bfd_reloc_code_real_type reloc
;
1013 static struct s390_lpe
*lpe_free_list
= NULL
;
1014 static struct s390_lpe
*lpe_list
= NULL
;
1015 static struct s390_lpe
*lpe_list_tail
= NULL
;
1016 static symbolS
*lp_sym
= NULL
;
1017 static int lp_count
= 0;
1018 static int lpe_count
= 0;
1021 s390_exp_compare (expressionS
*exp1
, expressionS
*exp2
)
1023 if (exp1
->X_op
!= exp2
->X_op
)
1028 case O_constant
: /* X_add_number must be equal. */
1030 return exp1
->X_add_number
== exp2
->X_add_number
;
1033 as_bad (_("Can't handle O_big in s390_exp_compare"));
1036 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
1041 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
1042 && (exp1
->X_add_number
== exp2
->X_add_number
);
1044 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
1049 case O_bit_inclusive_or
:
1051 case O_bit_exclusive_or
:
1063 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
)
1064 && (exp1
->X_op_symbol
== exp2
->X_op_symbol
)
1065 && (exp1
->X_add_number
== exp2
->X_add_number
);
1071 /* Test for @lit and if it's present make an entry in the literal pool and
1072 modify the current expression to be an offset into the literal pool. */
1073 static elf_suffix_type
1074 s390_lit_suffix (char **str_p
, expressionS
*exp_p
, elf_suffix_type suffix
)
1076 bfd_reloc_code_real_type reloc
;
1080 struct s390_lpe
*lpe
;
1084 return suffix
; /* No modification. */
1086 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
1088 while (ISALNUM (*str
))
1091 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0
1092 || (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
1093 return suffix
; /* no modification */
1094 nbytes
= ident
[3] - '0';
1096 reloc
= BFD_RELOC_UNUSED
;
1097 if (suffix
== ELF_SUFFIX_GOT
)
1100 reloc
= BFD_RELOC_390_GOT16
;
1101 else if (nbytes
== 4)
1102 reloc
= BFD_RELOC_32_GOT_PCREL
;
1103 else if (nbytes
== 8)
1104 reloc
= BFD_RELOC_390_GOT64
;
1106 else if (suffix
== ELF_SUFFIX_PLT
)
1109 reloc
= BFD_RELOC_390_PLT32
;
1110 else if (nbytes
== 8)
1111 reloc
= BFD_RELOC_390_PLT64
;
1114 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1115 as_bad (_("Invalid suffix for literal pool entry"));
1117 /* Search the pool if the new entry is a duplicate. */
1118 if (exp_p
->X_op
== O_big
)
1120 /* Special processing for big numbers. */
1121 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1123 if (lpe
->ex
.X_op
== O_big
)
1125 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
1127 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
1128 sizeof (FLONUM_TYPE
)) == 0)
1131 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
1133 if (memcmp (generic_bignum
, lpe
->bignum
,
1134 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
1142 /* Processing for 'normal' data types. */
1143 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
1144 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
1145 && s390_exp_compare (exp_p
, &lpe
->ex
) != 0)
1151 /* A new literal. */
1152 if (lpe_free_list
!= NULL
)
1154 lpe
= lpe_free_list
;
1155 lpe_free_list
= lpe_free_list
->next
;
1159 lpe
= XNEW (struct s390_lpe
);
1164 if (exp_p
->X_op
== O_big
)
1166 if (exp_p
->X_add_number
<= 0)
1167 lpe
->floatnum
= generic_floating_point_number
;
1168 else if (exp_p
->X_add_number
<= 4)
1169 memcpy (lpe
->bignum
, generic_bignum
,
1170 exp_p
->X_add_number
* sizeof (LITTLENUM_TYPE
));
1172 as_bad (_("Big number is too big"));
1175 lpe
->nbytes
= nbytes
;
1177 /* Literal pool name defined ? */
1180 sprintf (tmp_name
, ".L\001%i", lp_count
);
1181 lp_sym
= symbol_make (tmp_name
);
1184 /* Make name for literal pool entry. */
1185 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
1187 lpe
->sym
= symbol_make (tmp_name
);
1189 /* Add to literal pool list. */
1191 if (lpe_list_tail
!= NULL
)
1193 lpe_list_tail
->next
= lpe
;
1194 lpe_list_tail
= lpe
;
1197 lpe_list
= lpe_list_tail
= lpe
;
1200 /* Now change exp_p to the offset into the literal pool.
1201 That's the expression: .L^Ax^By-.L^Ax */
1202 exp_p
->X_add_symbol
= lpe
->sym
;
1203 exp_p
->X_op_symbol
= lp_sym
;
1204 exp_p
->X_op
= O_subtract
;
1205 exp_p
->X_add_number
= 0;
1209 /* We change the suffix type to ELF_SUFFIX_NONE, because
1210 the difference of two local labels is just a number. */
1211 return ELF_SUFFIX_NONE
;
1214 /* Like normal .long/.short/.word, except support @got, etc.
1215 clobbers input_line_pointer, checks end-of-line. */
1217 s390_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long */)
1220 elf_suffix_type suffix
;
1222 if (is_it_end_of_statement ())
1224 demand_empty_rest_of_line ();
1232 if (exp
.X_op
== O_symbol
1233 && *input_line_pointer
== '@'
1234 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
1236 bfd_reloc_code_real_type reloc
;
1237 reloc_howto_type
*reloc_howto
;
1243 static bfd_reloc_code_real_type tab2
[] =
1245 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1246 BFD_RELOC_390_GOT16
, /* ELF_SUFFIX_GOT */
1247 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_PLT */
1248 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1249 BFD_RELOC_16_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1250 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTPLT */
1251 BFD_RELOC_390_PLTOFF16
, /* ELF_SUFFIX_PLTOFF */
1252 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GD */
1253 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_GOTIE */
1254 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_IE */
1255 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDM */
1256 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_TLS_LDO */
1257 BFD_RELOC_UNUSED
/* ELF_SUFFIX_TLS_LE */
1259 reloc
= tab2
[suffix
];
1261 else if (nbytes
== 4)
1263 static bfd_reloc_code_real_type tab4
[] =
1265 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1266 BFD_RELOC_32_GOT_PCREL
, /* ELF_SUFFIX_GOT */
1267 BFD_RELOC_390_PLT32
, /* ELF_SUFFIX_PLT */
1268 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1269 BFD_RELOC_32_GOTOFF
, /* ELF_SUFFIX_GOTOFF */
1270 BFD_RELOC_390_GOTPLT32
, /* ELF_SUFFIX_GOTPLT */
1271 BFD_RELOC_390_PLTOFF32
, /* ELF_SUFFIX_PLTOFF */
1272 BFD_RELOC_390_TLS_GD32
, /* ELF_SUFFIX_TLS_GD */
1273 BFD_RELOC_390_TLS_GOTIE32
, /* ELF_SUFFIX_TLS_GOTIE */
1274 BFD_RELOC_390_TLS_IE32
, /* ELF_SUFFIX_TLS_IE */
1275 BFD_RELOC_390_TLS_LDM32
, /* ELF_SUFFIX_TLS_LDM */
1276 BFD_RELOC_390_TLS_LDO32
, /* ELF_SUFFIX_TLS_LDO */
1277 BFD_RELOC_390_TLS_LE32
/* ELF_SUFFIX_TLS_LE */
1279 reloc
= tab4
[suffix
];
1281 else if (nbytes
== 8)
1283 static bfd_reloc_code_real_type tab8
[] =
1285 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_NONE */
1286 BFD_RELOC_390_GOT64
, /* ELF_SUFFIX_GOT */
1287 BFD_RELOC_390_PLT64
, /* ELF_SUFFIX_PLT */
1288 BFD_RELOC_UNUSED
, /* ELF_SUFFIX_GOTENT */
1289 BFD_RELOC_390_GOTOFF64
, /* ELF_SUFFIX_GOTOFF */
1290 BFD_RELOC_390_GOTPLT64
, /* ELF_SUFFIX_GOTPLT */
1291 BFD_RELOC_390_PLTOFF64
, /* ELF_SUFFIX_PLTOFF */
1292 BFD_RELOC_390_TLS_GD64
, /* ELF_SUFFIX_TLS_GD */
1293 BFD_RELOC_390_TLS_GOTIE64
, /* ELF_SUFFIX_TLS_GOTIE */
1294 BFD_RELOC_390_TLS_IE64
, /* ELF_SUFFIX_TLS_IE */
1295 BFD_RELOC_390_TLS_LDM64
, /* ELF_SUFFIX_TLS_LDM */
1296 BFD_RELOC_390_TLS_LDO64
, /* ELF_SUFFIX_TLS_LDO */
1297 BFD_RELOC_390_TLS_LE64
/* ELF_SUFFIX_TLS_LE */
1299 reloc
= tab8
[suffix
];
1302 reloc
= BFD_RELOC_UNUSED
;
1304 if (reloc
!= BFD_RELOC_UNUSED
1305 && (reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
)))
1307 size
= bfd_get_reloc_size (reloc_howto
);
1309 as_bad (ngettext ("%s relocations do not fit in %d byte",
1310 "%s relocations do not fit in %d bytes",
1312 reloc_howto
->name
, nbytes
);
1313 where
= frag_more (nbytes
);
1314 md_number_to_chars (where
, 0, size
);
1315 /* To make fixup_segment do the pc relative conversion the
1316 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1317 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1318 size
, &exp
, false, reloc
);
1321 as_bad (_("relocation not applicable"));
1324 emit_expr (&exp
, (unsigned int) nbytes
);
1326 while (*input_line_pointer
++ == ',');
1328 input_line_pointer
--; /* Put terminator back into stream. */
1329 demand_empty_rest_of_line ();
1333 operand_type_str(const struct s390_operand
* operand
)
1335 if (operand
->flags
& S390_OPERAND_BASE
)
1336 return _("base register");
1337 else if (operand
->flags
& S390_OPERAND_DISP
)
1338 return _("displacement");
1339 else if (operand
->flags
& S390_OPERAND_INDEX
)
1341 if (operand
->flags
& S390_OPERAND_VR
)
1342 return _("vector index register");
1344 return _("index register");
1346 else if (operand
->flags
& S390_OPERAND_LENGTH
)
1348 else if (operand
->flags
& S390_OPERAND_AR
)
1349 return _("access register");
1350 else if (operand
->flags
& S390_OPERAND_CR
)
1351 return _("control register");
1352 else if (operand
->flags
& S390_OPERAND_FPR
)
1353 return _("floating-point register");
1354 else if (operand
->flags
& S390_OPERAND_GPR
)
1355 return _("general-purpose register");
1356 else if (operand
->flags
& S390_OPERAND_VR
)
1357 return _("vector register");
1360 if (operand
->flags
& S390_OPERAND_SIGNED
)
1361 return _("signed number");
1363 return _("unsigned number");
1367 /* Return true if all remaining operands in the opcode with
1368 OPCODE_FLAGS can be skipped. */
1370 skip_optargs_p (unsigned int opcode_flags
, const unsigned char *opindex_ptr
)
1372 if ((opcode_flags
& (S390_INSTR_FLAG_OPTPARM
| S390_INSTR_FLAG_OPTPARM2
))
1373 && opindex_ptr
[0] != '\0'
1374 && opindex_ptr
[1] == '\0')
1377 if ((opcode_flags
& S390_INSTR_FLAG_OPTPARM2
)
1378 && opindex_ptr
[0] != '\0'
1379 && opindex_ptr
[1] != '\0'
1380 && opindex_ptr
[2] == '\0')
1385 /* We need to keep a list of fixups. We can't simply generate them as
1386 we go, because that would require us to first create the frag, and
1387 that would screw up references to ``.''. */
1393 bfd_reloc_code_real_type reloc
;
1396 #define MAX_INSN_FIXUPS (4)
1398 /* This routine is called for each instruction to be assembled. */
1401 md_gather_operands (char *str
,
1402 unsigned char *insn
,
1403 const struct s390_opcode
*opcode
)
1405 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1406 const struct s390_operand
*operand
;
1407 const unsigned char *opindex_ptr
;
1409 elf_suffix_type suffix
;
1410 bfd_reloc_code_real_type reloc
;
1411 int omitted_base_or_index
;
1416 while (ISSPACE (*str
))
1419 /* Gather the operands. */
1420 omitted_base_or_index
= 0; /* Whether B in D(L,B) or X in D(X,B) were omitted. */
1421 operand_number
= 1; /* Current operand number in e.g. R1,I2,M3,D4(B4). */
1423 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1427 operand
= s390_operands
+ *opindex_ptr
;
1429 if ((opcode
->flags
& (S390_INSTR_FLAG_OPTPARM
| S390_INSTR_FLAG_OPTPARM2
))
1432 /* Optional parameters might need to be ORed with a
1433 value so calling s390_insert_operand is needed. */
1434 s390_insert_operand (insn
, operand
, 0, NULL
, 0, operand_number
);
1438 if (omitted_base_or_index
&& (operand
->flags
& S390_OPERAND_INDEX
))
1440 /* Skip omitted optional index register operand in D(X,B) due to
1441 D(,B) or D(B). Skip comma, if D(,B). */
1444 omitted_base_or_index
= 0;
1448 /* Gather the operand. */
1449 hold
= input_line_pointer
;
1450 input_line_pointer
= str
;
1452 /* Parse the operand. */
1453 if (! register_name (&ex
))
1456 resolve_register (&ex
);
1459 str
= input_line_pointer
;
1460 input_line_pointer
= hold
;
1462 /* Write the operand to the insn. */
1463 if (ex
.X_op
== O_illegal
)
1464 as_bad (_("operand %d: illegal operand"), operand_number
);
1465 else if (ex
.X_op
== O_absent
)
1467 if (opindex_ptr
[0] == '\0')
1469 as_bad (_("operand %d: missing %s operand"), operand_number
,
1470 operand_type_str(operand
));
1472 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1474 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1476 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1478 /* We need to generate a fixup for the
1479 expression returned by s390_lit_suffix. */
1480 if (fc
>= MAX_INSN_FIXUPS
)
1481 as_fatal (_("operand %d: too many fixups"), operand_number
);
1482 fixups
[fc
].exp
= ex
;
1483 fixups
[fc
].opindex
= *opindex_ptr
;
1484 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1489 if ((operand
->flags
& S390_OPERAND_LENGTH
)
1490 && ex
.X_op
!= O_constant
)
1491 as_bad (_("operand %d: invalid length field specified"),
1493 if ((operand
->flags
& S390_OPERAND_INDEX
)
1494 && ex
.X_add_number
== 0
1496 as_warn (_("operand %d: index register specified but zero"),
1498 if ((operand
->flags
& S390_OPERAND_BASE
)
1499 && ex
.X_add_number
== 0
1501 as_warn (_("operand %d: base register specified but zero"),
1503 if ((operand
->flags
& S390_OPERAND_GPR
)
1504 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1505 && (ex
.X_add_number
& 1))
1506 as_bad (_("operand %d: odd numbered general purpose register "
1507 "specified as register pair"), operand_number
);
1508 if ((operand
->flags
& S390_OPERAND_FPR
)
1509 && (operand
->flags
& S390_OPERAND_REG_PAIR
)
1510 && ex
.X_add_number
!= 0 && ex
.X_add_number
!= 1
1511 && ex
.X_add_number
!= 4 && ex
.X_add_number
!= 5
1512 && ex
.X_add_number
!= 8 && ex
.X_add_number
!= 9
1513 && ex
.X_add_number
!= 12 && ex
.X_add_number
!= 13)
1514 as_bad (_("operand %d: invalid floating-point register (FPR) "
1515 "pair (valid FPR pair operands are 0, 1, 4, 5, 8, 9, "
1516 "12 or 13)"), operand_number
);
1517 if (warn_regtype_mismatch
&& ex
.X_op
== O_register
1518 && !(opcode
->flags
& S390_INSTR_FLAG_PSEUDO_MNEMONIC
))
1520 const char *expected_regtype
= NULL
;
1522 if ((operand
->flags
& S390_OPERAND_AR
)
1523 && ex
.X_md
!= S390_REGTYPE_AR
)
1524 expected_regtype
= _("access register");
1525 else if ((operand
->flags
& S390_OPERAND_CR
)
1526 && ex
.X_md
!= S390_REGTYPE_CR
)
1527 expected_regtype
= _("control register");
1528 else if ((operand
->flags
& S390_OPERAND_FPR
)
1529 && ex
.X_md
!= S390_REGTYPE_FPR
1530 && (warn_regtype_mismatch
== S390_REGTYPE_CHECK_STRICT
1531 || (ex
.X_md
!= S390_REGTYPE_VR
)))
1532 expected_regtype
= _("floating-point register");
1533 else if ((operand
->flags
& S390_OPERAND_GPR
)
1534 && ex
.X_md
!= S390_REGTYPE_GR
)
1535 expected_regtype
= _("general register");
1536 else if ((operand
->flags
& S390_OPERAND_VR
)
1537 && ex
.X_md
!= S390_REGTYPE_VR
1538 && (warn_regtype_mismatch
== S390_REGTYPE_CHECK_STRICT
1539 || (ex
.X_md
!= S390_REGTYPE_FPR
)))
1540 expected_regtype
= _("vector register");
1542 if (expected_regtype
)
1544 if (operand
->flags
& S390_OPERAND_BASE
)
1545 as_warn (_("operand %d: expected %s name as base register"),
1546 operand_number
, expected_regtype
);
1547 else if (operand
->flags
& S390_OPERAND_INDEX
)
1548 as_warn (_("operand %d: expected %s name as index register"),
1549 operand_number
, expected_regtype
);
1551 as_warn (_("operand %d: expected %s name"),
1552 operand_number
, expected_regtype
);
1555 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0, operand_number
);
1560 suffix
= s390_elf_suffix (&str
, &ex
);
1561 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1562 reloc
= BFD_RELOC_UNUSED
;
1564 if (suffix
== ELF_SUFFIX_GOT
)
1566 if ((operand
->flags
& S390_OPERAND_DISP
) &&
1567 (operand
->bits
== 12))
1568 reloc
= BFD_RELOC_390_GOT12
;
1569 else if ((operand
->flags
& S390_OPERAND_DISP
) &&
1570 (operand
->bits
== 20))
1571 reloc
= BFD_RELOC_390_GOT20
;
1572 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1573 && (operand
->bits
== 16))
1574 reloc
= BFD_RELOC_390_GOT16
;
1575 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1576 && (operand
->bits
== 32))
1577 reloc
= BFD_RELOC_390_GOTENT
;
1579 else if (suffix
== ELF_SUFFIX_PLT
)
1581 if ((operand
->flags
& S390_OPERAND_PCREL
)
1582 && (operand
->bits
== 12))
1583 reloc
= BFD_RELOC_390_PLT12DBL
;
1584 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1585 && (operand
->bits
== 16))
1586 reloc
= BFD_RELOC_390_PLT16DBL
;
1587 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1588 && (operand
->bits
== 24))
1589 reloc
= BFD_RELOC_390_PLT24DBL
;
1590 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1591 && (operand
->bits
== 32))
1592 reloc
= BFD_RELOC_390_PLT32DBL
;
1594 else if (suffix
== ELF_SUFFIX_GOTENT
)
1596 if ((operand
->flags
& S390_OPERAND_PCREL
)
1597 && (operand
->bits
== 32))
1598 reloc
= BFD_RELOC_390_GOTENT
;
1600 else if (suffix
== ELF_SUFFIX_GOTOFF
)
1602 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1603 && (operand
->bits
== 16))
1604 reloc
= BFD_RELOC_16_GOTOFF
;
1606 else if (suffix
== ELF_SUFFIX_PLTOFF
)
1608 if ((operand
->flags
& S390_OPERAND_SIGNED
)
1609 && (operand
->bits
== 16))
1610 reloc
= BFD_RELOC_390_PLTOFF16
;
1612 else if (suffix
== ELF_SUFFIX_GOTPLT
)
1614 if ((operand
->flags
& S390_OPERAND_DISP
)
1615 && (operand
->bits
== 12))
1616 reloc
= BFD_RELOC_390_GOTPLT12
;
1617 else if ((operand
->flags
& S390_OPERAND_SIGNED
)
1618 && (operand
->bits
== 16))
1619 reloc
= BFD_RELOC_390_GOTPLT16
;
1620 else if ((operand
->flags
& S390_OPERAND_PCREL
)
1621 && (operand
->bits
== 32))
1622 reloc
= BFD_RELOC_390_GOTPLTENT
;
1624 else if (suffix
== ELF_SUFFIX_TLS_GOTIE
)
1626 if ((operand
->flags
& S390_OPERAND_DISP
)
1627 && (operand
->bits
== 12))
1628 reloc
= BFD_RELOC_390_TLS_GOTIE12
;
1629 else if ((operand
->flags
& S390_OPERAND_DISP
)
1630 && (operand
->bits
== 20))
1631 reloc
= BFD_RELOC_390_TLS_GOTIE20
;
1633 else if (suffix
== ELF_SUFFIX_TLS_IE
)
1635 if ((operand
->flags
& S390_OPERAND_PCREL
)
1636 && (operand
->bits
== 32))
1637 reloc
= BFD_RELOC_390_TLS_IEENT
;
1640 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1641 as_bad (_("operand %d: invalid operand suffix"), operand_number
);
1642 /* We need to generate a fixup of type 'reloc' for this
1644 if (fc
>= MAX_INSN_FIXUPS
)
1645 as_fatal (_("operand %d: too many fixups"), operand_number
);
1646 fixups
[fc
].exp
= ex
;
1647 fixups
[fc
].opindex
= *opindex_ptr
;
1648 fixups
[fc
].reloc
= reloc
;
1652 /* Check the next character. The call to expression has advanced
1653 str past any whitespace. */
1654 if (operand
->flags
& S390_OPERAND_DISP
)
1656 /* After a displacement a block in parentheses can start. */
1659 /* There is no opening parentheses. Check if operands of
1660 parenthesized block can be skipped. Only index and base
1661 register operands as well as optional operands may be
1662 skipped. A length operand may not be skipped. */
1663 operand
= s390_operands
+ *(++opindex_ptr
);
1664 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1665 as_bad (_("operand %d: syntax error; missing '(' after displacement"),
1668 /* Ok, skip all operands until S390_OPERAND_BASE. */
1669 while (!(operand
->flags
& S390_OPERAND_BASE
))
1670 operand
= s390_operands
+ *(++opindex_ptr
);
1672 /* If there is no further input and the remaining operands are
1673 optional then have these optional operands processed. */
1674 if (*str
== '\0' && skip_optargs_p (opcode
->flags
, &opindex_ptr
[1]))
1677 /* If there is a next operand it must be separated by a comma. */
1678 if (opindex_ptr
[1] != '\0')
1682 /* There is no comma. Skip all operands and stop. */
1683 while (opindex_ptr
[1] != '\0')
1685 operand
= s390_operands
+ *(++opindex_ptr
);
1686 as_bad (_("operand %d: syntax error; expected ','"),
1701 /* We found an opening parentheses. */
1703 for (f
= str
; *f
!= '\0'; f
++)
1704 if (*f
== ',' || *f
== ')')
1706 /* If there is no comma until the closing parenthesis ')' or
1707 there is a comma right after the opening parenthesis '(',
1708 we have to skip the omitted optional index or base register
1710 - Index X in D(X,B), when D(,B) or D(B)
1711 - Base B in D(L,B), when D(L) */
1712 if (*f
== ',' && f
== str
)
1714 /* Comma directly after opening parenthesis '(' ? */
1715 omitted_base_or_index
= 1;
1718 omitted_base_or_index
= (*f
!= ',');
1721 else if (operand
->flags
& S390_OPERAND_BASE
)
1723 /* After the base register the parenthesised block ends. */
1725 as_bad (_("operand %d: syntax error; missing ')' after base register"),
1729 omitted_base_or_index
= 0;
1731 /* If there is no further input and the remaining operands are
1732 optional then have these optional operands processed. */
1733 if (*str
== '\0' && skip_optargs_p (opcode
->flags
, &opindex_ptr
[1]))
1736 /* If there is a next operand it must be separated by a comma. */
1737 if (opindex_ptr
[1] != '\0')
1741 /* There is no comma. Skip all operands and stop. */
1742 while (opindex_ptr
[1] != '\0')
1744 operand
= s390_operands
+ *(++opindex_ptr
);
1745 as_bad (_("operand %d: syntax error; expected ','"),
1760 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1761 of D(L,B). In this case the base register has to be skipped.
1762 Same if the base register has been explicilty omitted in e.g.
1764 if (*str
== ')' || (str
[0] == ',' && str
[1] == ')'))
1766 operand
= s390_operands
+ *(++opindex_ptr
);
1768 if (!(operand
->flags
& S390_OPERAND_BASE
))
1769 as_bad (_("operand %d: syntax error; '%c' not allowed here"),
1770 operand_number
, *str
);
1776 /* If there is no further input and the remaining operands are
1777 optional then have these optional operands processed. */
1778 if (*str
== '\0' && skip_optargs_p (opcode
->flags
, &opindex_ptr
[1]))
1781 /* If there is a next operand it must be separated by a comma. */
1782 if (opindex_ptr
[1] != '\0')
1786 /* There is no comma. Skip all operands and stop. */
1787 while (opindex_ptr
[1] != '\0')
1789 operand
= s390_operands
+ *(++opindex_ptr
);
1790 as_bad (_("operand %d: syntax error; expected ','"),
1799 if (!(operand
->flags
& (S390_OPERAND_INDEX
1800 | S390_OPERAND_LENGTH
)))
1807 while (ISSPACE (*str
))
1810 /* Check for tls instruction marker. */
1811 reloc
= s390_tls_suffix (&str
, &ex
);
1812 if (reloc
!= BFD_RELOC_UNUSED
)
1814 /* We need to generate a fixup of type 'reloc' for this
1816 if (fc
>= MAX_INSN_FIXUPS
)
1817 as_fatal (_("too many fixups"));
1818 fixups
[fc
].exp
= ex
;
1819 fixups
[fc
].opindex
= -1;
1820 fixups
[fc
].reloc
= reloc
;
1828 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1830 as_bad (_("junk at end of line: `%s'"), str
);
1831 if (linefeed
!= NULL
)
1835 /* Write out the instruction. */
1836 f
= frag_more (opcode
->oplen
);
1837 memcpy (f
, insn
, opcode
->oplen
);
1838 dwarf2_emit_insn (opcode
->oplen
);
1840 /* Create any fixups. At this point we do not use a
1841 bfd_reloc_code_real_type, but instead just use the
1842 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1843 handle fixups for any operand type, although that is admittedly
1844 not a very exciting feature. We pick a BFD reloc type in
1846 for (i
= 0; i
< fc
; i
++)
1850 if (fixups
[i
].opindex
< 0)
1852 /* Create tls instruction marker relocation. */
1853 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->oplen
,
1854 &fixups
[i
].exp
, 0, fixups
[i
].reloc
);
1858 operand
= s390_operands
+ fixups
[i
].opindex
;
1860 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1862 reloc_howto_type
*reloc_howto
;
1865 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1869 size
= ((reloc_howto
->bitsize
- 1) / 8) + 1;
1871 if (size
< 1 || size
> 4)
1874 fixP
= fix_new_exp (frag_now
,
1875 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1876 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1878 /* Turn off overflow checking in fixup_segment. This is necessary
1879 because fixup_segment will signal an overflow for large 4 byte
1880 quantities for GOT12 relocations. */
1881 if ( fixups
[i
].reloc
== BFD_RELOC_390_GOT12
1882 || fixups
[i
].reloc
== BFD_RELOC_390_GOT20
1883 || fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1884 fixP
->fx_no_overflow
= 1;
1886 if (operand
->flags
& S390_OPERAND_PCREL
)
1887 fixP
->fx_pcrel_adjust
= operand
->shift
/ 8;
1890 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1892 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1893 ((bfd_reloc_code_real_type
)
1894 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1895 /* s390_insert_operand () does the range checking. */
1896 if (operand
->flags
& S390_OPERAND_PCREL
)
1897 fixP
->fx_no_overflow
= 1;
1902 /* This routine is called for each instruction to be assembled. */
1905 md_assemble (char *str
)
1907 const struct s390_opcode
*opcode
;
1908 unsigned char insn
[6];
1911 /* Get the opcode. */
1912 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1917 /* Look up the opcode in the hash table. */
1918 opcode
= (struct s390_opcode
*) str_hash_find (s390_opcode_hash
, str
);
1919 if (opcode
== (const struct s390_opcode
*) NULL
)
1921 as_bad (_("Unrecognized opcode: `%s'"), str
);
1924 else if (!(opcode
->modes
& current_mode_mask
))
1926 as_bad (_("Opcode %s not available in this mode"), str
);
1929 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1930 md_gather_operands (s
, insn
, opcode
);
1933 #ifndef WORKING_DOT_WORD
1934 /* Handle long and short jumps. We don't support these */
1936 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1938 addressT from_addr
, to_addr
;
1946 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1948 addressT from_addr
, to_addr
;
1956 /* Pseudo-op handling. */
1959 s390_insn (int ignore ATTRIBUTE_UNUSED
)
1962 const struct s390_opcode
*opformat
;
1963 unsigned char insn
[6];
1966 /* Get the opcode format. */
1967 s
= input_line_pointer
;
1968 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1971 as_bad (_("Invalid .insn format\n"));
1974 /* Look up the opcode in the hash table. */
1975 opformat
= (struct s390_opcode
*)
1976 str_hash_find (s390_opformat_hash
, input_line_pointer
);
1977 if (opformat
== (const struct s390_opcode
*) NULL
)
1979 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1982 input_line_pointer
= s
;
1984 if (exp
.X_op
== O_constant
)
1986 if ( ( opformat
->oplen
== 6
1987 && (addressT
) exp
.X_add_number
< (1ULL << 48))
1988 || ( opformat
->oplen
== 4
1989 && (addressT
) exp
.X_add_number
< (1ULL << 32))
1990 || ( opformat
->oplen
== 2
1991 && (addressT
) exp
.X_add_number
< (1ULL << 16)))
1992 md_number_to_chars ((char *) insn
, exp
.X_add_number
, opformat
->oplen
);
1994 as_bad (_("Invalid .insn format\n"));
1996 else if (exp
.X_op
== O_big
)
1998 if (exp
.X_add_number
> 0
1999 && opformat
->oplen
== 6
2000 && generic_bignum
[3] == 0)
2002 md_number_to_chars ((char *) insn
, generic_bignum
[2], 2);
2003 md_number_to_chars ((char *) &insn
[2], generic_bignum
[1], 2);
2004 md_number_to_chars ((char *) &insn
[4], generic_bignum
[0], 2);
2007 as_bad (_("Invalid .insn format\n"));
2010 as_bad (_("second operand of .insn not a constant\n"));
2012 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
2013 as_bad (_("missing comma after insn constant\n"));
2015 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
2017 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
2021 demand_empty_rest_of_line ();
2024 /* The .byte pseudo-op. This is similar to the normal .byte
2025 pseudo-op, but it can also take a single ASCII string. */
2028 s390_byte (int ignore ATTRIBUTE_UNUSED
)
2030 if (*input_line_pointer
!= '\"')
2036 /* Gather characters. A real double quote is doubled. Unusual
2037 characters are not permitted. */
2038 ++input_line_pointer
;
2043 c
= *input_line_pointer
++;
2047 if (*input_line_pointer
!= '\"')
2049 ++input_line_pointer
;
2052 FRAG_APPEND_1_CHAR (c
);
2055 demand_empty_rest_of_line ();
2058 /* The .ltorg pseudo-op.This emits all literals defined since the last
2059 .ltorg or the invocation of gas. Literals are defined with the
2063 s390_literals (int ignore ATTRIBUTE_UNUSED
)
2065 struct s390_lpe
*lpe
;
2067 if (lp_sym
== NULL
|| lpe_count
== 0)
2068 return; /* Nothing to be done. */
2070 /* Emit symbol for start of literal pool. */
2071 S_SET_SEGMENT (lp_sym
, now_seg
);
2072 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
2073 symbol_set_frag (lp_sym
, frag_now
);
2078 lpe_list
= lpe_list
->next
;
2079 S_SET_SEGMENT (lpe
->sym
, now_seg
);
2080 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
2081 symbol_set_frag (lpe
->sym
, frag_now
);
2083 /* Emit literal pool entry. */
2084 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
2086 reloc_howto_type
*reloc_howto
=
2087 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
2088 int size
= bfd_get_reloc_size (reloc_howto
);
2091 if (size
> lpe
->nbytes
)
2092 as_bad (ngettext ("%s relocations do not fit in %d byte",
2093 "%s relocations do not fit in %d bytes",
2095 reloc_howto
->name
, lpe
->nbytes
);
2096 where
= frag_more (lpe
->nbytes
);
2097 md_number_to_chars (where
, 0, size
);
2098 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
2099 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
2103 if (lpe
->ex
.X_op
== O_big
)
2105 if (lpe
->ex
.X_add_number
<= 0)
2106 generic_floating_point_number
= lpe
->floatnum
;
2108 memcpy (generic_bignum
, lpe
->bignum
,
2109 lpe
->ex
.X_add_number
* sizeof (LITTLENUM_TYPE
));
2111 emit_expr (&lpe
->ex
, lpe
->nbytes
);
2114 lpe
->next
= lpe_free_list
;
2115 lpe_free_list
= lpe
;
2117 lpe_list_tail
= NULL
;
2123 #define MAX_HISTORY 100
2125 /* The .machine pseudo op allows one to switch to a different CPU level in
2126 the asm listing. The current CPU setting can be stored on a stack
2127 with .machine push and restored with .machine pop. */
2130 s390_machine (int ignore ATTRIBUTE_UNUSED
)
2133 static struct cpu_history
2138 static int curr_hist
;
2142 if (*input_line_pointer
== '"')
2145 cpu_string
= demand_copy_C_string (&len
);
2151 cpu_string
= input_line_pointer
;
2156 c
= get_symbol_name (&str
);
2157 c
= restore_line_pointer (c
);
2159 ++ input_line_pointer
;
2163 c
= *input_line_pointer
;
2164 *input_line_pointer
= 0;
2165 cpu_string
= xstrdup (cpu_string
);
2166 (void) restore_line_pointer (c
);
2169 if (cpu_string
!= NULL
)
2171 unsigned int new_cpu
= current_cpu
;
2172 unsigned int new_flags
= current_flags
;
2174 if (strcmp (cpu_string
, "push") == 0)
2176 if (cpu_history
== NULL
)
2177 cpu_history
= XNEWVEC (struct cpu_history
, MAX_HISTORY
);
2179 if (curr_hist
>= MAX_HISTORY
)
2180 as_bad (_(".machine stack overflow"));
2183 cpu_history
[curr_hist
].cpu
= current_cpu
;
2184 cpu_history
[curr_hist
].flags
= current_flags
;
2188 else if (strcmp (cpu_string
, "pop") == 0)
2191 as_bad (_(".machine stack underflow"));
2195 new_cpu
= cpu_history
[curr_hist
].cpu
;
2196 new_flags
= cpu_history
[curr_hist
].flags
;
2200 new_cpu
= s390_parse_cpu (cpu_string
, &new_flags
, true);
2202 if (new_cpu
== S390_OPCODE_MAXCPU
)
2203 as_bad (_("invalid machine `%s'"), cpu_string
);
2205 if (new_cpu
!= current_cpu
|| new_flags
!= current_flags
)
2207 current_cpu
= new_cpu
;
2208 current_flags
= new_flags
;
2209 s390_setup_opcodes ();
2213 demand_empty_rest_of_line ();
2216 /* The .machinemode pseudo op allows one to switch to a different
2217 architecture mode in the asm listing. The current architecture
2218 mode setting can be stored on a stack with .machinemode push and
2219 restored with .machinemode pop. */
2222 s390_machinemode (int ignore ATTRIBUTE_UNUSED
)
2225 static unsigned int *mode_history
;
2226 static int curr_hist
;
2233 c
= get_symbol_name (&mode_string
);
2234 mode_string
= xstrdup (mode_string
);
2235 (void) restore_line_pointer (c
);
2238 if (mode_string
!= NULL
)
2240 unsigned int old_mode_mask
= current_mode_mask
;
2243 for (p
= mode_string
; *p
!= 0; p
++)
2246 if (strcmp (mode_string
, "push") == 0)
2248 if (mode_history
== NULL
)
2249 mode_history
= XNEWVEC (unsigned int, MAX_HISTORY
);
2251 if (curr_hist
>= MAX_HISTORY
)
2252 as_bad (_(".machinemode stack overflow"));
2254 mode_history
[curr_hist
++] = current_mode_mask
;
2256 else if (strcmp (mode_string
, "pop") == 0)
2259 as_bad (_(".machinemode stack underflow"));
2261 current_mode_mask
= mode_history
[--curr_hist
];
2265 if (strcmp (mode_string
, "esa") == 0)
2266 current_mode_mask
= 1 << S390_OPCODE_ESA
;
2267 else if (strcmp (mode_string
, "zarch") == 0)
2269 if (s390_arch_size
== 32)
2270 set_highgprs_p
= true;
2271 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2273 else if (strcmp (mode_string
, "zarch_nohighgprs") == 0)
2274 current_mode_mask
= 1 << S390_OPCODE_ZARCH
;
2276 as_bad (_("invalid machine mode `%s'"), mode_string
);
2279 if (current_mode_mask
!= old_mode_mask
)
2280 s390_setup_opcodes ();
2283 demand_empty_rest_of_line ();
2289 md_atof (int type
, char *litp
, int *sizep
)
2291 return ieee_md_atof (type
, litp
, sizep
, true);
2294 /* Align a section (I don't know why this is machine dependent). */
2297 md_section_align (asection
*seg
, valueT addr
)
2299 int align
= bfd_section_alignment (seg
);
2301 return ((addr
+ (1 << align
) - 1) & -(1 << align
));
2304 /* We don't have any form of relaxing. */
2307 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
2308 asection
*seg ATTRIBUTE_UNUSED
)
2314 /* Convert a machine dependent frag. We never generate these. */
2317 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2318 asection
*sec ATTRIBUTE_UNUSED
,
2319 fragS
*fragp ATTRIBUTE_UNUSED
)
2325 md_undefined_symbol (char *name
)
2327 if (*name
== '_' && *(name
+ 1) == 'G'
2328 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
2332 if (symbol_find (name
))
2333 as_bad (_("GOT already in symbol table"));
2334 GOT_symbol
= symbol_new (name
, undefined_section
,
2335 &zero_address_frag
, 0);
2342 /* Functions concerning relocs. */
2344 /* The location from which a PC relative jump should be calculated,
2345 given a PC relative reloc. */
2348 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2350 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2353 /* Here we decide which fixups can be adjusted to make them relative to
2354 the beginning of the section instead of the symbol. Basically we need
2355 to make sure that the dynamic relocations are done correctly, so in
2356 some cases we force the original symbol to be used. */
2358 tc_s390_fix_adjustable (fixS
*fixP
)
2360 /* Don't adjust pc-relative references to merge sections. */
2362 && (S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0)
2365 /* adjust_reloc_syms doesn't know about the GOT. */
2366 if ( fixP
->fx_r_type
== BFD_RELOC_16_GOTOFF
2367 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2368 || fixP
->fx_r_type
== BFD_RELOC_390_GOTOFF64
2369 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF16
2370 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF32
2371 || fixP
->fx_r_type
== BFD_RELOC_390_PLTOFF64
2372 || fixP
->fx_r_type
== BFD_RELOC_390_PLT12DBL
2373 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
2374 || fixP
->fx_r_type
== BFD_RELOC_390_PLT24DBL
2375 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
2376 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
2377 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
2378 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
2379 || fixP
->fx_r_type
== BFD_RELOC_390_GOT20
2380 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
2381 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
2382 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
2383 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
2384 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT12
2385 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT16
2386 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT20
2387 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT32
2388 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLT64
2389 || fixP
->fx_r_type
== BFD_RELOC_390_GOTPLTENT
2390 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LOAD
2391 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GDCALL
2392 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDCALL
2393 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD32
2394 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GD64
2395 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE12
2396 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE20
2397 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE32
2398 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_GOTIE64
2399 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM32
2400 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDM64
2401 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE32
2402 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IE64
2403 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_IEENT
2404 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE32
2405 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LE64
2406 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO32
2407 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_LDO64
2408 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPMOD
2409 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_DTPOFF
2410 || fixP
->fx_r_type
== BFD_RELOC_390_TLS_TPOFF
2411 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2412 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2417 /* Return true if we must always emit a reloc for a type and false if
2418 there is some hope of resolving it at assembly time. */
2420 tc_s390_force_relocation (struct fix
*fixp
)
2422 /* Ensure we emit a relocation for every reference to the global
2423 offset table or to the procedure link table. */
2424 switch (fixp
->fx_r_type
)
2426 case BFD_RELOC_390_GOT12
:
2427 case BFD_RELOC_390_GOT20
:
2428 case BFD_RELOC_32_GOT_PCREL
:
2429 case BFD_RELOC_32_GOTOFF
:
2430 case BFD_RELOC_390_GOTOFF64
:
2431 case BFD_RELOC_390_PLTOFF16
:
2432 case BFD_RELOC_390_PLTOFF32
:
2433 case BFD_RELOC_390_PLTOFF64
:
2434 case BFD_RELOC_390_GOTPC
:
2435 case BFD_RELOC_390_GOT16
:
2436 case BFD_RELOC_390_GOTPCDBL
:
2437 case BFD_RELOC_390_GOT64
:
2438 case BFD_RELOC_390_GOTENT
:
2439 case BFD_RELOC_390_PLT32
:
2440 case BFD_RELOC_390_PLT12DBL
:
2441 case BFD_RELOC_390_PLT16DBL
:
2442 case BFD_RELOC_390_PLT24DBL
:
2443 case BFD_RELOC_390_PLT32DBL
:
2444 case BFD_RELOC_390_PLT64
:
2445 case BFD_RELOC_390_GOTPLT12
:
2446 case BFD_RELOC_390_GOTPLT16
:
2447 case BFD_RELOC_390_GOTPLT20
:
2448 case BFD_RELOC_390_GOTPLT32
:
2449 case BFD_RELOC_390_GOTPLT64
:
2450 case BFD_RELOC_390_GOTPLTENT
:
2456 return generic_force_reloc (fixp
);
2459 /* Apply a fixup to the object code. This is called for all the
2460 fixups we generated by the call to fix_new_exp, above. In the call
2461 above we used a reloc code which was the largest legal reloc code
2462 plus the operand index. Here we undo that to recover the operand
2463 index. At this point all symbol values should be fully resolved,
2464 and we attempt to completely resolve the reloc. If we can not do
2465 that, we determine the correct reloc code and put it back in the
2469 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2472 valueT value
= *valP
;
2474 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2476 if (fixP
->fx_subsy
!= NULL
)
2477 as_bad_subtract (fixP
);
2479 if (fixP
->fx_addsy
!= NULL
)
2482 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2487 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2489 const struct s390_operand
*operand
;
2492 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2493 operand
= &s390_operands
[opindex
];
2497 /* Insert the fully resolved operand value. */
2498 s390_insert_operand ((unsigned char *) where
, operand
,
2499 (offsetT
) value
, fixP
->fx_file
, fixP
->fx_line
, 0);
2503 /* Determine a BFD reloc value based on the operand information.
2504 We are only prepared to turn a few of the operands into
2506 fixP
->fx_offset
= value
;
2507 if (operand
->bits
== 12 && operand
->shift
== 20 && !fixP
->fx_pcrel
)
2510 fixP
->fx_where
+= 2;
2511 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2513 else if (operand
->bits
== 12 && operand
->shift
== 36 && !fixP
->fx_pcrel
)
2516 fixP
->fx_where
+= 4;
2517 fixP
->fx_r_type
= BFD_RELOC_390_12
;
2519 else if (operand
->bits
== 20 && operand
->shift
== 20 && !fixP
->fx_pcrel
)
2522 fixP
->fx_where
+= 2;
2523 fixP
->fx_r_type
= BFD_RELOC_390_20
;
2525 else if (operand
->bits
== 8 && operand
->shift
== 8 && !fixP
->fx_pcrel
)
2528 fixP
->fx_where
+= 1;
2529 fixP
->fx_r_type
= BFD_RELOC_8
;
2531 else if (operand
->bits
== 12 && operand
->shift
== 12
2532 && (operand
->flags
& S390_OPERAND_PCREL
))
2535 fixP
->fx_where
+= 1;
2536 fixP
->fx_offset
+= 1;
2537 fixP
->fx_pcrel_adjust
= 1;
2538 fixP
->fx_r_type
= BFD_RELOC_390_PC12DBL
;
2540 else if (operand
->bits
== 16 && operand
->shift
== 16)
2543 fixP
->fx_where
+= 2;
2544 if (operand
->flags
& S390_OPERAND_PCREL
)
2546 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2547 fixP
->fx_offset
+= 2;
2548 fixP
->fx_pcrel_adjust
= 2;
2550 else if (fixP
->fx_pcrel
)
2552 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
2553 fixP
->fx_offset
+= 2;
2554 fixP
->fx_pcrel_adjust
= 2;
2557 fixP
->fx_r_type
= BFD_RELOC_16
;
2559 else if (operand
->bits
== 16 && operand
->shift
== 32
2560 && (operand
->flags
& S390_OPERAND_PCREL
))
2563 fixP
->fx_where
+= 4;
2564 fixP
->fx_offset
+= 4;
2565 fixP
->fx_pcrel_adjust
= 4;
2566 fixP
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
2568 else if (operand
->bits
== 24 && operand
->shift
== 24
2569 && (operand
->flags
& S390_OPERAND_PCREL
))
2572 fixP
->fx_where
+= 3;
2573 fixP
->fx_offset
+= 3;
2574 fixP
->fx_pcrel_adjust
= 3;
2575 fixP
->fx_r_type
= BFD_RELOC_390_PC24DBL
;
2577 else if (operand
->bits
== 32 && operand
->shift
== 16
2578 && (operand
->flags
& S390_OPERAND_PCREL
))
2581 fixP
->fx_where
+= 2;
2582 fixP
->fx_offset
+= 2;
2583 fixP
->fx_pcrel_adjust
= 2;
2584 fixP
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
2591 /* Use expr_symbol_where to see if this is an expression
2593 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2594 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2595 _("unresolved expression that must be resolved"));
2597 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2598 _("unsupported relocation type"));
2605 switch (fixP
->fx_r_type
)
2611 md_number_to_chars (where
, value
, 1);
2613 case BFD_RELOC_390_12
:
2614 case BFD_RELOC_390_GOT12
:
2615 case BFD_RELOC_390_GOTPLT12
:
2616 case BFD_RELOC_390_PC12DBL
:
2617 case BFD_RELOC_390_PLT12DBL
:
2619 value
+= fixP
->fx_pcrel_adjust
;
2628 mop
= bfd_getb16 ((unsigned char *) where
);
2629 mop
|= (unsigned short) (value
& 0xfff);
2630 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
2634 case BFD_RELOC_390_20
:
2635 case BFD_RELOC_390_GOT20
:
2636 case BFD_RELOC_390_GOTPLT20
:
2640 mop
= bfd_getb32 ((unsigned char *) where
);
2641 mop
|= (unsigned int) ((value
& 0xfff) << 8 |
2642 (value
& 0xff000) >> 12);
2643 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
);
2648 case BFD_RELOC_GPREL16
:
2649 case BFD_RELOC_16_GOT_PCREL
:
2650 case BFD_RELOC_16_GOTOFF
:
2652 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2653 _("cannot emit PC relative %s relocation%s%s"),
2654 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2655 fixP
->fx_addsy
!= NULL
? " against " : "",
2656 (fixP
->fx_addsy
!= NULL
2657 ? S_GET_NAME (fixP
->fx_addsy
)
2660 md_number_to_chars (where
, value
, 2);
2662 case BFD_RELOC_390_GOT16
:
2663 case BFD_RELOC_390_PLTOFF16
:
2664 case BFD_RELOC_390_GOTPLT16
:
2666 md_number_to_chars (where
, value
, 2);
2668 case BFD_RELOC_390_PC16DBL
:
2669 case BFD_RELOC_390_PLT16DBL
:
2670 value
+= fixP
->fx_pcrel_adjust
;
2672 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
2675 case BFD_RELOC_390_PC24DBL
:
2676 case BFD_RELOC_390_PLT24DBL
:
2677 value
+= fixP
->fx_pcrel_adjust
;
2683 mop
= bfd_getb32 ((unsigned char *) where
- 1);
2684 mop
|= (unsigned int) (value
& 0xffffff);
2685 bfd_putb32 ((bfd_vma
) mop
, (unsigned char *) where
- 1);
2691 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2693 fixP
->fx_r_type
= BFD_RELOC_32
;
2695 md_number_to_chars (where
, value
, 4);
2697 case BFD_RELOC_32_PCREL
:
2698 case BFD_RELOC_32_BASEREL
:
2699 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2701 md_number_to_chars (where
, value
, 4);
2703 case BFD_RELOC_32_GOT_PCREL
:
2704 case BFD_RELOC_390_PLTOFF32
:
2705 case BFD_RELOC_390_PLT32
:
2706 case BFD_RELOC_390_GOTPLT32
:
2708 md_number_to_chars (where
, value
, 4);
2710 case BFD_RELOC_390_PC32DBL
:
2711 case BFD_RELOC_390_PLT32DBL
:
2712 case BFD_RELOC_390_GOTPCDBL
:
2713 case BFD_RELOC_390_GOTENT
:
2714 case BFD_RELOC_390_GOTPLTENT
:
2715 value
+= fixP
->fx_pcrel_adjust
;
2717 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
2720 case BFD_RELOC_32_GOTOFF
:
2722 md_number_to_chars (where
, value
, sizeof (int));
2725 case BFD_RELOC_390_GOTOFF64
:
2727 md_number_to_chars (where
, value
, 8);
2730 case BFD_RELOC_390_GOT64
:
2731 case BFD_RELOC_390_PLTOFF64
:
2732 case BFD_RELOC_390_PLT64
:
2733 case BFD_RELOC_390_GOTPLT64
:
2735 md_number_to_chars (where
, value
, 8);
2740 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2742 fixP
->fx_r_type
= BFD_RELOC_64
;
2744 md_number_to_chars (where
, value
, 8);
2747 case BFD_RELOC_64_PCREL
:
2748 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
2750 md_number_to_chars (where
, value
, 8);
2753 case BFD_RELOC_VTABLE_INHERIT
:
2754 case BFD_RELOC_VTABLE_ENTRY
:
2758 case BFD_RELOC_390_TLS_LOAD
:
2759 case BFD_RELOC_390_TLS_GDCALL
:
2760 case BFD_RELOC_390_TLS_LDCALL
:
2761 case BFD_RELOC_390_TLS_GD32
:
2762 case BFD_RELOC_390_TLS_GD64
:
2763 case BFD_RELOC_390_TLS_GOTIE12
:
2764 case BFD_RELOC_390_TLS_GOTIE20
:
2765 case BFD_RELOC_390_TLS_GOTIE32
:
2766 case BFD_RELOC_390_TLS_GOTIE64
:
2767 case BFD_RELOC_390_TLS_LDM32
:
2768 case BFD_RELOC_390_TLS_LDM64
:
2769 case BFD_RELOC_390_TLS_IE32
:
2770 case BFD_RELOC_390_TLS_IE64
:
2771 case BFD_RELOC_390_TLS_LE32
:
2772 case BFD_RELOC_390_TLS_LE64
:
2773 case BFD_RELOC_390_TLS_LDO32
:
2774 case BFD_RELOC_390_TLS_LDO64
:
2775 case BFD_RELOC_390_TLS_DTPMOD
:
2776 case BFD_RELOC_390_TLS_DTPOFF
:
2777 case BFD_RELOC_390_TLS_TPOFF
:
2778 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2779 /* Fully resolved at link time. */
2781 case BFD_RELOC_390_TLS_IEENT
:
2782 /* Fully resolved at link time. */
2783 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
2789 const char *reloc_name
= bfd_get_reloc_code_name (fixP
->fx_r_type
);
2791 if (reloc_name
!= NULL
)
2792 as_fatal (_("Gas failure, reloc type %s\n"), reloc_name
);
2794 as_fatal (_("Gas failure, reloc type #%i\n"), fixP
->fx_r_type
);
2798 fixP
->fx_offset
= value
;
2802 /* Generate a reloc for a fixup. */
2805 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2807 bfd_reloc_code_real_type code
;
2810 code
= fixp
->fx_r_type
;
2811 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
2813 if ( (s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
)
2814 || (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
2815 code
= BFD_RELOC_390_GOTPC
;
2816 if (code
== BFD_RELOC_390_PC32DBL
)
2817 code
= BFD_RELOC_390_GOTPCDBL
;
2820 reloc
= XNEW (arelent
);
2821 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
2822 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2823 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2824 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2825 if (reloc
->howto
== NULL
)
2827 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2828 _("cannot represent relocation type %s"),
2829 bfd_get_reloc_code_name (code
));
2830 /* Set howto to a garbage value so that we can keep going. */
2831 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2832 gas_assert (reloc
->howto
!= NULL
);
2834 reloc
->addend
= fixp
->fx_offset
;
2840 s390_cfi_frame_initial_instructions (void)
2842 cfi_add_CFA_def_cfa (15, s390_arch_size
== 64 ? 160 : 96);
2846 tc_s390_regname_to_dw2regnum (char *regname
)
2850 if (regname
[0] != 'c' && regname
[0] != 'a')
2852 regnum
= reg_name_search (regname
);
2853 if (regname
[0] == 'f' && regnum
!= -1)
2856 else if (strcmp (regname
, "ap") == 0)
2858 else if (strcmp (regname
, "cc") == 0)
2864 s390_elf_final_processing (void)
2867 elf_elfheader (stdoutput
)->e_flags
|= EF_S390_HIGH_GPRS
;