S/390: Remove optional operand flag.
[external/binutils.git] / gas / config / tc-s390.c
1 /* tc-s390.c -- Assemble for the S390
2    Copyright (C) 2000-2017 Free Software Foundation, Inc.
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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA
20    02110-1301, USA.  */
21
22 #include "as.h"
23 #include "safe-ctype.h"
24 #include "subsegs.h"
25 #include "struc-symbol.h"
26 #include "dwarf2dbg.h"
27 #include "dw2gencfi.h"
28
29 #include "opcode/s390.h"
30 #include "elf/s390.h"
31
32 /* The default architecture.  */
33 #ifndef DEFAULT_ARCH
34 #define DEFAULT_ARCH "s390"
35 #endif
36 static const char *default_arch = DEFAULT_ARCH;
37 /* Either 32 or 64, selects file format.  */
38 static int s390_arch_size = 0;
39
40 /* If no -march option was given default to the highest available CPU.
41    Since with S/390 a newer CPU always supports everything from its
42    predecessors this will accept every valid asm input.  */
43 static unsigned int current_cpu = S390_OPCODE_MAXCPU - 1;
44 /* All facilities are enabled by default.  */
45 static unsigned int current_flags = S390_INSTR_FLAG_FACILITY_MASK;
46 /* The mode mask default is picked in init_default_arch depending on
47    the current cpu.  */
48 static unsigned int current_mode_mask = 0;
49
50 /* Set to TRUE if the highgprs flag in the ELF header needs to be set
51    for the output file.  */
52 static bfd_boolean set_highgprs_p = FALSE;
53
54 /* Whether to use user friendly register names. Default is TRUE.  */
55 #ifndef TARGET_REG_NAMES_P
56 #define TARGET_REG_NAMES_P TRUE
57 #endif
58
59 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
60
61 /* Set to TRUE if we want to warn about zero base/index registers.  */
62 static bfd_boolean warn_areg_zero = FALSE;
63
64 /* Generic assembler global variables which must be defined by all
65    targets.  */
66
67 const char comment_chars[] = "#";
68
69 /* Characters which start a comment at the beginning of a line.  */
70 const char line_comment_chars[] = "#";
71
72 /* Characters which may be used to separate multiple commands on a
73    single line.  */
74 const char line_separator_chars[] = ";";
75
76 /* Characters which are used to indicate an exponent in a floating
77    point number.  */
78 const char EXP_CHARS[] = "eE";
79
80 /* Characters which mean that a number is a floating point constant,
81    as in 0d1.0.  */
82 const char FLT_CHARS[] = "dD";
83
84 /* The dwarf2 data alignment, adjusted for 32 or 64 bit.  */
85 int s390_cie_data_alignment;
86
87 /* The target specific pseudo-ops which we support.  */
88
89 /* Define the prototypes for the pseudo-ops */
90 static void s390_byte (int);
91 static void s390_elf_cons (int);
92 static void s390_bss (int);
93 static void s390_insn (int);
94 static void s390_literals (int);
95 static void s390_machine (int);
96 static void s390_machinemode (int);
97
98 const pseudo_typeS md_pseudo_table[] =
99 {
100   { "align",        s_align_bytes,      0 },
101   /* Pseudo-ops which must be defined.  */
102   { "bss",          s390_bss,           0 },
103   { "insn",         s390_insn,          0 },
104   /* Pseudo-ops which must be overridden.  */
105   { "byte",         s390_byte,          0 },
106   { "short",        s390_elf_cons,      2 },
107   { "long",         s390_elf_cons,      4 },
108   { "quad",         s390_elf_cons,      8 },
109   { "ltorg",        s390_literals,      0 },
110   { "string",       stringer,           8 + 1 },
111   { "machine",      s390_machine,       0 },
112   { "machinemode",  s390_machinemode,   0 },
113   { NULL,           NULL,               0 }
114 };
115
116 /* Given NAME, find the register number associated with that name, return
117    the integer value associated with the given name or -1 on failure.  */
118
119 static int
120 reg_name_search (const char *name)
121 {
122   int val = -1;
123
124   if (strcasecmp (name, "lit") == 0)
125     return 13;
126
127   if (strcasecmp (name, "sp") == 0)
128     return 15;
129
130   if (name[0] != 'a' && name[0] != 'c' && name[0] != 'f'
131       && name[0] != 'r' && name[0] != 'v')
132     return -1;
133
134   if (ISDIGIT (name[1]))
135     {
136       val = name[1] - '0';
137       if (ISDIGIT (name[2]))
138         val = val * 10 + name[2] - '0';
139     }
140
141   if ((name[0] != 'v' && val > 15) || val > 31)
142     val = -1;
143
144   return val;
145 }
146
147
148 /*
149  * Summary of register_name().
150  *
151  * in:  Input_line_pointer points to 1st char of operand.
152  *
153  * out: A expressionS.
154  *      The operand may have been a register: in this case, X_op == O_register,
155  *      X_add_number is set to the register number, and truth is returned.
156  *      Input_line_pointer->(next non-blank) char after operand, or is in its
157  *      original state.
158  */
159
160 static bfd_boolean
161 register_name (expressionS *expressionP)
162 {
163   int reg_number;
164   char *name;
165   char *start;
166   char c;
167
168   /* Find the spelling of the operand.  */
169   start = name = input_line_pointer;
170   if (name[0] == '%' && ISALPHA (name[1]))
171     name = ++input_line_pointer;
172   else
173     return FALSE;
174
175   c = get_symbol_name (&name);
176   reg_number = reg_name_search (name);
177
178   /* Put back the delimiting char.  */
179   (void) restore_line_pointer (c);
180
181   /* Look to see if it's in the register table.  */
182   if (reg_number >= 0)
183     {
184       expressionP->X_op = O_register;
185       expressionP->X_add_number = reg_number;
186
187       /* Make the rest nice.  */
188       expressionP->X_add_symbol = NULL;
189       expressionP->X_op_symbol = NULL;
190       return TRUE;
191     }
192
193   /* Reset the line as if we had not done anything.  */
194   input_line_pointer = start;
195   return FALSE;
196 }
197
198 /* Local variables.  */
199
200 /* Opformat hash table.  */
201 static struct hash_control *s390_opformat_hash;
202
203 /* Opcode hash table.  */
204 static struct hash_control *s390_opcode_hash = NULL;
205
206 /* Flags to set in the elf header */
207 static flagword s390_flags = 0;
208
209 symbolS *GOT_symbol;            /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
210
211 #ifndef WORKING_DOT_WORD
212 int md_short_jump_size = 4;
213 int md_long_jump_size = 4;
214 #endif
215
216 const char *md_shortopts = "A:m:kVQ:";
217 struct option md_longopts[] = {
218   {NULL, no_argument, NULL, 0}
219 };
220 size_t md_longopts_size = sizeof (md_longopts);
221
222 /* Initialize the default opcode arch and word size from the default
223    architecture name if not specified by an option.  */
224 static void
225 init_default_arch (void)
226 {
227   if (strcmp (default_arch, "s390") == 0)
228     {
229       if (s390_arch_size == 0)
230         s390_arch_size = 32;
231     }
232   else if (strcmp (default_arch, "s390x") == 0)
233     {
234       if (s390_arch_size == 0)
235         s390_arch_size = 64;
236     }
237   else
238     as_fatal (_("Invalid default architecture, broken assembler."));
239
240   if (current_mode_mask == 0)
241     {
242       /* Default to z/Architecture mode if the CPU supports it.  */
243       if (current_cpu < S390_OPCODE_Z900)
244         current_mode_mask = 1 << S390_OPCODE_ESA;
245       else
246         current_mode_mask = 1 << S390_OPCODE_ZARCH;
247     }
248 }
249
250 /* Called by TARGET_FORMAT.  */
251 const char *
252 s390_target_format (void)
253 {
254   /* We don't get a chance to initialize anything before we're called,
255      so handle that now.  */
256   init_default_arch ();
257
258   return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
259 }
260
261 /* Map a cpu string ARG as given with -march= or .machine to the respective
262    enum s390_opcode_cpu_val value.  If ALLOW_EXTENSIONS is TRUE, the cpu name
263    can be followed by a list of cpu facility flags each beginning with the
264    character '+'.  The active cpu flags are returned through *RET_FLAGS.
265    In case of an error, S390_OPCODE_MAXCPU is returned.  */
266
267 static unsigned int
268 s390_parse_cpu (const char *         arg,
269                 unsigned int * ret_flags,
270                 bfd_boolean    allow_extensions)
271 {
272   static struct
273   {
274     const char * name;
275     unsigned int name_len;
276     const char * alt_name;
277     unsigned int alt_name_len;
278     unsigned int flags;
279   } cpu_table[S390_OPCODE_MAXCPU] =
280   {
281     { STRING_COMMA_LEN ("g5"), STRING_COMMA_LEN ("arch3"), 0 },
282     { STRING_COMMA_LEN ("g6"), STRING_COMMA_LEN (""), 0 },
283     { STRING_COMMA_LEN ("z900"), STRING_COMMA_LEN ("arch5"), 0 },
284     { STRING_COMMA_LEN ("z990"), STRING_COMMA_LEN ("arch6"), 0 },
285     { STRING_COMMA_LEN ("z9-109"), STRING_COMMA_LEN (""), 0 },
286     { STRING_COMMA_LEN ("z9-ec"), STRING_COMMA_LEN ("arch7"), 0 },
287     { STRING_COMMA_LEN ("z10"), STRING_COMMA_LEN ("arch8"), 0 },
288     { STRING_COMMA_LEN ("z196"), STRING_COMMA_LEN ("arch9"), 0 },
289     { STRING_COMMA_LEN ("zEC12"), STRING_COMMA_LEN ("arch10"),
290       S390_INSTR_FLAG_HTM },
291     { STRING_COMMA_LEN ("z13"), STRING_COMMA_LEN ("arch11"),
292       S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX },
293     { STRING_COMMA_LEN ("arch12"), STRING_COMMA_LEN (""),
294       S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }
295   };
296   static struct
297   {
298     const char * name;
299     unsigned int mask;
300     bfd_boolean  on;
301   } cpu_flags[] =
302   {
303     { "htm",   S390_INSTR_FLAG_HTM, TRUE },
304     { "nohtm", S390_INSTR_FLAG_HTM, FALSE },
305     { "vx",    S390_INSTR_FLAG_VX, TRUE },
306     { "novx",  S390_INSTR_FLAG_VX, FALSE }
307   };
308   unsigned int icpu;
309   char *ilp_bak;
310
311   icpu = S390_OPCODE_MAXCPU;
312   if (strncmp (arg, "all", 3) == 0 && (arg[3] == 0 || arg[3] == '+'))
313     {
314       icpu = S390_OPCODE_MAXCPU - 1;
315       arg += 3;
316     }
317   else
318     {
319       for (icpu = 0; icpu < S390_OPCODE_MAXCPU; icpu++)
320         {
321           unsigned int l, l_alt;
322
323           l = cpu_table[icpu].name_len;
324
325           if (strncmp (arg, cpu_table[icpu].name, l) == 0
326               && (arg[l] == 0 || arg[l] == '+'))
327             {
328               arg += l;
329               break;
330             }
331
332           l_alt = cpu_table[icpu].alt_name_len;
333
334           if (l_alt > 0
335               && strncmp (arg, cpu_table[icpu].alt_name, l_alt) == 0
336               && (arg[l_alt] == 0 || arg[l_alt] == '+'))
337             {
338               arg += l_alt;
339               break;
340             }
341         }
342     }
343
344   if (icpu == S390_OPCODE_MAXCPU)
345     return S390_OPCODE_MAXCPU;
346
347   ilp_bak = input_line_pointer;
348   if (icpu != S390_OPCODE_MAXCPU)
349     {
350       input_line_pointer = (char *) arg;
351       *ret_flags = (cpu_table[icpu].flags & S390_INSTR_FLAG_FACILITY_MASK);
352
353       while (*input_line_pointer == '+' && allow_extensions)
354         {
355           unsigned int iflag;
356           char *sym;
357           char c;
358
359           input_line_pointer++;
360           c = get_symbol_name (&sym);
361           for (iflag = 0; iflag < ARRAY_SIZE (cpu_flags); iflag++)
362             {
363               if (strcmp (sym, cpu_flags[iflag].name) == 0)
364                 {
365                   if (cpu_flags[iflag].on)
366                     *ret_flags |= cpu_flags[iflag].mask;
367                   else
368                     *ret_flags &= ~cpu_flags[iflag].mask;
369                   break;
370                 }
371             }
372           if (iflag == ARRAY_SIZE (cpu_flags))
373             as_bad (_("no such machine extension `%s'"), sym - 1);
374           *input_line_pointer = c;
375           if (iflag == ARRAY_SIZE (cpu_flags))
376             break;
377         }
378     }
379
380   SKIP_WHITESPACE ();
381
382   if (*input_line_pointer != 0 && *input_line_pointer != '\n')
383     {
384       as_bad (_("junk at end of machine string, first unrecognized character"
385                 " is `%c'"), *input_line_pointer);
386       icpu = S390_OPCODE_MAXCPU;
387     }
388   input_line_pointer = ilp_bak;
389
390   return icpu;
391 }
392
393 int
394 md_parse_option (int c, const char *arg)
395 {
396   switch (c)
397     {
398       /* -k: Ignore for FreeBSD compatibility.  */
399     case 'k':
400       break;
401     case 'm':
402       if (arg != NULL && strcmp (arg, "regnames") == 0)
403         reg_names_p = TRUE;
404
405       else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
406         reg_names_p = FALSE;
407
408       else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
409         warn_areg_zero = TRUE;
410
411       else if (arg != NULL && strcmp (arg, "31") == 0)
412         s390_arch_size = 32;
413
414       else if (arg != NULL && strcmp (arg, "64") == 0)
415         s390_arch_size = 64;
416
417       else if (arg != NULL && strcmp (arg, "esa") == 0)
418         current_mode_mask = 1 << S390_OPCODE_ESA;
419
420       else if (arg != NULL && strcmp (arg, "zarch") == 0)
421         {
422           if (s390_arch_size == 32)
423             set_highgprs_p = TRUE;
424           current_mode_mask = 1 << S390_OPCODE_ZARCH;
425         }
426
427       else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
428         {
429           current_cpu = s390_parse_cpu (arg + 5, &current_flags, FALSE);
430           if (current_cpu == S390_OPCODE_MAXCPU)
431             {
432               as_bad (_("invalid switch -m%s"), arg);
433               return 0;
434             }
435         }
436
437       else
438         {
439           as_bad (_("invalid switch -m%s"), arg);
440           return 0;
441         }
442       break;
443
444     case 'A':
445       /* Option -A is deprecated. Still available for compatibility.  */
446       if (arg != NULL && strcmp (arg, "esa") == 0)
447         current_cpu = S390_OPCODE_G5;
448       else if (arg != NULL && strcmp (arg, "esame") == 0)
449         current_cpu = S390_OPCODE_Z900;
450       else
451         as_bad (_("invalid architecture -A%s"), arg);
452       break;
453
454       /* -V: SVR4 argument to print version ID.  */
455     case 'V':
456       print_version_id ();
457       break;
458
459       /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
460          should be emitted or not.  FIXME: Not implemented.  */
461     case 'Q':
462       break;
463
464     default:
465       return 0;
466     }
467
468   return 1;
469 }
470
471 void
472 md_show_usage (FILE *stream)
473 {
474   fprintf (stream, _("\
475         S390 options:\n\
476         -mregnames        Allow symbolic names for registers\n\
477         -mwarn-areg-zero  Warn about zero base/index registers\n\
478         -mno-regnames     Do not allow symbolic names for registers\n\
479         -m31              Set file format to 31 bit format\n\
480         -m64              Set file format to 64 bit format\n"));
481   fprintf (stream, _("\
482         -V                print assembler version number\n\
483         -Qy, -Qn          ignored\n"));
484 }
485
486 /* Generate the hash table mapping mnemonics to struct s390_opcode.
487    This table is built at startup and whenever the CPU level is
488    changed using .machine.  */
489
490 static void
491 s390_setup_opcodes (void)
492 {
493   const struct s390_opcode *op;
494   const struct s390_opcode *op_end;
495   bfd_boolean dup_insn = FALSE;
496   const char *retval;
497
498   if (s390_opcode_hash != NULL)
499     hash_die (s390_opcode_hash);
500
501   /* Insert the opcodes into a hash table.  */
502   s390_opcode_hash = hash_new ();
503
504   op_end = s390_opcodes + s390_num_opcodes;
505   for (op = s390_opcodes; op < op_end; op++)
506     {
507       int use_opcode;
508
509       while (op < op_end - 1 && strcmp(op->name, op[1].name) == 0)
510         {
511           if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask))
512             break;
513           op++;
514         }
515
516       if ((op->modes & current_mode_mask) == 0)
517         use_opcode = 0;
518       else if ((op->flags & S390_INSTR_FLAG_FACILITY_MASK) == 0)
519         {
520           /* Opcodes that do not belong to a specific facility are enabled if
521              present in the selected cpu.  */
522           use_opcode = (op->min_cpu <= current_cpu);
523         }
524       else
525         {
526           unsigned int f;
527
528           /* Opcodes of a specific facility are enabled if the facility is
529              enabled.  Note: only some facilities are represented as flags.  */
530           f = (op->flags & S390_INSTR_FLAG_FACILITY_MASK);
531           use_opcode = ((f & current_flags) == f);
532         }
533       if (use_opcode)
534         {
535           retval = hash_insert (s390_opcode_hash, op->name, (void *) op);
536           if (retval != (const char *) NULL)
537             {
538               as_bad (_("Internal assembler error for instruction %s"),
539                       op->name);
540               dup_insn = TRUE;
541             }
542         }
543
544       while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0)
545         op++;
546     }
547
548   if (dup_insn)
549     abort ();
550 }
551
552 /* This function is called when the assembler starts up.  It is called
553    after the options have been parsed and the output file has been
554    opened.  */
555
556 void
557 md_begin (void)
558 {
559   const struct s390_opcode *op;
560   const struct s390_opcode *op_end;
561   const char *retval;
562
563   /* Give a warning if the combination -m64-bit and -Aesa is used.  */
564   if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900)
565     as_warn (_("The 64 bit file format is used without esame instructions."));
566
567   s390_cie_data_alignment = -s390_arch_size / 8;
568
569   /* Set the ELF flags if desired.  */
570   if (s390_flags)
571     bfd_set_private_flags (stdoutput, s390_flags);
572
573   /* Insert the opcode formats into a hash table.  */
574   s390_opformat_hash = hash_new ();
575
576   op_end = s390_opformats + s390_num_opformats;
577   for (op = s390_opformats; op < op_end; op++)
578     {
579       retval = hash_insert (s390_opformat_hash, op->name, (void *) op);
580       if (retval != (const char *) NULL)
581         as_bad (_("Internal assembler error for instruction format %s"),
582                 op->name);
583     }
584
585   s390_setup_opcodes ();
586
587   record_alignment (text_section, 2);
588   record_alignment (data_section, 2);
589   record_alignment (bss_section, 2);
590 }
591
592 /* Called after all assembly has been done.  */
593 void
594 s390_md_end (void)
595 {
596   if (s390_arch_size == 64)
597     bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
598   else
599     bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
600 }
601
602 /* Insert an operand value into an instruction.  */
603
604 static void
605 s390_insert_operand (unsigned char *insn,
606                      const struct s390_operand *operand,
607                      offsetT val,
608                      const char *file,
609                      unsigned int line)
610 {
611   addressT uval;
612   int offset;
613
614   if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
615     {
616       offsetT min, max;
617
618       max = ((offsetT) 1 << (operand->bits - 1)) - 1;
619       min = - ((offsetT) 1 << (operand->bits - 1));
620       /* Halve PCREL operands.  */
621       if (operand->flags & S390_OPERAND_PCREL)
622         val >>= 1;
623       /* Check for underflow / overflow.  */
624       if (val < min || val > max)
625         {
626           const char *err =
627             _("operand out of range (%s not between %ld and %ld)");
628           char buf[100];
629
630           if (operand->flags & S390_OPERAND_PCREL)
631             {
632               val <<= 1;
633               min <<= 1;
634               max <<= 1;
635             }
636           sprint_value (buf, val);
637           if (file == (char *) NULL)
638             as_bad (err, buf, (int) min, (int) max);
639           else
640             as_bad_where (file, line, err, buf, (int) min, (int) max);
641           return;
642         }
643       /* val is ok, now restrict it to operand->bits bits.  */
644       uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
645       /* val is restrict, now check for special case.  */
646       if (operand->bits == 20 && operand->shift == 20)
647         uval = (uval >> 12) | ((uval & 0xfff) << 8);
648     }
649   else
650     {
651       addressT min, max;
652
653       max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
654       min = (offsetT) 0;
655       uval = (addressT) val;
656
657       /* Vector register operands have an additional bit in the RXB
658          field.  */
659       if (operand->flags & S390_OPERAND_VR)
660         max = (max << 1) | 1;
661
662       /* Length x in an instructions has real length x+1.  */
663       if (operand->flags & S390_OPERAND_LENGTH)
664         uval--;
665       /* Check for underflow / overflow.  */
666       if (uval < min || uval > max)
667         {
668           if (operand->flags & S390_OPERAND_LENGTH)
669             {
670               uval++;
671               min++;
672               max++;
673             }
674
675           as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line);
676
677           return;
678         }
679     }
680
681   if (operand->flags & S390_OPERAND_VR)
682     {
683       /* Insert the extra bit into the RXB field.  */
684       switch (operand->shift)
685         {
686         case 8:
687           insn[4] |= (uval & 0x10) >> 1;
688           break;
689         case 12:
690           insn[4] |= (uval & 0x10) >> 2;
691           break;
692         case 16:
693           insn[4] |= (uval & 0x10) >> 3;
694           break;
695         case 32:
696           insn[4] |= (uval & 0x10) >> 4;
697           break;
698         }
699       uval &= 0xf;
700     }
701
702   if (operand->flags & S390_OPERAND_OR1)
703     uval |= 1;
704   if (operand->flags & S390_OPERAND_OR2)
705     uval |= 2;
706   if (operand->flags & S390_OPERAND_OR8)
707     uval |= 8;
708
709   /* Duplicate the operand at bit pos 12 to 16.  */
710   if (operand->flags & S390_OPERAND_CP16)
711     {
712       /* Copy VR operand at bit pos 12 to bit pos 16.  */
713       insn[2] |= uval << 4;
714       /* Copy the flag in the RXB field.  */
715       insn[4] |= (insn[4] & 4) >> 1;
716     }
717
718   /* Insert fragments of the operand byte for byte.  */
719   offset = operand->shift + operand->bits;
720   uval <<= (-offset) & 7;
721   insn += (offset - 1) / 8;
722   while (uval != 0)
723     {
724       *insn-- |= uval;
725       uval >>= 8;
726     }
727 }
728
729 struct map_tls
730   {
731     const char *string;
732     int length;
733     bfd_reloc_code_real_type reloc;
734   };
735
736 /* Parse tls marker and return the desired relocation.  */
737 static bfd_reloc_code_real_type
738 s390_tls_suffix (char **str_p, expressionS *exp_p)
739 {
740   static struct map_tls mapping[] =
741   {
742     { "tls_load", 8, BFD_RELOC_390_TLS_LOAD },
743     { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL  },
744     { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL  },
745     { NULL,  0, BFD_RELOC_UNUSED }
746   };
747   struct map_tls *ptr;
748   char *orig_line;
749   char *str;
750   char *ident;
751   int len;
752
753   str = *str_p;
754   if (*str++ != ':')
755     return BFD_RELOC_UNUSED;
756
757   ident = str;
758   while (ISIDNUM (*str))
759     str++;
760   len = str - ident;
761   if (*str++ != ':')
762     return BFD_RELOC_UNUSED;
763
764   orig_line = input_line_pointer;
765   input_line_pointer = str;
766   expression (exp_p);
767   str = input_line_pointer;
768   if (&input_line_pointer != str_p)
769     input_line_pointer = orig_line;
770
771   if (exp_p->X_op != O_symbol)
772     return BFD_RELOC_UNUSED;
773
774   for (ptr = &mapping[0]; ptr->length > 0; ptr++)
775     if (len == ptr->length
776         && strncasecmp (ident, ptr->string, ptr->length) == 0)
777       {
778         /* Found a matching tls suffix.  */
779         *str_p = str;
780         return ptr->reloc;
781       }
782   return BFD_RELOC_UNUSED;
783 }
784
785 /* Structure used to hold suffixes.  */
786 typedef enum
787   {
788     ELF_SUFFIX_NONE = 0,
789     ELF_SUFFIX_GOT,
790     ELF_SUFFIX_PLT,
791     ELF_SUFFIX_GOTENT,
792     ELF_SUFFIX_GOTOFF,
793     ELF_SUFFIX_GOTPLT,
794     ELF_SUFFIX_PLTOFF,
795     ELF_SUFFIX_TLS_GD,
796     ELF_SUFFIX_TLS_GOTIE,
797     ELF_SUFFIX_TLS_IE,
798     ELF_SUFFIX_TLS_LDM,
799     ELF_SUFFIX_TLS_LDO,
800     ELF_SUFFIX_TLS_LE
801   }
802 elf_suffix_type;
803
804 struct map_bfd
805   {
806     const char *string;
807     int length;
808     elf_suffix_type suffix;
809   };
810
811
812 /* Parse @got/@plt/@gotoff. and return the desired relocation.  */
813 static elf_suffix_type
814 s390_elf_suffix (char **str_p, expressionS *exp_p)
815 {
816   static struct map_bfd mapping[] =
817   {
818     { "got", 3, ELF_SUFFIX_GOT  },
819     { "got12", 5, ELF_SUFFIX_GOT  },
820     { "plt", 3, ELF_SUFFIX_PLT  },
821     { "gotent", 6, ELF_SUFFIX_GOTENT },
822     { "gotoff", 6, ELF_SUFFIX_GOTOFF },
823     { "gotplt", 6, ELF_SUFFIX_GOTPLT },
824     { "pltoff", 6, ELF_SUFFIX_PLTOFF },
825     { "tlsgd", 5, ELF_SUFFIX_TLS_GD },
826     { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE },
827     { "indntpoff", 9, ELF_SUFFIX_TLS_IE },
828     { "tlsldm", 6, ELF_SUFFIX_TLS_LDM },
829     { "dtpoff", 6, ELF_SUFFIX_TLS_LDO },
830     { "ntpoff", 6, ELF_SUFFIX_TLS_LE },
831     { NULL,  0, ELF_SUFFIX_NONE }
832   };
833
834   struct map_bfd *ptr;
835   char *str = *str_p;
836   char *ident;
837   int len;
838
839   if (*str++ != '@')
840     return ELF_SUFFIX_NONE;
841
842   ident = str;
843   while (ISALNUM (*str))
844     str++;
845   len = str - ident;
846
847   for (ptr = &mapping[0]; ptr->length > 0; ptr++)
848     if (len == ptr->length
849         && strncasecmp (ident, ptr->string, ptr->length) == 0)
850       {
851         if (exp_p->X_add_number != 0)
852           as_warn (_("identifier+constant@%s means identifier@%s+constant"),
853                    ptr->string, ptr->string);
854         /* Now check for identifier@suffix+constant.  */
855         if (*str == '-' || *str == '+')
856           {
857             char *orig_line = input_line_pointer;
858             expressionS new_exp;
859
860             input_line_pointer = str;
861             expression (&new_exp);
862
863             switch (new_exp.X_op)
864               {
865               case O_constant: /* X_add_number (a constant expression).  */
866                 exp_p->X_add_number += new_exp.X_add_number;
867                 str = input_line_pointer;
868                 break;
869               case O_symbol:   /* X_add_symbol + X_add_number.  */
870                 /* this case is used for e.g. xyz@PLT+.Label.  */
871                 exp_p->X_add_number += new_exp.X_add_number;
872                 exp_p->X_op_symbol = new_exp.X_add_symbol;
873                 exp_p->X_op = O_add;
874                 str = input_line_pointer;
875                 break;
876               case O_uminus:   /* (- X_add_symbol) + X_add_number.  */
877                 /* this case is used for e.g. xyz@PLT-.Label.  */
878                 exp_p->X_add_number += new_exp.X_add_number;
879                 exp_p->X_op_symbol = new_exp.X_add_symbol;
880                 exp_p->X_op = O_subtract;
881                 str = input_line_pointer;
882                 break;
883               default:
884                 break;
885               }
886
887             /* If s390_elf_suffix has not been called with
888                &input_line_pointer as first parameter, we have
889                clobbered the input_line_pointer. We have to
890                undo that.  */
891             if (&input_line_pointer != str_p)
892               input_line_pointer = orig_line;
893           }
894         *str_p = str;
895         return ptr->suffix;
896       }
897
898   return BFD_RELOC_UNUSED;
899 }
900
901 /* Structure used to hold a literal pool entry.  */
902 struct s390_lpe
903   {
904     struct s390_lpe *next;
905     expressionS ex;
906     FLONUM_TYPE floatnum;     /* used if X_op == O_big && X_add_number <= 0 */
907     LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0  */
908     int nbytes;
909     bfd_reloc_code_real_type reloc;
910     symbolS *sym;
911   };
912
913 static struct s390_lpe *lpe_free_list = NULL;
914 static struct s390_lpe *lpe_list = NULL;
915 static struct s390_lpe *lpe_list_tail = NULL;
916 static symbolS *lp_sym = NULL;
917 static int lp_count = 0;
918 static int lpe_count = 0;
919
920 static int
921 s390_exp_compare (expressionS *exp1, expressionS *exp2)
922 {
923   if (exp1->X_op != exp2->X_op)
924     return 0;
925
926   switch (exp1->X_op)
927     {
928     case O_constant:   /* X_add_number must be equal.  */
929     case O_register:
930       return exp1->X_add_number == exp2->X_add_number;
931
932     case O_big:
933       as_bad (_("Can't handle O_big in s390_exp_compare"));
934       return 0;
935
936     case O_symbol:     /* X_add_symbol & X_add_number must be equal.  */
937     case O_symbol_rva:
938     case O_uminus:
939     case O_bit_not:
940     case O_logical_not:
941       return (exp1->X_add_symbol == exp2->X_add_symbol)
942         &&   (exp1->X_add_number == exp2->X_add_number);
943
944     case O_multiply:   /* X_add_symbol,X_op_symbol&X_add_number must be equal.  */
945     case O_divide:
946     case O_modulus:
947     case O_left_shift:
948     case O_right_shift:
949     case O_bit_inclusive_or:
950     case O_bit_or_not:
951     case O_bit_exclusive_or:
952     case O_bit_and:
953     case O_add:
954     case O_subtract:
955     case O_eq:
956     case O_ne:
957     case O_lt:
958     case O_le:
959     case O_ge:
960     case O_gt:
961     case O_logical_and:
962     case O_logical_or:
963       return (exp1->X_add_symbol == exp2->X_add_symbol)
964         &&   (exp1->X_op_symbol  == exp2->X_op_symbol)
965         &&   (exp1->X_add_number == exp2->X_add_number);
966     default:
967       return 0;
968     }
969 }
970
971 /* Test for @lit and if it's present make an entry in the literal pool and
972    modify the current expression to be an offset into the literal pool.  */
973 static elf_suffix_type
974 s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix)
975 {
976   bfd_reloc_code_real_type reloc;
977   char tmp_name[64];
978   char *str = *str_p;
979   char *ident;
980   struct s390_lpe *lpe;
981   int nbytes, len;
982
983   if (*str++ != ':')
984     return suffix;       /* No modification.  */
985
986   /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8".  */
987   ident = str;
988   while (ISALNUM (*str))
989     str++;
990   len = str - ident;
991   if (len != 4 || strncasecmp (ident, "lit", 3) != 0
992       || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
993     return suffix;      /* no modification */
994   nbytes = ident[3] - '0';
995
996   reloc = BFD_RELOC_UNUSED;
997   if (suffix == ELF_SUFFIX_GOT)
998     {
999       if (nbytes == 2)
1000         reloc = BFD_RELOC_390_GOT16;
1001       else if (nbytes == 4)
1002         reloc = BFD_RELOC_32_GOT_PCREL;
1003       else if (nbytes == 8)
1004         reloc = BFD_RELOC_390_GOT64;
1005     }
1006   else if (suffix == ELF_SUFFIX_PLT)
1007     {
1008       if (nbytes == 4)
1009         reloc = BFD_RELOC_390_PLT32;
1010       else if (nbytes == 8)
1011         reloc = BFD_RELOC_390_PLT64;
1012     }
1013
1014   if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1015     as_bad (_("Invalid suffix for literal pool entry"));
1016
1017   /* Search the pool if the new entry is a duplicate.  */
1018   if (exp_p->X_op == O_big)
1019     {
1020       /* Special processing for big numbers.  */
1021       for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
1022         {
1023           if (lpe->ex.X_op == O_big)
1024             {
1025               if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
1026                 {
1027                   if (memcmp (&generic_floating_point_number, &lpe->floatnum,
1028                               sizeof (FLONUM_TYPE)) == 0)
1029                     break;
1030                 }
1031               else if (exp_p->X_add_number == lpe->ex.X_add_number)
1032                 {
1033                   if (memcmp (generic_bignum, lpe->bignum,
1034                               sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
1035                     break;
1036                 }
1037             }
1038         }
1039     }
1040   else
1041     {
1042       /* Processing for 'normal' data types.  */
1043       for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
1044         if (lpe->nbytes == nbytes && lpe->reloc == reloc
1045             && s390_exp_compare (exp_p, &lpe->ex) != 0)
1046           break;
1047     }
1048
1049   if (lpe == NULL)
1050     {
1051       /* A new literal.  */
1052       if (lpe_free_list != NULL)
1053         {
1054           lpe = lpe_free_list;
1055           lpe_free_list = lpe_free_list->next;
1056         }
1057       else
1058         {
1059           lpe = XNEW (struct s390_lpe);
1060         }
1061
1062       lpe->ex = *exp_p;
1063
1064       if (exp_p->X_op == O_big)
1065         {
1066           if (exp_p->X_add_number <= 0)
1067             lpe->floatnum = generic_floating_point_number;
1068           else if (exp_p->X_add_number <= 4)
1069             memcpy (lpe->bignum, generic_bignum,
1070                     exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
1071           else
1072             as_bad (_("Big number is too big"));
1073         }
1074
1075       lpe->nbytes = nbytes;
1076       lpe->reloc = reloc;
1077       /* Literal pool name defined ?  */
1078       if (lp_sym == NULL)
1079         {
1080           sprintf (tmp_name, ".L\001%i", lp_count);
1081           lp_sym = symbol_make (tmp_name);
1082         }
1083
1084       /* Make name for literal pool entry.  */
1085       sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
1086       lpe_count++;
1087       lpe->sym = symbol_make (tmp_name);
1088
1089       /* Add to literal pool list.  */
1090       lpe->next = NULL;
1091       if (lpe_list_tail != NULL)
1092         {
1093           lpe_list_tail->next = lpe;
1094           lpe_list_tail = lpe;
1095         }
1096       else
1097         lpe_list = lpe_list_tail = lpe;
1098     }
1099
1100   /* Now change exp_p to the offset into the literal pool.
1101      That's the expression: .L^Ax^By-.L^Ax   */
1102   exp_p->X_add_symbol = lpe->sym;
1103   exp_p->X_op_symbol = lp_sym;
1104   exp_p->X_op = O_subtract;
1105   exp_p->X_add_number = 0;
1106
1107   *str_p = str;
1108
1109   /* We change the suffix type to ELF_SUFFIX_NONE, because
1110      the difference of two local labels is just a number.  */
1111   return ELF_SUFFIX_NONE;
1112 }
1113
1114 /* Like normal .long/.short/.word, except support @got, etc.
1115    clobbers input_line_pointer, checks end-of-line.  */
1116 static void
1117 s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */)
1118 {
1119   expressionS exp;
1120   elf_suffix_type suffix;
1121
1122   if (is_it_end_of_statement ())
1123     {
1124       demand_empty_rest_of_line ();
1125       return;
1126     }
1127
1128   do
1129     {
1130       expression (&exp);
1131
1132       if (exp.X_op == O_symbol
1133           && *input_line_pointer == '@'
1134           && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
1135         {
1136           bfd_reloc_code_real_type reloc;
1137           reloc_howto_type *reloc_howto;
1138           int size;
1139           char *where;
1140
1141           if (nbytes == 2)
1142             {
1143               static bfd_reloc_code_real_type tab2[] =
1144                 {
1145                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_NONE  */
1146                   BFD_RELOC_390_GOT16,          /* ELF_SUFFIX_GOT  */
1147                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_PLT  */
1148                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_GOTENT  */
1149                   BFD_RELOC_16_GOTOFF,          /* ELF_SUFFIX_GOTOFF  */
1150                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_GOTPLT  */
1151                   BFD_RELOC_390_PLTOFF16,       /* ELF_SUFFIX_PLTOFF  */
1152                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_TLS_GD  */
1153                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_TLS_GOTIE  */
1154                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_TLS_IE  */
1155                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_TLS_LDM  */
1156                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_TLS_LDO  */
1157                   BFD_RELOC_UNUSED              /* ELF_SUFFIX_TLS_LE  */
1158                 };
1159               reloc = tab2[suffix];
1160             }
1161           else if (nbytes == 4)
1162             {
1163               static bfd_reloc_code_real_type tab4[] =
1164                 {
1165                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_NONE  */
1166                   BFD_RELOC_32_GOT_PCREL,       /* ELF_SUFFIX_GOT  */
1167                   BFD_RELOC_390_PLT32,          /* ELF_SUFFIX_PLT  */
1168                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_GOTENT  */
1169                   BFD_RELOC_32_GOTOFF,          /* ELF_SUFFIX_GOTOFF  */
1170                   BFD_RELOC_390_GOTPLT32,       /* ELF_SUFFIX_GOTPLT  */
1171                   BFD_RELOC_390_PLTOFF32,       /* ELF_SUFFIX_PLTOFF  */
1172                   BFD_RELOC_390_TLS_GD32,       /* ELF_SUFFIX_TLS_GD  */
1173                   BFD_RELOC_390_TLS_GOTIE32,    /* ELF_SUFFIX_TLS_GOTIE  */
1174                   BFD_RELOC_390_TLS_IE32,       /* ELF_SUFFIX_TLS_IE  */
1175                   BFD_RELOC_390_TLS_LDM32,      /* ELF_SUFFIX_TLS_LDM  */
1176                   BFD_RELOC_390_TLS_LDO32,      /* ELF_SUFFIX_TLS_LDO  */
1177                   BFD_RELOC_390_TLS_LE32        /* ELF_SUFFIX_TLS_LE  */
1178                 };
1179               reloc = tab4[suffix];
1180             }
1181           else if (nbytes == 8)
1182             {
1183               static bfd_reloc_code_real_type tab8[] =
1184                 {
1185                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_NONE  */
1186                   BFD_RELOC_390_GOT64,          /* ELF_SUFFIX_GOT  */
1187                   BFD_RELOC_390_PLT64,          /* ELF_SUFFIX_PLT  */
1188                   BFD_RELOC_UNUSED,             /* ELF_SUFFIX_GOTENT  */
1189                   BFD_RELOC_390_GOTOFF64,       /* ELF_SUFFIX_GOTOFF  */
1190                   BFD_RELOC_390_GOTPLT64,       /* ELF_SUFFIX_GOTPLT  */
1191                   BFD_RELOC_390_PLTOFF64,       /* ELF_SUFFIX_PLTOFF  */
1192                   BFD_RELOC_390_TLS_GD64,       /* ELF_SUFFIX_TLS_GD  */
1193                   BFD_RELOC_390_TLS_GOTIE64,    /* ELF_SUFFIX_TLS_GOTIE  */
1194                   BFD_RELOC_390_TLS_IE64,       /* ELF_SUFFIX_TLS_IE  */
1195                   BFD_RELOC_390_TLS_LDM64,      /* ELF_SUFFIX_TLS_LDM  */
1196                   BFD_RELOC_390_TLS_LDO64,      /* ELF_SUFFIX_TLS_LDO  */
1197                   BFD_RELOC_390_TLS_LE64        /* ELF_SUFFIX_TLS_LE  */
1198                 };
1199               reloc = tab8[suffix];
1200             }
1201           else
1202             reloc = BFD_RELOC_UNUSED;
1203
1204           if (reloc != BFD_RELOC_UNUSED
1205               && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc)))
1206             {
1207               size = bfd_get_reloc_size (reloc_howto);
1208               if (size > nbytes)
1209                 as_bad (_("%s relocations do not fit in %d bytes"),
1210                         reloc_howto->name, nbytes);
1211               where = frag_more (nbytes);
1212               md_number_to_chars (where, 0, size);
1213               /* To make fixup_segment do the pc relative conversion the
1214                  pcrel parameter on the fix_new_exp call needs to be FALSE.  */
1215               fix_new_exp (frag_now, where - frag_now->fr_literal,
1216                            size, &exp, FALSE, reloc);
1217             }
1218           else
1219             as_bad (_("relocation not applicable"));
1220         }
1221       else
1222         emit_expr (&exp, (unsigned int) nbytes);
1223     }
1224   while (*input_line_pointer++ == ',');
1225
1226   input_line_pointer--;         /* Put terminator back into stream.  */
1227   demand_empty_rest_of_line ();
1228 }
1229
1230 /* We need to keep a list of fixups.  We can't simply generate them as
1231    we go, because that would require us to first create the frag, and
1232    that would screw up references to ``.''.  */
1233
1234 struct s390_fixup
1235   {
1236     expressionS exp;
1237     int opindex;
1238     bfd_reloc_code_real_type reloc;
1239   };
1240
1241 #define MAX_INSN_FIXUPS (4)
1242
1243 /* This routine is called for each instruction to be assembled.  */
1244
1245 static char *
1246 md_gather_operands (char *str,
1247                     unsigned char *insn,
1248                     const struct s390_opcode *opcode)
1249 {
1250   struct s390_fixup fixups[MAX_INSN_FIXUPS];
1251   const struct s390_operand *operand;
1252   const unsigned char *opindex_ptr;
1253   expressionS ex;
1254   elf_suffix_type suffix;
1255   bfd_reloc_code_real_type reloc;
1256   int skip_optional;
1257   char *f;
1258   int fc, i;
1259
1260   while (ISSPACE (*str))
1261     str++;
1262
1263   skip_optional = 0;
1264
1265   /* Gather the operands.  */
1266   fc = 0;
1267   for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1268     {
1269       char *hold;
1270
1271       operand = s390_operands + *opindex_ptr;
1272
1273       if ((opcode->flags & S390_INSTR_FLAG_OPTPARM) && *str == '\0')
1274         {
1275           /* Optional parameters might need to be ORed with a
1276              value so calling s390_insert_operand is needed.  */
1277           s390_insert_operand (insn, operand, 0, NULL, 0);
1278           break;
1279         }
1280
1281       if (skip_optional && (operand->flags & S390_OPERAND_INDEX))
1282         {
1283           /* We do an early skip. For D(X,B) constructions the index
1284              register is skipped (X is optional). For D(L,B) the base
1285              register will be the skipped operand, because L is NOT
1286              optional.  */
1287           skip_optional = 0;
1288           continue;
1289         }
1290
1291       /* Gather the operand.  */
1292       hold = input_line_pointer;
1293       input_line_pointer = str;
1294
1295       /* Parse the operand.  */
1296       if (! register_name (&ex))
1297         expression (&ex);
1298
1299       str = input_line_pointer;
1300       input_line_pointer = hold;
1301
1302       /* Write the operand to the insn.  */
1303       if (ex.X_op == O_illegal)
1304         as_bad (_("illegal operand"));
1305       else if (ex.X_op == O_absent)
1306         {
1307           if (opindex_ptr[0] == '\0')
1308             break;
1309           as_bad (_("missing operand"));
1310         }
1311       else if (ex.X_op == O_register || ex.X_op == O_constant)
1312         {
1313           s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
1314
1315           if (ex.X_op != O_register && ex.X_op != O_constant)
1316             {
1317               /* We need to generate a fixup for the
1318                  expression returned by s390_lit_suffix.  */
1319               if (fc >= MAX_INSN_FIXUPS)
1320                 as_fatal (_("too many fixups"));
1321               fixups[fc].exp = ex;
1322               fixups[fc].opindex = *opindex_ptr;
1323               fixups[fc].reloc = BFD_RELOC_UNUSED;
1324               ++fc;
1325             }
1326           else
1327             {
1328               if ((operand->flags & S390_OPERAND_LENGTH)
1329                   && ex.X_op != O_constant)
1330                 as_fatal (_("invalid length field specified"));
1331               if ((operand->flags & S390_OPERAND_INDEX)
1332                   && ex.X_add_number == 0
1333                   && warn_areg_zero)
1334                 as_warn (_("index register specified but zero"));
1335               if ((operand->flags & S390_OPERAND_BASE)
1336                   && ex.X_add_number == 0
1337                   && warn_areg_zero)
1338                 as_warn (_("base register specified but zero"));
1339               if ((operand->flags & S390_OPERAND_GPR)
1340                   && (operand->flags & S390_OPERAND_REG_PAIR)
1341                   && (ex.X_add_number & 1))
1342                 as_fatal (_("odd numbered general purpose register specified as "
1343                             "register pair"));
1344               if ((operand->flags & S390_OPERAND_FPR)
1345                   && (operand->flags & S390_OPERAND_REG_PAIR)
1346                   && ex.X_add_number != 0 && ex.X_add_number != 1
1347                   && ex.X_add_number != 4 && ex.X_add_number != 5
1348                   && ex.X_add_number != 8 && ex.X_add_number != 9
1349                   && ex.X_add_number != 12 && ex.X_add_number != 13)
1350                 as_fatal (_("invalid floating point register pair.  Valid fp "
1351                             "register pair operands are 0, 1, 4, 5, 8, 9, "
1352                             "12 or 13."));
1353               s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0);
1354             }
1355         }
1356       else
1357         {
1358           suffix = s390_elf_suffix (&str, &ex);
1359           suffix = s390_lit_suffix (&str, &ex, suffix);
1360           reloc = BFD_RELOC_UNUSED;
1361
1362           if (suffix == ELF_SUFFIX_GOT)
1363             {
1364               if ((operand->flags & S390_OPERAND_DISP) &&
1365                   (operand->bits == 12))
1366                 reloc = BFD_RELOC_390_GOT12;
1367               else if ((operand->flags & S390_OPERAND_DISP) &&
1368                        (operand->bits == 20))
1369                 reloc = BFD_RELOC_390_GOT20;
1370               else if ((operand->flags & S390_OPERAND_SIGNED)
1371                        && (operand->bits == 16))
1372                 reloc = BFD_RELOC_390_GOT16;
1373               else if ((operand->flags & S390_OPERAND_PCREL)
1374                        && (operand->bits == 32))
1375                 reloc = BFD_RELOC_390_GOTENT;
1376             }
1377           else if (suffix == ELF_SUFFIX_PLT)
1378             {
1379               if ((operand->flags & S390_OPERAND_PCREL)
1380                   && (operand->bits == 12))
1381                 reloc = BFD_RELOC_390_PLT12DBL;
1382               else if ((operand->flags & S390_OPERAND_PCREL)
1383                        && (operand->bits == 16))
1384                 reloc = BFD_RELOC_390_PLT16DBL;
1385               else if ((operand->flags & S390_OPERAND_PCREL)
1386                        && (operand->bits == 24))
1387                 reloc = BFD_RELOC_390_PLT24DBL;
1388               else if ((operand->flags & S390_OPERAND_PCREL)
1389                        && (operand->bits == 32))
1390                 reloc = BFD_RELOC_390_PLT32DBL;
1391             }
1392           else if (suffix == ELF_SUFFIX_GOTENT)
1393             {
1394               if ((operand->flags & S390_OPERAND_PCREL)
1395                   && (operand->bits == 32))
1396                 reloc = BFD_RELOC_390_GOTENT;
1397             }
1398           else if (suffix == ELF_SUFFIX_GOTOFF)
1399             {
1400               if ((operand->flags & S390_OPERAND_SIGNED)
1401                   && (operand->bits == 16))
1402                 reloc = BFD_RELOC_16_GOTOFF;
1403             }
1404           else if (suffix == ELF_SUFFIX_PLTOFF)
1405             {
1406               if ((operand->flags & S390_OPERAND_SIGNED)
1407                   && (operand->bits == 16))
1408                 reloc = BFD_RELOC_390_PLTOFF16;
1409             }
1410           else if (suffix == ELF_SUFFIX_GOTPLT)
1411             {
1412               if ((operand->flags & S390_OPERAND_DISP)
1413                   && (operand->bits == 12))
1414                 reloc = BFD_RELOC_390_GOTPLT12;
1415               else if ((operand->flags & S390_OPERAND_SIGNED)
1416                        && (operand->bits == 16))
1417                 reloc = BFD_RELOC_390_GOTPLT16;
1418               else if ((operand->flags & S390_OPERAND_PCREL)
1419                        && (operand->bits == 32))
1420                 reloc = BFD_RELOC_390_GOTPLTENT;
1421             }
1422           else if (suffix == ELF_SUFFIX_TLS_GOTIE)
1423             {
1424               if ((operand->flags & S390_OPERAND_DISP)
1425                   && (operand->bits == 12))
1426                 reloc = BFD_RELOC_390_TLS_GOTIE12;
1427               else if ((operand->flags & S390_OPERAND_DISP)
1428                        && (operand->bits == 20))
1429                 reloc = BFD_RELOC_390_TLS_GOTIE20;
1430             }
1431           else if (suffix == ELF_SUFFIX_TLS_IE)
1432             {
1433               if ((operand->flags & S390_OPERAND_PCREL)
1434                        && (operand->bits == 32))
1435                 reloc = BFD_RELOC_390_TLS_IEENT;
1436             }
1437
1438           if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
1439             as_bad (_("invalid operand suffix"));
1440           /* We need to generate a fixup of type 'reloc' for this
1441              expression.  */
1442           if (fc >= MAX_INSN_FIXUPS)
1443             as_fatal (_("too many fixups"));
1444           fixups[fc].exp = ex;
1445           fixups[fc].opindex = *opindex_ptr;
1446           fixups[fc].reloc = reloc;
1447           ++fc;
1448         }
1449
1450       /* Check the next character. The call to expression has advanced
1451          str past any whitespace.  */
1452       if (operand->flags & S390_OPERAND_DISP)
1453         {
1454           /* After a displacement a block in parentheses can start.  */
1455           if (*str != '(')
1456             {
1457               /* Check if parenthesized block can be skipped. If the next
1458                  operand is neither an optional operand nor a base register
1459                  then we have a syntax error.  */
1460               operand = s390_operands + *(++opindex_ptr);
1461               if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
1462                 as_bad (_("syntax error; missing '(' after displacement"));
1463
1464               /* Ok, skip all operands until S390_OPERAND_BASE.  */
1465               while (!(operand->flags & S390_OPERAND_BASE))
1466                 operand = s390_operands + *(++opindex_ptr);
1467
1468               /* If there is a next operand it must be separated by a comma.  */
1469               if (opindex_ptr[1] != '\0')
1470                 {
1471                   if (*str != ',')
1472                     {
1473                       while (opindex_ptr[1] != '\0')
1474                         {
1475                           operand = s390_operands + *(++opindex_ptr);
1476                           as_bad (_("syntax error; expected ','"));
1477                           break;
1478                         }
1479                     }
1480                   else
1481                     str++;
1482                 }
1483             }
1484           else
1485             {
1486               /* We found an opening parentheses.  */
1487               str++;
1488               for (f = str; *f != '\0'; f++)
1489                 if (*f == ',' || *f == ')')
1490                   break;
1491               /* If there is no comma until the closing parentheses OR
1492                  there is a comma right after the opening parentheses,
1493                  we have to skip optional operands.  */
1494               if (*f == ',' && f == str)
1495                 {
1496                   /* comma directly after '(' ? */
1497                   skip_optional = 1;
1498                   str++;
1499                 }
1500               else
1501                 skip_optional = (*f != ',');
1502             }
1503         }
1504       else if (operand->flags & S390_OPERAND_BASE)
1505         {
1506           /* After the base register the parenthesised block ends.  */
1507           if (*str++ != ')')
1508             as_bad (_("syntax error; missing ')' after base register"));
1509           skip_optional = 0;
1510           /* If there is a next operand it must be separated by a comma.  */
1511           if (opindex_ptr[1] != '\0')
1512             {
1513               if (*str != ',')
1514                 {
1515                   while (opindex_ptr[1] != '\0')
1516                     {
1517                       operand = s390_operands + *(++opindex_ptr);
1518                       as_bad (_("syntax error; expected ','"));
1519                       break;
1520                     }
1521                 }
1522               else
1523                 str++;
1524             }
1525         }
1526       else
1527         {
1528           /* We can find an 'early' closing parentheses in e.g. D(L) instead
1529              of D(L,B).  In this case the base register has to be skipped.  */
1530           if (*str == ')')
1531             {
1532               operand = s390_operands + *(++opindex_ptr);
1533
1534               if (!(operand->flags & S390_OPERAND_BASE))
1535                 as_bad (_("syntax error; ')' not allowed here"));
1536               str++;
1537             }
1538
1539           if ((opcode->flags & S390_INSTR_FLAG_OPTPARM) && *str == '\0')
1540             continue;
1541
1542           /* If there is a next operand it must be separated by a comma.  */
1543           if (opindex_ptr[1] != '\0')
1544             {
1545               if (*str != ',')
1546                 {
1547                   while (opindex_ptr[1] != '\0')
1548                     {
1549                       operand = s390_operands + *(++opindex_ptr);
1550                       as_bad (_("syntax error; expected ','"));
1551                       break;
1552                     }
1553                 }
1554               else
1555                 str++;
1556             }
1557         }
1558     }
1559
1560   while (ISSPACE (*str))
1561     ++str;
1562
1563   /* Check for tls instruction marker.  */
1564   reloc = s390_tls_suffix (&str, &ex);
1565   if (reloc != BFD_RELOC_UNUSED)
1566     {
1567       /* We need to generate a fixup of type 'reloc' for this
1568          instruction.  */
1569       if (fc >= MAX_INSN_FIXUPS)
1570         as_fatal (_("too many fixups"));
1571       fixups[fc].exp = ex;
1572       fixups[fc].opindex = -1;
1573       fixups[fc].reloc = reloc;
1574       ++fc;
1575     }
1576
1577   if (*str != '\0')
1578     {
1579       char *linefeed;
1580
1581       if ((linefeed = strchr (str, '\n')) != NULL)
1582         *linefeed = '\0';
1583       as_bad (_("junk at end of line: `%s'"), str);
1584       if (linefeed != NULL)
1585         *linefeed = '\n';
1586     }
1587
1588   /* Write out the instruction.  */
1589   f = frag_more (opcode->oplen);
1590   memcpy (f, insn, opcode->oplen);
1591   dwarf2_emit_insn (opcode->oplen);
1592
1593   /* Create any fixups.  At this point we do not use a
1594      bfd_reloc_code_real_type, but instead just use the
1595      BFD_RELOC_UNUSED plus the operand index.  This lets us easily
1596      handle fixups for any operand type, although that is admittedly
1597      not a very exciting feature.  We pick a BFD reloc type in
1598      md_apply_fix.  */
1599   for (i = 0; i < fc; i++)
1600     {
1601
1602       if (fixups[i].opindex < 0)
1603         {
1604           /* Create tls instruction marker relocation.  */
1605           fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen,
1606                        &fixups[i].exp, 0, fixups[i].reloc);
1607           continue;
1608         }
1609
1610       operand = s390_operands + fixups[i].opindex;
1611
1612       if (fixups[i].reloc != BFD_RELOC_UNUSED)
1613         {
1614           reloc_howto_type *reloc_howto;
1615           fixS *fixP;
1616           int size;
1617
1618           reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1619           if (!reloc_howto)
1620             abort ();
1621
1622           size = ((reloc_howto->bitsize - 1) / 8) + 1;
1623
1624           if (size < 1 || size > 4)
1625             abort ();
1626
1627           fixP = fix_new_exp (frag_now,
1628                               f - frag_now->fr_literal + (operand->shift/8),
1629                               size, &fixups[i].exp, reloc_howto->pc_relative,
1630                               fixups[i].reloc);
1631           /* Turn off overflow checking in fixup_segment. This is necessary
1632              because fixup_segment will signal an overflow for large 4 byte
1633              quantities for GOT12 relocations.  */
1634           if (   fixups[i].reloc == BFD_RELOC_390_GOT12
1635               || fixups[i].reloc == BFD_RELOC_390_GOT20
1636               || fixups[i].reloc == BFD_RELOC_390_GOT16)
1637             fixP->fx_no_overflow = 1;
1638
1639           if (operand->flags & S390_OPERAND_PCREL)
1640             fixP->fx_pcrel_adjust = operand->shift / 8;
1641         }
1642       else
1643         fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp,
1644                      (operand->flags & S390_OPERAND_PCREL) != 0,
1645                      ((bfd_reloc_code_real_type)
1646                       (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1647     }
1648   return str;
1649 }
1650
1651 /* This routine is called for each instruction to be assembled.  */
1652
1653 void
1654 md_assemble (char *str)
1655 {
1656   const struct s390_opcode *opcode;
1657   unsigned char insn[6];
1658   char *s;
1659
1660   /* Get the opcode.  */
1661   for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1662     ;
1663   if (*s != '\0')
1664     *s++ = '\0';
1665
1666   /* Look up the opcode in the hash table.  */
1667   opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str);
1668   if (opcode == (const struct s390_opcode *) NULL)
1669     {
1670       as_bad (_("Unrecognized opcode: `%s'"), str);
1671       return;
1672     }
1673   else if (!(opcode->modes & current_mode_mask))
1674     {
1675       as_bad (_("Opcode %s not available in this mode"), str);
1676       return;
1677     }
1678   memcpy (insn, opcode->opcode, sizeof (insn));
1679   md_gather_operands (s, insn, opcode);
1680 }
1681
1682 #ifndef WORKING_DOT_WORD
1683 /* Handle long and short jumps. We don't support these */
1684 void
1685 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1686      char *ptr;
1687      addressT from_addr, to_addr;
1688      fragS *frag;
1689      symbolS *to_symbol;
1690 {
1691   abort ();
1692 }
1693
1694 void
1695 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1696      char *ptr;
1697      addressT from_addr, to_addr;
1698      fragS *frag;
1699      symbolS *to_symbol;
1700 {
1701   abort ();
1702 }
1703 #endif
1704
1705 void
1706 s390_bss (int ignore ATTRIBUTE_UNUSED)
1707 {
1708   /* We don't support putting frags in the BSS segment, we fake it
1709      by marking in_bss, then looking at s_skip for clues.  */
1710
1711   subseg_set (bss_section, 0);
1712   demand_empty_rest_of_line ();
1713 }
1714
1715 /* Pseudo-op handling.  */
1716
1717 void
1718 s390_insn (int ignore ATTRIBUTE_UNUSED)
1719 {
1720   expressionS exp;
1721   const struct s390_opcode *opformat;
1722   unsigned char insn[6];
1723   char *s;
1724
1725   /* Get the opcode format.  */
1726   s = input_line_pointer;
1727   while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
1728     s++;
1729   if (*s != ',')
1730     as_bad (_("Invalid .insn format\n"));
1731   *s++ = '\0';
1732
1733   /* Look up the opcode in the hash table.  */
1734   opformat = (struct s390_opcode *)
1735     hash_find (s390_opformat_hash, input_line_pointer);
1736   if (opformat == (const struct s390_opcode *) NULL)
1737     {
1738       as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
1739       return;
1740     }
1741   input_line_pointer = s;
1742   expression (&exp);
1743   if (exp.X_op == O_constant)
1744     {
1745       if (   (   opformat->oplen == 6
1746               && (addressT) exp.X_add_number < (1ULL << 48))
1747           || (   opformat->oplen == 4
1748               && (addressT) exp.X_add_number < (1ULL << 32))
1749           || (   opformat->oplen == 2
1750               && (addressT) exp.X_add_number < (1ULL << 16)))
1751         md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen);
1752       else
1753         as_bad (_("Invalid .insn format\n"));
1754     }
1755   else if (exp.X_op == O_big)
1756     {
1757       if (exp.X_add_number > 0
1758           && opformat->oplen == 6
1759           && generic_bignum[3] == 0)
1760         {
1761           md_number_to_chars ((char *) insn, generic_bignum[2], 2);
1762           md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2);
1763           md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2);
1764         }
1765       else
1766         as_bad (_("Invalid .insn format\n"));
1767     }
1768   else
1769     as_bad (_("second operand of .insn not a constant\n"));
1770
1771   if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
1772     as_bad (_("missing comma after insn constant\n"));
1773
1774   if ((s = strchr (input_line_pointer, '\n')) != NULL)
1775     *s = '\0';
1776   input_line_pointer = md_gather_operands (input_line_pointer, insn,
1777                                            opformat);
1778   if (s != NULL)
1779     *s = '\n';
1780   demand_empty_rest_of_line ();
1781 }
1782
1783 /* The .byte pseudo-op.  This is similar to the normal .byte
1784    pseudo-op, but it can also take a single ASCII string.  */
1785
1786 static void
1787 s390_byte (int ignore ATTRIBUTE_UNUSED)
1788 {
1789   if (*input_line_pointer != '\"')
1790     {
1791       cons (1);
1792       return;
1793     }
1794
1795   /* Gather characters.  A real double quote is doubled.  Unusual
1796      characters are not permitted.  */
1797   ++input_line_pointer;
1798   while (1)
1799     {
1800       char c;
1801
1802       c = *input_line_pointer++;
1803
1804       if (c == '\"')
1805         {
1806           if (*input_line_pointer != '\"')
1807             break;
1808           ++input_line_pointer;
1809         }
1810
1811       FRAG_APPEND_1_CHAR (c);
1812     }
1813
1814   demand_empty_rest_of_line ();
1815 }
1816
1817 /* The .ltorg pseudo-op.This emits all literals defined since the last
1818    .ltorg or the invocation of gas. Literals are defined with the
1819    @lit suffix.  */
1820
1821 static void
1822 s390_literals (int ignore ATTRIBUTE_UNUSED)
1823 {
1824   struct s390_lpe *lpe;
1825
1826   if (lp_sym == NULL || lpe_count == 0)
1827     return;     /* Nothing to be done.  */
1828
1829   /* Emit symbol for start of literal pool.  */
1830   S_SET_SEGMENT (lp_sym, now_seg);
1831   S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
1832   lp_sym->sy_frag = frag_now;
1833
1834   while (lpe_list)
1835     {
1836       lpe = lpe_list;
1837       lpe_list = lpe_list->next;
1838       S_SET_SEGMENT (lpe->sym, now_seg);
1839       S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
1840       lpe->sym->sy_frag = frag_now;
1841
1842       /* Emit literal pool entry.  */
1843       if (lpe->reloc != BFD_RELOC_UNUSED)
1844         {
1845           reloc_howto_type *reloc_howto =
1846             bfd_reloc_type_lookup (stdoutput, lpe->reloc);
1847           int size = bfd_get_reloc_size (reloc_howto);
1848           char *where;
1849
1850           if (size > lpe->nbytes)
1851             as_bad (_("%s relocations do not fit in %d bytes"),
1852                     reloc_howto->name, lpe->nbytes);
1853           where = frag_more (lpe->nbytes);
1854           md_number_to_chars (where, 0, size);
1855           fix_new_exp (frag_now, where - frag_now->fr_literal,
1856                        size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
1857         }
1858       else
1859         {
1860           if (lpe->ex.X_op == O_big)
1861             {
1862               if (lpe->ex.X_add_number <= 0)
1863                 generic_floating_point_number = lpe->floatnum;
1864               else
1865                 memcpy (generic_bignum, lpe->bignum,
1866                         lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
1867             }
1868           emit_expr (&lpe->ex, lpe->nbytes);
1869         }
1870
1871       lpe->next = lpe_free_list;
1872       lpe_free_list = lpe;
1873     }
1874   lpe_list_tail = NULL;
1875   lp_sym = NULL;
1876   lp_count++;
1877   lpe_count = 0;
1878 }
1879
1880 #define MAX_HISTORY 100
1881
1882 /* The .machine pseudo op allows to switch to a different CPU level in
1883    the asm listing.  The current CPU setting can be stored on a stack
1884    with .machine push and restored with .machine pop.  */
1885
1886 static void
1887 s390_machine (int ignore ATTRIBUTE_UNUSED)
1888 {
1889   char *cpu_string;
1890   static struct cpu_history
1891   {
1892     unsigned int cpu;
1893     unsigned int flags;
1894   } *cpu_history;
1895   static int curr_hist;
1896
1897   SKIP_WHITESPACE ();
1898
1899   if (*input_line_pointer == '"')
1900     {
1901       int len;
1902       cpu_string = demand_copy_C_string (&len);
1903     }
1904   else
1905     {
1906       char c;
1907
1908       cpu_string = input_line_pointer;
1909       do
1910         {
1911           char * str;
1912
1913           c = get_symbol_name (&str);
1914           c = restore_line_pointer (c);
1915           if (c == '+')
1916             ++ input_line_pointer;
1917         }
1918       while (c == '+');
1919
1920       c = *input_line_pointer;
1921       *input_line_pointer = 0;
1922       cpu_string = xstrdup (cpu_string);
1923       (void) restore_line_pointer (c);
1924     }
1925
1926   if (cpu_string != NULL)
1927     {
1928       unsigned int new_cpu = current_cpu;
1929       unsigned int new_flags = current_flags;
1930
1931       if (strcmp (cpu_string, "push") == 0)
1932         {
1933           if (cpu_history == NULL)
1934             cpu_history = XNEWVEC (struct cpu_history, MAX_HISTORY);
1935
1936           if (curr_hist >= MAX_HISTORY)
1937             as_bad (_(".machine stack overflow"));
1938           else
1939             {
1940               cpu_history[curr_hist].cpu = current_cpu;
1941               cpu_history[curr_hist].flags = current_flags;
1942               curr_hist++;
1943             }
1944         }
1945       else if (strcmp (cpu_string, "pop") == 0)
1946         {
1947           if (curr_hist <= 0)
1948             as_bad (_(".machine stack underflow"));
1949           else
1950             {
1951               curr_hist--;
1952               new_cpu = cpu_history[curr_hist].cpu;
1953               new_flags = cpu_history[curr_hist].flags;
1954             }
1955         }
1956       else
1957         new_cpu = s390_parse_cpu (cpu_string, &new_flags, TRUE);
1958
1959       if (new_cpu == S390_OPCODE_MAXCPU)
1960         as_bad (_("invalid machine `%s'"), cpu_string);
1961
1962       if (new_cpu != current_cpu || new_flags != current_flags)
1963         {
1964           current_cpu = new_cpu;
1965           current_flags = new_flags;
1966           s390_setup_opcodes ();
1967         }
1968     }
1969
1970   demand_empty_rest_of_line ();
1971 }
1972
1973 /* The .machinemode pseudo op allows to switch to a different
1974    architecture mode in the asm listing.  The current architecture
1975    mode setting can be stored on a stack with .machinemode push and
1976    restored with .machinemode pop.  */
1977
1978 static void
1979 s390_machinemode (int ignore ATTRIBUTE_UNUSED)
1980 {
1981   char *mode_string;
1982   static unsigned int *mode_history;
1983   static int curr_hist;
1984
1985   SKIP_WHITESPACE ();
1986
1987   {
1988     char c;
1989
1990     c = get_symbol_name (&mode_string);
1991     mode_string = xstrdup (mode_string);
1992     (void) restore_line_pointer (c);
1993   }
1994
1995   if (mode_string != NULL)
1996     {
1997       unsigned int old_mode_mask = current_mode_mask;
1998       char *p;
1999
2000       for (p = mode_string; *p != 0; p++)
2001         *p = TOLOWER (*p);
2002
2003       if (strcmp (mode_string, "push") == 0)
2004         {
2005           if (mode_history == NULL)
2006             mode_history = XNEWVEC (unsigned int, MAX_HISTORY);
2007
2008           if (curr_hist >= MAX_HISTORY)
2009             as_bad (_(".machinemode stack overflow"));
2010           else
2011             mode_history[curr_hist++] = current_mode_mask;
2012         }
2013       else if (strcmp (mode_string, "pop") == 0)
2014         {
2015           if (curr_hist <= 0)
2016             as_bad (_(".machinemode stack underflow"));
2017           else
2018             current_mode_mask = mode_history[--curr_hist];
2019         }
2020       else
2021         {
2022           if (strcmp (mode_string, "esa") == 0)
2023             current_mode_mask = 1 << S390_OPCODE_ESA;
2024           else if (strcmp (mode_string, "zarch") == 0)
2025             {
2026               if (s390_arch_size == 32)
2027                 set_highgprs_p = TRUE;
2028               current_mode_mask = 1 << S390_OPCODE_ZARCH;
2029             }
2030           else if (strcmp (mode_string, "zarch_nohighgprs") == 0)
2031             current_mode_mask = 1 << S390_OPCODE_ZARCH;
2032           else
2033             as_bad (_("invalid machine mode `%s'"), mode_string);
2034         }
2035
2036       if (current_mode_mask != old_mode_mask)
2037         s390_setup_opcodes ();
2038     }
2039
2040   demand_empty_rest_of_line ();
2041 }
2042
2043 #undef MAX_HISTORY
2044
2045 const char *
2046 md_atof (int type, char *litp, int *sizep)
2047 {
2048   return ieee_md_atof (type, litp, sizep, TRUE);
2049 }
2050
2051 /* Align a section (I don't know why this is machine dependent).  */
2052
2053 valueT
2054 md_section_align (asection *seg, valueT addr)
2055 {
2056   int align = bfd_get_section_alignment (stdoutput, seg);
2057
2058   return ((addr + (1 << align) - 1) & -(1 << align));
2059 }
2060
2061 /* We don't have any form of relaxing.  */
2062
2063 int
2064 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
2065                                asection *seg ATTRIBUTE_UNUSED)
2066 {
2067   abort ();
2068   return 0;
2069 }
2070
2071 /* Convert a machine dependent frag.  We never generate these.  */
2072
2073 void
2074 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
2075                  asection *sec ATTRIBUTE_UNUSED,
2076                  fragS *fragp ATTRIBUTE_UNUSED)
2077 {
2078   abort ();
2079 }
2080
2081 symbolS *
2082 md_undefined_symbol (char *name)
2083 {
2084   if (*name == '_' && *(name + 1) == 'G'
2085       && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
2086     {
2087       if (!GOT_symbol)
2088         {
2089           if (symbol_find (name))
2090             as_bad (_("GOT already in symbol table"));
2091           GOT_symbol = symbol_new (name, undefined_section,
2092                                    (valueT) 0, &zero_address_frag);
2093         }
2094       return GOT_symbol;
2095     }
2096   return 0;
2097 }
2098
2099 /* Functions concerning relocs.  */
2100
2101 /* The location from which a PC relative jump should be calculated,
2102    given a PC relative reloc.  */
2103
2104 long
2105 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
2106 {
2107   return fixp->fx_frag->fr_address + fixp->fx_where;
2108 }
2109
2110 /* Here we decide which fixups can be adjusted to make them relative to
2111    the beginning of the section instead of the symbol.  Basically we need
2112    to make sure that the dynamic relocations are done correctly, so in
2113    some cases we force the original symbol to be used.  */
2114 int
2115 tc_s390_fix_adjustable (fixS *fixP)
2116 {
2117   /* Don't adjust pc-relative references to merge sections.  */
2118   if (fixP->fx_pcrel
2119       && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0)
2120     return 0;
2121
2122   /* adjust_reloc_syms doesn't know about the GOT.  */
2123   if (   fixP->fx_r_type == BFD_RELOC_16_GOTOFF
2124       || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
2125       || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64
2126       || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16
2127       || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32
2128       || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64
2129       || fixP->fx_r_type == BFD_RELOC_390_PLT12DBL
2130       || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
2131       || fixP->fx_r_type == BFD_RELOC_390_PLT24DBL
2132       || fixP->fx_r_type == BFD_RELOC_390_PLT32
2133       || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
2134       || fixP->fx_r_type == BFD_RELOC_390_PLT64
2135       || fixP->fx_r_type == BFD_RELOC_390_GOT12
2136       || fixP->fx_r_type == BFD_RELOC_390_GOT20
2137       || fixP->fx_r_type == BFD_RELOC_390_GOT16
2138       || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
2139       || fixP->fx_r_type == BFD_RELOC_390_GOT64
2140       || fixP->fx_r_type == BFD_RELOC_390_GOTENT
2141       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
2142       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16
2143       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20
2144       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32
2145       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64
2146       || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT
2147       || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD
2148       || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL
2149       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL
2150       || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32
2151       || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64
2152       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12
2153       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20
2154       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32
2155       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64
2156       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32
2157       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64
2158       || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32
2159       || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64
2160       || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT
2161       || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32
2162       || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64
2163       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32
2164       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64
2165       || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD
2166       || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF
2167       || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF
2168       || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2169       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2170     return 0;
2171   return 1;
2172 }
2173
2174 /* Return true if we must always emit a reloc for a type and false if
2175    there is some hope of resolving it at assembly time.  */
2176 int
2177 tc_s390_force_relocation (struct fix *fixp)
2178 {
2179   /* Ensure we emit a relocation for every reference to the global
2180      offset table or to the procedure link table.  */
2181   switch (fixp->fx_r_type)
2182     {
2183     case BFD_RELOC_390_GOT12:
2184     case BFD_RELOC_390_GOT20:
2185     case BFD_RELOC_32_GOT_PCREL:
2186     case BFD_RELOC_32_GOTOFF:
2187     case BFD_RELOC_390_GOTOFF64:
2188     case BFD_RELOC_390_PLTOFF16:
2189     case BFD_RELOC_390_PLTOFF32:
2190     case BFD_RELOC_390_PLTOFF64:
2191     case BFD_RELOC_390_GOTPC:
2192     case BFD_RELOC_390_GOT16:
2193     case BFD_RELOC_390_GOTPCDBL:
2194     case BFD_RELOC_390_GOT64:
2195     case BFD_RELOC_390_GOTENT:
2196     case BFD_RELOC_390_PLT32:
2197     case BFD_RELOC_390_PLT12DBL:
2198     case BFD_RELOC_390_PLT16DBL:
2199     case BFD_RELOC_390_PLT24DBL:
2200     case BFD_RELOC_390_PLT32DBL:
2201     case BFD_RELOC_390_PLT64:
2202     case BFD_RELOC_390_GOTPLT12:
2203     case BFD_RELOC_390_GOTPLT16:
2204     case BFD_RELOC_390_GOTPLT20:
2205     case BFD_RELOC_390_GOTPLT32:
2206     case BFD_RELOC_390_GOTPLT64:
2207     case BFD_RELOC_390_GOTPLTENT:
2208       return 1;
2209     default:
2210       break;
2211     }
2212
2213   return generic_force_reloc (fixp);
2214 }
2215
2216 /* Apply a fixup to the object code.  This is called for all the
2217    fixups we generated by the call to fix_new_exp, above.  In the call
2218    above we used a reloc code which was the largest legal reloc code
2219    plus the operand index.  Here we undo that to recover the operand
2220    index.  At this point all symbol values should be fully resolved,
2221    and we attempt to completely resolve the reloc.  If we can not do
2222    that, we determine the correct reloc code and put it back in the
2223    fixup.  */
2224
2225 void
2226 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
2227 {
2228   char *where;
2229   valueT value = *valP;
2230
2231   where = fixP->fx_frag->fr_literal + fixP->fx_where;
2232
2233   if (fixP->fx_subsy != NULL)
2234     as_bad_where (fixP->fx_file, fixP->fx_line,
2235                   _("cannot emit relocation %s against subsy symbol %s"),
2236                   bfd_get_reloc_code_name (fixP->fx_r_type),
2237                   S_GET_NAME (fixP->fx_subsy));
2238
2239   if (fixP->fx_addsy != NULL)
2240     {
2241       if (fixP->fx_pcrel)
2242         value += fixP->fx_frag->fr_address + fixP->fx_where;
2243     }
2244   else
2245     fixP->fx_done = 1;
2246
2247   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
2248     {
2249       const struct s390_operand *operand;
2250       int opindex;
2251
2252       opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
2253       operand = &s390_operands[opindex];
2254
2255       if (fixP->fx_done)
2256         {
2257           /* Insert the fully resolved operand value.  */
2258           s390_insert_operand ((unsigned char *) where, operand,
2259                                (offsetT) value, fixP->fx_file, fixP->fx_line);
2260           return;
2261         }
2262
2263       /* Determine a BFD reloc value based on the operand information.
2264          We are only prepared to turn a few of the operands into
2265          relocs.  */
2266       fixP->fx_offset = value;
2267       if (operand->bits == 12 && operand->shift == 20)
2268         {
2269           fixP->fx_size = 2;
2270           fixP->fx_where += 2;
2271           fixP->fx_r_type = BFD_RELOC_390_12;
2272         }
2273       else if (operand->bits == 12 && operand->shift == 36)
2274         {
2275           fixP->fx_size = 2;
2276           fixP->fx_where += 4;
2277           fixP->fx_r_type = BFD_RELOC_390_12;
2278         }
2279       else if (operand->bits == 20 && operand->shift == 20)
2280         {
2281           fixP->fx_size = 2;
2282           fixP->fx_where += 2;
2283           fixP->fx_r_type = BFD_RELOC_390_20;
2284         }
2285       else if (operand->bits == 8 && operand->shift == 8)
2286         {
2287           fixP->fx_size = 1;
2288           fixP->fx_where += 1;
2289           fixP->fx_r_type = BFD_RELOC_8;
2290         }
2291       else if (operand->bits == 12 && operand->shift == 12
2292                && (operand->flags & S390_OPERAND_PCREL))
2293         {
2294           fixP->fx_size = 2;
2295           fixP->fx_where += 1;
2296           fixP->fx_offset += 1;
2297           fixP->fx_pcrel_adjust = 1;
2298           fixP->fx_r_type = BFD_RELOC_390_PC12DBL;
2299         }
2300       else if (operand->bits == 16 && operand->shift == 16)
2301         {
2302           fixP->fx_size = 2;
2303           fixP->fx_where += 2;
2304           if (operand->flags & S390_OPERAND_PCREL)
2305             {
2306               fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2307               fixP->fx_offset += 2;
2308               fixP->fx_pcrel_adjust = 2;
2309             }
2310           else
2311             fixP->fx_r_type = BFD_RELOC_16;
2312         }
2313       else if (operand->bits == 16 && operand->shift == 32
2314                && (operand->flags & S390_OPERAND_PCREL))
2315         {
2316           fixP->fx_size = 2;
2317           fixP->fx_where += 4;
2318           fixP->fx_offset += 4;
2319           fixP->fx_pcrel_adjust = 4;
2320           fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
2321         }
2322       else if (operand->bits == 24 && operand->shift == 24
2323                && (operand->flags & S390_OPERAND_PCREL))
2324         {
2325           fixP->fx_size = 3;
2326           fixP->fx_where += 3;
2327           fixP->fx_offset += 3;
2328           fixP->fx_pcrel_adjust = 3;
2329           fixP->fx_r_type = BFD_RELOC_390_PC24DBL;
2330         }
2331       else if (operand->bits == 32 && operand->shift == 16
2332                && (operand->flags & S390_OPERAND_PCREL))
2333         {
2334           fixP->fx_size = 4;
2335           fixP->fx_where += 2;
2336           fixP->fx_offset += 2;
2337           fixP->fx_pcrel_adjust = 2;
2338           fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
2339         }
2340       else
2341         {
2342           const char *sfile;
2343           unsigned int sline;
2344
2345           /* Use expr_symbol_where to see if this is an expression
2346              symbol.  */
2347           if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
2348             as_bad_where (fixP->fx_file, fixP->fx_line,
2349                           _("unresolved expression that must be resolved"));
2350           else
2351             as_bad_where (fixP->fx_file, fixP->fx_line,
2352                           _("unsupported relocation type"));
2353           fixP->fx_done = 1;
2354           return;
2355         }
2356     }
2357   else
2358     {
2359       switch (fixP->fx_r_type)
2360         {
2361         case BFD_RELOC_8:
2362           if (fixP->fx_pcrel)
2363             abort ();
2364           if (fixP->fx_done)
2365             md_number_to_chars (where, value, 1);
2366           break;
2367         case BFD_RELOC_390_12:
2368         case BFD_RELOC_390_GOT12:
2369         case BFD_RELOC_390_GOTPLT12:
2370         case BFD_RELOC_390_PC12DBL:
2371         case BFD_RELOC_390_PLT12DBL:
2372           if (fixP->fx_pcrel)
2373             value += fixP->fx_pcrel_adjust;
2374
2375           if (fixP->fx_done)
2376             {
2377               unsigned short mop;
2378
2379               if (fixP->fx_pcrel)
2380                 value >>= 1;
2381
2382               mop = bfd_getb16 ((unsigned char *) where);
2383               mop |= (unsigned short) (value & 0xfff);
2384               bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
2385             }
2386           break;
2387
2388         case BFD_RELOC_390_20:
2389         case BFD_RELOC_390_GOT20:
2390         case BFD_RELOC_390_GOTPLT20:
2391           if (fixP->fx_done)
2392             {
2393               unsigned int mop;
2394               mop = bfd_getb32 ((unsigned char *) where);
2395               mop |= (unsigned int) ((value & 0xfff) << 8 |
2396                                      (value & 0xff000) >> 12);
2397               bfd_putb32 ((bfd_vma) mop, (unsigned char *) where);
2398             }
2399           break;
2400
2401         case BFD_RELOC_16:
2402         case BFD_RELOC_GPREL16:
2403         case BFD_RELOC_16_GOT_PCREL:
2404         case BFD_RELOC_16_GOTOFF:
2405           if (fixP->fx_pcrel)
2406             as_bad_where (fixP->fx_file, fixP->fx_line,
2407                           _("cannot emit PC relative %s relocation%s%s"),
2408                           bfd_get_reloc_code_name (fixP->fx_r_type),
2409                           fixP->fx_addsy != NULL ? " against " : "",
2410                           (fixP->fx_addsy != NULL
2411                            ? S_GET_NAME (fixP->fx_addsy)
2412                            : ""));
2413           if (fixP->fx_done)
2414             md_number_to_chars (where, value, 2);
2415           break;
2416         case BFD_RELOC_390_GOT16:
2417         case BFD_RELOC_390_PLTOFF16:
2418         case BFD_RELOC_390_GOTPLT16:
2419           if (fixP->fx_done)
2420             md_number_to_chars (where, value, 2);
2421           break;
2422         case BFD_RELOC_390_PC16DBL:
2423         case BFD_RELOC_390_PLT16DBL:
2424           value += fixP->fx_pcrel_adjust;
2425           if (fixP->fx_done)
2426             md_number_to_chars (where, (offsetT) value >> 1, 2);
2427           break;
2428
2429         case BFD_RELOC_390_PC24DBL:
2430         case BFD_RELOC_390_PLT24DBL:
2431           value += fixP->fx_pcrel_adjust;
2432           if (fixP->fx_done)
2433             {
2434               unsigned int mop;
2435               value >>= 1;
2436
2437               mop = bfd_getb32 ((unsigned char *) where - 1);
2438               mop |= (unsigned int) (value & 0xffffff);
2439               bfd_putb32 ((bfd_vma) mop, (unsigned char *) where - 1);
2440             }
2441           break;
2442
2443         case BFD_RELOC_32:
2444           if (fixP->fx_pcrel)
2445             fixP->fx_r_type = BFD_RELOC_32_PCREL;
2446           else
2447             fixP->fx_r_type = BFD_RELOC_32;
2448           if (fixP->fx_done)
2449             md_number_to_chars (where, value, 4);
2450           break;
2451         case BFD_RELOC_32_PCREL:
2452         case BFD_RELOC_32_BASEREL:
2453           fixP->fx_r_type = BFD_RELOC_32_PCREL;
2454           if (fixP->fx_done)
2455             md_number_to_chars (where, value, 4);
2456           break;
2457         case BFD_RELOC_32_GOT_PCREL:
2458         case BFD_RELOC_390_PLTOFF32:
2459         case BFD_RELOC_390_PLT32:
2460         case BFD_RELOC_390_GOTPLT32:
2461           if (fixP->fx_done)
2462             md_number_to_chars (where, value, 4);
2463           break;
2464         case BFD_RELOC_390_PC32DBL:
2465         case BFD_RELOC_390_PLT32DBL:
2466         case BFD_RELOC_390_GOTPCDBL:
2467         case BFD_RELOC_390_GOTENT:
2468         case BFD_RELOC_390_GOTPLTENT:
2469           value += fixP->fx_pcrel_adjust;
2470           if (fixP->fx_done)
2471             md_number_to_chars (where, (offsetT) value >> 1, 4);
2472           break;
2473
2474         case BFD_RELOC_32_GOTOFF:
2475           if (fixP->fx_done)
2476             md_number_to_chars (where, value, sizeof (int));
2477           break;
2478
2479         case BFD_RELOC_390_GOTOFF64:
2480           if (fixP->fx_done)
2481             md_number_to_chars (where, value, 8);
2482           break;
2483
2484         case BFD_RELOC_390_GOT64:
2485         case BFD_RELOC_390_PLTOFF64:
2486         case BFD_RELOC_390_PLT64:
2487         case BFD_RELOC_390_GOTPLT64:
2488           if (fixP->fx_done)
2489             md_number_to_chars (where, value, 8);
2490           break;
2491
2492         case BFD_RELOC_64:
2493           if (fixP->fx_pcrel)
2494             fixP->fx_r_type = BFD_RELOC_64_PCREL;
2495           else
2496             fixP->fx_r_type = BFD_RELOC_64;
2497           if (fixP->fx_done)
2498             md_number_to_chars (where, value, 8);
2499           break;
2500
2501         case BFD_RELOC_64_PCREL:
2502           fixP->fx_r_type = BFD_RELOC_64_PCREL;
2503           if (fixP->fx_done)
2504             md_number_to_chars (where, value, 8);
2505           break;
2506
2507         case BFD_RELOC_VTABLE_INHERIT:
2508         case BFD_RELOC_VTABLE_ENTRY:
2509           fixP->fx_done = 0;
2510           return;
2511
2512         case BFD_RELOC_390_TLS_LOAD:
2513         case BFD_RELOC_390_TLS_GDCALL:
2514         case BFD_RELOC_390_TLS_LDCALL:
2515         case BFD_RELOC_390_TLS_GD32:
2516         case BFD_RELOC_390_TLS_GD64:
2517         case BFD_RELOC_390_TLS_GOTIE12:
2518         case BFD_RELOC_390_TLS_GOTIE20:
2519         case BFD_RELOC_390_TLS_GOTIE32:
2520         case BFD_RELOC_390_TLS_GOTIE64:
2521         case BFD_RELOC_390_TLS_LDM32:
2522         case BFD_RELOC_390_TLS_LDM64:
2523         case BFD_RELOC_390_TLS_IE32:
2524         case BFD_RELOC_390_TLS_IE64:
2525         case BFD_RELOC_390_TLS_LE32:
2526         case BFD_RELOC_390_TLS_LE64:
2527         case BFD_RELOC_390_TLS_LDO32:
2528         case BFD_RELOC_390_TLS_LDO64:
2529         case BFD_RELOC_390_TLS_DTPMOD:
2530         case BFD_RELOC_390_TLS_DTPOFF:
2531         case BFD_RELOC_390_TLS_TPOFF:
2532           S_SET_THREAD_LOCAL (fixP->fx_addsy);
2533           /* Fully resolved at link time.  */
2534           break;
2535         case BFD_RELOC_390_TLS_IEENT:
2536           /* Fully resolved at link time.  */
2537           S_SET_THREAD_LOCAL (fixP->fx_addsy);
2538           value += 2;
2539           break;
2540
2541         default:
2542           {
2543             const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
2544
2545             if (reloc_name != NULL)
2546               as_fatal (_("Gas failure, reloc type %s\n"), reloc_name);
2547             else
2548               as_fatal (_("Gas failure, reloc type #%i\n"), fixP->fx_r_type);
2549           }
2550         }
2551
2552       fixP->fx_offset = value;
2553     }
2554 }
2555
2556 /* Generate a reloc for a fixup.  */
2557
2558 arelent *
2559 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
2560 {
2561   bfd_reloc_code_real_type code;
2562   arelent *reloc;
2563
2564   code = fixp->fx_r_type;
2565   if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
2566     {
2567       if (   (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
2568           || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
2569         code = BFD_RELOC_390_GOTPC;
2570       if (code == BFD_RELOC_390_PC32DBL)
2571         code = BFD_RELOC_390_GOTPCDBL;
2572     }
2573
2574   reloc = XNEW (arelent);
2575   reloc->sym_ptr_ptr = XNEW (asymbol *);
2576   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2577   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2578   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2579   if (reloc->howto == NULL)
2580     {
2581       as_bad_where (fixp->fx_file, fixp->fx_line,
2582                     _("cannot represent relocation type %s"),
2583                     bfd_get_reloc_code_name (code));
2584       /* Set howto to a garbage value so that we can keep going.  */
2585       reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2586       gas_assert (reloc->howto != NULL);
2587     }
2588   reloc->addend = fixp->fx_offset;
2589
2590   return reloc;
2591 }
2592
2593 void
2594 s390_cfi_frame_initial_instructions (void)
2595 {
2596   cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96);
2597 }
2598
2599 int
2600 tc_s390_regname_to_dw2regnum (char *regname)
2601 {
2602   int regnum = -1;
2603
2604   if (regname[0] != 'c' && regname[0] != 'a')
2605     {
2606       regnum = reg_name_search (regname);
2607       if (regname[0] == 'f' && regnum != -1)
2608         regnum += 16;
2609     }
2610   else if (strcmp (regname, "ap") == 0)
2611     regnum = 32;
2612   else if (strcmp (regname, "cc") == 0)
2613     regnum = 33;
2614   return regnum;
2615 }
2616
2617 void
2618 s390_elf_final_processing (void)
2619 {
2620   if (set_highgprs_p)
2621     elf_elfheader (stdoutput)->e_flags |= EF_S390_HIGH_GPRS;
2622 }