Home | History | Annotate | Download | only in config
      1 /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set.
      2    Loosely based on the ppc files by Linas Vepstas <linas (at) linas.org> 1998, 99
      3    Copyright (C) 1994-2016 Free Software Foundation, Inc.
      4    Written by Ian Lance Taylor, Cygnus Support.
      5 
      6    This file is part of GAS, the GNU Assembler.
      7 
      8    GAS is free software; you can redistribute it and/or modify
      9    it under the terms of the GNU General Public License as published by
     10    the Free Software Foundation; either version 3, or (at your option)
     11    any later version.
     12 
     13    GAS is distributed in the hope that it will be useful,
     14    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16    GNU General Public License for more details.
     17 
     18    You should have received a copy of the GNU General Public License
     19    along with GAS; see the file COPYING.  If not, write to the Free
     20    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     21    02110-1301, USA.  */
     22 
     23 /* This assembler implements a very hacked version of an elf-like thing
     24    that gcc emits (when gcc is suitably hacked).  To make it behave more
     25    HLASM-like, try turning on the -M or --mri flag (as there are various
     26    similarities between HLASM and the MRI assemblers, such as section
     27    names, lack of leading . in pseudo-ops, DC and DS, etc.  */
     28 
     29 #include "as.h"
     30 #include "safe-ctype.h"
     31 #include "subsegs.h"
     32 #include "struc-symbol.h"
     33 
     34 #include "opcode/i370.h"
     35 
     36 #ifdef OBJ_ELF
     37 #include "elf/i370.h"
     38 #endif
     39 
     40 /* This is the assembler for the System/390 Architecture.  */
     41 
     42 /* Tell the main code what the endianness is.  */
     43 extern int target_big_endian;
     44 
     45 
     46 /* Generic assembler global variables which must be defined by all
     48    targets.  */
     49 
     50 #ifdef OBJ_ELF
     51 /* This string holds the chars that always start a comment.  If the
     52    pre-processor is disabled, these aren't very useful.  The macro
     53    tc_comment_chars points to this.  We use this, rather than the
     54    usual comment_chars, so that we can switch for Solaris conventions.  */
     55 static const char i370_eabi_comment_chars[] = "#";
     56 
     57 const char *i370_comment_chars = i370_eabi_comment_chars;
     58 #else
     59 const char comment_chars[] = "#";
     60 #endif
     61 
     62 /* Characters which start a comment at the beginning of a line.  */
     63 const char line_comment_chars[] = "#*";
     64 
     65 /* Characters which may be used to separate multiple commands on a
     66    single line.  */
     67 const char line_separator_chars[] = ";";
     68 
     69 /* Characters which are used to indicate an exponent in a floating
     70    point number.  */
     71 const char EXP_CHARS[] = "eE";
     72 
     73 /* Characters which mean that a number is a floating point constant,
     74    as in 0d1.0.  */
     75 const char FLT_CHARS[] = "dD";
     76 
     77 void
     78 md_show_usage (FILE *stream)
     79 {
     80   fprintf (stream, "\
     81 S/370 options: (these have not yet been tested and may not work) \n\
     82 -u        		ignored\n\
     83 -mregnames        	Allow symbolic names for registers\n\
     84 -mno-regnames        	Do not allow symbolic names for registers\n");
     85 #ifdef OBJ_ELF
     86   fprintf (stream, "\
     87 -mrelocatable        	support for GCC's -mrelocatble option\n\
     88 -mrelocatable-lib       support for GCC's -mrelocatble-lib option\n\
     89 -V        		print assembler version number\n");
     90 #endif
     91 }
     92 
     93 /* Whether to use user friendly register names.  */
     94 #define TARGET_REG_NAMES_P TRUE
     95 
     96 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
     97 
     98 
     99 /* Predefined register names if -mregnames
    101    In general, there are lots of them, in an attempt to be compatible
    102    with a number of assemblers.  */
    103 
    104 /* Structure to hold information about predefined registers.  */
    105 struct pd_reg
    106   {
    107     const char *name;
    108     int value;
    109   };
    110 
    111 /* List of registers that are pre-defined:
    112 
    113    Each general register has predefined names of the form:
    114    1. r<reg_num> which has the value <reg_num>.
    115    2. r.<reg_num> which has the value <reg_num>.
    116 
    117    Each floating point register has predefined names of the form:
    118    1. f<reg_num> which has the value <reg_num>.
    119    2. f.<reg_num> which has the value <reg_num>.
    120 
    121    There are only four floating point registers, and these are
    122    commonly labelled 0,2,4 and 6.  Thus, there is no f1, f3, etc.
    123 
    124    There are individual registers as well:
    125    rbase or r.base has the value  3  (base register)
    126    rpgt or r.pgt   has the value  4  (page origin table pointer)
    127    rarg or r.arg   has the value 11  (argument pointer)
    128    rtca or r.tca   has the value 12  (table of contents pointer)
    129    rtoc or r.toc   has the value 12  (table of contents pointer)
    130    sp or r.sp      has the value 13  (stack pointer)
    131    dsa or r.dsa    has the value 13  (stack pointer)
    132    lr              has the value 14  (link reg)
    133 
    134    The table is sorted. Suitable for searching by a binary search.  */
    135 
    136 static const struct pd_reg pre_defined_registers[] =
    137 {
    138   { "arg", 11 },   /* Argument Pointer.  */
    139   { "base", 3 },   /* Base Reg.  */
    140 
    141   { "f.0", 0 },    /* Floating point registers.  */
    142   { "f.2", 2 },
    143   { "f.4", 4 },
    144   { "f.6", 6 },
    145 
    146   { "f0", 0 },
    147   { "f2", 2 },
    148   { "f4", 4 },
    149   { "f6", 6 },
    150 
    151   { "dsa",13 },    /* Stack pointer.  */
    152   { "lr", 14 },    /* Link Register.  */
    153   { "pgt", 4 },    /* Page Origin Table Pointer.  */
    154 
    155   { "r.0", 0 },    /* General Purpose Registers.  */
    156   { "r.1", 1 },
    157   { "r.10", 10 },
    158   { "r.11", 11 },
    159   { "r.12", 12 },
    160   { "r.13", 13 },
    161   { "r.14", 14 },
    162   { "r.15", 15 },
    163   { "r.2", 2 },
    164   { "r.3", 3 },
    165   { "r.4", 4 },
    166   { "r.5", 5 },
    167   { "r.6", 6 },
    168   { "r.7", 7 },
    169   { "r.8", 8 },
    170   { "r.9", 9 },
    171 
    172   { "r.arg", 11 },  /* Argument Pointer.  */
    173   { "r.base", 3 },  /* Base Reg.  */
    174   { "r.dsa", 13 },  /* Stack Pointer.  */
    175   { "r.pgt", 4 },   /* Page Origin Table Pointer.  */
    176   { "r.sp", 13 },   /* Stack Pointer.  */
    177 
    178   { "r.tca", 12 },  /* Pointer to the table of contents.  */
    179   { "r.toc", 12 },  /* Pointer to the table of contents.  */
    180 
    181   { "r0", 0 },      /* More general purpose registers.  */
    182   { "r1", 1 },
    183   { "r10", 10 },
    184   { "r11", 11 },
    185   { "r12", 12 },
    186   { "r13", 13 },
    187   { "r14", 14 },
    188   { "r15", 15 },
    189   { "r2", 2 },
    190   { "r3", 3 },
    191   { "r4", 4 },
    192   { "r5", 5 },
    193   { "r6", 6 },
    194   { "r7", 7 },
    195   { "r8", 8 },
    196   { "r9", 9 },
    197 
    198   { "rbase", 3 },  /* Base Reg.  */
    199 
    200   { "rtca", 12 },  /* Pointer to the table of contents.  */
    201   { "rtoc", 12 },  /* Pointer to the table of contents.  */
    202 
    203   { "sp", 13 },   /* Stack Pointer.  */
    204 
    205 };
    206 
    207 #define REG_NAME_CNT        (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
    208 
    209 /* Given NAME, find the register number associated with that name, return
    210    the integer value associated with the given name or -1 on failure.  */
    211 
    212 static int
    213 reg_name_search (const struct pd_reg *regs,
    214 		 int regcount,
    215 		 const char *name)
    216 {
    217   int middle, low, high;
    218   int cmp;
    219 
    220   low = 0;
    221   high = regcount - 1;
    222 
    223   do
    224     {
    225       middle = (low + high) / 2;
    226       cmp = strcasecmp (name, regs[middle].name);
    227       if (cmp < 0)
    228         high = middle - 1;
    229       else if (cmp > 0)
    230         low = middle + 1;
    231       else
    232         return regs[middle].value;
    233     }
    234   while (low <= high);
    235 
    236   return -1;
    237 }
    238 
    239 /* Summary of register_name().
    240 
    241    in:        Input_line_pointer points to 1st char of operand.
    242 
    243    out:        An expressionS.
    244         The operand may have been a register: in this case, X_op == O_register,
    245         X_add_number is set to the register number, and truth is returned.
    246           Input_line_pointer->(next non-blank) char after operand, or is in its
    247         original state.  */
    248 
    249 static bfd_boolean
    250 register_name (expressionS *expressionP)
    251 {
    252   int reg_number;
    253   char *name;
    254   char *start;
    255   char c;
    256 
    257   /* Find the spelling of the operand.  */
    258   start = name = input_line_pointer;
    259   if (name[0] == '%' && ISALPHA (name[1]))
    260     name = ++input_line_pointer;
    261 
    262   else if (!reg_names_p)
    263     return FALSE;
    264 
    265   while (' ' == *name)
    266     name = ++input_line_pointer;
    267 
    268   /* If it's a number, treat it as a number.  If it's alpha, look to
    269      see if it's in the register table.  */
    270   if (!ISALPHA (name[0]))
    271     reg_number = get_single_number ();
    272   else
    273     {
    274       c = get_symbol_name (&name);
    275       reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
    276 
    277       /* Put back the delimiting char.  */
    278       (void) restore_line_pointer (c);
    279     }
    280 
    281   /* If numeric, make sure its not out of bounds.  */
    282   if ((0 <= reg_number) && (16 >= reg_number))
    283     {
    284       expressionP->X_op = O_register;
    285       expressionP->X_add_number = reg_number;
    286 
    287       /* Make the rest nice.  */
    288       expressionP->X_add_symbol = NULL;
    289       expressionP->X_op_symbol = NULL;
    290       return TRUE;
    291     }
    292 
    293   /* Reset the line as if we had not done anything.  */
    294   input_line_pointer = start;
    295   return FALSE;
    296 }
    297 
    298 /* Local variables.  */
    300 
    301 /* The type of processor we are assembling for.  This is one or more
    302    of the I370_OPCODE flags defined in opcode/i370.h.  */
    303 static int i370_cpu = 0;
    304 
    305 /* The base register to use for opcode with optional operands.
    306    We define two of these: "text" and "other".  Normally, "text"
    307    would get used in the .text section for branches, while "other"
    308    gets used in the .data section for address constants.
    309 
    310    The idea of a second base register in a different section
    311    is foreign to the usual HLASM-style semantics; however, it
    312    allows us to provide support for dynamically loaded libraries,
    313    by allowing us to place address constants in a section other
    314    than the text section. The "other" section need not be the
    315    .data section, it can be any section that isn't the .text section.
    316 
    317    Note that HLASM defines a multiple, concurrent .using semantic
    318    that we do not: in calculating offsets, it uses either the most
    319    recent .using directive, or the one with the smallest displacement.
    320    This allows HLASM to support a quasi-block-scope-like behaviour.
    321    Handy for people writing assembly by hand ... but not supported
    322    by us.  */
    323 static int i370_using_text_regno = -1;
    324 static int i370_using_other_regno = -1;
    325 
    326 /* The base address for address literals.  */
    327 static expressionS i370_using_text_baseaddr;
    328 static expressionS i370_using_other_baseaddr;
    329 
    330 /* the "other" section, used only for syntax error detection.  */
    331 static segT i370_other_section = undefined_section;
    332 
    333 /* Opcode hash table.  */
    334 static struct hash_control *i370_hash;
    335 
    336 /* Macro hash table.  */
    337 static struct hash_control *i370_macro_hash;
    338 
    339 #ifdef OBJ_ELF
    340 /* What type of shared library support to use.  */
    341 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
    342 #endif
    343 
    344 /* Flags to set in the elf header.  */
    345 static flagword i370_flags = 0;
    346 
    347 #ifndef WORKING_DOT_WORD
    348 int md_short_jump_size = 4;
    349 int md_long_jump_size = 4;
    350 #endif
    351 
    352 #ifdef OBJ_ELF
    354 const char *md_shortopts = "l:um:K:VQ:";
    355 #else
    356 const char *md_shortopts = "um:";
    357 #endif
    358 struct option md_longopts[] =
    359 {
    360   {NULL, no_argument, NULL, 0}
    361 };
    362 size_t md_longopts_size = sizeof (md_longopts);
    363 
    364 int
    365 md_parse_option (int c, const char *arg)
    366 {
    367   switch (c)
    368     {
    369     case 'u':
    370       /* -u means that any undefined symbols should be treated as
    371          external, which is the default for gas anyhow.  */
    372       break;
    373 
    374 #ifdef OBJ_ELF
    375     case 'K':
    376       /* Recognize -K PIC */
    377       if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
    378         {
    379           shlib = SHLIB_PIC;
    380           i370_flags |= EF_I370_RELOCATABLE_LIB;
    381         }
    382       else
    383         return 0;
    384 
    385       break;
    386 #endif
    387 
    388     case 'm':
    389 
    390       /* -m360 mean to assemble for the ancient 360 architecture.  */
    391       if (strcmp (arg, "360") == 0 || strcmp (arg, "i360") == 0)
    392 	i370_cpu = I370_OPCODE_360;
    393       /* -mxa means to assemble for the IBM 370 XA.  */
    394       else if (strcmp (arg, "xa") == 0)
    395 	i370_cpu = I370_OPCODE_370_XA;
    396       /* -many means to assemble for any architecture (370/XA).  */
    397       else if (strcmp (arg, "any") == 0)
    398 	i370_cpu = I370_OPCODE_370;
    399 
    400       else if (strcmp (arg, "regnames") == 0)
    401 	reg_names_p = TRUE;
    402 
    403       else if (strcmp (arg, "no-regnames") == 0)
    404 	reg_names_p = FALSE;
    405 
    406 #ifdef OBJ_ELF
    407       /* -mrelocatable/-mrelocatable-lib -- warn about
    408 	 initializations that require relocation.  */
    409       else if (strcmp (arg, "relocatable") == 0)
    410         {
    411           shlib = SHILB_MRELOCATABLE;
    412           i370_flags |= EF_I370_RELOCATABLE;
    413         }
    414       else if (strcmp (arg, "relocatable-lib") == 0)
    415         {
    416           shlib = SHILB_MRELOCATABLE;
    417           i370_flags |= EF_I370_RELOCATABLE_LIB;
    418         }
    419 #endif
    420       else
    421         {
    422           as_bad (_("invalid switch -m%s"), arg);
    423           return 0;
    424         }
    425       break;
    426 
    427 #ifdef OBJ_ELF
    428       /* -V: SVR4 argument to print version ID.  */
    429     case 'V':
    430       print_version_id ();
    431       break;
    432 
    433       /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
    434          should be emitted or not.  FIXME: Not implemented.  */
    435     case 'Q':
    436       break;
    437 
    438 #endif
    439 
    440     default:
    441       return 0;
    442     }
    443 
    444   return 1;
    445 }
    446 
    447 
    448 /* Set i370_cpu if it is not already set.
    450    Currently defaults to the reasonable superset;
    451    but can be made more fine grained if desred.  */
    452 
    453 static void
    454 i370_set_cpu (void)
    455 {
    456   const char *default_os  = TARGET_OS;
    457   const char *default_cpu = TARGET_CPU;
    458 
    459   /* Override with the superset for the moment.  */
    460   i370_cpu = I370_OPCODE_ESA390_SUPERSET;
    461   if (i370_cpu == 0)
    462     {
    463       if (strcmp (default_cpu, "i360") == 0)
    464         i370_cpu = I370_OPCODE_360;
    465       else if (strcmp (default_cpu, "i370") == 0)
    466         i370_cpu = I370_OPCODE_370;
    467       else if (strcmp (default_cpu, "XA") == 0)
    468         i370_cpu = I370_OPCODE_370_XA;
    469       else
    470         as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
    471     }
    472 }
    473 
    474 /* Figure out the BFD architecture to use.
    475    FIXME: specify the different 370 architectures.  */
    476 
    477 enum bfd_architecture
    478 i370_arch (void)
    479 {
    480    return bfd_arch_i370;
    481 }
    482 
    483 /* This function is called when the assembler starts up.  It is called
    484    after the options have been parsed and the output file has been
    485    opened.  */
    486 
    487 void
    488 md_begin (void)
    489 {
    490   const struct i370_opcode *op;
    491   const struct i370_opcode *op_end;
    492   const struct i370_macro *macro;
    493   const struct i370_macro *macro_end;
    494   bfd_boolean dup_insn = FALSE;
    495 
    496   i370_set_cpu ();
    497 
    498 #ifdef OBJ_ELF
    499   /* Set the ELF flags if desired.  */
    500   if (i370_flags)
    501     bfd_set_private_flags (stdoutput, i370_flags);
    502 #endif
    503 
    504   /* Insert the opcodes into a hash table.  */
    505   i370_hash = hash_new ();
    506 
    507    op_end = i370_opcodes + i370_num_opcodes;
    508    for (op = i370_opcodes; op < op_end; op++)
    509      {
    510        know ((op->opcode.i[0] & op->mask.i[0]) == op->opcode.i[0]
    511 	     && (op->opcode.i[1] & op->mask.i[1]) == op->opcode.i[1]);
    512 
    513        if ((op->flags & i370_cpu) != 0)
    514          {
    515            const char *retval;
    516 
    517            retval = hash_insert (i370_hash, op->name, (void *) op);
    518            if (retval != (const char *) NULL)
    519              {
    520                as_bad (_("Internal assembler error for instruction %s"), op->name);
    521                dup_insn = TRUE;
    522              }
    523          }
    524      }
    525 
    526   /* Insert the macros into a hash table.  */
    527   i370_macro_hash = hash_new ();
    528 
    529   macro_end = i370_macros + i370_num_macros;
    530   for (macro = i370_macros; macro < macro_end; macro++)
    531     {
    532       if ((macro->flags & i370_cpu) != 0)
    533         {
    534           const char *retval;
    535 
    536           retval = hash_insert (i370_macro_hash, macro->name, (void *) macro);
    537           if (retval != (const char *) NULL)
    538             {
    539               as_bad (_("Internal assembler error for macro %s"), macro->name);
    540               dup_insn = TRUE;
    541             }
    542         }
    543     }
    544 
    545   if (dup_insn)
    546     abort ();
    547 }
    548 
    549 /* Insert an operand value into an instruction.  */
    550 
    551 static i370_insn_t
    552 i370_insert_operand (i370_insn_t insn,
    553 		     const struct i370_operand *operand,
    554 		     offsetT val)
    555 {
    556   if (operand->insert)
    557     {
    558       const char *errmsg;
    559 
    560       /* Used for 48-bit insn's.  */
    561       errmsg = NULL;
    562       insn = (*operand->insert) (insn, (long) val, &errmsg);
    563       if (errmsg)
    564         as_bad ("%s", errmsg);
    565     }
    566   else
    567     /* This is used only for 16, 32 bit insn's.  */
    568     insn.i[0] |= (((long) val & ((1 << operand->bits) - 1))
    569 		  << operand->shift);
    570 
    571   return insn;
    572 }
    573 
    574 
    575 #ifdef OBJ_ELF
    577 /* Parse @got, etc. and return the desired relocation.
    578    Currently, i370 does not support (don't really need to support) any
    579    of these fancier markups ... for example, no one is going to
    580    write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
    581    So basically, we could get away with this routine returning
    582    BFD_RELOC_UNUSED in all circumstances.  However, I'll leave
    583    in for now in case someone ambitious finds a good use for this stuff ...
    584    this routine was pretty much just copied from the powerpc code ...  */
    585 
    586 static bfd_reloc_code_real_type
    587 i370_elf_suffix (char **str_p, expressionS *exp_p)
    588 {
    589   struct map_bfd
    590   {
    591     const char *string;
    592     int length;
    593     bfd_reloc_code_real_type reloc;
    594   };
    595 
    596   char ident[20];
    597   char *str = *str_p;
    598   char *str2;
    599   int ch;
    600   int len;
    601   struct map_bfd *ptr;
    602 
    603 #define MAP(str,reloc) { str, sizeof (str) - 1, reloc }
    604 
    605   static struct map_bfd mapping[] =
    606   {
    607     /* warnings with -mrelocatable.  */
    608     MAP ("fixup",	BFD_RELOC_CTOR),
    609     { (char *)0, 0,	BFD_RELOC_UNUSED }
    610   };
    611 
    612   if (*str++ != '@')
    613     return BFD_RELOC_UNUSED;
    614 
    615   for (ch = *str, str2 = ident;
    616        (str2 < ident + sizeof (ident) - 1
    617         && (ISALNUM (ch) || ch == '@'));
    618        ch = *++str)
    619     *str2++ = TOLOWER (ch);
    620 
    621   *str2 = '\0';
    622   len = str2 - ident;
    623 
    624   ch = ident[0];
    625   for (ptr = &mapping[0]; ptr->length > 0; ptr++)
    626     if (ch == ptr->string[0]
    627         && len == ptr->length
    628         && memcmp (ident, ptr->string, ptr->length) == 0)
    629       {
    630         if (exp_p->X_add_number != 0
    631             && (ptr->reloc == BFD_RELOC_16_GOTOFF
    632         	|| ptr->reloc == BFD_RELOC_LO16_GOTOFF
    633         	|| ptr->reloc == BFD_RELOC_HI16_GOTOFF
    634         	|| ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
    635           as_warn (_("identifier+constant@got means identifier@got+constant"));
    636 
    637         /* Now check for identifier@suffix+constant */
    638         if (*str == '-' || *str == '+')
    639           {
    640             char *orig_line = input_line_pointer;
    641             expressionS new_exp;
    642 
    643             input_line_pointer = str;
    644             expression (&new_exp);
    645             if (new_exp.X_op == O_constant)
    646               {
    647         	exp_p->X_add_number += new_exp.X_add_number;
    648         	str = input_line_pointer;
    649               }
    650 
    651             if (&input_line_pointer != str_p)
    652               input_line_pointer = orig_line;
    653           }
    654 
    655         *str_p = str;
    656         return ptr->reloc;
    657       }
    658 
    659   return BFD_RELOC_UNUSED;
    660 }
    661 
    662 /* Like normal .long/.short/.word, except support @got, etc.
    663    Clobbers input_line_pointer, checks end-of-line.  */
    664 
    665 static void
    666 i370_elf_cons (int nbytes)   /* 1=.byte, 2=.word, 4=.long.  */
    667 {
    668   expressionS exp;
    669   bfd_reloc_code_real_type reloc;
    670 
    671   if (is_it_end_of_statement ())
    672     {
    673       demand_empty_rest_of_line ();
    674       return;
    675     }
    676 
    677   do
    678     {
    679       expression (&exp);
    680 
    681       if (exp.X_op == O_symbol
    682           && *input_line_pointer == '@'
    683           && (reloc = i370_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
    684         {
    685           reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
    686           int size = bfd_get_reloc_size (reloc_howto);
    687 
    688           if (size > nbytes)
    689             as_bad (_("%s relocations do not fit in %d bytes\n"),
    690 		    reloc_howto->name, nbytes);
    691           else
    692             {
    693               char *p = frag_more ((int) nbytes);
    694               int offset = nbytes - size;
    695 
    696               fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
    697             }
    698         }
    699       else
    700         emit_expr (&exp, (unsigned int) nbytes);
    701     }
    702   while (*input_line_pointer++ == ',');
    703 
    704   input_line_pointer--;        	/* Put terminator back into stream.  */
    705   demand_empty_rest_of_line ();
    706 }
    707 
    708 
    709 /* ASCII to EBCDIC conversion table.  */
    711 static unsigned char ascebc[256] =
    712 {
    713  /*00  NL    SH    SX    EX    ET    NQ    AK    BL */
    714      0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
    715  /*08  BS    HT    LF    VT    FF    CR    SO    SI */
    716      0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
    717  /*10  DL    D1    D2    D3    D4    NK    SN    EB */
    718      0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
    719  /*18  CN    EM    SB    EC    FS    GS    RS    US */
    720      0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
    721  /*20  SP     !     "     #     $     %     &     ' */
    722      0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
    723  /*28   (     )     *     +     ,     -    .      / */
    724      0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
    725  /*30   0     1     2     3     4     5     6     7 */
    726      0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
    727  /*38   8     9     :     ;     <     =     >     ? */
    728      0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
    729  /*40   @     A     B     C     D     E     F     G */
    730      0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
    731  /*48   H     I     J     K     L     M     N     O */
    732      0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
    733  /*50   P     Q     R     S     T     U     V     W */
    734      0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
    735  /*58   X     Y     Z     [     \     ]     ^     _ */
    736      0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
    737  /*60   `     a     b     c     d     e     f     g */
    738      0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
    739  /*68   h     i     j     k     l     m     n     o */
    740      0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
    741  /*70   p     q     r     s     t     u     v     w */
    742      0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
    743  /*78   x     y     z     {     |     }     ~    DL */
    744      0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
    745      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    746      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    747      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    748      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    749      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    750      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    751      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    752      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    753      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    754      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    755      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    756      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    757      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    758      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    759      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
    760      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
    761 };
    762 
    763 /* EBCDIC to ASCII conversion table.  */
    764 unsigned char ebcasc[256] =
    765 {
    766  /*00  NU    SH    SX    EX    PF    HT    LC    DL */
    767      0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
    768  /*08              SM    VT    FF    CR    SO    SI */
    769      0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
    770  /*10  DE    D1    D2    TM    RS    NL    BS    IL */
    771      0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
    772  /*18  CN    EM    CC    C1    FS    GS    RS    US */
    773      0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
    774  /*20  DS    SS    FS          BP    LF    EB    EC */
    775      0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
    776  /*28              SM    C2    EQ    AK    BL       */
    777      0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
    778  /*30              SY          PN    RS    UC    ET */
    779      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
    780  /*38                    C3    D4    NK          SU */
    781      0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
    782  /*40  SP                                           */
    783      0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    784  /*48                     .     <     (     +     | */
    785      0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
    786  /*50   &                                           */
    787      0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    788  /*58               !     $     *     )     ;     ^ */
    789      0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
    790  /*60   -     /                                     */
    791      0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    792  /*68                     ,     %     _     >     ? */
    793      0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
    794  /*70                                               */
    795      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    796  /*78         `     :     #     @     '     =     " */
    797      0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
    798  /*80         a     b     c     d     e     f     g */
    799      0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
    800  /*88   h     i           {                         */
    801      0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
    802  /*90         j     k     l     m     n     o     p */
    803      0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
    804  /*98   q     r           }                         */
    805      0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
    806  /*A0         ~     s     t     u     v     w     x */
    807      0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
    808  /*A8   y     z                       [             */
    809      0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
    810  /*B0                                               */
    811      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    812  /*B8                                 ]             */
    813      0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
    814  /*C0   {     A     B     C     D     E     F     G */
    815      0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
    816  /*C8   H     I                                     */
    817      0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    818  /*D0   }     J     K     L     M     N     O     P */
    819      0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
    820  /*D8   Q     R                                     */
    821      0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    822  /*E0   \           S     T     U     V     W     X */
    823      0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
    824  /*E8   Y     Z                                     */
    825      0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    826  /*F0   0     1     2     3     4     5     6     7 */
    827      0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
    828  /*F8   8     9                                     */
    829      0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
    830 };
    831 
    832 /* EBCDIC translation tables needed for 3270 support.  */
    833 
    834 static void
    835 i370_ebcdic (int unused ATTRIBUTE_UNUSED)
    836 {
    837   char *p, *end;
    838   char delim = 0;
    839   size_t nbytes;
    840 
    841   nbytes = strlen (input_line_pointer);
    842   end = input_line_pointer + nbytes;
    843   while ('\r' == *end) end --;
    844   while ('\n' == *end) end --;
    845 
    846   delim = *input_line_pointer;
    847   if (('\'' == delim) || ('\"' == delim))
    848     {
    849       input_line_pointer ++;
    850       end = rindex (input_line_pointer, delim);
    851     }
    852 
    853   if (end > input_line_pointer)
    854     {
    855       nbytes = end - input_line_pointer +1;
    856       p = frag_more (nbytes);
    857       while (end > input_line_pointer)
    858 	{
    859 	  *p = ascebc [(unsigned char) (*input_line_pointer)];
    860 	  ++p; ++input_line_pointer;
    861 	}
    862       *p = '\0';
    863     }
    864   if (delim == *input_line_pointer) ++input_line_pointer;
    865 }
    866 
    867 
    868 /* Stub out a couple of routines.  */
    870 
    871 static void
    872 i370_rmode (int unused ATTRIBUTE_UNUSED)
    873 {
    874   as_tsktsk ("rmode ignored");
    875 }
    876 
    877 static void
    878 i370_dsect (int sect)
    879 {
    880   char *save_line = input_line_pointer;
    881   static char section[] = ".data\n";
    882 
    883   /* Just pretend this is .section .data.  */
    884   input_line_pointer = section;
    885   obj_elf_section (sect);
    886 
    887   input_line_pointer = save_line;
    888 }
    889 
    890 static void
    891 i370_csect (int unused ATTRIBUTE_UNUSED)
    892 {
    893   as_tsktsk ("csect not supported");
    894 }
    895 
    896 
    897 /* DC Define Const  is only partially supported.
    899    For samplecode on what to do, look at i370_elf_cons() above.
    900    This code handles pseudoops of the style
    901    DC   D'3.141592653'   # in sysv4, .double 3.14159265
    902    DC   F'1'             # in sysv4, .long   1.  */
    903 
    904 static void
    905 i370_dc (int unused ATTRIBUTE_UNUSED)
    906 {
    907   char * p, tmp[50];
    908   int nbytes=0;
    909   expressionS exp;
    910   char type=0;
    911   char * clse;
    912 
    913   if (is_it_end_of_statement ())
    914     {
    915       demand_empty_rest_of_line ();
    916       return;
    917     }
    918 
    919   /* Figure out the size.  */
    920   type = *input_line_pointer++;
    921   switch (type)
    922     {
    923     case 'H':  /* 16-bit */
    924       nbytes = 2;
    925       break;
    926     case 'E':  /* 32-bit */
    927     case 'F':  /* 32-bit */
    928       nbytes = 4;
    929       break;
    930     case 'D':  /* 64-bit */
    931       nbytes = 8;
    932       break;
    933     default:
    934       as_bad (_("unsupported DC type"));
    935       return;
    936     }
    937 
    938   /* Get rid of pesky quotes.  */
    939   if ('\'' == *input_line_pointer)
    940     {
    941       ++input_line_pointer;
    942       clse = strchr (input_line_pointer, '\'');
    943       if (clse)
    944 	*clse= ' ';
    945       else
    946 	as_bad (_("missing end-quote"));
    947     }
    948 
    949   if ('\"' == *input_line_pointer)
    950     {
    951       ++input_line_pointer;
    952       clse = strchr (input_line_pointer, '\"');
    953       if (clse)
    954 	*clse= ' ';
    955       else
    956 	as_bad (_("missing end-quote"));
    957     }
    958 
    959   switch (type)
    960     {
    961     case 'H':  /* 16-bit */
    962     case 'F':  /* 32-bit */
    963       expression (&exp);
    964       emit_expr (&exp, nbytes);
    965       break;
    966     case 'E':  /* 32-bit */
    967       type = 'f';
    968     case 'D':  /* 64-bit */
    969       md_atof (type, tmp, &nbytes);
    970       p = frag_more (nbytes);
    971       memcpy (p, tmp, nbytes);
    972       break;
    973     default:
    974       as_bad (_("unsupported DC type"));
    975       return;
    976     }
    977 
    978   demand_empty_rest_of_line ();
    979 }
    980 
    981 
    982 /* Provide minimal support for DS Define Storage.  */
    984 
    985 static void
    986 i370_ds (int unused ATTRIBUTE_UNUSED)
    987 {
    988   /* DS 0H or DS 0F or DS 0D.  */
    989   if ('0' == *input_line_pointer)
    990     {
    991       int alignment = 0;  /* Left shift 1 << align.  */
    992       input_line_pointer ++;
    993       switch (*input_line_pointer++)
    994 	{
    995 	case 'H':  /* 16-bit */
    996 	  alignment = 1;
    997 	  break;
    998 	case 'F':  /* 32-bit */
    999 	  alignment = 2;
   1000 	  break;
   1001 	case 'D':  /* 64-bit */
   1002 	  alignment = 3;
   1003 	  break;
   1004 	default:
   1005 	  as_bad (_("unsupported alignment"));
   1006 	  return;
   1007 	}
   1008       frag_align (alignment, 0, 0);
   1009       record_alignment (now_seg, alignment);
   1010     }
   1011   else
   1012     as_bad (_("this DS form not yet supported"));
   1013 }
   1014 
   1015 /* Solaris pseudo op to change to the .rodata section.  */
   1016 
   1017 static void
   1018 i370_elf_rdata (int sect)
   1019 {
   1020   char *save_line = input_line_pointer;
   1021   static char section[] = ".rodata\n";
   1022 
   1023   /* Just pretend this is .section .rodata.  */
   1024   input_line_pointer = section;
   1025   obj_elf_section (sect);
   1026 
   1027   input_line_pointer = save_line;
   1028 }
   1029 
   1030 /* Pseudo op to make file scope bss items.  */
   1031 
   1032 static void
   1033 i370_elf_lcomm (int unused ATTRIBUTE_UNUSED)
   1034 {
   1035   char *name;
   1036   char c;
   1037   char *p;
   1038   offsetT size;
   1039   symbolS *symbolP;
   1040   offsetT align;
   1041   segT old_sec;
   1042   int old_subsec;
   1043   char *pfrag;
   1044   int align2;
   1045 
   1046   c = get_symbol_name (&name);
   1047 
   1048   /* Just after name is now '\0'.  */
   1049   p = input_line_pointer;
   1050   (void) restore_line_pointer (c);
   1051   SKIP_WHITESPACE ();
   1052   if (*input_line_pointer != ',')
   1053     {
   1054       as_bad (_("Expected comma after symbol-name: rest of line ignored."));
   1055       ignore_rest_of_line ();
   1056       return;
   1057     }
   1058 
   1059   /* Skip ','.  */
   1060   input_line_pointer++;
   1061   if ((size = get_absolute_expression ()) < 0)
   1062     {
   1063       as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
   1064       ignore_rest_of_line ();
   1065       return;
   1066     }
   1067 
   1068   /* The third argument to .lcomm is the alignment.  */
   1069   if (*input_line_pointer != ',')
   1070     align = 8;
   1071   else
   1072     {
   1073       ++input_line_pointer;
   1074       align = get_absolute_expression ();
   1075       if (align <= 0)
   1076         {
   1077           as_warn (_("ignoring bad alignment"));
   1078           align = 8;
   1079         }
   1080     }
   1081 
   1082   *p = 0;
   1083   symbolP = symbol_find_or_make (name);
   1084   *p = c;
   1085 
   1086   if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
   1087     {
   1088       as_bad (_("Ignoring attempt to re-define symbol `%s'."),
   1089               S_GET_NAME (symbolP));
   1090       ignore_rest_of_line ();
   1091       return;
   1092     }
   1093 
   1094   if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
   1095     {
   1096       as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
   1097               S_GET_NAME (symbolP),
   1098               (long) S_GET_VALUE (symbolP),
   1099               (long) size);
   1100 
   1101       ignore_rest_of_line ();
   1102       return;
   1103     }
   1104 
   1105   /* Allocate_bss:  */
   1106   old_sec = now_seg;
   1107   old_subsec = now_subseg;
   1108   if (align)
   1109     {
   1110       /* Convert to a power of 2 alignment.  */
   1111       for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
   1112 	;
   1113       if (align != 1)
   1114         {
   1115           as_bad (_("Common alignment not a power of 2"));
   1116           ignore_rest_of_line ();
   1117           return;
   1118         }
   1119     }
   1120   else
   1121     align2 = 0;
   1122 
   1123   record_alignment (bss_section, align2);
   1124   subseg_set (bss_section, 0);
   1125   if (align2)
   1126     frag_align (align2, 0, 0);
   1127   if (S_GET_SEGMENT (symbolP) == bss_section)
   1128     symbol_get_frag (symbolP)->fr_symbol = 0;
   1129   symbol_set_frag (symbolP, frag_now);
   1130   pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
   1131         	    (char *) 0);
   1132   *pfrag = 0;
   1133   S_SET_SIZE (symbolP, size);
   1134   S_SET_SEGMENT (symbolP, bss_section);
   1135   subseg_set (old_sec, old_subsec);
   1136   demand_empty_rest_of_line ();
   1137 }
   1138 
   1139 /* Validate any relocations emitted for -mrelocatable, possibly adding
   1140    fixups for word relocations in writable segments, so we can adjust
   1141    them at runtime.  */
   1142 
   1143 static void
   1144 i370_elf_validate_fix (fixS *fixp, segT seg)
   1145 {
   1146   if (fixp->fx_done || fixp->fx_pcrel)
   1147     return;
   1148 
   1149   switch (shlib)
   1150     {
   1151     case SHLIB_NONE:
   1152     case SHLIB_PIC:
   1153       return;
   1154 
   1155     case SHILB_MRELOCATABLE:
   1156       if (fixp->fx_r_type <= BFD_RELOC_UNUSED
   1157           && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
   1158           && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
   1159           && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
   1160           && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
   1161           && fixp->fx_r_type != BFD_RELOC_32_BASEREL
   1162           && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
   1163           && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
   1164           && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
   1165           && strcmp (segment_name (seg), ".got2") != 0
   1166           && strcmp (segment_name (seg), ".dtors") != 0
   1167           && strcmp (segment_name (seg), ".ctors") != 0
   1168           && strcmp (segment_name (seg), ".fixup") != 0
   1169           && strcmp (segment_name (seg), ".stab") != 0
   1170           && strcmp (segment_name (seg), ".gcc_except_table") != 0
   1171           && strcmp (segment_name (seg), ".ex_shared") != 0)
   1172         {
   1173           if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
   1174               || fixp->fx_r_type != BFD_RELOC_CTOR)
   1175 	    as_bad_where (fixp->fx_file, fixp->fx_line,
   1176 			  "Relocation cannot be done when using -mrelocatable");
   1177         }
   1178       return;
   1179     default:
   1180       break;
   1181     }
   1182 }
   1183 #endif /* OBJ_ELF */
   1184 
   1185 
   1186 #define LITERAL_POOL_SUPPORT
   1188 #ifdef LITERAL_POOL_SUPPORT
   1189 /* Provide support for literal pools within the text section.
   1190    Loosely based on similar code from tc-arm.c.
   1191    We will use four symbols to locate four parts of the literal pool.
   1192    These four sections contain 64,32,16 and 8-bit constants; we use
   1193    four sections so that all memory access can be appropriately aligned.
   1194    That is, we want to avoid mixing these together so that we don't
   1195    waste space padding out to alignments.  The four pointers
   1196    longlong_poolP, word_poolP, etc. point to a symbol labeling the
   1197    start of each pool part.
   1198 
   1199    lit_pool_num increments from zero to infinity and uniquely id's
   1200      -- its used to generate the *_poolP symbol name.  */
   1201 
   1202 #define MAX_LITERAL_POOL_SIZE 1024
   1203 
   1204 typedef struct literalS
   1205 {
   1206   struct expressionS  exp;
   1207   char * sym_name;
   1208   char size;  /* 1,2,4 or 8 */
   1209   short offset;
   1210 } literalT;
   1211 
   1212 literalT literals[MAX_LITERAL_POOL_SIZE];
   1213 int next_literal_pool_place = 0; /* Next free entry in the pool.  */
   1214 
   1215 static symbolS *longlong_poolP = NULL;   /* 64-bit pool entries.  */
   1216 static symbolS *word_poolP = NULL;       /* 32-bit pool entries.  */
   1217 static symbolS *short_poolP = NULL;      /* 16-bit pool entries.  */
   1218 static symbolS *byte_poolP = NULL;       /* 8-bit  pool entries.  */
   1219 
   1220 static int lit_pool_num = 1;
   1221 
   1222 /* Create a new, empty symbol.  */
   1223 static symbolS *
   1224 symbol_make_empty (void)
   1225 {
   1226   return symbol_create (FAKE_LABEL_NAME, undefined_section,
   1227   			(valueT) 0, &zero_address_frag);
   1228 }
   1229 
   1230 /* Make the first argument an address-relative expression
   1231    by subtracting the second argument.  */
   1232 
   1233 static void
   1234 i370_make_relative (expressionS *exx, expressionS *baseaddr)
   1235 {
   1236   if (O_constant == baseaddr->X_op)
   1237     {
   1238        exx->X_op = O_symbol;
   1239        exx->X_add_number -= baseaddr->X_add_number;
   1240     }
   1241   else if (O_symbol == baseaddr->X_op)
   1242     {
   1243        exx->X_op = O_subtract;
   1244        exx->X_op_symbol = baseaddr->X_add_symbol;
   1245        exx->X_add_number -= baseaddr->X_add_number;
   1246     }
   1247   else if (O_uminus == baseaddr->X_op)
   1248     {
   1249        exx->X_op = O_add;
   1250        exx->X_op_symbol = baseaddr->X_add_symbol;
   1251        exx->X_add_number += baseaddr->X_add_number;
   1252     }
   1253   else
   1254     as_bad (_("Missing or bad .using directive"));
   1255 }
   1256 /* Add an expression to the literal pool.  */
   1257 
   1258 static  void
   1259 add_to_lit_pool (expressionS *exx, char *name, int sz)
   1260 {
   1261   int lit_count = 0;
   1262   int offset_in_pool = 0;
   1263 
   1264   /* Start a new pool, if necessary.  */
   1265   if (8 == sz && NULL == longlong_poolP)
   1266     longlong_poolP = symbol_make_empty ();
   1267   else if (4 == sz && NULL == word_poolP)
   1268     word_poolP = symbol_make_empty ();
   1269   else if (2 == sz && NULL == short_poolP)
   1270     short_poolP = symbol_make_empty ();
   1271   else if (1 == sz && NULL == byte_poolP)
   1272     byte_poolP = symbol_make_empty ();
   1273 
   1274   /* Check if this literal value is already in the pool.
   1275      FIXME: We should probably be checking expressions
   1276             of type O_symbol as well.
   1277      FIXME: This is probably(certainly?) broken for O_big,
   1278             which includes 64-bit long-longs.  */
   1279   while (lit_count < next_literal_pool_place)
   1280     {
   1281       if (exx->X_op == O_constant
   1282           && literals[lit_count].exp.X_op == exx->X_op
   1283           && literals[lit_count].exp.X_add_number == exx->X_add_number
   1284           && literals[lit_count].exp.X_unsigned == exx->X_unsigned
   1285           && literals[lit_count].size == sz)
   1286         break;
   1287       else if (literals[lit_count].sym_name
   1288 	       && name
   1289 	       && !strcmp (name, literals[lit_count].sym_name))
   1290         break;
   1291       if (sz == literals[lit_count].size)
   1292 	offset_in_pool += sz;
   1293       lit_count ++;
   1294     }
   1295 
   1296   if (lit_count == next_literal_pool_place) /* new entry */
   1297     {
   1298       if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE)
   1299 	as_bad (_("Literal Pool Overflow"));
   1300 
   1301       literals[next_literal_pool_place].exp = *exx;
   1302       literals[next_literal_pool_place].size = sz;
   1303       literals[next_literal_pool_place].offset = offset_in_pool;
   1304       if (name)
   1305 	literals[next_literal_pool_place].sym_name = strdup (name);
   1306       else
   1307 	literals[next_literal_pool_place].sym_name = NULL;
   1308       next_literal_pool_place++;
   1309     }
   1310 
   1311   /* ???_poolP points to the beginning of the literal pool.
   1312      X_add_number is the offset from the beginning of the
   1313      literal pool to this expr minus the location of the most
   1314      recent .using directive.  Thus, the grand total value of the
   1315      expression is the distance from .using to the literal.  */
   1316   if (8 == sz)
   1317     exx->X_add_symbol = longlong_poolP;
   1318   else if (4 == sz)
   1319     exx->X_add_symbol = word_poolP;
   1320   else if (2 == sz)
   1321     exx->X_add_symbol = short_poolP;
   1322   else if (1 == sz)
   1323     exx->X_add_symbol = byte_poolP;
   1324   exx->X_add_number = offset_in_pool;
   1325   exx->X_op_symbol = NULL;
   1326 
   1327   /* If the user has set up a base reg in another section,
   1328      use that; otherwise use the text section.  */
   1329   if (0 < i370_using_other_regno)
   1330     i370_make_relative (exx, &i370_using_other_baseaddr);
   1331   else
   1332     i370_make_relative (exx, &i370_using_text_baseaddr);
   1333 }
   1334 
   1335 /* The symbol setup for the literal pool is done in two steps.  First,
   1336    a symbol that represents the start of the literal pool is created,
   1337    above, in the add_to_pool() routine. This sym ???_poolP.
   1338    However, we don't know what fragment its in until a bit later.
   1339    So we defer the frag_now thing, and the symbol name, until .ltorg time.  */
   1340 
   1341 /* Can't use symbol_new here, so have to create a symbol and then at
   1342    a later date assign it a value. Thats what these functions do.  */
   1343 
   1344 static void
   1345 symbol_locate (symbolS *symbolP,
   1346 	       const char *name,	/* It is copied, the caller can modify.  */
   1347 	       segT segment,		/* Segment identifier (SEG_<something>).  */
   1348 	       valueT valu,		/* Symbol value.  */
   1349 	       fragS *frag)		/* Associated fragment.  */
   1350 {
   1351   size_t name_length;
   1352   char *preserved_copy_of_name;
   1353 
   1354   name_length = strlen (name) + 1;      /* +1 for \0 */
   1355   obstack_grow (&notes, name, name_length);
   1356   preserved_copy_of_name = obstack_finish (&notes);
   1357 
   1358   S_SET_NAME (symbolP, preserved_copy_of_name);
   1359 
   1360   S_SET_SEGMENT (symbolP, segment);
   1361   S_SET_VALUE (symbolP, valu);
   1362   symbol_clear_list_pointers (symbolP);
   1363 
   1364   symbol_set_frag (symbolP, frag);
   1365 
   1366   /* Link to end of symbol chain.  */
   1367   {
   1368     extern int symbol_table_frozen;
   1369 
   1370     if (symbol_table_frozen)
   1371       abort ();
   1372   }
   1373 
   1374   symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
   1375 
   1376   obj_symbol_new_hook (symbolP);
   1377 
   1378 #ifdef tc_symbol_new_hook
   1379   tc_symbol_new_hook (symbolP);
   1380 #endif
   1381 
   1382 #define DEBUG_SYMS
   1383 #ifdef DEBUG_SYMS
   1384   verify_symbol_chain(symbol_rootP, symbol_lastP);
   1385 #endif /* DEBUG_SYMS */
   1386 }
   1387 
   1388 /* i370_addr_offset() will convert operand expressions
   1389    that appear to be absolute into thier base-register
   1390    relative form.  These expressions come in two types:
   1391 
   1392    (1) of the form "* + const" * where "*" means
   1393    relative offset since the last using
   1394    i.e. "*" means ".-using_baseaddr"
   1395 
   1396    (2) labels, which are never absolute, but are always
   1397    relative to the last "using".  Anything with an alpha
   1398    character is considered to be a label (since symbols
   1399    can never be operands), and since we've already handled
   1400    register operands. For example, "BL .L33" branch low
   1401    to .L33 RX form insn frequently terminates for-loops.  */
   1402 
   1403 static bfd_boolean
   1404 i370_addr_offset (expressionS *exx)
   1405 {
   1406   char *dot, *lab;
   1407   int islabel = 0;
   1408   int all_digits = 0;
   1409 
   1410   /* Search for a label; anything with an alpha char will do.
   1411      Local labels consist of N digits followed by either b or f.  */
   1412   lab = input_line_pointer;
   1413   while (*lab && (',' != *lab) && ('(' != *lab))
   1414     {
   1415       if (ISDIGIT (*lab))
   1416 	all_digits = 1;
   1417       else if (ISALPHA (*lab))
   1418 	{
   1419 	  if (!all_digits)
   1420 	    {
   1421 	      islabel = 1;
   1422 	      break;
   1423 	    }
   1424 	  else if (('f' == *lab) || ('b' == *lab))
   1425 	    {
   1426 	      islabel = 1;
   1427 	      break;
   1428 	    }
   1429 	  if (all_digits)
   1430 	    break;
   1431 	}
   1432       else if ('.' != *lab)
   1433         break;
   1434       ++lab;
   1435     }
   1436 
   1437   /* See if operand has a * in it.  */
   1438   dot = strchr (input_line_pointer, '*');
   1439 
   1440   if (!dot && !islabel)
   1441     return FALSE;
   1442 
   1443   /* Replace * with . and let expr munch on it.  */
   1444   if (dot)
   1445     *dot = '.';
   1446   expression (exx);
   1447 
   1448   /* OK, now we have to subtract the "using" location.
   1449      Normally branches appear in the text section only.  */
   1450   if (0 == strncmp (now_seg->name, ".text", 5) || 0 > i370_using_other_regno)
   1451     i370_make_relative (exx, &i370_using_text_baseaddr);
   1452   else
   1453     i370_make_relative (exx, &i370_using_other_baseaddr);
   1454 
   1455   /* Put the * back.  */
   1456   if (dot)
   1457     *dot = '*';
   1458 
   1459   return TRUE;
   1460 }
   1461 
   1462 /* Handle address constants of various sorts.  */
   1463 /* The currently supported types are
   1464       =A(some_symb)
   1465       =V(some_extern)
   1466       =X'deadbeef'    hexadecimal
   1467       =F'1234'        32-bit const int
   1468       =H'1234'        16-bit const int.  */
   1469 
   1470 static bfd_boolean
   1471 i370_addr_cons (expressionS *exp)
   1472 {
   1473   char *name;
   1474   char *sym_name, delim;
   1475   int name_len;
   1476   int hex_len = 0;
   1477   int cons_len = 0;
   1478 
   1479   name = input_line_pointer;
   1480   sym_name = input_line_pointer;
   1481   /* Find the spelling of the operand.  */
   1482   if (name[0] == '=' && ISALPHA (name[1]))
   1483     name = ++input_line_pointer;
   1484   else
   1485     return FALSE;
   1486 
   1487   switch (name[0])
   1488     {
   1489     case 'A': /* A == address-of.  */
   1490     case 'V': /* V == extern.  */
   1491       ++input_line_pointer;
   1492       expression (exp);
   1493 
   1494       /* We use a simple string name to collapse together
   1495          multiple refrences to the same address literal.  */
   1496       name_len = strcspn (sym_name, ", ");
   1497       delim = *(sym_name + name_len);
   1498       *(sym_name + name_len) = 0x0;
   1499       add_to_lit_pool (exp, sym_name, 4);
   1500       *(sym_name + name_len) = delim;
   1501 
   1502       break;
   1503     case 'H':
   1504     case 'F':
   1505     case 'X':
   1506     case 'E':  /* Single-precision float point.  */
   1507     case 'D':  /* Double-precision float point.  */
   1508 
   1509       /* H == 16-bit fixed-point const; expression must be const.  */
   1510       /* F == fixed-point const; expression must be const.  */
   1511       /* X == fixed-point const; expression must be const.  */
   1512       if ('H' == name[0]) cons_len = 2;
   1513       else if ('F' == name[0]) cons_len = 4;
   1514       else if ('X' == name[0]) cons_len = -1;
   1515       else if ('E' == name[0]) cons_len = 4;
   1516       else if ('D' == name[0]) cons_len = 8;
   1517 
   1518       /* Extract length, if it is present;
   1519 	 FIXME: assume single-digit length.  */
   1520       if ('L' == name[1])
   1521 	{
   1522 	  /* Should work for ASCII and EBCDIC.  */
   1523 	  cons_len = name[2] - '0';
   1524 	  input_line_pointer += 2;
   1525 	}
   1526 
   1527       ++input_line_pointer;
   1528 
   1529       /* Get rid of pesky quotes.  */
   1530       if ('\'' == *input_line_pointer)
   1531 	{
   1532 	  char * clse;
   1533 
   1534 	  ++input_line_pointer;
   1535 	  clse = strchr (input_line_pointer, '\'');
   1536 	  if (clse)
   1537 	    *clse= ' ';
   1538 	  else
   1539 	    as_bad (_("missing end-quote"));
   1540 	}
   1541       if ('\"' == *input_line_pointer)
   1542 	{
   1543 	  char * clse;
   1544 
   1545 	  ++input_line_pointer;
   1546 	  clse = strchr (input_line_pointer, '\"');
   1547 	  if (clse)
   1548 	    *clse= ' ';
   1549 	  else
   1550 	    as_bad (_("missing end-quote"));
   1551 	}
   1552       if (('X' == name[0]) || ('E' == name[0]) || ('D' == name[0]))
   1553 	{
   1554 	  char tmp[50];
   1555 	  char *save;
   1556 
   1557 	  /* The length of hex constants is specified directly with L,
   1558 	     or implied through the number of hex digits. For example:
   1559 	     =X'AB'       one byte
   1560 	     =X'abcd'     two bytes
   1561 	     =X'000000AB' four bytes
   1562 	     =XL4'AB'     four bytes, left-padded withn zero.  */
   1563 	  if (('X' == name[0]) && (0 > cons_len))
   1564 	    {
   1565 	      save = input_line_pointer;
   1566 	      while (*save)
   1567 		{
   1568 		  if (ISXDIGIT (*save))
   1569 		    hex_len++;
   1570 		  save++;
   1571 		}
   1572 	      cons_len = (hex_len+1) /2;
   1573 	    }
   1574 	  /* I believe this works even for =XL8'dada0000beeebaaa'
   1575 	     which should parse out to X_op == O_big
   1576 	     Note that floats and doubles get represented as
   1577 	     0d3.14159265358979  or 0f 2.7.  */
   1578 	  tmp[0] = '0';
   1579 	  tmp[1] = name[0];
   1580 	  tmp[2] = 0;
   1581 	  strcat (tmp, input_line_pointer);
   1582 	  save = input_line_pointer;
   1583 	  input_line_pointer = tmp;
   1584 	  expression (exp);
   1585 	  input_line_pointer = save + (input_line_pointer-tmp-2);
   1586 
   1587 	  /* Fix up lengths for floats and doubles.  */
   1588 	  if (O_big == exp->X_op)
   1589 	    exp->X_add_number = cons_len / CHARS_PER_LITTLENUM;
   1590 	}
   1591       else
   1592 	expression (exp);
   1593 
   1594       /* O_big occurs when more than 4 bytes worth gets parsed.  */
   1595       if ((exp->X_op != O_constant) && (exp->X_op != O_big))
   1596 	{
   1597 	  as_bad (_("expression not a constant"));
   1598 	  return FALSE;
   1599 	}
   1600       add_to_lit_pool (exp, 0x0, cons_len);
   1601       break;
   1602 
   1603     default:
   1604       as_bad (_("Unknown/unsupported address literal type"));
   1605       return FALSE;
   1606     }
   1607 
   1608   return TRUE;
   1609 }
   1610 
   1611 
   1612 /* Dump the contents of the literal pool that we've accumulated so far.
   1614    This aligns the pool to the size of the largest literal in the pool.  */
   1615 
   1616 static void
   1617 i370_ltorg (int ignore ATTRIBUTE_UNUSED)
   1618 {
   1619   int litsize;
   1620   int lit_count = 0;
   1621   int biggest_literal_size = 0;
   1622   int biggest_align = 0;
   1623   char pool_name[20];
   1624 
   1625   if (strncmp (now_seg->name, ".text", 5))
   1626     {
   1627       if (i370_other_section == undefined_section)
   1628 	as_bad (_(".ltorg without prior .using in section %s"),
   1629 		now_seg->name);
   1630 
   1631       if (i370_other_section != now_seg)
   1632 	as_bad (_(".ltorg in section %s paired to .using in section %s"),
   1633 		now_seg->name, i370_other_section->name);
   1634     }
   1635 
   1636   if (! longlong_poolP
   1637       && ! word_poolP
   1638       && ! short_poolP
   1639       && ! byte_poolP)
   1640     /* Nothing to do.  */
   1641     return;
   1642 
   1643   /* Find largest literal .. 2 4 or 8.  */
   1644   lit_count = 0;
   1645   while (lit_count < next_literal_pool_place)
   1646     {
   1647       if (biggest_literal_size < literals[lit_count].size)
   1648 	biggest_literal_size = literals[lit_count].size;
   1649       lit_count ++;
   1650     }
   1651   if (1 == biggest_literal_size) biggest_align = 0;
   1652   else if (2 == biggest_literal_size) biggest_align = 1;
   1653   else if (4 == biggest_literal_size) biggest_align = 2;
   1654   else if (8 == biggest_literal_size) biggest_align = 3;
   1655   else as_bad (_("bad alignment of %d bytes in literal pool"), biggest_literal_size);
   1656   if (0 == biggest_align) biggest_align = 1;
   1657 
   1658   /* Align pool for short, word, double word accesses.  */
   1659   frag_align (biggest_align, 0, 0);
   1660   record_alignment (now_seg, biggest_align);
   1661 
   1662   /* Note that the gas listing will print only the first five
   1663      entries in the pool .... wonder how to make it print more.  */
   1664   /* Output largest literals first, then the smaller ones.  */
   1665   for (litsize=8; litsize; litsize /=2)
   1666     {
   1667       symbolS *current_poolP = NULL;
   1668       switch (litsize)
   1669 	{
   1670 	case 8:
   1671 	  current_poolP = longlong_poolP; break;
   1672 	case 4:
   1673 	  current_poolP = word_poolP; break;
   1674 	case 2:
   1675 	  current_poolP = short_poolP; break;
   1676 	case 1:
   1677 	  current_poolP = byte_poolP; break;
   1678 	default:
   1679 	  as_bad (_("bad literal size\n"));
   1680 	}
   1681       if (NULL == current_poolP)
   1682 	continue;
   1683       sprintf (pool_name, ".LITP%01d%06d", litsize, lit_pool_num);
   1684       symbol_locate (current_poolP, pool_name, now_seg,
   1685 		     (valueT) frag_now_fix (), frag_now);
   1686       symbol_table_insert (current_poolP);
   1687 
   1688       lit_count = 0;
   1689       while (lit_count < next_literal_pool_place)
   1690 	{
   1691 	  if (litsize == literals[lit_count].size)
   1692 	    {
   1693 #define EMIT_ADDR_CONS_SYMBOLS
   1694 #ifdef EMIT_ADDR_CONS_SYMBOLS
   1695 	      /* Create a bogus symbol, add it to the pool ...
   1696 	         For the most part, I think this is a useless exercise,
   1697 	         except that having these symbol names in the objects
   1698 	         is vaguely useful for debugging.  */
   1699 	      if (literals[lit_count].sym_name)
   1700 		{
   1701 		  symbolS * symP = symbol_make_empty ();
   1702 		  symbol_locate (symP, literals[lit_count].sym_name, now_seg,
   1703 				 (valueT) frag_now_fix (), frag_now);
   1704 		  symbol_table_insert (symP);
   1705 		}
   1706 #endif /* EMIT_ADDR_CONS_SYMBOLS */
   1707 
   1708 	      emit_expr (&(literals[lit_count].exp), literals[lit_count].size);
   1709 	    }
   1710 	  lit_count ++;
   1711 	}
   1712     }
   1713 
   1714   next_literal_pool_place = 0;
   1715   longlong_poolP = NULL;
   1716   word_poolP = NULL;
   1717   short_poolP = NULL;
   1718   byte_poolP = NULL;
   1719   lit_pool_num++;
   1720 }
   1721 
   1722 #endif /* LITERAL_POOL_SUPPORT */
   1723 
   1724 
   1725 /* Add support for the HLASM-like USING directive to indicate
   1727    the base register to use ...  we don't support the full
   1728    hlasm semantics for this ... we merely pluck a base address
   1729    and a register number out.  We print a warning if using is
   1730    called multiple times.  I suppose we should check to see
   1731    if the regno is valid.  */
   1732 
   1733 static void
   1734 i370_using (int ignore ATTRIBUTE_UNUSED)
   1735 {
   1736   expressionS ex, baseaddr;
   1737   int iregno;
   1738   char *star;
   1739 
   1740   /* If "*" appears in a using, it means "."
   1741      replace it with "." so that expr doesn't get confused.  */
   1742   star = strchr (input_line_pointer, '*');
   1743   if (star)
   1744     *star = '.';
   1745 
   1746   /* The first arg to using will usually be ".", but it can
   1747      be a more complex expression too.  */
   1748   expression (&baseaddr);
   1749   if (star)
   1750     *star = '*';
   1751   if (O_constant != baseaddr.X_op
   1752       && O_symbol != baseaddr.X_op
   1753       && O_uminus != baseaddr.X_op)
   1754     as_bad (_(".using: base address expression illegal or too complex"));
   1755 
   1756   if (*input_line_pointer != '\0') ++input_line_pointer;
   1757 
   1758   /* The second arg to using had better be a register.  */
   1759   register_name (&ex);
   1760   demand_empty_rest_of_line ();
   1761   iregno = ex.X_add_number;
   1762 
   1763   if (0 == strncmp (now_seg->name, ".text", 5))
   1764     {
   1765       i370_using_text_baseaddr = baseaddr;
   1766       i370_using_text_regno = iregno;
   1767     }
   1768   else
   1769     {
   1770       i370_using_other_baseaddr = baseaddr;
   1771       i370_using_other_regno = iregno;
   1772       i370_other_section = now_seg;
   1773     }
   1774 }
   1775 
   1776 static void
   1777 i370_drop (int ignore ATTRIBUTE_UNUSED)
   1778 {
   1779   expressionS ex;
   1780   int iregno;
   1781 
   1782   register_name (&ex);
   1783   demand_empty_rest_of_line ();
   1784   iregno = ex.X_add_number;
   1785 
   1786   if (0 == strncmp (now_seg->name, ".text", 5))
   1787     {
   1788       if (iregno != i370_using_text_regno)
   1789 	as_bad (_("droping register %d in section %s does not match using register %d"),
   1790 		iregno, now_seg->name, i370_using_text_regno);
   1791 
   1792       i370_using_text_regno = -1;
   1793       i370_using_text_baseaddr.X_op = O_absent;
   1794     }
   1795   else
   1796     {
   1797       if (iregno != i370_using_other_regno)
   1798 	as_bad (_("droping register %d in section %s does not match using register %d"),
   1799 		iregno, now_seg->name, i370_using_other_regno);
   1800 
   1801       if (i370_other_section != now_seg)
   1802 	as_bad (_("droping register %d in section %s previously used in section %s"),
   1803 		iregno, now_seg->name, i370_other_section->name);
   1804 
   1805       i370_using_other_regno = -1;
   1806       i370_using_other_baseaddr.X_op = O_absent;
   1807       i370_other_section = undefined_section;
   1808     }
   1809 }
   1810 
   1811 
   1812 /* We need to keep a list of fixups.  We can't simply generate them as
   1814    we go, because that would require us to first create the frag, and
   1815    that would screw up references to ``.''.  */
   1816 
   1817 struct i370_fixup
   1818 {
   1819   expressionS exp;
   1820   int opindex;
   1821   bfd_reloc_code_real_type reloc;
   1822 };
   1823 
   1824 #define MAX_INSN_FIXUPS 5
   1825 
   1826 /* Handle a macro.  Gather all the operands, transform them as
   1827    described by the macro, and call md_assemble recursively.  All the
   1828    operands are separated by commas; we don't accept parentheses
   1829    around operands here.  */
   1830 
   1831 static void
   1832 i370_macro (char *str, const struct i370_macro *macro)
   1833 {
   1834   char *operands[10];
   1835   unsigned int count;
   1836   char *s;
   1837   unsigned int len;
   1838   const char *format;
   1839   int arg;
   1840   char *send;
   1841   char *complete;
   1842 
   1843   /* Gather the users operands into the operands array.  */
   1844   count = 0;
   1845   s = str;
   1846   while (1)
   1847     {
   1848       if (count >= sizeof operands / sizeof operands[0])
   1849         break;
   1850       operands[count++] = s;
   1851       s = strchr (s, ',');
   1852       if (s == (char *) NULL)
   1853         break;
   1854       *s++ = '\0';
   1855     }
   1856 
   1857   if (count != macro->operands)
   1858     {
   1859       as_bad (_("wrong number of operands"));
   1860       return;
   1861     }
   1862 
   1863   /* Work out how large the string must be (the size is unbounded
   1864      because it includes user input).  */
   1865   len = 0;
   1866   format = macro->format;
   1867   while (*format != '\0')
   1868     {
   1869       if (*format != '%')
   1870         {
   1871           ++len;
   1872           ++format;
   1873         }
   1874       else
   1875         {
   1876           arg = strtol (format + 1, &send, 10);
   1877           know (send != format && arg >= 0 && (unsigned) arg < count);
   1878           len += strlen (operands[arg]);
   1879           format = send;
   1880         }
   1881     }
   1882 
   1883   /* Put the string together.  */
   1884   complete = s = XNEWVEC (char, len + 1);
   1885   format = macro->format;
   1886   while (*format != '\0')
   1887     {
   1888       if (*format != '%')
   1889         *s++ = *format++;
   1890       else
   1891         {
   1892           arg = strtol (format + 1, &send, 10);
   1893           strcpy (s, operands[arg]);
   1894           s += strlen (s);
   1895           format = send;
   1896         }
   1897     }
   1898   *s = '\0';
   1899 
   1900   /* Assemble the constructed instruction.  */
   1901   md_assemble (complete);
   1902   free (complete);
   1903 }
   1904 
   1905 /* This routine is called for each instruction to be assembled.  */
   1906 
   1907 void
   1908 md_assemble (char *str)
   1909 {
   1910   char *s;
   1911   const struct i370_opcode *opcode;
   1912   i370_insn_t insn;
   1913   const unsigned char *opindex_ptr;
   1914   int have_optional_index, have_optional_basereg, have_optional_reg;
   1915   int skip_optional_index, skip_optional_basereg, skip_optional_reg;
   1916   int use_text=0, use_other=0;
   1917   int off_by_one;
   1918   struct i370_fixup fixups[MAX_INSN_FIXUPS];
   1919   int fc;
   1920   char *f;
   1921   int i;
   1922 #ifdef OBJ_ELF
   1923   bfd_reloc_code_real_type reloc;
   1924 #endif
   1925 
   1926   /* Get the opcode.  */
   1927   for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
   1928     ;
   1929   if (*s != '\0')
   1930     *s++ = '\0';
   1931 
   1932   /* Look up the opcode in the hash table.  */
   1933   opcode = (const struct i370_opcode *) hash_find (i370_hash, str);
   1934   if (opcode == (const struct i370_opcode *) NULL)
   1935     {
   1936       const struct i370_macro *macro;
   1937 
   1938       gas_assert (i370_macro_hash);
   1939       macro = (const struct i370_macro *) hash_find (i370_macro_hash, str);
   1940       if (macro == (const struct i370_macro *) NULL)
   1941         as_bad (_("Unrecognized opcode: `%s'"), str);
   1942       else
   1943 	i370_macro (s, macro);
   1944 
   1945       return;
   1946     }
   1947 
   1948   insn = opcode->opcode;
   1949 
   1950   str = s;
   1951   while (ISSPACE (*str))
   1952     ++str;
   1953 
   1954   /* I370 operands are either expressions or address constants.
   1955      Many operand types are optional.  The optional operands
   1956      are always surrounded by parens, and are used to denote the base
   1957      register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
   1958      the fully-formed "A R1, D2(X2,B2)".  Note also the = sign,
   1959      such as A R1,=A(i) where the address-of operator =A implies
   1960      use of both a base register, and a missing index register.
   1961 
   1962      So, before we start seriously parsing the operands, we check
   1963      to see if we have an optional operand, and, if we do, we count
   1964      the number of commas to see which operand should be omitted.  */
   1965 
   1966   have_optional_index = have_optional_basereg = have_optional_reg = 0;
   1967   for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
   1968     {
   1969       const struct i370_operand *operand;
   1970 
   1971       operand = &i370_operands[*opindex_ptr];
   1972       if ((operand->flags & I370_OPERAND_INDEX) != 0)
   1973 	have_optional_index = 1;
   1974       if ((operand->flags & I370_OPERAND_BASE) != 0)
   1975 	have_optional_basereg = 1;
   1976       if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
   1977 	have_optional_reg = 1;
   1978     }
   1979 
   1980   skip_optional_index = skip_optional_basereg = skip_optional_reg = 0;
   1981   if (have_optional_index || have_optional_basereg)
   1982     {
   1983       unsigned int opcount, nwanted;
   1984 
   1985       /* There is an optional operand.  Count the number of
   1986 	 commas and open-parens in the input line.  */
   1987       if (*str == '\0')
   1988 	opcount = 0;
   1989       else
   1990 	{
   1991 	  opcount = 1;
   1992 	  s = str;
   1993 	  while ((s = strpbrk (s, ",(=")) != (char *) NULL)
   1994 	    {
   1995 	      ++opcount;
   1996 	      ++s;
   1997 	      if (',' == *s) ++s;  /* avoid counting things like (, */
   1998 	      if ('=' == *s) { ++s; --opcount; }
   1999 	    }
   2000 	}
   2001 
   2002       /* If there are fewer operands in the line then are called
   2003 	 for by the instruction, we want to skip the optional
   2004 	 operand.  */
   2005       nwanted = strlen ((char *) opcode->operands);
   2006       if (have_optional_index)
   2007 	{
   2008 	  if (opcount < nwanted)
   2009 	    skip_optional_index = 1;
   2010 	  if (have_optional_basereg && ((opcount+1) < nwanted))
   2011 	    skip_optional_basereg = 1;
   2012 	  if (have_optional_reg && ((opcount+1) < nwanted))
   2013 	    skip_optional_reg = 1;
   2014 	}
   2015       else
   2016 	{
   2017 	  if (have_optional_basereg && (opcount < nwanted))
   2018 	    skip_optional_basereg = 1;
   2019 	  if (have_optional_reg && (opcount < nwanted))
   2020 	    skip_optional_reg = 1;
   2021 	}
   2022     }
   2023 
   2024   /* Perform some off-by-one hacks on the length field of certain instructions.
   2025      Its such a shame to have to do this, but the problem is that HLASM got
   2026      defined so that the lengths differ by one from the actual machine instructions.
   2027      this code should probably be moved to a special inster-operand routine.
   2028      Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
   2029      hack alert -- aren't *all* SS instructions affected ??  */
   2030   off_by_one = 0;
   2031   if (0 == strcasecmp ("CLC", opcode->name)
   2032       || 0 == strcasecmp ("ED", opcode->name)
   2033       || 0 == strcasecmp ("EDMK", opcode->name)
   2034       || 0 == strcasecmp ("MVC", opcode->name)
   2035       || 0 == strcasecmp ("MVCIN", opcode->name)
   2036       || 0 == strcasecmp ("MVN", opcode->name)
   2037       || 0 == strcasecmp ("MVZ", opcode->name)
   2038       || 0 == strcasecmp ("NC", opcode->name)
   2039       || 0 == strcasecmp ("OC", opcode->name)
   2040       || 0 == strcasecmp ("XC", opcode->name))
   2041     off_by_one = 1;
   2042 
   2043   /* Gather the operands.  */
   2044   fc = 0;
   2045   for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
   2046     {
   2047       const struct i370_operand *operand;
   2048       char *hold;
   2049       expressionS ex;
   2050 
   2051       operand = &i370_operands[*opindex_ptr];
   2052 
   2053       /* If this is an index operand, and we are skipping it,
   2054 	 just insert a zero.  */
   2055       if (skip_optional_index &&
   2056 	  ((operand->flags & I370_OPERAND_INDEX) != 0))
   2057         {
   2058           insn = i370_insert_operand (insn, operand, 0);
   2059           continue;
   2060         }
   2061 
   2062       /* If this is the base operand, and we are skipping it,
   2063 	 just insert the current using basreg.  */
   2064       if (skip_optional_basereg &&
   2065           ((operand->flags & I370_OPERAND_BASE) != 0))
   2066         {
   2067           int basereg = -1;
   2068           if (use_text)
   2069             {
   2070               if (0 == strncmp (now_seg->name, ".text", 5)
   2071 		  || 0 > i370_using_other_regno)
   2072 		basereg = i370_using_text_regno;
   2073               else
   2074 		basereg = i370_using_other_regno;
   2075             }
   2076           else if (use_other)
   2077             {
   2078               if (0 > i370_using_other_regno)
   2079 		basereg = i370_using_text_regno;
   2080               else
   2081 		basereg = i370_using_other_regno;
   2082             }
   2083           if (0 > basereg)
   2084 	    as_bad (_("not using any base register"));
   2085 
   2086           insn = i370_insert_operand (insn, operand, basereg);
   2087           continue;
   2088         }
   2089 
   2090       /* If this is an optional operand, and we are skipping it,
   2091 	 Use zero (since a non-zero value would denote a register)  */
   2092       if (skip_optional_reg
   2093 	  && ((operand->flags & I370_OPERAND_OPTIONAL) != 0))
   2094         {
   2095           insn = i370_insert_operand (insn, operand, 0);
   2096           continue;
   2097         }
   2098 
   2099       /* Gather the operand.  */
   2100       hold = input_line_pointer;
   2101       input_line_pointer = str;
   2102 
   2103       /* Register names are only allowed where there are registers.  */
   2104       if ((operand->flags & I370_OPERAND_GPR) != 0)
   2105         {
   2106           /* Quickie hack to get past things like (,r13).  */
   2107           if (skip_optional_index && (',' == *input_line_pointer))
   2108             {
   2109               *input_line_pointer = ' ';
   2110               input_line_pointer ++;
   2111             }
   2112 
   2113           if (! register_name (&ex))
   2114 	    as_bad (_("expecting a register for operand %d"),
   2115 		    (int) (opindex_ptr - opcode->operands + 1));
   2116         }
   2117 
   2118       /* Check for an address constant expression.  */
   2119       /* We will put PSW-relative addresses in the text section,
   2120          and address literals in the .data (or other) section.  */
   2121       else if (i370_addr_cons (&ex))
   2122 	use_other = 1;
   2123       else if (i370_addr_offset (&ex))
   2124 	use_text = 1;
   2125       else expression (&ex);
   2126 
   2127       str = input_line_pointer;
   2128       input_line_pointer = hold;
   2129 
   2130       /* Perform some off-by-one hacks on the length field of certain instructions.
   2131          Its such a shame to have to do this, but the problem is that HLASM got
   2132          defined so that the programmer specifies a length that is one greater
   2133          than what the machine instruction wants.  Sigh.  */
   2134       if (off_by_one && (0 == strcasecmp ("SS L", operand->name)))
   2135 	ex.X_add_number --;
   2136 
   2137       if (ex.X_op == O_illegal)
   2138         as_bad (_("illegal operand"));
   2139       else if (ex.X_op == O_absent)
   2140         as_bad (_("missing operand"));
   2141       else if (ex.X_op == O_register)
   2142 	insn = i370_insert_operand (insn, operand, ex.X_add_number);
   2143       else if (ex.X_op == O_constant)
   2144         {
   2145 #ifdef OBJ_ELF
   2146           /* Allow @HA, @L, @H on constants.
   2147              Well actually, no we don't; there really don't make sense
   2148              (at least not to me) for the i370.  However, this code is
   2149              left here for any dubious future expansion reasons.  */
   2150           char *orig_str = str;
   2151 
   2152           if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
   2153             switch (reloc)
   2154               {
   2155               default:
   2156         	str = orig_str;
   2157         	break;
   2158 
   2159               case BFD_RELOC_LO16:
   2160         	/* X_unsigned is the default, so if the user has done
   2161                    something which cleared it, we always produce a
   2162                    signed value.  */
   2163 		ex.X_add_number = (((ex.X_add_number & 0xffff)
   2164 				    ^ 0x8000)
   2165 				   - 0x8000);
   2166         	break;
   2167 
   2168               case BFD_RELOC_HI16:
   2169         	ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
   2170         	break;
   2171 
   2172               case BFD_RELOC_HI16_S:
   2173         	ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
   2174         			   + ((ex.X_add_number >> 15) & 1));
   2175         	break;
   2176               }
   2177 #endif
   2178           insn = i370_insert_operand (insn, operand, ex.X_add_number);
   2179         }
   2180 #ifdef OBJ_ELF
   2181       else if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
   2182         {
   2183           as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
   2184 
   2185           /* We need to generate a fixup for this expression.  */
   2186           if (fc >= MAX_INSN_FIXUPS)
   2187             as_fatal ("too many fixups");
   2188           fixups[fc].exp = ex;
   2189           fixups[fc].opindex = 0;
   2190           fixups[fc].reloc = reloc;
   2191           ++fc;
   2192         }
   2193 #endif /* OBJ_ELF */
   2194       else
   2195         {
   2196           /* We need to generate a fixup for this expression.  */
   2197           /* Typically, the expression will just be a symbol ...
   2198                printf ("insn %s needs fixup for %s \n",
   2199                     opcode->name, ex.X_add_symbol->bsym->name);  */
   2200 
   2201           if (fc >= MAX_INSN_FIXUPS)
   2202             as_fatal ("too many fixups");
   2203           fixups[fc].exp = ex;
   2204           fixups[fc].opindex = *opindex_ptr;
   2205           fixups[fc].reloc = BFD_RELOC_UNUSED;
   2206           ++fc;
   2207         }
   2208 
   2209       /* Skip over delimiter (close paren, or comma).  */
   2210       if ((')' == *str) && (',' == *(str+1)))
   2211 	++str;
   2212       if (*str != '\0')
   2213 	++str;
   2214     }
   2215 
   2216   while (ISSPACE (*str))
   2217     ++str;
   2218 
   2219   if (*str != '\0')
   2220     as_bad (_("junk at end of line: `%s'"), str);
   2221 
   2222   /* Write out the instruction.  */
   2223   f = frag_more (opcode->len);
   2224   if (4 >= opcode->len)
   2225     md_number_to_chars (f, insn.i[0], opcode->len);
   2226   else
   2227     {
   2228       md_number_to_chars (f, insn.i[0], 4);
   2229 
   2230       if (6 == opcode->len)
   2231 	md_number_to_chars ((f + 4), ((insn.i[1])>>16), 2);
   2232       else
   2233 	{
   2234 	  /* Not used --- don't have any 8 byte instructions.  */
   2235 	  as_bad (_("Internal Error: bad instruction length"));
   2236 	  md_number_to_chars ((f + 4), insn.i[1], opcode->len -4);
   2237 	}
   2238     }
   2239 
   2240   /* Create any fixups.  At this point we do not use a
   2241      bfd_reloc_code_real_type, but instead just use the
   2242      BFD_RELOC_UNUSED plus the operand index.  This lets us easily
   2243      handle fixups for any operand type, although that is admittedly
   2244      not a very exciting feature.  We pick a BFD reloc type in
   2245      md_apply_fix.  */
   2246   for (i = 0; i < fc; i++)
   2247     {
   2248       const struct i370_operand *operand;
   2249 
   2250       operand = &i370_operands[fixups[i].opindex];
   2251       if (fixups[i].reloc != BFD_RELOC_UNUSED)
   2252 	{
   2253 	  reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
   2254 	  int size;
   2255 	  fixS *fixP;
   2256 
   2257 	  if (!reloc_howto)
   2258 	    abort ();
   2259 
   2260 	  size = bfd_get_reloc_size (reloc_howto);
   2261 
   2262 	  if (size < 1 || size > 4)
   2263 	    abort ();
   2264 
   2265 	  printf (" gwana doo fixup %d \n", i);
   2266 	  fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
   2267          		      &fixups[i].exp, reloc_howto->pc_relative,
   2268          		      fixups[i].reloc);
   2269 
   2270 	  /* Turn off complaints that the addend is too large for things like
   2271 	     foo+100000@ha.  */
   2272 	  switch (fixups[i].reloc)
   2273 	    {
   2274 	    case BFD_RELOC_16_GOTOFF:
   2275 	    case BFD_RELOC_LO16:
   2276 	    case BFD_RELOC_HI16:
   2277 	    case BFD_RELOC_HI16_S:
   2278 	      fixP->fx_no_overflow = 1;
   2279 	      break;
   2280 	    default:
   2281 	      break;
   2282 	    }
   2283 	}
   2284       else
   2285 	{
   2286 	  fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->len,
   2287 		       &fixups[i].exp,
   2288 		       (operand->flags & I370_OPERAND_RELATIVE) != 0,
   2289 		       ((bfd_reloc_code_real_type)
   2290 			(fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
   2291 	}
   2292     }
   2293 }
   2294 
   2295 
   2296 /* Pseudo-op handling.  */
   2298 
   2299 /* The .byte pseudo-op.  This is similar to the normal .byte
   2300    pseudo-op, but it can also take a single ASCII string.  */
   2301 
   2302 static void
   2303 i370_byte (int ignore ATTRIBUTE_UNUSED)
   2304 {
   2305   if (*input_line_pointer != '\"')
   2306     {
   2307       cons (1);
   2308       return;
   2309     }
   2310 
   2311   /* Gather characters.  A real double quote is doubled.  Unusual
   2312      characters are not permitted.  */
   2313   ++input_line_pointer;
   2314   while (1)
   2315     {
   2316       char c;
   2317 
   2318       c = *input_line_pointer++;
   2319 
   2320       if (c == '\"')
   2321         {
   2322         if (*input_line_pointer != '\"')
   2323             break;
   2324           ++input_line_pointer;
   2325         }
   2326 
   2327       FRAG_APPEND_1_CHAR (c);
   2328     }
   2329 
   2330   demand_empty_rest_of_line ();
   2331 }
   2332 
   2333 /* The .tc pseudo-op.  This is used when generating XCOFF and ELF.
   2335    This takes two or more arguments.
   2336 
   2337    When generating XCOFF output, the first argument is the name to
   2338    give to this location in the toc; this will be a symbol with class
   2339    TC.  The rest of the arguments are 4 byte values to actually put at
   2340    this location in the TOC; often there is just one more argument, a
   2341    relocatable symbol reference.
   2342 
   2343    When not generating XCOFF output, the arguments are the same, but
   2344    the first argument is simply ignored.  */
   2345 
   2346 static void
   2347 i370_tc (int ignore ATTRIBUTE_UNUSED)
   2348 {
   2349 
   2350   /* Skip the TOC symbol name.  */
   2351   while (is_part_of_name (*input_line_pointer)
   2352          || *input_line_pointer == '['
   2353          || *input_line_pointer == ']'
   2354          || *input_line_pointer == '{'
   2355          || *input_line_pointer == '}')
   2356     ++input_line_pointer;
   2357 
   2358   /* Align to a four byte boundary.  */
   2359   frag_align (2, 0, 0);
   2360   record_alignment (now_seg, 2);
   2361 
   2362   if (*input_line_pointer != ',')
   2363     demand_empty_rest_of_line ();
   2364   else
   2365     {
   2366       ++input_line_pointer;
   2367       cons (4);
   2368     }
   2369 }
   2370 
   2371 const char *
   2373 md_atof (int type, char *litp, int *sizep)
   2374 {
   2375   /* 360/370/390 have two float formats: an old, funky 360 single-precision
   2376      format, and the ieee format.  Support only the ieee format.  */
   2377   return ieee_md_atof (type, litp, sizep, TRUE);
   2378 }
   2379 
   2380 /* Write a value out to the object file, using the appropriate
   2381    endianness.  */
   2382 
   2383 void
   2384 md_number_to_chars (char *buf, valueT val, int n)
   2385 {
   2386   number_to_chars_bigendian (buf, val, n);
   2387 }
   2388 
   2389 /* Align a section (I don't know why this is machine dependent).  */
   2390 
   2391 valueT
   2392 md_section_align (asection *seg, valueT addr)
   2393 {
   2394   int align = bfd_get_section_alignment (stdoutput, seg);
   2395 
   2396   return (addr + (1 << align) - 1) & -(1 << align);
   2397 }
   2398 
   2399 /* We don't have any form of relaxing.  */
   2400 
   2401 int
   2402 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
   2403 			       asection *seg ATTRIBUTE_UNUSED)
   2404 {
   2405   abort ();
   2406   return 0;
   2407 }
   2408 
   2409 /* Convert a machine dependent frag.  We never generate these.  */
   2410 
   2411 void
   2412 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   2413 		 asection *sec ATTRIBUTE_UNUSED,
   2414 		 fragS *fragp ATTRIBUTE_UNUSED)
   2415 {
   2416   abort ();
   2417 }
   2418 
   2419 /* We have no need to default values of symbols.  */
   2420 
   2421 symbolS *
   2422 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
   2423 {
   2424   return 0;
   2425 }
   2426 
   2427 /* Functions concerning relocs.  */
   2429 
   2430 /* The location from which a PC relative jump should be calculated,
   2431    given a PC relative reloc.  */
   2432 
   2433 long
   2434 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
   2435 {
   2436   return fixp->fx_frag->fr_address + fixp->fx_where;
   2437 }
   2438 
   2439 /* Apply a fixup to the object code.  This is called for all the
   2440    fixups we generated by the call to fix_new_exp, above.  In the call
   2441    above we used a reloc code which was the largest legal reloc code
   2442    plus the operand index.  Here we undo that to recover the operand
   2443    index.  At this point all symbol values should be fully resolved,
   2444    and we attempt to completely resolve the reloc.  If we can not do
   2445    that, we determine the correct reloc code and put it back in the
   2446    fixup.
   2447 
   2448    See gas/cgen.c for more sample code and explanations of what's
   2449    going on here.  */
   2450 
   2451 void
   2452 md_apply_fix (fixS *fixP, valueT * valP, segT seg)
   2453 {
   2454   valueT value = * valP;
   2455 
   2456   if (fixP->fx_addsy != NULL)
   2457     {
   2458 #ifdef DEBUG
   2459       printf ("\nmd_apply_fix: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
   2460 	      S_GET_NAME (fixP->fx_addsy),
   2461 	      fixP->fx_frag->fr_address + fixP->fx_where,
   2462 	      fixP->fx_file, fixP->fx_line,
   2463 	      S_GET_VALUE (fixP->fx_addsy), value);
   2464 #endif
   2465     }
   2466   else
   2467     fixP->fx_done = 1;
   2468 
   2469   /* Apply fixups to operands.  Note that there should be no relocations
   2470      for any operands, since no instruction ever takes an operand
   2471      that requires reloc.  */
   2472   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
   2473     {
   2474       int opindex;
   2475       const struct i370_operand *operand;
   2476       char *where;
   2477       i370_insn_t insn;
   2478 
   2479       opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
   2480 
   2481       operand = &i370_operands[opindex];
   2482 
   2483 #ifdef DEBUG
   2484       printf ("\nmd_apply_fix: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
   2485 	      operand->name,
   2486 	      fixP->fx_frag->fr_address + fixP->fx_where,
   2487 	      fixP->fx_file, fixP->fx_line,
   2488 	      value);
   2489 #endif
   2490       /* Fetch the instruction, insert the fully resolved operand
   2491          value, and stuff the instruction back again.
   2492          fisxp->fx_size is the length of the instruction.  */
   2493       where = fixP->fx_frag->fr_literal + fixP->fx_where;
   2494       insn.i[0] = bfd_getb32 ((unsigned char *) where);
   2495 
   2496       if (6 <= fixP->fx_size)
   2497 	/* Deal with 48-bit insn's.  */
   2498 	insn.i[1] = bfd_getb32 (((unsigned char *) where)+4);
   2499 
   2500       insn = i370_insert_operand (insn, operand, (offsetT) value);
   2501       bfd_putb32 ((bfd_vma) insn.i[0], (unsigned char *) where);
   2502 
   2503       if (6 <= fixP->fx_size)
   2504 	/* Deal with 48-bit insn's.  */
   2505 	bfd_putb32 ((bfd_vma) insn.i[1], (((unsigned char *) where)+4));
   2506 
   2507       /* We are done, right? right !!  */
   2508       fixP->fx_done = 1;
   2509       if (fixP->fx_done)
   2510 	/* Nothing else to do here.  */
   2511 	return;
   2512 
   2513       /* Determine a BFD reloc value based on the operand information.
   2514 	 We are only prepared to turn a few of the operands into
   2515 	 relocs.  In fact, we support *zero* operand relocations ...
   2516 	 Why?  Because we are not expecting the compiler to generate
   2517 	 any operands that need relocation.  Due to the 12-bit naturew of
   2518 	 i370 addressing, this would be unusual.  */
   2519         {
   2520           const char *sfile;
   2521           unsigned int sline;
   2522 
   2523           /* Use expr_symbol_where to see if this is an expression
   2524              symbol.  */
   2525           if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
   2526             as_bad_where (fixP->fx_file, fixP->fx_line,
   2527         		  "unresolved expression that must be resolved");
   2528           else
   2529             as_bad_where (fixP->fx_file, fixP->fx_line,
   2530         		  "unsupported relocation type");
   2531           fixP->fx_done = 1;
   2532           return;
   2533         }
   2534     }
   2535   else
   2536     {
   2537       /* We branch to here if the fixup is not to a symbol that
   2538          appears in an instruction operand, but is rather some
   2539          declared storage.  */
   2540 #ifdef OBJ_ELF
   2541       i370_elf_validate_fix (fixP, seg);
   2542 #endif
   2543 #ifdef DEBUG
   2544       printf ("md_apply_fix: reloc case %d in segment  %s %s:%d\n",
   2545 	      fixP->fx_r_type, segment_name (seg), fixP->fx_file, fixP->fx_line);
   2546       printf ("\tcurrent fixup value is 0x%x \n", value);
   2547 #endif
   2548       switch (fixP->fx_r_type)
   2549         {
   2550         case BFD_RELOC_32:
   2551         case BFD_RELOC_CTOR:
   2552           if (fixP->fx_pcrel)
   2553             fixP->fx_r_type = BFD_RELOC_32_PCREL;
   2554 	  /* Fall through.  */
   2555 
   2556         case BFD_RELOC_RVA:
   2557         case BFD_RELOC_32_PCREL:
   2558         case BFD_RELOC_32_BASEREL:
   2559 #ifdef DEBUG
   2560           printf ("\t32 bit relocation at 0x%x\n",
   2561 		  fixP->fx_frag->fr_address + fixP->fx_where);
   2562 #endif
   2563           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
   2564         		      value, 4);
   2565           break;
   2566 
   2567         case BFD_RELOC_LO16:
   2568         case BFD_RELOC_16:
   2569           if (fixP->fx_pcrel)
   2570             as_bad_where (fixP->fx_file, fixP->fx_line,
   2571         		  "cannot emit PC relative %s relocation%s%s",
   2572         		  bfd_get_reloc_code_name (fixP->fx_r_type),
   2573         		  fixP->fx_addsy != NULL ? " against " : "",
   2574         		  (fixP->fx_addsy != NULL
   2575         		   ? S_GET_NAME (fixP->fx_addsy)
   2576         		   : ""));
   2577 
   2578           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
   2579         		      value, 2);
   2580           break;
   2581 
   2582           /* This case happens when you write, for example,
   2583              lis %r3,(L1-L2)@ha
   2584              where L1 and L2 are defined later.  */
   2585         case BFD_RELOC_HI16:
   2586           if (fixP->fx_pcrel)
   2587             abort ();
   2588           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
   2589         		      value >> 16, 2);
   2590           break;
   2591         case BFD_RELOC_HI16_S:
   2592           if (fixP->fx_pcrel)
   2593             abort ();
   2594           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
   2595         		      (value + 0x8000) >> 16, 2);
   2596           break;
   2597 
   2598         case BFD_RELOC_8:
   2599           if (fixP->fx_pcrel)
   2600             abort ();
   2601 
   2602           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
   2603         		      value, 1);
   2604           break;
   2605 
   2606         default:
   2607           fprintf (stderr,
   2608         	  "Gas failure, reloc value %d\n", fixP->fx_r_type);
   2609           fflush (stderr);
   2610           abort ();
   2611         }
   2612     }
   2613 
   2614   fixP->fx_addnumber = value;
   2615 }
   2616 
   2617 /* Generate a reloc for a fixup.  */
   2618 
   2619 arelent *
   2620 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
   2621 {
   2622   arelent *reloc;
   2623 
   2624   reloc = XNEW (arelent);
   2625 
   2626   reloc->sym_ptr_ptr = XNEW (asymbol *);
   2627   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   2628   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
   2629   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
   2630   if (reloc->howto == (reloc_howto_type *) NULL)
   2631     {
   2632       as_bad_where (fixp->fx_file, fixp->fx_line,
   2633         	    "reloc %d not supported by object file format", (int)fixp->fx_r_type);
   2634       return NULL;
   2635     }
   2636   reloc->addend = fixp->fx_addnumber;
   2637 
   2638 #ifdef DEBUG
   2639   printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
   2640 	  fixp->fx_addsy->bsym->name,
   2641 	  fixp->fx_file, fixp->fx_line,
   2642 	  reloc->address, reloc->addend);
   2643 #endif
   2644 
   2645   return reloc;
   2646 }
   2647 
   2648 /* The target specific pseudo-ops which we support.  */
   2649 
   2650 const pseudo_typeS md_pseudo_table[] =
   2651 {
   2652   /* Pseudo-ops which must be overridden.  */
   2653   { "byte",     i370_byte,	0 },
   2654 
   2655   { "dc",       i370_dc,	0 },
   2656   { "ds",       i370_ds,	0 },
   2657   { "rmode",    i370_rmode,	0 },
   2658   { "csect",    i370_csect,	0 },
   2659   { "dsect",    i370_dsect,	0 },
   2660 
   2661   /* enable ebcdic strings e.g. for 3270 support */
   2662   { "ebcdic",   i370_ebcdic,	0 },
   2663 
   2664 #ifdef OBJ_ELF
   2665   { "long",     i370_elf_cons,	4 },
   2666   { "word",     i370_elf_cons,	4 },
   2667   { "short",    i370_elf_cons,	2 },
   2668   { "rdata",    i370_elf_rdata,	0 },
   2669   { "rodata",   i370_elf_rdata,	0 },
   2670   { "lcomm",    i370_elf_lcomm,	0 },
   2671 #endif
   2672 
   2673   /* This pseudo-op is used even when not generating XCOFF output.  */
   2674   { "tc",       i370_tc,	0 },
   2675 
   2676   /* dump the literal pool */
   2677   { "ltorg",    i370_ltorg,	0 },
   2678 
   2679   /* support the hlasm-style USING directive */
   2680   { "using",    i370_using,	0 },
   2681   { "drop",     i370_drop,	0 },
   2682 
   2683   { NULL,       NULL,		0 }
   2684 };
   2685