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