Fix handling of BLX instruction to conform to Operations definition in the
[deliverable/binutils-gdb.git] / gas / config / tc-s390.c
CommitLineData
a85d7ed0 1/* tc-s390.c -- Assemble for the S390
302576af 2 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
a85d7ed0
NC
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4
5 This file is part of GAS, the GNU Assembler.
6
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.
11
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.
16
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
98d3f06f 20 02111-1307, USA. */
a85d7ed0
NC
21
22#include <stdio.h>
a85d7ed0 23#include "as.h"
3882b010 24#include "safe-ctype.h"
a85d7ed0
NC
25#include "subsegs.h"
26#include "struc-symbol.h"
27
28#include "opcode/s390.h"
29#include "elf/s390.h"
30
16a419ba 31/* The default architecture. */
a85d7ed0
NC
32#ifndef DEFAULT_ARCH
33#define DEFAULT_ARCH "s390"
34#endif
35static char *default_arch = DEFAULT_ARCH;
36/* Either 32 or 64, selects file format. */
37static int s390_arch_size;
16a419ba 38/* Current architecture. Start with the smallest instruction set. */
a85d7ed0
NC
39static enum s390_opcode_arch_val current_architecture = S390_OPCODE_ESA;
40static int current_arch_mask = 1 << S390_OPCODE_ESA;
41static int current_arch_requested = 0;
42
16a419ba 43/* Whether to use user friendly register names. Default is true. */
a85d7ed0
NC
44#ifndef TARGET_REG_NAMES_P
45#define TARGET_REG_NAMES_P true
46#endif
47
48static boolean reg_names_p = TARGET_REG_NAMES_P;
49
16a419ba
NC
50/* Set to TRUE if we want to warn about zero base/index registers. */
51static boolean warn_areg_zero = FALSE;
52
a85d7ed0
NC
53/* Generic assembler global variables which must be defined by all
54 targets. */
55
56const char comment_chars[] = "#";
57
58/* Characters which start a comment at the beginning of a line. */
59const char line_comment_chars[] = "#";
60
61/* Characters which may be used to separate multiple commands on a
62 single line. */
63const char line_separator_chars[] = ";";
64
65/* Characters which are used to indicate an exponent in a floating
66 point number. */
67const char EXP_CHARS[] = "eE";
68
69/* Characters which mean that a number is a floating point constant,
70 as in 0d1.0. */
71const char FLT_CHARS[] = "dD";
72
73/* The target specific pseudo-ops which we support. */
74
75/* Define the prototypes for the pseudo-ops */
76static void s390_byte PARAMS ((int));
77static void s390_elf_cons PARAMS ((int));
78static void s390_bss PARAMS ((int));
79static void s390_insn PARAMS ((int));
80static void s390_literals PARAMS ((int));
81
82const pseudo_typeS md_pseudo_table[] =
83{
84 { "align", s_align_bytes, 0 },
98d3f06f 85 /* Pseudo-ops which must be defined. */
198ce79b 86 { "bss", s390_bss, 0 },
a85d7ed0
NC
87 { "insn", s390_insn, 0 },
88 /* Pseudo-ops which must be overridden. */
89 { "byte", s390_byte, 0 },
90 { "short", s390_elf_cons, 2 },
91 { "long", s390_elf_cons, 4 },
92 { "quad", s390_elf_cons, 8 },
93 { "ltorg", s390_literals, 0 },
94 { "string", stringer, 2 },
95 { NULL, NULL, 0 }
96};
97
98
99/* Structure to hold information about predefined registers. */
100struct pd_reg
101 {
102 char *name;
103 int value;
104 };
105
106/* List of registers that are pre-defined:
107
108 Each access register has a predefined name of the form:
109 a<reg_num> which has the value <reg_num>.
110
111 Each control register has a predefined name of the form:
112 c<reg_num> which has the value <reg_num>.
113
114 Each general register has a predefined name of the form:
115 r<reg_num> which has the value <reg_num>.
116
117 Each floating point register a has predefined name of the form:
118 f<reg_num> which has the value <reg_num>.
119
120 There are individual registers as well:
121 sp has the value 15
122 lit has the value 12
123
98d3f06f 124 The table is sorted. Suitable for searching by a binary search. */
a85d7ed0
NC
125
126static const struct pd_reg pre_defined_registers[] =
127{
128 { "a0", 0 }, /* Access registers */
129 { "a1", 1 },
130 { "a10", 10 },
131 { "a11", 11 },
132 { "a12", 12 },
133 { "a13", 13 },
134 { "a14", 14 },
135 { "a15", 15 },
136 { "a2", 2 },
137 { "a3", 3 },
138 { "a4", 4 },
139 { "a5", 5 },
140 { "a6", 6 },
141 { "a7", 7 },
142 { "a8", 8 },
143 { "a9", 9 },
144
145 { "c0", 0 }, /* Control registers */
146 { "c1", 1 },
147 { "c10", 10 },
148 { "c11", 11 },
149 { "c12", 12 },
150 { "c13", 13 },
151 { "c14", 14 },
152 { "c15", 15 },
153 { "c2", 2 },
154 { "c3", 3 },
155 { "c4", 4 },
156 { "c5", 5 },
157 { "c6", 6 },
158 { "c7", 7 },
159 { "c8", 8 },
160 { "c9", 9 },
161
162 { "f0", 0 }, /* Floating point registers */
198ce79b
AJ
163 { "f1", 1 },
164 { "f10", 10 },
165 { "f11", 11 },
166 { "f12", 12 },
167 { "f13", 13 },
168 { "f14", 14 },
169 { "f15", 15 },
170 { "f2", 2 },
171 { "f3", 3 },
172 { "f4", 4 },
173 { "f5", 5 },
174 { "f6", 6 },
175 { "f7", 7 },
176 { "f8", 8 },
177 { "f9", 9 },
a85d7ed0
NC
178
179 { "lit", 13 }, /* Pointer to literal pool */
180
181 { "r0", 0 }, /* General purpose registers */
182 { "r1", 1 },
183 { "r10", 10 },
184 { "r11", 11 },
185 { "r12", 12 },
186 { "r13", 13 },
187 { "r14", 14 },
188 { "r15", 15 },
189 { "r2", 2 },
190 { "r3", 3 },
191 { "r4", 4 },
192 { "r5", 5 },
193 { "r6", 6 },
194 { "r7", 7 },
195 { "r8", 8 },
196 { "r9", 9 },
197
198 { "sp", 15 }, /* Stack pointer */
199
200};
201
07726851 202#define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
a85d7ed0 203
9d654c1c
AJ
204static int reg_name_search
205 PARAMS ((const struct pd_reg *, int, const char *));
206static boolean register_name PARAMS ((expressionS *));
207static void init_default_arch PARAMS ((void));
208static void s390_insert_operand
209 PARAMS ((unsigned char *, const struct s390_operand *, offsetT, char *,
210 unsigned int));
211static char *md_gather_operands
212 PARAMS ((char *, unsigned char *, const struct s390_opcode *));
213
a85d7ed0
NC
214/* Given NAME, find the register number associated with that name, return
215 the integer value associated with the given name or -1 on failure. */
216
217static int
218reg_name_search (regs, regcount, name)
219 const struct pd_reg *regs;
220 int regcount;
221 const char *name;
222{
223 int middle, low, high;
224 int cmp;
225
226 low = 0;
227 high = regcount - 1;
228
229 do
230 {
231 middle = (low + high) / 2;
232 cmp = strcasecmp (name, regs[middle].name);
233 if (cmp < 0)
234 high = middle - 1;
235 else if (cmp > 0)
236 low = middle + 1;
237 else
238 return regs[middle].value;
239 }
240 while (low <= high);
241
242 return -1;
243}
244
245
246/*
247 * Summary of register_name().
248 *
249 * in: Input_line_pointer points to 1st char of operand.
250 *
251 * out: A expressionS.
252 * The operand may have been a register: in this case, X_op == O_register,
253 * X_add_number is set to the register number, and truth is returned.
254 * Input_line_pointer->(next non-blank) char after operand, or is in its
255 * original state.
256 */
257
258static boolean
259register_name (expressionP)
260 expressionS *expressionP;
261{
262 int reg_number;
263 char *name;
264 char *start;
265 char c;
266
468cced8 267 /* Find the spelling of the operand. */
a85d7ed0 268 start = name = input_line_pointer;
3882b010 269 if (name[0] == '%' && ISALPHA (name[1]))
a85d7ed0
NC
270 name = ++input_line_pointer;
271 else
272 return false;
273
274 c = get_symbol_end ();
275 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
276
468cced8
AM
277 /* Put back the delimiting char. */
278 *input_line_pointer = c;
279
280 /* Look to see if it's in the register table. */
198ce79b 281 if (reg_number >= 0)
a85d7ed0
NC
282 {
283 expressionP->X_op = O_register;
284 expressionP->X_add_number = reg_number;
198ce79b 285
468cced8 286 /* Make the rest nice. */
a85d7ed0
NC
287 expressionP->X_add_symbol = NULL;
288 expressionP->X_op_symbol = NULL;
a85d7ed0
NC
289 return true;
290 }
468cced8
AM
291
292 /* Reset the line as if we had not done anything. */
293 input_line_pointer = start;
294 return false;
a85d7ed0
NC
295}
296
297/* Local variables. */
298
299/* Opformat hash table. */
300static struct hash_control *s390_opformat_hash;
301
302/* Opcode hash table. */
303static struct hash_control *s390_opcode_hash;
304
305/* Flags to set in the elf header */
306static flagword s390_flags = 0;
307
308symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
309
310#ifndef WORKING_DOT_WORD
311const int md_short_jump_size = 4;
312const int md_long_jump_size = 4;
313#endif
314
315CONST char *md_shortopts = "A:m:kVQ:";
316struct option md_longopts[] = {
317 {NULL, no_argument, NULL, 0}
318};
07726851 319size_t md_longopts_size = sizeof (md_longopts);
a85d7ed0
NC
320
321/* Initialize the default opcode arch and word size from the default
322 architecture name. */
323static void
324init_default_arch ()
325{
326 if (current_arch_requested)
327 return;
07855bec 328
07726851 329 if (strcmp (default_arch, "s390") == 0)
07855bec
NC
330 {
331 s390_arch_size = 32;
332 current_architecture = S390_OPCODE_ESA;
333 }
07726851 334 else if (strcmp (default_arch, "s390x") == 0)
07855bec
NC
335 {
336 s390_arch_size = 64;
337 current_architecture = S390_OPCODE_ESAME;
338 }
339 else
a85d7ed0
NC
340 as_fatal ("Invalid default architecture, broken assembler.");
341 current_arch_mask = 1 << current_architecture;
342}
343
344/* Called by TARGET_FORMAT. */
345const char *
346s390_target_format ()
347{
348 /* We don't get a chance to initialize anything before we're called,
349 so handle that now. */
350 if (! s390_arch_size)
351 init_default_arch ();
352
353 return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
354}
355
356int
357md_parse_option (c, arg)
358 int c;
359 char *arg;
360{
07855bec
NC
361 switch (c)
362 {
363 /* -k: Ignore for FreeBSD compatibility. */
364 case 'k':
365 break;
366 case 'm':
367 if (arg != NULL && strcmp (arg, "regnames") == 0)
368 reg_names_p = true;
198ce79b 369
07855bec
NC
370 else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
371 reg_names_p = false;
198ce79b 372
16a419ba
NC
373 else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
374 warn_areg_zero = TRUE;
375
ff0fb565
MS
376 else if (arg != NULL && strcmp (arg, "31") == 0)
377 s390_arch_size = 31;
378
379 else if (arg != NULL && strcmp (arg, "64") == 0)
380 s390_arch_size = 64;
381
07855bec
NC
382 else
383 {
384 as_bad (_("invalid switch -m%s"), arg);
385 return 0;
386 }
387 break;
198ce79b 388
07855bec
NC
389 case 'A':
390 if (arg != NULL && strcmp (arg, "esa") == 0)
819e6420 391 current_architecture = S390_OPCODE_ESA;
07855bec 392 else if (arg != NULL && strcmp (arg, "esame") == 0)
819e6420 393 current_architecture = S390_OPCODE_ESAME;
07855bec
NC
394 else
395 as_bad ("invalid architecture -A%s", arg);
396 current_arch_mask = 1 << current_architecture;
397 current_arch_requested = 1;
398 break;
399
400 /* -V: SVR4 argument to print version ID. */
401 case 'V':
402 print_version_id ();
403 break;
198ce79b 404
07855bec
NC
405 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
406 should be emitted or not. FIXME: Not implemented. */
407 case 'Q':
408 break;
198ce79b 409
07855bec
NC
410 default:
411 return 0;
412 }
198ce79b 413
a85d7ed0
NC
414 return 1;
415}
416
417void
418md_show_usage (stream)
419 FILE *stream;
420{
07855bec 421 fprintf (stream, _("\
16a419ba
NC
422 S390 options:\n\
423 -mregnames Allow symbolic names for registers\n\
424 -mwarn-areg-zero Warn about zero base/index registers\n\
ff0fb565
MS
425 -mno-regnames Do not allow symbolic names for registers\n\
426 -m31 Set file format to 31 bit format\n\
427 -m64 Set file format to 64 bit format\n"));
07855bec 428 fprintf (stream, _("\
16a419ba
NC
429 -V print assembler version number\n\
430 -Qy, -Qn ignored\n"));
a85d7ed0
NC
431}
432
433/* This function is called when the assembler starts up. It is called
434 after the options have been parsed and the output file has been
16a419ba 435 opened. */
a85d7ed0
NC
436
437void
438md_begin ()
439{
440 register const struct s390_opcode *op;
441 const struct s390_opcode *op_end;
442 boolean dup_insn = false;
443 const char *retval;
444
ff0fb565
MS
445 /* Give a warning if the combination -m64-bit and -Aesa is used. */
446 if (s390_arch_size == 64 && current_arch_mask == (1 << S390_OPCODE_ESA))
447 as_warn ("The 64 bit file format is used without esame instructions.");
448
16a419ba 449 /* Set the ELF flags if desired. */
a85d7ed0
NC
450 if (s390_flags)
451 bfd_set_private_flags (stdoutput, s390_flags);
452
453 /* Insert the opcode formats into a hash table. */
454 s390_opformat_hash = hash_new ();
455
456 op_end = s390_opformats + s390_num_opformats;
07855bec
NC
457 for (op = s390_opformats; op < op_end; op++)
458 {
459 retval = hash_insert (s390_opformat_hash, op->name, (PTR) op);
460 if (retval != (const char *) NULL)
461 {
462 as_bad (_("Internal assembler error for instruction format %s"),
463 op->name);
464 dup_insn = true;
465 }
466 }
a85d7ed0
NC
467
468 /* Insert the opcodes into a hash table. */
469 s390_opcode_hash = hash_new ();
470
471 op_end = s390_opcodes + s390_num_opcodes;
07855bec
NC
472 for (op = s390_opcodes; op < op_end; op++)
473 {
474 retval = hash_insert (s390_opcode_hash, op->name, (PTR) op);
475 if (retval != (const char *) NULL)
476 {
477 as_bad (_("Internal assembler error for instruction %s"), op->name);
478 dup_insn = true;
479 }
480 }
481
a85d7ed0
NC
482 if (dup_insn)
483 abort ();
484
485 record_alignment (text_section, 2);
486 record_alignment (data_section, 2);
487 record_alignment (bss_section, 2);
488
489}
490
491/* Called after all assembly has been done. */
492void
493s390_md_end ()
494{
07855bec 495 if (s390_arch_size == 64)
ff0fb565 496 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
07855bec 497 else
ff0fb565 498 bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
a85d7ed0
NC
499}
500
501void
502s390_align_code (fragP, count)
503 fragS *fragP;
504 int count;
505{
506 /* We use nop pattern 0x0707. */
07855bec
NC
507 if (count > 0)
508 {
07726851 509 memset (fragP->fr_literal + fragP->fr_fix, 0x07, count);
07855bec
NC
510 fragP->fr_var = count;
511 }
a85d7ed0
NC
512}
513
514/* Insert an operand value into an instruction. */
515
516static void
517s390_insert_operand (insn, operand, val, file, line)
518 unsigned char *insn;
519 const struct s390_operand *operand;
520 offsetT val;
521 char *file;
522 unsigned int line;
523{
524 addressT uval;
525 int offset;
526
07855bec
NC
527 if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
528 {
529 offsetT min, max;
530
531 max = ((offsetT) 1 << (operand->bits - 1)) - 1;
532 min = - ((offsetT) 1 << (operand->bits - 1));
533 /* Halve PCREL operands. */
534 if (operand->flags & S390_OPERAND_PCREL)
535 val >>= 1;
536 /* Check for underflow / overflow. */
537 if (val < min || val > max)
538 {
539 const char *err =
540 "operand out of range (%s not between %ld and %ld)";
541 char buf[100];
542
543 if (operand->flags & S390_OPERAND_PCREL)
544 {
545 val <<= 1;
546 min <<= 1;
547 max <<= 1;
548 }
549 sprint_value (buf, val);
550 if (file == (char *) NULL)
551 as_bad (err, buf, (int) min, (int) max);
552 else
553 as_bad_where (file, line, err, buf, (int) min, (int) max);
554 return;
555 }
556 /* val is ok, now restrict it to operand->bits bits. */
557 uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
a85d7ed0 558 }
07855bec
NC
559 else
560 {
561 addressT min, max;
198ce79b 562
98d3f06f 563 max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
07855bec
NC
564 min = (offsetT) 0;
565 uval = (addressT) val;
566 /* Length x in an instructions has real length x+1. */
567 if (operand->flags & S390_OPERAND_LENGTH)
568 uval--;
569 /* Check for underflow / overflow. */
570 if (uval < min || uval > max)
571 {
572 const char *err =
573 "operand out of range (%s not between %ld and %ld)";
574 char buf[100];
198ce79b 575
07855bec
NC
576 if (operand->flags & S390_OPERAND_LENGTH)
577 {
578 uval++;
579 min++;
580 max++;
581 }
582 sprint_value (buf, uval);
583 if (file == (char *) NULL)
584 as_bad (err, buf, (int) min, (int) max);
585 else
586 as_bad_where (file, line, err, buf, (int) min, (int) max);
587 return;
588 }
a85d7ed0 589 }
a85d7ed0
NC
590
591 /* Insert fragments of the operand byte for byte. */
592 offset = operand->shift + operand->bits;
593 uval <<= (-offset) & 7;
98d3f06f 594 insn += (offset - 1) / 8;
07855bec
NC
595 while (uval != 0)
596 {
597 *insn-- |= uval;
598 uval >>= 8;
599 }
a85d7ed0
NC
600}
601
602/* Structure used to hold suffixes. */
07855bec
NC
603typedef enum
604 {
605 ELF_SUFFIX_NONE = 0,
606 ELF_SUFFIX_GOT,
607 ELF_SUFFIX_PLT,
608 ELF_SUFFIX_GOTENT
609 }
610elf_suffix_type;
611
612struct map_bfd
613 {
614 char *string;
615 int length;
616 elf_suffix_type suffix;
617 };
a85d7ed0 618
9d654c1c
AJ
619static elf_suffix_type s390_elf_suffix PARAMS ((char **, expressionS *));
620static int s390_exp_compare PARAMS ((expressionS *exp1, expressionS *exp2));
621static elf_suffix_type s390_lit_suffix
622 PARAMS ((char **, expressionS *, elf_suffix_type));
623
624
a85d7ed0
NC
625/* Parse @got/@plt/@gotoff. and return the desired relocation. */
626static elf_suffix_type
627s390_elf_suffix (str_p, exp_p)
628 char **str_p;
629 expressionS *exp_p;
630{
07855bec
NC
631 static struct map_bfd mapping[] =
632 {
a85d7ed0
NC
633 { "got", 3, ELF_SUFFIX_GOT },
634 { "got12", 5, ELF_SUFFIX_GOT },
635 { "plt", 3, ELF_SUFFIX_PLT },
636 { "gotent", 6, ELF_SUFFIX_GOTENT },
637 { NULL, 0, ELF_SUFFIX_NONE }
638 };
639
640 struct map_bfd *ptr;
641 char *str = *str_p;
642 char *ident;
643 int len;
644
645 if (*str++ != '@')
646 return ELF_SUFFIX_NONE;
647
648 ident = str;
3882b010 649 while (ISALNUM (*str))
a85d7ed0
NC
650 str++;
651 len = str - ident;
652
653 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
16a419ba
NC
654 if (len == ptr->length
655 && strncasecmp (ident, ptr->string, ptr->length) == 0)
07855bec
NC
656 {
657 if (exp_p->X_add_number != 0)
658 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
659 ptr->string, ptr->string);
660 /* Now check for identifier@suffix+constant. */
661 if (*str == '-' || *str == '+')
662 {
663 char *orig_line = input_line_pointer;
664 expressionS new_exp;
665
666 input_line_pointer = str;
667 expression (&new_exp);
668
669 switch (new_exp.X_op)
670 {
671 case O_constant: /* X_add_number (a constant expression). */
672 exp_p->X_add_number += new_exp.X_add_number;
673 str = input_line_pointer;
674 break;
675 case O_symbol: /* X_add_symbol + X_add_number. */
676 /* this case is used for e.g. xyz@PLT+.Label. */
677 exp_p->X_add_number += new_exp.X_add_number;
678 exp_p->X_op_symbol = new_exp.X_add_symbol;
679 exp_p->X_op = O_add;
680 str = input_line_pointer;
681 break;
682 case O_uminus: /* (- X_add_symbol) + X_add_number. */
683 /* this case is used for e.g. xyz@PLT-.Label. */
684 exp_p->X_add_number += new_exp.X_add_number;
685 exp_p->X_op_symbol = new_exp.X_add_symbol;
686 exp_p->X_op = O_subtract;
687 str = input_line_pointer;
688 break;
689 default:
690 break;
691 }
692
693 /* If s390_elf_suffix has not been called with
694 &input_line_pointer as first parameter, we have
695 clobbered the input_line_pointer. We have to
696 undo that. */
697 if (&input_line_pointer != str_p)
698 input_line_pointer = orig_line;
a85d7ed0 699 }
07855bec
NC
700 *str_p = str;
701 return ptr->suffix;
a85d7ed0 702 }
a85d7ed0
NC
703
704 return BFD_RELOC_UNUSED;
705}
706
707/* Structure used to hold a literal pool entry. */
07855bec
NC
708struct s390_lpe
709 {
710 struct s390_lpe *next;
711 expressionS ex;
712 FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */
713 LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */
714 int nbytes;
715 bfd_reloc_code_real_type reloc;
716 symbolS *sym;
717 };
a85d7ed0
NC
718
719static struct s390_lpe *lpe_free_list = NULL;
720static struct s390_lpe *lpe_list = NULL;
721static struct s390_lpe *lpe_list_tail = NULL;
722static symbolS *lp_sym = NULL;
723static int lp_count = 0;
724static int lpe_count = 0;
725
726static int
98d3f06f 727s390_exp_compare (exp1, exp2)
a85d7ed0
NC
728 expressionS *exp1;
729 expressionS *exp2;
730{
731 if (exp1->X_op != exp2->X_op)
732 return 0;
733
07855bec
NC
734 switch (exp1->X_op)
735 {
736 case O_constant: /* X_add_number must be equal. */
737 case O_register:
738 return exp1->X_add_number == exp2->X_add_number;
739
740 case O_big:
198ce79b 741 as_bad (_("Can't handle O_big in s390_exp_compare"));
07855bec
NC
742
743 case O_symbol: /* X_add_symbol & X_add_number must be equal. */
744 case O_symbol_rva:
745 case O_uminus:
746 case O_bit_not:
747 case O_logical_not:
16a419ba
NC
748 return (exp1->X_add_symbol == exp2->X_add_symbol)
749 && (exp1->X_add_number == exp2->X_add_number);
07855bec
NC
750
751 case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
752 case O_divide:
753 case O_modulus:
754 case O_left_shift:
755 case O_right_shift:
756 case O_bit_inclusive_or:
757 case O_bit_or_not:
758 case O_bit_exclusive_or:
759 case O_bit_and:
760 case O_add:
761 case O_subtract:
762 case O_eq:
763 case O_ne:
764 case O_lt:
765 case O_le:
766 case O_ge:
767 case O_gt:
768 case O_logical_and:
769 case O_logical_or:
16a419ba
NC
770 return (exp1->X_add_symbol == exp2->X_add_symbol)
771 && (exp1->X_op_symbol == exp2->X_op_symbol)
772 && (exp1->X_add_number == exp2->X_add_number);
07855bec 773 default:
98d3f06f
KH
774 return 0;
775 }
a85d7ed0
NC
776}
777
778/* Test for @lit and if its present make an entry in the literal pool and
779 modify the current expression to be an offset into the literal pool. */
780static elf_suffix_type
781s390_lit_suffix (str_p, exp_p, suffix)
782 char **str_p;
783 expressionS *exp_p;
784 elf_suffix_type suffix;
785{
786 bfd_reloc_code_real_type reloc;
787 char tmp_name[64];
788 char *str = *str_p;
789 char *ident;
790 struct s390_lpe *lpe;
791 int nbytes, len;
792
793 if (*str++ != ':')
794 return suffix; /* No modification. */
198ce79b 795
a85d7ed0
NC
796 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
797 ident = str;
3882b010 798 while (ISALNUM (*str))
a85d7ed0
NC
799 str++;
800 len = str - ident;
16a419ba
NC
801 if (len != 4 || strncasecmp (ident, "lit", 3) != 0
802 || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
a85d7ed0
NC
803 return suffix; /* no modification */
804 nbytes = ident[3] - '0';
805
806 reloc = BFD_RELOC_UNUSED;
07855bec
NC
807 if (suffix == ELF_SUFFIX_GOT)
808 {
809 if (nbytes == 2)
810 reloc = BFD_RELOC_390_GOT16;
811 else if (nbytes == 4)
812 reloc = BFD_RELOC_32_GOT_PCREL;
813 else if (nbytes == 8)
814 reloc = BFD_RELOC_390_GOT64;
815 }
816 else if (suffix == ELF_SUFFIX_PLT)
817 {
818 if (nbytes == 4)
819 reloc = BFD_RELOC_390_PLT32;
820 else if (nbytes == 8)
821 reloc = BFD_RELOC_390_PLT64;
822 }
a85d7ed0 823
07855bec 824 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
a85d7ed0 825 as_bad (_("Invalid suffix for literal pool entry"));
a85d7ed0
NC
826
827 /* Search the pool if the new entry is a duplicate. */
07855bec
NC
828 if (exp_p->X_op == O_big)
829 {
830 /* Special processing for big numbers. */
831 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
832 {
833 if (lpe->ex.X_op == O_big)
834 {
835 if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
836 {
837 if (memcmp (&generic_floating_point_number, &lpe->floatnum,
838 sizeof (FLONUM_TYPE)) == 0)
839 break;
840 }
841 else if (exp_p->X_add_number == lpe->ex.X_add_number)
842 {
843 if (memcmp (generic_bignum, lpe->bignum,
844 sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
845 break;
846 }
847 }
848 }
a85d7ed0 849 }
07855bec
NC
850 else
851 {
852 /* Processing for 'normal' data types. */
853 for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
16a419ba 854 if (lpe->nbytes == nbytes && lpe->reloc == reloc
98d3f06f 855 && s390_exp_compare (exp_p, &lpe->ex) != 0)
07855bec 856 break;
a85d7ed0 857 }
07855bec
NC
858
859 if (lpe == NULL)
860 {
861 /* A new literal. */
862 if (lpe_free_list != NULL)
863 {
864 lpe = lpe_free_list;
865 lpe_free_list = lpe_free_list->next;
866 }
a85d7ed0 867 else
07855bec 868 {
98d3f06f 869 lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe));
07855bec
NC
870 }
871
872 lpe->ex = *exp_p;
873
874 if (exp_p->X_op == O_big)
875 {
876 if (exp_p->X_add_number <= 0)
877 lpe->floatnum = generic_floating_point_number;
878 else if (exp_p->X_add_number <= 4)
879 memcpy (lpe->bignum, generic_bignum,
98d3f06f 880 exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
07855bec
NC
881 else
882 as_bad (_("Big number is too big"));
883 }
884
885 lpe->nbytes = nbytes;
886 lpe->reloc = reloc;
887 /* Literal pool name defined ? */
888 if (lp_sym == NULL)
889 {
07726851 890 sprintf (tmp_name, ".L\001%i", lp_count);
98d3f06f 891 lp_sym = symbol_make (tmp_name);
07855bec 892 }
a85d7ed0 893
07855bec 894 /* Make name for literal pool entry. */
07726851 895 sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
07855bec 896 lpe_count++;
98d3f06f 897 lpe->sym = symbol_make (tmp_name);
07855bec
NC
898
899 /* Add to literal pool list. */
900 lpe->next = NULL;
901 if (lpe_list_tail != NULL)
902 {
903 lpe_list_tail->next = lpe;
904 lpe_list_tail = lpe;
905 }
906 else
907 lpe_list = lpe_list_tail = lpe;
908 }
198ce79b 909
a85d7ed0
NC
910 /* Now change exp_p to the offset into the literal pool.
911 Thats the expression: .L^Ax^By-.L^Ax */
912 exp_p->X_add_symbol = lpe->sym;
913 exp_p->X_op_symbol = lp_sym;
914 exp_p->X_op = O_subtract;
915 exp_p->X_add_number = 0;
916
917 *str_p = str;
918
919 /* We change the suffix type to ELF_SUFFIX_NONE, because
920 the difference of two local labels is just a number. */
921 return ELF_SUFFIX_NONE;
922}
923
924/* Like normal .long/.short/.word, except support @got, etc.
925 clobbers input_line_pointer, checks end-of-line. */
926static void
927s390_elf_cons (nbytes)
928 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
929{
930 expressionS exp;
931 elf_suffix_type suffix;
932
07855bec
NC
933 if (is_it_end_of_statement ())
934 {
935 demand_empty_rest_of_line ();
936 return;
937 }
a85d7ed0 938
07855bec
NC
939 do
940 {
941 expression (&exp);
942
943 if (exp.X_op == O_symbol
944 && *input_line_pointer == '@'
945 && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
946 {
947 bfd_reloc_code_real_type reloc;
948 reloc_howto_type *reloc_howto;
949 int size;
950 char *where;
951
952 if (nbytes == 2 && suffix == ELF_SUFFIX_GOT)
953 reloc = BFD_RELOC_390_GOT16;
954 else if (nbytes == 4 && suffix == ELF_SUFFIX_GOT)
955 reloc = BFD_RELOC_32_GOT_PCREL;
956 else if (nbytes == 8 && suffix == ELF_SUFFIX_GOT)
957 reloc = BFD_RELOC_390_GOT64;
958 else if (nbytes == 4 && suffix == ELF_SUFFIX_PLT)
959 reloc = BFD_RELOC_390_PLT32;
960 else if (nbytes == 8 && suffix == ELF_SUFFIX_PLT)
961 reloc = BFD_RELOC_390_PLT64;
962 else
963 reloc = BFD_RELOC_UNUSED;
964
965 if (reloc != BFD_RELOC_UNUSED)
966 {
967 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
968 size = bfd_get_reloc_size (reloc_howto);
969 if (size > nbytes)
970 as_bad (_("%s relocations do not fit in %d bytes"),
971 reloc_howto->name, nbytes);
07726851 972 where = frag_more (nbytes);
07855bec 973 md_number_to_chars (where, 0, size);
198ce79b
AJ
974 /* To make fixup_segment do the pc relative conversion the
975 pcrel parameter on the fix_new_exp call needs to be false. */
976 fix_new_exp (frag_now, where - frag_now->fr_literal,
977 size, &exp, false, reloc);
07855bec
NC
978 }
979 else
980 as_bad (_("relocation not applicable"));
981 }
a85d7ed0 982 else
07855bec
NC
983 emit_expr (&exp, (unsigned int) nbytes);
984 }
985 while (*input_line_pointer++ == ',');
a85d7ed0 986
98d3f06f 987 input_line_pointer--; /* Put terminator back into stream. */
a85d7ed0
NC
988 demand_empty_rest_of_line ();
989}
990
991/* We need to keep a list of fixups. We can't simply generate them as
992 we go, because that would require us to first create the frag, and
993 that would screw up references to ``.''. */
994
995struct s390_fixup
07855bec
NC
996 {
997 expressionS exp;
998 int opindex;
999 bfd_reloc_code_real_type reloc;
1000 };
a85d7ed0
NC
1001
1002#define MAX_INSN_FIXUPS (4)
1003
1004/* This routine is called for each instruction to be assembled. */
1005
9d654c1c 1006static char *
a85d7ed0
NC
1007md_gather_operands (str, insn, opcode)
1008 char *str;
1009 unsigned char *insn;
1010 const struct s390_opcode *opcode;
1011{
1012 struct s390_fixup fixups[MAX_INSN_FIXUPS];
1013 const struct s390_operand *operand;
1014 const unsigned char *opindex_ptr;
1015 elf_suffix_type suffix;
1016 bfd_reloc_code_real_type reloc;
1017 int skip_optional;
1018 int parentheses;
1019 char *f;
1020 int fc, i;
1021
98d3f06f
KH
1022 while (ISSPACE (*str))
1023 str++;
a85d7ed0
NC
1024
1025 parentheses = 0;
1026 skip_optional = 0;
1027
1028 /* Gather the operands. */
1029 fc = 0;
07855bec
NC
1030 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1031 {
1032 expressionS ex;
1033 char *hold;
1034
1035 operand = s390_operands + *opindex_ptr;
198ce79b 1036
07855bec
NC
1037 if (skip_optional && (operand->flags & S390_OPERAND_INDEX))
1038 {
1039 /* We do an early skip. For D(X,B) constructions the index
198ce79b 1040 register is skipped (X is optional). For D(L,B) the base
07855bec
NC
1041 register will be the skipped operand, because L is NOT
1042 optional. */
1043 skip_optional = 0;
1044 continue;
1045 }
198ce79b 1046
07855bec
NC
1047 /* Gather the operand. */
1048 hold = input_line_pointer;
1049 input_line_pointer = str;
1050
98d3f06f
KH
1051 /* Parse the operand. */
1052 if (! register_name (&ex))
07855bec 1053 expression (&ex);
198ce79b 1054
07855bec
NC
1055 str = input_line_pointer;
1056 input_line_pointer = hold;
198ce79b 1057
07855bec
NC
1058 /* Write the operand to the insn. */
1059 if (ex.X_op == O_illegal)
1060 as_bad (_("illegal operand"));
1061 else if (ex.X_op == O_absent)
1062 as_bad (_("missing operand"));
1063 else if (ex.X_op == O_register || ex.X_op == O_constant)
1064 {
1065 s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
1066
1067 if (ex.X_op != O_register && ex.X_op != O_constant)
1068 {
1069 /* We need to generate a fixup for the
1070 expression returned by s390_lit_suffix. */
1071 if (fc >= MAX_INSN_FIXUPS)
1072 as_fatal (_("too many fixups"));
1073 fixups[fc].exp = ex;
1074 fixups[fc].opindex = *opindex_ptr;
1075 fixups[fc].reloc = BFD_RELOC_UNUSED;
1076 ++fc;
1077 }
1078 else
1079 {
16a419ba
NC
1080 if ((operand->flags & S390_OPERAND_INDEX)
1081 && ex.X_add_number == 0
1082 && warn_areg_zero == TRUE)
07726851 1083 as_warn ("index register specified but zero");
16a419ba
NC
1084 if ((operand->flags & S390_OPERAND_BASE)
1085 && ex.X_add_number == 0
1086 && warn_areg_zero == TRUE)
07726851 1087 as_warn ("base register specified but zero");
07855bec
NC
1088 s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0);
1089 }
1090 }
1091 else
1092 {
1093 suffix = s390_elf_suffix (&str, &ex);
1094 suffix = s390_lit_suffix (&str, &ex, suffix);
1095 reloc = BFD_RELOC_UNUSED;
1096
1097 if (suffix == ELF_SUFFIX_GOT)
1098 {
1099 if (operand->flags & S390_OPERAND_DISP)
1100 reloc = BFD_RELOC_390_GOT12;
16a419ba
NC
1101 else if ((operand->flags & S390_OPERAND_SIGNED)
1102 && (operand->bits == 16))
07855bec 1103 reloc = BFD_RELOC_390_GOT16;
16a419ba
NC
1104 else if ((operand->flags & S390_OPERAND_PCREL)
1105 && (operand->bits == 32))
07855bec
NC
1106 reloc = BFD_RELOC_390_GOTENT;
1107 }
1108 else if (suffix == ELF_SUFFIX_PLT)
1109 {
16a419ba
NC
1110 if ((operand->flags & S390_OPERAND_PCREL)
1111 && (operand->bits == 16))
07855bec 1112 reloc = BFD_RELOC_390_PLT16DBL;
16a419ba
NC
1113 else if ((operand->flags & S390_OPERAND_PCREL)
1114 && (operand->bits == 32))
07855bec
NC
1115 reloc = BFD_RELOC_390_PLT32DBL;
1116 }
1117 else if (suffix == ELF_SUFFIX_GOTENT)
1118 {
16a419ba
NC
1119 if ((operand->flags & S390_OPERAND_PCREL)
1120 && (operand->bits == 32))
07855bec
NC
1121 reloc = BFD_RELOC_390_GOTENT;
1122 }
1123
1124 if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1125 as_bad (_("invalid operand suffix"));
1126 /* We need to generate a fixup of type 'reloc' for this
1127 expression. */
a85d7ed0
NC
1128 if (fc >= MAX_INSN_FIXUPS)
1129 as_fatal (_("too many fixups"));
1130 fixups[fc].exp = ex;
1131 fixups[fc].opindex = *opindex_ptr;
07855bec 1132 fixups[fc].reloc = reloc;
a85d7ed0 1133 ++fc;
07855bec 1134 }
198ce79b 1135
07855bec
NC
1136 /* Check the next character. The call to expression has advanced
1137 str past any whitespace. */
1138 if (operand->flags & S390_OPERAND_DISP)
1139 {
1140 /* After a displacement a block in parentheses can start. */
1141 if (*str != '(')
1142 {
1143 /* Check if parethesed block can be skipped. If the next
1144 operand is neiter an optional operand nor a base register
1145 then we have a syntax error. */
1146 operand = s390_operands + *(++opindex_ptr);
1147 if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
1148 as_bad (_("syntax error; missing '(' after displacement"));
1149
1150 /* Ok, skip all operands until S390_OPERAND_BASE. */
1151 while (!(operand->flags & S390_OPERAND_BASE))
1152 operand = s390_operands + *(++opindex_ptr);
198ce79b 1153
07855bec
NC
1154 /* If there is a next operand it must be seperated by a comma. */
1155 if (opindex_ptr[1] != '\0')
1156 {
1157 if (*str++ != ',')
07726851 1158 as_bad (_("syntax error; expected ,"));
07855bec
NC
1159 }
1160 }
1161 else
1162 {
1163 /* We found an opening parentheses. */
1164 str++;
1165 for (f = str; *f != '\0'; f++)
1166 if (*f == ',' || *f == ')')
1167 break;
1168 /* If there is no comma until the closing parentheses OR
1169 there is a comma right after the opening parentheses,
1170 we have to skip optional operands. */
1171 if (*f == ',' && f == str)
1172 {
1173 /* comma directly after '(' ? */
1174 skip_optional = 1;
1175 str++;
1176 }
1177 else
1178 skip_optional = (*f != ',');
1179 }
1180 }
1181 else if (operand->flags & S390_OPERAND_BASE)
1182 {
1183 /* After the base register the parenthesed block ends. */
1184 if (*str++ != ')')
1185 as_bad (_("syntax error; missing ')' after base register"));
1186 skip_optional = 0;
1187 /* If there is a next operand it must be seperated by a comma. */
1188 if (opindex_ptr[1] != '\0')
1189 {
1190 if (*str++ != ',')
1191 as_bad (_("syntax error; expected ,"));
1192 }
1193 }
1194 else
1195 {
1196 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1197 of D(L,B). In this case the base register has to be skipped. */
1198 if (*str == ')')
1199 {
1200 operand = s390_operands + *(++opindex_ptr);
1201
1202 if (!(operand->flags & S390_OPERAND_BASE))
1203 as_bad (_("syntax error; ')' not allowed here"));
1204 str++;
1205 }
1206 /* If there is a next operand it must be seperated by a comma. */
1207 if (opindex_ptr[1] != '\0')
1208 {
1209 if (*str++ != ',')
07726851 1210 as_bad (_("syntax error; expected ,"));
07855bec 1211 }
a85d7ed0 1212 }
a85d7ed0 1213 }
a85d7ed0 1214
3882b010 1215 while (ISSPACE (*str))
a85d7ed0
NC
1216 ++str;
1217
07855bec
NC
1218 if (*str != '\0')
1219 {
1220 char *linefeed;
a85d7ed0 1221
07726851 1222 if ((linefeed = strchr (str, '\n')) != NULL)
07855bec
NC
1223 *linefeed = '\0';
1224 as_bad (_("junk at end of line: `%s'"), str);
1225 if (linefeed != NULL)
1226 *linefeed = '\n';
1227 }
a85d7ed0
NC
1228
1229 /* Write out the instruction. */
1230 f = frag_more (opcode->oplen);
07855bec 1231 memcpy (f, insn, opcode->oplen);
8f5b2891 1232 dwarf2_emit_insn (opcode->oplen);
a85d7ed0
NC
1233
1234 /* Create any fixups. At this point we do not use a
1235 bfd_reloc_code_real_type, but instead just use the
1236 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1237 handle fixups for any operand type, although that is admittedly
1238 not a very exciting feature. We pick a BFD reloc type in
1239 md_apply_fix3. */
07855bec
NC
1240 for (i = 0; i < fc; i++)
1241 {
1242 operand = s390_operands + fixups[i].opindex;
a85d7ed0 1243
07855bec
NC
1244 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1245 {
1246 reloc_howto_type *reloc_howto;
1247 fixS *fixP;
1248 int size;
198ce79b 1249
07855bec
NC
1250 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1251 if (!reloc_howto)
1252 abort ();
198ce79b 1253
07855bec
NC
1254 size = bfd_get_reloc_size (reloc_howto);
1255
1256 if (size < 1 || size > 4)
1257 abort ();
198ce79b
AJ
1258
1259 fixP = fix_new_exp (frag_now,
1260 f - frag_now->fr_literal + (operand->shift/8),
07855bec
NC
1261 size, &fixups[i].exp, reloc_howto->pc_relative,
1262 fixups[i].reloc);
1263 /* Turn off overflow checking in fixup_segment. This is necessary
1264 because fixup_segment will signal an overflow for large 4 byte
1265 quantities for GOT12 relocations. */
16a419ba
NC
1266 if ( fixups[i].reloc == BFD_RELOC_390_GOT12
1267 || fixups[i].reloc == BFD_RELOC_390_GOT16)
07855bec
NC
1268 fixP->fx_no_overflow = 1;
1269 }
1270 else
1271 fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp,
1272 (operand->flags & S390_OPERAND_PCREL) != 0,
1273 ((bfd_reloc_code_real_type)
1274 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1275 }
a85d7ed0
NC
1276 return str;
1277}
1278
1279/* This routine is called for each instruction to be assembled. */
1280
1281void
1282md_assemble (str)
1283 char *str;
1284{
1285 const struct s390_opcode *opcode;
1286 unsigned char insn[6];
1287 char *s;
1288
1289 /* Get the opcode. */
3882b010 1290 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
a85d7ed0
NC
1291 ;
1292 if (*s != '\0')
1293 *s++ = '\0';
1294
1295 /* Look up the opcode in the hash table. */
1296 opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str);
07855bec
NC
1297 if (opcode == (const struct s390_opcode *) NULL)
1298 {
1299 as_bad (_("Unrecognized opcode: `%s'"), str);
1300 return;
1301 }
1302 else if (!(opcode->architecture & current_arch_mask))
1303 {
07726851 1304 as_bad ("Opcode %s not available in this architecture", str);
07855bec
NC
1305 return;
1306 }
a85d7ed0 1307
07726851 1308 memcpy (insn, opcode->opcode, sizeof (insn));
07855bec 1309 md_gather_operands (s, insn, opcode);
a85d7ed0
NC
1310}
1311
1312#ifndef WORKING_DOT_WORD
1313/* Handle long and short jumps. We don't support these */
1314void
1315md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1316 char *ptr;
1317 addressT from_addr, to_addr;
1318 fragS *frag;
1319 symbolS *to_symbol;
1320{
1321 abort ();
1322}
1323
1324void
1325md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1326 char *ptr;
1327 addressT from_addr, to_addr;
1328 fragS *frag;
1329 symbolS *to_symbol;
1330{
1331 abort ();
1332}
1333#endif
1334
1335void
1336s390_bss (ignore)
1337 int ignore ATTRIBUTE_UNUSED;
1338{
1339 /* We don't support putting frags in the BSS segment, we fake it
1340 by marking in_bss, then looking at s_skip for clues. */
1341
1342 subseg_set (bss_section, 0);
1343 demand_empty_rest_of_line ();
1344}
1345
1346/* Pseudo-op handling. */
1347
1348void
07726851 1349s390_insn (ignore)
a85d7ed0
NC
1350 int ignore ATTRIBUTE_UNUSED;
1351{
1352 expressionS exp;
1353 const struct s390_opcode *opformat;
1354 unsigned char insn[6];
1355 char *s;
1356
1357 /* Get the opcode format. */
1358 s = input_line_pointer;
3882b010 1359 while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
a85d7ed0
NC
1360 s++;
1361 if (*s != ',')
1362 as_bad (_("Invalid .insn format\n"));
1363 *s++ = '\0';
1364
1365 /* Look up the opcode in the hash table. */
1366 opformat = (struct s390_opcode *)
1367 hash_find (s390_opformat_hash, input_line_pointer);
07855bec
NC
1368 if (opformat == (const struct s390_opcode *) NULL)
1369 {
1370 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
1371 return;
1372 }
a85d7ed0
NC
1373 input_line_pointer = s;
1374 expression (&exp);
07855bec
NC
1375 if (exp.X_op == O_constant)
1376 {
16a419ba
NC
1377 if ( ((opformat->oplen == 6) && (exp.X_op > 0) && (exp.X_op < (1ULL << 48)))
1378 || ((opformat->oplen == 4) && (exp.X_op > 0) && (exp.X_op < (1ULL << 32)))
1379 || ((opformat->oplen == 2) && (exp.X_op > 0) && (exp.X_op < (1ULL << 16))))
07855bec
NC
1380 md_number_to_chars (insn, exp.X_add_number, opformat->oplen);
1381 else
07726851 1382 as_bad (_("Invalid .insn format\n"));
07855bec
NC
1383 }
1384 else if (exp.X_op == O_big)
1385 {
16a419ba
NC
1386 if (exp.X_add_number > 0
1387 && opformat->oplen == 6
1388 && generic_bignum[3] == 0)
07855bec
NC
1389 {
1390 md_number_to_chars (insn, generic_bignum[2], 2);
1391 md_number_to_chars (&insn[2], generic_bignum[1], 2);
1392 md_number_to_chars (&insn[4], generic_bignum[0], 2);
1393 }
1394 else
07726851 1395 as_bad (_("Invalid .insn format\n"));
07855bec
NC
1396 }
1397 else
a85d7ed0 1398 as_bad (_("second operand of .insn not a constant\n"));
a85d7ed0 1399
b6849f55
NC
1400 if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
1401 as_bad (_("missing comma after insn constant\n"));
98d3f06f 1402
07726851 1403 if ((s = strchr (input_line_pointer, '\n')) != NULL)
a85d7ed0 1404 *s = '\0';
b6849f55
NC
1405 input_line_pointer = md_gather_operands (input_line_pointer, insn,
1406 opformat);
a85d7ed0
NC
1407 if (s != NULL)
1408 *s = '\n';
1409 demand_empty_rest_of_line ();
1410}
1411
1412/* The .byte pseudo-op. This is similar to the normal .byte
1413 pseudo-op, but it can also take a single ASCII string. */
1414
1415static void
1416s390_byte (ignore)
1417 int ignore ATTRIBUTE_UNUSED;
1418{
1419 if (*input_line_pointer != '\"')
1420 {
1421 cons (1);
1422 return;
1423 }
1424
1425 /* Gather characters. A real double quote is doubled. Unusual
1426 characters are not permitted. */
1427 ++input_line_pointer;
1428 while (1)
1429 {
1430 char c;
1431
1432 c = *input_line_pointer++;
1433
1434 if (c == '\"')
1435 {
1436 if (*input_line_pointer != '\"')
1437 break;
1438 ++input_line_pointer;
1439 }
1440
1441 FRAG_APPEND_1_CHAR (c);
1442 }
1443
1444 demand_empty_rest_of_line ();
1445}
1446
1447/* The .ltorg pseudo-op.This emits all literals defined since the last
198ce79b 1448 .ltorg or the invocation of gas. Literals are defined with the
a85d7ed0
NC
1449 @lit suffix. */
1450
1451static void
1452s390_literals (ignore)
1453 int ignore ATTRIBUTE_UNUSED;
1454{
1455 struct s390_lpe *lpe;
1456
1457 if (lp_sym == NULL || lpe_count == 0)
98d3f06f 1458 return; /* Nothing to be done. */
a85d7ed0
NC
1459
1460 /* Emit symbol for start of literal pool. */
1461 S_SET_SEGMENT (lp_sym, now_seg);
1462 S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
1463 lp_sym->sy_frag = frag_now;
1464
07855bec
NC
1465 while (lpe_list)
1466 {
1467 lpe = lpe_list;
1468 lpe_list = lpe_list->next;
1469 S_SET_SEGMENT (lpe->sym, now_seg);
1470 S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
1471 lpe->sym->sy_frag = frag_now;
1472
1473 /* Emit literal pool entry. */
1474 if (lpe->reloc != BFD_RELOC_UNUSED)
1475 {
198ce79b 1476 reloc_howto_type *reloc_howto =
07855bec
NC
1477 bfd_reloc_type_lookup (stdoutput, lpe->reloc);
1478 int size = bfd_get_reloc_size (reloc_howto);
1479 char *where;
1480
1481 if (size > lpe->nbytes)
1482 as_bad (_("%s relocations do not fit in %d bytes"),
1483 reloc_howto->name, lpe->nbytes);
07726851 1484 where = frag_more (lpe->nbytes);
07855bec
NC
1485 md_number_to_chars (where, 0, size);
1486 fix_new_exp (frag_now, where - frag_now->fr_literal,
1487 size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
1488 }
1489 else
1490 {
1491 if (lpe->ex.X_op == O_big)
1492 {
1493 if (lpe->ex.X_add_number <= 0)
1494 generic_floating_point_number = lpe->floatnum;
1495 else
1496 memcpy (generic_bignum, lpe->bignum,
98d3f06f 1497 lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
07855bec
NC
1498 }
1499 emit_expr (&lpe->ex, lpe->nbytes);
1500 }
a85d7ed0 1501
07855bec
NC
1502 lpe->next = lpe_free_list;
1503 lpe_free_list = lpe;
1504 }
a85d7ed0
NC
1505 lpe_list_tail = NULL;
1506 lp_sym = NULL;
1507 lp_count++;
1508 lpe_count = 0;
1509}
1510
1511/* Turn a string in input_line_pointer into a floating point constant
1512 of type type, and store the appropriate bytes in *litp. The number
1513 of LITTLENUMS emitted is stored in *sizep . An error message is
1514 returned, or NULL on OK. */
1515
1516char *
1517md_atof (type, litp, sizep)
1518 int type;
1519 char *litp;
1520 int *sizep;
1521{
1522 int prec;
1523 LITTLENUM_TYPE words[4];
1524 char *t;
1525 int i;
1526
1527 switch (type)
1528 {
1529 case 'f':
1530 prec = 2;
1531 break;
1532
1533 case 'd':
1534 prec = 4;
1535 break;
1536
1537 default:
1538 *sizep = 0;
1539 return "bad call to md_atof";
1540 }
1541
1542 t = atof_ieee (input_line_pointer, type, words);
1543 if (t)
1544 input_line_pointer = t;
1545
1546 *sizep = prec * 2;
1547
1548 for (i = 0; i < prec; i++)
1549 {
1550 md_number_to_chars (litp, (valueT) words[i], 2);
1551 litp += 2;
1552 }
198ce79b 1553
a85d7ed0
NC
1554 return NULL;
1555}
1556
1557/* Align a section (I don't know why this is machine dependent). */
1558
1559valueT
1560md_section_align (seg, addr)
1561 asection *seg;
1562 valueT addr;
1563{
1564 int align = bfd_get_section_alignment (stdoutput, seg);
1565
1566 return ((addr + (1 << align) - 1) & (-1 << align));
1567}
1568
1569/* We don't have any form of relaxing. */
1570
1571int
1572md_estimate_size_before_relax (fragp, seg)
1573 fragS *fragp ATTRIBUTE_UNUSED;
1574 asection *seg ATTRIBUTE_UNUSED;
1575{
1576 abort ();
1577 return 0;
1578}
1579
1580/* Convert a machine dependent frag. We never generate these. */
1581
1582void
1583md_convert_frag (abfd, sec, fragp)
1584 bfd *abfd ATTRIBUTE_UNUSED;
1585 asection *sec ATTRIBUTE_UNUSED;
1586 fragS *fragp ATTRIBUTE_UNUSED;
1587{
1588 abort ();
1589}
1590
1591symbolS *
1592md_undefined_symbol (name)
1593 char *name;
1594{
98d3f06f 1595 if (*name == '_' && *(name + 1) == 'G'
07726851 1596 && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
98d3f06f
KH
1597 {
1598 if (!GOT_symbol)
1599 {
1600 if (symbol_find (name))
1601 as_bad (_("GOT already in symbol table"));
1602 GOT_symbol = symbol_new (name, undefined_section,
1603 (valueT) 0, &zero_address_frag);
1604 }
1605 return GOT_symbol;
1606 }
a85d7ed0
NC
1607 return 0;
1608}
1609
1610/* Functions concerning relocs. */
1611
1612/* The location from which a PC relative jump should be calculated,
1613 given a PC relative reloc. */
1614
1615long
1616md_pcrel_from_section (fixp, sec)
1617 fixS *fixp;
1618 segT sec ATTRIBUTE_UNUSED;
1619{
1620 return fixp->fx_frag->fr_address + fixp->fx_where;
1621}
1622
1623/* Here we decide which fixups can be adjusted to make them relative to
1624 the beginning of the section instead of the symbol. Basically we need
1625 to make sure that the dynamic relocations are done correctly, so in
1626 some cases we force the original symbol to be used. */
1627int
98d3f06f
KH
1628tc_s390_fix_adjustable (fixP)
1629 fixS *fixP;
a85d7ed0
NC
1630{
1631 /* Prevent all adjustments to global symbols. */
1632 if (S_IS_EXTERN (fixP->fx_addsy))
1633 return 0;
1634 if (S_IS_WEAK (fixP->fx_addsy))
1635 return 0;
302576af 1636 /* Don't adjust pc-relative references to merge sections. */
98d3f06f 1637 if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0
302576af
MS
1638 && fixP->fx_pcrel)
1639 return 0;
a85d7ed0 1640 /* adjust_reloc_syms doesn't know about the GOT. */
16a419ba 1641 if ( fixP->fx_r_type == BFD_RELOC_32_GOTOFF
a85d7ed0
NC
1642 || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
1643 || fixP->fx_r_type == BFD_RELOC_390_PLT32
1644 || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
1645 || fixP->fx_r_type == BFD_RELOC_390_PLT64
1646 || fixP->fx_r_type == BFD_RELOC_390_GOT12
1647 || fixP->fx_r_type == BFD_RELOC_390_GOT16
1648 || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
1649 || fixP->fx_r_type == BFD_RELOC_390_GOT64
07855bec 1650 || fixP->fx_r_type == BFD_RELOC_390_GOTENT
a85d7ed0
NC
1651 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1652 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1653 return 0;
1654 return 1;
1655}
1656
b8edc45c
MS
1657/* Return true if we must always emit a reloc for a type and false if
1658 there is some hope of resolving it a assembly time. */
1659int
1660tc_s390_force_relocation (fixp)
1661 struct fix *fixp;
1662{
1663 /* Ensure we emit a relocation for every reference to the global
1664 offset table or to the procedure link table. */
1665 switch (fixp->fx_r_type)
1666 {
1667 case BFD_RELOC_390_GOT12:
1668 case BFD_RELOC_32_GOT_PCREL:
1669 case BFD_RELOC_32_GOTOFF:
1670 case BFD_RELOC_390_GOTPC:
1671 case BFD_RELOC_390_GOT16:
1672 case BFD_RELOC_390_GOTPCDBL:
1673 case BFD_RELOC_390_GOT64:
1674 case BFD_RELOC_390_GOTENT:
1675 case BFD_RELOC_390_PLT32:
1676 case BFD_RELOC_390_PLT16DBL:
1677 case BFD_RELOC_390_PLT32DBL:
1678 case BFD_RELOC_390_PLT64:
1679 case BFD_RELOC_VTABLE_INHERIT:
1680 case BFD_RELOC_VTABLE_ENTRY:
1681 return 1;
1682 default:
1683 return 0;
1684 }
1685}
1686
a85d7ed0
NC
1687/* Apply a fixup to the object code. This is called for all the
1688 fixups we generated by the call to fix_new_exp, above. In the call
1689 above we used a reloc code which was the largest legal reloc code
1690 plus the operand index. Here we undo that to recover the operand
1691 index. At this point all symbol values should be fully resolved,
1692 and we attempt to completely resolve the reloc. If we can not do
1693 that, we determine the correct reloc code and put it back in the
1694 fixup. */
1695
94f592af
NC
1696void
1697md_apply_fix3 (fixP, valP, seg)
1698 fixS *fixP;
1699 valueT *valP;
b8edc45c 1700 segT seg;
a85d7ed0
NC
1701{
1702 char *where;
98d3f06f 1703 valueT value = *valP;
a85d7ed0 1704
94f592af 1705 where = fixP->fx_frag->fr_literal + fixP->fx_where;
a85d7ed0 1706
98d3f06f 1707 if (fixP->fx_subsy != NULL)
07855bec 1708 {
94f592af
NC
1709 if ((fixP->fx_addsy != NULL
1710 && S_GET_SEGMENT (fixP->fx_addsy) == S_GET_SEGMENT (fixP->fx_subsy)
1711 && SEG_NORMAL (S_GET_SEGMENT (fixP->fx_addsy)))
1712 || (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section))
1713 value += S_GET_VALUE (fixP->fx_subsy);
1714 if (!S_IS_DEFINED (fixP->fx_subsy))
1715 as_bad_where (fixP->fx_file, fixP->fx_line,
07855bec 1716 _("unresolved fx_subsy symbol that must be resolved"));
98d3f06f 1717 value -= S_GET_VALUE (fixP->fx_subsy);
a85d7ed0 1718
94f592af
NC
1719 if (S_GET_SEGMENT (fixP->fx_subsy) == seg && ! fixP->fx_pcrel)
1720 value += MD_PCREL_FROM_SECTION (fixP, seg);
b8edc45c 1721 }
98d3f06f
KH
1722
1723 if (fixP->fx_addsy != NULL)
07855bec 1724 {
94f592af
NC
1725 if ((fixP->fx_subsy != NULL
1726 && S_GET_SEGMENT (fixP->fx_addsy) == S_GET_SEGMENT (fixP->fx_subsy)
98d3f06f 1727 && SEG_NORMAL (S_GET_SEGMENT (fixP->fx_addsy)))
94f592af
NC
1728 || (S_GET_SEGMENT (fixP->fx_addsy) == seg
1729 && fixP->fx_pcrel && TC_RELOC_RTSYM_LOC_FIXUP (fixP))
98d3f06f 1730 || (!fixP->fx_pcrel
94f592af
NC
1731 && S_GET_SEGMENT (fixP->fx_addsy) == absolute_section)
1732 || (S_GET_SEGMENT (fixP->fx_addsy) != undefined_section
1733 && !bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy))
98d3f06f 1734 && TC_FIX_ADJUSTABLE (fixP)))
94f592af
NC
1735 value -= S_GET_VALUE (fixP->fx_addsy);
1736
1737 if (fixP->fx_pcrel)
1738 value += fixP->fx_frag->fr_address + fixP->fx_where;
07855bec
NC
1739 }
1740 else
94f592af 1741 fixP->fx_done = 1;
a85d7ed0 1742
94f592af 1743 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
07855bec
NC
1744 {
1745 const struct s390_operand *operand;
1746 int opindex;
198ce79b 1747
94f592af 1748 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
07855bec 1749 operand = &s390_operands[opindex];
198ce79b 1750
94f592af 1751 if (fixP->fx_done)
07855bec
NC
1752 {
1753 /* Insert the fully resolved operand value. */
1754 s390_insert_operand (where, operand, (offsetT) value,
94f592af
NC
1755 fixP->fx_file, fixP->fx_line);
1756 return;
07855bec 1757 }
198ce79b 1758
07855bec
NC
1759 /* Determine a BFD reloc value based on the operand information.
1760 We are only prepared to turn a few of the operands into
1761 relocs. */
94f592af 1762 fixP->fx_offset = value;
07855bec
NC
1763 if (operand->bits == 12 && operand->shift == 20)
1764 {
94f592af
NC
1765 fixP->fx_size = 2;
1766 fixP->fx_where += 2;
1767 fixP->fx_r_type = BFD_RELOC_390_12;
07855bec
NC
1768 }
1769 else if (operand->bits == 12 && operand->shift == 36)
1770 {
94f592af
NC
1771 fixP->fx_size = 2;
1772 fixP->fx_where += 4;
1773 fixP->fx_r_type = BFD_RELOC_390_12;
07855bec
NC
1774 }
1775 else if (operand->bits == 8 && operand->shift == 8)
1776 {
94f592af
NC
1777 fixP->fx_size = 1;
1778 fixP->fx_where += 1;
1779 fixP->fx_r_type = BFD_RELOC_8;
07855bec
NC
1780 }
1781 else if (operand->bits == 16 && operand->shift == 16)
1782 {
94f592af
NC
1783 fixP->fx_size = 2;
1784 fixP->fx_where += 2;
07855bec
NC
1785 if (operand->flags & S390_OPERAND_PCREL)
1786 {
94f592af
NC
1787 fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
1788 fixP->fx_offset += 2;
07855bec
NC
1789 }
1790 else
94f592af 1791 fixP->fx_r_type = BFD_RELOC_16;
07855bec 1792 }
16a419ba
NC
1793 else if (operand->bits == 32 && operand->shift == 16
1794 && (operand->flags & S390_OPERAND_PCREL))
07855bec 1795 {
94f592af
NC
1796 fixP->fx_size = 4;
1797 fixP->fx_where += 2;
1798 fixP->fx_offset += 2;
1799 fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
07855bec 1800 }
a85d7ed0 1801 else
07855bec
NC
1802 {
1803 char *sfile;
1804 unsigned int sline;
198ce79b 1805
07855bec
NC
1806 /* Use expr_symbol_where to see if this is an expression
1807 symbol. */
94f592af
NC
1808 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
1809 as_bad_where (fixP->fx_file, fixP->fx_line,
07855bec
NC
1810 _("unresolved expression that must be resolved"));
1811 else
94f592af 1812 as_bad_where (fixP->fx_file, fixP->fx_line,
07855bec 1813 _("unsupported relocation type"));
94f592af
NC
1814 fixP->fx_done = 1;
1815 return;
07855bec 1816 }
a85d7ed0 1817 }
07855bec
NC
1818 else
1819 {
94f592af 1820 switch (fixP->fx_r_type)
07855bec
NC
1821 {
1822 case BFD_RELOC_8:
94f592af 1823 if (fixP->fx_pcrel)
07855bec 1824 abort ();
94f592af 1825 if (fixP->fx_done)
07855bec
NC
1826 md_number_to_chars (where, value, 1);
1827 break;
1828 case BFD_RELOC_390_12:
1829 case BFD_RELOC_390_GOT12:
94f592af 1830 if (fixP->fx_done)
07855bec
NC
1831 {
1832 unsigned short mop;
1833
1834 mop = bfd_getb16 ((unsigned char *) where);
1835 mop |= (unsigned short) (value & 0xfff);
1836 bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
198ce79b 1837 }
07855bec 1838 break;
198ce79b 1839
07855bec
NC
1840 case BFD_RELOC_16:
1841 case BFD_RELOC_GPREL16:
1842 case BFD_RELOC_16_GOT_PCREL:
1843 case BFD_RELOC_16_GOTOFF:
94f592af
NC
1844 if (fixP->fx_pcrel)
1845 as_bad_where (fixP->fx_file, fixP->fx_line,
07855bec 1846 "cannot emit PC relative %s relocation%s%s",
94f592af
NC
1847 bfd_get_reloc_code_name (fixP->fx_r_type),
1848 fixP->fx_addsy != NULL ? " against " : "",
1849 (fixP->fx_addsy != NULL
1850 ? S_GET_NAME (fixP->fx_addsy)
07855bec 1851 : ""));
94f592af 1852 if (fixP->fx_done)
07855bec
NC
1853 md_number_to_chars (where, value, 2);
1854 break;
1855 case BFD_RELOC_390_GOT16:
94f592af 1856 if (fixP->fx_done)
07855bec
NC
1857 md_number_to_chars (where, value, 2);
1858 break;
1859 case BFD_RELOC_390_PC16DBL:
1860 case BFD_RELOC_390_PLT16DBL:
1861 value += 2;
94f592af 1862 if (fixP->fx_done)
07855bec
NC
1863 md_number_to_chars (where, (offsetT) value >> 1, 2);
1864 break;
1865
1866 case BFD_RELOC_32:
94f592af
NC
1867 if (fixP->fx_pcrel)
1868 fixP->fx_r_type = BFD_RELOC_32_PCREL;
07855bec 1869 else
94f592af
NC
1870 fixP->fx_r_type = BFD_RELOC_32;
1871 if (fixP->fx_done)
07855bec
NC
1872 md_number_to_chars (where, value, 4);
1873 break;
1874 case BFD_RELOC_32_PCREL:
1875 case BFD_RELOC_32_BASEREL:
94f592af
NC
1876 fixP->fx_r_type = BFD_RELOC_32_PCREL;
1877 if (fixP->fx_done)
07855bec
NC
1878 md_number_to_chars (where, value, 4);
1879 break;
1880 case BFD_RELOC_32_GOT_PCREL:
1881 case BFD_RELOC_390_PLT32:
94f592af 1882 if (fixP->fx_done)
07855bec
NC
1883 md_number_to_chars (where, value, 4);
1884 break;
1885 case BFD_RELOC_390_PC32DBL:
1886 case BFD_RELOC_390_PLT32DBL:
1887 case BFD_RELOC_390_GOTPCDBL:
1888 case BFD_RELOC_390_GOTENT:
1889 value += 2;
94f592af 1890 if (fixP->fx_done)
07855bec
NC
1891 md_number_to_chars (where, (offsetT) value >> 1, 4);
1892 break;
1893
1894 case BFD_RELOC_32_GOTOFF:
94f592af 1895 if (fixP->fx_done)
07726851 1896 md_number_to_chars (where, value, sizeof (int));
07855bec
NC
1897 break;
1898
1899 case BFD_RELOC_390_GOT64:
1900 case BFD_RELOC_390_PLT64:
94f592af 1901 if (fixP->fx_done)
07855bec
NC
1902 md_number_to_chars (where, value, 8);
1903 break;
1904
1905 case BFD_RELOC_64:
94f592af
NC
1906 if (fixP->fx_pcrel)
1907 fixP->fx_r_type = BFD_RELOC_64_PCREL;
07855bec 1908 else
94f592af
NC
1909 fixP->fx_r_type = BFD_RELOC_64;
1910 if (fixP->fx_done)
07855bec
NC
1911 md_number_to_chars (where, value, 8);
1912 break;
1913
1914 case BFD_RELOC_64_PCREL:
94f592af
NC
1915 fixP->fx_r_type = BFD_RELOC_64_PCREL;
1916 if (fixP->fx_done)
07855bec
NC
1917 md_number_to_chars (where, value, 8);
1918 break;
1919
1920 case BFD_RELOC_VTABLE_INHERIT:
1921 case BFD_RELOC_VTABLE_ENTRY:
94f592af
NC
1922 fixP->fx_done = 0;
1923 return;
07855bec
NC
1924
1925 default:
1926 {
94f592af 1927 const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
198ce79b 1928
07855bec
NC
1929 if (reloc_name != NULL)
1930 fprintf (stderr, "Gas failure, reloc type %s\n", reloc_name);
1931 else
94f592af 1932 fprintf (stderr, "Gas failure, reloc type #%i\n", fixP->fx_r_type);
07855bec
NC
1933 fflush (stderr);
1934 abort ();
1935 }
1936 }
a85d7ed0 1937
94f592af 1938 fixP->fx_offset = value;
07855bec 1939 }
a85d7ed0
NC
1940}
1941
1942/* Generate a reloc for a fixup. */
1943
1944arelent *
1945tc_gen_reloc (seg, fixp)
1946 asection *seg ATTRIBUTE_UNUSED;
1947 fixS *fixp;
1948{
1949 bfd_reloc_code_real_type code;
1950 arelent *reloc;
1951
1952 code = fixp->fx_r_type;
07855bec
NC
1953 if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
1954 {
16a419ba
NC
1955 if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
1956 || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
07855bec
NC
1957 code = BFD_RELOC_390_GOTPC;
1958 if (code == BFD_RELOC_390_PC32DBL)
1959 code = BFD_RELOC_390_GOTPCDBL;
1960 }
a85d7ed0
NC
1961
1962 reloc = (arelent *) xmalloc (sizeof (arelent));
1963 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1964 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1965 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1966 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1967 if (reloc->howto == NULL)
1968 {
1969 as_bad_where (fixp->fx_file, fixp->fx_line,
98d3f06f
KH
1970 _("cannot represent relocation type %s"),
1971 bfd_get_reloc_code_name (code));
a85d7ed0
NC
1972 /* Set howto to a garbage value so that we can keep going. */
1973 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
1974 assert (reloc->howto != NULL);
1975 }
1976 reloc->addend = fixp->fx_offset;
1977
1978 return reloc;
1979}
This page took 0.166968 seconds and 4 git commands to generate.