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