Back to index

cell-binutils  2.17cvs20070401
tc-i370.c
Go to the documentation of this file.
00001 /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set.
00002    Loosely based on the ppc files by Linas Vepstas <linas@linas.org> 1998, 99
00003    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
00004    2004, 2005, 2006 Free Software Foundation, Inc.
00005    Written by Ian Lance Taylor, Cygnus Support.
00006 
00007    This file is part of GAS, the GNU Assembler.
00008 
00009    GAS is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2, or (at your option)
00012    any later version.
00013 
00014    GAS is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with GAS; see the file COPYING.  If not, write to the Free
00021    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00022    02110-1301, USA.  */
00023 
00024 /* This assembler implements a very hacked version of an elf-like thing
00025    that gcc emits (when gcc is suitably hacked).  To make it behave more
00026    HLASM-like, try turning on the -M or --mri flag (as there are various
00027    similarities between HLASM and the MRI assemblers, such as section
00028    names, lack of leading . in pseudo-ops, DC and DS, etc.  */
00029 
00030 #include "as.h"
00031 #include "safe-ctype.h"
00032 #include "subsegs.h"
00033 #include "struc-symbol.h"
00034 
00035 #include "opcode/i370.h"
00036 
00037 #ifdef OBJ_ELF
00038 #include "elf/i370.h"
00039 #endif
00040 
00041 /* This is the assembler for the System/390 Architecture.  */
00042 
00043 /* Tell the main code what the endianness is.  */
00044 extern int target_big_endian;
00045 
00046 
00047 /* Generic assembler global variables which must be defined by all
00048    targets.  */
00049 
00050 #ifdef OBJ_ELF
00051 /* This string holds the chars that always start a comment.  If the
00052    pre-processor is disabled, these aren't very useful.  The macro
00053    tc_comment_chars points to this.  We use this, rather than the
00054    usual comment_chars, so that we can switch for Solaris conventions.  */
00055 static const char i370_eabi_comment_chars[] = "#";
00056 
00057 const char *i370_comment_chars = i370_eabi_comment_chars;
00058 #else
00059 const char comment_chars[] = "#";
00060 #endif
00061 
00062 /* Characters which start a comment at the beginning of a line.  */
00063 const char line_comment_chars[] = "#*";
00064 
00065 /* Characters which may be used to separate multiple commands on a
00066    single line.  */
00067 const char line_separator_chars[] = ";";
00068 
00069 /* Characters which are used to indicate an exponent in a floating
00070    point number.  */
00071 const char EXP_CHARS[] = "eE";
00072 
00073 /* Characters which mean that a number is a floating point constant,
00074    as in 0d1.0.  */
00075 const char FLT_CHARS[] = "dD";
00076 
00077 void
00078 md_show_usage (FILE *stream)
00079 {
00080   fprintf (stream, "\
00081 S/370 options: (these have not yet been tested and may not work) \n\
00082 -u                   ignored\n\
00083 -mregnames           Allow symbolic names for registers\n\
00084 -mno-regnames               Do not allow symbolic names for registers\n");
00085 #ifdef OBJ_ELF
00086   fprintf (stream, "\
00087 -mrelocatable               support for GCC's -mrelocatble option\n\
00088 -mrelocatable-lib       support for GCC's -mrelocatble-lib option\n\
00089 -V                   print assembler version number\n");
00090 #endif
00091 }
00092 
00093 /* Whether to use user friendly register names.  */
00094 #define TARGET_REG_NAMES_P TRUE
00095 
00096 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
00097 
00098 
00099 /* Predefined register names if -mregnames
00100    In general, there are lots of them, in an attempt to be compatible
00101    with a number of assemblers.  */
00102 
00103 /* Structure to hold information about predefined registers.  */
00104 struct pd_reg
00105   {
00106     char *name;
00107     int value;
00108   };
00109 
00110 /* List of registers that are pre-defined:
00111 
00112    Each general register has predefined names of the form:
00113    1. r<reg_num> which has the value <reg_num>.
00114    2. r.<reg_num> which has the value <reg_num>.
00115 
00116    Each floating point register has predefined names of the form:
00117    1. f<reg_num> which has the value <reg_num>.
00118    2. f.<reg_num> which has the value <reg_num>.
00119 
00120    There are only four floating point registers, and these are
00121    commonly labelled 0,2,4 and 6.  Thus, there is no f1, f3, etc.
00122 
00123    There are individual registers as well:
00124    rbase or r.base has the value  3  (base register)
00125    rpgt or r.pgt   has the value  4  (page origin table pointer)
00126    rarg or r.arg   has the value 11  (argument pointer)
00127    rtca or r.tca   has the value 12  (table of contents pointer)
00128    rtoc or r.toc   has the value 12  (table of contents pointer)
00129    sp or r.sp      has the value 13  (stack pointer)
00130    dsa or r.dsa    has the value 13  (stack pointer)
00131    lr              has the value 14  (link reg)
00132 
00133    The table is sorted. Suitable for searching by a binary search.  */
00134 
00135 static const struct pd_reg pre_defined_registers[] =
00136 {
00137   { "arg", 11 },   /* Argument Pointer.  */
00138   { "base", 3 },   /* Base Reg.  */
00139 
00140   { "f.0", 0 },    /* Floating point registers.  */
00141   { "f.2", 2 },
00142   { "f.4", 4 },
00143   { "f.6", 6 },
00144 
00145   { "f0", 0 },
00146   { "f2", 2 },
00147   { "f4", 4 },
00148   { "f6", 6 },
00149 
00150   { "dsa",13 },    /* Stack pointer.  */
00151   { "lr", 14 },    /* Link Register.  */
00152   { "pgt", 4 },    /* Page Origin Table Pointer.  */
00153 
00154   { "r.0", 0 },    /* General Purpose Registers.  */
00155   { "r.1", 1 },
00156   { "r.10", 10 },
00157   { "r.11", 11 },
00158   { "r.12", 12 },
00159   { "r.13", 13 },
00160   { "r.14", 14 },
00161   { "r.15", 15 },
00162   { "r.2", 2 },
00163   { "r.3", 3 },
00164   { "r.4", 4 },
00165   { "r.5", 5 },
00166   { "r.6", 6 },
00167   { "r.7", 7 },
00168   { "r.8", 8 },
00169   { "r.9", 9 },
00170 
00171   { "r.arg", 11 },  /* Argument Pointer.  */
00172   { "r.base", 3 },  /* Base Reg.  */
00173   { "r.dsa", 13 },  /* Stack Pointer.  */
00174   { "r.pgt", 4 },   /* Page Origin Table Pointer.  */
00175   { "r.sp", 13 },   /* Stack Pointer.  */
00176 
00177   { "r.tca", 12 },  /* Pointer to the table of contents.  */
00178   { "r.toc", 12 },  /* Pointer to the table of contents.  */
00179 
00180   { "r0", 0 },      /* More general purpose registers.  */
00181   { "r1", 1 },
00182   { "r10", 10 },
00183   { "r11", 11 },
00184   { "r12", 12 },
00185   { "r13", 13 },
00186   { "r14", 14 },
00187   { "r15", 15 },
00188   { "r2", 2 },
00189   { "r3", 3 },
00190   { "r4", 4 },
00191   { "r5", 5 },
00192   { "r6", 6 },
00193   { "r7", 7 },
00194   { "r8", 8 },
00195   { "r9", 9 },
00196 
00197   { "rbase", 3 },  /* Base Reg.  */
00198 
00199   { "rtca", 12 },  /* Pointer to the table of contents.  */
00200   { "rtoc", 12 },  /* Pointer to the table of contents.  */
00201 
00202   { "sp", 13 },   /* Stack Pointer.  */
00203 
00204 };
00205 
00206 #define REG_NAME_CNT        (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
00207 
00208 /* Given NAME, find the register number associated with that name, return
00209    the integer value associated with the given name or -1 on failure.  */
00210 
00211 static int
00212 reg_name_search (const struct pd_reg *regs,
00213                int regcount,
00214                const char *name)
00215 {
00216   int middle, low, high;
00217   int cmp;
00218 
00219   low = 0;
00220   high = regcount - 1;
00221 
00222   do
00223     {
00224       middle = (low + high) / 2;
00225       cmp = strcasecmp (name, regs[middle].name);
00226       if (cmp < 0)
00227         high = middle - 1;
00228       else if (cmp > 0)
00229         low = middle + 1;
00230       else
00231         return regs[middle].value;
00232     }
00233   while (low <= high);
00234 
00235   return -1;
00236 }
00237 
00238 /* Summary of register_name().
00239 
00240    in:        Input_line_pointer points to 1st char of operand.
00241 
00242    out:        An expressionS.
00243         The operand may have been a register: in this case, X_op == O_register,
00244         X_add_number is set to the register number, and truth is returned.
00245           Input_line_pointer->(next non-blank) char after operand, or is in its
00246         original state.  */
00247 
00248 static bfd_boolean
00249 register_name (expressionS *expressionP)
00250 {
00251   int reg_number;
00252   char *name;
00253   char *start;
00254   char c;
00255 
00256   /* Find the spelling of the operand.  */
00257   start = name = input_line_pointer;
00258   if (name[0] == '%' && ISALPHA (name[1]))
00259     name = ++input_line_pointer;
00260 
00261   else if (!reg_names_p)
00262     return FALSE;
00263 
00264   while (' ' == *name)
00265     name = ++input_line_pointer;
00266 
00267   /* If it's a number, treat it as a number.  If it's alpha, look to
00268      see if it's in the register table.  */
00269   if (!ISALPHA (name[0]))
00270     reg_number = get_single_number ();
00271   else
00272     {
00273       c = get_symbol_end ();
00274       reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
00275 
00276       /* Put back the delimiting char.  */
00277       *input_line_pointer = c;
00278     }
00279 
00280   /* If numeric, make sure its not out of bounds.  */
00281   if ((0 <= reg_number) && (16 >= reg_number))
00282     {
00283       expressionP->X_op = O_register;
00284       expressionP->X_add_number = reg_number;
00285 
00286       /* Make the rest nice.  */
00287       expressionP->X_add_symbol = NULL;
00288       expressionP->X_op_symbol = NULL;
00289       return TRUE;
00290     }
00291 
00292   /* Reset the line as if we had not done anything.  */
00293   input_line_pointer = start;
00294   return FALSE;
00295 }
00296 
00297 /* Local variables.  */
00298 
00299 /* The type of processor we are assembling for.  This is one or more
00300    of the I370_OPCODE flags defined in opcode/i370.h.  */
00301 static int i370_cpu = 0;
00302 
00303 /* The base register to use for opcode with optional operands.
00304    We define two of these: "text" and "other".  Normally, "text"
00305    would get used in the .text section for branches, while "other"
00306    gets used in the .data section for address constants.
00307 
00308    The idea of a second base register in a different section
00309    is foreign to the usual HLASM-style semantics; however, it
00310    allows us to provide support for dynamically loaded libraries,
00311    by allowing us to place address constants in a section other
00312    than the text section. The "other" section need not be the
00313    .data section, it can be any section that isn't the .text section.
00314 
00315    Note that HLASM defines a multiple, concurrent .using semantic
00316    that we do not: in calculating offsets, it uses either the most
00317    recent .using directive, or the one with the smallest displacement.
00318    This allows HLASM to support a quasi-block-scope-like behaviour.
00319    Handy for people writing assembly by hand ... but not supported
00320    by us.  */
00321 static int i370_using_text_regno = -1;
00322 static int i370_using_other_regno = -1;
00323 
00324 /* The base address for address literals.  */
00325 static expressionS i370_using_text_baseaddr;
00326 static expressionS i370_using_other_baseaddr;
00327 
00328 /* the "other" section, used only for syntax error detection.  */
00329 static segT i370_other_section = undefined_section;
00330 
00331 /* Opcode hash table.  */
00332 static struct hash_control *i370_hash;
00333 
00334 /* Macro hash table.  */
00335 static struct hash_control *i370_macro_hash;
00336 
00337 #ifdef OBJ_ELF
00338 /* What type of shared library support to use.  */
00339 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
00340 #endif
00341 
00342 /* Flags to set in the elf header.  */
00343 static flagword i370_flags = 0;
00344 
00345 #ifndef WORKING_DOT_WORD
00346 int md_short_jump_size = 4;
00347 int md_long_jump_size = 4;
00348 #endif
00349 
00350 #ifdef OBJ_ELF
00351 const char *md_shortopts = "l:um:K:VQ:";
00352 #else
00353 const char *md_shortopts = "um:";
00354 #endif
00355 struct option md_longopts[] =
00356 {
00357   {NULL, no_argument, NULL, 0}
00358 };
00359 size_t md_longopts_size = sizeof (md_longopts);
00360 
00361 int
00362 md_parse_option (int c, char *arg)
00363 {
00364   switch (c)
00365     {
00366     case 'u':
00367       /* -u means that any undefined symbols should be treated as
00368          external, which is the default for gas anyhow.  */
00369       break;
00370 
00371 #ifdef OBJ_ELF
00372     case 'K':
00373       /* Recognize -K PIC */
00374       if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
00375         {
00376           shlib = SHLIB_PIC;
00377           i370_flags |= EF_I370_RELOCATABLE_LIB;
00378         }
00379       else
00380         return 0;
00381 
00382       break;
00383 #endif
00384 
00385     case 'm':
00386 
00387       /* -m360 mean to assemble for the ancient 360 architecture.  */
00388       if (strcmp (arg, "360") == 0 || strcmp (arg, "i360") == 0)
00389        i370_cpu = I370_OPCODE_360;
00390       /* -mxa means to assemble for the IBM 370 XA.  */
00391       else if (strcmp (arg, "xa") == 0)
00392        i370_cpu = I370_OPCODE_370_XA;
00393       /* -many means to assemble for any architecture (370/XA).  */
00394       else if (strcmp (arg, "any") == 0)
00395        i370_cpu = I370_OPCODE_370;
00396 
00397       else if (strcmp (arg, "regnames") == 0)
00398        reg_names_p = TRUE;
00399 
00400       else if (strcmp (arg, "no-regnames") == 0)
00401        reg_names_p = FALSE;
00402 
00403 #ifdef OBJ_ELF
00404       /* -mrelocatable/-mrelocatable-lib -- warn about
00405         initializations that require relocation.  */
00406       else if (strcmp (arg, "relocatable") == 0)
00407         {
00408           shlib = SHILB_MRELOCATABLE;
00409           i370_flags |= EF_I370_RELOCATABLE;
00410         }
00411       else if (strcmp (arg, "relocatable-lib") == 0)
00412         {
00413           shlib = SHILB_MRELOCATABLE;
00414           i370_flags |= EF_I370_RELOCATABLE_LIB;
00415         }
00416 #endif
00417       else
00418         {
00419           as_bad ("invalid switch -m%s", arg);
00420           return 0;
00421         }
00422       break;
00423 
00424 #ifdef OBJ_ELF
00425       /* -V: SVR4 argument to print version ID.  */
00426     case 'V':
00427       print_version_id ();
00428       break;
00429 
00430       /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
00431          should be emitted or not.  FIXME: Not implemented.  */
00432     case 'Q':
00433       break;
00434 
00435 #endif
00436 
00437     default:
00438       return 0;
00439     }
00440 
00441   return 1;
00442 }
00443 
00444 
00445 /* Set i370_cpu if it is not already set.
00446    Currently defaults to the reasonable superset;
00447    but can be made more fine grained if desred.  */
00448 
00449 static void
00450 i370_set_cpu (void)
00451 {
00452   const char *default_os  = TARGET_OS;
00453   const char *default_cpu = TARGET_CPU;
00454 
00455   /* Override with the superset for the moment.  */
00456   i370_cpu = I370_OPCODE_ESA390_SUPERSET;
00457   if (i370_cpu == 0)
00458     {
00459       if (strcmp (default_cpu, "i360") == 0)
00460         i370_cpu = I370_OPCODE_360;
00461       else if (strcmp (default_cpu, "i370") == 0)
00462         i370_cpu = I370_OPCODE_370;
00463       else if (strcmp (default_cpu, "XA") == 0)
00464         i370_cpu = I370_OPCODE_370_XA;
00465       else
00466         as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
00467     }
00468 }
00469 
00470 /* Figure out the BFD architecture to use.
00471    FIXME: specify the different 370 architectures.  */
00472 
00473 enum bfd_architecture
00474 i370_arch (void)
00475 {
00476    return bfd_arch_i370;
00477 }
00478 
00479 /* This function is called when the assembler starts up.  It is called
00480    after the options have been parsed and the output file has been
00481    opened.  */
00482 
00483 void
00484 md_begin (void)
00485 {
00486   const struct i370_opcode *op;
00487   const struct i370_opcode *op_end;
00488   const struct i370_macro *macro;
00489   const struct i370_macro *macro_end;
00490   bfd_boolean dup_insn = FALSE;
00491 
00492   i370_set_cpu ();
00493 
00494 #ifdef OBJ_ELF
00495   /* Set the ELF flags if desired.  */
00496   if (i370_flags)
00497     bfd_set_private_flags (stdoutput, i370_flags);
00498 #endif
00499 
00500   /* Insert the opcodes into a hash table.  */
00501   i370_hash = hash_new ();
00502 
00503    op_end = i370_opcodes + i370_num_opcodes;
00504    for (op = i370_opcodes; op < op_end; op++)
00505      {
00506        know ((op->opcode.i[0] & op->mask.i[0]) == op->opcode.i[0]
00507             && (op->opcode.i[1] & op->mask.i[1]) == op->opcode.i[1]);
00508 
00509        if ((op->flags & i370_cpu) != 0)
00510          {
00511            const char *retval;
00512 
00513            retval = hash_insert (i370_hash, op->name, (void *) op);
00514            if (retval != (const char *) NULL)
00515              {
00516                as_bad ("Internal assembler error for instruction %s", op->name);
00517                dup_insn = TRUE;
00518              }
00519          }
00520      }
00521 
00522   /* Insert the macros into a hash table.  */
00523   i370_macro_hash = hash_new ();
00524 
00525   macro_end = i370_macros + i370_num_macros;
00526   for (macro = i370_macros; macro < macro_end; macro++)
00527     {
00528       if ((macro->flags & i370_cpu) != 0)
00529         {
00530           const char *retval;
00531 
00532           retval = hash_insert (i370_macro_hash, macro->name, (void *) macro);
00533           if (retval != (const char *) NULL)
00534             {
00535               as_bad ("Internal assembler error for macro %s", macro->name);
00536               dup_insn = TRUE;
00537             }
00538         }
00539     }
00540 
00541   if (dup_insn)
00542     abort ();
00543 }
00544 
00545 /* Insert an operand value into an instruction.  */
00546 
00547 static i370_insn_t
00548 i370_insert_operand (i370_insn_t insn,
00549                    const struct i370_operand *operand,
00550                    offsetT val)
00551 {
00552   if (operand->insert)
00553     {
00554       const char *errmsg;
00555 
00556       /* Used for 48-bit insn's.  */
00557       errmsg = NULL;
00558       insn = (*operand->insert) (insn, (long) val, &errmsg);
00559       if (errmsg)
00560         as_bad ("%s", errmsg);
00561     }
00562   else
00563     /* This is used only for 16, 32 bit insn's.  */
00564     insn.i[0] |= (((long) val & ((1 << operand->bits) - 1))
00565                 << operand->shift);
00566 
00567   return insn;
00568 }
00569 
00570 
00571 #ifdef OBJ_ELF
00572 /* Parse @got, etc. and return the desired relocation.
00573    Currently, i370 does not support (don't really need to support) any
00574    of these fancier markups ... for example, no one is going to
00575    write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
00576    So basically, we could get away with this routine returning
00577    BFD_RELOC_UNUSED in all circumstances.  However, I'll leave
00578    in for now in case someone ambitious finds a good use for this stuff ...
00579    this routine was pretty much just copied from the powerpc code ...  */
00580 
00581 static bfd_reloc_code_real_type
00582 i370_elf_suffix (char **str_p, expressionS *exp_p)
00583 {
00584   struct map_bfd
00585   {
00586     char *string;
00587     int length;
00588     bfd_reloc_code_real_type reloc;
00589   };
00590 
00591   char ident[20];
00592   char *str = *str_p;
00593   char *str2;
00594   int ch;
00595   int len;
00596   struct map_bfd *ptr;
00597 
00598 #define MAP(str,reloc) { str, sizeof (str) - 1, reloc }
00599 
00600   static struct map_bfd mapping[] =
00601   {
00602     /* warnings with -mrelocatable.  */
00603     MAP ("fixup",    BFD_RELOC_CTOR),
00604     { (char *)0, 0,  BFD_RELOC_UNUSED }
00605   };
00606 
00607   if (*str++ != '@')
00608     return BFD_RELOC_UNUSED;
00609 
00610   for (ch = *str, str2 = ident;
00611        (str2 < ident + sizeof (ident) - 1
00612         && (ISALNUM (ch) || ch == '@'));
00613        ch = *++str)
00614     *str2++ = TOLOWER (ch);
00615 
00616   *str2 = '\0';
00617   len = str2 - ident;
00618 
00619   ch = ident[0];
00620   for (ptr = &mapping[0]; ptr->length > 0; ptr++)
00621     if (ch == ptr->string[0]
00622         && len == ptr->length
00623         && memcmp (ident, ptr->string, ptr->length) == 0)
00624       {
00625         if (exp_p->X_add_number != 0
00626             && (ptr->reloc == BFD_RELOC_16_GOTOFF
00627               || ptr->reloc == BFD_RELOC_LO16_GOTOFF
00628               || ptr->reloc == BFD_RELOC_HI16_GOTOFF
00629               || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
00630           as_warn ("identifier+constant@got means identifier@got+constant");
00631 
00632         /* Now check for identifier@suffix+constant */
00633         if (*str == '-' || *str == '+')
00634           {
00635             char *orig_line = input_line_pointer;
00636             expressionS new_exp;
00637 
00638             input_line_pointer = str;
00639             expression (&new_exp);
00640             if (new_exp.X_op == O_constant)
00641               {
00642               exp_p->X_add_number += new_exp.X_add_number;
00643               str = input_line_pointer;
00644               }
00645 
00646             if (&input_line_pointer != str_p)
00647               input_line_pointer = orig_line;
00648           }
00649 
00650         *str_p = str;
00651         return ptr->reloc;
00652       }
00653 
00654   return BFD_RELOC_UNUSED;
00655 }
00656 
00657 /* Like normal .long/.short/.word, except support @got, etc.
00658    Clobbers input_line_pointer, checks end-of-line.  */
00659 
00660 static void
00661 i370_elf_cons (int nbytes)   /* 1=.byte, 2=.word, 4=.long.  */
00662 {
00663   expressionS exp;
00664   bfd_reloc_code_real_type reloc;
00665 
00666   if (is_it_end_of_statement ())
00667     {
00668       demand_empty_rest_of_line ();
00669       return;
00670     }
00671 
00672   do
00673     {
00674       expression (&exp);
00675 
00676       if (exp.X_op == O_symbol
00677           && *input_line_pointer == '@'
00678           && (reloc = i370_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
00679         {
00680           reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
00681           int size = bfd_get_reloc_size (reloc_howto);
00682 
00683           if (size > nbytes)
00684             as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
00685           else
00686             {
00687               char *p = frag_more ((int) nbytes);
00688               int offset = nbytes - size;
00689 
00690               fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
00691             }
00692         }
00693       else
00694         emit_expr (&exp, (unsigned int) nbytes);
00695     }
00696   while (*input_line_pointer++ == ',');
00697 
00698   input_line_pointer--;            /* Put terminator back into stream.  */
00699   demand_empty_rest_of_line ();
00700 }
00701 
00702 
00703 /* ASCII to EBCDIC conversion table.  */
00704 static unsigned char ascebc[256] =
00705 {
00706  /*00  NL    SH    SX    EX    ET    NQ    AK    BL */
00707      0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
00708  /*08  BS    HT    LF    VT    FF    CR    SO    SI */
00709      0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
00710  /*10  DL    D1    D2    D3    D4    NK    SN    EB */
00711      0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
00712  /*18  CN    EM    SB    EC    FS    GS    RS    US */
00713      0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
00714  /*20  SP     !     "     #     $     %     &     ' */
00715      0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
00716  /*28   (     )     *     +     ,     -    .      / */
00717      0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
00718  /*30   0     1     2     3     4     5     6     7 */
00719      0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
00720  /*38   8     9     :     ;     <     =     >     ? */
00721      0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
00722  /*40   @     A     B     C     D     E     F     G */
00723      0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
00724  /*48   H     I     J     K     L     M     N     O */
00725      0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
00726  /*50   P     Q     R     S     T     U     V     W */
00727      0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
00728  /*58   X     Y     Z     [     \     ]     ^     _ */
00729      0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
00730  /*60   `     a     b     c     d     e     f     g */
00731      0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
00732  /*68   h     i     j     k     l     m     n     o */
00733      0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
00734  /*70   p     q     r     s     t     u     v     w */
00735      0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
00736  /*78   x     y     z     {     |     }     ~    DL */
00737      0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
00738      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00739      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00740      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00741      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00742      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00743      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00744      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00745      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00746      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00747      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00748      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00749      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00750      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00751      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00752      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
00753      0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
00754 };
00755 
00756 /* EBCDIC to ASCII conversion table.  */
00757 unsigned char ebcasc[256] =
00758 {
00759  /*00  NU    SH    SX    EX    PF    HT    LC    DL */
00760      0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
00761  /*08              SM    VT    FF    CR    SO    SI */
00762      0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
00763  /*10  DE    D1    D2    TM    RS    NL    BS    IL */
00764      0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
00765  /*18  CN    EM    CC    C1    FS    GS    RS    US */
00766      0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
00767  /*20  DS    SS    FS          BP    LF    EB    EC */
00768      0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
00769  /*28              SM    C2    EQ    AK    BL       */
00770      0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
00771  /*30              SY          PN    RS    UC    ET */
00772      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
00773  /*38                    C3    D4    NK          SU */
00774      0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
00775  /*40  SP                                           */
00776      0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00777  /*48                     .     <     (     +     | */
00778      0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
00779  /*50   &                                           */
00780      0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00781  /*58               !     $     *     )     ;     ^ */
00782      0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
00783  /*60   -     /                                     */
00784      0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00785  /*68                     ,     %     _     >     ? */
00786      0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
00787  /*70                                               */
00788      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00789  /*78         `     :     #     @     '     =     " */
00790      0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
00791  /*80         a     b     c     d     e     f     g */
00792      0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
00793  /*88   h     i           {                         */
00794      0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
00795  /*90         j     k     l     m     n     o     p */
00796      0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
00797  /*98   q     r           }                         */
00798      0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
00799  /*A0         ~     s     t     u     v     w     x */
00800      0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
00801  /*A8   y     z                       [             */
00802      0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
00803  /*B0                                               */
00804      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00805  /*B8                                 ]             */
00806      0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
00807  /*C0   {     A     B     C     D     E     F     G */
00808      0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
00809  /*C8   H     I                                     */
00810      0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00811  /*D0   }     J     K     L     M     N     O     P */
00812      0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
00813  /*D8   Q     R                                     */
00814      0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00815  /*E0   \           S     T     U     V     W     X */
00816      0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
00817  /*E8   Y     Z                                     */
00818      0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00819  /*F0   0     1     2     3     4     5     6     7 */
00820      0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
00821  /*F8   8     9                                     */
00822      0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
00823 };
00824 
00825 /* EBCDIC translation tables needed for 3270 support.  */
00826 
00827 static void
00828 i370_ebcdic (int unused ATTRIBUTE_UNUSED)
00829 {
00830   char *p, *end;
00831   char delim = 0;
00832   size_t nbytes;
00833 
00834   nbytes = strlen (input_line_pointer);
00835   end = input_line_pointer + nbytes;
00836   while ('\r' == *end) end --;
00837   while ('\n' == *end) end --;
00838 
00839   delim = *input_line_pointer;
00840   if (('\'' == delim) || ('\"' == delim))
00841     {
00842       input_line_pointer ++;
00843       end = rindex (input_line_pointer, delim);
00844     }
00845 
00846   if (end > input_line_pointer)
00847     {
00848       nbytes = end - input_line_pointer +1;
00849       p = frag_more (nbytes);
00850       while (end > input_line_pointer)
00851        {
00852          *p = ascebc [(unsigned char) (*input_line_pointer)];
00853          ++p; ++input_line_pointer;
00854        }
00855       *p = '\0';
00856     }
00857   if (delim == *input_line_pointer) ++input_line_pointer;
00858 }
00859 
00860 
00861 /* Stub out a couple of routines.  */
00862 
00863 static void
00864 i370_rmode (int unused ATTRIBUTE_UNUSED)
00865 {
00866   as_tsktsk ("rmode ignored");
00867 }
00868 
00869 static void
00870 i370_dsect (int sect)
00871 {
00872   char *save_line = input_line_pointer;
00873   static char section[] = ".data\n";
00874 
00875   /* Just pretend this is .section .data.  */
00876   input_line_pointer = section;
00877   obj_elf_section (sect);
00878 
00879   input_line_pointer = save_line;
00880 }
00881 
00882 static void
00883 i370_csect (int unused ATTRIBUTE_UNUSED)
00884 {
00885   as_tsktsk ("csect not supported");
00886 }
00887 
00888 
00889 /* DC Define Const  is only partially supported.
00890    For samplecode on what to do, look at i370_elf_cons() above.
00891    This code handles pseudoops of the style
00892    DC   D'3.141592653'   # in sysv4, .double 3.14159265
00893    DC   F'1'             # in sysv4, .long   1.  */
00894 
00895 static void
00896 i370_dc (int unused ATTRIBUTE_UNUSED)
00897 {
00898   char * p, tmp[50];
00899   int nbytes=0;
00900   expressionS exp;
00901   char type=0;
00902 
00903   if (is_it_end_of_statement ())
00904     {
00905       demand_empty_rest_of_line ();
00906       return;
00907     }
00908 
00909   /* Figure out the size.  */
00910   type = *input_line_pointer++;
00911   switch (type)
00912     {
00913     case 'H':  /* 16-bit */
00914       nbytes = 2;
00915       break;
00916     case 'E':  /* 32-bit */
00917     case 'F':  /* 32-bit */
00918       nbytes = 4;
00919       break;
00920     case 'D':  /* 64-bit */
00921       nbytes = 8;
00922       break;
00923     default:
00924       as_bad ("unsupported DC type");
00925       return;
00926     }
00927 
00928   /* Get rid of pesky quotes.  */
00929   if ('\'' == *input_line_pointer)
00930     {
00931       char * close;
00932 
00933       ++input_line_pointer;
00934       close = strchr (input_line_pointer, '\'');
00935       if (close)
00936        *close= ' ';
00937       else
00938        as_bad ("missing end-quote");
00939     }
00940 
00941   if ('\"' == *input_line_pointer)
00942     {
00943       char * close;
00944 
00945       ++input_line_pointer;
00946       close = strchr (input_line_pointer, '\"');
00947       if (close)
00948        *close= ' ';
00949       else
00950        as_bad ("missing end-quote");
00951     }
00952 
00953   switch (type)
00954     {
00955     case 'H':  /* 16-bit */
00956     case 'F':  /* 32-bit */
00957       expression (&exp);
00958       emit_expr (&exp, nbytes);
00959       break;
00960     case 'E':  /* 32-bit */
00961     case 'D':  /* 64-bit */
00962       md_atof (type, tmp, &nbytes);
00963       p = frag_more (nbytes);
00964       memcpy (p, tmp, nbytes);
00965       break;
00966     default:
00967       as_bad ("unsupported DC type");
00968       return;
00969     }
00970 
00971   demand_empty_rest_of_line ();
00972 }
00973 
00974 
00975 /* Provide minimal support for DS Define Storage.  */
00976 
00977 static void
00978 i370_ds (int unused ATTRIBUTE_UNUSED)
00979 {
00980   /* DS 0H or DS 0F or DS 0D.  */
00981   if ('0' == *input_line_pointer)
00982     {
00983       int alignment = 0;  /* Left shift 1 << align.  */
00984       input_line_pointer ++;
00985       switch (*input_line_pointer++)
00986        {
00987        case 'H':  /* 16-bit */
00988          alignment = 1;
00989          break;
00990        case 'F':  /* 32-bit */
00991          alignment = 2;
00992          break;
00993        case 'D':  /* 64-bit */
00994          alignment = 3;
00995          break;
00996        default:
00997          as_bad ("unsupported alignment");
00998          return;
00999        }
01000       frag_align (alignment, 0, 0);
01001       record_alignment (now_seg, alignment);
01002     }
01003   else
01004     as_bad ("this DS form not yet supported");
01005 }
01006 
01007 /* Solaris pseudo op to change to the .rodata section.  */
01008 
01009 static void
01010 i370_elf_rdata (int sect)
01011 {
01012   char *save_line = input_line_pointer;
01013   static char section[] = ".rodata\n";
01014 
01015   /* Just pretend this is .section .rodata.  */
01016   input_line_pointer = section;
01017   obj_elf_section (sect);
01018 
01019   input_line_pointer = save_line;
01020 }
01021 
01022 /* Pseudo op to make file scope bss items.  */
01023 
01024 static void
01025 i370_elf_lcomm (int unused ATTRIBUTE_UNUSED)
01026 {
01027   char *name;
01028   char c;
01029   char *p;
01030   offsetT size;
01031   symbolS *symbolP;
01032   offsetT align;
01033   segT old_sec;
01034   int old_subsec;
01035   char *pfrag;
01036   int align2;
01037 
01038   name = input_line_pointer;
01039   c = get_symbol_end ();
01040 
01041   /* Just after name is now '\0'.  */
01042   p = input_line_pointer;
01043   *p = c;
01044   SKIP_WHITESPACE ();
01045   if (*input_line_pointer != ',')
01046     {
01047       as_bad ("Expected comma after symbol-name: rest of line ignored.");
01048       ignore_rest_of_line ();
01049       return;
01050     }
01051 
01052   /* Skip ','.  */
01053   input_line_pointer++;
01054   if ((size = get_absolute_expression ()) < 0)
01055     {
01056       as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size);
01057       ignore_rest_of_line ();
01058       return;
01059     }
01060 
01061   /* The third argument to .lcomm is the alignment.  */
01062   if (*input_line_pointer != ',')
01063     align = 8;
01064   else
01065     {
01066       ++input_line_pointer;
01067       align = get_absolute_expression ();
01068       if (align <= 0)
01069         {
01070           as_warn ("ignoring bad alignment");
01071           align = 8;
01072         }
01073     }
01074 
01075   *p = 0;
01076   symbolP = symbol_find_or_make (name);
01077   *p = c;
01078 
01079   if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
01080     {
01081       as_bad ("Ignoring attempt to re-define symbol `%s'.",
01082               S_GET_NAME (symbolP));
01083       ignore_rest_of_line ();
01084       return;
01085     }
01086 
01087   if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
01088     {
01089       as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
01090               S_GET_NAME (symbolP),
01091               (long) S_GET_VALUE (symbolP),
01092               (long) size);
01093 
01094       ignore_rest_of_line ();
01095       return;
01096     }
01097 
01098   /* Allocate_bss:  */
01099   old_sec = now_seg;
01100   old_subsec = now_subseg;
01101   if (align)
01102     {
01103       /* Convert to a power of 2 alignment.  */
01104       for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
01105        ;
01106       if (align != 1)
01107         {
01108           as_bad ("Common alignment not a power of 2");
01109           ignore_rest_of_line ();
01110           return;
01111         }
01112     }
01113   else
01114     align2 = 0;
01115 
01116   record_alignment (bss_section, align2);
01117   subseg_set (bss_section, 0);
01118   if (align2)
01119     frag_align (align2, 0, 0);
01120   if (S_GET_SEGMENT (symbolP) == bss_section)
01121     symbol_get_frag (symbolP)->fr_symbol = 0;
01122   symbol_set_frag (symbolP, frag_now);
01123   pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
01124                   (char *) 0);
01125   *pfrag = 0;
01126   S_SET_SIZE (symbolP, size);
01127   S_SET_SEGMENT (symbolP, bss_section);
01128   subseg_set (old_sec, old_subsec);
01129   demand_empty_rest_of_line ();
01130 }
01131 
01132 /* Validate any relocations emitted for -mrelocatable, possibly adding
01133    fixups for word relocations in writable segments, so we can adjust
01134    them at runtime.  */
01135 
01136 static void
01137 i370_elf_validate_fix (fixS *fixp, segT seg)
01138 {
01139   if (fixp->fx_done || fixp->fx_pcrel)
01140     return;
01141 
01142   switch (shlib)
01143     {
01144     case SHLIB_NONE:
01145     case SHLIB_PIC:
01146       return;
01147 
01148     case SHILB_MRELOCATABLE:
01149       if (fixp->fx_r_type <= BFD_RELOC_UNUSED
01150           && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
01151           && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
01152           && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
01153           && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
01154           && fixp->fx_r_type != BFD_RELOC_32_BASEREL
01155           && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
01156           && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
01157           && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
01158           && strcmp (segment_name (seg), ".got2") != 0
01159           && strcmp (segment_name (seg), ".dtors") != 0
01160           && strcmp (segment_name (seg), ".ctors") != 0
01161           && strcmp (segment_name (seg), ".fixup") != 0
01162           && strcmp (segment_name (seg), ".stab") != 0
01163           && strcmp (segment_name (seg), ".gcc_except_table") != 0
01164           && strcmp (segment_name (seg), ".ex_shared") != 0)
01165         {
01166           if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
01167               || fixp->fx_r_type != BFD_RELOC_CTOR)
01168            as_bad_where (fixp->fx_file, fixp->fx_line,
01169                        "Relocation cannot be done when using -mrelocatable");
01170         }
01171       return;
01172     default:
01173       break;
01174     }
01175 }
01176 #endif /* OBJ_ELF */
01177 
01178 
01179 #define LITERAL_POOL_SUPPORT
01180 #ifdef LITERAL_POOL_SUPPORT
01181 /* Provide support for literal pools within the text section.
01182    Loosely based on similar code from tc-arm.c.
01183    We will use four symbols to locate four parts of the literal pool.
01184    These four sections contain 64,32,16 and 8-bit constants; we use
01185    four sections so that all memory access can be appropriately aligned.
01186    That is, we want to avoid mixing these together so that we don't
01187    waste space padding out to alignments.  The four pointers
01188    longlong_poolP, word_poolP, etc. point to a symbol labeling the
01189    start of each pool part.
01190  
01191    lit_pool_num increments from zero to infinity and uniquely id's
01192      -- its used to generate the *_poolP symbol name.  */
01193 
01194 #define MAX_LITERAL_POOL_SIZE 1024
01195 
01196 typedef struct literalS
01197 {
01198   struct expressionS  exp;
01199   char * sym_name;
01200   char size;  /* 1,2,4 or 8 */
01201   short offset;
01202 } literalT;
01203 
01204 literalT literals[MAX_LITERAL_POOL_SIZE];
01205 int next_literal_pool_place = 0; /* Next free entry in the pool.  */
01206 
01207 static symbolS *longlong_poolP = NULL;   /* 64-bit pool entries.  */
01208 static symbolS *word_poolP = NULL;       /* 32-bit pool entries.  */
01209 static symbolS *short_poolP = NULL;      /* 16-bit pool entries.  */
01210 static symbolS *byte_poolP = NULL;       /* 8-bit  pool entries.  */
01211 
01212 static int lit_pool_num = 1;
01213 
01214 /* Create a new, empty symbol.  */
01215 static symbolS *
01216 symbol_make_empty (void)
01217 {
01218   return symbol_create (FAKE_LABEL_NAME, undefined_section,
01219                      (valueT) 0, &zero_address_frag);
01220 }
01221 
01222 /* Make the first argument an address-relative expression
01223    by subtracting the second argument.  */
01224 
01225 static void
01226 i370_make_relative (expressionS *exx, expressionS *baseaddr)
01227 {
01228   if (O_constant == baseaddr->X_op)
01229     {
01230        exx->X_op = O_symbol;
01231        exx->X_add_number -= baseaddr->X_add_number;
01232     }
01233   else if (O_symbol == baseaddr->X_op)
01234     {
01235        exx->X_op = O_subtract;
01236        exx->X_op_symbol = baseaddr->X_add_symbol;
01237        exx->X_add_number -= baseaddr->X_add_number;
01238     }
01239   else if (O_uminus == baseaddr->X_op)
01240     {
01241        exx->X_op = O_add;
01242        exx->X_op_symbol = baseaddr->X_add_symbol;
01243        exx->X_add_number += baseaddr->X_add_number;
01244     }
01245   else
01246     as_bad ("Missing or bad .using directive");
01247 }
01248 /* Add an expression to the literal pool.  */
01249 
01250 static  void
01251 add_to_lit_pool (expressionS *exx, char *name, int sz)
01252 {
01253   int lit_count = 0;
01254   int offset_in_pool = 0;
01255 
01256   /* Start a new pool, if necessary.  */
01257   if (8 == sz && NULL == longlong_poolP)
01258     longlong_poolP = symbol_make_empty ();
01259   else if (4 == sz && NULL == word_poolP)
01260     word_poolP = symbol_make_empty ();
01261   else if (2 == sz && NULL == short_poolP)
01262     short_poolP = symbol_make_empty ();
01263   else if (1 == sz && NULL == byte_poolP)
01264     byte_poolP = symbol_make_empty ();
01265 
01266   /* Check if this literal value is already in the pool.
01267      FIXME: We should probably be checking expressions
01268             of type O_symbol as well.
01269      FIXME: This is probably(certainly?) broken for O_big,
01270             which includes 64-bit long-longs.  */
01271   while (lit_count < next_literal_pool_place)
01272     {
01273       if (exx->X_op == O_constant
01274           && literals[lit_count].exp.X_op == exx->X_op
01275           && literals[lit_count].exp.X_add_number == exx->X_add_number
01276           && literals[lit_count].exp.X_unsigned == exx->X_unsigned
01277           && literals[lit_count].size == sz)
01278         break;
01279       else if (literals[lit_count].sym_name
01280               && name
01281               && !strcmp (name, literals[lit_count].sym_name))
01282         break;
01283       if (sz == literals[lit_count].size)
01284        offset_in_pool += sz;
01285       lit_count ++;
01286     }
01287 
01288   if (lit_count == next_literal_pool_place) /* new entry */
01289     {
01290       if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE)
01291        as_bad ("Literal Pool Overflow");
01292 
01293       literals[next_literal_pool_place].exp = *exx;
01294       literals[next_literal_pool_place].size = sz;
01295       literals[next_literal_pool_place].offset = offset_in_pool;
01296       if (name)
01297        literals[next_literal_pool_place].sym_name = strdup (name);
01298       else
01299        literals[next_literal_pool_place].sym_name = NULL;
01300       next_literal_pool_place++;
01301     }
01302 
01303   /* ???_poolP points to the beginning of the literal pool.
01304      X_add_number is the offset from the beginning of the
01305      literal pool to this expr minus the location of the most
01306      recent .using directive.  Thus, the grand total value of the
01307      expression is the distance from .using to the literal.  */
01308   if (8 == sz)
01309     exx->X_add_symbol = longlong_poolP;
01310   else if (4 == sz)
01311     exx->X_add_symbol = word_poolP;
01312   else if (2 == sz)
01313     exx->X_add_symbol = short_poolP;
01314   else if (1 == sz)
01315     exx->X_add_symbol = byte_poolP;
01316   exx->X_add_number = offset_in_pool;
01317   exx->X_op_symbol = NULL;
01318 
01319   /* If the user has set up a base reg in another section,
01320      use that; otherwise use the text section.  */
01321   if (0 < i370_using_other_regno)
01322     i370_make_relative (exx, &i370_using_other_baseaddr);
01323   else
01324     i370_make_relative (exx, &i370_using_text_baseaddr);
01325 }
01326 
01327 /* The symbol setup for the literal pool is done in two steps.  First,
01328    a symbol that represents the start of the literal pool is created,
01329    above, in the add_to_pool() routine. This sym ???_poolP.
01330    However, we don't know what fragment its in until a bit later.
01331    So we defer the frag_now thing, and the symbol name, until .ltorg time.  */
01332 
01333 /* Can't use symbol_new here, so have to create a symbol and then at
01334    a later date assign it a value. Thats what these functions do.  */
01335 
01336 static void
01337 symbol_locate (symbolS *symbolP,
01338               const char *name,    /* It is copied, the caller can modify.  */
01339               segT segment,        /* Segment identifier (SEG_<something>).  */
01340               valueT valu,         /* Symbol value.  */
01341               fragS *frag)         /* Associated fragment.  */
01342 {
01343   size_t name_length;
01344   char *preserved_copy_of_name;
01345 
01346   name_length = strlen (name) + 1;      /* +1 for \0 */
01347   obstack_grow (&notes, name, name_length);
01348   preserved_copy_of_name = obstack_finish (&notes);
01349 
01350   S_SET_NAME (symbolP, preserved_copy_of_name);
01351 
01352   S_SET_SEGMENT (symbolP, segment);
01353   S_SET_VALUE (symbolP, valu);
01354   symbol_clear_list_pointers (symbolP);
01355 
01356   symbol_set_frag (symbolP, frag);
01357 
01358   /* Link to end of symbol chain.  */
01359   {
01360     extern int symbol_table_frozen;
01361 
01362     if (symbol_table_frozen)
01363       abort ();
01364   }
01365 
01366   symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
01367 
01368   obj_symbol_new_hook (symbolP);
01369 
01370 #ifdef tc_symbol_new_hook
01371   tc_symbol_new_hook (symbolP);
01372 #endif
01373 
01374 #define DEBUG_SYMS
01375 #ifdef DEBUG_SYMS
01376   verify_symbol_chain(symbol_rootP, symbol_lastP);
01377 #endif /* DEBUG_SYMS */
01378 }
01379 
01380 /* i370_addr_offset() will convert operand expressions
01381    that appear to be absolute into thier base-register
01382    relative form.  These expressions come in two types:
01383 
01384    (1) of the form "* + const" * where "*" means
01385    relative offset since the last using
01386    i.e. "*" means ".-using_baseaddr"
01387 
01388    (2) labels, which are never absolute, but are always
01389    relative to the last "using".  Anything with an alpha
01390    character is considered to be a label (since symbols
01391    can never be operands), and since we've already handled
01392    register operands. For example, "BL .L33" branch low
01393    to .L33 RX form insn frequently terminates for-loops.  */
01394 
01395 static bfd_boolean
01396 i370_addr_offset (expressionS *exx)
01397 {
01398   char *dot, *lab;
01399   int islabel = 0;
01400   int all_digits = 0;
01401 
01402   /* Search for a label; anything with an alpha char will do.
01403      Local labels consist of N digits followed by either b or f.  */
01404   lab = input_line_pointer;
01405   while (*lab && (',' != *lab) && ('(' != *lab))
01406     {
01407       if (ISDIGIT (*lab))
01408        all_digits = 1;
01409       else if (ISALPHA (*lab))
01410        {
01411          if (!all_digits)
01412            {
01413              islabel = 1;
01414              break;
01415            }
01416          else if (('f' == *lab) || ('b' == *lab))
01417            {
01418              islabel = 1;
01419              break;
01420            }
01421          if (all_digits)
01422            break;
01423        }
01424       else if ('.' != *lab)
01425         break;
01426       ++lab;
01427     }
01428 
01429   /* See if operand has a * in it.  */
01430   dot = strchr (input_line_pointer, '*');
01431 
01432   if (!dot && !islabel)
01433     return FALSE;
01434 
01435   /* Replace * with . and let expr munch on it.  */
01436   if (dot)
01437     *dot = '.';
01438   expression (exx);
01439 
01440   /* OK, now we have to subtract the "using" location.
01441      Normally branches appear in the text section only.  */
01442   if (0 == strncmp (now_seg->name, ".text", 5) || 0 > i370_using_other_regno)
01443     i370_make_relative (exx, &i370_using_text_baseaddr);
01444   else
01445     i370_make_relative (exx, &i370_using_other_baseaddr);
01446 
01447   /* Put the * back.  */
01448   if (dot)
01449     *dot = '*';
01450 
01451   return TRUE;
01452 }
01453 
01454 /* Handle address constants of various sorts.  */
01455 /* The currently supported types are
01456       =A(some_symb)
01457       =V(some_extern)
01458       =X'deadbeef'    hexadecimal
01459       =F'1234'        32-bit const int
01460       =H'1234'        16-bit const int.  */
01461 
01462 static bfd_boolean
01463 i370_addr_cons (expressionS *exp)
01464 {
01465   char *name;
01466   char *sym_name, delim;
01467   int name_len;
01468   int hex_len = 0;
01469   int cons_len = 0;
01470 
01471   name = input_line_pointer;
01472   sym_name = input_line_pointer;
01473   /* Find the spelling of the operand.  */
01474   if (name[0] == '=' && ISALPHA (name[1]))
01475     name = ++input_line_pointer;
01476   else
01477     return FALSE;
01478 
01479   switch (name[0])
01480     {
01481     case 'A': /* A == address-of.  */
01482     case 'V': /* V == extern.  */
01483       ++input_line_pointer;
01484       expression (exp);
01485 
01486       /* We use a simple string name to collapse together
01487          multiple refrences to the same address literal.  */
01488       name_len = strcspn (sym_name, ", ");
01489       delim = *(sym_name + name_len);
01490       *(sym_name + name_len) = 0x0;
01491       add_to_lit_pool (exp, sym_name, 4);
01492       *(sym_name + name_len) = delim;
01493 
01494       break;
01495     case 'H':
01496     case 'F':
01497     case 'X':
01498     case 'E':  /* Single-precision float point.  */
01499     case 'D':  /* Double-precision float point.  */
01500 
01501       /* H == 16-bit fixed-point const; expression must be const.  */
01502       /* F == fixed-point const; expression must be const.  */
01503       /* X == fixed-point const; expression must be const.  */
01504       if ('H' == name[0]) cons_len = 2;
01505       else if ('F' == name[0]) cons_len = 4;
01506       else if ('X' == name[0]) cons_len = -1;
01507       else if ('E' == name[0]) cons_len = 4;
01508       else if ('D' == name[0]) cons_len = 8;
01509 
01510       /* Extract length, if it is present;
01511         FIXME: assume single-digit length.  */
01512       if ('L' == name[1])
01513        {
01514          /* Should work for ASCII and EBCDIC.  */
01515          cons_len = name[2] - '0';
01516          input_line_pointer += 2;
01517        }
01518 
01519       ++input_line_pointer;
01520 
01521       /* Get rid of pesky quotes.  */
01522       if ('\'' == *input_line_pointer)
01523        {
01524          char * close;
01525          ++input_line_pointer;
01526          close = strchr (input_line_pointer, '\'');
01527          if (close)
01528            *close= ' ';
01529          else
01530            as_bad ("missing end-quote");
01531        }
01532       if ('\"' == *input_line_pointer)
01533        {
01534          char * close;
01535          ++input_line_pointer;
01536          close = strchr (input_line_pointer, '\"');
01537          if (close)
01538            *close= ' ';
01539          else
01540            as_bad ("missing end-quote");
01541        }
01542       if (('X' == name[0]) || ('E' == name[0]) || ('D' == name[0]))
01543        {
01544          char tmp[50];
01545          char *save;
01546 
01547          /* The length of hex constants is specified directly with L,
01548             or implied through the number of hex digits. For example:
01549             =X'AB'       one byte
01550             =X'abcd'     two bytes
01551             =X'000000AB' four bytes
01552             =XL4'AB'     four bytes, left-padded withn zero.  */
01553          if (('X' == name[0]) && (0 > cons_len))
01554            {
01555              save = input_line_pointer;
01556              while (*save)
01557               {
01558                 if (ISXDIGIT (*save))
01559                   hex_len++;
01560                 save++;
01561               }
01562              cons_len = (hex_len+1) /2;
01563            }
01564          /* I believe this works even for =XL8'dada0000beeebaaa'
01565             which should parse out to X_op == O_big
01566             Note that floats and doubles get represented as
01567             0d3.14159265358979  or 0f 2.7.  */
01568          tmp[0] = '0';
01569          tmp[1] = name[0];
01570          tmp[2] = 0;
01571          strcat (tmp, input_line_pointer);
01572          save = input_line_pointer;
01573          input_line_pointer = tmp;
01574          expression (exp);
01575          input_line_pointer = save + (input_line_pointer-tmp-2);
01576 
01577          /* Fix up lengths for floats and doubles.  */
01578          if (O_big == exp->X_op)
01579            exp->X_add_number = cons_len / CHARS_PER_LITTLENUM;
01580        }
01581       else
01582        expression (exp);
01583 
01584       /* O_big occurs when more than 4 bytes worth gets parsed.  */
01585       if ((exp->X_op != O_constant) && (exp->X_op != O_big))
01586        {
01587          as_bad ("expression not a constant");
01588          return FALSE;
01589        }
01590       add_to_lit_pool (exp, 0x0, cons_len);
01591       break;
01592 
01593     default:
01594       as_bad ("Unknown/unsupported address literal type");
01595       return FALSE;
01596     }
01597 
01598   return TRUE;
01599 }
01600 
01601 
01602 /* Dump the contents of the literal pool that we've accumulated so far.
01603    This aligns the pool to the size of the largest literal in the pool.  */
01604 
01605 static void
01606 i370_ltorg (int ignore ATTRIBUTE_UNUSED)
01607 {
01608   int litsize;
01609   int lit_count = 0;
01610   int biggest_literal_size = 0;
01611   int biggest_align = 0;
01612   char pool_name[20];
01613 
01614   if (strncmp (now_seg->name, ".text", 5))
01615     {
01616       if (i370_other_section == undefined_section)
01617        as_bad (".ltorg without prior .using in section %s",
01618               now_seg->name);
01619 
01620       if (i370_other_section != now_seg)
01621        as_bad (".ltorg in section %s paired to .using in section %s",
01622               now_seg->name, i370_other_section->name);
01623     }
01624 
01625   if (! longlong_poolP
01626       && ! word_poolP
01627       && ! short_poolP
01628       && ! byte_poolP)
01629     /* Nothing to do.  */
01630     return;
01631 
01632   /* Find largest literal .. 2 4 or 8.  */
01633   lit_count = 0;
01634   while (lit_count < next_literal_pool_place)
01635     {
01636       if (biggest_literal_size < literals[lit_count].size)
01637        biggest_literal_size = literals[lit_count].size;
01638       lit_count ++;
01639     }
01640   if (1 == biggest_literal_size) biggest_align = 0;
01641   else if (2 == biggest_literal_size) biggest_align = 1;
01642   else if (4 == biggest_literal_size) biggest_align = 2;
01643   else if (8 == biggest_literal_size) biggest_align = 3;
01644   else as_bad ("bad alignment of %d bytes in literal pool", biggest_literal_size);
01645   if (0 == biggest_align) biggest_align = 1;
01646 
01647   /* Align pool for short, word, double word accesses.  */
01648   frag_align (biggest_align, 0, 0);
01649   record_alignment (now_seg, biggest_align);
01650 
01651   /* Note that the gas listing will print only the first five
01652      entries in the pool .... wonder how to make it print more.  */
01653   /* Output largest literals first, then the smaller ones.  */
01654   for (litsize=8; litsize; litsize /=2)
01655     {
01656       symbolS *current_poolP = NULL;
01657       switch (litsize)
01658        {
01659        case 8:
01660          current_poolP = longlong_poolP; break;
01661        case 4:
01662          current_poolP = word_poolP; break;
01663        case 2:
01664          current_poolP = short_poolP; break;
01665        case 1:
01666          current_poolP = byte_poolP; break;
01667        default:
01668          as_bad ("bad literal size\n");
01669        }
01670       if (NULL == current_poolP)
01671        continue;
01672       sprintf (pool_name, ".LITP%01d%06d", litsize, lit_pool_num);
01673       symbol_locate (current_poolP, pool_name, now_seg,
01674                    (valueT) frag_now_fix (), frag_now);
01675       symbol_table_insert (current_poolP);
01676 
01677       lit_count = 0;
01678       while (lit_count < next_literal_pool_place)
01679        {
01680          if (litsize == literals[lit_count].size)
01681            {
01682 #define EMIT_ADDR_CONS_SYMBOLS
01683 #ifdef EMIT_ADDR_CONS_SYMBOLS
01684              /* Create a bogus symbol, add it to the pool ...
01685                 For the most part, I think this is a useless exercise,
01686                 except that having these symbol names in the objects
01687                 is vaguely useful for debugging.  */
01688              if (literals[lit_count].sym_name)
01689               {
01690                 symbolS * symP = symbol_make_empty ();
01691                 symbol_locate (symP, literals[lit_count].sym_name, now_seg,
01692                              (valueT) frag_now_fix (), frag_now);
01693                 symbol_table_insert (symP);
01694               }
01695 #endif /* EMIT_ADDR_CONS_SYMBOLS */
01696 
01697              emit_expr (&(literals[lit_count].exp), literals[lit_count].size);
01698            }
01699          lit_count ++;
01700        }
01701     }
01702 
01703   next_literal_pool_place = 0;
01704   longlong_poolP = NULL;
01705   word_poolP = NULL;
01706   short_poolP = NULL;
01707   byte_poolP = NULL;
01708   lit_pool_num++;
01709 }
01710 
01711 #endif /* LITERAL_POOL_SUPPORT */
01712 
01713 
01714 /* Add support for the HLASM-like USING directive to indicate
01715    the base register to use ...  we don't support the full
01716    hlasm semantics for this ... we merely pluck a base address
01717    and a register number out.  We print a warning if using is
01718    called multiple times.  I suppose we should check to see
01719    if the regno is valid.  */
01720 
01721 static void
01722 i370_using (int ignore ATTRIBUTE_UNUSED)
01723 {
01724   expressionS ex, baseaddr;
01725   int iregno;
01726   char *star;
01727 
01728   /* If "*" appears in a using, it means "."
01729      replace it with "." so that expr doesn't get confused.  */
01730   star = strchr (input_line_pointer, '*');
01731   if (star)
01732     *star = '.';
01733 
01734   /* The first arg to using will usually be ".", but it can
01735      be a more complex expression too.  */
01736   expression (&baseaddr);
01737   if (star)
01738     *star = '*';
01739   if (O_constant != baseaddr.X_op
01740       && O_symbol != baseaddr.X_op
01741       && O_uminus != baseaddr.X_op)
01742     as_bad (".using: base address expression illegal or too complex");
01743 
01744   if (*input_line_pointer != '\0') ++input_line_pointer;
01745 
01746   /* The second arg to using had better be a register.  */
01747   register_name (&ex);
01748   demand_empty_rest_of_line ();
01749   iregno = ex.X_add_number;
01750 
01751   if (0 == strncmp (now_seg->name, ".text", 5))
01752     {
01753       i370_using_text_baseaddr = baseaddr;
01754       i370_using_text_regno = iregno;
01755     }
01756   else
01757     {
01758       i370_using_other_baseaddr = baseaddr;
01759       i370_using_other_regno = iregno;
01760       i370_other_section = now_seg;
01761     }
01762 }
01763 
01764 static void
01765 i370_drop (int ignore ATTRIBUTE_UNUSED)
01766 {
01767   expressionS ex;
01768   int iregno;
01769 
01770   register_name (&ex);
01771   demand_empty_rest_of_line ();
01772   iregno = ex.X_add_number;
01773 
01774   if (0 == strncmp (now_seg->name, ".text", 5))
01775     {
01776       if (iregno != i370_using_text_regno)
01777        as_bad ("droping register %d in section %s does not match using register %d",
01778               iregno, now_seg->name, i370_using_text_regno);
01779 
01780       i370_using_text_regno = -1;
01781       i370_using_text_baseaddr.X_op = O_absent;
01782     }
01783   else
01784     {
01785       if (iregno != i370_using_other_regno)
01786        as_bad ("droping register %d in section %s does not match using register %d",
01787               iregno, now_seg->name, i370_using_other_regno);
01788 
01789       if (i370_other_section != now_seg)
01790        as_bad ("droping register %d in section %s previously used in section %s",
01791               iregno, now_seg->name, i370_other_section->name);
01792 
01793       i370_using_other_regno = -1;
01794       i370_using_other_baseaddr.X_op = O_absent;
01795       i370_other_section = undefined_section;
01796     }
01797 }
01798 
01799 
01800 /* We need to keep a list of fixups.  We can't simply generate them as
01801    we go, because that would require us to first create the frag, and
01802    that would screw up references to ``.''.  */
01803 
01804 struct i370_fixup
01805 {
01806   expressionS exp;
01807   int opindex;
01808   bfd_reloc_code_real_type reloc;
01809 };
01810 
01811 #define MAX_INSN_FIXUPS 5
01812 
01813 /* Handle a macro.  Gather all the operands, transform them as
01814    described by the macro, and call md_assemble recursively.  All the
01815    operands are separated by commas; we don't accept parentheses
01816    around operands here.  */
01817 
01818 static void
01819 i370_macro (char *str, const struct i370_macro *macro)
01820 {
01821   char *operands[10];
01822   unsigned int count;
01823   char *s;
01824   unsigned int len;
01825   const char *format;
01826   int arg;
01827   char *send;
01828   char *complete;
01829 
01830   /* Gather the users operands into the operands array.  */
01831   count = 0;
01832   s = str;
01833   while (1)
01834     {
01835       if (count >= sizeof operands / sizeof operands[0])
01836         break;
01837       operands[count++] = s;
01838       s = strchr (s, ',');
01839       if (s == (char *) NULL)
01840         break;
01841       *s++ = '\0';
01842     }
01843 
01844   if (count != macro->operands)
01845     {
01846       as_bad ("wrong number of operands");
01847       return;
01848     }
01849 
01850   /* Work out how large the string must be (the size is unbounded
01851      because it includes user input).  */
01852   len = 0;
01853   format = macro->format;
01854   while (*format != '\0')
01855     {
01856       if (*format != '%')
01857         {
01858           ++len;
01859           ++format;
01860         }
01861       else
01862         {
01863           arg = strtol (format + 1, &send, 10);
01864           know (send != format && arg >= 0 && (unsigned) arg < count);
01865           len += strlen (operands[arg]);
01866           format = send;
01867         }
01868     }
01869 
01870   /* Put the string together.  */
01871   complete = s = alloca (len + 1);
01872   format = macro->format;
01873   while (*format != '\0')
01874     {
01875       if (*format != '%')
01876         *s++ = *format++;
01877       else
01878         {
01879           arg = strtol (format + 1, &send, 10);
01880           strcpy (s, operands[arg]);
01881           s += strlen (s);
01882           format = send;
01883         }
01884     }
01885   *s = '\0';
01886 
01887   /* Assemble the constructed instruction.  */
01888   md_assemble (complete);
01889 }
01890 
01891 /* This routine is called for each instruction to be assembled.  */
01892 
01893 void
01894 md_assemble (char *str)
01895 {
01896   char *s, *opcode_str;
01897   const struct i370_opcode *opcode;
01898   i370_insn_t insn;
01899   const unsigned char *opindex_ptr;
01900   int have_optional_index, have_optional_basereg, have_optional_reg;
01901   int skip_optional_index, skip_optional_basereg, skip_optional_reg;
01902   int use_text=0, use_other=0;
01903   int off_by_one;
01904   struct i370_fixup fixups[MAX_INSN_FIXUPS];
01905   int fc;
01906   char *f;
01907   int i;
01908 #ifdef OBJ_ELF
01909   bfd_reloc_code_real_type reloc;
01910 #endif
01911 
01912   /* Get the opcode.  */
01913   for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
01914     ;
01915   if (*s != '\0')
01916     *s++ = '\0';
01917   opcode_str = str;
01918 
01919   /* Look up the opcode in the hash table.  */
01920   opcode = (const struct i370_opcode *) hash_find (i370_hash, str);
01921   if (opcode == (const struct i370_opcode *) NULL)
01922     {
01923       const struct i370_macro *macro;
01924 
01925       assert (i370_macro_hash);
01926       macro = (const struct i370_macro *) hash_find (i370_macro_hash, str);
01927       if (macro == (const struct i370_macro *) NULL)
01928         as_bad ("Unrecognized opcode: `%s'", str);
01929       else
01930        i370_macro (s, macro);
01931 
01932       return;
01933     }
01934 
01935   insn = opcode->opcode;
01936 
01937   str = s;
01938   while (ISSPACE (*str))
01939     ++str;
01940 
01941   /* I370 operands are either expressions or address constants.
01942      Many operand types are optional.  The optional operands
01943      are always surrounded by parens, and are used to denote the base
01944      register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
01945      the fully-formed "A R1, D2(X2,B2)".  Note also the = sign,
01946      such as A R1,=A(i) where the address-of operator =A implies
01947      use of both a base register, and a missing index register.
01948 
01949      So, before we start seriously parsing the operands, we check
01950      to see if we have an optional operand, and, if we do, we count
01951      the number of commas to see which operand should be omitted.  */
01952 
01953   have_optional_index = have_optional_basereg = have_optional_reg = 0;
01954   for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
01955     {
01956       const struct i370_operand *operand;
01957 
01958       operand = &i370_operands[*opindex_ptr];
01959       if ((operand->flags & I370_OPERAND_INDEX) != 0)
01960        have_optional_index = 1;
01961       if ((operand->flags & I370_OPERAND_BASE) != 0)
01962        have_optional_basereg = 1;
01963       if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
01964        have_optional_reg = 1;
01965     }
01966 
01967   skip_optional_index = skip_optional_basereg = skip_optional_reg = 0;
01968   if (have_optional_index || have_optional_basereg)
01969     {
01970       unsigned int opcount, nwanted;
01971 
01972       /* There is an optional operand.  Count the number of
01973         commas and open-parens in the input line.  */
01974       if (*str == '\0')
01975        opcount = 0;
01976       else
01977        {
01978          opcount = 1;
01979          s = str;
01980          while ((s = strpbrk (s, ",(=")) != (char *) NULL)
01981            {
01982              ++opcount;
01983              ++s;
01984              if (',' == *s) ++s;  /* avoid counting things like (, */
01985              if ('=' == *s) { ++s; --opcount; }
01986            }
01987        }
01988 
01989       /* If there are fewer operands in the line then are called
01990         for by the instruction, we want to skip the optional
01991         operand.  */
01992       nwanted = strlen ((char *) opcode->operands);
01993       if (have_optional_index)
01994        {
01995          if (opcount < nwanted)
01996            skip_optional_index = 1;
01997          if (have_optional_basereg && ((opcount+1) < nwanted))
01998            skip_optional_basereg = 1;
01999          if (have_optional_reg && ((opcount+1) < nwanted))
02000            skip_optional_reg = 1;
02001        }
02002       else
02003        {
02004          if (have_optional_basereg && (opcount < nwanted))
02005            skip_optional_basereg = 1;
02006          if (have_optional_reg && (opcount < nwanted))
02007            skip_optional_reg = 1;
02008        }
02009     }
02010 
02011   /* Perform some off-by-one hacks on the length field of certain instructions.
02012      Its such a shame to have to do this, but the problem is that HLASM got
02013      defined so that the lengths differ by one from the actual machine instructions.
02014      this code should probably be moved to a special inster-operand routine.
02015      Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
02016      hack alert -- aren't *all* SS instructions affected ??  */
02017   off_by_one = 0;
02018   if (0 == strcasecmp ("CLC", opcode->name)
02019       || 0 == strcasecmp ("ED", opcode->name)
02020       || 0 == strcasecmp ("EDMK", opcode->name)
02021       || 0 == strcasecmp ("MVC", opcode->name)
02022       || 0 == strcasecmp ("MVCIN", opcode->name)
02023       || 0 == strcasecmp ("MVN", opcode->name)
02024       || 0 == strcasecmp ("MVZ", opcode->name)
02025       || 0 == strcasecmp ("NC", opcode->name)
02026       || 0 == strcasecmp ("OC", opcode->name)
02027       || 0 == strcasecmp ("XC", opcode->name))
02028     off_by_one = 1;
02029 
02030   /* Gather the operands.  */
02031   fc = 0;
02032   for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
02033     {
02034       const struct i370_operand *operand;
02035       const char *errmsg;
02036       char *hold;
02037       expressionS ex;
02038 
02039       operand = &i370_operands[*opindex_ptr];
02040       errmsg = NULL;
02041 
02042       /* If this is an index operand, and we are skipping it,
02043         just insert a zero.  */
02044       if (skip_optional_index &&
02045          ((operand->flags & I370_OPERAND_INDEX) != 0))
02046         {
02047           insn = i370_insert_operand (insn, operand, 0);
02048           continue;
02049         }
02050 
02051       /* If this is the base operand, and we are skipping it,
02052         just insert the current using basreg.  */
02053       if (skip_optional_basereg &&
02054           ((operand->flags & I370_OPERAND_BASE) != 0))
02055         {
02056           int basereg = -1;
02057           if (use_text)
02058             {
02059               if (0 == strncmp (now_seg->name, ".text", 5)
02060                 || 0 > i370_using_other_regno)
02061               basereg = i370_using_text_regno;
02062               else
02063               basereg = i370_using_other_regno;
02064             }
02065           else if (use_other)
02066             {
02067               if (0 > i370_using_other_regno)
02068               basereg = i370_using_text_regno;
02069               else
02070               basereg = i370_using_other_regno;
02071             }
02072           if (0 > basereg)
02073            as_bad ("not using any base register");
02074 
02075           insn = i370_insert_operand (insn, operand, basereg);
02076           continue;
02077         }
02078 
02079       /* If this is an optional operand, and we are skipping it,
02080         Use zero (since a non-zero value would denote a register)  */
02081       if (skip_optional_reg
02082          && ((operand->flags & I370_OPERAND_OPTIONAL) != 0))
02083         {
02084           insn = i370_insert_operand (insn, operand, 0);
02085           continue;
02086         }
02087 
02088       /* Gather the operand.  */
02089       hold = input_line_pointer;
02090       input_line_pointer = str;
02091 
02092       /* Register names are only allowed where there are registers.  */
02093       if ((operand->flags & I370_OPERAND_GPR) != 0)
02094         {
02095           /* Quickie hack to get past things like (,r13).  */
02096           if (skip_optional_index && (',' == *input_line_pointer))
02097             {
02098               *input_line_pointer = ' ';
02099               input_line_pointer ++;
02100             }
02101 
02102           if (! register_name (&ex))
02103            as_bad ("expecting a register for operand %d",
02104                   (int) (opindex_ptr - opcode->operands + 1));
02105         }
02106 
02107       /* Check for an address constant expression.  */
02108       /* We will put PSW-relative addresses in the text section,
02109          and address literals in the .data (or other) section.  */
02110       else if (i370_addr_cons (&ex))
02111        use_other = 1;
02112       else if (i370_addr_offset (&ex))
02113        use_text = 1;
02114       else expression (&ex);
02115 
02116       str = input_line_pointer;
02117       input_line_pointer = hold;
02118 
02119       /* Perform some off-by-one hacks on the length field of certain instructions.
02120          Its such a shame to have to do this, but the problem is that HLASM got
02121          defined so that the programmer specifies a length that is one greater
02122          than what the machine instruction wants.  Sigh.  */
02123       if (off_by_one && (0 == strcasecmp ("SS L", operand->name)))
02124        ex.X_add_number --;
02125 
02126       if (ex.X_op == O_illegal)
02127         as_bad ("illegal operand");
02128       else if (ex.X_op == O_absent)
02129         as_bad ("missing operand");
02130       else if (ex.X_op == O_register)
02131        insn = i370_insert_operand (insn, operand, ex.X_add_number);
02132       else if (ex.X_op == O_constant)
02133         {
02134 #ifdef OBJ_ELF
02135           /* Allow @HA, @L, @H on constants.
02136              Well actually, no we don't; there really don't make sense
02137              (at least not to me) for the i370.  However, this code is
02138              left here for any dubious future expansion reasons.  */
02139           char *orig_str = str;
02140 
02141           if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
02142             switch (reloc)
02143               {
02144               default:
02145               str = orig_str;
02146               break;
02147 
02148               case BFD_RELOC_LO16:
02149               /* X_unsigned is the default, so if the user has done
02150                    something which cleared it, we always produce a
02151                    signed value.  */
02152               ex.X_add_number = (((ex.X_add_number & 0xffff)
02153                                 ^ 0x8000)
02154                                - 0x8000);
02155               break;
02156 
02157               case BFD_RELOC_HI16:
02158               ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
02159               break;
02160 
02161               case BFD_RELOC_HI16_S:
02162               ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
02163                                + ((ex.X_add_number >> 15) & 1));
02164               break;
02165               }
02166 #endif
02167           insn = i370_insert_operand (insn, operand, ex.X_add_number);
02168         }
02169 #ifdef OBJ_ELF
02170       else if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
02171         {
02172           as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
02173 
02174           /* We need to generate a fixup for this expression.  */
02175           if (fc >= MAX_INSN_FIXUPS)
02176             as_fatal ("too many fixups");
02177           fixups[fc].exp = ex;
02178           fixups[fc].opindex = 0;
02179           fixups[fc].reloc = reloc;
02180           ++fc;
02181         }
02182 #endif /* OBJ_ELF */
02183       else
02184         {
02185           /* We need to generate a fixup for this expression.  */
02186           /* Typically, the expression will just be a symbol ...
02187                printf ("insn %s needs fixup for %s \n",
02188                     opcode->name, ex.X_add_symbol->bsym->name);  */
02189 
02190           if (fc >= MAX_INSN_FIXUPS)
02191             as_fatal ("too many fixups");
02192           fixups[fc].exp = ex;
02193           fixups[fc].opindex = *opindex_ptr;
02194           fixups[fc].reloc = BFD_RELOC_UNUSED;
02195           ++fc;
02196         }
02197 
02198       /* Skip over delimiter (close paren, or comma).  */
02199       if ((')' == *str) && (',' == *(str+1)))
02200        ++str;
02201       if (*str != '\0')
02202        ++str;
02203     }
02204 
02205   while (ISSPACE (*str))
02206     ++str;
02207 
02208   if (*str != '\0')
02209     as_bad ("junk at end of line: `%s'", str);
02210 
02211   /* Write out the instruction.  */
02212   f = frag_more (opcode->len);
02213   if (4 >= opcode->len)
02214     md_number_to_chars (f, insn.i[0], opcode->len);
02215   else
02216     {
02217       md_number_to_chars (f, insn.i[0], 4);
02218 
02219       if (6 == opcode->len)
02220        md_number_to_chars ((f + 4), ((insn.i[1])>>16), 2);
02221       else
02222        {
02223          /* Not used --- don't have any 8 byte instructions.  */
02224          as_bad ("Internal Error: bad instruction length");
02225          md_number_to_chars ((f + 4), insn.i[1], opcode->len -4);
02226        }
02227     }
02228 
02229   /* Create any fixups.  At this point we do not use a
02230      bfd_reloc_code_real_type, but instead just use the
02231      BFD_RELOC_UNUSED plus the operand index.  This lets us easily
02232      handle fixups for any operand type, although that is admittedly
02233      not a very exciting feature.  We pick a BFD reloc type in
02234      md_apply_fix.  */
02235   for (i = 0; i < fc; i++)
02236     {
02237       const struct i370_operand *operand;
02238 
02239       operand = &i370_operands[fixups[i].opindex];
02240       if (fixups[i].reloc != BFD_RELOC_UNUSED)
02241        {
02242          reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
02243          int size;
02244          fixS *fixP;
02245 
02246          if (!reloc_howto)
02247            abort ();
02248 
02249          size = bfd_get_reloc_size (reloc_howto);
02250 
02251          if (size < 1 || size > 4)
02252            abort ();
02253 
02254          printf (" gwana doo fixup %d \n", i);
02255          fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
02256                            &fixups[i].exp, reloc_howto->pc_relative,
02257                            fixups[i].reloc);
02258 
02259          /* Turn off complaints that the addend is too large for things like
02260             foo+100000@ha.  */
02261          switch (fixups[i].reloc)
02262            {
02263            case BFD_RELOC_16_GOTOFF:
02264            case BFD_RELOC_LO16:
02265            case BFD_RELOC_HI16:
02266            case BFD_RELOC_HI16_S:
02267              fixP->fx_no_overflow = 1;
02268              break;
02269            default:
02270              break;
02271            }
02272        }
02273       else
02274        {
02275          fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->len,
02276                      &fixups[i].exp,
02277                      (operand->flags & I370_OPERAND_RELATIVE) != 0,
02278                      ((bfd_reloc_code_real_type)
02279                      (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
02280        }
02281     }
02282 }
02283 
02284 
02285 /* Pseudo-op handling.  */
02286 
02287 /* The .byte pseudo-op.  This is similar to the normal .byte
02288    pseudo-op, but it can also take a single ASCII string.  */
02289 
02290 static void
02291 i370_byte (int ignore ATTRIBUTE_UNUSED)
02292 {
02293   if (*input_line_pointer != '\"')
02294     {
02295       cons (1);
02296       return;
02297     }
02298 
02299   /* Gather characters.  A real double quote is doubled.  Unusual
02300      characters are not permitted.  */
02301   ++input_line_pointer;
02302   while (1)
02303     {
02304       char c;
02305 
02306       c = *input_line_pointer++;
02307 
02308       if (c == '\"')
02309         {
02310         if (*input_line_pointer != '\"')
02311             break;
02312           ++input_line_pointer;
02313         }
02314 
02315       FRAG_APPEND_1_CHAR (c);
02316     }
02317 
02318   demand_empty_rest_of_line ();
02319 }
02320 
02321 /* The .tc pseudo-op.  This is used when generating XCOFF and ELF.
02322    This takes two or more arguments.
02323 
02324    When generating XCOFF output, the first argument is the name to
02325    give to this location in the toc; this will be a symbol with class
02326    TC.  The rest of the arguments are 4 byte values to actually put at
02327    this location in the TOC; often there is just one more argument, a
02328    relocatable symbol reference.
02329 
02330    When not generating XCOFF output, the arguments are the same, but
02331    the first argument is simply ignored.  */
02332 
02333 static void
02334 i370_tc (int ignore ATTRIBUTE_UNUSED)
02335 {
02336 
02337   /* Skip the TOC symbol name.  */
02338   while (is_part_of_name (*input_line_pointer)
02339          || *input_line_pointer == '['
02340          || *input_line_pointer == ']'
02341          || *input_line_pointer == '{'
02342          || *input_line_pointer == '}')
02343     ++input_line_pointer;
02344 
02345   /* Align to a four byte boundary.  */
02346   frag_align (2, 0, 0);
02347   record_alignment (now_seg, 2);
02348 
02349   if (*input_line_pointer != ',')
02350     demand_empty_rest_of_line ();
02351   else
02352     {
02353       ++input_line_pointer;
02354       cons (4);
02355     }
02356 }
02357 
02358 /* Turn a string in input_line_pointer into a floating point constant
02359    of type TYPE, and store the appropriate bytes in *LITP.  The number
02360    of LITTLENUMS emitted is stored in *SIZEP.  An error message is
02361    returned, or NULL on OK.  */
02362 
02363 char *
02364 md_atof (int type, char *litp, int *sizep)
02365 {
02366   int prec;
02367   LITTLENUM_TYPE words[4];
02368   char *t;
02369   int i;
02370 
02371   switch (type)
02372     {
02373     case 'f':
02374     case 'E':
02375       type = 'f';
02376       prec = 2;
02377       break;
02378 
02379     case 'd':
02380     case 'D':
02381       type = 'd';
02382       prec = 4;
02383       break;
02384 
02385     default:
02386       *sizep = 0;
02387       return "bad call to md_atof";
02388     }
02389 
02390   /* 360/370/390 have two float formats: an old, funky 360 single-precision
02391    * format, and the ieee format.  Support only the ieee format.  */
02392   t = atof_ieee (input_line_pointer, type, words);
02393   if (t)
02394     input_line_pointer = t;
02395 
02396   *sizep = prec * 2;
02397 
02398   for (i = 0; i < prec; i++)
02399     {
02400       md_number_to_chars (litp, (valueT) words[i], 2);
02401       litp += 2;
02402     }
02403 
02404   return NULL;
02405 }
02406 
02407 /* Write a value out to the object file, using the appropriate
02408    endianness.  */
02409 
02410 void
02411 md_number_to_chars (char *buf, valueT val, int n)
02412 {
02413   number_to_chars_bigendian (buf, val, n);
02414 }
02415 
02416 /* Align a section (I don't know why this is machine dependent).  */
02417 
02418 valueT
02419 md_section_align (asection *seg, valueT addr)
02420 {
02421   int align = bfd_get_section_alignment (stdoutput, seg);
02422 
02423   return (addr + (1 << align) - 1) & (-1 << align);
02424 }
02425 
02426 /* We don't have any form of relaxing.  */
02427 
02428 int
02429 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
02430                             asection *seg ATTRIBUTE_UNUSED)
02431 {
02432   abort ();
02433   return 0;
02434 }
02435 
02436 /* Convert a machine dependent frag.  We never generate these.  */
02437 
02438 void
02439 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
02440                asection *sec ATTRIBUTE_UNUSED,
02441                fragS *fragp ATTRIBUTE_UNUSED)
02442 {
02443   abort ();
02444 }
02445 
02446 /* We have no need to default values of symbols.  */
02447 
02448 symbolS *
02449 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
02450 {
02451   return 0;
02452 }
02453 
02454 /* Functions concerning relocs.  */
02455 
02456 /* The location from which a PC relative jump should be calculated,
02457    given a PC relative reloc.  */
02458 
02459 long
02460 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
02461 {
02462   return fixp->fx_frag->fr_address + fixp->fx_where;
02463 }
02464 
02465 /* Apply a fixup to the object code.  This is called for all the
02466    fixups we generated by the call to fix_new_exp, above.  In the call
02467    above we used a reloc code which was the largest legal reloc code
02468    plus the operand index.  Here we undo that to recover the operand
02469    index.  At this point all symbol values should be fully resolved,
02470    and we attempt to completely resolve the reloc.  If we can not do
02471    that, we determine the correct reloc code and put it back in the
02472    fixup.
02473 
02474    See gas/cgen.c for more sample code and explanations of what's
02475    going on here.  */
02476 
02477 void
02478 md_apply_fix (fixS *fixP, valueT * valP, segT seg)
02479 {
02480   valueT value = * valP;
02481 
02482   if (fixP->fx_addsy != NULL)
02483     {
02484 #ifdef DEBUG
02485       printf ("\nmd_apply_fix: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
02486              S_GET_NAME (fixP->fx_addsy),
02487              fixP->fx_frag->fr_address + fixP->fx_where,
02488              fixP->fx_file, fixP->fx_line,
02489              S_GET_VALUE (fixP->fx_addsy), value);
02490 #endif
02491     }
02492   else
02493     fixP->fx_done = 1;
02494 
02495   /* Apply fixups to operands.  Note that there should be no relocations
02496      for any operands, since no instruction ever takes an operand
02497      that requires reloc.  */
02498   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
02499     {
02500       int opindex;
02501       const struct i370_operand *operand;
02502       char *where;
02503       i370_insn_t insn;
02504 
02505       opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
02506 
02507       operand = &i370_operands[opindex];
02508 
02509 #ifdef DEBUG
02510       printf ("\nmd_apply_fix: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
02511              operand->name,
02512              fixP->fx_frag->fr_address + fixP->fx_where,
02513              fixP->fx_file, fixP->fx_line,
02514              value);
02515 #endif
02516       /* Fetch the instruction, insert the fully resolved operand
02517          value, and stuff the instruction back again.
02518          fisxp->fx_size is the length of the instruction.  */
02519       where = fixP->fx_frag->fr_literal + fixP->fx_where;
02520       insn.i[0] = bfd_getb32 ((unsigned char *) where);
02521 
02522       if (6 <= fixP->fx_size)
02523        /* Deal with 48-bit insn's.  */
02524        insn.i[1] = bfd_getb32 (((unsigned char *) where)+4);
02525 
02526       insn = i370_insert_operand (insn, operand, (offsetT) value);
02527       bfd_putb32 ((bfd_vma) insn.i[0], (unsigned char *) where);
02528 
02529       if (6 <= fixP->fx_size)
02530        /* Deal with 48-bit insn's.  */
02531        bfd_putb32 ((bfd_vma) insn.i[1], (((unsigned char *) where)+4));
02532 
02533       /* We are done, right? right !!  */
02534       fixP->fx_done = 1;
02535       if (fixP->fx_done)
02536        /* Nothing else to do here.  */
02537        return;
02538 
02539       /* Determine a BFD reloc value based on the operand information.
02540         We are only prepared to turn a few of the operands into
02541         relocs.  In fact, we support *zero* operand relocations ...
02542         Why?  Because we are not expecting the compiler to generate
02543         any operands that need relocation.  Due to the 12-bit naturew of
02544         i370 addressing, this would be unusual.  */
02545         {
02546           char *sfile;
02547           unsigned int sline;
02548 
02549           /* Use expr_symbol_where to see if this is an expression
02550              symbol.  */
02551           if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
02552             as_bad_where (fixP->fx_file, fixP->fx_line,
02553                        "unresolved expression that must be resolved");
02554           else
02555             as_bad_where (fixP->fx_file, fixP->fx_line,
02556                        "unsupported relocation type");
02557           fixP->fx_done = 1;
02558           return;
02559         }
02560     }
02561   else
02562     {
02563       /* We branch to here if the fixup is not to a symbol that
02564          appears in an instruction operand, but is rather some
02565          declared storage.  */
02566 #ifdef OBJ_ELF
02567       i370_elf_validate_fix (fixP, seg);
02568 #endif
02569 #ifdef DEBUG
02570       printf ("md_apply_fix: reloc case %d in segment  %s %s:%d\n",
02571              fixP->fx_r_type, segment_name (seg), fixP->fx_file, fixP->fx_line);
02572       printf ("\tcurrent fixup value is 0x%x \n", value);
02573 #endif
02574       switch (fixP->fx_r_type)
02575         {
02576         case BFD_RELOC_32:
02577         case BFD_RELOC_CTOR:
02578           if (fixP->fx_pcrel)
02579             fixP->fx_r_type = BFD_RELOC_32_PCREL;
02580          /* Fall through.  */
02581 
02582         case BFD_RELOC_RVA:
02583         case BFD_RELOC_32_PCREL:
02584         case BFD_RELOC_32_BASEREL:
02585 #ifdef DEBUG
02586           printf ("\t32 bit relocation at 0x%x\n",
02587                 fixP->fx_frag->fr_address + fixP->fx_where);
02588 #endif
02589           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
02590                            value, 4);
02591           break;
02592 
02593         case BFD_RELOC_LO16:
02594         case BFD_RELOC_16:
02595           if (fixP->fx_pcrel)
02596             as_bad_where (fixP->fx_file, fixP->fx_line,
02597                        "cannot emit PC relative %s relocation%s%s",
02598                        bfd_get_reloc_code_name (fixP->fx_r_type),
02599                        fixP->fx_addsy != NULL ? " against " : "",
02600                        (fixP->fx_addsy != NULL
02601                         ? S_GET_NAME (fixP->fx_addsy)
02602                         : ""));
02603 
02604           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
02605                            value, 2);
02606           break;
02607 
02608           /* This case happens when you write, for example,
02609              lis %r3,(L1-L2)@ha
02610              where L1 and L2 are defined later.  */
02611         case BFD_RELOC_HI16:
02612           if (fixP->fx_pcrel)
02613             abort ();
02614           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
02615                            value >> 16, 2);
02616           break;
02617         case BFD_RELOC_HI16_S:
02618           if (fixP->fx_pcrel)
02619             abort ();
02620           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
02621                            (value + 0x8000) >> 16, 2);
02622           break;
02623 
02624         case BFD_RELOC_8:
02625           if (fixP->fx_pcrel)
02626             abort ();
02627 
02628           md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
02629                            value, 1);
02630           break;
02631 
02632         default:
02633           fprintf (stderr,
02634                 "Gas failure, reloc value %d\n", fixP->fx_r_type);
02635           fflush (stderr);
02636           abort ();
02637         }
02638     }
02639 
02640   fixP->fx_addnumber = value;
02641 }
02642 
02643 /* Generate a reloc for a fixup.  */
02644 
02645 arelent *
02646 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
02647 {
02648   arelent *reloc;
02649 
02650   reloc = xmalloc (sizeof (arelent));
02651 
02652   reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
02653   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
02654   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
02655   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
02656   if (reloc->howto == (reloc_howto_type *) NULL)
02657     {
02658       as_bad_where (fixp->fx_file, fixp->fx_line,
02659                   "reloc %d not supported by object file format", (int)fixp->fx_r_type);
02660       return NULL;
02661     }
02662   reloc->addend = fixp->fx_addnumber;
02663 
02664 #ifdef DEBUG
02665   printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
02666          fixp->fx_addsy->bsym->name,
02667          fixp->fx_file, fixp->fx_line,
02668          reloc->address, reloc->addend);
02669 #endif
02670 
02671   return reloc;
02672 }
02673 
02674 /* The target specific pseudo-ops which we support.  */
02675 
02676 const pseudo_typeS md_pseudo_table[] =
02677 {
02678   /* Pseudo-ops which must be overridden.  */
02679   { "byte",     i370_byte,  0 },
02680 
02681   { "dc",       i370_dc,    0 },
02682   { "ds",       i370_ds,    0 },
02683   { "rmode",    i370_rmode, 0 },
02684   { "csect",    i370_csect, 0 },
02685   { "dsect",    i370_dsect, 0 },
02686 
02687   /* enable ebcdic strings e.g. for 3270 support */
02688   { "ebcdic",   i370_ebcdic,       0 },
02689 
02690 #ifdef OBJ_ELF
02691   { "long",     i370_elf_cons,     4 },
02692   { "word",     i370_elf_cons,     4 },
02693   { "short",    i370_elf_cons,     2 },
02694   { "rdata",    i370_elf_rdata,    0 },
02695   { "rodata",   i370_elf_rdata,    0 },
02696   { "lcomm",    i370_elf_lcomm,    0 },
02697 #endif
02698 
02699   /* This pseudo-op is used even when not generating XCOFF output.  */
02700   { "tc",       i370_tc,    0 },
02701 
02702   /* dump the literal pool */
02703   { "ltorg",    i370_ltorg, 0 },
02704 
02705   /* support the hlasm-style USING directive */
02706   { "using",    i370_using, 0 },
02707   { "drop",     i370_drop,  0 },
02708 
02709   { NULL,       NULL,              0 }
02710 };
02711