1 /* tc-m32r.c -- Assembler for the Renesas M32R.
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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)
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.
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, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include "safe-ctype.h"
26 #include "opcodes/m32r-desc.h"
27 #include "opcodes/m32r-opc.h"
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
35 struct sym_link
*next
;
39 static sym_linkS
*debug_sym_link
= (sym_linkS
*) 0;
41 /* Structure to hold all of the different components describing
42 an individual instruction. */
45 const CGEN_INSN
*insn
;
46 const CGEN_INSN
*orig_insn
;
49 CGEN_INSN_INT buffer
[1];
50 #define INSN_VALUE(buf) (*(buf))
52 unsigned char buffer
[CGEN_MAX_INSN_SIZE
];
53 #define INSN_VALUE(buf) (buf)
58 fixS
*fixups
[GAS_CGEN_MAX_FIXUPS
];
59 int indices
[MAX_OPERAND_INSTANCES
];
60 sym_linkS
*debug_sym_link
;
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
;
68 /* Non-zero if we've seen a relaxable insn since the last 32 bit
70 static int seen_relaxable_p
= 0;
72 /* Non-zero if we are generating PIC code. */
75 /* Non-zero if -relax specified, in which case sufficient relocs are output
76 for the linker to do relaxing.
77 We do simple forms of relaxing internally, but they are always done.
78 This flag does not apply to them. */
79 static int m32r_relax
;
81 /* Non-zero if warn when a high/shigh reloc has no matching low reloc.
82 Each high/shigh reloc must be paired with it's low cousin in order to
83 properly calculate the addend in a relocatable link (since there is a
84 potential carry from the low to the high/shigh).
85 This option is off by default though for user-written assembler code it
86 might make sense to make the default be on (i.e. have gcc pass a flag
87 to turn it off). This warning must not be on for GCC created code as
88 optimization may delete the low but not the high/shigh (at least we
89 shouldn't assume or require it to). */
90 static int warn_unmatched_high
= 0;
92 /* 1 if -m32rx has been specified, in which case support for
93 the extended M32RX instruction set should be enabled.
94 2 if -m32r2 has been specified, in which case support for
95 the extended M32R2 instruction set should be enabled. */
96 static int enable_m32rx
= 0; /* Default to M32R. */
98 /* Non-zero if -m32rx -hidden has been specified, in which case support for
99 the special M32RX instruction set should be enabled. */
100 static int enable_special
= 0;
102 /* Non-zero if -bitinst has been specified, in which case support
103 for extended M32R bit-field instruction set should be enabled. */
104 static int enable_special_m32r
= 1;
106 /* Non-zero if -float has been specified, in which case support for
107 extended M32R floating point instruction set should be enabled. */
108 static int enable_special_float
= 0;
110 /* Non-zero if the programmer should be warned when an explicit parallel
111 instruction might have constraint violations. */
112 static int warn_explicit_parallel_conflicts
= 1;
114 /* Non-zero if the programmer should not receive any messages about
115 parallel instruction with potential or real constraint violations.
116 The ability to suppress these messages is intended only for hardware
117 vendors testing the chip. It superceedes
118 warn_explicit_parallel_conflicts. */
119 static int ignore_parallel_conflicts
= 0;
121 /* Non-zero if insns can be made parallel. */
122 static int use_parallel
= 0;
124 /* Non-zero if optimizations should be performed. */
128 static int m32r_flags
= 0;
130 /* Stuff for .scomm symbols. */
131 static segT sbss_section
;
132 static asection scom_section
;
133 static asymbol scom_symbol
;
135 const char comment_chars
[] = ";";
136 const char line_comment_chars
[] = "#";
137 const char line_separator_chars
[] = "!";
138 const char EXP_CHARS
[] = "eE";
139 const char FLT_CHARS
[] = "dD";
141 /* Relocations against symbols are done in two
142 parts, with a HI relocation and a LO relocation. Each relocation
143 has only 16 bits of space to store an addend. This means that in
144 order for the linker to handle carries correctly, it must be able
145 to locate both the HI and the LO relocation. This means that the
146 relocations must appear in order in the relocation table.
148 In order to implement this, we keep track of each unmatched HI
149 relocation. We then sort them so that they immediately precede the
150 corresponding LO relocation. */
155 struct m32r_hi_fixup
*next
;
160 /* The section this fixup is in. */
164 /* The list of unmatched HI relocs. */
166 static struct m32r_hi_fixup
*m32r_hi_fixup_list
;
170 enum bfd_architecture bfd_mach
;
174 { bfd_mach_m32r
, (1<<MACH_M32R
) },
175 { bfd_mach_m32rx
, (1<<MACH_M32RX
) },
176 { bfd_mach_m32r2
, (1<<MACH_M32R2
) }
184 if (stdoutput
!= NULL
)
185 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, mach_table
[on
].bfd_mach
);
187 if (gas_cgen_cpu_desc
!= NULL
)
188 gas_cgen_cpu_desc
->machs
= mach_table
[on
].mach_flags
;
191 #define M32R_SHORTOPTS "O::K:"
193 const char *md_shortopts
= M32R_SHORTOPTS
;
197 OPTION_M32R
= OPTION_MD_BASE
,
204 OPTION_WARN_PARALLEL
,
205 OPTION_NO_WARN_PARALLEL
,
206 OPTION_IGNORE_PARALLEL
,
207 OPTION_NO_IGNORE_PARALLEL
,
210 OPTION_NO_SPECIAL_M32R
,
211 OPTION_SPECIAL_FLOAT
,
212 OPTION_WARN_UNMATCHED
,
213 OPTION_NO_WARN_UNMATCHED
216 struct option md_longopts
[] =
218 {"m32r", no_argument
, NULL
, OPTION_M32R
},
219 {"m32rx", no_argument
, NULL
, OPTION_M32RX
},
220 {"m32r2", no_argument
, NULL
, OPTION_M32R2
},
221 {"big", no_argument
, NULL
, OPTION_BIG
},
222 {"little", no_argument
, NULL
, OPTION_LITTLE
},
223 {"EB", no_argument
, NULL
, OPTION_BIG
},
224 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
225 {"parallel", no_argument
, NULL
, OPTION_PARALLEL
},
226 {"no-parallel", no_argument
, NULL
, OPTION_NO_PARALLEL
},
227 {"warn-explicit-parallel-conflicts", no_argument
, NULL
, OPTION_WARN_PARALLEL
},
228 {"Wp", no_argument
, NULL
, OPTION_WARN_PARALLEL
},
229 {"no-warn-explicit-parallel-conflicts", no_argument
, NULL
, OPTION_NO_WARN_PARALLEL
},
230 {"Wnp", no_argument
, NULL
, OPTION_NO_WARN_PARALLEL
},
231 {"ignore-parallel-conflicts", no_argument
, NULL
, OPTION_IGNORE_PARALLEL
},
232 {"Ip", no_argument
, NULL
, OPTION_IGNORE_PARALLEL
},
233 {"no-ignore-parallel-conflicts", no_argument
, NULL
, OPTION_NO_IGNORE_PARALLEL
},
234 {"nIp", no_argument
, NULL
, OPTION_NO_IGNORE_PARALLEL
},
235 {"hidden", no_argument
, NULL
, OPTION_SPECIAL
},
236 {"bitinst", no_argument
, NULL
, OPTION_SPECIAL_M32R
},
237 {"no-bitinst", no_argument
, NULL
, OPTION_NO_SPECIAL_M32R
},
238 {"float", no_argument
, NULL
, OPTION_SPECIAL_FLOAT
},
239 /* Sigh. I guess all warnings must now have both variants. */
240 {"warn-unmatched-high", no_argument
, NULL
, OPTION_WARN_UNMATCHED
},
241 {"Wuh", no_argument
, NULL
, OPTION_WARN_UNMATCHED
},
242 {"no-warn-unmatched-high", no_argument
, NULL
, OPTION_NO_WARN_UNMATCHED
},
243 {"Wnuh", no_argument
, NULL
, OPTION_NO_WARN_UNMATCHED
},
244 {NULL
, no_argument
, NULL
, 0}
247 size_t md_longopts_size
= sizeof (md_longopts
);
252 target_big_endian
= ! on
;
255 /* Use parallel execution. */
263 if (use_parallel
== 1)
270 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
290 enable_special_m32r
= 1;
294 target_big_endian
= 1;
298 target_big_endian
= 0;
301 case OPTION_PARALLEL
:
305 case OPTION_NO_PARALLEL
:
309 case OPTION_WARN_PARALLEL
:
310 warn_explicit_parallel_conflicts
= 1;
313 case OPTION_NO_WARN_PARALLEL
:
314 warn_explicit_parallel_conflicts
= 0;
317 case OPTION_IGNORE_PARALLEL
:
318 ignore_parallel_conflicts
= 1;
321 case OPTION_NO_IGNORE_PARALLEL
:
322 ignore_parallel_conflicts
= 0;
330 /* Pretend that we do not recognise this option. */
331 as_bad (_("Unrecognised option: -hidden"));
336 case OPTION_SPECIAL_M32R
:
337 enable_special_m32r
= 1;
340 case OPTION_NO_SPECIAL_M32R
:
341 enable_special_m32r
= 0;
344 case OPTION_SPECIAL_FLOAT
:
345 enable_special_float
= 1;
348 case OPTION_WARN_UNMATCHED
:
349 warn_unmatched_high
= 1;
352 case OPTION_NO_WARN_UNMATCHED
:
353 warn_unmatched_high
= 0;
357 if (strcmp (arg
, "PIC") != 0)
358 as_warn (_("Unrecognized option following -K"));
371 md_show_usage (FILE *stream
)
373 fprintf (stream
, _(" M32R specific command line options:\n"));
375 fprintf (stream
, _("\
376 -m32r disable support for the m32rx instruction set\n"));
377 fprintf (stream
, _("\
378 -m32rx support the extended m32rx instruction set\n"));
379 fprintf (stream
, _("\
380 -m32r2 support the extended m32r2 instruction set\n"));
381 fprintf (stream
, _("\
382 -EL,-little produce little endian code and data\n"));
383 fprintf (stream
, _("\
384 -EB,-big produce big endian code and data\n"));
385 fprintf (stream
, _("\
386 -parallel try to combine instructions in parallel\n"));
387 fprintf (stream
, _("\
388 -no-parallel disable -parallel\n"));
389 fprintf (stream
, _("\
390 -no-bitinst disallow the M32R2's extended bit-field instructions\n"));
391 fprintf (stream
, _("\
392 -O try to optimize code. Implies -parallel\n"));
394 fprintf (stream
, _("\
395 -warn-explicit-parallel-conflicts warn when parallel instructions\n"));
396 fprintf (stream
, _("\
397 might violate contraints\n"));
398 fprintf (stream
, _("\
399 -no-warn-explicit-parallel-conflicts do not warn when parallel\n"));
400 fprintf (stream
, _("\
401 instructions might violate contraints\n"));
402 fprintf (stream
, _("\
403 -Wp synonym for -warn-explicit-parallel-conflicts\n"));
404 fprintf (stream
, _("\
405 -Wnp synonym for -no-warn-explicit-parallel-conflicts\n"));
406 fprintf (stream
, _("\
407 -ignore-parallel-conflicts do not check parallel instructions\n"));
408 fprintf (stream
, _("\
409 fo contraint violations\n"));
410 fprintf (stream
, _("\
411 -no-ignore-parallel-conflicts check parallel instructions for\n"));
412 fprintf (stream
, _("\
413 contraint violations\n"));
414 fprintf (stream
, _("\
415 -Ip synonym for -ignore-parallel-conflicts\n"));
416 fprintf (stream
, _("\
417 -nIp synonym for -no-ignore-parallel-conflicts\n"));
419 fprintf (stream
, _("\
420 -warn-unmatched-high warn when an (s)high reloc has no matching low reloc\n"));
421 fprintf (stream
, _("\
422 -no-warn-unmatched-high do not warn about missing low relocs\n"));
423 fprintf (stream
, _("\
424 -Wuh synonym for -warn-unmatched-high\n"));
425 fprintf (stream
, _("\
426 -Wnuh synonym for -no-warn-unmatched-high\n"));
428 fprintf (stream
, _("\
429 -KPIC generate PIC\n"));
432 /* Set by md_assemble for use by m32r_fill_insn. */
433 static subsegT prev_subseg
;
434 static segT prev_seg
;
436 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
437 symbolS
* GOT_symbol
;
440 m32r_PIC_related_p (symbolS
*sym
)
447 if (sym
== GOT_symbol
)
450 exp
= symbol_get_value_expression (sym
);
452 return (exp
->X_op
== O_PIC_reloc
453 || exp
->X_md
== BFD_RELOC_M32R_26_PLTREL
454 || m32r_PIC_related_p (exp
->X_add_symbol
)
455 || m32r_PIC_related_p (exp
->X_op_symbol
));
459 m32r_check_fixup (expressionS
*main_exp
, bfd_reloc_code_real_type
*r_type_p
)
461 expressionS
*exp
= main_exp
;
463 if (exp
->X_op
== O_add
&& m32r_PIC_related_p (exp
->X_op_symbol
))
466 if (exp
->X_op
== O_symbol
&& exp
->X_add_symbol
)
468 if (exp
->X_add_symbol
== GOT_symbol
)
470 *r_type_p
= BFD_RELOC_M32R_GOTPC24
;
474 else if (exp
->X_op
== O_add
)
476 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
481 if (exp
->X_op
== O_PIC_reloc
)
483 *r_type_p
= exp
->X_md
;
485 exp
->X_op
= O_symbol
;
488 main_exp
->X_add_symbol
= exp
->X_add_symbol
;
489 main_exp
->X_add_number
+= exp
->X_add_number
;
493 return (m32r_PIC_related_p (exp
->X_add_symbol
)
494 || m32r_PIC_related_p (exp
->X_op_symbol
));
499 /* FIXME: Should be machine generated. */
500 #define NOP_INSN 0x7000
501 #define PAR_NOP_INSN 0xf000 /* Can only be used in 2nd slot. */
503 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
504 of an rs_align_code fragment. */
507 m32r_handle_align (fragS
*fragp
)
509 static const unsigned char nop_pattern
[] = { 0xf0, 0x00 };
510 static const unsigned char multi_nop_pattern
[] = { 0x70, 0x00, 0xf0, 0x00 };
515 if (fragp
->fr_type
!= rs_align_code
)
518 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
519 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
531 memcpy (p
, nop_pattern
, 2);
537 memcpy (p
, multi_nop_pattern
, 4);
539 fragp
->fr_fix
+= fix
;
543 /* If the last instruction was the first of 2 16 bit insns,
544 output a nop to move the PC to a 32 bit boundary.
546 This is done via an alignment specification since branch relaxing
547 may make it unnecessary.
549 Internally, we need to output one of these each time a 32 bit insn is
550 seen after an insn that is relaxable. */
553 fill_insn (int ignore ATTRIBUTE_UNUSED
)
555 frag_align_code (2, 0);
556 prev_insn
.insn
= NULL
;
557 seen_relaxable_p
= 0;
560 /* Record the symbol so that when we output the insn, we can create
561 a symbol that is at the start of the instruction. This is used
562 to emit the label for the start of a breakpoint without causing
563 the assembler to emit a NOP if the previous instruction was a
564 16 bit instruction. */
567 debug_sym (int ignore ATTRIBUTE_UNUSED
)
575 name
= input_line_pointer
;
576 delim
= get_symbol_end ();
577 end_name
= input_line_pointer
;
579 if ((symbolP
= symbol_find (name
)) == NULL
580 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
581 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
583 symbol_table_insert (symbolP
);
584 if (S_IS_DEFINED (symbolP
) && (S_GET_SEGMENT (symbolP
) != reg_section
585 || S_IS_EXTERNAL (symbolP
)
586 || S_IS_WEAK (symbolP
)))
587 /* xgettext:c-format */
588 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP
));
592 link
= (sym_linkS
*) xmalloc (sizeof (sym_linkS
));
593 link
->symbol
= symbolP
;
594 link
->next
= debug_sym_link
;
595 debug_sym_link
= link
;
596 symbol_get_obj (symbolP
)->local
= 1;
600 demand_empty_rest_of_line ();
603 /* Second pass to expanding the debug symbols, go through linked
604 list of symbols and reassign the address. */
607 expand_debug_syms (sym_linkS
*syms
, int align
)
609 char *save_input_line
= input_line_pointer
;
610 sym_linkS
*next_syms
;
615 (void) frag_align_code (align
, 0);
616 for (; syms
!= (sym_linkS
*) 0; syms
= next_syms
)
618 symbolS
*symbolP
= syms
->symbol
;
619 next_syms
= syms
->next
;
620 input_line_pointer
= ".\n";
621 pseudo_set (symbolP
);
622 free ((char *) syms
);
625 input_line_pointer
= save_input_line
;
629 m32r_flush_pending_output (void)
633 expand_debug_syms (debug_sym_link
, 1);
634 debug_sym_link
= (sym_linkS
*) 0;
638 /* Cover function to fill_insn called after a label and at end of assembly.
639 The result is always 1: we're called in a conditional to see if the
640 current line is a label. */
643 m32r_fill_insn (int done
)
645 if (prev_seg
!= NULL
)
648 subsegT subseg
= now_subseg
;
650 subseg_set (prev_seg
, prev_subseg
);
654 subseg_set (seg
, subseg
);
657 if (done
&& debug_sym_link
)
659 expand_debug_syms (debug_sym_link
, 1);
660 debug_sym_link
= (sym_linkS
*) 0;
666 /* The default target format to use. */
669 m32r_target_format (void)
672 if (target_big_endian
)
673 return "elf32-m32r-linux";
675 return "elf32-m32rle-linux";
677 if (target_big_endian
)
680 return "elf32-m32rle";
691 /* Initialize the `cgen' interface. */
693 /* Set the machine number and endian. */
694 gas_cgen_cpu_desc
= m32r_cgen_cpu_open (CGEN_CPU_OPEN_MACHS
, 0,
695 CGEN_CPU_OPEN_ENDIAN
,
697 CGEN_ENDIAN_BIG
: CGEN_ENDIAN_LITTLE
),
699 m32r_cgen_init_asm (gas_cgen_cpu_desc
);
701 /* The operand instance table is used during optimization to determine
702 which insns can be executed in parallel. It is also used to give
703 warnings regarding operand interference in parallel insns. */
704 m32r_cgen_init_opinst_table (gas_cgen_cpu_desc
);
706 /* This is a callback from cgen to gas to parse operands. */
707 cgen_set_parse_operand_fn (gas_cgen_cpu_desc
, gas_cgen_parse_operand
);
709 /* Save the current subseg so we can restore it [it's the default one and
710 we don't want the initial section to be .sbss]. */
714 /* The sbss section is for local .scomm symbols. */
715 sbss_section
= subseg_new (".sbss", 0);
717 /* This is copied from perform_an_assembly_pass. */
718 applicable
= bfd_applicable_section_flags (stdoutput
);
719 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
& SEC_ALLOC
);
721 subseg_set (seg
, subseg
);
723 /* We must construct a fake section similar to bfd_com_section
724 but with the name .scommon. */
725 scom_section
= bfd_com_section
;
726 scom_section
.name
= ".scommon";
727 scom_section
.output_section
= & scom_section
;
728 scom_section
.symbol
= & scom_symbol
;
729 scom_section
.symbol_ptr_ptr
= & scom_section
.symbol
;
730 scom_symbol
= * bfd_com_section
.symbol
;
731 scom_symbol
.name
= ".scommon";
732 scom_symbol
.section
= & scom_section
;
734 allow_m32rx (enable_m32rx
);
736 gas_cgen_initialize_saved_fixups_array ();
739 #define OPERAND_IS_COND_BIT(operand, indices, index) \
740 ((operand)->hw_type == HW_H_COND \
741 || ((operand)->hw_type == HW_H_PSW) \
742 || ((operand)->hw_type == HW_H_CR \
743 && (indices [index] == 0 || indices [index] == 1)))
745 /* Returns true if an output of instruction 'a' is referenced by an operand
746 of instruction 'b'. If 'check_outputs' is true then b's outputs are
747 checked, otherwise its inputs are examined. */
750 first_writes_to_seconds_operands (m32r_insn
*a
,
752 const int check_outputs
)
754 const CGEN_OPINST
*a_operands
= CGEN_INSN_OPERANDS (a
->insn
);
755 const CGEN_OPINST
*b_ops
= CGEN_INSN_OPERANDS (b
->insn
);
758 if (ignore_parallel_conflicts
)
761 /* If at least one of the instructions takes no operands, then there is
762 nothing to check. There really are instructions without operands,
764 if (a_operands
== NULL
|| b_ops
== NULL
)
767 /* Scan the operand list of 'a' looking for an output operand. */
769 a_operands
->type
!= CGEN_OPINST_END
;
770 a_index
++, a_operands
++)
772 if (a_operands
->type
== CGEN_OPINST_OUTPUT
)
775 const CGEN_OPINST
*b_operands
= b_ops
;
778 The Condition bit 'C' is a shadow of the CBR register (control
779 register 1) and also a shadow of bit 31 of the program status
780 word (control register 0). For now this is handled here, rather
783 if (OPERAND_IS_COND_BIT (a_operands
, a
->indices
, a_index
))
785 /* Scan operand list of 'b' looking for another reference to the
786 condition bit, which goes in the right direction. */
788 b_operands
->type
!= CGEN_OPINST_END
;
789 b_index
++, b_operands
++)
791 if ((b_operands
->type
794 : CGEN_OPINST_INPUT
))
795 && OPERAND_IS_COND_BIT (b_operands
, b
->indices
, b_index
))
801 /* Scan operand list of 'b' looking for an operand that
802 references the same hardware element, and which goes in the
805 b_operands
->type
!= CGEN_OPINST_END
;
806 b_index
++, b_operands
++)
808 if ((b_operands
->type
811 : CGEN_OPINST_INPUT
))
812 && (b_operands
->hw_type
== a_operands
->hw_type
)
813 && (a
->indices
[a_index
] == b
->indices
[b_index
]))
823 /* Returns true if the insn can (potentially) alter the program counter. */
826 writes_to_pc (m32r_insn
*a
)
828 if (CGEN_INSN_ATTR_VALUE (a
->insn
, CGEN_INSN_UNCOND_CTI
)
829 || CGEN_INSN_ATTR_VALUE (a
->insn
, CGEN_INSN_COND_CTI
))
834 /* Return NULL if the two 16 bit insns can be executed in parallel.
835 Otherwise return a pointer to an error message explaining why not. */
838 can_make_parallel (m32r_insn
*a
, m32r_insn
*b
)
843 /* Make sure the instructions are the right length. */
844 if (CGEN_FIELDS_BITSIZE (&a
->fields
) != 16
845 || CGEN_FIELDS_BITSIZE (&b
->fields
) != 16)
848 if (first_writes_to_seconds_operands (a
, b
, TRUE
))
849 return _("instructions write to the same destination register.");
851 a_pipe
= CGEN_INSN_ATTR_VALUE (a
->insn
, CGEN_INSN_PIPE
);
852 b_pipe
= CGEN_INSN_ATTR_VALUE (b
->insn
, CGEN_INSN_PIPE
);
854 /* Make sure that the instructions use the correct execution pipelines. */
855 if (a_pipe
== PIPE_NONE
856 || b_pipe
== PIPE_NONE
)
857 return _("Instructions do not use parallel execution pipelines.");
859 /* Leave this test for last, since it is the only test that can
860 go away if the instructions are swapped, and we want to make
861 sure that any other errors are detected before this happens. */
864 || (b_pipe
== PIPE_O_OS
&& (enable_m32rx
!= 2)))
865 return _("Instructions share the same execution pipeline");
870 /* Force the top bit of the second 16-bit insn to be set. */
873 make_parallel (CGEN_INSN_BYTES_PTR buffer
)
878 buffer
[CGEN_CPU_ENDIAN (gas_cgen_cpu_desc
) == CGEN_ENDIAN_BIG
? 0 : 1]
883 /* Same as make_parallel except buffer contains the bytes in target order. */
886 target_make_parallel (char *buffer
)
888 buffer
[CGEN_CPU_ENDIAN (gas_cgen_cpu_desc
) == CGEN_ENDIAN_BIG
? 0 : 1]
892 /* Assemble two instructions with an explicit parallel operation (||) or
893 sequential operation (->). */
896 assemble_two_insns (char *str1
, char *str2
, int parallel_p
)
902 char save_str2
= *str2
;
904 /* Separate the two instructions. */
907 /* Make sure the two insns begin on a 32 bit boundary.
908 This is also done for the serial case (foo -> bar), relaxing doesn't
909 affect insns written like this.
910 Note that we must always do this as we can't assume anything about
911 whether we're currently on a 32 bit boundary or not. Relaxing may
915 first
.debug_sym_link
= debug_sym_link
;
916 debug_sym_link
= (sym_linkS
*) 0;
918 /* Parse the first instruction. */
919 if (! (first
.insn
= m32r_cgen_assemble_insn
920 (gas_cgen_cpu_desc
, str1
, & first
.fields
, first
.buffer
, & errmsg
)))
927 if (CGEN_FIELDS_BITSIZE (&first
.fields
) != 16)
929 /* xgettext:c-format */
930 as_bad (_("not a 16 bit instruction '%s'"), str1
);
934 else if ((enable_m32rx
== 1)
935 /* FIXME: Need standard macro to perform this test. */
936 && ((CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_MACH
)
938 && !((CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_MACH
)
939 & (1 << MACH_M32RX
)))))
941 /* xgettext:c-format */
942 as_bad (_("instruction '%s' is for the M32R2 only"), str1
);
945 else if ((! enable_special
946 && CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_SPECIAL
))
947 || (! enable_special_m32r
948 && CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_SPECIAL_M32R
)))
950 else if (! enable_special
951 && CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_SPECIAL
))
954 /* xgettext:c-format */
955 as_bad (_("unknown instruction '%s'"), str1
);
958 else if (! enable_m32rx
959 /* FIXME: Need standard macro to perform this test. */
960 && (CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_MACH
)
961 == (1 << MACH_M32RX
)))
963 /* xgettext:c-format */
964 as_bad (_("instruction '%s' is for the M32RX only"), str1
);
968 /* Check to see if this is an allowable parallel insn. */
970 && CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_PIPE
) == PIPE_NONE
)
972 /* xgettext:c-format */
973 as_bad (_("instruction '%s' cannot be executed in parallel."), str1
);
977 /* Restore the original assembly text, just in case it is needed. */
980 /* Save the original string pointer. */
983 /* Advanced past the parsed string. */
986 /* Remember the entire string in case it is needed for error
990 /* Convert the opcode to lower case. */
994 while (ISSPACE (*s2
++))
999 while (ISALNUM (*s2
))
1001 *s2
= TOLOWER (*s2
);
1006 /* Preserve any fixups that have been generated and reset the list
1008 gas_cgen_save_fixups (0);
1010 /* Get the indices of the operands of the instruction. */
1011 /* FIXME: CGEN_FIELDS is already recorded, but relying on that fact
1012 doesn't seem right. Perhaps allow passing fields like we do insn. */
1013 /* FIXME: ALIAS insns do not have operands, so we use this function
1014 to find the equivalent insn and overwrite the value stored in our
1015 structure. We still need the original insn, however, since this
1016 may have certain attributes that are not present in the unaliased
1017 version (eg relaxability). When aliases behave differently this
1018 may have to change. */
1019 first
.orig_insn
= first
.insn
;
1021 CGEN_FIELDS tmp_fields
;
1022 first
.insn
= cgen_lookup_get_insn_operands
1023 (gas_cgen_cpu_desc
, NULL
, INSN_VALUE (first
.buffer
), NULL
, 16,
1024 first
.indices
, &tmp_fields
);
1027 if (first
.insn
== NULL
)
1028 as_fatal (_("internal error: lookup/get operands failed"));
1030 second
.debug_sym_link
= NULL
;
1032 /* Parse the second instruction. */
1033 if (! (second
.insn
= m32r_cgen_assemble_insn
1034 (gas_cgen_cpu_desc
, str1
, & second
.fields
, second
.buffer
, & errmsg
)))
1041 if (CGEN_FIELDS_BITSIZE (&second
.fields
) != 16)
1043 /* xgettext:c-format */
1044 as_bad (_("not a 16 bit instruction '%s'"), str1
);
1048 else if ((enable_m32rx
== 1)
1049 /* FIXME: Need standard macro to perform this test. */
1050 && ((CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_MACH
)
1051 & (1 << MACH_M32R2
))
1052 && !((CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_MACH
)
1053 & (1 << MACH_M32RX
)))))
1055 /* xgettext:c-format */
1056 as_bad (_("instruction '%s' is for the M32R2 only"), str1
);
1059 else if ((! enable_special
1060 && CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_SPECIAL
))
1061 || (! enable_special_m32r
1062 && CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_SPECIAL_M32R
)))
1064 else if (! enable_special
1065 && CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_SPECIAL
))
1068 /* xgettext:c-format */
1069 as_bad (_("unknown instruction '%s'"), str1
);
1072 else if (! enable_m32rx
1073 && CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_MACH
) == (1 << MACH_M32RX
))
1075 /* xgettext:c-format */
1076 as_bad (_("instruction '%s' is for the M32RX only"), str1
);
1080 /* Check to see if this is an allowable parallel insn. */
1082 && CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_PIPE
) == PIPE_NONE
)
1084 /* xgettext:c-format */
1085 as_bad (_("instruction '%s' cannot be executed in parallel."), str1
);
1089 if (parallel_p
&& ! enable_m32rx
)
1091 if (CGEN_INSN_NUM (first
.insn
) != M32R_INSN_NOP
1092 && CGEN_INSN_NUM (second
.insn
) != M32R_INSN_NOP
)
1094 /* xgettext:c-format */
1095 as_bad (_("'%s': only the NOP instruction can be issued in parallel on the m32r"), str2
);
1100 /* Get the indices of the operands of the instruction. */
1101 second
.orig_insn
= second
.insn
;
1103 CGEN_FIELDS tmp_fields
;
1104 second
.insn
= cgen_lookup_get_insn_operands
1105 (gas_cgen_cpu_desc
, NULL
, INSN_VALUE (second
.buffer
), NULL
, 16,
1106 second
.indices
, &tmp_fields
);
1109 if (second
.insn
== NULL
)
1110 as_fatal (_("internal error: lookup/get operands failed"));
1112 /* We assume that if the first instruction writes to a register that is
1113 read by the second instruction it is because the programmer intended
1114 this to happen, (after all they have explicitly requested that these
1115 two instructions be executed in parallel). Although if the global
1116 variable warn_explicit_parallel_conflicts is true then we do generate
1117 a warning message. Similarly we assume that parallel branch and jump
1118 instructions are deliberate and should not produce errors. */
1120 if (parallel_p
&& warn_explicit_parallel_conflicts
)
1122 if (first_writes_to_seconds_operands (&first
, &second
, FALSE
))
1123 /* xgettext:c-format */
1124 as_warn (_("%s: output of 1st instruction is the same as an input to 2nd instruction - is this intentional ?"), str2
);
1126 if (first_writes_to_seconds_operands (&second
, &first
, FALSE
))
1127 /* xgettext:c-format */
1128 as_warn (_("%s: output of 2nd instruction is the same as an input to 1st instruction - is this intentional ?"), str2
);
1132 || (errmsg
= (char *) can_make_parallel (&first
, &second
)) == NULL
)
1134 /* Get the fixups for the first instruction. */
1135 gas_cgen_swap_fixups (0);
1138 expand_debug_syms (first
.debug_sym_link
, 1);
1139 gas_cgen_finish_insn (first
.orig_insn
, first
.buffer
,
1140 CGEN_FIELDS_BITSIZE (&first
.fields
), 0, NULL
);
1142 /* Force the top bit of the second insn to be set. */
1144 make_parallel (second
.buffer
);
1146 /* Get its fixups. */
1147 gas_cgen_restore_fixups (0);
1150 expand_debug_syms (second
.debug_sym_link
, 1);
1151 gas_cgen_finish_insn (second
.orig_insn
, second
.buffer
,
1152 CGEN_FIELDS_BITSIZE (&second
.fields
), 0, NULL
);
1154 /* Try swapping the instructions to see if they work that way. */
1155 else if (can_make_parallel (&second
, &first
) == NULL
)
1157 /* Write out the second instruction first. */
1158 expand_debug_syms (second
.debug_sym_link
, 1);
1159 gas_cgen_finish_insn (second
.orig_insn
, second
.buffer
,
1160 CGEN_FIELDS_BITSIZE (&second
.fields
), 0, NULL
);
1162 /* Force the top bit of the first instruction to be set. */
1163 make_parallel (first
.buffer
);
1165 /* Get the fixups for the first instruction. */
1166 gas_cgen_restore_fixups (0);
1168 /* Write out the first instruction. */
1169 expand_debug_syms (first
.debug_sym_link
, 1);
1170 gas_cgen_finish_insn (first
.orig_insn
, first
.buffer
,
1171 CGEN_FIELDS_BITSIZE (&first
.fields
), 0, NULL
);
1175 as_bad ("'%s': %s", str2
, errmsg
);
1179 if (CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_SPECIAL
)
1180 || CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_SPECIAL
))
1181 m32r_flags
|= E_M32R_HAS_HIDDEN_INST
;
1182 if (CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_SPECIAL_M32R
)
1183 || CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_SPECIAL_M32R
))
1184 m32r_flags
|= E_M32R_HAS_BIT_INST
;
1185 if (CGEN_INSN_ATTR_VALUE (first
.insn
, CGEN_INSN_SPECIAL_FLOAT
)
1186 || CGEN_INSN_ATTR_VALUE (second
.insn
, CGEN_INSN_SPECIAL_FLOAT
))
1187 m32r_flags
|= E_M32R_HAS_FLOAT_INST
;
1189 /* Set these so m32r_fill_insn can use them. */
1191 prev_subseg
= now_subseg
;
1195 md_assemble (char *str
)
1201 /* Initialize GAS's cgen interface for a new instruction. */
1202 gas_cgen_init_parse ();
1204 /* Look for a parallel instruction separator. */
1205 if ((str2
= strstr (str
, "||")) != NULL
)
1207 assemble_two_insns (str
, str2
, 1);
1208 m32r_flags
|= E_M32R_HAS_PARALLEL
;
1212 /* Also look for a sequential instruction separator. */
1213 if ((str2
= strstr (str
, "->")) != NULL
)
1215 assemble_two_insns (str
, str2
, 0);
1219 insn
.debug_sym_link
= debug_sym_link
;
1220 debug_sym_link
= (sym_linkS
*) 0;
1222 insn
.insn
= m32r_cgen_assemble_insn
1223 (gas_cgen_cpu_desc
, str
, &insn
.fields
, insn
.buffer
, & errmsg
);
1232 if ((enable_m32rx
== 1)
1233 /* FIXME: Need standard macro to perform this test. */
1234 && ((CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_MACH
)
1235 & (1 << MACH_M32R2
))
1236 && !((CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_MACH
)
1237 & (1 << MACH_M32RX
)))))
1239 /* xgettext:c-format */
1240 as_bad (_("instruction '%s' is for the M32R2 only"), str
);
1243 else if ((! enable_special
1244 && CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_SPECIAL
))
1245 || (! enable_special_m32r
1246 && CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_SPECIAL_M32R
)))
1248 if (! enable_special
1249 && CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_SPECIAL
))
1252 /* xgettext:c-format */
1253 as_bad (_("unknown instruction '%s'"), str
);
1256 else if (! enable_m32rx
1257 && CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_MACH
) == (1 << MACH_M32RX
))
1259 /* xgettext:c-format */
1260 as_bad (_("instruction '%s' is for the M32RX only"), str
);
1264 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_SPECIAL
))
1265 m32r_flags
|= E_M32R_HAS_HIDDEN_INST
;
1266 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_SPECIAL_M32R
))
1267 m32r_flags
|= E_M32R_HAS_BIT_INST
;
1268 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_SPECIAL_FLOAT
))
1269 m32r_flags
|= E_M32R_HAS_FLOAT_INST
;
1271 if (CGEN_INSN_BITSIZE (insn
.insn
) == 32)
1273 /* 32 bit insns must live on 32 bit boundaries. */
1274 if (prev_insn
.insn
|| seen_relaxable_p
)
1276 /* ??? If calling fill_insn too many times turns us into a memory
1277 pig, can we call a fn to assemble a nop instead of
1278 !seen_relaxable_p? */
1282 expand_debug_syms (insn
.debug_sym_link
, 2);
1284 /* Doesn't really matter what we pass for RELAX_P here. */
1285 gas_cgen_finish_insn (insn
.insn
, insn
.buffer
,
1286 CGEN_FIELDS_BITSIZE (&insn
.fields
), 1, NULL
);
1290 int on_32bit_boundary_p
;
1293 if (CGEN_INSN_BITSIZE (insn
.insn
) != 16)
1296 insn
.orig_insn
= insn
.insn
;
1298 /* If the previous insn was relaxable, then it may be expanded
1299 to fill the current 16 bit slot. Emit a NOP here to occupy
1300 this slot, so that we can start at optimizing at a 32 bit
1302 if (prev_insn
.insn
&& seen_relaxable_p
&& optimize
)
1307 /* Get the indices of the operands of the instruction.
1308 FIXME: See assemble_parallel for notes on orig_insn. */
1310 CGEN_FIELDS tmp_fields
;
1311 insn
.insn
= cgen_lookup_get_insn_operands
1312 (gas_cgen_cpu_desc
, NULL
, INSN_VALUE (insn
.buffer
), NULL
,
1313 16, insn
.indices
, &tmp_fields
);
1316 if (insn
.insn
== NULL
)
1317 as_fatal (_("internal error: lookup/get operands failed"));
1320 /* Compute whether we're on a 32 bit boundary or not.
1321 prev_insn.insn is NULL when we're on a 32 bit boundary. */
1322 on_32bit_boundary_p
= prev_insn
.insn
== NULL
;
1324 /* Change a frag to, if each insn to swap is in a different frag.
1325 It must keep only one instruction in a frag. */
1326 if (parallel() && on_32bit_boundary_p
)
1328 frag_wane (frag_now
);
1332 /* Look to see if this instruction can be combined with the
1333 previous instruction to make one, parallel, 32 bit instruction.
1334 If the previous instruction (potentially) changed the flow of
1335 program control, then it cannot be combined with the current
1336 instruction. If the current instruction is relaxable, then it
1337 might be replaced with a longer version, so we cannot combine it.
1338 Also if the output of the previous instruction is used as an
1339 input to the current instruction then it cannot be combined.
1340 Otherwise call can_make_parallel() with both orderings of the
1341 instructions to see if they can be combined. */
1342 if (! on_32bit_boundary_p
1344 && CGEN_INSN_ATTR_VALUE (insn
.orig_insn
, CGEN_INSN_RELAXABLE
) == 0
1345 && ! writes_to_pc (&prev_insn
)
1346 && ! first_writes_to_seconds_operands (&prev_insn
, &insn
, FALSE
))
1348 if (can_make_parallel (&prev_insn
, &insn
) == NULL
)
1349 make_parallel (insn
.buffer
);
1350 else if (can_make_parallel (&insn
, &prev_insn
) == NULL
)
1354 expand_debug_syms (insn
.debug_sym_link
, 1);
1360 /* Ensure each pair of 16 bit insns is in the same frag. */
1363 gas_cgen_finish_insn (insn
.orig_insn
, insn
.buffer
,
1364 CGEN_FIELDS_BITSIZE (&insn
.fields
),
1365 1 /* relax_p */, &fi
);
1366 insn
.addr
= fi
.addr
;
1367 insn
.frag
= fi
.frag
;
1368 insn
.num_fixups
= fi
.num_fixups
;
1369 for (i
= 0; i
< fi
.num_fixups
; ++i
)
1370 insn
.fixups
[i
] = fi
.fixups
[i
];
1377 #define SWAP_BYTES(a,b) tmp = a; a = b; b = tmp
1379 /* Swap the two insns */
1380 SWAP_BYTES (prev_insn
.addr
[0], insn
.addr
[0]);
1381 SWAP_BYTES (prev_insn
.addr
[1], insn
.addr
[1]);
1383 target_make_parallel (insn
.addr
);
1385 /* Swap any relaxable frags recorded for the two insns. */
1386 /* FIXME: Clarify. relaxation precludes parallel insns */
1387 if (prev_insn
.frag
->fr_opcode
== prev_insn
.addr
)
1388 prev_insn
.frag
->fr_opcode
= insn
.addr
;
1389 else if (insn
.frag
->fr_opcode
== insn
.addr
)
1390 insn
.frag
->fr_opcode
= prev_insn
.addr
;
1392 /* Change a frag to, if each insn is in a different frag.
1393 It must keep only one instruction in a frag. */
1394 if (prev_insn
.frag
!= insn
.frag
)
1396 for (i
= 0; i
< prev_insn
.num_fixups
; ++i
)
1397 prev_insn
.fixups
[i
]->fx_frag
= insn
.frag
;
1398 for (i
= 0; i
< insn
.num_fixups
; ++i
)
1399 insn
.fixups
[i
]->fx_frag
= prev_insn
.frag
;
1403 /* Update the addresses in any fixups.
1404 Note that we don't have to handle the case where each insn is in
1405 a different frag as we ensure they're in the same frag above. */
1406 for (i
= 0; i
< prev_insn
.num_fixups
; ++i
)
1407 prev_insn
.fixups
[i
]->fx_where
+= 2;
1408 for (i
= 0; i
< insn
.num_fixups
; ++i
)
1409 insn
.fixups
[i
]->fx_where
-= 2;
1413 /* Keep track of whether we've seen a pair of 16 bit insns.
1414 prev_insn.insn is NULL when we're on a 32 bit boundary. */
1415 if (on_32bit_boundary_p
)
1418 prev_insn
.insn
= NULL
;
1420 /* If the insn needs the following one to be on a 32 bit boundary
1421 (e.g. subroutine calls), fill this insn's slot. */
1422 if (on_32bit_boundary_p
1423 && CGEN_INSN_ATTR_VALUE (insn
.orig_insn
, CGEN_INSN_FILL_SLOT
) != 0)
1426 /* If this is a relaxable insn (can be replaced with a larger version)
1427 mark the fact so that we can emit an alignment directive for a
1428 following 32 bit insn if we see one. */
1429 if (CGEN_INSN_ATTR_VALUE (insn
.orig_insn
, CGEN_INSN_RELAXABLE
) != 0)
1430 seen_relaxable_p
= 1;
1433 /* Set these so m32r_fill_insn can use them. */
1435 prev_subseg
= now_subseg
;
1438 /* The syntax in the manual says constants begin with '#'.
1439 We just ignore it. */
1442 md_operand (expressionS
*expressionP
)
1444 if (*input_line_pointer
== '#')
1446 input_line_pointer
++;
1447 expression (expressionP
);
1452 md_section_align (segT segment
, valueT size
)
1454 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1456 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1460 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1465 /* .scomm pseudo-op handler.
1467 This is a new pseudo-op to handle putting objects in .scommon.
1468 By doing this the linker won't need to do any work,
1469 and more importantly it removes the implicit -G arg necessary to
1470 correctly link the object file. */
1473 m32r_scomm (int ignore ATTRIBUTE_UNUSED
)
1483 name
= input_line_pointer
;
1484 c
= get_symbol_end ();
1486 /* Just after name is now '\0'. */
1487 p
= input_line_pointer
;
1490 if (*input_line_pointer
!= ',')
1492 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1493 ignore_rest_of_line ();
1498 input_line_pointer
++;
1499 if ((size
= get_absolute_expression ()) < 0)
1501 /* xgettext:c-format */
1502 as_warn (_(".SCOMMon length (%ld.) <0! Ignored."), (long) size
);
1503 ignore_rest_of_line ();
1507 /* The third argument to .scomm is the alignment. */
1508 if (*input_line_pointer
!= ',')
1512 ++input_line_pointer
;
1513 align
= get_absolute_expression ();
1516 as_warn (_("ignoring bad alignment"));
1521 /* Convert to a power of 2 alignment. */
1524 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
)
1528 as_bad (_("Common alignment not a power of 2"));
1529 ignore_rest_of_line ();
1537 symbolP
= symbol_find_or_make (name
);
1540 if (S_IS_DEFINED (symbolP
))
1542 /* xgettext:c-format */
1543 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1544 S_GET_NAME (symbolP
));
1545 ignore_rest_of_line ();
1549 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1551 /* xgettext:c-format */
1552 as_bad (_("Length of .scomm \"%s\" is already %ld. Not changed to %ld."),
1553 S_GET_NAME (symbolP
),
1554 (long) S_GET_VALUE (symbolP
),
1557 ignore_rest_of_line ();
1561 if (symbol_get_obj (symbolP
)->local
)
1563 segT old_sec
= now_seg
;
1564 int old_subsec
= now_subseg
;
1567 record_alignment (sbss_section
, align2
);
1568 subseg_set (sbss_section
, 0);
1571 frag_align (align2
, 0, 0);
1573 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
1574 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1576 symbol_set_frag (symbolP
, frag_now
);
1578 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1581 S_SET_SIZE (symbolP
, size
);
1582 S_SET_SEGMENT (symbolP
, sbss_section
);
1583 S_CLEAR_EXTERNAL (symbolP
);
1584 subseg_set (old_sec
, old_subsec
);
1588 S_SET_VALUE (symbolP
, (valueT
) size
);
1589 S_SET_ALIGN (symbolP
, align2
);
1590 S_SET_EXTERNAL (symbolP
);
1591 S_SET_SEGMENT (symbolP
, &scom_section
);
1594 demand_empty_rest_of_line ();
1597 /* The target specific pseudo-ops which we support. */
1598 const pseudo_typeS md_pseudo_table
[] =
1600 { "word", cons
, 4 },
1601 { "fillinsn", fill_insn
, 0 },
1602 { "scomm", m32r_scomm
, 0 },
1603 { "debugsym", debug_sym
, 0 },
1604 { "m32r", allow_m32rx
, 0 },
1605 { "m32rx", allow_m32rx
, 1 },
1606 { "m32r2", allow_m32rx
, 2 },
1607 { "little", little
, 1 },
1608 { "big", little
, 0 },
1612 /* Interface to relax_segment. */
1614 /* FIXME: Build table by hand, get it working, then machine generate. */
1616 const relax_typeS md_relax_table
[] =
1619 1) most positive reach of this state,
1620 2) most negative reach of this state,
1621 3) how many bytes this mode will add to the size of the current frag
1622 4) which index into the table to try if we can't fit into this one. */
1624 /* The first entry must be unused because an `rlx_more' value of zero ends
1628 /* The displacement used by GAS is from the end of the 2 byte insn,
1629 so we subtract 2 from the following. */
1630 /* 16 bit insn, 8 bit disp -> 10 bit range.
1631 This doesn't handle a branch in the right slot at the border:
1632 the "& -4" isn't taken into account. It's not important enough to
1633 complicate things over it, so we subtract an extra 2 (or + 2 in -ve
1635 {511 - 2 - 2, -512 - 2 + 2, 0, 2 },
1636 /* 32 bit insn, 24 bit disp -> 26 bit range. */
1637 {0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 },
1638 /* Same thing, but with leading nop for alignment. */
1639 {0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 }
1643 m32r_relax_frag (segT segment
, fragS
*fragP
, long stretch
)
1645 /* Address of branch insn. */
1646 long address
= fragP
->fr_address
+ fragP
->fr_fix
- 2;
1649 /* Keep 32 bit insns aligned on 32 bit boundaries. */
1650 if (fragP
->fr_subtype
== 2)
1652 if ((address
& 3) != 0)
1654 fragP
->fr_subtype
= 3;
1658 else if (fragP
->fr_subtype
== 3)
1660 if ((address
& 3) == 0)
1662 fragP
->fr_subtype
= 2;
1668 growth
= relax_frag (segment
, fragP
, stretch
);
1670 /* Long jump on odd halfword boundary? */
1671 if (fragP
->fr_subtype
== 2 && (address
& 3) != 0)
1673 fragP
->fr_subtype
= 3;
1681 /* Return an initial guess of the length by which a fragment must grow to
1682 hold a branch to reach its destination.
1683 Also updates fr_type/fr_subtype as necessary.
1685 Called just before doing relaxation.
1686 Any symbol that is now undefined will not become defined.
1687 The guess for fr_var is ACTUALLY the growth beyond fr_fix.
1688 Whatever we do to grow fr_fix or fr_var contributes to our returned value.
1689 Although it may not be explicit in the frag, pretend fr_var starts
1693 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
1695 /* The only thing we have to handle here are symbols outside of the
1696 current segment. They may be undefined or in a different segment in
1697 which case linker scripts may place them anywhere.
1698 However, we can't finish the fragment here and emit the reloc as insn
1699 alignment requirements may move the insn about. */
1700 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
1701 || S_IS_EXTERNAL (fragP
->fr_symbol
)
1702 || S_IS_WEAK (fragP
->fr_symbol
))
1704 /* The symbol is undefined in this segment.
1705 Change the relaxation subtype to the max allowable and leave
1706 all further handling to md_convert_frag. */
1707 fragP
->fr_subtype
= 2;
1710 const CGEN_INSN
*insn
;
1713 /* Update the recorded insn.
1714 Fortunately we don't have to look very far.
1715 FIXME: Change this to record in the instruction the next higher
1716 relaxable insn to use. */
1717 for (i
= 0, insn
= fragP
->fr_cgen
.insn
; i
< 4; i
++, insn
++)
1719 if ((strcmp (CGEN_INSN_MNEMONIC (insn
),
1720 CGEN_INSN_MNEMONIC (fragP
->fr_cgen
.insn
))
1722 && CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAXED
))
1728 fragP
->fr_cgen
.insn
= insn
;
1733 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
1736 /* *FRAGP has been relaxed to its final size, and now needs to have
1737 the bytes inside it modified to conform to the new size.
1739 Called after relaxation is finished.
1740 fragP->fr_type == rs_machine_dependent.
1741 fragP->fr_subtype is the subtype of what the address relaxed to. */
1744 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1755 opcode
= fragP
->fr_opcode
;
1757 /* Address opcode resides at in file space. */
1758 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 2;
1760 switch (fragP
->fr_subtype
)
1764 displacement
= &opcode
[1];
1769 displacement
= &opcode
[1];
1772 opcode
[2] = opcode
[0] | 0x80;
1773 md_number_to_chars (opcode
, PAR_NOP_INSN
, 2);
1774 opcode_address
+= 2;
1776 displacement
= &opcode
[3];
1782 if (S_GET_SEGMENT (fragP
->fr_symbol
) != sec
1783 || S_IS_EXTERNAL (fragP
->fr_symbol
)
1784 || S_IS_WEAK (fragP
->fr_symbol
))
1786 /* Symbol must be resolved by linker. */
1787 if (fragP
->fr_offset
& 3)
1788 as_warn (_("Addend to unresolved symbol not on word boundary."));
1789 #ifdef USE_M32R_OLD_RELOC
1790 addend
= fragP
->fr_offset
>> 2; /* Old M32R used USE_REL. */
1797 /* Address we want to reach in file space. */
1798 target_address
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1799 addend
= (target_address
- (opcode_address
& -4)) >> 2;
1802 /* Create a relocation for symbols that must be resolved by the linker.
1803 Otherwise output the completed insn. */
1805 if (S_GET_SEGMENT (fragP
->fr_symbol
) != sec
1806 || S_IS_EXTERNAL (fragP
->fr_symbol
)
1807 || S_IS_WEAK (fragP
->fr_symbol
))
1811 assert (fragP
->fr_subtype
!= 1);
1812 assert (fragP
->fr_cgen
.insn
!= 0);
1814 fixP
= gas_cgen_record_fixup (fragP
,
1815 /* Offset of branch insn in frag. */
1816 fragP
->fr_fix
+ extension
- 4,
1817 fragP
->fr_cgen
.insn
,
1819 /* FIXME: quick hack. */
1820 cgen_operand_lookup_by_num (gas_cgen_cpu_desc
,
1821 M32R_OPERAND_DISP24
),
1822 fragP
->fr_cgen
.opinfo
,
1823 fragP
->fr_symbol
, fragP
->fr_offset
);
1824 if (fragP
->fr_cgen
.opinfo
)
1825 fixP
->fx_r_type
= fragP
->fr_cgen
.opinfo
;
1828 #define SIZE_FROM_RELAX_STATE(n) ((n) == 1 ? 1 : 3)
1830 md_number_to_chars (displacement
, (valueT
) addend
,
1831 SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
));
1833 fragP
->fr_fix
+= extension
;
1836 /* Functions concerning relocs. */
1838 /* The location from which a PC relative jump should be calculated,
1839 given a PC relative reloc. */
1842 md_pcrel_from_section (fixS
*fixP
, segT sec
)
1844 if (fixP
->fx_addsy
!= (symbolS
*) NULL
1845 && (! S_IS_DEFINED (fixP
->fx_addsy
)
1846 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
1847 || S_IS_EXTERNAL (fixP
->fx_addsy
)
1848 || S_IS_WEAK (fixP
->fx_addsy
)))
1850 if (S_GET_SEGMENT (fixP
->fx_addsy
) != sec
1851 && S_IS_DEFINED (fixP
->fx_addsy
)
1852 && ! S_IS_EXTERNAL (fixP
->fx_addsy
)
1853 && ! S_IS_WEAK (fixP
->fx_addsy
))
1854 return fixP
->fx_offset
;
1856 /* The symbol is undefined (or is defined but not in this section).
1857 Let the linker figure it out. */
1861 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
) & -4L;
1864 /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP.
1865 Returns BFD_RELOC_NONE if no reloc type can be found.
1866 *FIXP may be modified if desired. */
1868 bfd_reloc_code_real_type
1869 md_cgen_lookup_reloc (const CGEN_INSN
*insn ATTRIBUTE_UNUSED
,
1870 const CGEN_OPERAND
*operand
,
1873 switch (operand
->type
)
1875 case M32R_OPERAND_DISP8
: return BFD_RELOC_M32R_10_PCREL
;
1876 case M32R_OPERAND_DISP16
: return BFD_RELOC_M32R_18_PCREL
;
1877 case M32R_OPERAND_DISP24
: return BFD_RELOC_M32R_26_PCREL
;
1878 case M32R_OPERAND_UIMM24
: return BFD_RELOC_M32R_24
;
1879 case M32R_OPERAND_HI16
:
1880 case M32R_OPERAND_SLO16
:
1881 case M32R_OPERAND_ULO16
:
1882 /* If low/high/shigh/sda was used, it is recorded in `opinfo'. */
1883 if (fixP
->fx_cgen
.opinfo
!= 0)
1884 return fixP
->fx_cgen
.opinfo
;
1887 /* Avoid -Wall warning. */
1890 return BFD_RELOC_NONE
;
1893 /* Record a HI16 reloc for later matching with its LO16 cousin. */
1896 m32r_record_hi16 (int reloc_type
,
1898 segT seg ATTRIBUTE_UNUSED
)
1900 struct m32r_hi_fixup
*hi_fixup
;
1902 assert (reloc_type
== BFD_RELOC_M32R_HI16_SLO
1903 || reloc_type
== BFD_RELOC_M32R_HI16_ULO
);
1905 hi_fixup
= xmalloc (sizeof (* hi_fixup
));
1906 hi_fixup
->fixp
= fixP
;
1907 hi_fixup
->seg
= now_seg
;
1908 hi_fixup
->next
= m32r_hi_fixup_list
;
1910 m32r_hi_fixup_list
= hi_fixup
;
1913 /* Called while parsing an instruction to create a fixup.
1914 We need to check for HI16 relocs and queue them up for later sorting. */
1917 m32r_cgen_record_fixup_exp (fragS
*frag
,
1919 const CGEN_INSN
*insn
,
1921 const CGEN_OPERAND
*operand
,
1926 bfd_reloc_code_real_type r_type
= BFD_RELOC_UNUSED
;
1928 if (m32r_check_fixup (exp
, &r_type
))
1929 as_bad (_("Invalid PIC expression."));
1931 fixP
= gas_cgen_record_fixup_exp (frag
, where
, insn
, length
,
1932 operand
, opinfo
, exp
);
1934 switch (operand
->type
)
1936 case M32R_OPERAND_HI16
:
1937 /* If low/high/shigh/sda was used, it is recorded in `opinfo'. */
1938 if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_SLO
1939 || fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_ULO
)
1940 m32r_record_hi16 (fixP
->fx_cgen
.opinfo
, fixP
, now_seg
);
1944 /* Avoid -Wall warning. */
1950 case BFD_RELOC_UNUSED
:
1954 case BFD_RELOC_M32R_GOTPC24
:
1955 if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_SLO
)
1956 r_type
= BFD_RELOC_M32R_GOTPC_HI_SLO
;
1957 else if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_ULO
)
1958 r_type
= BFD_RELOC_M32R_GOTPC_HI_ULO
;
1959 else if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_LO16
)
1960 r_type
= BFD_RELOC_M32R_GOTPC_LO
;
1963 case BFD_RELOC_M32R_GOT24
:
1964 if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_SLO
)
1965 r_type
= BFD_RELOC_M32R_GOT16_HI_SLO
;
1966 else if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_ULO
)
1967 r_type
= BFD_RELOC_M32R_GOT16_HI_ULO
;
1968 else if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_LO16
)
1969 r_type
= BFD_RELOC_M32R_GOT16_LO
;
1972 case BFD_RELOC_M32R_GOTOFF
:
1973 if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_SLO
)
1974 r_type
= BFD_RELOC_M32R_GOTOFF_HI_SLO
;
1975 else if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_HI16_ULO
)
1976 r_type
= BFD_RELOC_M32R_GOTOFF_HI_ULO
;
1977 else if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_M32R_LO16
)
1978 r_type
= BFD_RELOC_M32R_GOTOFF_LO
;
1981 case BFD_RELOC_M32R_26_PLTREL
:
1982 as_bad (_("Invalid PIC expression."));
1986 fixP
->fx_r_type
= r_type
;
1991 /* Return BFD reloc type from opinfo field in a fixS.
1992 It's tricky using fx_r_type in m32r_frob_file because the values
1993 are BFD_RELOC_UNUSED + operand number. */
1994 #define FX_OPINFO_R_TYPE(f) ((f)->fx_cgen.opinfo)
1996 /* Sort any unmatched HI16 relocs so that they immediately precede
1997 the corresponding LO16 reloc. This is called before md_apply_fix and
2001 m32r_frob_file (void)
2003 struct m32r_hi_fixup
*l
;
2005 for (l
= m32r_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
2007 segment_info_type
*seginfo
;
2010 assert (FX_OPINFO_R_TYPE (l
->fixp
) == BFD_RELOC_M32R_HI16_SLO
2011 || FX_OPINFO_R_TYPE (l
->fixp
) == BFD_RELOC_M32R_HI16_ULO
);
2013 /* Check quickly whether the next fixup happens to be a matching low. */
2014 if (l
->fixp
->fx_next
!= NULL
2015 && FX_OPINFO_R_TYPE (l
->fixp
->fx_next
) == BFD_RELOC_M32R_LO16
2016 && l
->fixp
->fx_addsy
== l
->fixp
->fx_next
->fx_addsy
2017 && l
->fixp
->fx_offset
== l
->fixp
->fx_next
->fx_offset
)
2020 /* Look through the fixups for this segment for a matching `low'.
2021 When we find one, move the high/shigh just in front of it. We do
2022 this in two passes. In the first pass, we try to find a
2023 unique `low'. In the second pass, we permit multiple high's
2024 relocs for a single `low'. */
2025 seginfo
= seg_info (l
->seg
);
2026 for (pass
= 0; pass
< 2; pass
++)
2032 for (f
= seginfo
->fix_root
; f
!= NULL
; f
= f
->fx_next
)
2034 /* Check whether this is a `low' fixup which matches l->fixp. */
2035 if (FX_OPINFO_R_TYPE (f
) == BFD_RELOC_M32R_LO16
2036 && f
->fx_addsy
== l
->fixp
->fx_addsy
2037 && f
->fx_offset
== l
->fixp
->fx_offset
2040 || (FX_OPINFO_R_TYPE (prev
) != BFD_RELOC_M32R_HI16_SLO
2041 && FX_OPINFO_R_TYPE (prev
) != BFD_RELOC_M32R_HI16_ULO
)
2042 || prev
->fx_addsy
!= f
->fx_addsy
2043 || prev
->fx_offset
!= f
->fx_offset
))
2047 /* Move l->fixp before f. */
2048 for (pf
= &seginfo
->fix_root
;
2050 pf
= & (*pf
)->fx_next
)
2051 assert (*pf
!= NULL
);
2053 *pf
= l
->fixp
->fx_next
;
2055 l
->fixp
->fx_next
= f
;
2057 seginfo
->fix_root
= l
->fixp
;
2059 prev
->fx_next
= l
->fixp
;
2071 && warn_unmatched_high
)
2072 as_warn_where (l
->fixp
->fx_file
, l
->fixp
->fx_line
,
2073 _("Unmatched high/shigh reloc"));
2078 /* See whether we need to force a relocation into the output file.
2079 This is used to force out switch and PC relative relocations when
2083 m32r_force_relocation (fixS
*fix
)
2085 if (generic_force_reloc (fix
))
2091 return fix
->fx_pcrel
;
2094 /* Write a value out to the object file, using the appropriate endianness. */
2097 md_number_to_chars (char *buf
, valueT val
, int n
)
2099 if (target_big_endian
)
2100 number_to_chars_bigendian (buf
, val
, n
);
2102 number_to_chars_littleendian (buf
, val
, n
);
2105 /* Turn a string in input_line_pointer into a floating point constant
2106 of type TYPE, and store the appropriate bytes in *LITP. The number
2107 of LITTLENUMS emitted is stored in *SIZEP. An error message is
2108 returned, or NULL on OK. */
2110 /* Equal to MAX_PRECISION in atof-ieee.c. */
2111 #define MAX_LITTLENUMS 6
2114 md_atof (int type
, char *litP
, int *sizeP
)
2118 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2137 /* FIXME: Some targets allow other format chars for bigger sizes
2142 return _("Bad call to md_atof()");
2145 t
= atof_ieee (input_line_pointer
, type
, words
);
2147 input_line_pointer
= t
;
2148 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2150 if (target_big_endian
)
2152 for (i
= 0; i
< prec
; i
++)
2154 md_number_to_chars (litP
, (valueT
) words
[i
],
2155 sizeof (LITTLENUM_TYPE
));
2156 litP
+= sizeof (LITTLENUM_TYPE
);
2161 for (i
= prec
- 1; i
>= 0; i
--)
2163 md_number_to_chars (litP
, (valueT
) words
[i
],
2164 sizeof (LITTLENUM_TYPE
));
2165 litP
+= sizeof (LITTLENUM_TYPE
);
2173 m32r_elf_section_change_hook (void)
2175 /* If we have reached the end of a section and we have just emitted a
2176 16 bit insn, then emit a nop to make sure that the section ends on
2177 a 32 bit boundary. */
2179 if (prev_insn
.insn
|| seen_relaxable_p
)
2180 (void) m32r_fill_insn (0);
2183 /* Return true if can adjust the reloc to be relative to its section
2184 (such as .data) instead of relative to some symbol. */
2187 m32r_fix_adjustable (fixS
*fixP
)
2189 bfd_reloc_code_real_type reloc_type
;
2191 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2193 const CGEN_INSN
*insn
= NULL
;
2194 int opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2195 const CGEN_OPERAND
*operand
=
2196 cgen_operand_lookup_by_num(gas_cgen_cpu_desc
, opindex
);
2198 reloc_type
= md_cgen_lookup_reloc (insn
, operand
, fixP
);
2201 reloc_type
= fixP
->fx_r_type
;
2203 if (fixP
->fx_addsy
== NULL
)
2206 /* Prevent all adjustments to global symbols. */
2207 if (S_IS_EXTERNAL (fixP
->fx_addsy
))
2209 if (S_IS_WEAK (fixP
->fx_addsy
))
2213 && (reloc_type
== BFD_RELOC_M32R_24
2214 || reloc_type
== BFD_RELOC_M32R_26_PCREL
2215 || reloc_type
== BFD_RELOC_M32R_HI16_SLO
2216 || reloc_type
== BFD_RELOC_M32R_HI16_ULO
2217 || reloc_type
== BFD_RELOC_M32R_LO16
))
2220 if (reloc_type
== BFD_RELOC_M32R_GOT24
2221 || reloc_type
== BFD_RELOC_M32R_26_PLTREL
2222 || reloc_type
== BFD_RELOC_M32R_GOTPC_HI_SLO
2223 || reloc_type
== BFD_RELOC_M32R_GOTPC_HI_ULO
2224 || reloc_type
== BFD_RELOC_M32R_GOTPC_LO
2225 || reloc_type
== BFD_RELOC_M32R_GOT16_HI_SLO
2226 || reloc_type
== BFD_RELOC_M32R_GOT16_HI_ULO
2227 || reloc_type
== BFD_RELOC_M32R_GOT16_LO
)
2230 /* We need the symbol name for the VTABLE entries. */
2231 if (reloc_type
== BFD_RELOC_VTABLE_INHERIT
2232 || reloc_type
== BFD_RELOC_VTABLE_ENTRY
)
2239 m32r_elf_final_processing (void)
2242 m32r_flags
|= E_M32R_HAS_PARALLEL
;
2243 elf_elfheader (stdoutput
)->e_flags
|= m32r_flags
;
2246 /* Translate internal representation of relocation info to BFD target
2250 tc_gen_reloc (asection
* section
, fixS
* fixP
)
2253 bfd_reloc_code_real_type code
;
2255 reloc
= xmalloc (sizeof (* reloc
));
2257 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2258 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
2259 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2263 if (fixP
->fx_r_type
== BFD_RELOC_32
)
2264 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2265 else if (fixP
->fx_r_type
== BFD_RELOC_16
)
2267 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
2268 bfd_set_error (bfd_error_bad_value
);
2272 code
= fixP
->fx_r_type
;
2276 printf("%s",bfd_get_reloc_code_name(code
));
2280 case BFD_RELOC_M32R_26_PCREL
:
2281 code
= BFD_RELOC_M32R_26_PLTREL
;
2284 case BFD_RELOC_M32R_24
:
2285 if (fixP
->fx_addsy
!= NULL
2286 && strcmp (S_GET_NAME (fixP
->fx_addsy
), GOT_NAME
) == 0)
2287 code
= BFD_RELOC_M32R_GOTPC24
;
2289 code
= BFD_RELOC_M32R_GOT24
;
2292 case BFD_RELOC_M32R_HI16_ULO
:
2293 if (fixP
->fx_addsy
!= NULL
2294 && strcmp (S_GET_NAME (fixP
->fx_addsy
), GOT_NAME
) == 0)
2295 code
= BFD_RELOC_M32R_GOTPC_HI_ULO
;
2297 code
= BFD_RELOC_M32R_GOT16_HI_ULO
;
2300 case BFD_RELOC_M32R_HI16_SLO
:
2301 if (fixP
->fx_addsy
!= NULL
2302 && strcmp (S_GET_NAME (fixP
->fx_addsy
), GOT_NAME
) == 0)
2303 code
= BFD_RELOC_M32R_GOTPC_HI_SLO
;
2305 code
= BFD_RELOC_M32R_GOT16_HI_SLO
;
2308 case BFD_RELOC_M32R_LO16
:
2309 if (fixP
->fx_addsy
!= NULL
2310 && strcmp (S_GET_NAME (fixP
->fx_addsy
), GOT_NAME
) == 0)
2311 code
= BFD_RELOC_M32R_GOTPC_LO
;
2313 code
= BFD_RELOC_M32R_GOT16_LO
;
2320 printf(" => %s",bfd_get_reloc_code_name(code
));
2324 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2327 printf(" => %s\n",reloc
->howto
->name
);
2330 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2332 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2333 _("internal error: can't export reloc type %d (`%s')"),
2334 fixP
->fx_r_type
, bfd_get_reloc_code_name (code
));
2338 /* Use fx_offset for these cases. */
2339 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2340 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2341 || fixP
->fx_r_type
== BFD_RELOC_32_PCREL
)
2342 reloc
->addend
= fixP
->fx_offset
;
2344 && code
!= BFD_RELOC_M32R_26_PLTREL
)
2346 && fixP
->fx_addsy
!= NULL
2347 && (S_GET_SEGMENT(fixP
->fx_addsy
) != section
)
2348 && S_IS_DEFINED (fixP
->fx_addsy
)
2349 && ! S_IS_EXTERNAL(fixP
->fx_addsy
)
2350 && ! S_IS_WEAK(fixP
->fx_addsy
))
2351 /* Already used fx_offset in the opcode field itseld. */
2352 reloc
->addend
= fixP
->fx_offset
;
2354 reloc
->addend
= fixP
->fx_addnumber
;
2359 inline static char *
2360 m32r_end_of_match (char *cont
, char *what
)
2362 int len
= strlen (what
);
2364 if (strncasecmp (cont
, what
, strlen (what
)) == 0
2365 && ! is_part_of_name (cont
[len
]))
2372 m32r_parse_name (char const *name
,
2374 enum expr_mode mode
,
2377 char *next
= input_line_pointer
;
2383 exprP
->X_op_symbol
= NULL
;
2384 exprP
->X_md
= BFD_RELOC_UNUSED
;
2386 if (strcmp (name
, GOT_NAME
) == 0)
2389 GOT_symbol
= symbol_find_or_make (name
);
2391 exprP
->X_add_symbol
= GOT_symbol
;
2393 /* If we have an absolute symbol or a
2394 reg, then we know its value now. */
2395 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
2396 if (mode
!= expr_defer
&& segment
== absolute_section
)
2398 exprP
->X_op
= O_constant
;
2399 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
2400 exprP
->X_add_symbol
= NULL
;
2402 else if (mode
!= expr_defer
&& segment
== reg_section
)
2404 exprP
->X_op
= O_register
;
2405 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
2406 exprP
->X_add_symbol
= NULL
;
2410 exprP
->X_op
= O_symbol
;
2411 exprP
->X_add_number
= 0;
2417 exprP
->X_add_symbol
= symbol_find_or_make (name
);
2419 if (*nextcharP
!= '@')
2421 else if ((next_end
= m32r_end_of_match (next
+ 1, "GOTOFF")))
2423 reloc_type
= BFD_RELOC_M32R_GOTOFF
;
2424 op_type
= O_PIC_reloc
;
2426 else if ((next_end
= m32r_end_of_match (next
+ 1, "GOT")))
2428 reloc_type
= BFD_RELOC_M32R_GOT24
;
2429 op_type
= O_PIC_reloc
;
2431 else if ((next_end
= m32r_end_of_match (next
+ 1, "PLT")))
2433 reloc_type
= BFD_RELOC_M32R_26_PLTREL
;
2434 op_type
= O_PIC_reloc
;
2439 *input_line_pointer
= *nextcharP
;
2440 input_line_pointer
= next_end
;
2441 *nextcharP
= *input_line_pointer
;
2442 *input_line_pointer
= '\0';
2444 exprP
->X_op
= op_type
;
2445 exprP
->X_add_number
= 0;
2446 exprP
->X_md
= reloc_type
;
2452 m32r_cgen_parse_fix_exp(int opinfo
, expressionS
*exp
)
2454 if (exp
->X_op
== O_PIC_reloc
2455 && exp
->X_md
== BFD_RELOC_M32R_26_PLTREL
)
2457 exp
->X_op
= O_symbol
;