f887fcc0c5527bfad2320b448b96e474fb6d773e
[external/binutils.git] / gas / config / tc-arc.h
1 /* tc-arc.h - Macros and type defines for the ARC.
2    Copyright (C) 2014-2017 Free Software Foundation, Inc.
3
4    Contributed by Claudiu Zissulescu (claziss@synopsys.com)
5
6    This file is part of GAS, the GNU Assembler.
7
8    GAS is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 3,
11    or (at your option) any later version.
12
13    GAS is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
16    the GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GAS; see the file COPYING.  If not, write to the Free
20    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21    02110-1301, USA.  */
22
23 #include "opcode/arc.h"
24
25 /* By convention, you should define this macro in the `.h' file.  For
26    example, `tc-m68k.h' defines `TC_M68K'.  You might have to use this
27    if it is necessary to add CPU specific code to the object format
28    file.  */
29 #define TC_ARC
30
31 /* We want local label support.  */
32 #define LOCAL_LABELS_FB 1
33
34 /* This macro is the BFD architecture to pass to
35    `bfd_set_arch_mach'.  */
36 #define TARGET_ARCH bfd_arch_arc
37
38 /* The `extsym - .' expressions can be emitted using PC-relative
39    relocs.  */
40 #define DIFF_EXPR_OK
41
42 #define REGISTER_PREFIX '%'
43
44 #undef  LITTLE_ENDIAN
45 #define LITTLE_ENDIAN   1234
46
47 #undef  BIG_ENDIAN
48 #define BIG_ENDIAN      4321
49
50 #ifdef TARGET_BYTES_BIG_ENDIAN
51
52 # define DEFAULT_TARGET_FORMAT  "elf32-bigarc"
53 # define DEFAULT_BYTE_ORDER     BIG_ENDIAN
54
55 #else
56 /* You should define this macro to be non-zero if the target is big
57    endian, and zero if the target is little endian.  */
58 # define TARGET_BYTES_BIG_ENDIAN 0
59
60 # define DEFAULT_TARGET_FORMAT  "elf32-littlearc"
61 # define DEFAULT_BYTE_ORDER     LITTLE_ENDIAN
62
63 #endif /* TARGET_BYTES_BIG_ENDIAN.  */
64
65 /* The endianness of the target format may change based on command
66    line arguments.  */
67 extern const char *arc_target_format;
68
69 /* This macro is the BFD target name to use when creating the output
70    file.  This will normally depend upon the `OBJ_FMT' macro.  */
71 #define TARGET_FORMAT arc_target_format
72
73 /* `md_short_jump_size'
74    `md_long_jump_size'
75    `md_create_short_jump'
76    `md_create_long_jump'
77
78    If `WORKING_DOT_WORD' is defined, GAS will not do broken word
79    processing (*note Broken words::.).  Otherwise, you should set
80    `md_short_jump_size' to the size of a short jump (a jump that is
81    just long enough to jump around a long jmp) and `md_long_jump_size'
82    to the size of a long jump (a jump that can go anywhere in the
83    function).  You should define `md_create_short_jump' to create a
84    short jump around a long jump, and define `md_create_long_jump' to
85    create a long jump.  */
86 #define WORKING_DOT_WORD
87
88 #define LISTING_HEADER "ARC GAS "
89
90 /* The number of bytes to put into a word in a listing.  This affects
91    the way the bytes are clumped together in the listing.  For
92    example, a value of 2 might print `1234 5678' where a value of 1
93    would print `12 34 56 78'.  The default value is 4.  */
94 #define LISTING_WORD_SIZE 2
95
96 /* If you define this macro, it should return the position from which
97    the PC relative adjustment for a PC relative fixup should be made.
98    On many processors, the base of a PC relative instruction is the
99    next instruction, so this macro would return the length of an
100    instruction, plus the address of the PC relative fixup.  The latter
101    can be calculated as fixp->fx_where +
102    fixp->fx_frag->fr_address.  */
103 extern long md_pcrel_from_section (struct fix *, segT);
104 #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from_section (FIX, SEC)
105
106 /* [ ] is index operator.  */
107 #define NEED_INDEX_OPERATOR
108
109 #define MAX_MEM_FOR_RS_ALIGN_CODE (1+2)
110
111 /* HANDLE_ALIGN called after all the assembly has been done,
112    so we can fill in all the rs_align_code type frags with
113    nop instructions.  */
114 #define HANDLE_ALIGN(FRAGP)      arc_handle_align (FRAGP)
115
116 /* Values passed to md_apply_fix3 don't include the symbol value.  */
117 #define MD_APPLY_SYM_VALUE(FIX) 0
118
119 /* No shared lib support, so we don't need to ensure externally
120    visible symbols can be overridden.  */
121 #define EXTERN_FORCE_RELOC 0
122
123 /* You may define this macro to generate a fixup for a data allocation
124    pseudo-op.  */
125 #define TC_CONS_FIX_NEW(FRAG, OFF, LEN, EXP, RELOC)     \
126   arc_cons_fix_new ((FRAG), (OFF), (LEN), (EXP), (RELOC))
127
128 /* We don't want gas to fixup the following program memory related
129    relocations.  Check also that fx_addsy is not NULL, in order to
130    make sure that the fixup refers to some sort of label.  */
131 #define TC_VALIDATE_FIX(FIXP,SEG,SKIP)                               \
132   if ((FIXP->fx_r_type == BFD_RELOC_ARC_GOTPC32                      \
133        || FIXP->fx_r_type == BFD_RELOC_ARC_PLT32                     \
134        || FIXP->fx_r_type == BFD_RELOC_ARC_S25W_PCREL_PLT            \
135        || FIXP->fx_r_type == BFD_RELOC_ARC_S25H_PCREL_PLT            \
136        || FIXP->fx_r_type == BFD_RELOC_ARC_S21W_PCREL_PLT            \
137        || FIXP->fx_r_type == BFD_RELOC_ARC_S21H_PCREL_PLT)           \
138       && FIXP->fx_addsy != NULL                                      \
139       && FIXP->fx_subsy == NULL)                                     \
140     {                                                                \
141       symbol_mark_used_in_reloc (FIXP->fx_addsy);                    \
142       goto SKIP;                                                     \
143     }
144
145 /* BFD_RELOC_ARC_TLS_GD_LD may use fx_subsy to store a label that is
146    later turned into fx_offset.  */
147 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \
148   ((FIX)->fx_r_type == BFD_RELOC_ARC_TLS_GD_LD)
149
150 #define TC_VALIDATE_FIX_SUB(FIX, SEG) \
151   ((md_register_arithmetic || (SEG) != reg_section) \
152    && ((FIX)->fx_r_type == BFD_RELOC_GPREL32 \
153        || (FIX)->fx_r_type == BFD_RELOC_GPREL16 \
154        || (FIX)->fx_r_type == BFD_RELOC_ARC_TLS_DTPOFF \
155        || (FIX)->fx_r_type == BFD_RELOC_ARC_TLS_DTPOFF_S9 \
156        || TC_FORCE_RELOCATION_SUB_LOCAL (FIX, SEG)))
157
158 /* We use this to mark the end-loop label.  We use this mark for ZOL
159    validity checks.  */
160 #define TC_SYMFIELD_TYPE   unsigned int
161 #define ARC_GET_FLAG(s)   (*symbol_get_tc (s))
162 #define ARC_SET_FLAG(s,v) (*symbol_get_tc (s) |= (v))
163
164 /* The symbol is a ZOL's end loop label.  */
165 #define ARC_FLAG_ZOL      (1 << 0)
166 /* The symbol is an AUX register.  */
167 #define ARC_FLAG_AUX      (1 << 1)
168
169 /* We use this hook to check the validity of the last to instructions
170    of a ZOL.  */
171 #define tc_frob_label(S)  arc_frob_label (S)
172
173 #define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
174
175 /* We need to take care of not having section relative fixups for the
176    fixups with respect to Position Independent Code.  */
177 #define tc_fix_adjustable(FIX)  tc_arc_fix_adjustable(FIX)
178
179 /* This hook is required to parse register names as operands.  */
180 #define md_parse_name(name, exp, m, c) arc_parse_name (name, exp)
181
182 /* Used within frags to pass some information to some relaxation
183    machine dependent values.  */
184 #define TC_FRAG_TYPE struct arc_relax_type
185
186 /* Adjust non PC-rel values at relaxation time.  */
187 #define TC_PCREL_ADJUST(F) arc_pcrel_adjust (F)
188
189 /* Adjust symbol table.  */
190 #define obj_adjust_symtab() arc_adjust_symtab ()
191
192 /* Object attribute hooks.  */
193 #define md_end arc_md_end
194 #define CONVERT_SYMBOLIC_ATTRIBUTE(name) arc_convert_symbolic_attribute (name)
195 #ifndef TC_COPY_SYMBOL_ATTRIBUTES
196 #define TC_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
197   (arc_copy_symbol_attributes (DEST, SRC))
198 #endif
199
200 extern void arc_copy_symbol_attributes (symbolS *, symbolS *);
201 extern int arc_convert_symbolic_attribute (const char *);
202 extern void arc_md_end (void);
203 extern void arc_adjust_symtab (void);
204 extern int arc_pcrel_adjust (fragS *);
205 extern bfd_boolean arc_parse_name (const char *, struct expressionS *);
206 extern int tc_arc_fix_adjustable (struct fix *);
207 extern void arc_handle_align (fragS *);
208 extern void arc_cons_fix_new (fragS *, int, int, expressionS *,
209                               bfd_reloc_code_real_type);
210 extern void arc_frob_label (symbolS *);
211 extern void tc_arc_frame_initial_instructions (void);
212 extern int tc_arc_regname_to_dw2regnum (char *regname);
213
214 /* The blink register is r31.  */
215 #define DWARF2_DEFAULT_RETURN_COLUMN    31
216 /* Registers are generally saved at negative offsets to the CFA.  */
217 #define DWARF2_CIE_DATA_ALIGNMENT       (-4)
218
219 /* We want .cfi_* pseudo-ops for generating unwind info.  */
220 #define TARGET_USE_CFIPOP 1
221
222 /* CFI hooks.  */
223 #define tc_cfi_frame_initial_instructions  tc_arc_frame_initial_instructions
224 #define tc_regname_to_dw2regnum tc_arc_regname_to_dw2regnum
225
226 /* Define the NOPs.  */
227 #define NOP_OPCODE_S   0x000078E0
228 #define NOP_OPCODE_L   0x264A7000 /* mov 0,0.  */
229
230 #define MAX_FLAG_NAME_LENGTH 7
231
232 struct arc_flags
233 {
234   /* Name of the parsed flag.  */
235   char name[MAX_FLAG_NAME_LENGTH + 1];
236
237   /* Pointer to arc flags.  */
238   const struct arc_flag_operand *flgp;
239 };
240
241 extern const relax_typeS md_relax_table[];
242 #define TC_GENERIC_RELAX_TABLE md_relax_table
243
244 /* Used to construct instructions at md_convert_frag stage of
245    relaxation.  */
246 struct arc_relax_type
247 {
248   /* Dictates whether the pc-relativity should be kept in mind when
249      relax_frag is called or whether the pc-relativity should be
250      solved outside of relaxation.  For clarification: BL(_S) and
251      B(_S) use pcrel == 1 and ADD with a solvable expression as 3rd
252      operand use pcrel == 0.  */
253   unsigned char pcrel;
254
255   /* Expressions that dictate the operands.  Used for re-assembling in
256      md_convert_frag.  */
257   expressionS tok[MAX_INSN_ARGS];
258
259   /* Number of tok (i.e. number of operands).  Used for re-assembling
260      in md_convert_frag.  */
261   int ntok;
262
263   /* Flags of instruction.  Used for re-assembling in
264      md_convert_frag.  */
265   struct arc_flags pflags[MAX_INSN_FLGS];
266
267   /* Number of flags.  Used for re-assembling in md_convert_frag.  */
268   int nflg;
269 };