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