tc-i386.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* tc-i386.h -- Header file for tc-i386.c
  2. Copyright (C) 1989-2022 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_I386
  17. #define TC_I386 1
  18. #include "opcodes/i386-opc.h"
  19. struct fix;
  20. #define TARGET_BYTES_BIG_ENDIAN 0
  21. #define TARGET_ARCH (i386_arch ())
  22. #define TARGET_MACH (i386_mach ())
  23. extern enum bfd_architecture i386_arch (void);
  24. extern unsigned long i386_mach (void);
  25. #ifdef TE_FreeBSD
  26. #define AOUT_TARGET_FORMAT "a.out-i386-freebsd"
  27. #endif
  28. #ifdef TE_NetBSD
  29. #define AOUT_TARGET_FORMAT "a.out-i386-netbsd"
  30. #endif
  31. #ifdef TE_386BSD
  32. #define AOUT_TARGET_FORMAT "a.out-i386-bsd"
  33. #endif
  34. #ifdef TE_LINUX
  35. #define AOUT_TARGET_FORMAT "a.out-i386-linux"
  36. #endif
  37. #ifdef TE_Mach
  38. #define AOUT_TARGET_FORMAT "a.out-mach3"
  39. #endif
  40. #ifdef TE_DYNIX
  41. #define AOUT_TARGET_FORMAT "a.out-i386-dynix"
  42. #endif
  43. #ifndef AOUT_TARGET_FORMAT
  44. #define AOUT_TARGET_FORMAT "a.out-i386"
  45. #endif
  46. #ifdef TE_FreeBSD
  47. #define ELF_TARGET_FORMAT "elf32-i386-freebsd"
  48. #define ELF_TARGET_FORMAT64 "elf64-x86-64-freebsd"
  49. #elif defined (TE_VXWORKS)
  50. #define ELF_TARGET_FORMAT "elf32-i386-vxworks"
  51. #elif defined TE_CLOUDABI
  52. #define ELF_TARGET_FORMAT64 "elf64-x86-64-cloudabi"
  53. #endif
  54. #ifdef TE_SOLARIS
  55. #define ELF_TARGET_FORMAT "elf32-i386-sol2"
  56. #define ELF_TARGET_FORMAT64 "elf64-x86-64-sol2"
  57. #endif
  58. #ifndef ELF_TARGET_FORMAT
  59. #define ELF_TARGET_FORMAT "elf32-i386"
  60. #endif
  61. #ifndef ELF_TARGET_FORMAT64
  62. #define ELF_TARGET_FORMAT64 "elf64-x86-64"
  63. #endif
  64. #ifndef ELF_TARGET_FORMAT32
  65. #define ELF_TARGET_FORMAT32 "elf32-x86-64"
  66. #endif
  67. #ifndef ELF_TARGET_IAMCU_FORMAT
  68. #define ELF_TARGET_IAMCU_FORMAT "elf32-iamcu"
  69. #endif
  70. #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
  71. || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
  72. || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
  73. extern const char *i386_target_format (void);
  74. #define TARGET_FORMAT i386_target_format ()
  75. #else
  76. #ifdef TE_GO32
  77. #define TARGET_FORMAT "coff-go32"
  78. #endif
  79. #ifdef OBJ_AOUT
  80. #define TARGET_FORMAT AOUT_TARGET_FORMAT
  81. #endif
  82. #endif
  83. #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
  84. /* '$' may be used as immediate prefix. */
  85. #undef LOCAL_LABELS_DOLLAR
  86. #define LOCAL_LABELS_DOLLAR 0
  87. #undef LOCAL_LABELS_FB
  88. #define LOCAL_LABELS_FB 1
  89. extern const char extra_symbol_chars[];
  90. #define tc_symbol_chars extra_symbol_chars
  91. extern const char *i386_comment_chars;
  92. #define tc_comment_chars i386_comment_chars
  93. /* The name of the global offset table generated by the compiler. Allow
  94. this to be overridden if need be. */
  95. #ifndef GLOBAL_OFFSET_TABLE_NAME
  96. #define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
  97. #endif
  98. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) x86_cons (EXP, NBYTES)
  99. extern bfd_reloc_code_real_type x86_cons (expressionS *, int);
  100. #define TC_CONS_FIX_NEW(FRAG, OFF, LEN, EXP, RELOC) \
  101. x86_cons_fix_new(FRAG, OFF, LEN, EXP, RELOC)
  102. extern void x86_cons_fix_new
  103. (fragS *, unsigned int, unsigned int, expressionS *, bfd_reloc_code_real_type);
  104. #define X_PRECISION 5
  105. #define X_PRECISION_PAD 0
  106. #define TC_ADDRESS_BYTES x86_address_bytes
  107. extern int x86_address_bytes (void);
  108. #define DIFF_EXPR_OK /* foo-. gets turned into PC relative relocs */
  109. #define NO_RELOC BFD_RELOC_NONE
  110. int i386_validate_fix (struct fix *);
  111. #define TC_VALIDATE_FIX(FIX,SEGTYPE,SKIP) do { \
  112. if (!i386_validate_fix(FIX)) goto SKIP; \
  113. } while (0)
  114. #define tc_fix_adjustable(X) tc_i386_fix_adjustable(X)
  115. extern int tc_i386_fix_adjustable (struct fix *);
  116. /* Values passed to md_apply_fix don't include the symbol value. */
  117. #define MD_APPLY_SYM_VALUE(FIX) 0
  118. /* ELF wants external syms kept, as does PE COFF. */
  119. #if defined (TE_PE) && defined (STRICT_PE_FORMAT)
  120. #define EXTERN_FORCE_RELOC \
  121. (OUTPUT_FLAVOR == bfd_target_elf_flavour \
  122. || OUTPUT_FLAVOR == bfd_target_coff_flavour)
  123. #else
  124. #define EXTERN_FORCE_RELOC \
  125. (OUTPUT_FLAVOR == bfd_target_elf_flavour)
  126. #endif
  127. /* This expression evaluates to true if the relocation is for a local
  128. object for which we still want to do the relocation at runtime.
  129. False if we are willing to perform this relocation while building
  130. the .o file. GOTOFF and GOT32 do not need to be checked here because
  131. they are not pcrel. .*/
  132. #define TC_FORCE_RELOCATION_LOCAL(FIX) \
  133. (GENERIC_FORCE_RELOCATION_LOCAL (FIX) \
  134. || (FIX)->fx_r_type == BFD_RELOC_386_PLT32 \
  135. || (FIX)->fx_r_type == BFD_RELOC_386_GOTPC \
  136. || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCREL \
  137. || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX \
  138. || (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX)
  139. #define TC_FORCE_RELOCATION_ABS(FIX) \
  140. (TC_FORCE_RELOCATION (FIX) \
  141. || (FIX)->fx_r_type == BFD_RELOC_386_GOT32 \
  142. || (FIX)->fx_r_type == BFD_RELOC_386_GOT32X \
  143. || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCREL \
  144. || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX \
  145. || (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX)
  146. extern int i386_parse_name (char *, expressionS *, char *);
  147. #define md_parse_name(s, e, m, c) i386_parse_name (s, e, c)
  148. extern operatorT i386_operator (const char *name, unsigned int operands, char *);
  149. #define md_operator i386_operator
  150. extern int i386_need_index_operator (void);
  151. #define md_need_index_operator i386_need_index_operator
  152. #define md_register_arithmetic 0
  153. extern const struct relax_type md_relax_table[];
  154. #define TC_GENERIC_RELAX_TABLE md_relax_table
  155. extern int optimize_align_code;
  156. #define md_do_align(n, fill, len, max, around) \
  157. if ((n) \
  158. && !need_pass_2 \
  159. && optimize_align_code \
  160. && (!(fill) \
  161. || ((char)*(fill) == (char)0x90 && (len) == 1)) \
  162. && subseg_text_p (now_seg)) \
  163. { \
  164. frag_align_code ((n), (max)); \
  165. goto around; \
  166. }
  167. #define MAX_MEM_FOR_RS_ALIGN_CODE (alignment ? ((1 << alignment) - 1) : 1)
  168. extern void i386_cons_align (int);
  169. #define md_cons_align(nbytes) i386_cons_align (nbytes)
  170. void i386_print_statistics (FILE *);
  171. #define tc_print_statistics i386_print_statistics
  172. extern unsigned int i386_frag_max_var (fragS *);
  173. #define md_frag_max_var i386_frag_max_var
  174. extern long i386_generic_table_relax_frag (segT, fragS *, long);
  175. #define md_generic_table_relax_frag(segment, fragP, stretch) \
  176. i386_generic_table_relax_frag (segment, fragP, stretch)
  177. #define md_number_to_chars number_to_chars_littleendian
  178. enum processor_type
  179. {
  180. PROCESSOR_UNKNOWN,
  181. PROCESSOR_I386,
  182. PROCESSOR_I486,
  183. PROCESSOR_PENTIUM,
  184. PROCESSOR_PENTIUMPRO,
  185. PROCESSOR_PENTIUM4,
  186. PROCESSOR_NOCONA,
  187. PROCESSOR_CORE,
  188. PROCESSOR_CORE2,
  189. PROCESSOR_COREI7,
  190. PROCESSOR_IAMCU,
  191. PROCESSOR_K6,
  192. PROCESSOR_ATHLON,
  193. PROCESSOR_K8,
  194. PROCESSOR_GENERIC32,
  195. PROCESSOR_GENERIC64,
  196. PROCESSOR_AMDFAM10,
  197. PROCESSOR_BD,
  198. PROCESSOR_ZNVER,
  199. PROCESSOR_BT
  200. };
  201. extern enum processor_type cpu_arch_tune;
  202. extern enum processor_type cpu_arch_isa;
  203. extern i386_cpu_flags cpu_arch_isa_flags;
  204. struct i386_tc_frag_data
  205. {
  206. union
  207. {
  208. fragS *padding_fragP;
  209. fragS *branch_fragP;
  210. } u;
  211. addressT padding_address;
  212. enum processor_type isa;
  213. i386_cpu_flags isa_flags;
  214. enum processor_type tune;
  215. unsigned int max_bytes;
  216. unsigned char length;
  217. unsigned char last_length;
  218. unsigned char max_prefix_length;
  219. unsigned char prefix_length;
  220. unsigned char default_prefix;
  221. unsigned char cmp_size;
  222. unsigned int mf_type : 3;
  223. unsigned int classified : 1;
  224. unsigned int branch_type : 3;
  225. unsigned int code64 : 1; /* Only set by output_branch for now. */
  226. };
  227. /* We need to emit the right NOP pattern in .align frags. This is
  228. done after the text-to-bits assembly pass, so we need to mark it with
  229. the isa/tune settings at the time the .align was assembled. */
  230. #define TC_FRAG_TYPE struct i386_tc_frag_data
  231. #define TC_FRAG_INIT(FRAGP, MAX_BYTES) \
  232. do \
  233. { \
  234. (FRAGP)->tc_frag_data.u.padding_fragP = NULL; \
  235. (FRAGP)->tc_frag_data.padding_address = 0; \
  236. (FRAGP)->tc_frag_data.isa = cpu_arch_isa; \
  237. (FRAGP)->tc_frag_data.isa_flags = cpu_arch_isa_flags; \
  238. (FRAGP)->tc_frag_data.tune = cpu_arch_tune; \
  239. (FRAGP)->tc_frag_data.max_bytes = (MAX_BYTES); \
  240. (FRAGP)->tc_frag_data.length = 0; \
  241. (FRAGP)->tc_frag_data.last_length = 0; \
  242. (FRAGP)->tc_frag_data.max_prefix_length = 0; \
  243. (FRAGP)->tc_frag_data.prefix_length = 0; \
  244. (FRAGP)->tc_frag_data.default_prefix = 0; \
  245. (FRAGP)->tc_frag_data.cmp_size = 0; \
  246. (FRAGP)->tc_frag_data.classified = 0; \
  247. (FRAGP)->tc_frag_data.branch_type = 0; \
  248. (FRAGP)->tc_frag_data.mf_type = 0; \
  249. } \
  250. while (0)
  251. #define WORKING_DOT_WORD 1
  252. /* How to generate NOPs for .nop direct directive. */
  253. extern void i386_generate_nops (fragS *, char *, offsetT, int);
  254. #define md_generate_nops(frag, where, amount, control) \
  255. i386_generate_nops ((frag), (where), (amount), (control))
  256. #define HANDLE_ALIGN(fragP) \
  257. if (fragP->fr_type == rs_align_code) \
  258. { \
  259. offsetT __count = (fragP->fr_next->fr_address \
  260. - fragP->fr_address \
  261. - fragP->fr_fix); \
  262. if (__count > 0 \
  263. && (unsigned int) __count <= fragP->tc_frag_data.max_bytes) \
  264. md_generate_nops (fragP, fragP->fr_literal + fragP->fr_fix, \
  265. __count, 0); \
  266. }
  267. /* We want .cfi_* pseudo-ops for generating unwind info. */
  268. #define TARGET_USE_CFIPOP 1
  269. extern unsigned int x86_dwarf2_return_column;
  270. #define DWARF2_DEFAULT_RETURN_COLUMN x86_dwarf2_return_column
  271. extern int x86_cie_data_alignment;
  272. #define DWARF2_CIE_DATA_ALIGNMENT x86_cie_data_alignment
  273. extern int x86_dwarf2_addr_size (void);
  274. #define DWARF2_ADDR_SIZE(bfd) x86_dwarf2_addr_size ()
  275. #define tc_parse_to_dw2regnum tc_x86_parse_to_dw2regnum
  276. extern void tc_x86_parse_to_dw2regnum (expressionS *);
  277. #define tc_cfi_frame_initial_instructions tc_x86_frame_initial_instructions
  278. extern void tc_x86_frame_initial_instructions (void);
  279. #define md_elf_section_type(str,len) i386_elf_section_type (str, len)
  280. extern int i386_elf_section_type (const char *, size_t);
  281. #ifdef TE_SOLARIS
  282. #define md_fix_up_eh_frame(sec) i386_solaris_fix_up_eh_frame (sec)
  283. extern void i386_solaris_fix_up_eh_frame (segT);
  284. #endif
  285. /* Support for SHF_X86_64_LARGE */
  286. extern bfd_vma x86_64_section_word (char *, size_t);
  287. extern bfd_vma x86_64_section_letter (int, const char **);
  288. #define md_elf_section_letter(LETTER, PTR_MSG) x86_64_section_letter (LETTER, PTR_MSG)
  289. #define md_elf_section_word(STR, LEN) x86_64_section_word (STR, LEN)
  290. #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
  291. extern void x86_cleanup (void);
  292. #define md_cleanup() x86_cleanup ()
  293. #endif
  294. #ifdef TE_PE
  295. #define O_secrel O_md1
  296. #define TC_DWARF2_EMIT_OFFSET tc_pe_dwarf2_emit_offset
  297. void tc_pe_dwarf2_emit_offset (symbolS *, unsigned int);
  298. #endif /* TE_PE */
  299. /* X_add_symbol:X_op_symbol (Intel mode only) */
  300. #define O_full_ptr O_md2
  301. #ifdef OBJ_MACH_O
  302. #define TC_FORCE_RELOCATION(FIX) (obj_mach_o_force_reloc (FIX))
  303. #define TC_FORCE_RELOCATION_SUB_SAME(FIX,SEG) \
  304. (obj_mach_o_force_reloc_sub_same (FIX, SEG))
  305. #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX,SEG) \
  306. (obj_mach_o_force_reloc_sub_local (FIX, SEG))
  307. #define TC_VALIDATE_FIX_SUB(FIX, SEG) 1
  308. #endif /* OBJ_MACH_O */
  309. #endif /* TC_I386 */