tc-bfin.c revision 1.1.1.3 1 1.1 skrll /* tc-bfin.c -- Assembler for the ADI Blackfin.
2 1.1.1.2 christos Copyright 2005, 2006, 2007, 2008, 2009, 2010
3 1.1 skrll Free Software Foundation, Inc.
4 1.1 skrll
5 1.1 skrll This file is part of GAS, the GNU Assembler.
6 1.1 skrll
7 1.1 skrll GAS is free software; you can redistribute it and/or modify
8 1.1 skrll it under the terms of the GNU General Public License as published by
9 1.1 skrll the Free Software Foundation; either version 3, or (at your option)
10 1.1 skrll any later version.
11 1.1 skrll
12 1.1 skrll GAS is distributed in the hope that it will be useful,
13 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 skrll GNU General Public License for more details.
16 1.1 skrll
17 1.1 skrll You should have received a copy of the GNU General Public License
18 1.1 skrll along with GAS; see the file COPYING. If not, write to the Free
19 1.1 skrll Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 1.1 skrll 02110-1301, USA. */
21 1.1 skrll
22 1.1 skrll #include "as.h"
23 1.1 skrll #include "struc-symbol.h"
24 1.1 skrll #include "bfin-defs.h"
25 1.1 skrll #include "obstack.h"
26 1.1 skrll #include "safe-ctype.h"
27 1.1 skrll #ifdef OBJ_ELF
28 1.1 skrll #include "dwarf2dbg.h"
29 1.1 skrll #endif
30 1.1 skrll #include "libbfd.h"
31 1.1 skrll #include "elf/common.h"
32 1.1 skrll #include "elf/bfin.h"
33 1.1 skrll
34 1.1 skrll extern int yyparse (void);
35 1.1 skrll struct yy_buffer_state;
36 1.1 skrll typedef struct yy_buffer_state *YY_BUFFER_STATE;
37 1.1 skrll extern YY_BUFFER_STATE yy_scan_string (const char *yy_str);
38 1.1 skrll extern void yy_delete_buffer (YY_BUFFER_STATE b);
39 1.1 skrll static parse_state parse (char *line);
40 1.1 skrll
41 1.1 skrll /* Global variables. */
42 1.1 skrll struct bfin_insn *insn;
43 1.1 skrll int last_insn_size;
44 1.1 skrll
45 1.1 skrll extern struct obstack mempool;
46 1.1 skrll FILE *errorf;
47 1.1 skrll
48 1.1 skrll /* Flags to set in the elf header */
49 1.1 skrll #define DEFAULT_FLAGS 0
50 1.1 skrll
51 1.1 skrll #ifdef OBJ_FDPIC_ELF
52 1.1 skrll # define DEFAULT_FDPIC EF_BFIN_FDPIC
53 1.1 skrll #else
54 1.1 skrll # define DEFAULT_FDPIC 0
55 1.1 skrll #endif
56 1.1 skrll
57 1.1 skrll static flagword bfin_flags = DEFAULT_FLAGS | DEFAULT_FDPIC;
58 1.1 skrll static const char *bfin_pic_flag = DEFAULT_FDPIC ? "-mfdpic" : (const char *)0;
59 1.1 skrll
60 1.1 skrll /* Blackfin specific function to handle FD-PIC pointer initializations. */
61 1.1 skrll
62 1.1 skrll static void
63 1.1 skrll bfin_pic_ptr (int nbytes)
64 1.1 skrll {
65 1.1 skrll expressionS exp;
66 1.1 skrll char *p;
67 1.1 skrll
68 1.1 skrll if (nbytes != 4)
69 1.1 skrll abort ();
70 1.1 skrll
71 1.1 skrll #ifdef md_flush_pending_output
72 1.1 skrll md_flush_pending_output ();
73 1.1 skrll #endif
74 1.1 skrll
75 1.1 skrll if (is_it_end_of_statement ())
76 1.1 skrll {
77 1.1 skrll demand_empty_rest_of_line ();
78 1.1 skrll return;
79 1.1 skrll }
80 1.1 skrll
81 1.1 skrll #ifdef md_cons_align
82 1.1 skrll md_cons_align (nbytes);
83 1.1 skrll #endif
84 1.1 skrll
85 1.1 skrll do
86 1.1 skrll {
87 1.1 skrll bfd_reloc_code_real_type reloc_type = BFD_RELOC_BFIN_FUNCDESC;
88 1.1.1.2 christos
89 1.1 skrll if (strncasecmp (input_line_pointer, "funcdesc(", 9) == 0)
90 1.1 skrll {
91 1.1 skrll input_line_pointer += 9;
92 1.1 skrll expression (&exp);
93 1.1 skrll if (*input_line_pointer == ')')
94 1.1 skrll input_line_pointer++;
95 1.1 skrll else
96 1.1 skrll as_bad (_("missing ')'"));
97 1.1 skrll }
98 1.1 skrll else
99 1.1 skrll error ("missing funcdesc in picptr");
100 1.1 skrll
101 1.1 skrll p = frag_more (4);
102 1.1 skrll memset (p, 0, 4);
103 1.1 skrll fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
104 1.1 skrll reloc_type);
105 1.1 skrll }
106 1.1 skrll while (*input_line_pointer++ == ',');
107 1.1 skrll
108 1.1 skrll input_line_pointer--; /* Put terminator back into stream. */
109 1.1 skrll demand_empty_rest_of_line ();
110 1.1 skrll }
111 1.1 skrll
112 1.1 skrll static void
113 1.1 skrll bfin_s_bss (int ignore ATTRIBUTE_UNUSED)
114 1.1 skrll {
115 1.1 skrll register int temp;
116 1.1 skrll
117 1.1 skrll temp = get_absolute_expression ();
118 1.1 skrll subseg_set (bss_section, (subsegT) temp);
119 1.1 skrll demand_empty_rest_of_line ();
120 1.1 skrll }
121 1.1 skrll
122 1.1 skrll const pseudo_typeS md_pseudo_table[] = {
123 1.1 skrll {"align", s_align_bytes, 0},
124 1.1 skrll {"byte2", cons, 2},
125 1.1 skrll {"byte4", cons, 4},
126 1.1 skrll {"picptr", bfin_pic_ptr, 4},
127 1.1 skrll {"code", obj_elf_section, 0},
128 1.1 skrll {"db", cons, 1},
129 1.1 skrll {"dd", cons, 4},
130 1.1 skrll {"dw", cons, 2},
131 1.1 skrll {"p", s_ignore, 0},
132 1.1 skrll {"pdata", s_ignore, 0},
133 1.1 skrll {"var", s_ignore, 0},
134 1.1 skrll {"bss", bfin_s_bss, 0},
135 1.1 skrll {0, 0, 0}
136 1.1 skrll };
137 1.1 skrll
138 1.1 skrll /* Characters that are used to denote comments and line separators. */
139 1.1.1.2 christos const char comment_chars[] = "#";
140 1.1 skrll const char line_comment_chars[] = "#";
141 1.1 skrll const char line_separator_chars[] = ";";
142 1.1 skrll
143 1.1 skrll /* Characters that can be used to separate the mantissa from the
144 1.1 skrll exponent in floating point numbers. */
145 1.1 skrll const char EXP_CHARS[] = "eE";
146 1.1 skrll
147 1.1 skrll /* Characters that mean this number is a floating point constant.
148 1.1 skrll As in 0f12.456 or 0d1.2345e12. */
149 1.1 skrll const char FLT_CHARS[] = "fFdDxX";
150 1.1 skrll
151 1.1.1.2 christos typedef enum bfin_cpu_type
152 1.1.1.2 christos {
153 1.1.1.2 christos BFIN_CPU_UNKNOWN,
154 1.1.1.2 christos BFIN_CPU_BF504,
155 1.1.1.2 christos BFIN_CPU_BF506,
156 1.1.1.2 christos BFIN_CPU_BF512,
157 1.1.1.2 christos BFIN_CPU_BF514,
158 1.1.1.2 christos BFIN_CPU_BF516,
159 1.1.1.2 christos BFIN_CPU_BF518,
160 1.1.1.2 christos BFIN_CPU_BF522,
161 1.1.1.2 christos BFIN_CPU_BF523,
162 1.1.1.2 christos BFIN_CPU_BF524,
163 1.1.1.2 christos BFIN_CPU_BF525,
164 1.1.1.2 christos BFIN_CPU_BF526,
165 1.1.1.2 christos BFIN_CPU_BF527,
166 1.1.1.2 christos BFIN_CPU_BF531,
167 1.1.1.2 christos BFIN_CPU_BF532,
168 1.1.1.2 christos BFIN_CPU_BF533,
169 1.1.1.2 christos BFIN_CPU_BF534,
170 1.1.1.2 christos BFIN_CPU_BF536,
171 1.1.1.2 christos BFIN_CPU_BF537,
172 1.1.1.2 christos BFIN_CPU_BF538,
173 1.1.1.2 christos BFIN_CPU_BF539,
174 1.1.1.2 christos BFIN_CPU_BF542,
175 1.1.1.2 christos BFIN_CPU_BF542M,
176 1.1.1.2 christos BFIN_CPU_BF544,
177 1.1.1.2 christos BFIN_CPU_BF544M,
178 1.1.1.2 christos BFIN_CPU_BF547,
179 1.1.1.2 christos BFIN_CPU_BF547M,
180 1.1.1.2 christos BFIN_CPU_BF548,
181 1.1.1.2 christos BFIN_CPU_BF548M,
182 1.1.1.2 christos BFIN_CPU_BF549,
183 1.1.1.2 christos BFIN_CPU_BF549M,
184 1.1.1.2 christos BFIN_CPU_BF561,
185 1.1.1.2 christos BFIN_CPU_BF592,
186 1.1.1.2 christos } bfin_cpu_t;
187 1.1.1.2 christos
188 1.1.1.2 christos bfin_cpu_t bfin_cpu_type = BFIN_CPU_UNKNOWN;
189 1.1.1.2 christos /* -msi-revision support. There are three special values:
190 1.1.1.2 christos -1 -msi-revision=none.
191 1.1.1.2 christos 0xffff -msi-revision=any. */
192 1.1.1.2 christos int bfin_si_revision;
193 1.1.1.2 christos
194 1.1.1.2 christos unsigned int bfin_anomaly_checks = 0;
195 1.1.1.2 christos
196 1.1.1.2 christos struct bfin_cpu
197 1.1.1.2 christos {
198 1.1.1.2 christos const char *name;
199 1.1.1.2 christos bfin_cpu_t type;
200 1.1.1.2 christos int si_revision;
201 1.1.1.2 christos unsigned int anomaly_checks;
202 1.1.1.2 christos };
203 1.1.1.2 christos
204 1.1.1.2 christos struct bfin_cpu bfin_cpus[] =
205 1.1.1.2 christos {
206 1.1.1.2 christos {"bf504", BFIN_CPU_BF504, 0x0000, AC_05000074},
207 1.1.1.2 christos
208 1.1.1.2 christos {"bf506", BFIN_CPU_BF506, 0x0000, AC_05000074},
209 1.1.1.2 christos
210 1.1.1.2 christos {"bf512", BFIN_CPU_BF512, 0x0002, AC_05000074},
211 1.1.1.2 christos {"bf512", BFIN_CPU_BF512, 0x0001, AC_05000074},
212 1.1.1.2 christos {"bf512", BFIN_CPU_BF512, 0x0000, AC_05000074},
213 1.1.1.2 christos
214 1.1.1.2 christos {"bf514", BFIN_CPU_BF514, 0x0002, AC_05000074},
215 1.1.1.2 christos {"bf514", BFIN_CPU_BF514, 0x0001, AC_05000074},
216 1.1.1.2 christos {"bf514", BFIN_CPU_BF514, 0x0000, AC_05000074},
217 1.1.1.2 christos
218 1.1.1.2 christos {"bf516", BFIN_CPU_BF516, 0x0002, AC_05000074},
219 1.1.1.2 christos {"bf516", BFIN_CPU_BF516, 0x0001, AC_05000074},
220 1.1.1.2 christos {"bf516", BFIN_CPU_BF516, 0x0000, AC_05000074},
221 1.1.1.2 christos
222 1.1.1.2 christos {"bf518", BFIN_CPU_BF518, 0x0002, AC_05000074},
223 1.1.1.2 christos {"bf518", BFIN_CPU_BF518, 0x0001, AC_05000074},
224 1.1.1.2 christos {"bf518", BFIN_CPU_BF518, 0x0000, AC_05000074},
225 1.1.1.2 christos
226 1.1.1.2 christos {"bf522", BFIN_CPU_BF522, 0x0002, AC_05000074},
227 1.1.1.2 christos {"bf522", BFIN_CPU_BF522, 0x0001, AC_05000074},
228 1.1.1.2 christos {"bf522", BFIN_CPU_BF522, 0x0000, AC_05000074},
229 1.1.1.2 christos
230 1.1.1.2 christos {"bf523", BFIN_CPU_BF523, 0x0002, AC_05000074},
231 1.1.1.2 christos {"bf523", BFIN_CPU_BF523, 0x0001, AC_05000074},
232 1.1.1.2 christos {"bf523", BFIN_CPU_BF523, 0x0000, AC_05000074},
233 1.1.1.2 christos
234 1.1.1.2 christos {"bf524", BFIN_CPU_BF524, 0x0002, AC_05000074},
235 1.1.1.2 christos {"bf524", BFIN_CPU_BF524, 0x0001, AC_05000074},
236 1.1.1.2 christos {"bf524", BFIN_CPU_BF524, 0x0000, AC_05000074},
237 1.1.1.2 christos
238 1.1.1.2 christos {"bf525", BFIN_CPU_BF525, 0x0002, AC_05000074},
239 1.1.1.2 christos {"bf525", BFIN_CPU_BF525, 0x0001, AC_05000074},
240 1.1.1.2 christos {"bf525", BFIN_CPU_BF525, 0x0000, AC_05000074},
241 1.1.1.2 christos
242 1.1.1.2 christos {"bf526", BFIN_CPU_BF526, 0x0002, AC_05000074},
243 1.1.1.2 christos {"bf526", BFIN_CPU_BF526, 0x0001, AC_05000074},
244 1.1.1.2 christos {"bf526", BFIN_CPU_BF526, 0x0000, AC_05000074},
245 1.1.1.2 christos
246 1.1.1.2 christos {"bf527", BFIN_CPU_BF527, 0x0002, AC_05000074},
247 1.1.1.2 christos {"bf527", BFIN_CPU_BF527, 0x0001, AC_05000074},
248 1.1.1.2 christos {"bf527", BFIN_CPU_BF527, 0x0000, AC_05000074},
249 1.1.1.2 christos
250 1.1.1.2 christos {"bf531", BFIN_CPU_BF531, 0x0006, AC_05000074},
251 1.1.1.2 christos {"bf531", BFIN_CPU_BF531, 0x0005, AC_05000074},
252 1.1.1.2 christos {"bf531", BFIN_CPU_BF531, 0x0004, AC_05000074},
253 1.1.1.2 christos {"bf531", BFIN_CPU_BF531, 0x0003, AC_05000074},
254 1.1.1.2 christos
255 1.1.1.2 christos {"bf532", BFIN_CPU_BF532, 0x0006, AC_05000074},
256 1.1.1.2 christos {"bf532", BFIN_CPU_BF532, 0x0005, AC_05000074},
257 1.1.1.2 christos {"bf532", BFIN_CPU_BF532, 0x0004, AC_05000074},
258 1.1.1.2 christos {"bf532", BFIN_CPU_BF532, 0x0003, AC_05000074},
259 1.1.1.2 christos
260 1.1.1.2 christos {"bf533", BFIN_CPU_BF533, 0x0006, AC_05000074},
261 1.1.1.2 christos {"bf533", BFIN_CPU_BF533, 0x0005, AC_05000074},
262 1.1.1.2 christos {"bf533", BFIN_CPU_BF533, 0x0004, AC_05000074},
263 1.1.1.2 christos {"bf533", BFIN_CPU_BF533, 0x0003, AC_05000074},
264 1.1.1.2 christos
265 1.1.1.2 christos {"bf534", BFIN_CPU_BF534, 0x0003, AC_05000074},
266 1.1.1.2 christos {"bf534", BFIN_CPU_BF534, 0x0002, AC_05000074},
267 1.1.1.2 christos {"bf534", BFIN_CPU_BF534, 0x0001, AC_05000074},
268 1.1.1.2 christos
269 1.1.1.2 christos {"bf536", BFIN_CPU_BF536, 0x0003, AC_05000074},
270 1.1.1.2 christos {"bf536", BFIN_CPU_BF536, 0x0002, AC_05000074},
271 1.1.1.2 christos {"bf536", BFIN_CPU_BF536, 0x0001, AC_05000074},
272 1.1.1.2 christos
273 1.1.1.2 christos {"bf537", BFIN_CPU_BF537, 0x0003, AC_05000074},
274 1.1.1.2 christos {"bf537", BFIN_CPU_BF537, 0x0002, AC_05000074},
275 1.1.1.2 christos {"bf537", BFIN_CPU_BF537, 0x0001, AC_05000074},
276 1.1.1.2 christos
277 1.1.1.2 christos {"bf538", BFIN_CPU_BF538, 0x0005, AC_05000074},
278 1.1.1.2 christos {"bf538", BFIN_CPU_BF538, 0x0004, AC_05000074},
279 1.1.1.2 christos {"bf538", BFIN_CPU_BF538, 0x0003, AC_05000074},
280 1.1.1.2 christos {"bf538", BFIN_CPU_BF538, 0x0002, AC_05000074},
281 1.1.1.2 christos
282 1.1.1.2 christos {"bf539", BFIN_CPU_BF539, 0x0005, AC_05000074},
283 1.1.1.2 christos {"bf539", BFIN_CPU_BF539, 0x0004, AC_05000074},
284 1.1.1.2 christos {"bf539", BFIN_CPU_BF539, 0x0003, AC_05000074},
285 1.1.1.2 christos {"bf539", BFIN_CPU_BF539, 0x0002, AC_05000074},
286 1.1.1.2 christos
287 1.1.1.2 christos {"bf542m", BFIN_CPU_BF542M, 0x0003, AC_05000074},
288 1.1.1.2 christos
289 1.1.1.3 christos {"bf542", BFIN_CPU_BF542, 0x0004, AC_05000074},
290 1.1.1.2 christos {"bf542", BFIN_CPU_BF542, 0x0002, AC_05000074},
291 1.1.1.2 christos {"bf542", BFIN_CPU_BF542, 0x0001, AC_05000074},
292 1.1.1.2 christos {"bf542", BFIN_CPU_BF542, 0x0000, AC_05000074},
293 1.1.1.2 christos
294 1.1.1.2 christos {"bf544m", BFIN_CPU_BF544M, 0x0003, AC_05000074},
295 1.1.1.2 christos
296 1.1.1.3 christos {"bf544", BFIN_CPU_BF544, 0x0004, AC_05000074},
297 1.1.1.2 christos {"bf544", BFIN_CPU_BF544, 0x0002, AC_05000074},
298 1.1.1.2 christos {"bf544", BFIN_CPU_BF544, 0x0001, AC_05000074},
299 1.1.1.2 christos {"bf544", BFIN_CPU_BF544, 0x0000, AC_05000074},
300 1.1.1.2 christos
301 1.1.1.2 christos {"bf547m", BFIN_CPU_BF547M, 0x0003, AC_05000074},
302 1.1.1.2 christos
303 1.1.1.3 christos {"bf547", BFIN_CPU_BF547, 0x0004, AC_05000074},
304 1.1.1.2 christos {"bf547", BFIN_CPU_BF547, 0x0002, AC_05000074},
305 1.1.1.2 christos {"bf547", BFIN_CPU_BF547, 0x0001, AC_05000074},
306 1.1.1.2 christos {"bf547", BFIN_CPU_BF547, 0x0000, AC_05000074},
307 1.1.1.2 christos
308 1.1.1.2 christos {"bf548m", BFIN_CPU_BF548M, 0x0003, AC_05000074},
309 1.1.1.2 christos
310 1.1.1.3 christos {"bf548", BFIN_CPU_BF548, 0x0004, AC_05000074},
311 1.1.1.2 christos {"bf548", BFIN_CPU_BF548, 0x0002, AC_05000074},
312 1.1.1.2 christos {"bf548", BFIN_CPU_BF548, 0x0001, AC_05000074},
313 1.1.1.2 christos {"bf548", BFIN_CPU_BF548, 0x0000, AC_05000074},
314 1.1.1.2 christos
315 1.1.1.2 christos {"bf549m", BFIN_CPU_BF549M, 0x0003, AC_05000074},
316 1.1.1.2 christos
317 1.1.1.3 christos {"bf549", BFIN_CPU_BF549, 0x0004, AC_05000074},
318 1.1.1.2 christos {"bf549", BFIN_CPU_BF549, 0x0002, AC_05000074},
319 1.1.1.2 christos {"bf549", BFIN_CPU_BF549, 0x0001, AC_05000074},
320 1.1.1.2 christos {"bf549", BFIN_CPU_BF549, 0x0000, AC_05000074},
321 1.1.1.2 christos
322 1.1.1.2 christos {"bf561", BFIN_CPU_BF561, 0x0005, AC_05000074},
323 1.1.1.2 christos {"bf561", BFIN_CPU_BF561, 0x0003, AC_05000074},
324 1.1.1.2 christos {"bf561", BFIN_CPU_BF561, 0x0002, AC_05000074},
325 1.1.1.2 christos
326 1.1.1.2 christos {"bf592", BFIN_CPU_BF592, 0x0001, AC_05000074},
327 1.1.1.2 christos {"bf592", BFIN_CPU_BF592, 0x0000, AC_05000074},
328 1.1.1.2 christos
329 1.1.1.2 christos {NULL, 0, 0, 0}
330 1.1.1.2 christos };
331 1.1.1.2 christos
332 1.1 skrll /* Define bfin-specific command-line options (there are none). */
333 1.1 skrll const char *md_shortopts = "";
334 1.1 skrll
335 1.1 skrll #define OPTION_FDPIC (OPTION_MD_BASE)
336 1.1 skrll #define OPTION_NOPIC (OPTION_MD_BASE + 1)
337 1.1.1.2 christos #define OPTION_MCPU (OPTION_MD_BASE + 2)
338 1.1 skrll
339 1.1 skrll struct option md_longopts[] =
340 1.1 skrll {
341 1.1.1.2 christos { "mcpu", required_argument, NULL, OPTION_MCPU },
342 1.1 skrll { "mfdpic", no_argument, NULL, OPTION_FDPIC },
343 1.1 skrll { "mnopic", no_argument, NULL, OPTION_NOPIC },
344 1.1 skrll { "mno-fdpic", no_argument, NULL, OPTION_NOPIC },
345 1.1 skrll { NULL, no_argument, NULL, 0 },
346 1.1 skrll };
347 1.1 skrll
348 1.1 skrll size_t md_longopts_size = sizeof (md_longopts);
349 1.1 skrll
350 1.1 skrll
351 1.1 skrll int
352 1.1 skrll md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
353 1.1 skrll {
354 1.1 skrll switch (c)
355 1.1 skrll {
356 1.1 skrll default:
357 1.1 skrll return 0;
358 1.1 skrll
359 1.1.1.2 christos case OPTION_MCPU:
360 1.1.1.2 christos {
361 1.1.1.2 christos const char *p, *q;
362 1.1.1.2 christos int i;
363 1.1.1.2 christos
364 1.1.1.2 christos i = 0;
365 1.1.1.2 christos while ((p = bfin_cpus[i].name) != NULL)
366 1.1.1.2 christos {
367 1.1.1.2 christos if (strncmp (arg, p, strlen (p)) == 0)
368 1.1.1.2 christos break;
369 1.1.1.2 christos i++;
370 1.1.1.2 christos }
371 1.1.1.2 christos
372 1.1.1.2 christos if (p == NULL)
373 1.1.1.2 christos as_fatal ("-mcpu=%s is not valid", arg);
374 1.1.1.2 christos
375 1.1.1.2 christos bfin_cpu_type = bfin_cpus[i].type;
376 1.1.1.2 christos
377 1.1.1.2 christos q = arg + strlen (p);
378 1.1.1.2 christos
379 1.1.1.2 christos if (*q == '\0')
380 1.1.1.2 christos {
381 1.1.1.2 christos bfin_si_revision = bfin_cpus[i].si_revision;
382 1.1.1.2 christos bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
383 1.1.1.2 christos }
384 1.1.1.2 christos else if (strcmp (q, "-none") == 0)
385 1.1.1.2 christos bfin_si_revision = -1;
386 1.1.1.2 christos else if (strcmp (q, "-any") == 0)
387 1.1.1.2 christos {
388 1.1.1.2 christos bfin_si_revision = 0xffff;
389 1.1.1.2 christos while (bfin_cpus[i].type == bfin_cpu_type)
390 1.1.1.2 christos {
391 1.1.1.2 christos bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
392 1.1.1.2 christos i++;
393 1.1.1.2 christos }
394 1.1.1.2 christos }
395 1.1.1.2 christos else
396 1.1.1.2 christos {
397 1.1.1.2 christos unsigned int si_major, si_minor;
398 1.1.1.2 christos int rev_len, n;
399 1.1.1.2 christos
400 1.1.1.2 christos rev_len = strlen (q);
401 1.1.1.2 christos
402 1.1.1.2 christos if (sscanf (q, "-%u.%u%n", &si_major, &si_minor, &n) != 2
403 1.1.1.2 christos || n != rev_len
404 1.1.1.2 christos || si_major > 0xff || si_minor > 0xff)
405 1.1.1.2 christos {
406 1.1.1.2 christos invalid_silicon_revision:
407 1.1.1.2 christos as_fatal ("-mcpu=%s has invalid silicon revision", arg);
408 1.1.1.2 christos }
409 1.1.1.2 christos
410 1.1.1.2 christos bfin_si_revision = (si_major << 8) | si_minor;
411 1.1.1.2 christos
412 1.1.1.2 christos while (bfin_cpus[i].type == bfin_cpu_type
413 1.1.1.2 christos && bfin_cpus[i].si_revision != bfin_si_revision)
414 1.1.1.2 christos i++;
415 1.1.1.2 christos
416 1.1.1.2 christos if (bfin_cpus[i].type != bfin_cpu_type)
417 1.1.1.2 christos goto invalid_silicon_revision;
418 1.1.1.2 christos
419 1.1.1.2 christos bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
420 1.1.1.2 christos }
421 1.1.1.2 christos
422 1.1.1.2 christos break;
423 1.1.1.2 christos }
424 1.1.1.2 christos
425 1.1 skrll case OPTION_FDPIC:
426 1.1 skrll bfin_flags |= EF_BFIN_FDPIC;
427 1.1 skrll bfin_pic_flag = "-mfdpic";
428 1.1 skrll break;
429 1.1 skrll
430 1.1 skrll case OPTION_NOPIC:
431 1.1 skrll bfin_flags &= ~(EF_BFIN_FDPIC);
432 1.1 skrll bfin_pic_flag = 0;
433 1.1 skrll break;
434 1.1 skrll }
435 1.1 skrll
436 1.1 skrll return 1;
437 1.1 skrll }
438 1.1 skrll
439 1.1 skrll void
440 1.1.1.2 christos md_show_usage (FILE * stream)
441 1.1 skrll {
442 1.1.1.2 christos fprintf (stream, _(" Blackfin specific assembler options:\n"));
443 1.1.1.2 christos fprintf (stream, _(" -mcpu=<cpu[-sirevision]> specify the name of the target CPU\n"));
444 1.1.1.2 christos fprintf (stream, _(" -mfdpic assemble for the FDPIC ABI\n"));
445 1.1.1.2 christos fprintf (stream, _(" -mno-fdpic/-mnopic disable -mfdpic\n"));
446 1.1 skrll }
447 1.1 skrll
448 1.1 skrll /* Perform machine-specific initializations. */
449 1.1 skrll void
450 1.1 skrll md_begin ()
451 1.1 skrll {
452 1.1 skrll /* Set the ELF flags if desired. */
453 1.1 skrll if (bfin_flags)
454 1.1 skrll bfd_set_private_flags (stdoutput, bfin_flags);
455 1.1 skrll
456 1.1 skrll /* Set the default machine type. */
457 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_bfin, 0))
458 1.1 skrll as_warn (_("Could not set architecture and machine."));
459 1.1 skrll
460 1.1 skrll /* Ensure that lines can begin with '(', for multiple
461 1.1 skrll register stack pops. */
462 1.1 skrll lex_type ['('] = LEX_BEGIN_NAME;
463 1.1.1.2 christos
464 1.1 skrll #ifdef OBJ_ELF
465 1.1 skrll record_alignment (text_section, 2);
466 1.1 skrll record_alignment (data_section, 2);
467 1.1 skrll record_alignment (bss_section, 2);
468 1.1 skrll #endif
469 1.1 skrll
470 1.1 skrll errorf = stderr;
471 1.1 skrll obstack_init (&mempool);
472 1.1 skrll
473 1.1 skrll #ifdef DEBUG
474 1.1 skrll extern int debug_codeselection;
475 1.1 skrll debug_codeselection = 1;
476 1.1.1.2 christos #endif
477 1.1 skrll
478 1.1 skrll last_insn_size = 0;
479 1.1 skrll }
480 1.1 skrll
481 1.1 skrll /* Perform the main parsing, and assembly of the input here. Also,
482 1.1 skrll call the required routines for alignment and fixups here.
483 1.1 skrll This is called for every line that contains real assembly code. */
484 1.1 skrll
485 1.1 skrll void
486 1.1 skrll md_assemble (char *line)
487 1.1 skrll {
488 1.1 skrll char *toP = 0;
489 1.1 skrll extern char *current_inputline;
490 1.1 skrll int size, insn_size;
491 1.1 skrll struct bfin_insn *tmp_insn;
492 1.1 skrll size_t len;
493 1.1 skrll static size_t buffer_len = 0;
494 1.1 skrll parse_state state;
495 1.1 skrll
496 1.1 skrll len = strlen (line);
497 1.1 skrll if (len + 2 > buffer_len)
498 1.1 skrll {
499 1.1 skrll if (buffer_len > 0)
500 1.1 skrll free (current_inputline);
501 1.1 skrll buffer_len = len + 40;
502 1.1 skrll current_inputline = xmalloc (buffer_len);
503 1.1 skrll }
504 1.1 skrll memcpy (current_inputline, line, len);
505 1.1 skrll current_inputline[len] = ';';
506 1.1 skrll current_inputline[len + 1] = '\0';
507 1.1 skrll
508 1.1 skrll state = parse (current_inputline);
509 1.1 skrll if (state == NO_INSN_GENERATED)
510 1.1 skrll return;
511 1.1 skrll
512 1.1 skrll for (insn_size = 0, tmp_insn = insn; tmp_insn; tmp_insn = tmp_insn->next)
513 1.1 skrll if (!tmp_insn->reloc || !tmp_insn->exp->symbol)
514 1.1 skrll insn_size += 2;
515 1.1 skrll
516 1.1 skrll if (insn_size)
517 1.1 skrll toP = frag_more (insn_size);
518 1.1 skrll
519 1.1 skrll last_insn_size = insn_size;
520 1.1 skrll
521 1.1 skrll #ifdef DEBUG
522 1.1 skrll printf ("INS:");
523 1.1 skrll #endif
524 1.1 skrll while (insn)
525 1.1 skrll {
526 1.1 skrll if (insn->reloc && insn->exp->symbol)
527 1.1 skrll {
528 1.1 skrll char *prev_toP = toP - 2;
529 1.1 skrll switch (insn->reloc)
530 1.1 skrll {
531 1.1 skrll case BFD_RELOC_BFIN_24_PCREL_JUMP_L:
532 1.1 skrll case BFD_RELOC_24_PCREL:
533 1.1 skrll case BFD_RELOC_BFIN_16_LOW:
534 1.1 skrll case BFD_RELOC_BFIN_16_HIGH:
535 1.1 skrll size = 4;
536 1.1 skrll break;
537 1.1 skrll default:
538 1.1 skrll size = 2;
539 1.1 skrll }
540 1.1 skrll
541 1.1 skrll /* Following if condition checks for the arithmetic relocations.
542 1.1 skrll If the case then it doesn't required to generate the code.
543 1.1 skrll It has been assumed that, their ID will be contiguous. */
544 1.1 skrll if ((BFD_ARELOC_BFIN_PUSH <= insn->reloc
545 1.1 skrll && BFD_ARELOC_BFIN_COMP >= insn->reloc)
546 1.1 skrll || insn->reloc == BFD_RELOC_BFIN_16_IMM)
547 1.1 skrll {
548 1.1 skrll size = 2;
549 1.1 skrll }
550 1.1 skrll if (insn->reloc == BFD_ARELOC_BFIN_CONST
551 1.1 skrll || insn->reloc == BFD_ARELOC_BFIN_PUSH)
552 1.1 skrll size = 4;
553 1.1 skrll
554 1.1 skrll fix_new (frag_now,
555 1.1 skrll (prev_toP - frag_now->fr_literal),
556 1.1 skrll size, insn->exp->symbol, insn->exp->value,
557 1.1 skrll insn->pcrel, insn->reloc);
558 1.1 skrll }
559 1.1 skrll else
560 1.1 skrll {
561 1.1 skrll md_number_to_chars (toP, insn->value, 2);
562 1.1 skrll toP += 2;
563 1.1 skrll }
564 1.1 skrll
565 1.1 skrll #ifdef DEBUG
566 1.1 skrll printf (" reloc :");
567 1.1 skrll printf (" %02x%02x", ((unsigned char *) &insn->value)[0],
568 1.1 skrll ((unsigned char *) &insn->value)[1]);
569 1.1 skrll printf ("\n");
570 1.1 skrll #endif
571 1.1 skrll insn = insn->next;
572 1.1 skrll }
573 1.1 skrll #ifdef OBJ_ELF
574 1.1 skrll dwarf2_emit_insn (insn_size);
575 1.1 skrll #endif
576 1.1.1.2 christos
577 1.1.1.2 christos while (*line++ != '\0')
578 1.1.1.2 christos if (*line == '\n')
579 1.1.1.2 christos bump_line_counters ();
580 1.1 skrll }
581 1.1 skrll
582 1.1 skrll /* Parse one line of instructions, and generate opcode for it.
583 1.1 skrll To parse the line, YACC and LEX are used, because the instruction set
584 1.1 skrll syntax doesn't confirm to the AT&T assembly syntax.
585 1.1 skrll To call a YACC & LEX generated parser, we must provide the input via
586 1.1 skrll a FILE stream, otherwise stdin is used by default. Below the input
587 1.1 skrll to the function will be put into a temporary file, then the generated
588 1.1 skrll parser uses the temporary file for parsing. */
589 1.1 skrll
590 1.1 skrll static parse_state
591 1.1 skrll parse (char *line)
592 1.1 skrll {
593 1.1 skrll parse_state state;
594 1.1 skrll YY_BUFFER_STATE buffstate;
595 1.1 skrll
596 1.1 skrll buffstate = yy_scan_string (line);
597 1.1 skrll
598 1.1 skrll /* our lex requires setting the start state to keyword
599 1.1 skrll every line as the first word may be a keyword.
600 1.1 skrll Fixes a bug where we could not have keywords as labels. */
601 1.1 skrll set_start_state ();
602 1.1 skrll
603 1.1 skrll /* Call yyparse here. */
604 1.1 skrll state = yyparse ();
605 1.1 skrll if (state == SEMANTIC_ERROR)
606 1.1 skrll {
607 1.1 skrll as_bad (_("Parse failed."));
608 1.1 skrll insn = 0;
609 1.1 skrll }
610 1.1 skrll
611 1.1 skrll yy_delete_buffer (buffstate);
612 1.1 skrll return state;
613 1.1 skrll }
614 1.1 skrll
615 1.1 skrll /* We need to handle various expressions properly.
616 1.1 skrll Such as, [SP--] = 34, concerned by md_assemble(). */
617 1.1 skrll
618 1.1 skrll void
619 1.1 skrll md_operand (expressionS * expressionP)
620 1.1 skrll {
621 1.1 skrll if (*input_line_pointer == '[')
622 1.1 skrll {
623 1.1 skrll as_tsktsk ("We found a '['!");
624 1.1 skrll input_line_pointer++;
625 1.1 skrll expression (expressionP);
626 1.1 skrll }
627 1.1 skrll }
628 1.1 skrll
629 1.1 skrll /* Handle undefined symbols. */
630 1.1 skrll symbolS *
631 1.1 skrll md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
632 1.1 skrll {
633 1.1 skrll return (symbolS *) 0;
634 1.1 skrll }
635 1.1 skrll
636 1.1 skrll int
637 1.1 skrll md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
638 1.1 skrll segT segment ATTRIBUTE_UNUSED)
639 1.1 skrll {
640 1.1 skrll return 0;
641 1.1 skrll }
642 1.1 skrll
643 1.1 skrll /* Convert from target byte order to host byte order. */
644 1.1 skrll
645 1.1 skrll static int
646 1.1 skrll md_chars_to_number (char *val, int n)
647 1.1 skrll {
648 1.1 skrll int retval;
649 1.1 skrll
650 1.1 skrll for (retval = 0; n--;)
651 1.1 skrll {
652 1.1 skrll retval <<= 8;
653 1.1 skrll retval |= val[n];
654 1.1 skrll }
655 1.1 skrll return retval;
656 1.1 skrll }
657 1.1 skrll
658 1.1 skrll void
659 1.1 skrll md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
660 1.1 skrll {
661 1.1 skrll char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
662 1.1 skrll
663 1.1 skrll long value = *valueP;
664 1.1 skrll long newval;
665 1.1 skrll
666 1.1 skrll switch (fixP->fx_r_type)
667 1.1 skrll {
668 1.1 skrll case BFD_RELOC_BFIN_GOT:
669 1.1 skrll case BFD_RELOC_BFIN_GOT17M4:
670 1.1 skrll case BFD_RELOC_BFIN_FUNCDESC_GOT17M4:
671 1.1 skrll fixP->fx_no_overflow = 1;
672 1.1 skrll newval = md_chars_to_number (where, 2);
673 1.1 skrll newval |= 0x0 & 0x7f;
674 1.1 skrll md_number_to_chars (where, newval, 2);
675 1.1 skrll break;
676 1.1 skrll
677 1.1 skrll case BFD_RELOC_BFIN_10_PCREL:
678 1.1 skrll if (!value)
679 1.1 skrll break;
680 1.1 skrll if (value < -1024 || value > 1022)
681 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line,
682 1.1 skrll _("pcrel too far BFD_RELOC_BFIN_10"));
683 1.1 skrll
684 1.1 skrll /* 11 bit offset even numbered, so we remove right bit. */
685 1.1 skrll value = value >> 1;
686 1.1 skrll newval = md_chars_to_number (where, 2);
687 1.1 skrll newval |= value & 0x03ff;
688 1.1 skrll md_number_to_chars (where, newval, 2);
689 1.1 skrll break;
690 1.1 skrll
691 1.1 skrll case BFD_RELOC_BFIN_12_PCREL_JUMP:
692 1.1 skrll case BFD_RELOC_BFIN_12_PCREL_JUMP_S:
693 1.1 skrll case BFD_RELOC_12_PCREL:
694 1.1 skrll if (!value)
695 1.1 skrll break;
696 1.1 skrll
697 1.1 skrll if (value < -4096 || value > 4094)
698 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_12"));
699 1.1 skrll /* 13 bit offset even numbered, so we remove right bit. */
700 1.1 skrll value = value >> 1;
701 1.1 skrll newval = md_chars_to_number (where, 2);
702 1.1 skrll newval |= value & 0xfff;
703 1.1 skrll md_number_to_chars (where, newval, 2);
704 1.1 skrll break;
705 1.1 skrll
706 1.1 skrll case BFD_RELOC_BFIN_16_LOW:
707 1.1 skrll case BFD_RELOC_BFIN_16_HIGH:
708 1.1 skrll fixP->fx_done = FALSE;
709 1.1 skrll break;
710 1.1 skrll
711 1.1 skrll case BFD_RELOC_BFIN_24_PCREL_JUMP_L:
712 1.1 skrll case BFD_RELOC_BFIN_24_PCREL_CALL_X:
713 1.1 skrll case BFD_RELOC_24_PCREL:
714 1.1 skrll if (!value)
715 1.1 skrll break;
716 1.1 skrll
717 1.1 skrll if (value < -16777216 || value > 16777214)
718 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_24"));
719 1.1 skrll
720 1.1 skrll /* 25 bit offset even numbered, so we remove right bit. */
721 1.1 skrll value = value >> 1;
722 1.1 skrll value++;
723 1.1 skrll
724 1.1 skrll md_number_to_chars (where - 2, value >> 16, 1);
725 1.1 skrll md_number_to_chars (where, value, 1);
726 1.1 skrll md_number_to_chars (where + 1, value >> 8, 1);
727 1.1 skrll break;
728 1.1 skrll
729 1.1 skrll case BFD_RELOC_BFIN_5_PCREL: /* LSETUP (a, b) : "a" */
730 1.1 skrll if (!value)
731 1.1 skrll break;
732 1.1 skrll if (value < 4 || value > 30)
733 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_5"));
734 1.1 skrll value = value >> 1;
735 1.1 skrll newval = md_chars_to_number (where, 1);
736 1.1 skrll newval = (newval & 0xf0) | (value & 0xf);
737 1.1 skrll md_number_to_chars (where, newval, 1);
738 1.1 skrll break;
739 1.1 skrll
740 1.1 skrll case BFD_RELOC_BFIN_11_PCREL: /* LSETUP (a, b) : "b" */
741 1.1 skrll if (!value)
742 1.1 skrll break;
743 1.1 skrll value += 2;
744 1.1 skrll if (value < 4 || value > 2046)
745 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_11_PCREL"));
746 1.1 skrll /* 11 bit unsigned even, so we remove right bit. */
747 1.1 skrll value = value >> 1;
748 1.1 skrll newval = md_chars_to_number (where, 2);
749 1.1 skrll newval |= value & 0x03ff;
750 1.1 skrll md_number_to_chars (where, newval, 2);
751 1.1 skrll break;
752 1.1 skrll
753 1.1 skrll case BFD_RELOC_8:
754 1.1 skrll if (value < -0x80 || value >= 0x7f)
755 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line, _("rel too far BFD_RELOC_8"));
756 1.1 skrll md_number_to_chars (where, value, 1);
757 1.1 skrll break;
758 1.1 skrll
759 1.1 skrll case BFD_RELOC_BFIN_16_IMM:
760 1.1 skrll case BFD_RELOC_16:
761 1.1 skrll if (value < -0x8000 || value >= 0x7fff)
762 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line, _("rel too far BFD_RELOC_16"));
763 1.1 skrll md_number_to_chars (where, value, 2);
764 1.1 skrll break;
765 1.1 skrll
766 1.1 skrll case BFD_RELOC_32:
767 1.1 skrll md_number_to_chars (where, value, 4);
768 1.1 skrll break;
769 1.1 skrll
770 1.1 skrll case BFD_RELOC_BFIN_PLTPC:
771 1.1 skrll md_number_to_chars (where, value, 2);
772 1.1 skrll break;
773 1.1 skrll
774 1.1 skrll case BFD_RELOC_BFIN_FUNCDESC:
775 1.1 skrll case BFD_RELOC_VTABLE_INHERIT:
776 1.1 skrll case BFD_RELOC_VTABLE_ENTRY:
777 1.1 skrll fixP->fx_done = FALSE;
778 1.1 skrll break;
779 1.1 skrll
780 1.1 skrll default:
781 1.1 skrll if ((BFD_ARELOC_BFIN_PUSH > fixP->fx_r_type) || (BFD_ARELOC_BFIN_COMP < fixP->fx_r_type))
782 1.1 skrll {
783 1.1 skrll fprintf (stderr, "Relocation %d not handled in gas." " Contact support.\n", fixP->fx_r_type);
784 1.1 skrll return;
785 1.1 skrll }
786 1.1 skrll }
787 1.1 skrll
788 1.1 skrll if (!fixP->fx_addsy)
789 1.1 skrll fixP->fx_done = TRUE;
790 1.1 skrll
791 1.1 skrll }
792 1.1 skrll
793 1.1 skrll /* Round up a section size to the appropriate boundary. */
794 1.1 skrll valueT
795 1.1 skrll md_section_align (segment, size)
796 1.1 skrll segT segment;
797 1.1 skrll valueT size;
798 1.1 skrll {
799 1.1 skrll int boundary = bfd_get_section_alignment (stdoutput, segment);
800 1.1 skrll return ((size + (1 << boundary) - 1) & (-1 << boundary));
801 1.1 skrll }
802 1.1 skrll
803 1.1 skrll
804 1.1 skrll char *
805 1.1 skrll md_atof (int type, char * litP, int * sizeP)
806 1.1 skrll {
807 1.1 skrll return ieee_md_atof (type, litP, sizeP, FALSE);
808 1.1 skrll }
809 1.1 skrll
810 1.1 skrll
811 1.1 skrll /* If while processing a fixup, a reloc really needs to be created
812 1.1 skrll then it is done here. */
813 1.1 skrll
814 1.1 skrll arelent *
815 1.1 skrll tc_gen_reloc (seg, fixp)
816 1.1 skrll asection *seg ATTRIBUTE_UNUSED;
817 1.1 skrll fixS *fixp;
818 1.1 skrll {
819 1.1 skrll arelent *reloc;
820 1.1 skrll
821 1.1 skrll reloc = (arelent *) xmalloc (sizeof (arelent));
822 1.1 skrll reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
823 1.1 skrll *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
824 1.1 skrll reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
825 1.1 skrll
826 1.1 skrll reloc->addend = fixp->fx_offset;
827 1.1 skrll reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
828 1.1 skrll
829 1.1 skrll if (reloc->howto == (reloc_howto_type *) NULL)
830 1.1 skrll {
831 1.1 skrll as_bad_where (fixp->fx_file, fixp->fx_line,
832 1.1 skrll /* xgettext:c-format. */
833 1.1 skrll _("reloc %d not supported by object file format"),
834 1.1 skrll (int) fixp->fx_r_type);
835 1.1 skrll
836 1.1 skrll xfree (reloc);
837 1.1 skrll
838 1.1 skrll return NULL;
839 1.1 skrll }
840 1.1 skrll
841 1.1 skrll return reloc;
842 1.1 skrll }
843 1.1 skrll
844 1.1 skrll /* The location from which a PC relative jump should be calculated,
845 1.1 skrll given a PC relative reloc. */
846 1.1 skrll
847 1.1 skrll long
848 1.1 skrll md_pcrel_from_section (fixP, sec)
849 1.1 skrll fixS *fixP;
850 1.1 skrll segT sec;
851 1.1 skrll {
852 1.1 skrll if (fixP->fx_addsy != (symbolS *) NULL
853 1.1 skrll && (!S_IS_DEFINED (fixP->fx_addsy)
854 1.1 skrll || S_GET_SEGMENT (fixP->fx_addsy) != sec))
855 1.1 skrll {
856 1.1 skrll /* The symbol is undefined (or is defined but not in this section).
857 1.1 skrll Let the linker figure it out. */
858 1.1 skrll return 0;
859 1.1 skrll }
860 1.1 skrll return fixP->fx_frag->fr_address + fixP->fx_where;
861 1.1 skrll }
862 1.1 skrll
863 1.1 skrll /* Return true if the fix can be handled by GAS, false if it must
864 1.1 skrll be passed through to the linker. */
865 1.1 skrll
866 1.1.1.2 christos bfd_boolean
867 1.1 skrll bfin_fix_adjustable (fixS *fixP)
868 1.1.1.2 christos {
869 1.1 skrll switch (fixP->fx_r_type)
870 1.1.1.2 christos {
871 1.1 skrll /* Adjust_reloc_syms doesn't know about the GOT. */
872 1.1 skrll case BFD_RELOC_BFIN_GOT:
873 1.1 skrll case BFD_RELOC_BFIN_PLTPC:
874 1.1 skrll /* We need the symbol name for the VTABLE entries. */
875 1.1 skrll case BFD_RELOC_VTABLE_INHERIT:
876 1.1 skrll case BFD_RELOC_VTABLE_ENTRY:
877 1.1 skrll return 0;
878 1.1.1.2 christos
879 1.1 skrll default:
880 1.1 skrll return 1;
881 1.1 skrll }
882 1.1 skrll }
883 1.1 skrll
884 1.1 skrll /* Special extra functions that help bfin-parse.y perform its job. */
885 1.1 skrll
886 1.1 skrll struct obstack mempool;
887 1.1 skrll
888 1.1 skrll INSTR_T
889 1.1 skrll conscode (INSTR_T head, INSTR_T tail)
890 1.1 skrll {
891 1.1 skrll if (!head)
892 1.1 skrll return tail;
893 1.1 skrll head->next = tail;
894 1.1 skrll return head;
895 1.1 skrll }
896 1.1 skrll
897 1.1 skrll INSTR_T
898 1.1 skrll conctcode (INSTR_T head, INSTR_T tail)
899 1.1 skrll {
900 1.1 skrll INSTR_T temp = (head);
901 1.1 skrll if (!head)
902 1.1 skrll return tail;
903 1.1 skrll while (temp->next)
904 1.1 skrll temp = temp->next;
905 1.1 skrll temp->next = tail;
906 1.1 skrll
907 1.1 skrll return head;
908 1.1 skrll }
909 1.1 skrll
910 1.1 skrll INSTR_T
911 1.1 skrll note_reloc (INSTR_T code, Expr_Node * symbol, int reloc, int pcrel)
912 1.1 skrll {
913 1.1 skrll /* Assert that the symbol is not an operator. */
914 1.1.1.2 christos gas_assert (symbol->type == Expr_Node_Reloc);
915 1.1 skrll
916 1.1 skrll return note_reloc1 (code, symbol->value.s_value, reloc, pcrel);
917 1.1 skrll
918 1.1 skrll }
919 1.1 skrll
920 1.1 skrll INSTR_T
921 1.1 skrll note_reloc1 (INSTR_T code, const char *symbol, int reloc, int pcrel)
922 1.1 skrll {
923 1.1 skrll code->reloc = reloc;
924 1.1 skrll code->exp = mkexpr (0, symbol_find_or_make (symbol));
925 1.1 skrll code->pcrel = pcrel;
926 1.1 skrll return code;
927 1.1 skrll }
928 1.1 skrll
929 1.1 skrll INSTR_T
930 1.1 skrll note_reloc2 (INSTR_T code, const char *symbol, int reloc, int value, int pcrel)
931 1.1 skrll {
932 1.1 skrll code->reloc = reloc;
933 1.1 skrll code->exp = mkexpr (value, symbol_find_or_make (symbol));
934 1.1 skrll code->pcrel = pcrel;
935 1.1 skrll return code;
936 1.1 skrll }
937 1.1 skrll
938 1.1 skrll INSTR_T
939 1.1 skrll gencode (unsigned long x)
940 1.1 skrll {
941 1.1.1.2 christos INSTR_T cell = obstack_alloc (&mempool, sizeof (struct bfin_insn));
942 1.1 skrll memset (cell, 0, sizeof (struct bfin_insn));
943 1.1 skrll cell->value = (x);
944 1.1 skrll return cell;
945 1.1 skrll }
946 1.1 skrll
947 1.1 skrll int reloc;
948 1.1 skrll int ninsns;
949 1.1 skrll int count_insns;
950 1.1 skrll
951 1.1 skrll static void *
952 1.1 skrll allocate (int n)
953 1.1 skrll {
954 1.1.1.2 christos return obstack_alloc (&mempool, n);
955 1.1 skrll }
956 1.1 skrll
957 1.1 skrll Expr_Node *
958 1.1 skrll Expr_Node_Create (Expr_Node_Type type,
959 1.1 skrll Expr_Node_Value value,
960 1.1 skrll Expr_Node *Left_Child,
961 1.1 skrll Expr_Node *Right_Child)
962 1.1 skrll {
963 1.1 skrll
964 1.1 skrll
965 1.1 skrll Expr_Node *node = (Expr_Node *) allocate (sizeof (Expr_Node));
966 1.1 skrll node->type = type;
967 1.1 skrll node->value = value;
968 1.1 skrll node->Left_Child = Left_Child;
969 1.1 skrll node->Right_Child = Right_Child;
970 1.1 skrll return node;
971 1.1 skrll }
972 1.1 skrll
973 1.1 skrll static const char *con = ".__constant";
974 1.1 skrll static const char *op = ".__operator";
975 1.1 skrll static INSTR_T Expr_Node_Gen_Reloc_R (Expr_Node * head);
976 1.1 skrll INSTR_T Expr_Node_Gen_Reloc (Expr_Node *head, int parent_reloc);
977 1.1 skrll
978 1.1 skrll INSTR_T
979 1.1 skrll Expr_Node_Gen_Reloc (Expr_Node * head, int parent_reloc)
980 1.1 skrll {
981 1.1 skrll /* Top level reloction expression generator VDSP style.
982 1.1 skrll If the relocation is just by itself, generate one item
983 1.1 skrll else generate this convoluted expression. */
984 1.1 skrll
985 1.1 skrll INSTR_T note = NULL_CODE;
986 1.1 skrll INSTR_T note1 = NULL_CODE;
987 1.1 skrll int pcrel = 1; /* Is the parent reloc pcrelative?
988 1.1 skrll This calculation here and HOWTO should match. */
989 1.1 skrll
990 1.1 skrll if (parent_reloc)
991 1.1 skrll {
992 1.1 skrll /* If it's 32 bit quantity then 16bit code needs to be added. */
993 1.1 skrll int value = 0;
994 1.1 skrll
995 1.1 skrll if (head->type == Expr_Node_Constant)
996 1.1 skrll {
997 1.1 skrll /* If note1 is not null code, we have to generate a right
998 1.1 skrll aligned value for the constant. Otherwise the reloc is
999 1.1 skrll a part of the basic command and the yacc file
1000 1.1 skrll generates this. */
1001 1.1 skrll value = head->value.i_value;
1002 1.1 skrll }
1003 1.1 skrll switch (parent_reloc)
1004 1.1 skrll {
1005 1.1 skrll /* Some relocations will need to allocate extra words. */
1006 1.1 skrll case BFD_RELOC_BFIN_16_IMM:
1007 1.1 skrll case BFD_RELOC_BFIN_16_LOW:
1008 1.1 skrll case BFD_RELOC_BFIN_16_HIGH:
1009 1.1 skrll note1 = conscode (gencode (value), NULL_CODE);
1010 1.1 skrll pcrel = 0;
1011 1.1 skrll break;
1012 1.1 skrll case BFD_RELOC_BFIN_PLTPC:
1013 1.1 skrll note1 = conscode (gencode (value), NULL_CODE);
1014 1.1 skrll pcrel = 0;
1015 1.1 skrll break;
1016 1.1 skrll case BFD_RELOC_16:
1017 1.1 skrll case BFD_RELOC_BFIN_GOT:
1018 1.1 skrll case BFD_RELOC_BFIN_GOT17M4:
1019 1.1 skrll case BFD_RELOC_BFIN_FUNCDESC_GOT17M4:
1020 1.1 skrll note1 = conscode (gencode (value), NULL_CODE);
1021 1.1 skrll pcrel = 0;
1022 1.1 skrll break;
1023 1.1 skrll case BFD_RELOC_24_PCREL:
1024 1.1 skrll case BFD_RELOC_BFIN_24_PCREL_JUMP_L:
1025 1.1 skrll case BFD_RELOC_BFIN_24_PCREL_CALL_X:
1026 1.1 skrll /* These offsets are even numbered pcrel. */
1027 1.1 skrll note1 = conscode (gencode (value >> 1), NULL_CODE);
1028 1.1 skrll break;
1029 1.1 skrll default:
1030 1.1 skrll note1 = NULL_CODE;
1031 1.1 skrll }
1032 1.1 skrll }
1033 1.1 skrll if (head->type == Expr_Node_Constant)
1034 1.1 skrll note = note1;
1035 1.1 skrll else if (head->type == Expr_Node_Reloc)
1036 1.1 skrll {
1037 1.1 skrll note = note_reloc1 (gencode (0), head->value.s_value, parent_reloc, pcrel);
1038 1.1 skrll if (note1 != NULL_CODE)
1039 1.1 skrll note = conscode (note1, note);
1040 1.1 skrll }
1041 1.1 skrll else if (head->type == Expr_Node_Binop
1042 1.1 skrll && (head->value.op_value == Expr_Op_Type_Add
1043 1.1 skrll || head->value.op_value == Expr_Op_Type_Sub)
1044 1.1 skrll && head->Left_Child->type == Expr_Node_Reloc
1045 1.1 skrll && head->Right_Child->type == Expr_Node_Constant)
1046 1.1 skrll {
1047 1.1 skrll int val = head->Right_Child->value.i_value;
1048 1.1 skrll if (head->value.op_value == Expr_Op_Type_Sub)
1049 1.1 skrll val = -val;
1050 1.1 skrll note = conscode (note_reloc2 (gencode (0), head->Left_Child->value.s_value,
1051 1.1 skrll parent_reloc, val, 0),
1052 1.1 skrll NULL_CODE);
1053 1.1 skrll if (note1 != NULL_CODE)
1054 1.1 skrll note = conscode (note1, note);
1055 1.1 skrll }
1056 1.1 skrll else
1057 1.1 skrll {
1058 1.1 skrll /* Call the recursive function. */
1059 1.1 skrll note = note_reloc1 (gencode (0), op, parent_reloc, pcrel);
1060 1.1 skrll if (note1 != NULL_CODE)
1061 1.1 skrll note = conscode (note1, note);
1062 1.1 skrll note = conctcode (Expr_Node_Gen_Reloc_R (head), note);
1063 1.1 skrll }
1064 1.1 skrll return note;
1065 1.1 skrll }
1066 1.1 skrll
1067 1.1 skrll static INSTR_T
1068 1.1 skrll Expr_Node_Gen_Reloc_R (Expr_Node * head)
1069 1.1 skrll {
1070 1.1 skrll
1071 1.1 skrll INSTR_T note = 0;
1072 1.1 skrll INSTR_T note1 = 0;
1073 1.1 skrll
1074 1.1 skrll switch (head->type)
1075 1.1 skrll {
1076 1.1 skrll case Expr_Node_Constant:
1077 1.1 skrll note = conscode (note_reloc2 (gencode (0), con, BFD_ARELOC_BFIN_CONST, head->value.i_value, 0), NULL_CODE);
1078 1.1 skrll break;
1079 1.1 skrll case Expr_Node_Reloc:
1080 1.1 skrll note = conscode (note_reloc (gencode (0), head, BFD_ARELOC_BFIN_PUSH, 0), NULL_CODE);
1081 1.1 skrll break;
1082 1.1 skrll case Expr_Node_Binop:
1083 1.1 skrll note1 = conctcode (Expr_Node_Gen_Reloc_R (head->Left_Child), Expr_Node_Gen_Reloc_R (head->Right_Child));
1084 1.1 skrll switch (head->value.op_value)
1085 1.1 skrll {
1086 1.1 skrll case Expr_Op_Type_Add:
1087 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_ADD, 0), NULL_CODE));
1088 1.1 skrll break;
1089 1.1 skrll case Expr_Op_Type_Sub:
1090 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_SUB, 0), NULL_CODE));
1091 1.1 skrll break;
1092 1.1 skrll case Expr_Op_Type_Mult:
1093 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_MULT, 0), NULL_CODE));
1094 1.1 skrll break;
1095 1.1 skrll case Expr_Op_Type_Div:
1096 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_DIV, 0), NULL_CODE));
1097 1.1 skrll break;
1098 1.1 skrll case Expr_Op_Type_Mod:
1099 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_MOD, 0), NULL_CODE));
1100 1.1 skrll break;
1101 1.1 skrll case Expr_Op_Type_Lshift:
1102 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_LSHIFT, 0), NULL_CODE));
1103 1.1 skrll break;
1104 1.1 skrll case Expr_Op_Type_Rshift:
1105 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_RSHIFT, 0), NULL_CODE));
1106 1.1 skrll break;
1107 1.1 skrll case Expr_Op_Type_BAND:
1108 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_AND, 0), NULL_CODE));
1109 1.1 skrll break;
1110 1.1 skrll case Expr_Op_Type_BOR:
1111 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_OR, 0), NULL_CODE));
1112 1.1 skrll break;
1113 1.1 skrll case Expr_Op_Type_BXOR:
1114 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_XOR, 0), NULL_CODE));
1115 1.1 skrll break;
1116 1.1 skrll case Expr_Op_Type_LAND:
1117 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_LAND, 0), NULL_CODE));
1118 1.1 skrll break;
1119 1.1 skrll case Expr_Op_Type_LOR:
1120 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_LOR, 0), NULL_CODE));
1121 1.1 skrll break;
1122 1.1 skrll default:
1123 1.1 skrll fprintf (stderr, "%s:%d:Unknown operator found for arithmetic" " relocation", __FILE__, __LINE__);
1124 1.1 skrll
1125 1.1 skrll
1126 1.1 skrll }
1127 1.1 skrll break;
1128 1.1 skrll case Expr_Node_Unop:
1129 1.1 skrll note1 = conscode (Expr_Node_Gen_Reloc_R (head->Left_Child), NULL_CODE);
1130 1.1 skrll switch (head->value.op_value)
1131 1.1 skrll {
1132 1.1 skrll case Expr_Op_Type_NEG:
1133 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_NEG, 0), NULL_CODE));
1134 1.1 skrll break;
1135 1.1 skrll case Expr_Op_Type_COMP:
1136 1.1 skrll note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_COMP, 0), NULL_CODE));
1137 1.1 skrll break;
1138 1.1 skrll default:
1139 1.1 skrll fprintf (stderr, "%s:%d:Unknown operator found for arithmetic" " relocation", __FILE__, __LINE__);
1140 1.1 skrll }
1141 1.1 skrll break;
1142 1.1 skrll default:
1143 1.1 skrll fprintf (stderr, "%s:%d:Unknown node expression found during " "arithmetic relocation generation", __FILE__, __LINE__);
1144 1.1 skrll }
1145 1.1 skrll return note;
1146 1.1 skrll }
1147 1.1.1.2 christos
1148 1.1 skrll /* Blackfin opcode generation. */
1150 1.1 skrll
1151 1.1 skrll /* These functions are called by the generated parser
1152 1.1 skrll (from bfin-parse.y), the register type classification
1153 1.1 skrll happens in bfin-lex.l. */
1154 1.1 skrll
1155 1.1 skrll #include "bfin-aux.h"
1156 1.1 skrll #include "opcode/bfin.h"
1157 1.1 skrll
1158 1.1 skrll #define INIT(t) t c_code = init_##t
1159 1.1.1.2 christos #define ASSIGN(x) c_code.opcode |= ((x & c_code.mask_##x)<<c_code.bits_##x)
1160 1.1 skrll #define ASSIGNF(x,f) c_code.opcode |= ((x & c_code.mask_##f)<<c_code.bits_##f)
1161 1.1 skrll #define ASSIGN_R(x) c_code.opcode |= (((x ? (x->regno & CODE_MASK) : 0) & c_code.mask_##x)<<c_code.bits_##x)
1162 1.1 skrll
1163 1.1 skrll #define HI(x) ((x >> 16) & 0xffff)
1164 1.1 skrll #define LO(x) ((x ) & 0xffff)
1165 1.1 skrll
1166 1.1 skrll #define GROUP(x) ((x->regno & CLASS_MASK) >> 4)
1167 1.1 skrll
1168 1.1 skrll #define GEN_OPCODE32() \
1169 1.1 skrll conscode (gencode (HI (c_code.opcode)), \
1170 1.1 skrll conscode (gencode (LO (c_code.opcode)), NULL_CODE))
1171 1.1 skrll
1172 1.1 skrll #define GEN_OPCODE16() \
1173 1.1 skrll conscode (gencode (c_code.opcode), NULL_CODE)
1174 1.1 skrll
1175 1.1 skrll
1176 1.1 skrll /* 32 BIT INSTRUCTIONS. */
1177 1.1 skrll
1178 1.1 skrll
1179 1.1 skrll /* DSP32 instruction generation. */
1180 1.1 skrll
1181 1.1 skrll INSTR_T
1182 1.1 skrll bfin_gen_dsp32mac (int op1, int MM, int mmod, int w1, int P,
1183 1.1 skrll int h01, int h11, int h00, int h10, int op0,
1184 1.1 skrll REG_T dst, REG_T src0, REG_T src1, int w0)
1185 1.1 skrll {
1186 1.1 skrll INIT (DSP32Mac);
1187 1.1 skrll
1188 1.1 skrll ASSIGN (op0);
1189 1.1 skrll ASSIGN (op1);
1190 1.1 skrll ASSIGN (MM);
1191 1.1 skrll ASSIGN (mmod);
1192 1.1 skrll ASSIGN (w0);
1193 1.1 skrll ASSIGN (w1);
1194 1.1 skrll ASSIGN (h01);
1195 1.1 skrll ASSIGN (h11);
1196 1.1 skrll ASSIGN (h00);
1197 1.1 skrll ASSIGN (h10);
1198 1.1 skrll ASSIGN (P);
1199 1.1 skrll
1200 1.1 skrll /* If we have full reg assignments, mask out LSB to encode
1201 1.1 skrll single or simultaneous even/odd register moves. */
1202 1.1 skrll if (P)
1203 1.1 skrll {
1204 1.1 skrll dst->regno &= 0x06;
1205 1.1 skrll }
1206 1.1 skrll
1207 1.1 skrll ASSIGN_R (dst);
1208 1.1 skrll ASSIGN_R (src0);
1209 1.1 skrll ASSIGN_R (src1);
1210 1.1 skrll
1211 1.1 skrll return GEN_OPCODE32 ();
1212 1.1 skrll }
1213 1.1 skrll
1214 1.1 skrll INSTR_T
1215 1.1 skrll bfin_gen_dsp32mult (int op1, int MM, int mmod, int w1, int P,
1216 1.1 skrll int h01, int h11, int h00, int h10, int op0,
1217 1.1 skrll REG_T dst, REG_T src0, REG_T src1, int w0)
1218 1.1 skrll {
1219 1.1 skrll INIT (DSP32Mult);
1220 1.1 skrll
1221 1.1 skrll ASSIGN (op0);
1222 1.1 skrll ASSIGN (op1);
1223 1.1 skrll ASSIGN (MM);
1224 1.1 skrll ASSIGN (mmod);
1225 1.1 skrll ASSIGN (w0);
1226 1.1 skrll ASSIGN (w1);
1227 1.1 skrll ASSIGN (h01);
1228 1.1 skrll ASSIGN (h11);
1229 1.1 skrll ASSIGN (h00);
1230 1.1 skrll ASSIGN (h10);
1231 1.1 skrll ASSIGN (P);
1232 1.1 skrll
1233 1.1 skrll if (P)
1234 1.1 skrll {
1235 1.1 skrll dst->regno &= 0x06;
1236 1.1 skrll }
1237 1.1 skrll
1238 1.1 skrll ASSIGN_R (dst);
1239 1.1 skrll ASSIGN_R (src0);
1240 1.1 skrll ASSIGN_R (src1);
1241 1.1 skrll
1242 1.1 skrll return GEN_OPCODE32 ();
1243 1.1 skrll }
1244 1.1 skrll
1245 1.1 skrll INSTR_T
1246 1.1 skrll bfin_gen_dsp32alu (int HL, int aopcde, int aop, int s, int x,
1247 1.1 skrll REG_T dst0, REG_T dst1, REG_T src0, REG_T src1)
1248 1.1 skrll {
1249 1.1 skrll INIT (DSP32Alu);
1250 1.1 skrll
1251 1.1 skrll ASSIGN (HL);
1252 1.1 skrll ASSIGN (aopcde);
1253 1.1 skrll ASSIGN (aop);
1254 1.1 skrll ASSIGN (s);
1255 1.1 skrll ASSIGN (x);
1256 1.1 skrll ASSIGN_R (dst0);
1257 1.1 skrll ASSIGN_R (dst1);
1258 1.1 skrll ASSIGN_R (src0);
1259 1.1 skrll ASSIGN_R (src1);
1260 1.1 skrll
1261 1.1 skrll return GEN_OPCODE32 ();
1262 1.1 skrll }
1263 1.1 skrll
1264 1.1 skrll INSTR_T
1265 1.1 skrll bfin_gen_dsp32shift (int sopcde, REG_T dst0, REG_T src0,
1266 1.1 skrll REG_T src1, int sop, int HLs)
1267 1.1 skrll {
1268 1.1 skrll INIT (DSP32Shift);
1269 1.1 skrll
1270 1.1 skrll ASSIGN (sopcde);
1271 1.1 skrll ASSIGN (sop);
1272 1.1 skrll ASSIGN (HLs);
1273 1.1 skrll
1274 1.1 skrll ASSIGN_R (dst0);
1275 1.1 skrll ASSIGN_R (src0);
1276 1.1 skrll ASSIGN_R (src1);
1277 1.1 skrll
1278 1.1 skrll return GEN_OPCODE32 ();
1279 1.1 skrll }
1280 1.1 skrll
1281 1.1 skrll INSTR_T
1282 1.1 skrll bfin_gen_dsp32shiftimm (int sopcde, REG_T dst0, int immag,
1283 1.1 skrll REG_T src1, int sop, int HLs)
1284 1.1 skrll {
1285 1.1 skrll INIT (DSP32ShiftImm);
1286 1.1 skrll
1287 1.1 skrll ASSIGN (sopcde);
1288 1.1 skrll ASSIGN (sop);
1289 1.1 skrll ASSIGN (HLs);
1290 1.1 skrll
1291 1.1 skrll ASSIGN_R (dst0);
1292 1.1 skrll ASSIGN (immag);
1293 1.1 skrll ASSIGN_R (src1);
1294 1.1 skrll
1295 1.1 skrll return GEN_OPCODE32 ();
1296 1.1 skrll }
1297 1.1 skrll
1298 1.1 skrll /* LOOP SETUP. */
1299 1.1 skrll
1300 1.1 skrll INSTR_T
1301 1.1 skrll bfin_gen_loopsetup (Expr_Node * psoffset, REG_T c, int rop,
1302 1.1 skrll Expr_Node * peoffset, REG_T reg)
1303 1.1 skrll {
1304 1.1 skrll int soffset, eoffset;
1305 1.1 skrll INIT (LoopSetup);
1306 1.1 skrll
1307 1.1 skrll soffset = (EXPR_VALUE (psoffset) >> 1);
1308 1.1 skrll ASSIGN (soffset);
1309 1.1 skrll eoffset = (EXPR_VALUE (peoffset) >> 1);
1310 1.1 skrll ASSIGN (eoffset);
1311 1.1 skrll ASSIGN (rop);
1312 1.1 skrll ASSIGN_R (c);
1313 1.1 skrll ASSIGN_R (reg);
1314 1.1 skrll
1315 1.1 skrll return
1316 1.1 skrll conscode (gencode (HI (c_code.opcode)),
1317 1.1 skrll conctcode (Expr_Node_Gen_Reloc (psoffset, BFD_RELOC_BFIN_5_PCREL),
1318 1.1 skrll conctcode (gencode (LO (c_code.opcode)), Expr_Node_Gen_Reloc (peoffset, BFD_RELOC_BFIN_11_PCREL))));
1319 1.1 skrll
1320 1.1 skrll }
1321 1.1 skrll
1322 1.1 skrll /* Call, Link. */
1323 1.1 skrll
1324 1.1 skrll INSTR_T
1325 1.1 skrll bfin_gen_calla (Expr_Node * addr, int S)
1326 1.1 skrll {
1327 1.1 skrll int val;
1328 1.1.1.2 christos int high_val;
1329 1.1 skrll int rel = 0;
1330 1.1 skrll INIT (CALLa);
1331 1.1 skrll
1332 1.1.1.2 christos switch(S){
1333 1.1.1.2 christos case 0 : rel = BFD_RELOC_BFIN_24_PCREL_JUMP_L; break;
1334 1.1.1.2 christos case 1 : rel = BFD_RELOC_24_PCREL; break;
1335 1.1 skrll case 2 : rel = BFD_RELOC_BFIN_PLTPC; break;
1336 1.1 skrll default : break;
1337 1.1 skrll }
1338 1.1 skrll
1339 1.1 skrll ASSIGN (S);
1340 1.1 skrll
1341 1.1 skrll val = EXPR_VALUE (addr) >> 1;
1342 1.1 skrll high_val = val >> 16;
1343 1.1 skrll
1344 1.1.1.2 christos return conscode (gencode (HI (c_code.opcode) | (high_val & 0xff)),
1345 1.1 skrll Expr_Node_Gen_Reloc (addr, rel));
1346 1.1 skrll }
1347 1.1 skrll
1348 1.1 skrll INSTR_T
1349 1.1 skrll bfin_gen_linkage (int R, int framesize)
1350 1.1 skrll {
1351 1.1 skrll INIT (Linkage);
1352 1.1 skrll
1353 1.1 skrll ASSIGN (R);
1354 1.1 skrll ASSIGN (framesize);
1355 1.1 skrll
1356 1.1 skrll return GEN_OPCODE32 ();
1357 1.1 skrll }
1358 1.1 skrll
1359 1.1 skrll
1360 1.1 skrll /* Load and Store. */
1361 1.1 skrll
1362 1.1.1.2 christos INSTR_T
1363 1.1 skrll bfin_gen_ldimmhalf (REG_T reg, int H, int S, int Z, Expr_Node * phword, int rel)
1364 1.1 skrll {
1365 1.1 skrll int grp, hword;
1366 1.1 skrll unsigned val = EXPR_VALUE (phword);
1367 1.1 skrll INIT (LDIMMhalf);
1368 1.1 skrll
1369 1.1 skrll ASSIGN (H);
1370 1.1 skrll ASSIGN (S);
1371 1.1 skrll ASSIGN (Z);
1372 1.1 skrll
1373 1.1 skrll ASSIGN_R (reg);
1374 1.1 skrll grp = (GROUP (reg));
1375 1.1.1.2 christos ASSIGN (grp);
1376 1.1 skrll if (rel == 2)
1377 1.1 skrll {
1378 1.1 skrll return conscode (gencode (HI (c_code.opcode)), Expr_Node_Gen_Reloc (phword, BFD_RELOC_BFIN_16_IMM));
1379 1.1.1.2 christos }
1380 1.1 skrll else if (rel == 1)
1381 1.1 skrll {
1382 1.1 skrll return conscode (gencode (HI (c_code.opcode)), Expr_Node_Gen_Reloc (phword, IS_H (*reg) ? BFD_RELOC_BFIN_16_HIGH : BFD_RELOC_BFIN_16_LOW));
1383 1.1 skrll }
1384 1.1 skrll else
1385 1.1 skrll {
1386 1.1 skrll hword = val;
1387 1.1 skrll ASSIGN (hword);
1388 1.1 skrll }
1389 1.1 skrll return GEN_OPCODE32 ();
1390 1.1 skrll }
1391 1.1 skrll
1392 1.1 skrll INSTR_T
1393 1.1 skrll bfin_gen_ldstidxi (REG_T ptr, REG_T reg, int W, int sz, int Z, Expr_Node * poffset)
1394 1.1 skrll {
1395 1.1 skrll INIT (LDSTidxI);
1396 1.1 skrll
1397 1.1 skrll if (!IS_PREG (*ptr) || (!IS_DREG (*reg) && !Z))
1398 1.1 skrll {
1399 1.1 skrll fprintf (stderr, "Warning: possible mixup of Preg/Dreg\n");
1400 1.1 skrll return 0;
1401 1.1 skrll }
1402 1.1 skrll
1403 1.1 skrll ASSIGN_R (ptr);
1404 1.1 skrll ASSIGN_R (reg);
1405 1.1 skrll ASSIGN (W);
1406 1.1 skrll ASSIGN (sz);
1407 1.1 skrll
1408 1.1 skrll ASSIGN (Z);
1409 1.1 skrll
1410 1.1 skrll if (poffset->type != Expr_Node_Constant)
1411 1.1 skrll {
1412 1.1 skrll /* a GOT relocation such as R0 = [P5 + symbol@GOT] */
1413 1.1 skrll /* distinguish between R0 = [P5 + symbol@GOT] and
1414 1.1 skrll P5 = [P5 + _current_shared_library_p5_offset_]
1415 1.1 skrll */
1416 1.1 skrll if (poffset->type == Expr_Node_Reloc
1417 1.1 skrll && !strcmp (poffset->value.s_value,
1418 1.1 skrll "_current_shared_library_p5_offset_"))
1419 1.1 skrll {
1420 1.1 skrll return conscode (gencode (HI (c_code.opcode)),
1421 1.1 skrll Expr_Node_Gen_Reloc(poffset, BFD_RELOC_16));
1422 1.1 skrll }
1423 1.1 skrll else if (poffset->type != Expr_Node_GOT_Reloc)
1424 1.1 skrll abort ();
1425 1.1 skrll
1426 1.1 skrll return conscode (gencode (HI (c_code.opcode)),
1427 1.1 skrll Expr_Node_Gen_Reloc(poffset->Left_Child,
1428 1.1 skrll poffset->value.i_value));
1429 1.1 skrll }
1430 1.1 skrll else
1431 1.1 skrll {
1432 1.1 skrll int value, offset;
1433 1.1.1.2 christos switch (sz)
1434 1.1.1.2 christos { /* load/store access size */
1435 1.1 skrll case 0: /* 32 bit */
1436 1.1 skrll value = EXPR_VALUE (poffset) >> 2;
1437 1.1.1.2 christos break;
1438 1.1 skrll case 1: /* 16 bit */
1439 1.1 skrll value = EXPR_VALUE (poffset) >> 1;
1440 1.1.1.2 christos break;
1441 1.1 skrll case 2: /* 8 bit */
1442 1.1 skrll value = EXPR_VALUE (poffset);
1443 1.1 skrll break;
1444 1.1 skrll default:
1445 1.1 skrll abort ();
1446 1.1 skrll }
1447 1.1 skrll
1448 1.1 skrll offset = (value & 0xffff);
1449 1.1 skrll ASSIGN (offset);
1450 1.1 skrll return GEN_OPCODE32 ();
1451 1.1 skrll }
1452 1.1 skrll }
1453 1.1 skrll
1454 1.1 skrll
1455 1.1 skrll INSTR_T
1456 1.1 skrll bfin_gen_ldst (REG_T ptr, REG_T reg, int aop, int sz, int Z, int W)
1457 1.1 skrll {
1458 1.1 skrll INIT (LDST);
1459 1.1 skrll
1460 1.1 skrll if (!IS_PREG (*ptr) || (!IS_DREG (*reg) && !Z))
1461 1.1 skrll {
1462 1.1 skrll fprintf (stderr, "Warning: possible mixup of Preg/Dreg\n");
1463 1.1 skrll return 0;
1464 1.1 skrll }
1465 1.1 skrll
1466 1.1 skrll ASSIGN_R (ptr);
1467 1.1 skrll ASSIGN_R (reg);
1468 1.1 skrll ASSIGN (aop);
1469 1.1 skrll ASSIGN (sz);
1470 1.1 skrll ASSIGN (Z);
1471 1.1 skrll ASSIGN (W);
1472 1.1 skrll
1473 1.1 skrll return GEN_OPCODE16 ();
1474 1.1 skrll }
1475 1.1 skrll
1476 1.1.1.2 christos INSTR_T
1477 1.1 skrll bfin_gen_ldstii (REG_T ptr, REG_T reg, Expr_Node * poffset, int W, int opc)
1478 1.1 skrll {
1479 1.1 skrll int offset;
1480 1.1 skrll int value = 0;
1481 1.1 skrll INIT (LDSTii);
1482 1.1 skrll
1483 1.1 skrll if (!IS_PREG (*ptr))
1484 1.1 skrll {
1485 1.1 skrll fprintf (stderr, "Warning: possible mixup of Preg/Dreg\n");
1486 1.1 skrll return 0;
1487 1.1 skrll }
1488 1.1.1.2 christos
1489 1.1 skrll switch (opc)
1490 1.1 skrll {
1491 1.1 skrll case 1:
1492 1.1 skrll case 2:
1493 1.1 skrll value = EXPR_VALUE (poffset) >> 1;
1494 1.1 skrll break;
1495 1.1 skrll case 0:
1496 1.1 skrll case 3:
1497 1.1 skrll value = EXPR_VALUE (poffset) >> 2;
1498 1.1 skrll break;
1499 1.1 skrll }
1500 1.1 skrll
1501 1.1 skrll ASSIGN_R (ptr);
1502 1.1 skrll ASSIGN_R (reg);
1503 1.1 skrll
1504 1.1 skrll offset = value;
1505 1.1 skrll ASSIGN (offset);
1506 1.1.1.2 christos ASSIGN (W);
1507 1.1 skrll ASSIGNF (opc, op);
1508 1.1 skrll
1509 1.1 skrll return GEN_OPCODE16 ();
1510 1.1 skrll }
1511 1.1 skrll
1512 1.1 skrll INSTR_T
1513 1.1 skrll bfin_gen_ldstiifp (REG_T sreg, Expr_Node * poffset, int W)
1514 1.1 skrll {
1515 1.1 skrll /* Set bit 4 if it's a Preg. */
1516 1.1 skrll int reg = (sreg->regno & CODE_MASK) | (IS_PREG (*sreg) ? 0x8 : 0x0);
1517 1.1 skrll int offset = ((~(EXPR_VALUE (poffset) >> 2)) & 0x1f) + 1;
1518 1.1 skrll INIT (LDSTiiFP);
1519 1.1 skrll ASSIGN (reg);
1520 1.1 skrll ASSIGN (offset);
1521 1.1 skrll ASSIGN (W);
1522 1.1 skrll
1523 1.1 skrll return GEN_OPCODE16 ();
1524 1.1 skrll }
1525 1.1 skrll
1526 1.1 skrll INSTR_T
1527 1.1 skrll bfin_gen_ldstpmod (REG_T ptr, REG_T reg, int aop, int W, REG_T idx)
1528 1.1 skrll {
1529 1.1 skrll INIT (LDSTpmod);
1530 1.1 skrll
1531 1.1 skrll ASSIGN_R (ptr);
1532 1.1 skrll ASSIGN_R (reg);
1533 1.1 skrll ASSIGN (aop);
1534 1.1 skrll ASSIGN (W);
1535 1.1 skrll ASSIGN_R (idx);
1536 1.1 skrll
1537 1.1 skrll return GEN_OPCODE16 ();
1538 1.1 skrll }
1539 1.1 skrll
1540 1.1 skrll INSTR_T
1541 1.1 skrll bfin_gen_dspldst (REG_T i, REG_T reg, int aop, int W, int m)
1542 1.1 skrll {
1543 1.1 skrll INIT (DspLDST);
1544 1.1 skrll
1545 1.1 skrll ASSIGN_R (i);
1546 1.1 skrll ASSIGN_R (reg);
1547 1.1 skrll ASSIGN (aop);
1548 1.1 skrll ASSIGN (W);
1549 1.1 skrll ASSIGN (m);
1550 1.1 skrll
1551 1.1 skrll return GEN_OPCODE16 ();
1552 1.1 skrll }
1553 1.1 skrll
1554 1.1 skrll INSTR_T
1555 1.1 skrll bfin_gen_logi2op (int opc, int src, int dst)
1556 1.1 skrll {
1557 1.1 skrll INIT (LOGI2op);
1558 1.1 skrll
1559 1.1 skrll ASSIGN (opc);
1560 1.1 skrll ASSIGN (src);
1561 1.1 skrll ASSIGN (dst);
1562 1.1 skrll
1563 1.1 skrll return GEN_OPCODE16 ();
1564 1.1 skrll }
1565 1.1 skrll
1566 1.1 skrll INSTR_T
1567 1.1 skrll bfin_gen_brcc (int T, int B, Expr_Node * poffset)
1568 1.1 skrll {
1569 1.1 skrll int offset;
1570 1.1 skrll INIT (BRCC);
1571 1.1 skrll
1572 1.1 skrll ASSIGN (T);
1573 1.1 skrll ASSIGN (B);
1574 1.1 skrll offset = ((EXPR_VALUE (poffset) >> 1));
1575 1.1 skrll ASSIGN (offset);
1576 1.1 skrll return conscode (gencode (c_code.opcode), Expr_Node_Gen_Reloc (poffset, BFD_RELOC_BFIN_10_PCREL));
1577 1.1 skrll }
1578 1.1 skrll
1579 1.1 skrll INSTR_T
1580 1.1 skrll bfin_gen_ujump (Expr_Node * poffset)
1581 1.1 skrll {
1582 1.1 skrll int offset;
1583 1.1 skrll INIT (UJump);
1584 1.1 skrll
1585 1.1 skrll offset = ((EXPR_VALUE (poffset) >> 1));
1586 1.1 skrll ASSIGN (offset);
1587 1.1 skrll
1588 1.1 skrll return conscode (gencode (c_code.opcode),
1589 1.1 skrll Expr_Node_Gen_Reloc (
1590 1.1 skrll poffset, BFD_RELOC_BFIN_12_PCREL_JUMP_S));
1591 1.1 skrll }
1592 1.1 skrll
1593 1.1 skrll INSTR_T
1594 1.1 skrll bfin_gen_alu2op (REG_T dst, REG_T src, int opc)
1595 1.1 skrll {
1596 1.1 skrll INIT (ALU2op);
1597 1.1 skrll
1598 1.1 skrll ASSIGN_R (dst);
1599 1.1 skrll ASSIGN_R (src);
1600 1.1 skrll ASSIGN (opc);
1601 1.1 skrll
1602 1.1 skrll return GEN_OPCODE16 ();
1603 1.1 skrll }
1604 1.1 skrll
1605 1.1.1.2 christos INSTR_T
1606 1.1 skrll bfin_gen_compi2opd (REG_T dst, int src, int opc)
1607 1.1 skrll {
1608 1.1 skrll INIT (COMPI2opD);
1609 1.1 skrll
1610 1.1 skrll ASSIGN_R (dst);
1611 1.1.1.2 christos ASSIGN (src);
1612 1.1 skrll ASSIGNF (opc, op);
1613 1.1 skrll
1614 1.1 skrll return GEN_OPCODE16 ();
1615 1.1 skrll }
1616 1.1 skrll
1617 1.1.1.2 christos INSTR_T
1618 1.1 skrll bfin_gen_compi2opp (REG_T dst, int src, int opc)
1619 1.1 skrll {
1620 1.1 skrll INIT (COMPI2opP);
1621 1.1 skrll
1622 1.1 skrll ASSIGN_R (dst);
1623 1.1.1.2 christos ASSIGN (src);
1624 1.1 skrll ASSIGNF (opc, op);
1625 1.1 skrll
1626 1.1 skrll return GEN_OPCODE16 ();
1627 1.1 skrll }
1628 1.1 skrll
1629 1.1.1.2 christos INSTR_T
1630 1.1 skrll bfin_gen_dagmodik (REG_T i, int opc)
1631 1.1 skrll {
1632 1.1 skrll INIT (DagMODik);
1633 1.1 skrll
1634 1.1.1.2 christos ASSIGN_R (i);
1635 1.1 skrll ASSIGNF (opc, op);
1636 1.1 skrll
1637 1.1 skrll return GEN_OPCODE16 ();
1638 1.1 skrll }
1639 1.1 skrll
1640 1.1.1.2 christos INSTR_T
1641 1.1 skrll bfin_gen_dagmodim (REG_T i, REG_T m, int opc, int br)
1642 1.1 skrll {
1643 1.1 skrll INIT (DagMODim);
1644 1.1 skrll
1645 1.1 skrll ASSIGN_R (i);
1646 1.1.1.2 christos ASSIGN_R (m);
1647 1.1 skrll ASSIGNF (opc, op);
1648 1.1 skrll ASSIGN (br);
1649 1.1 skrll
1650 1.1 skrll return GEN_OPCODE16 ();
1651 1.1 skrll }
1652 1.1 skrll
1653 1.1 skrll INSTR_T
1654 1.1 skrll bfin_gen_ptr2op (REG_T dst, REG_T src, int opc)
1655 1.1 skrll {
1656 1.1 skrll INIT (PTR2op);
1657 1.1 skrll
1658 1.1 skrll ASSIGN_R (dst);
1659 1.1 skrll ASSIGN_R (src);
1660 1.1 skrll ASSIGN (opc);
1661 1.1 skrll
1662 1.1 skrll return GEN_OPCODE16 ();
1663 1.1 skrll }
1664 1.1 skrll
1665 1.1 skrll INSTR_T
1666 1.1 skrll bfin_gen_comp3op (REG_T src0, REG_T src1, REG_T dst, int opc)
1667 1.1 skrll {
1668 1.1 skrll INIT (COMP3op);
1669 1.1 skrll
1670 1.1 skrll ASSIGN_R (src0);
1671 1.1 skrll ASSIGN_R (src1);
1672 1.1 skrll ASSIGN_R (dst);
1673 1.1 skrll ASSIGN (opc);
1674 1.1 skrll
1675 1.1 skrll return GEN_OPCODE16 ();
1676 1.1 skrll }
1677 1.1 skrll
1678 1.1 skrll INSTR_T
1679 1.1 skrll bfin_gen_ccflag (REG_T x, int y, int opc, int I, int G)
1680 1.1 skrll {
1681 1.1 skrll INIT (CCflag);
1682 1.1 skrll
1683 1.1 skrll ASSIGN_R (x);
1684 1.1 skrll ASSIGN (y);
1685 1.1 skrll ASSIGN (opc);
1686 1.1 skrll ASSIGN (I);
1687 1.1 skrll ASSIGN (G);
1688 1.1 skrll
1689 1.1 skrll return GEN_OPCODE16 ();
1690 1.1 skrll }
1691 1.1 skrll
1692 1.1 skrll INSTR_T
1693 1.1 skrll bfin_gen_ccmv (REG_T src, REG_T dst, int T)
1694 1.1 skrll {
1695 1.1 skrll int s, d;
1696 1.1 skrll INIT (CCmv);
1697 1.1 skrll
1698 1.1 skrll ASSIGN_R (src);
1699 1.1 skrll ASSIGN_R (dst);
1700 1.1 skrll s = (GROUP (src));
1701 1.1 skrll ASSIGN (s);
1702 1.1 skrll d = (GROUP (dst));
1703 1.1 skrll ASSIGN (d);
1704 1.1 skrll ASSIGN (T);
1705 1.1 skrll
1706 1.1 skrll return GEN_OPCODE16 ();
1707 1.1 skrll }
1708 1.1 skrll
1709 1.1.1.2 christos INSTR_T
1710 1.1 skrll bfin_gen_cc2stat (int cbit, int opc, int D)
1711 1.1 skrll {
1712 1.1 skrll INIT (CC2stat);
1713 1.1 skrll
1714 1.1.1.2 christos ASSIGN (cbit);
1715 1.1 skrll ASSIGNF (opc, op);
1716 1.1 skrll ASSIGN (D);
1717 1.1 skrll
1718 1.1 skrll return GEN_OPCODE16 ();
1719 1.1 skrll }
1720 1.1 skrll
1721 1.1 skrll INSTR_T
1722 1.1 skrll bfin_gen_regmv (REG_T src, REG_T dst)
1723 1.1 skrll {
1724 1.1 skrll int gs, gd;
1725 1.1 skrll INIT (RegMv);
1726 1.1 skrll
1727 1.1 skrll ASSIGN_R (src);
1728 1.1 skrll ASSIGN_R (dst);
1729 1.1 skrll
1730 1.1 skrll gs = (GROUP (src));
1731 1.1 skrll ASSIGN (gs);
1732 1.1 skrll gd = (GROUP (dst));
1733 1.1 skrll ASSIGN (gd);
1734 1.1 skrll
1735 1.1 skrll return GEN_OPCODE16 ();
1736 1.1 skrll }
1737 1.1 skrll
1738 1.1.1.2 christos INSTR_T
1739 1.1 skrll bfin_gen_cc2dreg (int opc, REG_T reg)
1740 1.1 skrll {
1741 1.1 skrll INIT (CC2dreg);
1742 1.1.1.2 christos
1743 1.1 skrll ASSIGNF (opc, op);
1744 1.1 skrll ASSIGN_R (reg);
1745 1.1 skrll
1746 1.1 skrll return GEN_OPCODE16 ();
1747 1.1 skrll }
1748 1.1 skrll
1749 1.1 skrll INSTR_T
1750 1.1 skrll bfin_gen_progctrl (int prgfunc, int poprnd)
1751 1.1 skrll {
1752 1.1 skrll INIT (ProgCtrl);
1753 1.1 skrll
1754 1.1 skrll ASSIGN (prgfunc);
1755 1.1 skrll ASSIGN (poprnd);
1756 1.1 skrll
1757 1.1 skrll return GEN_OPCODE16 ();
1758 1.1 skrll }
1759 1.1 skrll
1760 1.1.1.2 christos INSTR_T
1761 1.1 skrll bfin_gen_cactrl (REG_T reg, int a, int opc)
1762 1.1 skrll {
1763 1.1 skrll INIT (CaCTRL);
1764 1.1 skrll
1765 1.1 skrll ASSIGN_R (reg);
1766 1.1.1.2 christos ASSIGN (a);
1767 1.1 skrll ASSIGNF (opc, op);
1768 1.1 skrll
1769 1.1 skrll return GEN_OPCODE16 ();
1770 1.1 skrll }
1771 1.1 skrll
1772 1.1 skrll INSTR_T
1773 1.1 skrll bfin_gen_pushpopmultiple (int dr, int pr, int d, int p, int W)
1774 1.1 skrll {
1775 1.1 skrll INIT (PushPopMultiple);
1776 1.1 skrll
1777 1.1 skrll ASSIGN (dr);
1778 1.1 skrll ASSIGN (pr);
1779 1.1 skrll ASSIGN (d);
1780 1.1 skrll ASSIGN (p);
1781 1.1 skrll ASSIGN (W);
1782 1.1 skrll
1783 1.1 skrll return GEN_OPCODE16 ();
1784 1.1 skrll }
1785 1.1 skrll
1786 1.1 skrll INSTR_T
1787 1.1 skrll bfin_gen_pushpopreg (REG_T reg, int W)
1788 1.1 skrll {
1789 1.1 skrll int grp;
1790 1.1 skrll INIT (PushPopReg);
1791 1.1 skrll
1792 1.1 skrll ASSIGN_R (reg);
1793 1.1 skrll grp = (GROUP (reg));
1794 1.1 skrll ASSIGN (grp);
1795 1.1 skrll ASSIGN (W);
1796 1.1 skrll
1797 1.1 skrll return GEN_OPCODE16 ();
1798 1.1 skrll }
1799 1.1 skrll
1800 1.1 skrll /* Pseudo Debugging Support. */
1801 1.1 skrll
1802 1.1 skrll INSTR_T
1803 1.1 skrll bfin_gen_pseudodbg (int fn, int reg, int grp)
1804 1.1 skrll {
1805 1.1 skrll INIT (PseudoDbg);
1806 1.1 skrll
1807 1.1 skrll ASSIGN (fn);
1808 1.1 skrll ASSIGN (reg);
1809 1.1 skrll ASSIGN (grp);
1810 1.1 skrll
1811 1.1 skrll return GEN_OPCODE16 ();
1812 1.1 skrll }
1813 1.1 skrll
1814 1.1 skrll INSTR_T
1815 1.1 skrll bfin_gen_pseudodbg_assert (int dbgop, REG_T regtest, int expected)
1816 1.1.1.2 christos {
1817 1.1 skrll int grp;
1818 1.1 skrll INIT (PseudoDbg_Assert);
1819 1.1 skrll
1820 1.1 skrll ASSIGN (dbgop);
1821 1.1.1.2 christos ASSIGN_R (regtest);
1822 1.1.1.2 christos grp = GROUP (regtest);
1823 1.1 skrll ASSIGN (grp);
1824 1.1 skrll ASSIGN (expected);
1825 1.1 skrll
1826 1.1 skrll return GEN_OPCODE32 ();
1827 1.1 skrll }
1828 1.1.1.2 christos
1829 1.1.1.2 christos INSTR_T
1830 1.1.1.2 christos bfin_gen_pseudochr (int ch)
1831 1.1.1.2 christos {
1832 1.1.1.2 christos INIT (PseudoChr);
1833 1.1.1.2 christos
1834 1.1.1.2 christos ASSIGN (ch);
1835 1.1.1.2 christos
1836 1.1.1.2 christos return GEN_OPCODE16 ();
1837 1.1.1.2 christos }
1838 1.1 skrll
1839 1.1 skrll /* Multiple instruction generation. */
1840 1.1 skrll
1841 1.1 skrll INSTR_T
1842 1.1 skrll bfin_gen_multi_instr (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
1843 1.1 skrll {
1844 1.1 skrll INSTR_T walk;
1845 1.1 skrll
1846 1.1 skrll /* If it's a 0, convert into MNOP. */
1847 1.1 skrll if (dsp32)
1848 1.1 skrll {
1849 1.1 skrll walk = dsp32->next;
1850 1.1 skrll SET_MULTI_INSTRUCTION_BIT (dsp32);
1851 1.1 skrll }
1852 1.1 skrll else
1853 1.1 skrll {
1854 1.1 skrll dsp32 = gencode (0xc803);
1855 1.1 skrll walk = gencode (0x1800);
1856 1.1 skrll dsp32->next = walk;
1857 1.1 skrll }
1858 1.1 skrll
1859 1.1 skrll if (!dsp16_grp1)
1860 1.1 skrll {
1861 1.1 skrll dsp16_grp1 = gencode (0x0000);
1862 1.1 skrll }
1863 1.1 skrll
1864 1.1 skrll if (!dsp16_grp2)
1865 1.1 skrll {
1866 1.1 skrll dsp16_grp2 = gencode (0x0000);
1867 1.1 skrll }
1868 1.1 skrll
1869 1.1 skrll walk->next = dsp16_grp1;
1870 1.1 skrll dsp16_grp1->next = dsp16_grp2;
1871 1.1 skrll dsp16_grp2->next = NULL_CODE;
1872 1.1 skrll
1873 1.1 skrll return dsp32;
1874 1.1 skrll }
1875 1.1 skrll
1876 1.1.1.2 christos INSTR_T
1877 1.1 skrll bfin_gen_loop (Expr_Node *exp, REG_T reg, int rop, REG_T preg)
1878 1.1 skrll {
1879 1.1 skrll const char *loopsym;
1880 1.1 skrll char *lbeginsym, *lendsym;
1881 1.1 skrll Expr_Node_Value lbeginval, lendval;
1882 1.1.1.2 christos Expr_Node *lbegin, *lend;
1883 1.1 skrll symbolS *sym;
1884 1.1.1.2 christos
1885 1.1 skrll loopsym = exp->value.s_value;
1886 1.1 skrll lbeginsym = (char *) xmalloc (strlen (loopsym) + strlen ("__BEGIN") + 5);
1887 1.1 skrll lendsym = (char *) xmalloc (strlen (loopsym) + strlen ("__END") + 5);
1888 1.1 skrll
1889 1.1 skrll lbeginsym[0] = 0;
1890 1.1 skrll lendsym[0] = 0;
1891 1.1 skrll
1892 1.1 skrll strcat (lbeginsym, "L$L$");
1893 1.1 skrll strcat (lbeginsym, loopsym);
1894 1.1 skrll strcat (lbeginsym, "__BEGIN");
1895 1.1 skrll
1896 1.1 skrll strcat (lendsym, "L$L$");
1897 1.1 skrll strcat (lendsym, loopsym);
1898 1.1 skrll strcat (lendsym, "__END");
1899 1.1 skrll
1900 1.1 skrll lbeginval.s_value = lbeginsym;
1901 1.1 skrll lendval.s_value = lendsym;
1902 1.1 skrll
1903 1.1 skrll lbegin = Expr_Node_Create (Expr_Node_Reloc, lbeginval, NULL, NULL);
1904 1.1 skrll lend = Expr_Node_Create (Expr_Node_Reloc, lendval, NULL, NULL);
1905 1.1.1.2 christos
1906 1.1.1.2 christos sym = symbol_find(loopsym);
1907 1.1.1.2 christos if (!S_IS_LOCAL (sym) || (S_IS_LOCAL (sym) && !symbol_used_p (sym)))
1908 1.1.1.2 christos symbol_remove (sym, &symbol_rootP, &symbol_lastP);
1909 1.1.1.2 christos
1910 1.1.1.2 christos return bfin_gen_loopsetup (lbegin, reg, rop, lend, preg);
1911 1.1.1.2 christos }
1912 1.1.1.2 christos
1913 1.1.1.2 christos void
1914 1.1.1.2 christos bfin_loop_attempt_create_label (Expr_Node *exp, int is_begin)
1915 1.1.1.2 christos {
1916 1.1.1.2 christos char *name;
1917 1.1.1.2 christos name = fb_label_name (exp->value.i_value, is_begin);
1918 1.1.1.2 christos exp->value.s_value = xstrdup (name);
1919 1.1.1.2 christos exp->type = Expr_Node_Reloc;
1920 1.1.1.2 christos }
1921 1.1.1.2 christos
1922 1.1.1.2 christos void
1923 1.1.1.2 christos bfin_loop_beginend (Expr_Node *exp, int begin)
1924 1.1.1.2 christos {
1925 1.1.1.2 christos const char *loopsym;
1926 1.1.1.2 christos char *label_name;
1927 1.1.1.2 christos symbolS *linelabel;
1928 1.1.1.2 christos const char *suffix = begin ? "__BEGIN" : "__END";
1929 1.1.1.2 christos
1930 1.1.1.2 christos loopsym = exp->value.s_value;
1931 1.1.1.2 christos label_name = (char *) xmalloc (strlen (loopsym) + strlen (suffix) + 5);
1932 1.1.1.2 christos
1933 1.1.1.2 christos label_name[0] = 0;
1934 1.1.1.2 christos
1935 1.1.1.2 christos strcat (label_name, "L$L$");
1936 1.1.1.2 christos strcat (label_name, loopsym);
1937 1.1 skrll strcat (label_name, suffix);
1938 1.1.1.2 christos
1939 1.1.1.2 christos linelabel = colon (label_name);
1940 1.1.1.2 christos
1941 1.1.1.2 christos /* LOOP_END follows the last instruction in the loop.
1942 1.1.1.2 christos Adjust label address. */
1943 1.1.1.2 christos if (!begin)
1944 1.1 skrll ((struct local_symbol *) linelabel)->lsy_value -= last_insn_size;
1945 1.1 skrll }
1946 1.1 skrll
1947 1.1 skrll bfd_boolean
1948 1.1 skrll bfin_eol_in_insn (char *line)
1949 1.1 skrll {
1950 1.1 skrll /* Allow a new-line to appear in the middle of a multi-issue instruction. */
1951 1.1 skrll
1952 1.1 skrll char *temp = line;
1953 1.1 skrll
1954 1.1 skrll if (*line != '\n')
1955 1.1 skrll return FALSE;
1956 1.1 skrll
1957 1.1 skrll /* A semi-colon followed by a newline is always the end of a line. */
1958 1.1 skrll if (line[-1] == ';')
1959 1.1 skrll return FALSE;
1960 1.1 skrll
1961 1.1 skrll if (line[-1] == '|')
1962 1.1 skrll return TRUE;
1963 1.1 skrll
1964 1.1 skrll /* If the || is on the next line, there might be leading whitespace. */
1965 1.1 skrll temp++;
1966 1.1 skrll while (*temp == ' ' || *temp == '\t') temp++;
1967 1.1 skrll
1968 1.1 skrll if (*temp == '|')
1969 1.1 skrll return TRUE;
1970 1.1 skrll
1971 1.1 skrll return FALSE;
1972 1.1 skrll }
1973 1.1 skrll
1974 1.1.1.2 christos bfd_boolean
1975 1.1 skrll bfin_start_label (char *s, char *ptr)
1976 1.1.1.2 christos {
1977 1.1.1.2 christos while (s != ptr)
1978 1.1.1.2 christos {
1979 1.1.1.2 christos if (*s == '(' || *s == '[')
1980 1.1.1.2 christos return FALSE;
1981 1.1.1.2 christos s++;
1982 1.1 skrll }
1983 1.1 skrll
1984 1.1.1.2 christos return TRUE;
1985 1.1 skrll }
1986 1.1 skrll
1987 1.1 skrll int
1988 1.1 skrll bfin_force_relocation (struct fix *fixp)
1989 1.1 skrll {
1990 1.1 skrll if (fixp->fx_r_type ==BFD_RELOC_BFIN_16_LOW
1991 1.1 skrll || fixp->fx_r_type == BFD_RELOC_BFIN_16_HIGH)
1992 1.1 skrll return TRUE;
1993 1.1 skrll
1994 1.1 skrll return generic_force_reloc (fixp);
1995 1.1.1.2 christos }
1996 1.1.1.2 christos
1997 1.1.1.2 christos /* This is a stripped down version of the disassembler. The only thing it
1999 1.1.1.2 christos does is return a mask of registers modified by an instruction. Only
2000 1.1.1.2 christos instructions that can occur in a parallel-issue bundle are handled, and
2001 1.1.1.2 christos only the registers that can cause a conflict are recorded. */
2002 1.1.1.2 christos
2003 1.1.1.2 christos #define DREG_MASK(n) (0x101 << (n))
2004 1.1.1.2 christos #define DREGH_MASK(n) (0x100 << (n))
2005 1.1.1.2 christos #define DREGL_MASK(n) (0x001 << (n))
2006 1.1.1.2 christos #define IREG_MASK(n) (1 << ((n) + 16))
2007 1.1.1.2 christos
2008 1.1.1.2 christos static int
2009 1.1.1.2 christos decode_ProgCtrl_0 (int iw0)
2010 1.1.1.2 christos {
2011 1.1.1.2 christos if (iw0 == 0)
2012 1.1.1.2 christos return 0;
2013 1.1.1.2 christos abort ();
2014 1.1.1.2 christos }
2015 1.1.1.2 christos
2016 1.1.1.2 christos static int
2017 1.1.1.2 christos decode_LDSTpmod_0 (int iw0)
2018 1.1.1.2 christos {
2019 1.1.1.2 christos /* LDSTpmod
2020 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2021 1.1.1.2 christos | 1 | 0 | 0 | 0 |.W.|.aop...|.reg.......|.idx.......|.ptr.......|
2022 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2023 1.1.1.2 christos int W = ((iw0 >> LDSTpmod_W_bits) & LDSTpmod_W_mask);
2024 1.1.1.2 christos int aop = ((iw0 >> LDSTpmod_aop_bits) & LDSTpmod_aop_mask);
2025 1.1.1.2 christos int idx = ((iw0 >> LDSTpmod_idx_bits) & LDSTpmod_idx_mask);
2026 1.1.1.2 christos int ptr = ((iw0 >> LDSTpmod_ptr_bits) & LDSTpmod_ptr_mask);
2027 1.1.1.2 christos int reg = ((iw0 >> LDSTpmod_reg_bits) & LDSTpmod_reg_mask);
2028 1.1.1.2 christos
2029 1.1.1.2 christos if (aop == 1 && W == 0 && idx == ptr)
2030 1.1.1.2 christos return DREGL_MASK (reg);
2031 1.1.1.2 christos else if (aop == 2 && W == 0 && idx == ptr)
2032 1.1.1.2 christos return DREGH_MASK (reg);
2033 1.1.1.2 christos else if (aop == 1 && W == 1 && idx == ptr)
2034 1.1.1.2 christos return 0;
2035 1.1.1.2 christos else if (aop == 2 && W == 1 && idx == ptr)
2036 1.1.1.2 christos return 0;
2037 1.1.1.2 christos else if (aop == 0 && W == 0)
2038 1.1.1.2 christos return DREG_MASK (reg);
2039 1.1.1.2 christos else if (aop == 1 && W == 0)
2040 1.1.1.2 christos return DREGL_MASK (reg);
2041 1.1.1.2 christos else if (aop == 2 && W == 0)
2042 1.1.1.2 christos return DREGH_MASK (reg);
2043 1.1.1.2 christos else if (aop == 3 && W == 0)
2044 1.1.1.2 christos return DREG_MASK (reg);
2045 1.1.1.2 christos else if (aop == 3 && W == 1)
2046 1.1.1.2 christos return DREG_MASK (reg);
2047 1.1.1.2 christos else if (aop == 0 && W == 1)
2048 1.1.1.2 christos return 0;
2049 1.1.1.2 christos else if (aop == 1 && W == 1)
2050 1.1.1.2 christos return 0;
2051 1.1.1.2 christos else if (aop == 2 && W == 1)
2052 1.1.1.2 christos return 0;
2053 1.1.1.2 christos else
2054 1.1.1.2 christos return 0;
2055 1.1.1.2 christos
2056 1.1.1.2 christos return 2;
2057 1.1.1.2 christos }
2058 1.1.1.2 christos
2059 1.1.1.2 christos static int
2060 1.1.1.2 christos decode_dagMODim_0 (int iw0)
2061 1.1.1.2 christos {
2062 1.1.1.2 christos /* dagMODim
2063 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2064 1.1.1.2 christos | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 |.br| 1 | 1 |.op|.m.....|.i.....|
2065 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2066 1.1.1.2 christos int i = ((iw0 >> DagMODim_i_bits) & DagMODim_i_mask);
2067 1.1.1.2 christos int opc = ((iw0 >> DagMODim_op_bits) & DagMODim_op_mask);
2068 1.1.1.2 christos
2069 1.1.1.2 christos if (opc == 0 || opc == 1)
2070 1.1.1.2 christos return IREG_MASK (i);
2071 1.1.1.2 christos else
2072 1.1.1.2 christos return 0;
2073 1.1.1.2 christos
2074 1.1.1.2 christos return 2;
2075 1.1.1.2 christos }
2076 1.1.1.2 christos
2077 1.1.1.2 christos static int
2078 1.1.1.2 christos decode_dagMODik_0 (int iw0)
2079 1.1.1.2 christos {
2080 1.1.1.2 christos /* dagMODik
2081 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2082 1.1.1.2 christos | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 |.op....|.i.....|
2083 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2084 1.1.1.2 christos int i = ((iw0 >> DagMODik_i_bits) & DagMODik_i_mask);
2085 1.1.1.2 christos return IREG_MASK (i);
2086 1.1.1.2 christos }
2087 1.1.1.2 christos
2088 1.1.1.2 christos /* GOOD */
2089 1.1.1.2 christos static int
2090 1.1.1.2 christos decode_dspLDST_0 (int iw0)
2091 1.1.1.2 christos {
2092 1.1.1.2 christos /* dspLDST
2093 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2094 1.1.1.2 christos | 1 | 0 | 0 | 1 | 1 | 1 |.W.|.aop...|.m.....|.i.....|.reg.......|
2095 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2096 1.1.1.2 christos int i = ((iw0 >> DspLDST_i_bits) & DspLDST_i_mask);
2097 1.1.1.2 christos int m = ((iw0 >> DspLDST_m_bits) & DspLDST_m_mask);
2098 1.1.1.2 christos int W = ((iw0 >> DspLDST_W_bits) & DspLDST_W_mask);
2099 1.1.1.2 christos int aop = ((iw0 >> DspLDST_aop_bits) & DspLDST_aop_mask);
2100 1.1.1.2 christos int reg = ((iw0 >> DspLDST_reg_bits) & DspLDST_reg_mask);
2101 1.1.1.2 christos
2102 1.1.1.2 christos if (aop == 0 && W == 0 && m == 0)
2103 1.1.1.2 christos return DREG_MASK (reg) | IREG_MASK (i);
2104 1.1.1.2 christos else if (aop == 0 && W == 0 && m == 1)
2105 1.1.1.2 christos return DREGL_MASK (reg) | IREG_MASK (i);
2106 1.1.1.2 christos else if (aop == 0 && W == 0 && m == 2)
2107 1.1.1.2 christos return DREGH_MASK (reg) | IREG_MASK (i);
2108 1.1.1.2 christos else if (aop == 1 && W == 0 && m == 0)
2109 1.1.1.2 christos return DREG_MASK (reg) | IREG_MASK (i);
2110 1.1.1.2 christos else if (aop == 1 && W == 0 && m == 1)
2111 1.1.1.2 christos return DREGL_MASK (reg) | IREG_MASK (i);
2112 1.1.1.2 christos else if (aop == 1 && W == 0 && m == 2)
2113 1.1.1.2 christos return DREGH_MASK (reg) | IREG_MASK (i);
2114 1.1.1.2 christos else if (aop == 2 && W == 0 && m == 0)
2115 1.1.1.2 christos return DREG_MASK (reg);
2116 1.1.1.2 christos else if (aop == 2 && W == 0 && m == 1)
2117 1.1.1.2 christos return DREGL_MASK (reg);
2118 1.1.1.2 christos else if (aop == 2 && W == 0 && m == 2)
2119 1.1.1.2 christos return DREGH_MASK (reg);
2120 1.1.1.2 christos else if (aop == 0 && W == 1 && m == 0)
2121 1.1.1.2 christos return IREG_MASK (i);
2122 1.1.1.2 christos else if (aop == 0 && W == 1 && m == 1)
2123 1.1.1.2 christos return IREG_MASK (i);
2124 1.1.1.2 christos else if (aop == 0 && W == 1 && m == 2)
2125 1.1.1.2 christos return IREG_MASK (i);
2126 1.1.1.2 christos else if (aop == 1 && W == 1 && m == 0)
2127 1.1.1.2 christos return IREG_MASK (i);
2128 1.1.1.2 christos else if (aop == 1 && W == 1 && m == 1)
2129 1.1.1.2 christos return IREG_MASK (i);
2130 1.1.1.2 christos else if (aop == 1 && W == 1 && m == 2)
2131 1.1.1.2 christos return IREG_MASK (i);
2132 1.1.1.2 christos else if (aop == 2 && W == 1 && m == 0)
2133 1.1.1.2 christos return 0;
2134 1.1.1.2 christos else if (aop == 2 && W == 1 && m == 1)
2135 1.1.1.2 christos return 0;
2136 1.1.1.2 christos else if (aop == 2 && W == 1 && m == 2)
2137 1.1.1.2 christos return 0;
2138 1.1.1.2 christos else if (aop == 3 && W == 0)
2139 1.1.1.2 christos return DREG_MASK (reg) | IREG_MASK (i);
2140 1.1.1.2 christos else if (aop == 3 && W == 1)
2141 1.1.1.2 christos return IREG_MASK (i);
2142 1.1.1.2 christos
2143 1.1.1.2 christos abort ();
2144 1.1.1.2 christos }
2145 1.1.1.2 christos
2146 1.1.1.2 christos /* GOOD */
2147 1.1.1.2 christos static int
2148 1.1.1.2 christos decode_LDST_0 (int iw0)
2149 1.1.1.2 christos {
2150 1.1.1.2 christos /* LDST
2151 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2152 1.1.1.2 christos | 1 | 0 | 0 | 1 |.sz....|.W.|.aop...|.Z.|.ptr.......|.reg.......|
2153 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2154 1.1.1.2 christos int Z = ((iw0 >> LDST_Z_bits) & LDST_Z_mask);
2155 1.1.1.2 christos int W = ((iw0 >> LDST_W_bits) & LDST_W_mask);
2156 1.1.1.2 christos int sz = ((iw0 >> LDST_sz_bits) & LDST_sz_mask);
2157 1.1.1.2 christos int aop = ((iw0 >> LDST_aop_bits) & LDST_aop_mask);
2158 1.1.1.2 christos int reg = ((iw0 >> LDST_reg_bits) & LDST_reg_mask);
2159 1.1.1.2 christos
2160 1.1.1.2 christos if (aop == 0 && sz == 0 && Z == 0 && W == 0)
2161 1.1.1.2 christos return DREG_MASK (reg);
2162 1.1.1.2 christos else if (aop == 0 && sz == 0 && Z == 1 && W == 0)
2163 1.1.1.2 christos return 0;
2164 1.1.1.2 christos else if (aop == 0 && sz == 1 && Z == 0 && W == 0)
2165 1.1.1.2 christos return DREG_MASK (reg);
2166 1.1.1.2 christos else if (aop == 0 && sz == 1 && Z == 1 && W == 0)
2167 1.1.1.2 christos return DREG_MASK (reg);
2168 1.1.1.2 christos else if (aop == 0 && sz == 2 && Z == 0 && W == 0)
2169 1.1.1.2 christos return DREG_MASK (reg);
2170 1.1.1.2 christos else if (aop == 0 && sz == 2 && Z == 1 && W == 0)
2171 1.1.1.2 christos return DREG_MASK (reg);
2172 1.1.1.2 christos else if (aop == 1 && sz == 0 && Z == 0 && W == 0)
2173 1.1.1.2 christos return DREG_MASK (reg);
2174 1.1.1.2 christos else if (aop == 1 && sz == 0 && Z == 1 && W == 0)
2175 1.1.1.2 christos return 0;
2176 1.1.1.2 christos else if (aop == 1 && sz == 1 && Z == 0 && W == 0)
2177 1.1.1.2 christos return DREG_MASK (reg);
2178 1.1.1.2 christos else if (aop == 1 && sz == 1 && Z == 1 && W == 0)
2179 1.1.1.2 christos return DREG_MASK (reg);
2180 1.1.1.2 christos else if (aop == 1 && sz == 2 && Z == 0 && W == 0)
2181 1.1.1.2 christos return DREG_MASK (reg);
2182 1.1.1.2 christos else if (aop == 1 && sz == 2 && Z == 1 && W == 0)
2183 1.1.1.2 christos return DREG_MASK (reg);
2184 1.1.1.2 christos else if (aop == 2 && sz == 0 && Z == 0 && W == 0)
2185 1.1.1.2 christos return DREG_MASK (reg);
2186 1.1.1.2 christos else if (aop == 2 && sz == 0 && Z == 1 && W == 0)
2187 1.1.1.2 christos return 0;
2188 1.1.1.2 christos else if (aop == 2 && sz == 1 && Z == 0 && W == 0)
2189 1.1.1.2 christos return DREG_MASK (reg);
2190 1.1.1.2 christos else if (aop == 2 && sz == 1 && Z == 1 && W == 0)
2191 1.1.1.2 christos return DREG_MASK (reg);
2192 1.1.1.2 christos else if (aop == 2 && sz == 2 && Z == 0 && W == 0)
2193 1.1.1.2 christos return DREG_MASK (reg);
2194 1.1.1.2 christos else if (aop == 2 && sz == 2 && Z == 1 && W == 0)
2195 1.1.1.2 christos return DREG_MASK (reg);
2196 1.1.1.2 christos else if (aop == 0 && sz == 0 && Z == 0 && W == 1)
2197 1.1.1.2 christos return 0;
2198 1.1.1.2 christos else if (aop == 0 && sz == 0 && Z == 1 && W == 1)
2199 1.1.1.2 christos return 0;
2200 1.1.1.2 christos else if (aop == 0 && sz == 1 && Z == 0 && W == 1)
2201 1.1.1.2 christos return 0;
2202 1.1.1.2 christos else if (aop == 0 && sz == 2 && Z == 0 && W == 1)
2203 1.1.1.2 christos return 0;
2204 1.1.1.2 christos else if (aop == 1 && sz == 0 && Z == 0 && W == 1)
2205 1.1.1.2 christos return 0;
2206 1.1.1.2 christos else if (aop == 1 && sz == 0 && Z == 1 && W == 1)
2207 1.1.1.2 christos return 0;
2208 1.1.1.2 christos else if (aop == 1 && sz == 1 && Z == 0 && W == 1)
2209 1.1.1.2 christos return 0;
2210 1.1.1.2 christos else if (aop == 1 && sz == 2 && Z == 0 && W == 1)
2211 1.1.1.2 christos return 0;
2212 1.1.1.2 christos else if (aop == 2 && sz == 0 && Z == 0 && W == 1)
2213 1.1.1.2 christos return 0;
2214 1.1.1.2 christos else if (aop == 2 && sz == 0 && Z == 1 && W == 1)
2215 1.1.1.2 christos return 0;
2216 1.1.1.2 christos else if (aop == 2 && sz == 1 && Z == 0 && W == 1)
2217 1.1.1.2 christos return 0;
2218 1.1.1.2 christos else if (aop == 2 && sz == 2 && Z == 0 && W == 1)
2219 1.1.1.2 christos return 0;
2220 1.1.1.2 christos
2221 1.1.1.2 christos abort ();
2222 1.1.1.2 christos }
2223 1.1.1.2 christos
2224 1.1.1.2 christos static int
2225 1.1.1.2 christos decode_LDSTiiFP_0 (int iw0)
2226 1.1.1.2 christos {
2227 1.1.1.2 christos /* LDSTiiFP
2228 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2229 1.1.1.2 christos | 1 | 0 | 1 | 1 | 1 | 0 |.W.|.offset............|.reg...........|
2230 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2231 1.1.1.2 christos int reg = ((iw0 >> LDSTiiFP_reg_bits) & LDSTiiFP_reg_mask);
2232 1.1.1.2 christos int W = ((iw0 >> LDSTiiFP_W_bits) & LDSTiiFP_W_mask);
2233 1.1.1.2 christos
2234 1.1.1.2 christos if (W == 0)
2235 1.1.1.2 christos return reg < 8 ? DREG_MASK (reg) : 0;
2236 1.1.1.2 christos else
2237 1.1.1.2 christos return 0;
2238 1.1.1.2 christos }
2239 1.1.1.2 christos
2240 1.1.1.2 christos static int
2241 1.1.1.2 christos decode_LDSTii_0 (int iw0)
2242 1.1.1.2 christos {
2243 1.1.1.2 christos /* LDSTii
2244 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2245 1.1.1.2 christos | 1 | 0 | 1 |.W.|.op....|.offset........|.ptr.......|.reg.......|
2246 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2247 1.1.1.2 christos int reg = ((iw0 >> LDSTii_reg_bit) & LDSTii_reg_mask);
2248 1.1.1.2 christos int opc = ((iw0 >> LDSTii_op_bit) & LDSTii_op_mask);
2249 1.1.1.2 christos int W = ((iw0 >> LDSTii_W_bit) & LDSTii_W_mask);
2250 1.1.1.2 christos
2251 1.1.1.2 christos if (W == 0 && opc != 3)
2252 1.1.1.2 christos return DREG_MASK (reg);
2253 1.1.1.2 christos else if (W == 0 && opc == 3)
2254 1.1.1.2 christos return 0;
2255 1.1.1.2 christos else if (W == 1 && opc == 0)
2256 1.1.1.2 christos return 0;
2257 1.1.1.2 christos else if (W == 1 && opc == 1)
2258 1.1.1.2 christos return 0;
2259 1.1.1.2 christos else if (W == 1 && opc == 3)
2260 1.1.1.2 christos return 0;
2261 1.1.1.2 christos
2262 1.1.1.2 christos abort ();
2263 1.1.1.2 christos }
2264 1.1.1.2 christos
2265 1.1.1.2 christos static int
2266 1.1.1.2 christos decode_dsp32mac_0 (int iw0, int iw1)
2267 1.1.1.2 christos {
2268 1.1.1.2 christos int result = 0;
2269 1.1.1.2 christos /* dsp32mac
2270 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2271 1.1.1.2 christos | 1 | 1 | 0 | 0 |.M.| 0 | 0 |.mmod..........|.MM|.P.|.w1|.op1...|
2272 1.1.1.2 christos |.h01|.h11|.w0|.op0...|.h00|.h10|.dst.......|.src0......|.src1..|
2273 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2274 1.1.1.2 christos int op1 = ((iw0 >> (DSP32Mac_op1_bits - 16)) & DSP32Mac_op1_mask);
2275 1.1.1.2 christos int w1 = ((iw0 >> (DSP32Mac_w1_bits - 16)) & DSP32Mac_w1_mask);
2276 1.1.1.2 christos int P = ((iw0 >> (DSP32Mac_p_bits - 16)) & DSP32Mac_p_mask);
2277 1.1.1.2 christos int mmod = ((iw0 >> (DSP32Mac_mmod_bits - 16)) & DSP32Mac_mmod_mask);
2278 1.1.1.2 christos int w0 = ((iw1 >> DSP32Mac_w0_bits) & DSP32Mac_w0_mask);
2279 1.1.1.2 christos int MM = ((iw1 >> DSP32Mac_MM_bits) & DSP32Mac_MM_mask);
2280 1.1.1.2 christos int dst = ((iw1 >> DSP32Mac_dst_bits) & DSP32Mac_dst_mask);
2281 1.1.1.2 christos int op0 = ((iw1 >> DSP32Mac_op0_bits) & DSP32Mac_op0_mask);
2282 1.1.1.2 christos
2283 1.1.1.2 christos if (w0 == 0 && w1 == 0 && op1 == 3 && op0 == 3)
2284 1.1.1.2 christos return 0;
2285 1.1.1.2 christos
2286 1.1.1.2 christos if (op1 == 3 && MM)
2287 1.1.1.2 christos return 0;
2288 1.1.1.2 christos
2289 1.1.1.2 christos if ((w1 || w0) && mmod == M_W32)
2290 1.1.1.2 christos return 0;
2291 1.1.1.2 christos
2292 1.1.1.2 christos if (((1 << mmod) & (P ? 0x131b : 0x1b5f)) == 0)
2293 1.1.1.2 christos return 0;
2294 1.1.1.2 christos
2295 1.1.1.2 christos if (w1 == 1 || op1 != 3)
2296 1.1.1.2 christos {
2297 1.1.1.2 christos if (w1)
2298 1.1.1.2 christos {
2299 1.1.1.2 christos if (P)
2300 1.1.1.2 christos return DREG_MASK (dst + 1);
2301 1.1.1.2 christos else
2302 1.1.1.2 christos return DREGH_MASK (dst);
2303 1.1.1.2 christos }
2304 1.1.1.2 christos }
2305 1.1.1.2 christos
2306 1.1.1.2 christos if (w0 == 1 || op0 != 3)
2307 1.1.1.2 christos {
2308 1.1.1.2 christos if (w0)
2309 1.1.1.2 christos {
2310 1.1.1.2 christos if (P)
2311 1.1.1.2 christos return DREG_MASK (dst);
2312 1.1.1.2 christos else
2313 1.1.1.2 christos return DREGL_MASK (dst);
2314 1.1.1.2 christos }
2315 1.1.1.2 christos }
2316 1.1.1.2 christos
2317 1.1.1.2 christos return result;
2318 1.1.1.2 christos }
2319 1.1.1.2 christos
2320 1.1.1.2 christos static int
2321 1.1.1.2 christos decode_dsp32mult_0 (int iw0, int iw1)
2322 1.1.1.2 christos {
2323 1.1.1.2 christos /* dsp32mult
2324 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2325 1.1.1.2 christos | 1 | 1 | 0 | 0 |.M.| 0 | 1 |.mmod..........|.MM|.P.|.w1|.op1...|
2326 1.1.1.2 christos |.h01|.h11|.w0|.op0...|.h00|.h10|.dst.......|.src0......|.src1..|
2327 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2328 1.1.1.2 christos int w1 = ((iw0 >> (DSP32Mac_w1_bits - 16)) & DSP32Mac_w1_mask);
2329 1.1.1.2 christos int P = ((iw0 >> (DSP32Mac_p_bits - 16)) & DSP32Mac_p_mask);
2330 1.1.1.2 christos int mmod = ((iw0 >> (DSP32Mac_mmod_bits - 16)) & DSP32Mac_mmod_mask);
2331 1.1.1.2 christos int w0 = ((iw1 >> DSP32Mac_w0_bits) & DSP32Mac_w0_mask);
2332 1.1.1.2 christos int dst = ((iw1 >> DSP32Mac_dst_bits) & DSP32Mac_dst_mask);
2333 1.1.1.2 christos int result = 0;
2334 1.1.1.2 christos
2335 1.1.1.2 christos if (w1 == 0 && w0 == 0)
2336 1.1.1.2 christos return 0;
2337 1.1.1.2 christos
2338 1.1.1.2 christos if (((1 << mmod) & (P ? 0x313 : 0x1b57)) == 0)
2339 1.1.1.2 christos return 0;
2340 1.1.1.2 christos
2341 1.1.1.2 christos if (w1)
2342 1.1.1.2 christos {
2343 1.1.1.2 christos if (P)
2344 1.1.1.2 christos return DREG_MASK (dst | 1);
2345 1.1.1.2 christos else
2346 1.1.1.2 christos return DREGH_MASK (dst);
2347 1.1.1.2 christos }
2348 1.1.1.2 christos
2349 1.1.1.2 christos if (w0)
2350 1.1.1.2 christos {
2351 1.1.1.2 christos if (P)
2352 1.1.1.2 christos return DREG_MASK (dst);
2353 1.1.1.2 christos else
2354 1.1.1.2 christos return DREGL_MASK (dst);
2355 1.1.1.2 christos }
2356 1.1.1.2 christos
2357 1.1.1.2 christos return result;
2358 1.1.1.2 christos }
2359 1.1.1.2 christos
2360 1.1.1.2 christos static int
2361 1.1.1.2 christos decode_dsp32alu_0 (int iw0, int iw1)
2362 1.1.1.2 christos {
2363 1.1.1.2 christos /* dsp32alu
2364 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2365 1.1.1.2 christos | 1 | 1 | 0 | 0 |.M.| 1 | 0 | - | - | - |.HL|.aopcde............|
2366 1.1.1.2 christos |.aop...|.s.|.x.|.dst0......|.dst1......|.src0......|.src1......|
2367 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2368 1.1.1.2 christos int s = ((iw1 >> DSP32Alu_s_bits) & DSP32Alu_s_mask);
2369 1.1.1.2 christos int x = ((iw1 >> DSP32Alu_x_bits) & DSP32Alu_x_mask);
2370 1.1.1.2 christos int aop = ((iw1 >> DSP32Alu_aop_bits) & DSP32Alu_aop_mask);
2371 1.1.1.2 christos int dst0 = ((iw1 >> DSP32Alu_dst0_bits) & DSP32Alu_dst0_mask);
2372 1.1.1.2 christos int dst1 = ((iw1 >> DSP32Alu_dst1_bits) & DSP32Alu_dst1_mask);
2373 1.1.1.2 christos int HL = ((iw0 >> (DSP32Alu_HL_bits - 16)) & DSP32Alu_HL_mask);
2374 1.1.1.2 christos int aopcde = ((iw0 >> (DSP32Alu_aopcde_bits - 16)) & DSP32Alu_aopcde_mask);
2375 1.1.1.2 christos
2376 1.1.1.2 christos if (aop == 0 && aopcde == 9 && s == 0)
2377 1.1.1.2 christos return 0;
2378 1.1.1.2 christos else if (aop == 2 && aopcde == 9 && HL == 0 && s == 0)
2379 1.1.1.2 christos return 0;
2380 1.1.1.2 christos else if (aop >= x * 2 && aopcde == 5)
2381 1.1.1.2 christos return HL ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2382 1.1.1.2 christos else if (HL == 0 && aopcde == 2)
2383 1.1.1.2 christos return DREGL_MASK (dst0);
2384 1.1.1.2 christos else if (HL == 1 && aopcde == 2)
2385 1.1.1.2 christos return DREGH_MASK (dst0);
2386 1.1.1.2 christos else if (HL == 0 && aopcde == 3)
2387 1.1.1.2 christos return DREGL_MASK (dst0);
2388 1.1.1.2 christos else if (HL == 1 && aopcde == 3)
2389 1.1.1.2 christos return DREGH_MASK (dst0);
2390 1.1.1.2 christos
2391 1.1.1.2 christos else if (aop == 0 && aopcde == 9 && s == 1)
2392 1.1.1.2 christos return 0;
2393 1.1.1.2 christos else if (aop == 1 && aopcde == 9 && s == 0)
2394 1.1.1.2 christos return 0;
2395 1.1.1.2 christos else if (aop == 2 && aopcde == 9 && s == 1)
2396 1.1.1.2 christos return 0;
2397 1.1.1.2 christos else if (aop == 3 && aopcde == 9 && s == 0)
2398 1.1.1.2 christos return 0;
2399 1.1.1.2 christos else if (aopcde == 8)
2400 1.1.1.2 christos return 0;
2401 1.1.1.2 christos else if (aop == 0 && aopcde == 11)
2402 1.1.1.2 christos return DREG_MASK (dst0);
2403 1.1.1.2 christos else if (aop == 1 && aopcde == 11)
2404 1.1.1.2 christos return HL ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2405 1.1.1.2 christos else if (aopcde == 11)
2406 1.1.1.2 christos return 0;
2407 1.1.1.2 christos else if (aopcde == 22)
2408 1.1.1.2 christos return DREG_MASK (dst0);
2409 1.1.1.2 christos
2410 1.1.1.2 christos else if ((aop == 0 || aop == 1) && aopcde == 14)
2411 1.1.1.2 christos return 0;
2412 1.1.1.2 christos else if (aop == 3 && HL == 0 && aopcde == 14)
2413 1.1.1.2 christos return 0;
2414 1.1.1.2 christos
2415 1.1.1.2 christos else if (aop == 3 && HL == 0 && aopcde == 15)
2416 1.1.1.2 christos return DREG_MASK (dst0);
2417 1.1.1.2 christos
2418 1.1.1.2 christos else if (aop == 1 && aopcde == 16)
2419 1.1.1.2 christos return 0;
2420 1.1.1.2 christos
2421 1.1.1.2 christos else if (aop == 0 && aopcde == 16)
2422 1.1.1.2 christos return 0;
2423 1.1.1.2 christos
2424 1.1.1.2 christos else if (aop == 3 && HL == 0 && aopcde == 16)
2425 1.1.1.2 christos return 0;
2426 1.1.1.2 christos
2427 1.1.1.2 christos else if (aop == 3 && HL == 0 && aopcde == 7)
2428 1.1.1.2 christos return DREG_MASK (dst0);
2429 1.1.1.2 christos else if ((aop == 0 || aop == 1 || aop == 2) && aopcde == 7)
2430 1.1.1.2 christos return DREG_MASK (dst0);
2431 1.1.1.2 christos
2432 1.1.1.2 christos else if (aop == 0 && aopcde == 12)
2433 1.1.1.2 christos return DREG_MASK (dst0);
2434 1.1.1.2 christos else if (aop == 1 && aopcde == 12)
2435 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2436 1.1.1.2 christos else if (aop == 3 && aopcde == 12)
2437 1.1.1.2 christos return HL ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2438 1.1.1.2 christos
2439 1.1.1.2 christos else if (aopcde == 0)
2440 1.1.1.2 christos return DREG_MASK (dst0);
2441 1.1.1.2 christos else if (aopcde == 1)
2442 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2443 1.1.1.2 christos
2444 1.1.1.2 christos else if (aop == 0 && aopcde == 10)
2445 1.1.1.2 christos return DREGL_MASK (dst0);
2446 1.1.1.2 christos else if (aop == 1 && aopcde == 10)
2447 1.1.1.2 christos return DREGL_MASK (dst0);
2448 1.1.1.2 christos
2449 1.1.1.2 christos else if ((aop == 1 || aop == 0) && aopcde == 4)
2450 1.1.1.2 christos return DREG_MASK (dst0);
2451 1.1.1.2 christos else if (aop == 2 && aopcde == 4)
2452 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2453 1.1.1.2 christos
2454 1.1.1.2 christos else if (aop == 0 && aopcde == 17)
2455 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2456 1.1.1.2 christos else if (aop == 1 && aopcde == 17)
2457 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2458 1.1.1.2 christos else if (aop == 0 && aopcde == 18)
2459 1.1.1.2 christos return 0;
2460 1.1.1.2 christos else if (aop == 3 && aopcde == 18)
2461 1.1.1.2 christos return 0;
2462 1.1.1.2 christos
2463 1.1.1.2 christos else if ((aop == 0 || aop == 1 || aop == 2) && aopcde == 6)
2464 1.1.1.2 christos return DREG_MASK (dst0);
2465 1.1.1.2 christos
2466 1.1.1.2 christos else if ((aop == 0 || aop == 1) && aopcde == 20)
2467 1.1.1.2 christos return DREG_MASK (dst0);
2468 1.1.1.2 christos
2469 1.1.1.2 christos else if ((aop == 0 || aop == 1) && aopcde == 21)
2470 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2471 1.1.1.2 christos
2472 1.1.1.2 christos else if (aop == 0 && aopcde == 23 && HL == 1)
2473 1.1.1.2 christos return DREG_MASK (dst0);
2474 1.1.1.2 christos else if (aop == 0 && aopcde == 23 && HL == 0)
2475 1.1.1.2 christos return DREG_MASK (dst0);
2476 1.1.1.2 christos
2477 1.1.1.2 christos else if (aop == 0 && aopcde == 24)
2478 1.1.1.2 christos return DREG_MASK (dst0);
2479 1.1.1.2 christos else if (aop == 1 && aopcde == 24)
2480 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2481 1.1.1.2 christos else if (aopcde == 13)
2482 1.1.1.2 christos return DREG_MASK (dst0) | DREG_MASK (dst1);
2483 1.1.1.2 christos else
2484 1.1.1.2 christos return 0;
2485 1.1.1.2 christos
2486 1.1.1.2 christos return 4;
2487 1.1.1.2 christos }
2488 1.1.1.2 christos
2489 1.1.1.2 christos static int
2490 1.1.1.2 christos decode_dsp32shift_0 (int iw0, int iw1)
2491 1.1.1.2 christos {
2492 1.1.1.2 christos /* dsp32shift
2493 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2494 1.1.1.2 christos | 1 | 1 | 0 | 0 |.M.| 1 | 1 | 0 | 0 | - | - |.sopcde............|
2495 1.1.1.2 christos |.sop...|.HLs...|.dst0......| - | - | - |.src0......|.src1......|
2496 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2497 1.1.1.2 christos int HLs = ((iw1 >> DSP32Shift_HLs_bits) & DSP32Shift_HLs_mask);
2498 1.1.1.2 christos int sop = ((iw1 >> DSP32Shift_sop_bits) & DSP32Shift_sop_mask);
2499 1.1.1.2 christos int src0 = ((iw1 >> DSP32Shift_src0_bits) & DSP32Shift_src0_mask);
2500 1.1.1.2 christos int src1 = ((iw1 >> DSP32Shift_src1_bits) & DSP32Shift_src1_mask);
2501 1.1.1.2 christos int dst0 = ((iw1 >> DSP32Shift_dst0_bits) & DSP32Shift_dst0_mask);
2502 1.1.1.2 christos int sopcde = ((iw0 >> (DSP32Shift_sopcde_bits - 16)) & DSP32Shift_sopcde_mask);
2503 1.1.1.2 christos
2504 1.1.1.2 christos if (sop == 0 && sopcde == 0)
2505 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2506 1.1.1.2 christos else if (sop == 1 && sopcde == 0)
2507 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2508 1.1.1.2 christos else if (sop == 2 && sopcde == 0)
2509 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2510 1.1.1.2 christos else if (sop == 0 && sopcde == 3)
2511 1.1.1.2 christos return 0;
2512 1.1.1.2 christos else if (sop == 1 && sopcde == 3)
2513 1.1.1.2 christos return 0;
2514 1.1.1.2 christos else if (sop == 2 && sopcde == 3)
2515 1.1.1.2 christos return 0;
2516 1.1.1.2 christos else if (sop == 3 && sopcde == 3)
2517 1.1.1.2 christos return DREG_MASK (dst0);
2518 1.1.1.2 christos else if (sop == 0 && sopcde == 1)
2519 1.1.1.2 christos return DREG_MASK (dst0);
2520 1.1.1.2 christos else if (sop == 1 && sopcde == 1)
2521 1.1.1.2 christos return DREG_MASK (dst0);
2522 1.1.1.2 christos else if (sop == 2 && sopcde == 1)
2523 1.1.1.2 christos return DREG_MASK (dst0);
2524 1.1.1.2 christos else if (sopcde == 2)
2525 1.1.1.2 christos return DREG_MASK (dst0);
2526 1.1.1.2 christos else if (sopcde == 4)
2527 1.1.1.2 christos return DREG_MASK (dst0);
2528 1.1.1.2 christos else if (sop == 0 && sopcde == 5)
2529 1.1.1.2 christos return DREGL_MASK (dst0);
2530 1.1.1.2 christos else if (sop == 1 && sopcde == 5)
2531 1.1.1.2 christos return DREGL_MASK (dst0);
2532 1.1.1.2 christos else if (sop == 2 && sopcde == 5)
2533 1.1.1.2 christos return DREGL_MASK (dst0);
2534 1.1.1.2 christos else if (sop == 0 && sopcde == 6)
2535 1.1.1.2 christos return DREGL_MASK (dst0);
2536 1.1.1.2 christos else if (sop == 1 && sopcde == 6)
2537 1.1.1.2 christos return DREGL_MASK (dst0);
2538 1.1.1.2 christos else if (sop == 3 && sopcde == 6)
2539 1.1.1.2 christos return DREGL_MASK (dst0);
2540 1.1.1.2 christos else if (sop == 0 && sopcde == 7)
2541 1.1.1.2 christos return DREGL_MASK (dst0);
2542 1.1.1.2 christos else if (sop == 1 && sopcde == 7)
2543 1.1.1.2 christos return DREGL_MASK (dst0);
2544 1.1.1.2 christos else if (sop == 2 && sopcde == 7)
2545 1.1.1.2 christos return DREGL_MASK (dst0);
2546 1.1.1.2 christos else if (sop == 3 && sopcde == 7)
2547 1.1.1.2 christos return DREGL_MASK (dst0);
2548 1.1.1.2 christos else if (sop == 0 && sopcde == 8)
2549 1.1.1.2 christos return DREG_MASK (src0) | DREG_MASK (src1);
2550 1.1.1.2 christos #if 0
2551 1.1.1.2 christos {
2552 1.1.1.2 christos OUTS (outf, "BITMUX (");
2553 1.1.1.2 christos OUTS (outf, dregs (src0));
2554 1.1.1.2 christos OUTS (outf, ", ");
2555 1.1.1.2 christos OUTS (outf, dregs (src1));
2556 1.1.1.2 christos OUTS (outf, ", A0) (ASR)");
2557 1.1.1.2 christos }
2558 1.1.1.2 christos #endif
2559 1.1.1.2 christos else if (sop == 1 && sopcde == 8)
2560 1.1.1.2 christos return DREG_MASK (src0) | DREG_MASK (src1);
2561 1.1.1.2 christos #if 0
2562 1.1.1.2 christos {
2563 1.1.1.2 christos OUTS (outf, "BITMUX (");
2564 1.1.1.2 christos OUTS (outf, dregs (src0));
2565 1.1.1.2 christos OUTS (outf, ", ");
2566 1.1.1.2 christos OUTS (outf, dregs (src1));
2567 1.1.1.2 christos OUTS (outf, ", A0) (ASL)");
2568 1.1.1.2 christos }
2569 1.1.1.2 christos #endif
2570 1.1.1.2 christos else if (sopcde == 9)
2571 1.1.1.2 christos return sop < 2 ? DREGL_MASK (dst0) : DREG_MASK (dst0);
2572 1.1.1.2 christos else if (sopcde == 10)
2573 1.1.1.2 christos return DREG_MASK (dst0);
2574 1.1.1.2 christos else if (sop == 0 && sopcde == 11)
2575 1.1.1.2 christos return DREGL_MASK (dst0);
2576 1.1.1.2 christos else if (sop == 1 && sopcde == 11)
2577 1.1.1.2 christos return DREGL_MASK (dst0);
2578 1.1.1.2 christos else if (sop == 0 && sopcde == 12)
2579 1.1.1.2 christos return 0;
2580 1.1.1.2 christos else if (sop == 1 && sopcde == 12)
2581 1.1.1.2 christos return DREGL_MASK (dst0);
2582 1.1.1.2 christos else if (sop == 0 && sopcde == 13)
2583 1.1.1.2 christos return DREG_MASK (dst0);
2584 1.1.1.2 christos else if (sop == 1 && sopcde == 13)
2585 1.1.1.2 christos return DREG_MASK (dst0);
2586 1.1.1.2 christos else if (sop == 2 && sopcde == 13)
2587 1.1.1.2 christos return DREG_MASK (dst0);
2588 1.1.1.2 christos
2589 1.1.1.2 christos abort ();
2590 1.1.1.2 christos }
2591 1.1.1.2 christos
2592 1.1.1.2 christos static int
2593 1.1.1.2 christos decode_dsp32shiftimm_0 (int iw0, int iw1)
2594 1.1.1.2 christos {
2595 1.1.1.2 christos /* dsp32shiftimm
2596 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2597 1.1.1.2 christos | 1 | 1 | 0 | 0 |.M.| 1 | 1 | 0 | 1 | - | - |.sopcde............|
2598 1.1.1.2 christos |.sop...|.HLs...|.dst0......|.immag.................|.src1......|
2599 1.1.1.2 christos +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+ */
2600 1.1.1.2 christos int sop = ((iw1 >> DSP32ShiftImm_sop_bits) & DSP32ShiftImm_sop_mask);
2601 1.1.1.2 christos int bit8 = ((iw1 >> 8) & 0x1);
2602 1.1.1.2 christos int dst0 = ((iw1 >> DSP32ShiftImm_dst0_bits) & DSP32ShiftImm_dst0_mask);
2603 1.1.1.2 christos int sopcde = ((iw0 >> (DSP32ShiftImm_sopcde_bits - 16)) & DSP32ShiftImm_sopcde_mask);
2604 1.1.1.2 christos int HLs = ((iw1 >> DSP32ShiftImm_HLs_bits) & DSP32ShiftImm_HLs_mask);
2605 1.1.1.2 christos
2606 1.1.1.2 christos
2607 1.1.1.2 christos if (sop == 0 && sopcde == 0)
2608 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2609 1.1.1.2 christos else if (sop == 1 && sopcde == 0 && bit8 == 0)
2610 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2611 1.1.1.2 christos else if (sop == 1 && sopcde == 0 && bit8 == 1)
2612 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2613 1.1.1.2 christos else if (sop == 2 && sopcde == 0 && bit8 == 0)
2614 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2615 1.1.1.2 christos else if (sop == 2 && sopcde == 0 && bit8 == 1)
2616 1.1.1.2 christos return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2617 1.1.1.2 christos else if (sop == 2 && sopcde == 3 && HLs == 1)
2618 1.1.1.2 christos return 0;
2619 1.1.1.2 christos else if (sop == 0 && sopcde == 3 && HLs == 0 && bit8 == 0)
2620 1.1.1.2 christos return 0;
2621 1.1.1.2 christos else if (sop == 0 && sopcde == 3 && HLs == 0 && bit8 == 1)
2622 1.1.1.2 christos return 0;
2623 1.1.1.2 christos else if (sop == 0 && sopcde == 3 && HLs == 1 && bit8 == 0)
2624 1.1.1.2 christos return 0;
2625 1.1.1.2 christos else if (sop == 0 && sopcde == 3 && HLs == 1 && bit8 == 1)
2626 1.1.1.2 christos return 0;
2627 1.1.1.2 christos else if (sop == 1 && sopcde == 3 && HLs == 0)
2628 1.1.1.2 christos return 0;
2629 1.1.1.2 christos else if (sop == 1 && sopcde == 3 && HLs == 1)
2630 1.1.1.2 christos return 0;
2631 1.1.1.2 christos else if (sop == 2 && sopcde == 3 && HLs == 0)
2632 1.1.1.2 christos return 0;
2633 1.1.1.2 christos else if (sop == 1 && sopcde == 1 && bit8 == 0)
2634 1.1.1.2 christos return DREG_MASK (dst0);
2635 1.1.1.2 christos else if (sop == 1 && sopcde == 1 && bit8 == 1)
2636 1.1.1.2 christos return DREG_MASK (dst0);
2637 1.1.1.2 christos else if (sop == 2 && sopcde == 1 && bit8 == 1)
2638 1.1.1.2 christos return DREG_MASK (dst0);
2639 1.1.1.2 christos else if (sop == 2 && sopcde == 1 && bit8 == 0)
2640 1.1.1.2 christos return DREG_MASK (dst0);
2641 1.1.1.2 christos else if (sop == 0 && sopcde == 1)
2642 1.1.1.2 christos return DREG_MASK (dst0);
2643 1.1.1.2 christos else if (sop == 1 && sopcde == 2)
2644 1.1.1.2 christos return DREG_MASK (dst0);
2645 1.1.1.2 christos else if (sop == 2 && sopcde == 2 && bit8 == 1)
2646 1.1.1.2 christos return DREG_MASK (dst0);
2647 1.1.1.2 christos else if (sop == 2 && sopcde == 2 && bit8 == 0)
2648 1.1.1.2 christos return DREG_MASK (dst0);
2649 1.1.1.2 christos else if (sop == 3 && sopcde == 2)
2650 1.1.1.2 christos return DREG_MASK (dst0);
2651 1.1.1.2 christos else if (sop == 0 && sopcde == 2)
2652 1.1.1.2 christos return DREG_MASK (dst0);
2653 1.1.1.2 christos
2654 1.1.1.2 christos abort ();
2655 1.1.1.2 christos }
2656 1.1.1.2 christos
2657 1.1.1.2 christos int
2658 1.1.1.2 christos insn_regmask (int iw0, int iw1)
2659 1.1.1.2 christos {
2660 1.1.1.2 christos if ((iw0 & 0xf7ff) == 0xc003 && iw1 == 0x1800)
2661 1.1.1.2 christos return 0; /* MNOP */
2662 1.1.1.2 christos else if ((iw0 & 0xff00) == 0x0000)
2663 1.1.1.2 christos return decode_ProgCtrl_0 (iw0);
2664 1.1.1.2 christos else if ((iw0 & 0xffc0) == 0x0240)
2665 1.1.1.2 christos abort ();
2666 1.1.1.2 christos else if ((iw0 & 0xff80) == 0x0100)
2667 1.1.1.2 christos abort ();
2668 1.1.1.2 christos else if ((iw0 & 0xfe00) == 0x0400)
2669 1.1.1.2 christos abort ();
2670 1.1.1.2 christos else if ((iw0 & 0xfe00) == 0x0600)
2671 1.1.1.2 christos abort ();
2672 1.1.1.2 christos else if ((iw0 & 0xf800) == 0x0800)
2673 1.1.1.2 christos abort ();
2674 1.1.1.2 christos else if ((iw0 & 0xffe0) == 0x0200)
2675 1.1.1.2 christos abort ();
2676 1.1.1.2 christos else if ((iw0 & 0xff00) == 0x0300)
2677 1.1.1.2 christos abort ();
2678 1.1.1.2 christos else if ((iw0 & 0xf000) == 0x1000)
2679 1.1.1.2 christos abort ();
2680 1.1.1.2 christos else if ((iw0 & 0xf000) == 0x2000)
2681 1.1.1.2 christos abort ();
2682 1.1.1.2 christos else if ((iw0 & 0xf000) == 0x3000)
2683 1.1.1.2 christos abort ();
2684 1.1.1.2 christos else if ((iw0 & 0xfc00) == 0x4000)
2685 1.1.1.2 christos abort ();
2686 1.1.1.2 christos else if ((iw0 & 0xfe00) == 0x4400)
2687 1.1.1.2 christos abort ();
2688 1.1.1.2 christos else if ((iw0 & 0xf800) == 0x4800)
2689 1.1.1.2 christos abort ();
2690 1.1.1.2 christos else if ((iw0 & 0xf000) == 0x5000)
2691 1.1.1.2 christos abort ();
2692 1.1.1.2 christos else if ((iw0 & 0xf800) == 0x6000)
2693 1.1.1.2 christos abort ();
2694 1.1.1.2 christos else if ((iw0 & 0xf800) == 0x6800)
2695 1.1.1.2 christos abort ();
2696 1.1.1.2 christos else if ((iw0 & 0xf000) == 0x8000)
2697 1.1.1.2 christos return decode_LDSTpmod_0 (iw0);
2698 1.1.1.2 christos else if ((iw0 & 0xff60) == 0x9e60)
2699 1.1.1.2 christos return decode_dagMODim_0 (iw0);
2700 1.1.1.2 christos else if ((iw0 & 0xfff0) == 0x9f60)
2701 1.1.1.2 christos return decode_dagMODik_0 (iw0);
2702 1.1.1.2 christos else if ((iw0 & 0xfc00) == 0x9c00)
2703 1.1.1.2 christos return decode_dspLDST_0 (iw0);
2704 1.1.1.2 christos else if ((iw0 & 0xf000) == 0x9000)
2705 1.1.1.2 christos return decode_LDST_0 (iw0);
2706 1.1.1.2 christos else if ((iw0 & 0xfc00) == 0xb800)
2707 1.1.1.2 christos return decode_LDSTiiFP_0 (iw0);
2708 1.1.1.2 christos else if ((iw0 & 0xe000) == 0xA000)
2709 1.1.1.2 christos return decode_LDSTii_0 (iw0);
2710 1.1.1.2 christos else if ((iw0 & 0xff80) == 0xe080 && (iw1 & 0x0C00) == 0x0000)
2711 1.1.1.2 christos abort ();
2712 1.1.1.2 christos else if ((iw0 & 0xff00) == 0xe100 && (iw1 & 0x0000) == 0x0000)
2713 1.1.1.2 christos abort ();
2714 1.1.1.2 christos else if ((iw0 & 0xfe00) == 0xe200 && (iw1 & 0x0000) == 0x0000)
2715 1.1.1.2 christos abort ();
2716 1.1.1.2 christos else if ((iw0 & 0xfc00) == 0xe400 && (iw1 & 0x0000) == 0x0000)
2717 1.1.1.2 christos abort ();
2718 1.1.1.2 christos else if ((iw0 & 0xfffe) == 0xe800 && (iw1 & 0x0000) == 0x0000)
2719 1.1.1.2 christos abort ();
2720 1.1.1.2 christos else if ((iw0 & 0xf600) == 0xc000 && (iw1 & 0x0000) == 0x0000)
2721 1.1.1.2 christos return decode_dsp32mac_0 (iw0, iw1);
2722 1.1.1.2 christos else if ((iw0 & 0xf600) == 0xc200 && (iw1 & 0x0000) == 0x0000)
2723 1.1.1.2 christos return decode_dsp32mult_0 (iw0, iw1);
2724 1.1.1.2 christos else if ((iw0 & 0xf7c0) == 0xc400 && (iw1 & 0x0000) == 0x0000)
2725 1.1.1.2 christos return decode_dsp32alu_0 (iw0, iw1);
2726 1.1.1.2 christos else if ((iw0 & 0xf780) == 0xc600 && (iw1 & 0x01c0) == 0x0000)
2727 1.1.1.2 christos return decode_dsp32shift_0 (iw0, iw1);
2728 1.1.1.2 christos else if ((iw0 & 0xf780) == 0xc680 && (iw1 & 0x0000) == 0x0000)
2729 1.1.1.2 christos return decode_dsp32shiftimm_0 (iw0, iw1);
2730 1.1.1.2 christos else if ((iw0 & 0xff00) == 0xf800)
2731 1.1.1.2 christos abort ();
2732 1.1.1.2 christos else if ((iw0 & 0xFFC0) == 0xf000 && (iw1 & 0x0000) == 0x0000)
2733 1.1.1.2 christos abort ();
2734 1.1.1.2 christos
2735 abort ();
2736 }
2737