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