Back to index

cell-binutils  2.17cvs20070401
tc-xtensa.h
Go to the documentation of this file.
00001 /* tc-xtensa.h -- Header file for tc-xtensa.c.
00002    Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
00003 
00004    This file is part of GAS, the GNU Assembler.
00005 
00006    GAS is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    GAS is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with GAS; see the file COPYING.  If not, write to the Free
00018    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00019    02110-1301, USA.  */
00020 
00021 #ifndef TC_XTENSA
00022 #define TC_XTENSA 1
00023 
00024 struct fix;
00025 
00026 #ifndef OBJ_ELF
00027 #error Xtensa support requires ELF object format
00028 #endif
00029 
00030 #include "xtensa-isa.h"
00031 #include "xtensa-config.h"
00032 
00033 #define TARGET_BYTES_BIG_ENDIAN XCHAL_HAVE_BE
00034 
00035 
00036 /* Maximum number of opcode slots in a VLIW instruction.  */
00037 #define MAX_SLOTS 15
00038 
00039 
00040 /* For all xtensa relax states except RELAX_DESIRE_ALIGN and
00041    RELAX_DESIRE_ALIGN_IF_TARGET, the amount a frag might grow is stored
00042    in the fr_var field.  For the two exceptions, fr_var is a float value
00043    that records the frequency with which the following instruction is
00044    executed as a branch target.  The aligner uses this information to
00045    tell which targets are most important to be aligned.  */
00046 
00047 enum xtensa_relax_statesE
00048 {
00049   RELAX_ALIGN_NEXT_OPCODE,
00050   /* Use the first opcode of the next fragment to determine the
00051      alignment requirements.  This is ONLY used for LOOPs currently.  */
00052 
00053   RELAX_CHECK_ALIGN_NEXT_OPCODE,
00054   /* The next non-empty frag contains a loop instruction.  Check to see
00055      if it is correctly aligned, but do not align it.  */
00056 
00057   RELAX_DESIRE_ALIGN_IF_TARGET,
00058   /* These are placed in front of labels and converted to either
00059      RELAX_DESIRE_ALIGN / RELAX_LOOP_END or rs_fill of 0 before
00060      relaxation begins.  */
00061 
00062   RELAX_ADD_NOP_IF_A0_B_RETW,
00063   /* These are placed in front of conditional branches.  Before
00064      relaxation begins, they are turned into either NOPs for branches
00065      immediately followed by RETW or RETW.N or rs_fills of 0.  This is
00066      used to avoid a hardware bug in some early versions of the
00067      processor.  */
00068 
00069   RELAX_ADD_NOP_IF_PRE_LOOP_END,
00070   /* These are placed after JX instructions.  Before relaxation begins,
00071      they are turned into either NOPs, if the JX is one instruction
00072      before a loop end label, or rs_fills of 0.  This is used to avoid a
00073      hardware interlock issue prior to Xtensa version T1040.  */
00074 
00075   RELAX_ADD_NOP_IF_SHORT_LOOP,
00076   /* These are placed after LOOP instructions and turned into NOPs when:
00077      (1) there are less than 3 instructions in the loop; we place 2 of
00078      these in a row to add up to 2 NOPS in short loops; or (2) the
00079      instructions in the loop do not include a branch or jump.
00080      Otherwise they are turned into rs_fills of 0 before relaxation
00081      begins.  This is used to avoid hardware bug PR3830.  */
00082 
00083   RELAX_ADD_NOP_IF_CLOSE_LOOP_END,
00084   /* These are placed after LOOP instructions and turned into NOPs if
00085      there are less than 12 bytes to the end of some other loop's end.
00086      Otherwise they are turned into rs_fills of 0 before relaxation
00087      begins.  This is used to avoid hardware bug PR3830.  */
00088 
00089   RELAX_DESIRE_ALIGN,
00090   /* The next fragment would like its first instruction to NOT cross an
00091      instruction fetch boundary.  */
00092 
00093   RELAX_MAYBE_DESIRE_ALIGN,
00094   /* The next fragment might like its first instruction to NOT cross an
00095      instruction fetch boundary.  These are placed after a branch that
00096      might be relaxed.  If the branch is relaxed, then this frag will be
00097      a branch target and this frag will be changed to RELAX_DESIRE_ALIGN
00098      frag.  */
00099 
00100   RELAX_LOOP_END,
00101   /* This will be turned into a NOP or NOP.N if the previous instruction
00102      is expanded to negate a loop.  */
00103 
00104   RELAX_LOOP_END_ADD_NOP,
00105   /* When the code density option is available, this will generate a
00106      NOP.N marked RELAX_NARROW.  Otherwise, it will create an rs_fill
00107      fragment with a NOP in it.  */
00108 
00109   RELAX_LITERAL,
00110   /* Another fragment could generate an expansion here but has not yet.  */
00111 
00112   RELAX_LITERAL_NR,
00113   /* Expansion has been generated by an instruction that generates a
00114      literal.  However, the stretch has NOT been reported yet in this
00115      fragment.  */
00116 
00117   RELAX_LITERAL_FINAL,
00118   /* Expansion has been generated by an instruction that generates a
00119      literal.  */
00120 
00121   RELAX_LITERAL_POOL_BEGIN,
00122   RELAX_LITERAL_POOL_END,
00123   /* Technically these are not relaxations at all but mark a location
00124      to store literals later.  Note that fr_var stores the frchain for
00125      BEGIN frags and fr_var stores now_seg for END frags.  */
00126 
00127   RELAX_NARROW,
00128   /* The last instruction in this fragment (at->fr_opcode) can be
00129      freely replaced with a single wider instruction if a future
00130      alignment desires or needs it.  */
00131 
00132   RELAX_IMMED,
00133   /* The last instruction in this fragment (at->fr_opcode) contains
00134      the value defined by fr_symbol (fr_offset = 0).  If the value
00135      does not fit, use the specified expansion.  This is similar to
00136      "NARROW", except that these may not be expanded in order to align
00137      code.  */
00138 
00139   RELAX_IMMED_STEP1,
00140   /* The last instruction in this fragment (at->fr_opcode) contains a
00141      literal.  It has already been expanded at least 1 step.  */
00142 
00143   RELAX_IMMED_STEP2,
00144   /* The last instruction in this fragment (at->fr_opcode) contains a
00145      literal.  It has already been expanded at least 2 steps.  */
00146 
00147   RELAX_SLOTS,
00148   /* There are instructions within the last VLIW instruction that need
00149      relaxation.  Find the relaxation based on the slot info in
00150      xtensa_frag_type.  Relaxations that deal with particular opcodes
00151      are slot-based (e.g., converting a MOVI to an L32R).  Relaxations
00152      that deal with entire instructions, such as alignment, are not
00153      slot-based.  */
00154 
00155   RELAX_FILL_NOP,
00156   /* This marks the location of a pipeline stall.  We can fill these guys
00157      in for alignment of any size.  */
00158 
00159   RELAX_UNREACHABLE,
00160   /* This marks the location as unreachable.  The assembler may widen or
00161      narrow this area to meet alignment requirements of nearby
00162      instructions.  */
00163 
00164   RELAX_MAYBE_UNREACHABLE,
00165   /* This marks the location as possibly unreachable.  These are placed
00166      after a branch that may be relaxed into a branch and jump. If the
00167      branch is relaxed, then this frag will be converted to a
00168      RELAX_UNREACHABLE frag.  */
00169 
00170   RELAX_NONE
00171 };
00172 
00173 /* This is used as a stopper to bound the number of steps that
00174    can be taken.  */
00175 #define RELAX_IMMED_MAXSTEPS (RELAX_IMMED_STEP2 - RELAX_IMMED)
00176 
00177 struct xtensa_frag_type
00178 {
00179   /* Info about the current state of assembly, e.g., transform,
00180      absolute_literals, etc.  These need to be passed to the backend and
00181      then to the object file.
00182 
00183      When is_assembly_state_set is false, the frag inherits some of the
00184      state settings from the previous frag in this segment.  Because it
00185      is not possible to intercept all fragment closures (frag_more and
00186      frag_append_1_char can close a frag), we use a pass after initial
00187      assembly to fill in the assembly states.  */
00188 
00189   unsigned int is_assembly_state_set : 1;
00190   unsigned int is_no_density : 1;
00191   unsigned int is_no_transform : 1;
00192   unsigned int use_longcalls : 1;
00193   unsigned int use_absolute_literals : 1;
00194 
00195   /* Inhibits relaxation of machine-dependent alignment frags the
00196      first time through a relaxation....  */
00197   unsigned int relax_seen : 1;
00198 
00199   /* Information that is needed in the object file and set when known.  */
00200   unsigned int is_literal : 1;
00201   unsigned int is_loop_target : 1;
00202   unsigned int is_branch_target : 1;
00203   unsigned int is_insn : 1;
00204   unsigned int is_unreachable : 1;
00205 
00206   unsigned int is_specific_opcode : 1; /* also implies no_transform */
00207 
00208   unsigned int is_align : 1;
00209   unsigned int is_text_align : 1;
00210   unsigned int alignment : 5;
00211 
00212   /* A frag with this bit set is the first in a loop that actually
00213      contains an instruction.  */
00214   unsigned int is_first_loop_insn : 1;
00215 
00216   /* A frag with this bit set is a branch that we are using to
00217      align branch targets as if it were a normal narrow instruction.  */
00218   unsigned int is_aligning_branch : 1;
00219 
00220   /* For text fragments that can generate literals at relax time, this
00221      variable points to the frag where the literal will be stored.  For
00222      literal frags, this variable points to the nearest literal pool
00223      location frag.  This literal frag will be moved to after this
00224      location.  */
00225   fragS *literal_frag;
00226 
00227   /* The destination segment for literal frags.  (Note that this is only
00228      valid after xtensa_move_literals.)  This field is also used for
00229      LITERAL_POOL_END frags.  */
00230   segT lit_seg;
00231 
00232   /* Frag chain for LITERAL_POOL_BEGIN frags.  */
00233   struct frchain *lit_frchain;
00234 
00235   /* For the relaxation scheme, some literal fragments can have their
00236      expansions modified by an instruction that relaxes.  */
00237   int text_expansion[MAX_SLOTS];
00238   int literal_expansion[MAX_SLOTS];
00239   int unreported_expansion;
00240 
00241   /* For text fragments that can generate literals at relax time:  */
00242   fragS *literal_frags[MAX_SLOTS];
00243   enum xtensa_relax_statesE slot_subtypes[MAX_SLOTS];
00244   symbolS *slot_symbols[MAX_SLOTS];
00245   offsetT slot_offsets[MAX_SLOTS];
00246 
00247   /* The global aligner needs to walk backward through the list of
00248      frags.  This field is only valid after xtensa_end.  */
00249   fragS *fr_prev;
00250 };
00251 
00252 
00253 /* For VLIW support, we need to know what slot a fixup applies to.  */
00254 typedef struct xtensa_fix_data_struct
00255 {
00256   int slot;
00257   symbolS *X_add_symbol;
00258   offsetT X_add_number;
00259 } xtensa_fix_data;
00260 
00261 
00262 /* Structure to record xtensa-specific symbol information.  */
00263 typedef struct xtensa_symfield_type
00264 {
00265   unsigned int is_loop_target : 1;
00266   unsigned int is_branch_target : 1;
00267 } xtensa_symfield_type;
00268 
00269 
00270 /* Structure for saving information about a block of property data
00271    for frags that have the same flags.   The forward reference is
00272    in this header file.  The actual definition is in tc-xtensa.c.  */
00273 struct xtensa_block_info_struct;
00274 typedef struct xtensa_block_info_struct xtensa_block_info;
00275 
00276 
00277 /* Property section types.  */
00278 typedef enum
00279 {
00280   xt_literal_sec,
00281   xt_prop_sec,
00282   max_xt_sec
00283 } xt_section_type;
00284 
00285 typedef struct xtensa_segment_info_struct
00286 {
00287   fragS *literal_pool_loc;
00288   xtensa_block_info *blocks[max_xt_sec];
00289 } xtensa_segment_info;
00290 
00291 
00292 extern const char *xtensa_target_format (void);
00293 extern void xtensa_init_fix_data (struct fix *);
00294 extern void xtensa_frag_init (fragS *);
00295 extern int xtensa_force_relocation (struct fix *);
00296 extern int xtensa_validate_fix_sub (struct fix *);
00297 extern void xtensa_frob_label (struct symbol *);
00298 extern void xtensa_end (void);
00299 extern void xtensa_post_relax_hook (void);
00300 extern void xtensa_file_arch_init (bfd *);
00301 extern void xtensa_flush_pending_output (void);
00302 extern bfd_boolean xtensa_fix_adjustable (struct fix *);
00303 extern void xtensa_symbol_new_hook (symbolS *);
00304 extern long xtensa_relax_frag (fragS *, long, int *);
00305 extern void xtensa_elf_section_change_hook (void);
00306 extern int xtensa_unrecognized_line (int);
00307 extern bfd_boolean xtensa_check_inside_bundle (void);
00308 extern void xtensa_handle_align (fragS *);
00309 extern char *xtensa_section_rename (char *);
00310 
00311 #define TARGET_FORMAT                     xtensa_target_format ()
00312 #define TARGET_ARCH                bfd_arch_xtensa
00313 #define TC_SEGMENT_INFO_TYPE              xtensa_segment_info
00314 #define TC_SYMFIELD_TYPE                struct xtensa_symfield_type
00315 #define TC_FIX_TYPE                xtensa_fix_data
00316 #define TC_INIT_FIX_DATA(x)        xtensa_init_fix_data (x)
00317 #define TC_FRAG_TYPE               struct xtensa_frag_type
00318 #define TC_FRAG_INIT(frag)         xtensa_frag_init (frag)
00319 #define TC_FORCE_RELOCATION(fix)   xtensa_force_relocation (fix)
00320 #define TC_FORCE_RELOCATION_SUB_SAME(fix, seg) \
00321   (! SEG_NORMAL (seg) || xtensa_force_relocation (fix))
00322 #define       TC_VALIDATE_FIX_SUB(fix)    xtensa_validate_fix_sub (fix)
00323 #define NO_PSEUDO_DOT                     xtensa_check_inside_bundle ()
00324 #define tc_canonicalize_symbol_name(s)    xtensa_section_rename (s)
00325 #define tc_canonicalize_section_name(s)   xtensa_section_rename (s)
00326 #define tc_init_after_args()              xtensa_file_arch_init (stdoutput)
00327 #define tc_fix_adjustable(fix)            xtensa_fix_adjustable (fix)
00328 #define tc_frob_label(sym)         xtensa_frob_label (sym)
00329 #define tc_unrecognized_line(ch)   xtensa_unrecognized_line (ch)
00330 #define md_do_align(a,b,c,d,e)            xtensa_flush_pending_output ()
00331 #define md_elf_section_change_hook xtensa_elf_section_change_hook
00332 #define md_end                            xtensa_end
00333 #define md_flush_pending_output()  xtensa_flush_pending_output ()
00334 #define md_operand(x)
00335 #define TEXT_SECTION_NAME          xtensa_section_rename (".text")
00336 #define DATA_SECTION_NAME          xtensa_section_rename (".data")
00337 #define BSS_SECTION_NAME           xtensa_section_rename (".bss")
00338 #define HANDLE_ALIGN(fragP)        xtensa_handle_align (fragP)
00339 #define MAX_MEM_FOR_RS_ALIGN_CODE  1
00340 
00341 
00342 /* The renumber_section function must be mapped over all the sections
00343    after calling xtensa_post_relax_hook.  That function is static in
00344    write.c so it cannot be called from xtensa_post_relax_hook itself.  */
00345 
00346 #define md_post_relax_hook \
00347   do \
00348     { \
00349       int i = 0; \
00350       xtensa_post_relax_hook (); \
00351       bfd_map_over_sections (stdoutput, renumber_sections, &i); \
00352     } \
00353   while (0)
00354 
00355 
00356 /* Because xtensa relaxation can insert a new literal into the middle of
00357    fragment and thus require re-running the relaxation pass on the
00358    section, we need an explicit flag here.  We explicitly use the name
00359    "stretched" here to avoid changing the source code in write.c.  */
00360 
00361 #define md_relax_frag(segment, fragP, stretch) \
00362   xtensa_relax_frag (fragP, stretch, &stretched)
00363 
00364 
00365 #define LOCAL_LABELS_FB 1
00366 #define WORKING_DOT_WORD 1
00367 #define DOUBLESLASH_LINE_COMMENTS
00368 #define TC_HANDLES_FX_DONE
00369 #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 0
00370 #define TC_LINKRELAX_FIXUP(SEG) 0
00371 #define MD_APPLY_SYM_VALUE(FIX) 0
00372 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
00373 
00374 /* Use line number format that is amenable to linker relaxation.  */
00375 #define DWARF2_USE_FIXED_ADVANCE_PC (linkrelax != 0)
00376 
00377 
00378 /* Resource reservation info functions.  */
00379 
00380 /* Returns the number of copies of a particular unit.  */
00381 typedef int (*unit_num_copies_func) (void *, xtensa_funcUnit);
00382 
00383 /* Returns the number of units the opcode uses.  */
00384 typedef int (*opcode_num_units_func) (void *, xtensa_opcode);
00385 
00386 /* Given an opcode and an index into the opcode's funcUnit list,
00387    returns the unit used for the index.  */
00388 typedef int (*opcode_funcUnit_use_unit_func) (void *, xtensa_opcode, int);
00389 
00390 /* Given an opcode and an index into the opcode's funcUnit list,
00391    returns the cycle during which the unit is used.  */
00392 typedef int (*opcode_funcUnit_use_stage_func) (void *, xtensa_opcode, int);
00393 
00394 /* The above typedefs parameterize the resource_table so that the
00395    optional scheduler doesn't need its own resource reservation system.
00396 
00397    For simple resource checking, which is all that happens normally,
00398    the functions will be as follows (with some wrapping to make the
00399    interface more convenient):
00400 
00401    unit_num_copies_func = xtensa_funcUnit_num_copies
00402    opcode_num_units_func = xtensa_opcode_num_funcUnit_uses
00403    opcode_funcUnit_use_unit_func = xtensa_opcode_funcUnit_use->unit
00404    opcode_funcUnit_use_stage_func = xtensa_opcode_funcUnit_use->stage
00405 
00406    Of course the optional scheduler has its own reservation table
00407    and functions.  */
00408 
00409 int opcode_funcUnit_use_unit (void *, xtensa_opcode, int);
00410 int opcode_funcUnit_use_stage (void *, xtensa_opcode, int);
00411 
00412 typedef struct
00413 {
00414   void *data;
00415   int cycles;
00416   int allocated_cycles;
00417   int num_units;
00418   unit_num_copies_func unit_num_copies;
00419   opcode_num_units_func opcode_num_units;
00420   opcode_funcUnit_use_unit_func opcode_unit_use;
00421   opcode_funcUnit_use_stage_func opcode_unit_stage;
00422   unsigned char **units;
00423 } resource_table;
00424 
00425 resource_table *new_resource_table
00426   (void *, int, int, unit_num_copies_func, opcode_num_units_func,
00427    opcode_funcUnit_use_unit_func, opcode_funcUnit_use_stage_func);
00428 void resize_resource_table (resource_table *, int);
00429 void clear_resource_table (resource_table *);
00430 bfd_boolean resources_available (resource_table *, xtensa_opcode, int);
00431 void reserve_resources (resource_table *, xtensa_opcode, int);
00432 void release_resources (resource_table *, xtensa_opcode, int);
00433 
00434 #endif /* TC_XTENSA */