Add support for Andes NDS32:
[deliverable/binutils-gdb.git] / gas / config / tc-nds32.h
1 /* tc-nds32.h -- Header file for tc-nds32.c.
2 Copyright (C) 2012-2013 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
4
5 This file is part of GAS.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
21
22 #ifndef TC_NDS32
23 #define TC_NDS32
24
25 #include "bfd_stdint.h"
26
27 #define LISTING_HEADER \
28 (target_big_endian ? "NDS32 GAS" : "NDS32 GAS Little Endian")
29
30 /* The target BFD architecture. */
31 #define TARGET_ARCH bfd_arch_nds32
32
33 /* mapping to mach_table[5] */
34 #define ISA_V1 bfd_mach_n1h
35 #define ISA_V2 bfd_mach_n1h_v2
36 #define ISA_V3 bfd_mach_n1h_v3
37 #define ISA_V3M bfd_mach_n1h_v3m
38
39 /* Default to big endian. Please note that for Andes architecture,
40 instructions are always in big-endian format. */
41 #ifndef TARGET_BYTES_BIG_ENDIAN
42 #define TARGET_BYTES_BIG_ENDIAN 1
43 #endif
44
45 /* This is used to construct expressions out of @GOTOFF, @PLT and @GOT
46 symbols. The relocation type is stored in X_md. */
47 #define O_PIC_reloc O_md1
48
49 /* as.c. */
50 /* Extend GAS command line option handling capability. */
51 extern int nds32_parse_option (int, char *);
52 extern void nds32_after_parse_args (void);
53 /* The endianness of the target format may change based on command
54 line arguments. */
55 extern const char * nds32_target_format (void);
56
57 #define md_parse_option(optc, optarg) nds32_parse_option (optc, optarg)
58 #define md_after_parse_args() nds32_after_parse_args ()
59 #define TARGET_FORMAT nds32_target_format()
60
61 /* expr.c */
62 extern int nds32_parse_name (char const *, expressionS *, enum expr_mode, char *);
63 extern bfd_boolean nds32_allow_local_subtract (expressionS *, expressionS *, segT);
64 #define md_parse_name(name, exprP, mode, nextcharP) \
65 nds32_parse_name (name, exprP, mode, nextcharP)
66 #define md_allow_local_subtract(lhs,rhs,sect) nds32_allow_local_subtract (lhs, rhs, sect)
67
68 /* dwarf2dbg.c. */
69 #define DWARF2_USE_FIXED_ADVANCE_PC 1
70
71 /* write.c. */
72 extern long nds32_pcrel_from_section (struct fix *, segT);
73 extern bfd_boolean nds32_fix_adjustable (struct fix *);
74 extern void nds32_frob_file (void);
75 extern void nds32_post_relax_hook (void);
76 extern void nds32_frob_file_before_fix (void);
77 extern void elf_nds32_final_processing (void);
78 extern int nds32_validate_fix_sub (struct fix *, segT);
79 extern int nds32_force_relocation (struct fix *);
80 extern void nds32_set_section_relocs (asection *, arelent ** , unsigned int);
81
82 /* Fill in rs_align_code fragments. TODO: Review this. */
83 extern void nds32_handle_align (fragS *);
84 extern int nds32_relax_frag (segT, fragS *, long);
85 extern int tc_nds32_regname_to_dw2regnum (char *);
86 extern void tc_nds32_frame_initial_instructions (void);
87
88 #define MD_PCREL_FROM_SECTION(fix, sect) nds32_pcrel_from_section (fix, sect)
89 #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 0
90 #define tc_fix_adjustable(FIX) nds32_fix_adjustable (FIX)
91 #define md_apply_fix(fixP, addn, seg) nds32_apply_fix (fixP, addn, seg)
92 #define md_post_relax_hook nds32_post_relax_hook ()
93 #define tc_frob_file_before_fix() nds32_frob_file_before_fix ()
94 #define elf_tc_final_processing() elf_nds32_final_processing ()
95 /* For DIFF relocations. The default behavior is inconsistent with the
96 asm internal document. */
97 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEC) \
98 (! SEG_NORMAL (SEC) || TC_FORCE_RELOCATION (FIX))
99 #define TC_FORCE_RELOCATION(fix) nds32_force_relocation (fix)
100 #define TC_VALIDATE_FIX_SUB(FIX,SEG) nds32_validate_fix_sub (FIX,SEG)
101 #define SET_SECTION_RELOCS(sec, relocs, n) nds32_set_section_relocs (sec, relocs, n)
102 /* Values passed to md_apply_fix don't include the symbol value. */
103 #define MD_APPLY_SYM_VALUE(FIX) 0
104 #define HANDLE_ALIGN(f) nds32_handle_align (f)
105 #undef DIFF_EXPR_OK /* They should be fixed in linker. */
106 #define md_relax_frag(segment, fragP, stretch) nds32_relax_frag (segment, fragP, stretch)
107 #define WORKING_DOT_WORD /* We don't need to handle .word strangely. */
108 /* Using to chain fixup with previous fixup. */
109 #define TC_FIX_TYPE struct fix *
110 #define TC_INIT_FIX_DATA(fixP) \
111 do \
112 { \
113 fixP->tc_fix_data = NULL; \
114 } \
115 while (0)
116
117 /* read.c. */
118 /* Extend GAS macro handling capability. */
119 extern void nds32_macro_start (void);
120 extern void nds32_macro_end (void);
121 extern void nds32_macro_info (void *);
122 extern void nds32_start_line_hook (void);
123 extern void nds32_elf_section_change_hook (void);
124 extern void md_begin (void);
125 extern void md_end (void);
126 extern int nds32_start_label (int, int);
127 extern void nds32_cleanup (void);
128 extern void nds32_flush_pending_output (void);
129 extern void nds32_cons_align (int);
130 extern void nds32_check_label (symbolS *);
131 extern void nds32_frob_label (symbolS *);
132 extern void nds32_pre_do_align (int, char *, int, int);
133 extern void nds32_do_align (int);
134
135 #define md_macro_start() nds32_macro_start ()
136 #define md_macro_end() nds32_macro_end ()
137 #define md_macro_info(args) nds32_macro_info (args)
138 #define TC_START_LABEL(C, S, STR) (C == ':' && nds32_start_label (0, 0))
139 #define tc_check_label(label) nds32_check_label (label)
140 #define tc_frob_label(label) nds32_frob_label (label)
141 #define md_end md_end
142 #define md_start_line_hook() nds32_start_line_hook ()
143 #define md_cons_align(n) nds32_cons_align (n)
144 /* COLE: TODO: Review md_do_align. */
145 #define md_do_align(N, FILL, LEN, MAX, LABEL) \
146 nds32_pre_do_align (N, FILL, LEN, MAX); \
147 if ((N) > 1 && (subseg_text_p (now_seg) \
148 || strncmp (now_seg->name, ".gcc_except_table", sizeof(".gcc_except_table") - 1) == 0)) \
149 nds32_do_align (N); \
150 goto LABEL;
151 #define md_elf_section_change_hook() nds32_elf_section_change_hook ()
152 #define md_flush_pending_output() nds32_flush_pending_output ()
153 #define md_cleanup() nds32_cleanup ()
154 #define LOCAL_LABELS_FB 1 /* Permit temporary numeric labels. */
155
156 /* frags.c. */
157 struct nds32_frag_type
158 {
159 relax_substateT flag;
160 struct nds32_opcode *opcode;
161 uint32_t insn;
162 /* To Save previos label fixup if existence. */
163 struct fix *fixup;
164 };
165
166 extern void nds32_frag_init (fragS *);
167
168 #define TC_FRAG_TYPE struct nds32_frag_type
169 #define TC_FRAG_INIT(fragP) nds32_frag_init (fragP)
170
171 /* CFI directive. */
172 extern void nds32_elf_frame_initial_instructions (void);
173 extern int tc_nds32_regname_to_dw2regnum (char *);
174
175 #define TARGET_USE_CFIPOP 1
176 #define DWARF2_DEFAULT_RETURN_COLUMN 30
177 #define DWARF2_CIE_DATA_ALIGNMENT -4
178 #define DWARF2_LINE_MIN_INSN_LENGTH 2
179
180 #define tc_regname_to_dw2regnum tc_nds32_regname_to_dw2regnum
181 #define tc_cfi_frame_initial_instructions tc_nds32_frame_initial_instructions
182
183 /* COLE: TODO: Review These. They seem to be obsoleted. */
184 #if 1
185 #define TC_RELOC_RTSYM_LOC_FIXUP(FIX) \
186 ((FIX)->fx_addsy == NULL \
187 || (! S_IS_EXTERNAL ((FIX)->fx_addsy) \
188 && ! S_IS_WEAK ((FIX)->fx_addsy) \
189 && S_IS_DEFINED ((FIX)->fx_addsy) \
190 && ! S_IS_COMMON ((FIX)->fx_addsy)))
191 #define TC_HANDLES_FX_DONE
192 /* This arranges for gas/write.c to not apply a relocation if
193 obj_fix_adjustable() says it is not adjustable. */
194 #define TC_FIX_ADJUSTABLE(fixP) obj_fix_adjustable (fixP)
195 #endif
196
197 /* Because linker may relax the code, assemble-time expression
198 optimization is not allowed. */
199 #define md_allow_eh_opt 0
200
201 /* For nds32 relax. */
202 enum nds32_br_range
203 {
204 BR_RANGE_S256 = 0,
205 BR_RANGE_S16K,
206 BR_RANGE_S64K,
207 BR_RANGE_S16M,
208 BR_RANGE_U4G,
209 BR_RANGE_NUM
210 };
211
212 enum nds32_ramp
213 {
214 NDS32_CREATE_LABLE = 1,
215 NDS32_RELAX = 2,
216 NDS32_ORIGIN = 4,
217 NDS32_CONVERT = 8
218 };
219
220 typedef struct nds32_relax_fixup_info
221 {
222 int offset;
223 int size;
224 /* Reverse branch has to jump to the end of instruction pattern. */
225 int ramp;
226 enum bfd_reloc_code_real r_type;
227 } nds32_relax_fixup_info_t;
228
229 typedef struct nds32_cond_field
230 {
231 int offset;
232 int bitpos; /* Register position. */
233 int bitmask; /* Number of register bits. */
234 } nds32_cond_field_t;
235
236 /* The max relaxation pattern is 20-bytes including the nop. */
237 #define NDS32_MAXCHAR 20
238 /* In current, the max entend number of instruction for one pseudo instruction
239 is 4, but its number of relocation may be 5. */
240 #define MAX_RELAX_NUM 8
241
242 typedef struct nds32_relax_info
243 {
244 /* Opcode for the instruction. */
245 const char *opcode;
246 enum nds32_br_range br_range;
247 nds32_cond_field_t cond_field[MAX_RELAX_NUM]; /* TODO: Reuse nds32_field? */
248 /* Code sequences for different branch range. */
249 uint32_t relax_code_seq[BR_RANGE_NUM][MAX_RELAX_NUM];
250 nds32_cond_field_t relax_code_condition[BR_RANGE_NUM][MAX_RELAX_NUM];
251 int relax_code_size[BR_RANGE_NUM];
252 int relax_branch_isize[BR_RANGE_NUM];
253 nds32_relax_fixup_info_t relax_fixup[BR_RANGE_NUM][MAX_RELAX_NUM];
254 } relax_info_t;
255
256 /* Relocation table. */
257 struct nds32_relocation_map
258 {
259 unsigned int main_type;
260 /* Number of instructions, {relocations type, instruction type}. */
261 unsigned int reloc_insn[6][6][3];
262 };
263
264 #endif /* TC_NDS32 */
This page took 0.037488 seconds and 4 git commands to generate.