Back to index

cell-binutils  2.17cvs20070401
tc-s390.c
Go to the documentation of this file.
00001 /* tc-s390.c -- Assemble for the S390
00002    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006
00003    Free Software Foundation, Inc.
00004    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
00005 
00006    This file is part of GAS, the GNU Assembler.
00007 
00008    GAS is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    GAS is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with GAS; see the file COPYING.  If not, write to the Free
00020    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 #include "as.h"
00024 #include "safe-ctype.h"
00025 #include "subsegs.h"
00026 #include "struc-symbol.h"
00027 #include "dwarf2dbg.h"
00028 #include "dw2gencfi.h"
00029 
00030 #include "opcode/s390.h"
00031 #include "elf/s390.h"
00032 
00033 /* The default architecture.  */
00034 #ifndef DEFAULT_ARCH
00035 #define DEFAULT_ARCH "s390"
00036 #endif
00037 static char *default_arch = DEFAULT_ARCH;
00038 /* Either 32 or 64, selects file format.  */
00039 static int s390_arch_size = 0;
00040 
00041 static unsigned int current_mode_mask = 0;
00042 static unsigned int current_cpu = -1U;
00043 
00044 /* Whether to use user friendly register names. Default is TRUE.  */
00045 #ifndef TARGET_REG_NAMES_P
00046 #define TARGET_REG_NAMES_P TRUE
00047 #endif
00048 
00049 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
00050 
00051 /* Set to TRUE if we want to warn about zero base/index registers.  */
00052 static bfd_boolean warn_areg_zero = FALSE;
00053 
00054 /* Generic assembler global variables which must be defined by all
00055    targets.  */
00056 
00057 const char comment_chars[] = "#";
00058 
00059 /* Characters which start a comment at the beginning of a line.  */
00060 const char line_comment_chars[] = "#";
00061 
00062 /* Characters which may be used to separate multiple commands on a
00063    single line.  */
00064 const char line_separator_chars[] = ";";
00065 
00066 /* Characters which are used to indicate an exponent in a floating
00067    point number.  */
00068 const char EXP_CHARS[] = "eE";
00069 
00070 /* Characters which mean that a number is a floating point constant,
00071    as in 0d1.0.  */
00072 const char FLT_CHARS[] = "dD";
00073 
00074 /* The dwarf2 data alignment, adjusted for 32 or 64 bit.  */
00075 int s390_cie_data_alignment;
00076 
00077 /* The target specific pseudo-ops which we support.  */
00078 
00079 /* Define the prototypes for the pseudo-ops */
00080 static void s390_byte PARAMS ((int));
00081 static void s390_elf_cons PARAMS ((int));
00082 static void s390_bss PARAMS ((int));
00083 static void s390_insn PARAMS ((int));
00084 static void s390_literals PARAMS ((int));
00085 
00086 const pseudo_typeS md_pseudo_table[] =
00087 {
00088   { "align", s_align_bytes, 0 },
00089   /* Pseudo-ops which must be defined.  */
00090   { "bss",      s390_bss,       0 },
00091   { "insn",     s390_insn,      0 },
00092   /* Pseudo-ops which must be overridden.  */
00093   { "byte",   s390_byte,    0 },
00094   { "short",    s390_elf_cons,  2 },
00095   { "long",   s390_elf_cons,       4 },
00096   { "quad",     s390_elf_cons,  8 },
00097   { "ltorg",    s390_literals,  0 },
00098   { "string",   stringer,       2 },
00099   { NULL,     NULL,         0 }
00100 };
00101 
00102 
00103 /* Structure to hold information about predefined registers.  */
00104 struct pd_reg
00105   {
00106     char *name;
00107     int value;
00108   };
00109 
00110 /* List of registers that are pre-defined:
00111 
00112    Each access register has a predefined name of the form:
00113      a<reg_num> which has the value <reg_num>.
00114 
00115    Each control register has a predefined name of the form:
00116      c<reg_num> which has the value <reg_num>.
00117 
00118    Each general register has a predefined name of the form:
00119      r<reg_num> which has the value <reg_num>.
00120 
00121    Each floating point register a has predefined name of the form:
00122      f<reg_num> which has the value <reg_num>.
00123 
00124    There are individual registers as well:
00125      sp     has the value 15
00126      lit    has the value 12
00127 
00128    The table is sorted. Suitable for searching by a binary search.  */
00129 
00130 static const struct pd_reg pre_defined_registers[] =
00131 {
00132   { "a0", 0 },     /* Access registers */
00133   { "a1", 1 },
00134   { "a10", 10 },
00135   { "a11", 11 },
00136   { "a12", 12 },
00137   { "a13", 13 },
00138   { "a14", 14 },
00139   { "a15", 15 },
00140   { "a2", 2 },
00141   { "a3", 3 },
00142   { "a4", 4 },
00143   { "a5", 5 },
00144   { "a6", 6 },
00145   { "a7", 7 },
00146   { "a8", 8 },
00147   { "a9", 9 },
00148 
00149   { "c0", 0 },     /* Control registers */
00150   { "c1", 1 },
00151   { "c10", 10 },
00152   { "c11", 11 },
00153   { "c12", 12 },
00154   { "c13", 13 },
00155   { "c14", 14 },
00156   { "c15", 15 },
00157   { "c2", 2 },
00158   { "c3", 3 },
00159   { "c4", 4 },
00160   { "c5", 5 },
00161   { "c6", 6 },
00162   { "c7", 7 },
00163   { "c8", 8 },
00164   { "c9", 9 },
00165 
00166   { "f0", 0 },     /* Floating point registers */
00167   { "f1", 1 },
00168   { "f10", 10 },
00169   { "f11", 11 },
00170   { "f12", 12 },
00171   { "f13", 13 },
00172   { "f14", 14 },
00173   { "f15", 15 },
00174   { "f2", 2 },
00175   { "f3", 3 },
00176   { "f4", 4 },
00177   { "f5", 5 },
00178   { "f6", 6 },
00179   { "f7", 7 },
00180   { "f8", 8 },
00181   { "f9", 9 },
00182 
00183   { "lit", 13 },   /* Pointer to literal pool */
00184 
00185   { "r0", 0 },     /* General purpose registers */
00186   { "r1", 1 },
00187   { "r10", 10 },
00188   { "r11", 11 },
00189   { "r12", 12 },
00190   { "r13", 13 },
00191   { "r14", 14 },
00192   { "r15", 15 },
00193   { "r2", 2 },
00194   { "r3", 3 },
00195   { "r4", 4 },
00196   { "r5", 5 },
00197   { "r6", 6 },
00198   { "r7", 7 },
00199   { "r8", 8 },
00200   { "r9", 9 },
00201 
00202   { "sp", 15 },   /* Stack pointer */
00203 
00204 };
00205 
00206 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
00207 
00208 static int reg_name_search
00209   PARAMS ((const struct pd_reg *, int, const char *));
00210 static bfd_boolean register_name PARAMS ((expressionS *));
00211 static void init_default_arch PARAMS ((void));
00212 static void s390_insert_operand
00213   PARAMS ((unsigned char *, const struct s390_operand *, offsetT, char *,
00214           unsigned int));
00215 static char *md_gather_operands
00216   PARAMS ((char *, unsigned char *, const struct s390_opcode *));
00217 
00218 /* Given NAME, find the register number associated with that name, return
00219    the integer value associated with the given name or -1 on failure.  */
00220 
00221 static int
00222 reg_name_search (regs, regcount, name)
00223      const struct pd_reg *regs;
00224      int regcount;
00225      const char *name;
00226 {
00227   int middle, low, high;
00228   int cmp;
00229 
00230   low = 0;
00231   high = regcount - 1;
00232 
00233   do
00234     {
00235       middle = (low + high) / 2;
00236       cmp = strcasecmp (name, regs[middle].name);
00237       if (cmp < 0)
00238        high = middle - 1;
00239       else if (cmp > 0)
00240        low = middle + 1;
00241       else
00242        return regs[middle].value;
00243     }
00244   while (low <= high);
00245 
00246   return -1;
00247 }
00248 
00249 
00250 /*
00251  * Summary of register_name().
00252  *
00253  * in: Input_line_pointer points to 1st char of operand.
00254  *
00255  * out:       A expressionS.
00256  *      The operand may have been a register: in this case, X_op == O_register,
00257  *      X_add_number is set to the register number, and truth is returned.
00258  *     Input_line_pointer->(next non-blank) char after operand, or is in its
00259  *      original state.
00260  */
00261 
00262 static bfd_boolean
00263 register_name (expressionP)
00264      expressionS *expressionP;
00265 {
00266   int reg_number;
00267   char *name;
00268   char *start;
00269   char c;
00270 
00271   /* Find the spelling of the operand.  */
00272   start = name = input_line_pointer;
00273   if (name[0] == '%' && ISALPHA (name[1]))
00274     name = ++input_line_pointer;
00275   else
00276     return FALSE;
00277 
00278   c = get_symbol_end ();
00279   reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
00280 
00281   /* Put back the delimiting char.  */
00282   *input_line_pointer = c;
00283 
00284   /* Look to see if it's in the register table.  */
00285   if (reg_number >= 0)
00286     {
00287       expressionP->X_op = O_register;
00288       expressionP->X_add_number = reg_number;
00289 
00290       /* Make the rest nice.  */
00291       expressionP->X_add_symbol = NULL;
00292       expressionP->X_op_symbol = NULL;
00293       return TRUE;
00294     }
00295 
00296   /* Reset the line as if we had not done anything.  */
00297   input_line_pointer = start;
00298   return FALSE;
00299 }
00300 
00301 /* Local variables.  */
00302 
00303 /* Opformat hash table.  */
00304 static struct hash_control *s390_opformat_hash;
00305 
00306 /* Opcode hash table.  */
00307 static struct hash_control *s390_opcode_hash;
00308 
00309 /* Flags to set in the elf header */
00310 static flagword s390_flags = 0;
00311 
00312 symbolS *GOT_symbol;        /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
00313 
00314 #ifndef WORKING_DOT_WORD
00315 int md_short_jump_size = 4;
00316 int md_long_jump_size = 4;
00317 #endif
00318 
00319 const char *md_shortopts = "A:m:kVQ:";
00320 struct option md_longopts[] = {
00321   {NULL, no_argument, NULL, 0}
00322 };
00323 size_t md_longopts_size = sizeof (md_longopts);
00324 
00325 /* Initialize the default opcode arch and word size from the default
00326    architecture name if not specified by an option.  */
00327 static void
00328 init_default_arch ()
00329 {
00330   if (strcmp (default_arch, "s390") == 0)
00331     {
00332       if (s390_arch_size == 0)
00333        s390_arch_size = 32;
00334     }
00335   else if (strcmp (default_arch, "s390x") == 0)
00336     {
00337       if (s390_arch_size == 0)
00338        s390_arch_size = 64;
00339     }
00340   else
00341     as_fatal ("Invalid default architecture, broken assembler.");
00342 
00343   if (current_mode_mask == 0)
00344     {
00345       if (s390_arch_size == 32)
00346        current_mode_mask = 1 << S390_OPCODE_ESA;
00347       else
00348        current_mode_mask = 1 << S390_OPCODE_ZARCH;
00349     }
00350   if (current_cpu == -1U)
00351     {
00352       if (current_mode_mask == (1 << S390_OPCODE_ESA))
00353        current_cpu = S390_OPCODE_G5;
00354       else
00355        current_cpu = S390_OPCODE_Z900;
00356     }
00357 }
00358 
00359 /* Called by TARGET_FORMAT.  */
00360 const char *
00361 s390_target_format ()
00362 {
00363   /* We don't get a chance to initialize anything before we're called,
00364      so handle that now.  */
00365   init_default_arch ();
00366 
00367   return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390";
00368 }
00369 
00370 int
00371 md_parse_option (c, arg)
00372      int c;
00373      char *arg;
00374 {
00375   switch (c)
00376     {
00377       /* -k: Ignore for FreeBSD compatibility.  */
00378     case 'k':
00379       break;
00380     case 'm':
00381       if (arg != NULL && strcmp (arg, "regnames") == 0)
00382        reg_names_p = TRUE;
00383 
00384       else if (arg != NULL && strcmp (arg, "no-regnames") == 0)
00385        reg_names_p = FALSE;
00386 
00387       else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0)
00388        warn_areg_zero = TRUE;
00389 
00390       else if (arg != NULL && strcmp (arg, "31") == 0)
00391        s390_arch_size = 32;
00392 
00393       else if (arg != NULL && strcmp (arg, "64") == 0)
00394        s390_arch_size = 64;
00395 
00396       else if (arg != NULL && strcmp (arg, "esa") == 0)
00397        current_mode_mask = 1 << S390_OPCODE_ESA;
00398 
00399       else if (arg != NULL && strcmp (arg, "zarch") == 0)
00400        current_mode_mask = 1 << S390_OPCODE_ZARCH;
00401 
00402       else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
00403        {
00404          if (strcmp (arg + 5, "g5") == 0)
00405            current_cpu = S390_OPCODE_G5;
00406          else if (strcmp (arg + 5, "g6") == 0)
00407            current_cpu = S390_OPCODE_G6;
00408          else if (strcmp (arg + 5, "z900") == 0)
00409            current_cpu = S390_OPCODE_Z900;
00410          else if (strcmp (arg + 5, "z990") == 0)
00411            current_cpu = S390_OPCODE_Z990;
00412          else if (strcmp (arg + 5, "z9-109") == 0)
00413            current_cpu = S390_OPCODE_Z9_109;
00414          else if (strcmp (arg + 5, "z9-ec") == 0)
00415            current_cpu = S390_OPCODE_Z9_EC;
00416          else
00417            {
00418              as_bad (_("invalid switch -m%s"), arg);
00419              return 0;
00420            }
00421        }
00422 
00423       else
00424        {
00425          as_bad (_("invalid switch -m%s"), arg);
00426          return 0;
00427        }
00428       break;
00429 
00430     case 'A':
00431       /* Option -A is deprecated. Still available for compatibility.  */
00432       if (arg != NULL && strcmp (arg, "esa") == 0)
00433        current_cpu = S390_OPCODE_G5;
00434       else if (arg != NULL && strcmp (arg, "esame") == 0)
00435        current_cpu = S390_OPCODE_Z900;
00436       else
00437        as_bad ("invalid architecture -A%s", arg);
00438       break;
00439 
00440       /* -V: SVR4 argument to print version ID.  */
00441     case 'V':
00442       print_version_id ();
00443       break;
00444 
00445       /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
00446         should be emitted or not.  FIXME: Not implemented.  */
00447     case 'Q':
00448       break;
00449 
00450     default:
00451       return 0;
00452     }
00453 
00454   return 1;
00455 }
00456 
00457 void
00458 md_show_usage (stream)
00459      FILE *stream;
00460 {
00461   fprintf (stream, _("\
00462         S390 options:\n\
00463         -mregnames        Allow symbolic names for registers\n\
00464         -mwarn-areg-zero  Warn about zero base/index registers\n\
00465         -mno-regnames     Do not allow symbolic names for registers\n\
00466         -m31              Set file format to 31 bit format\n\
00467         -m64              Set file format to 64 bit format\n"));
00468   fprintf (stream, _("\
00469         -V                print assembler version number\n\
00470         -Qy, -Qn          ignored\n"));
00471 }
00472 
00473 /* This function is called when the assembler starts up.  It is called
00474    after the options have been parsed and the output file has been
00475    opened.  */
00476 
00477 void
00478 md_begin ()
00479 {
00480   register const struct s390_opcode *op;
00481   const struct s390_opcode *op_end;
00482   bfd_boolean dup_insn = FALSE;
00483   const char *retval;
00484 
00485   /* Give a warning if the combination -m64-bit and -Aesa is used.  */
00486   if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900)
00487     as_warn ("The 64 bit file format is used without esame instructions.");
00488 
00489   s390_cie_data_alignment = -s390_arch_size / 8;
00490 
00491   /* Set the ELF flags if desired.  */
00492   if (s390_flags)
00493     bfd_set_private_flags (stdoutput, s390_flags);
00494 
00495   /* Insert the opcode formats into a hash table.  */
00496   s390_opformat_hash = hash_new ();
00497 
00498   op_end = s390_opformats + s390_num_opformats;
00499   for (op = s390_opformats; op < op_end; op++)
00500     {
00501       retval = hash_insert (s390_opformat_hash, op->name, (PTR) op);
00502       if (retval != (const char *) NULL)
00503        {
00504          as_bad (_("Internal assembler error for instruction format %s"),
00505                 op->name);
00506          dup_insn = TRUE;
00507        }
00508     }
00509 
00510   /* Insert the opcodes into a hash table.  */
00511   s390_opcode_hash = hash_new ();
00512 
00513   op_end = s390_opcodes + s390_num_opcodes;
00514   for (op = s390_opcodes; op < op_end; op++)
00515     if (op->min_cpu <= current_cpu)
00516       {
00517        retval = hash_insert (s390_opcode_hash, op->name, (PTR) op);
00518        if (retval != (const char *) NULL)
00519          {
00520            as_bad (_("Internal assembler error for instruction %s"),
00521                   op->name);
00522            dup_insn = TRUE;
00523          }
00524        while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0)
00525          op++;
00526       }
00527 
00528   if (dup_insn)
00529     abort ();
00530 
00531   record_alignment (text_section, 2);
00532   record_alignment (data_section, 2);
00533   record_alignment (bss_section, 2);
00534 
00535 }
00536 
00537 /* Called after all assembly has been done.  */
00538 void
00539 s390_md_end ()
00540 {
00541   if (s390_arch_size == 64)
00542     bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);
00543   else
00544     bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31);
00545 }
00546 
00547 /* Insert an operand value into an instruction.  */
00548 
00549 static void
00550 s390_insert_operand (insn, operand, val, file, line)
00551      unsigned char *insn;
00552      const struct s390_operand *operand;
00553      offsetT val;
00554      char *file;
00555      unsigned int line;
00556 {
00557   addressT uval;
00558   int offset;
00559 
00560   if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL))
00561     {
00562       offsetT min, max;
00563 
00564       max = ((offsetT) 1 << (operand->bits - 1)) - 1;
00565       min = - ((offsetT) 1 << (operand->bits - 1));
00566       /* Halve PCREL operands.  */
00567       if (operand->flags & S390_OPERAND_PCREL)
00568        val >>= 1;
00569       /* Check for underflow / overflow.  */
00570       if (val < min || val > max)
00571        {
00572          const char *err =
00573            "operand out of range (%s not between %ld and %ld)";
00574          char buf[100];
00575 
00576          if (operand->flags & S390_OPERAND_PCREL)
00577            {
00578              val <<= 1;
00579              min <<= 1;
00580              max <<= 1;
00581            }
00582          sprint_value (buf, val);
00583          if (file == (char *) NULL)
00584            as_bad (err, buf, (int) min, (int) max);
00585          else
00586            as_bad_where (file, line, err, buf, (int) min, (int) max);
00587          return;
00588        }
00589       /* val is ok, now restrict it to operand->bits bits.  */
00590       uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1);
00591       /* val is restrict, now check for special case.  */
00592       if (operand->bits == 20 && operand->shift == 20)
00593         uval = (uval >> 12) | ((uval & 0xfff) << 8);
00594     }
00595   else
00596     {
00597       addressT min, max;
00598 
00599       max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1;
00600       min = (offsetT) 0;
00601       uval = (addressT) val;
00602       /* Length x in an instructions has real length x+1.  */
00603       if (operand->flags & S390_OPERAND_LENGTH)
00604        uval--;
00605       /* Check for underflow / overflow.  */
00606       if (uval < min || uval > max)
00607        {
00608          if (operand->flags & S390_OPERAND_LENGTH)
00609            {
00610              uval++;
00611              min++;
00612              max++;
00613            }
00614 
00615          as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line);
00616 
00617          return;
00618        }
00619     }
00620 
00621   /* Insert fragments of the operand byte for byte.  */
00622   offset = operand->shift + operand->bits;
00623   uval <<= (-offset) & 7;
00624   insn += (offset - 1) / 8;
00625   while (uval != 0)
00626     {
00627       *insn-- |= uval;
00628       uval >>= 8;
00629     }
00630 }
00631 
00632 struct map_tls
00633   {
00634     char *string;
00635     int length;
00636     bfd_reloc_code_real_type reloc;
00637   };
00638 
00639 static bfd_reloc_code_real_type s390_tls_suffix
00640   PARAMS ((char **, expressionS *));
00641 
00642 /* Parse tls marker and return the desired relocation.  */
00643 static bfd_reloc_code_real_type
00644 s390_tls_suffix (str_p, exp_p)
00645      char **str_p;
00646      expressionS *exp_p;
00647 {
00648   static struct map_tls mapping[] =
00649   {
00650     { "tls_load", 8, BFD_RELOC_390_TLS_LOAD },
00651     { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL  },
00652     { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL  },
00653     { NULL,  0, BFD_RELOC_UNUSED }
00654   };
00655   struct map_tls *ptr;
00656   char *orig_line;
00657   char *str;
00658   char *ident;
00659   int len;
00660 
00661   str = *str_p;
00662   if (*str++ != ':')
00663     return BFD_RELOC_UNUSED;
00664 
00665   ident = str;
00666   while (ISIDNUM (*str))
00667     str++;
00668   len = str - ident;
00669   if (*str++ != ':')
00670     return BFD_RELOC_UNUSED;
00671 
00672   orig_line = input_line_pointer;
00673   input_line_pointer = str;
00674   expression (exp_p);
00675   str = input_line_pointer;
00676   if (&input_line_pointer != str_p)
00677     input_line_pointer = orig_line;
00678 
00679   if (exp_p->X_op != O_symbol)
00680     return BFD_RELOC_UNUSED;
00681 
00682   for (ptr = &mapping[0]; ptr->length > 0; ptr++)
00683     if (len == ptr->length
00684        && strncasecmp (ident, ptr->string, ptr->length) == 0)
00685       {
00686        /* Found a matching tls suffix.  */
00687        *str_p = str;
00688        return ptr->reloc;
00689       }
00690   return BFD_RELOC_UNUSED;
00691 }
00692 
00693 /* Structure used to hold suffixes.  */
00694 typedef enum
00695   {
00696     ELF_SUFFIX_NONE = 0,
00697     ELF_SUFFIX_GOT,
00698     ELF_SUFFIX_PLT,
00699     ELF_SUFFIX_GOTENT,
00700     ELF_SUFFIX_GOTOFF,
00701     ELF_SUFFIX_GOTPLT,
00702     ELF_SUFFIX_PLTOFF,
00703     ELF_SUFFIX_TLS_GD,
00704     ELF_SUFFIX_TLS_GOTIE,
00705     ELF_SUFFIX_TLS_IE,
00706     ELF_SUFFIX_TLS_LDM,
00707     ELF_SUFFIX_TLS_LDO,
00708     ELF_SUFFIX_TLS_LE
00709   }
00710 elf_suffix_type;
00711 
00712 struct map_bfd
00713   {
00714     char *string;
00715     int length;
00716     elf_suffix_type suffix;
00717   };
00718 
00719 static elf_suffix_type s390_elf_suffix PARAMS ((char **, expressionS *));
00720 static int s390_exp_compare PARAMS ((expressionS *exp1, expressionS *exp2));
00721 static elf_suffix_type s390_lit_suffix
00722   PARAMS ((char **, expressionS *, elf_suffix_type));
00723 
00724 
00725 /* Parse @got/@plt/@gotoff. and return the desired relocation.  */
00726 static elf_suffix_type
00727 s390_elf_suffix (str_p, exp_p)
00728      char **str_p;
00729      expressionS *exp_p;
00730 {
00731   static struct map_bfd mapping[] =
00732   {
00733     { "got", 3, ELF_SUFFIX_GOT  },
00734     { "got12", 5, ELF_SUFFIX_GOT  },
00735     { "plt", 3, ELF_SUFFIX_PLT  },
00736     { "gotent", 6, ELF_SUFFIX_GOTENT },
00737     { "gotoff", 6, ELF_SUFFIX_GOTOFF },
00738     { "gotplt", 6, ELF_SUFFIX_GOTPLT },
00739     { "pltoff", 6, ELF_SUFFIX_PLTOFF },
00740     { "tlsgd", 5, ELF_SUFFIX_TLS_GD },
00741     { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE },
00742     { "indntpoff", 9, ELF_SUFFIX_TLS_IE },
00743     { "tlsldm", 6, ELF_SUFFIX_TLS_LDM },
00744     { "dtpoff", 6, ELF_SUFFIX_TLS_LDO },
00745     { "ntpoff", 6, ELF_SUFFIX_TLS_LE },
00746     { NULL,  0, ELF_SUFFIX_NONE }
00747   };
00748 
00749   struct map_bfd *ptr;
00750   char *str = *str_p;
00751   char *ident;
00752   int len;
00753 
00754   if (*str++ != '@')
00755     return ELF_SUFFIX_NONE;
00756 
00757   ident = str;
00758   while (ISALNUM (*str))
00759     str++;
00760   len = str - ident;
00761 
00762   for (ptr = &mapping[0]; ptr->length > 0; ptr++)
00763     if (len == ptr->length
00764        && strncasecmp (ident, ptr->string, ptr->length) == 0)
00765       {
00766        if (exp_p->X_add_number != 0)
00767          as_warn (_("identifier+constant@%s means identifier@%s+constant"),
00768                  ptr->string, ptr->string);
00769        /* Now check for identifier@suffix+constant.  */
00770        if (*str == '-' || *str == '+')
00771          {
00772            char *orig_line = input_line_pointer;
00773            expressionS new_exp;
00774 
00775            input_line_pointer = str;
00776            expression (&new_exp);
00777 
00778            switch (new_exp.X_op)
00779              {
00780              case O_constant: /* X_add_number (a constant expression).  */
00781               exp_p->X_add_number += new_exp.X_add_number;
00782               str = input_line_pointer;
00783               break;
00784              case O_symbol:   /* X_add_symbol + X_add_number.  */
00785               /* this case is used for e.g. xyz@PLT+.Label.  */
00786               exp_p->X_add_number += new_exp.X_add_number;
00787               exp_p->X_op_symbol = new_exp.X_add_symbol;
00788               exp_p->X_op = O_add;
00789               str = input_line_pointer;
00790               break;
00791              case O_uminus:   /* (- X_add_symbol) + X_add_number.  */
00792               /* this case is used for e.g. xyz@PLT-.Label.  */
00793               exp_p->X_add_number += new_exp.X_add_number;
00794               exp_p->X_op_symbol = new_exp.X_add_symbol;
00795               exp_p->X_op = O_subtract;
00796               str = input_line_pointer;
00797               break;
00798              default:
00799               break;
00800              }
00801 
00802            /* If s390_elf_suffix has not been called with
00803               &input_line_pointer as first parameter, we have
00804               clobbered the input_line_pointer. We have to
00805               undo that.  */
00806            if (&input_line_pointer != str_p)
00807              input_line_pointer = orig_line;
00808          }
00809        *str_p = str;
00810        return ptr->suffix;
00811       }
00812 
00813   return BFD_RELOC_UNUSED;
00814 }
00815 
00816 /* Structure used to hold a literal pool entry.  */
00817 struct s390_lpe
00818   {
00819     struct s390_lpe *next;
00820     expressionS ex;
00821     FLONUM_TYPE floatnum;     /* used if X_op == O_big && X_add_number <= 0 */
00822     LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0  */
00823     int nbytes;
00824     bfd_reloc_code_real_type reloc;
00825     symbolS *sym;
00826   };
00827 
00828 static struct s390_lpe *lpe_free_list = NULL;
00829 static struct s390_lpe *lpe_list = NULL;
00830 static struct s390_lpe *lpe_list_tail = NULL;
00831 static symbolS *lp_sym = NULL;
00832 static int lp_count = 0;
00833 static int lpe_count = 0;
00834 
00835 static int
00836 s390_exp_compare (exp1, exp2)
00837      expressionS *exp1;
00838      expressionS *exp2;
00839 {
00840   if (exp1->X_op != exp2->X_op)
00841     return 0;
00842 
00843   switch (exp1->X_op)
00844     {
00845     case O_constant:   /* X_add_number must be equal.  */
00846     case O_register:
00847       return exp1->X_add_number == exp2->X_add_number;
00848 
00849     case O_big:
00850       as_bad (_("Can't handle O_big in s390_exp_compare"));
00851 
00852     case O_symbol:     /* X_add_symbol & X_add_number must be equal.  */
00853     case O_symbol_rva:
00854     case O_uminus:
00855     case O_bit_not:
00856     case O_logical_not:
00857       return (exp1->X_add_symbol == exp2->X_add_symbol)
00858        &&   (exp1->X_add_number == exp2->X_add_number);
00859 
00860     case O_multiply:   /* X_add_symbol,X_op_symbol&X_add_number must be equal.  */
00861     case O_divide:
00862     case O_modulus:
00863     case O_left_shift:
00864     case O_right_shift:
00865     case O_bit_inclusive_or:
00866     case O_bit_or_not:
00867     case O_bit_exclusive_or:
00868     case O_bit_and:
00869     case O_add:
00870     case O_subtract:
00871     case O_eq:
00872     case O_ne:
00873     case O_lt:
00874     case O_le:
00875     case O_ge:
00876     case O_gt:
00877     case O_logical_and:
00878     case O_logical_or:
00879       return (exp1->X_add_symbol == exp2->X_add_symbol)
00880        &&   (exp1->X_op_symbol  == exp2->X_op_symbol)
00881        &&   (exp1->X_add_number == exp2->X_add_number);
00882     default:
00883       return 0;
00884     }
00885 }
00886 
00887 /* Test for @lit and if its present make an entry in the literal pool and
00888    modify the current expression to be an offset into the literal pool.  */
00889 static elf_suffix_type
00890 s390_lit_suffix (str_p, exp_p, suffix)
00891      char **str_p;
00892      expressionS *exp_p;
00893      elf_suffix_type suffix;
00894 {
00895   bfd_reloc_code_real_type reloc;
00896   char tmp_name[64];
00897   char *str = *str_p;
00898   char *ident;
00899   struct s390_lpe *lpe;
00900   int nbytes, len;
00901 
00902   if (*str++ != ':')
00903     return suffix;       /* No modification.  */
00904 
00905   /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8".  */
00906   ident = str;
00907   while (ISALNUM (*str))
00908     str++;
00909   len = str - ident;
00910   if (len != 4 || strncasecmp (ident, "lit", 3) != 0
00911       || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8'))
00912     return suffix;      /* no modification */
00913   nbytes = ident[3] - '0';
00914 
00915   reloc = BFD_RELOC_UNUSED;
00916   if (suffix == ELF_SUFFIX_GOT)
00917     {
00918       if (nbytes == 2)
00919        reloc = BFD_RELOC_390_GOT16;
00920       else if (nbytes == 4)
00921        reloc = BFD_RELOC_32_GOT_PCREL;
00922       else if (nbytes == 8)
00923        reloc = BFD_RELOC_390_GOT64;
00924     }
00925   else if (suffix == ELF_SUFFIX_PLT)
00926     {
00927       if (nbytes == 4)
00928        reloc = BFD_RELOC_390_PLT32;
00929       else if (nbytes == 8)
00930        reloc = BFD_RELOC_390_PLT64;
00931     }
00932 
00933   if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
00934     as_bad (_("Invalid suffix for literal pool entry"));
00935 
00936   /* Search the pool if the new entry is a duplicate.  */
00937   if (exp_p->X_op == O_big)
00938     {
00939       /* Special processing for big numbers.  */
00940       for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
00941        {
00942          if (lpe->ex.X_op == O_big)
00943            {
00944              if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0)
00945               {
00946                 if (memcmp (&generic_floating_point_number, &lpe->floatnum,
00947                            sizeof (FLONUM_TYPE)) == 0)
00948                   break;
00949               }
00950              else if (exp_p->X_add_number == lpe->ex.X_add_number)
00951               {
00952                 if (memcmp (generic_bignum, lpe->bignum,
00953                            sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0)
00954                   break;
00955               }
00956            }
00957        }
00958     }
00959   else
00960     {
00961       /* Processing for 'normal' data types.  */
00962       for (lpe = lpe_list; lpe != NULL; lpe = lpe->next)
00963        if (lpe->nbytes == nbytes && lpe->reloc == reloc
00964            && s390_exp_compare (exp_p, &lpe->ex) != 0)
00965          break;
00966     }
00967 
00968   if (lpe == NULL)
00969     {
00970       /* A new literal.  */
00971       if (lpe_free_list != NULL)
00972        {
00973          lpe = lpe_free_list;
00974          lpe_free_list = lpe_free_list->next;
00975        }
00976       else
00977        {
00978          lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe));
00979        }
00980 
00981       lpe->ex = *exp_p;
00982 
00983       if (exp_p->X_op == O_big)
00984        {
00985          if (exp_p->X_add_number <= 0)
00986            lpe->floatnum = generic_floating_point_number;
00987          else if (exp_p->X_add_number <= 4)
00988            memcpy (lpe->bignum, generic_bignum,
00989                   exp_p->X_add_number * sizeof (LITTLENUM_TYPE));
00990          else
00991            as_bad (_("Big number is too big"));
00992        }
00993 
00994       lpe->nbytes = nbytes;
00995       lpe->reloc = reloc;
00996       /* Literal pool name defined ?  */
00997       if (lp_sym == NULL)
00998        {
00999          sprintf (tmp_name, ".L\001%i", lp_count);
01000          lp_sym = symbol_make (tmp_name);
01001        }
01002 
01003       /* Make name for literal pool entry.  */
01004       sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count);
01005       lpe_count++;
01006       lpe->sym = symbol_make (tmp_name);
01007 
01008       /* Add to literal pool list.  */
01009       lpe->next = NULL;
01010       if (lpe_list_tail != NULL)
01011        {
01012          lpe_list_tail->next = lpe;
01013          lpe_list_tail = lpe;
01014        }
01015       else
01016        lpe_list = lpe_list_tail = lpe;
01017     }
01018 
01019   /* Now change exp_p to the offset into the literal pool.
01020      Thats the expression: .L^Ax^By-.L^Ax   */
01021   exp_p->X_add_symbol = lpe->sym;
01022   exp_p->X_op_symbol = lp_sym;
01023   exp_p->X_op = O_subtract;
01024   exp_p->X_add_number = 0;
01025 
01026   *str_p = str;
01027 
01028   /* We change the suffix type to ELF_SUFFIX_NONE, because
01029      the difference of two local labels is just a number.  */
01030   return ELF_SUFFIX_NONE;
01031 }
01032 
01033 /* Like normal .long/.short/.word, except support @got, etc.
01034    clobbers input_line_pointer, checks end-of-line.  */
01035 static void
01036 s390_elf_cons (nbytes)
01037      register int nbytes;   /* 1=.byte, 2=.word, 4=.long */
01038 {
01039   expressionS exp;
01040   elf_suffix_type suffix;
01041 
01042   if (is_it_end_of_statement ())
01043     {
01044       demand_empty_rest_of_line ();
01045       return;
01046     }
01047 
01048   do
01049     {
01050       expression (&exp);
01051 
01052       if (exp.X_op == O_symbol
01053          && *input_line_pointer == '@'
01054          && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE)
01055        {
01056          bfd_reloc_code_real_type reloc;
01057          reloc_howto_type *reloc_howto;
01058          int size;
01059          char *where;
01060 
01061          if (nbytes == 2)
01062            {
01063              static bfd_reloc_code_real_type tab2[] =
01064               {
01065                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_NONE  */
01066                 BFD_RELOC_390_GOT16,             /* ELF_SUFFIX_GOT  */
01067                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_PLT  */
01068                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_GOTENT  */
01069                 BFD_RELOC_16_GOTOFF,             /* ELF_SUFFIX_GOTOFF  */
01070                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_GOTPLT  */
01071                 BFD_RELOC_390_PLTOFF16,   /* ELF_SUFFIX_PLTOFF  */
01072                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_TLS_GD  */
01073                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_TLS_GOTIE  */
01074                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_TLS_IE  */
01075                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_TLS_LDM  */
01076                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_TLS_LDO  */
01077                 BFD_RELOC_UNUSED          /* ELF_SUFFIX_TLS_LE  */
01078               };
01079              reloc = tab2[suffix];
01080            }
01081          else if (nbytes == 4)
01082            {
01083              static bfd_reloc_code_real_type tab4[] =
01084               {
01085                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_NONE  */
01086                 BFD_RELOC_32_GOT_PCREL,   /* ELF_SUFFIX_GOT  */
01087                 BFD_RELOC_390_PLT32,             /* ELF_SUFFIX_PLT  */
01088                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_GOTENT  */
01089                 BFD_RELOC_32_GOTOFF,             /* ELF_SUFFIX_GOTOFF  */
01090                 BFD_RELOC_390_GOTPLT32,   /* ELF_SUFFIX_GOTPLT  */
01091                 BFD_RELOC_390_PLTOFF32,   /* ELF_SUFFIX_PLTOFF  */
01092                 BFD_RELOC_390_TLS_GD32,   /* ELF_SUFFIX_TLS_GD  */
01093                 BFD_RELOC_390_TLS_GOTIE32,       /* ELF_SUFFIX_TLS_GOTIE  */
01094                 BFD_RELOC_390_TLS_IE32,   /* ELF_SUFFIX_TLS_IE  */
01095                 BFD_RELOC_390_TLS_LDM32,  /* ELF_SUFFIX_TLS_LDM  */
01096                 BFD_RELOC_390_TLS_LDO32,  /* ELF_SUFFIX_TLS_LDO  */
01097                 BFD_RELOC_390_TLS_LE32    /* ELF_SUFFIX_TLS_LE  */
01098               };
01099              reloc = tab4[suffix];
01100            }
01101          else if (nbytes == 8)
01102            {
01103              static bfd_reloc_code_real_type tab8[] =
01104               {
01105                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_NONE  */
01106                 BFD_RELOC_390_GOT64,             /* ELF_SUFFIX_GOT  */
01107                 BFD_RELOC_390_PLT64,             /* ELF_SUFFIX_PLT  */
01108                 BFD_RELOC_UNUSED,         /* ELF_SUFFIX_GOTENT  */
01109                 BFD_RELOC_390_GOTOFF64,   /* ELF_SUFFIX_GOTOFF  */
01110                 BFD_RELOC_390_GOTPLT64,   /* ELF_SUFFIX_GOTPLT  */
01111                 BFD_RELOC_390_PLTOFF64,   /* ELF_SUFFIX_PLTOFF  */
01112                 BFD_RELOC_390_TLS_GD64,   /* ELF_SUFFIX_TLS_GD  */
01113                 BFD_RELOC_390_TLS_GOTIE64,       /* ELF_SUFFIX_TLS_GOTIE  */
01114                 BFD_RELOC_390_TLS_IE64,   /* ELF_SUFFIX_TLS_IE  */
01115                 BFD_RELOC_390_TLS_LDM64,  /* ELF_SUFFIX_TLS_LDM  */
01116                 BFD_RELOC_390_TLS_LDO64,  /* ELF_SUFFIX_TLS_LDO  */
01117                 BFD_RELOC_390_TLS_LE64    /* ELF_SUFFIX_TLS_LE  */
01118               };
01119              reloc = tab8[suffix];
01120            }
01121          else
01122            reloc = BFD_RELOC_UNUSED;
01123 
01124          if (reloc != BFD_RELOC_UNUSED
01125              && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc)))
01126            {
01127              size = bfd_get_reloc_size (reloc_howto);
01128              if (size > nbytes)
01129               as_bad (_("%s relocations do not fit in %d bytes"),
01130                      reloc_howto->name, nbytes);
01131              where = frag_more (nbytes);
01132              md_number_to_chars (where, 0, size);
01133              /* To make fixup_segment do the pc relative conversion the
01134                pcrel parameter on the fix_new_exp call needs to be FALSE.  */
01135              fix_new_exp (frag_now, where - frag_now->fr_literal,
01136                         size, &exp, FALSE, reloc);
01137            }
01138          else
01139            as_bad (_("relocation not applicable"));
01140        }
01141       else
01142        emit_expr (&exp, (unsigned int) nbytes);
01143     }
01144   while (*input_line_pointer++ == ',');
01145 
01146   input_line_pointer--;            /* Put terminator back into stream.  */
01147   demand_empty_rest_of_line ();
01148 }
01149 
01150 /* We need to keep a list of fixups.  We can't simply generate them as
01151    we go, because that would require us to first create the frag, and
01152    that would screw up references to ``.''.  */
01153 
01154 struct s390_fixup
01155   {
01156     expressionS exp;
01157     int opindex;
01158     bfd_reloc_code_real_type reloc;
01159   };
01160 
01161 #define MAX_INSN_FIXUPS (4)
01162 
01163 /* This routine is called for each instruction to be assembled.  */
01164 
01165 static char *
01166 md_gather_operands (str, insn, opcode)
01167      char *str;
01168      unsigned char *insn;
01169      const struct s390_opcode *opcode;
01170 {
01171   struct s390_fixup fixups[MAX_INSN_FIXUPS];
01172   const struct s390_operand *operand;
01173   const unsigned char *opindex_ptr;
01174   expressionS ex;
01175   elf_suffix_type suffix;
01176   bfd_reloc_code_real_type reloc;
01177   int skip_optional;
01178   int parentheses;
01179   char *f;
01180   int fc, i;
01181 
01182   while (ISSPACE (*str))
01183     str++;
01184 
01185   parentheses = 0;
01186   skip_optional = 0;
01187 
01188   /* Gather the operands.  */
01189   fc = 0;
01190   for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
01191     {
01192       char *hold;
01193 
01194       operand = s390_operands + *opindex_ptr;
01195 
01196       if (skip_optional && (operand->flags & S390_OPERAND_INDEX))
01197        {
01198          /* We do an early skip. For D(X,B) constructions the index
01199             register is skipped (X is optional). For D(L,B) the base
01200             register will be the skipped operand, because L is NOT
01201             optional.  */
01202          skip_optional = 0;
01203          continue;
01204        }
01205 
01206       /* Gather the operand.  */
01207       hold = input_line_pointer;
01208       input_line_pointer = str;
01209 
01210       /* Parse the operand.  */
01211       if (! register_name (&ex))
01212        expression (&ex);
01213 
01214       str = input_line_pointer;
01215       input_line_pointer = hold;
01216 
01217       /* Write the operand to the insn.  */
01218       if (ex.X_op == O_illegal)
01219        as_bad (_("illegal operand"));
01220       else if (ex.X_op == O_absent)
01221        as_bad (_("missing operand"));
01222       else if (ex.X_op == O_register || ex.X_op == O_constant)
01223        {
01224          s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE);
01225 
01226          if (ex.X_op != O_register && ex.X_op != O_constant)
01227            {
01228              /* We need to generate a fixup for the
01229                expression returned by s390_lit_suffix.  */
01230              if (fc >= MAX_INSN_FIXUPS)
01231               as_fatal (_("too many fixups"));
01232              fixups[fc].exp = ex;
01233              fixups[fc].opindex = *opindex_ptr;
01234              fixups[fc].reloc = BFD_RELOC_UNUSED;
01235              ++fc;
01236            }
01237          else
01238            {
01239              if ((operand->flags & S390_OPERAND_INDEX)
01240                 && ex.X_add_number == 0
01241                 && warn_areg_zero)
01242               as_warn ("index register specified but zero");
01243              if ((operand->flags & S390_OPERAND_BASE)
01244                 && ex.X_add_number == 0
01245                 && warn_areg_zero)
01246               as_warn ("base register specified but zero");
01247              s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0);
01248            }
01249        }
01250       else
01251        {
01252          suffix = s390_elf_suffix (&str, &ex);
01253          suffix = s390_lit_suffix (&str, &ex, suffix);
01254          reloc = BFD_RELOC_UNUSED;
01255 
01256          if (suffix == ELF_SUFFIX_GOT)
01257            {
01258              if ((operand->flags & S390_OPERAND_DISP) &&
01259                 (operand->bits == 12))
01260               reloc = BFD_RELOC_390_GOT12;
01261              else if ((operand->flags & S390_OPERAND_DISP) &&
01262                      (operand->bits == 20))
01263               reloc = BFD_RELOC_390_GOT20;
01264              else if ((operand->flags & S390_OPERAND_SIGNED)
01265                      && (operand->bits == 16))
01266               reloc = BFD_RELOC_390_GOT16;
01267              else if ((operand->flags & S390_OPERAND_PCREL)
01268                      && (operand->bits == 32))
01269               reloc = BFD_RELOC_390_GOTENT;
01270            }
01271          else if (suffix == ELF_SUFFIX_PLT)
01272            {
01273              if ((operand->flags & S390_OPERAND_PCREL)
01274                 && (operand->bits == 16))
01275               reloc = BFD_RELOC_390_PLT16DBL;
01276              else if ((operand->flags & S390_OPERAND_PCREL)
01277                      && (operand->bits == 32))
01278               reloc = BFD_RELOC_390_PLT32DBL;
01279            }
01280          else if (suffix == ELF_SUFFIX_GOTENT)
01281            {
01282              if ((operand->flags & S390_OPERAND_PCREL)
01283                 && (operand->bits == 32))
01284               reloc = BFD_RELOC_390_GOTENT;
01285            }
01286          else if (suffix == ELF_SUFFIX_GOTOFF)
01287            {
01288              if ((operand->flags & S390_OPERAND_SIGNED)
01289                 && (operand->bits == 16))
01290               reloc = BFD_RELOC_16_GOTOFF;
01291            }
01292          else if (suffix == ELF_SUFFIX_PLTOFF)
01293            {
01294              if ((operand->flags & S390_OPERAND_SIGNED)
01295                 && (operand->bits == 16))
01296               reloc = BFD_RELOC_390_PLTOFF16;
01297            }
01298          else if (suffix == ELF_SUFFIX_GOTPLT)
01299            {
01300              if ((operand->flags & S390_OPERAND_DISP)
01301                 && (operand->bits == 12))
01302               reloc = BFD_RELOC_390_GOTPLT12;
01303              else if ((operand->flags & S390_OPERAND_SIGNED)
01304                      && (operand->bits == 16))
01305               reloc = BFD_RELOC_390_GOTPLT16;
01306              else if ((operand->flags & S390_OPERAND_PCREL)
01307                      && (operand->bits == 32))
01308               reloc = BFD_RELOC_390_GOTPLTENT;
01309            }
01310          else if (suffix == ELF_SUFFIX_TLS_GOTIE)
01311            {
01312              if ((operand->flags & S390_OPERAND_DISP)
01313                 && (operand->bits == 12))
01314               reloc = BFD_RELOC_390_TLS_GOTIE12;
01315              else if ((operand->flags & S390_OPERAND_DISP)
01316                      && (operand->bits == 20))
01317               reloc = BFD_RELOC_390_TLS_GOTIE20;
01318            }
01319          else if (suffix == ELF_SUFFIX_TLS_IE)
01320            {
01321              if ((operand->flags & S390_OPERAND_PCREL)
01322                      && (operand->bits == 32))
01323               reloc = BFD_RELOC_390_TLS_IEENT;
01324            }
01325 
01326          if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED)
01327            as_bad (_("invalid operand suffix"));
01328          /* We need to generate a fixup of type 'reloc' for this
01329             expression.  */
01330          if (fc >= MAX_INSN_FIXUPS)
01331            as_fatal (_("too many fixups"));
01332          fixups[fc].exp = ex;
01333          fixups[fc].opindex = *opindex_ptr;
01334          fixups[fc].reloc = reloc;
01335          ++fc;
01336        }
01337 
01338       /* Check the next character. The call to expression has advanced
01339         str past any whitespace.  */
01340       if (operand->flags & S390_OPERAND_DISP)
01341        {
01342          /* After a displacement a block in parentheses can start.  */
01343          if (*str != '(')
01344            {
01345              /* Check if parenthesized block can be skipped. If the next
01346                operand is neiter an optional operand nor a base register
01347                then we have a syntax error.  */
01348              operand = s390_operands + *(++opindex_ptr);
01349              if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE)))
01350               as_bad (_("syntax error; missing '(' after displacement"));
01351 
01352              /* Ok, skip all operands until S390_OPERAND_BASE.  */
01353              while (!(operand->flags & S390_OPERAND_BASE))
01354               operand = s390_operands + *(++opindex_ptr);
01355 
01356              /* If there is a next operand it must be separated by a comma.  */
01357              if (opindex_ptr[1] != '\0')
01358               {
01359                 if (*str != ',')
01360                   {
01361                     while (opindex_ptr[1] != '\0')
01362                      {
01363                        operand = s390_operands + *(++opindex_ptr);
01364                        if (operand->flags & S390_OPERAND_OPTIONAL)
01365                          continue;
01366                        as_bad (_("syntax error; expected ,"));
01367                        break;
01368                      }
01369                   }
01370                 else
01371                   str++;
01372               }
01373            }
01374          else
01375            {
01376              /* We found an opening parentheses.  */
01377              str++;
01378              for (f = str; *f != '\0'; f++)
01379               if (*f == ',' || *f == ')')
01380                 break;
01381              /* If there is no comma until the closing parentheses OR
01382                there is a comma right after the opening parentheses,
01383                we have to skip optional operands.  */
01384              if (*f == ',' && f == str)
01385               {
01386                 /* comma directly after '(' ? */
01387                 skip_optional = 1;
01388                 str++;
01389               }
01390              else
01391               skip_optional = (*f != ',');
01392            }
01393        }
01394       else if (operand->flags & S390_OPERAND_BASE)
01395        {
01396          /* After the base register the parenthesed block ends.  */
01397          if (*str++ != ')')
01398            as_bad (_("syntax error; missing ')' after base register"));
01399          skip_optional = 0;
01400          /* If there is a next operand it must be separated by a comma.  */
01401          if (opindex_ptr[1] != '\0')
01402            {
01403              if (*str != ',')
01404               {
01405                 while (opindex_ptr[1] != '\0')
01406                   {
01407                     operand = s390_operands + *(++opindex_ptr);
01408                     if (operand->flags & S390_OPERAND_OPTIONAL)
01409                      continue;
01410                     as_bad (_("syntax error; expected ,"));
01411                     break;
01412                   }
01413               }
01414              else
01415               str++;
01416            }
01417        }
01418       else
01419        {
01420          /* We can find an 'early' closing parentheses in e.g. D(L) instead
01421             of D(L,B).  In this case the base register has to be skipped.  */
01422          if (*str == ')')
01423            {
01424              operand = s390_operands + *(++opindex_ptr);
01425 
01426              if (!(operand->flags & S390_OPERAND_BASE))
01427               as_bad (_("syntax error; ')' not allowed here"));
01428              str++;
01429            }
01430          /* If there is a next operand it must be separated by a comma.  */
01431          if (opindex_ptr[1] != '\0')
01432            {
01433              if (*str != ',')
01434               {
01435                 while (opindex_ptr[1] != '\0')
01436                   {
01437                     operand = s390_operands + *(++opindex_ptr);
01438                     if (operand->flags & S390_OPERAND_OPTIONAL)
01439                      continue;
01440                     as_bad (_("syntax error; expected ,"));
01441                     break;
01442                   }
01443               }
01444              else
01445               str++;
01446            }
01447        }
01448     }
01449 
01450   while (ISSPACE (*str))
01451     ++str;
01452 
01453   /* Check for tls instruction marker.  */
01454   reloc = s390_tls_suffix (&str, &ex);
01455   if (reloc != BFD_RELOC_UNUSED)
01456     {
01457       /* We need to generate a fixup of type 'reloc' for this
01458         instruction.  */
01459       if (fc >= MAX_INSN_FIXUPS)
01460        as_fatal (_("too many fixups"));
01461       fixups[fc].exp = ex;
01462       fixups[fc].opindex = -1;
01463       fixups[fc].reloc = reloc;
01464       ++fc;
01465     }
01466 
01467   if (*str != '\0')
01468     {
01469       char *linefeed;
01470 
01471       if ((linefeed = strchr (str, '\n')) != NULL)
01472        *linefeed = '\0';
01473       as_bad (_("junk at end of line: `%s'"), str);
01474       if (linefeed != NULL)
01475        *linefeed = '\n';
01476     }
01477 
01478   /* Write out the instruction.  */
01479   f = frag_more (opcode->oplen);
01480   memcpy (f, insn, opcode->oplen);
01481   dwarf2_emit_insn (opcode->oplen);
01482 
01483   /* Create any fixups.  At this point we do not use a
01484      bfd_reloc_code_real_type, but instead just use the
01485      BFD_RELOC_UNUSED plus the operand index.  This lets us easily
01486      handle fixups for any operand type, although that is admittedly
01487      not a very exciting feature.  We pick a BFD reloc type in
01488      md_apply_fix.  */
01489   for (i = 0; i < fc; i++)
01490     {
01491 
01492       if (fixups[i].opindex < 0)
01493        {
01494          /* Create tls instruction marker relocation.  */
01495          fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen,
01496                      &fixups[i].exp, 0, fixups[i].reloc);
01497          continue;
01498        }
01499 
01500       operand = s390_operands + fixups[i].opindex;
01501 
01502       if (fixups[i].reloc != BFD_RELOC_UNUSED)
01503        {
01504          reloc_howto_type *reloc_howto;
01505          fixS *fixP;
01506          int size;
01507 
01508          reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
01509          if (!reloc_howto)
01510            abort ();
01511 
01512          size = bfd_get_reloc_size (reloc_howto);
01513 
01514          if (size < 1 || size > 4)
01515            abort ();
01516 
01517          fixP = fix_new_exp (frag_now,
01518                            f - frag_now->fr_literal + (operand->shift/8),
01519                            size, &fixups[i].exp, reloc_howto->pc_relative,
01520                            fixups[i].reloc);
01521          /* Turn off overflow checking in fixup_segment. This is necessary
01522             because fixup_segment will signal an overflow for large 4 byte
01523             quantities for GOT12 relocations.  */
01524          if (   fixups[i].reloc == BFD_RELOC_390_GOT12
01525              || fixups[i].reloc == BFD_RELOC_390_GOT20
01526              || fixups[i].reloc == BFD_RELOC_390_GOT16)
01527            fixP->fx_no_overflow = 1;
01528        }
01529       else
01530        fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp,
01531                    (operand->flags & S390_OPERAND_PCREL) != 0,
01532                    ((bfd_reloc_code_real_type)
01533                     (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
01534     }
01535   return str;
01536 }
01537 
01538 /* This routine is called for each instruction to be assembled.  */
01539 
01540 void
01541 md_assemble (str)
01542      char *str;
01543 {
01544   const struct s390_opcode *opcode;
01545   unsigned char insn[6];
01546   char *s;
01547 
01548   /* Get the opcode.  */
01549   for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
01550     ;
01551   if (*s != '\0')
01552     *s++ = '\0';
01553 
01554   /* Look up the opcode in the hash table.  */
01555   opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str);
01556   if (opcode == (const struct s390_opcode *) NULL)
01557     {
01558       as_bad (_("Unrecognized opcode: `%s'"), str);
01559       return;
01560     }
01561   else if (!(opcode->modes & current_mode_mask))
01562     {
01563       as_bad ("Opcode %s not available in this mode", str);
01564       return;
01565     }
01566   memcpy (insn, opcode->opcode, sizeof (insn));
01567   md_gather_operands (s, insn, opcode);
01568 }
01569 
01570 #ifndef WORKING_DOT_WORD
01571 /* Handle long and short jumps. We don't support these */
01572 void
01573 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
01574      char *ptr;
01575      addressT from_addr, to_addr;
01576      fragS *frag;
01577      symbolS *to_symbol;
01578 {
01579   abort ();
01580 }
01581 
01582 void
01583 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
01584      char *ptr;
01585      addressT from_addr, to_addr;
01586      fragS *frag;
01587      symbolS *to_symbol;
01588 {
01589   abort ();
01590 }
01591 #endif
01592 
01593 void
01594 s390_bss (ignore)
01595      int ignore ATTRIBUTE_UNUSED;
01596 {
01597   /* We don't support putting frags in the BSS segment, we fake it
01598      by marking in_bss, then looking at s_skip for clues.  */
01599 
01600   subseg_set (bss_section, 0);
01601   demand_empty_rest_of_line ();
01602 }
01603 
01604 /* Pseudo-op handling.  */
01605 
01606 void
01607 s390_insn (ignore)
01608      int ignore ATTRIBUTE_UNUSED;
01609 {
01610   expressionS exp;
01611   const struct s390_opcode *opformat;
01612   unsigned char insn[6];
01613   char *s;
01614 
01615   /* Get the opcode format.  */
01616   s = input_line_pointer;
01617   while (*s != '\0' && *s != ',' && ! ISSPACE (*s))
01618     s++;
01619   if (*s != ',')
01620     as_bad (_("Invalid .insn format\n"));
01621   *s++ = '\0';
01622 
01623   /* Look up the opcode in the hash table.  */
01624   opformat = (struct s390_opcode *)
01625     hash_find (s390_opformat_hash, input_line_pointer);
01626   if (opformat == (const struct s390_opcode *) NULL)
01627     {
01628       as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer);
01629       return;
01630     }
01631   input_line_pointer = s;
01632   expression (&exp);
01633   if (exp.X_op == O_constant)
01634     {
01635       if (   (   opformat->oplen == 6
01636              && (addressT) exp.X_add_number < (1ULL << 48))
01637          || (   opformat->oplen == 4
01638              && (addressT) exp.X_add_number < (1ULL << 32))
01639          || (   opformat->oplen == 2
01640              && (addressT) exp.X_add_number < (1ULL << 16)))
01641        md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen);
01642       else
01643        as_bad (_("Invalid .insn format\n"));
01644     }
01645   else if (exp.X_op == O_big)
01646     {
01647       if (exp.X_add_number > 0
01648          && opformat->oplen == 6
01649          && generic_bignum[3] == 0)
01650        {
01651          md_number_to_chars ((char *) insn, generic_bignum[2], 2);
01652          md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2);
01653          md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2);
01654        }
01655       else
01656        as_bad (_("Invalid .insn format\n"));
01657     }
01658   else
01659     as_bad (_("second operand of .insn not a constant\n"));
01660 
01661   if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',')
01662     as_bad (_("missing comma after insn constant\n"));
01663 
01664   if ((s = strchr (input_line_pointer, '\n')) != NULL)
01665     *s = '\0';
01666   input_line_pointer = md_gather_operands (input_line_pointer, insn,
01667                                       opformat);
01668   if (s != NULL)
01669     *s = '\n';
01670   demand_empty_rest_of_line ();
01671 }
01672 
01673 /* The .byte pseudo-op.  This is similar to the normal .byte
01674    pseudo-op, but it can also take a single ASCII string.  */
01675 
01676 static void
01677 s390_byte (ignore)
01678      int ignore ATTRIBUTE_UNUSED;
01679 {
01680   if (*input_line_pointer != '\"')
01681     {
01682       cons (1);
01683       return;
01684     }
01685 
01686   /* Gather characters.  A real double quote is doubled.  Unusual
01687      characters are not permitted.  */
01688   ++input_line_pointer;
01689   while (1)
01690     {
01691       char c;
01692 
01693       c = *input_line_pointer++;
01694 
01695       if (c == '\"')
01696        {
01697          if (*input_line_pointer != '\"')
01698            break;
01699          ++input_line_pointer;
01700        }
01701 
01702       FRAG_APPEND_1_CHAR (c);
01703     }
01704 
01705   demand_empty_rest_of_line ();
01706 }
01707 
01708 /* The .ltorg pseudo-op.This emits all literals defined since the last
01709    .ltorg or the invocation of gas. Literals are defined with the
01710    @lit suffix.  */
01711 
01712 static void
01713 s390_literals (ignore)
01714      int ignore ATTRIBUTE_UNUSED;
01715 {
01716   struct s390_lpe *lpe;
01717 
01718   if (lp_sym == NULL || lpe_count == 0)
01719     return;     /* Nothing to be done.  */
01720 
01721   /* Emit symbol for start of literal pool.  */
01722   S_SET_SEGMENT (lp_sym, now_seg);
01723   S_SET_VALUE (lp_sym, (valueT) frag_now_fix ());
01724   lp_sym->sy_frag = frag_now;
01725 
01726   while (lpe_list)
01727     {
01728       lpe = lpe_list;
01729       lpe_list = lpe_list->next;
01730       S_SET_SEGMENT (lpe->sym, now_seg);
01731       S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ());
01732       lpe->sym->sy_frag = frag_now;
01733 
01734       /* Emit literal pool entry.  */
01735       if (lpe->reloc != BFD_RELOC_UNUSED)
01736        {
01737          reloc_howto_type *reloc_howto =
01738            bfd_reloc_type_lookup (stdoutput, lpe->reloc);
01739          int size = bfd_get_reloc_size (reloc_howto);
01740          char *where;
01741 
01742          if (size > lpe->nbytes)
01743            as_bad (_("%s relocations do not fit in %d bytes"),
01744                   reloc_howto->name, lpe->nbytes);
01745          where = frag_more (lpe->nbytes);
01746          md_number_to_chars (where, 0, size);
01747          fix_new_exp (frag_now, where - frag_now->fr_literal,
01748                      size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc);
01749        }
01750       else
01751        {
01752          if (lpe->ex.X_op == O_big)
01753            {
01754              if (lpe->ex.X_add_number <= 0)
01755               generic_floating_point_number = lpe->floatnum;
01756              else
01757               memcpy (generic_bignum, lpe->bignum,
01758                      lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE));
01759            }
01760          emit_expr (&lpe->ex, lpe->nbytes);
01761        }
01762 
01763       lpe->next = lpe_free_list;
01764       lpe_free_list = lpe;
01765     }
01766   lpe_list_tail = NULL;
01767   lp_sym = NULL;
01768   lp_count++;
01769   lpe_count = 0;
01770 }
01771 
01772 /* Turn a string in input_line_pointer into a floating point constant
01773    of type type, and store the appropriate bytes in *litp.  The number
01774    of LITTLENUMS emitted is stored in *sizep .  An error message is
01775    returned, or NULL on OK.  */
01776 
01777 char *
01778 md_atof (type, litp, sizep)
01779      int type;
01780      char *litp;
01781      int *sizep;
01782 {
01783   int prec;
01784   LITTLENUM_TYPE words[4];
01785   char *t;
01786   int i;
01787 
01788   switch (type)
01789     {
01790     case 'f':
01791       prec = 2;
01792       break;
01793 
01794     case 'd':
01795       prec = 4;
01796       break;
01797 
01798     default:
01799       *sizep = 0;
01800       return "bad call to md_atof";
01801     }
01802 
01803   t = atof_ieee (input_line_pointer, type, words);
01804   if (t)
01805     input_line_pointer = t;
01806 
01807   *sizep = prec * 2;
01808 
01809   for (i = 0; i < prec; i++)
01810     {
01811       md_number_to_chars (litp, (valueT) words[i], 2);
01812       litp += 2;
01813     }
01814 
01815   return NULL;
01816 }
01817 
01818 /* Align a section (I don't know why this is machine dependent).  */
01819 
01820 valueT
01821 md_section_align (seg, addr)
01822      asection *seg;
01823      valueT addr;
01824 {
01825   int align = bfd_get_section_alignment (stdoutput, seg);
01826 
01827   return ((addr + (1 << align) - 1) & (-1 << align));
01828 }
01829 
01830 /* We don't have any form of relaxing.  */
01831 
01832 int
01833 md_estimate_size_before_relax (fragp, seg)
01834      fragS *fragp ATTRIBUTE_UNUSED;
01835      asection *seg ATTRIBUTE_UNUSED;
01836 {
01837   abort ();
01838   return 0;
01839 }
01840 
01841 /* Convert a machine dependent frag.  We never generate these.  */
01842 
01843 void
01844 md_convert_frag (abfd, sec, fragp)
01845      bfd *abfd ATTRIBUTE_UNUSED;
01846      asection *sec ATTRIBUTE_UNUSED;
01847      fragS *fragp ATTRIBUTE_UNUSED;
01848 {
01849   abort ();
01850 }
01851 
01852 symbolS *
01853 md_undefined_symbol (name)
01854      char *name;
01855 {
01856   if (*name == '_' && *(name + 1) == 'G'
01857       && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
01858     {
01859       if (!GOT_symbol)
01860        {
01861          if (symbol_find (name))
01862            as_bad (_("GOT already in symbol table"));
01863          GOT_symbol = symbol_new (name, undefined_section,
01864                                (valueT) 0, &zero_address_frag);
01865        }
01866       return GOT_symbol;
01867     }
01868   return 0;
01869 }
01870 
01871 /* Functions concerning relocs.  */
01872 
01873 /* The location from which a PC relative jump should be calculated,
01874    given a PC relative reloc.  */
01875 
01876 long
01877 md_pcrel_from_section (fixp, sec)
01878      fixS *fixp;
01879      segT sec ATTRIBUTE_UNUSED;
01880 {
01881   return fixp->fx_frag->fr_address + fixp->fx_where;
01882 }
01883 
01884 /* Here we decide which fixups can be adjusted to make them relative to
01885    the beginning of the section instead of the symbol.  Basically we need
01886    to make sure that the dynamic relocations are done correctly, so in
01887    some cases we force the original symbol to be used.  */
01888 int
01889 tc_s390_fix_adjustable (fixP)
01890      fixS *fixP;
01891 {
01892   /* Don't adjust references to merge sections.  */
01893   if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0)
01894     return 0;
01895   /* adjust_reloc_syms doesn't know about the GOT.  */
01896   if (   fixP->fx_r_type == BFD_RELOC_16_GOTOFF
01897       || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
01898       || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64
01899       || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16
01900       || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32
01901       || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64
01902       || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL
01903       || fixP->fx_r_type == BFD_RELOC_390_PLT32
01904       || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL
01905       || fixP->fx_r_type == BFD_RELOC_390_PLT64
01906       || fixP->fx_r_type == BFD_RELOC_390_GOT12
01907       || fixP->fx_r_type == BFD_RELOC_390_GOT20
01908       || fixP->fx_r_type == BFD_RELOC_390_GOT16
01909       || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
01910       || fixP->fx_r_type == BFD_RELOC_390_GOT64
01911       || fixP->fx_r_type == BFD_RELOC_390_GOTENT
01912       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
01913       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16
01914       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20
01915       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32
01916       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64
01917       || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT
01918       || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD
01919       || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL
01920       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL
01921       || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32
01922       || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64
01923       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12
01924       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20
01925       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32
01926       || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64
01927       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32
01928       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64
01929       || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32
01930       || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64
01931       || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT
01932       || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32
01933       || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64
01934       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32
01935       || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64
01936       || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD
01937       || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF
01938       || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF
01939       || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
01940       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
01941     return 0;
01942   return 1;
01943 }
01944 
01945 /* Return true if we must always emit a reloc for a type and false if
01946    there is some hope of resolving it at assembly time.  */
01947 int
01948 tc_s390_force_relocation (fixp)
01949      struct fix *fixp;
01950 {
01951   /* Ensure we emit a relocation for every reference to the global
01952      offset table or to the procedure link table.  */
01953   switch (fixp->fx_r_type)
01954     {
01955     case BFD_RELOC_390_GOT12:
01956     case BFD_RELOC_390_GOT20:
01957     case BFD_RELOC_32_GOT_PCREL:
01958     case BFD_RELOC_32_GOTOFF:
01959     case BFD_RELOC_390_GOTOFF64:
01960     case BFD_RELOC_390_PLTOFF16:
01961     case BFD_RELOC_390_PLTOFF32:
01962     case BFD_RELOC_390_PLTOFF64:
01963     case BFD_RELOC_390_GOTPC:
01964     case BFD_RELOC_390_GOT16:
01965     case BFD_RELOC_390_GOTPCDBL:
01966     case BFD_RELOC_390_GOT64:
01967     case BFD_RELOC_390_GOTENT:
01968     case BFD_RELOC_390_PLT32:
01969     case BFD_RELOC_390_PLT16DBL:
01970     case BFD_RELOC_390_PLT32DBL:
01971     case BFD_RELOC_390_PLT64:
01972     case BFD_RELOC_390_GOTPLT12:
01973     case BFD_RELOC_390_GOTPLT16:
01974     case BFD_RELOC_390_GOTPLT20:
01975     case BFD_RELOC_390_GOTPLT32:
01976     case BFD_RELOC_390_GOTPLT64:
01977     case BFD_RELOC_390_GOTPLTENT:
01978       return 1;
01979     default:
01980       break;;
01981     }
01982 
01983   return generic_force_reloc (fixp);
01984 }
01985 
01986 /* Apply a fixup to the object code.  This is called for all the
01987    fixups we generated by the call to fix_new_exp, above.  In the call
01988    above we used a reloc code which was the largest legal reloc code
01989    plus the operand index.  Here we undo that to recover the operand
01990    index.  At this point all symbol values should be fully resolved,
01991    and we attempt to completely resolve the reloc.  If we can not do
01992    that, we determine the correct reloc code and put it back in the
01993    fixup.  */
01994 
01995 void
01996 md_apply_fix (fixP, valP, seg)
01997      fixS *fixP;
01998      valueT *valP;
01999      segT seg ATTRIBUTE_UNUSED;
02000 {
02001   char *where;
02002   valueT value = *valP;
02003 
02004   where = fixP->fx_frag->fr_literal + fixP->fx_where;
02005 
02006   if (fixP->fx_subsy != NULL)
02007     as_bad_where (fixP->fx_file, fixP->fx_line,
02008                 "cannot emit relocation %s against subsy symbol %s",
02009                 bfd_get_reloc_code_name (fixP->fx_r_type),
02010                 S_GET_NAME (fixP->fx_subsy));
02011 
02012   if (fixP->fx_addsy != NULL)
02013     {
02014       if (fixP->fx_pcrel)
02015        value += fixP->fx_frag->fr_address + fixP->fx_where;
02016     }
02017   else
02018     fixP->fx_done = 1;
02019 
02020   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
02021     {
02022       const struct s390_operand *operand;
02023       int opindex;
02024 
02025       opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
02026       operand = &s390_operands[opindex];
02027 
02028       if (fixP->fx_done)
02029        {
02030          /* Insert the fully resolved operand value.  */
02031          s390_insert_operand ((unsigned char *) where, operand,
02032                             (offsetT) value, fixP->fx_file, fixP->fx_line);
02033          return;
02034        }
02035 
02036       /* Determine a BFD reloc value based on the operand information.
02037         We are only prepared to turn a few of the operands into
02038         relocs.  */
02039       fixP->fx_offset = value;
02040       if (operand->bits == 12 && operand->shift == 20)
02041        {
02042          fixP->fx_size = 2;
02043          fixP->fx_where += 2;
02044          fixP->fx_r_type = BFD_RELOC_390_12;
02045        }
02046       else if (operand->bits == 12 && operand->shift == 36)
02047        {
02048          fixP->fx_size = 2;
02049          fixP->fx_where += 4;
02050          fixP->fx_r_type = BFD_RELOC_390_12;
02051        }
02052       else if (operand->bits == 20 && operand->shift == 20)
02053        {
02054          fixP->fx_size = 2;
02055          fixP->fx_where += 2;
02056          fixP->fx_r_type = BFD_RELOC_390_20;
02057        }
02058       else if (operand->bits == 8 && operand->shift == 8)
02059        {
02060          fixP->fx_size = 1;
02061          fixP->fx_where += 1;
02062          fixP->fx_r_type = BFD_RELOC_8;
02063        }
02064       else if (operand->bits == 16 && operand->shift == 16)
02065        {
02066          fixP->fx_size = 2;
02067          fixP->fx_where += 2;
02068          if (operand->flags & S390_OPERAND_PCREL)
02069            {
02070              fixP->fx_r_type = BFD_RELOC_390_PC16DBL;
02071              fixP->fx_offset += 2;
02072            }
02073          else
02074            fixP->fx_r_type = BFD_RELOC_16;
02075        }
02076       else if (operand->bits == 32 && operand->shift == 16
02077               && (operand->flags & S390_OPERAND_PCREL))
02078        {
02079          fixP->fx_size = 4;
02080          fixP->fx_where += 2;
02081          fixP->fx_offset += 2;
02082          fixP->fx_r_type = BFD_RELOC_390_PC32DBL;
02083        }
02084       else
02085        {
02086          char *sfile;
02087          unsigned int sline;
02088 
02089          /* Use expr_symbol_where to see if this is an expression
02090             symbol.  */
02091          if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
02092            as_bad_where (fixP->fx_file, fixP->fx_line,
02093                        _("unresolved expression that must be resolved"));
02094          else
02095            as_bad_where (fixP->fx_file, fixP->fx_line,
02096                        _("unsupported relocation type"));
02097          fixP->fx_done = 1;
02098          return;
02099        }
02100     }
02101   else
02102     {
02103       switch (fixP->fx_r_type)
02104        {
02105        case BFD_RELOC_8:
02106          if (fixP->fx_pcrel)
02107            abort ();
02108          if (fixP->fx_done)
02109            md_number_to_chars (where, value, 1);
02110          break;
02111        case BFD_RELOC_390_12:
02112        case BFD_RELOC_390_GOT12:
02113        case BFD_RELOC_390_GOTPLT12:
02114          if (fixP->fx_done)
02115            {
02116              unsigned short mop;
02117 
02118              mop = bfd_getb16 ((unsigned char *) where);
02119              mop |= (unsigned short) (value & 0xfff);
02120              bfd_putb16 ((bfd_vma) mop, (unsigned char *) where);
02121            }
02122          break;
02123 
02124        case BFD_RELOC_390_20:
02125        case BFD_RELOC_390_GOT20:
02126        case BFD_RELOC_390_GOTPLT20:
02127          if (fixP->fx_done)
02128            {
02129              unsigned int mop;
02130              mop = bfd_getb32 ((unsigned char *) where);
02131              mop |= (unsigned int) ((value & 0xfff) << 8 |
02132                                  (value & 0xff000) >> 12);
02133              bfd_putb32 ((bfd_vma) mop, (unsigned char *) where);
02134            } 
02135          break;
02136 
02137        case BFD_RELOC_16:
02138        case BFD_RELOC_GPREL16:
02139        case BFD_RELOC_16_GOT_PCREL:
02140        case BFD_RELOC_16_GOTOFF:
02141          if (fixP->fx_pcrel)
02142            as_bad_where (fixP->fx_file, fixP->fx_line,
02143                        "cannot emit PC relative %s relocation%s%s",
02144                        bfd_get_reloc_code_name (fixP->fx_r_type),
02145                        fixP->fx_addsy != NULL ? " against " : "",
02146                        (fixP->fx_addsy != NULL
02147                         ? S_GET_NAME (fixP->fx_addsy)
02148                         : ""));
02149          if (fixP->fx_done)
02150            md_number_to_chars (where, value, 2);
02151          break;
02152        case BFD_RELOC_390_GOT16:
02153        case BFD_RELOC_390_PLTOFF16:
02154        case BFD_RELOC_390_GOTPLT16:
02155          if (fixP->fx_done)
02156            md_number_to_chars (where, value, 2);
02157          break;
02158        case BFD_RELOC_390_PC16DBL:
02159        case BFD_RELOC_390_PLT16DBL:
02160          value += 2;
02161          if (fixP->fx_done)
02162            md_number_to_chars (where, (offsetT) value >> 1, 2);
02163          break;
02164 
02165        case BFD_RELOC_32:
02166          if (fixP->fx_pcrel)
02167            fixP->fx_r_type = BFD_RELOC_32_PCREL;
02168          else
02169            fixP->fx_r_type = BFD_RELOC_32;
02170          if (fixP->fx_done)
02171            md_number_to_chars (where, value, 4);
02172          break;
02173        case BFD_RELOC_32_PCREL:
02174        case BFD_RELOC_32_BASEREL:
02175          fixP->fx_r_type = BFD_RELOC_32_PCREL;
02176          if (fixP->fx_done)
02177            md_number_to_chars (where, value, 4);
02178          break;
02179        case BFD_RELOC_32_GOT_PCREL:
02180        case BFD_RELOC_390_PLTOFF32:
02181        case BFD_RELOC_390_PLT32:
02182        case BFD_RELOC_390_GOTPLT32:
02183          if (fixP->fx_done)
02184            md_number_to_chars (where, value, 4);
02185          break;
02186        case BFD_RELOC_390_PC32DBL:
02187        case BFD_RELOC_390_PLT32DBL:
02188        case BFD_RELOC_390_GOTPCDBL:
02189        case BFD_RELOC_390_GOTENT:
02190        case BFD_RELOC_390_GOTPLTENT:
02191          value += 2;
02192          if (fixP->fx_done)
02193            md_number_to_chars (where, (offsetT) value >> 1, 4);
02194          break;
02195 
02196        case BFD_RELOC_32_GOTOFF:
02197          if (fixP->fx_done)
02198            md_number_to_chars (where, value, sizeof (int));
02199          break;
02200 
02201        case BFD_RELOC_390_GOTOFF64:
02202          if (fixP->fx_done)
02203            md_number_to_chars (where, value, 8);
02204          break;
02205 
02206        case BFD_RELOC_390_GOT64:
02207        case BFD_RELOC_390_PLTOFF64:
02208        case BFD_RELOC_390_PLT64:
02209        case BFD_RELOC_390_GOTPLT64:
02210          if (fixP->fx_done)
02211            md_number_to_chars (where, value, 8);
02212          break;
02213 
02214        case BFD_RELOC_64:
02215          if (fixP->fx_pcrel)
02216            fixP->fx_r_type = BFD_RELOC_64_PCREL;
02217          else
02218            fixP->fx_r_type = BFD_RELOC_64;
02219          if (fixP->fx_done)
02220            md_number_to_chars (where, value, 8);
02221          break;
02222 
02223        case BFD_RELOC_64_PCREL:
02224          fixP->fx_r_type = BFD_RELOC_64_PCREL;
02225          if (fixP->fx_done)
02226            md_number_to_chars (where, value, 8);
02227          break;
02228 
02229        case BFD_RELOC_VTABLE_INHERIT:
02230        case BFD_RELOC_VTABLE_ENTRY:
02231          fixP->fx_done = 0;
02232          return;
02233 
02234        case BFD_RELOC_390_TLS_LOAD:
02235        case BFD_RELOC_390_TLS_GDCALL:
02236        case BFD_RELOC_390_TLS_LDCALL:
02237        case BFD_RELOC_390_TLS_GD32:
02238        case BFD_RELOC_390_TLS_GD64:
02239        case BFD_RELOC_390_TLS_GOTIE12:
02240        case BFD_RELOC_390_TLS_GOTIE20:
02241        case BFD_RELOC_390_TLS_GOTIE32:
02242        case BFD_RELOC_390_TLS_GOTIE64:
02243        case BFD_RELOC_390_TLS_LDM32:
02244        case BFD_RELOC_390_TLS_LDM64:
02245        case BFD_RELOC_390_TLS_IE32:
02246        case BFD_RELOC_390_TLS_IE64:
02247        case BFD_RELOC_390_TLS_LE32:
02248        case BFD_RELOC_390_TLS_LE64:
02249        case BFD_RELOC_390_TLS_LDO32:
02250        case BFD_RELOC_390_TLS_LDO64:
02251        case BFD_RELOC_390_TLS_DTPMOD:
02252        case BFD_RELOC_390_TLS_DTPOFF:
02253        case BFD_RELOC_390_TLS_TPOFF:
02254          S_SET_THREAD_LOCAL (fixP->fx_addsy);
02255          /* Fully resolved at link time.  */
02256          break;
02257        case BFD_RELOC_390_TLS_IEENT:
02258          /* Fully resolved at link time.  */
02259          S_SET_THREAD_LOCAL (fixP->fx_addsy);
02260          value += 2;
02261          break;
02262 
02263        default:
02264          {
02265            const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type);
02266 
02267            if (reloc_name != NULL)
02268              fprintf (stderr, "Gas failure, reloc type %s\n", reloc_name);
02269            else
02270              fprintf (stderr, "Gas failure, reloc type #%i\n", fixP->fx_r_type);
02271            fflush (stderr);
02272            abort ();
02273          }
02274        }
02275 
02276       fixP->fx_offset = value;
02277     }
02278 }
02279 
02280 /* Generate a reloc for a fixup.  */
02281 
02282 arelent *
02283 tc_gen_reloc (seg, fixp)
02284      asection *seg ATTRIBUTE_UNUSED;
02285      fixS *fixp;
02286 {
02287   bfd_reloc_code_real_type code;
02288   arelent *reloc;
02289 
02290   code = fixp->fx_r_type;
02291   if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
02292     {
02293       if (   (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
02294          || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
02295        code = BFD_RELOC_390_GOTPC;
02296       if (code == BFD_RELOC_390_PC32DBL)
02297        code = BFD_RELOC_390_GOTPCDBL;
02298     }
02299 
02300   reloc = (arelent *) xmalloc (sizeof (arelent));
02301   reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
02302   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
02303   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
02304   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
02305   if (reloc->howto == NULL)
02306     {
02307       as_bad_where (fixp->fx_file, fixp->fx_line,
02308                   _("cannot represent relocation type %s"),
02309                   bfd_get_reloc_code_name (code));
02310       /* Set howto to a garbage value so that we can keep going.  */
02311       reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
02312       assert (reloc->howto != NULL);
02313     }
02314   reloc->addend = fixp->fx_offset;
02315 
02316   return reloc;
02317 }
02318 
02319 void
02320 s390_cfi_frame_initial_instructions ()
02321 {
02322   cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96);
02323 }
02324 
02325 int
02326 tc_s390_regname_to_dw2regnum (char *regname)
02327 {
02328   int regnum = -1;
02329 
02330   if (regname[0] != 'c' && regname[0] != 'a')
02331     {
02332       regnum = reg_name_search (pre_defined_registers, REG_NAME_CNT, regname);
02333       if (regname[0] == 'f' && regnum != -1)
02334         regnum += 16;
02335     }
02336   else if (strcmp (regname, "ap") == 0)
02337     regnum = 32;
02338   else if (strcmp (regname, "cc") == 0)
02339     regnum = 33;
02340   return regnum;
02341 }