Commit | Line | Data |
---|---|---|
35c08157 | 1 | /* tc-nds32.h -- Header file for tc-nds32.c. |
2571583a | 2 | Copyright (C) 2012-2017 Free Software Foundation, Inc. |
35c08157 KLC |
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 | ||
35c08157 KLC |
45 | /* as.c. */ |
46 | /* Extend GAS command line option handling capability. */ | |
17b9d67d | 47 | extern int nds32_parse_option (int, const char *); |
35c08157 KLC |
48 | extern void nds32_after_parse_args (void); |
49 | /* The endianness of the target format may change based on command | |
50 | line arguments. */ | |
51 | extern const char * nds32_target_format (void); | |
52 | ||
53 | #define md_parse_option(optc, optarg) nds32_parse_option (optc, optarg) | |
54 | #define md_after_parse_args() nds32_after_parse_args () | |
55 | #define TARGET_FORMAT nds32_target_format() | |
56 | ||
57 | /* expr.c */ | |
58 | extern int nds32_parse_name (char const *, expressionS *, enum expr_mode, char *); | |
59 | extern bfd_boolean nds32_allow_local_subtract (expressionS *, expressionS *, segT); | |
60 | #define md_parse_name(name, exprP, mode, nextcharP) \ | |
61 | nds32_parse_name (name, exprP, mode, nextcharP) | |
62 | #define md_allow_local_subtract(lhs,rhs,sect) nds32_allow_local_subtract (lhs, rhs, sect) | |
63 | ||
64 | /* dwarf2dbg.c. */ | |
65 | #define DWARF2_USE_FIXED_ADVANCE_PC 1 | |
66 | ||
67 | /* write.c. */ | |
68 | extern long nds32_pcrel_from_section (struct fix *, segT); | |
69 | extern bfd_boolean nds32_fix_adjustable (struct fix *); | |
70 | extern void nds32_frob_file (void); | |
71 | extern void nds32_post_relax_hook (void); | |
72 | extern void nds32_frob_file_before_fix (void); | |
73 | extern void elf_nds32_final_processing (void); | |
74 | extern int nds32_validate_fix_sub (struct fix *, segT); | |
75 | extern int nds32_force_relocation (struct fix *); | |
76 | extern void nds32_set_section_relocs (asection *, arelent ** , unsigned int); | |
77 | ||
78 | /* Fill in rs_align_code fragments. TODO: Review this. */ | |
79 | extern void nds32_handle_align (fragS *); | |
80 | extern int nds32_relax_frag (segT, fragS *, long); | |
81 | extern int tc_nds32_regname_to_dw2regnum (char *); | |
82 | extern void tc_nds32_frame_initial_instructions (void); | |
83 | ||
84 | #define MD_PCREL_FROM_SECTION(fix, sect) nds32_pcrel_from_section (fix, sect) | |
85 | #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 0 | |
86 | #define tc_fix_adjustable(FIX) nds32_fix_adjustable (FIX) | |
87 | #define md_apply_fix(fixP, addn, seg) nds32_apply_fix (fixP, addn, seg) | |
88 | #define md_post_relax_hook nds32_post_relax_hook () | |
89 | #define tc_frob_file_before_fix() nds32_frob_file_before_fix () | |
90 | #define elf_tc_final_processing() elf_nds32_final_processing () | |
91 | /* For DIFF relocations. The default behavior is inconsistent with the | |
92 | asm internal document. */ | |
93 | #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEC) \ | |
94 | (! SEG_NORMAL (SEC) || TC_FORCE_RELOCATION (FIX)) | |
95 | #define TC_FORCE_RELOCATION(fix) nds32_force_relocation (fix) | |
96 | #define TC_VALIDATE_FIX_SUB(FIX,SEG) nds32_validate_fix_sub (FIX,SEG) | |
97 | #define SET_SECTION_RELOCS(sec, relocs, n) nds32_set_section_relocs (sec, relocs, n) | |
98 | /* Values passed to md_apply_fix don't include the symbol value. */ | |
99 | #define MD_APPLY_SYM_VALUE(FIX) 0 | |
100 | #define HANDLE_ALIGN(f) nds32_handle_align (f) | |
101 | #undef DIFF_EXPR_OK /* They should be fixed in linker. */ | |
102 | #define md_relax_frag(segment, fragP, stretch) nds32_relax_frag (segment, fragP, stretch) | |
103 | #define WORKING_DOT_WORD /* We don't need to handle .word strangely. */ | |
104 | /* Using to chain fixup with previous fixup. */ | |
105 | #define TC_FIX_TYPE struct fix * | |
106 | #define TC_INIT_FIX_DATA(fixP) \ | |
107 | do \ | |
108 | { \ | |
109 | fixP->tc_fix_data = NULL; \ | |
110 | } \ | |
111 | while (0) | |
112 | ||
113 | /* read.c. */ | |
114 | /* Extend GAS macro handling capability. */ | |
115 | extern void nds32_macro_start (void); | |
116 | extern void nds32_macro_end (void); | |
117 | extern void nds32_macro_info (void *); | |
118 | extern void nds32_start_line_hook (void); | |
119 | extern void nds32_elf_section_change_hook (void); | |
120 | extern void md_begin (void); | |
121 | extern void md_end (void); | |
122 | extern int nds32_start_label (int, int); | |
123 | extern void nds32_cleanup (void); | |
124 | extern void nds32_flush_pending_output (void); | |
125 | extern void nds32_cons_align (int); | |
126 | extern void nds32_check_label (symbolS *); | |
127 | extern void nds32_frob_label (symbolS *); | |
128 | extern void nds32_pre_do_align (int, char *, int, int); | |
129 | extern void nds32_do_align (int); | |
130 | ||
131 | #define md_macro_start() nds32_macro_start () | |
132 | #define md_macro_end() nds32_macro_end () | |
133 | #define md_macro_info(args) nds32_macro_info (args) | |
2e57ce7b AM |
134 | #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) \ |
135 | (NEXT_CHAR == ':' && nds32_start_label (0, 0)) | |
35c08157 KLC |
136 | #define tc_check_label(label) nds32_check_label (label) |
137 | #define tc_frob_label(label) nds32_frob_label (label) | |
138 | #define md_end md_end | |
139 | #define md_start_line_hook() nds32_start_line_hook () | |
140 | #define md_cons_align(n) nds32_cons_align (n) | |
141 | /* COLE: TODO: Review md_do_align. */ | |
142 | #define md_do_align(N, FILL, LEN, MAX, LABEL) \ | |
143 | nds32_pre_do_align (N, FILL, LEN, MAX); \ | |
144 | if ((N) > 1 && (subseg_text_p (now_seg) \ | |
145 | || strncmp (now_seg->name, ".gcc_except_table", sizeof(".gcc_except_table") - 1) == 0)) \ | |
146 | nds32_do_align (N); \ | |
147 | goto LABEL; | |
148 | #define md_elf_section_change_hook() nds32_elf_section_change_hook () | |
149 | #define md_flush_pending_output() nds32_flush_pending_output () | |
150 | #define md_cleanup() nds32_cleanup () | |
151 | #define LOCAL_LABELS_FB 1 /* Permit temporary numeric labels. */ | |
152 | ||
153 | /* frags.c. */ | |
1c8f6a4d | 154 | |
ea16498d KLC |
155 | enum FRAG_ATTR |
156 | { | |
157 | NDS32_FRAG_RELAXABLE = 0x1, | |
158 | NDS32_FRAG_RELAXED = 0x2, | |
159 | NDS32_FRAG_BRANCH = 0x4, | |
160 | NDS32_FRAG_LABEL = 0x8, | |
161 | NDS32_FRAG_FINAL = 0x10, | |
162 | NDS32_FRAG_RELAXABLE_BRANCH = 0x20, | |
163 | NDS32_FRAG_ALIGN = 0x40 | |
164 | }; | |
1c8f6a4d | 165 | |
35c08157 KLC |
166 | struct nds32_frag_type |
167 | { | |
168 | relax_substateT flag; | |
169 | struct nds32_opcode *opcode; | |
170 | uint32_t insn; | |
33eaf5de | 171 | /* To Save previous label fixup if existence. */ |
35c08157 KLC |
172 | struct fix *fixup; |
173 | }; | |
174 | ||
175 | extern void nds32_frag_init (fragS *); | |
176 | ||
177 | #define TC_FRAG_TYPE struct nds32_frag_type | |
178 | #define TC_FRAG_INIT(fragP) nds32_frag_init (fragP) | |
179 | ||
180 | /* CFI directive. */ | |
181 | extern void nds32_elf_frame_initial_instructions (void); | |
182 | extern int tc_nds32_regname_to_dw2regnum (char *); | |
183 | ||
184 | #define TARGET_USE_CFIPOP 1 | |
185 | #define DWARF2_DEFAULT_RETURN_COLUMN 30 | |
186 | #define DWARF2_CIE_DATA_ALIGNMENT -4 | |
187 | #define DWARF2_LINE_MIN_INSN_LENGTH 2 | |
188 | ||
189 | #define tc_regname_to_dw2regnum tc_nds32_regname_to_dw2regnum | |
190 | #define tc_cfi_frame_initial_instructions tc_nds32_frame_initial_instructions | |
191 | ||
192 | /* COLE: TODO: Review These. They seem to be obsoleted. */ | |
193 | #if 1 | |
194 | #define TC_RELOC_RTSYM_LOC_FIXUP(FIX) \ | |
195 | ((FIX)->fx_addsy == NULL \ | |
196 | || (! S_IS_EXTERNAL ((FIX)->fx_addsy) \ | |
197 | && ! S_IS_WEAK ((FIX)->fx_addsy) \ | |
198 | && S_IS_DEFINED ((FIX)->fx_addsy) \ | |
199 | && ! S_IS_COMMON ((FIX)->fx_addsy))) | |
200 | #define TC_HANDLES_FX_DONE | |
201 | /* This arranges for gas/write.c to not apply a relocation if | |
202 | obj_fix_adjustable() says it is not adjustable. */ | |
203 | #define TC_FIX_ADJUSTABLE(fixP) obj_fix_adjustable (fixP) | |
204 | #endif | |
205 | ||
206 | /* Because linker may relax the code, assemble-time expression | |
207 | optimization is not allowed. */ | |
208 | #define md_allow_eh_opt 0 | |
209 | ||
210 | /* For nds32 relax. */ | |
211 | enum nds32_br_range | |
212 | { | |
213 | BR_RANGE_S256 = 0, | |
214 | BR_RANGE_S16K, | |
215 | BR_RANGE_S64K, | |
216 | BR_RANGE_S16M, | |
217 | BR_RANGE_U4G, | |
218 | BR_RANGE_NUM | |
219 | }; | |
220 | ||
221 | enum nds32_ramp | |
222 | { | |
1c8f6a4d KLC |
223 | NDS32_CREATE_LABEL = 1, |
224 | NDS32_RELAX = (1 << 1), /* Obsolete in the future. */ | |
225 | NDS32_ORIGIN = (1 << 2), | |
226 | NDS32_INSN16 = (1 << 3), | |
227 | NDS32_PTR = (1 << 4), | |
228 | NDS32_ABS = (1 << 5), | |
229 | NDS32_HINT = (1 << 6), | |
230 | NDS32_FIX = (1 << 7), | |
231 | NDS32_ADDEND = (1 << 8), | |
ea16498d KLC |
232 | NDS32_SYM = (1 << 9), |
233 | NDS32_PCREL = (1 << 10) | |
35c08157 KLC |
234 | }; |
235 | ||
236 | typedef struct nds32_relax_fixup_info | |
237 | { | |
238 | int offset; | |
239 | int size; | |
240 | /* Reverse branch has to jump to the end of instruction pattern. */ | |
241 | int ramp; | |
242 | enum bfd_reloc_code_real r_type; | |
243 | } nds32_relax_fixup_info_t; | |
244 | ||
245 | typedef struct nds32_cond_field | |
246 | { | |
247 | int offset; | |
248 | int bitpos; /* Register position. */ | |
249 | int bitmask; /* Number of register bits. */ | |
1c8f6a4d | 250 | bfd_boolean signed_extend; |
35c08157 KLC |
251 | } nds32_cond_field_t; |
252 | ||
253 | /* The max relaxation pattern is 20-bytes including the nop. */ | |
254 | #define NDS32_MAXCHAR 20 | |
33eaf5de | 255 | /* In current, the max extended number of instruction for one pseudo instruction |
1c8f6a4d KLC |
256 | is 4, but its number of relocation may be 12. */ |
257 | #define MAX_RELAX_NUM 4 | |
258 | #define MAX_RELAX_FIX 12 | |
35c08157 KLC |
259 | |
260 | typedef struct nds32_relax_info | |
261 | { | |
262 | /* Opcode for the instruction. */ | |
263 | const char *opcode; | |
264 | enum nds32_br_range br_range; | |
265 | nds32_cond_field_t cond_field[MAX_RELAX_NUM]; /* TODO: Reuse nds32_field? */ | |
266 | /* Code sequences for different branch range. */ | |
267 | uint32_t relax_code_seq[BR_RANGE_NUM][MAX_RELAX_NUM]; | |
268 | nds32_cond_field_t relax_code_condition[BR_RANGE_NUM][MAX_RELAX_NUM]; | |
1c8f6a4d | 269 | unsigned int relax_code_size[BR_RANGE_NUM]; |
35c08157 | 270 | int relax_branch_isize[BR_RANGE_NUM]; |
1c8f6a4d | 271 | nds32_relax_fixup_info_t relax_fixup[BR_RANGE_NUM][MAX_RELAX_FIX]; |
35c08157 KLC |
272 | } relax_info_t; |
273 | ||
1c8f6a4d KLC |
274 | enum nds32_relax_hint_type |
275 | { | |
276 | NDS32_RELAX_HINT_NONE = 0, | |
277 | NDS32_RELAX_HINT_LA, | |
278 | NDS32_RELAX_HINT_LS | |
279 | }; | |
280 | ||
281 | struct nds32_relax_hint_table | |
35c08157 | 282 | { |
1c8f6a4d KLC |
283 | enum nds32_relax_hint_type main_type; |
284 | unsigned int relax_code_size; | |
285 | uint32_t relax_code_seq[MAX_RELAX_NUM]; | |
286 | nds32_relax_fixup_info_t relax_fixup[MAX_RELAX_FIX]; | |
35c08157 KLC |
287 | }; |
288 | ||
289 | #endif /* TC_NDS32 */ |