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