2004-07-12 Paolo Bonzini <bonzini@gnu.org>
[binutils.git] / gas / config / tc-s390.c
blob02427283d9e7e8f1dc719d2e1cedbdf89937aa9c
1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001, 2002, 2003, 2004 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 2, or (at your option)
10 any later version.
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, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include <stdio.h>
23 #include "as.h"
24 #include "safe-ctype.h"
25 #include "subsegs.h"
26 #include "struc-symbol.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "opcode/s390.h"
31 #include "elf/s390.h"
33 /* The default architecture. */
34 #ifndef DEFAULT_ARCH
35 #define DEFAULT_ARCH "s390"
36 #endif
37 static char *default_arch = DEFAULT_ARCH;
38 /* Either 32 or 64, selects file format. */
39 static int s390_arch_size = 0;
41 static unsigned int current_mode_mask = 0;
42 static unsigned int current_cpu = -1U;
44 /* Whether to use user friendly register names. Default is TRUE. */
45 #ifndef TARGET_REG_NAMES_P
46 #define TARGET_REG_NAMES_P TRUE
47 #endif
49 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
51 /* Set to TRUE if we want to warn about zero base/index registers. */
52 static bfd_boolean warn_areg_zero = FALSE;
54 /* Generic assembler global variables which must be defined by all
55 targets. */
57 const char comment_chars[] = "#";
59 /* Characters which start a comment at the beginning of a line. */
60 const char line_comment_chars[] = "#";
62 /* Characters which may be used to separate multiple commands on a
63 single line. */
64 const char line_separator_chars[] = ";";
66 /* Characters which are used to indicate an exponent in a floating
67 point number. */
68 const char EXP_CHARS[] = "eE";
70 /* Characters which mean that a number is a floating point constant,
71 as in 0d1.0. */
72 const char FLT_CHARS[] = "dD";
74 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
75 int s390_cie_data_alignment;
77 /* The target specific pseudo-ops which we support. */
79 /* Define the prototypes for the pseudo-ops */
80 static void s390_byte PARAMS ((int));
81 static void s390_elf_cons PARAMS ((int));
82 static void s390_bss PARAMS ((int));
83 static void s390_insn PARAMS ((int));
84 static void s390_literals PARAMS ((int));
86 const pseudo_typeS md_pseudo_table[] =
88 { "align", s_align_bytes, 0 },
89 /* Pseudo-ops which must be defined. */
90 { "bss", s390_bss, 0 },
91 { "insn", s390_insn, 0 },
92 /* Pseudo-ops which must be overridden. */
93 { "byte", s390_byte, 0 },
94 { "short", s390_elf_cons, 2 },
95 { "long", s390_elf_cons, 4 },
96 { "quad", s390_elf_cons, 8 },
97 { "ltorg", s390_literals, 0 },
98 { "string", stringer, 2 },
99 { NULL, NULL, 0 }
103 /* Structure to hold information about predefined registers. */
104 struct pd_reg
106 char *name;
107 int value;
110 /* List of registers that are pre-defined:
112 Each access register has a predefined name of the form:
113 a<reg_num> which has the value <reg_num>.
115 Each control register has a predefined name of the form:
116 c<reg_num> which has the value <reg_num>.
118 Each general register has a predefined name of the form:
119 r<reg_num> which has the value <reg_num>.
121 Each floating point register a has predefined name of the form:
122 f<reg_num> which has the value <reg_num>.
124 There are individual registers as well:
125 sp has the value 15
126 lit has the value 12
128 The table is sorted. Suitable for searching by a binary search. */
130 static const struct pd_reg pre_defined_registers[] =
132 { "a0", 0 }, /* Access registers */
133 { "a1", 1 },
134 { "a10", 10 },
135 { "a11", 11 },
136 { "a12", 12 },
137 { "a13", 13 },
138 { "a14", 14 },
139 { "a15", 15 },
140 { "a2", 2 },
141 { "a3", 3 },
142 { "a4", 4 },
143 { "a5", 5 },
144 { "a6", 6 },
145 { "a7", 7 },
146 { "a8", 8 },
147 { "a9", 9 },
149 { "c0", 0 }, /* Control registers */
150 { "c1", 1 },
151 { "c10", 10 },
152 { "c11", 11 },
153 { "c12", 12 },
154 { "c13", 13 },
155 { "c14", 14 },
156 { "c15", 15 },
157 { "c2", 2 },
158 { "c3", 3 },
159 { "c4", 4 },
160 { "c5", 5 },
161 { "c6", 6 },
162 { "c7", 7 },
163 { "c8", 8 },
164 { "c9", 9 },
166 { "f0", 0 }, /* Floating point registers */
167 { "f1", 1 },
168 { "f10", 10 },
169 { "f11", 11 },
170 { "f12", 12 },
171 { "f13", 13 },
172 { "f14", 14 },
173 { "f15", 15 },
174 { "f2", 2 },
175 { "f3", 3 },
176 { "f4", 4 },
177 { "f5", 5 },
178 { "f6", 6 },
179 { "f7", 7 },
180 { "f8", 8 },
181 { "f9", 9 },
183 { "lit", 13 }, /* Pointer to literal pool */
185 { "r0", 0 }, /* General purpose registers */
186 { "r1", 1 },
187 { "r10", 10 },
188 { "r11", 11 },
189 { "r12", 12 },
190 { "r13", 13 },
191 { "r14", 14 },
192 { "r15", 15 },
193 { "r2", 2 },
194 { "r3", 3 },
195 { "r4", 4 },
196 { "r5", 5 },
197 { "r6", 6 },
198 { "r7", 7 },
199 { "r8", 8 },
200 { "r9", 9 },
202 { "sp", 15 }, /* Stack pointer */
206 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
208 static int reg_name_search
209 PARAMS ((const struct pd_reg *, int, const char *));
210 static bfd_boolean register_name PARAMS ((expressionS *));
211 static void init_default_arch PARAMS ((void));
212 static void s390_insert_operand
213 PARAMS ((unsigned char *, const struct s390_operand *, offsetT, char *,
214 unsigned int));
215 static char *md_gather_operands
216 PARAMS ((char *, unsigned char *, const struct s390_opcode *));
218 /* Given NAME, find the register number associated with that name, return
219 the integer value associated with the given name or -1 on failure. */
221 static int
222 reg_name_search (regs, regcount, name)
223 const struct pd_reg *regs;
224 int regcount;
225 const char *name;
227 int middle, low, high;
228 int cmp;
230 low = 0;
231 high = regcount - 1;
235 middle = (low + high) / 2;
236 cmp = strcasecmp (name, regs[middle].name);
237 if (cmp < 0)
238 high = middle - 1;
239 else if (cmp > 0)
240 low = middle + 1;
241 else
242 return regs[middle].value;
244 while (low <= high);
246 return -1;
251 * Summary of register_name().
253 * in: Input_line_pointer points to 1st char of operand.
255 * out: A expressionS.
256 * The operand may have been a register: in this case, X_op == O_register,
257 * X_add_number is set to the register number, and truth is returned.
258 * Input_line_pointer->(next non-blank) char after operand, or is in its
259 * original state.
262 static bfd_boolean
263 register_name (expressionP)
264 expressionS *expressionP;
266 int reg_number;
267 char *name;
268 char *start;
269 char c;
271 /* Find the spelling of the operand. */
272 start = name = input_line_pointer;
273 if (name[0] == '%' && ISALPHA (name[1]))
274 name = ++input_line_pointer;
275 else
276 return FALSE;
278 c = get_symbol_end ();
279 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
281 /* Put back the delimiting char. */
282 *input_line_pointer = c;
284 /* Look to see if it's in the register table. */
285 if (reg_number >= 0)
287 expressionP->X_op = O_register;
288 expressionP->X_add_number = reg_number;
290 /* Make the rest nice. */
291 expressionP->X_add_symbol = NULL;
292 expressionP->X_op_symbol = NULL;
293 return TRUE;
296 /* Reset the line as if we had not done anything. */
297 input_line_pointer = start;
298 return FALSE;
301 /* Local variables. */
303 /* Opformat hash table. */
304 static struct hash_control *s390_opformat_hash;
306 /* Opcode hash table. */
307 static struct hash_control *s390_opcode_hash;
309 /* Flags to set in the elf header */
310 static flagword s390_flags = 0;
312 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
314 #ifndef WORKING_DOT_WORD
315 const int md_short_jump_size = 4;
316 const int md_long_jump_size = 4;
317 #endif
319 const char *md_shortopts = "A:m:kVQ:";
320 struct option md_longopts[] = {
321 {NULL, no_argument, NULL, 0}
323 size_t md_longopts_size = sizeof (md_longopts);
325 /* Initialize the default opcode arch and word size from the default
326 architecture name if not specified by an option. */
327 static void
328 init_default_arch ()
330 if (strcmp (default_arch, "s390") == 0)
332 if (s390_arch_size == 0)
333 s390_arch_size = 32;
335 else if (strcmp (default_arch, "s390x") == 0)
337 if (s390_arch_size == 0)
338 s390_arch_size = 64;
340 else
341 as_fatal ("Invalid default architecture, broken assembler.");
343 if (current_mode_mask == 0)
345 if (s390_arch_size == 32)
346 current_mode_mask = 1 << S390_OPCODE_ESA;
347 else
348 current_mode_mask = 1 << S390_OPCODE_ZARCH;
350 if (current_cpu == -1U)
352 if (current_mode_mask == (1 << S390_OPCODE_ESA))
353 current_cpu = S390_OPCODE_G5;
354 else
355 current_cpu = S390_OPCODE_Z900;
359 /* Called by TARGET_FORMAT. */
360 const char *
361 s390_target_format ()
363 /* We don't get a chance to initialize anything before we're called,
364 so handle that now. */
365 init_default_arch ();
367 return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
371 md_parse_option (c, arg)
372 int c;
373 char *arg;
375 switch (c)
377 /* -k: Ignore for FreeBSD compatibility. */
378 case 'k':
379 break;
380 case 'm':
381 if (arg != NULL && strcmp (arg, "regnames") == 0)
382 reg_names_p = TRUE;
384 else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
385 reg_names_p = FALSE;
387 else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
388 warn_areg_zero = TRUE;
390 else if (arg != NULL && strcmp (arg, "31") == 0)
391 s390_arch_size = 32;
393 else if (arg != NULL && strcmp (arg, "64") == 0)
394 s390_arch_size = 64;
396 else if (arg != NULL && strcmp (arg, "esa") == 0)
397 current_mode_mask = 1 << S390_OPCODE_ESA;
399 else if (arg != NULL && strcmp (arg, "zarch") == 0)
400 current_mode_mask = 1 << S390_OPCODE_ZARCH;
402 else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
404 if (strcmp (arg + 5, "g5") == 0)
405 current_cpu = S390_OPCODE_G5;
406 else if (strcmp (arg + 5, "g6") == 0)
407 current_cpu = S390_OPCODE_G6;
408 else if (strcmp (arg + 5, "z900") == 0)
409 current_cpu = S390_OPCODE_Z900;
410 else if (strcmp (arg + 5, "z990") == 0)
411 current_cpu = S390_OPCODE_Z990;
412 else
414 as_bad (_("invalid switch -m%s"), arg);
415 return 0;
419 else
421 as_bad (_("invalid switch -m%s"), arg);
422 return 0;
424 break;
426 case 'A':
427 /* Option -A is deprecated. Still available for compatibility. */
428 if (arg != NULL && strcmp (arg, "esa") == 0)
429 current_cpu = S390_OPCODE_G5;
430 else if (arg != NULL && strcmp (arg, "esame") == 0)
431 current_cpu = S390_OPCODE_Z900;
432 else
433 as_bad ("invalid architecture -A%s", arg);
434 break;
436 /* -V: SVR4 argument to print version ID. */
437 case 'V':
438 print_version_id ();
439 break;
441 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
442 should be emitted or not. FIXME: Not implemented. */
443 case 'Q':
444 break;
446 default:
447 return 0;
450 return 1;
453 void
454 md_show_usage (stream)
455 FILE *stream;
457 fprintf (stream, _("\
458 S390 options:\n\
459 -mregnames Allow symbolic names for registers\n\
460 -mwarn-areg-zero Warn about zero base/index registers\n\
461 -mno-regnames Do not allow symbolic names for registers\n\
462 -m31 Set file format to 31 bit format\n\
463 -m64 Set file format to 64 bit format\n"));
464 fprintf (stream, _("\
465 -V print assembler version number\n\
466 -Qy, -Qn ignored\n"));
469 /* This function is called when the assembler starts up. It is called
470 after the options have been parsed and the output file has been
471 opened. */
473 void
474 md_begin ()
476 register const struct s390_opcode *op;
477 const struct s390_opcode *op_end;
478 bfd_boolean dup_insn = FALSE;
479 const char *retval;
481 /* Give a warning if the combination -m64-bit and -Aesa is used. */
482 if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900)
483 as_warn ("The 64 bit file format is used without esame instructions.");
485 s390_cie_data_alignment = -s390_arch_size / 8;
487 /* Set the ELF flags if desired. */
488 if (s390_flags)
489 bfd_set_private_flags (stdoutput, s390_flags);
491 /* Insert the opcode formats into a hash table. */
492 s390_opformat_hash = hash_new ();
494 op_end = s390_opformats + s390_num_opformats;
495 for (op = s390_opformats; op < op_end; op++)
497 retval = hash_insert (s390_opformat_hash, op->name, (PTR) op);
498 if (retval != (const char *) NULL)
500 as_bad (_("Internal assembler error for instruction format %s"),
501 op->name);
502 dup_insn = TRUE;
506 /* Insert the opcodes into a hash table. */
507 s390_opcode_hash = hash_new ();
509 op_end = s390_opcodes + s390_num_opcodes;
510 for (op = s390_opcodes; op < op_end; op++)
511 if (op->min_cpu <= current_cpu)
513 retval = hash_insert (s390_opcode_hash, op->name, (PTR) op);
514 if (retval != (const char *) NULL)
516 as_bad (_("Internal assembler error for instruction %s"),
517 op->name);
518 dup_insn = TRUE;
520 while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0)
521 op++;
524 if (dup_insn)
525 abort ();
527 record_alignment (text_section, 2);
528 record_alignment (data_section, 2);
529 record_alignment (bss_section, 2);
533 /* Called after all assembly has been done. */
534 void
535 s390_md_end ()
537 if (s390_arch_size == 64)
538 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
539 else
540 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
543 /* Insert an operand value into an instruction. */
545 static void
546 s390_insert_operand (insn, operand, val, file, line)
547 unsigned char *insn;
548 const struct s390_operand *operand;
549 offsetT val;
550 char *file;
551 unsigned int line;
553 addressT uval;
554 int offset;
556 if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
558 offsetT min, max;
560 max = ((offsetT) 1 << (operand->bits - 1)) - 1;
561 min = - ((offsetT) 1 << (operand->bits - 1));
562 /* Halve PCREL operands. */
563 if (operand->flags & S390_OPERAND_PCREL)
564 val >>= 1;
565 /* Check for underflow / overflow. */
566 if (val < min || val > max)
568 const char *err =
569 "operand out of range (%s not between %ld and %ld)";
570 char buf[100];
572 if (operand->flags & S390_OPERAND_PCREL)
574 val <<= 1;
575 min <<= 1;
576 max <<= 1;
578 sprint_value (buf, val);
579 if (file == (char *) NULL)
580 as_bad (err, buf, (int) min, (int) max);
581 else
582 as_bad_where (file, line, err, buf, (int) min, (int) max);
583 return;
585 /* val is ok, now restrict it to operand->bits bits. */
586 uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
587 /* val is restrict, now check for special case. */
588 if (operand->bits == 20 && operand->shift == 20)
589 uval = (uval >> 12) | ((uval & 0xfff) << 8);
591 else
593 addressT min, max;
595 max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
596 min = (offsetT) 0;
597 uval = (addressT) val;
598 /* Length x in an instructions has real length x+1. */
599 if (operand->flags & S390_OPERAND_LENGTH)
600 uval--;
601 /* Check for underflow / overflow. */
602 if (uval < min || uval > max)
604 if (operand->flags & S390_OPERAND_LENGTH)
606 uval++;
607 min++;
608 max++;
611 as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line);
613 return;
617 /* Insert fragments of the operand byte for byte. */
618 offset = operand->shift + operand->bits;
619 uval <<= (-offset) & 7;
620 insn += (offset - 1) / 8;
621 while (uval != 0)
623 *insn-- |= uval;
624 uval >>= 8;
628 struct map_tls
630 char *string;
631 int length;
632 bfd_reloc_code_real_type reloc;
635 static bfd_reloc_code_real_type s390_tls_suffix
636 PARAMS ((char **, expressionS *));
638 /* Parse tls marker and return the desired relocation. */
639 static bfd_reloc_code_real_type
640 s390_tls_suffix (str_p, exp_p)
641 char **str_p;
642 expressionS *exp_p;
644 static struct map_tls mapping[] =
646 { "tls_load", 8, BFD_RELOC_390_TLS_LOAD },
647 { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL },
648 { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL },
649 { NULL, 0, BFD_RELOC_UNUSED }
651 struct map_tls *ptr;
652 char *orig_line;
653 char *str;
654 char *ident;
655 int len;
657 str = *str_p;
658 if (*str++ != ':')
659 return BFD_RELOC_UNUSED;
661 ident = str;
662 while (ISIDNUM (*str))
663 str++;
664 len = str - ident;
665 if (*str++ != ':')
666 return BFD_RELOC_UNUSED;
668 orig_line = input_line_pointer;
669 input_line_pointer = str;
670 expression (exp_p);
671 str = input_line_pointer;
672 if (&input_line_pointer != str_p)
673 input_line_pointer = orig_line;
675 if (exp_p->X_op != O_symbol)
676 return BFD_RELOC_UNUSED;
678 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
679 if (len == ptr->length
680 && strncasecmp (ident, ptr->string, ptr->length) == 0)
682 /* Found a matching tls suffix. */
683 *str_p = str;
684 return ptr->reloc;
686 return BFD_RELOC_UNUSED;
689 /* Structure used to hold suffixes. */
690 typedef enum
692 ELF_SUFFIX_NONE = 0,
693 ELF_SUFFIX_GOT,
694 ELF_SUFFIX_PLT,
695 ELF_SUFFIX_GOTENT,
696 ELF_SUFFIX_GOTOFF,
697 ELF_SUFFIX_GOTPLT,
698 ELF_SUFFIX_PLTOFF,
699 ELF_SUFFIX_TLS_GD,
700 ELF_SUFFIX_TLS_GOTIE,
701 ELF_SUFFIX_TLS_IE,
702 ELF_SUFFIX_TLS_LDM,
703 ELF_SUFFIX_TLS_LDO,
704 ELF_SUFFIX_TLS_LE
706 elf_suffix_type;
708 struct map_bfd
710 char *string;
711 int length;
712 elf_suffix_type suffix;
715 static elf_suffix_type s390_elf_suffix PARAMS ((char **, expressionS *));
716 static int s390_exp_compare PARAMS ((expressionS *exp1, expressionS *exp2));
717 static elf_suffix_type s390_lit_suffix
718 PARAMS ((char **, expressionS *, elf_suffix_type));
721 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
722 static elf_suffix_type
723 s390_elf_suffix (str_p, exp_p)
724 char **str_p;
725 expressionS *exp_p;
727 static struct map_bfd mapping[] =
729 { "got", 3, ELF_SUFFIX_GOT },
730 { "got12", 5, ELF_SUFFIX_GOT },
731 { "plt", 3, ELF_SUFFIX_PLT },
732 { "gotent", 6, ELF_SUFFIX_GOTENT },
733 { "gotoff", 6, ELF_SUFFIX_GOTOFF },
734 { "gotplt", 6, ELF_SUFFIX_GOTPLT },
735 { "pltoff", 6, ELF_SUFFIX_PLTOFF },
736 { "tlsgd", 5, ELF_SUFFIX_TLS_GD },
737 { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE },
738 { "indntpoff", 9, ELF_SUFFIX_TLS_IE },
739 { "tlsldm", 6, ELF_SUFFIX_TLS_LDM },
740 { "dtpoff", 6, ELF_SUFFIX_TLS_LDO },
741 { "ntpoff", 6, ELF_SUFFIX_TLS_LE },
742 { NULL, 0, ELF_SUFFIX_NONE }
745 struct map_bfd *ptr;
746 char *str = *str_p;
747 char *ident;
748 int len;
750 if (*str++ != '@')
751 return ELF_SUFFIX_NONE;
753 ident = str;
754 while (ISALNUM (*str))
755 str++;
756 len = str - ident;
758 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
759 if (len == ptr->length
760 && strncasecmp (ident, ptr->string, ptr->length) == 0)
762 if (exp_p->X_add_number != 0)
763 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
764 ptr->string, ptr->string);
765 /* Now check for identifier@suffix+constant. */
766 if (*str == '-' || *str == '+')
768 char *orig_line = input_line_pointer;
769 expressionS new_exp;
771 input_line_pointer = str;
772 expression (&new_exp);
774 switch (new_exp.X_op)
776 case O_constant: /* X_add_number (a constant expression). */
777 exp_p->X_add_number += new_exp.X_add_number;
778 str = input_line_pointer;
779 break;
780 case O_symbol: /* X_add_symbol + X_add_number. */
781 /* this case is used for e.g. xyz@PLT+.Label. */
782 exp_p->X_add_number += new_exp.X_add_number;
783 exp_p->X_op_symbol = new_exp.X_add_symbol;
784 exp_p->X_op = O_add;
785 str = input_line_pointer;
786 break;
787 case O_uminus: /* (- X_add_symbol) + X_add_number. */
788 /* this case is used for e.g. xyz@PLT-.Label. */
789 exp_p->X_add_number += new_exp.X_add_number;
790 exp_p->X_op_symbol = new_exp.X_add_symbol;
791 exp_p->X_op = O_subtract;
792 str = input_line_pointer;
793 break;
794 default:
795 break;
798 /* If s390_elf_suffix has not been called with
799 &input_line_pointer as first parameter, we have
800 clobbered the input_line_pointer. We have to
801 undo that. */
802 if (&input_line_pointer != str_p)
803 input_line_pointer = orig_line;
805 *str_p = str;
806 return ptr->suffix;
809 return BFD_RELOC_UNUSED;
812 /* Structure used to hold a literal pool entry. */
813 struct s390_lpe
815 struct s390_lpe *next;
816 expressionS ex;
817 FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */
818 LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */
819 int nbytes;
820 bfd_reloc_code_real_type reloc;
821 symbolS *sym;
824 static struct s390_lpe *lpe_free_list = NULL;
825 static struct s390_lpe *lpe_list = NULL;
826 static struct s390_lpe *lpe_list_tail = NULL;
827 static symbolS *lp_sym = NULL;
828 static int lp_count = 0;
829 static int lpe_count = 0;
831 static int
832 s390_exp_compare (exp1, exp2)
833 expressionS *exp1;
834 expressionS *exp2;
836 if (exp1->X_op != exp2->X_op)
837 return 0;
839 switch (exp1->X_op)
841 case O_constant: /* X_add_number must be equal. */
842 case O_register:
843 return exp1->X_add_number == exp2->X_add_number;
845 case O_big:
846 as_bad (_("Can't handle O_big in s390_exp_compare"));
848 case O_symbol: /* X_add_symbol & X_add_number must be equal. */
849 case O_symbol_rva:
850 case O_uminus:
851 case O_bit_not:
852 case O_logical_not:
853 return (exp1->X_add_symbol == exp2->X_add_symbol)
854 && (exp1->X_add_number == exp2->X_add_number);
856 case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
857 case O_divide:
858 case O_modulus:
859 case O_left_shift:
860 case O_right_shift:
861 case O_bit_inclusive_or:
862 case O_bit_or_not:
863 case O_bit_exclusive_or:
864 case O_bit_and:
865 case O_add:
866 case O_subtract:
867 case O_eq:
868 case O_ne:
869 case O_lt:
870 case O_le:
871 case O_ge:
872 case O_gt:
873 case O_logical_and:
874 case O_logical_or:
875 return (exp1->X_add_symbol == exp2->X_add_symbol)
876 && (exp1->X_op_symbol == exp2->X_op_symbol)
877 && (exp1->X_add_number == exp2->X_add_number);
878 default:
879 return 0;
883 /* Test for @lit and if its present make an entry in the literal pool and
884 modify the current expression to be an offset into the literal pool. */
885 static elf_suffix_type
886 s390_lit_suffix (str_p, exp_p, suffix)
887 char **str_p;
888 expressionS *exp_p;
889 elf_suffix_type suffix;
891 bfd_reloc_code_real_type reloc;
892 char tmp_name[64];
893 char *str = *str_p;
894 char *ident;
895 struct s390_lpe *lpe;
896 int nbytes, len;
898 if (*str++ != ':')
899 return suffix; /* No modification. */
901 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
902 ident = str;
903 while (ISALNUM (*str))
904 str++;
905 len = str - ident;
906 if (len != 4 || strncasecmp (ident, "lit", 3) != 0
907 || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
908 return suffix; /* no modification */
909 nbytes = ident[3] - '0';
911 reloc = BFD_RELOC_UNUSED;
912 if (suffix == ELF_SUFFIX_GOT)
914 if (nbytes == 2)
915 reloc = BFD_RELOC_390_GOT16;
916 else if (nbytes == 4)
917 reloc = BFD_RELOC_32_GOT_PCREL;
918 else if (nbytes == 8)
919 reloc = BFD_RELOC_390_GOT64;
921 else if (suffix == ELF_SUFFIX_PLT)
923 if (nbytes == 4)
924 reloc = BFD_RELOC_390_PLT32;
925 else if (nbytes == 8)
926 reloc = BFD_RELOC_390_PLT64;
929 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
930 as_bad (_("Invalid suffix for literal pool entry"));
932 /* Search the pool if the new entry is a duplicate. */
933 if (exp_p->X_op == O_big)
935 /* Special processing for big numbers. */
936 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
938 if (lpe->ex.X_op == O_big)
940 if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
942 if (memcmp (&generic_floating_point_number, &lpe->floatnum,
943 sizeof (FLONUM_TYPE)) == 0)
944 break;
946 else if (exp_p->X_add_number == lpe->ex.X_add_number)
948 if (memcmp (generic_bignum, lpe->bignum,
949 sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
950 break;
955 else
957 /* Processing for 'normal' data types. */
958 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
959 if (lpe->nbytes == nbytes && lpe->reloc == reloc
960 && s390_exp_compare (exp_p, &lpe->ex) != 0)
961 break;
964 if (lpe == NULL)
966 /* A new literal. */
967 if (lpe_free_list != NULL)
969 lpe = lpe_free_list;
970 lpe_free_list = lpe_free_list->next;
972 else
974 lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe));
977 lpe->ex = *exp_p;
979 if (exp_p->X_op == O_big)
981 if (exp_p->X_add_number <= 0)
982 lpe->floatnum = generic_floating_point_number;
983 else if (exp_p->X_add_number <= 4)
984 memcpy (lpe->bignum, generic_bignum,
985 exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
986 else
987 as_bad (_("Big number is too big"));
990 lpe->nbytes = nbytes;
991 lpe->reloc = reloc;
992 /* Literal pool name defined ? */
993 if (lp_sym == NULL)
995 sprintf (tmp_name, ".L\001%i", lp_count);
996 lp_sym = symbol_make (tmp_name);
999 /* Make name for literal pool entry. */
1000 sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
1001 lpe_count++;
1002 lpe->sym = symbol_make (tmp_name);
1004 /* Add to literal pool list. */
1005 lpe->next = NULL;
1006 if (lpe_list_tail != NULL)
1008 lpe_list_tail->next = lpe;
1009 lpe_list_tail = lpe;
1011 else
1012 lpe_list = lpe_list_tail = lpe;
1015 /* Now change exp_p to the offset into the literal pool.
1016 Thats the expression: .L^Ax^By-.L^Ax */
1017 exp_p->X_add_symbol = lpe->sym;
1018 exp_p->X_op_symbol = lp_sym;
1019 exp_p->X_op = O_subtract;
1020 exp_p->X_add_number = 0;
1022 *str_p = str;
1024 /* We change the suffix type to ELF_SUFFIX_NONE, because
1025 the difference of two local labels is just a number. */
1026 return ELF_SUFFIX_NONE;
1029 /* Like normal .long/.short/.word, except support @got, etc.
1030 clobbers input_line_pointer, checks end-of-line. */
1031 static void
1032 s390_elf_cons (nbytes)
1033 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1035 expressionS exp;
1036 elf_suffix_type suffix;
1038 if (is_it_end_of_statement ())
1040 demand_empty_rest_of_line ();
1041 return;
1046 expression (&exp);
1048 if (exp.X_op == O_symbol
1049 && *input_line_pointer == '@'
1050 && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
1052 bfd_reloc_code_real_type reloc;
1053 reloc_howto_type *reloc_howto;
1054 int size;
1055 char *where;
1057 if (nbytes == 2)
1059 static bfd_reloc_code_real_type tab2[] =
1061 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1062 BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */
1063 BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */
1064 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1065 BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1066 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */
1067 BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */
1068 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */
1069 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */
1070 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */
1071 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */
1072 BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */
1073 BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */
1075 reloc = tab2[suffix];
1077 else if (nbytes == 4)
1079 static bfd_reloc_code_real_type tab4[] =
1081 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1082 BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */
1083 BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */
1084 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1085 BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */
1086 BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */
1087 BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */
1088 BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */
1089 BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */
1090 BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */
1091 BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */
1092 BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */
1093 BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */
1095 reloc = tab4[suffix];
1097 else if (nbytes == 8)
1099 static bfd_reloc_code_real_type tab8[] =
1101 BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */
1102 BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */
1103 BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */
1104 BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */
1105 BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */
1106 BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */
1107 BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */
1108 BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */
1109 BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */
1110 BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */
1111 BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */
1112 BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */
1113 BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */
1115 reloc = tab8[suffix];
1117 else
1118 reloc = BFD_RELOC_UNUSED;
1120 if (reloc != BFD_RELOC_UNUSED
1121 && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc)))
1123 size = bfd_get_reloc_size (reloc_howto);
1124 if (size > nbytes)
1125 as_bad (_("%s relocations do not fit in %d bytes"),
1126 reloc_howto->name, nbytes);
1127 where = frag_more (nbytes);
1128 md_number_to_chars (where, 0, size);
1129 /* To make fixup_segment do the pc relative conversion the
1130 pcrel parameter on the fix_new_exp call needs to be FALSE. */
1131 fix_new_exp (frag_now, where - frag_now->fr_literal,
1132 size, &exp, FALSE, reloc);
1134 else
1135 as_bad (_("relocation not applicable"));
1137 else
1138 emit_expr (&exp, (unsigned int) nbytes);
1140 while (*input_line_pointer++ == ',');
1142 input_line_pointer--; /* Put terminator back into stream. */
1143 demand_empty_rest_of_line ();
1146 /* We need to keep a list of fixups. We can't simply generate them as
1147 we go, because that would require us to first create the frag, and
1148 that would screw up references to ``.''. */
1150 struct s390_fixup
1152 expressionS exp;
1153 int opindex;
1154 bfd_reloc_code_real_type reloc;
1157 #define MAX_INSN_FIXUPS (4)
1159 /* This routine is called for each instruction to be assembled. */
1161 static char *
1162 md_gather_operands (str, insn, opcode)
1163 char *str;
1164 unsigned char *insn;
1165 const struct s390_opcode *opcode;
1167 struct s390_fixup fixups[MAX_INSN_FIXUPS];
1168 const struct s390_operand *operand;
1169 const unsigned char *opindex_ptr;
1170 expressionS ex;
1171 elf_suffix_type suffix;
1172 bfd_reloc_code_real_type reloc;
1173 int skip_optional;
1174 int parentheses;
1175 char *f;
1176 int fc, i;
1178 while (ISSPACE (*str))
1179 str++;
1181 parentheses = 0;
1182 skip_optional = 0;
1184 /* Gather the operands. */
1185 fc = 0;
1186 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1188 char *hold;
1190 operand = s390_operands + *opindex_ptr;
1192 if (skip_optional && (operand->flags & S390_OPERAND_INDEX))
1194 /* We do an early skip. For D(X,B) constructions the index
1195 register is skipped (X is optional). For D(L,B) the base
1196 register will be the skipped operand, because L is NOT
1197 optional. */
1198 skip_optional = 0;
1199 continue;
1202 /* Gather the operand. */
1203 hold = input_line_pointer;
1204 input_line_pointer = str;
1206 /* Parse the operand. */
1207 if (! register_name (&ex))
1208 expression (&ex);
1210 str = input_line_pointer;
1211 input_line_pointer = hold;
1213 /* Write the operand to the insn. */
1214 if (ex.X_op == O_illegal)
1215 as_bad (_("illegal operand"));
1216 else if (ex.X_op == O_absent)
1217 as_bad (_("missing operand"));
1218 else if (ex.X_op == O_register || ex.X_op == O_constant)
1220 s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
1222 if (ex.X_op != O_register && ex.X_op != O_constant)
1224 /* We need to generate a fixup for the
1225 expression returned by s390_lit_suffix. */
1226 if (fc >= MAX_INSN_FIXUPS)
1227 as_fatal (_("too many fixups"));
1228 fixups[fc].exp = ex;
1229 fixups[fc].opindex = *opindex_ptr;
1230 fixups[fc].reloc = BFD_RELOC_UNUSED;
1231 ++fc;
1233 else
1235 if ((operand->flags & S390_OPERAND_INDEX)
1236 && ex.X_add_number == 0
1237 && warn_areg_zero)
1238 as_warn ("index register specified but zero");
1239 if ((operand->flags & S390_OPERAND_BASE)
1240 && ex.X_add_number == 0
1241 && warn_areg_zero)
1242 as_warn ("base register specified but zero");
1243 s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0);
1246 else
1248 suffix = s390_elf_suffix (&str, &ex);
1249 suffix = s390_lit_suffix (&str, &ex, suffix);
1250 reloc = BFD_RELOC_UNUSED;
1252 if (suffix == ELF_SUFFIX_GOT)
1254 if ((operand->flags & S390_OPERAND_DISP) &&
1255 (operand->bits == 12))
1256 reloc = BFD_RELOC_390_GOT12;
1257 else if ((operand->flags & S390_OPERAND_DISP) &&
1258 (operand->bits == 20))
1259 reloc = BFD_RELOC_390_GOT20;
1260 else if ((operand->flags & S390_OPERAND_SIGNED)
1261 && (operand->bits == 16))
1262 reloc = BFD_RELOC_390_GOT16;
1263 else if ((operand->flags & S390_OPERAND_PCREL)
1264 && (operand->bits == 32))
1265 reloc = BFD_RELOC_390_GOTENT;
1267 else if (suffix == ELF_SUFFIX_PLT)
1269 if ((operand->flags & S390_OPERAND_PCREL)
1270 && (operand->bits == 16))
1271 reloc = BFD_RELOC_390_PLT16DBL;
1272 else if ((operand->flags & S390_OPERAND_PCREL)
1273 && (operand->bits == 32))
1274 reloc = BFD_RELOC_390_PLT32DBL;
1276 else if (suffix == ELF_SUFFIX_GOTENT)
1278 if ((operand->flags & S390_OPERAND_PCREL)
1279 && (operand->bits == 32))
1280 reloc = BFD_RELOC_390_GOTENT;
1282 else if (suffix == ELF_SUFFIX_GOTOFF)
1284 if ((operand->flags & S390_OPERAND_SIGNED)
1285 && (operand->bits == 16))
1286 reloc = BFD_RELOC_16_GOTOFF;
1288 else if (suffix == ELF_SUFFIX_PLTOFF)
1290 if ((operand->flags & S390_OPERAND_SIGNED)
1291 && (operand->bits == 16))
1292 reloc = BFD_RELOC_390_PLTOFF16;
1294 else if (suffix == ELF_SUFFIX_GOTPLT)
1296 if ((operand->flags & S390_OPERAND_DISP)
1297 && (operand->bits == 12))
1298 reloc = BFD_RELOC_390_GOTPLT12;
1299 else if ((operand->flags & S390_OPERAND_SIGNED)
1300 && (operand->bits == 16))
1301 reloc = BFD_RELOC_390_GOTPLT16;
1302 else if ((operand->flags & S390_OPERAND_PCREL)
1303 && (operand->bits == 32))
1304 reloc = BFD_RELOC_390_GOTPLTENT;
1306 else if (suffix == ELF_SUFFIX_TLS_GOTIE)
1308 if ((operand->flags & S390_OPERAND_DISP)
1309 && (operand->bits == 12))
1310 reloc = BFD_RELOC_390_TLS_GOTIE12;
1311 else if ((operand->flags & S390_OPERAND_DISP)
1312 && (operand->bits == 20))
1313 reloc = BFD_RELOC_390_TLS_GOTIE20;
1315 else if (suffix == ELF_SUFFIX_TLS_IE)
1317 if ((operand->flags & S390_OPERAND_PCREL)
1318 && (operand->bits == 32))
1319 reloc = BFD_RELOC_390_TLS_IEENT;
1322 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1323 as_bad (_("invalid operand suffix"));
1324 /* We need to generate a fixup of type 'reloc' for this
1325 expression. */
1326 if (fc >= MAX_INSN_FIXUPS)
1327 as_fatal (_("too many fixups"));
1328 fixups[fc].exp = ex;
1329 fixups[fc].opindex = *opindex_ptr;
1330 fixups[fc].reloc = reloc;
1331 ++fc;
1334 /* Check the next character. The call to expression has advanced
1335 str past any whitespace. */
1336 if (operand->flags & S390_OPERAND_DISP)
1338 /* After a displacement a block in parentheses can start. */
1339 if (*str != '(')
1341 /* Check if parenthesized block can be skipped. If the next
1342 operand is neiter an optional operand nor a base register
1343 then we have a syntax error. */
1344 operand = s390_operands + *(++opindex_ptr);
1345 if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
1346 as_bad (_("syntax error; missing '(' after displacement"));
1348 /* Ok, skip all operands until S390_OPERAND_BASE. */
1349 while (!(operand->flags & S390_OPERAND_BASE))
1350 operand = s390_operands + *(++opindex_ptr);
1352 /* If there is a next operand it must be separated by a comma. */
1353 if (opindex_ptr[1] != '\0')
1355 if (*str++ != ',')
1356 as_bad (_("syntax error; expected ,"));
1359 else
1361 /* We found an opening parentheses. */
1362 str++;
1363 for (f = str; *f != '\0'; f++)
1364 if (*f == ',' || *f == ')')
1365 break;
1366 /* If there is no comma until the closing parentheses OR
1367 there is a comma right after the opening parentheses,
1368 we have to skip optional operands. */
1369 if (*f == ',' && f == str)
1371 /* comma directly after '(' ? */
1372 skip_optional = 1;
1373 str++;
1375 else
1376 skip_optional = (*f != ',');
1379 else if (operand->flags & S390_OPERAND_BASE)
1381 /* After the base register the parenthesed block ends. */
1382 if (*str++ != ')')
1383 as_bad (_("syntax error; missing ')' after base register"));
1384 skip_optional = 0;
1385 /* If there is a next operand it must be separated by a comma. */
1386 if (opindex_ptr[1] != '\0')
1388 if (*str++ != ',')
1389 as_bad (_("syntax error; expected ,"));
1392 else
1394 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1395 of D(L,B). In this case the base register has to be skipped. */
1396 if (*str == ')')
1398 operand = s390_operands + *(++opindex_ptr);
1400 if (!(operand->flags & S390_OPERAND_BASE))
1401 as_bad (_("syntax error; ')' not allowed here"));
1402 str++;
1404 /* If there is a next operand it must be separated by a comma. */
1405 if (opindex_ptr[1] != '\0')
1407 if (*str++ != ',')
1408 as_bad (_("syntax error; expected ,"));
1413 while (ISSPACE (*str))
1414 ++str;
1416 /* Check for tls instruction marker. */
1417 reloc = s390_tls_suffix (&str, &ex);
1418 if (reloc != BFD_RELOC_UNUSED)
1420 /* We need to generate a fixup of type 'reloc' for this
1421 instruction. */
1422 if (fc >= MAX_INSN_FIXUPS)
1423 as_fatal (_("too many fixups"));
1424 fixups[fc].exp = ex;
1425 fixups[fc].opindex = -1;
1426 fixups[fc].reloc = reloc;
1427 ++fc;
1430 if (*str != '\0')
1432 char *linefeed;
1434 if ((linefeed = strchr (str, '\n')) != NULL)
1435 *linefeed = '\0';
1436 as_bad (_("junk at end of line: `%s'"), str);
1437 if (linefeed != NULL)
1438 *linefeed = '\n';
1441 /* Write out the instruction. */
1442 f = frag_more (opcode->oplen);
1443 memcpy (f, insn, opcode->oplen);
1444 dwarf2_emit_insn (opcode->oplen);
1446 /* Create any fixups. At this point we do not use a
1447 bfd_reloc_code_real_type, but instead just use the
1448 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1449 handle fixups for any operand type, although that is admittedly
1450 not a very exciting feature. We pick a BFD reloc type in
1451 md_apply_fix3. */
1452 for (i = 0; i < fc; i++)
1455 if (fixups[i].opindex < 0)
1457 /* Create tls instruction marker relocation. */
1458 fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen,
1459 &fixups[i].exp, 0, fixups[i].reloc);
1460 continue;
1463 operand = s390_operands + fixups[i].opindex;
1465 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1467 reloc_howto_type *reloc_howto;
1468 fixS *fixP;
1469 int size;
1471 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1472 if (!reloc_howto)
1473 abort ();
1475 size = bfd_get_reloc_size (reloc_howto);
1477 if (size < 1 || size > 4)
1478 abort ();
1480 fixP = fix_new_exp (frag_now,
1481 f - frag_now->fr_literal + (operand->shift/8),
1482 size, &fixups[i].exp, reloc_howto->pc_relative,
1483 fixups[i].reloc);
1484 /* Turn off overflow checking in fixup_segment. This is necessary
1485 because fixup_segment will signal an overflow for large 4 byte
1486 quantities for GOT12 relocations. */
1487 if ( fixups[i].reloc == BFD_RELOC_390_GOT12
1488 || fixups[i].reloc == BFD_RELOC_390_GOT20
1489 || fixups[i].reloc == BFD_RELOC_390_GOT16)
1490 fixP->fx_no_overflow = 1;
1492 else
1493 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp,
1494 (operand->flags & S390_OPERAND_PCREL) != 0,
1495 ((bfd_reloc_code_real_type)
1496 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1498 return str;
1501 /* This routine is called for each instruction to be assembled. */
1503 void
1504 md_assemble (str)
1505 char *str;
1507 const struct s390_opcode *opcode;
1508 unsigned char insn[6];
1509 char *s;
1511 /* Get the opcode. */
1512 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1514 if (*s != '\0')
1515 *s++ = '\0';
1517 /* Look up the opcode in the hash table. */
1518 opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str);
1519 if (opcode == (const struct s390_opcode *) NULL)
1521 as_bad (_("Unrecognized opcode: `%s'"), str);
1522 return;
1524 else if (!(opcode->modes & current_mode_mask))
1526 as_bad ("Opcode %s not available in this mode", str);
1527 return;
1529 memcpy (insn, opcode->opcode, sizeof (insn));
1530 md_gather_operands (s, insn, opcode);
1533 #ifndef WORKING_DOT_WORD
1534 /* Handle long and short jumps. We don't support these */
1535 void
1536 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1537 char *ptr;
1538 addressT from_addr, to_addr;
1539 fragS *frag;
1540 symbolS *to_symbol;
1542 abort ();
1545 void
1546 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1547 char *ptr;
1548 addressT from_addr, to_addr;
1549 fragS *frag;
1550 symbolS *to_symbol;
1552 abort ();
1554 #endif
1556 void
1557 s390_bss (ignore)
1558 int ignore ATTRIBUTE_UNUSED;
1560 /* We don't support putting frags in the BSS segment, we fake it
1561 by marking in_bss, then looking at s_skip for clues. */
1563 subseg_set (bss_section, 0);
1564 demand_empty_rest_of_line ();
1567 /* Pseudo-op handling. */
1569 void
1570 s390_insn (ignore)
1571 int ignore ATTRIBUTE_UNUSED;
1573 expressionS exp;
1574 const struct s390_opcode *opformat;
1575 unsigned char insn[6];
1576 char *s;
1578 /* Get the opcode format. */
1579 s = input_line_pointer;
1580 while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
1581 s++;
1582 if (*s != ',')
1583 as_bad (_("Invalid .insn format\n"));
1584 *s++ = '\0';
1586 /* Look up the opcode in the hash table. */
1587 opformat = (struct s390_opcode *)
1588 hash_find (s390_opformat_hash, input_line_pointer);
1589 if (opformat == (const struct s390_opcode *) NULL)
1591 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
1592 return;
1594 input_line_pointer = s;
1595 expression (&exp);
1596 if (exp.X_op == O_constant)
1598 if ( ( opformat->oplen == 6
1599 && (addressT) exp.X_add_number >= 0
1600 && (addressT) exp.X_add_number < (1ULL << 48))
1601 || ( opformat->oplen == 4
1602 && (addressT) exp.X_add_number >= 0
1603 && (addressT) exp.X_add_number < (1ULL << 32))
1604 || ( opformat->oplen == 2
1605 && (addressT) exp.X_add_number >= 0
1606 && (addressT) exp.X_add_number < (1ULL << 16)))
1607 md_number_to_chars (insn, exp.X_add_number, opformat->oplen);
1608 else
1609 as_bad (_("Invalid .insn format\n"));
1611 else if (exp.X_op == O_big)
1613 if (exp.X_add_number > 0
1614 && opformat->oplen == 6
1615 && generic_bignum[3] == 0)
1617 md_number_to_chars (insn, generic_bignum[2], 2);
1618 md_number_to_chars (&insn[2], generic_bignum[1], 2);
1619 md_number_to_chars (&insn[4], generic_bignum[0], 2);
1621 else
1622 as_bad (_("Invalid .insn format\n"));
1624 else
1625 as_bad (_("second operand of .insn not a constant\n"));
1627 if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
1628 as_bad (_("missing comma after insn constant\n"));
1630 if ((s = strchr (input_line_pointer, '\n')) != NULL)
1631 *s = '\0';
1632 input_line_pointer = md_gather_operands (input_line_pointer, insn,
1633 opformat);
1634 if (s != NULL)
1635 *s = '\n';
1636 demand_empty_rest_of_line ();
1639 /* The .byte pseudo-op. This is similar to the normal .byte
1640 pseudo-op, but it can also take a single ASCII string. */
1642 static void
1643 s390_byte (ignore)
1644 int ignore ATTRIBUTE_UNUSED;
1646 if (*input_line_pointer != '\"')
1648 cons (1);
1649 return;
1652 /* Gather characters. A real double quote is doubled. Unusual
1653 characters are not permitted. */
1654 ++input_line_pointer;
1655 while (1)
1657 char c;
1659 c = *input_line_pointer++;
1661 if (c == '\"')
1663 if (*input_line_pointer != '\"')
1664 break;
1665 ++input_line_pointer;
1668 FRAG_APPEND_1_CHAR (c);
1671 demand_empty_rest_of_line ();
1674 /* The .ltorg pseudo-op.This emits all literals defined since the last
1675 .ltorg or the invocation of gas. Literals are defined with the
1676 @lit suffix. */
1678 static void
1679 s390_literals (ignore)
1680 int ignore ATTRIBUTE_UNUSED;
1682 struct s390_lpe *lpe;
1684 if (lp_sym == NULL || lpe_count == 0)
1685 return; /* Nothing to be done. */
1687 /* Emit symbol for start of literal pool. */
1688 S_SET_SEGMENT (lp_sym, now_seg);
1689 S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
1690 lp_sym->sy_frag = frag_now;
1692 while (lpe_list)
1694 lpe = lpe_list;
1695 lpe_list = lpe_list->next;
1696 S_SET_SEGMENT (lpe->sym, now_seg);
1697 S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
1698 lpe->sym->sy_frag = frag_now;
1700 /* Emit literal pool entry. */
1701 if (lpe->reloc != BFD_RELOC_UNUSED)
1703 reloc_howto_type *reloc_howto =
1704 bfd_reloc_type_lookup (stdoutput, lpe->reloc);
1705 int size = bfd_get_reloc_size (reloc_howto);
1706 char *where;
1708 if (size > lpe->nbytes)
1709 as_bad (_("%s relocations do not fit in %d bytes"),
1710 reloc_howto->name, lpe->nbytes);
1711 where = frag_more (lpe->nbytes);
1712 md_number_to_chars (where, 0, size);
1713 fix_new_exp (frag_now, where - frag_now->fr_literal,
1714 size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
1716 else
1718 if (lpe->ex.X_op == O_big)
1720 if (lpe->ex.X_add_number <= 0)
1721 generic_floating_point_number = lpe->floatnum;
1722 else
1723 memcpy (generic_bignum, lpe->bignum,
1724 lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
1726 emit_expr (&lpe->ex, lpe->nbytes);
1729 lpe->next = lpe_free_list;
1730 lpe_free_list = lpe;
1732 lpe_list_tail = NULL;
1733 lp_sym = NULL;
1734 lp_count++;
1735 lpe_count = 0;
1738 /* Turn a string in input_line_pointer into a floating point constant
1739 of type type, and store the appropriate bytes in *litp. The number
1740 of LITTLENUMS emitted is stored in *sizep . An error message is
1741 returned, or NULL on OK. */
1743 char *
1744 md_atof (type, litp, sizep)
1745 int type;
1746 char *litp;
1747 int *sizep;
1749 int prec;
1750 LITTLENUM_TYPE words[4];
1751 char *t;
1752 int i;
1754 switch (type)
1756 case 'f':
1757 prec = 2;
1758 break;
1760 case 'd':
1761 prec = 4;
1762 break;
1764 default:
1765 *sizep = 0;
1766 return "bad call to md_atof";
1769 t = atof_ieee (input_line_pointer, type, words);
1770 if (t)
1771 input_line_pointer = t;
1773 *sizep = prec * 2;
1775 for (i = 0; i < prec; i++)
1777 md_number_to_chars (litp, (valueT) words[i], 2);
1778 litp += 2;
1781 return NULL;
1784 /* Align a section (I don't know why this is machine dependent). */
1786 valueT
1787 md_section_align (seg, addr)
1788 asection *seg;
1789 valueT addr;
1791 int align = bfd_get_section_alignment (stdoutput, seg);
1793 return ((addr + (1 << align) - 1) & (-1 << align));
1796 /* We don't have any form of relaxing. */
1799 md_estimate_size_before_relax (fragp, seg)
1800 fragS *fragp ATTRIBUTE_UNUSED;
1801 asection *seg ATTRIBUTE_UNUSED;
1803 abort ();
1804 return 0;
1807 /* Convert a machine dependent frag. We never generate these. */
1809 void
1810 md_convert_frag (abfd, sec, fragp)
1811 bfd *abfd ATTRIBUTE_UNUSED;
1812 asection *sec ATTRIBUTE_UNUSED;
1813 fragS *fragp ATTRIBUTE_UNUSED;
1815 abort ();
1818 symbolS *
1819 md_undefined_symbol (name)
1820 char *name;
1822 if (*name == '_' && *(name + 1) == 'G'
1823 && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
1825 if (!GOT_symbol)
1827 if (symbol_find (name))
1828 as_bad (_("GOT already in symbol table"));
1829 GOT_symbol = symbol_new (name, undefined_section,
1830 (valueT) 0, &zero_address_frag);
1832 return GOT_symbol;
1834 return 0;
1837 /* Functions concerning relocs. */
1839 /* The location from which a PC relative jump should be calculated,
1840 given a PC relative reloc. */
1842 long
1843 md_pcrel_from_section (fixp, sec)
1844 fixS *fixp;
1845 segT sec ATTRIBUTE_UNUSED;
1847 return fixp->fx_frag->fr_address + fixp->fx_where;
1850 /* Here we decide which fixups can be adjusted to make them relative to
1851 the beginning of the section instead of the symbol. Basically we need
1852 to make sure that the dynamic relocations are done correctly, so in
1853 some cases we force the original symbol to be used. */
1855 tc_s390_fix_adjustable (fixP)
1856 fixS *fixP;
1858 /* Don't adjust references to merge sections. */
1859 if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0)
1860 return 0;
1861 /* adjust_reloc_syms doesn't know about the GOT. */
1862 if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF
1863 || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
1864 || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64
1865 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16
1866 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32
1867 || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64
1868 || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
1869 || fixP->fx_r_type == BFD_RELOC_390_PLT32
1870 || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
1871 || fixP->fx_r_type == BFD_RELOC_390_PLT64
1872 || fixP->fx_r_type == BFD_RELOC_390_GOT12
1873 || fixP->fx_r_type == BFD_RELOC_390_GOT20
1874 || fixP->fx_r_type == BFD_RELOC_390_GOT16
1875 || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
1876 || fixP->fx_r_type == BFD_RELOC_390_GOT64
1877 || fixP->fx_r_type == BFD_RELOC_390_GOTENT
1878 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
1879 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16
1880 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20
1881 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32
1882 || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64
1883 || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT
1884 || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD
1885 || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL
1886 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL
1887 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32
1888 || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64
1889 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12
1890 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20
1891 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32
1892 || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64
1893 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32
1894 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64
1895 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32
1896 || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64
1897 || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT
1898 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32
1899 || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64
1900 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32
1901 || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64
1902 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD
1903 || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF
1904 || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF
1905 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1906 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1907 return 0;
1908 return 1;
1911 /* Return true if we must always emit a reloc for a type and false if
1912 there is some hope of resolving it at assembly time. */
1914 tc_s390_force_relocation (fixp)
1915 struct fix *fixp;
1917 /* Ensure we emit a relocation for every reference to the global
1918 offset table or to the procedure link table. */
1919 switch (fixp->fx_r_type)
1921 case BFD_RELOC_390_GOT12:
1922 case BFD_RELOC_390_GOT20:
1923 case BFD_RELOC_32_GOT_PCREL:
1924 case BFD_RELOC_32_GOTOFF:
1925 case BFD_RELOC_390_GOTOFF64:
1926 case BFD_RELOC_390_PLTOFF16:
1927 case BFD_RELOC_390_PLTOFF32:
1928 case BFD_RELOC_390_PLTOFF64:
1929 case BFD_RELOC_390_GOTPC:
1930 case BFD_RELOC_390_GOT16:
1931 case BFD_RELOC_390_GOTPCDBL:
1932 case BFD_RELOC_390_GOT64:
1933 case BFD_RELOC_390_GOTENT:
1934 case BFD_RELOC_390_PLT32:
1935 case BFD_RELOC_390_PLT16DBL:
1936 case BFD_RELOC_390_PLT32DBL:
1937 case BFD_RELOC_390_PLT64:
1938 case BFD_RELOC_390_GOTPLT12:
1939 case BFD_RELOC_390_GOTPLT16:
1940 case BFD_RELOC_390_GOTPLT20:
1941 case BFD_RELOC_390_GOTPLT32:
1942 case BFD_RELOC_390_GOTPLT64:
1943 case BFD_RELOC_390_GOTPLTENT:
1944 return 1;
1945 default:
1946 break;;
1949 return generic_force_reloc (fixp);
1952 /* Apply a fixup to the object code. This is called for all the
1953 fixups we generated by the call to fix_new_exp, above. In the call
1954 above we used a reloc code which was the largest legal reloc code
1955 plus the operand index. Here we undo that to recover the operand
1956 index. At this point all symbol values should be fully resolved,
1957 and we attempt to completely resolve the reloc. If we can not do
1958 that, we determine the correct reloc code and put it back in the
1959 fixup. */
1961 void
1962 md_apply_fix3 (fixP, valP, seg)
1963 fixS *fixP;
1964 valueT *valP;
1965 segT seg ATTRIBUTE_UNUSED;
1967 char *where;
1968 valueT value = *valP;
1970 where = fixP->fx_frag->fr_literal + fixP->fx_where;
1972 if (fixP->fx_subsy != NULL)
1973 as_bad_where (fixP->fx_file, fixP->fx_line,
1974 "cannot emit relocation %s against subsy symbol %s",
1975 bfd_get_reloc_code_name (fixP->fx_r_type),
1976 S_GET_NAME (fixP->fx_subsy));
1978 if (fixP->fx_addsy != NULL)
1980 if (fixP->fx_pcrel)
1981 value += fixP->fx_frag->fr_address + fixP->fx_where;
1983 else
1984 fixP->fx_done = 1;
1986 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
1988 const struct s390_operand *operand;
1989 int opindex;
1991 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
1992 operand = &s390_operands[opindex];
1994 if (fixP->fx_done)
1996 /* Insert the fully resolved operand value. */
1997 s390_insert_operand (where, operand, (offsetT) value,
1998 fixP->fx_file, fixP->fx_line);
1999 return;
2002 /* Determine a BFD reloc value based on the operand information.
2003 We are only prepared to turn a few of the operands into
2004 relocs. */
2005 fixP->fx_offset = value;
2006 if (operand->bits == 12 && operand->shift == 20)
2008 fixP->fx_size = 2;
2009 fixP->fx_where += 2;
2010 fixP->fx_r_type = BFD_RELOC_390_12;
2012 else if (operand->bits == 12 && operand->shift == 36)
2014 fixP->fx_size = 2;
2015 fixP->fx_where += 4;
2016 fixP->fx_r_type = BFD_RELOC_390_12;
2018 else if (operand->bits == 20 && operand->shift == 20)
2020 fixP->fx_size = 2;
2021 fixP->fx_where += 2;
2022 fixP->fx_r_type = BFD_RELOC_390_20;
2024 else if (operand->bits == 8 && operand->shift == 8)
2026 fixP->fx_size = 1;
2027 fixP->fx_where += 1;
2028 fixP->fx_r_type = BFD_RELOC_8;
2030 else if (operand->bits == 16 && operand->shift == 16)
2032 fixP->fx_size = 2;
2033 fixP->fx_where += 2;
2034 if (operand->flags & S390_OPERAND_PCREL)
2036 fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2037 fixP->fx_offset += 2;
2039 else
2040 fixP->fx_r_type = BFD_RELOC_16;
2042 else if (operand->bits == 32 && operand->shift == 16
2043 && (operand->flags & S390_OPERAND_PCREL))
2045 fixP->fx_size = 4;
2046 fixP->fx_where += 2;
2047 fixP->fx_offset += 2;
2048 fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
2050 else
2052 char *sfile;
2053 unsigned int sline;
2055 /* Use expr_symbol_where to see if this is an expression
2056 symbol. */
2057 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
2058 as_bad_where (fixP->fx_file, fixP->fx_line,
2059 _("unresolved expression that must be resolved"));
2060 else
2061 as_bad_where (fixP->fx_file, fixP->fx_line,
2062 _("unsupported relocation type"));
2063 fixP->fx_done = 1;
2064 return;
2067 else
2069 switch (fixP->fx_r_type)
2071 case BFD_RELOC_8:
2072 if (fixP->fx_pcrel)
2073 abort ();
2074 if (fixP->fx_done)
2075 md_number_to_chars (where, value, 1);
2076 break;
2077 case BFD_RELOC_390_12:
2078 case BFD_RELOC_390_GOT12:
2079 case BFD_RELOC_390_GOTPLT12:
2080 if (fixP->fx_done)
2082 unsigned short mop;
2084 mop = bfd_getb16 ((unsigned char *) where);
2085 mop |= (unsigned short) (value & 0xfff);
2086 bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
2088 break;
2090 case BFD_RELOC_390_20:
2091 case BFD_RELOC_390_GOT20:
2092 case BFD_RELOC_390_GOTPLT20:
2093 if (fixP->fx_done)
2095 unsigned int mop;
2096 mop = bfd_getb32 ((unsigned char *) where);
2097 mop |= (unsigned int) ((value & 0xfff) << 8 |
2098 (value & 0xff000) >> 12);
2099 bfd_putb32 ((bfd_vma) mop, (unsigned char *) where);
2101 break;
2103 case BFD_RELOC_16:
2104 case BFD_RELOC_GPREL16:
2105 case BFD_RELOC_16_GOT_PCREL:
2106 case BFD_RELOC_16_GOTOFF:
2107 if (fixP->fx_pcrel)
2108 as_bad_where (fixP->fx_file, fixP->fx_line,
2109 "cannot emit PC relative %s relocation%s%s",
2110 bfd_get_reloc_code_name (fixP->fx_r_type),
2111 fixP->fx_addsy != NULL ? " against " : "",
2112 (fixP->fx_addsy != NULL
2113 ? S_GET_NAME (fixP->fx_addsy)
2114 : ""));
2115 if (fixP->fx_done)
2116 md_number_to_chars (where, value, 2);
2117 break;
2118 case BFD_RELOC_390_GOT16:
2119 case BFD_RELOC_390_PLTOFF16:
2120 case BFD_RELOC_390_GOTPLT16:
2121 if (fixP->fx_done)
2122 md_number_to_chars (where, value, 2);
2123 break;
2124 case BFD_RELOC_390_PC16DBL:
2125 case BFD_RELOC_390_PLT16DBL:
2126 value += 2;
2127 if (fixP->fx_done)
2128 md_number_to_chars (where, (offsetT) value >> 1, 2);
2129 break;
2131 case BFD_RELOC_32:
2132 if (fixP->fx_pcrel)
2133 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2134 else
2135 fixP->fx_r_type = BFD_RELOC_32;
2136 if (fixP->fx_done)
2137 md_number_to_chars (where, value, 4);
2138 break;
2139 case BFD_RELOC_32_PCREL:
2140 case BFD_RELOC_32_BASEREL:
2141 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2142 if (fixP->fx_done)
2143 md_number_to_chars (where, value, 4);
2144 break;
2145 case BFD_RELOC_32_GOT_PCREL:
2146 case BFD_RELOC_390_PLTOFF32:
2147 case BFD_RELOC_390_PLT32:
2148 case BFD_RELOC_390_GOTPLT32:
2149 if (fixP->fx_done)
2150 md_number_to_chars (where, value, 4);
2151 break;
2152 case BFD_RELOC_390_PC32DBL:
2153 case BFD_RELOC_390_PLT32DBL:
2154 case BFD_RELOC_390_GOTPCDBL:
2155 case BFD_RELOC_390_GOTENT:
2156 case BFD_RELOC_390_GOTPLTENT:
2157 value += 2;
2158 if (fixP->fx_done)
2159 md_number_to_chars (where, (offsetT) value >> 1, 4);
2160 break;
2162 case BFD_RELOC_32_GOTOFF:
2163 if (fixP->fx_done)
2164 md_number_to_chars (where, value, sizeof (int));
2165 break;
2167 case BFD_RELOC_390_GOTOFF64:
2168 if (fixP->fx_done)
2169 md_number_to_chars (where, value, 8);
2170 break;
2172 case BFD_RELOC_390_GOT64:
2173 case BFD_RELOC_390_PLTOFF64:
2174 case BFD_RELOC_390_PLT64:
2175 case BFD_RELOC_390_GOTPLT64:
2176 if (fixP->fx_done)
2177 md_number_to_chars (where, value, 8);
2178 break;
2180 case BFD_RELOC_64:
2181 if (fixP->fx_pcrel)
2182 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2183 else
2184 fixP->fx_r_type = BFD_RELOC_64;
2185 if (fixP->fx_done)
2186 md_number_to_chars (where, value, 8);
2187 break;
2189 case BFD_RELOC_64_PCREL:
2190 fixP->fx_r_type = BFD_RELOC_64_PCREL;
2191 if (fixP->fx_done)
2192 md_number_to_chars (where, value, 8);
2193 break;
2195 case BFD_RELOC_VTABLE_INHERIT:
2196 case BFD_RELOC_VTABLE_ENTRY:
2197 fixP->fx_done = 0;
2198 return;
2200 case BFD_RELOC_390_TLS_LOAD:
2201 case BFD_RELOC_390_TLS_GDCALL:
2202 case BFD_RELOC_390_TLS_LDCALL:
2203 case BFD_RELOC_390_TLS_GD32:
2204 case BFD_RELOC_390_TLS_GD64:
2205 case BFD_RELOC_390_TLS_GOTIE12:
2206 case BFD_RELOC_390_TLS_GOTIE20:
2207 case BFD_RELOC_390_TLS_GOTIE32:
2208 case BFD_RELOC_390_TLS_GOTIE64:
2209 case BFD_RELOC_390_TLS_LDM32:
2210 case BFD_RELOC_390_TLS_LDM64:
2211 case BFD_RELOC_390_TLS_IE32:
2212 case BFD_RELOC_390_TLS_IE64:
2213 case BFD_RELOC_390_TLS_LE32:
2214 case BFD_RELOC_390_TLS_LE64:
2215 case BFD_RELOC_390_TLS_LDO32:
2216 case BFD_RELOC_390_TLS_LDO64:
2217 case BFD_RELOC_390_TLS_DTPMOD:
2218 case BFD_RELOC_390_TLS_DTPOFF:
2219 case BFD_RELOC_390_TLS_TPOFF:
2220 /* Fully resolved at link time. */
2221 break;
2222 case BFD_RELOC_390_TLS_IEENT:
2223 /* Fully resolved at link time. */
2224 value += 2;
2225 break;
2227 default:
2229 const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
2231 if (reloc_name != NULL)
2232 fprintf (stderr, "Gas failure, reloc type %s\n", reloc_name);
2233 else
2234 fprintf (stderr, "Gas failure, reloc type #%i\n", fixP->fx_r_type);
2235 fflush (stderr);
2236 abort ();
2240 fixP->fx_offset = value;
2244 /* Generate a reloc for a fixup. */
2246 arelent *
2247 tc_gen_reloc (seg, fixp)
2248 asection *seg ATTRIBUTE_UNUSED;
2249 fixS *fixp;
2251 bfd_reloc_code_real_type code;
2252 arelent *reloc;
2254 code = fixp->fx_r_type;
2255 if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
2257 if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
2258 || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
2259 code = BFD_RELOC_390_GOTPC;
2260 if (code == BFD_RELOC_390_PC32DBL)
2261 code = BFD_RELOC_390_GOTPCDBL;
2264 reloc = (arelent *) xmalloc (sizeof (arelent));
2265 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2266 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2267 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2268 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2269 if (reloc->howto == NULL)
2271 as_bad_where (fixp->fx_file, fixp->fx_line,
2272 _("cannot represent relocation type %s"),
2273 bfd_get_reloc_code_name (code));
2274 /* Set howto to a garbage value so that we can keep going. */
2275 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2276 assert (reloc->howto != NULL);
2278 reloc->addend = fixp->fx_offset;
2280 return reloc;
2283 void
2284 s390_cfi_frame_initial_instructions ()
2286 cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96);
2290 tc_s390_regname_to_dw2regnum (const char *regname)
2292 int regnum = -1;
2294 if (regname[0] != 'c' && regname[0] != 'a')
2296 regnum = reg_name_search (pre_defined_registers, REG_NAME_CNT, regname);
2297 if (regname[0] == 'f' && regnum != -1)
2298 regnum += 16;
2300 else if (strcmp (regname, "ap") == 0)
2301 regnum = 32;
2302 else if (strcmp (regname, "cc") == 0)
2303 regnum = 33;
2304 return regnum;