tc-d30v.c revision 1.1.1.9 1 1.1 skrll /* tc-d30v.c -- Assembler code for the Mitsubishi D30V
2 1.1.1.9 christos Copyright (C) 1997-2025 Free Software Foundation, Inc.
3 1.1 skrll
4 1.1 skrll This file is part of GAS, the GNU Assembler.
5 1.1 skrll
6 1.1 skrll GAS is free software; you can redistribute it and/or modify
7 1.1 skrll it under the terms of the GNU General Public License as published by
8 1.1 skrll the Free Software Foundation; either version 3, or (at your option)
9 1.1 skrll any later version.
10 1.1 skrll
11 1.1 skrll GAS is distributed in the hope that it will be useful,
12 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 skrll GNU General Public License for more details.
15 1.1 skrll
16 1.1 skrll You should have received a copy of the GNU General Public License
17 1.1 skrll along with GAS; see the file COPYING. If not, write to
18 1.1 skrll the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 1.1 skrll Boston, MA 02110-1301, USA. */
20 1.1 skrll
21 1.1 skrll #include "as.h"
22 1.1 skrll #include "safe-ctype.h"
23 1.1 skrll #include "subsegs.h"
24 1.1 skrll #include "opcode/d30v.h"
25 1.1.1.2 christos #include "dwarf2dbg.h"
26 1.1 skrll
27 1.1 skrll const char comment_chars[] = ";";
28 1.1 skrll const char line_comment_chars[] = "#";
29 1.1 skrll const char line_separator_chars[] = "";
30 1.1.1.9 christos const char md_shortopts[] = "OnNcC";
31 1.1 skrll const char EXP_CHARS[] = "eE";
32 1.1 skrll const char FLT_CHARS[] = "dD";
33 1.1 skrll
34 1.1 skrll #include <limits.h>
35 1.1 skrll #ifndef CHAR_BIT
36 1.1 skrll #define CHAR_BIT 8
37 1.1 skrll #endif
38 1.1 skrll
39 1.1 skrll #define NOP_MULTIPLY 1
40 1.1 skrll #define NOP_ALL 2
41 1.1 skrll static int warn_nops = 0;
42 1.1 skrll static int Optimizing = 0;
43 1.1 skrll static int warn_register_name_conflicts = 1;
44 1.1 skrll
45 1.1 skrll #define FORCE_SHORT 1
46 1.1 skrll #define FORCE_LONG 2
47 1.1 skrll
48 1.1 skrll /* EXEC types. */
49 1.1 skrll typedef enum _exec_type
50 1.1 skrll {
51 1.1 skrll EXEC_UNKNOWN, /* No order specified. */
52 1.1 skrll EXEC_PARALLEL, /* Done in parallel (FM=00). */
53 1.1 skrll EXEC_SEQ, /* Sequential (FM=01). */
54 1.1 skrll EXEC_REVSEQ /* Reverse sequential (FM=10). */
55 1.1 skrll } exec_type_enum;
56 1.1 skrll
57 1.1 skrll /* Fixups. */
58 1.1 skrll #define MAX_INSN_FIXUPS 5
59 1.1 skrll
60 1.1 skrll struct d30v_fixup
61 1.1 skrll {
62 1.1 skrll expressionS exp;
63 1.1 skrll int operand;
64 1.1 skrll int pcrel;
65 1.1 skrll int size;
66 1.1 skrll bfd_reloc_code_real_type reloc;
67 1.1 skrll };
68 1.1 skrll
69 1.1 skrll typedef struct _fixups
70 1.1 skrll {
71 1.1 skrll int fc;
72 1.1 skrll struct d30v_fixup fix[MAX_INSN_FIXUPS];
73 1.1 skrll struct _fixups *next;
74 1.1 skrll } Fixups;
75 1.1 skrll
76 1.1 skrll static Fixups FixUps[2];
77 1.1 skrll static Fixups *fixups;
78 1.1 skrll
79 1.1 skrll /* Whether current and previous instruction are word multiply insns. */
80 1.1 skrll static int cur_mul32_p = 0;
81 1.1 skrll static int prev_mul32_p = 0;
82 1.1 skrll
83 1.1 skrll /* The flag_explicitly_parallel is true iff the instruction being assembled
84 1.1 skrll has been explicitly written as a parallel short-instruction pair by the
85 1.1 skrll human programmer. It is used in parallel_ok () to distinguish between
86 1.1 skrll those dangerous parallelizations attempted by the human, which are to be
87 1.1 skrll allowed, and those attempted by the assembler, which are not. It is set
88 1.1 skrll from md_assemble (). */
89 1.1 skrll static int flag_explicitly_parallel = 0;
90 1.1 skrll static int flag_xp_state = 0;
91 1.1 skrll
92 1.1 skrll /* Whether current and previous left sub-instruction disables
93 1.1 skrll execution of right sub-instruction. */
94 1.1 skrll static int cur_left_kills_right_p = 0;
95 1.1 skrll static int prev_left_kills_right_p = 0;
96 1.1 skrll
97 1.1 skrll /* The known current alignment of the current section. */
98 1.1 skrll static int d30v_current_align;
99 1.1 skrll static segT d30v_current_align_seg;
100 1.1 skrll
101 1.1 skrll /* The last seen label in the current section. This is used to auto-align
102 1.1 skrll labels preceding instructions. */
103 1.1 skrll static symbolS *d30v_last_label;
104 1.1 skrll
105 1.1 skrll /* Two nops. */
106 1.1 skrll #define NOP_LEFT ((long long) NOP << 32)
107 1.1 skrll #define NOP_RIGHT ((long long) NOP)
108 1.1 skrll #define NOP2 (FM00 | NOP_LEFT | NOP_RIGHT)
109 1.1 skrll
110 1.1.1.9 christos const struct option md_longopts[] =
111 1.1 skrll {
112 1.1 skrll {NULL, no_argument, NULL, 0}
113 1.1 skrll };
114 1.1 skrll
115 1.1.1.9 christos const size_t md_longopts_size = sizeof (md_longopts);
116 1.1 skrll
117 1.1 skrll /* Opcode hash table. */
118 1.1.1.7 christos static htab_t d30v_hash;
119 1.1 skrll
120 1.1 skrll /* Do a binary search of the pre_defined_registers array to see if
121 1.1.1.5 christos NAME is a valid register name. Return the register number from the
122 1.1 skrll array on success, or -1 on failure. */
123 1.1 skrll
124 1.1 skrll static int
125 1.1 skrll reg_name_search (char *name)
126 1.1 skrll {
127 1.1 skrll int middle, low, high;
128 1.1 skrll int cmp;
129 1.1 skrll
130 1.1 skrll low = 0;
131 1.1 skrll high = reg_name_cnt () - 1;
132 1.1 skrll
133 1.1 skrll do
134 1.1 skrll {
135 1.1 skrll middle = (low + high) / 2;
136 1.1 skrll cmp = strcasecmp (name, pre_defined_registers[middle].name);
137 1.1 skrll if (cmp < 0)
138 1.1 skrll high = middle - 1;
139 1.1 skrll else if (cmp > 0)
140 1.1 skrll low = middle + 1;
141 1.1 skrll else
142 1.1 skrll {
143 1.1 skrll if (symbol_find (name) != NULL)
144 1.1 skrll {
145 1.1 skrll if (warn_register_name_conflicts)
146 1.1 skrll as_warn (_("Register name %s conflicts with symbol of the same name"),
147 1.1 skrll name);
148 1.1 skrll }
149 1.1 skrll
150 1.1 skrll return pre_defined_registers[middle].value;
151 1.1 skrll }
152 1.1 skrll }
153 1.1 skrll while (low <= high);
154 1.1 skrll
155 1.1 skrll return -1;
156 1.1 skrll }
157 1.1 skrll
158 1.1 skrll /* Check the string at input_line_pointer to see if it is a valid
159 1.1 skrll register name. */
160 1.1 skrll
161 1.1 skrll static int
162 1.1 skrll register_name (expressionS *expressionP)
163 1.1 skrll {
164 1.1 skrll int reg_number;
165 1.1 skrll char c, *p = input_line_pointer;
166 1.1 skrll
167 1.1.1.9 christos while (!is_end_of_stmt (*p) && *p != ',' && !is_whitespace (*p) && *p != ')')
168 1.1 skrll p++;
169 1.1 skrll
170 1.1 skrll c = *p;
171 1.1 skrll if (c)
172 1.1 skrll *p++ = 0;
173 1.1 skrll
174 1.1 skrll /* Look to see if it's in the register table. */
175 1.1 skrll reg_number = reg_name_search (input_line_pointer);
176 1.1 skrll if (reg_number >= 0)
177 1.1 skrll {
178 1.1 skrll expressionP->X_op = O_register;
179 1.1 skrll /* Temporarily store a pointer to the string here. */
180 1.1 skrll expressionP->X_op_symbol = (symbolS *) input_line_pointer;
181 1.1 skrll expressionP->X_add_number = reg_number;
182 1.1 skrll input_line_pointer = p;
183 1.1 skrll return 1;
184 1.1 skrll }
185 1.1 skrll if (c)
186 1.1 skrll *(p - 1) = c;
187 1.1 skrll return 0;
188 1.1 skrll }
189 1.1 skrll
190 1.1 skrll static int
191 1.1 skrll check_range (unsigned long num, int bits, int flags)
192 1.1 skrll {
193 1.1 skrll long min, max;
194 1.1 skrll
195 1.1 skrll /* Don't bother checking 32-bit values. */
196 1.1 skrll if (bits == 32)
197 1.1 skrll {
198 1.1 skrll if (sizeof (unsigned long) * CHAR_BIT == 32)
199 1.1 skrll return 0;
200 1.1 skrll
201 1.1 skrll /* We don't record signed or unsigned for 32-bit quantities.
202 1.1 skrll Allow either. */
203 1.1 skrll min = -((unsigned long) 1 << (bits - 1));
204 1.1 skrll max = ((unsigned long) 1 << bits) - 1;
205 1.1 skrll return (long) num < min || (long) num > max;
206 1.1 skrll }
207 1.1 skrll
208 1.1 skrll if (flags & OPERAND_SHIFT)
209 1.1 skrll {
210 1.1 skrll /* We know that all shifts are right by three bits. */
211 1.1 skrll num >>= 3;
212 1.1 skrll
213 1.1 skrll if (flags & OPERAND_SIGNED)
214 1.1 skrll {
215 1.1 skrll unsigned long sign_bit = ((unsigned long) -1L >> 4) + 1;
216 1.1 skrll num = (num ^ sign_bit) - sign_bit;
217 1.1 skrll }
218 1.1 skrll }
219 1.1 skrll
220 1.1 skrll if (flags & OPERAND_SIGNED)
221 1.1 skrll {
222 1.1 skrll max = ((unsigned long) 1 << (bits - 1)) - 1;
223 1.1 skrll min = - ((unsigned long) 1 << (bits - 1));
224 1.1 skrll return (long) num > max || (long) num < min;
225 1.1 skrll }
226 1.1 skrll else
227 1.1 skrll {
228 1.1 skrll max = ((unsigned long) 1 << bits) - 1;
229 1.1 skrll return num > (unsigned long) max;
230 1.1 skrll }
231 1.1 skrll }
232 1.1 skrll
233 1.1 skrll void
234 1.1 skrll md_show_usage (FILE *stream)
235 1.1 skrll {
236 1.1 skrll fprintf (stream, _("\nD30V options:\n\
237 1.1 skrll -O Make adjacent short instructions parallel if possible.\n\
238 1.1 skrll -n Warn about all NOPs inserted by the assembler.\n\
239 1.1.1.5 christos -N Warn about NOPs inserted after word multiplies.\n\
240 1.1.1.5 christos -c Warn about symbols whose names match register names.\n\
241 1.1 skrll -C Opposite of -C. -c is the default.\n"));
242 1.1 skrll }
243 1.1 skrll
244 1.1 skrll int
245 1.1.1.4 christos md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
246 1.1 skrll {
247 1.1 skrll switch (c)
248 1.1 skrll {
249 1.1 skrll /* Optimize. Will attempt to parallelize operations. */
250 1.1 skrll case 'O':
251 1.1 skrll Optimizing = 1;
252 1.1 skrll break;
253 1.1 skrll
254 1.1 skrll /* Warn about all NOPS that the assembler inserts. */
255 1.1 skrll case 'n':
256 1.1 skrll warn_nops = NOP_ALL;
257 1.1 skrll break;
258 1.1 skrll
259 1.1 skrll /* Warn about the NOPS that the assembler inserts because of the
260 1.1 skrll multiply hazard. */
261 1.1 skrll case 'N':
262 1.1 skrll warn_nops = NOP_MULTIPLY;
263 1.1 skrll break;
264 1.1 skrll
265 1.1 skrll case 'c':
266 1.1 skrll warn_register_name_conflicts = 1;
267 1.1 skrll break;
268 1.1 skrll
269 1.1 skrll case 'C':
270 1.1 skrll warn_register_name_conflicts = 0;
271 1.1 skrll break;
272 1.1 skrll
273 1.1 skrll default:
274 1.1 skrll return 0;
275 1.1 skrll }
276 1.1 skrll return 1;
277 1.1 skrll }
278 1.1 skrll
279 1.1 skrll symbolS *
280 1.1 skrll md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
281 1.1 skrll {
282 1.1 skrll return 0;
283 1.1 skrll }
284 1.1 skrll
285 1.1.1.4 christos const char *
286 1.1 skrll md_atof (int type, char *litP, int *sizeP)
287 1.1 skrll {
288 1.1.1.7 christos return ieee_md_atof (type, litP, sizeP, true);
289 1.1 skrll }
290 1.1 skrll
291 1.1 skrll void
292 1.1 skrll md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
293 1.1 skrll asection *sec ATTRIBUTE_UNUSED,
294 1.1 skrll fragS *fragP ATTRIBUTE_UNUSED)
295 1.1 skrll {
296 1.1 skrll abort ();
297 1.1 skrll }
298 1.1 skrll
299 1.1 skrll valueT
300 1.1 skrll md_section_align (asection *seg, valueT addr)
301 1.1 skrll {
302 1.1.1.6 christos int align = bfd_section_alignment (seg);
303 1.1.1.3 christos return ((addr + (1 << align) - 1) & -(1 << align));
304 1.1 skrll }
305 1.1 skrll
306 1.1 skrll void
307 1.1 skrll md_begin (void)
308 1.1 skrll {
309 1.1.1.9 christos const struct d30v_opcode *opcode;
310 1.1.1.7 christos d30v_hash = str_htab_create ();
311 1.1 skrll
312 1.1 skrll /* Insert opcode names into a hash table. */
313 1.1.1.9 christos for (opcode = d30v_opcode_table; opcode->name; opcode++)
314 1.1.1.7 christos str_hash_insert (d30v_hash, opcode->name, opcode, 0);
315 1.1 skrll
316 1.1 skrll fixups = &FixUps[0];
317 1.1 skrll FixUps[0].next = &FixUps[1];
318 1.1 skrll FixUps[1].next = &FixUps[0];
319 1.1 skrll
320 1.1 skrll d30v_current_align_seg = now_seg;
321 1.1 skrll }
322 1.1 skrll
323 1.1 skrll /* Remove the postincrement or postdecrement operator ( '+' or '-' )
324 1.1 skrll from an expression. */
325 1.1 skrll
326 1.1 skrll static int
327 1.1 skrll postfix (char *p)
328 1.1 skrll {
329 1.1 skrll while (*p != '-' && *p != '+')
330 1.1 skrll {
331 1.1.1.9 christos if (is_end_of_stmt (*p) || is_whitespace (*p) || *p == ',')
332 1.1 skrll break;
333 1.1 skrll p++;
334 1.1 skrll }
335 1.1 skrll
336 1.1 skrll if (*p == '-')
337 1.1 skrll {
338 1.1 skrll *p = ' ';
339 1.1 skrll return -1;
340 1.1 skrll }
341 1.1 skrll
342 1.1 skrll if (*p == '+')
343 1.1 skrll {
344 1.1 skrll *p = ' ';
345 1.1 skrll return 1;
346 1.1 skrll }
347 1.1 skrll
348 1.1 skrll return 0;
349 1.1 skrll }
350 1.1 skrll
351 1.1 skrll static bfd_reloc_code_real_type
352 1.1 skrll get_reloc (const struct d30v_operand *op, int rel_flag)
353 1.1 skrll {
354 1.1 skrll switch (op->bits)
355 1.1 skrll {
356 1.1 skrll case 6:
357 1.1 skrll if (op->flags & OPERAND_SHIFT)
358 1.1 skrll return BFD_RELOC_D30V_9_PCREL;
359 1.1 skrll else
360 1.1 skrll return BFD_RELOC_D30V_6;
361 1.1 skrll break;
362 1.1 skrll case 12:
363 1.1 skrll if (!(op->flags & OPERAND_SHIFT))
364 1.1 skrll as_warn (_("unexpected 12-bit reloc type"));
365 1.1 skrll if (rel_flag == RELOC_PCREL)
366 1.1 skrll return BFD_RELOC_D30V_15_PCREL;
367 1.1 skrll else
368 1.1 skrll return BFD_RELOC_D30V_15;
369 1.1 skrll case 18:
370 1.1 skrll if (!(op->flags & OPERAND_SHIFT))
371 1.1 skrll as_warn (_("unexpected 18-bit reloc type"));
372 1.1 skrll if (rel_flag == RELOC_PCREL)
373 1.1 skrll return BFD_RELOC_D30V_21_PCREL;
374 1.1 skrll else
375 1.1 skrll return BFD_RELOC_D30V_21;
376 1.1 skrll case 32:
377 1.1 skrll if (rel_flag == RELOC_PCREL)
378 1.1 skrll return BFD_RELOC_D30V_32_PCREL;
379 1.1 skrll else
380 1.1 skrll return BFD_RELOC_D30V_32;
381 1.1 skrll default:
382 1.1 skrll return 0;
383 1.1 skrll }
384 1.1 skrll }
385 1.1 skrll
386 1.1 skrll /* Parse a string of operands and return an array of expressions. */
387 1.1 skrll
388 1.1 skrll static int
389 1.1 skrll get_operands (expressionS exp[], int cmp_hack)
390 1.1 skrll {
391 1.1 skrll char *p = input_line_pointer;
392 1.1 skrll int numops = 0;
393 1.1 skrll int post = 0;
394 1.1 skrll
395 1.1 skrll if (cmp_hack)
396 1.1 skrll {
397 1.1 skrll exp[numops].X_op = O_absent;
398 1.1 skrll exp[numops++].X_add_number = cmp_hack - 1;
399 1.1 skrll }
400 1.1 skrll
401 1.1 skrll while (*p)
402 1.1 skrll {
403 1.1.1.9 christos while (is_whitespace (*p) || *p == ',')
404 1.1 skrll p++;
405 1.1 skrll
406 1.1 skrll if (*p == 0 || *p == '\n' || *p == '\r')
407 1.1 skrll break;
408 1.1 skrll
409 1.1 skrll if (*p == '@')
410 1.1 skrll {
411 1.1 skrll p++;
412 1.1 skrll exp[numops].X_op = O_absent;
413 1.1 skrll if (*p == '(')
414 1.1 skrll {
415 1.1 skrll p++;
416 1.1 skrll exp[numops].X_add_number = OPERAND_ATPAR;
417 1.1 skrll post = postfix (p);
418 1.1 skrll }
419 1.1 skrll else if (*p == '-')
420 1.1 skrll {
421 1.1 skrll p++;
422 1.1 skrll exp[numops].X_add_number = OPERAND_ATMINUS;
423 1.1 skrll }
424 1.1 skrll else
425 1.1 skrll {
426 1.1 skrll exp[numops].X_add_number = OPERAND_ATSIGN;
427 1.1 skrll post = postfix (p);
428 1.1 skrll }
429 1.1 skrll numops++;
430 1.1 skrll continue;
431 1.1 skrll }
432 1.1 skrll
433 1.1 skrll if (*p == ')')
434 1.1 skrll {
435 1.1 skrll /* Just skip the trailing paren. */
436 1.1 skrll p++;
437 1.1 skrll continue;
438 1.1 skrll }
439 1.1 skrll
440 1.1 skrll input_line_pointer = p;
441 1.1 skrll
442 1.1 skrll /* Check to see if it might be a register name. */
443 1.1 skrll if (!register_name (&exp[numops]))
444 1.1 skrll {
445 1.1 skrll /* Parse as an expression. */
446 1.1 skrll expression (&exp[numops]);
447 1.1 skrll }
448 1.1 skrll
449 1.1 skrll if (exp[numops].X_op == O_illegal)
450 1.1 skrll as_bad (_("illegal operand"));
451 1.1 skrll else if (exp[numops].X_op == O_absent)
452 1.1 skrll as_bad (_("missing operand"));
453 1.1 skrll
454 1.1 skrll numops++;
455 1.1 skrll p = input_line_pointer;
456 1.1 skrll
457 1.1 skrll switch (post)
458 1.1 skrll {
459 1.1 skrll case -1:
460 1.1 skrll /* Postdecrement mode. */
461 1.1 skrll exp[numops].X_op = O_absent;
462 1.1 skrll exp[numops++].X_add_number = OPERAND_MINUS;
463 1.1 skrll break;
464 1.1 skrll case 1:
465 1.1 skrll /* Postincrement mode. */
466 1.1 skrll exp[numops].X_op = O_absent;
467 1.1 skrll exp[numops++].X_add_number = OPERAND_PLUS;
468 1.1 skrll break;
469 1.1 skrll }
470 1.1 skrll post = 0;
471 1.1 skrll }
472 1.1 skrll
473 1.1 skrll exp[numops].X_op = 0;
474 1.1 skrll
475 1.1 skrll return numops;
476 1.1 skrll }
477 1.1 skrll
478 1.1 skrll /* Generate the instruction.
479 1.1 skrll It does everything but write the FM bits. */
480 1.1 skrll
481 1.1 skrll static long long
482 1.1 skrll build_insn (struct d30v_insn *opcode, expressionS *opers)
483 1.1 skrll {
484 1.1.1.2 christos int i, bits, shift, flags;
485 1.1 skrll unsigned long number, id = 0;
486 1.1 skrll long long insn;
487 1.1.1.9 christos const struct d30v_opcode *op = opcode->op;
488 1.1.1.9 christos const struct d30v_format *form = opcode->form;
489 1.1 skrll
490 1.1 skrll insn =
491 1.1 skrll opcode->ecc << 28 | op->op1 << 25 | op->op2 << 20 | form->modifier << 18;
492 1.1 skrll
493 1.1 skrll for (i = 0; form->operands[i]; i++)
494 1.1 skrll {
495 1.1 skrll flags = d30v_operand_table[form->operands[i]].flags;
496 1.1 skrll
497 1.1 skrll /* Must be a register or number. */
498 1.1 skrll if (!(flags & OPERAND_REG) && !(flags & OPERAND_NUM)
499 1.1 skrll && !(flags & OPERAND_NAME) && !(flags & OPERAND_SPECIAL))
500 1.1 skrll continue;
501 1.1 skrll
502 1.1 skrll bits = d30v_operand_table[form->operands[i]].bits;
503 1.1 skrll if (flags & OPERAND_SHIFT)
504 1.1 skrll bits += 3;
505 1.1 skrll
506 1.1 skrll shift = 12 - d30v_operand_table[form->operands[i]].position;
507 1.1 skrll if (opers[i].X_op != O_symbol)
508 1.1 skrll number = opers[i].X_add_number;
509 1.1 skrll else
510 1.1 skrll number = 0;
511 1.1 skrll if (flags & OPERAND_REG)
512 1.1 skrll {
513 1.1 skrll /* Check for mvfsys or mvtsys control registers. */
514 1.1 skrll if (flags & OPERAND_CONTROL && (number & 0x7f) > MAX_CONTROL_REG)
515 1.1 skrll {
516 1.1 skrll /* PSWL or PSWH. */
517 1.1 skrll id = (number & 0x7f) - MAX_CONTROL_REG;
518 1.1 skrll number = 0;
519 1.1 skrll }
520 1.1 skrll else if (number & OPERAND_FLAG)
521 1.1 skrll /* NUMBER is a flag register. */
522 1.1 skrll id = 3;
523 1.1 skrll
524 1.1 skrll number &= 0x7F;
525 1.1 skrll }
526 1.1 skrll else if (flags & OPERAND_SPECIAL)
527 1.1 skrll number = id;
528 1.1 skrll
529 1.1 skrll if (opers[i].X_op != O_register && opers[i].X_op != O_constant
530 1.1 skrll && !(flags & OPERAND_NAME))
531 1.1 skrll {
532 1.1 skrll /* Now create a fixup. */
533 1.1 skrll if (fixups->fc >= MAX_INSN_FIXUPS)
534 1.1 skrll as_fatal (_("too many fixups"));
535 1.1 skrll
536 1.1 skrll fixups->fix[fixups->fc].reloc =
537 1.1 skrll get_reloc (d30v_operand_table + form->operands[i], op->reloc_flag);
538 1.1 skrll fixups->fix[fixups->fc].size = 4;
539 1.1 skrll fixups->fix[fixups->fc].exp = opers[i];
540 1.1 skrll fixups->fix[fixups->fc].operand = form->operands[i];
541 1.1 skrll if (fixups->fix[fixups->fc].reloc == BFD_RELOC_D30V_9_PCREL)
542 1.1 skrll fixups->fix[fixups->fc].pcrel = RELOC_PCREL;
543 1.1 skrll else
544 1.1 skrll fixups->fix[fixups->fc].pcrel = op->reloc_flag;
545 1.1 skrll (fixups->fc)++;
546 1.1 skrll }
547 1.1 skrll
548 1.1 skrll /* Truncate to the proper number of bits. */
549 1.1 skrll if ((opers[i].X_op == O_constant) && check_range (number, bits, flags))
550 1.1 skrll as_bad (_("operand out of range: %ld"), number);
551 1.1 skrll if (bits < 31)
552 1.1 skrll number &= 0x7FFFFFFF >> (31 - bits);
553 1.1 skrll if (flags & OPERAND_SHIFT)
554 1.1 skrll number >>= 3;
555 1.1 skrll if (bits == 32)
556 1.1 skrll {
557 1.1 skrll /* It's a LONG instruction. */
558 1.1 skrll insn |= ((number & 0xffffffff) >> 26); /* Top 6 bits. */
559 1.1 skrll insn <<= 32; /* Shift the first word over. */
560 1.1 skrll insn |= ((number & 0x03FC0000) << 2); /* Next 8 bits. */
561 1.1 skrll insn |= number & 0x0003FFFF; /* Bottom 18 bits. */
562 1.1 skrll }
563 1.1 skrll else
564 1.1 skrll insn |= number << shift;
565 1.1 skrll }
566 1.1 skrll
567 1.1 skrll return insn;
568 1.1 skrll }
569 1.1 skrll
570 1.1 skrll static void
571 1.1 skrll d30v_number_to_chars (char *buf, /* Return 'nbytes' of chars here. */
572 1.1 skrll long long value, /* The value of the bits. */
573 1.1 skrll int n) /* Number of bytes in the output. */
574 1.1 skrll {
575 1.1 skrll while (n--)
576 1.1 skrll {
577 1.1 skrll buf[n] = value & 0xff;
578 1.1 skrll value >>= 8;
579 1.1 skrll }
580 1.1 skrll }
581 1.1 skrll
582 1.1 skrll /* Write out a long form instruction. */
583 1.1 skrll
584 1.1 skrll static void
585 1.1 skrll write_long (struct d30v_insn *opcode ATTRIBUTE_UNUSED,
586 1.1 skrll long long insn,
587 1.1 skrll Fixups *fx)
588 1.1 skrll {
589 1.1 skrll int i, where;
590 1.1 skrll char *f = frag_more (8);
591 1.1 skrll
592 1.1.1.2 christos dwarf2_emit_insn (8);
593 1.1 skrll insn |= FM11;
594 1.1 skrll d30v_number_to_chars (f, insn, 8);
595 1.1 skrll
596 1.1 skrll for (i = 0; i < fx->fc; i++)
597 1.1 skrll {
598 1.1 skrll if (fx->fix[i].reloc)
599 1.1 skrll {
600 1.1 skrll where = f - frag_now->fr_literal;
601 1.1 skrll fix_new_exp (frag_now, where, fx->fix[i].size, &(fx->fix[i].exp),
602 1.1 skrll fx->fix[i].pcrel, fx->fix[i].reloc);
603 1.1 skrll }
604 1.1 skrll }
605 1.1 skrll
606 1.1 skrll fx->fc = 0;
607 1.1 skrll }
608 1.1 skrll
609 1.1 skrll /* Write out a short form instruction by itself. */
610 1.1 skrll
611 1.1 skrll static void
612 1.1 skrll write_1_short (struct d30v_insn *opcode,
613 1.1 skrll long long insn,
614 1.1 skrll Fixups *fx,
615 1.1 skrll int use_sequential)
616 1.1 skrll {
617 1.1 skrll char *f = frag_more (8);
618 1.1 skrll int i, where;
619 1.1 skrll
620 1.1.1.2 christos dwarf2_emit_insn (8);
621 1.1 skrll if (warn_nops == NOP_ALL)
622 1.1 skrll as_warn (_("%s NOP inserted"), use_sequential ?
623 1.1 skrll _("sequential") : _("parallel"));
624 1.1 skrll
625 1.1 skrll /* The other container needs to be NOP. */
626 1.1 skrll if (use_sequential)
627 1.1 skrll {
628 1.1 skrll /* Use a sequential NOP rather than a parallel one,
629 1.1 skrll as the current instruction is a FLAG_MUL32 type one
630 1.1 skrll and the next instruction is a load. */
631 1.1 skrll
632 1.1 skrll /* According to 4.3.1: for FM=01, sub-instructions performed
633 1.1 skrll only by IU cannot be encoded in L-container. */
634 1.1 skrll if (opcode->op->unit == IU)
635 1.1 skrll /* Right then left. */
636 1.1 skrll insn |= FM10 | NOP_LEFT;
637 1.1 skrll else
638 1.1 skrll /* Left then right. */
639 1.1 skrll insn = FM01 | (insn << 32) | NOP_RIGHT;
640 1.1 skrll }
641 1.1 skrll else
642 1.1 skrll {
643 1.1 skrll /* According to 4.3.1: for FM=00, sub-instructions performed
644 1.1 skrll only by IU cannot be encoded in L-container. */
645 1.1 skrll if (opcode->op->unit == IU)
646 1.1 skrll /* Right container. */
647 1.1 skrll insn |= FM00 | NOP_LEFT;
648 1.1 skrll else
649 1.1 skrll /* Left container. */
650 1.1 skrll insn = FM00 | (insn << 32) | NOP_RIGHT;
651 1.1 skrll }
652 1.1 skrll
653 1.1 skrll d30v_number_to_chars (f, insn, 8);
654 1.1 skrll
655 1.1 skrll for (i = 0; i < fx->fc; i++)
656 1.1 skrll {
657 1.1 skrll if (fx->fix[i].reloc)
658 1.1 skrll {
659 1.1 skrll where = f - frag_now->fr_literal;
660 1.1 skrll fix_new_exp (frag_now,
661 1.1 skrll where,
662 1.1 skrll fx->fix[i].size,
663 1.1 skrll &(fx->fix[i].exp),
664 1.1 skrll fx->fix[i].pcrel,
665 1.1 skrll fx->fix[i].reloc);
666 1.1 skrll }
667 1.1 skrll }
668 1.1 skrll
669 1.1 skrll fx->fc = 0;
670 1.1 skrll }
671 1.1 skrll
672 1.1 skrll /* Check 2 instructions and determine if they can be safely
673 1.1 skrll executed in parallel. Return 1 if they can be. */
674 1.1 skrll
675 1.1 skrll static int
676 1.1 skrll parallel_ok (struct d30v_insn *op1,
677 1.1 skrll unsigned long insn1,
678 1.1 skrll struct d30v_insn *op2,
679 1.1 skrll unsigned long insn2,
680 1.1 skrll exec_type_enum exec_type)
681 1.1 skrll {
682 1.1 skrll int i, j, shift, regno, bits, ecc;
683 1.1 skrll unsigned long flags, mask, flags_set1, flags_set2, flags_used1, flags_used2;
684 1.1 skrll unsigned long ins, mod_reg[2][3], used_reg[2][3], flag_reg[2];
685 1.1.1.9 christos const struct d30v_format *f;
686 1.1.1.9 christos const struct d30v_opcode *op;
687 1.1 skrll
688 1.1 skrll /* Section 4.3: Both instructions must not be IU or MU only. */
689 1.1 skrll if ((op1->op->unit == IU && op2->op->unit == IU)
690 1.1 skrll || (op1->op->unit == MU && op2->op->unit == MU))
691 1.1 skrll return 0;
692 1.1 skrll
693 1.1 skrll /* First instruction must not be a jump to safely optimize, unless this
694 1.1 skrll is an explicit parallel operation. */
695 1.1 skrll if (exec_type != EXEC_PARALLEL
696 1.1 skrll && (op1->op->flags_used & (FLAG_JMP | FLAG_JSR)))
697 1.1 skrll return 0;
698 1.1 skrll
699 1.1 skrll /* If one instruction is /TX or /XT and the other is /FX or /XF respectively,
700 1.1 skrll then it is safe to allow the two to be done as parallel ops, since only
701 1.1 skrll one will ever be executed at a time. */
702 1.1 skrll if ((op1->ecc == ECC_TX && op2->ecc == ECC_FX)
703 1.1 skrll || (op1->ecc == ECC_FX && op2->ecc == ECC_TX)
704 1.1 skrll || (op1->ecc == ECC_XT && op2->ecc == ECC_XF)
705 1.1 skrll || (op1->ecc == ECC_XF && op2->ecc == ECC_XT))
706 1.1 skrll return 1;
707 1.1 skrll
708 1.1 skrll /* [0] r0-r31
709 1.1 skrll [1] r32-r63
710 1.1 skrll [2] a0, a1, flag registers. */
711 1.1 skrll for (j = 0; j < 2; j++)
712 1.1 skrll {
713 1.1 skrll if (j == 0)
714 1.1 skrll {
715 1.1 skrll f = op1->form;
716 1.1 skrll op = op1->op;
717 1.1 skrll ecc = op1->ecc;
718 1.1 skrll ins = insn1;
719 1.1 skrll }
720 1.1 skrll else
721 1.1 skrll {
722 1.1 skrll f = op2->form;
723 1.1 skrll op = op2->op;
724 1.1 skrll ecc = op2->ecc;
725 1.1 skrll ins = insn2;
726 1.1 skrll }
727 1.1 skrll
728 1.1 skrll flag_reg[j] = 0;
729 1.1 skrll mod_reg[j][0] = mod_reg[j][1] = 0;
730 1.1 skrll used_reg[j][0] = used_reg[j][1] = 0;
731 1.1 skrll
732 1.1 skrll if (flag_explicitly_parallel)
733 1.1 skrll {
734 1.1 skrll /* For human specified parallel instructions we have been asked
735 1.1 skrll to ignore the possibility that both instructions could modify
736 1.1 skrll bits in the PSW, so we initialise the mod & used arrays to 0.
737 1.1 skrll We have been asked, however, to refuse to allow parallel
738 1.1 skrll instructions which explicitly set the same flag register,
739 1.1 skrll eg "cmpne f0,r1,0x10 || cmpeq f0, r5, 0x2", so further on we test
740 1.1 skrll for the use of a flag register and set a bit in the mod or used
741 1.1 skrll array appropriately. */
742 1.1 skrll mod_reg[j][2] = 0;
743 1.1 skrll used_reg[j][2] = 0;
744 1.1 skrll }
745 1.1 skrll else
746 1.1 skrll {
747 1.1 skrll mod_reg[j][2] = (op->flags_set & FLAG_ALL);
748 1.1 skrll used_reg[j][2] = (op->flags_used & FLAG_ALL);
749 1.1 skrll }
750 1.1 skrll
751 1.1 skrll /* BSR/JSR always sets R62. */
752 1.1 skrll if (op->flags_used & FLAG_JSR)
753 1.1 skrll mod_reg[j][1] = (1L << (62 - 32));
754 1.1 skrll
755 1.1 skrll /* Conditional execution affects the flags_used. */
756 1.1 skrll switch (ecc)
757 1.1 skrll {
758 1.1 skrll case ECC_TX:
759 1.1 skrll case ECC_FX:
760 1.1 skrll used_reg[j][2] |= flag_reg[j] = FLAG_0;
761 1.1 skrll break;
762 1.1 skrll
763 1.1 skrll case ECC_XT:
764 1.1 skrll case ECC_XF:
765 1.1 skrll used_reg[j][2] |= flag_reg[j] = FLAG_1;
766 1.1 skrll break;
767 1.1 skrll
768 1.1 skrll case ECC_TT:
769 1.1 skrll case ECC_TF:
770 1.1 skrll used_reg[j][2] |= flag_reg[j] = (FLAG_0 | FLAG_1);
771 1.1 skrll break;
772 1.1 skrll }
773 1.1 skrll
774 1.1 skrll for (i = 0; f->operands[i]; i++)
775 1.1 skrll {
776 1.1 skrll flags = d30v_operand_table[f->operands[i]].flags;
777 1.1 skrll shift = 12 - d30v_operand_table[f->operands[i]].position;
778 1.1 skrll bits = d30v_operand_table[f->operands[i]].bits;
779 1.1 skrll if (bits == 32)
780 1.1 skrll mask = 0xffffffff;
781 1.1 skrll else
782 1.1 skrll mask = 0x7FFFFFFF >> (31 - bits);
783 1.1 skrll
784 1.1 skrll if ((flags & OPERAND_PLUS) || (flags & OPERAND_MINUS))
785 1.1 skrll {
786 1.1 skrll /* This is a post-increment or post-decrement.
787 1.1 skrll The previous register needs to be marked as modified. */
788 1.1 skrll shift = 12 - d30v_operand_table[f->operands[i - 1]].position;
789 1.1 skrll regno = (ins >> shift) & 0x3f;
790 1.1 skrll if (regno >= 32)
791 1.1 skrll mod_reg[j][1] |= 1L << (regno - 32);
792 1.1 skrll else
793 1.1 skrll mod_reg[j][0] |= 1L << regno;
794 1.1 skrll }
795 1.1 skrll else if (flags & OPERAND_REG)
796 1.1 skrll {
797 1.1 skrll regno = (ins >> shift) & mask;
798 1.1 skrll /* The memory write functions don't have a destination
799 1.1 skrll register. */
800 1.1 skrll if ((flags & OPERAND_DEST) && !(op->flags_set & FLAG_MEM))
801 1.1 skrll {
802 1.1 skrll /* MODIFIED registers and flags. */
803 1.1 skrll if (flags & OPERAND_ACC)
804 1.1 skrll {
805 1.1 skrll if (regno == 0)
806 1.1 skrll mod_reg[j][2] |= FLAG_A0;
807 1.1 skrll else if (regno == 1)
808 1.1 skrll mod_reg[j][2] |= FLAG_A1;
809 1.1 skrll else
810 1.1 skrll abort ();
811 1.1 skrll }
812 1.1 skrll else if (flags & OPERAND_FLAG)
813 1.1 skrll mod_reg[j][2] |= 1L << regno;
814 1.1 skrll else if (!(flags & OPERAND_CONTROL))
815 1.1 skrll {
816 1.1 skrll int r, z;
817 1.1 skrll
818 1.1 skrll /* Need to check if there are two destination
819 1.1 skrll registers, for example ld2w. */
820 1.1 skrll if (flags & OPERAND_2REG)
821 1.1 skrll z = 1;
822 1.1 skrll else
823 1.1 skrll z = 0;
824 1.1 skrll
825 1.1 skrll for (r = regno; r <= regno + z; r++)
826 1.1 skrll {
827 1.1 skrll if (r >= 32)
828 1.1 skrll mod_reg[j][1] |= 1L << (r - 32);
829 1.1 skrll else
830 1.1 skrll mod_reg[j][0] |= 1L << r;
831 1.1 skrll }
832 1.1 skrll }
833 1.1 skrll }
834 1.1 skrll else
835 1.1 skrll {
836 1.1 skrll /* USED, but not modified registers and flags. */
837 1.1 skrll if (flags & OPERAND_ACC)
838 1.1 skrll {
839 1.1 skrll if (regno == 0)
840 1.1 skrll used_reg[j][2] |= FLAG_A0;
841 1.1 skrll else if (regno == 1)
842 1.1 skrll used_reg[j][2] |= FLAG_A1;
843 1.1 skrll else
844 1.1 skrll abort ();
845 1.1 skrll }
846 1.1 skrll else if (flags & OPERAND_FLAG)
847 1.1 skrll used_reg[j][2] |= 1L << regno;
848 1.1 skrll else if (!(flags & OPERAND_CONTROL))
849 1.1 skrll {
850 1.1 skrll int r, z;
851 1.1 skrll
852 1.1 skrll /* Need to check if there are two source
853 1.1 skrll registers, for example st2w. */
854 1.1 skrll if (flags & OPERAND_2REG)
855 1.1 skrll z = 1;
856 1.1 skrll else
857 1.1 skrll z = 0;
858 1.1 skrll
859 1.1 skrll for (r = regno; r <= regno + z; r++)
860 1.1 skrll {
861 1.1 skrll if (r >= 32)
862 1.1.1.7 christos used_reg[j][1] |= 1UL << (r - 32);
863 1.1 skrll else
864 1.1.1.7 christos used_reg[j][0] |= 1UL << r;
865 1.1 skrll }
866 1.1 skrll }
867 1.1 skrll }
868 1.1 skrll }
869 1.1 skrll }
870 1.1 skrll }
871 1.1 skrll
872 1.1 skrll flags_set1 = op1->op->flags_set;
873 1.1 skrll flags_set2 = op2->op->flags_set;
874 1.1 skrll flags_used1 = op1->op->flags_used;
875 1.1 skrll flags_used2 = op2->op->flags_used;
876 1.1 skrll
877 1.1 skrll /* Check for illegal combinations with ADDppp/SUBppp. */
878 1.1 skrll if (((flags_set1 & FLAG_NOT_WITH_ADDSUBppp) != 0
879 1.1 skrll && (flags_used2 & FLAG_ADDSUBppp) != 0)
880 1.1 skrll || ((flags_set2 & FLAG_NOT_WITH_ADDSUBppp) != 0
881 1.1 skrll && (flags_used1 & FLAG_ADDSUBppp) != 0))
882 1.1 skrll return 0;
883 1.1 skrll
884 1.1 skrll /* Load instruction combined with half-word multiply is illegal. */
885 1.1 skrll if (((flags_used1 & FLAG_MEM) != 0 && (flags_used2 & FLAG_MUL16))
886 1.1 skrll || ((flags_used2 & FLAG_MEM) != 0 && (flags_used1 & FLAG_MUL16)))
887 1.1 skrll return 0;
888 1.1 skrll
889 1.1 skrll /* Specifically allow add || add by removing carry, overflow bits dependency.
890 1.1 skrll This is safe, even if an addc follows since the IU takes the argument in
891 1.1 skrll the right container, and it writes its results last.
892 1.1 skrll However, don't paralellize add followed by addc or sub followed by
893 1.1 skrll subb. */
894 1.1 skrll if (mod_reg[0][2] == FLAG_CVVA && mod_reg[1][2] == FLAG_CVVA
895 1.1 skrll && (used_reg[0][2] & ~flag_reg[0]) == 0
896 1.1 skrll && (used_reg[1][2] & ~flag_reg[1]) == 0
897 1.1 skrll && op1->op->unit == EITHER && op2->op->unit == EITHER)
898 1.1 skrll {
899 1.1 skrll mod_reg[0][2] = mod_reg[1][2] = 0;
900 1.1 skrll }
901 1.1 skrll
902 1.1 skrll for (j = 0; j < 3; j++)
903 1.1 skrll {
904 1.1 skrll /* If the second instruction depends on the first, we obviously
905 1.1 skrll cannot parallelize. Note, the mod flag implies use, so
906 1.1 skrll check that as well. */
907 1.1 skrll /* If flag_explicitly_parallel is set, then the case of the
908 1.1 skrll second instruction using a register the first instruction
909 1.1 skrll modifies is assumed to be okay; we trust the human. We
910 1.1 skrll don't trust the human if both instructions modify the same
911 1.1 skrll register but we do trust the human if they modify the same
912 1.1 skrll flags. */
913 1.1 skrll /* We have now been requested not to trust the human if the
914 1.1 skrll instructions modify the same flag registers either. */
915 1.1 skrll if (flag_explicitly_parallel)
916 1.1 skrll {
917 1.1 skrll if ((mod_reg[0][j] & mod_reg[1][j]) != 0)
918 1.1 skrll return 0;
919 1.1 skrll }
920 1.1 skrll else
921 1.1 skrll if ((mod_reg[0][j] & (mod_reg[1][j] | used_reg[1][j])) != 0)
922 1.1 skrll return 0;
923 1.1 skrll }
924 1.1 skrll
925 1.1 skrll return 1;
926 1.1 skrll }
927 1.1 skrll
928 1.1 skrll /* Write out a short form instruction if possible.
929 1.1 skrll Return number of instructions not written out. */
930 1.1 skrll
931 1.1 skrll static int
932 1.1 skrll write_2_short (struct d30v_insn *opcode1,
933 1.1 skrll long long insn1,
934 1.1 skrll struct d30v_insn *opcode2,
935 1.1 skrll long long insn2,
936 1.1 skrll exec_type_enum exec_type,
937 1.1 skrll Fixups *fx)
938 1.1 skrll {
939 1.1 skrll long long insn = NOP2;
940 1.1 skrll char *f;
941 1.1 skrll int i, j, where;
942 1.1 skrll
943 1.1 skrll if (exec_type == EXEC_SEQ
944 1.1 skrll && (opcode1->op->flags_used & (FLAG_JMP | FLAG_JSR))
945 1.1 skrll && ((opcode1->op->flags_used & FLAG_DELAY) == 0)
946 1.1 skrll && ((opcode1->ecc == ECC_AL) || ! Optimizing))
947 1.1 skrll {
948 1.1 skrll /* Unconditional, non-delayed branches kill instructions in
949 1.1 skrll the right bin. Conditional branches don't always but if
950 1.1 skrll we are not optimizing, then we have been asked to produce
951 1.1 skrll an error about such constructs. For the purposes of this
952 1.1 skrll test, subroutine calls are considered to be branches. */
953 1.1.1.7 christos write_1_short (opcode1, insn1, fx->next, false);
954 1.1 skrll return 1;
955 1.1 skrll }
956 1.1 skrll
957 1.1 skrll /* Note: we do not have to worry about subroutine calls occurring
958 1.1 skrll in the right hand container. The return address is always
959 1.1 skrll aligned to the next 64 bit boundary, be that 64 or 32 bit away. */
960 1.1 skrll switch (exec_type)
961 1.1 skrll {
962 1.1 skrll case EXEC_UNKNOWN: /* Order not specified. */
963 1.1 skrll if (Optimizing
964 1.1 skrll && parallel_ok (opcode1, insn1, opcode2, insn2, exec_type)
965 1.1 skrll && ! ( (opcode1->op->unit == EITHER_BUT_PREFER_MU
966 1.1 skrll || opcode1->op->unit == MU)
967 1.1 skrll &&
968 1.1 skrll ( opcode2->op->unit == EITHER_BUT_PREFER_MU
969 1.1 skrll || opcode2->op->unit == MU)))
970 1.1 skrll {
971 1.1 skrll /* Parallel. */
972 1.1 skrll exec_type = EXEC_PARALLEL;
973 1.1 skrll
974 1.1 skrll if (opcode1->op->unit == IU
975 1.1 skrll || opcode2->op->unit == MU
976 1.1 skrll || opcode2->op->unit == EITHER_BUT_PREFER_MU)
977 1.1 skrll insn = FM00 | (insn2 << 32) | insn1;
978 1.1 skrll else
979 1.1 skrll {
980 1.1 skrll insn = FM00 | (insn1 << 32) | insn2;
981 1.1 skrll fx = fx->next;
982 1.1 skrll }
983 1.1 skrll }
984 1.1 skrll else if ((opcode1->op->flags_used & (FLAG_JMP | FLAG_JSR)
985 1.1 skrll && ((opcode1->op->flags_used & FLAG_DELAY) == 0))
986 1.1 skrll || opcode1->op->flags_used & FLAG_RP)
987 1.1 skrll {
988 1.1 skrll /* We must emit (non-delayed) branch type instructions
989 1.1 skrll on their own with nothing in the right container. */
990 1.1 skrll /* We must treat repeat instructions likewise, since the
991 1.1 skrll following instruction has to be separate from the repeat
992 1.1 skrll in order to be repeated. */
993 1.1.1.7 christos write_1_short (opcode1, insn1, fx->next, false);
994 1.1 skrll return 1;
995 1.1 skrll }
996 1.1 skrll else if (prev_left_kills_right_p)
997 1.1 skrll {
998 1.1.1.5 christos /* The left instruction kills the right slot, so we
999 1.1 skrll must leave it empty. */
1000 1.1.1.7 christos write_1_short (opcode1, insn1, fx->next, false);
1001 1.1 skrll return 1;
1002 1.1 skrll }
1003 1.1 skrll else if (opcode1->op->unit == IU)
1004 1.1 skrll {
1005 1.1 skrll if (opcode2->op->unit == EITHER_BUT_PREFER_MU)
1006 1.1 skrll {
1007 1.1 skrll /* Case 103810 is a request from Mitsubishi that opcodes
1008 1.1 skrll with EITHER_BUT_PREFER_MU should not be executed in
1009 1.1 skrll reverse sequential order. */
1010 1.1.1.7 christos write_1_short (opcode1, insn1, fx->next, false);
1011 1.1 skrll return 1;
1012 1.1 skrll }
1013 1.1 skrll
1014 1.1 skrll /* Reverse sequential. */
1015 1.1 skrll insn = FM10 | (insn2 << 32) | insn1;
1016 1.1 skrll exec_type = EXEC_REVSEQ;
1017 1.1 skrll }
1018 1.1 skrll else
1019 1.1 skrll {
1020 1.1 skrll /* Sequential. */
1021 1.1 skrll insn = FM01 | (insn1 << 32) | insn2;
1022 1.1 skrll fx = fx->next;
1023 1.1 skrll exec_type = EXEC_SEQ;
1024 1.1 skrll }
1025 1.1 skrll break;
1026 1.1 skrll
1027 1.1 skrll case EXEC_PARALLEL: /* Parallel. */
1028 1.1 skrll flag_explicitly_parallel = flag_xp_state;
1029 1.1 skrll if (! parallel_ok (opcode1, insn1, opcode2, insn2, exec_type))
1030 1.1 skrll as_bad (_("Instructions may not be executed in parallel"));
1031 1.1 skrll else if (opcode1->op->unit == IU)
1032 1.1 skrll {
1033 1.1 skrll if (opcode2->op->unit == IU)
1034 1.1 skrll as_bad (_("Two IU instructions may not be executed in parallel"));
1035 1.1 skrll as_warn (_("Swapping instruction order"));
1036 1.1 skrll insn = FM00 | (insn2 << 32) | insn1;
1037 1.1 skrll }
1038 1.1 skrll else if (opcode2->op->unit == MU)
1039 1.1 skrll {
1040 1.1 skrll if (opcode1->op->unit == MU)
1041 1.1 skrll as_bad (_("Two MU instructions may not be executed in parallel"));
1042 1.1 skrll else if (opcode1->op->unit == EITHER_BUT_PREFER_MU)
1043 1.1 skrll as_warn (_("Executing %s in IU may not work"), opcode1->op->name);
1044 1.1 skrll as_warn (_("Swapping instruction order"));
1045 1.1 skrll insn = FM00 | (insn2 << 32) | insn1;
1046 1.1 skrll }
1047 1.1 skrll else
1048 1.1 skrll {
1049 1.1 skrll if (opcode2->op->unit == EITHER_BUT_PREFER_MU)
1050 1.1 skrll as_warn (_("Executing %s in IU may not work in parallel execution"),
1051 1.1 skrll opcode2->op->name);
1052 1.1 skrll
1053 1.1 skrll insn = FM00 | (insn1 << 32) | insn2;
1054 1.1 skrll fx = fx->next;
1055 1.1 skrll }
1056 1.1 skrll flag_explicitly_parallel = 0;
1057 1.1 skrll break;
1058 1.1 skrll
1059 1.1 skrll case EXEC_SEQ: /* Sequential. */
1060 1.1 skrll if (opcode1->op->unit == IU)
1061 1.1 skrll as_bad (_("IU instruction may not be in the left container"));
1062 1.1 skrll if (prev_left_kills_right_p)
1063 1.1 skrll as_bad (_("special left instruction `%s' kills instruction "
1064 1.1 skrll "`%s' in right container"),
1065 1.1 skrll opcode1->op->name, opcode2->op->name);
1066 1.1 skrll insn = FM01 | (insn1 << 32) | insn2;
1067 1.1 skrll fx = fx->next;
1068 1.1 skrll break;
1069 1.1 skrll
1070 1.1 skrll case EXEC_REVSEQ: /* Reverse sequential. */
1071 1.1 skrll if (opcode2->op->unit == MU)
1072 1.1 skrll as_bad (_("MU instruction may not be in the right container"));
1073 1.1 skrll if (opcode1->op->unit == EITHER_BUT_PREFER_MU)
1074 1.1 skrll as_warn (_("Executing %s in reverse serial with %s may not work"),
1075 1.1 skrll opcode1->op->name, opcode2->op->name);
1076 1.1 skrll else if (opcode2->op->unit == EITHER_BUT_PREFER_MU)
1077 1.1 skrll as_warn (_("Executing %s in IU in reverse serial may not work"),
1078 1.1 skrll opcode2->op->name);
1079 1.1 skrll insn = FM10 | (insn1 << 32) | insn2;
1080 1.1 skrll fx = fx->next;
1081 1.1 skrll break;
1082 1.1 skrll
1083 1.1 skrll default:
1084 1.1 skrll as_fatal (_("unknown execution type passed to write_2_short()"));
1085 1.1 skrll }
1086 1.1 skrll
1087 1.1 skrll f = frag_more (8);
1088 1.1.1.2 christos dwarf2_emit_insn (8);
1089 1.1 skrll d30v_number_to_chars (f, insn, 8);
1090 1.1 skrll
1091 1.1 skrll /* If the previous instruction was a 32-bit multiply but it is put into a
1092 1.1 skrll parallel container, mark the current instruction as being a 32-bit
1093 1.1 skrll multiply. */
1094 1.1 skrll if (prev_mul32_p && exec_type == EXEC_PARALLEL)
1095 1.1 skrll cur_mul32_p = 1;
1096 1.1 skrll
1097 1.1 skrll for (j = 0; j < 2; j++)
1098 1.1 skrll {
1099 1.1 skrll for (i = 0; i < fx->fc; i++)
1100 1.1 skrll {
1101 1.1 skrll if (fx->fix[i].reloc)
1102 1.1 skrll {
1103 1.1 skrll where = (f - frag_now->fr_literal) + 4 * j;
1104 1.1 skrll
1105 1.1 skrll fix_new_exp (frag_now,
1106 1.1 skrll where,
1107 1.1 skrll fx->fix[i].size,
1108 1.1 skrll &(fx->fix[i].exp),
1109 1.1 skrll fx->fix[i].pcrel,
1110 1.1 skrll fx->fix[i].reloc);
1111 1.1 skrll }
1112 1.1 skrll }
1113 1.1 skrll
1114 1.1 skrll fx->fc = 0;
1115 1.1 skrll fx = fx->next;
1116 1.1 skrll }
1117 1.1 skrll
1118 1.1 skrll return 0;
1119 1.1 skrll }
1120 1.1 skrll
1121 1.1 skrll /* Get a pointer to an entry in the format table.
1122 1.1 skrll It must look at all formats for an opcode and use the operands
1123 1.1 skrll to choose the correct one. Return NULL on error. */
1124 1.1 skrll
1125 1.1.1.9 christos static const struct d30v_format *
1126 1.1.1.9 christos find_format (const struct d30v_opcode *opcode,
1127 1.1 skrll expressionS myops[],
1128 1.1 skrll int fsize,
1129 1.1 skrll int cmp_hack)
1130 1.1 skrll {
1131 1.1.1.2 christos int match, opcode_index, i = 0, j, k;
1132 1.1.1.9 christos const struct d30v_format *fm;
1133 1.1 skrll
1134 1.1 skrll if (opcode == NULL)
1135 1.1 skrll return NULL;
1136 1.1 skrll
1137 1.1 skrll /* Get all the operands and save them as expressions. */
1138 1.1.1.2 christos get_operands (myops, cmp_hack);
1139 1.1 skrll
1140 1.1.1.2 christos while ((opcode_index = opcode->format[i++]) != 0)
1141 1.1 skrll {
1142 1.1.1.2 christos if (fsize == FORCE_SHORT && opcode_index >= LONG)
1143 1.1 skrll continue;
1144 1.1 skrll
1145 1.1.1.2 christos if (fsize == FORCE_LONG && opcode_index < LONG)
1146 1.1 skrll continue;
1147 1.1 skrll
1148 1.1.1.9 christos fm = &d30v_format_table[opcode_index];
1149 1.1.1.2 christos k = opcode_index;
1150 1.1.1.2 christos while (fm->form == opcode_index)
1151 1.1 skrll {
1152 1.1 skrll match = 1;
1153 1.1 skrll /* Now check the operands for compatibility. */
1154 1.1 skrll for (j = 0; match && fm->operands[j]; j++)
1155 1.1 skrll {
1156 1.1 skrll int flags = d30v_operand_table[fm->operands[j]].flags;
1157 1.1 skrll int bits = d30v_operand_table[fm->operands[j]].bits;
1158 1.1.1.4 christos operatorT X_op = myops[j].X_op;
1159 1.1 skrll int num = myops[j].X_add_number;
1160 1.1 skrll
1161 1.1 skrll if (flags & OPERAND_SPECIAL)
1162 1.1 skrll break;
1163 1.1 skrll else if (X_op == O_illegal)
1164 1.1 skrll match = 0;
1165 1.1 skrll else if (flags & OPERAND_REG)
1166 1.1 skrll {
1167 1.1 skrll if (X_op != O_register
1168 1.1 skrll || ((flags & OPERAND_ACC) && !(num & OPERAND_ACC))
1169 1.1 skrll || (!(flags & OPERAND_ACC) && (num & OPERAND_ACC))
1170 1.1 skrll || ((flags & OPERAND_FLAG) && !(num & OPERAND_FLAG))
1171 1.1 skrll || (!(flags & (OPERAND_FLAG | OPERAND_CONTROL)) && (num & OPERAND_FLAG))
1172 1.1 skrll || ((flags & OPERAND_CONTROL)
1173 1.1 skrll && !(num & (OPERAND_CONTROL | OPERAND_FLAG))))
1174 1.1 skrll match = 0;
1175 1.1 skrll }
1176 1.1 skrll else if (((flags & OPERAND_MINUS)
1177 1.1 skrll && (X_op != O_absent || num != OPERAND_MINUS))
1178 1.1 skrll || ((flags & OPERAND_PLUS)
1179 1.1 skrll && (X_op != O_absent || num != OPERAND_PLUS))
1180 1.1 skrll || ((flags & OPERAND_ATMINUS)
1181 1.1 skrll && (X_op != O_absent || num != OPERAND_ATMINUS))
1182 1.1 skrll || ((flags & OPERAND_ATPAR)
1183 1.1 skrll && (X_op != O_absent || num != OPERAND_ATPAR))
1184 1.1 skrll || ((flags & OPERAND_ATSIGN)
1185 1.1 skrll && (X_op != O_absent || num != OPERAND_ATSIGN)))
1186 1.1 skrll match = 0;
1187 1.1 skrll else if (flags & OPERAND_NUM)
1188 1.1 skrll {
1189 1.1 skrll /* A number can be a constant or symbol expression. */
1190 1.1 skrll
1191 1.1 skrll /* If we have found a register name, but that name
1192 1.1 skrll also matches a symbol, then re-parse the name as
1193 1.1 skrll an expression. */
1194 1.1 skrll if (X_op == O_register
1195 1.1 skrll && symbol_find ((char *) myops[j].X_op_symbol))
1196 1.1 skrll {
1197 1.1 skrll input_line_pointer = (char *) myops[j].X_op_symbol;
1198 1.1 skrll expression (&myops[j]);
1199 1.1 skrll }
1200 1.1 skrll
1201 1.1 skrll /* Turn an expression into a symbol for later resolution. */
1202 1.1 skrll if (X_op != O_absent && X_op != O_constant
1203 1.1 skrll && X_op != O_symbol && X_op != O_register
1204 1.1 skrll && X_op != O_big)
1205 1.1 skrll {
1206 1.1 skrll symbolS *sym = make_expr_symbol (&myops[j]);
1207 1.1 skrll myops[j].X_op = X_op = O_symbol;
1208 1.1 skrll myops[j].X_add_symbol = sym;
1209 1.1 skrll myops[j].X_add_number = num = 0;
1210 1.1 skrll }
1211 1.1 skrll
1212 1.1 skrll if (fm->form >= LONG)
1213 1.1 skrll {
1214 1.1 skrll /* If we're testing for a LONG format, either fits. */
1215 1.1 skrll if (X_op != O_constant && X_op != O_symbol)
1216 1.1 skrll match = 0;
1217 1.1 skrll }
1218 1.1 skrll else if (fm->form < LONG
1219 1.1 skrll && ((fsize == FORCE_SHORT && X_op == O_symbol)
1220 1.1 skrll || (fm->form == SHORT_D2 && j == 0)))
1221 1.1 skrll match = 1;
1222 1.1 skrll
1223 1.1 skrll /* This is the tricky part. Will the constant or symbol
1224 1.1 skrll fit into the space in the current format? */
1225 1.1 skrll else if (X_op == O_constant)
1226 1.1 skrll {
1227 1.1 skrll if (check_range (num, bits, flags))
1228 1.1 skrll match = 0;
1229 1.1 skrll }
1230 1.1 skrll else if (X_op == O_symbol
1231 1.1 skrll && S_IS_DEFINED (myops[j].X_add_symbol)
1232 1.1 skrll && S_GET_SEGMENT (myops[j].X_add_symbol) == now_seg
1233 1.1 skrll && opcode->reloc_flag == RELOC_PCREL)
1234 1.1 skrll {
1235 1.1 skrll /* If the symbol is defined, see if the value will fit
1236 1.1 skrll into the form we're considering. */
1237 1.1 skrll fragS *f;
1238 1.1 skrll long value;
1239 1.1 skrll
1240 1.1 skrll /* Calculate the current address by running through the
1241 1.1 skrll previous frags and adding our current offset. */
1242 1.1.1.3 christos value = frag_now_fix_octets ();
1243 1.1 skrll for (f = frchain_now->frch_root; f; f = f->fr_next)
1244 1.1 skrll value += f->fr_fix + f->fr_offset;
1245 1.1.1.3 christos value = S_GET_VALUE (myops[j].X_add_symbol) - value;
1246 1.1 skrll if (check_range (value, bits, flags))
1247 1.1 skrll match = 0;
1248 1.1 skrll }
1249 1.1 skrll else
1250 1.1 skrll match = 0;
1251 1.1 skrll }
1252 1.1 skrll }
1253 1.1 skrll /* We're only done if the operands matched so far AND there
1254 1.1 skrll are no more to check. */
1255 1.1 skrll if (match && myops[j].X_op == 0)
1256 1.1 skrll {
1257 1.1 skrll /* Final check - issue a warning if an odd numbered register
1258 1.1 skrll is used as the first register in an instruction that reads
1259 1.1 skrll or writes 2 registers. */
1260 1.1 skrll
1261 1.1 skrll for (j = 0; fm->operands[j]; j++)
1262 1.1 skrll if (myops[j].X_op == O_register
1263 1.1 skrll && (myops[j].X_add_number & 1)
1264 1.1 skrll && (d30v_operand_table[fm->operands[j]].flags & OPERAND_2REG))
1265 1.1 skrll as_warn (_("Odd numbered register used as target of multi-register instruction"));
1266 1.1 skrll
1267 1.1 skrll return fm;
1268 1.1 skrll }
1269 1.1.1.9 christos fm = &d30v_format_table[++k];
1270 1.1 skrll }
1271 1.1 skrll }
1272 1.1 skrll return NULL;
1273 1.1 skrll }
1274 1.1 skrll
1275 1.1 skrll /* Assemble a single instruction and return an opcode.
1276 1.1 skrll Return -1 (an invalid opcode) on error. */
1277 1.1 skrll
1278 1.1 skrll #define NAME_BUF_LEN 20
1279 1.1 skrll
1280 1.1 skrll static long long
1281 1.1 skrll do_assemble (char *str,
1282 1.1 skrll struct d30v_insn *opcode,
1283 1.1 skrll int shortp,
1284 1.1 skrll int is_parallel)
1285 1.1 skrll {
1286 1.1 skrll char *op_start;
1287 1.1 skrll char *save;
1288 1.1 skrll char *op_end;
1289 1.1 skrll char name[NAME_BUF_LEN];
1290 1.1 skrll int cmp_hack;
1291 1.1 skrll int nlen = 0;
1292 1.1 skrll int fsize = (shortp ? FORCE_SHORT : 0);
1293 1.1 skrll expressionS myops[6];
1294 1.1 skrll long long insn;
1295 1.1 skrll
1296 1.1 skrll /* Drop leading whitespace. */
1297 1.1.1.9 christos while (is_whitespace (*str))
1298 1.1 skrll str++;
1299 1.1 skrll
1300 1.1 skrll /* Find the opcode end. */
1301 1.1 skrll for (op_start = op_end = str;
1302 1.1 skrll *op_end
1303 1.1 skrll && nlen < (NAME_BUF_LEN - 1)
1304 1.1 skrll && *op_end != '/'
1305 1.1.1.9 christos && !is_end_of_stmt (*op_end) && !is_whitespace (*op_end);
1306 1.1 skrll op_end++)
1307 1.1 skrll {
1308 1.1 skrll name[nlen] = TOLOWER (op_start[nlen]);
1309 1.1 skrll nlen++;
1310 1.1 skrll }
1311 1.1 skrll
1312 1.1 skrll if (nlen == 0)
1313 1.1 skrll return -1;
1314 1.1 skrll
1315 1.1 skrll name[nlen] = 0;
1316 1.1 skrll
1317 1.1 skrll /* If there is an execution condition code, handle it. */
1318 1.1 skrll if (*op_end == '/')
1319 1.1 skrll {
1320 1.1 skrll int i = 0;
1321 1.1 skrll while ((i < ECC_MAX) && strncasecmp (d30v_ecc_names[i], op_end + 1, 2))
1322 1.1 skrll i++;
1323 1.1 skrll
1324 1.1 skrll if (i == ECC_MAX)
1325 1.1 skrll {
1326 1.1 skrll char tmp[4];
1327 1.1 skrll strncpy (tmp, op_end + 1, 2);
1328 1.1 skrll tmp[2] = 0;
1329 1.1 skrll as_bad (_("unknown condition code: %s"), tmp);
1330 1.1 skrll return -1;
1331 1.1 skrll }
1332 1.1 skrll opcode->ecc = i;
1333 1.1 skrll op_end += 3;
1334 1.1 skrll }
1335 1.1 skrll else
1336 1.1 skrll opcode->ecc = ECC_AL;
1337 1.1 skrll
1338 1.1 skrll /* CMP and CMPU change their name based on condition codes. */
1339 1.1.1.7 christos if (startswith (name, "cmp"))
1340 1.1 skrll {
1341 1.1 skrll int p, i;
1342 1.1.1.9 christos const char **d30v_str = d30v_cc_names;
1343 1.1.1.2 christos
1344 1.1 skrll if (name[3] == 'u')
1345 1.1 skrll p = 4;
1346 1.1 skrll else
1347 1.1 skrll p = 3;
1348 1.1 skrll
1349 1.1.1.2 christos for (i = 1; *d30v_str && strncmp (*d30v_str, &name[p], 2); i++, d30v_str++)
1350 1.1 skrll ;
1351 1.1 skrll
1352 1.1 skrll /* cmpu only supports some condition codes. */
1353 1.1 skrll if (p == 4)
1354 1.1 skrll {
1355 1.1 skrll if (i < 3 || i > 6)
1356 1.1 skrll {
1357 1.1 skrll name[p + 2] = 0;
1358 1.1 skrll as_bad (_("cmpu doesn't support condition code %s"), &name[p]);
1359 1.1 skrll }
1360 1.1 skrll }
1361 1.1 skrll
1362 1.1.1.2 christos if (!*d30v_str)
1363 1.1 skrll {
1364 1.1 skrll name[p + 2] = 0;
1365 1.1 skrll as_bad (_("unknown condition code: %s"), &name[p]);
1366 1.1 skrll }
1367 1.1 skrll
1368 1.1 skrll cmp_hack = i;
1369 1.1 skrll name[p] = 0;
1370 1.1 skrll }
1371 1.1 skrll else
1372 1.1 skrll cmp_hack = 0;
1373 1.1 skrll
1374 1.1 skrll /* Need to look for .s or .l. */
1375 1.1 skrll if (name[nlen - 2] == '.')
1376 1.1 skrll {
1377 1.1 skrll switch (name[nlen - 1])
1378 1.1 skrll {
1379 1.1 skrll case 's':
1380 1.1 skrll fsize = FORCE_SHORT;
1381 1.1 skrll break;
1382 1.1 skrll case 'l':
1383 1.1 skrll fsize = FORCE_LONG;
1384 1.1 skrll break;
1385 1.1 skrll }
1386 1.1 skrll name[nlen - 2] = 0;
1387 1.1 skrll }
1388 1.1 skrll
1389 1.1 skrll /* Find the first opcode with the proper name. */
1390 1.1.1.9 christos opcode->op = str_hash_find (d30v_hash, name);
1391 1.1 skrll if (opcode->op == NULL)
1392 1.1 skrll {
1393 1.1 skrll as_bad (_("unknown opcode: %s"), name);
1394 1.1 skrll return -1;
1395 1.1 skrll }
1396 1.1 skrll
1397 1.1 skrll save = input_line_pointer;
1398 1.1 skrll input_line_pointer = op_end;
1399 1.1 skrll while (!(opcode->form = find_format (opcode->op, myops, fsize, cmp_hack)))
1400 1.1 skrll {
1401 1.1 skrll opcode->op++;
1402 1.1 skrll if (opcode->op->name == NULL || strcmp (opcode->op->name, name))
1403 1.1 skrll {
1404 1.1 skrll as_bad (_("operands for opcode `%s' do not match any valid format"),
1405 1.1 skrll name);
1406 1.1 skrll return -1;
1407 1.1 skrll }
1408 1.1 skrll }
1409 1.1 skrll input_line_pointer = save;
1410 1.1 skrll
1411 1.1 skrll insn = build_insn (opcode, myops);
1412 1.1 skrll
1413 1.1 skrll /* Propagate multiply status. */
1414 1.1 skrll if (insn != -1)
1415 1.1 skrll {
1416 1.1 skrll if (is_parallel && prev_mul32_p)
1417 1.1 skrll cur_mul32_p = 1;
1418 1.1 skrll else
1419 1.1 skrll {
1420 1.1 skrll prev_mul32_p = cur_mul32_p;
1421 1.1 skrll cur_mul32_p = (opcode->op->flags_used & FLAG_MUL32) != 0;
1422 1.1 skrll }
1423 1.1 skrll }
1424 1.1 skrll
1425 1.1 skrll /* Propagate left_kills_right status. */
1426 1.1 skrll if (insn != -1)
1427 1.1 skrll {
1428 1.1 skrll prev_left_kills_right_p = cur_left_kills_right_p;
1429 1.1 skrll
1430 1.1 skrll if (opcode->op->flags_set & FLAG_LKR)
1431 1.1 skrll {
1432 1.1 skrll cur_left_kills_right_p = 1;
1433 1.1 skrll
1434 1.1 skrll if (strcmp (opcode->op->name, "mvtsys") == 0)
1435 1.1 skrll {
1436 1.1 skrll /* Left kills right for only mvtsys only for
1437 1.1 skrll PSW/PSWH/PSWL/flags target. */
1438 1.1 skrll if ((myops[0].X_op == O_register) &&
1439 1.1 skrll ((myops[0].X_add_number == OPERAND_CONTROL) || /* psw */
1440 1.1 skrll (myops[0].X_add_number == OPERAND_CONTROL+MAX_CONTROL_REG+2) || /* pswh */
1441 1.1 skrll (myops[0].X_add_number == OPERAND_CONTROL+MAX_CONTROL_REG+1) || /* pswl */
1442 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+0) || /* f0 */
1443 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+1) || /* f1 */
1444 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+2) || /* f2 */
1445 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+3) || /* f3 */
1446 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+4) || /* f4 */
1447 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+5) || /* f5 */
1448 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+6) || /* f6 */
1449 1.1 skrll (myops[0].X_add_number == OPERAND_FLAG+7))) /* f7 */
1450 1.1 skrll {
1451 1.1 skrll cur_left_kills_right_p = 1;
1452 1.1 skrll }
1453 1.1 skrll else
1454 1.1 skrll {
1455 1.1 skrll /* Other mvtsys target registers don't kill right
1456 1.1 skrll instruction. */
1457 1.1 skrll cur_left_kills_right_p = 0;
1458 1.1 skrll }
1459 1.1 skrll } /* mvtsys */
1460 1.1 skrll }
1461 1.1 skrll else
1462 1.1 skrll cur_left_kills_right_p = 0;
1463 1.1 skrll }
1464 1.1 skrll
1465 1.1 skrll return insn;
1466 1.1 skrll }
1467 1.1 skrll
1468 1.1 skrll /* Called internally to handle all alignment needs. This takes care
1469 1.1 skrll of eliding calls to frag_align if'n the cached current alignment
1470 1.1 skrll says we've already got it, as well as taking care of the auto-aligning
1471 1.1 skrll labels wrt code. */
1472 1.1 skrll
1473 1.1 skrll static void
1474 1.1 skrll d30v_align (int n, char *pfill, symbolS *label)
1475 1.1 skrll {
1476 1.1 skrll /* The front end is prone to changing segments out from under us
1477 1.1 skrll temporarily when -g is in effect. */
1478 1.1 skrll int switched_seg_p = (d30v_current_align_seg != now_seg);
1479 1.1 skrll
1480 1.1 skrll /* Do not assume that if 'd30v_current_align >= n' and
1481 1.1 skrll '! switched_seg_p' that it is safe to avoid performing
1482 1.1 skrll this alignment request. The alignment of the current frag
1483 1.1 skrll can be changed under our feet, for example by a .ascii
1484 1.1 skrll directive in the source code. cf testsuite/gas/d30v/reloc.s */
1485 1.1.1.7 christos d30v_cleanup (false);
1486 1.1 skrll
1487 1.1 skrll if (pfill == NULL)
1488 1.1 skrll {
1489 1.1 skrll if (n > 2
1490 1.1.1.6 christos && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
1491 1.1 skrll {
1492 1.1 skrll static char const nop[4] = { 0x00, 0xf0, 0x00, 0x00 };
1493 1.1 skrll
1494 1.1 skrll /* First, make sure we're on a four-byte boundary, in case
1495 1.1 skrll someone has been putting .byte values the text section. */
1496 1.1 skrll if (d30v_current_align < 2 || switched_seg_p)
1497 1.1 skrll frag_align (2, 0, 0);
1498 1.1 skrll frag_align_pattern (n, nop, sizeof nop, 0);
1499 1.1 skrll }
1500 1.1 skrll else
1501 1.1 skrll frag_align (n, 0, 0);
1502 1.1 skrll }
1503 1.1 skrll else
1504 1.1 skrll frag_align (n, *pfill, 0);
1505 1.1 skrll
1506 1.1 skrll if (!switched_seg_p)
1507 1.1 skrll d30v_current_align = n;
1508 1.1 skrll
1509 1.1 skrll if (label != NULL)
1510 1.1 skrll {
1511 1.1 skrll symbolS *sym;
1512 1.1.1.7 christos int label_seen = false;
1513 1.1 skrll struct frag *old_frag;
1514 1.1 skrll valueT old_value;
1515 1.1 skrll valueT new_value;
1516 1.1 skrll
1517 1.1.1.2 christos gas_assert (S_GET_SEGMENT (label) == now_seg);
1518 1.1 skrll
1519 1.1 skrll old_frag = symbol_get_frag (label);
1520 1.1 skrll old_value = S_GET_VALUE (label);
1521 1.1 skrll new_value = (valueT) frag_now_fix ();
1522 1.1 skrll
1523 1.1 skrll /* It is possible to have more than one label at a particular
1524 1.1 skrll address, especially if debugging is enabled, so we must
1525 1.1 skrll take care to adjust all the labels at this address in this
1526 1.1 skrll fragment. To save time we search from the end of the symbol
1527 1.1 skrll list, backwards, since the symbols we are interested in are
1528 1.1 skrll almost certainly the ones that were most recently added.
1529 1.1 skrll Also to save time we stop searching once we have seen at least
1530 1.1 skrll one matching label, and we encounter a label that is no longer
1531 1.1 skrll in the target fragment. Note, this search is guaranteed to
1532 1.1 skrll find at least one match when sym == label, so no special case
1533 1.1 skrll code is necessary. */
1534 1.1 skrll for (sym = symbol_lastP; sym != NULL; sym = symbol_previous (sym))
1535 1.1 skrll {
1536 1.1 skrll if (symbol_get_frag (sym) == old_frag
1537 1.1 skrll && S_GET_VALUE (sym) == old_value)
1538 1.1 skrll {
1539 1.1.1.7 christos label_seen = true;
1540 1.1 skrll symbol_set_frag (sym, frag_now);
1541 1.1 skrll S_SET_VALUE (sym, new_value);
1542 1.1 skrll }
1543 1.1 skrll else if (label_seen && symbol_get_frag (sym) != old_frag)
1544 1.1 skrll break;
1545 1.1 skrll }
1546 1.1 skrll }
1547 1.1 skrll
1548 1.1 skrll record_alignment (now_seg, n);
1549 1.1 skrll }
1550 1.1 skrll
1551 1.1 skrll /* This is the main entry point for the machine-dependent assembler.
1552 1.1 skrll STR points to a machine-dependent instruction. This function is
1553 1.1 skrll supposed to emit the frags/bytes it assembles to. For the D30V, it
1554 1.1 skrll mostly handles the special VLIW parsing and packing and leaves the
1555 1.1 skrll difficult stuff to do_assemble (). */
1556 1.1 skrll
1557 1.1 skrll static long long prev_insn = -1;
1558 1.1 skrll static struct d30v_insn prev_opcode;
1559 1.1 skrll static subsegT prev_subseg;
1560 1.1 skrll static segT prev_seg = 0;
1561 1.1 skrll
1562 1.1 skrll void
1563 1.1 skrll md_assemble (char *str)
1564 1.1 skrll {
1565 1.1 skrll struct d30v_insn opcode;
1566 1.1 skrll long long insn;
1567 1.1 skrll /* Execution type; parallel, etc. */
1568 1.1 skrll exec_type_enum extype = EXEC_UNKNOWN;
1569 1.1 skrll /* Saved extype. Used for multiline instructions. */
1570 1.1 skrll static exec_type_enum etype = EXEC_UNKNOWN;
1571 1.1 skrll char *str2;
1572 1.1 skrll
1573 1.1 skrll if ((prev_insn != -1) && prev_seg
1574 1.1 skrll && ((prev_seg != now_seg) || (prev_subseg != now_subseg)))
1575 1.1.1.7 christos d30v_cleanup (false);
1576 1.1 skrll
1577 1.1 skrll if (d30v_current_align < 3)
1578 1.1 skrll d30v_align (3, NULL, d30v_last_label);
1579 1.1 skrll else if (d30v_current_align > 3)
1580 1.1 skrll d30v_current_align = 3;
1581 1.1 skrll d30v_last_label = NULL;
1582 1.1 skrll
1583 1.1 skrll flag_explicitly_parallel = 0;
1584 1.1 skrll flag_xp_state = 0;
1585 1.1 skrll if (etype == EXEC_UNKNOWN)
1586 1.1 skrll {
1587 1.1 skrll /* Look for the special multiple instruction separators. */
1588 1.1 skrll str2 = strstr (str, "||");
1589 1.1 skrll if (str2)
1590 1.1 skrll {
1591 1.1 skrll extype = EXEC_PARALLEL;
1592 1.1 skrll flag_xp_state = 1;
1593 1.1 skrll }
1594 1.1 skrll else
1595 1.1 skrll {
1596 1.1 skrll str2 = strstr (str, "->");
1597 1.1 skrll if (str2)
1598 1.1 skrll extype = EXEC_SEQ;
1599 1.1 skrll else
1600 1.1 skrll {
1601 1.1 skrll str2 = strstr (str, "<-");
1602 1.1 skrll if (str2)
1603 1.1 skrll extype = EXEC_REVSEQ;
1604 1.1 skrll }
1605 1.1 skrll }
1606 1.1 skrll
1607 1.1 skrll /* STR2 points to the separator, if one. */
1608 1.1 skrll if (str2)
1609 1.1 skrll {
1610 1.1 skrll *str2 = 0;
1611 1.1 skrll
1612 1.1 skrll /* If two instructions are present and we already have one saved,
1613 1.1 skrll then first write it out. */
1614 1.1.1.7 christos d30v_cleanup (false);
1615 1.1 skrll
1616 1.1 skrll /* Assemble first instruction and save it. */
1617 1.1 skrll prev_insn = do_assemble (str, &prev_opcode, 1, 0);
1618 1.1 skrll if (prev_insn == -1)
1619 1.1 skrll as_bad (_("Cannot assemble instruction"));
1620 1.1 skrll if (prev_opcode.form != NULL && prev_opcode.form->form >= LONG)
1621 1.1 skrll as_bad (_("First opcode is long. Unable to mix instructions as specified."));
1622 1.1 skrll fixups = fixups->next;
1623 1.1 skrll str = str2 + 2;
1624 1.1 skrll prev_seg = now_seg;
1625 1.1 skrll prev_subseg = now_subseg;
1626 1.1 skrll }
1627 1.1 skrll }
1628 1.1 skrll
1629 1.1 skrll insn = do_assemble (str, &opcode,
1630 1.1 skrll (extype != EXEC_UNKNOWN || etype != EXEC_UNKNOWN),
1631 1.1 skrll extype == EXEC_PARALLEL);
1632 1.1 skrll if (insn == -1)
1633 1.1 skrll {
1634 1.1 skrll if (extype != EXEC_UNKNOWN)
1635 1.1 skrll etype = extype;
1636 1.1 skrll as_bad (_("Cannot assemble instruction"));
1637 1.1 skrll return;
1638 1.1 skrll }
1639 1.1 skrll
1640 1.1 skrll if (etype != EXEC_UNKNOWN)
1641 1.1 skrll {
1642 1.1 skrll extype = etype;
1643 1.1 skrll etype = EXEC_UNKNOWN;
1644 1.1 skrll }
1645 1.1 skrll
1646 1.1 skrll /* Word multiply instructions must not be followed by either a load or a
1647 1.1 skrll 16-bit multiply instruction in the next cycle. */
1648 1.1 skrll if ( (extype != EXEC_REVSEQ)
1649 1.1 skrll && prev_mul32_p
1650 1.1 skrll && (opcode.op->flags_used & (FLAG_MEM | FLAG_MUL16)))
1651 1.1 skrll {
1652 1.1 skrll /* However, load and multiply should able to be combined in a parallel
1653 1.1 skrll operation, so check for that first. */
1654 1.1 skrll if (prev_insn != -1
1655 1.1 skrll && (opcode.op->flags_used & FLAG_MEM)
1656 1.1 skrll && opcode.form->form < LONG
1657 1.1 skrll && (extype == EXEC_PARALLEL || (Optimizing && extype == EXEC_UNKNOWN))
1658 1.1 skrll && parallel_ok (&prev_opcode, (long) prev_insn,
1659 1.1 skrll &opcode, (long) insn, extype)
1660 1.1 skrll && write_2_short (&prev_opcode, (long) prev_insn,
1661 1.1 skrll &opcode, (long) insn, extype, fixups) == 0)
1662 1.1 skrll {
1663 1.1 skrll /* No instructions saved. */
1664 1.1 skrll prev_insn = -1;
1665 1.1 skrll return;
1666 1.1 skrll }
1667 1.1 skrll else
1668 1.1 skrll {
1669 1.1 skrll /* Can't parallelize, flush previous instruction and emit a
1670 1.1 skrll word of NOPS, unless the previous instruction is a NOP,
1671 1.1 skrll in which case just flush it, as this will generate a word
1672 1.1 skrll of NOPs for us. */
1673 1.1 skrll
1674 1.1 skrll if (prev_insn != -1 && (strcmp (prev_opcode.op->name, "nop") == 0))
1675 1.1.1.7 christos d30v_cleanup (false);
1676 1.1 skrll else
1677 1.1 skrll {
1678 1.1 skrll char *f;
1679 1.1 skrll
1680 1.1 skrll if (prev_insn != -1)
1681 1.1.1.7 christos d30v_cleanup (true);
1682 1.1 skrll else
1683 1.1 skrll {
1684 1.1 skrll f = frag_more (8);
1685 1.1.1.2 christos dwarf2_emit_insn (8);
1686 1.1 skrll d30v_number_to_chars (f, NOP2, 8);
1687 1.1 skrll
1688 1.1 skrll if (warn_nops == NOP_ALL || warn_nops == NOP_MULTIPLY)
1689 1.1 skrll {
1690 1.1 skrll if (opcode.op->flags_used & FLAG_MEM)
1691 1.1 skrll as_warn (_("word of NOPs added between word multiply and load"));
1692 1.1 skrll else
1693 1.1 skrll as_warn (_("word of NOPs added between word multiply and 16-bit multiply"));
1694 1.1 skrll }
1695 1.1 skrll }
1696 1.1 skrll }
1697 1.1 skrll
1698 1.1 skrll extype = EXEC_UNKNOWN;
1699 1.1 skrll }
1700 1.1 skrll }
1701 1.1 skrll else if ( (extype == EXEC_REVSEQ)
1702 1.1 skrll && cur_mul32_p
1703 1.1 skrll && (prev_opcode.op->flags_used & (FLAG_MEM | FLAG_MUL16)))
1704 1.1 skrll {
1705 1.1 skrll /* Can't parallelize, flush current instruction and add a
1706 1.1 skrll sequential NOP. */
1707 1.1.1.7 christos write_1_short (&opcode, (long) insn, fixups->next->next, true);
1708 1.1 skrll
1709 1.1 skrll /* Make the previous instruction the current one. */
1710 1.1 skrll extype = EXEC_UNKNOWN;
1711 1.1 skrll insn = prev_insn;
1712 1.1 skrll now_seg = prev_seg;
1713 1.1 skrll now_subseg = prev_subseg;
1714 1.1 skrll prev_insn = -1;
1715 1.1 skrll cur_mul32_p = prev_mul32_p;
1716 1.1 skrll prev_mul32_p = 0;
1717 1.1 skrll memcpy (&opcode, &prev_opcode, sizeof (prev_opcode));
1718 1.1 skrll }
1719 1.1 skrll
1720 1.1 skrll /* If this is a long instruction, write it and any previous short
1721 1.1 skrll instruction. */
1722 1.1 skrll if (opcode.form->form >= LONG)
1723 1.1 skrll {
1724 1.1 skrll if (extype != EXEC_UNKNOWN)
1725 1.1 skrll as_bad (_("Instruction uses long version, so it cannot be mixed as specified"));
1726 1.1.1.7 christos d30v_cleanup (false);
1727 1.1 skrll write_long (&opcode, insn, fixups);
1728 1.1 skrll prev_insn = -1;
1729 1.1 skrll }
1730 1.1 skrll else if ((prev_insn != -1)
1731 1.1 skrll && (write_2_short
1732 1.1 skrll (&prev_opcode, (long) prev_insn, &opcode,
1733 1.1 skrll (long) insn, extype, fixups) == 0))
1734 1.1 skrll {
1735 1.1 skrll /* No instructions saved. */
1736 1.1 skrll prev_insn = -1;
1737 1.1 skrll }
1738 1.1 skrll else
1739 1.1 skrll {
1740 1.1 skrll if (extype != EXEC_UNKNOWN)
1741 1.1 skrll as_bad (_("Unable to mix instructions as specified"));
1742 1.1 skrll
1743 1.1 skrll /* Save off last instruction so it may be packed on next pass. */
1744 1.1 skrll memcpy (&prev_opcode, &opcode, sizeof (prev_opcode));
1745 1.1 skrll prev_insn = insn;
1746 1.1 skrll prev_seg = now_seg;
1747 1.1 skrll prev_subseg = now_subseg;
1748 1.1 skrll fixups = fixups->next;
1749 1.1 skrll prev_mul32_p = cur_mul32_p;
1750 1.1 skrll }
1751 1.1 skrll }
1752 1.1 skrll
1753 1.1 skrll /* If while processing a fixup, a reloc really needs to be created,
1754 1.1 skrll then it is done here. */
1755 1.1 skrll
1756 1.1 skrll arelent *
1757 1.1 skrll tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
1758 1.1 skrll {
1759 1.1 skrll arelent *reloc;
1760 1.1.1.9 christos reloc = notes_alloc (sizeof (arelent));
1761 1.1.1.9 christos reloc->sym_ptr_ptr = notes_alloc (sizeof (asymbol *));
1762 1.1 skrll *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1763 1.1 skrll reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1764 1.1 skrll reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1765 1.1 skrll if (reloc->howto == NULL)
1766 1.1 skrll {
1767 1.1 skrll as_bad_where (fixp->fx_file, fixp->fx_line,
1768 1.1 skrll _("reloc %d not supported by object file format"),
1769 1.1 skrll (int) fixp->fx_r_type);
1770 1.1 skrll return NULL;
1771 1.1 skrll }
1772 1.1 skrll
1773 1.1 skrll reloc->addend = 0;
1774 1.1 skrll return reloc;
1775 1.1 skrll }
1776 1.1 skrll
1777 1.1 skrll int
1778 1.1 skrll md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
1779 1.1 skrll asection *seg ATTRIBUTE_UNUSED)
1780 1.1 skrll {
1781 1.1 skrll abort ();
1782 1.1 skrll return 0;
1783 1.1 skrll }
1784 1.1 skrll
1785 1.1 skrll long
1786 1.1 skrll md_pcrel_from_section (fixS *fixp, segT sec)
1787 1.1 skrll {
1788 1.1.1.9 christos if (fixp->fx_addsy != NULL
1789 1.1 skrll && (!S_IS_DEFINED (fixp->fx_addsy)
1790 1.1 skrll || (S_GET_SEGMENT (fixp->fx_addsy) != sec)))
1791 1.1 skrll return 0;
1792 1.1 skrll return fixp->fx_frag->fr_address + fixp->fx_where;
1793 1.1 skrll }
1794 1.1 skrll
1795 1.1 skrll /* Called after the assembler has finished parsing the input file or
1796 1.1 skrll after a label is defined. Because the D30V assembler sometimes
1797 1.1 skrll saves short instructions to see if it can package them with the
1798 1.1 skrll next instruction, there may be a short instruction that still needs
1799 1.1 skrll written. */
1800 1.1 skrll
1801 1.1 skrll int
1802 1.1 skrll d30v_cleanup (int use_sequential)
1803 1.1 skrll {
1804 1.1 skrll segT seg;
1805 1.1 skrll subsegT subseg;
1806 1.1 skrll
1807 1.1 skrll if (prev_insn != -1)
1808 1.1 skrll {
1809 1.1 skrll seg = now_seg;
1810 1.1 skrll subseg = now_subseg;
1811 1.1 skrll subseg_set (prev_seg, prev_subseg);
1812 1.1 skrll write_1_short (&prev_opcode, (long) prev_insn, fixups->next,
1813 1.1 skrll use_sequential);
1814 1.1 skrll subseg_set (seg, subseg);
1815 1.1 skrll prev_insn = -1;
1816 1.1 skrll if (use_sequential)
1817 1.1.1.7 christos prev_mul32_p = false;
1818 1.1 skrll }
1819 1.1 skrll
1820 1.1 skrll return 1;
1821 1.1 skrll }
1822 1.1 skrll
1823 1.1 skrll /* This function is called at the start of every line. It checks to
1824 1.1 skrll see if the first character is a '.', which indicates the start of a
1825 1.1 skrll pseudo-op. If it is, then write out any unwritten instructions. */
1826 1.1 skrll
1827 1.1 skrll void
1828 1.1 skrll d30v_start_line (void)
1829 1.1 skrll {
1830 1.1 skrll char *c = input_line_pointer;
1831 1.1 skrll
1832 1.1.1.9 christos while (is_whitespace (*c))
1833 1.1 skrll c++;
1834 1.1 skrll
1835 1.1 skrll if (*c == '.')
1836 1.1.1.7 christos d30v_cleanup (false);
1837 1.1 skrll }
1838 1.1 skrll
1839 1.1 skrll static void
1840 1.1.1.4 christos check_size (long value, int bits, const char *file, int line)
1841 1.1 skrll {
1842 1.1 skrll int tmp, max;
1843 1.1 skrll
1844 1.1 skrll if (value < 0)
1845 1.1 skrll tmp = ~value;
1846 1.1 skrll else
1847 1.1 skrll tmp = value;
1848 1.1 skrll
1849 1.1 skrll max = (1 << (bits - 1)) - 1;
1850 1.1 skrll
1851 1.1 skrll if (tmp > max)
1852 1.1 skrll as_bad_where (file, line, _("value too large to fit in %d bits"), bits);
1853 1.1 skrll }
1854 1.1 skrll
1855 1.1 skrll /* d30v_frob_label() is called when after a label is recognized. */
1856 1.1 skrll
1857 1.1 skrll void
1858 1.1 skrll d30v_frob_label (symbolS *lab)
1859 1.1 skrll {
1860 1.1 skrll /* Emit any pending instructions. */
1861 1.1.1.7 christos d30v_cleanup (false);
1862 1.1 skrll
1863 1.1 skrll /* Update the label's address with the current output pointer. */
1864 1.1 skrll symbol_set_frag (lab, frag_now);
1865 1.1 skrll S_SET_VALUE (lab, (valueT) frag_now_fix ());
1866 1.1 skrll
1867 1.1 skrll /* Record this label for future adjustment after we find out what
1868 1.1 skrll kind of data it references, and the required alignment therewith. */
1869 1.1 skrll d30v_last_label = lab;
1870 1.1.1.2 christos
1871 1.1.1.2 christos dwarf2_emit_label (lab);
1872 1.1 skrll }
1873 1.1 skrll
1874 1.1 skrll /* Hook into cons for capturing alignment changes. */
1875 1.1 skrll
1876 1.1 skrll void
1877 1.1 skrll d30v_cons_align (int size)
1878 1.1 skrll {
1879 1.1 skrll int log_size;
1880 1.1 skrll
1881 1.1.1.2 christos /* Don't specially align anything in debug sections. */
1882 1.1.1.2 christos if ((now_seg->flags & SEC_ALLOC) == 0
1883 1.1.1.2 christos || strcmp (now_seg->name, ".eh_frame") == 0)
1884 1.1.1.2 christos return;
1885 1.1.1.2 christos
1886 1.1 skrll log_size = 0;
1887 1.1 skrll while ((size >>= 1) != 0)
1888 1.1 skrll ++log_size;
1889 1.1 skrll
1890 1.1 skrll if (d30v_current_align < log_size)
1891 1.1.1.9 christos d30v_align (log_size, NULL, NULL);
1892 1.1 skrll else if (d30v_current_align > log_size)
1893 1.1 skrll d30v_current_align = log_size;
1894 1.1 skrll d30v_last_label = NULL;
1895 1.1 skrll }
1896 1.1 skrll
1897 1.1 skrll void
1898 1.1 skrll md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
1899 1.1 skrll {
1900 1.1 skrll char *where;
1901 1.1 skrll unsigned long insn, insn2;
1902 1.1 skrll long value = *valP;
1903 1.1 skrll
1904 1.1.1.9 christos if (fixP->fx_addsy == NULL)
1905 1.1 skrll fixP->fx_done = 1;
1906 1.1 skrll
1907 1.1 skrll /* We don't support subtracting a symbol. */
1908 1.1.1.9 christos if (fixP->fx_subsy != NULL)
1909 1.1.1.7 christos as_bad_subtract (fixP);
1910 1.1 skrll
1911 1.1 skrll /* Fetch the instruction, insert the fully resolved operand
1912 1.1 skrll value, and stuff the instruction back again. */
1913 1.1 skrll where = fixP->fx_frag->fr_literal + fixP->fx_where;
1914 1.1.1.9 christos insn = bfd_getb32 (where);
1915 1.1 skrll
1916 1.1 skrll switch (fixP->fx_r_type)
1917 1.1 skrll {
1918 1.1.1.6 christos case BFD_RELOC_8:
1919 1.1.1.9 christos *where = value;
1920 1.1 skrll break;
1921 1.1 skrll
1922 1.1.1.6 christos case BFD_RELOC_16:
1923 1.1.1.9 christos bfd_putb16 (value, where);
1924 1.1 skrll break;
1925 1.1 skrll
1926 1.1.1.6 christos case BFD_RELOC_64:
1927 1.1.1.9 christos bfd_putb32 (value, where);
1928 1.1.1.9 christos bfd_putb32 (0, where + 4);
1929 1.1 skrll break;
1930 1.1 skrll
1931 1.1 skrll case BFD_RELOC_D30V_6:
1932 1.1 skrll check_size (value, 6, fixP->fx_file, fixP->fx_line);
1933 1.1 skrll insn |= value & 0x3F;
1934 1.1.1.9 christos bfd_putb32 (insn, where);
1935 1.1 skrll break;
1936 1.1 skrll
1937 1.1 skrll case BFD_RELOC_D30V_9_PCREL:
1938 1.1 skrll if (fixP->fx_where & 0x7)
1939 1.1 skrll {
1940 1.1 skrll if (fixP->fx_done)
1941 1.1 skrll value += 4;
1942 1.1 skrll else
1943 1.1 skrll fixP->fx_r_type = BFD_RELOC_D30V_9_PCREL_R;
1944 1.1 skrll }
1945 1.1 skrll check_size (value, 9, fixP->fx_file, fixP->fx_line);
1946 1.1 skrll insn |= ((value >> 3) & 0x3F) << 12;
1947 1.1.1.9 christos bfd_putb32 (insn, where);
1948 1.1 skrll break;
1949 1.1 skrll
1950 1.1 skrll case BFD_RELOC_D30V_15:
1951 1.1 skrll check_size (value, 15, fixP->fx_file, fixP->fx_line);
1952 1.1 skrll insn |= (value >> 3) & 0xFFF;
1953 1.1.1.9 christos bfd_putb32 (insn, where);
1954 1.1 skrll break;
1955 1.1 skrll
1956 1.1 skrll case BFD_RELOC_D30V_15_PCREL:
1957 1.1 skrll if (fixP->fx_where & 0x7)
1958 1.1 skrll {
1959 1.1 skrll if (fixP->fx_done)
1960 1.1 skrll value += 4;
1961 1.1 skrll else
1962 1.1 skrll fixP->fx_r_type = BFD_RELOC_D30V_15_PCREL_R;
1963 1.1 skrll }
1964 1.1 skrll check_size (value, 15, fixP->fx_file, fixP->fx_line);
1965 1.1 skrll insn |= (value >> 3) & 0xFFF;
1966 1.1.1.9 christos bfd_putb32 (insn, where);
1967 1.1 skrll break;
1968 1.1 skrll
1969 1.1 skrll case BFD_RELOC_D30V_21:
1970 1.1 skrll check_size (value, 21, fixP->fx_file, fixP->fx_line);
1971 1.1 skrll insn |= (value >> 3) & 0x3FFFF;
1972 1.1.1.9 christos bfd_putb32 (insn, where);
1973 1.1 skrll break;
1974 1.1 skrll
1975 1.1 skrll case BFD_RELOC_D30V_21_PCREL:
1976 1.1 skrll if (fixP->fx_where & 0x7)
1977 1.1 skrll {
1978 1.1 skrll if (fixP->fx_done)
1979 1.1 skrll value += 4;
1980 1.1 skrll else
1981 1.1 skrll fixP->fx_r_type = BFD_RELOC_D30V_21_PCREL_R;
1982 1.1 skrll }
1983 1.1 skrll check_size (value, 21, fixP->fx_file, fixP->fx_line);
1984 1.1 skrll insn |= (value >> 3) & 0x3FFFF;
1985 1.1.1.9 christos bfd_putb32 (insn, where);
1986 1.1 skrll break;
1987 1.1 skrll
1988 1.1 skrll case BFD_RELOC_D30V_32:
1989 1.1.1.9 christos insn2 = bfd_getb32 (where + 4);
1990 1.1 skrll insn |= (value >> 26) & 0x3F; /* Top 6 bits. */
1991 1.1 skrll insn2 |= ((value & 0x03FC0000) << 2); /* Next 8 bits. */
1992 1.1 skrll insn2 |= value & 0x0003FFFF; /* Bottom 18 bits. */
1993 1.1.1.9 christos bfd_putb32 (insn, where);
1994 1.1.1.9 christos bfd_putb32 (insn2, where + 4);
1995 1.1 skrll break;
1996 1.1 skrll
1997 1.1 skrll case BFD_RELOC_D30V_32_PCREL:
1998 1.1.1.9 christos insn2 = bfd_getb32 (where + 4);
1999 1.1 skrll insn |= (value >> 26) & 0x3F; /* Top 6 bits. */
2000 1.1 skrll insn2 |= ((value & 0x03FC0000) << 2); /* Next 8 bits. */
2001 1.1 skrll insn2 |= value & 0x0003FFFF; /* Bottom 18 bits. */
2002 1.1.1.9 christos bfd_putb32 (insn, where);
2003 1.1.1.9 christos bfd_putb32 (insn2, where + 4);
2004 1.1 skrll break;
2005 1.1 skrll
2006 1.1 skrll case BFD_RELOC_32:
2007 1.1.1.9 christos bfd_putb32 (value, where);
2008 1.1 skrll break;
2009 1.1 skrll
2010 1.1 skrll default:
2011 1.1 skrll as_bad (_("line %d: unknown relocation type: 0x%x"),
2012 1.1 skrll fixP->fx_line, fixP->fx_r_type);
2013 1.1 skrll }
2014 1.1 skrll }
2015 1.1 skrll
2016 1.1 skrll /* Handle the .align pseudo-op. This aligns to a power of two. We
2017 1.1 skrll hook here to latch the current alignment. */
2018 1.1 skrll
2019 1.1 skrll static void
2020 1.1 skrll s_d30v_align (int ignore ATTRIBUTE_UNUSED)
2021 1.1 skrll {
2022 1.1 skrll int align;
2023 1.1 skrll char fill, *pfill = NULL;
2024 1.1 skrll long max_alignment = 15;
2025 1.1 skrll
2026 1.1 skrll align = get_absolute_expression ();
2027 1.1 skrll if (align > max_alignment)
2028 1.1 skrll {
2029 1.1 skrll align = max_alignment;
2030 1.1 skrll as_warn (_("Alignment too large: %d assumed"), align);
2031 1.1 skrll }
2032 1.1 skrll else if (align < 0)
2033 1.1 skrll {
2034 1.1 skrll as_warn (_("Alignment negative: 0 assumed"));
2035 1.1 skrll align = 0;
2036 1.1 skrll }
2037 1.1 skrll
2038 1.1 skrll if (*input_line_pointer == ',')
2039 1.1 skrll {
2040 1.1 skrll input_line_pointer++;
2041 1.1 skrll fill = get_absolute_expression ();
2042 1.1 skrll pfill = &fill;
2043 1.1 skrll }
2044 1.1 skrll
2045 1.1 skrll d30v_last_label = NULL;
2046 1.1 skrll d30v_align (align, pfill, NULL);
2047 1.1 skrll
2048 1.1 skrll demand_empty_rest_of_line ();
2049 1.1 skrll }
2050 1.1 skrll
2051 1.1 skrll /* Handle the .text pseudo-op. This is like the usual one, but it
2052 1.1 skrll clears the saved last label and resets known alignment. */
2053 1.1 skrll
2054 1.1 skrll static void
2055 1.1 skrll s_d30v_text (int i)
2056 1.1 skrll
2057 1.1 skrll {
2058 1.1.1.8 christos obj_elf_text (i);
2059 1.1 skrll d30v_last_label = NULL;
2060 1.1 skrll d30v_current_align = 0;
2061 1.1 skrll d30v_current_align_seg = now_seg;
2062 1.1 skrll }
2063 1.1 skrll
2064 1.1 skrll /* Handle the .data pseudo-op. This is like the usual one, but it
2065 1.1 skrll clears the saved last label and resets known alignment. */
2066 1.1 skrll
2067 1.1 skrll static void
2068 1.1 skrll s_d30v_data (int i)
2069 1.1 skrll {
2070 1.1.1.8 christos obj_elf_data (i);
2071 1.1 skrll d30v_last_label = NULL;
2072 1.1 skrll d30v_current_align = 0;
2073 1.1 skrll d30v_current_align_seg = now_seg;
2074 1.1 skrll }
2075 1.1 skrll
2076 1.1 skrll /* Handle the .section pseudo-op. This is like the usual one, but it
2077 1.1 skrll clears the saved last label and resets known alignment. */
2078 1.1 skrll
2079 1.1 skrll static void
2080 1.1 skrll s_d30v_section (int ignore)
2081 1.1 skrll {
2082 1.1 skrll obj_elf_section (ignore);
2083 1.1 skrll d30v_last_label = NULL;
2084 1.1 skrll d30v_current_align = 0;
2085 1.1 skrll d30v_current_align_seg = now_seg;
2086 1.1 skrll }
2087 1.1 skrll
2088 1.1 skrll /* The target specific pseudo-ops which we support. */
2089 1.1 skrll const pseudo_typeS md_pseudo_table[] =
2090 1.1 skrll {
2091 1.1 skrll { "word", cons, 4 },
2092 1.1 skrll { "hword", cons, 2 },
2093 1.1 skrll { "align", s_d30v_align, 0 },
2094 1.1 skrll { "text", s_d30v_text, 0 },
2095 1.1 skrll { "data", s_d30v_data, 0 },
2096 1.1 skrll { "section", s_d30v_section, 0 },
2097 1.1 skrll { "section.s", s_d30v_section, 0 },
2098 1.1 skrll { "sect", s_d30v_section, 0 },
2099 1.1 skrll { "sect.s", s_d30v_section, 0 },
2100 1.1 skrll { NULL, NULL, 0 }
2101 1.1 skrll };
2102