1 /* tc-xtensa.c -- Assemble Xtensa instructions.
2 Copyright 2003 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 MA 02111-1307, USA. */
24 #include "safe-ctype.h"
25 #include "tc-xtensa.h"
28 #include "xtensa-relax.h"
29 #include "xtensa-istack.h"
30 #include "dwarf2dbg.h"
31 #include "struc-symbol.h"
32 #include "xtensa-config.h"
35 #define uint32 unsigned int
38 #define int32 signed int
43 There are 3 forms for instructions,
44 1) the MEMORY format -- this is the encoding 2 or 3 byte instruction
45 2) the TInsn -- handles instructions/labels and literals;
46 all operands are assumed to be expressions
47 3) the IStack -- a stack of TInsn. this allows us to
48 reason about the generated expansion instructions
50 Naming conventions (used somewhat inconsistently):
51 The xtensa_ functions are exported
52 The xg_ functions are internal
54 We also have a couple of different extensibility mechanisms.
55 1) The idiom replacement:
56 This is used when a line is first parsed to
57 replace an instruction pattern with another instruction
58 It is currently limited to replacements of instructions
59 with constant operands.
60 2) The xtensa-relax.c mechanism that has stronger instruction
61 replacement patterns. When an instruction's immediate field
62 does not fit the next instruction sequence is attempted.
63 In addition, "narrow" opcodes are supported this way. */
66 /* Define characters with special meanings to GAS. */
67 const char comment_chars
[] = "#";
68 const char line_comment_chars
[] = "#";
69 const char line_separator_chars
[] = ";";
70 const char EXP_CHARS
[] = "eE";
71 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
74 /* Flag to indicate whether the hardware supports the density option.
75 If not, enabling density instructions (via directives or --density flag)
79 bfd_boolean density_supported
= XCHAL_HAVE_DENSITY
;
81 bfd_boolean density_supported
= TRUE
;
84 #define XTENSA_FETCH_WIDTH 4
86 /* Flags for properties of the last instruction in a segment. */
87 #define FLAG_IS_A0_WRITER 0x1
88 #define FLAG_IS_BAD_LOOPEND 0x2
91 /* We define a special segment names ".literal" to place literals
92 into. The .fini and .init sections are special because they
93 contain code that is moved together by the linker. We give them
94 their own special .fini.literal and .init.literal sections. */
96 #define LITERAL_SECTION_NAME xtensa_section_rename (".literal")
97 #define FINI_SECTION_NAME xtensa_section_rename (".fini")
98 #define INIT_SECTION_NAME xtensa_section_rename (".init")
99 #define FINI_LITERAL_SECTION_NAME xtensa_section_rename (".fini.literal")
100 #define INIT_LITERAL_SECTION_NAME xtensa_section_rename (".init.literal")
103 /* This type is used for the directive_stack to keep track of the
104 state of the literal collection pools. */
106 typedef struct lit_state_struct
108 const char *lit_seg_name
;
109 const char *init_lit_seg_name
;
110 const char *fini_lit_seg_name
;
116 static lit_state default_lit_sections
;
119 /* We keep lists of literal segments. The seg_list type is the node
120 for such a list. The *_literal_head locals are the heads of the
121 various lists. All of these lists have a dummy node at the start. */
123 typedef struct seg_list_struct
125 struct seg_list_struct
*next
;
129 static seg_list literal_head_h
;
130 static seg_list
*literal_head
= &literal_head_h
;
131 static seg_list init_literal_head_h
;
132 static seg_list
*init_literal_head
= &init_literal_head_h
;
133 static seg_list fini_literal_head_h
;
134 static seg_list
*fini_literal_head
= &fini_literal_head_h
;
137 /* Global flag to indicate when we are emitting literals. */
138 int generating_literals
= 0;
141 /* Structure for saving the current state before emitting literals. */
142 typedef struct emit_state_struct
147 int generating_literals
;
162 directive_literal_prefix
168 bfd_boolean can_be_negated
;
171 const directive_infoS directive_info
[] =
180 {"literal_prefix", FALSE
}
183 bfd_boolean directive_state
[] =
187 #if STATIC_LIBISA && !XCHAL_HAVE_DENSITY
194 FALSE
, /* freeregs */
195 FALSE
, /* longcalls */
196 FALSE
/* literal_prefix */
200 enum xtensa_relax_statesE
202 RELAX_ALIGN_NEXT_OPCODE
,
203 /* Use the first opcode of the next fragment to determine the
204 alignment requirements. This is ONLY used for LOOPS
207 RELAX_DESIRE_ALIGN_IF_TARGET
,
208 /* These are placed in front of labels. They will all be converted
209 to RELAX_DESIRE_ALIGN / RELAX_LOOP_END or rs_fill of 0 before
210 relaxation begins. */
212 RELAX_ADD_NOP_IF_A0_B_RETW
,
213 /* These are placed in front of conditional branches. It will be
214 turned into a NOP (using a1) if the branch is immediately
215 followed by a RETW or RETW.N. Otherwise it will be turned into
216 an rs_fill of 0 before relaxation begins. */
218 RELAX_ADD_NOP_IF_PRE_LOOP_END
,
219 /* These are placed after JX instructions. It will be turned into a
220 NOP if there is one instruction before a loop end label.
221 Otherwise it will be turned into an rs_fill of 0 before
222 relaxation begins. This is used to avoid a hardware TIE
223 interlock issue prior to T1040. */
225 RELAX_ADD_NOP_IF_SHORT_LOOP
,
226 /* These are placed after LOOP instructions. It will be turned into
227 a NOP when: (1) there are less than 3 instructions in the loop;
228 we place 2 of these in a row to add up to 2 NOPS in short loops;
229 or (2) The instructions in the loop do not include a branch or
230 jump. Otherwise it will be turned into an rs_fill of 0 before
231 relaxation begins. This is used to avoid hardware bug
234 RELAX_ADD_NOP_IF_CLOSE_LOOP_END
,
235 /* These are placed after LOOP instructions. It will be turned into
236 a NOP if there are less than 12 bytes to the end of some other
237 loop's end. Otherwise it will be turned into an rs_fill of 0
238 before relaxation begins. This is used to avoid hardware bug
242 /* The next fragment like its first instruction to NOT cross a
246 /* This will be turned into a NOP or NOP.N if the previous
247 instruction is expanded to negate a loop. */
249 RELAX_LOOP_END_ADD_NOP
,
250 /* When the code density option is available, this will generate a
251 NOP.N marked RELAX_NARROW. Otherwise, it will create an rs_fill
252 fragment with a NOP in it. */
255 /* Another fragment could generate an expansion here but has not yet. */
258 /* Expansion has been generated by an instruction that generates a
259 literal. However, the stretch has NOT been reported yet in this
263 /* Expansion has been generated by an instruction that generates a
266 RELAX_LITERAL_POOL_BEGIN
,
267 RELAX_LITERAL_POOL_END
,
268 /* Technically these are not relaxations at all, but mark a location
269 to store literals later. Note that fr_var stores the frchain for
270 BEGIN frags and fr_var stores now_seg for END frags. */
273 /* The last instruction in this fragment (at->fr_opcode) can be
274 freely replaced with a single wider instruction if a future
275 alignment desires or needs it. */
278 /* The last instruction in this fragment (at->fr_opcode) contains
279 the value defined by fr_symbol (fr_offset = 0). If the value
280 does not fit, use the specified expansion. This is similar to
281 "NARROW", except that these may not be expanded in order to align
285 /* The last instruction in this fragment (at->fr_opcode) contains a
286 literal. It has already been expanded at least 1 step. */
289 /* The last instruction in this fragment (at->fr_opcode) contains a
290 literal. It has already been expanded at least 2 steps. */
293 /* This is used as a stopper to bound the number of steps that
295 #define RELAX_IMMED_MAXSTEPS (RELAX_IMMED_STEP2 - RELAX_IMMED)
298 typedef bfd_boolean (*frag_predicate
) (const fragS
*);
301 /* Directive functions. */
303 static bfd_boolean use_generics
305 static bfd_boolean use_longcalls
307 static bfd_boolean code_density_available
309 static bfd_boolean can_relax
311 static void directive_push
312 PARAMS ((directiveE
, bfd_boolean
, const void *));
313 static void directive_pop
314 PARAMS ((directiveE
*, bfd_boolean
*, const char **,
315 unsigned int *, const void **));
316 static void directive_balance
318 static bfd_boolean inside_directive
319 PARAMS ((directiveE
));
320 static void get_directive
321 PARAMS ((directiveE
*, bfd_boolean
*));
322 static void xtensa_begin_directive
324 static void xtensa_end_directive
326 static void xtensa_literal_prefix
327 PARAMS ((char const *, int));
328 static void xtensa_literal_position
330 static void xtensa_literal_pseudo
333 /* Parsing and Idiom Translation Functions. */
335 static const char *expression_end
336 PARAMS ((const char *));
337 static unsigned tc_get_register
338 PARAMS ((const char *));
339 static void expression_maybe_register
340 PARAMS ((xtensa_operand
, expressionS
*));
341 static int tokenize_arguments
342 PARAMS ((char **, char *));
343 static bfd_boolean parse_arguments
344 PARAMS ((TInsn
*, int, char **));
345 static int xg_translate_idioms
346 PARAMS ((char **, int *, char **));
347 static int xg_translate_sysreg_op
348 PARAMS ((char **, int *, char **));
349 static void xg_reverse_shift_count
351 static int xg_arg_is_constant
352 PARAMS ((char *, offsetT
*));
353 static void xg_replace_opname
354 PARAMS ((char **, char *));
355 static int xg_check_num_args
356 PARAMS ((int *, int, char *, char **));
358 /* Functions for dealing with the Xtensa ISA. */
360 static bfd_boolean operand_is_immed
361 PARAMS ((xtensa_operand
));
362 static bfd_boolean operand_is_pcrel_label
363 PARAMS ((xtensa_operand
));
364 static int get_relaxable_immed
365 PARAMS ((xtensa_opcode
));
366 static xtensa_opcode get_opcode_from_buf
367 PARAMS ((const char *));
368 static bfd_boolean is_direct_call_opcode
369 PARAMS ((xtensa_opcode
));
370 static bfd_boolean is_call_opcode
371 PARAMS ((xtensa_opcode
));
372 static bfd_boolean is_entry_opcode
373 PARAMS ((xtensa_opcode
));
374 static bfd_boolean is_loop_opcode
375 PARAMS ((xtensa_opcode
));
376 static bfd_boolean is_the_loop_opcode
377 PARAMS ((xtensa_opcode
));
378 static bfd_boolean is_jx_opcode
379 PARAMS ((xtensa_opcode
));
380 static bfd_boolean is_windowed_return_opcode
381 PARAMS ((xtensa_opcode
));
382 static bfd_boolean is_conditional_branch_opcode
383 PARAMS ((xtensa_opcode
));
384 static bfd_boolean is_branch_or_jump_opcode
385 PARAMS ((xtensa_opcode
));
386 static bfd_reloc_code_real_type opnum_to_reloc
388 static int reloc_to_opnum
389 PARAMS ((bfd_reloc_code_real_type
));
390 static void xtensa_insnbuf_set_operand
391 PARAMS ((xtensa_insnbuf
, xtensa_opcode
, xtensa_operand
, int32
,
392 const char *, unsigned int));
393 static uint32 xtensa_insnbuf_get_operand
394 PARAMS ((xtensa_insnbuf
, xtensa_opcode
, int));
395 static void xtensa_insnbuf_set_immediate_field
396 PARAMS ((xtensa_opcode
, xtensa_insnbuf
, int32
, const char *,
398 static bfd_boolean is_negatable_branch
401 /* Functions for Internal Lists of Symbols. */
402 static void xtensa_define_label
403 PARAMS ((symbolS
*));
404 static void add_target_symbol
405 PARAMS ((symbolS
*, bfd_boolean
));
406 static symbolS
*xtensa_find_label
407 PARAMS ((fragS
*, offsetT
, bfd_boolean
));
408 static void map_over_defined_symbols
409 PARAMS ((void (*fn
) (symbolS
*)));
410 static bfd_boolean is_loop_target_label
411 PARAMS ((symbolS
*));
412 static void xtensa_mark_target_fragments
415 /* Various Other Internal Functions. */
417 static bfd_boolean is_unique_insn_expansion
418 PARAMS ((TransitionRule
*));
419 static int xg_get_insn_size
421 static int xg_get_build_instr_size
422 PARAMS ((BuildInstr
*));
423 static bfd_boolean xg_is_narrow_insn
425 static bfd_boolean xg_is_single_relaxable_insn
427 static int xg_get_max_narrow_insn_size
428 PARAMS ((xtensa_opcode
));
429 static int xg_get_max_insn_widen_size
430 PARAMS ((xtensa_opcode
));
431 static int xg_get_max_insn_widen_literal_size
432 PARAMS ((xtensa_opcode
));
433 static bfd_boolean xg_is_relaxable_insn
434 PARAMS ((TInsn
*, int));
435 static symbolS
*get_special_literal_symbol
437 static symbolS
*get_special_label_symbol
439 static bfd_boolean xg_build_to_insn
440 PARAMS ((TInsn
*, TInsn
*, BuildInstr
*));
441 static bfd_boolean xg_build_to_stack
442 PARAMS ((IStack
*, TInsn
*, BuildInstr
*));
443 static bfd_boolean xg_expand_to_stack
444 PARAMS ((IStack
*, TInsn
*, int));
445 static bfd_boolean xg_expand_narrow
446 PARAMS ((TInsn
*, TInsn
*));
447 static bfd_boolean xg_immeds_fit
448 PARAMS ((const TInsn
*));
449 static bfd_boolean xg_symbolic_immeds_fit
450 PARAMS ((const TInsn
*, segT
, fragS
*, offsetT
, long));
451 static bfd_boolean xg_check_operand
452 PARAMS ((int32
, xtensa_operand
));
453 static int is_dnrange
454 PARAMS ((fragS
*, symbolS
*, long));
455 static int xg_assembly_relax
456 PARAMS ((IStack
*, TInsn
*, segT
, fragS
*, offsetT
, int, long));
457 static void xg_force_frag_space
459 static void xg_finish_frag
460 PARAMS ((char *, enum xtensa_relax_statesE
, int, bfd_boolean
));
461 static bfd_boolean is_branch_jmp_to_next
462 PARAMS ((TInsn
*, fragS
*));
463 static void xg_add_branch_and_loop_targets
465 static bfd_boolean xg_instruction_matches_rule
466 PARAMS ((TInsn
*, TransitionRule
*));
467 static TransitionRule
*xg_instruction_match
469 static bfd_boolean xg_build_token_insn
470 PARAMS ((BuildInstr
*, TInsn
*, TInsn
*));
471 static bfd_boolean xg_simplify_insn
472 PARAMS ((TInsn
*, TInsn
*));
473 static bfd_boolean xg_expand_assembly_insn
474 PARAMS ((IStack
*, TInsn
*));
475 static symbolS
*xg_assemble_literal
477 static void xg_assemble_literal_space
479 static symbolS
*xtensa_create_literal_symbol
480 PARAMS ((segT
, fragS
*));
481 static symbolS
*xtensa_create_local_symbol
482 PARAMS ((bfd
*, const char *, segT
, valueT
, fragS
*));
483 static bfd_boolean get_is_linkonce_section
484 PARAMS ((bfd
*, segT
));
485 static bfd_boolean xg_emit_insn
486 PARAMS ((TInsn
*, bfd_boolean
));
487 static bfd_boolean xg_emit_insn_to_buf
488 PARAMS ((TInsn
*, char *, fragS
*, offsetT
, bfd_boolean
));
489 static bfd_boolean xg_add_opcode_fix
490 PARAMS ((xtensa_opcode
, int, expressionS
*, fragS
*, offsetT
));
491 static void xg_resolve_literals
492 PARAMS ((TInsn
*, symbolS
*));
493 static void xg_resolve_labels
494 PARAMS ((TInsn
*, symbolS
*));
495 static void xg_assemble_tokens
497 static bfd_boolean is_register_writer
498 PARAMS ((const TInsn
*, const char *, int));
499 static bfd_boolean is_bad_loopend_opcode
500 PARAMS ((const TInsn
*));
501 static bfd_boolean is_unaligned_label
502 PARAMS ((symbolS
*));
503 static fragS
*next_non_empty_frag
504 PARAMS ((const fragS
*));
505 static xtensa_opcode next_frag_opcode
506 PARAMS ((const fragS
*));
507 static void update_next_frag_nop_state
509 static bfd_boolean next_frag_is_branch_target
510 PARAMS ((const fragS
*));
511 static bfd_boolean next_frag_is_loop_target
512 PARAMS ((const fragS
*));
513 static addressT next_frag_pre_opcode_bytes
514 PARAMS ((const fragS
*));
515 static bfd_boolean is_next_frag_target
516 PARAMS ((const fragS
*, const fragS
*));
517 static void xtensa_mark_literal_pool_location
518 PARAMS ((bfd_boolean
));
519 static void xtensa_move_labels
520 PARAMS ((fragS
*, valueT
, fragS
*, valueT
));
521 static void assemble_nop
522 PARAMS ((size_t, char *));
523 static addressT get_expanded_loop_offset
524 PARAMS ((xtensa_opcode
));
525 static fragS
*get_literal_pool_location
527 static void set_literal_pool_location
528 PARAMS ((segT
, fragS
*));
530 /* Helpers for xtensa_end(). */
532 static void xtensa_cleanup_align_frags
534 static void xtensa_fix_target_frags
536 static bfd_boolean frag_can_negate_branch
538 static void xtensa_fix_a0_b_retw_frags
540 static bfd_boolean next_instrs_are_b_retw
542 static void xtensa_fix_b_j_loop_end_frags
544 static bfd_boolean next_instr_is_loop_end
546 static void xtensa_fix_close_loop_end_frags
548 static size_t min_bytes_to_other_loop_end
549 PARAMS ((fragS
*, fragS
*, offsetT
, size_t));
550 static size_t unrelaxed_frag_min_size
552 static void xtensa_fix_short_loop_frags
554 static size_t count_insns_to_loop_end
555 PARAMS ((fragS
*, bfd_boolean
, size_t));
556 static size_t unrelaxed_frag_min_insn_count
558 static bfd_boolean branch_before_loop_end
560 static bfd_boolean unrelaxed_frag_has_b_j
562 static void xtensa_sanity_check
564 static bfd_boolean is_empty_loop
565 PARAMS ((const TInsn
*, fragS
*));
566 static bfd_boolean is_local_forward_loop
567 PARAMS ((const TInsn
*, fragS
*));
569 /* Alignment Functions. */
571 static size_t get_text_align_power
573 static addressT get_text_align_max_fill_size
574 PARAMS ((int, bfd_boolean
, bfd_boolean
));
575 static addressT get_text_align_fill_size
576 PARAMS ((addressT
, int, int, bfd_boolean
, bfd_boolean
));
577 static size_t get_text_align_nop_count
578 PARAMS ((size_t, bfd_boolean
));
579 static size_t get_text_align_nth_nop_size
580 PARAMS ((size_t, size_t, bfd_boolean
));
581 static addressT get_noop_aligned_address
582 PARAMS ((fragS
*, addressT
));
583 static addressT get_widen_aligned_address
584 PARAMS ((fragS
*, addressT
));
586 /* Helpers for xtensa_relax_frag(). */
588 static long relax_frag_text_align
589 PARAMS ((fragS
*, long));
590 static long relax_frag_add_nop
592 static long relax_frag_narrow
593 PARAMS ((fragS
*, long));
594 static bfd_boolean future_alignment_required
595 PARAMS ((fragS
*, long));
596 static long relax_frag_immed
597 PARAMS ((segT
, fragS
*, long, int, int *));
599 /* Helpers for md_convert_frag(). */
601 static void convert_frag_align_next_opcode
603 static void convert_frag_narrow
605 static void convert_frag_immed
606 PARAMS ((segT
, fragS
*, int));
607 static fixS
*fix_new_exp_in_seg
608 PARAMS ((segT
, subsegT
, fragS
*, int, int, expressionS
*, int,
609 bfd_reloc_code_real_type
));
610 static void convert_frag_immed_finish_loop
611 PARAMS ((segT
, fragS
*, TInsn
*));
612 static offsetT get_expression_value
613 PARAMS ((segT
, expressionS
*));
615 /* Flags for the Last Instruction in Each Subsegment. */
617 static unsigned get_last_insn_flags
618 PARAMS ((segT
, subsegT
));
619 static void set_last_insn_flags
620 PARAMS ((segT
, subsegT
, unsigned, bfd_boolean
));
622 /* Segment list functions. */
624 static void xtensa_remove_section
626 static void xtensa_insert_section
627 PARAMS ((segT
, segT
));
628 static void xtensa_move_seg_list_to_beginning
629 PARAMS ((seg_list
*));
630 static void xtensa_move_literals
632 static void xtensa_move_frag_symbol
633 PARAMS ((symbolS
*));
634 static void xtensa_move_frag_symbols
636 static void xtensa_reorder_seg_list
637 PARAMS ((seg_list
*, segT
));
638 static void xtensa_reorder_segments
640 static segT get_last_sec
642 static void xtensa_switch_to_literal_fragment
643 PARAMS ((emit_state
*));
644 static void xtensa_switch_section_emit_state
645 PARAMS ((emit_state
*, segT
, subsegT
));
646 static void xtensa_restore_emit_state
647 PARAMS ((emit_state
*));
648 static void cache_literal_section
649 PARAMS ((seg_list
*, const char *, segT
*));
650 static segT retrieve_literal_seg
651 PARAMS ((seg_list
*, const char *));
652 static segT seg_present
653 PARAMS ((const char *));
654 static void add_seg_list
655 PARAMS ((seg_list
*, segT
));
657 /* Property Table (e.g., ".xt.insn" and ".xt.lit") Functions. */
659 static void xtensa_create_property_segments
660 PARAMS ((frag_predicate
, const char *, xt_section_type
));
661 static segment_info_type
*retrieve_segment_info
663 static segT retrieve_xtensa_section
665 static bfd_boolean section_has_property
666 PARAMS ((segT sec
, frag_predicate
));
667 static void add_xt_block_frags
668 PARAMS ((segT
, segT
, xtensa_block_info
**, frag_predicate
));
669 static bfd_boolean get_frag_is_literal
670 PARAMS ((const fragS
*));
671 static bfd_boolean get_frag_is_insn
672 PARAMS ((const fragS
*));
674 /* Import from elf32-xtensa.c in BFD library. */
675 extern char *xtensa_get_property_section_name
676 PARAMS ((bfd
*, asection
*, const char *));
678 /* TInsn and IStack functions. */
679 static bfd_boolean tinsn_has_symbolic_operands
680 PARAMS ((const TInsn
*));
681 static bfd_boolean tinsn_has_invalid_symbolic_operands
682 PARAMS ((const TInsn
*));
683 static bfd_boolean tinsn_has_complex_operands
684 PARAMS ((const TInsn
*));
685 static bfd_boolean tinsn_to_insnbuf
686 PARAMS ((TInsn
*, xtensa_insnbuf
));
687 static bfd_boolean tinsn_check_arguments
688 PARAMS ((const TInsn
*));
689 static void tinsn_from_chars
690 PARAMS ((TInsn
*, char *));
691 static void tinsn_immed_from_frag
692 PARAMS ((TInsn
*, fragS
*));
693 static int get_num_stack_text_bytes
695 static int get_num_stack_literal_bytes
698 /* Expression Utilities. */
699 bfd_boolean expr_is_const
700 PARAMS ((const expressionS
*));
701 offsetT get_expr_const
702 PARAMS ((const expressionS
*));
704 PARAMS ((expressionS
*, offsetT
));
705 void set_expr_symbol_offset
706 PARAMS ((expressionS
*, symbolS
*, offsetT
));
707 bfd_boolean expr_is_equal
708 PARAMS ((expressionS
*, expressionS
*));
709 static void copy_expr
710 PARAMS ((expressionS
*, const expressionS
*));
712 #ifdef XTENSA_SECTION_RENAME
713 static void build_section_rename
714 PARAMS ((const char *));
715 static void add_section_rename
716 PARAMS ((char *, char *));
719 #ifdef XTENSA_COMBINE_LITERALS
720 static void find_lit_sym_translation
721 PARAMS ((expressionS
*));
722 static void add_lit_sym_translation
723 PARAMS ((char *, offsetT
, symbolS
*));
727 /* ISA imported from bfd. */
728 extern xtensa_isa xtensa_default_isa
;
730 extern int target_big_endian
;
732 static xtensa_opcode xtensa_addi_opcode
;
733 static xtensa_opcode xtensa_addmi_opcode
;
734 static xtensa_opcode xtensa_call0_opcode
;
735 static xtensa_opcode xtensa_call4_opcode
;
736 static xtensa_opcode xtensa_call8_opcode
;
737 static xtensa_opcode xtensa_call12_opcode
;
738 static xtensa_opcode xtensa_callx0_opcode
;
739 static xtensa_opcode xtensa_callx4_opcode
;
740 static xtensa_opcode xtensa_callx8_opcode
;
741 static xtensa_opcode xtensa_callx12_opcode
;
742 static xtensa_opcode xtensa_entry_opcode
;
743 static xtensa_opcode xtensa_isync_opcode
;
744 static xtensa_opcode xtensa_j_opcode
;
745 static xtensa_opcode xtensa_jx_opcode
;
746 static xtensa_opcode xtensa_loop_opcode
;
747 static xtensa_opcode xtensa_loopnez_opcode
;
748 static xtensa_opcode xtensa_loopgtz_opcode
;
749 static xtensa_opcode xtensa_nop_n_opcode
;
750 static xtensa_opcode xtensa_or_opcode
;
751 static xtensa_opcode xtensa_ret_opcode
;
752 static xtensa_opcode xtensa_ret_n_opcode
;
753 static xtensa_opcode xtensa_retw_opcode
;
754 static xtensa_opcode xtensa_retw_n_opcode
;
755 static xtensa_opcode xtensa_rsr_opcode
;
756 static xtensa_opcode xtensa_waiti_opcode
;
759 /* Command-line Options. */
761 bfd_boolean use_literal_section
= TRUE
;
762 static bfd_boolean align_targets
= TRUE
;
763 static bfd_boolean align_only_targets
= FALSE
;
764 static bfd_boolean software_a0_b_retw_interlock
= TRUE
;
765 static bfd_boolean has_a0_b_retw
= FALSE
;
766 static bfd_boolean workaround_a0_b_retw
= TRUE
;
768 static bfd_boolean software_avoid_b_j_loop_end
= TRUE
;
769 static bfd_boolean workaround_b_j_loop_end
= TRUE
;
770 static bfd_boolean maybe_has_b_j_loop_end
= FALSE
;
772 static bfd_boolean software_avoid_short_loop
= TRUE
;
773 static bfd_boolean workaround_short_loop
= TRUE
;
774 static bfd_boolean maybe_has_short_loop
= FALSE
;
776 static bfd_boolean software_avoid_close_loop_end
= TRUE
;
777 static bfd_boolean workaround_close_loop_end
= TRUE
;
778 static bfd_boolean maybe_has_close_loop_end
= FALSE
;
780 /* When avoid_short_loops is true, all loops with early exits must
781 have at least 3 instructions. avoid_all_short_loops is a modifier
782 to the avoid_short_loop flag. In addition to the avoid_short_loop
783 actions, all straightline loopgtz and loopnez must have at least 3
786 static bfd_boolean software_avoid_all_short_loops
= TRUE
;
787 static bfd_boolean workaround_all_short_loops
= TRUE
;
789 /* This is on a per-instruction basis. */
790 static bfd_boolean specific_opcode
= FALSE
;
794 option_density
= OPTION_MD_BASE
,
803 option_text_section_literals
,
804 option_no_text_section_literals
,
806 option_align_targets
,
807 option_no_align_targets
,
809 option_align_only_targets
,
810 option_no_align_only_targets
,
815 option_workaround_a0_b_retw
,
816 option_no_workaround_a0_b_retw
,
818 option_workaround_b_j_loop_end
,
819 option_no_workaround_b_j_loop_end
,
821 option_workaround_short_loop
,
822 option_no_workaround_short_loop
,
824 option_workaround_all_short_loops
,
825 option_no_workaround_all_short_loops
,
827 option_workaround_close_loop_end
,
828 option_no_workaround_close_loop_end
,
830 option_no_workarounds
,
832 #ifdef XTENSA_SECTION_RENAME
833 option_literal_section_name
,
834 option_text_section_name
,
835 option_data_section_name
,
836 option_bss_section_name
,
837 option_rename_section_name
,
844 const char *md_shortopts
= "";
846 struct option md_longopts
[] =
848 {"density", no_argument
, NULL
, option_density
},
849 {"no-density", no_argument
, NULL
, option_no_density
},
850 /* At least as early as alameda, --[no-]relax didn't work as
851 documented, so as of albany, --[no-]relax is equivalent to
852 --[no-]generics. Both of these will be deprecated in
854 {"relax", no_argument
, NULL
, option_generics
},
855 {"no-relax", no_argument
, NULL
, option_no_generics
},
856 {"generics", no_argument
, NULL
, option_generics
},
857 {"no-generics", no_argument
, NULL
, option_no_generics
},
858 {"text-section-literals", no_argument
, NULL
, option_text_section_literals
},
859 {"no-text-section-literals", no_argument
, NULL
,
860 option_no_text_section_literals
},
861 /* This option was changed from -align-target to -target-align
862 because it conflicted with the "-al" option. */
863 {"target-align", no_argument
, NULL
, option_align_targets
},
864 {"no-target-align", no_argument
, NULL
,
865 option_no_align_targets
},
867 /* This option should do a better job aligning targets because
868 it will only attempt to align targets that are the target of a
870 { "target-align-only", no_argument
, NULL
, option_align_only_targets
},
871 { "no-target-align-only", no_argument
, NULL
, option_no_align_only_targets
},
873 {"longcalls", no_argument
, NULL
, option_longcalls
},
874 {"no-longcalls", no_argument
, NULL
, option_no_longcalls
},
876 {"no-workaround-a0-b-retw", no_argument
, NULL
,
877 option_no_workaround_a0_b_retw
},
878 {"workaround-a0-b-retw", no_argument
, NULL
, option_workaround_a0_b_retw
},
880 {"no-workaround-b-j-loop-end", no_argument
, NULL
,
881 option_no_workaround_b_j_loop_end
},
882 {"workaround-b-j-loop-end", no_argument
, NULL
,
883 option_workaround_b_j_loop_end
},
885 {"no-workaround-short-loops", no_argument
, NULL
,
886 option_no_workaround_short_loop
},
887 {"workaround-short-loops", no_argument
, NULL
, option_workaround_short_loop
},
889 {"no-workaround-all-short-loops", no_argument
, NULL
,
890 option_no_workaround_all_short_loops
},
891 {"workaround-all-short-loop", no_argument
, NULL
,
892 option_workaround_all_short_loops
},
894 {"no-workaround-close-loop-end", no_argument
, NULL
,
895 option_no_workaround_close_loop_end
},
896 {"workaround-close-loop-end", no_argument
, NULL
,
897 option_workaround_close_loop_end
},
899 {"no-workarounds", no_argument
, NULL
, option_no_workarounds
},
901 #ifdef XTENSA_SECTION_RENAME
902 {"literal-section-name", required_argument
, NULL
,
903 option_literal_section_name
},
904 {"text-section-name", required_argument
, NULL
,
905 option_text_section_name
},
906 {"data-section-name", required_argument
, NULL
,
907 option_data_section_name
},
908 {"rename-section", required_argument
, NULL
,
909 option_rename_section_name
},
910 {"bss-section-name", required_argument
, NULL
,
911 option_bss_section_name
},
912 #endif /* XTENSA_SECTION_RENAME */
914 {NULL
, no_argument
, NULL
, 0}
917 size_t md_longopts_size
= sizeof md_longopts
;
921 md_parse_option (c
, arg
)
928 if (!density_supported
)
930 as_bad (_("'--density' option not supported in this Xtensa "
934 directive_state
[directive_density
] = TRUE
;
936 case option_no_density
:
937 directive_state
[directive_density
] = FALSE
;
939 case option_generics
:
940 directive_state
[directive_generics
] = TRUE
;
942 case option_no_generics
:
943 directive_state
[directive_generics
] = FALSE
;
945 case option_longcalls
:
946 directive_state
[directive_longcalls
] = TRUE
;
948 case option_no_longcalls
:
949 directive_state
[directive_longcalls
] = FALSE
;
951 case option_text_section_literals
:
952 use_literal_section
= FALSE
;
954 case option_no_text_section_literals
:
955 use_literal_section
= TRUE
;
957 case option_workaround_a0_b_retw
:
958 workaround_a0_b_retw
= TRUE
;
959 software_a0_b_retw_interlock
= TRUE
;
961 case option_no_workaround_a0_b_retw
:
962 workaround_a0_b_retw
= FALSE
;
963 software_a0_b_retw_interlock
= FALSE
;
965 case option_workaround_b_j_loop_end
:
966 workaround_b_j_loop_end
= TRUE
;
967 software_avoid_b_j_loop_end
= TRUE
;
969 case option_no_workaround_b_j_loop_end
:
970 workaround_b_j_loop_end
= FALSE
;
971 software_avoid_b_j_loop_end
= FALSE
;
974 case option_workaround_short_loop
:
975 workaround_short_loop
= TRUE
;
976 software_avoid_short_loop
= TRUE
;
978 case option_no_workaround_short_loop
:
979 workaround_short_loop
= FALSE
;
980 software_avoid_short_loop
= FALSE
;
983 case option_workaround_all_short_loops
:
984 workaround_all_short_loops
= TRUE
;
985 software_avoid_all_short_loops
= TRUE
;
987 case option_no_workaround_all_short_loops
:
988 workaround_all_short_loops
= FALSE
;
989 software_avoid_all_short_loops
= FALSE
;
992 case option_workaround_close_loop_end
:
993 workaround_close_loop_end
= TRUE
;
994 software_avoid_close_loop_end
= TRUE
;
996 case option_no_workaround_close_loop_end
:
997 workaround_close_loop_end
= FALSE
;
998 software_avoid_close_loop_end
= FALSE
;
1001 case option_no_workarounds
:
1002 workaround_a0_b_retw
= FALSE
;
1003 software_a0_b_retw_interlock
= FALSE
;
1004 workaround_b_j_loop_end
= FALSE
;
1005 software_avoid_b_j_loop_end
= FALSE
;
1006 workaround_short_loop
= FALSE
;
1007 software_avoid_short_loop
= FALSE
;
1008 workaround_all_short_loops
= FALSE
;
1009 software_avoid_all_short_loops
= FALSE
;
1010 workaround_close_loop_end
= FALSE
;
1011 software_avoid_close_loop_end
= FALSE
;
1014 case option_align_targets
:
1015 align_targets
= TRUE
;
1017 case option_no_align_targets
:
1018 align_targets
= FALSE
;
1021 case option_align_only_targets
:
1022 align_only_targets
= TRUE
;
1024 case option_no_align_only_targets
:
1025 align_only_targets
= FALSE
;
1028 #ifdef XTENSA_SECTION_RENAME
1029 case option_literal_section_name
:
1030 add_section_rename (".literal", arg
);
1031 as_warn (_("'--literal-section-name' is deprecated; "
1032 "use '--rename-section .literal=NEWNAME'"));
1035 case option_text_section_name
:
1036 add_section_rename (".text", arg
);
1037 as_warn (_("'--text-section-name' is deprecated; "
1038 "use '--rename-section .text=NEWNAME'"));
1041 case option_data_section_name
:
1042 add_section_rename (".data", arg
);
1043 as_warn (_("'--data-section-name' is deprecated; "
1044 "use '--rename-section .data=NEWNAME'"));
1047 case option_bss_section_name
:
1048 add_section_rename (".bss", arg
);
1049 as_warn (_("'--bss-section-name' is deprecated; "
1050 "use '--rename-section .bss=NEWNAME'"));
1053 case option_rename_section_name
:
1054 build_section_rename (arg
);
1056 #endif /* XTENSA_SECTION_RENAME */
1059 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1060 should be emitted or not. FIXME: Not implemented. */
1070 md_show_usage (stream
)
1073 fputs ("\nXtensa options:\n"
1074 "--[no-]density [Do not] emit density instructions\n"
1075 "--[no-]relax [Do not] perform branch relaxation\n"
1076 "--[no-]generics [Do not] transform instructions\n"
1077 "--[no-]longcalls [Do not] emit 32-bit call sequences\n"
1078 "--[no-]target-align [Do not] try to align branch targets\n"
1079 "--[no-]text-section-literals\n"
1080 " [Do not] put literals in the text section\n"
1081 "--no-workarounds Do not use any Xtensa workarounds\n"
1082 #ifdef XTENSA_SECTION_RENAME
1083 "--rename-section old=new(:old1=new1)*\n"
1084 " Rename section 'old' to 'new'\n"
1085 "\nThe following Xtensa options are deprecated\n"
1086 "--literal-section-name Name of literal section (default .literal)\n"
1087 "--text-section-name Name of text section (default .text)\n"
1088 "--data-section-name Name of data section (default .data)\n"
1089 "--bss-section-name Name of bss section (default .bss)\n"
1095 /* Directive data and functions. */
1097 typedef struct state_stackS_struct
1099 directiveE directive
;
1100 bfd_boolean negated
;
1101 bfd_boolean old_state
;
1105 struct state_stackS_struct
*prev
;
1108 state_stackS
*directive_state_stack
;
1110 const pseudo_typeS md_pseudo_table
[] =
1112 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
1113 {"literal_position", xtensa_literal_position
, 0},
1114 {"frame", s_ignore
, 0}, /* formerly used for STABS debugging */
1116 {"begin", xtensa_begin_directive
, 0},
1117 {"end", xtensa_end_directive
, 0},
1118 {"file", (void (*) PARAMS ((int))) dwarf2_directive_file
, 0},
1119 {"loc", dwarf2_directive_loc
, 0},
1120 {"literal", xtensa_literal_pseudo
, 0},
1128 return directive_state
[directive_generics
];
1135 return directive_state
[directive_longcalls
];
1140 code_density_available ()
1142 return directive_state
[directive_density
];
1149 return use_generics ();
1154 directive_push (directive
, negated
, datum
)
1155 directiveE directive
;
1156 bfd_boolean negated
;
1161 state_stackS
*stack
= (state_stackS
*) xmalloc (sizeof (state_stackS
));
1163 as_where (&file
, &line
);
1165 stack
->directive
= directive
;
1166 stack
->negated
= negated
;
1167 stack
->old_state
= directive_state
[directive
];
1170 stack
->datum
= datum
;
1171 stack
->prev
= directive_state_stack
;
1172 directive_state_stack
= stack
;
1174 directive_state
[directive
] = !negated
;
1178 directive_pop (directive
, negated
, file
, line
, datum
)
1179 directiveE
*directive
;
1180 bfd_boolean
*negated
;
1185 state_stackS
*top
= directive_state_stack
;
1187 if (!directive_state_stack
)
1189 as_bad (_("unmatched end directive"));
1190 *directive
= directive_none
;
1194 directive_state
[directive_state_stack
->directive
] = top
->old_state
;
1195 *directive
= top
->directive
;
1196 *negated
= top
->negated
;
1199 *datum
= top
->datum
;
1200 directive_state_stack
= top
->prev
;
1206 directive_balance ()
1208 while (directive_state_stack
)
1210 directiveE directive
;
1211 bfd_boolean negated
;
1216 directive_pop (&directive
, &negated
, &file
, &line
, &datum
);
1217 as_warn_where ((char *) file
, line
,
1218 _(".begin directive with no matching .end directive"));
1224 inside_directive (dir
)
1227 state_stackS
*top
= directive_state_stack
;
1229 while (top
&& top
->directive
!= dir
)
1232 return (top
!= NULL
);
1237 get_directive (directive
, negated
)
1238 directiveE
*directive
;
1239 bfd_boolean
*negated
;
1244 if (strncmp (input_line_pointer
, "no-", 3) != 0)
1249 input_line_pointer
+= 3;
1252 len
= strspn (input_line_pointer
,
1253 "abcdefghijklmnopqrstuvwxyz_/0123456789.");
1255 for (i
= 0; i
< sizeof (directive_info
) / sizeof (*directive_info
); ++i
)
1257 if (strncmp (input_line_pointer
, directive_info
[i
].name
, len
) == 0)
1259 input_line_pointer
+= len
;
1260 *directive
= (directiveE
) i
;
1261 if (*negated
&& !directive_info
[i
].can_be_negated
)
1262 as_bad (_("directive %s can't be negated"),
1263 directive_info
[i
].name
);
1268 as_bad (_("unknown directive"));
1269 *directive
= (directiveE
) XTENSA_UNDEFINED
;
1274 xtensa_begin_directive (ignore
)
1275 int ignore ATTRIBUTE_UNUSED
;
1277 directiveE directive
;
1278 bfd_boolean negated
;
1283 get_directive (&directive
, &negated
);
1284 if (directive
== (directiveE
) XTENSA_UNDEFINED
)
1286 discard_rest_of_line ();
1292 case directive_literal
:
1293 state
= (emit_state
*) xmalloc (sizeof (emit_state
));
1294 xtensa_switch_to_literal_fragment (state
);
1295 directive_push (directive_literal
, negated
, state
);
1298 case directive_literal_prefix
:
1299 /* Check to see if the current fragment is a literal
1300 fragment. If it is, then this operation is not allowed. */
1301 if (frag_now
->tc_frag_data
.is_literal
)
1303 as_bad (_("cannot set literal_prefix inside literal fragment"));
1307 /* Allocate the literal state for this section and push
1308 onto the directive stack. */
1309 ls
= xmalloc (sizeof (lit_state
));
1312 *ls
= default_lit_sections
;
1314 directive_push (directive_literal_prefix
, negated
, ls
);
1316 /* Parse the new prefix from the input_line_pointer. */
1318 len
= strspn (input_line_pointer
,
1319 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1320 "abcdefghijklmnopqrstuvwxyz_/0123456789.$");
1322 /* Process the new prefix. */
1323 xtensa_literal_prefix (input_line_pointer
, len
);
1325 /* Skip the name in the input line. */
1326 input_line_pointer
+= len
;
1329 case directive_freeregs
:
1330 /* This information is currently unused, but we'll accept the statement
1331 and just discard the rest of the line. This won't check the syntax,
1332 but it will accept every correct freeregs directive. */
1333 input_line_pointer
+= strcspn (input_line_pointer
, "\n");
1334 directive_push (directive_freeregs
, negated
, 0);
1337 case directive_density
:
1338 if (!density_supported
&& !negated
)
1340 as_warn (_("Xtensa density option not supported; ignored"));
1346 directive_push (directive
, negated
, 0);
1350 demand_empty_rest_of_line ();
1355 xtensa_end_directive (ignore
)
1356 int ignore ATTRIBUTE_UNUSED
;
1358 directiveE begin_directive
, end_directive
;
1359 bfd_boolean begin_negated
, end_negated
;
1365 get_directive (&end_directive
, &end_negated
);
1366 if (end_directive
== (directiveE
) XTENSA_UNDEFINED
)
1368 discard_rest_of_line ();
1372 if (end_directive
== directive_density
&& !density_supported
&& !end_negated
)
1374 as_warn (_("Xtensa density option not supported; ignored"));
1375 demand_empty_rest_of_line ();
1379 directive_pop (&begin_directive
, &begin_negated
, &file
, &line
,
1380 (const void **) &state
);
1382 if (begin_directive
!= directive_none
)
1384 if (begin_directive
!= end_directive
|| begin_negated
!= end_negated
)
1386 as_bad (_("does not match begin %s%s at %s:%d"),
1387 begin_negated
? "no-" : "",
1388 directive_info
[begin_directive
].name
, file
, line
);
1392 switch (end_directive
)
1394 case directive_literal
:
1395 frag_var (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
1396 xtensa_restore_emit_state (state
);
1400 case directive_freeregs
:
1403 case directive_literal_prefix
:
1404 /* Restore the default collection sections from saved state. */
1405 s
= (lit_state
*) state
;
1408 if (use_literal_section
)
1409 default_lit_sections
= *s
;
1411 /* free the state storage */
1421 demand_empty_rest_of_line ();
1425 /* Place an aligned literal fragment at the current location. */
1428 xtensa_literal_position (ignore
)
1429 int ignore ATTRIBUTE_UNUSED
;
1431 if (inside_directive (directive_literal
))
1432 as_warn (_(".literal_position inside literal directive; ignoring"));
1433 else if (!use_literal_section
)
1434 xtensa_mark_literal_pool_location (FALSE
);
1436 demand_empty_rest_of_line ();
1440 /* Support .literal label, value@plt + offset. */
1443 xtensa_literal_pseudo (ignored
)
1444 int ignored ATTRIBUTE_UNUSED
;
1448 #ifdef XTENSA_COMBINE_LITERALS
1451 bfd_boolean used_name
= FALSE
;
1459 /* If we are using text-section literals, then this is the right value... */
1462 base_name
= input_line_pointer
;
1464 xtensa_switch_to_literal_fragment (&state
);
1466 /* ...but if we aren't using text-section-literals, then we
1467 need to put them in the section we just switched to. */
1468 if (use_literal_section
)
1471 /* All literals are aligned to four-byte boundaries
1472 which is handled by switch to literal fragment. */
1473 /* frag_align (2, 0, 0); */
1475 c
= get_symbol_end ();
1476 /* Just after name is now '\0'. */
1477 p
= input_line_pointer
;
1481 if (*input_line_pointer
!= ',' && *input_line_pointer
!= ':')
1483 as_bad (_("expected comma or colon after symbol name; "
1484 "rest of line ignored"));
1485 ignore_rest_of_line ();
1486 xtensa_restore_emit_state (&state
);
1491 #ifdef XTENSA_COMBINE_LITERALS
1492 /* We need next name to start out equal to base_name,
1493 but we modify it later to refer to a symbol and an offset. */
1494 next_name
= xmalloc (strlen (base_name
) + 1);
1495 strcpy (next_name
, base_name
);
1497 /* We need a copy of base_name because we refer to it in the
1498 lit_sym_translations and the source is somewhere in the input stream. */
1499 base_name
= xmalloc (strlen (base_name
) + 1);
1500 strcpy (base_name
, next_name
);
1509 input_line_pointer
++; /* skip ',' or ':' */
1513 #ifdef XTENSA_COMBINE_LITERALS
1514 duplicate
= is_duplicate_literal (&expP
, dest_seg
);
1517 add_lit_sym_translation (base_name
, offset
, duplicate
);
1524 /* We only support 4-byte literals with .literal. */
1525 emit_expr (&expP
, 4);
1527 #ifdef XTENSA_COMBINE_LITERALS
1528 cache_literal (next_name
, &expP
, dest_seg
);
1531 if (*input_line_pointer
== ',')
1534 next_name
= xmalloc (strlen (base_name
) +
1535 strlen (XTENSA_LIT_PLUS_OFFSET
) + 10);
1536 sprintf (next_name
, "%s%s%d",
1537 XTENSA_LIT_PLUS_OFFSET
, base_name
, offset
);
1541 while (*input_line_pointer
== ',');
1544 #ifdef XTENSA_COMBINE_LITERALS
1549 demand_empty_rest_of_line ();
1551 xtensa_restore_emit_state (&state
);
1556 xtensa_literal_prefix (start
, len
)
1560 segT s_now
; /* Storage for the current seg and subseg. */
1562 char *name
; /* Pointer to the name itself. */
1565 if (!use_literal_section
)
1568 /* Store away the current section and subsection. */
1570 ss_now
= now_subseg
;
1572 /* Get a null-terminated copy of the name. */
1573 name
= xmalloc (len
+ 1);
1576 strncpy (name
, start
, len
);
1579 /* Allocate the sections (interesting note: the memory pointing to
1580 the name is actually used for the name by the new section). */
1581 newname
= xmalloc (len
+ strlen (".literal") + 1);
1582 strcpy (newname
, name
);
1583 strcpy (newname
+ len
, ".literal");
1585 /* Note that retrieve_literal_seg does not create a segment if
1586 it already exists. */
1587 default_lit_sections
.lit_seg
= NULL
; /* retrieved on demand */
1589 /* Canonicalizing section names allows renaming literal
1590 sections to occur correctly. */
1591 default_lit_sections
.lit_seg_name
=
1592 tc_canonicalize_symbol_name (newname
);
1596 /* Restore the current section and subsection and set the
1597 generation into the old segment. */
1598 subseg_set (s_now
, ss_now
);
1602 /* Parsing and Idiom Translation. */
1605 expression_end (name
)
1627 #define ERROR_REG_NUM ((unsigned) -1)
1630 tc_get_register (prefix
)
1634 const char *next_expr
;
1635 const char *old_line_pointer
;
1638 old_line_pointer
= input_line_pointer
;
1640 if (*input_line_pointer
== '$')
1641 ++input_line_pointer
;
1643 /* Accept "sp" as a synonym for "a1". */
1644 if (input_line_pointer
[0] == 's' && input_line_pointer
[1] == 'p'
1645 && expression_end (input_line_pointer
+ 2))
1647 input_line_pointer
+= 2;
1648 return 1; /* AR[1] */
1651 while (*input_line_pointer
++ == *prefix
++)
1653 --input_line_pointer
;
1658 as_bad (_("bad register name: %s"), old_line_pointer
);
1659 return ERROR_REG_NUM
;
1662 if (!ISDIGIT ((unsigned char) *input_line_pointer
))
1664 as_bad (_("bad register number: %s"), input_line_pointer
);
1665 return ERROR_REG_NUM
;
1670 while (ISDIGIT ((int) *input_line_pointer
))
1671 reg
= reg
* 10 + *input_line_pointer
++ - '0';
1673 if (!(next_expr
= expression_end (input_line_pointer
)))
1675 as_bad (_("bad register name: %s"), old_line_pointer
);
1676 return ERROR_REG_NUM
;
1679 input_line_pointer
= (char *) next_expr
;
1685 #define PLT_SUFFIX "@PLT"
1686 #define plt_suffix "@plt"
1689 expression_maybe_register (opnd
, tok
)
1690 xtensa_operand opnd
;
1693 char *kind
= xtensa_operand_kind (opnd
);
1695 if ((strlen (kind
) == 1)
1696 && (*kind
== 'l' || *kind
== 'L' || *kind
== 'i' || *kind
== 'r'))
1698 segT t
= expression (tok
);
1699 if (t
== absolute_section
&& operand_is_pcrel_label (opnd
))
1701 assert (tok
->X_op
== O_constant
);
1702 tok
->X_op
= O_symbol
;
1703 tok
->X_add_symbol
= &abs_symbol
;
1705 if (tok
->X_op
== O_symbol
1706 && (!strncmp (input_line_pointer
, PLT_SUFFIX
,
1707 strlen (PLT_SUFFIX
) - 1)
1708 || !strncmp (input_line_pointer
, plt_suffix
,
1709 strlen (plt_suffix
) - 1)))
1711 tok
->X_add_symbol
->sy_tc
.plt
= 1;
1712 input_line_pointer
+= strlen (plt_suffix
);
1714 #ifdef XTENSA_COMBINE_LITERALS
1715 find_lit_sym_translation (tok
);
1720 unsigned reg
= tc_get_register (kind
);
1722 if (reg
!= ERROR_REG_NUM
) /* Already errored */
1725 if ((xtensa_operand_encode (opnd
, &buf
) != xtensa_encode_result_ok
)
1726 || (reg
!= xtensa_operand_decode (opnd
, buf
)))
1727 as_bad (_("register number out of range"));
1730 tok
->X_op
= O_register
;
1731 tok
->X_add_symbol
= 0;
1732 tok
->X_add_number
= reg
;
1737 /* Split up the arguments for an opcode or pseudo-op. */
1740 tokenize_arguments (args
, str
)
1744 char *old_input_line_pointer
;
1745 bfd_boolean saw_comma
= FALSE
;
1746 bfd_boolean saw_arg
= FALSE
;
1748 char *arg_end
, *arg
;
1751 /* Save and restore input_line_pointer around this function. */
1752 old_input_line_pointer
= input_line_pointer
;
1753 input_line_pointer
= str
;
1755 while (*input_line_pointer
)
1758 switch (*input_line_pointer
)
1764 input_line_pointer
++;
1765 if (saw_comma
|| !saw_arg
)
1771 if (!saw_comma
&& saw_arg
)
1774 arg_end
= input_line_pointer
+ 1;
1775 while (!expression_end (arg_end
))
1778 arg_len
= arg_end
- input_line_pointer
;
1779 arg
= (char *) xmalloc (arg_len
+ 1);
1780 args
[num_args
] = arg
;
1782 strncpy (arg
, input_line_pointer
, arg_len
);
1783 arg
[arg_len
] = '\0';
1785 input_line_pointer
= arg_end
;
1796 input_line_pointer
= old_input_line_pointer
;
1800 input_line_pointer
= old_input_line_pointer
;
1805 /* Parse the arguments to an opcode. Return true on error. */
1808 parse_arguments (insn
, num_args
, arg_strings
)
1813 expressionS
*tok
= insn
->tok
;
1814 xtensa_opcode opcode
= insn
->opcode
;
1815 bfd_boolean had_error
= TRUE
;
1816 xtensa_isa isa
= xtensa_default_isa
;
1818 int opcode_operand_count
;
1819 int actual_operand_count
= 0;
1820 xtensa_operand opnd
= NULL
;
1821 char *old_input_line_pointer
;
1823 if (insn
->insn_type
== ITYPE_LITERAL
)
1824 opcode_operand_count
= 1;
1826 opcode_operand_count
= xtensa_num_operands (isa
, opcode
);
1828 memset (tok
, 0, sizeof (*tok
) * MAX_INSN_ARGS
);
1830 /* Save and restore input_line_pointer around this function. */
1831 old_input_line_pointer
= input_line_pointer
;
1833 for (n
= 0; n
< num_args
; n
++)
1835 input_line_pointer
= arg_strings
[n
];
1837 if (actual_operand_count
>= opcode_operand_count
)
1839 as_warn (_("too many arguments"));
1842 assert (actual_operand_count
< MAX_INSN_ARGS
);
1844 opnd
= xtensa_get_operand (isa
, opcode
, actual_operand_count
);
1845 expression_maybe_register (opnd
, tok
);
1847 if (tok
->X_op
== O_illegal
|| tok
->X_op
== O_absent
)
1849 actual_operand_count
++;
1853 insn
->ntok
= tok
- insn
->tok
;
1857 input_line_pointer
= old_input_line_pointer
;
1863 xg_reverse_shift_count (cnt_argp
)
1866 char *cnt_arg
, *new_arg
;
1867 cnt_arg
= *cnt_argp
;
1869 /* replace the argument with "31-(argument)" */
1870 new_arg
= (char *) xmalloc (strlen (cnt_arg
) + 6);
1871 sprintf (new_arg
, "31-(%s)", cnt_arg
);
1874 *cnt_argp
= new_arg
;
1878 /* If "arg" is a constant expression, return non-zero with the value
1882 xg_arg_is_constant (arg
, valp
)
1887 char *save_ptr
= input_line_pointer
;
1889 input_line_pointer
= arg
;
1891 input_line_pointer
= save_ptr
;
1893 if (exp
.X_op
== O_constant
)
1895 *valp
= exp
.X_add_number
;
1904 xg_replace_opname (popname
, newop
)
1909 *popname
= (char *) xmalloc (strlen (newop
) + 1);
1910 strcpy (*popname
, newop
);
1915 xg_check_num_args (pnum_args
, expected_num
, opname
, arg_strings
)
1921 int num_args
= *pnum_args
;
1923 if (num_args
< expected_num
)
1925 as_bad (_("not enough operands (%d) for '%s'; expected %d"),
1926 num_args
, opname
, expected_num
);
1930 if (num_args
> expected_num
)
1932 as_warn (_("too many operands (%d) for '%s'; expected %d"),
1933 num_args
, opname
, expected_num
);
1934 while (num_args
-- > expected_num
)
1936 free (arg_strings
[num_args
]);
1937 arg_strings
[num_args
] = 0;
1939 *pnum_args
= expected_num
;
1948 xg_translate_sysreg_op (popname
, pnum_args
, arg_strings
)
1953 char *opname
, *new_opname
;
1955 bfd_boolean has_underbar
= FALSE
;
1960 has_underbar
= TRUE
;
1964 /* Opname == [rw]ur... */
1966 if (opname
[3] == '\0')
1968 /* If the register is not specified as part of the opcode,
1969 then get it from the operand and move it to the opcode. */
1971 if (xg_check_num_args (pnum_args
, 2, opname
, arg_strings
))
1974 if (!xg_arg_is_constant (arg_strings
[1], &val
))
1976 as_bad (_("register number for `%s' is not a constant"), opname
);
1979 if ((unsigned) val
> 255)
1981 as_bad (_("register number (%ld) for `%s' is out of range"),
1986 /* Remove the last argument, which is now part of the opcode. */
1987 free (arg_strings
[1]);
1991 /* Translate the opcode. */
1992 new_opname
= (char *) xmalloc (8);
1993 sprintf (new_opname
, "%s%cur%u", (has_underbar
? "_" : ""),
1994 opname
[0], (unsigned) val
);
1996 *popname
= new_opname
;
2003 /* If the instruction is an idiom (i.e., a built-in macro), translate it.
2004 Returns non-zero if an error was found. */
2007 xg_translate_idioms (popname
, pnum_args
, arg_strings
)
2012 char *opname
= *popname
;
2013 bfd_boolean has_underbar
= FALSE
;
2017 has_underbar
= TRUE
;
2021 if (strcmp (opname
, "mov") == 0)
2023 if (!has_underbar
&& code_density_available ())
2024 xg_replace_opname (popname
, "mov.n");
2027 if (xg_check_num_args (pnum_args
, 2, opname
, arg_strings
))
2029 xg_replace_opname (popname
, (has_underbar
? "_or" : "or"));
2030 arg_strings
[2] = (char *) xmalloc (strlen (arg_strings
[1]) + 1);
2031 strcpy (arg_strings
[2], arg_strings
[1]);
2037 if (strcmp (opname
, "bbsi.l") == 0)
2039 if (xg_check_num_args (pnum_args
, 3, opname
, arg_strings
))
2041 xg_replace_opname (popname
, (has_underbar
? "_bbsi" : "bbsi"));
2042 if (target_big_endian
)
2043 xg_reverse_shift_count (&arg_strings
[1]);
2047 if (strcmp (opname
, "bbci.l") == 0)
2049 if (xg_check_num_args (pnum_args
, 3, opname
, arg_strings
))
2051 xg_replace_opname (popname
, (has_underbar
? "_bbci" : "bbci"));
2052 if (target_big_endian
)
2053 xg_reverse_shift_count (&arg_strings
[1]);
2057 if (strcmp (opname
, "nop") == 0)
2059 if (!has_underbar
&& code_density_available ())
2060 xg_replace_opname (popname
, "nop.n");
2063 if (xg_check_num_args (pnum_args
, 0, opname
, arg_strings
))
2065 xg_replace_opname (popname
, (has_underbar
? "_or" : "or"));
2066 arg_strings
[0] = (char *) xmalloc (3);
2067 arg_strings
[1] = (char *) xmalloc (3);
2068 arg_strings
[2] = (char *) xmalloc (3);
2069 strcpy (arg_strings
[0], "a1");
2070 strcpy (arg_strings
[1], "a1");
2071 strcpy (arg_strings
[2], "a1");
2077 if ((opname
[0] == 'r' || opname
[0] == 'w')
2079 && opname
[2] == 'r')
2080 return xg_translate_sysreg_op (popname
, pnum_args
, arg_strings
);
2083 /* WIDENING DENSITY OPCODES
2085 questionable relaxations (widening) from old "tai" idioms:
2095 Note: this incomplete list was imported to match the "tai"
2096 behavior; other density opcodes are not handled.
2098 The xtensa-relax code may know how to do these but it doesn't do
2099 anything when these density opcodes appear inside a no-density
2100 region. Somehow GAS should either print an error when that happens
2101 or do the widening. The old "tai" behavior was to do the widening.
2102 For now, I'll make it widen but print a warning.
2104 FIXME: GAS needs to detect density opcodes inside no-density
2105 regions and treat them as errors. This code should be removed
2106 when that is done. */
2110 && density_supported
2111 && !code_density_available ())
2113 if (strcmp (opname
, "add.n") == 0)
2114 xg_replace_opname (popname
, "add");
2116 else if (strcmp (opname
, "beqz.n") == 0)
2117 xg_replace_opname (popname
, "beqz");
2119 else if (strcmp (opname
, "ret.n") == 0)
2120 xg_replace_opname (popname
, "ret");
2122 else if (strcmp (opname
, "retw.n") == 0)
2123 xg_replace_opname (popname
, "retw");
2125 else if (strcmp (opname
, "movi.n") == 0)
2126 xg_replace_opname (popname
, "movi");
2128 else if (strcmp (opname
, "mov.n") == 0)
2130 if (xg_check_num_args (pnum_args
, 2, opname
, arg_strings
))
2132 xg_replace_opname (popname
, "or");
2133 arg_strings
[2] = (char *) xmalloc (strlen (arg_strings
[1]) + 1);
2134 strcpy (arg_strings
[2], arg_strings
[1]);
2138 else if (strcmp (opname
, "nop.n") == 0)
2140 if (xg_check_num_args (pnum_args
, 0, opname
, arg_strings
))
2142 xg_replace_opname (popname
, "or");
2143 arg_strings
[0] = (char *) xmalloc (3);
2144 arg_strings
[1] = (char *) xmalloc (3);
2145 arg_strings
[2] = (char *) xmalloc (3);
2146 strcpy (arg_strings
[0], "a1");
2147 strcpy (arg_strings
[1], "a1");
2148 strcpy (arg_strings
[2], "a1");
2157 /* Functions for dealing with the Xtensa ISA. */
2159 /* Return true if the given operand is an immed or target instruction,
2160 i.e., has a reloc associated with it. Currently, this is only true
2161 if the operand kind is "i, "l" or "L". */
2164 operand_is_immed (opnd
)
2165 xtensa_operand opnd
;
2167 const char *opkind
= xtensa_operand_kind (opnd
);
2168 if (opkind
[0] == '\0' || opkind
[1] != '\0')
2181 /* Return true if the given operand is a pc-relative label. This is
2182 true for "l", "L", and "r" operand kinds. */
2185 operand_is_pcrel_label (opnd
)
2186 xtensa_operand opnd
;
2188 const char *opkind
= xtensa_operand_kind (opnd
);
2189 if (opkind
[0] == '\0' || opkind
[1] != '\0')
2202 /* Currently the assembler only allows us to use a single target per
2203 fragment. Because of this, only one operand for a given
2204 instruction may be symbolic. If there is an operand of kind "lrL",
2205 the last one is chosen. Otherwise, the result is the number of the
2206 last operand of type "i", and if there are none of those, we fail
2210 get_relaxable_immed (opcode
)
2211 xtensa_opcode opcode
;
2213 int last_immed
= -1;
2215 xtensa_operand operand
;
2217 if (opcode
== XTENSA_UNDEFINED
)
2220 noperands
= xtensa_num_operands (xtensa_default_isa
, opcode
);
2221 for (opi
= noperands
- 1; opi
>= 0; opi
--)
2223 operand
= xtensa_get_operand (xtensa_default_isa
, opcode
, opi
);
2224 if (operand_is_pcrel_label (operand
))
2226 if (last_immed
== -1 && operand_is_immed (operand
))
2234 get_opcode_from_buf (buf
)
2237 static xtensa_insnbuf insnbuf
= NULL
;
2238 xtensa_opcode opcode
;
2239 xtensa_isa isa
= xtensa_default_isa
;
2241 insnbuf
= xtensa_insnbuf_alloc (isa
);
2243 xtensa_insnbuf_from_chars (isa
, insnbuf
, buf
);
2244 opcode
= xtensa_decode_insn (isa
, insnbuf
);
2250 is_direct_call_opcode (opcode
)
2251 xtensa_opcode opcode
;
2253 if (opcode
== XTENSA_UNDEFINED
)
2256 return (opcode
== xtensa_call0_opcode
2257 || opcode
== xtensa_call4_opcode
2258 || opcode
== xtensa_call8_opcode
2259 || opcode
== xtensa_call12_opcode
);
2264 is_call_opcode (opcode
)
2265 xtensa_opcode opcode
;
2267 if (is_direct_call_opcode (opcode
))
2270 if (opcode
== XTENSA_UNDEFINED
)
2273 return (opcode
== xtensa_callx0_opcode
2274 || opcode
== xtensa_callx4_opcode
2275 || opcode
== xtensa_callx8_opcode
2276 || opcode
== xtensa_callx12_opcode
);
2280 /* Return true if the opcode is an entry opcode. This is used because
2281 "entry" adds an implicit ".align 4" and also the entry instruction
2282 has an extra check for an operand value. */
2285 is_entry_opcode (opcode
)
2286 xtensa_opcode opcode
;
2288 if (opcode
== XTENSA_UNDEFINED
)
2291 return (opcode
== xtensa_entry_opcode
);
2295 /* Return true if it is one of the loop opcodes. Loops are special
2296 because they need automatic alignment and they have a relaxation so
2297 complex that we hard-coded it. */
2300 is_loop_opcode (opcode
)
2301 xtensa_opcode opcode
;
2303 if (opcode
== XTENSA_UNDEFINED
)
2306 return (opcode
== xtensa_loop_opcode
2307 || opcode
== xtensa_loopnez_opcode
2308 || opcode
== xtensa_loopgtz_opcode
);
2313 is_the_loop_opcode (opcode
)
2314 xtensa_opcode opcode
;
2316 if (opcode
== XTENSA_UNDEFINED
)
2319 return (opcode
== xtensa_loop_opcode
);
2324 is_jx_opcode (opcode
)
2325 xtensa_opcode opcode
;
2327 if (opcode
== XTENSA_UNDEFINED
)
2330 return (opcode
== xtensa_jx_opcode
);
2334 /* Return true if the opcode is a retw or retw.n.
2335 Needed to add nops to avoid a hardware interlock issue. */
2338 is_windowed_return_opcode (opcode
)
2339 xtensa_opcode opcode
;
2341 if (opcode
== XTENSA_UNDEFINED
)
2344 return (opcode
== xtensa_retw_opcode
|| opcode
== xtensa_retw_n_opcode
);
2348 /* Return true if the opcode type is "l" and the opcode is NOT a jump. */
2351 is_conditional_branch_opcode (opcode
)
2352 xtensa_opcode opcode
;
2354 xtensa_isa isa
= xtensa_default_isa
;
2357 if (opcode
== xtensa_j_opcode
&& opcode
!= XTENSA_UNDEFINED
)
2360 num_ops
= xtensa_num_operands (isa
, opcode
);
2361 for (i
= 0; i
< num_ops
; i
++)
2363 xtensa_operand operand
= xtensa_get_operand (isa
, opcode
, i
);
2364 if (strcmp (xtensa_operand_kind (operand
), "l") == 0)
2371 /* Return true if the given opcode is a conditional branch
2372 instruction, i.e., currently this is true if the instruction
2373 is a jx or has an operand with 'l' type and is not a loop. */
2376 is_branch_or_jump_opcode (opcode
)
2377 xtensa_opcode opcode
;
2381 if (opcode
== XTENSA_UNDEFINED
)
2384 if (is_loop_opcode (opcode
))
2387 if (is_jx_opcode (opcode
))
2390 op_count
= xtensa_num_operands (xtensa_default_isa
, opcode
);
2391 for (opn
= 0; opn
< op_count
; opn
++)
2393 xtensa_operand opnd
=
2394 xtensa_get_operand (xtensa_default_isa
, opcode
, opn
);
2395 const char *opkind
= xtensa_operand_kind (opnd
);
2396 if (opkind
&& opkind
[0] == 'l' && opkind
[1] == '\0')
2403 /* Convert from operand numbers to BFD relocation type code.
2404 Return BFD_RELOC_NONE on failure. */
2406 bfd_reloc_code_real_type
2407 opnum_to_reloc (opnum
)
2413 return BFD_RELOC_XTENSA_OP0
;
2415 return BFD_RELOC_XTENSA_OP1
;
2417 return BFD_RELOC_XTENSA_OP2
;
2421 return BFD_RELOC_NONE
;
2425 /* Convert from BFD relocation type code to operand number.
2426 Return -1 on failure. */
2429 reloc_to_opnum (reloc
)
2430 bfd_reloc_code_real_type reloc
;
2434 case BFD_RELOC_XTENSA_OP0
:
2436 case BFD_RELOC_XTENSA_OP1
:
2438 case BFD_RELOC_XTENSA_OP2
:
2448 xtensa_insnbuf_set_operand (insnbuf
, opcode
, operand
, value
, file
, line
)
2449 xtensa_insnbuf insnbuf
;
2450 xtensa_opcode opcode
;
2451 xtensa_operand operand
;
2456 xtensa_encode_result encode_result
;
2457 uint32 valbuf
= value
;
2459 encode_result
= xtensa_operand_encode (operand
, &valbuf
);
2461 switch (encode_result
)
2463 case xtensa_encode_result_ok
:
2465 case xtensa_encode_result_align
:
2466 as_bad_where ((char *) file
, line
,
2467 _("operand %d not properly aligned for '%s'"),
2468 value
, xtensa_opcode_name (xtensa_default_isa
, opcode
));
2470 case xtensa_encode_result_not_in_table
:
2471 as_bad_where ((char *) file
, line
,
2472 _("operand %d not in immediate table for '%s'"),
2473 value
, xtensa_opcode_name (xtensa_default_isa
, opcode
));
2475 case xtensa_encode_result_too_high
:
2476 as_bad_where ((char *) file
, line
,
2477 _("operand %d too large for '%s'"), value
,
2478 xtensa_opcode_name (xtensa_default_isa
, opcode
));
2480 case xtensa_encode_result_too_low
:
2481 as_bad_where ((char *) file
, line
,
2482 _("operand %d too small for '%s'"), value
,
2483 xtensa_opcode_name (xtensa_default_isa
, opcode
));
2485 case xtensa_encode_result_not_ok
:
2486 as_bad_where ((char *) file
, line
,
2487 _("operand %d is invalid for '%s'"), value
,
2488 xtensa_opcode_name (xtensa_default_isa
, opcode
));
2494 xtensa_operand_set_field (operand
, insnbuf
, valbuf
);
2499 xtensa_insnbuf_get_operand (insnbuf
, opcode
, opnum
)
2500 xtensa_insnbuf insnbuf
;
2501 xtensa_opcode opcode
;
2504 xtensa_operand op
= xtensa_get_operand (xtensa_default_isa
, opcode
, opnum
);
2505 return xtensa_operand_decode (op
, xtensa_operand_get_field (op
, insnbuf
));
2510 xtensa_insnbuf_set_immediate_field (opcode
, insnbuf
, value
, file
, line
)
2511 xtensa_opcode opcode
;
2512 xtensa_insnbuf insnbuf
;
2517 xtensa_isa isa
= xtensa_default_isa
;
2518 int last_opnd
= xtensa_num_operands (isa
, opcode
) - 1;
2519 xtensa_operand operand
= xtensa_get_operand (isa
, opcode
, last_opnd
);
2520 xtensa_insnbuf_set_operand (insnbuf
, opcode
, operand
, value
, file
, line
);
2525 is_negatable_branch (insn
)
2528 xtensa_isa isa
= xtensa_default_isa
;
2530 int num_ops
= xtensa_num_operands (isa
, insn
->opcode
);
2532 for (i
= 0; i
< num_ops
; i
++)
2534 xtensa_operand opnd
= xtensa_get_operand (isa
, insn
->opcode
, i
);
2535 char *kind
= xtensa_operand_kind (opnd
);
2536 if (strlen (kind
) == 1 && *kind
== 'l')
2543 /* Lists for recording various properties of symbols. */
2545 typedef struct symbol_consS_struct
2548 /* These are used for the target taken. */
2549 int is_loop_target
:1;
2550 int is_branch_target
:1;
2553 struct symbol_consS_struct
*rest
;
2556 symbol_consS
*defined_symbols
= 0;
2557 symbol_consS
*branch_targets
= 0;
2561 xtensa_define_label (sym
)
2564 symbol_consS
*cons
= (symbol_consS
*) xmalloc (sizeof (symbol_consS
));
2567 cons
->is_branch_target
= 0;
2568 cons
->is_loop_target
= 0;
2569 cons
->is_literal
= generating_literals
? 1 : 0;
2571 cons
->rest
= defined_symbols
;
2572 defined_symbols
= cons
;
2577 add_target_symbol (sym
, is_loop
)
2579 bfd_boolean is_loop
;
2581 symbol_consS
*cons
, *sym_e
;
2583 for (sym_e
= branch_targets
; sym_e
; sym_e
= sym_e
->rest
)
2585 if (sym_e
->first
== sym
)
2588 sym_e
->is_loop_target
= 1;
2590 sym_e
->is_branch_target
= 1;
2595 cons
= (symbol_consS
*) xmalloc (sizeof (symbol_consS
));
2597 cons
->is_branch_target
= (is_loop
? 0 : 1);
2598 cons
->is_loop_target
= (is_loop
? 1 : 0);
2599 cons
->rest
= branch_targets
;
2600 branch_targets
= cons
;
2604 /* Find the symbol at a given position. (Note: the "loops_ok"
2605 argument is provided to allow ignoring labels that define loop
2606 ends. This fixes a bug where the NOPs to align a loop opcode were
2607 included in a previous zero-cost loop:
2626 This argument is used to prevent moving the NOP to before the
2627 loop-end label, which is what you want in this special case.) */
2630 xtensa_find_label (fragP
, offset
, loops_ok
)
2633 bfd_boolean loops_ok
;
2635 symbol_consS
*consP
;
2637 for (consP
= defined_symbols
; consP
; consP
= consP
->rest
)
2639 symbolS
*symP
= consP
->first
;
2641 if (S_GET_SEGMENT (symP
) == now_seg
2642 && symbol_get_frag (symP
) == fragP
2643 && symbol_constant_p (symP
)
2644 && S_GET_VALUE (symP
) == fragP
->fr_address
+ (unsigned) offset
2645 && (loops_ok
|| !is_loop_target_label (symP
)))
2653 map_over_defined_symbols (fn
)
2654 void (*fn
) PARAMS ((symbolS
*));
2656 symbol_consS
*sym_cons
;
2658 for (sym_cons
= defined_symbols
; sym_cons
; sym_cons
= sym_cons
->rest
)
2659 fn (sym_cons
->first
);
2664 is_loop_target_label (sym
)
2667 symbol_consS
*sym_e
;
2669 for (sym_e
= branch_targets
; sym_e
; sym_e
= sym_e
->rest
)
2671 if (sym_e
->first
== sym
)
2672 return sym_e
->is_loop_target
;
2678 /* Walk over all of the symbols that are branch target labels and
2679 loop target labels. Mark the associated fragments for these with
2680 the appropriate flags. */
2683 xtensa_mark_target_fragments ()
2685 symbol_consS
*sym_e
;
2687 for (sym_e
= branch_targets
; sym_e
; sym_e
= sym_e
->rest
)
2689 symbolS
*sym
= sym_e
->first
;
2691 if (symbol_get_frag (sym
)
2692 && symbol_constant_p (sym
)
2693 && S_GET_VALUE (sym
) == 0)
2695 if (sym_e
->is_branch_target
)
2696 symbol_get_frag (sym
)->tc_frag_data
.is_branch_target
= TRUE
;
2697 if (sym_e
->is_loop_target
)
2698 symbol_get_frag (sym
)->tc_frag_data
.is_loop_target
= TRUE
;
2704 /* Various Other Internal Functions. */
2707 is_unique_insn_expansion (r
)
2710 if (!r
->to_instr
|| r
->to_instr
->next
!= NULL
)
2712 if (r
->to_instr
->typ
!= INSTR_INSTR
)
2719 xg_get_insn_size (insn
)
2722 assert (insn
->insn_type
== ITYPE_INSN
);
2723 return xtensa_insn_length (xtensa_default_isa
, insn
->opcode
);
2728 xg_get_build_instr_size (insn
)
2731 assert (insn
->typ
== INSTR_INSTR
);
2732 return xtensa_insn_length (xtensa_default_isa
, insn
->opcode
);
2737 xg_is_narrow_insn (insn
)
2740 TransitionTable
*table
= xg_build_widen_table ();
2743 assert (insn
->insn_type
== ITYPE_INSN
);
2744 assert (insn
->opcode
< table
->num_opcodes
);
2746 for (l
= table
->table
[insn
->opcode
]; l
!= NULL
; l
= l
->next
)
2748 TransitionRule
*rule
= l
->rule
;
2750 if (xg_instruction_matches_rule (insn
, rule
)
2751 && is_unique_insn_expansion (rule
))
2753 /* It only generates one instruction... */
2754 assert (insn
->insn_type
== ITYPE_INSN
);
2755 /* ...and it is a larger instruction. */
2756 if (xg_get_insn_size (insn
)
2757 < xg_get_build_instr_size (rule
->to_instr
))
2765 return (num_match
== 1);
2770 xg_is_single_relaxable_insn (insn
)
2773 TransitionTable
*table
= xg_build_widen_table ();
2776 assert (insn
->insn_type
== ITYPE_INSN
);
2777 assert (insn
->opcode
< table
->num_opcodes
);
2779 for (l
= table
->table
[insn
->opcode
]; l
!= NULL
; l
= l
->next
)
2781 TransitionRule
*rule
= l
->rule
;
2783 if (xg_instruction_matches_rule (insn
, rule
)
2784 && is_unique_insn_expansion (rule
))
2786 assert (insn
->insn_type
== ITYPE_INSN
);
2787 /* ... and it is a larger instruction. */
2788 if (xg_get_insn_size (insn
)
2789 <= xg_get_build_instr_size (rule
->to_instr
))
2797 return (num_match
== 1);
2801 /* Return the largest size instruction that this instruction can
2802 expand to. Currently, in all cases, this is 3 bytes. Of course we
2803 could just calculate this once and generate a table. */
2806 xg_get_max_narrow_insn_size (opcode
)
2807 xtensa_opcode opcode
;
2809 /* Go ahead and compute it, but it better be 3. */
2810 TransitionTable
*table
= xg_build_widen_table ();
2812 int old_size
= xtensa_insn_length (xtensa_default_isa
, opcode
);
2813 assert (opcode
< table
->num_opcodes
);
2815 /* Actually we can do better. Check to see of Only one applies. */
2816 for (l
= table
->table
[opcode
]; l
!= NULL
; l
= l
->next
)
2818 TransitionRule
*rule
= l
->rule
;
2820 /* If it only generates one instruction. */
2821 if (is_unique_insn_expansion (rule
))
2823 int new_size
= xtensa_insn_length (xtensa_default_isa
,
2824 rule
->to_instr
->opcode
);
2825 if (new_size
> old_size
)
2827 assert (new_size
== 3);
2836 /* Return the maximum number of bytes this opcode can expand to. */
2839 xg_get_max_insn_widen_size (opcode
)
2840 xtensa_opcode opcode
;
2842 TransitionTable
*table
= xg_build_widen_table ();
2844 int max_size
= xtensa_insn_length (xtensa_default_isa
, opcode
);
2846 assert (opcode
< table
->num_opcodes
);
2848 for (l
= table
->table
[opcode
]; l
!= NULL
; l
= l
->next
)
2850 TransitionRule
*rule
= l
->rule
;
2851 BuildInstr
*build_list
;
2856 build_list
= rule
->to_instr
;
2857 if (is_unique_insn_expansion (rule
))
2859 assert (build_list
->typ
== INSTR_INSTR
);
2860 this_size
= xg_get_max_insn_widen_size (build_list
->opcode
);
2863 for (; build_list
!= NULL
; build_list
= build_list
->next
)
2865 switch (build_list
->typ
)
2868 this_size
+= xtensa_insn_length (xtensa_default_isa
,
2869 build_list
->opcode
);
2872 case INSTR_LITERAL_DEF
:
2873 case INSTR_LABEL_DEF
:
2878 if (this_size
> max_size
)
2879 max_size
= this_size
;
2885 /* Return the maximum number of literal bytes this opcode can generate. */
2888 xg_get_max_insn_widen_literal_size (opcode
)
2889 xtensa_opcode opcode
;
2891 TransitionTable
*table
= xg_build_widen_table ();
2895 assert (opcode
< table
->num_opcodes
);
2897 for (l
= table
->table
[opcode
]; l
!= NULL
; l
= l
->next
)
2899 TransitionRule
*rule
= l
->rule
;
2900 BuildInstr
*build_list
;
2905 build_list
= rule
->to_instr
;
2906 if (is_unique_insn_expansion (rule
))
2908 assert (build_list
->typ
== INSTR_INSTR
);
2909 this_size
= xg_get_max_insn_widen_literal_size (build_list
->opcode
);
2912 for (; build_list
!= NULL
; build_list
= build_list
->next
)
2914 switch (build_list
->typ
)
2916 case INSTR_LITERAL_DEF
:
2917 /* hard coded 4-byte literal. */
2921 case INSTR_LABEL_DEF
:
2926 if (this_size
> max_size
)
2927 max_size
= this_size
;
2934 xg_is_relaxable_insn (insn
, lateral_steps
)
2938 int steps_taken
= 0;
2939 TransitionTable
*table
= xg_build_widen_table ();
2942 assert (insn
->insn_type
== ITYPE_INSN
);
2943 assert (insn
->opcode
< table
->num_opcodes
);
2945 for (l
= table
->table
[insn
->opcode
]; l
!= NULL
; l
= l
->next
)
2947 TransitionRule
*rule
= l
->rule
;
2949 if (xg_instruction_matches_rule (insn
, rule
))
2951 if (steps_taken
== lateral_steps
)
2961 get_special_literal_symbol ()
2963 static symbolS
*sym
= NULL
;
2966 sym
= symbol_find_or_make ("SPECIAL_LITERAL0\001");
2972 get_special_label_symbol ()
2974 static symbolS
*sym
= NULL
;
2977 sym
= symbol_find_or_make ("SPECIAL_LABEL0\001");
2982 /* Return true on success. */
2985 xg_build_to_insn (targ
, insn
, bi
)
2993 memset (targ
, 0, sizeof (TInsn
));
2998 targ
->opcode
= bi
->opcode
;
2999 targ
->insn_type
= ITYPE_INSN
;
3000 targ
->is_specific_opcode
= FALSE
;
3002 for (; op
!= NULL
; op
= op
->next
)
3004 int op_num
= op
->op_num
;
3005 int op_data
= op
->op_data
;
3007 assert (op
->op_num
< MAX_INSN_ARGS
);
3009 if (targ
->ntok
<= op_num
)
3010 targ
->ntok
= op_num
+ 1;
3015 set_expr_const (&targ
->tok
[op_num
], op_data
);
3018 assert (op_data
< insn
->ntok
);
3019 copy_expr (&targ
->tok
[op_num
], &insn
->tok
[op_data
]);
3022 sym
= get_special_literal_symbol ();
3023 set_expr_symbol_offset (&targ
->tok
[op_num
], sym
, 0);
3026 sym
= get_special_label_symbol ();
3027 set_expr_symbol_offset (&targ
->tok
[op_num
], sym
, 0);
3030 /* currently handles:
3033 OP_OPERAND_F32MINUS */
3034 if (xg_has_userdef_op_fn (op
->typ
))
3036 assert (op_data
< insn
->ntok
);
3037 if (expr_is_const (&insn
->tok
[op_data
]))
3040 copy_expr (&targ
->tok
[op_num
], &insn
->tok
[op_data
]);
3041 val
= xg_apply_userdef_op_fn (op
->typ
,
3044 targ
->tok
[op_num
].X_add_number
= val
;
3047 return FALSE
; /* We cannot use a relocation for this. */
3056 case INSTR_LITERAL_DEF
:
3058 targ
->opcode
= XTENSA_UNDEFINED
;
3059 targ
->insn_type
= ITYPE_LITERAL
;
3060 targ
->is_specific_opcode
= FALSE
;
3061 for (; op
!= NULL
; op
= op
->next
)
3063 int op_num
= op
->op_num
;
3064 int op_data
= op
->op_data
;
3065 assert (op
->op_num
< MAX_INSN_ARGS
);
3067 if (targ
->ntok
<= op_num
)
3068 targ
->ntok
= op_num
+ 1;
3073 assert (op_data
< insn
->ntok
);
3074 copy_expr (&targ
->tok
[op_num
], &insn
->tok
[op_data
]);
3086 case INSTR_LABEL_DEF
:
3088 targ
->opcode
= XTENSA_UNDEFINED
;
3089 targ
->insn_type
= ITYPE_LABEL
;
3090 targ
->is_specific_opcode
= FALSE
;
3091 /* Literal with no ops. is a label? */
3092 assert (op
== NULL
);
3103 /* Return true on success. */
3106 xg_build_to_stack (istack
, insn
, bi
)
3111 for (; bi
!= NULL
; bi
= bi
->next
)
3113 TInsn
*next_insn
= istack_push_space (istack
);
3115 if (!xg_build_to_insn (next_insn
, insn
, bi
))
3122 /* Return true on valid expansion. */
3125 xg_expand_to_stack (istack
, insn
, lateral_steps
)
3130 int stack_size
= istack
->ninsn
;
3131 int steps_taken
= 0;
3132 TransitionTable
*table
= xg_build_widen_table ();
3135 assert (insn
->insn_type
== ITYPE_INSN
);
3136 assert (insn
->opcode
< table
->num_opcodes
);
3138 for (l
= table
->table
[insn
->opcode
]; l
!= NULL
; l
= l
->next
)
3140 TransitionRule
*rule
= l
->rule
;
3142 if (xg_instruction_matches_rule (insn
, rule
))
3144 if (lateral_steps
== steps_taken
)
3148 /* This is it. Expand the rule to the stack. */
3149 if (!xg_build_to_stack (istack
, insn
, rule
->to_instr
))
3152 /* Check to see if it fits. */
3153 for (i
= stack_size
; i
< istack
->ninsn
; i
++)
3155 TInsn
*insn
= &istack
->insn
[i
];
3157 if (insn
->insn_type
== ITYPE_INSN
3158 && !tinsn_has_symbolic_operands (insn
)
3159 && !xg_immeds_fit (insn
))
3161 istack
->ninsn
= stack_size
;
3175 xg_expand_narrow (targ
, insn
)
3179 TransitionTable
*table
= xg_build_widen_table ();
3182 assert (insn
->insn_type
== ITYPE_INSN
);
3183 assert (insn
->opcode
< table
->num_opcodes
);
3185 for (l
= table
->table
[insn
->opcode
]; l
!= NULL
; l
= l
->next
)
3187 TransitionRule
*rule
= l
->rule
;
3188 if (xg_instruction_matches_rule (insn
, rule
)
3189 && is_unique_insn_expansion (rule
))
3191 /* Is it a larger instruction? */
3192 if (xg_get_insn_size (insn
)
3193 <= xg_get_build_instr_size (rule
->to_instr
))
3195 xg_build_to_insn (targ
, insn
, rule
->to_instr
);
3204 /* Assumes: All immeds are constants. Check that all constants fit
3205 into their immeds; return false if not. */
3208 xg_immeds_fit (insn
)
3214 assert (insn
->insn_type
== ITYPE_INSN
);
3215 for (i
= 0; i
< n
; ++i
)
3217 const expressionS
*expr
= &insn
->tok
[i
];
3218 xtensa_operand opnd
= xtensa_get_operand (xtensa_default_isa
,
3220 if (!operand_is_immed (opnd
))
3228 if (xg_check_operand (expr
->X_add_number
, opnd
))
3233 /* The symbol should have a fixup associated with it. */
3242 /* This should only be called after we have an initial
3243 estimate of the addresses. */
3246 xg_symbolic_immeds_fit (insn
, pc_seg
, pc_frag
, pc_offset
, stretch
)
3254 offsetT target
, pc
, new_offset
;
3258 assert (insn
->insn_type
== ITYPE_INSN
);
3260 for (i
= 0; i
< n
; ++i
)
3262 const expressionS
*expr
= &insn
->tok
[i
];
3263 xtensa_operand opnd
= xtensa_get_operand (xtensa_default_isa
,
3265 if (!operand_is_immed (opnd
))
3272 if (xg_check_operand (expr
->X_add_number
, opnd
))
3277 /* We only allow symbols for pc-relative stuff.
3278 If pc_frag == 0, then we don't have frag locations yet. */
3282 /* If it is PC-relative and the symbol is in the same segment as
3284 if (!xtensa_operand_isPCRelative (opnd
)
3285 || S_GET_SEGMENT (expr
->X_add_symbol
) != pc_seg
)
3288 symbolP
= expr
->X_add_symbol
;
3289 target
= S_GET_VALUE (symbolP
) + expr
->X_add_number
;
3290 pc
= pc_frag
->fr_address
+ pc_offset
;
3292 /* If frag has yet to be reached on this pass, assume it
3293 will move by STRETCH just as we did. If this is not so,
3294 it will be because some frag between grows, and that will
3295 force another pass. Beware zero-length frags. There
3296 should be a faster way to do this. */
3298 if (stretch
&& is_dnrange (pc_frag
, symbolP
, stretch
))
3301 new_offset
= xtensa_operand_do_reloc (opnd
, target
, pc
);
3302 if (xg_check_operand (new_offset
, opnd
))
3307 /* The symbol should have a fixup associated with it. */
3316 /* This will check to see if the value can be converted into the
3317 operand type. It will return true if it does not fit. */
3320 xg_check_operand (value
, operand
)
3322 xtensa_operand operand
;
3324 uint32 valbuf
= value
;
3325 return (xtensa_operand_encode (operand
, &valbuf
) != xtensa_encode_result_ok
);
3329 /* Check if a symbol is pointing to somewhere after
3330 the start frag, given that the segment has stretched
3331 by stretch during relaxation.
3333 This is more complicated than it might appear at first blush
3334 because of the stretching that goes on. Here is how the check
3337 If the symbol and the frag are in the same segment, then
3338 the symbol could be down range. Note that this function
3339 assumes that start_frag is in now_seg.
3341 If the symbol is pointing to a frag with an address greater than
3342 than the start_frag's address, then it _could_ be down range.
3344 The problem comes because target_frag may or may not have had
3345 stretch bytes added to its address already, depending on if it is
3346 before or after start frag. (And if we knew that, then we wouldn't
3347 need this function.) start_frag has definitely already had stretch
3348 bytes added to its address.
3350 If target_frag's address hasn't been adjusted yet, then to
3351 determine if it comes after start_frag, we need to subtract
3352 stretch from start_frag's address.
3354 If target_frag's address has been adjusted, then it might have
3355 been adjusted such that it comes after start_frag's address minus
3358 So, in that case, we scan for it down stream to within
3359 stretch bytes. We could search to the end of the fr_chain, but
3360 that ends up taking too much time (over a minute on some gnu
3364 is_dnrange (start_frag
, sym
, stretch
)
3369 if (S_GET_SEGMENT (sym
) == now_seg
)
3371 fragS
*cur_frag
= symbol_get_frag (sym
);
3373 if (cur_frag
->fr_address
>= start_frag
->fr_address
- stretch
)
3375 int distance
= stretch
;
3377 while (cur_frag
&& distance
>= 0)
3379 distance
-= cur_frag
->fr_fix
;
3380 if (cur_frag
== start_frag
)
3382 cur_frag
= cur_frag
->fr_next
;
3391 /* Relax the assembly instruction at least "min_steps".
3392 Return the number of steps taken. */
3395 xg_assembly_relax (istack
, insn
, pc_seg
, pc_frag
, pc_offset
, min_steps
,
3400 fragS
*pc_frag
; /* If pc_frag == 0, then no pc-relative. */
3401 offsetT pc_offset
; /* Offset in fragment. */
3402 int min_steps
; /* Minimum number of conversion steps. */
3403 long stretch
; /* Number of bytes stretched so far. */
3405 int steps_taken
= 0;
3407 /* assert (has no symbolic operands)
3408 Some of its immeds don't fit.
3409 Try to build a relaxed version.
3410 This may go through a couple of stages
3411 of single instruction transformations before
3414 TInsn single_target
;
3416 int lateral_steps
= 0;
3417 int istack_size
= istack
->ninsn
;
3419 if (xg_symbolic_immeds_fit (insn
, pc_seg
, pc_frag
, pc_offset
, stretch
)
3420 && steps_taken
>= min_steps
)
3422 istack_push (istack
, insn
);
3425 tinsn_copy (¤t_insn
, insn
);
3427 /* Walk through all of the single instruction expansions. */
3428 while (xg_is_single_relaxable_insn (¤t_insn
))
3430 int error_val
= xg_expand_narrow (&single_target
, ¤t_insn
);
3432 assert (!error_val
);
3434 if (xg_symbolic_immeds_fit (&single_target
, pc_seg
, pc_frag
, pc_offset
,
3438 if (steps_taken
>= min_steps
)
3440 istack_push (istack
, &single_target
);
3444 tinsn_copy (¤t_insn
, &single_target
);
3447 /* Now check for a multi-instruction expansion. */
3448 while (xg_is_relaxable_insn (¤t_insn
, lateral_steps
))
3450 if (xg_symbolic_immeds_fit (¤t_insn
, pc_seg
, pc_frag
, pc_offset
,
3453 if (steps_taken
>= min_steps
)
3455 istack_push (istack
, ¤t_insn
);
3460 if (xg_expand_to_stack (istack
, ¤t_insn
, lateral_steps
))
3462 if (steps_taken
>= min_steps
)
3466 istack
->ninsn
= istack_size
;
3469 /* It's not going to work -- use the original. */
3470 istack_push (istack
, insn
);
3476 xg_force_frag_space (size
)
3479 /* This may have the side effect of creating a new fragment for the
3480 space to go into. I just do not like the name of the "frag"
3487 xg_finish_frag (last_insn
, state
, max_growth
, is_insn
)
3489 enum xtensa_relax_statesE state
;
3491 bfd_boolean is_insn
;
3493 /* Finish off this fragment so that it has at LEAST the desired
3494 max_growth. If it doesn't fit in this fragment, close this one
3495 and start a new one. In either case, return a pointer to the
3496 beginning of the growth area. */
3499 xg_force_frag_space (max_growth
);
3501 old_frag
= frag_now
;
3503 frag_now
->fr_opcode
= last_insn
;
3505 frag_now
->tc_frag_data
.is_insn
= TRUE
;
3507 frag_var (rs_machine_dependent
, max_growth
, max_growth
,
3508 state
, frag_now
->fr_symbol
, frag_now
->fr_offset
, last_insn
);
3510 /* Just to make sure that we did not split it up. */
3511 assert (old_frag
->fr_next
== frag_now
);
3516 is_branch_jmp_to_next (insn
, fragP
)
3520 xtensa_isa isa
= xtensa_default_isa
;
3522 int num_ops
= xtensa_num_operands (isa
, insn
->opcode
);
3527 if (is_loop_opcode (insn
->opcode
))
3530 for (i
= 0; i
< num_ops
; i
++)
3532 xtensa_operand opnd
= xtensa_get_operand (isa
, insn
->opcode
, i
);
3533 char *kind
= xtensa_operand_kind (opnd
);
3534 if (strlen (kind
) == 1 && *kind
== 'l')
3540 if (target_op
== -1)
3543 if (insn
->ntok
<= target_op
)
3546 if (insn
->tok
[target_op
].X_op
!= O_symbol
)
3549 sym
= insn
->tok
[target_op
].X_add_symbol
;
3553 if (insn
->tok
[target_op
].X_add_number
!= 0)
3556 target_frag
= symbol_get_frag (sym
);
3557 if (target_frag
== NULL
)
3560 if (is_next_frag_target (fragP
->fr_next
, target_frag
)
3561 && S_GET_VALUE (sym
) == target_frag
->fr_address
)
3569 xg_add_branch_and_loop_targets (insn
)
3572 xtensa_isa isa
= xtensa_default_isa
;
3573 int num_ops
= xtensa_num_operands (isa
, insn
->opcode
);
3575 if (is_loop_opcode (insn
->opcode
))
3578 xtensa_operand opnd
= xtensa_get_operand (isa
, insn
->opcode
, i
);
3579 char *kind
= xtensa_operand_kind (opnd
);
3580 if (strlen (kind
) == 1 && *kind
== 'l')
3581 if (insn
->tok
[i
].X_op
== O_symbol
)
3582 add_target_symbol (insn
->tok
[i
].X_add_symbol
, TRUE
);
3586 /* Currently, we do not add branch targets. This is an optimization
3587 for later that tries to align only branch targets, not just any
3588 label in a text section. */
3590 if (align_only_targets
)
3594 for (i
= 0; i
< insn
->ntok
&& i
< num_ops
; i
++)
3596 xtensa_operand opnd
= xtensa_get_operand (isa
, insn
->opcode
, i
);
3597 char *kind
= xtensa_operand_kind (opnd
);
3598 if (strlen (kind
) == 1 && *kind
== 'l'
3599 && insn
->tok
[i
].X_op
== O_symbol
)
3600 add_target_symbol (insn
->tok
[i
].X_add_symbol
, FALSE
);
3606 /* Return the transition rule that matches or NULL if none matches. */
3609 xg_instruction_matches_rule (insn
, rule
)
3611 TransitionRule
*rule
;
3613 PreconditionList
*condition_l
;
3615 if (rule
->opcode
!= insn
->opcode
)
3618 for (condition_l
= rule
->conditions
;
3619 condition_l
!= NULL
;
3620 condition_l
= condition_l
->next
)
3624 Precondition
*cond
= condition_l
->precond
;
3629 /* The expression must be the constant. */
3630 assert (cond
->op_num
< insn
->ntok
);
3631 exp1
= &insn
->tok
[cond
->op_num
];
3632 if (!expr_is_const (exp1
))
3637 if (get_expr_const (exp1
) != cond
->op_data
)
3641 if (get_expr_const (exp1
) == cond
->op_data
)
3648 assert (cond
->op_num
< insn
->ntok
);
3649 assert (cond
->op_data
< insn
->ntok
);
3650 exp1
= &insn
->tok
[cond
->op_num
];
3651 exp2
= &insn
->tok
[cond
->op_data
];
3656 if (!expr_is_equal (exp1
, exp2
))
3660 if (expr_is_equal (exp1
, exp2
))
3677 xg_instruction_match (insn
)
3680 TransitionTable
*table
= xg_build_simplify_table ();
3682 assert (insn
->opcode
< table
->num_opcodes
);
3684 /* Walk through all of the possible transitions. */
3685 for (l
= table
->table
[insn
->opcode
]; l
!= NULL
; l
= l
->next
)
3687 TransitionRule
*rule
= l
->rule
;
3688 if (xg_instruction_matches_rule (insn
, rule
))
3695 /* Return false if no error. */
3698 xg_build_token_insn (instr_spec
, old_insn
, new_insn
)
3699 BuildInstr
*instr_spec
;
3706 switch (instr_spec
->typ
)
3709 new_insn
->insn_type
= ITYPE_INSN
;
3710 new_insn
->opcode
= instr_spec
->opcode
;
3711 new_insn
->is_specific_opcode
= FALSE
;
3713 case INSTR_LITERAL_DEF
:
3714 new_insn
->insn_type
= ITYPE_LITERAL
;
3715 new_insn
->opcode
= XTENSA_UNDEFINED
;
3716 new_insn
->is_specific_opcode
= FALSE
;
3718 case INSTR_LABEL_DEF
:
3719 as_bad (_("INSTR_LABEL_DEF not supported yet"));
3723 for (b_op
= instr_spec
->ops
; b_op
!= NULL
; b_op
= b_op
->next
)
3726 const expressionS
*src_exp
;
3732 /* The expression must be the constant. */
3733 assert (b_op
->op_num
< MAX_INSN_ARGS
);
3734 exp
= &new_insn
->tok
[b_op
->op_num
];
3735 set_expr_const (exp
, b_op
->op_data
);
3739 assert (b_op
->op_num
< MAX_INSN_ARGS
);
3740 assert (b_op
->op_data
< (unsigned) old_insn
->ntok
);
3741 src_exp
= &old_insn
->tok
[b_op
->op_data
];
3742 exp
= &new_insn
->tok
[b_op
->op_num
];
3743 copy_expr (exp
, src_exp
);
3748 as_bad (_("can't handle generation of literal/labels yet"));
3752 as_bad (_("can't handle undefined OP TYPE"));
3757 new_insn
->ntok
= num_ops
;
3762 /* Return true if it was simplified. */
3765 xg_simplify_insn (old_insn
, new_insn
)
3769 TransitionRule
*rule
= xg_instruction_match (old_insn
);
3770 BuildInstr
*insn_spec
;
3774 insn_spec
= rule
->to_instr
;
3775 /* There should only be one. */
3776 assert (insn_spec
!= NULL
);
3777 assert (insn_spec
->next
== NULL
);
3778 if (insn_spec
->next
!= NULL
)
3781 xg_build_token_insn (insn_spec
, old_insn
, new_insn
);
3787 /* xg_expand_assembly_insn: (1) Simplify the instruction, i.e., l32i ->
3788 l32i.n. (2) Check the number of operands. (3) Place the instruction
3789 tokens into the stack or if we can relax it at assembly time, place
3790 multiple instructions/literals onto the stack. Return false if no
3794 xg_expand_assembly_insn (istack
, orig_insn
)
3800 memset (&new_insn
, 0, sizeof (TInsn
));
3802 /* On return, we will be using the "use_tokens" with "use_ntok".
3803 This will reduce things like addi to addi.n. */
3804 if (code_density_available () && !orig_insn
->is_specific_opcode
)
3806 if (xg_simplify_insn (orig_insn
, &new_insn
))
3807 orig_insn
= &new_insn
;
3810 noperands
= xtensa_num_operands (xtensa_default_isa
, orig_insn
->opcode
);
3811 if (orig_insn
->ntok
< noperands
)
3813 as_bad (_("found %d operands for '%s': Expected %d"),
3815 xtensa_opcode_name (xtensa_default_isa
, orig_insn
->opcode
),
3819 if (orig_insn
->ntok
> noperands
)
3820 as_warn (_("found too many (%d) operands for '%s': Expected %d"),
3822 xtensa_opcode_name (xtensa_default_isa
, orig_insn
->opcode
),
3825 /* If there are not enough operands, we will assert above. If there
3826 are too many, just cut out the extras here. */
3828 orig_insn
->ntok
= noperands
;
3832 Instructions with all constant immeds:
3833 Assemble them and relax the instruction if possible.
3834 Give error if not possible; no fixup needed.
3836 Instructions with symbolic immeds:
3837 Assemble them with a Fix up (that may cause instruction expansion).
3838 Also close out the fragment if the fixup may cause instruction expansion.
3840 There are some other special cases where we need alignment.
3841 1) before certain instructions with required alignment (OPCODE_ALIGN)
3842 2) before labels that have jumps (LABEL_ALIGN)
3843 3) after call instructions (RETURN_ALIGN)
3844 Multiple of these may be possible on the same fragment.
3845 If so, make sure to satisfy the required alignment.
3846 Then try to get the desired alignment. */
3848 if (tinsn_has_invalid_symbolic_operands (orig_insn
))
3851 if (orig_insn
->is_specific_opcode
|| !can_relax ())
3853 istack_push (istack
, orig_insn
);
3857 if (tinsn_has_symbolic_operands (orig_insn
))
3859 if (tinsn_has_complex_operands (orig_insn
))
3860 xg_assembly_relax (istack
, orig_insn
, 0, 0, 0, 0, 0);
3862 istack_push (istack
, orig_insn
);
3866 if (xg_immeds_fit (orig_insn
))
3867 istack_push (istack
, orig_insn
);
3869 xg_assembly_relax (istack
, orig_insn
, 0, 0, 0, 0, 0);
3873 for (i
= 0; i
< istack
->ninsn
; i
++)
3875 if (xg_simplify_insn (&new_insn
, &istack
->insn
[i
]))
3876 istack
->insn
[i
] = new_insn
;
3884 /* Currently all literals that are generated here are 32-bit L32R targets. */
3887 xg_assemble_literal (insn
)
3888 /* const */ TInsn
*insn
;
3891 symbolS
*lit_sym
= NULL
;
3893 /* size = 4 for L32R. It could easily be larger when we move to
3894 larger constants. Add a parameter later. */
3895 offsetT litsize
= 4;
3896 offsetT litalign
= 2; /* 2^2 = 4 */
3897 expressionS saved_loc
;
3898 set_expr_symbol_offset (&saved_loc
, frag_now
->fr_symbol
, frag_now_fix ());
3900 assert (insn
->insn_type
== ITYPE_LITERAL
);
3901 assert (insn
->ntok
= 1); /* must be only one token here */
3903 xtensa_switch_to_literal_fragment (&state
);
3905 /* Force a 4-byte align here. Note that this opens a new frag, so all
3906 literals done with this function have a frag to themselves. That's
3907 important for the way text section literals work. */
3908 frag_align (litalign
, 0, 0);
3910 emit_expr (&insn
->tok
[0], litsize
);
3912 assert (frag_now
->tc_frag_data
.literal_frag
== NULL
);
3913 frag_now
->tc_frag_data
.literal_frag
= get_literal_pool_location (now_seg
);
3914 frag_now
->fr_symbol
= xtensa_create_literal_symbol (now_seg
, frag_now
);
3915 lit_sym
= frag_now
->fr_symbol
;
3916 frag_now
->tc_frag_data
.is_literal
= TRUE
;
3919 xtensa_restore_emit_state (&state
);
3925 xg_assemble_literal_space (size
)
3926 /* const */ int size
;
3929 /* We might have to do something about this alignment. It only
3930 takes effect if something is placed here. */
3931 offsetT litalign
= 2; /* 2^2 = 4 */
3932 fragS
*lit_saved_frag
;
3934 expressionS saved_loc
;
3936 assert (size
% 4 == 0);
3937 set_expr_symbol_offset (&saved_loc
, frag_now
->fr_symbol
, frag_now_fix ());
3939 xtensa_switch_to_literal_fragment (&state
);
3941 /* Force a 4-byte align here. */
3942 frag_align (litalign
, 0, 0);
3944 xg_force_frag_space (size
);
3946 lit_saved_frag
= frag_now
;
3947 frag_now
->tc_frag_data
.literal_frag
= get_literal_pool_location (now_seg
);
3948 frag_now
->tc_frag_data
.is_literal
= TRUE
;
3949 frag_now
->fr_symbol
= xtensa_create_literal_symbol (now_seg
, frag_now
);
3950 xg_finish_frag (0, RELAX_LITERAL
, size
, FALSE
);
3953 xtensa_restore_emit_state (&state
);
3954 frag_now
->tc_frag_data
.literal_frag
= lit_saved_frag
;
3959 xtensa_create_literal_symbol (sec
, frag
)
3963 static int lit_num
= 0;
3964 static char name
[256];
3967 sprintf (name
, ".L_lit_sym%d", lit_num
);
3968 fragSym
= xtensa_create_local_symbol (stdoutput
, name
, sec
, 0, frag_now
);
3970 frag
->tc_frag_data
.is_literal
= TRUE
;
3976 /* Create a local symbol. If it is in a linkonce section, we have to
3977 be careful to make sure that if it is used in a relocation that the
3978 symbol will be in the output file. */
3981 xtensa_create_local_symbol (abfd
, name
, sec
, value
, frag
)
3990 if (get_is_linkonce_section (abfd
, sec
))
3992 symbolP
= symbol_new (name
, sec
, value
, frag
);
3993 S_CLEAR_EXTERNAL (symbolP
);
3994 /* symbolP->local = 1; */
3997 symbolP
= symbol_new (name
, sec
, value
, frag
);
4003 /* Return true if the section flags are marked linkonce
4004 or the name is .gnu.linkonce*. */
4007 get_is_linkonce_section (abfd
, sec
)
4008 bfd
*abfd ATTRIBUTE_UNUSED
;
4011 flagword flags
, link_once_flags
;
4013 flags
= bfd_get_section_flags (abfd
, sec
);
4014 link_once_flags
= (flags
& SEC_LINK_ONCE
);
4016 /* Flags might not be set yet. */
4017 if (!link_once_flags
)
4019 static size_t len
= sizeof ".gnu.linkonce.t.";
4021 if (strncmp (segment_name (sec
), ".gnu.linkonce.t.", len
- 1) == 0)
4022 link_once_flags
= SEC_LINK_ONCE
;
4024 return (link_once_flags
!= 0);
4028 /* Emit an instruction to the current fragment. If record_fix is true,
4029 then this instruction will not change and we can go ahead and record
4030 the fixup. If record_fix is false, then the instruction may change
4031 and we are going to close out this fragment. Go ahead and set the
4032 fr_symbol and fr_offset instead of adding a fixup. */
4035 xg_emit_insn (t_insn
, record_fix
)
4037 bfd_boolean record_fix
;
4039 bfd_boolean ok
= TRUE
;
4040 xtensa_isa isa
= xtensa_default_isa
;
4041 xtensa_opcode opcode
= t_insn
->opcode
;
4042 bfd_boolean has_fixup
= FALSE
;
4048 static xtensa_insnbuf insnbuf
= NULL
;
4050 /* Use a static pointer to the insn buffer so we don't have to call
4051 malloc each time through. */
4053 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
4055 has_fixup
= tinsn_to_insnbuf (t_insn
, insnbuf
);
4057 noperands
= xtensa_num_operands (isa
, opcode
);
4058 assert (noperands
== t_insn
->ntok
);
4060 byte_count
= xtensa_insn_length (isa
, opcode
);
4062 /* This should NEVER cause us to jump into a new frag;
4063 we've already reserved space. */
4064 old_size
= frag_now_fix ();
4065 f
= frag_more (byte_count
);
4066 assert (oldfrag
== frag_now
);
4068 /* This needs to generate a record that lists the parts that are
4070 if (!frag_now
->tc_frag_data
.is_insn
)
4072 /* If we are at the beginning of a fragment, switch this
4073 fragment to an instruction fragment. */
4074 if (now_seg
!= absolute_section
&& old_size
!= 0)
4075 as_warn (_("instruction fragment may contain data"));
4076 frag_now
->tc_frag_data
.is_insn
= TRUE
;
4079 xtensa_insnbuf_to_chars (isa
, insnbuf
, f
);
4081 /* dwarf2_emit_insn (byte_count); */
4083 /* Now spit out the opcode fixup.... */
4087 for (i
= 0; i
< noperands
; ++i
)
4089 expressionS
*expr
= &t_insn
->tok
[i
];
4093 if (get_relaxable_immed (opcode
) == i
)
4097 if (!xg_add_opcode_fix (opcode
, i
, expr
, frag_now
,
4098 f
- frag_now
->fr_literal
))
4103 /* Write it to the fr_offset, fr_symbol. */
4104 frag_now
->fr_symbol
= expr
->X_add_symbol
;
4105 frag_now
->fr_offset
= expr
->X_add_number
;
4110 as_bad (_("invalid operand %d on '%s'"),
4111 i
, xtensa_opcode_name (isa
, opcode
));
4121 as_bad (_("invalid expression for operand %d on '%s'"),
4122 i
, xtensa_opcode_name (isa
, opcode
));
4133 xg_emit_insn_to_buf (t_insn
, buf
, fragP
, offset
, build_fix
)
4138 bfd_boolean build_fix
;
4140 static xtensa_insnbuf insnbuf
= NULL
;
4141 bfd_boolean has_symbolic_immed
= FALSE
;
4142 bfd_boolean ok
= TRUE
;
4144 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
4146 has_symbolic_immed
= tinsn_to_insnbuf (t_insn
, insnbuf
);
4147 if (has_symbolic_immed
&& build_fix
)
4150 int opnum
= get_relaxable_immed (t_insn
->opcode
);
4151 expressionS
*exp
= &t_insn
->tok
[opnum
];
4153 if (!xg_add_opcode_fix (t_insn
->opcode
,
4154 opnum
, exp
, fragP
, offset
))
4157 fragP
->tc_frag_data
.is_insn
= TRUE
;
4158 xtensa_insnbuf_to_chars (xtensa_default_isa
, insnbuf
, buf
);
4163 /* Put in a fixup record based on the opcode.
4164 Return true on success. */
4167 xg_add_opcode_fix (opcode
, opnum
, expr
, fragP
, offset
)
4168 xtensa_opcode opcode
;
4174 bfd_reloc_code_real_type reloc
;
4175 reloc_howto_type
*howto
;
4179 reloc
= opnum_to_reloc (opnum
);
4180 if (reloc
== BFD_RELOC_NONE
)
4182 as_bad (_("invalid relocation operand %i on '%s'"),
4183 opnum
, xtensa_opcode_name (xtensa_default_isa
, opcode
));
4187 howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
4191 as_bad (_("undefined symbol for opcode \"%s\"."),
4192 xtensa_opcode_name (xtensa_default_isa
, opcode
));
4196 insn_length
= xtensa_insn_length (xtensa_default_isa
, opcode
);
4197 the_fix
= fix_new_exp (fragP
, offset
, insn_length
, expr
,
4198 howto
->pc_relative
, reloc
);
4200 if (expr
->X_add_symbol
&&
4201 (S_IS_EXTERNAL (expr
->X_add_symbol
) || S_IS_WEAK (expr
->X_add_symbol
)))
4202 the_fix
->fx_plt
= TRUE
;
4209 xg_resolve_literals (insn
, lit_sym
)
4213 symbolS
*sym
= get_special_literal_symbol ();
4217 assert (insn
->insn_type
== ITYPE_INSN
);
4218 for (i
= 0; i
< insn
->ntok
; i
++)
4219 if (insn
->tok
[i
].X_add_symbol
== sym
)
4220 insn
->tok
[i
].X_add_symbol
= lit_sym
;
4226 xg_resolve_labels (insn
, label_sym
)
4230 symbolS
*sym
= get_special_label_symbol ();
4232 /* assert(!insn->is_literal); */
4233 for (i
= 0; i
< insn
->ntok
; i
++)
4234 if (insn
->tok
[i
].X_add_symbol
== sym
)
4235 insn
->tok
[i
].X_add_symbol
= label_sym
;
4241 xg_assemble_tokens (insn
)
4242 /*const */ TInsn
*insn
;
4244 /* By the time we get here, there's not too much left to do.
4245 1) Check our assumptions.
4246 2) Check if the current instruction is "narrow".
4247 If so, then finish the frag, create another one.
4248 We could also go back to change some previous
4249 "narrow" frags into no-change ones if we have more than
4250 MAX_NARROW_ALIGNMENT of them without alignment restrictions
4254 1) It has constant operands and doesn't fit.
4255 Go ahead and assemble it so it will fail.
4256 2) It has constant operands that fit.
4257 If narrow and !is_specific_opcode,
4258 assemble it and put in a relocation
4261 3) It has a symbolic immediate operand
4262 a) Find the worst-case relaxation required
4263 b) Find the worst-case literal pool space required.
4264 Insert appropriate alignment & space in the literal.
4266 Add the relocation. */
4268 assert (insn
->insn_type
== ITYPE_INSN
);
4270 if (!tinsn_has_symbolic_operands (insn
))
4272 if (xg_is_narrow_insn (insn
) && !insn
->is_specific_opcode
)
4274 /* assemble it but add max required space */
4275 int max_size
= xg_get_max_narrow_insn_size (insn
->opcode
);
4276 int min_size
= xg_get_insn_size (insn
);
4278 assert (max_size
== 3);
4279 /* make sure we have enough space to widen it */
4280 xg_force_frag_space (max_size
);
4281 /* Output the instruction. It may cause an error if some
4282 operands do not fit. */
4283 last_insn
= frag_more (0);
4284 if (xg_emit_insn (insn
, TRUE
))
4285 as_warn (_("instruction with constant operands does not fit"));
4286 xg_finish_frag (last_insn
, RELAX_NARROW
, max_size
- min_size
, TRUE
);
4290 /* Assemble it. No relocation needed. */
4291 int max_size
= xg_get_insn_size (insn
);
4292 xg_force_frag_space (max_size
);
4293 if (xg_emit_insn (insn
, FALSE
))
4294 as_warn (_("instruction with constant operands does not "
4295 "fit without widening"));
4296 /* frag_more (max_size); */
4298 /* Special case for jx. If the jx is the next to last
4299 instruction in a loop, we will add a NOP after it. This
4300 avoids a hardware issue that could occur if the jx jumped
4301 to the next instruction. */
4302 if (software_avoid_b_j_loop_end
4303 && is_jx_opcode (insn
->opcode
))
4305 maybe_has_b_j_loop_end
= TRUE
;
4306 /* add 2 of these */
4307 frag_now
->tc_frag_data
.is_insn
= TRUE
;
4308 frag_var (rs_machine_dependent
, 4, 4,
4309 RELAX_ADD_NOP_IF_PRE_LOOP_END
,
4310 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
4316 /* Need to assemble it with space for the relocation. */
4317 if (!insn
->is_specific_opcode
)
4319 /* Assemble it but add max required space. */
4321 int min_size
= xg_get_insn_size (insn
);
4322 int max_size
= xg_get_max_insn_widen_size (insn
->opcode
);
4323 int max_literal_size
=
4324 xg_get_max_insn_widen_literal_size (insn
->opcode
);
4327 symbolS
*immed_sym
= xg_get_insn_immed_symbol (insn
);
4328 set_frag_segment (frag_now
, now_seg
);
4331 /* Make sure we have enough space to widen the instruction.
4332 This may open a new fragment. */
4333 xg_force_frag_space (max_size
);
4334 if (max_literal_size
!= 0)
4335 xg_assemble_literal_space (max_literal_size
);
4337 /* Output the instruction. It may cause an error if some
4338 operands do not fit. Emit the incomplete instruction. */
4339 last_insn
= frag_more (0);
4340 xg_emit_insn (insn
, FALSE
);
4342 xg_finish_frag (last_insn
, RELAX_IMMED
, max_size
- min_size
, TRUE
);
4344 /* Special cases for loops:
4345 close_loop_end should be inserted AFTER short_loop.
4346 Make sure that CLOSE loops are processed BEFORE short_loops
4347 when converting them. */
4349 /* "short_loop": add a NOP if the loop is < 4 bytes. */
4350 if (software_avoid_short_loop
4351 && is_loop_opcode (insn
->opcode
))
4353 maybe_has_short_loop
= TRUE
;
4354 frag_now
->tc_frag_data
.is_insn
= TRUE
;
4355 frag_var (rs_machine_dependent
, 4, 4,
4356 RELAX_ADD_NOP_IF_SHORT_LOOP
,
4357 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
4358 frag_now
->tc_frag_data
.is_insn
= TRUE
;
4359 frag_var (rs_machine_dependent
, 4, 4,
4360 RELAX_ADD_NOP_IF_SHORT_LOOP
,
4361 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
4364 /* "close_loop_end": Add up to 12 bytes of NOPs to keep a
4365 loop at least 12 bytes away from another loop's loop
4367 if (software_avoid_close_loop_end
4368 && is_loop_opcode (insn
->opcode
))
4370 maybe_has_close_loop_end
= TRUE
;
4371 frag_now
->tc_frag_data
.is_insn
= TRUE
;
4372 frag_var (rs_machine_dependent
, 12, 12,
4373 RELAX_ADD_NOP_IF_CLOSE_LOOP_END
,
4374 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
4379 /* Assemble it in place. No expansion will be required,
4380 but we'll still need a relocation record. */
4381 int max_size
= xg_get_insn_size (insn
);
4382 xg_force_frag_space (max_size
);
4383 if (xg_emit_insn (insn
, TRUE
))
4384 as_warn (_("instruction's constant operands do not fit"));
4390 /* Return true if the instruction can write to the specified
4391 integer register. */
4394 is_register_writer (insn
, regset
, regnum
)
4401 xtensa_isa isa
= xtensa_default_isa
;
4403 num_ops
= xtensa_num_operands (isa
, insn
->opcode
);
4405 for (i
= 0; i
< num_ops
; i
++)
4407 xtensa_operand operand
= xtensa_get_operand (isa
, insn
->opcode
, i
);
4408 char inout
= xtensa_operand_inout (operand
);
4410 if (inout
== '>' || inout
== '=')
4412 if (strcmp (xtensa_operand_kind (operand
), regset
) == 0)
4414 if ((insn
->tok
[i
].X_op
== O_register
)
4415 && (insn
->tok
[i
].X_add_number
== regnum
))
4425 is_bad_loopend_opcode (tinsn
)
4426 const TInsn
* tinsn
;
4428 xtensa_opcode opcode
= tinsn
->opcode
;
4430 if (opcode
== XTENSA_UNDEFINED
)
4433 if (opcode
== xtensa_call0_opcode
4434 || opcode
== xtensa_callx0_opcode
4435 || opcode
== xtensa_call4_opcode
4436 || opcode
== xtensa_callx4_opcode
4437 || opcode
== xtensa_call8_opcode
4438 || opcode
== xtensa_callx8_opcode
4439 || opcode
== xtensa_call12_opcode
4440 || opcode
== xtensa_callx12_opcode
4441 || opcode
== xtensa_isync_opcode
4442 || opcode
== xtensa_ret_opcode
4443 || opcode
== xtensa_ret_n_opcode
4444 || opcode
== xtensa_retw_opcode
4445 || opcode
== xtensa_retw_n_opcode
4446 || opcode
== xtensa_waiti_opcode
)
4449 /* An RSR of LCOUNT is illegal as the last opcode in a loop. */
4450 if (opcode
== xtensa_rsr_opcode
4452 && tinsn
->tok
[1].X_op
== O_constant
4453 && tinsn
->tok
[1].X_add_number
== 2)
4460 /* Labels that begin with ".Ln" or ".LM" are unaligned.
4461 This allows the debugger to add unaligned labels.
4462 Also, the assembler generates stabs labels that need
4463 not be aligned: FAKE_LABEL_NAME . {"F", "L", "endfunc"}. */
4466 is_unaligned_label (sym
)
4469 const char *name
= S_GET_NAME (sym
);
4470 static size_t fake_size
= 0;
4474 && name
[1] == 'L' && (name
[2] == 'n' || name
[2] == 'M'))
4477 /* FAKE_LABEL_NAME followed by "F", "L" or "endfunc" */
4479 fake_size
= strlen (FAKE_LABEL_NAME
);
4482 && strncmp (FAKE_LABEL_NAME
, name
, fake_size
) == 0
4483 && (name
[fake_size
] == 'F'
4484 || name
[fake_size
] == 'L'
4485 || (name
[fake_size
] == 'e'
4486 && strncmp ("endfunc", name
+fake_size
, 7) == 0)))
4494 next_non_empty_frag (fragP
)
4497 fragS
*next_fragP
= fragP
->fr_next
;
4499 /* Sometimes an empty will end up here due storage allocation issues.
4500 So we have to skip until we find something legit. */
4501 while (next_fragP
&& next_fragP
->fr_fix
== 0)
4502 next_fragP
= next_fragP
->fr_next
;
4504 if (next_fragP
== NULL
|| next_fragP
->fr_fix
== 0)
4512 next_frag_opcode (fragP
)
4513 const fragS
* fragP
;
4515 const fragS
*next_fragP
= next_non_empty_frag (fragP
);
4516 static xtensa_insnbuf insnbuf
= NULL
;
4517 xtensa_isa isa
= xtensa_default_isa
;
4520 insnbuf
= xtensa_insnbuf_alloc (isa
);
4522 if (next_fragP
== NULL
)
4523 return XTENSA_UNDEFINED
;
4525 xtensa_insnbuf_from_chars (isa
, insnbuf
, next_fragP
->fr_literal
);
4526 return xtensa_decode_insn (isa
, insnbuf
);
4530 /* Return true if the target frag is one of the next non-empty frags. */
4533 is_next_frag_target (fragP
, target
)
4535 const fragS
*target
;
4540 for (; fragP
; fragP
= fragP
->fr_next
)
4542 if (fragP
== target
)
4544 if (fragP
->fr_fix
!= 0)
4546 if (fragP
->fr_type
== rs_fill
&& fragP
->fr_offset
!= 0)
4548 if ((fragP
->fr_type
== rs_align
|| fragP
->fr_type
== rs_align_code
)
4549 && ((fragP
->fr_address
% (1 << fragP
->fr_offset
)) != 0))
4551 if (fragP
->fr_type
== rs_space
)
4558 /* If the next legit fragment is an end-of-loop marker,
4559 switch its state so it will instantiate a NOP. */
4562 update_next_frag_nop_state (fragP
)
4565 fragS
*next_fragP
= fragP
->fr_next
;
4567 while (next_fragP
&& next_fragP
->fr_fix
== 0)
4569 if (next_fragP
->fr_type
== rs_machine_dependent
4570 && next_fragP
->fr_subtype
== RELAX_LOOP_END
)
4572 next_fragP
->fr_subtype
= RELAX_LOOP_END_ADD_NOP
;
4575 next_fragP
= next_fragP
->fr_next
;
4581 next_frag_is_branch_target (fragP
)
4584 /* Sometimes an empty will end up here due storage allocation issues,
4585 so we have to skip until we find something legit. */
4586 for (fragP
= fragP
->fr_next
; fragP
; fragP
= fragP
->fr_next
)
4588 if (fragP
->tc_frag_data
.is_branch_target
)
4590 if (fragP
->fr_fix
!= 0)
4598 next_frag_is_loop_target (fragP
)
4601 /* Sometimes an empty will end up here due storage allocation issues.
4602 So we have to skip until we find something legit. */
4603 for (fragP
= fragP
->fr_next
; fragP
; fragP
= fragP
->fr_next
)
4605 if (fragP
->tc_frag_data
.is_loop_target
)
4607 if (fragP
->fr_fix
!= 0)
4615 next_frag_pre_opcode_bytes (fragp
)
4618 const fragS
*next_fragp
= fragp
->fr_next
;
4620 xtensa_opcode next_opcode
= next_frag_opcode (fragp
);
4621 if (!is_loop_opcode (next_opcode
))
4624 /* Sometimes an empty will end up here due storage allocation issues.
4625 So we have to skip until we find something legit. */
4626 while (next_fragp
->fr_fix
== 0)
4627 next_fragp
= next_fragp
->fr_next
;
4629 if (next_fragp
->fr_type
!= rs_machine_dependent
)
4632 /* There is some implicit knowledge encoded in here.
4633 The LOOP instructions that are NOT RELAX_IMMED have
4635 if (next_fragp
->fr_subtype
> RELAX_IMMED
)
4636 return get_expanded_loop_offset (next_opcode
);
4642 /* Mark a location where we can later insert literal frags. Update
4643 the section's literal_pool_loc, so subsequent literals can be
4644 placed nearest to their use. */
4647 xtensa_mark_literal_pool_location (move_labels
)
4648 bfd_boolean move_labels
;
4650 /* Any labels pointing to the current location need
4651 to be adjusted to after the literal pool. */
4653 fragS
*label_target
= frag_now
;
4654 fragS
*pool_location
;
4655 offsetT label_offset
= frag_now_fix ();
4657 frag_align (2, 0, 0);
4659 /* We stash info in the fr_var of these frags
4660 so we can later move the literal's fixes into this
4661 frchain's fix list. We can use fr_var because fr_var's
4662 interpretation depends solely on the fr_type and subtype. */
4663 pool_location
= frag_now
;
4664 frag_variant (rs_machine_dependent
, 0, (int) frchain_now
,
4665 RELAX_LITERAL_POOL_BEGIN
, NULL
, 0, NULL
);
4666 frag_variant (rs_machine_dependent
, 0, (int) now_seg
,
4667 RELAX_LITERAL_POOL_END
, NULL
, 0, NULL
);
4669 /* Now put a frag into the literal pool that points to this location. */
4670 set_literal_pool_location (now_seg
, pool_location
);
4671 xtensa_switch_to_literal_fragment (&s
);
4673 /* Close whatever frag is there. */
4674 frag_variant (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
4675 frag_now
->tc_frag_data
.literal_frag
= pool_location
;
4676 frag_variant (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
4677 xtensa_restore_emit_state (&s
);
4679 xtensa_move_labels (label_target
, label_offset
, frag_now
, 0);
4684 xtensa_move_labels (old_frag
, old_offset
, new_frag
, new_offset
)
4687 fragS
*new_frag ATTRIBUTE_UNUSED
;
4692 /* Repeat until there are no more.... */
4693 for (old_sym
= xtensa_find_label (old_frag
, old_offset
, TRUE
);
4695 old_sym
= xtensa_find_label (old_frag
, old_offset
, TRUE
))
4697 S_SET_VALUE (old_sym
, (valueT
) new_offset
);
4698 symbol_set_frag (old_sym
, frag_now
);
4703 /* Assemble a NOP of the requested size in the buffer. User must have
4704 allocated "buf" with at least "size" bytes. */
4707 assemble_nop (size
, buf
)
4711 static xtensa_insnbuf insnbuf
= NULL
;
4714 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
4716 tinsn_init (&t_insn
);
4720 t_insn
.opcode
= xtensa_nop_n_opcode
;
4722 if (t_insn
.opcode
== XTENSA_UNDEFINED
)
4723 as_fatal (_("opcode 'NOP.N' unavailable in this configuration"));
4724 tinsn_to_insnbuf (&t_insn
, insnbuf
);
4725 xtensa_insnbuf_to_chars (xtensa_default_isa
, insnbuf
, buf
);
4729 t_insn
.opcode
= xtensa_or_opcode
;
4730 assert (t_insn
.opcode
!= XTENSA_UNDEFINED
);
4731 if (t_insn
.opcode
== XTENSA_UNDEFINED
)
4732 as_fatal (_("opcode 'OR' unavailable in this configuration"));
4733 set_expr_const (&t_insn
.tok
[0], 1);
4734 set_expr_const (&t_insn
.tok
[1], 1);
4735 set_expr_const (&t_insn
.tok
[2], 1);
4737 tinsn_to_insnbuf (&t_insn
, insnbuf
);
4738 xtensa_insnbuf_to_chars (xtensa_default_isa
, insnbuf
, buf
);
4742 as_fatal (_("invalid %d-byte NOP requested"), size
);
4747 /* Return the number of bytes for the offset of the expanded loop
4748 instruction. This should be incorporated into the relaxation
4749 specification but is hard-coded here. This is used to auto-align
4750 the loop instruction. It is invalid to call this function if the
4751 configuration does not have loops or if the opcode is not a loop
4755 get_expanded_loop_offset (opcode
)
4756 xtensa_opcode opcode
;
4758 /* This is the OFFSET of the loop instruction in the expanded loop.
4759 This MUST correspond directly to the specification of the loop
4760 expansion. It will be validated on fragment conversion. */
4761 if (opcode
== XTENSA_UNDEFINED
)
4762 as_fatal (_("get_expanded_loop_offset: undefined opcode"));
4763 if (opcode
== xtensa_loop_opcode
)
4765 if (opcode
== xtensa_loopnez_opcode
)
4767 if (opcode
== xtensa_loopgtz_opcode
)
4769 as_fatal (_("get_expanded_loop_offset: invalid opcode"));
4775 get_literal_pool_location (seg
)
4778 return seg_info (seg
)->tc_segment_info_data
.literal_pool_loc
;
4783 set_literal_pool_location (seg
, literal_pool_loc
)
4785 fragS
*literal_pool_loc
;
4787 seg_info (seg
)->tc_segment_info_data
.literal_pool_loc
= literal_pool_loc
;
4791 /* External Functions and Other GAS Hooks. */
4794 xtensa_target_format ()
4796 return (target_big_endian
? "elf32-xtensa-be" : "elf32-xtensa-le");
4801 xtensa_file_arch_init (abfd
)
4804 bfd_set_private_flags (abfd
, 0x100 | 0x200);
4809 md_number_to_chars (buf
, val
, n
)
4814 if (target_big_endian
)
4815 number_to_chars_bigendian (buf
, val
, n
);
4817 number_to_chars_littleendian (buf
, val
, n
);
4821 /* This function is called once, at assembler startup time. It should
4822 set up all the tables, etc. that the MD part of the assembler will
4828 segT current_section
= now_seg
;
4829 int current_subsec
= now_subseg
;
4833 isa
= xtensa_isa_init ();
4835 /* ISA was already initialized by xtensa_init(). */
4836 isa
= xtensa_default_isa
;
4839 /* Set up the .literal, .fini.literal and .init.literal sections. */
4840 memset (&default_lit_sections
, 0, sizeof (default_lit_sections
));
4841 default_lit_sections
.init_lit_seg_name
= INIT_LITERAL_SECTION_NAME
;
4842 default_lit_sections
.fini_lit_seg_name
= FINI_LITERAL_SECTION_NAME
;
4843 default_lit_sections
.lit_seg_name
= LITERAL_SECTION_NAME
;
4845 subseg_set (current_section
, current_subsec
);
4847 xtensa_addi_opcode
= xtensa_opcode_lookup (isa
, "addi");
4848 xtensa_addmi_opcode
= xtensa_opcode_lookup (isa
, "addmi");
4849 xtensa_call0_opcode
= xtensa_opcode_lookup (isa
, "call0");
4850 xtensa_call4_opcode
= xtensa_opcode_lookup (isa
, "call4");
4851 xtensa_call8_opcode
= xtensa_opcode_lookup (isa
, "call8");
4852 xtensa_call12_opcode
= xtensa_opcode_lookup (isa
, "call12");
4853 xtensa_callx0_opcode
= xtensa_opcode_lookup (isa
, "callx0");
4854 xtensa_callx4_opcode
= xtensa_opcode_lookup (isa
, "callx4");
4855 xtensa_callx8_opcode
= xtensa_opcode_lookup (isa
, "callx8");
4856 xtensa_callx12_opcode
= xtensa_opcode_lookup (isa
, "callx12");
4857 xtensa_entry_opcode
= xtensa_opcode_lookup (isa
, "entry");
4858 xtensa_isync_opcode
= xtensa_opcode_lookup (isa
, "isync");
4859 xtensa_j_opcode
= xtensa_opcode_lookup (isa
, "j");
4860 xtensa_jx_opcode
= xtensa_opcode_lookup (isa
, "jx");
4861 xtensa_loop_opcode
= xtensa_opcode_lookup (isa
, "loop");
4862 xtensa_loopnez_opcode
= xtensa_opcode_lookup (isa
, "loopnez");
4863 xtensa_loopgtz_opcode
= xtensa_opcode_lookup (isa
, "loopgtz");
4864 xtensa_nop_n_opcode
= xtensa_opcode_lookup (isa
, "nop.n");
4865 xtensa_or_opcode
= xtensa_opcode_lookup (isa
, "or");
4866 xtensa_ret_opcode
= xtensa_opcode_lookup (isa
, "ret");
4867 xtensa_ret_n_opcode
= xtensa_opcode_lookup (isa
, "ret.n");
4868 xtensa_retw_opcode
= xtensa_opcode_lookup (isa
, "retw");
4869 xtensa_retw_n_opcode
= xtensa_opcode_lookup (isa
, "retw.n");
4870 xtensa_rsr_opcode
= xtensa_opcode_lookup (isa
, "rsr");
4871 xtensa_waiti_opcode
= xtensa_opcode_lookup (isa
, "waiti");
4875 /* tc_frob_label hook */
4878 xtensa_frob_label (sym
)
4881 xtensa_define_label (sym
);
4882 if (is_loop_target_label (sym
)
4883 && (get_last_insn_flags (now_seg
, now_subseg
)
4884 & FLAG_IS_BAD_LOOPEND
) != 0)
4885 as_bad (_("invalid last instruction for a zero-overhead loop"));
4887 /* No target aligning in the absolute section. */
4888 if (now_seg
!= absolute_section
&& align_targets
4889 && !is_unaligned_label (sym
))
4891 fragS
*old_frag
= frag_now
;
4892 offsetT old_offset
= frag_now_fix ();
4893 if (frag_now
->tc_frag_data
.is_literal
)
4895 /* frag_now->tc_frag_data.is_insn = TRUE; */
4896 frag_var (rs_machine_dependent
, 4, 4,
4897 RELAX_DESIRE_ALIGN_IF_TARGET
,
4898 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
4899 xtensa_move_labels (old_frag
, old_offset
, frag_now
, 0);
4900 /* Once we know whether or not the label is a branch target
4901 We will suppress some of these alignments. */
4906 /* md_flush_pending_output hook */
4909 xtensa_flush_pending_output ()
4911 /* If there is a non-zero instruction fragment, close it. */
4912 if (frag_now_fix () != 0 && frag_now
->tc_frag_data
.is_insn
)
4914 frag_wane (frag_now
);
4917 frag_now
->tc_frag_data
.is_insn
= FALSE
;
4925 xtensa_isa isa
= xtensa_default_isa
;
4928 bfd_boolean has_underbar
= FALSE
;
4929 char *arg_strings
[MAX_INSN_ARGS
];
4931 IStack istack
; /* Put instructions into here. */
4932 TInsn orig_insn
; /* Original instruction from the input. */
4934 symbolS
*lit_sym
= NULL
;
4936 if (frag_now
->tc_frag_data
.is_literal
)
4938 static bfd_boolean reported
= 0;
4940 as_bad (_("cannot assemble '%s' into a literal fragment"), str
);
4947 istack_init (&istack
);
4948 tinsn_init (&orig_insn
);
4950 /* Split off the opcode. */
4951 opnamelen
= strspn (str
, "abcdefghijklmnopqrstuvwxyz_/0123456789.");
4952 opname
= xmalloc (opnamelen
+ 1);
4953 memcpy (opname
, str
, opnamelen
);
4954 opname
[opnamelen
] = '\0';
4956 num_args
= tokenize_arguments (arg_strings
, str
+ opnamelen
);
4959 as_bad (_("syntax error"));
4963 if (xg_translate_idioms (&opname
, &num_args
, arg_strings
))
4966 /* Check for an underbar prefix. */
4969 has_underbar
= TRUE
;
4973 orig_insn
.insn_type
= ITYPE_INSN
;
4975 orig_insn
.is_specific_opcode
= (has_underbar
|| !use_generics ());
4976 specific_opcode
= orig_insn
.is_specific_opcode
;
4978 orig_insn
.opcode
= xtensa_opcode_lookup (isa
, opname
);
4979 if (orig_insn
.opcode
== XTENSA_UNDEFINED
)
4981 as_bad (_("unknown opcode %s"), opname
);
4985 if (frag_now_fix () != 0 && !frag_now
->tc_frag_data
.is_insn
)
4987 frag_wane (frag_now
);
4991 if (software_a0_b_retw_interlock
)
4993 if ((get_last_insn_flags (now_seg
, now_subseg
) & FLAG_IS_A0_WRITER
) != 0
4994 && is_conditional_branch_opcode (orig_insn
.opcode
))
4996 has_a0_b_retw
= TRUE
;
4998 /* Mark this fragment with the special RELAX_ADD_NOP_IF_A0_B_RETW.
4999 After the first assembly pass we will check all of them and
5000 add a nop if needed. */
5001 frag_now
->tc_frag_data
.is_insn
= TRUE
;
5002 frag_var (rs_machine_dependent
, 4, 4,
5003 RELAX_ADD_NOP_IF_A0_B_RETW
,
5004 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
5005 frag_now
->tc_frag_data
.is_insn
= TRUE
;
5006 frag_var (rs_machine_dependent
, 4, 4,
5007 RELAX_ADD_NOP_IF_A0_B_RETW
,
5008 frag_now
->fr_symbol
, frag_now
->fr_offset
, NULL
);
5012 /* Special case: The call instructions should be marked "specific opcode"
5013 to keep them from expanding. */
5014 if (!use_longcalls () && is_direct_call_opcode (orig_insn
.opcode
))
5015 orig_insn
.is_specific_opcode
= TRUE
;
5017 /* Parse the arguments. */
5018 if (parse_arguments (&orig_insn
, num_args
, arg_strings
))
5020 as_bad (_("syntax error"));
5024 /* Free the opcode and argument strings, now that they've been parsed. */
5025 free (has_underbar
? opname
- 1 : opname
);
5027 while (num_args
-- > 0)
5028 free (arg_strings
[num_args
]);
5030 /* Check for the right number and type of arguments. */
5031 if (tinsn_check_arguments (&orig_insn
))
5034 /* See if the instruction implies an aligned section. */
5035 if (is_entry_opcode (orig_insn
.opcode
) || is_loop_opcode (orig_insn
.opcode
))
5036 record_alignment (now_seg
, 2);
5038 xg_add_branch_and_loop_targets (&orig_insn
);
5040 /* Special cases for instructions that force an alignment... */
5041 if (!orig_insn
.is_specific_opcode
&& is_loop_opcode (orig_insn
.opcode
))
5043 fragS
*old_frag
= frag_now
;
5044 offsetT old_offset
= frag_now_fix ();
5045 symbolS
*old_sym
= NULL
;
5048 frag_now
->tc_frag_data
.is_insn
= TRUE
;
5049 frag_now
->tc_frag_data
.is_no_density
= !code_density_available ();
5050 max_fill
= get_text_align_max_fill_size
5051 (get_text_align_power (XTENSA_FETCH_WIDTH
),
5052 TRUE
, frag_now
->tc_frag_data
.is_no_density
);
5053 frag_var (rs_machine_dependent
, max_fill
, max_fill
,
5054 RELAX_ALIGN_NEXT_OPCODE
, frag_now
->fr_symbol
,
5055 frag_now
->fr_offset
, NULL
);
5057 /* Repeat until there are no more. */
5058 while ((old_sym
= xtensa_find_label (old_frag
, old_offset
, FALSE
)))
5060 S_SET_VALUE (old_sym
, (valueT
) 0);
5061 symbol_set_frag (old_sym
, frag_now
);
5065 /* Special count for "entry" instruction. */
5066 if (is_entry_opcode (orig_insn
.opcode
))
5068 /* Check that the second opcode (#1) is >= 16. */
5069 if (orig_insn
.ntok
>= 2)
5071 expressionS
*exp
= &orig_insn
.tok
[1];
5075 if (exp
->X_add_number
< 16)
5076 as_warn (_("entry instruction with stack decrement < 16"));
5080 as_warn (_("entry instruction with non-constant decrement"));
5085 if (!orig_insn
.is_specific_opcode
&& is_entry_opcode (orig_insn
.opcode
))
5087 xtensa_mark_literal_pool_location (TRUE
);
5089 /* Automatically align ENTRY instructions. */
5090 frag_align (2, 0, 0);
5093 if (software_a0_b_retw_interlock
)
5094 set_last_insn_flags (now_seg
, now_subseg
, FLAG_IS_A0_WRITER
,
5095 is_register_writer (&orig_insn
, "a", 0));
5097 set_last_insn_flags (now_seg
, now_subseg
, FLAG_IS_BAD_LOOPEND
,
5098 is_bad_loopend_opcode (&orig_insn
));
5101 assemble_tokens (opcode, tok, ntok);
5102 expand the tokens from the orig_insn into the
5103 stack of instructions that will not expand
5104 unless required at relaxation time. */
5105 if (xg_expand_assembly_insn (&istack
, &orig_insn
))
5108 for (i
= 0; i
< istack
.ninsn
; i
++)
5110 TInsn
*insn
= &istack
.insn
[i
];
5111 if (insn
->insn_type
== ITYPE_LITERAL
)
5113 assert (lit_sym
== NULL
);
5114 lit_sym
= xg_assemble_literal (insn
);
5119 xg_resolve_literals (insn
, lit_sym
);
5120 xg_assemble_tokens (insn
);
5124 /* Now, if the original opcode was a call... */
5125 if (align_targets
&& is_call_opcode (orig_insn
.opcode
))
5127 frag_now
->tc_frag_data
.is_insn
= TRUE
;
5128 frag_var (rs_machine_dependent
, 4, 4,
5130 frag_now
->fr_symbol
,
5131 frag_now
->fr_offset
,
5137 /* TC_CONS_FIX_NEW hook: Check for "@PLT" suffix on symbol references.
5138 If found, use an XTENSA_PLT reloc for 4-byte values. Otherwise, this
5139 is the same as the standard code in read.c. */
5142 xtensa_cons_fix_new (frag
, where
, size
, exp
)
5148 bfd_reloc_code_real_type r
;
5149 bfd_boolean plt
= FALSE
;
5151 if (*input_line_pointer
== '@')
5153 if (!strncmp (input_line_pointer
, PLT_SUFFIX
, strlen (PLT_SUFFIX
) - 1)
5154 && !strncmp (input_line_pointer
, plt_suffix
,
5155 strlen (plt_suffix
) - 1))
5157 as_bad (_("undefined @ suffix '%s', expected '%s'"),
5158 input_line_pointer
, plt_suffix
);
5159 ignore_rest_of_line ();
5163 input_line_pointer
+= strlen (plt_suffix
);
5176 r
= plt
? BFD_RELOC_XTENSA_PLT
: BFD_RELOC_32
;
5182 as_bad (_("unsupported BFD relocation size %u"), size
);
5186 fix_new_exp (frag
, where
, size
, exp
, 0, r
);
5190 /* TC_FRAG_INIT hook */
5193 xtensa_frag_init (frag
)
5196 frag
->tc_frag_data
.is_no_density
= !code_density_available ();
5201 md_undefined_symbol (name
)
5202 char *name ATTRIBUTE_UNUSED
;
5208 /* Round up a section size to the appropriate boundary. */
5211 md_section_align (segment
, size
)
5212 segT segment ATTRIBUTE_UNUSED
;
5215 return size
; /* Byte alignment is fine. */
5220 md_pcrel_from (fixP
)
5224 static xtensa_insnbuf insnbuf
= NULL
;
5226 xtensa_operand operand
;
5227 xtensa_opcode opcode
;
5228 xtensa_isa isa
= xtensa_default_isa
;
5229 valueT addr
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
5234 if (fixP
->fx_r_type
== BFD_RELOC_XTENSA_ASM_EXPAND
)
5238 insnbuf
= xtensa_insnbuf_alloc (isa
);
5240 insn_p
= &fixP
->fx_frag
->fr_literal
[fixP
->fx_where
];
5241 xtensa_insnbuf_from_chars (isa
, insnbuf
, insn_p
);
5242 opcode
= xtensa_decode_insn (isa
, insnbuf
);
5244 opnum
= reloc_to_opnum (fixP
->fx_r_type
);
5247 as_fatal (_("invalid operand relocation for '%s' instruction"),
5248 xtensa_opcode_name (isa
, opcode
));
5249 if (opnum
>= xtensa_num_operands (isa
, opcode
))
5250 as_fatal (_("invalid relocation for operand %d in '%s' instruction"),
5251 opnum
, xtensa_opcode_name (isa
, opcode
));
5252 operand
= xtensa_get_operand (isa
, opcode
, opnum
);
5255 as_warn_where (fixP
->fx_file
,
5257 _("invalid relocation type %d for %s instruction"),
5258 fixP
->fx_r_type
, xtensa_opcode_name (isa
, opcode
));
5262 if (!operand_is_pcrel_label (operand
))
5264 as_bad_where (fixP
->fx_file
,
5266 _("invalid relocation for operand %d of '%s'"),
5267 opnum
, xtensa_opcode_name (isa
, opcode
));
5270 if (!xtensa_operand_isPCRelative (operand
))
5272 as_warn_where (fixP
->fx_file
,
5274 _("non-PCREL relocation operand %d for '%s': %s"),
5275 opnum
, xtensa_opcode_name (isa
, opcode
),
5276 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5280 return 0 - xtensa_operand_do_reloc (operand
, 0, addr
);
5284 /* tc_symbol_new_hook */
5287 xtensa_symbol_new_hook (symbolP
)
5290 symbolP
->sy_tc
.plt
= 0;
5294 /* tc_fix_adjustable hook */
5297 xtensa_fix_adjustable (fixP
)
5300 /* We need the symbol name for the VTABLE entries. */
5301 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
5302 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
5310 md_apply_fix3 (fixP
, valP
, seg
)
5313 segT seg ATTRIBUTE_UNUSED
;
5315 if (fixP
->fx_pcrel
== 0 && fixP
->fx_addsy
== 0)
5317 /* This happens when the relocation is within the current section.
5318 It seems this implies a PCREL operation. We'll catch it and error
5321 char *const fixpos
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5322 static xtensa_insnbuf insnbuf
= NULL
;
5323 xtensa_opcode opcode
;
5326 switch (fixP
->fx_r_type
)
5328 case BFD_RELOC_XTENSA_ASM_EXPAND
:
5332 case BFD_RELOC_XTENSA_ASM_SIMPLIFY
:
5333 as_bad (_("unhandled local relocation fix %s"),
5334 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5340 /* The only one we support that isn't an instruction field. */
5341 md_number_to_chars (fixpos
, *valP
, fixP
->fx_size
);
5345 case BFD_RELOC_XTENSA_OP0
:
5346 case BFD_RELOC_XTENSA_OP1
:
5347 case BFD_RELOC_XTENSA_OP2
:
5348 isa
= xtensa_default_isa
;
5350 insnbuf
= xtensa_insnbuf_alloc (isa
);
5352 xtensa_insnbuf_from_chars (isa
, insnbuf
, fixpos
);
5353 opcode
= xtensa_decode_insn (isa
, insnbuf
);
5354 if (opcode
== XTENSA_UNDEFINED
)
5355 as_fatal (_("undecodable FIX"));
5357 xtensa_insnbuf_set_immediate_field (opcode
, insnbuf
, *valP
,
5358 fixP
->fx_file
, fixP
->fx_line
);
5360 fixP
->fx_frag
->tc_frag_data
.is_insn
= TRUE
;
5361 xtensa_insnbuf_to_chars (isa
, insnbuf
, fixpos
);
5365 case BFD_RELOC_VTABLE_INHERIT
:
5366 case BFD_RELOC_VTABLE_ENTRY
:
5371 as_bad (_("unhandled local relocation fix %s"),
5372 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5379 md_atof (type
, litP
, sizeP
)
5385 LITTLENUM_TYPE words
[4];
5401 return "bad call to md_atof";
5404 t
= atof_ieee (input_line_pointer
, type
, words
);
5406 input_line_pointer
= t
;
5410 for (i
= prec
- 1; i
>= 0; i
--)
5413 if (target_big_endian
)
5414 idx
= (prec
- 1 - i
);
5416 md_number_to_chars (litP
, (valueT
) words
[idx
], 2);
5425 md_estimate_size_before_relax (fragP
, seg
)
5427 segT seg ATTRIBUTE_UNUSED
;
5429 return fragP
->tc_frag_data
.text_expansion
;
5433 /* Translate internal representation of relocation info to BFD target
5437 tc_gen_reloc (section
, fixp
)
5438 asection
*section ATTRIBUTE_UNUSED
;
5443 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5444 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5445 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5446 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5448 /* Make sure none of our internal relocations make it this far.
5449 They'd better have been fully resolved by this point. */
5450 assert ((int) fixp
->fx_r_type
> 0);
5452 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5453 if (reloc
->howto
== NULL
)
5455 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5456 _("cannot represent `%s' relocation in object file"),
5457 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5461 if (!fixp
->fx_pcrel
!= !reloc
->howto
->pc_relative
)
5463 as_fatal (_("internal error? cannot generate `%s' relocation"),
5464 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5466 assert (!fixp
->fx_pcrel
== !reloc
->howto
->pc_relative
);
5468 reloc
->addend
= fixp
->fx_offset
;
5470 switch (fixp
->fx_r_type
)
5472 case BFD_RELOC_XTENSA_OP0
:
5473 case BFD_RELOC_XTENSA_OP1
:
5474 case BFD_RELOC_XTENSA_OP2
:
5475 case BFD_RELOC_XTENSA_ASM_EXPAND
:
5477 case BFD_RELOC_XTENSA_PLT
:
5478 case BFD_RELOC_VTABLE_INHERIT
:
5479 case BFD_RELOC_VTABLE_ENTRY
:
5482 case BFD_RELOC_XTENSA_ASM_SIMPLIFY
:
5483 as_warn (_("emitting simplification relocation"));
5487 as_warn (_("emitting unknown relocation"));
5497 directive_balance ();
5498 xtensa_move_literals ();
5500 xtensa_reorder_segments ();
5501 xtensa_mark_target_fragments ();
5502 xtensa_cleanup_align_frags ();
5503 xtensa_fix_target_frags ();
5504 if (software_a0_b_retw_interlock
&& has_a0_b_retw
)
5505 xtensa_fix_a0_b_retw_frags ();
5506 if (software_avoid_b_j_loop_end
&& maybe_has_b_j_loop_end
)
5507 xtensa_fix_b_j_loop_end_frags ();
5509 /* "close_loop_end" should be processed BEFORE "short_loop". */
5510 if (software_avoid_close_loop_end
&& maybe_has_close_loop_end
)
5511 xtensa_fix_close_loop_end_frags ();
5513 if (software_avoid_short_loop
&& maybe_has_short_loop
)
5514 xtensa_fix_short_loop_frags ();
5516 xtensa_sanity_check ();
5521 xtensa_cleanup_align_frags ()
5525 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
5529 /* Walk over all of the fragments in a subsection. */
5530 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
5532 if ((fragP
->fr_type
== rs_align
5533 || fragP
->fr_type
== rs_align_code
5534 || (fragP
->fr_type
== rs_machine_dependent
5535 && (fragP
->fr_subtype
== RELAX_DESIRE_ALIGN
5536 || fragP
->fr_subtype
== RELAX_DESIRE_ALIGN_IF_TARGET
)))
5537 && fragP
->fr_fix
== 0)
5539 fragS
* next
= fragP
->fr_next
;
5542 && next
->fr_type
== rs_machine_dependent
5543 && next
->fr_subtype
== RELAX_DESIRE_ALIGN_IF_TARGET
)
5546 next
= next
->fr_next
;
5554 /* Re-process all of the fragments looking to convert all of the
5555 RELAX_DESIRE_ALIGN_IF_TARGET fragments. If there is a branch
5556 target in the next fragment, convert this to RELAX_DESIRE_ALIGN.
5557 If the next fragment starts with a loop target, AND the previous
5558 fragment can be expanded to negate the branch, convert this to a
5559 RELAX_LOOP_END. Otherwise, convert to a .fill 0. */
5562 xtensa_fix_target_frags ()
5566 /* When this routine is called, all of the subsections are still intact
5567 so we walk over subsections instead of sections. */
5568 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
5570 bfd_boolean prev_frag_can_negate_branch
= FALSE
;
5573 /* Walk over all of the fragments in a subsection. */
5574 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
5576 if (fragP
->fr_type
== rs_machine_dependent
5577 && fragP
->fr_subtype
== RELAX_DESIRE_ALIGN_IF_TARGET
)
5579 if (next_frag_is_loop_target (fragP
))
5581 if (prev_frag_can_negate_branch
)
5582 fragP
->fr_subtype
= RELAX_LOOP_END
;
5585 if (!align_only_targets
||
5586 next_frag_is_branch_target (fragP
))
5587 fragP
->fr_subtype
= RELAX_DESIRE_ALIGN
;
5592 else if (!align_only_targets
5593 || next_frag_is_branch_target (fragP
))
5594 fragP
->fr_subtype
= RELAX_DESIRE_ALIGN
;
5598 if (fragP
->fr_fix
!= 0)
5599 prev_frag_can_negate_branch
= FALSE
;
5600 if (frag_can_negate_branch (fragP
))
5601 prev_frag_can_negate_branch
= TRUE
;
5608 frag_can_negate_branch (fragP
)
5611 if (fragP
->fr_type
== rs_machine_dependent
5612 && fragP
->fr_subtype
== RELAX_IMMED
)
5615 tinsn_from_chars (&t_insn
, fragP
->fr_opcode
);
5616 if (is_negatable_branch (&t_insn
))
5623 /* Re-process all of the fragments looking to convert all of the
5624 RELAX_ADD_NOP_IF_A0_B_RETW. If the next instruction is a
5625 conditional branch or a retw/retw.n, convert this frag to one that
5626 will generate a NOP. In any case close it off with a .fill 0. */
5629 xtensa_fix_a0_b_retw_frags ()
5633 /* When this routine is called, all of the subsections are still intact
5634 so we walk over subsections instead of sections. */
5635 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
5639 /* Walk over all of the fragments in a subsection. */
5640 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
5642 if (fragP
->fr_type
== rs_machine_dependent
5643 && fragP
->fr_subtype
== RELAX_ADD_NOP_IF_A0_B_RETW
)
5645 if (next_instrs_are_b_retw (fragP
))
5646 relax_frag_add_nop (fragP
);
5656 next_instrs_are_b_retw (fragP
)
5659 xtensa_opcode opcode
;
5660 const fragS
*next_fragP
= next_non_empty_frag (fragP
);
5661 static xtensa_insnbuf insnbuf
= NULL
;
5662 xtensa_isa isa
= xtensa_default_isa
;
5666 insnbuf
= xtensa_insnbuf_alloc (isa
);
5668 if (next_fragP
== NULL
)
5671 /* Check for the conditional branch. */
5672 xtensa_insnbuf_from_chars (isa
, insnbuf
, &next_fragP
->fr_literal
[offset
]);
5673 opcode
= xtensa_decode_insn (isa
, insnbuf
);
5675 if (!is_conditional_branch_opcode (opcode
))
5678 offset
+= xtensa_insn_length (isa
, opcode
);
5679 if (offset
== next_fragP
->fr_fix
)
5681 next_fragP
= next_non_empty_frag (next_fragP
);
5684 if (next_fragP
== NULL
)
5687 /* Check for the retw/retw.n. */
5688 xtensa_insnbuf_from_chars (isa
, insnbuf
, &next_fragP
->fr_literal
[offset
]);
5689 opcode
= xtensa_decode_insn (isa
, insnbuf
);
5691 if (is_windowed_return_opcode (opcode
))
5697 /* Re-process all of the fragments looking to convert all of the
5698 RELAX_ADD_NOP_IF_PRE_LOOP_END. If there is one instruction and a
5699 loop end label, convert this frag to one that will generate a NOP.
5700 In any case close it off with a .fill 0. */
5703 xtensa_fix_b_j_loop_end_frags ()
5707 /* When this routine is called, all of the subsections are still intact
5708 so we walk over subsections instead of sections. */
5709 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
5713 /* Walk over all of the fragments in a subsection. */
5714 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
5716 if (fragP
->fr_type
== rs_machine_dependent
5717 && fragP
->fr_subtype
== RELAX_ADD_NOP_IF_PRE_LOOP_END
)
5719 if (next_instr_is_loop_end (fragP
))
5720 relax_frag_add_nop (fragP
);
5730 next_instr_is_loop_end (fragP
)
5733 const fragS
*next_fragP
;
5735 if (next_frag_is_loop_target (fragP
))
5738 next_fragP
= next_non_empty_frag (fragP
);
5739 if (next_fragP
== NULL
)
5742 if (!next_frag_is_loop_target (next_fragP
))
5745 /* If the size is >= 3 then there is more than one instruction here.
5746 The hardware bug will not fire. */
5747 if (next_fragP
->fr_fix
> 3)
5754 /* Re-process all of the fragments looking to convert all of the
5755 RELAX_ADD_NOP_IF_CLOSE_LOOP_END. If there is an loop end that is
5756 not MY loop's loop end within 12 bytes, add enough nops here to
5757 make it at least 12 bytes away. In any case close it off with a
5761 xtensa_fix_close_loop_end_frags ()
5765 /* When this routine is called, all of the subsections are still intact
5766 so we walk over subsections instead of sections. */
5767 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
5771 fragS
*current_target
= NULL
;
5772 offsetT current_offset
= 0;
5774 /* Walk over all of the fragments in a subsection. */
5775 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
5777 if (fragP
->fr_type
== rs_machine_dependent
5778 && fragP
->fr_subtype
== RELAX_IMMED
)
5780 /* Read it. If the instruction is a loop, get the target. */
5781 xtensa_opcode opcode
= get_opcode_from_buf (fragP
->fr_opcode
);
5782 if (is_loop_opcode (opcode
))
5786 tinsn_from_chars (&t_insn
, fragP
->fr_opcode
);
5787 tinsn_immed_from_frag (&t_insn
, fragP
);
5789 /* Get the current fragment target. */
5790 if (fragP
->fr_symbol
)
5792 current_target
= symbol_get_frag (fragP
->fr_symbol
);
5793 current_offset
= fragP
->fr_offset
;
5799 && fragP
->fr_type
== rs_machine_dependent
5800 && fragP
->fr_subtype
== RELAX_ADD_NOP_IF_CLOSE_LOOP_END
)
5803 size_t bytes_added
= 0;
5805 #define REQUIRED_LOOP_DIVIDING_BYTES 12
5806 /* Max out at 12. */
5807 min_bytes
= min_bytes_to_other_loop_end
5808 (fragP
->fr_next
, current_target
, current_offset
,
5809 REQUIRED_LOOP_DIVIDING_BYTES
);
5811 if (min_bytes
< REQUIRED_LOOP_DIVIDING_BYTES
)
5813 while (min_bytes
+ bytes_added
5814 < REQUIRED_LOOP_DIVIDING_BYTES
)
5818 if (fragP
->fr_var
< length
)
5819 as_warn (_("fr_var %lu < length %d; ignoring"),
5820 fragP
->fr_var
, length
);
5823 assemble_nop (length
,
5824 fragP
->fr_literal
+ fragP
->fr_fix
);
5825 fragP
->fr_fix
+= length
;
5826 fragP
->fr_var
-= length
;
5828 bytes_added
+= length
;
5839 min_bytes_to_other_loop_end (fragP
, current_target
, current_offset
, max_size
)
5841 fragS
*current_target
;
5842 offsetT current_offset
;
5846 fragS
*current_fragP
;
5848 for (current_fragP
= fragP
;
5850 current_fragP
= current_fragP
->fr_next
)
5852 if (current_fragP
->tc_frag_data
.is_loop_target
5853 && current_fragP
!= current_target
)
5854 return offset
+ current_offset
;
5856 offset
+= unrelaxed_frag_min_size (current_fragP
);
5858 if (offset
+ current_offset
>= max_size
)
5866 unrelaxed_frag_min_size (fragP
)
5869 size_t size
= fragP
->fr_fix
;
5872 if (fragP
->fr_type
== rs_fill
)
5873 size
+= fragP
->fr_offset
;
5879 /* Re-process all of the fragments looking to convert all
5880 of the RELAX_ADD_NOP_IF_SHORT_LOOP. If:
5883 1) the instruction size count to the loop end label
5884 is too short (<= 2 instructions),
5885 2) loop has a jump or branch in it
5888 1) software_avoid_all_short_loops is true
5889 2) The generating loop was a 'loopgtz' or 'loopnez'
5890 3) the instruction size count to the loop end label is too short
5892 then convert this frag (and maybe the next one) to generate a NOP.
5893 In any case close it off with a .fill 0. */
5896 xtensa_fix_short_loop_frags ()
5900 /* When this routine is called, all of the subsections are still intact
5901 so we walk over subsections instead of sections. */
5902 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
5905 fragS
*current_target
= NULL
;
5906 offsetT current_offset
= 0;
5907 xtensa_opcode current_opcode
= XTENSA_UNDEFINED
;
5909 /* Walk over all of the fragments in a subsection. */
5910 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
5912 /* check on the current loop */
5913 if (fragP
->fr_type
== rs_machine_dependent
5914 && fragP
->fr_subtype
== RELAX_IMMED
)
5916 /* Read it. If the instruction is a loop, get the target. */
5917 xtensa_opcode opcode
= get_opcode_from_buf (fragP
->fr_opcode
);
5918 if (is_loop_opcode (opcode
))
5922 tinsn_from_chars (&t_insn
, fragP
->fr_opcode
);
5923 tinsn_immed_from_frag (&t_insn
, fragP
);
5925 /* Get the current fragment target. */
5926 if (fragP
->fr_symbol
)
5928 current_target
= symbol_get_frag (fragP
->fr_symbol
);
5929 current_offset
= fragP
->fr_offset
;
5930 current_opcode
= opcode
;
5935 if (fragP
->fr_type
== rs_machine_dependent
5936 && fragP
->fr_subtype
== RELAX_ADD_NOP_IF_SHORT_LOOP
)
5939 count_insns_to_loop_end (fragP
->fr_next
, TRUE
, 3);
5941 && (branch_before_loop_end (fragP
->fr_next
)
5942 || (software_avoid_all_short_loops
5943 && current_opcode
!= XTENSA_UNDEFINED
5944 && !is_the_loop_opcode (current_opcode
))))
5945 relax_frag_add_nop (fragP
);
5955 count_insns_to_loop_end (base_fragP
, count_relax_add
, max_count
)
5957 bfd_boolean count_relax_add
;
5960 fragS
*fragP
= NULL
;
5961 size_t insn_count
= 0;
5965 for (; fragP
&& !fragP
->tc_frag_data
.is_loop_target
; fragP
= fragP
->fr_next
)
5967 insn_count
+= unrelaxed_frag_min_insn_count (fragP
);
5968 if (insn_count
>= max_count
)
5971 if (count_relax_add
)
5973 if (fragP
->fr_type
== rs_machine_dependent
5974 && fragP
->fr_subtype
== RELAX_ADD_NOP_IF_SHORT_LOOP
)
5976 /* In order to add the appropriate number of
5977 NOPs, we count an instruction for downstream
5980 if (insn_count
>= max_count
)
5990 unrelaxed_frag_min_insn_count (fragP
)
5993 size_t insn_count
= 0;
5996 if (!fragP
->tc_frag_data
.is_insn
)
5999 /* Decode the fixed instructions. */
6000 while (offset
< fragP
->fr_fix
)
6002 xtensa_opcode opcode
= get_opcode_from_buf (fragP
->fr_literal
+ offset
);
6003 if (opcode
== XTENSA_UNDEFINED
)
6005 as_fatal (_("undecodable instruction in instruction frag"));
6008 offset
+= xtensa_insn_length (xtensa_default_isa
, opcode
);
6017 branch_before_loop_end (base_fragP
)
6022 for (fragP
= base_fragP
;
6023 fragP
&& !fragP
->tc_frag_data
.is_loop_target
;
6024 fragP
= fragP
->fr_next
)
6026 if (unrelaxed_frag_has_b_j (fragP
))
6034 unrelaxed_frag_has_b_j (fragP
)
6037 size_t insn_count
= 0;
6040 if (!fragP
->tc_frag_data
.is_insn
)
6043 /* Decode the fixed instructions. */
6044 while (offset
< fragP
->fr_fix
)
6046 xtensa_opcode opcode
= get_opcode_from_buf (fragP
->fr_literal
+ offset
);
6047 if (opcode
== XTENSA_UNDEFINED
)
6049 as_fatal (_("undecodable instruction in instruction frag"));
6052 if (is_branch_or_jump_opcode (opcode
))
6054 offset
+= xtensa_insn_length (xtensa_default_isa
, opcode
);
6060 /* Checks to be made after initial assembly but before relaxation. */
6063 xtensa_sanity_check ()
6070 as_where (&file_name
, &line
);
6071 for (frchP
= frchain_root
; frchP
; frchP
= frchP
->frch_next
)
6075 /* Walk over all of the fragments in a subsection. */
6076 for (fragP
= frchP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
6078 /* Currently we only check for empty loops here. */
6079 if (fragP
->fr_type
== rs_machine_dependent
6080 && fragP
->fr_subtype
== RELAX_IMMED
)
6082 static xtensa_insnbuf insnbuf
= NULL
;
6085 if (fragP
->fr_opcode
!= NULL
)
6088 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
6089 tinsn_from_chars (&t_insn
, fragP
->fr_opcode
);
6090 tinsn_immed_from_frag (&t_insn
, fragP
);
6092 if (is_loop_opcode (t_insn
.opcode
))
6094 if (is_empty_loop (&t_insn
, fragP
))
6096 new_logical_line (fragP
->fr_file
, fragP
->fr_line
);
6097 as_bad (_("invalid empty loop"));
6099 if (!is_local_forward_loop (&t_insn
, fragP
))
6101 new_logical_line (fragP
->fr_file
, fragP
->fr_line
);
6102 as_bad (_("loop target does not follow "
6103 "loop instruction in section"));
6110 new_logical_line (file_name
, line
);
6114 #define LOOP_IMMED_OPN 1
6116 /* Return true if the loop target is the next non-zero fragment. */
6119 is_empty_loop (insn
, fragP
)
6123 const expressionS
*expr
;
6127 if (insn
->insn_type
!= ITYPE_INSN
)
6130 if (!is_loop_opcode (insn
->opcode
))
6133 if (insn
->ntok
<= LOOP_IMMED_OPN
)
6136 expr
= &insn
->tok
[LOOP_IMMED_OPN
];
6138 if (expr
->X_op
!= O_symbol
)
6141 symbolP
= expr
->X_add_symbol
;
6145 if (symbol_get_frag (symbolP
) == NULL
)
6148 if (S_GET_VALUE (symbolP
) != 0)
6151 /* Walk through the zero-size fragments from this one. If we find
6152 the target fragment, then this is a zero-size loop. */
6153 for (next_fragP
= fragP
->fr_next
;
6155 next_fragP
= next_fragP
->fr_next
)
6157 if (next_fragP
== symbol_get_frag (symbolP
))
6159 if (next_fragP
->fr_fix
!= 0)
6167 is_local_forward_loop (insn
, fragP
)
6171 const expressionS
*expr
;
6175 if (insn
->insn_type
!= ITYPE_INSN
)
6178 if (!is_loop_opcode (insn
->opcode
))
6181 if (insn
->ntok
<= LOOP_IMMED_OPN
)
6184 expr
= &insn
->tok
[LOOP_IMMED_OPN
];
6186 if (expr
->X_op
!= O_symbol
)
6189 symbolP
= expr
->X_add_symbol
;
6193 if (symbol_get_frag (symbolP
) == NULL
)
6196 /* Walk through fragments until we find the target.
6197 If we do not find the target, then this is an invalid loop. */
6198 for (next_fragP
= fragP
->fr_next
;
6200 next_fragP
= next_fragP
->fr_next
)
6201 if (next_fragP
== symbol_get_frag (symbolP
))
6208 /* Alignment Functions. */
6211 get_text_align_power (target_size
)
6215 for (i
= 0; i
< sizeof (size_t); i
++)
6217 if (target_size
<= (1 << i
))
6220 as_fatal (_("get_text_align_power: argument too large"));
6226 get_text_align_max_fill_size (align_pow
, use_nops
, use_no_density
)
6228 bfd_boolean use_nops
;
6229 bfd_boolean use_no_density
;
6232 return (1 << align_pow
);
6234 return 3 * (1 << align_pow
);
6236 return 1 + (1 << align_pow
);
6240 /* get_text_align_fill_size ()
6244 target_size = size of next instruction
6245 align_pow = get_text_align_power (target_size).
6249 address = current address + loop instruction size;
6250 target_size = 3 (for 2 or 3 byte target)
6251 = 8 (for 8 byte target)
6252 align_pow = get_text_align_power (target_size);
6254 use_no_density = set appropriately
6256 address = current address + loop instruction size;
6258 align_pow = get_text_align_power (target_size);
6260 use_no_density = 0. */
6263 get_text_align_fill_size (address
, align_pow
, target_size
,
6264 use_nops
, use_no_density
)
6268 bfd_boolean use_nops
;
6269 bfd_boolean use_no_density
;
6273 align_pow: log2 (required alignment).
6275 target_size: alignment must allow the new_address and
6276 new_address+target_size-1.
6278 use_nops: if true, then we can only use 2 or 3 byte nops.
6280 use_no_density: if use_nops and use_no_density, we can only use
6283 Usually, for non-zero target_size, the align_pow is the power of 2
6284 that is greater than or equal to the target_size. This handles the
6285 2-byte, 3-byte and 8-byte instructions. */
6287 size_t alignment
= (1 << align_pow
);
6290 /* This is the easy case. */
6292 mod
= address
% alignment
;
6294 mod
= alignment
- mod
;
6295 assert ((address
+ mod
) % alignment
== 0);
6299 /* This is the slightly harder case. */
6300 assert ((int) alignment
>= target_size
);
6301 assert (target_size
> 0);
6302 if (!use_no_density
)
6305 for (i
= 0; i
< alignment
* 2; i
++)
6309 if ((address
+ i
) >> align_pow
==
6310 (address
+ i
+ target_size
- 1) >> align_pow
)
6318 /* Can only fill multiples of 3. */
6319 for (i
= 0; i
<= alignment
* 3; i
+= 3)
6321 if ((address
+ i
) >> align_pow
==
6322 (address
+ i
+ target_size
- 1) >> align_pow
)
6331 /* This will assert if it is not possible. */
6334 get_text_align_nop_count (fill_size
, use_no_density
)
6336 bfd_boolean use_no_density
;
6341 assert (fill_size
% 3 == 0);
6342 return (fill_size
/ 3);
6345 assert (fill_size
!= 1); /* Bad argument. */
6347 while (fill_size
> 1)
6349 size_t insn_size
= 3;
6350 if (fill_size
== 2 || fill_size
== 4)
6352 fill_size
-= insn_size
;
6355 assert (fill_size
!= 1); /* Bad algorithm. */
6361 get_text_align_nth_nop_size (fill_size
, n
, use_no_density
)
6364 bfd_boolean use_no_density
;
6368 assert (get_text_align_nop_count (fill_size
, use_no_density
) > n
);
6373 while (fill_size
> 1)
6375 size_t insn_size
= 3;
6376 if (fill_size
== 2 || fill_size
== 4)
6378 fill_size
-= insn_size
;
6388 /* For the given fragment, find the appropriate address
6389 for it to begin at if we are using NOPs to align it. */
6392 get_noop_aligned_address (fragP
, address
)
6396 static xtensa_insnbuf insnbuf
= NULL
;
6397 size_t fill_size
= 0;
6400 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
6402 switch (fragP
->fr_type
)
6404 case rs_machine_dependent
:
6405 if (fragP
->fr_subtype
== RELAX_ALIGN_NEXT_OPCODE
)
6407 /* The rule is: get next fragment's FIRST instruction. Find
6408 the smallest number of bytes that need to be added to
6409 ensure that the next fragment's FIRST instruction will fit
6412 E.G., 2 bytes : 0, 1, 2 mod 4
6415 If the FIRST instruction MIGHT be relaxed,
6416 assume that it will become a 3 byte instruction. */
6418 int target_insn_size
;
6419 xtensa_opcode opcode
= next_frag_opcode (fragP
);
6420 addressT pre_opcode_bytes
;
6422 if (opcode
== XTENSA_UNDEFINED
)
6424 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
6425 _("invalid opcode for RELAX_ALIGN_NEXT_OPCODE"));
6426 as_fatal (_("cannot continue"));
6429 target_insn_size
= xtensa_insn_length (xtensa_default_isa
, opcode
);
6431 pre_opcode_bytes
= next_frag_pre_opcode_bytes (fragP
);
6433 if (is_loop_opcode (opcode
))
6435 /* next_fragP should be the loop. */
6436 const fragS
*next_fragP
= next_non_empty_frag (fragP
);
6437 xtensa_opcode next_opcode
= next_frag_opcode (next_fragP
);
6440 pre_opcode_bytes
+= target_insn_size
;
6442 /* For loops, the alignment depends on the size of the
6443 instruction following the loop, not the loop instruction. */
6444 if (next_opcode
== XTENSA_UNDEFINED
)
6445 target_insn_size
= 3;
6449 xtensa_insn_length (xtensa_default_isa
, next_opcode
);
6451 if (target_insn_size
== 2)
6452 target_insn_size
= 3; /* ISA specifies this. */
6455 /* If it was 8, then we'll need a larger alignment
6457 alignment
= get_text_align_power (target_insn_size
);
6459 /* Is Now_seg valid */
6460 record_alignment (now_seg
, alignment
);
6463 as_fatal (_("expected loop opcode in relax align next target"));
6465 fill_size
= get_text_align_fill_size
6466 (address
+ pre_opcode_bytes
,
6467 get_text_align_power (target_insn_size
),
6468 target_insn_size
, TRUE
, fragP
->tc_frag_data
.is_no_density
);
6474 fill_size
= get_text_align_fill_size
6475 (address
, fragP
->fr_offset
, 1, TRUE
,
6476 fragP
->tc_frag_data
.is_no_density
);
6480 as_fatal (_("expected align_code or RELAX_ALIGN_NEXT_OPCODE"));
6483 return address
+ fill_size
;
6487 /* 3 mechanisms for relaxing an alignment:
6489 Align to a power of 2.
6490 Align so the next fragment's instruction does not cross a word boundary.
6491 Align the current instruction so that if the next instruction
6492 were 3 bytes, it would not cross a word boundary.
6496 zeros - This is easy; always insert zeros.
6497 nops - 3 and 2 byte instructions
6501 >=5 : 3 byte instruction + fn(n-3)
6502 widening - widen previous instructions. */
6505 get_widen_aligned_address (fragP
, address
)
6509 addressT align_pow
, new_address
, loop_insn_offset
;
6512 xtensa_opcode opcode
, next_opcode
;
6513 static xtensa_insnbuf insnbuf
= NULL
;
6516 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
6518 if (fragP
->fr_type
== rs_align
|| fragP
->fr_type
== rs_align_code
)
6520 align_pow
= fragP
->fr_offset
;
6521 new_address
= ((address
+ ((1 << align_pow
) - 1))
6522 << align_pow
) >> align_pow
;
6526 if (fragP
->fr_type
== rs_machine_dependent
)
6528 switch (fragP
->fr_subtype
)
6530 case RELAX_DESIRE_ALIGN
:
6532 /* The rule is: get the next fragment's FIRST instruction.
6533 Find the smallest number of bytes needed to be added
6534 in order to ensure that the next fragment is FIRST
6535 instruction will fit in a single word.
6536 i.e. 2 bytes : 0, 1, 2. mod 4
6538 If the FIRST instruction MIGHT be relaxed,
6539 assume that it will become a 3-byte instruction. */
6542 /* Check to see if it might be 2 bytes. */
6543 next_opcode
= next_frag_opcode (fragP
);
6544 if (next_opcode
!= XTENSA_UNDEFINED
6545 && xtensa_insn_length (xtensa_default_isa
, next_opcode
) == 2)
6548 assert (insn_size
<= 4);
6549 for (new_address
= address
; new_address
< address
+ 4; new_address
++)
6551 if (new_address
>> 2 == (new_address
+ insn_size
- 1) >> 2)
6554 as_bad (_("internal error aligning"));
6557 case RELAX_ALIGN_NEXT_OPCODE
:
6558 /* The rule is: get next fragment's FIRST instruction.
6559 Find the smallest number of bytes needed to be added
6560 in order to ensure that the next fragment's FIRST
6561 instruction will fit in a single word.
6562 i.e. 2 bytes : 0, 1, 2. mod 4
6564 If the FIRST instruction MIGHT be relaxed,
6565 assume that it will become a 3 byte instruction. */
6567 opcode
= next_frag_opcode (fragP
);
6568 if (opcode
== XTENSA_UNDEFINED
)
6570 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
6571 _("invalid opcode for RELAX_ALIGN_NEXT_OPCODE"));
6572 as_fatal (_("cannot continue"));
6574 insn_size
= xtensa_insn_length (xtensa_default_isa
, opcode
);
6575 assert (insn_size
<= 4);
6576 assert (is_loop_opcode (opcode
));
6578 loop_insn_offset
= 0;
6579 next_frag
= next_non_empty_frag (fragP
);
6581 /* If the loop has been expanded then the loop
6582 instruction could be at an offset from this fragment. */
6583 if (next_frag
->fr_subtype
!= RELAX_IMMED
)
6584 loop_insn_offset
= get_expanded_loop_offset (opcode
);
6586 for (new_address
= address
; new_address
< address
+ 4; new_address
++)
6588 if ((new_address
+ loop_insn_offset
+ insn_size
) >> 2 ==
6589 (new_address
+ loop_insn_offset
+ insn_size
+ 2) >> 2)
6592 as_bad (_("internal error aligning"));
6596 as_bad (_("internal error aligning"));
6600 as_bad (_("internal error aligning"));
6605 /* md_relax_frag Hook and Helper Functions. */
6607 /* Return the number of bytes added to this fragment, given that the
6608 input has been stretched already by "stretch". */
6611 xtensa_relax_frag (fragP
, stretch
, stretched_p
)
6616 int unreported
= fragP
->tc_frag_data
.unreported_expansion
;
6617 long new_stretch
= 0;
6621 as_where (&file_name
, &line
);
6622 new_logical_line (fragP
->fr_file
, fragP
->fr_line
);
6624 fragP
->tc_frag_data
.unreported_expansion
= 0;
6626 switch (fragP
->fr_subtype
)
6628 case RELAX_ALIGN_NEXT_OPCODE
:
6629 /* Always convert. */
6630 new_stretch
= relax_frag_text_align (fragP
, stretch
);
6633 case RELAX_LOOP_END
:
6637 case RELAX_LOOP_END_ADD_NOP
:
6638 /* Add a NOP and switch to .fill 0. */
6639 new_stretch
= relax_frag_add_nop (fragP
);
6642 case RELAX_DESIRE_ALIGN
:
6643 /* We REALLY want to change the relaxation order here. This
6644 should do NOTHING. The narrowing before it will either align
6649 case RELAX_LITERAL_FINAL
:
6652 case RELAX_LITERAL_NR
:
6654 fragP
->fr_subtype
= RELAX_LITERAL_FINAL
;
6655 assert (unreported
== lit_size
);
6656 memset (&fragP
->fr_literal
[fragP
->fr_fix
], 0, 4);
6657 fragP
->fr_var
-= lit_size
;
6658 fragP
->fr_fix
+= lit_size
;
6663 new_stretch
= relax_frag_narrow (fragP
, stretch
);
6667 case RELAX_IMMED_STEP1
:
6668 case RELAX_IMMED_STEP2
:
6669 /* Place the immediate. */
6670 new_stretch
= relax_frag_immed (now_seg
, fragP
, stretch
,
6671 fragP
->fr_subtype
- RELAX_IMMED
,
6675 case RELAX_LITERAL_POOL_BEGIN
:
6676 case RELAX_LITERAL_POOL_END
:
6677 /* No relaxation required. */
6681 as_bad (_("bad relaxation state"));
6684 new_logical_line (file_name
, line
);
6690 relax_frag_text_align (fragP
, stretch
)
6694 addressT old_address
, old_next_address
, old_size
;
6695 addressT new_address
, new_next_address
, new_size
;
6698 /* Overview of the relaxation procedure for alignment
6699 inside an executable section:
6701 The old size is stored in the tc_frag_data.text_expansion field.
6703 Calculate the new address, fix up the text_expansion and
6704 return the growth. */
6706 /* Calculate the old address of this fragment and the next fragment. */
6707 old_address
= fragP
->fr_address
- stretch
;
6708 old_next_address
= (fragP
->fr_address
- stretch
+ fragP
->fr_fix
+
6709 fragP
->tc_frag_data
.text_expansion
);
6710 old_size
= old_next_address
- old_address
;
6712 /* Calculate the new address of this fragment and the next fragment. */
6713 new_address
= fragP
->fr_address
;
6715 get_noop_aligned_address (fragP
, fragP
->fr_address
+ fragP
->fr_fix
);
6716 new_size
= new_next_address
- new_address
;
6718 growth
= new_size
- old_size
;
6720 /* Fix up the text_expansion field and return the new growth. */
6721 fragP
->tc_frag_data
.text_expansion
+= growth
;
6726 /* Add a NOP (i.e., "or a1, a1, a1"). Use the 3-byte one because we
6727 don't know about the availability of density yet. TODO: When the
6728 flags are stored per fragment, use NOP.N when possible. */
6731 relax_frag_add_nop (fragP
)
6734 static xtensa_insnbuf insnbuf
= NULL
;
6736 char *nop_buf
= fragP
->fr_literal
+ fragP
->fr_fix
;
6739 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
6741 tinsn_init (&t_insn
);
6742 t_insn
.opcode
= xtensa_or_opcode
;
6743 assert (t_insn
.opcode
!= XTENSA_UNDEFINED
);
6746 set_expr_const (&t_insn
.tok
[0], 1);
6747 set_expr_const (&t_insn
.tok
[1], 1);
6748 set_expr_const (&t_insn
.tok
[2], 1);
6750 tinsn_to_insnbuf (&t_insn
, insnbuf
);
6751 fragP
->tc_frag_data
.is_insn
= TRUE
;
6752 xtensa_insnbuf_to_chars (xtensa_default_isa
, insnbuf
, nop_buf
);
6754 length
= xtensa_insn_length (xtensa_default_isa
, t_insn
.opcode
);
6755 if (fragP
->fr_var
< length
)
6757 as_warn (_("fr_var (%ld) < length (%d); ignoring"),
6758 fragP
->fr_var
, length
);
6763 fragP
->fr_fix
+= length
;
6764 fragP
->fr_var
-= length
;
6771 relax_frag_narrow (fragP
, stretch
)
6775 /* Overview of the relaxation procedure for alignment inside an
6776 executable section: Find the number of widenings required and the
6777 number of nop bytes required. Store the number of bytes ALREADY
6778 widened. If there are enough instructions to widen (must go back
6779 ONLY through NARROW fragments), mark each of the fragments as TO BE
6780 widened, recalculate the fragment addresses. */
6782 assert (fragP
->fr_type
== rs_machine_dependent
6783 && fragP
->fr_subtype
== RELAX_NARROW
);
6785 if (!future_alignment_required (fragP
, 0))
6787 /* If already expanded but no longer needed because of a prior
6788 stretch, it is SAFE to unexpand because the next fragment will
6789 NEVER start at an address > the previous time through the
6791 if (fragP
->tc_frag_data
.text_expansion
)
6795 fragP
->tc_frag_data
.text_expansion
= 0;
6798 /* Otherwise we have to live with this bad choice. */
6804 if (fragP
->tc_frag_data
.text_expansion
== 0)
6806 fragP
->tc_frag_data
.text_expansion
= 1;
6815 future_alignment_required (fragP
, stretch
)
6819 long address
= fragP
->fr_address
+ stretch
;
6821 addressT aligned_address
;
6822 offsetT desired_diff
;
6826 /* Limit this to a small search. */
6829 address
+= fragP
->fr_fix
;
6831 switch (fragP
->fr_type
)
6834 address
+= fragP
->fr_offset
* fragP
->fr_var
;
6837 case rs_machine_dependent
:
6838 switch (fragP
->fr_subtype
)
6841 /* address += fragP->fr_fix; */
6846 address
+= (/* fragP->fr_fix + */
6847 fragP
->tc_frag_data
.text_expansion
);
6850 case RELAX_ALIGN_NEXT_OPCODE
:
6851 case RELAX_DESIRE_ALIGN
:
6852 /* address += fragP->fr_fix; */
6853 aligned_address
= get_widen_aligned_address (fragP
, address
);
6854 desired_diff
= aligned_address
- address
;
6855 assert (desired_diff
>= 0);
6856 /* If there are enough wideners in between do it. */
6857 /* return (num_widens == desired_diff); */
6858 if (num_widens
== desired_diff
)
6860 if (fragP
->fr_subtype
== RELAX_ALIGN_NEXT_OPCODE
)
6872 fragP
= fragP
->fr_next
;
6880 relax_frag_immed (segP
, fragP
, stretch
, min_steps
, stretched_p
)
6887 static xtensa_insnbuf insnbuf
= NULL
;
6890 bfd_boolean negatable_branch
= FALSE
;
6891 bfd_boolean branch_jmp_to_next
= FALSE
;
6893 offsetT frag_offset
;
6896 int num_text_bytes
, num_literal_bytes
;
6897 int literal_diff
, text_diff
;
6899 assert (fragP
->fr_opcode
!= NULL
);
6902 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
6904 tinsn_from_chars (&t_insn
, fragP
->fr_opcode
);
6905 tinsn_immed_from_frag (&t_insn
, fragP
);
6907 negatable_branch
= is_negatable_branch (&t_insn
);
6909 old_size
= xtensa_insn_length (xtensa_default_isa
, t_insn
.opcode
);
6911 if (software_avoid_b_j_loop_end
)
6912 branch_jmp_to_next
= is_branch_jmp_to_next (&t_insn
, fragP
);
6914 /* Special case: replace a branch to the next instruction with a NOP.
6915 This is required to work around a hardware bug in T1040.0 and also
6916 serves as an optimization. */
6918 if (branch_jmp_to_next
6919 && ((old_size
== 2) || (old_size
== 3))
6920 && !next_frag_is_loop_target (fragP
))
6923 /* Here is the fun stuff: Get the immediate field from this
6924 instruction. If it fits, we are done. If not, find the next
6925 instruction sequence that fits. */
6927 frag_offset
= fragP
->fr_opcode
- fragP
->fr_literal
;
6928 istack_init (&istack
);
6929 num_steps
= xg_assembly_relax (&istack
, &t_insn
, segP
, fragP
, frag_offset
,
6930 min_steps
, stretch
);
6931 if (num_steps
< min_steps
)
6933 as_fatal (_("internal error: relaxation failed"));
6937 if (num_steps
> RELAX_IMMED_MAXSTEPS
)
6939 as_fatal (_("internal error: relaxation requires too many steps"));
6943 fragP
->fr_subtype
= (int) RELAX_IMMED
+ num_steps
;
6945 /* Figure out the number of bytes needed. */
6947 num_text_bytes
= get_num_stack_text_bytes (&istack
) - old_size
;
6948 num_literal_bytes
= get_num_stack_literal_bytes (&istack
);
6949 literal_diff
= num_literal_bytes
- fragP
->tc_frag_data
.literal_expansion
;
6950 text_diff
= num_text_bytes
- fragP
->tc_frag_data
.text_expansion
;
6952 /* It MUST get larger. If not, we could get an infinite loop. */
6953 know (num_text_bytes
>= 0);
6954 know (literal_diff
>= 0 && text_diff
>= 0);
6956 fragP
->tc_frag_data
.text_expansion
= num_text_bytes
;
6957 fragP
->tc_frag_data
.literal_expansion
= num_literal_bytes
;
6959 /* Find the associated expandable literal for this. */
6960 if (literal_diff
!= 0)
6962 lit_fragP
= fragP
->tc_frag_data
.literal_frag
;
6965 assert (literal_diff
== 4);
6966 lit_fragP
->tc_frag_data
.unreported_expansion
+= literal_diff
;
6968 /* We expect that the literal section state has NOT been
6970 assert (lit_fragP
->fr_type
== rs_machine_dependent
6971 && lit_fragP
->fr_subtype
== RELAX_LITERAL
);
6972 lit_fragP
->fr_subtype
= RELAX_LITERAL_NR
;
6974 /* We need to mark this section for another iteration
6980 /* This implicitly uses the assumption that a branch is negated
6981 when the size of the output increases by at least 2 bytes. */
6983 if (negatable_branch
&& num_text_bytes
>= 2)
6985 /* If next frag is a loop end, then switch it to add a NOP. */
6986 update_next_frag_nop_state (fragP
);
6993 /* md_convert_frag Hook and Helper Functions. */
6996 md_convert_frag (abfd
, sec
, fragp
)
6997 bfd
*abfd ATTRIBUTE_UNUSED
;
7004 as_where (&file_name
, &line
);
7005 new_logical_line (fragp
->fr_file
, fragp
->fr_line
);
7007 switch (fragp
->fr_subtype
)
7009 case RELAX_ALIGN_NEXT_OPCODE
:
7010 /* Always convert. */
7011 convert_frag_align_next_opcode (fragp
);
7014 case RELAX_DESIRE_ALIGN
:
7015 /* Do nothing. If not aligned already, too bad. */
7019 case RELAX_LITERAL_FINAL
:
7023 /* No conversion. */
7024 convert_frag_narrow (fragp
);
7028 case RELAX_IMMED_STEP1
:
7029 case RELAX_IMMED_STEP2
:
7030 /* Place the immediate. */
7031 convert_frag_immed (sec
, fragp
, fragp
->fr_subtype
- RELAX_IMMED
);
7034 case RELAX_LITERAL_NR
:
7035 if (use_literal_section
)
7037 /* This should have been handled during relaxation. When
7038 relaxing a code segment, literals sometimes need to be
7039 added to the corresponding literal segment. If that
7040 literal segment has already been relaxed, then we end up
7041 in this situation. Marking the literal segments as data
7042 would make this happen less often (since GAS always relaxes
7043 code before data), but we could still get into trouble if
7044 there are instructions in a segment that is not marked as
7045 containing code. Until we can implement a better solution,
7046 cheat and adjust the addresses of all the following frags.
7047 This could break subsequent alignments, but the linker's
7048 literal coalescing will do that anyway. */
7051 fragp
->fr_subtype
= RELAX_LITERAL_FINAL
;
7052 assert (fragp
->tc_frag_data
.unreported_expansion
== 4);
7053 memset (&fragp
->fr_literal
[fragp
->fr_fix
], 0, 4);
7056 for (f
= fragp
->fr_next
; f
; f
= f
->fr_next
)
7060 as_bad (_("invalid relaxation fragment result"));
7065 new_logical_line (file_name
, line
);
7070 convert_frag_align_next_opcode (fragp
)
7073 char *nop_buf
; /* Location for Writing. */
7076 bfd_boolean use_no_density
= fragp
->tc_frag_data
.is_no_density
;
7077 addressT aligned_address
;
7078 size_t fill_size
, nop_count
;
7080 aligned_address
= get_noop_aligned_address (fragp
, fragp
->fr_address
+
7082 fill_size
= aligned_address
- (fragp
->fr_address
+ fragp
->fr_fix
);
7083 nop_count
= get_text_align_nop_count (fill_size
, use_no_density
);
7084 nop_buf
= fragp
->fr_literal
+ fragp
->fr_fix
;
7086 for (i
= 0; i
< nop_count
; i
++)
7089 nop_size
= get_text_align_nth_nop_size (fill_size
, i
, use_no_density
);
7091 assemble_nop (nop_size
, nop_buf
);
7092 nop_buf
+= nop_size
;
7095 fragp
->fr_fix
+= fill_size
;
7096 fragp
->fr_var
-= fill_size
;
7101 convert_frag_narrow (fragP
)
7104 static xtensa_insnbuf insnbuf
= NULL
;
7105 TInsn t_insn
, single_target
;
7106 int size
, old_size
, diff
, error_val
;
7107 offsetT frag_offset
;
7109 if (fragP
->tc_frag_data
.text_expansion
== 0)
7111 /* No conversion. */
7116 assert (fragP
->fr_opcode
!= NULL
);
7119 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
7121 tinsn_from_chars (&t_insn
, fragP
->fr_opcode
);
7122 tinsn_immed_from_frag (&t_insn
, fragP
);
7124 /* Just convert it to a wide form.... */
7126 old_size
= xtensa_insn_length (xtensa_default_isa
, t_insn
.opcode
);
7128 tinsn_init (&single_target
);
7129 frag_offset
= fragP
->fr_opcode
- fragP
->fr_literal
;
7131 error_val
= xg_expand_narrow (&single_target
, &t_insn
);
7133 as_bad (_("unable to widen instruction"));
7135 size
= xtensa_insn_length (xtensa_default_isa
, single_target
.opcode
);
7136 xg_emit_insn_to_buf (&single_target
, fragP
->fr_opcode
,
7137 fragP
, frag_offset
, TRUE
);
7139 diff
= size
- old_size
;
7141 assert (diff
<= fragP
->fr_var
);
7142 fragP
->fr_var
-= diff
;
7143 fragP
->fr_fix
+= diff
;
7151 convert_frag_immed (segP
, fragP
, min_steps
)
7156 char *immed_instr
= fragP
->fr_opcode
;
7157 static xtensa_insnbuf insnbuf
= NULL
;
7159 bfd_boolean expanded
= FALSE
;
7160 char *fr_opcode
= fragP
->fr_opcode
;
7161 bfd_boolean branch_jmp_to_next
= FALSE
;
7164 assert (fragP
->fr_opcode
!= NULL
);
7167 insnbuf
= xtensa_insnbuf_alloc (xtensa_default_isa
);
7169 tinsn_from_chars (&orig_t_insn
, fragP
->fr_opcode
);
7170 tinsn_immed_from_frag (&orig_t_insn
, fragP
);
7172 /* Here is the fun stuff: Get the immediate field from this
7173 instruction. If it fits, we're done. If not, find the next
7174 instruction sequence that fits. */
7176 if (software_avoid_b_j_loop_end
)
7177 branch_jmp_to_next
= is_branch_jmp_to_next (&orig_t_insn
, fragP
);
7179 if (branch_jmp_to_next
&& !next_frag_is_loop_target (fragP
))
7181 /* Conversion just inserts a NOP and marks the fix as completed. */
7182 size
= xtensa_insn_length (xtensa_default_isa
, orig_t_insn
.opcode
);
7183 assemble_nop (size
, fragP
->fr_opcode
);
7190 symbolS
*lit_sym
= NULL
;
7194 symbolS
*gen_label
= NULL
;
7195 offsetT frag_offset
;
7197 /* It does not fit. Find something that does and
7198 convert immediately. */
7199 frag_offset
= fragP
->fr_opcode
- fragP
->fr_literal
;
7200 istack_init (&istack
);
7201 xg_assembly_relax (&istack
, &orig_t_insn
,
7202 segP
, fragP
, frag_offset
, min_steps
, 0);
7204 old_size
= xtensa_insn_length (xtensa_default_isa
, orig_t_insn
.opcode
);
7206 /* Assemble this right inline. */
7208 /* First, create the mapping from a label name to the REAL label. */
7210 for (i
= 0; i
< istack
.ninsn
; i
++)
7212 TInsn
*t_insn
= &istack
.insn
[i
];
7216 switch (t_insn
->insn_type
)
7219 if (lit_sym
!= NULL
)
7220 as_bad (_("multiple literals in expansion"));
7221 /* First find the appropriate space in the literal pool. */
7222 lit_frag
= fragP
->tc_frag_data
.literal_frag
;
7223 if (lit_frag
== NULL
)
7224 as_bad (_("no registered fragment for literal"));
7225 if (t_insn
->ntok
!= 1)
7226 as_bad (_("number of literal tokens != 1"));
7228 /* Set the literal symbol and add a fixup. */
7229 lit_sym
= lit_frag
->fr_symbol
;
7233 assert (gen_label
== NULL
);
7234 gen_label
= symbol_new (FAKE_LABEL_NAME
, now_seg
,
7235 fragP
->fr_opcode
- fragP
->fr_literal
+
7240 size
= xtensa_insn_length (xtensa_default_isa
, t_insn
->opcode
);
7247 for (i
= 0; i
< istack
.ninsn
; i
++)
7249 TInsn
*t_insn
= &istack
.insn
[i
];
7254 switch (t_insn
->insn_type
)
7257 lit_frag
= fragP
->tc_frag_data
.literal_frag
;
7258 /* already checked */
7259 assert (lit_frag
!= NULL
);
7260 assert (lit_sym
!= NULL
);
7261 assert (t_insn
->ntok
== 1);
7263 target_seg
= S_GET_SEGMENT (lit_sym
);
7264 assert (target_seg
);
7265 fix_new_exp_in_seg (target_seg
, 0, lit_frag
, 0, 4,
7266 &t_insn
->tok
[0], FALSE
, BFD_RELOC_32
);
7273 xg_resolve_labels (t_insn
, gen_label
);
7274 xg_resolve_literals (t_insn
, lit_sym
);
7275 size
= xtensa_insn_length (xtensa_default_isa
, t_insn
->opcode
);
7277 xg_emit_insn_to_buf (t_insn
, immed_instr
, fragP
,
7278 immed_instr
- fragP
->fr_literal
, TRUE
);
7279 immed_instr
+= size
;
7284 diff
= total_size
- old_size
;
7288 assert (diff
<= fragP
->fr_var
);
7289 fragP
->fr_var
-= diff
;
7290 fragP
->fr_fix
+= diff
;
7296 /* Check for undefined immediates in LOOP instructions. */
7297 if (is_loop_opcode (orig_t_insn
.opcode
))
7300 sym
= orig_t_insn
.tok
[1].X_add_symbol
;
7301 if (sym
!= NULL
&& !S_IS_DEFINED (sym
))
7303 as_bad (_("unresolved loop target symbol: %s"), S_GET_NAME (sym
));
7306 sym
= orig_t_insn
.tok
[1].X_op_symbol
;
7307 if (sym
!= NULL
&& !S_IS_DEFINED (sym
))
7309 as_bad (_("unresolved loop target symbol: %s"), S_GET_NAME (sym
));
7314 if (expanded
&& is_loop_opcode (orig_t_insn
.opcode
))
7315 convert_frag_immed_finish_loop (segP
, fragP
, &orig_t_insn
);
7317 if (expanded
&& is_direct_call_opcode (orig_t_insn
.opcode
))
7319 /* Add an expansion note on the expanded instruction. */
7320 fix_new_exp_in_seg (now_seg
, 0, fragP
, fr_opcode
- fragP
->fr_literal
, 4,
7321 &orig_t_insn
.tok
[0], TRUE
,
7322 BFD_RELOC_XTENSA_ASM_EXPAND
);
7328 /* Add a new fix expression into the desired segment. We have to
7329 switch to that segment to do this. */
7332 fix_new_exp_in_seg (new_seg
, new_subseg
,
7333 frag
, where
, size
, exp
, pcrel
, r_type
)
7341 bfd_reloc_code_real_type r_type
;
7345 subsegT subseg
= now_subseg
;
7346 assert (new_seg
!= 0);
7347 subseg_set (new_seg
, new_subseg
);
7349 if (r_type
== BFD_RELOC_32
7350 && exp
->X_add_symbol
7351 && exp
->X_add_symbol
->sy_tc
.plt
== 1)
7353 r_type
= BFD_RELOC_XTENSA_PLT
;
7356 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
7357 subseg_set (seg
, subseg
);
7362 /* Relax a loop instruction so that it can span loop >256 bytes. */
7368 addi as, as, lo8(label-.L1)
7369 addmi as, as, mid8(label-.L1)
7379 convert_frag_immed_finish_loop (segP
, fragP
, t_insn
)
7387 unsigned long target
;
7388 static xtensa_insnbuf insnbuf
= NULL
;
7389 unsigned int loop_length
, loop_length_hi
, loop_length_lo
;
7390 xtensa_isa isa
= xtensa_default_isa
;
7391 addressT loop_offset
;
7392 addressT addi_offset
= 9;
7393 addressT addmi_offset
= 12;
7396 insnbuf
= xtensa_insnbuf_alloc (isa
);
7398 /* Get the loop offset. */
7399 loop_offset
= get_expanded_loop_offset (t_insn
->opcode
);
7400 /* Validate that there really is a LOOP at the loop_offset. */
7401 tinsn_from_chars (&loop_insn
, fragP
->fr_opcode
+ loop_offset
);
7403 if (!is_loop_opcode (loop_insn
.opcode
))
7405 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
7406 _("loop relaxation specification does not correspond"));
7409 addi_offset
+= loop_offset
;
7410 addmi_offset
+= loop_offset
;
7412 assert (t_insn
->ntok
== 2);
7413 target
= get_expression_value (segP
, &t_insn
->tok
[1]);
7416 know (symbolP
->sy_frag
);
7417 know (!(S_GET_SEGMENT (symbolP
) == absolute_section
)
7418 || symbol_get_frag (symbolP
) == &zero_address_frag
);
7420 loop_length
= target
- (fragP
->fr_address
+ fragP
->fr_fix
);
7421 loop_length_hi
= loop_length
& ~0x0ff;
7422 loop_length_lo
= loop_length
& 0x0ff;
7423 if (loop_length_lo
>= 128)
7425 loop_length_lo
-= 256;
7426 loop_length_hi
+= 256;
7429 /* Because addmi sign-extends the immediate, 'loop_length_hi' can be at most
7430 32512. If the loop is larger than that, then we just fail. */
7431 if (loop_length_hi
> 32512)
7432 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
7433 _("loop too long for LOOP instruction"));
7435 tinsn_from_chars (&addi_insn
, fragP
->fr_opcode
+ addi_offset
);
7436 assert (addi_insn
.opcode
== xtensa_addi_opcode
);
7438 tinsn_from_chars (&addmi_insn
, fragP
->fr_opcode
+ addmi_offset
);
7439 assert (addmi_insn
.opcode
== xtensa_addmi_opcode
);
7441 set_expr_const (&addi_insn
.tok
[2], loop_length_lo
);
7442 tinsn_to_insnbuf (&addi_insn
, insnbuf
);
7444 fragP
->tc_frag_data
.is_insn
= TRUE
;
7445 xtensa_insnbuf_to_chars (isa
, insnbuf
, fragP
->fr_opcode
+ addi_offset
);
7447 set_expr_const (&addmi_insn
.tok
[2], loop_length_hi
);
7448 tinsn_to_insnbuf (&addmi_insn
, insnbuf
);
7449 xtensa_insnbuf_to_chars (isa
, insnbuf
, fragP
->fr_opcode
+ addmi_offset
);
7454 get_expression_value (segP
, exp
)
7458 if (exp
->X_op
== O_constant
)
7459 return exp
->X_add_number
;
7460 if (exp
->X_op
== O_symbol
)
7462 /* Find the fragment. */
7463 symbolS
*sym
= exp
->X_add_symbol
;
7465 assert (S_GET_SEGMENT (sym
) == segP
7466 || S_GET_SEGMENT (sym
) == absolute_section
);
7468 return (S_GET_VALUE (sym
) + exp
->X_add_number
);
7470 as_bad (_("invalid expression evaluation type %d"), exp
->X_op
);
7475 /* A map that keeps information on a per-subsegment basis. This is
7476 maintained during initial assembly, but is invalid once the
7477 subsegments are smashed together. I.E., it cannot be used during
7480 typedef struct subseg_map_struct
7489 struct subseg_map_struct
*next
;
7492 static subseg_map
*sseg_map
= NULL
;
7496 get_last_insn_flags (seg
, subseg
)
7500 subseg_map
*subseg_e
;
7502 for (subseg_e
= sseg_map
; subseg_e
!= NULL
; subseg_e
= subseg_e
->next
)
7503 if (seg
== subseg_e
->seg
&& subseg
== subseg_e
->subseg
)
7504 return subseg_e
->flags
;
7511 set_last_insn_flags (seg
, subseg
, fl
, val
)
7517 subseg_map
*subseg_e
;
7519 for (subseg_e
= sseg_map
; subseg_e
; subseg_e
= subseg_e
->next
)
7520 if (seg
== subseg_e
->seg
&& subseg
== subseg_e
->subseg
)
7525 subseg_e
= (subseg_map
*) xmalloc (sizeof (subseg_map
));
7526 memset (subseg_e
, 0, sizeof (subseg_map
));
7527 subseg_e
->seg
= seg
;
7528 subseg_e
->subseg
= subseg
;
7529 subseg_e
->flags
= 0;
7530 subseg_e
->next
= sseg_map
;
7531 sseg_map
= subseg_e
;
7535 subseg_e
->flags
|= fl
;
7537 subseg_e
->flags
&= ~fl
;
7541 /* Segment Lists and emit_state Stuff. */
7543 /* Remove the segment from the global sections list. */
7546 xtensa_remove_section (sec
)
7549 /* Handle brain-dead bfd_section_list_remove macro, which
7550 expect the address of the prior section's "next" field, not
7551 just the address of the section to remove. */
7553 segT
*ps_next_ptr
= &stdoutput
->sections
;
7554 while (*ps_next_ptr
!= sec
&& *ps_next_ptr
!= NULL
)
7555 ps_next_ptr
= &(*ps_next_ptr
)->next
;
7557 assert (*ps_next_ptr
!= NULL
);
7559 bfd_section_list_remove (stdoutput
, ps_next_ptr
);
7564 xtensa_insert_section (after_sec
, sec
)
7568 segT
*after_sec_next
;
7569 if (after_sec
== NULL
)
7570 after_sec_next
= &stdoutput
->sections
;
7572 after_sec_next
= &after_sec
->next
;
7574 bfd_section_list_insert (stdoutput
, after_sec_next
, sec
);
7579 xtensa_move_seg_list_to_beginning (head
)
7585 segT literal_section
= head
->seg
;
7587 /* Move the literal section to the front of the section list. */
7588 assert (literal_section
);
7589 xtensa_remove_section (literal_section
);
7590 xtensa_insert_section (NULL
, literal_section
);
7598 xtensa_move_literals ()
7601 frchainS
*frchain_from
, *frchain_to
;
7602 fragS
*search_frag
, *next_frag
, *last_frag
, *literal_pool
, *insert_after
;
7603 fragS
**frag_splice
;
7606 fixS
*fix
, *next_fix
, **fix_splice
;
7608 /* As clunky as this is, we can't rely on frag_var
7609 and frag_variant to get called in all situations. */
7611 segment
= literal_head
->next
;
7614 frchain_from
= seg_info (segment
->seg
)->frchainP
;
7615 search_frag
= frchain_from
->frch_root
;
7618 search_frag
->tc_frag_data
.is_literal
= TRUE
;
7619 search_frag
= search_frag
->fr_next
;
7621 segment
= segment
->next
;
7624 if (use_literal_section
)
7627 segment
= literal_head
->next
;
7630 frchain_from
= seg_info (segment
->seg
)->frchainP
;
7631 search_frag
= frchain_from
->frch_root
;
7632 literal_pool
= NULL
;
7634 frag_splice
= &(frchain_from
->frch_root
);
7636 while (!search_frag
->tc_frag_data
.literal_frag
)
7638 assert (search_frag
->fr_fix
== 0
7639 || search_frag
->fr_type
== rs_align
);
7640 search_frag
= search_frag
->fr_next
;
7643 assert (search_frag
->tc_frag_data
.literal_frag
->fr_subtype
7644 == RELAX_LITERAL_POOL_BEGIN
);
7645 xtensa_switch_section_emit_state (&state
, segment
->seg
, 0);
7647 /* Make sure that all the frags in this series are closed, and
7648 that there is at least one left over of zero-size. This
7649 prevents us from making a segment with an frchain without any
7651 frag_variant (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
7652 last_frag
= frag_now
;
7653 frag_variant (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
7655 while (search_frag
!= frag_now
)
7657 next_frag
= search_frag
->fr_next
;
7659 /* First, move the frag out of the literal section and
7660 to the appropriate place. */
7661 if (search_frag
->tc_frag_data
.literal_frag
)
7663 literal_pool
= search_frag
->tc_frag_data
.literal_frag
;
7664 assert (literal_pool
->fr_subtype
== RELAX_LITERAL_POOL_BEGIN
);
7665 /* Note that we set this fr_var to be a fix
7666 chain when we created the literal pool location
7667 as RELAX_LITERAL_POOL_BEGIN. */
7668 frchain_to
= (frchainS
*) literal_pool
->fr_var
;
7670 insert_after
= literal_pool
;
7672 while (insert_after
->fr_next
->fr_subtype
!= RELAX_LITERAL_POOL_END
)
7673 insert_after
= insert_after
->fr_next
;
7675 dest_seg
= (segT
) insert_after
->fr_next
->fr_var
;
7677 *frag_splice
= next_frag
;
7678 search_frag
->fr_next
= insert_after
->fr_next
;
7679 insert_after
->fr_next
= search_frag
;
7680 search_frag
->tc_frag_data
.lit_seg
= dest_seg
;
7682 /* Now move any fixups associated with this frag to the
7684 fix
= frchain_from
->fix_root
;
7685 fix_splice
= &(frchain_from
->fix_root
);
7688 next_fix
= fix
->fx_next
;
7689 if (fix
->fx_frag
== search_frag
)
7691 *fix_splice
= next_fix
;
7692 fix
->fx_next
= frchain_to
->fix_root
;
7693 frchain_to
->fix_root
= fix
;
7694 if (frchain_to
->fix_tail
== NULL
)
7695 frchain_to
->fix_tail
= fix
;
7698 fix_splice
= &(fix
->fx_next
);
7701 search_frag
= next_frag
;
7704 if (frchain_from
->fix_root
!= NULL
)
7706 frchain_from
= seg_info (segment
->seg
)->frchainP
;
7707 as_warn (_("fixes not all moved from %s"), segment
->seg
->name
);
7709 assert (frchain_from
->fix_root
== NULL
);
7711 frchain_from
->fix_tail
= NULL
;
7712 xtensa_restore_emit_state (&state
);
7713 segment
= segment
->next
;
7716 xtensa_move_frag_symbols ();
7721 xtensa_move_frag_symbol (sym
)
7724 fragS
*frag
= symbol_get_frag (sym
);
7726 if (frag
->tc_frag_data
.lit_seg
!= (segT
) 0)
7727 S_SET_SEGMENT (sym
, frag
->tc_frag_data
.lit_seg
);
7732 xtensa_move_frag_symbols ()
7736 /* Although you might think that only one of these lists should be
7737 searched, it turns out that the difference of the two sets
7738 (either way) is not empty. They do overlap quite a bit,
7741 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbolP
->sy_next
)
7742 xtensa_move_frag_symbol (symbolP
);
7744 map_over_defined_symbols (xtensa_move_frag_symbol
);
7749 xtensa_reorder_seg_list (head
, after
)
7753 /* Move all of the sections in the section list to come
7754 after "after" in the gnu segment list. */
7759 segT literal_section
= head
->seg
;
7761 /* Move the literal section after "after". */
7762 assert (literal_section
);
7763 if (literal_section
!= after
)
7765 xtensa_remove_section (literal_section
);
7766 xtensa_insert_section (after
, literal_section
);
7774 /* Push all the literal segments to the end of the gnu list. */
7777 xtensa_reorder_segments ()
7784 for (sec
= stdoutput
->sections
; sec
!= NULL
; sec
= sec
->next
)
7787 /* Now that we have the last section, push all the literal
7788 sections to the end. */
7789 last_sec
= get_last_sec ();
7790 xtensa_reorder_seg_list (literal_head
, last_sec
);
7791 xtensa_reorder_seg_list (init_literal_head
, last_sec
);
7792 xtensa_reorder_seg_list (fini_literal_head
, last_sec
);
7794 /* Now perform the final error check. */
7795 for (sec
= stdoutput
->sections
; sec
!= NULL
; sec
= sec
->next
)
7797 assert (new_count
== old_count
);
7804 segT last_sec
= stdoutput
->sections
;
7805 while (last_sec
->next
!= NULL
)
7806 last_sec
= last_sec
->next
;
7812 /* Change the emit state (seg, subseg, and frag related stuff) to the
7813 correct location. Return a emit_state which can be passed to
7814 xtensa_restore_emit_state to return to current fragment. */
7817 xtensa_switch_to_literal_fragment (result
)
7820 /* When we mark a literal pool location, we want to put a frag in
7821 the literal pool that points to it. But to do that, we want to
7822 switch_to_literal_fragment. But literal sections don't have
7823 literal pools, so their location is always null, so we would
7824 recurse forever. This is kind of hacky, but it works. */
7826 static bfd_boolean recursive
= FALSE
;
7827 fragS
*pool_location
= get_literal_pool_location (now_seg
);
7828 bfd_boolean is_init
=
7829 (now_seg
&& !strcmp (segment_name (now_seg
), INIT_SECTION_NAME
));
7831 bfd_boolean is_fini
=
7832 (now_seg
&& !strcmp (segment_name (now_seg
), FINI_SECTION_NAME
));
7835 if (pool_location
== NULL
7836 && !use_literal_section
7838 && !is_init
&& ! is_fini
)
7840 as_warn (_("inlining literal pool; "
7841 "specify location with .literal_position."));
7843 xtensa_mark_literal_pool_location (FALSE
);
7847 /* Special case: If we are in the ".fini" or ".init" section, then
7848 we will ALWAYS be generating to the ".fini.literal" and
7849 ".init.literal" sections. */
7853 cache_literal_section (init_literal_head
,
7854 default_lit_sections
.init_lit_seg_name
,
7855 &default_lit_sections
.init_lit_seg
);
7856 xtensa_switch_section_emit_state (result
,
7857 default_lit_sections
.init_lit_seg
, 0);
7861 cache_literal_section (fini_literal_head
,
7862 default_lit_sections
.fini_lit_seg_name
,
7863 &default_lit_sections
.fini_lit_seg
);
7864 xtensa_switch_section_emit_state (result
,
7865 default_lit_sections
.fini_lit_seg
, 0);
7869 cache_literal_section (literal_head
,
7870 default_lit_sections
.lit_seg_name
,
7871 &default_lit_sections
.lit_seg
);
7872 xtensa_switch_section_emit_state (result
,
7873 default_lit_sections
.lit_seg
, 0);
7876 if (!use_literal_section
&&
7877 !is_init
&& !is_fini
&&
7878 get_literal_pool_location (now_seg
) != pool_location
)
7880 /* Close whatever frag is there. */
7881 frag_variant (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
7882 frag_now
->tc_frag_data
.literal_frag
= pool_location
;
7883 frag_variant (rs_fill
, 0, 0, 0, NULL
, 0, NULL
);
7886 /* Do a 4 byte align here. */
7887 frag_align (2, 0, 0);
7891 /* Call this function before emitting data into the literal section.
7892 This is a helper function for xtensa_switch_to_literal_fragment.
7893 This is similar to a .section new_now_seg subseg. */
7896 xtensa_switch_section_emit_state (state
, new_now_seg
, new_now_subseg
)
7899 subsegT new_now_subseg
;
7901 state
->name
= now_seg
->name
;
7902 state
->now_seg
= now_seg
;
7903 state
->now_subseg
= now_subseg
;
7904 state
->generating_literals
= generating_literals
;
7905 generating_literals
++;
7906 subseg_new (segment_name (new_now_seg
), new_now_subseg
);
7910 /* Use to restore the emitting into the normal place. */
7913 xtensa_restore_emit_state (state
)
7916 generating_literals
= state
->generating_literals
;
7917 subseg_new (state
->name
, state
->now_subseg
);
7921 /* Get a segment of a given name. If the segment is already
7922 present, return it; otherwise, create a new one. */
7925 cache_literal_section (head
, name
, seg
)
7930 segT current_section
= now_seg
;
7931 int current_subsec
= now_subseg
;
7935 *seg
= retrieve_literal_seg (head
, name
);
7936 subseg_set (current_section
, current_subsec
);
7940 /* Get a segment of a given name. If the segment is already
7941 present, return it; otherwise, create a new one. */
7944 retrieve_literal_seg (head
, name
)
7952 ret
= seg_present (name
);
7955 ret
= subseg_new (name
, (subsegT
) 0);
7956 add_seg_list (head
, ret
);
7957 bfd_set_section_flags (stdoutput
, ret
, SEC_HAS_CONTENTS
|
7958 SEC_READONLY
| SEC_ALLOC
| SEC_LOAD
| SEC_CODE
);
7959 bfd_set_section_alignment (stdoutput
, ret
, 2);
7966 /* Return a segment of a given name if it is present. */
7973 seg
= stdoutput
->sections
;
7977 if (!strcmp (segment_name (seg
), name
))
7986 /* Add a segment to a segment list. */
7989 add_seg_list (head
, seg
)
7994 n
= (seg_list
*) xmalloc (sizeof (seg_list
));
7998 n
->next
= head
->next
;
8003 /* Set up Property Tables after Relaxation. */
8005 #define XTENSA_INSN_SEC_NAME ".xt.insn"
8006 #define XTENSA_LIT_SEC_NAME ".xt.lit"
8009 xtensa_post_relax_hook ()
8011 xtensa_move_seg_list_to_beginning (literal_head
);
8012 xtensa_move_seg_list_to_beginning (init_literal_head
);
8013 xtensa_move_seg_list_to_beginning (fini_literal_head
);
8015 xtensa_create_property_segments (get_frag_is_insn
,
8016 XTENSA_INSN_SEC_NAME
,
8018 if (use_literal_section
)
8019 xtensa_create_property_segments (get_frag_is_literal
,
8020 XTENSA_LIT_SEC_NAME
,
8026 get_frag_is_literal (fragP
)
8029 assert (fragP
!= NULL
);
8030 return (fragP
->tc_frag_data
.is_literal
);
8035 get_frag_is_insn (fragP
)
8038 assert (fragP
!= NULL
);
8039 return (fragP
->tc_frag_data
.is_insn
);
8044 xtensa_create_property_segments (property_function
, section_name_base
,
8046 frag_predicate property_function
;
8047 const char * section_name_base
;
8048 xt_section_type sec_type
;
8052 /* Walk over all of the current segments.
8053 Walk over each fragment
8054 For each fragment that has instructions
8055 Build an instruction record (append where possible). */
8057 for (seclist
= &stdoutput
->sections
;
8058 seclist
&& *seclist
;
8059 seclist
= &(*seclist
)->next
)
8061 segT sec
= *seclist
;
8062 if (section_has_property (sec
, property_function
))
8064 char * property_section_name
=
8065 xtensa_get_property_section_name (stdoutput
, sec
,
8067 segT insn_sec
= retrieve_xtensa_section (property_section_name
);
8068 segment_info_type
*xt_seg_info
= retrieve_segment_info (insn_sec
);
8069 xtensa_block_info
** xt_blocks
=
8070 &xt_seg_info
->tc_segment_info_data
.blocks
[sec_type
];
8071 /* Walk over all of the frchains here and add new sections. */
8072 add_xt_block_frags (sec
, insn_sec
, xt_blocks
, property_function
);
8076 /* Now we fill them out.... */
8078 for (seclist
= &stdoutput
->sections
;
8079 seclist
&& *seclist
;
8080 seclist
= &(*seclist
)->next
)
8082 segment_info_type
*seginfo
;
8083 xtensa_block_info
*block
;
8084 segT sec
= *seclist
;
8085 seginfo
= seg_info (sec
);
8086 block
= seginfo
->tc_segment_info_data
.blocks
[sec_type
];
8090 xtensa_block_info
*cur_block
;
8091 /* This is a section with some data. */
8092 size_t num_recs
= 0;
8095 for (cur_block
= block
; cur_block
; cur_block
= cur_block
->next
)
8098 rec_size
= num_recs
* 8;
8099 bfd_set_section_size (stdoutput
, sec
, rec_size
);
8101 /* In order to make this work with the assembler, we have to
8102 build some frags and then build the "fixups" for it. It
8103 would be easier to just set the contents then set the
8108 /* Allocate a fragment and leak it. */
8116 frag_size
= sizeof (fragS
) + rec_size
;
8117 fragP
= (fragS
*) xmalloc (frag_size
);
8119 memset (fragP
, 0, frag_size
);
8120 fragP
->fr_address
= 0;
8121 fragP
->fr_next
= NULL
;
8122 fragP
->fr_fix
= rec_size
;
8124 fragP
->fr_type
= rs_fill
;
8125 /* the rest are zeros */
8127 frchainP
= seginfo
->frchainP
;
8128 frchainP
->frch_root
= fragP
;
8129 frchainP
->frch_last
= fragP
;
8131 fixes
= (fixS
*) xmalloc (sizeof (fixS
) * num_recs
);
8132 memset (fixes
, 0, sizeof (fixS
) * num_recs
);
8134 seginfo
->fix_root
= fixes
;
8135 seginfo
->fix_tail
= &fixes
[num_recs
- 1];
8137 frag_data
= &fragP
->fr_literal
[0];
8138 for (i
= 0; i
< num_recs
; i
++)
8140 fixS
*fix
= &fixes
[i
];
8143 /* Write the fixup. */
8144 if (i
!= num_recs
- 1)
8145 fix
->fx_next
= &fixes
[i
+ 1];
8147 fix
->fx_next
= NULL
;
8150 fix
->fx_frag
= fragP
;
8151 fix
->fx_where
= i
* 8;
8152 fix
->fx_addsy
= section_symbol (cur_block
->sec
);
8153 fix
->fx_offset
= cur_block
->offset
;
8154 fix
->fx_r_type
= BFD_RELOC_32
;
8155 fix
->fx_file
= "Internal Assembly";
8158 /* Write the length. */
8159 md_number_to_chars (&frag_data
[4 + 8 * i
],
8160 cur_block
->size
, 4);
8161 cur_block
= cur_block
->next
;
8170 retrieve_segment_info (seg
)
8173 segment_info_type
*seginfo
;
8174 seginfo
= (segment_info_type
*) bfd_get_section_userdata (stdoutput
, seg
);
8179 seginfo
= (segment_info_type
*) xmalloc (sizeof (*seginfo
));
8180 memset ((PTR
) seginfo
, 0, sizeof (*seginfo
));
8181 seginfo
->fix_root
= NULL
;
8182 seginfo
->fix_tail
= NULL
;
8183 seginfo
->bfd_section
= seg
;
8185 /* We will not be dealing with these, only our special ones. */
8187 if (seg
== bfd_abs_section_ptr
)
8188 abs_seg_info
= seginfo
;
8189 else if (seg
== bfd_und_section_ptr
)
8190 und_seg_info
= seginfo
;
8193 bfd_set_section_userdata (stdoutput
, seg
, (PTR
) seginfo
);
8195 seg_fix_rootP
= &segment_info
[seg
].fix_root
;
8196 seg_fix_tailP
= &segment_info
[seg
].fix_tail
;
8199 frchainP
= (frchainS
*) xmalloc (sizeof (frchainS
));
8200 frchainP
->frch_root
= NULL
;
8201 frchainP
->frch_last
= NULL
;
8202 frchainP
->frch_next
= NULL
;
8203 frchainP
->frch_seg
= seg
;
8204 frchainP
->frch_subseg
= 0;
8205 frchainP
->fix_root
= NULL
;
8206 frchainP
->fix_tail
= NULL
;
8207 /* Do not init the objstack. */
8208 /* obstack_begin (&frchainP->frch_obstack, chunksize); */
8209 /* frchainP->frch_frag_now = fragP; */
8210 frchainP
->frch_frag_now
= NULL
;
8212 seginfo
->frchainP
= frchainP
;
8220 retrieve_xtensa_section (sec_name
)
8223 bfd
*abfd
= stdoutput
;
8224 flagword flags
, out_flags
, link_once_flags
;
8227 flags
= bfd_get_section_flags (abfd
, now_seg
);
8228 link_once_flags
= (flags
& SEC_LINK_ONCE
);
8229 if (link_once_flags
)
8230 link_once_flags
|= (flags
& SEC_LINK_DUPLICATES
);
8231 out_flags
= (SEC_RELOC
| SEC_HAS_CONTENTS
| SEC_READONLY
| link_once_flags
);
8233 s
= bfd_make_section_old_way (abfd
, sec_name
);
8235 as_bad (_("could not create section %s"), sec_name
);
8236 if (!bfd_set_section_flags (abfd
, s
, out_flags
))
8237 as_bad (_("invalid flag combination on section %s"), sec_name
);
8244 section_has_property (sec
, property_function
)
8246 frag_predicate property_function
;
8248 segment_info_type
*seginfo
= seg_info (sec
);
8251 if (seginfo
&& seginfo
->frchainP
)
8253 for (fragP
= seginfo
->frchainP
->frch_root
; fragP
; fragP
= fragP
->fr_next
)
8255 if (property_function (fragP
)
8256 && (fragP
->fr_type
!= rs_fill
|| fragP
->fr_fix
!= 0))
8264 /* Two types of block sections exist right now: literal and insns. */
8267 add_xt_block_frags (sec
, xt_block_sec
, xt_block
, property_function
)
8270 xtensa_block_info
**xt_block
;
8271 frag_predicate property_function
;
8273 segment_info_type
*seg_info
;
8274 segment_info_type
*xt_seg_info
;
8278 xt_seg_info
= retrieve_segment_info (xt_block_sec
);
8279 seg_info
= retrieve_segment_info (sec
);
8281 /* Build it if needed. */
8282 while (*xt_block
!= NULL
)
8283 xt_block
= &(*xt_block
)->next
;
8284 /* We are either at NULL at the beginning or at the end. */
8286 /* Walk through the frags. */
8289 if (seg_info
->frchainP
)
8291 for (fragP
= seg_info
->frchainP
->frch_root
;
8293 fragP
= fragP
->fr_next
)
8295 if (property_function (fragP
)
8296 && (fragP
->fr_type
!= rs_fill
|| fragP
->fr_fix
!= 0))
8298 if (*xt_block
!= NULL
)
8300 if ((*xt_block
)->offset
+ (*xt_block
)->size
8301 == fragP
->fr_address
)
8302 (*xt_block
)->size
+= fragP
->fr_fix
;
8304 xt_block
= &((*xt_block
)->next
);
8306 if (*xt_block
== NULL
)
8308 xtensa_block_info
*new_block
= (xtensa_block_info
*)
8309 xmalloc (sizeof (xtensa_block_info
));
8310 new_block
->sec
= sec
;
8311 new_block
->offset
= fragP
->fr_address
;
8312 new_block
->size
= fragP
->fr_fix
;
8313 new_block
->next
= NULL
;
8314 *xt_block
= new_block
;
8322 /* Instruction Stack Functions (from "xtensa-istack.h"). */
8328 memset (stack
, 0, sizeof (IStack
));
8334 istack_empty (stack
)
8337 return (stack
->ninsn
== 0);
8345 return (stack
->ninsn
== MAX_ISTACK
);
8349 /* Return a pointer to the top IStack entry.
8350 It is an error to call this if istack_empty () is true. */
8356 int rec
= stack
->ninsn
- 1;
8357 assert (!istack_empty (stack
));
8358 return &stack
->insn
[rec
];
8362 /* Add a new TInsn to an IStack.
8363 It is an error to call this if istack_full () is true. */
8366 istack_push (stack
, insn
)
8370 int rec
= stack
->ninsn
;
8371 assert (!istack_full (stack
));
8372 tinsn_copy (&stack
->insn
[rec
], insn
);
8377 /* Clear space for the next TInsn on the IStack and return a pointer
8378 to it. It is an error to call this if istack_full () is true. */
8381 istack_push_space (stack
)
8384 int rec
= stack
->ninsn
;
8386 assert (!istack_full (stack
));
8387 insn
= &stack
->insn
[rec
];
8388 memset (insn
, 0, sizeof (TInsn
));
8394 /* Remove the last pushed instruction. It is an error to call this if
8395 istack_empty () returns true. */
8401 int rec
= stack
->ninsn
- 1;
8402 assert (!istack_empty (stack
));
8404 memset (&stack
->insn
[rec
], 0, sizeof (TInsn
));
8408 /* TInsn functions. */
8414 memset (dst
, 0, sizeof (TInsn
));
8419 tinsn_copy (dst
, src
)
8424 memcpy (dst
, src
, sizeof (TInsn
));
8428 /* Get the ``num''th token of the TInsn.
8429 It is illegal to call this if num > insn->ntoks. */
8432 tinsn_get_tok (insn
, num
)
8436 assert (num
< insn
->ntok
);
8437 return &insn
->tok
[num
];
8441 /* Return true if ANY of the operands in the insn are symbolic. */
8444 tinsn_has_symbolic_operands (insn
)
8450 assert (insn
->insn_type
== ITYPE_INSN
);
8452 for (i
= 0; i
< n
; ++i
)
8454 switch (insn
->tok
[i
].X_op
)
8468 tinsn_has_invalid_symbolic_operands (insn
)
8474 assert (insn
->insn_type
== ITYPE_INSN
);
8476 for (i
= 0; i
< n
; ++i
)
8478 switch (insn
->tok
[i
].X_op
)
8484 if (i
== get_relaxable_immed (insn
->opcode
))
8486 as_bad (_("invalid symbolic operand %d on '%s'"),
8487 i
, xtensa_opcode_name (xtensa_default_isa
, insn
->opcode
));
8495 /* For assembly code with complex expressions (e.g. subtraction),
8496 we have to build them in the literal pool so that
8497 their results are calculated correctly after relaxation.
8498 The relaxation only handles expressions that
8499 boil down to SYMBOL + OFFSET. */
8502 tinsn_has_complex_operands (insn
)
8507 assert (insn
->insn_type
== ITYPE_INSN
);
8508 for (i
= 0; i
< n
; ++i
)
8510 switch (insn
->tok
[i
].X_op
)
8524 /* Convert the constant operands in the t_insn to insnbuf.
8525 Return true if there is a symbol in the immediate field.
8527 Before this is called,
8528 1) the number of operands are correct
8529 2) the t_insn is a ITYPE_INSN
8530 3) ONLY the relaxable_ is built
8531 4) All operands are O_constant, O_symbol. All constants fit
8532 The return value tells whether there are any remaining O_symbols. */
8535 tinsn_to_insnbuf (t_insn
, insnbuf
)
8537 xtensa_insnbuf insnbuf
;
8539 xtensa_isa isa
= xtensa_default_isa
;
8540 xtensa_opcode opcode
= t_insn
->opcode
;
8541 bfd_boolean has_fixup
= FALSE
;
8542 int noperands
= xtensa_num_operands (isa
, opcode
);
8548 assert (t_insn
->insn_type
== ITYPE_INSN
);
8549 if (noperands
!= t_insn
->ntok
)
8550 as_fatal (_("operand number mismatch"));
8552 xtensa_encode_insn (isa
, opcode
, insnbuf
);
8554 for (i
= 0; i
< noperands
; ++i
)
8556 expressionS
*expr
= &t_insn
->tok
[i
];
8557 xtensa_operand operand
= xtensa_get_operand (isa
, opcode
, i
);
8561 /* The register number has already been checked in
8562 expression_maybe_register, so we don't need to check here. */
8563 opnd_value
= expr
->X_add_number
;
8564 (void) xtensa_operand_encode (operand
, &opnd_value
);
8565 xtensa_operand_set_field (operand
, insnbuf
, opnd_value
);
8569 as_where (&file_name
, &line
);
8570 /* It is a constant and we called this function,
8571 then we have to try to fit it. */
8572 xtensa_insnbuf_set_operand (insnbuf
, opcode
, operand
,
8573 expr
->X_add_number
, file_name
, line
);
8586 /* Check the instruction arguments. Return true on failure. */
8589 tinsn_check_arguments (insn
)
8592 xtensa_isa isa
= xtensa_default_isa
;
8593 xtensa_opcode opcode
= insn
->opcode
;
8595 if (opcode
== XTENSA_UNDEFINED
)
8597 as_bad (_("invalid opcode"));
8601 if (xtensa_num_operands (isa
, opcode
) > insn
->ntok
)
8603 as_bad (_("too few operands"));
8607 if (xtensa_num_operands (isa
, opcode
) < insn
->ntok
)
8609 as_bad (_("too many operands"));
8616 /* Load an instruction from its encoded form. */
8619 tinsn_from_chars (t_insn
, f
)
8623 static xtensa_insnbuf insnbuf
= NULL
;
8625 xtensa_opcode opcode
;
8626 xtensa_isa isa
= xtensa_default_isa
;
8629 insnbuf
= xtensa_insnbuf_alloc (isa
);
8631 xtensa_insnbuf_from_chars (isa
, insnbuf
, f
);
8632 opcode
= xtensa_decode_insn (isa
, insnbuf
);
8634 /* Find the immed. */
8635 tinsn_init (t_insn
);
8636 t_insn
->insn_type
= ITYPE_INSN
;
8637 t_insn
->is_specific_opcode
= FALSE
; /* Must not be specific. */
8638 t_insn
->opcode
= opcode
;
8639 t_insn
->ntok
= xtensa_num_operands (isa
, opcode
);
8640 for (i
= 0; i
< t_insn
->ntok
; i
++)
8642 set_expr_const (&t_insn
->tok
[i
],
8643 xtensa_insnbuf_get_operand (insnbuf
, opcode
, i
));
8648 /* Read the value of the relaxable immed from the fr_symbol and fr_offset. */
8651 tinsn_immed_from_frag (t_insn
, fragP
)
8655 xtensa_opcode opcode
= t_insn
->opcode
;
8658 if (fragP
->fr_symbol
)
8660 opnum
= get_relaxable_immed (opcode
);
8661 set_expr_symbol_offset (&t_insn
->tok
[opnum
],
8662 fragP
->fr_symbol
, fragP
->fr_offset
);
8668 get_num_stack_text_bytes (istack
)
8674 for (i
= 0; i
< istack
->ninsn
; i
++)
8676 TInsn
*t_insn
= &istack
->insn
[i
];
8677 if (t_insn
->insn_type
== ITYPE_INSN
)
8678 text_bytes
+= xg_get_insn_size (t_insn
);
8685 get_num_stack_literal_bytes (istack
)
8691 for (i
= 0; i
< istack
->ninsn
; i
++)
8693 TInsn
*t_insn
= &istack
->insn
[i
];
8695 if (t_insn
->insn_type
== ITYPE_LITERAL
&& t_insn
->ntok
== 1)
8702 /* Expression utilities. */
8704 /* Return true if the expression is an integer constant. */
8708 const expressionS
*s
;
8710 return (s
->X_op
== O_constant
);
8714 /* Get the expression constant.
8715 Calling this is illegal if expr_is_const () returns true. */
8719 const expressionS
*s
;
8721 assert (expr_is_const (s
));
8722 return s
->X_add_number
;
8726 /* Set the expression to a constant value. */
8729 set_expr_const (s
, val
)
8733 s
->X_op
= O_constant
;
8734 s
->X_add_number
= val
;
8735 s
->X_add_symbol
= NULL
;
8736 s
->X_op_symbol
= NULL
;
8740 /* Set the expression to a symbol + constant offset. */
8743 set_expr_symbol_offset (s
, sym
, offset
)
8749 s
->X_add_symbol
= sym
;
8750 s
->X_op_symbol
= NULL
; /* unused */
8751 s
->X_add_number
= offset
;
8756 expr_is_equal (s1
, s2
)
8760 if (s1
->X_op
!= s2
->X_op
)
8762 if (s1
->X_add_symbol
!= s2
->X_add_symbol
)
8764 if (s1
->X_op_symbol
!= s2
->X_op_symbol
)
8766 if (s1
->X_add_number
!= s2
->X_add_number
)
8773 copy_expr (dst
, src
)
8775 const expressionS
*src
;
8777 memcpy (dst
, src
, sizeof (expressionS
));
8781 /* Support for Tensilica's "--rename-section" option. */
8783 #ifdef XTENSA_SECTION_RENAME
8785 struct rename_section_struct
8789 struct rename_section_struct
*next
;
8792 static struct rename_section_struct
*section_rename
;
8795 /* Parse the string oldname=new_name:oldname2=new_name2
8796 and call add_section_rename. */
8799 build_section_rename (arg
)
8802 char *this_arg
= NULL
;
8803 char *next_arg
= NULL
;
8805 for (this_arg
= strdup (arg
); this_arg
!= NULL
; this_arg
= next_arg
)
8809 next_arg
= strchr (this_arg
, ':');
8817 char *old_name
= this_arg
;
8818 char *new_name
= strchr (this_arg
, '=');
8820 if (*old_name
== '\0')
8822 as_warn (_("ignoring extra '-rename-section' delimiter ':'"));
8825 if (!new_name
|| new_name
[1] == '\0')
8827 as_warn (_("ignoring invalid '-rename-section' "
8828 "specification: '%s'"), old_name
);
8833 add_section_rename (old_name
, new_name
);
8840 add_section_rename (old_name
, new_name
)
8844 struct rename_section_struct
*r
= section_rename
;
8846 /* Check for invalid section renaming. */
8847 for (r
= section_rename
; r
!= NULL
; r
= r
->next
)
8849 if (strcmp (r
->old_name
, old_name
) == 0)
8850 as_bad (_("section %s renamed multiple times"), old_name
);
8851 if (strcmp (r
->new_name
, new_name
) == 0)
8852 as_bad (_("multiple sections remapped to output section %s"),
8857 r
= (struct rename_section_struct
*)
8858 xmalloc (sizeof (struct rename_section_struct
));
8859 r
->old_name
= strdup (old_name
);
8860 r
->new_name
= strdup (new_name
);
8861 r
->next
= section_rename
;
8867 xtensa_section_rename (name
)
8870 struct rename_section_struct
*r
= section_rename
;
8872 for (r
= section_rename
; r
!= NULL
; r
= r
->next
)
8873 if (strcmp (r
->old_name
, name
) == 0)
8879 #endif /* XTENSA_SECTION_RENAME */
8882 /* Combining identical literals. */
8884 #ifdef XTENSA_COMBINE_LITERALS
8886 /* This code records all the .literal values that are ever seen and
8887 detects duplicates so that identical values can be combined. This
8888 is currently disabled because it's only half-baked. */
8890 #define XTENSA_LIT_PLUS_OFFSET ".xtensa_litsym_offset_"
8892 /* TODO: make this into a more efficient data structure. */
8893 typedef struct literal_list_elem
8895 symbolS
*sym
; /* The symbol that points to this literal. */
8896 expressionS expr
; /* The expression. */
8898 struct literal_list_elem
*next
; /* Next in the list. */
8899 } literal_list_elem
;
8901 literal_list_elem
*lit_cache
= NULL
;
8903 typedef struct lit_sym_translation
8905 char *name
; /* This name. */
8906 offsetT offset
; /* Plus this offset. */
8907 symbolS
*sym
; /* Should really mean this symbol. */
8908 struct lit_sym_translation
*next
;
8909 } lit_sym_translation
;
8911 lit_sym_translation
*translations
= NULL
;
8913 static bfd_boolean is_duplicate_expression
8914 PARAMS ((expressionS
*, expressionS
*));
8915 static void cache_literal
8916 PARAMS ((char *sym_name
, expressionS
*, segT
));
8917 static symbolS
*is_duplicate_literal
8918 PARAMS ((expressionS
*, segT
));
8922 is_duplicate_expression (e1
, e2
)
8926 if (e1
->X_op
!= e2
->X_op
)
8928 if (e1
->X_add_symbol
!= e2
->X_add_symbol
)
8930 if (e1
->X_op_symbol
!= e2
->X_op_symbol
)
8932 if (e1
->X_add_number
!= e2
->X_add_number
)
8934 if (e1
->X_unsigned
!= e2
->X_unsigned
)
8936 if (e1
->X_md
!= e2
->X_md
)
8943 cache_literal (sym_name
, expP
, seg
)
8948 literal_list_elem
*lit
= xmalloc (sizeof (literal_list_elem
));
8950 lit
->sym
= symbol_find (sym_name
);
8953 lit
->next
= lit_cache
;
8959 is_duplicate_literal (expr
, seg
)
8963 literal_list_elem
*lit
= lit_cache
;
8967 if (is_duplicate_expression (&lit
->expr
, expr
) && seg
== lit
->seg
)
8977 add_lit_sym_translation (name
, offset
, target
)
8982 lit_sym_translation
*lit_trans
= xmalloc (sizeof (lit_sym_translation
));
8984 lit_trans
->name
= name
;
8985 lit_trans
->offset
= offset
;
8986 lit_trans
->sym
= target
;
8987 lit_trans
->next
= translations
;
8988 translations
= lit_trans
;
8993 find_lit_sym_translation (expr
)
8996 lit_sym_translation
*lit_trans
= translations
;
8998 if (expr
->X_op
!= O_symbol
)
9001 while (lit_trans
!= NULL
)
9003 if (lit_trans
->offset
== expr
->X_add_number
9004 && strcmp (lit_trans
->name
, S_GET_NAME (expr
->X_add_symbol
)) == 0)
9006 expr
->X_add_symbol
= lit_trans
->sym
;
9007 expr
->X_add_number
= 0;
9010 lit_trans
= lit_trans
->next
;
9014 #endif /* XTENSA_COMBINE_LITERALS */