tc-xtensa.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /* tc-xtensa.h -- Header file for tc-xtensa.c.
  2. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #ifndef TC_XTENSA
  17. #define TC_XTENSA 1
  18. struct fix;
  19. #ifndef OBJ_ELF
  20. #error Xtensa support requires ELF object format
  21. #endif
  22. #include "xtensa-isa.h"
  23. #include "xtensa-config.h"
  24. #define TARGET_BYTES_BIG_ENDIAN XCHAL_HAVE_BE
  25. /* Maximum number of opcode slots in a VLIW instruction. */
  26. #define MAX_SLOTS 15
  27. /* For all xtensa relax states except RELAX_DESIRE_ALIGN and
  28. RELAX_DESIRE_ALIGN_IF_TARGET, the amount a frag might grow is stored
  29. in the fr_var field. For the two exceptions, fr_var is a float value
  30. that records the frequency with which the following instruction is
  31. executed as a branch target. The aligner uses this information to
  32. tell which targets are most important to be aligned. */
  33. enum xtensa_relax_statesE
  34. {
  35. RELAX_XTENSA_NONE,
  36. RELAX_ALIGN_NEXT_OPCODE,
  37. /* Use the first opcode of the next fragment to determine the
  38. alignment requirements. This is ONLY used for LOOPs currently. */
  39. RELAX_CHECK_ALIGN_NEXT_OPCODE,
  40. /* The next non-empty frag contains a loop instruction. Check to see
  41. if it is correctly aligned, but do not align it. */
  42. RELAX_DESIRE_ALIGN_IF_TARGET,
  43. /* These are placed in front of labels and converted to either
  44. RELAX_DESIRE_ALIGN / RELAX_LOOP_END or rs_fill of 0 before
  45. relaxation begins. */
  46. RELAX_ADD_NOP_IF_A0_B_RETW,
  47. /* These are placed in front of conditional branches. Before
  48. relaxation begins, they are turned into either NOPs for branches
  49. immediately followed by RETW or RETW.N or rs_fills of 0. This is
  50. used to avoid a hardware bug in some early versions of the
  51. processor. */
  52. RELAX_ADD_NOP_IF_PRE_LOOP_END,
  53. /* These are placed after JX instructions. Before relaxation begins,
  54. they are turned into either NOPs, if the JX is one instruction
  55. before a loop end label, or rs_fills of 0. This is used to avoid a
  56. hardware interlock issue prior to Xtensa version T1040. */
  57. RELAX_ADD_NOP_IF_SHORT_LOOP,
  58. /* These are placed after LOOP instructions and turned into NOPs when:
  59. (1) there are less than 3 instructions in the loop; we place 2 of
  60. these in a row to add up to 2 NOPS in short loops; or (2) the
  61. instructions in the loop do not include a branch or jump.
  62. Otherwise they are turned into rs_fills of 0 before relaxation
  63. begins. This is used to avoid hardware bug PR3830. */
  64. RELAX_ADD_NOP_IF_CLOSE_LOOP_END,
  65. /* These are placed after LOOP instructions and turned into NOPs if
  66. there are less than 12 bytes to the end of some other loop's end.
  67. Otherwise they are turned into rs_fills of 0 before relaxation
  68. begins. This is used to avoid hardware bug PR3830. */
  69. RELAX_DESIRE_ALIGN,
  70. /* The next fragment would like its first instruction to NOT cross an
  71. instruction fetch boundary. */
  72. RELAX_MAYBE_DESIRE_ALIGN,
  73. /* The next fragment might like its first instruction to NOT cross an
  74. instruction fetch boundary. These are placed after a branch that
  75. might be relaxed. If the branch is relaxed, then this frag will be
  76. a branch target and this frag will be changed to RELAX_DESIRE_ALIGN
  77. frag. */
  78. RELAX_LOOP_END,
  79. /* This will be turned into a NOP or NOP.N if the previous instruction
  80. is expanded to negate a loop. */
  81. RELAX_LOOP_END_ADD_NOP,
  82. /* When the code density option is available, this will generate a
  83. NOP.N marked RELAX_NARROW. Otherwise, it will create an rs_fill
  84. fragment with a NOP in it. Once a frag has been converted to
  85. RELAX_LOOP_END_ADD_NOP, it should never be changed back to
  86. RELAX_LOOP_END. */
  87. RELAX_LITERAL,
  88. /* Another fragment could generate an expansion here but has not yet. */
  89. RELAX_LITERAL_NR,
  90. /* Expansion has been generated by an instruction that generates a
  91. literal. However, the stretch has NOT been reported yet in this
  92. fragment. */
  93. RELAX_LITERAL_FINAL,
  94. /* Expansion has been generated by an instruction that generates a
  95. literal. */
  96. RELAX_LITERAL_POOL_BEGIN,
  97. RELAX_LITERAL_POOL_END,
  98. RELAX_LITERAL_POOL_CANDIDATE_BEGIN,
  99. /* Technically these are not relaxations at all but mark a location
  100. to store literals later. Note that fr_var stores the frchain for
  101. BEGIN frags and fr_var stores now_seg for END frags. */
  102. RELAX_NARROW,
  103. /* The last instruction in this fragment (at->fr_opcode) can be
  104. freely replaced with a single wider instruction if a future
  105. alignment desires or needs it. */
  106. RELAX_IMMED,
  107. /* The last instruction in this fragment (at->fr_opcode) contains
  108. an immediate or symbol. If the value does not fit, relax the
  109. opcode using expansions from the relax table. */
  110. RELAX_IMMED_STEP1,
  111. /* The last instruction in this fragment (at->fr_opcode) contains a
  112. literal. It has already been expanded 1 step. */
  113. RELAX_IMMED_STEP2,
  114. /* The last instruction in this fragment (at->fr_opcode) contains a
  115. literal. It has already been expanded 2 steps. */
  116. RELAX_IMMED_STEP3,
  117. /* The last instruction in this fragment (at->fr_opcode) contains a
  118. literal. It has already been expanded 3 steps. */
  119. RELAX_SLOTS,
  120. /* There are instructions within the last VLIW instruction that need
  121. relaxation. Find the relaxation based on the slot info in
  122. xtensa_frag_type. Relaxations that deal with particular opcodes
  123. are slot-based (e.g., converting a MOVI to an L32R). Relaxations
  124. that deal with entire instructions, such as alignment, are not
  125. slot-based. */
  126. RELAX_FILL_NOP,
  127. /* This marks the location of a pipeline stall. We can fill these guys
  128. in for alignment of any size. */
  129. RELAX_UNREACHABLE,
  130. /* This marks the location as unreachable. The assembler may widen or
  131. narrow this area to meet alignment requirements of nearby
  132. instructions. */
  133. RELAX_MAYBE_UNREACHABLE,
  134. /* This marks the location as possibly unreachable. These are placed
  135. after a branch that may be relaxed into a branch and jump. If the
  136. branch is relaxed, then this frag will be converted to a
  137. RELAX_UNREACHABLE frag. */
  138. RELAX_ORG,
  139. /* This marks the location as having previously been an rs_org frag.
  140. rs_org frags are converted to fill-zero frags immediately after
  141. relaxation. However, we need to remember where they were so we can
  142. prevent the linker from changing the size of any frag between the
  143. section start and the org frag. */
  144. RELAX_TRAMPOLINE,
  145. /* Every few thousand frags, we insert one of these, just in case we may
  146. need some space for a trampoline (jump to a jump) because the function
  147. has gotten too big. If not needed, it disappears. */
  148. RELAX_NONE
  149. };
  150. /* This is used as a stopper to bound the number of steps that
  151. can be taken. */
  152. #define RELAX_IMMED_MAXSTEPS (RELAX_IMMED_STEP3 - RELAX_IMMED)
  153. struct xtensa_frag_type
  154. {
  155. /* Info about the current state of assembly, e.g., transform,
  156. absolute_literals, etc. These need to be passed to the backend and
  157. then to the object file.
  158. When is_assembly_state_set is false, the frag inherits some of the
  159. state settings from the previous frag in this segment. Because it
  160. is not possible to intercept all fragment closures (frag_more and
  161. frag_append_1_char can close a frag), we use a pass after initial
  162. assembly to fill in the assembly states. */
  163. unsigned int is_assembly_state_set : 1;
  164. unsigned int is_no_density : 1;
  165. unsigned int is_no_transform : 1;
  166. unsigned int use_longcalls : 1;
  167. unsigned int use_absolute_literals : 1;
  168. /* Inhibits relaxation of machine-dependent alignment frags the
  169. first time through a relaxation.... */
  170. unsigned int relax_seen : 1;
  171. /* Information that is needed in the object file and set when known. */
  172. unsigned int is_literal : 1;
  173. unsigned int is_loop_target : 1;
  174. unsigned int is_branch_target : 1;
  175. unsigned int is_insn : 1;
  176. unsigned int is_unreachable : 1;
  177. unsigned int is_specific_opcode : 1; /* also implies no_transform */
  178. unsigned int is_align : 1;
  179. unsigned int is_text_align : 1;
  180. unsigned int alignment : 5;
  181. /* A frag with this bit set is the first in a loop that actually
  182. contains an instruction. */
  183. unsigned int is_first_loop_insn : 1;
  184. /* A frag with this bit set is a branch that we are using to
  185. align branch targets as if it were a normal narrow instruction. */
  186. unsigned int is_aligning_branch : 1;
  187. /* For text fragments that can generate literals at relax time, this
  188. variable points to the frag where the literal will be stored. For
  189. literal frags, this variable points to the nearest literal pool
  190. location frag. This literal frag will be moved to after this
  191. location. For RELAX_LITERAL_POOL_BEGIN frags, this field points
  192. to the frag immediately before the corresponding RELAX_LITERAL_POOL_END
  193. frag, to make moving frags for this literal pool efficient. */
  194. fragS *literal_frag;
  195. /* The destination segment for literal frags. (Note that this is only
  196. valid after xtensa_move_literals.) This field is also used for
  197. LITERAL_POOL_END frags. */
  198. segT lit_seg;
  199. /* Frag chain for LITERAL_POOL_BEGIN frags. */
  200. struct frchain *lit_frchain;
  201. /* For the relaxation scheme, some literal fragments can have their
  202. expansions modified by an instruction that relaxes. */
  203. int text_expansion[MAX_SLOTS];
  204. int literal_expansion[MAX_SLOTS];
  205. int unreported_expansion;
  206. /* For slots that have a free register for relaxation, record that
  207. register. */
  208. expressionS free_reg[MAX_SLOTS];
  209. /* For text fragments that can generate literals at relax time: */
  210. fragS *literal_frags[MAX_SLOTS];
  211. enum xtensa_relax_statesE slot_subtypes[MAX_SLOTS];
  212. symbolS *slot_symbols[MAX_SLOTS];
  213. offsetT slot_offsets[MAX_SLOTS];
  214. /* When marking frags after this one in the chain as no transform,
  215. cache the last one in the chain, so that we can skip to the
  216. end of the chain. */
  217. fragS *no_transform_end;
  218. };
  219. /* For VLIW support, we need to know what slot a fixup applies to. */
  220. typedef struct xtensa_fix_data_struct
  221. {
  222. int slot;
  223. symbolS *X_add_symbol;
  224. offsetT X_add_number;
  225. } xtensa_fix_data;
  226. /* Structure to record xtensa-specific symbol information. */
  227. typedef struct xtensa_symfield_type
  228. {
  229. unsigned int is_loop_target : 1;
  230. unsigned int is_branch_target : 1;
  231. symbolS *next_expr_symbol;
  232. } xtensa_symfield_type;
  233. /* Structure for saving information about a block of property data
  234. for frags that have the same flags. The forward reference is
  235. in this header file. The actual definition is in tc-xtensa.c. */
  236. struct xtensa_block_info_struct;
  237. typedef struct xtensa_block_info_struct xtensa_block_info;
  238. /* Property section types. */
  239. typedef enum
  240. {
  241. xt_literal_sec,
  242. xt_prop_sec,
  243. max_xt_sec
  244. } xt_section_type;
  245. typedef struct xtensa_segment_info_struct
  246. {
  247. fragS *literal_pool_loc;
  248. xtensa_block_info *blocks[max_xt_sec];
  249. } xtensa_segment_info;
  250. extern const char *xtensa_target_format (void);
  251. extern void xtensa_init_fix_data (struct fix *);
  252. extern void xtensa_frag_init (fragS *);
  253. extern int xtensa_force_relocation (struct fix *);
  254. extern int xtensa_validate_fix_sub (struct fix *);
  255. extern void xtensa_frob_label (struct symbol *);
  256. extern void xtensa_end (void);
  257. extern void xtensa_post_relax_hook (void);
  258. extern void xtensa_file_arch_init (bfd *);
  259. extern void xtensa_flush_pending_output (void);
  260. extern bfd_boolean xtensa_fix_adjustable (struct fix *);
  261. extern void xtensa_symbol_new_hook (symbolS *);
  262. extern long xtensa_relax_frag (fragS *, long, int *);
  263. extern void xtensa_elf_section_change_hook (void);
  264. extern int xtensa_unrecognized_line (int);
  265. extern bfd_boolean xtensa_check_inside_bundle (void);
  266. extern void xtensa_handle_align (fragS *);
  267. extern char *xtensa_section_rename (char *);
  268. #define TARGET_FORMAT xtensa_target_format ()
  269. #define TARGET_ARCH bfd_arch_xtensa
  270. #define TC_SEGMENT_INFO_TYPE xtensa_segment_info
  271. #define TC_SYMFIELD_TYPE struct xtensa_symfield_type
  272. #define TC_FIX_TYPE xtensa_fix_data
  273. #define TC_INIT_FIX_DATA(x) xtensa_init_fix_data (x)
  274. #define TC_FRAG_TYPE struct xtensa_frag_type
  275. #define TC_FRAG_INIT(frag) xtensa_frag_init (frag)
  276. #define TC_FORCE_RELOCATION(fix) xtensa_force_relocation (fix)
  277. #define TC_FORCE_RELOCATION_SUB_SAME(fix, seg) \
  278. (! SEG_NORMAL (seg) || xtensa_force_relocation (fix))
  279. #define TC_VALIDATE_FIX_SUB(fix, seg) xtensa_validate_fix_sub (fix)
  280. #define NO_PSEUDO_DOT xtensa_check_inside_bundle ()
  281. #define tc_canonicalize_symbol_name(s) xtensa_section_rename (s)
  282. #define tc_canonicalize_section_name(s) xtensa_section_rename (s)
  283. #define tc_init_after_args() xtensa_file_arch_init (stdoutput)
  284. #define tc_fix_adjustable(fix) xtensa_fix_adjustable (fix)
  285. #define tc_frob_label(sym) xtensa_frob_label (sym)
  286. #define tc_unrecognized_line(ch) xtensa_unrecognized_line (ch)
  287. #define tc_symbol_new_hook(sym) xtensa_symbol_new_hook (sym)
  288. #define md_do_align(a,b,c,d,e) xtensa_flush_pending_output ()
  289. #define md_elf_section_change_hook xtensa_elf_section_change_hook
  290. #define md_end xtensa_end
  291. #define md_flush_pending_output() xtensa_flush_pending_output ()
  292. #define md_operand(x)
  293. #define TEXT_SECTION_NAME xtensa_section_rename (".text")
  294. #define DATA_SECTION_NAME xtensa_section_rename (".data")
  295. #define BSS_SECTION_NAME xtensa_section_rename (".bss")
  296. #define HANDLE_ALIGN(fragP) xtensa_handle_align (fragP)
  297. #define MAX_MEM_FOR_RS_ALIGN_CODE 1
  298. /* The renumber_section function must be mapped over all the sections
  299. after calling xtensa_post_relax_hook. That function is static in
  300. write.c so it cannot be called from xtensa_post_relax_hook itself. */
  301. #define md_post_relax_hook \
  302. do \
  303. { \
  304. int i = 0; \
  305. xtensa_post_relax_hook (); \
  306. bfd_map_over_sections (stdoutput, renumber_sections, &i); \
  307. } \
  308. while (0)
  309. /* Because xtensa relaxation can insert a new literal into the middle of
  310. fragment and thus require re-running the relaxation pass on the
  311. section, we need an explicit flag here. We explicitly use the name
  312. "stretched" here to avoid changing the source code in write.c. */
  313. #define md_relax_frag(segment, fragP, stretch) \
  314. xtensa_relax_frag (fragP, stretch, &stretched)
  315. /* Only allow call frame debug info optimization when linker relaxation is
  316. not enabled as otherwise we could generate the DWARF directives without
  317. the relocs necessary to patch them up. */
  318. #define md_allow_eh_opt (linkrelax == 0)
  319. #define LOCAL_LABELS_FB 1
  320. #define WORKING_DOT_WORD 1
  321. #define DOUBLESLASH_LINE_COMMENTS
  322. #define TC_HANDLES_FX_DONE
  323. #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 0
  324. #define TC_LINKRELAX_FIXUP(SEG) 0
  325. #define MD_APPLY_SYM_VALUE(FIX) 0
  326. #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
  327. /* Use line number format that is amenable to linker relaxation. */
  328. #define DWARF2_USE_FIXED_ADVANCE_PC (linkrelax != 0)
  329. /* Resource reservation info functions. */
  330. /* Returns the number of copies of a particular unit. */
  331. typedef int (*unit_num_copies_func) (void *, xtensa_funcUnit);
  332. /* Returns the number of units the opcode uses. */
  333. typedef int (*opcode_num_units_func) (void *, xtensa_opcode);
  334. /* Given an opcode and an index into the opcode's funcUnit list,
  335. returns the unit used for the index. */
  336. typedef int (*opcode_funcUnit_use_unit_func) (void *, xtensa_opcode, int);
  337. /* Given an opcode and an index into the opcode's funcUnit list,
  338. returns the cycle during which the unit is used. */
  339. typedef int (*opcode_funcUnit_use_stage_func) (void *, xtensa_opcode, int);
  340. /* The above typedefs parameterize the resource_table so that the
  341. optional scheduler doesn't need its own resource reservation system.
  342. For simple resource checking, which is all that happens normally,
  343. the functions will be as follows (with some wrapping to make the
  344. interface more convenient):
  345. unit_num_copies_func = xtensa_funcUnit_num_copies
  346. opcode_num_units_func = xtensa_opcode_num_funcUnit_uses
  347. opcode_funcUnit_use_unit_func = xtensa_opcode_funcUnit_use->unit
  348. opcode_funcUnit_use_stage_func = xtensa_opcode_funcUnit_use->stage
  349. Of course the optional scheduler has its own reservation table
  350. and functions. */
  351. int opcode_funcUnit_use_unit (void *, xtensa_opcode, int);
  352. int opcode_funcUnit_use_stage (void *, xtensa_opcode, int);
  353. typedef struct
  354. {
  355. void *data;
  356. int cycles;
  357. int allocated_cycles;
  358. int num_units;
  359. unit_num_copies_func unit_num_copies;
  360. opcode_num_units_func opcode_num_units;
  361. opcode_funcUnit_use_unit_func opcode_unit_use;
  362. opcode_funcUnit_use_stage_func opcode_unit_stage;
  363. unsigned char **units;
  364. } resource_table;
  365. resource_table *new_resource_table
  366. (void *, int, int, unit_num_copies_func, opcode_num_units_func,
  367. opcode_funcUnit_use_unit_func, opcode_funcUnit_use_stage_func);
  368. void resize_resource_table (resource_table *, int);
  369. void clear_resource_table (resource_table *);
  370. bfd_boolean resources_available (resource_table *, xtensa_opcode, int);
  371. void reserve_resources (resource_table *, xtensa_opcode, int);
  372. void release_resources (resource_table *, xtensa_opcode, int);
  373. #endif /* TC_XTENSA */