Home | History | Annotate | Line # | Download | only in config
tc-m32r.c revision 1.1.1.3
      1      1.1  christos /* tc-m32r.c -- Assembler for the Renesas M32R.
      2  1.1.1.3  christos    Copyright (C) 1996-2016 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos    This file is part of GAS, the GNU Assembler.
      5      1.1  christos 
      6      1.1  christos    GAS is free software; you can redistribute it and/or modify
      7      1.1  christos    it under the terms of the GNU General Public License as published by
      8      1.1  christos    the Free Software Foundation; either version 3, or (at your option)
      9      1.1  christos    any later version.
     10      1.1  christos 
     11      1.1  christos    GAS is distributed in the hope that it will be useful,
     12      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14      1.1  christos    GNU General Public License for more details.
     15      1.1  christos 
     16      1.1  christos    You should have received a copy of the GNU General Public License
     17      1.1  christos    along with GAS; see the file COPYING.  If not, write to
     18      1.1  christos    the Free Software Foundation, 51 Franklin Street - Fifth Floor,
     19      1.1  christos    Boston, MA 02110-1301, USA.  */
     20      1.1  christos 
     21      1.1  christos #include "as.h"
     22      1.1  christos #include "safe-ctype.h"
     23      1.1  christos #include "subsegs.h"
     24      1.1  christos #include "symcat.h"
     25      1.1  christos #include "opcodes/m32r-desc.h"
     26      1.1  christos #include "opcodes/m32r-opc.h"
     27      1.1  christos #include "cgen.h"
     28      1.1  christos #include "elf/m32r.h"
     29      1.1  christos 
     30      1.1  christos /* Linked list of symbols that are debugging symbols to be defined as the
     31      1.1  christos    beginning of the current instruction.  */
     32      1.1  christos typedef struct sym_link
     33      1.1  christos {
     34      1.1  christos   struct sym_link *next;
     35      1.1  christos   symbolS *symbol;
     36      1.1  christos } sym_linkS;
     37      1.1  christos 
     38      1.1  christos static sym_linkS *debug_sym_link = (sym_linkS *) 0;
     39      1.1  christos 
     40      1.1  christos /* Structure to hold all of the different components describing
     41      1.1  christos    an individual instruction.  */
     42      1.1  christos typedef struct
     43      1.1  christos {
     44      1.1  christos   const CGEN_INSN *insn;
     45      1.1  christos   const CGEN_INSN *orig_insn;
     46      1.1  christos   CGEN_FIELDS fields;
     47      1.1  christos #if CGEN_INT_INSN_P
     48      1.1  christos   CGEN_INSN_INT buffer[1];
     49      1.1  christos #define INSN_VALUE(buf) (*(buf))
     50      1.1  christos #else
     51      1.1  christos   unsigned char buffer[CGEN_MAX_INSN_SIZE];
     52      1.1  christos #define INSN_VALUE(buf) (buf)
     53      1.1  christos #endif
     54      1.1  christos   char *addr;
     55      1.1  christos   fragS *frag;
     56      1.1  christos   int num_fixups;
     57      1.1  christos   fixS *fixups[GAS_CGEN_MAX_FIXUPS];
     58      1.1  christos   int indices[MAX_OPERAND_INSTANCES];
     59      1.1  christos   sym_linkS *debug_sym_link;
     60      1.1  christos }
     61      1.1  christos m32r_insn;
     62      1.1  christos 
     63      1.1  christos /* prev_insn.insn is non-null if last insn was a 16 bit insn on a 32 bit
     64      1.1  christos    boundary (i.e. was the first of two 16 bit insns).  */
     65      1.1  christos static m32r_insn prev_insn;
     66      1.1  christos 
     67      1.1  christos /* Non-zero if we've seen a relaxable insn since the last 32 bit
     68      1.1  christos    alignment request.  */
     69      1.1  christos static int seen_relaxable_p = 0;
     70      1.1  christos 
     71      1.1  christos /* Non-zero if we are generating PIC code.  */
     72      1.1  christos int pic_code;
     73      1.1  christos 
     74      1.1  christos /* Non-zero if -relax specified, in which case sufficient relocs are output
     75      1.1  christos    for the linker to do relaxing.
     76      1.1  christos    We do simple forms of relaxing internally, but they are always done.
     77      1.1  christos    This flag does not apply to them.  */
     78      1.1  christos static int m32r_relax;
     79      1.1  christos 
     80      1.1  christos /* Non-zero if warn when a high/shigh reloc has no matching low reloc.
     81      1.1  christos    Each high/shigh reloc must be paired with it's low cousin in order to
     82      1.1  christos    properly calculate the addend in a relocatable link (since there is a
     83      1.1  christos    potential carry from the low to the high/shigh).
     84      1.1  christos    This option is off by default though for user-written assembler code it
     85      1.1  christos    might make sense to make the default be on (i.e. have gcc pass a flag
     86      1.1  christos    to turn it off).  This warning must not be on for GCC created code as
     87      1.1  christos    optimization may delete the low but not the high/shigh (at least we
     88      1.1  christos    shouldn't assume or require it to).  */
     89      1.1  christos static int warn_unmatched_high = 0;
     90      1.1  christos 
     91      1.1  christos /* 1 if -m32rx has been specified, in which case support for
     92      1.1  christos      the extended M32RX instruction set should be enabled.
     93      1.1  christos    2 if -m32r2 has been specified, in which case support for
     94      1.1  christos      the extended M32R2 instruction set should be enabled.  */
     95      1.1  christos static int enable_m32rx = 0; /* Default to M32R.  */
     96      1.1  christos 
     97      1.1  christos /* Non-zero if -m32rx -hidden has been specified, in which case support for
     98      1.1  christos    the special M32RX instruction set should be enabled.  */
     99      1.1  christos static int enable_special = 0;
    100      1.1  christos 
    101      1.1  christos /* Non-zero if -bitinst has been specified, in which case support
    102      1.1  christos    for extended M32R bit-field instruction set should be enabled.  */
    103      1.1  christos static int enable_special_m32r = 1;
    104      1.1  christos 
    105      1.1  christos /* Non-zero if -float has been specified, in which case support for
    106      1.1  christos    extended M32R floating point instruction set should be enabled.  */
    107      1.1  christos static int enable_special_float = 0;
    108      1.1  christos 
    109      1.1  christos /* Non-zero if the programmer should be warned when an explicit parallel
    110      1.1  christos    instruction might have constraint violations.  */
    111      1.1  christos static int warn_explicit_parallel_conflicts = 1;
    112      1.1  christos 
    113      1.1  christos /* Non-zero if the programmer should not receive any messages about
    114      1.1  christos    parallel instruction with potential or real constraint violations.
    115      1.1  christos    The ability to suppress these messages is intended only for hardware
    116      1.1  christos    vendors testing the chip.  It superceedes
    117      1.1  christos    warn_explicit_parallel_conflicts.  */
    118      1.1  christos static int ignore_parallel_conflicts = 0;
    119      1.1  christos 
    120      1.1  christos /* Non-zero if insns can be made parallel.  */
    121      1.1  christos static int use_parallel = 0;
    122      1.1  christos 
    123      1.1  christos /* Non-zero if optimizations should be performed.  */
    124      1.1  christos static int optimize;
    125      1.1  christos 
    126      1.1  christos /* m32r er_flags.  */
    127      1.1  christos static int m32r_flags = 0;
    128      1.1  christos 
    129      1.1  christos /* Stuff for .scomm symbols.  */
    130      1.1  christos static segT     sbss_section;
    131      1.1  christos static asection scom_section;
    132      1.1  christos static asymbol  scom_symbol;
    133      1.1  christos 
    134      1.1  christos const char comment_chars[]        = ";";
    135      1.1  christos const char line_comment_chars[]   = "#";
    136      1.1  christos const char line_separator_chars[] = "!";
    137      1.1  christos const char EXP_CHARS[]            = "eE";
    138      1.1  christos const char FLT_CHARS[]            = "dD";
    139      1.1  christos 
    140      1.1  christos /* Relocations against symbols are done in two
    141      1.1  christos    parts, with a HI relocation and a LO relocation.  Each relocation
    142      1.1  christos    has only 16 bits of space to store an addend.  This means that in
    143      1.1  christos    order for the linker to handle carries correctly, it must be able
    144      1.1  christos    to locate both the HI and the LO relocation.  This means that the
    145      1.1  christos    relocations must appear in order in the relocation table.
    146      1.1  christos 
    147      1.1  christos    In order to implement this, we keep track of each unmatched HI
    148      1.1  christos    relocation.  We then sort them so that they immediately precede the
    149      1.1  christos    corresponding LO relocation.  */
    150      1.1  christos 
    151      1.1  christos struct m32r_hi_fixup
    152      1.1  christos {
    153      1.1  christos   /* Next HI fixup.  */
    154      1.1  christos   struct m32r_hi_fixup *next;
    155      1.1  christos 
    156      1.1  christos   /* This fixup.  */
    157      1.1  christos   fixS *fixp;
    158      1.1  christos 
    159      1.1  christos   /* The section this fixup is in.  */
    160      1.1  christos   segT seg;
    161      1.1  christos };
    162      1.1  christos 
    163      1.1  christos /* The list of unmatched HI relocs.  */
    164      1.1  christos 
    165      1.1  christos static struct m32r_hi_fixup *m32r_hi_fixup_list;
    166      1.1  christos 
    167  1.1.1.3  christos static const struct
    169      1.1  christos {
    170      1.1  christos   enum bfd_architecture bfd_mach;
    171      1.1  christos   int mach_flags;
    172      1.1  christos } mach_table[] =
    173      1.1  christos {
    174      1.1  christos   { bfd_mach_m32r,  (1<<MACH_M32R) },
    175      1.1  christos   { bfd_mach_m32rx, (1<<MACH_M32RX) },
    176      1.1  christos   { bfd_mach_m32r2, (1<<MACH_M32R2) }
    177      1.1  christos };
    178      1.1  christos 
    179      1.1  christos static void
    180      1.1  christos allow_m32rx (int on)
    181      1.1  christos {
    182      1.1  christos   enable_m32rx = on;
    183      1.1  christos 
    184      1.1  christos   if (stdoutput != NULL)
    185      1.1  christos     bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach_table[on].bfd_mach);
    186      1.1  christos 
    187      1.1  christos   if (gas_cgen_cpu_desc != NULL)
    188      1.1  christos     gas_cgen_cpu_desc->machs = mach_table[on].mach_flags;
    189      1.1  christos }
    190      1.1  christos 
    191      1.1  christos #define M32R_SHORTOPTS "O::K:"
    193      1.1  christos 
    194      1.1  christos const char *md_shortopts = M32R_SHORTOPTS;
    195      1.1  christos 
    196      1.1  christos enum md_option_enums
    197      1.1  christos {
    198      1.1  christos   OPTION_M32R = OPTION_MD_BASE,
    199      1.1  christos   OPTION_M32RX,
    200      1.1  christos   OPTION_M32R2,
    201      1.1  christos   OPTION_BIG,
    202      1.1  christos   OPTION_LITTLE,
    203      1.1  christos   OPTION_PARALLEL,
    204      1.1  christos   OPTION_NO_PARALLEL,
    205      1.1  christos   OPTION_WARN_PARALLEL,
    206      1.1  christos   OPTION_NO_WARN_PARALLEL,
    207      1.1  christos   OPTION_IGNORE_PARALLEL,
    208      1.1  christos   OPTION_NO_IGNORE_PARALLEL,
    209      1.1  christos   OPTION_SPECIAL,
    210      1.1  christos   OPTION_SPECIAL_M32R,
    211      1.1  christos   OPTION_NO_SPECIAL_M32R,
    212      1.1  christos   OPTION_SPECIAL_FLOAT,
    213      1.1  christos   OPTION_WARN_UNMATCHED,
    214      1.1  christos   OPTION_NO_WARN_UNMATCHED
    215      1.1  christos };
    216      1.1  christos 
    217      1.1  christos struct option md_longopts[] =
    218      1.1  christos {
    219      1.1  christos   {"m32r",  no_argument, NULL, OPTION_M32R},
    220      1.1  christos   {"m32rx", no_argument, NULL, OPTION_M32RX},
    221      1.1  christos   {"m32r2", no_argument, NULL, OPTION_M32R2},
    222      1.1  christos   {"big", no_argument, NULL, OPTION_BIG},
    223      1.1  christos   {"little", no_argument, NULL, OPTION_LITTLE},
    224      1.1  christos   {"EB", no_argument, NULL, OPTION_BIG},
    225      1.1  christos   {"EL", no_argument, NULL, OPTION_LITTLE},
    226      1.1  christos   {"parallel", no_argument, NULL, OPTION_PARALLEL},
    227      1.1  christos   {"no-parallel", no_argument, NULL, OPTION_NO_PARALLEL},
    228      1.1  christos   {"warn-explicit-parallel-conflicts", no_argument, NULL, OPTION_WARN_PARALLEL},
    229      1.1  christos   {"Wp", no_argument, NULL, OPTION_WARN_PARALLEL},
    230      1.1  christos   {"no-warn-explicit-parallel-conflicts", no_argument, NULL, OPTION_NO_WARN_PARALLEL},
    231      1.1  christos   {"Wnp", no_argument, NULL, OPTION_NO_WARN_PARALLEL},
    232      1.1  christos   {"ignore-parallel-conflicts", no_argument, NULL, OPTION_IGNORE_PARALLEL},
    233      1.1  christos   {"Ip", no_argument, NULL, OPTION_IGNORE_PARALLEL},
    234      1.1  christos   {"no-ignore-parallel-conflicts", no_argument, NULL, OPTION_NO_IGNORE_PARALLEL},
    235      1.1  christos   {"nIp", no_argument, NULL, OPTION_NO_IGNORE_PARALLEL},
    236      1.1  christos   {"hidden", no_argument, NULL, OPTION_SPECIAL},
    237      1.1  christos   {"bitinst", no_argument, NULL, OPTION_SPECIAL_M32R},
    238      1.1  christos   {"no-bitinst", no_argument, NULL, OPTION_NO_SPECIAL_M32R},
    239      1.1  christos   {"float", no_argument, NULL, OPTION_SPECIAL_FLOAT},
    240      1.1  christos   /* Sigh.  I guess all warnings must now have both variants.  */
    241      1.1  christos   {"warn-unmatched-high", no_argument, NULL, OPTION_WARN_UNMATCHED},
    242      1.1  christos   {"Wuh", no_argument, NULL, OPTION_WARN_UNMATCHED},
    243      1.1  christos   {"no-warn-unmatched-high", no_argument, NULL, OPTION_NO_WARN_UNMATCHED},
    244      1.1  christos   {"Wnuh", no_argument, NULL, OPTION_NO_WARN_UNMATCHED},
    245      1.1  christos   {NULL, no_argument, NULL, 0}
    246      1.1  christos };
    247      1.1  christos 
    248      1.1  christos size_t md_longopts_size = sizeof (md_longopts);
    249      1.1  christos 
    250      1.1  christos static void
    251      1.1  christos little (int on)
    252      1.1  christos {
    253      1.1  christos   target_big_endian = ! on;
    254      1.1  christos }
    255      1.1  christos 
    256      1.1  christos /* Use parallel execution.  */
    257      1.1  christos 
    258      1.1  christos static int
    259      1.1  christos parallel (void)
    260      1.1  christos {
    261      1.1  christos   if (! enable_m32rx)
    262      1.1  christos     return 0;
    263      1.1  christos 
    264      1.1  christos   if (use_parallel == 1)
    265      1.1  christos     return 1;
    266      1.1  christos 
    267      1.1  christos   return 0;
    268      1.1  christos }
    269  1.1.1.3  christos 
    270      1.1  christos int
    271      1.1  christos md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
    272      1.1  christos {
    273      1.1  christos   switch (c)
    274      1.1  christos     {
    275      1.1  christos     case 'O':
    276      1.1  christos       optimize = 1;
    277      1.1  christos       use_parallel = 1;
    278      1.1  christos       break;
    279      1.1  christos 
    280      1.1  christos     case OPTION_M32R:
    281      1.1  christos       allow_m32rx (0);
    282      1.1  christos       break;
    283      1.1  christos 
    284      1.1  christos     case OPTION_M32RX:
    285      1.1  christos       allow_m32rx (1);
    286      1.1  christos       break;
    287      1.1  christos 
    288      1.1  christos     case OPTION_M32R2:
    289      1.1  christos       allow_m32rx (2);
    290      1.1  christos       enable_special = 1;
    291      1.1  christos       enable_special_m32r = 1;
    292      1.1  christos       break;
    293      1.1  christos 
    294      1.1  christos     case OPTION_BIG:
    295      1.1  christos       target_big_endian = 1;
    296      1.1  christos       break;
    297      1.1  christos 
    298      1.1  christos     case OPTION_LITTLE:
    299      1.1  christos       target_big_endian = 0;
    300      1.1  christos       break;
    301      1.1  christos 
    302      1.1  christos     case OPTION_PARALLEL:
    303      1.1  christos       use_parallel = 1;
    304      1.1  christos       break;
    305      1.1  christos 
    306      1.1  christos     case OPTION_NO_PARALLEL:
    307      1.1  christos       use_parallel = 0;
    308      1.1  christos       break;
    309      1.1  christos 
    310      1.1  christos     case OPTION_WARN_PARALLEL:
    311      1.1  christos       warn_explicit_parallel_conflicts = 1;
    312      1.1  christos       break;
    313      1.1  christos 
    314      1.1  christos     case OPTION_NO_WARN_PARALLEL:
    315      1.1  christos       warn_explicit_parallel_conflicts = 0;
    316      1.1  christos       break;
    317      1.1  christos 
    318      1.1  christos     case OPTION_IGNORE_PARALLEL:
    319      1.1  christos       ignore_parallel_conflicts = 1;
    320      1.1  christos       break;
    321      1.1  christos 
    322      1.1  christos     case OPTION_NO_IGNORE_PARALLEL:
    323      1.1  christos       ignore_parallel_conflicts = 0;
    324      1.1  christos       break;
    325      1.1  christos 
    326      1.1  christos     case OPTION_SPECIAL:
    327      1.1  christos       if (enable_m32rx)
    328      1.1  christos 	enable_special = 1;
    329      1.1  christos       else
    330      1.1  christos 	{
    331      1.1  christos 	  /* Pretend that we do not recognise this option.  */
    332      1.1  christos 	  as_bad (_("Unrecognised option: -hidden"));
    333      1.1  christos 	  return 0;
    334      1.1  christos 	}
    335      1.1  christos       break;
    336      1.1  christos 
    337      1.1  christos     case OPTION_SPECIAL_M32R:
    338      1.1  christos       enable_special_m32r = 1;
    339      1.1  christos       break;
    340      1.1  christos 
    341      1.1  christos     case OPTION_NO_SPECIAL_M32R:
    342      1.1  christos       enable_special_m32r = 0;
    343      1.1  christos       break;
    344      1.1  christos 
    345      1.1  christos     case OPTION_SPECIAL_FLOAT:
    346      1.1  christos       enable_special_float = 1;
    347      1.1  christos       break;
    348      1.1  christos 
    349      1.1  christos     case OPTION_WARN_UNMATCHED:
    350      1.1  christos       warn_unmatched_high = 1;
    351      1.1  christos       break;
    352      1.1  christos 
    353      1.1  christos     case OPTION_NO_WARN_UNMATCHED:
    354      1.1  christos       warn_unmatched_high = 0;
    355      1.1  christos       break;
    356      1.1  christos 
    357      1.1  christos     case 'K':
    358      1.1  christos       if (strcmp (arg, "PIC") != 0)
    359      1.1  christos         as_warn (_("Unrecognized option following -K"));
    360      1.1  christos       else
    361      1.1  christos         pic_code = 1;
    362      1.1  christos       break;
    363      1.1  christos 
    364      1.1  christos     default:
    365      1.1  christos       return 0;
    366      1.1  christos     }
    367      1.1  christos 
    368      1.1  christos   return 1;
    369      1.1  christos }
    370      1.1  christos 
    371      1.1  christos void
    372      1.1  christos md_show_usage (FILE *stream)
    373      1.1  christos {
    374      1.1  christos   fprintf (stream, _(" M32R specific command line options:\n"));
    375      1.1  christos 
    376      1.1  christos   fprintf (stream, _("\
    377      1.1  christos   -m32r                   disable support for the m32rx instruction set\n"));
    378      1.1  christos   fprintf (stream, _("\
    379      1.1  christos   -m32rx                  support the extended m32rx instruction set\n"));
    380      1.1  christos   fprintf (stream, _("\
    381      1.1  christos   -m32r2                  support the extended m32r2 instruction set\n"));
    382      1.1  christos   fprintf (stream, _("\
    383      1.1  christos   -EL,-little             produce little endian code and data\n"));
    384      1.1  christos   fprintf (stream, _("\
    385      1.1  christos   -EB,-big                produce big endian code and data\n"));
    386      1.1  christos   fprintf (stream, _("\
    387      1.1  christos   -parallel               try to combine instructions in parallel\n"));
    388      1.1  christos   fprintf (stream, _("\
    389      1.1  christos   -no-parallel            disable -parallel\n"));
    390      1.1  christos   fprintf (stream, _("\
    391      1.1  christos   -no-bitinst             disallow the M32R2's extended bit-field instructions\n"));
    392      1.1  christos   fprintf (stream, _("\
    393      1.1  christos   -O                      try to optimize code.  Implies -parallel\n"));
    394      1.1  christos 
    395      1.1  christos   fprintf (stream, _("\
    396      1.1  christos   -warn-explicit-parallel-conflicts     warn when parallel instructions\n"));
    397      1.1  christos   fprintf (stream, _("\
    398      1.1  christos                                          might violate contraints\n"));
    399      1.1  christos   fprintf (stream, _("\
    400      1.1  christos   -no-warn-explicit-parallel-conflicts  do not warn when parallel\n"));
    401      1.1  christos   fprintf (stream, _("\
    402      1.1  christos                                          instructions might violate contraints\n"));
    403      1.1  christos   fprintf (stream, _("\
    404      1.1  christos   -Wp                     synonym for -warn-explicit-parallel-conflicts\n"));
    405      1.1  christos   fprintf (stream, _("\
    406      1.1  christos   -Wnp                    synonym for -no-warn-explicit-parallel-conflicts\n"));
    407      1.1  christos   fprintf (stream, _("\
    408      1.1  christos   -ignore-parallel-conflicts            do not check parallel instructions\n"));
    409      1.1  christos   fprintf (stream, _("\
    410      1.1  christos                                          for constraint violations\n"));
    411      1.1  christos   fprintf (stream, _("\
    412      1.1  christos   -no-ignore-parallel-conflicts         check parallel instructions for\n"));
    413      1.1  christos   fprintf (stream, _("\
    414      1.1  christos                                          constraint violations\n"));
    415      1.1  christos   fprintf (stream, _("\
    416      1.1  christos   -Ip                     synonym for -ignore-parallel-conflicts\n"));
    417      1.1  christos   fprintf (stream, _("\
    418      1.1  christos   -nIp                    synonym for -no-ignore-parallel-conflicts\n"));
    419      1.1  christos 
    420      1.1  christos   fprintf (stream, _("\
    421      1.1  christos   -warn-unmatched-high    warn when an (s)high reloc has no matching low reloc\n"));
    422      1.1  christos   fprintf (stream, _("\
    423      1.1  christos   -no-warn-unmatched-high do not warn about missing low relocs\n"));
    424      1.1  christos   fprintf (stream, _("\
    425      1.1  christos   -Wuh                    synonym for -warn-unmatched-high\n"));
    426      1.1  christos   fprintf (stream, _("\
    427      1.1  christos   -Wnuh                   synonym for -no-warn-unmatched-high\n"));
    428      1.1  christos 
    429      1.1  christos   fprintf (stream, _("\
    430      1.1  christos   -KPIC                   generate PIC\n"));
    431      1.1  christos }
    432      1.1  christos 
    433      1.1  christos /* Set by md_assemble for use by m32r_fill_insn.  */
    434      1.1  christos static subsegT prev_subseg;
    435      1.1  christos static segT prev_seg;
    436      1.1  christos 
    437      1.1  christos #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
    438      1.1  christos symbolS * GOT_symbol;
    439      1.1  christos 
    440      1.1  christos static inline int
    441      1.1  christos m32r_PIC_related_p (symbolS *sym)
    442      1.1  christos {
    443      1.1  christos   expressionS *exp;
    444      1.1  christos 
    445      1.1  christos   if (! sym)
    446      1.1  christos     return 0;
    447      1.1  christos 
    448      1.1  christos   if (sym == GOT_symbol)
    449      1.1  christos     return 1;
    450      1.1  christos 
    451      1.1  christos   exp = symbol_get_value_expression (sym);
    452      1.1  christos 
    453      1.1  christos   return (exp->X_op == O_PIC_reloc
    454      1.1  christos           || exp->X_md == BFD_RELOC_M32R_26_PLTREL
    455      1.1  christos           || m32r_PIC_related_p (exp->X_add_symbol)
    456      1.1  christos           || m32r_PIC_related_p (exp->X_op_symbol));
    457      1.1  christos }
    458      1.1  christos 
    459      1.1  christos static inline int
    460      1.1  christos m32r_check_fixup (expressionS *main_exp, bfd_reloc_code_real_type *r_type_p)
    461      1.1  christos {
    462      1.1  christos   expressionS *exp = main_exp;
    463      1.1  christos 
    464      1.1  christos   if (exp->X_op == O_add && m32r_PIC_related_p (exp->X_op_symbol))
    465      1.1  christos     return 1;
    466      1.1  christos 
    467      1.1  christos   if (exp->X_op == O_symbol && exp->X_add_symbol)
    468      1.1  christos     {
    469      1.1  christos       if (exp->X_add_symbol == GOT_symbol)
    470      1.1  christos         {
    471      1.1  christos           *r_type_p = BFD_RELOC_M32R_GOTPC24;
    472      1.1  christos           return 0;
    473      1.1  christos         }
    474      1.1  christos     }
    475      1.1  christos   else if (exp->X_op == O_add)
    476      1.1  christos     {
    477      1.1  christos       exp = symbol_get_value_expression (exp->X_add_symbol);
    478      1.1  christos       if (! exp)
    479      1.1  christos         return 0;
    480      1.1  christos     }
    481      1.1  christos 
    482      1.1  christos   if (exp->X_op == O_PIC_reloc)
    483      1.1  christos     {
    484      1.1  christos       *r_type_p = exp->X_md;
    485      1.1  christos       if (exp == main_exp)
    486      1.1  christos         exp->X_op = O_symbol;
    487      1.1  christos       else
    488      1.1  christos        {
    489      1.1  christos           main_exp->X_add_symbol = exp->X_add_symbol;
    490      1.1  christos           main_exp->X_add_number += exp->X_add_number;
    491      1.1  christos        }
    492      1.1  christos     }
    493      1.1  christos   else
    494      1.1  christos     return (m32r_PIC_related_p (exp->X_add_symbol)
    495      1.1  christos             || m32r_PIC_related_p (exp->X_op_symbol));
    496      1.1  christos 
    497      1.1  christos   return 0;
    498      1.1  christos }
    499      1.1  christos 
    500      1.1  christos /* FIXME: Should be machine generated.  */
    501      1.1  christos #define NOP_INSN     0x7000
    502      1.1  christos #define PAR_NOP_INSN 0xf000 /* Can only be used in 2nd slot.  */
    503      1.1  christos 
    504      1.1  christos /* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
    505      1.1  christos    of an rs_align_code fragment.  */
    506      1.1  christos 
    507      1.1  christos void
    508      1.1  christos m32r_handle_align (fragS *fragp)
    509      1.1  christos {
    510      1.1  christos   static const unsigned char nop_pattern[] = { 0xf0, 0x00 };
    511      1.1  christos   static const unsigned char multi_nop_pattern[] = { 0x70, 0x00, 0xf0, 0x00 };
    512      1.1  christos 
    513      1.1  christos   int bytes, fix;
    514      1.1  christos   char *p;
    515      1.1  christos 
    516      1.1  christos   if (fragp->fr_type != rs_align_code)
    517      1.1  christos     return;
    518      1.1  christos 
    519      1.1  christos   bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
    520      1.1  christos   p = fragp->fr_literal + fragp->fr_fix;
    521      1.1  christos   fix = 0;
    522      1.1  christos 
    523      1.1  christos   if (bytes & 1)
    524      1.1  christos     {
    525      1.1  christos       fix = 1;
    526      1.1  christos       *p++ = 0;
    527      1.1  christos       bytes--;
    528      1.1  christos     }
    529      1.1  christos 
    530      1.1  christos   if (bytes & 2)
    531      1.1  christos     {
    532      1.1  christos       memcpy (p, nop_pattern, 2);
    533      1.1  christos       p += 2;
    534      1.1  christos       bytes -= 2;
    535      1.1  christos       fix += 2;
    536      1.1  christos     }
    537      1.1  christos 
    538      1.1  christos   memcpy (p, multi_nop_pattern, 4);
    539      1.1  christos 
    540      1.1  christos   fragp->fr_fix += fix;
    541      1.1  christos   fragp->fr_var = 4;
    542      1.1  christos }
    543      1.1  christos 
    544      1.1  christos /* If the last instruction was the first of 2 16 bit insns,
    545      1.1  christos    output a nop to move the PC to a 32 bit boundary.
    546      1.1  christos 
    547      1.1  christos    This is done via an alignment specification since branch relaxing
    548      1.1  christos    may make it unnecessary.
    549      1.1  christos 
    550      1.1  christos    Internally, we need to output one of these each time a 32 bit insn is
    551      1.1  christos    seen after an insn that is relaxable.  */
    552      1.1  christos 
    553      1.1  christos static void
    554      1.1  christos fill_insn (int ignore ATTRIBUTE_UNUSED)
    555      1.1  christos {
    556      1.1  christos   frag_align_code (2, 0);
    557      1.1  christos   prev_insn.insn = NULL;
    558      1.1  christos   seen_relaxable_p = 0;
    559      1.1  christos }
    560      1.1  christos 
    561      1.1  christos /* Record the symbol so that when we output the insn, we can create
    562      1.1  christos    a symbol that is at the start of the instruction.  This is used
    563      1.1  christos    to emit the label for the start of a breakpoint without causing
    564      1.1  christos    the assembler to emit a NOP if the previous instruction was a
    565      1.1  christos    16 bit instruction.  */
    566      1.1  christos 
    567      1.1  christos static void
    568      1.1  christos debug_sym (int ignore ATTRIBUTE_UNUSED)
    569      1.1  christos {
    570      1.1  christos   char *name;
    571      1.1  christos   char delim;
    572      1.1  christos   symbolS *symbolP;
    573  1.1.1.2  christos   sym_linkS *lnk;
    574      1.1  christos 
    575      1.1  christos   delim = get_symbol_name (&name);
    576      1.1  christos 
    577      1.1  christos   if ((symbolP = symbol_find (name)) == NULL
    578      1.1  christos       && (symbolP = md_undefined_symbol (name)) == NULL)
    579      1.1  christos     symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
    580      1.1  christos 
    581      1.1  christos   symbol_table_insert (symbolP);
    582      1.1  christos   if (S_IS_DEFINED (symbolP) && (S_GET_SEGMENT (symbolP) != reg_section
    583      1.1  christos                                  || S_IS_EXTERNAL (symbolP)
    584      1.1  christos                                  || S_IS_WEAK (symbolP)))
    585      1.1  christos     /* xgettext:c-format */
    586      1.1  christos     as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
    587      1.1  christos 
    588  1.1.1.3  christos   else
    589      1.1  christos     {
    590      1.1  christos       lnk = XNEW (sym_linkS);
    591      1.1  christos       lnk->symbol = symbolP;
    592      1.1  christos       lnk->next = debug_sym_link;
    593      1.1  christos       debug_sym_link = lnk;
    594      1.1  christos       symbol_get_obj (symbolP)->local = 1;
    595  1.1.1.2  christos     }
    596      1.1  christos 
    597      1.1  christos   (void) restore_line_pointer (delim);
    598      1.1  christos   demand_empty_rest_of_line ();
    599      1.1  christos }
    600      1.1  christos 
    601      1.1  christos /* Second pass to expanding the debug symbols, go through linked
    602      1.1  christos    list of symbols and reassign the address.  */
    603      1.1  christos 
    604      1.1  christos static void
    605      1.1  christos expand_debug_syms (sym_linkS *syms, int align)
    606      1.1  christos {
    607      1.1  christos   char *save_input_line = input_line_pointer;
    608      1.1  christos   sym_linkS *next_syms;
    609      1.1  christos 
    610      1.1  christos   if (!syms)
    611      1.1  christos     return;
    612      1.1  christos 
    613      1.1  christos   (void) frag_align_code (align, 0);
    614      1.1  christos   for (; syms != (sym_linkS *) 0; syms = next_syms)
    615      1.1  christos     {
    616  1.1.1.3  christos       symbolS *symbolP = syms->symbol;
    617      1.1  christos       next_syms = syms->next;
    618      1.1  christos       input_line_pointer = (char *) ".\n";
    619      1.1  christos       pseudo_set (symbolP);
    620      1.1  christos       free ((char *) syms);
    621      1.1  christos     }
    622      1.1  christos 
    623      1.1  christos   input_line_pointer = save_input_line;
    624      1.1  christos }
    625      1.1  christos 
    626      1.1  christos void
    627      1.1  christos m32r_flush_pending_output (void)
    628      1.1  christos {
    629      1.1  christos   if (debug_sym_link)
    630      1.1  christos     {
    631      1.1  christos       expand_debug_syms (debug_sym_link, 1);
    632      1.1  christos       debug_sym_link = (sym_linkS *) 0;
    633      1.1  christos     }
    634      1.1  christos }
    635      1.1  christos 
    636      1.1  christos /* Cover function to fill_insn called after a label and at end of assembly.
    637      1.1  christos    The result is always 1: we're called in a conditional to see if the
    638      1.1  christos    current line is a label.  */
    639      1.1  christos 
    640      1.1  christos int
    641      1.1  christos m32r_fill_insn (int done)
    642      1.1  christos {
    643      1.1  christos   if (prev_seg != NULL)
    644      1.1  christos     {
    645      1.1  christos       segT seg = now_seg;
    646      1.1  christos       subsegT subseg = now_subseg;
    647      1.1  christos 
    648      1.1  christos       subseg_set (prev_seg, prev_subseg);
    649      1.1  christos 
    650      1.1  christos       fill_insn (0);
    651      1.1  christos 
    652      1.1  christos       subseg_set (seg, subseg);
    653      1.1  christos     }
    654      1.1  christos 
    655      1.1  christos   if (done && debug_sym_link)
    656      1.1  christos     {
    657      1.1  christos       expand_debug_syms (debug_sym_link, 1);
    658      1.1  christos       debug_sym_link = (sym_linkS *) 0;
    659      1.1  christos     }
    660      1.1  christos 
    661      1.1  christos   return 1;
    662      1.1  christos }
    663      1.1  christos 
    664      1.1  christos /* The default target format to use.  */
    666      1.1  christos 
    667      1.1  christos const char *
    668      1.1  christos m32r_target_format (void)
    669      1.1  christos {
    670      1.1  christos #ifdef TE_LINUX
    671      1.1  christos   if (target_big_endian)
    672      1.1  christos     return "elf32-m32r-linux";
    673      1.1  christos   else
    674      1.1  christos     return "elf32-m32rle-linux";
    675      1.1  christos #else
    676      1.1  christos   if (target_big_endian)
    677      1.1  christos     return "elf32-m32r";
    678      1.1  christos   else
    679      1.1  christos     return "elf32-m32rle";
    680      1.1  christos #endif
    681      1.1  christos }
    682      1.1  christos 
    683      1.1  christos void
    684      1.1  christos md_begin (void)
    685      1.1  christos {
    686      1.1  christos   flagword applicable;
    687      1.1  christos   segT seg;
    688      1.1  christos   subsegT subseg;
    689      1.1  christos 
    690      1.1  christos   /* Initialize the `cgen' interface.  */
    691      1.1  christos 
    692      1.1  christos   /* Set the machine number and endian.  */
    693      1.1  christos   gas_cgen_cpu_desc = m32r_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
    694      1.1  christos 					  CGEN_CPU_OPEN_ENDIAN,
    695      1.1  christos 					  (target_big_endian ?
    696      1.1  christos 					   CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE),
    697      1.1  christos 					  CGEN_CPU_OPEN_END);
    698      1.1  christos   m32r_cgen_init_asm (gas_cgen_cpu_desc);
    699      1.1  christos 
    700      1.1  christos   /* The operand instance table is used during optimization to determine
    701      1.1  christos      which insns can be executed in parallel.  It is also used to give
    702      1.1  christos      warnings regarding operand interference in parallel insns.  */
    703      1.1  christos   m32r_cgen_init_opinst_table (gas_cgen_cpu_desc);
    704      1.1  christos 
    705      1.1  christos   /* This is a callback from cgen to gas to parse operands.  */
    706      1.1  christos   cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);
    707      1.1  christos 
    708      1.1  christos   /* Save the current subseg so we can restore it [it's the default one and
    709      1.1  christos      we don't want the initial section to be .sbss].  */
    710      1.1  christos   seg    = now_seg;
    711      1.1  christos   subseg = now_subseg;
    712      1.1  christos 
    713      1.1  christos   /* The sbss section is for local .scomm symbols.  */
    714      1.1  christos   sbss_section = subseg_new (".sbss", 0);
    715      1.1  christos   seg_info (sbss_section)->bss = 1;
    716      1.1  christos 
    717      1.1  christos   /* This is copied from perform_an_assembly_pass.  */
    718      1.1  christos   applicable = bfd_applicable_section_flags (stdoutput);
    719      1.1  christos   bfd_set_section_flags (stdoutput, sbss_section, applicable & SEC_ALLOC);
    720      1.1  christos 
    721      1.1  christos   subseg_set (seg, subseg);
    722      1.1  christos 
    723      1.1  christos   /* We must construct a fake section similar to bfd_com_section
    724      1.1  christos      but with the name .scommon.  */
    725      1.1  christos   scom_section                = *bfd_com_section_ptr;
    726      1.1  christos   scom_section.name           = ".scommon";
    727      1.1  christos   scom_section.output_section = & scom_section;
    728      1.1  christos   scom_section.symbol         = & scom_symbol;
    729      1.1  christos   scom_section.symbol_ptr_ptr = & scom_section.symbol;
    730      1.1  christos   scom_symbol                 = * bfd_com_section_ptr->symbol;
    731      1.1  christos   scom_symbol.name            = ".scommon";
    732      1.1  christos   scom_symbol.section         = & scom_section;
    733      1.1  christos 
    734      1.1  christos   allow_m32rx (enable_m32rx);
    735      1.1  christos 
    736      1.1  christos   gas_cgen_initialize_saved_fixups_array ();
    737      1.1  christos }
    738      1.1  christos 
    739      1.1  christos #define OPERAND_IS_COND_BIT(operand, indices, index) \
    740      1.1  christos   ((operand)->hw_type == HW_H_COND			\
    741      1.1  christos    || ((operand)->hw_type == HW_H_PSW)			\
    742      1.1  christos    || ((operand)->hw_type == HW_H_CR			\
    743      1.1  christos        && (indices [index] == 0 || indices [index] == 1)))
    744      1.1  christos 
    745      1.1  christos /* Returns true if an output of instruction 'a' is referenced by an operand
    746      1.1  christos    of instruction 'b'.  If 'check_outputs' is true then b's outputs are
    747      1.1  christos    checked, otherwise its inputs are examined.  */
    748      1.1  christos 
    749      1.1  christos static int
    750      1.1  christos first_writes_to_seconds_operands (m32r_insn *a,
    751      1.1  christos 				  m32r_insn *b,
    752      1.1  christos 				  const int check_outputs)
    753      1.1  christos {
    754      1.1  christos   const CGEN_OPINST *a_operands = CGEN_INSN_OPERANDS (a->insn);
    755      1.1  christos   const CGEN_OPINST *b_ops = CGEN_INSN_OPERANDS (b->insn);
    756      1.1  christos   int a_index;
    757      1.1  christos 
    758      1.1  christos   if (ignore_parallel_conflicts)
    759      1.1  christos     return 0;
    760      1.1  christos 
    761      1.1  christos   /* If at least one of the instructions takes no operands, then there is
    762      1.1  christos      nothing to check.  There really are instructions without operands,
    763      1.1  christos      eg 'nop'.  */
    764      1.1  christos   if (a_operands == NULL || b_ops == NULL)
    765      1.1  christos     return 0;
    766      1.1  christos 
    767      1.1  christos   /* Scan the operand list of 'a' looking for an output operand.  */
    768      1.1  christos   for (a_index = 0;
    769      1.1  christos        a_operands->type != CGEN_OPINST_END;
    770      1.1  christos        a_index ++, a_operands ++)
    771      1.1  christos     {
    772      1.1  christos       if (a_operands->type == CGEN_OPINST_OUTPUT)
    773      1.1  christos 	{
    774      1.1  christos 	  int b_index;
    775      1.1  christos 	  const CGEN_OPINST *b_operands = b_ops;
    776      1.1  christos 
    777      1.1  christos 	  /* Special Case:
    778      1.1  christos 	     The Condition bit 'C' is a shadow of the CBR register (control
    779      1.1  christos 	     register 1) and also a shadow of bit 31 of the program status
    780      1.1  christos 	     word (control register 0).  For now this is handled here, rather
    781      1.1  christos 	     than by cgen....  */
    782      1.1  christos 
    783      1.1  christos 	  if (OPERAND_IS_COND_BIT (a_operands, a->indices, a_index))
    784      1.1  christos 	    {
    785      1.1  christos 	      /* Scan operand list of 'b' looking for another reference to the
    786      1.1  christos 		 condition bit, which goes in the right direction.  */
    787      1.1  christos 	      for (b_index = 0;
    788      1.1  christos 		   b_operands->type != CGEN_OPINST_END;
    789      1.1  christos 		   b_index++, b_operands++)
    790      1.1  christos 		{
    791      1.1  christos 		  if ((b_operands->type
    792      1.1  christos 		       == (check_outputs
    793      1.1  christos 			   ? CGEN_OPINST_OUTPUT
    794      1.1  christos 			   : CGEN_OPINST_INPUT))
    795      1.1  christos 		      && OPERAND_IS_COND_BIT (b_operands, b->indices, b_index))
    796      1.1  christos 		    return 1;
    797      1.1  christos 		}
    798      1.1  christos 	    }
    799      1.1  christos 	  else
    800      1.1  christos 	    {
    801      1.1  christos 	      /* Scan operand list of 'b' looking for an operand that
    802      1.1  christos 		 references the same hardware element, and which goes in the
    803      1.1  christos 		 right direction.  */
    804      1.1  christos 	      for (b_index = 0;
    805      1.1  christos 		   b_operands->type != CGEN_OPINST_END;
    806      1.1  christos 		   b_index++, b_operands++)
    807      1.1  christos 		{
    808      1.1  christos 		  if ((b_operands->type
    809      1.1  christos 		       == (check_outputs
    810      1.1  christos 			   ? CGEN_OPINST_OUTPUT
    811      1.1  christos 			   : CGEN_OPINST_INPUT))
    812      1.1  christos 		      && (b_operands->hw_type == a_operands->hw_type)
    813      1.1  christos 		      && (a->indices[a_index] == b->indices[b_index]))
    814      1.1  christos 		    return 1;
    815      1.1  christos 		}
    816      1.1  christos 	    }
    817      1.1  christos 	}
    818      1.1  christos     }
    819      1.1  christos 
    820      1.1  christos   return 0;
    821      1.1  christos }
    822      1.1  christos 
    823      1.1  christos /* Returns true if the insn can (potentially) alter the program counter.  */
    824      1.1  christos 
    825      1.1  christos static int
    826      1.1  christos writes_to_pc (m32r_insn *a)
    827      1.1  christos {
    828      1.1  christos   if (CGEN_INSN_ATTR_VALUE (a->insn, CGEN_INSN_UNCOND_CTI)
    829      1.1  christos       || CGEN_INSN_ATTR_VALUE (a->insn, CGEN_INSN_COND_CTI))
    830      1.1  christos     return 1;
    831      1.1  christos   return 0;
    832      1.1  christos }
    833      1.1  christos 
    834      1.1  christos /* Return NULL if the two 16 bit insns can be executed in parallel.
    835      1.1  christos    Otherwise return a pointer to an error message explaining why not.  */
    836      1.1  christos 
    837      1.1  christos static const char *
    838      1.1  christos can_make_parallel (m32r_insn *a, m32r_insn *b)
    839      1.1  christos {
    840      1.1  christos   PIPE_ATTR a_pipe;
    841      1.1  christos   PIPE_ATTR b_pipe;
    842      1.1  christos 
    843      1.1  christos   /* Make sure the instructions are the right length.  */
    844      1.1  christos   if (CGEN_FIELDS_BITSIZE (&a->fields) != 16
    845      1.1  christos       || CGEN_FIELDS_BITSIZE (&b->fields) != 16)
    846      1.1  christos     abort ();
    847      1.1  christos 
    848      1.1  christos   if (first_writes_to_seconds_operands (a, b, TRUE))
    849      1.1  christos     return _("instructions write to the same destination register.");
    850      1.1  christos 
    851      1.1  christos   a_pipe = CGEN_INSN_ATTR_VALUE (a->insn, CGEN_INSN_PIPE);
    852      1.1  christos   b_pipe = CGEN_INSN_ATTR_VALUE (b->insn, CGEN_INSN_PIPE);
    853      1.1  christos 
    854      1.1  christos   /* Make sure that the instructions use the correct execution pipelines.  */
    855      1.1  christos   if (a_pipe == PIPE_NONE
    856      1.1  christos       || b_pipe == PIPE_NONE)
    857      1.1  christos     return _("Instructions do not use parallel execution pipelines.");
    858      1.1  christos 
    859      1.1  christos   /* Leave this test for last, since it is the only test that can
    860      1.1  christos      go away if the instructions are swapped, and we want to make
    861      1.1  christos      sure that any other errors are detected before this happens.  */
    862      1.1  christos   if (a_pipe == PIPE_S
    863      1.1  christos       || b_pipe == PIPE_O
    864      1.1  christos       || (b_pipe == PIPE_O_OS && (enable_m32rx != 2)))
    865      1.1  christos     return _("Instructions share the same execution pipeline");
    866      1.1  christos 
    867      1.1  christos   return NULL;
    868      1.1  christos }
    869      1.1  christos 
    870      1.1  christos /* Force the top bit of the second 16-bit insn to be set.  */
    871      1.1  christos 
    872      1.1  christos static void
    873      1.1  christos make_parallel (CGEN_INSN_BYTES_PTR buffer)
    874      1.1  christos {
    875      1.1  christos #if CGEN_INT_INSN_P
    876      1.1  christos   *buffer |= 0x8000;
    877      1.1  christos #else
    878      1.1  christos   buffer[CGEN_CPU_ENDIAN (gas_cgen_cpu_desc) == CGEN_ENDIAN_BIG ? 0 : 1]
    879      1.1  christos     |= 0x80;
    880      1.1  christos #endif
    881      1.1  christos }
    882      1.1  christos 
    883      1.1  christos /* Same as make_parallel except buffer contains the bytes in target order.  */
    884      1.1  christos 
    885      1.1  christos static void
    886      1.1  christos target_make_parallel (char *buffer)
    887      1.1  christos {
    888      1.1  christos   buffer[CGEN_CPU_ENDIAN (gas_cgen_cpu_desc) == CGEN_ENDIAN_BIG ? 0 : 1]
    889      1.1  christos     |= 0x80;
    890      1.1  christos }
    891      1.1  christos 
    892      1.1  christos /* Assemble two instructions with an explicit parallel operation (||) or
    893      1.1  christos    sequential operation (->).  */
    894      1.1  christos 
    895      1.1  christos static void
    896      1.1  christos assemble_two_insns (char *str1, char *str2, int parallel_p)
    897      1.1  christos {
    898      1.1  christos   char *str3;
    899      1.1  christos   m32r_insn first;
    900      1.1  christos   m32r_insn second;
    901      1.1  christos   char *errmsg;
    902      1.1  christos   char save_str2 = *str2;
    903      1.1  christos 
    904      1.1  christos   /* Separate the two instructions.  */
    905      1.1  christos   *str2 = 0;
    906      1.1  christos 
    907      1.1  christos   /* Make sure the two insns begin on a 32 bit boundary.
    908      1.1  christos      This is also done for the serial case (foo -> bar), relaxing doesn't
    909      1.1  christos      affect insns written like this.
    910      1.1  christos      Note that we must always do this as we can't assume anything about
    911      1.1  christos      whether we're currently on a 32 bit boundary or not.  Relaxing may
    912      1.1  christos      change this.  */
    913      1.1  christos   fill_insn (0);
    914      1.1  christos 
    915      1.1  christos   first.debug_sym_link = debug_sym_link;
    916      1.1  christos   debug_sym_link = (sym_linkS *) 0;
    917      1.1  christos 
    918      1.1  christos   /* Parse the first instruction.  */
    919      1.1  christos   if (! (first.insn = m32r_cgen_assemble_insn
    920      1.1  christos 	 (gas_cgen_cpu_desc, str1, & first.fields, first.buffer, & errmsg)))
    921      1.1  christos     {
    922      1.1  christos       as_bad ("%s", errmsg);
    923      1.1  christos       return;
    924      1.1  christos     }
    925      1.1  christos 
    926      1.1  christos   /* Check it.  */
    927      1.1  christos   if (CGEN_FIELDS_BITSIZE (&first.fields) != 16)
    928      1.1  christos     {
    929      1.1  christos       /* xgettext:c-format  */
    930      1.1  christos       as_bad (_("not a 16 bit instruction '%s'"), str1);
    931      1.1  christos       return;
    932      1.1  christos     }
    933      1.1  christos #ifdef E_M32R2_ARCH
    934      1.1  christos   else if ((enable_m32rx == 1)
    935      1.1  christos            /* FIXME: Need standard macro to perform this test.  */
    936      1.1  christos            && ((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH)
    937      1.1  christos                 & (1 << MACH_M32R2))
    938      1.1  christos                && !((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH)
    939      1.1  christos                     & (1 << MACH_M32RX)))))
    940      1.1  christos     {
    941      1.1  christos       /* xgettext:c-format  */
    942      1.1  christos       as_bad (_("instruction '%s' is for the M32R2 only"), str1);
    943      1.1  christos       return;
    944      1.1  christos     }
    945      1.1  christos   else if ((! enable_special
    946      1.1  christos             && CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL))
    947      1.1  christos            || (! enable_special_m32r
    948      1.1  christos                && CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL_M32R)))
    949      1.1  christos #else
    950      1.1  christos   else if (! enable_special
    951      1.1  christos       && CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL))
    952      1.1  christos #endif
    953      1.1  christos     {
    954      1.1  christos       /* xgettext:c-format  */
    955      1.1  christos       as_bad (_("unknown instruction '%s'"), str1);
    956      1.1  christos       return;
    957      1.1  christos     }
    958      1.1  christos   else if (! enable_m32rx
    959      1.1  christos 	   /* FIXME: Need standard macro to perform this test.  */
    960      1.1  christos 	   && (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH)
    961      1.1  christos 	       == (1 << MACH_M32RX)))
    962      1.1  christos     {
    963      1.1  christos       /* xgettext:c-format  */
    964      1.1  christos       as_bad (_("instruction '%s' is for the M32RX only"), str1);
    965      1.1  christos       return;
    966      1.1  christos     }
    967      1.1  christos 
    968      1.1  christos   /* Check to see if this is an allowable parallel insn.  */
    969      1.1  christos   if (parallel_p
    970      1.1  christos       && CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_PIPE) == PIPE_NONE)
    971      1.1  christos     {
    972      1.1  christos       /* xgettext:c-format  */
    973      1.1  christos       as_bad (_("instruction '%s' cannot be executed in parallel."), str1);
    974      1.1  christos       return;
    975      1.1  christos     }
    976      1.1  christos 
    977      1.1  christos   /* Restore the original assembly text, just in case it is needed.  */
    978      1.1  christos   *str2 = save_str2;
    979      1.1  christos 
    980      1.1  christos   /* Save the original string pointer.  */
    981      1.1  christos   str3 = str1;
    982      1.1  christos 
    983      1.1  christos   /* Advanced past the parsed string.  */
    984      1.1  christos   str1 = str2 + 2;
    985      1.1  christos 
    986      1.1  christos   /* Remember the entire string in case it is needed for error
    987      1.1  christos      messages.  */
    988      1.1  christos   str2 = str3;
    989      1.1  christos 
    990      1.1  christos   /* Convert the opcode to lower case.  */
    991      1.1  christos   {
    992      1.1  christos     char *s2 = str1;
    993      1.1  christos 
    994      1.1  christos     while (ISSPACE (*s2++))
    995      1.1  christos       continue;
    996      1.1  christos 
    997      1.1  christos     --s2;
    998      1.1  christos 
    999      1.1  christos     while (ISALNUM (*s2))
   1000      1.1  christos       {
   1001      1.1  christos 	*s2 = TOLOWER (*s2);
   1002      1.1  christos 	s2++;
   1003      1.1  christos       }
   1004      1.1  christos   }
   1005      1.1  christos 
   1006      1.1  christos   /* Preserve any fixups that have been generated and reset the list
   1007      1.1  christos      to empty.  */
   1008      1.1  christos   gas_cgen_save_fixups (0);
   1009      1.1  christos 
   1010      1.1  christos   /* Get the indices of the operands of the instruction.  */
   1011      1.1  christos   /* FIXME: CGEN_FIELDS is already recorded, but relying on that fact
   1012      1.1  christos      doesn't seem right.  Perhaps allow passing fields like we do insn.  */
   1013      1.1  christos   /* FIXME: ALIAS insns do not have operands, so we use this function
   1014      1.1  christos      to find the equivalent insn and overwrite the value stored in our
   1015      1.1  christos      structure.  We still need the original insn, however, since this
   1016      1.1  christos      may have certain attributes that are not present in the unaliased
   1017      1.1  christos      version (eg relaxability).  When aliases behave differently this
   1018      1.1  christos      may have to change.  */
   1019      1.1  christos   first.orig_insn = first.insn;
   1020      1.1  christos   {
   1021      1.1  christos     CGEN_FIELDS tmp_fields;
   1022      1.1  christos     first.insn = cgen_lookup_get_insn_operands
   1023      1.1  christos       (gas_cgen_cpu_desc, NULL, INSN_VALUE (first.buffer), NULL, 16,
   1024      1.1  christos        first.indices, &tmp_fields);
   1025      1.1  christos   }
   1026      1.1  christos 
   1027      1.1  christos   if (first.insn == NULL)
   1028      1.1  christos     as_fatal (_("internal error: lookup/get operands failed"));
   1029      1.1  christos 
   1030      1.1  christos   second.debug_sym_link = NULL;
   1031      1.1  christos 
   1032      1.1  christos   /* Parse the second instruction.  */
   1033      1.1  christos   if (! (second.insn = m32r_cgen_assemble_insn
   1034      1.1  christos 	 (gas_cgen_cpu_desc, str1, & second.fields, second.buffer, & errmsg)))
   1035      1.1  christos     {
   1036      1.1  christos       as_bad ("%s", errmsg);
   1037      1.1  christos       return;
   1038      1.1  christos     }
   1039      1.1  christos 
   1040      1.1  christos   /* Check it.  */
   1041      1.1  christos   if (CGEN_FIELDS_BITSIZE (&second.fields) != 16)
   1042      1.1  christos     {
   1043      1.1  christos       /* xgettext:c-format  */
   1044      1.1  christos       as_bad (_("not a 16 bit instruction '%s'"), str1);
   1045      1.1  christos       return;
   1046      1.1  christos     }
   1047      1.1  christos #ifdef E_M32R2_ARCH
   1048      1.1  christos   else if ((enable_m32rx == 1)
   1049      1.1  christos            /* FIXME: Need standard macro to perform this test.  */
   1050      1.1  christos            && ((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH)
   1051      1.1  christos                 & (1 << MACH_M32R2))
   1052      1.1  christos                && !((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH)
   1053      1.1  christos                     & (1 << MACH_M32RX)))))
   1054      1.1  christos     {
   1055      1.1  christos       /* xgettext:c-format  */
   1056      1.1  christos       as_bad (_("instruction '%s' is for the M32R2 only"), str1);
   1057      1.1  christos       return;
   1058      1.1  christos     }
   1059      1.1  christos   else if ((! enable_special
   1060      1.1  christos             && CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL))
   1061      1.1  christos            || (! enable_special_m32r
   1062      1.1  christos                && CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL_M32R)))
   1063      1.1  christos #else
   1064      1.1  christos   else if (! enable_special
   1065      1.1  christos       && CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL))
   1066      1.1  christos #endif
   1067      1.1  christos     {
   1068      1.1  christos       /* xgettext:c-format  */
   1069      1.1  christos       as_bad (_("unknown instruction '%s'"), str1);
   1070      1.1  christos       return;
   1071      1.1  christos     }
   1072      1.1  christos   else if (! enable_m32rx
   1073      1.1  christos       && CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_MACH) == (1 << MACH_M32RX))
   1074      1.1  christos     {
   1075      1.1  christos       /* xgettext:c-format  */
   1076      1.1  christos       as_bad (_("instruction '%s' is for the M32RX only"), str1);
   1077      1.1  christos       return;
   1078      1.1  christos     }
   1079      1.1  christos 
   1080      1.1  christos   /* Check to see if this is an allowable parallel insn.  */
   1081      1.1  christos   if (parallel_p
   1082      1.1  christos       && CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_PIPE) == PIPE_NONE)
   1083      1.1  christos     {
   1084      1.1  christos       /* xgettext:c-format  */
   1085      1.1  christos       as_bad (_("instruction '%s' cannot be executed in parallel."), str1);
   1086      1.1  christos       return;
   1087      1.1  christos     }
   1088      1.1  christos 
   1089      1.1  christos   if (parallel_p && ! enable_m32rx)
   1090      1.1  christos     {
   1091      1.1  christos       if (CGEN_INSN_NUM (first.insn) != M32R_INSN_NOP
   1092      1.1  christos 	  && CGEN_INSN_NUM (second.insn) != M32R_INSN_NOP)
   1093      1.1  christos 	{
   1094      1.1  christos 	  /* xgettext:c-format  */
   1095      1.1  christos 	  as_bad (_("'%s': only the NOP instruction can be issued in parallel on the m32r"), str2);
   1096      1.1  christos 	  return;
   1097      1.1  christos 	}
   1098      1.1  christos     }
   1099      1.1  christos 
   1100      1.1  christos   /* Get the indices of the operands of the instruction.  */
   1101      1.1  christos   second.orig_insn = second.insn;
   1102      1.1  christos   {
   1103      1.1  christos     CGEN_FIELDS tmp_fields;
   1104      1.1  christos     second.insn = cgen_lookup_get_insn_operands
   1105      1.1  christos       (gas_cgen_cpu_desc, NULL, INSN_VALUE (second.buffer), NULL, 16,
   1106      1.1  christos        second.indices, &tmp_fields);
   1107      1.1  christos   }
   1108      1.1  christos 
   1109      1.1  christos   if (second.insn == NULL)
   1110      1.1  christos     as_fatal (_("internal error: lookup/get operands failed"));
   1111      1.1  christos 
   1112      1.1  christos   /* We assume that if the first instruction writes to a register that is
   1113      1.1  christos      read by the second instruction it is because the programmer intended
   1114      1.1  christos      this to happen, (after all they have explicitly requested that these
   1115      1.1  christos      two instructions be executed in parallel).  Although if the global
   1116      1.1  christos      variable warn_explicit_parallel_conflicts is true then we do generate
   1117      1.1  christos      a warning message.  Similarly we assume that parallel branch and jump
   1118      1.1  christos      instructions are deliberate and should not produce errors.  */
   1119      1.1  christos 
   1120      1.1  christos   if (parallel_p && warn_explicit_parallel_conflicts)
   1121      1.1  christos     {
   1122      1.1  christos       if (first_writes_to_seconds_operands (&first, &second, FALSE))
   1123      1.1  christos 	/* xgettext:c-format  */
   1124      1.1  christos 	as_warn (_("%s: output of 1st instruction is the same as an input to 2nd instruction - is this intentional ?"), str2);
   1125      1.1  christos 
   1126      1.1  christos       if (first_writes_to_seconds_operands (&second, &first, FALSE))
   1127      1.1  christos 	/* xgettext:c-format  */
   1128      1.1  christos 	as_warn (_("%s: output of 2nd instruction is the same as an input to 1st instruction - is this intentional ?"), str2);
   1129      1.1  christos     }
   1130      1.1  christos 
   1131      1.1  christos   if (!parallel_p
   1132      1.1  christos       || (errmsg = (char *) can_make_parallel (&first, &second)) == NULL)
   1133      1.1  christos     {
   1134      1.1  christos       /* Get the fixups for the first instruction.  */
   1135      1.1  christos       gas_cgen_swap_fixups (0);
   1136      1.1  christos 
   1137      1.1  christos       /* Write it out.  */
   1138      1.1  christos       expand_debug_syms (first.debug_sym_link, 1);
   1139      1.1  christos       gas_cgen_finish_insn (first.orig_insn, first.buffer,
   1140      1.1  christos 			    CGEN_FIELDS_BITSIZE (&first.fields), 0, NULL);
   1141      1.1  christos 
   1142      1.1  christos       /* Force the top bit of the second insn to be set.  */
   1143      1.1  christos       if (parallel_p)
   1144      1.1  christos 	make_parallel (second.buffer);
   1145      1.1  christos 
   1146      1.1  christos       /* Get its fixups.  */
   1147      1.1  christos       gas_cgen_restore_fixups (0);
   1148      1.1  christos 
   1149      1.1  christos       /* Write it out.  */
   1150      1.1  christos       expand_debug_syms (second.debug_sym_link, 1);
   1151      1.1  christos       gas_cgen_finish_insn (second.orig_insn, second.buffer,
   1152      1.1  christos 			    CGEN_FIELDS_BITSIZE (&second.fields), 0, NULL);
   1153      1.1  christos     }
   1154      1.1  christos   /* Try swapping the instructions to see if they work that way.  */
   1155      1.1  christos   else if (can_make_parallel (&second, &first) == NULL)
   1156      1.1  christos     {
   1157      1.1  christos       /* Write out the second instruction first.  */
   1158      1.1  christos       expand_debug_syms (second.debug_sym_link, 1);
   1159      1.1  christos       gas_cgen_finish_insn (second.orig_insn, second.buffer,
   1160      1.1  christos 			    CGEN_FIELDS_BITSIZE (&second.fields), 0, NULL);
   1161      1.1  christos 
   1162      1.1  christos       /* Force the top bit of the first instruction to be set.  */
   1163      1.1  christos       make_parallel (first.buffer);
   1164      1.1  christos 
   1165      1.1  christos       /* Get the fixups for the first instruction.  */
   1166      1.1  christos       gas_cgen_restore_fixups (0);
   1167      1.1  christos 
   1168      1.1  christos       /* Write out the first instruction.  */
   1169      1.1  christos       expand_debug_syms (first.debug_sym_link, 1);
   1170      1.1  christos       gas_cgen_finish_insn (first.orig_insn, first.buffer,
   1171      1.1  christos 			    CGEN_FIELDS_BITSIZE (&first.fields), 0, NULL);
   1172      1.1  christos     }
   1173      1.1  christos   else
   1174      1.1  christos     {
   1175      1.1  christos       as_bad ("'%s': %s", str2, errmsg);
   1176      1.1  christos       return;
   1177      1.1  christos     }
   1178      1.1  christos 
   1179      1.1  christos   if (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL)
   1180      1.1  christos       || CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL))
   1181      1.1  christos     m32r_flags |= E_M32R_HAS_HIDDEN_INST;
   1182      1.1  christos   if (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL_M32R)
   1183      1.1  christos       || CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL_M32R))
   1184      1.1  christos     m32r_flags |= E_M32R_HAS_BIT_INST;
   1185      1.1  christos   if (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL_FLOAT)
   1186      1.1  christos       || CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL_FLOAT))
   1187      1.1  christos     m32r_flags |= E_M32R_HAS_FLOAT_INST;
   1188      1.1  christos 
   1189      1.1  christos   /* Set these so m32r_fill_insn can use them.  */
   1190      1.1  christos   prev_seg    = now_seg;
   1191      1.1  christos   prev_subseg = now_subseg;
   1192      1.1  christos }
   1193      1.1  christos 
   1194      1.1  christos void
   1195      1.1  christos md_assemble (char *str)
   1196      1.1  christos {
   1197      1.1  christos   m32r_insn insn;
   1198      1.1  christos   char *errmsg;
   1199      1.1  christos   char *str2 = NULL;
   1200      1.1  christos 
   1201      1.1  christos   /* Initialize GAS's cgen interface for a new instruction.  */
   1202      1.1  christos   gas_cgen_init_parse ();
   1203      1.1  christos 
   1204      1.1  christos   /* Look for a parallel instruction separator.  */
   1205      1.1  christos   if ((str2 = strstr (str, "||")) != NULL)
   1206      1.1  christos     {
   1207      1.1  christos       assemble_two_insns (str, str2, 1);
   1208      1.1  christos       m32r_flags |= E_M32R_HAS_PARALLEL;
   1209      1.1  christos       return;
   1210      1.1  christos     }
   1211      1.1  christos 
   1212      1.1  christos   /* Also look for a sequential instruction separator.  */
   1213      1.1  christos   if ((str2 = strstr (str, "->")) != NULL)
   1214      1.1  christos     {
   1215      1.1  christos       assemble_two_insns (str, str2, 0);
   1216      1.1  christos       return;
   1217      1.1  christos     }
   1218      1.1  christos 
   1219      1.1  christos   insn.debug_sym_link = debug_sym_link;
   1220      1.1  christos   debug_sym_link = (sym_linkS *) 0;
   1221      1.1  christos 
   1222      1.1  christos   insn.insn = m32r_cgen_assemble_insn
   1223      1.1  christos     (gas_cgen_cpu_desc, str, &insn.fields, insn.buffer, & errmsg);
   1224      1.1  christos 
   1225      1.1  christos   if (!insn.insn)
   1226      1.1  christos     {
   1227      1.1  christos       as_bad ("%s", errmsg);
   1228      1.1  christos       return;
   1229      1.1  christos     }
   1230      1.1  christos 
   1231      1.1  christos #ifdef E_M32R2_ARCH
   1232      1.1  christos   if ((enable_m32rx == 1)
   1233      1.1  christos        /* FIXME: Need standard macro to perform this test.  */
   1234      1.1  christos       && ((CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_MACH)
   1235      1.1  christos            & (1 << MACH_M32R2))
   1236      1.1  christos           && !((CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_MACH)
   1237      1.1  christos                & (1 << MACH_M32RX)))))
   1238      1.1  christos     {
   1239      1.1  christos       /* xgettext:c-format  */
   1240      1.1  christos       as_bad (_("instruction '%s' is for the M32R2 only"), str);
   1241      1.1  christos       return;
   1242      1.1  christos     }
   1243      1.1  christos   else if ((! enable_special
   1244      1.1  christos        && CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL))
   1245      1.1  christos       || (! enable_special_m32r
   1246      1.1  christos           && CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL_M32R)))
   1247      1.1  christos #else
   1248      1.1  christos   if (! enable_special
   1249      1.1  christos       && CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL))
   1250      1.1  christos #endif
   1251      1.1  christos     {
   1252      1.1  christos       /* xgettext:c-format  */
   1253      1.1  christos       as_bad (_("unknown instruction '%s'"), str);
   1254      1.1  christos       return;
   1255      1.1  christos     }
   1256      1.1  christos   else if (! enable_m32rx
   1257      1.1  christos 	   && CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_MACH) == (1 << MACH_M32RX))
   1258      1.1  christos     {
   1259      1.1  christos       /* xgettext:c-format  */
   1260      1.1  christos       as_bad (_("instruction '%s' is for the M32RX only"), str);
   1261      1.1  christos       return;
   1262      1.1  christos     }
   1263      1.1  christos 
   1264      1.1  christos   if (CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL))
   1265      1.1  christos     m32r_flags |= E_M32R_HAS_HIDDEN_INST;
   1266      1.1  christos   if (CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL_M32R))
   1267      1.1  christos     m32r_flags |= E_M32R_HAS_BIT_INST;
   1268      1.1  christos   if (CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL_FLOAT))
   1269      1.1  christos     m32r_flags |= E_M32R_HAS_FLOAT_INST;
   1270      1.1  christos 
   1271      1.1  christos   if (CGEN_INSN_BITSIZE (insn.insn) == 32)
   1272      1.1  christos     {
   1273      1.1  christos       /* 32 bit insns must live on 32 bit boundaries.  */
   1274      1.1  christos       if (prev_insn.insn || seen_relaxable_p)
   1275      1.1  christos 	{
   1276      1.1  christos 	  /* ??? If calling fill_insn too many times turns us into a memory
   1277      1.1  christos 	     pig, can we call a fn to assemble a nop instead of
   1278      1.1  christos 	     !seen_relaxable_p?  */
   1279      1.1  christos 	  fill_insn (0);
   1280      1.1  christos 	}
   1281      1.1  christos 
   1282      1.1  christos       expand_debug_syms (insn.debug_sym_link, 2);
   1283      1.1  christos 
   1284      1.1  christos       /* Doesn't really matter what we pass for RELAX_P here.  */
   1285      1.1  christos       gas_cgen_finish_insn (insn.insn, insn.buffer,
   1286      1.1  christos 			    CGEN_FIELDS_BITSIZE (&insn.fields), 1, NULL);
   1287      1.1  christos     }
   1288      1.1  christos   else
   1289      1.1  christos     {
   1290      1.1  christos       int on_32bit_boundary_p;
   1291      1.1  christos       int swap = FALSE;
   1292      1.1  christos 
   1293      1.1  christos       if (CGEN_INSN_BITSIZE (insn.insn) != 16)
   1294      1.1  christos 	abort ();
   1295      1.1  christos 
   1296      1.1  christos       insn.orig_insn = insn.insn;
   1297      1.1  christos 
   1298      1.1  christos       /* If the previous insn was relaxable, then it may be expanded
   1299      1.1  christos 	 to fill the current 16 bit slot.  Emit a NOP here to occupy
   1300      1.1  christos 	 this slot, so that we can start at optimizing at a 32 bit
   1301      1.1  christos 	 boundary.  */
   1302      1.1  christos       if (prev_insn.insn && seen_relaxable_p && optimize)
   1303      1.1  christos 	fill_insn (0);
   1304      1.1  christos 
   1305      1.1  christos       if (enable_m32rx)
   1306      1.1  christos 	{
   1307      1.1  christos 	  /* Get the indices of the operands of the instruction.
   1308      1.1  christos 	     FIXME: See assemble_parallel for notes on orig_insn.  */
   1309      1.1  christos 	  {
   1310      1.1  christos 	    CGEN_FIELDS tmp_fields;
   1311      1.1  christos 	    insn.insn = cgen_lookup_get_insn_operands
   1312      1.1  christos 	      (gas_cgen_cpu_desc, NULL, INSN_VALUE (insn.buffer), NULL,
   1313      1.1  christos 	       16, insn.indices, &tmp_fields);
   1314      1.1  christos 	  }
   1315      1.1  christos 
   1316      1.1  christos 	  if (insn.insn == NULL)
   1317      1.1  christos 	    as_fatal (_("internal error: lookup/get operands failed"));
   1318      1.1  christos 	}
   1319      1.1  christos 
   1320      1.1  christos       /* Compute whether we're on a 32 bit boundary or not.
   1321      1.1  christos 	 prev_insn.insn is NULL when we're on a 32 bit boundary.  */
   1322      1.1  christos       on_32bit_boundary_p = prev_insn.insn == NULL;
   1323      1.1  christos 
   1324      1.1  christos       /* Change a frag to, if each insn to swap is in a different frag.
   1325      1.1  christos          It must keep only one instruction in a frag.  */
   1326      1.1  christos       if (parallel() && on_32bit_boundary_p)
   1327      1.1  christos         {
   1328      1.1  christos           frag_wane (frag_now);
   1329      1.1  christos           frag_new (0);
   1330      1.1  christos         }
   1331      1.1  christos 
   1332      1.1  christos       /* Look to see if this instruction can be combined with the
   1333      1.1  christos 	 previous instruction to make one, parallel, 32 bit instruction.
   1334      1.1  christos 	 If the previous instruction (potentially) changed the flow of
   1335      1.1  christos 	 program control, then it cannot be combined with the current
   1336      1.1  christos 	 instruction.  If the current instruction is relaxable, then it
   1337      1.1  christos 	 might be replaced with a longer version, so we cannot combine it.
   1338      1.1  christos 	 Also if the output of the previous instruction is used as an
   1339      1.1  christos 	 input to the current instruction then it cannot be combined.
   1340      1.1  christos 	 Otherwise call can_make_parallel() with both orderings of the
   1341      1.1  christos 	 instructions to see if they can be combined.  */
   1342      1.1  christos       if (! on_32bit_boundary_p
   1343      1.1  christos 	  && parallel ()
   1344      1.1  christos 	  && CGEN_INSN_ATTR_VALUE (insn.orig_insn, CGEN_INSN_RELAXABLE) == 0
   1345      1.1  christos 	  && ! writes_to_pc (&prev_insn)
   1346      1.1  christos 	  && ! first_writes_to_seconds_operands (&prev_insn, &insn, FALSE))
   1347      1.1  christos 	{
   1348      1.1  christos 	  if (can_make_parallel (&prev_insn, &insn) == NULL)
   1349      1.1  christos 	    make_parallel (insn.buffer);
   1350      1.1  christos 	  else if (can_make_parallel (&insn, &prev_insn) == NULL)
   1351      1.1  christos 	    swap = TRUE;
   1352      1.1  christos 	}
   1353      1.1  christos 
   1354      1.1  christos       expand_debug_syms (insn.debug_sym_link, 1);
   1355      1.1  christos 
   1356      1.1  christos       {
   1357      1.1  christos 	int i;
   1358      1.1  christos 	finished_insnS fi;
   1359      1.1  christos 
   1360      1.1  christos 	/* Ensure each pair of 16 bit insns is in the same frag.  */
   1361      1.1  christos 	frag_grow (4);
   1362      1.1  christos 
   1363      1.1  christos 	gas_cgen_finish_insn (insn.orig_insn, insn.buffer,
   1364      1.1  christos 			      CGEN_FIELDS_BITSIZE (&insn.fields),
   1365      1.1  christos 			      1 /* relax_p  */, &fi);
   1366      1.1  christos 	insn.addr = fi.addr;
   1367      1.1  christos 	insn.frag = fi.frag;
   1368      1.1  christos 	insn.num_fixups = fi.num_fixups;
   1369      1.1  christos 	for (i = 0; i < fi.num_fixups; ++i)
   1370      1.1  christos 	  insn.fixups[i] = fi.fixups[i];
   1371      1.1  christos       }
   1372      1.1  christos 
   1373      1.1  christos       if (swap)
   1374      1.1  christos 	{
   1375      1.1  christos 	  int i, tmp;
   1376      1.1  christos 
   1377      1.1  christos #define SWAP_BYTES(a,b) tmp = a; a = b; b = tmp
   1378      1.1  christos 
   1379      1.1  christos 	  /* Swap the two insns */
   1380      1.1  christos 	  SWAP_BYTES (prev_insn.addr[0], insn.addr[0]);
   1381      1.1  christos 	  SWAP_BYTES (prev_insn.addr[1], insn.addr[1]);
   1382      1.1  christos 
   1383      1.1  christos 	  target_make_parallel (insn.addr);
   1384      1.1  christos 
   1385      1.1  christos 	  /* Swap any relaxable frags recorded for the two insns.  */
   1386      1.1  christos 	  /* FIXME: Clarify.  relaxation precludes parallel insns */
   1387      1.1  christos 	  if (prev_insn.frag->fr_opcode == prev_insn.addr)
   1388      1.1  christos 	    prev_insn.frag->fr_opcode = insn.addr;
   1389      1.1  christos 	  else if (insn.frag->fr_opcode == insn.addr)
   1390      1.1  christos 	    insn.frag->fr_opcode = prev_insn.addr;
   1391      1.1  christos 
   1392      1.1  christos           /* Change a frag to, if each insn is in a different frag.
   1393      1.1  christos 	     It must keep only one instruction in a frag.  */
   1394      1.1  christos           if (prev_insn.frag != insn.frag)
   1395      1.1  christos             {
   1396      1.1  christos               for (i = 0; i < prev_insn.num_fixups; ++i)
   1397      1.1  christos                 prev_insn.fixups[i]->fx_frag = insn.frag;
   1398      1.1  christos               for (i = 0; i < insn.num_fixups; ++i)
   1399      1.1  christos                 insn.fixups[i]->fx_frag = prev_insn.frag;
   1400      1.1  christos             }
   1401      1.1  christos           else
   1402      1.1  christos 	    {
   1403      1.1  christos 	      /* Update the addresses in any fixups.
   1404      1.1  christos 		 Note that we don't have to handle the case where each insn is in
   1405      1.1  christos 		 a different frag as we ensure they're in the same frag above.  */
   1406      1.1  christos 	      for (i = 0; i < prev_insn.num_fixups; ++i)
   1407      1.1  christos 		prev_insn.fixups[i]->fx_where += 2;
   1408      1.1  christos 	      for (i = 0; i < insn.num_fixups; ++i)
   1409      1.1  christos 		insn.fixups[i]->fx_where -= 2;
   1410      1.1  christos 	    }
   1411      1.1  christos 	}
   1412      1.1  christos 
   1413      1.1  christos       /* Keep track of whether we've seen a pair of 16 bit insns.
   1414      1.1  christos 	 prev_insn.insn is NULL when we're on a 32 bit boundary.  */
   1415      1.1  christos       if (on_32bit_boundary_p)
   1416      1.1  christos 	prev_insn = insn;
   1417      1.1  christos       else
   1418      1.1  christos 	prev_insn.insn = NULL;
   1419      1.1  christos 
   1420      1.1  christos       /* If the insn needs the following one to be on a 32 bit boundary
   1421      1.1  christos 	 (e.g. subroutine calls), fill this insn's slot.  */
   1422      1.1  christos       if (on_32bit_boundary_p
   1423      1.1  christos 	  && CGEN_INSN_ATTR_VALUE (insn.orig_insn, CGEN_INSN_FILL_SLOT) != 0)
   1424      1.1  christos 	fill_insn (0);
   1425      1.1  christos 
   1426      1.1  christos       /* If this is a relaxable insn (can be replaced with a larger version)
   1427      1.1  christos 	 mark the fact so that we can emit an alignment directive for a
   1428      1.1  christos 	 following 32 bit insn if we see one.   */
   1429      1.1  christos       if (CGEN_INSN_ATTR_VALUE (insn.orig_insn, CGEN_INSN_RELAXABLE) != 0)
   1430      1.1  christos 	seen_relaxable_p = 1;
   1431      1.1  christos     }
   1432      1.1  christos 
   1433      1.1  christos   /* Set these so m32r_fill_insn can use them.  */
   1434      1.1  christos   prev_seg    = now_seg;
   1435      1.1  christos   prev_subseg = now_subseg;
   1436      1.1  christos }
   1437      1.1  christos 
   1438      1.1  christos /* The syntax in the manual says constants begin with '#'.
   1439      1.1  christos    We just ignore it.  */
   1440      1.1  christos 
   1441      1.1  christos void
   1442      1.1  christos md_operand (expressionS *expressionP)
   1443      1.1  christos {
   1444      1.1  christos   if (*input_line_pointer == '#')
   1445      1.1  christos     {
   1446      1.1  christos       input_line_pointer++;
   1447      1.1  christos       expression (expressionP);
   1448      1.1  christos     }
   1449      1.1  christos }
   1450      1.1  christos 
   1451      1.1  christos valueT
   1452      1.1  christos md_section_align (segT segment, valueT size)
   1453  1.1.1.2  christos {
   1454      1.1  christos   int align = bfd_get_section_alignment (stdoutput, segment);
   1455      1.1  christos 
   1456      1.1  christos   return ((size + (1 << align) - 1) & -(1 << align));
   1457      1.1  christos }
   1458      1.1  christos 
   1459      1.1  christos symbolS *
   1460      1.1  christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
   1461      1.1  christos {
   1462      1.1  christos   return 0;
   1463      1.1  christos }
   1464      1.1  christos 
   1465      1.1  christos /* .scomm pseudo-op handler.
   1467      1.1  christos 
   1468      1.1  christos    This is a new pseudo-op to handle putting objects in .scommon.
   1469      1.1  christos    By doing this the linker won't need to do any work,
   1470      1.1  christos    and more importantly it removes the implicit -G arg necessary to
   1471      1.1  christos    correctly link the object file.  */
   1472      1.1  christos 
   1473      1.1  christos static void
   1474      1.1  christos m32r_scomm (int ignore ATTRIBUTE_UNUSED)
   1475      1.1  christos {
   1476      1.1  christos   char *name;
   1477      1.1  christos   char c;
   1478      1.1  christos   char *p;
   1479      1.1  christos   offsetT size;
   1480  1.1.1.2  christos   symbolS *symbolP;
   1481      1.1  christos   offsetT align;
   1482      1.1  christos   int align2;
   1483      1.1  christos 
   1484      1.1  christos   c = get_symbol_name (&name);
   1485  1.1.1.2  christos 
   1486      1.1  christos   /* Just after name is now '\0'.  */
   1487      1.1  christos   p = input_line_pointer;
   1488      1.1  christos   *p = c;
   1489      1.1  christos   SKIP_WHITESPACE_AFTER_NAME ();
   1490      1.1  christos   if (*input_line_pointer != ',')
   1491      1.1  christos     {
   1492      1.1  christos       as_bad (_("Expected comma after symbol-name: rest of line ignored."));
   1493      1.1  christos       ignore_rest_of_line ();
   1494      1.1  christos       return;
   1495      1.1  christos     }
   1496      1.1  christos 
   1497      1.1  christos   /* Skip ','.  */
   1498      1.1  christos   input_line_pointer++;
   1499      1.1  christos   if ((size = get_absolute_expression ()) < 0)
   1500      1.1  christos     {
   1501      1.1  christos       /* xgettext:c-format  */
   1502      1.1  christos       as_warn (_(".SCOMMon length (%ld.) <0! Ignored."), (long) size);
   1503      1.1  christos       ignore_rest_of_line ();
   1504      1.1  christos       return;
   1505      1.1  christos     }
   1506      1.1  christos 
   1507      1.1  christos   /* The third argument to .scomm is the alignment.  */
   1508      1.1  christos   if (*input_line_pointer != ',')
   1509      1.1  christos     align = 8;
   1510      1.1  christos   else
   1511      1.1  christos     {
   1512      1.1  christos       ++input_line_pointer;
   1513      1.1  christos       align = get_absolute_expression ();
   1514      1.1  christos       if (align <= 0)
   1515      1.1  christos 	{
   1516      1.1  christos 	  as_warn (_("ignoring bad alignment"));
   1517      1.1  christos 	  align = 8;
   1518      1.1  christos 	}
   1519      1.1  christos     }
   1520      1.1  christos 
   1521      1.1  christos   /* Convert to a power of 2 alignment.  */
   1522      1.1  christos   if (align)
   1523      1.1  christos     {
   1524      1.1  christos       for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
   1525      1.1  christos 	continue;
   1526      1.1  christos       if (align != 1)
   1527      1.1  christos 	{
   1528      1.1  christos 	  as_bad (_("Common alignment not a power of 2"));
   1529      1.1  christos 	  ignore_rest_of_line ();
   1530      1.1  christos 	  return;
   1531      1.1  christos 	}
   1532      1.1  christos     }
   1533      1.1  christos   else
   1534      1.1  christos     align2 = 0;
   1535      1.1  christos 
   1536      1.1  christos   *p = 0;
   1537      1.1  christos   symbolP = symbol_find_or_make (name);
   1538      1.1  christos   *p = c;
   1539      1.1  christos 
   1540      1.1  christos   if (S_IS_DEFINED (symbolP))
   1541      1.1  christos     {
   1542      1.1  christos       /* xgettext:c-format  */
   1543      1.1  christos       as_bad (_("Ignoring attempt to re-define symbol `%s'."),
   1544      1.1  christos 	      S_GET_NAME (symbolP));
   1545      1.1  christos       ignore_rest_of_line ();
   1546      1.1  christos       return;
   1547      1.1  christos     }
   1548      1.1  christos 
   1549      1.1  christos   if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
   1550      1.1  christos     {
   1551      1.1  christos       /* xgettext:c-format  */
   1552      1.1  christos       as_bad (_("Length of .scomm \"%s\" is already %ld. Not changed to %ld."),
   1553      1.1  christos 	      S_GET_NAME (symbolP),
   1554      1.1  christos 	      (long) S_GET_VALUE (symbolP),
   1555      1.1  christos 	      (long) size);
   1556      1.1  christos 
   1557      1.1  christos       ignore_rest_of_line ();
   1558      1.1  christos       return;
   1559      1.1  christos     }
   1560      1.1  christos 
   1561      1.1  christos   if (symbol_get_obj (symbolP)->local)
   1562      1.1  christos     {
   1563      1.1  christos       segT old_sec = now_seg;
   1564      1.1  christos       int old_subsec = now_subseg;
   1565      1.1  christos       char *pfrag;
   1566      1.1  christos 
   1567      1.1  christos       record_alignment (sbss_section, align2);
   1568      1.1  christos       subseg_set (sbss_section, 0);
   1569      1.1  christos 
   1570      1.1  christos       if (align2)
   1571      1.1  christos 	frag_align (align2, 0, 0);
   1572      1.1  christos 
   1573      1.1  christos       if (S_GET_SEGMENT (symbolP) == sbss_section)
   1574      1.1  christos 	symbol_get_frag (symbolP)->fr_symbol = 0;
   1575      1.1  christos 
   1576      1.1  christos       symbol_set_frag (symbolP, frag_now);
   1577      1.1  christos 
   1578      1.1  christos       pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
   1579      1.1  christos 			(char *) 0);
   1580      1.1  christos       *pfrag = 0;
   1581      1.1  christos       S_SET_SIZE (symbolP, size);
   1582      1.1  christos       S_SET_SEGMENT (symbolP, sbss_section);
   1583      1.1  christos       S_CLEAR_EXTERNAL (symbolP);
   1584      1.1  christos       subseg_set (old_sec, old_subsec);
   1585      1.1  christos     }
   1586      1.1  christos   else
   1587      1.1  christos     {
   1588      1.1  christos       S_SET_VALUE (symbolP, (valueT) size);
   1589      1.1  christos       S_SET_ALIGN (symbolP, align2);
   1590      1.1  christos       S_SET_EXTERNAL (symbolP);
   1591      1.1  christos       S_SET_SEGMENT (symbolP, &scom_section);
   1592      1.1  christos     }
   1593      1.1  christos 
   1594      1.1  christos   demand_empty_rest_of_line ();
   1595      1.1  christos }
   1596      1.1  christos 
   1597      1.1  christos /* The target specific pseudo-ops which we support.  */
   1598      1.1  christos const pseudo_typeS md_pseudo_table[] =
   1599      1.1  christos {
   1600      1.1  christos   { "word",	cons,		4 },
   1601      1.1  christos   { "fillinsn", fill_insn,	0 },
   1602      1.1  christos   { "scomm",	m32r_scomm,	0 },
   1603      1.1  christos   { "debugsym",	debug_sym,	0 },
   1604      1.1  christos   { "m32r",	allow_m32rx,	0 },
   1605      1.1  christos   { "m32rx",	allow_m32rx,	1 },
   1606      1.1  christos   { "m32r2",	allow_m32rx,	2 },
   1607      1.1  christos   { "little",   little,         1 },
   1608      1.1  christos   { "big",      little,         0 },
   1609      1.1  christos   { NULL, NULL, 0 }
   1610      1.1  christos };
   1611      1.1  christos 
   1612      1.1  christos /* Interface to relax_segment.  */
   1614      1.1  christos 
   1615      1.1  christos /* FIXME: Build table by hand, get it working, then machine generate.  */
   1616      1.1  christos 
   1617      1.1  christos const relax_typeS md_relax_table[] =
   1618      1.1  christos {
   1619      1.1  christos /* The fields are:
   1620      1.1  christos    1) most positive reach of this state,
   1621      1.1  christos    2) most negative reach of this state,
   1622      1.1  christos    3) how many bytes this mode will add to the size of the current frag
   1623      1.1  christos    4) which index into the table to try if we can't fit into this one.  */
   1624      1.1  christos 
   1625      1.1  christos   /* The first entry must be unused because an `rlx_more' value of zero ends
   1626      1.1  christos      each list.  */
   1627      1.1  christos   {1, 1, 0, 0},
   1628      1.1  christos 
   1629      1.1  christos   /* The displacement used by GAS is from the end of the 2 byte insn,
   1630      1.1  christos      so we subtract 2 from the following.  */
   1631      1.1  christos   /* 16 bit insn, 8 bit disp -> 10 bit range.
   1632      1.1  christos      This doesn't handle a branch in the right slot at the border:
   1633      1.1  christos      the "& -4" isn't taken into account.  It's not important enough to
   1634      1.1  christos      complicate things over it, so we subtract an extra 2 (or + 2 in -ve
   1635      1.1  christos      case).  */
   1636      1.1  christos   {511 - 2 - 2, -512 - 2 + 2, 0, 2 },
   1637      1.1  christos   /* 32 bit insn, 24 bit disp -> 26 bit range.  */
   1638      1.1  christos   {0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 },
   1639      1.1  christos   /* Same thing, but with leading nop for alignment.  */
   1640      1.1  christos   {0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 }
   1641      1.1  christos };
   1642      1.1  christos 
   1643      1.1  christos long
   1644      1.1  christos m32r_relax_frag (segT segment, fragS *fragP, long stretch)
   1645      1.1  christos {
   1646      1.1  christos   /* Address of branch insn.  */
   1647      1.1  christos   long address = fragP->fr_address + fragP->fr_fix - 2;
   1648      1.1  christos   long growth = 0;
   1649      1.1  christos 
   1650      1.1  christos   /* Keep 32 bit insns aligned on 32 bit boundaries.  */
   1651      1.1  christos   if (fragP->fr_subtype == 2)
   1652      1.1  christos     {
   1653      1.1  christos       if ((address & 3) != 0)
   1654      1.1  christos 	{
   1655      1.1  christos 	  fragP->fr_subtype = 3;
   1656      1.1  christos 	  growth = 2;
   1657      1.1  christos 	}
   1658      1.1  christos     }
   1659      1.1  christos   else if (fragP->fr_subtype == 3)
   1660      1.1  christos     {
   1661      1.1  christos       if ((address & 3) == 0)
   1662      1.1  christos 	{
   1663      1.1  christos 	  fragP->fr_subtype = 2;
   1664      1.1  christos 	  growth = -2;
   1665      1.1  christos 	}
   1666      1.1  christos     }
   1667      1.1  christos   else
   1668      1.1  christos     {
   1669      1.1  christos       growth = relax_frag (segment, fragP, stretch);
   1670      1.1  christos 
   1671      1.1  christos       /* Long jump on odd halfword boundary?  */
   1672      1.1  christos       if (fragP->fr_subtype == 2 && (address & 3) != 0)
   1673      1.1  christos 	{
   1674      1.1  christos 	  fragP->fr_subtype = 3;
   1675      1.1  christos 	  growth += 2;
   1676      1.1  christos 	}
   1677      1.1  christos     }
   1678      1.1  christos 
   1679      1.1  christos   return growth;
   1680      1.1  christos }
   1681      1.1  christos 
   1682      1.1  christos /* Return an initial guess of the length by which a fragment must grow to
   1683      1.1  christos    hold a branch to reach its destination.
   1684      1.1  christos    Also updates fr_type/fr_subtype as necessary.
   1685      1.1  christos 
   1686      1.1  christos    Called just before doing relaxation.
   1687      1.1  christos    Any symbol that is now undefined will not become defined.
   1688      1.1  christos    The guess for fr_var is ACTUALLY the growth beyond fr_fix.
   1689      1.1  christos    Whatever we do to grow fr_fix or fr_var contributes to our returned value.
   1690      1.1  christos    Although it may not be explicit in the frag, pretend fr_var starts
   1691      1.1  christos    with a 0 value.  */
   1692      1.1  christos 
   1693      1.1  christos int
   1694      1.1  christos md_estimate_size_before_relax (fragS *fragP, segT segment)
   1695      1.1  christos {
   1696      1.1  christos   /* The only thing we have to handle here are symbols outside of the
   1697      1.1  christos      current segment.  They may be undefined or in a different segment in
   1698      1.1  christos      which case linker scripts may place them anywhere.
   1699      1.1  christos      However, we can't finish the fragment here and emit the reloc as insn
   1700      1.1  christos      alignment requirements may move the insn about.  */
   1701      1.1  christos   if (S_GET_SEGMENT (fragP->fr_symbol) != segment
   1702      1.1  christos       || S_IS_EXTERNAL (fragP->fr_symbol)
   1703      1.1  christos       || S_IS_WEAK (fragP->fr_symbol))
   1704      1.1  christos     {
   1705      1.1  christos       /* The symbol is undefined in this segment.
   1706      1.1  christos 	 Change the relaxation subtype to the max allowable and leave
   1707      1.1  christos 	 all further handling to md_convert_frag.  */
   1708      1.1  christos       fragP->fr_subtype = 2;
   1709      1.1  christos 
   1710      1.1  christos       {
   1711      1.1  christos 	const CGEN_INSN *insn;
   1712      1.1  christos 	int i;
   1713      1.1  christos 
   1714      1.1  christos 	/* Update the recorded insn.
   1715      1.1  christos 	   Fortunately we don't have to look very far.
   1716      1.1  christos 	   FIXME: Change this to record in the instruction the next higher
   1717      1.1  christos 	   relaxable insn to use.  */
   1718      1.1  christos 	for (i = 0, insn = fragP->fr_cgen.insn; i < 4; i++, insn++)
   1719      1.1  christos 	  {
   1720      1.1  christos 	    if ((strcmp (CGEN_INSN_MNEMONIC (insn),
   1721      1.1  christos 			 CGEN_INSN_MNEMONIC (fragP->fr_cgen.insn))
   1722      1.1  christos 		 == 0)
   1723      1.1  christos 		&& CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED))
   1724      1.1  christos 	      break;
   1725      1.1  christos 	  }
   1726      1.1  christos 	if (i == 4)
   1727      1.1  christos 	  abort ();
   1728      1.1  christos 
   1729      1.1  christos 	fragP->fr_cgen.insn = insn;
   1730      1.1  christos 	return 2;
   1731      1.1  christos       }
   1732      1.1  christos     }
   1733      1.1  christos 
   1734      1.1  christos   return md_relax_table[fragP->fr_subtype].rlx_length;
   1735      1.1  christos }
   1736      1.1  christos 
   1737      1.1  christos /* *FRAGP has been relaxed to its final size, and now needs to have
   1738      1.1  christos    the bytes inside it modified to conform to the new size.
   1739      1.1  christos 
   1740      1.1  christos    Called after relaxation is finished.
   1741      1.1  christos    fragP->fr_type == rs_machine_dependent.
   1742      1.1  christos    fragP->fr_subtype is the subtype of what the address relaxed to.  */
   1743      1.1  christos 
   1744      1.1  christos void
   1745      1.1  christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   1746      1.1  christos 		 segT sec,
   1747      1.1  christos 		 fragS *fragP)
   1748      1.1  christos {
   1749      1.1  christos   char *opcode;
   1750      1.1  christos   char *displacement;
   1751      1.1  christos   int target_address;
   1752      1.1  christos   int opcode_address;
   1753      1.1  christos   int extension;
   1754      1.1  christos   int addend;
   1755      1.1  christos 
   1756      1.1  christos   opcode = fragP->fr_opcode;
   1757      1.1  christos 
   1758      1.1  christos   /* Address opcode resides at in file space.  */
   1759      1.1  christos   opcode_address = fragP->fr_address + fragP->fr_fix - 2;
   1760      1.1  christos 
   1761      1.1  christos   switch (fragP->fr_subtype)
   1762      1.1  christos     {
   1763      1.1  christos     case 1:
   1764      1.1  christos       extension = 0;
   1765      1.1  christos       displacement = &opcode[1];
   1766      1.1  christos       break;
   1767      1.1  christos     case 2:
   1768      1.1  christos       opcode[0] |= 0x80;
   1769      1.1  christos       extension = 2;
   1770      1.1  christos       displacement = &opcode[1];
   1771      1.1  christos       break;
   1772      1.1  christos     case 3:
   1773      1.1  christos       opcode[2] = opcode[0] | 0x80;
   1774      1.1  christos       md_number_to_chars (opcode, PAR_NOP_INSN, 2);
   1775      1.1  christos       opcode_address += 2;
   1776      1.1  christos       extension = 4;
   1777      1.1  christos       displacement = &opcode[3];
   1778      1.1  christos       break;
   1779      1.1  christos     default:
   1780      1.1  christos       abort ();
   1781      1.1  christos     }
   1782      1.1  christos 
   1783      1.1  christos   if (S_GET_SEGMENT (fragP->fr_symbol) != sec
   1784      1.1  christos       || S_IS_EXTERNAL (fragP->fr_symbol)
   1785      1.1  christos       || S_IS_WEAK (fragP->fr_symbol))
   1786      1.1  christos     {
   1787      1.1  christos       /* Symbol must be resolved by linker.  */
   1788      1.1  christos       if (fragP->fr_offset & 3)
   1789      1.1  christos 	as_warn (_("Addend to unresolved symbol not on word boundary."));
   1790      1.1  christos #ifdef USE_M32R_OLD_RELOC
   1791      1.1  christos       addend = fragP->fr_offset >> 2; /* Old M32R used USE_REL. */
   1792      1.1  christos #else
   1793      1.1  christos       addend = 0;
   1794      1.1  christos #endif
   1795      1.1  christos     }
   1796      1.1  christos   else
   1797      1.1  christos     {
   1798      1.1  christos       /* Address we want to reach in file space.  */
   1799      1.1  christos       target_address = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset;
   1800      1.1  christos       addend = (target_address - (opcode_address & -4)) >> 2;
   1801      1.1  christos     }
   1802      1.1  christos 
   1803      1.1  christos   /* Create a relocation for symbols that must be resolved by the linker.
   1804      1.1  christos      Otherwise output the completed insn.  */
   1805      1.1  christos 
   1806      1.1  christos   if (S_GET_SEGMENT (fragP->fr_symbol) != sec
   1807      1.1  christos       || S_IS_EXTERNAL (fragP->fr_symbol)
   1808      1.1  christos       || S_IS_WEAK (fragP->fr_symbol))
   1809      1.1  christos     {
   1810      1.1  christos       fixS *fixP;
   1811      1.1  christos 
   1812      1.1  christos       gas_assert (fragP->fr_subtype != 1);
   1813      1.1  christos       gas_assert (fragP->fr_cgen.insn != 0);
   1814      1.1  christos 
   1815      1.1  christos       fixP = gas_cgen_record_fixup (fragP,
   1816      1.1  christos 				    /* Offset of branch insn in frag.  */
   1817      1.1  christos 				    fragP->fr_fix + extension - 4,
   1818      1.1  christos 				    fragP->fr_cgen.insn,
   1819      1.1  christos 				    4 /* Length.  */,
   1820      1.1  christos 				    /* FIXME: quick hack.  */
   1821      1.1  christos 				    cgen_operand_lookup_by_num (gas_cgen_cpu_desc,
   1822      1.1  christos 								M32R_OPERAND_DISP24),
   1823      1.1  christos 				    fragP->fr_cgen.opinfo,
   1824      1.1  christos 				    fragP->fr_symbol, fragP->fr_offset);
   1825      1.1  christos       if (fragP->fr_cgen.opinfo)
   1826      1.1  christos         fixP->fx_r_type = fragP->fr_cgen.opinfo;
   1827      1.1  christos     }
   1828      1.1  christos 
   1829      1.1  christos #define SIZE_FROM_RELAX_STATE(n) ((n) == 1 ? 1 : 3)
   1830      1.1  christos 
   1831      1.1  christos   md_number_to_chars (displacement, (valueT) addend,
   1832      1.1  christos 		      SIZE_FROM_RELAX_STATE (fragP->fr_subtype));
   1833      1.1  christos 
   1834      1.1  christos   fragP->fr_fix += extension;
   1835      1.1  christos }
   1836      1.1  christos 
   1837      1.1  christos /* Functions concerning relocs.  */
   1839      1.1  christos 
   1840      1.1  christos /* The location from which a PC relative jump should be calculated,
   1841      1.1  christos    given a PC relative reloc.  */
   1842      1.1  christos 
   1843      1.1  christos long
   1844      1.1  christos md_pcrel_from_section (fixS *fixP, segT sec)
   1845      1.1  christos {
   1846      1.1  christos   if (fixP->fx_addsy != (symbolS *) NULL
   1847      1.1  christos       && (! S_IS_DEFINED (fixP->fx_addsy)
   1848      1.1  christos 	  || S_GET_SEGMENT (fixP->fx_addsy) != sec
   1849      1.1  christos           || S_IS_EXTERNAL (fixP->fx_addsy)
   1850      1.1  christos           || S_IS_WEAK (fixP->fx_addsy)))
   1851      1.1  christos     {
   1852      1.1  christos       if (S_GET_SEGMENT (fixP->fx_addsy) != sec
   1853      1.1  christos           && S_IS_DEFINED (fixP->fx_addsy)
   1854      1.1  christos           && ! S_IS_EXTERNAL (fixP->fx_addsy)
   1855      1.1  christos           && ! S_IS_WEAK (fixP->fx_addsy))
   1856      1.1  christos         return fixP->fx_offset;
   1857      1.1  christos 
   1858      1.1  christos       /* The symbol is undefined (or is defined but not in this section).
   1859      1.1  christos 	 Let the linker figure it out.  */
   1860      1.1  christos       return 0;
   1861      1.1  christos     }
   1862      1.1  christos 
   1863      1.1  christos   return (fixP->fx_frag->fr_address + fixP->fx_where) & -4L;
   1864      1.1  christos }
   1865      1.1  christos 
   1866      1.1  christos /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP.
   1867      1.1  christos    Returns BFD_RELOC_NONE if no reloc type can be found.
   1868      1.1  christos    *FIXP may be modified if desired.  */
   1869      1.1  christos 
   1870      1.1  christos bfd_reloc_code_real_type
   1871      1.1  christos md_cgen_lookup_reloc (const CGEN_INSN *insn ATTRIBUTE_UNUSED,
   1872      1.1  christos 		      const CGEN_OPERAND *operand,
   1873      1.1  christos 		      fixS *fixP)
   1874      1.1  christos {
   1875      1.1  christos   switch (operand->type)
   1876      1.1  christos     {
   1877      1.1  christos     case M32R_OPERAND_DISP8:  return BFD_RELOC_M32R_10_PCREL;
   1878      1.1  christos     case M32R_OPERAND_DISP16: return BFD_RELOC_M32R_18_PCREL;
   1879      1.1  christos     case M32R_OPERAND_DISP24: return BFD_RELOC_M32R_26_PCREL;
   1880      1.1  christos     case M32R_OPERAND_UIMM24: return BFD_RELOC_M32R_24;
   1881      1.1  christos     case M32R_OPERAND_HI16:
   1882      1.1  christos     case M32R_OPERAND_SLO16:
   1883      1.1  christos     case M32R_OPERAND_ULO16:
   1884      1.1  christos       /* If low/high/shigh/sda was used, it is recorded in `opinfo'.  */
   1885      1.1  christos       if (fixP->fx_cgen.opinfo != 0)
   1886      1.1  christos 	return fixP->fx_cgen.opinfo;
   1887      1.1  christos       break;
   1888      1.1  christos     default:
   1889      1.1  christos       /* Avoid -Wall warning.  */
   1890      1.1  christos       break;
   1891      1.1  christos     }
   1892      1.1  christos   return BFD_RELOC_NONE;
   1893      1.1  christos }
   1894      1.1  christos 
   1895      1.1  christos /* Record a HI16 reloc for later matching with its LO16 cousin.  */
   1896      1.1  christos 
   1897      1.1  christos static void
   1898      1.1  christos m32r_record_hi16 (int reloc_type,
   1899      1.1  christos 		  fixS *fixP,
   1900      1.1  christos 		  segT seg ATTRIBUTE_UNUSED)
   1901  1.1.1.3  christos {
   1902      1.1  christos   struct m32r_hi_fixup *hi_fixup;
   1903      1.1  christos 
   1904      1.1  christos   gas_assert (reloc_type == BFD_RELOC_M32R_HI16_SLO
   1905      1.1  christos 	  || reloc_type == BFD_RELOC_M32R_HI16_ULO);
   1906      1.1  christos 
   1907      1.1  christos   hi_fixup = XNEW (struct m32r_hi_fixup);
   1908      1.1  christos   hi_fixup->fixp = fixP;
   1909      1.1  christos   hi_fixup->seg  = now_seg;
   1910      1.1  christos   hi_fixup->next = m32r_hi_fixup_list;
   1911      1.1  christos 
   1912      1.1  christos   m32r_hi_fixup_list = hi_fixup;
   1913      1.1  christos }
   1914      1.1  christos 
   1915      1.1  christos /* Called while parsing an instruction to create a fixup.
   1916      1.1  christos    We need to check for HI16 relocs and queue them up for later sorting.  */
   1917      1.1  christos 
   1918      1.1  christos fixS *
   1919      1.1  christos m32r_cgen_record_fixup_exp (fragS *frag,
   1920      1.1  christos 			    int where,
   1921      1.1  christos 			    const CGEN_INSN *insn,
   1922      1.1  christos 			    int length,
   1923      1.1  christos 			    const CGEN_OPERAND *operand,
   1924      1.1  christos 			    int opinfo,
   1925      1.1  christos 			    expressionS *exp)
   1926      1.1  christos {
   1927      1.1  christos   fixS *fixP;
   1928      1.1  christos   bfd_reloc_code_real_type r_type = BFD_RELOC_UNUSED;
   1929      1.1  christos 
   1930      1.1  christos   if (m32r_check_fixup (exp, &r_type))
   1931      1.1  christos     as_bad (_("Invalid PIC expression."));
   1932      1.1  christos 
   1933      1.1  christos   fixP = gas_cgen_record_fixup_exp (frag, where, insn, length,
   1934      1.1  christos 				    operand, opinfo, exp);
   1935      1.1  christos 
   1936      1.1  christos   switch (operand->type)
   1937      1.1  christos     {
   1938      1.1  christos     case M32R_OPERAND_HI16:
   1939      1.1  christos       /* If low/high/shigh/sda was used, it is recorded in `opinfo'.  */
   1940      1.1  christos       if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO
   1941      1.1  christos 	  || fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO)
   1942      1.1  christos 	m32r_record_hi16 (fixP->fx_cgen.opinfo, fixP, now_seg);
   1943      1.1  christos       break;
   1944      1.1  christos 
   1945      1.1  christos     default:
   1946      1.1  christos       /* Avoid -Wall warning.  */
   1947      1.1  christos       break;
   1948      1.1  christos     }
   1949      1.1  christos 
   1950      1.1  christos   switch (r_type)
   1951      1.1  christos     {
   1952      1.1  christos     case BFD_RELOC_UNUSED:
   1953      1.1  christos     default:
   1954      1.1  christos       return fixP;
   1955      1.1  christos 
   1956      1.1  christos     case BFD_RELOC_M32R_GOTPC24:
   1957      1.1  christos       if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO)
   1958      1.1  christos         r_type = BFD_RELOC_M32R_GOTPC_HI_SLO;
   1959      1.1  christos       else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO)
   1960      1.1  christos         r_type = BFD_RELOC_M32R_GOTPC_HI_ULO;
   1961      1.1  christos       else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_LO16)
   1962      1.1  christos         r_type = BFD_RELOC_M32R_GOTPC_LO;
   1963      1.1  christos       break;
   1964      1.1  christos 
   1965      1.1  christos     case BFD_RELOC_M32R_GOT24:
   1966      1.1  christos       if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO)
   1967      1.1  christos         r_type = BFD_RELOC_M32R_GOT16_HI_SLO;
   1968      1.1  christos       else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO)
   1969      1.1  christos         r_type = BFD_RELOC_M32R_GOT16_HI_ULO;
   1970      1.1  christos       else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_LO16)
   1971      1.1  christos         r_type = BFD_RELOC_M32R_GOT16_LO;
   1972      1.1  christos       break;
   1973      1.1  christos 
   1974      1.1  christos     case BFD_RELOC_M32R_GOTOFF:
   1975      1.1  christos       if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO)
   1976      1.1  christos         r_type = BFD_RELOC_M32R_GOTOFF_HI_SLO;
   1977      1.1  christos       else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO)
   1978      1.1  christos         r_type = BFD_RELOC_M32R_GOTOFF_HI_ULO;
   1979      1.1  christos       else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_LO16)
   1980      1.1  christos         r_type = BFD_RELOC_M32R_GOTOFF_LO;
   1981      1.1  christos       break;
   1982      1.1  christos 
   1983      1.1  christos     case BFD_RELOC_M32R_26_PLTREL:
   1984      1.1  christos       as_bad (_("Invalid PIC expression."));
   1985      1.1  christos       break;
   1986      1.1  christos     }
   1987      1.1  christos 
   1988      1.1  christos   fixP->fx_r_type = r_type;
   1989      1.1  christos 
   1990      1.1  christos   return fixP;
   1991      1.1  christos }
   1992      1.1  christos 
   1993      1.1  christos /* Return BFD reloc type from opinfo field in a fixS.
   1994      1.1  christos    It's tricky using fx_r_type in m32r_frob_file because the values
   1995      1.1  christos    are BFD_RELOC_UNUSED + operand number.  */
   1996      1.1  christos #define FX_OPINFO_R_TYPE(f) ((f)->fx_cgen.opinfo)
   1997      1.1  christos 
   1998      1.1  christos /* Sort any unmatched HI16 relocs so that they immediately precede
   1999      1.1  christos    the corresponding LO16 reloc.  This is called before md_apply_fix and
   2000      1.1  christos    tc_gen_reloc.  */
   2001      1.1  christos 
   2002      1.1  christos void
   2003      1.1  christos m32r_frob_file (void)
   2004      1.1  christos {
   2005      1.1  christos   struct m32r_hi_fixup *l;
   2006      1.1  christos 
   2007      1.1  christos   for (l = m32r_hi_fixup_list; l != NULL; l = l->next)
   2008      1.1  christos     {
   2009      1.1  christos       segment_info_type *seginfo;
   2010      1.1  christos       int pass;
   2011      1.1  christos 
   2012      1.1  christos       gas_assert (FX_OPINFO_R_TYPE (l->fixp) == BFD_RELOC_M32R_HI16_SLO
   2013      1.1  christos 	      || FX_OPINFO_R_TYPE (l->fixp) == BFD_RELOC_M32R_HI16_ULO);
   2014      1.1  christos 
   2015      1.1  christos       /* Check quickly whether the next fixup happens to be a matching low.  */
   2016      1.1  christos       if (l->fixp->fx_next != NULL
   2017      1.1  christos 	  && FX_OPINFO_R_TYPE (l->fixp->fx_next) == BFD_RELOC_M32R_LO16
   2018      1.1  christos 	  && l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy
   2019      1.1  christos 	  && l->fixp->fx_offset == l->fixp->fx_next->fx_offset)
   2020      1.1  christos 	continue;
   2021      1.1  christos 
   2022      1.1  christos       /* Look through the fixups for this segment for a matching `low'.
   2023      1.1  christos          When we find one, move the high/shigh just in front of it.  We do
   2024      1.1  christos          this in two passes.  In the first pass, we try to find a
   2025      1.1  christos          unique `low'.  In the second pass, we permit multiple high's
   2026      1.1  christos          relocs for a single `low'.  */
   2027      1.1  christos       seginfo = seg_info (l->seg);
   2028      1.1  christos       for (pass = 0; pass < 2; pass++)
   2029      1.1  christos 	{
   2030      1.1  christos 	  fixS *f;
   2031      1.1  christos 	  fixS *prev;
   2032      1.1  christos 
   2033      1.1  christos 	  prev = NULL;
   2034      1.1  christos 	  for (f = seginfo->fix_root; f != NULL; f = f->fx_next)
   2035      1.1  christos 	    {
   2036      1.1  christos 	      /* Check whether this is a `low' fixup which matches l->fixp.  */
   2037      1.1  christos 	      if (FX_OPINFO_R_TYPE (f) == BFD_RELOC_M32R_LO16
   2038      1.1  christos 		  && f->fx_addsy == l->fixp->fx_addsy
   2039      1.1  christos 		  && f->fx_offset == l->fixp->fx_offset
   2040      1.1  christos 		  && (pass == 1
   2041      1.1  christos 		      || prev == NULL
   2042      1.1  christos 		      || (FX_OPINFO_R_TYPE (prev) != BFD_RELOC_M32R_HI16_SLO
   2043      1.1  christos 			  && FX_OPINFO_R_TYPE (prev) != BFD_RELOC_M32R_HI16_ULO)
   2044      1.1  christos 		      || prev->fx_addsy != f->fx_addsy
   2045      1.1  christos 		      || prev->fx_offset != f->fx_offset))
   2046      1.1  christos 		{
   2047      1.1  christos 		  fixS **pf;
   2048      1.1  christos 
   2049      1.1  christos 		  /* Move l->fixp before f.  */
   2050      1.1  christos 		  for (pf = &seginfo->fix_root;
   2051      1.1  christos 		       *pf != l->fixp;
   2052      1.1  christos 		       pf = & (*pf)->fx_next)
   2053      1.1  christos 		    gas_assert (*pf != NULL);
   2054      1.1  christos 
   2055      1.1  christos 		  *pf = l->fixp->fx_next;
   2056      1.1  christos 
   2057      1.1  christos 		  l->fixp->fx_next = f;
   2058      1.1  christos 		  if (prev == NULL)
   2059      1.1  christos 		    seginfo->fix_root = l->fixp;
   2060      1.1  christos 		  else
   2061      1.1  christos 		    prev->fx_next = l->fixp;
   2062      1.1  christos 
   2063      1.1  christos 		  break;
   2064      1.1  christos 		}
   2065      1.1  christos 
   2066      1.1  christos 	      prev = f;
   2067      1.1  christos 	    }
   2068      1.1  christos 
   2069      1.1  christos 	  if (f != NULL)
   2070      1.1  christos 	    break;
   2071      1.1  christos 
   2072      1.1  christos 	  if (pass == 1
   2073      1.1  christos 	      && warn_unmatched_high)
   2074      1.1  christos 	    as_warn_where (l->fixp->fx_file, l->fixp->fx_line,
   2075      1.1  christos 			   _("Unmatched high/shigh reloc"));
   2076      1.1  christos 	}
   2077      1.1  christos     }
   2078      1.1  christos }
   2079      1.1  christos 
   2080      1.1  christos /* See whether we need to force a relocation into the output file.
   2081      1.1  christos    This is used to force out switch and PC relative relocations when
   2082      1.1  christos    relaxing.  */
   2083      1.1  christos 
   2084      1.1  christos int
   2085      1.1  christos m32r_force_relocation (fixS *fix)
   2086      1.1  christos {
   2087      1.1  christos   if (generic_force_reloc (fix))
   2088      1.1  christos     return 1;
   2089      1.1  christos 
   2090      1.1  christos   if (! m32r_relax)
   2091      1.1  christos     return 0;
   2092      1.1  christos 
   2093      1.1  christos   return fix->fx_pcrel;
   2094      1.1  christos }
   2095      1.1  christos 
   2096      1.1  christos /* Write a value out to the object file, using the appropriate endianness.  */
   2098      1.1  christos 
   2099      1.1  christos void
   2100      1.1  christos md_number_to_chars (char *buf, valueT val, int n)
   2101      1.1  christos {
   2102      1.1  christos   if (target_big_endian)
   2103      1.1  christos     number_to_chars_bigendian (buf, val, n);
   2104      1.1  christos   else
   2105      1.1  christos     number_to_chars_littleendian (buf, val, n);
   2106      1.1  christos }
   2107      1.1  christos 
   2108      1.1  christos /* Turn a string in input_line_pointer into a floating point constant
   2109  1.1.1.3  christos    of type TYPE, and store the appropriate bytes in *LITP.  The number
   2110      1.1  christos    of LITTLENUMS emitted is stored in *SIZEP.  An error message is
   2111      1.1  christos    returned, or NULL on OK.  */
   2112      1.1  christos 
   2113      1.1  christos /* Equal to MAX_PRECISION in atof-ieee.c.  */
   2114      1.1  christos #define MAX_LITTLENUMS 6
   2115      1.1  christos 
   2116      1.1  christos const char *
   2117      1.1  christos md_atof (int type, char *litP, int *sizeP)
   2118      1.1  christos {
   2119      1.1  christos   return ieee_md_atof (type, litP, sizeP, target_big_endian);
   2120      1.1  christos }
   2121      1.1  christos 
   2122      1.1  christos void
   2123      1.1  christos m32r_elf_section_change_hook (void)
   2124      1.1  christos {
   2125      1.1  christos   /* If we have reached the end of a section and we have just emitted a
   2126      1.1  christos      16 bit insn, then emit a nop to make sure that the section ends on
   2127      1.1  christos      a 32 bit boundary.  */
   2128      1.1  christos 
   2129      1.1  christos   if (prev_insn.insn || seen_relaxable_p)
   2130      1.1  christos     (void) m32r_fill_insn (0);
   2131      1.1  christos }
   2132      1.1  christos 
   2133      1.1  christos /* Return true if can adjust the reloc to be relative to its section
   2134      1.1  christos    (such as .data) instead of relative to some symbol.  */
   2135      1.1  christos 
   2136      1.1  christos bfd_boolean
   2137      1.1  christos m32r_fix_adjustable (fixS *fixP)
   2138      1.1  christos {
   2139      1.1  christos   bfd_reloc_code_real_type reloc_type;
   2140      1.1  christos 
   2141      1.1  christos   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
   2142      1.1  christos     {
   2143      1.1  christos       const CGEN_INSN *insn = NULL;
   2144      1.1  christos       int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
   2145      1.1  christos       const CGEN_OPERAND *operand =
   2146      1.1  christos 	cgen_operand_lookup_by_num(gas_cgen_cpu_desc, opindex);
   2147      1.1  christos 
   2148      1.1  christos       reloc_type = md_cgen_lookup_reloc (insn, operand, fixP);
   2149      1.1  christos     }
   2150      1.1  christos   else
   2151      1.1  christos     reloc_type = fixP->fx_r_type;
   2152      1.1  christos 
   2153      1.1  christos   if (fixP->fx_addsy == NULL)
   2154      1.1  christos     return 1;
   2155      1.1  christos 
   2156      1.1  christos   /* Prevent all adjustments to global symbols.  */
   2157      1.1  christos   if (S_IS_EXTERNAL (fixP->fx_addsy))
   2158      1.1  christos     return 0;
   2159      1.1  christos   if (S_IS_WEAK (fixP->fx_addsy))
   2160      1.1  christos     return 0;
   2161      1.1  christos 
   2162      1.1  christos   if (pic_code
   2163      1.1  christos       && (reloc_type == BFD_RELOC_M32R_24
   2164      1.1  christos           || reloc_type == BFD_RELOC_M32R_26_PCREL
   2165      1.1  christos           || reloc_type == BFD_RELOC_M32R_HI16_SLO
   2166      1.1  christos           || reloc_type == BFD_RELOC_M32R_HI16_ULO
   2167      1.1  christos           || reloc_type == BFD_RELOC_M32R_LO16))
   2168      1.1  christos     return 0;
   2169      1.1  christos 
   2170      1.1  christos   if (reloc_type == BFD_RELOC_M32R_GOT24
   2171      1.1  christos       || reloc_type == BFD_RELOC_M32R_26_PLTREL
   2172      1.1  christos       || reloc_type == BFD_RELOC_M32R_GOTPC_HI_SLO
   2173      1.1  christos       || reloc_type == BFD_RELOC_M32R_GOTPC_HI_ULO
   2174      1.1  christos       || reloc_type == BFD_RELOC_M32R_GOTPC_LO
   2175      1.1  christos       || reloc_type == BFD_RELOC_M32R_GOT16_HI_SLO
   2176      1.1  christos       || reloc_type == BFD_RELOC_M32R_GOT16_HI_ULO
   2177      1.1  christos       || reloc_type == BFD_RELOC_M32R_GOT16_LO)
   2178      1.1  christos     return 0;
   2179      1.1  christos 
   2180      1.1  christos   /* We need the symbol name for the VTABLE entries.  */
   2181      1.1  christos   if (reloc_type == BFD_RELOC_VTABLE_INHERIT
   2182      1.1  christos       || reloc_type == BFD_RELOC_VTABLE_ENTRY)
   2183      1.1  christos     return 0;
   2184      1.1  christos 
   2185      1.1  christos   return 1;
   2186      1.1  christos }
   2187      1.1  christos 
   2188      1.1  christos void
   2189      1.1  christos m32r_elf_final_processing (void)
   2190      1.1  christos {
   2191      1.1  christos   if (use_parallel)
   2192      1.1  christos     m32r_flags |= E_M32R_HAS_PARALLEL;
   2193      1.1  christos   elf_elfheader (stdoutput)->e_flags |= m32r_flags;
   2194      1.1  christos }
   2195      1.1  christos 
   2196      1.1  christos /* Translate internal representation of relocation info to BFD target
   2197  1.1.1.2  christos    format. */
   2198  1.1.1.3  christos 
   2199  1.1.1.2  christos arelent *
   2200  1.1.1.3  christos tc_gen_reloc (asection * section, fixS * fixP)
   2201      1.1  christos {
   2202      1.1  christos   arelent * reloc;
   2203      1.1  christos   bfd_reloc_code_real_type code;
   2204      1.1  christos 
   2205      1.1  christos   reloc = XNEW (arelent);
   2206      1.1  christos 
   2207      1.1  christos   reloc->sym_ptr_ptr = XNEW (asymbol *);
   2208      1.1  christos   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   2209      1.1  christos   reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
   2210      1.1  christos 
   2211      1.1  christos   if (fixP->fx_pcrel)
   2212      1.1  christos     {
   2213      1.1  christos       if (fixP->fx_r_type == BFD_RELOC_32)
   2214  1.1.1.2  christos         fixP->fx_r_type = BFD_RELOC_32_PCREL;
   2215      1.1  christos       else if (fixP->fx_r_type == BFD_RELOC_16)
   2216      1.1  christos 	{
   2217      1.1  christos           fixP->fx_r_type = BFD_RELOC_16_PCREL;
   2218      1.1  christos           bfd_set_error (bfd_error_bad_value);
   2219      1.1  christos 	}
   2220      1.1  christos     }
   2221      1.1  christos 
   2222      1.1  christos   code = fixP->fx_r_type;
   2223      1.1  christos   if (pic_code)
   2224      1.1  christos     {
   2225      1.1  christos #ifdef DEBUG_PIC
   2226      1.1  christos printf("%s",bfd_get_reloc_code_name(code));
   2227      1.1  christos #endif
   2228      1.1  christos       switch (code)
   2229      1.1  christos         {
   2230      1.1  christos         case BFD_RELOC_M32R_26_PCREL:
   2231      1.1  christos             code = BFD_RELOC_M32R_26_PLTREL;
   2232      1.1  christos           break;
   2233      1.1  christos 
   2234      1.1  christos         case BFD_RELOC_M32R_24:
   2235      1.1  christos           if (fixP->fx_addsy != NULL
   2236      1.1  christos               && strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0)
   2237      1.1  christos             code = BFD_RELOC_M32R_GOTPC24;
   2238      1.1  christos           else
   2239      1.1  christos             code = BFD_RELOC_M32R_GOT24;
   2240      1.1  christos           break;
   2241      1.1  christos 
   2242      1.1  christos         case BFD_RELOC_M32R_HI16_ULO:
   2243      1.1  christos           if (fixP->fx_addsy != NULL
   2244      1.1  christos               && strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0)
   2245      1.1  christos             code = BFD_RELOC_M32R_GOTPC_HI_ULO;
   2246      1.1  christos           else
   2247      1.1  christos             code = BFD_RELOC_M32R_GOT16_HI_ULO;
   2248      1.1  christos           break;
   2249      1.1  christos 
   2250      1.1  christos         case BFD_RELOC_M32R_HI16_SLO:
   2251      1.1  christos           if (fixP->fx_addsy != NULL
   2252      1.1  christos               && strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0)
   2253      1.1  christos             code = BFD_RELOC_M32R_GOTPC_HI_SLO;
   2254      1.1  christos           else
   2255      1.1  christos             code = BFD_RELOC_M32R_GOT16_HI_SLO;
   2256      1.1  christos           break;
   2257      1.1  christos 
   2258      1.1  christos         case BFD_RELOC_M32R_LO16:
   2259      1.1  christos           if (fixP->fx_addsy != NULL
   2260      1.1  christos               && strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0)
   2261      1.1  christos             code = BFD_RELOC_M32R_GOTPC_LO;
   2262      1.1  christos           else
   2263      1.1  christos             code = BFD_RELOC_M32R_GOT16_LO;
   2264      1.1  christos           break;
   2265      1.1  christos 
   2266  1.1.1.2  christos         default:
   2267      1.1  christos           break;
   2268      1.1  christos         }
   2269      1.1  christos #ifdef DEBUG_PIC
   2270      1.1  christos printf(" => %s",bfd_get_reloc_code_name(code));
   2271      1.1  christos #endif
   2272      1.1  christos     }
   2273      1.1  christos 
   2274      1.1  christos   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
   2275      1.1  christos 
   2276      1.1  christos #ifdef DEBUG_PIC
   2277      1.1  christos printf(" => %s\n",reloc->howto->name);
   2278      1.1  christos #endif
   2279      1.1  christos 
   2280  1.1.1.2  christos  if (reloc->howto == (reloc_howto_type *) NULL)
   2281      1.1  christos     {
   2282      1.1  christos       as_bad_where (fixP->fx_file, fixP->fx_line,
   2283      1.1  christos             _("internal error: can't export reloc type %d (`%s')"),
   2284      1.1  christos             fixP->fx_r_type, bfd_get_reloc_code_name (code));
   2285      1.1  christos       return NULL;
   2286      1.1  christos     }
   2287      1.1  christos 
   2288      1.1  christos   /* Use fx_offset for these cases.  */
   2289      1.1  christos   if (   fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
   2290      1.1  christos       || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
   2291      1.1  christos       || fixP->fx_r_type == BFD_RELOC_32_PCREL)
   2292      1.1  christos     reloc->addend  = fixP->fx_offset;
   2293      1.1  christos   else if ((!pic_code
   2294      1.1  christos             && code != BFD_RELOC_M32R_26_PLTREL)
   2295      1.1  christos            && fixP->fx_pcrel
   2296      1.1  christos            && fixP->fx_addsy != NULL
   2297      1.1  christos            && (S_GET_SEGMENT(fixP->fx_addsy) != section)
   2298  1.1.1.2  christos            && S_IS_DEFINED (fixP->fx_addsy)
   2299      1.1  christos            && ! S_IS_EXTERNAL(fixP->fx_addsy)
   2300      1.1  christos            && ! S_IS_WEAK(fixP->fx_addsy))
   2301      1.1  christos     /* Already used fx_offset in the opcode field itseld.  */
   2302      1.1  christos     reloc->addend  = fixP->fx_offset;
   2303  1.1.1.3  christos   else
   2304      1.1  christos     reloc->addend  = fixP->fx_addnumber;
   2305      1.1  christos 
   2306      1.1  christos   return reloc;
   2307      1.1  christos }
   2308      1.1  christos 
   2309      1.1  christos inline static char *
   2310      1.1  christos m32r_end_of_match (char *cont, const char *what)
   2311      1.1  christos {
   2312      1.1  christos   int len = strlen (what);
   2313      1.1  christos 
   2314      1.1  christos   if (strncasecmp (cont, what, strlen (what)) == 0
   2315      1.1  christos       && ! is_part_of_name (cont[len]))
   2316      1.1  christos     return cont + len;
   2317      1.1  christos 
   2318      1.1  christos   return NULL;
   2319      1.1  christos }
   2320      1.1  christos 
   2321      1.1  christos int
   2322      1.1  christos m32r_parse_name (char const *name,
   2323      1.1  christos 		 expressionS *exprP,
   2324      1.1  christos 		 enum expr_mode mode,
   2325      1.1  christos 		 char *nextcharP)
   2326      1.1  christos {
   2327      1.1  christos   char *next = input_line_pointer;
   2328      1.1  christos   char *next_end;
   2329      1.1  christos   int reloc_type;
   2330      1.1  christos   operatorT op_type;
   2331      1.1  christos   segT segment;
   2332      1.1  christos 
   2333      1.1  christos   exprP->X_op_symbol = NULL;
   2334      1.1  christos   exprP->X_md = BFD_RELOC_UNUSED;
   2335      1.1  christos 
   2336      1.1  christos   if (strcmp (name, GOT_NAME) == 0)
   2337      1.1  christos     {
   2338      1.1  christos       if (! GOT_symbol)
   2339      1.1  christos 	GOT_symbol = symbol_find_or_make (name);
   2340      1.1  christos 
   2341      1.1  christos       exprP->X_add_symbol = GOT_symbol;
   2342      1.1  christos     no_suffix:
   2343      1.1  christos       /* If we have an absolute symbol or a
   2344      1.1  christos 	 reg, then we know its value now.  */
   2345      1.1  christos       segment = S_GET_SEGMENT (exprP->X_add_symbol);
   2346      1.1  christos       if (mode != expr_defer && segment == absolute_section)
   2347      1.1  christos 	{
   2348      1.1  christos 	  exprP->X_op = O_constant;
   2349      1.1  christos 	  exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
   2350      1.1  christos 	  exprP->X_add_symbol = NULL;
   2351      1.1  christos 	}
   2352      1.1  christos       else if (mode != expr_defer && segment == reg_section)
   2353      1.1  christos 	{
   2354      1.1  christos 	  exprP->X_op = O_register;
   2355      1.1  christos 	  exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
   2356      1.1  christos 	  exprP->X_add_symbol = NULL;
   2357      1.1  christos 	}
   2358      1.1  christos       else
   2359      1.1  christos 	{
   2360      1.1  christos 	  exprP->X_op = O_symbol;
   2361      1.1  christos 	  exprP->X_add_number = 0;
   2362      1.1  christos 	}
   2363      1.1  christos 
   2364      1.1  christos       return 1;
   2365      1.1  christos     }
   2366      1.1  christos 
   2367      1.1  christos   exprP->X_add_symbol = symbol_find_or_make (name);
   2368      1.1  christos 
   2369      1.1  christos   if (*nextcharP != '@')
   2370      1.1  christos     goto no_suffix;
   2371      1.1  christos   else if ((next_end = m32r_end_of_match (next + 1, "GOTOFF")))
   2372      1.1  christos     {
   2373      1.1  christos       reloc_type = BFD_RELOC_M32R_GOTOFF;
   2374      1.1  christos       op_type = O_PIC_reloc;
   2375      1.1  christos     }
   2376      1.1  christos   else if ((next_end = m32r_end_of_match (next + 1, "GOT")))
   2377      1.1  christos     {
   2378      1.1  christos       reloc_type = BFD_RELOC_M32R_GOT24;
   2379      1.1  christos       op_type = O_PIC_reloc;
   2380      1.1  christos     }
   2381      1.1  christos   else if ((next_end = m32r_end_of_match (next + 1, "PLT")))
   2382      1.1  christos     {
   2383      1.1  christos       reloc_type = BFD_RELOC_M32R_26_PLTREL;
   2384      1.1  christos       op_type = O_PIC_reloc;
   2385      1.1  christos     }
   2386      1.1  christos   else
   2387      1.1  christos     goto no_suffix;
   2388      1.1  christos 
   2389      1.1  christos   *input_line_pointer = *nextcharP;
   2390      1.1  christos   input_line_pointer = next_end;
   2391      1.1  christos   *nextcharP = *input_line_pointer;
   2392      1.1  christos   *input_line_pointer = '\0';
   2393      1.1  christos 
   2394      1.1  christos   exprP->X_op = op_type;
   2395      1.1  christos   exprP->X_add_number = 0;
   2396      1.1  christos   exprP->X_md = reloc_type;
   2397      1.1  christos 
   2398      1.1  christos   return 1;
   2399      1.1  christos }
   2400      1.1  christos 
   2401      1.1  christos int
   2402      1.1  christos m32r_cgen_parse_fix_exp(int opinfo, expressionS *exp)
   2403      1.1  christos {
   2404      1.1  christos   if (exp->X_op == O_PIC_reloc
   2405      1.1  christos       && exp->X_md == BFD_RELOC_M32R_26_PLTREL)
   2406                        {
   2407                          exp->X_op = O_symbol;
   2408                          opinfo = exp->X_md;
   2409                        }
   2410                    
   2411                      return opinfo;
   2412                    }
   2413