ld: Move the .note.build-id section to near the start of the memory map.
[binutils-gdb.git] / gas / config / tc-visium.c
blobfcb128a1abbcc93babc03b71e11098c723e1cc39
1 /* This is the machine dependent code of the Visium Assembler.
3 Copyright (C) 2005-2024 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "as.h"
23 #include "safe-ctype.h"
24 #include "subsegs.h"
25 #include "obstack.h"
27 #include "opcode/visium.h"
28 #include "elf/visium.h"
29 #include "dwarf2dbg.h"
30 #include "dw2gencfi.h"
32 /* Relocations and fixups:
34 There are two different cases where an instruction or data
35 directive operand requires relocation, or fixup.
37 1. Relative branch instructions, take an 16-bit signed word
38 offset. The formula for computing the offset is this:
40 offset = (destination - pc) / 4
42 Branch instructions never branch to a label not declared
43 locally, so the actual offset can always be computed by the assembler.
44 However, we provide a relocation type to support this.
46 2. Load literal instructions, such as MOVIU, which take a 16-bit
47 literal operand. The literal may be the top or bottom half of
48 a 32-bit value computed by the assembler, or by the linker. We provide
49 two relocation types here.
51 3. Data items (long, word and byte) preset with a value computed by
52 the linker. */
55 /* This string holds the chars that always start a comment. If the
56 pre-processor is disabled, these aren't very useful. */
57 const char comment_chars[] = "!;";
59 /* This array holds the chars that only start a comment at the beginning
60 of a line. If the line seems to have the form '# 123 filename' .line
61 and .file directives will appear in the pre-processed output. Note that
62 input_file.c hand checks for '#' at the beginning of the first line of
63 the input file. This is because the compiler outputs #NO_APP at the
64 beginning of its output. Also note that comments like this one will
65 always work. */
66 const char line_comment_chars[] = "#!;";
67 const char line_separator_chars[] = "";
69 /* Chars that can be used to separate mantissa from exponent in floating point
70 numbers. */
71 const char EXP_CHARS[] = "eE";
73 /* Chars that mean this number is a floating point constant, as in
74 "0f12.456" or "0d1.2345e12".
76 ...Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
77 changed in read.c. Ideally it shouldn't have to know about it at all,
78 but nothing is ideal around here. */
79 const char FLT_CHARS[] = "rRsSfFdDxXeE";
81 /* The size of a relocation record. */
82 const int md_reloc_size = 8;
84 /* The architecture for which we are assembling. */
85 enum visium_arch_val
87 VISIUM_ARCH_DEF,
88 VISIUM_ARCH_MCM24,
89 VISIUM_ARCH_MCM,
90 VISIUM_ARCH_GR6
93 static enum visium_arch_val visium_arch = VISIUM_ARCH_DEF;
95 /* The opcode architecture for which we are assembling. In contrast to the
96 previous one, this only determines which instructions are supported. */
97 static enum visium_opcode_arch_val visium_opcode_arch = VISIUM_OPCODE_ARCH_DEF;
99 /* Flags to set in the ELF header e_flags field. */
100 static flagword visium_flags = 0;
102 /* More than this number of nops in an alignment op gets a branch instead. */
103 static unsigned int nop_limit = 5;
106 /* Translate internal representation of relocation info to BFD target
107 format. */
108 arelent *
109 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
111 arelent *reloc;
112 bfd_reloc_code_real_type code;
114 reloc = XNEW (arelent);
116 reloc->sym_ptr_ptr = XNEW (asymbol *);
117 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
118 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
120 switch (fixp->fx_r_type)
122 case BFD_RELOC_8:
123 case BFD_RELOC_16:
124 case BFD_RELOC_32:
125 case BFD_RELOC_8_PCREL:
126 case BFD_RELOC_16_PCREL:
127 case BFD_RELOC_32_PCREL:
128 case BFD_RELOC_VISIUM_HI16:
129 case BFD_RELOC_VISIUM_LO16:
130 case BFD_RELOC_VISIUM_IM16:
131 case BFD_RELOC_VISIUM_REL16:
132 case BFD_RELOC_VISIUM_HI16_PCREL:
133 case BFD_RELOC_VISIUM_LO16_PCREL:
134 case BFD_RELOC_VISIUM_IM16_PCREL:
135 case BFD_RELOC_VTABLE_INHERIT:
136 case BFD_RELOC_VTABLE_ENTRY:
137 code = fixp->fx_r_type;
138 break;
139 default:
140 as_bad_where (fixp->fx_file, fixp->fx_line,
141 "internal error: unknown relocation type %d (`%s')",
142 fixp->fx_r_type,
143 bfd_get_reloc_code_name (fixp->fx_r_type));
144 return 0;
147 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
148 if (reloc->howto == 0)
150 as_bad_where (fixp->fx_file, fixp->fx_line,
151 "internal error: can't export reloc type %d (`%s')",
152 fixp->fx_r_type, bfd_get_reloc_code_name (code));
153 return 0;
156 /* Write the addend. */
157 if (reloc->howto->pc_relative == 0)
158 reloc->addend = fixp->fx_addnumber;
159 else
160 reloc->addend = fixp->fx_offset;
162 return reloc;
165 static void visium_rdata (int);
167 static void visium_update_parity_bit (char *);
168 static char *parse_exp (char *, expressionS *);
170 /* This table describes all the machine specific pseudo-ops the assembler
171 has to support, and that aren't handled elsewhere. The fields are:
173 1: Pseudo-op name without dot.
174 2: Function to call to execute this pseudo-op.
175 3: Integer arg to pass to the function. */
176 const pseudo_typeS md_pseudo_table[] =
178 {"align", s_align_bytes, 0},
179 {"noopt", s_ignore, 0},
180 {"optim", s_ignore, 0},
181 {"rdata", visium_rdata, 0},
182 {"rodata", visium_rdata, 0},
183 {0, 0, 0}
187 static void
188 visium_rdata (int xxx)
190 char *save_line = input_line_pointer;
191 static char section[] = ".rodata\n";
193 /* Just pretend this is .section .rodata */
194 input_line_pointer = section;
195 obj_elf_section (xxx);
196 input_line_pointer = save_line;
199 /* Align a section. */
200 valueT
201 md_section_align (asection *seg, valueT addr)
203 int align = bfd_section_alignment (seg);
205 return ((addr + (1 << align) - 1) & -(1 << align));
208 void
209 md_number_to_chars (char *buf, valueT val, int n)
211 number_to_chars_bigendian (buf, val, n);
214 symbolS *
215 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
217 return 0;
220 /* The parse options. */
221 const char *md_shortopts = "m:";
223 struct option md_longopts[] =
225 {NULL, no_argument, NULL, 0}
228 size_t md_longopts_size = sizeof (md_longopts);
230 struct visium_option_table
232 char *option; /* Option name to match. */
233 char *help; /* Help information. */
234 int *var; /* Variable to change. */
235 int value; /* To what to change it. */
236 char *deprecated; /* If non-null, print this message. */
239 static struct visium_option_table visium_opts[] =
241 {NULL, NULL, NULL, 0, NULL}
244 struct visium_arch_option_table
246 const char *name;
247 enum visium_arch_val value;
250 static struct visium_arch_option_table visium_archs[] =
252 {"mcm24", VISIUM_ARCH_MCM24},
253 {"mcm", VISIUM_ARCH_MCM},
254 {"gr5", VISIUM_ARCH_MCM},
255 {"gr6", VISIUM_ARCH_GR6},
258 struct visium_long_option_table
260 const char *option; /* Substring to match. */
261 const char *help; /* Help information. */
262 int (*func) (const char *subopt); /* Function to decode sub-option. */
263 const char *deprecated; /* If non-null, print this message. */
266 static int
267 visium_parse_arch (const char *str)
269 unsigned int i;
271 if (strlen (str) == 0)
273 as_bad ("missing architecture name `%s'", str);
274 return 0;
277 for (i = 0; i < ARRAY_SIZE (visium_archs); i++)
278 if (strcmp (visium_archs[i].name, str) == 0)
280 visium_arch = visium_archs[i].value;
281 return 1;
284 as_bad ("unknown architecture `%s'\n", str);
285 return 0;
288 static struct visium_long_option_table visium_long_opts[] =
290 {"mtune=", "<arch_name>\t assemble for architecture <arch name>",
291 visium_parse_arch, NULL},
292 {NULL, NULL, NULL, NULL}
296 md_parse_option (int c, const char *arg)
298 struct visium_option_table *opt;
299 struct visium_long_option_table *lopt;
301 switch (c)
303 case 'a':
304 /* Listing option. Just ignore these, we don't support additional
305 ones. */
306 return 0;
308 default:
309 for (opt = visium_opts; opt->option != NULL; opt++)
311 if (c == opt->option[0]
312 && ((arg == NULL && opt->option[1] == 0)
313 || strcmp (arg, opt->option + 1) == 0))
315 /* If the option is deprecated, tell the user. */
316 if (opt->deprecated != NULL)
317 as_tsktsk ("option `-%c%s' is deprecated: %s", c,
318 arg ? arg : "", opt->deprecated);
320 if (opt->var != NULL)
321 *opt->var = opt->value;
323 return 1;
327 for (lopt = visium_long_opts; lopt->option != NULL; lopt++)
329 /* These options are expected to have an argument. */
330 if (c == lopt->option[0]
331 && arg != NULL
332 && strncmp (arg, lopt->option + 1,
333 strlen (lopt->option + 1)) == 0)
335 /* If the option is deprecated, tell the user. */
336 if (lopt->deprecated != NULL)
337 as_tsktsk ("option `-%c%s' is deprecated: %s", c, arg,
338 lopt->deprecated);
340 /* Call the sup-option parser. */
341 return lopt->func (arg + strlen (lopt->option) - 1);
345 return 0;
348 return 1;
351 void
352 md_show_usage (FILE * fp)
354 struct visium_option_table *opt;
355 struct visium_long_option_table *lopt;
357 fprintf (fp, " Visium-specific assembler options:\n");
359 for (opt = visium_opts; opt->option != NULL; opt++)
360 if (opt->help != NULL)
361 fprintf (fp, " -%-23s%s\n", opt->option, opt->help);
363 for (lopt = visium_long_opts; lopt->option != NULL; lopt++)
364 if (lopt->help != NULL)
365 fprintf (fp, " -%s%s\n", lopt->option, lopt->help);
369 /* Interface to relax_segment. */
371 /* Return the estimate of the size of a machine dependent frag
372 before any relaxing is done. It may also create any necessary
373 relocations. */
375 md_estimate_size_before_relax (fragS * fragP,
376 segT segment ATTRIBUTE_UNUSED)
378 fragP->fr_var = 4;
379 return 4;
382 /* Get the address of a symbol during relaxation. From tc-arm.c. */
383 static addressT
384 relaxed_symbol_addr (fragS *fragp, long stretch)
386 fragS *sym_frag;
387 addressT addr;
388 symbolS *sym;
390 sym = fragp->fr_symbol;
391 sym_frag = symbol_get_frag (sym);
392 know (S_GET_SEGMENT (sym) != absolute_section
393 || sym_frag == &zero_address_frag);
394 addr = S_GET_VALUE (sym) + fragp->fr_offset;
396 /* If frag has yet to be reached on this pass, assume it will
397 move by STRETCH just as we did. If this is not so, it will
398 be because some frag between grows, and that will force
399 another pass. */
400 if (stretch != 0
401 && sym_frag->relax_marker != fragp->relax_marker)
403 fragS *f;
405 /* Adjust stretch for any alignment frag. Note that if have
406 been expanding the earlier code, the symbol may be
407 defined in what appears to be an earlier frag. FIXME:
408 This doesn't handle the fr_subtype field, which specifies
409 a maximum number of bytes to skip when doing an
410 alignment. */
411 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
413 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
415 if (stretch < 0)
416 stretch = - ((- stretch)
417 & ~ ((1 << (int) f->fr_offset) - 1));
418 else
419 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
420 if (stretch == 0)
421 break;
424 if (f != NULL)
425 addr += stretch;
428 return addr;
431 /* Relax a machine dependent frag. This returns the amount by which
432 the current size of the frag should change. */
434 visium_relax_frag (asection *sec, fragS *fragP, long stretch)
436 int old_size, new_size;
437 addressT addr;
439 /* We only handle relaxation for the BRR instruction. */
440 gas_assert (fragP->fr_subtype == mode_ci);
442 if (!S_IS_DEFINED (fragP->fr_symbol)
443 || sec != S_GET_SEGMENT (fragP->fr_symbol)
444 || S_IS_WEAK (fragP->fr_symbol))
445 return 0;
447 old_size = fragP->fr_var;
448 addr = relaxed_symbol_addr (fragP, stretch);
450 /* If the target is the address of the instruction, we'll insert a NOP. */
451 if (addr == fragP->fr_address + fragP->fr_fix)
452 new_size = 8;
453 else
454 new_size = 4;
456 fragP->fr_var = new_size;
457 return new_size - old_size;
460 /* Convert a machine dependent frag. */
461 void
462 md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
463 fragS * fragP)
465 char *buf = &fragP->fr_literal[0] + fragP->fr_fix;
466 expressionS exp;
467 fixS *fixP;
469 /* We only handle relaxation for the BRR instruction. */
470 gas_assert (fragP->fr_subtype == mode_ci);
472 /* Insert the NOP if requested. */
473 if (fragP->fr_var == 8)
475 memcpy (buf + 4, buf, 4);
476 memset (buf, 0, 4);
477 fragP->fr_fix += 4;
480 exp.X_op = O_symbol;
481 exp.X_add_symbol = fragP->fr_symbol;
482 exp.X_add_number = fragP->fr_offset;
484 /* Now we can create the relocation at the correct offset. */
485 fixP = fix_new_exp (fragP, fragP->fr_fix, 4, &exp, 1, BFD_RELOC_VISIUM_REL16);
486 fixP->fx_file = fragP->fr_file;
487 fixP->fx_line = fragP->fr_line;
488 fragP->fr_fix += 4;
489 fragP->fr_var = 0;
492 /* The location from which a PC relative jump should be calculated,
493 given a PC relative jump reloc. */
494 long
495 visium_pcrel_from_section (fixS *fixP, segT sec)
497 if (fixP->fx_addsy != (symbolS *) NULL
498 && (!S_IS_DEFINED (fixP->fx_addsy)
499 || S_GET_SEGMENT (fixP->fx_addsy) != sec))
501 /* The symbol is undefined (or is defined but not in this section).
502 Let the linker figure it out. */
503 return 0;
506 /* Return the address of the instruction. */
507 return fixP->fx_where + fixP->fx_frag->fr_address;
510 /* Indicate whether a fixup against a locally defined
511 symbol should be adjusted to be against the section
512 symbol. */
513 bool
514 visium_fix_adjustable (fixS *fix)
516 /* We need the symbol name for the VTABLE entries. */
517 return (fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
518 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY);
521 /* Update the parity bit of the 4-byte instruction in BUF. */
522 static void
523 visium_update_parity_bit (char *buf)
525 int p1 = (buf[0] & 0x7f) ^ buf[1] ^ buf[2] ^ buf[3];
526 int p2 = 0;
527 int i;
529 for (i = 1; i <= 8; i++)
531 p2 ^= (p1 & 1);
532 p1 >>= 1;
535 buf[0] = (buf[0] & 0x7f) | ((p2 << 7) & 0x80);
538 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
539 of an rs_align_code fragment. */
540 void
541 visium_handle_align (fragS *fragP)
543 valueT count
544 = fragP->fr_next->fr_address - (fragP->fr_address + fragP->fr_fix);
545 valueT fix = count & 3;
546 char *p = fragP->fr_literal + fragP->fr_fix;
548 if (fix)
550 memset (p, 0, fix);
551 p += fix;
552 count -= fix;
553 fragP->fr_fix += fix;
556 if (count == 0)
557 return;
559 fragP->fr_var = 4;
561 if (count > 4 * nop_limit && count <= 131068)
563 struct frag *rest;
565 /* Make a branch, then follow with nops. Insert another
566 frag to handle the nops. */
567 md_number_to_chars (p, 0x78000000 + (count >> 2), 4);
568 visium_update_parity_bit (p);
570 rest = xmalloc (SIZEOF_STRUCT_FRAG + 4);
571 memcpy (rest, fragP, SIZEOF_STRUCT_FRAG);
572 fragP->fr_next = rest;
573 rest->fr_address += rest->fr_fix + 4;
574 rest->fr_fix = 0;
575 /* If we leave the next frag as rs_align_code we'll come here
576 again, resulting in a bunch of branches rather than a
577 branch followed by nops. */
578 rest->fr_type = rs_align;
579 p = rest->fr_literal;
582 memset (p, 0, 4);
585 /* Apply a fixS to the frags, now that we know the value it ought to
586 hold. */
587 void
588 md_apply_fix (fixS * fixP, valueT * value, segT segment)
590 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
591 offsetT val;
592 long insn;
594 val = *value;
596 gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
598 /* Remember value for tc_gen_reloc. */
599 fixP->fx_addnumber = val;
601 /* Since DIFF_EXPR_OK is defined, .-foo gets turned into PC
602 relative relocs. If this has happened, a non-PC relative
603 reloc must be reinstalled with its PC relative version here. */
604 if (fixP->fx_pcrel)
606 switch (fixP->fx_r_type)
608 case BFD_RELOC_8:
609 fixP->fx_r_type = BFD_RELOC_8_PCREL;
610 break;
611 case BFD_RELOC_16:
612 fixP->fx_r_type = BFD_RELOC_16_PCREL;
613 break;
614 case BFD_RELOC_32:
615 fixP->fx_r_type = BFD_RELOC_32_PCREL;
616 break;
617 case BFD_RELOC_VISIUM_HI16:
618 fixP->fx_r_type = BFD_RELOC_VISIUM_HI16_PCREL;
619 break;
620 case BFD_RELOC_VISIUM_LO16:
621 fixP->fx_r_type = BFD_RELOC_VISIUM_LO16_PCREL;
622 break;
623 case BFD_RELOC_VISIUM_IM16:
624 fixP->fx_r_type = BFD_RELOC_VISIUM_IM16_PCREL;
625 break;
626 default:
627 break;
631 /* If this is a data relocation, just output VAL. */
632 switch (fixP->fx_r_type)
634 case BFD_RELOC_8:
635 case BFD_RELOC_8_PCREL:
636 md_number_to_chars (buf, val, 1);
637 break;
638 case BFD_RELOC_16:
639 case BFD_RELOC_16_PCREL:
640 md_number_to_chars (buf, val, 2);
641 break;
642 case BFD_RELOC_32:
643 case BFD_RELOC_32_PCREL:
644 md_number_to_chars (buf, val, 4);
645 break;
646 case BFD_RELOC_VTABLE_INHERIT:
647 case BFD_RELOC_VTABLE_ENTRY:
648 fixP->fx_done = 0;
649 break;
650 default:
651 /* It's a relocation against an instruction. */
652 insn = bfd_getb32 ((unsigned char *) buf);
654 switch (fixP->fx_r_type)
656 case BFD_RELOC_VISIUM_REL16:
657 if (fixP->fx_addsy == NULL
658 || (S_IS_DEFINED (fixP->fx_addsy)
659 && S_GET_SEGMENT (fixP->fx_addsy) == segment))
661 if (val > 0x1fffc || val < -0x20000)
662 as_bad_where
663 (fixP->fx_file, fixP->fx_line,
664 "16-bit word displacement out of range: value = %d",
665 (int) val);
666 val = (val >> 2);
668 insn = (insn & 0xffff0000) | (val & 0x0000ffff);
670 break;
672 case BFD_RELOC_VISIUM_HI16:
673 case BFD_RELOC_VISIUM_HI16_PCREL:
674 if (fixP->fx_addsy == NULL)
675 insn = (insn & 0xffff0000) | ((val >> 16) & 0x0000ffff);
676 break;
678 case BFD_RELOC_VISIUM_LO16:
679 case BFD_RELOC_VISIUM_LO16_PCREL:
680 if (fixP->fx_addsy == NULL)
681 insn = (insn & 0xffff0000) | (val & 0x0000ffff);
682 break;
684 case BFD_RELOC_VISIUM_IM16:
685 case BFD_RELOC_VISIUM_IM16_PCREL:
686 if (fixP->fx_addsy == NULL)
688 if ((val & 0xffff0000) != 0)
689 as_bad_where (fixP->fx_file, fixP->fx_line,
690 "16-bit immediate out of range: value = %d",
691 (int) val);
693 insn = (insn & 0xffff0000) | val;
695 break;
697 case BFD_RELOC_NONE:
698 default:
699 as_bad_where (fixP->fx_file, fixP->fx_line,
700 "bad or unhandled relocation type: 0x%02x",
701 fixP->fx_r_type);
702 break;
705 bfd_putb32 (insn, (unsigned char *) buf);
706 visium_update_parity_bit (buf);
707 break;
710 /* Are we finished with this relocation now? */
711 if (fixP->fx_addsy == NULL)
712 fixP->fx_done = 1;
715 char *
716 parse_exp (char *s, expressionS * op)
718 char *save = input_line_pointer;
719 char *new;
721 if (!s)
723 return s;
726 input_line_pointer = s;
727 expression (op);
728 new = input_line_pointer;
729 input_line_pointer = save;
730 return new;
733 /* If the given string is a Visium opcode mnemonic return the code
734 otherwise return -1. Use binary chop to find matching entry. */
735 static int
736 get_opcode (int *code, enum addressing_mode *mode, char *flags, char *mnem)
738 int l = 0;
739 int r = sizeof (opcode_table) / sizeof (struct opcode_entry) - 1;
743 int mid = (l + r) / 2;
744 int ans = strcmp (mnem, opcode_table[mid].mnem);
746 if (ans < 0)
747 r = mid - 1;
748 else if (ans > 0)
749 l = mid + 1;
750 else
752 *code = opcode_table[mid].code;
753 *mode = opcode_table[mid].mode;
754 *flags = opcode_table[mid].flags;
756 return 0;
759 while (l <= r);
761 return -1;
764 /* This function is called when the assembler starts up. It is called
765 after the options have been parsed and the output file has been
766 opened. */
767 void
768 md_begin (void)
770 switch (visium_arch)
772 case VISIUM_ARCH_DEF:
773 break;
774 case VISIUM_ARCH_MCM24:
775 visium_opcode_arch = VISIUM_OPCODE_ARCH_GR5;
776 visium_flags |= EF_VISIUM_ARCH_MCM24;
777 break;
778 case VISIUM_ARCH_MCM:
779 visium_opcode_arch = VISIUM_OPCODE_ARCH_GR5;
780 visium_flags |= EF_VISIUM_ARCH_MCM;
781 break;
782 case VISIUM_ARCH_GR6:
783 visium_opcode_arch = VISIUM_OPCODE_ARCH_GR6;
784 visium_flags |= EF_VISIUM_ARCH_MCM | EF_VISIUM_ARCH_GR6;
785 nop_limit = 2;
786 break;
787 default:
788 gas_assert (0);
791 bfd_set_private_flags (stdoutput, visium_flags);
794 /* This is identical to the md_atof in m68k.c. I think this is right,
795 but I'm not sure.
797 Turn a string in input_line_pointer into a floating point constant of type
798 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
799 emitted is stored in *sizeP . An error message is returned,
800 or NULL on OK. */
802 const char *
803 md_atof (int type, char *litP, int *sizeP)
805 int i, prec;
806 LITTLENUM_TYPE words[MAX_LITTLENUMS];
807 char *t;
809 switch (type)
811 case 'f':
812 case 'F':
813 case 's':
814 case 'S':
815 prec = 2;
816 break;
818 case 'd':
819 case 'D':
820 case 'r':
821 case 'R':
822 prec = 4;
823 break;
825 case 'x':
826 case 'X':
827 prec = 6;
828 break;
830 case 'p':
831 case 'P':
832 prec = 6;
833 break;
835 default:
836 *sizeP = 0;
837 return _("Bad call to MD_ATOF()");
840 t = atof_ieee (input_line_pointer, type, words);
841 if (t)
842 input_line_pointer = t;
843 *sizeP = prec * sizeof (LITTLENUM_TYPE);
845 if (target_big_endian)
847 for (i = 0; i < prec; i++)
849 md_number_to_chars (litP, (valueT) words[i],
850 sizeof (LITTLENUM_TYPE));
851 litP += sizeof (LITTLENUM_TYPE);
854 else
856 for (i = prec - 1; i >= 0; i--)
858 md_number_to_chars (litP, (valueT) words[i],
859 sizeof (LITTLENUM_TYPE));
860 litP += sizeof (LITTLENUM_TYPE);
864 return 0;
867 static inline char *
868 skip_space (char *s)
870 while (*s == ' ' || *s == '\t')
871 ++s;
873 return s;
876 static int
877 parse_gen_reg (char **sptr, int *rptr)
879 char *s = skip_space (*sptr);
880 char buf[10];
881 int cnt;
882 int l, r;
884 cnt = 0;
885 memset (buf, '\0', 10);
886 while ((ISALNUM (*s)) && cnt < 10)
887 buf[cnt++] = TOLOWER (*s++);
889 l = 0;
890 r = sizeof (gen_reg_table) / sizeof (struct reg_entry) - 1;
894 int mid = (l + r) / 2;
895 int ans = strcmp (buf, gen_reg_table[mid].name);
897 if (ans < 0)
898 r = mid - 1;
899 else if (ans > 0)
900 l = mid + 1;
901 else
903 *rptr = gen_reg_table[mid].code;
904 *sptr = s;
905 return 0;
908 while (l <= r);
910 return -1;
913 static int
914 parse_fp_reg (char **sptr, int *rptr)
916 char *s = skip_space (*sptr);
917 char buf[10];
918 int cnt;
919 int l, r;
921 cnt = 0;
922 memset (buf, '\0', 10);
923 while ((ISALNUM (*s)) && cnt < 10)
924 buf[cnt++] = TOLOWER (*s++);
926 l = 0;
927 r = sizeof (fp_reg_table) / sizeof (struct reg_entry) - 1;
931 int mid = (l + r) / 2;
932 int ans = strcmp (buf, fp_reg_table[mid].name);
934 if (ans < 0)
935 r = mid - 1;
936 else if (ans > 0)
937 l = mid + 1;
938 else
940 *rptr = fp_reg_table[mid].code;
941 *sptr = s;
942 return 0;
945 while (l <= r);
947 return -1;
950 static int
951 parse_cc (char **sptr, int *rptr)
953 char *s = skip_space (*sptr);
954 char buf[10];
955 int cnt;
956 int l, r;
958 cnt = 0;
959 memset (buf, '\0', 10);
960 while ((ISALNUM (*s)) && cnt < 10)
961 buf[cnt++] = TOLOWER (*s++);
963 l = 0;
964 r = sizeof (cc_table) / sizeof (struct cc_entry) - 1;
968 int mid = (l + r) / 2;
969 int ans = strcmp (buf, cc_table[mid].name);
971 if (ans < 0)
972 r = mid - 1;
973 else if (ans > 0)
974 l = mid + 1;
975 else
977 *rptr = cc_table[mid].code;
978 *sptr = s;
979 return 0;
982 while (l <= r);
984 return -1;
987 /* Previous dest is the destination register number of the instruction
988 before the current one. */
989 static int previous_dest = 0;
990 static int previous_mode = 0;
991 static int condition_code = 0;
992 static int this_dest = 0;
993 static int this_mode = 0;
996 /* This is the main function in this file. It takes a line of assembly language
997 source code and assembles it. Note, labels and pseudo ops have already
998 been removed, so too has leading white space. */
999 void
1000 md_assemble (char *str0)
1002 char *str = str0;
1003 int cnt;
1004 char mnem[10];
1005 int opcode;
1006 enum addressing_mode amode;
1007 char arch_flags;
1008 int ans;
1010 char *output;
1011 int reloc = 0;
1012 relax_substateT relax = 0;
1013 expressionS e1;
1014 int r1, r2, r3;
1015 int cc;
1016 int indx;
1018 /* Initialize the expression. */
1019 e1.X_op = O_absent;
1021 /* Initialize destination register.
1022 If the instruction we just looked at is in the delay slot of an
1023 unconditional branch, then there is no index hazard. */
1024 if ((previous_mode == mode_cad || previous_mode == mode_ci)
1025 && condition_code == 15)
1026 this_dest = 0;
1028 previous_dest = this_dest;
1029 previous_mode = this_mode;
1030 this_dest = 0;
1032 /* Drop leading whitespace (probably not required). */
1033 while (*str == ' ')
1034 str++;
1036 /* Get opcode mnemonic and make sure it's in lower case. */
1037 cnt = 0;
1038 memset (mnem, '\0', 10);
1039 while ((ISALNUM (*str) || *str == '.' || *str == '_') && cnt < 10)
1040 mnem[cnt++] = TOLOWER (*str++);
1042 /* Look up mnemonic in opcode table, and get the code,
1043 the instruction format, and the flags that indicate
1044 which family members support this mnemonic. */
1045 if (get_opcode (&opcode, &amode, &arch_flags, mnem) < 0)
1047 as_bad ("Unknown instruction mnemonic `%s'", mnem);
1048 return;
1051 if ((VISIUM_OPCODE_ARCH_MASK (visium_opcode_arch) & arch_flags) == 0)
1053 as_bad ("Architecture mismatch on `%s'", mnem);
1054 return;
1057 this_mode = amode;
1059 switch (amode)
1061 case mode_d:
1062 /* register :=
1063 Example:
1064 readmda r1 */
1065 ans = parse_gen_reg (&str, &r1);
1066 if (ans < 0)
1068 as_bad ("Dest register required");
1069 return;
1071 opcode |= (r1 << 10);
1072 this_dest = r1;
1073 break;
1075 case mode_a:
1076 /* op= register
1077 Example: asld r1 */
1078 ans = parse_gen_reg (&str, &r1);
1079 if (ans < 0)
1081 as_bad ("SourceA register required");
1082 return;
1084 opcode |= (r1 << 16);
1085 break;
1087 case mode_ab:
1088 /* register * register
1089 Example:
1090 mults r1,r2 */
1091 ans = parse_gen_reg (&str, &r1);
1092 if (ans < 0)
1094 as_bad ("SourceA register required");
1095 return;
1097 str = skip_space (str);
1098 if (*str == ',')
1100 str++;
1101 ans = parse_gen_reg (&str, &r2);
1102 if (ans < 0)
1104 as_bad ("SourceB register required");
1105 return;
1107 opcode |= (r1 << 16) | (r2 << 4);
1109 else
1111 as_bad ("SourceB register required");
1112 return;
1114 break;
1116 case mode_da:
1117 /* register := register
1118 Example:
1119 extb.l r1,r2 */
1120 ans = parse_gen_reg (&str, &r1);
1121 if (ans < 0)
1123 as_bad ("Dest register required");
1124 return;
1126 str = skip_space (str);
1127 if (*str == ',')
1129 str++;
1130 ans = parse_gen_reg (&str, &r2);
1131 if (ans < 0)
1133 as_bad ("SourceA register required");
1134 return;
1136 opcode |= (r1 << 10) | (r2 << 16);
1138 else
1140 as_bad ("SourceB register required");
1141 return;
1143 this_dest = r1;
1144 break;
1146 case mode_dab:
1147 /* register := register * register
1148 Example:
1149 add.l r1,r2,r3 */
1150 ans = parse_gen_reg (&str, &r1);
1151 if (ans < 0)
1153 as_bad ("Dest register required");
1154 return;
1156 str = skip_space (str);
1157 if (*str == ',')
1159 str++;
1160 ans = parse_gen_reg (&str, &r2);
1161 if (ans < 0)
1163 as_bad ("SourceA register required");
1164 return;
1166 str = skip_space (str);
1167 if (*str == ',')
1169 str++;
1170 ans = parse_gen_reg (&str, &r3);
1171 if (ans < 0)
1173 as_bad ("SourceB register required");
1174 return;
1177 /* Got three regs, assemble instruction. */
1178 opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
1180 else
1182 as_bad ("SourceA register required");
1183 return;
1186 else
1188 as_bad ("Dest register required");
1189 return;
1191 this_dest = r1;
1192 break;
1194 case mode_iab:
1195 /* 5-bit immediate * register * register
1196 Example:
1197 eamwrite 3,r1,r2 */
1198 str = parse_exp (str, &e1);
1199 str = skip_space (str);
1200 if (e1.X_op != O_absent && *str == ',')
1202 int eam_op = e1.X_add_number;
1204 str = skip_space (str + 1);
1205 ans = parse_gen_reg (&str, &r2);
1206 if (ans < 0)
1208 as_bad ("SourceA register required");
1209 return;
1211 str = skip_space (str);
1212 if (*str == ',')
1214 str++;
1215 ans = parse_gen_reg (&str, &r3);
1216 if (ans < 0)
1218 as_bad ("SourceB register required");
1219 return;
1222 /* Got three operands, assemble instruction. */
1223 if (eam_op < 0 || eam_op > 31)
1225 as_bad ("eam_op out of range");
1227 opcode |= ((eam_op & 0x1f) << 10) | (r2 << 16) | (r3 << 4);
1230 else
1232 as_bad ("EAM_OP required");
1233 return;
1235 break;
1237 case mode_0ab:
1238 /* zero * register * register
1239 Example:
1240 cmp.l r1,r2 */
1241 ans = parse_gen_reg (&str, &r1);
1242 if (ans < 0)
1244 as_bad ("SourceA register required");
1245 return;
1247 str = skip_space (str);
1248 if (*str == ',')
1250 str++;
1251 ans = parse_gen_reg (&str, &r2);
1252 if (ans < 0)
1254 as_bad ("SourceB register required");
1255 return;
1257 opcode |= (r1 << 16) | (r2 << 4);
1259 else
1261 as_bad ("SourceB register required");
1262 return;
1264 break;
1266 case mode_da0:
1267 /* register * register * zero
1268 Example:
1269 move.l r1,r2 */
1270 ans = parse_gen_reg (&str, &r1);
1271 if (ans < 0)
1273 as_bad ("Dest register required");
1274 return;
1276 str = skip_space (str);
1277 if (*str == ',')
1279 str++;
1280 ans = parse_gen_reg (&str, &r2);
1281 if (ans < 0)
1283 as_bad ("SourceA register required");
1284 return;
1286 opcode |= (r1 << 10) | (r2 << 16);
1288 else
1290 as_bad ("SourceA register required");
1291 return;
1293 this_dest = r1;
1294 break;
1296 case mode_cad:
1297 /* condition * register * register
1298 Example:
1299 bra tr,r1,r2 */
1300 ans = parse_cc (&str, &cc);
1301 if (ans < 0)
1303 as_bad ("condition code required");
1304 return;
1307 str = skip_space (str);
1308 if (*str == ',')
1310 str = skip_space (str + 1);
1311 ans = parse_gen_reg (&str, &r2);
1312 if (ans < 0)
1314 as_bad ("SourceA register required");
1315 return;
1317 str = skip_space (str);
1318 if (*str == ',')
1320 str++;
1321 ans = parse_gen_reg (&str, &r3);
1322 if (ans < 0)
1324 as_bad ("Dest register required");
1325 return;
1328 /* Got three operands, assemble instruction. */
1329 opcode |= (cc << 27) | (r2 << 16) | (r3 << 10);
1331 else
1333 as_bad ("Dest register required");
1334 return;
1337 else
1339 as_bad ("SourceA register required");
1340 return;
1343 if (previous_mode == mode_cad || previous_mode == mode_ci)
1344 as_bad ("branch instruction in delay slot");
1346 /* For the GR6, BRA insns must be aligned on 64-bit boundaries. */
1347 if (visium_arch == VISIUM_ARCH_GR6)
1348 do_align (3, NULL, 0, 0);
1350 this_dest = r3;
1351 condition_code = cc;
1352 break;
1354 case mode_das:
1355 /* register := register * 5-bit immediate/register shift count
1356 Example:
1357 asl.l r1,r2,4 */
1358 ans = parse_gen_reg (&str, &r1);
1359 if (ans < 0)
1361 as_bad ("Dest register required");
1362 return;
1364 str = skip_space (str);
1365 if (*str == ',')
1367 str++;
1368 ans = parse_gen_reg (&str, &r2);
1369 if (ans < 0)
1371 as_bad ("SourceA register required");
1372 return;
1374 str = skip_space (str);
1375 if (*str == ',')
1377 str++;
1378 ans = parse_gen_reg (&str, &r3);
1379 if (ans == 0)
1381 opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
1383 else
1385 str = parse_exp (str, &e1);
1386 if (e1.X_op == O_constant)
1388 int imm = e1.X_add_number;
1390 if (imm < 0 || imm > 31)
1391 as_bad ("immediate value out of range");
1393 opcode |=
1394 (r1 << 10) | (r2 << 16) | (1 << 9) | ((imm & 0x1f) <<
1397 else
1399 as_bad ("immediate operand required");
1400 return;
1405 else
1407 as_bad ("SourceA register required");
1408 return;
1410 this_dest = r1;
1411 break;
1413 case mode_di:
1414 /* register := 5-bit immediate
1415 Example:
1416 eamread r1,3 */
1417 ans = parse_gen_reg (&str, &r1);
1418 if (ans < 0)
1420 as_bad ("Dest register required");
1421 return;
1423 str = skip_space (str);
1424 if (*str == ',')
1426 str++;
1427 str = parse_exp (str, &e1);
1428 if (e1.X_op == O_constant)
1430 int opnd2 = e1.X_add_number;
1432 if (opnd2 < 0 || opnd2 > 31)
1434 as_bad ("immediate operand out of range");
1435 return;
1437 opcode |= (r1 << 10) | ((opnd2 & 0x1f) << 4);
1439 else
1441 as_bad ("immediate operand required");
1442 return;
1445 else
1447 as_bad ("immediate operand required");
1448 return;
1450 this_dest = r1;
1451 break;
1453 case mode_ir:
1454 /* 5-bit immediate * register, e.g. trace 1,r1 */
1455 str = parse_exp (str, &e1);
1456 str = skip_space (str);
1457 if (e1.X_op == O_constant && *str == ',')
1459 int opnd1 = e1.X_add_number;
1461 str = skip_space (str + 1);
1462 ans = parse_gen_reg (&str, &r2);
1463 if (ans < 0)
1465 as_bad ("SourceA register required");
1466 return;
1469 /* Got two operands, assemble instruction. */
1470 if (opnd1 < 0 || opnd1 > 31)
1472 as_bad ("1st operand out of range");
1474 opcode |= ((opnd1 & 0x1f) << 10) | (r2 << 16);
1476 else
1478 as_bad ("Immediate operand required");
1479 return;
1481 break;
1483 case mode_ai:
1484 /* register *= 16-bit unsigned immediate
1485 Example:
1486 addi r1,123 */
1487 ans = parse_gen_reg (&str, &r1);
1488 if (ans < 0)
1490 as_bad ("Dest register required");
1491 return;
1493 opcode |= (r1 << 16);
1495 str = skip_space (str);
1496 if (*str != ',')
1498 as_bad ("immediate value missing");
1499 return;
1501 this_dest = r1;
1502 /* Fall through. */
1504 case mode_i:
1505 /* MOVIL/WRTL traditionally get an implicit "%l" applied
1506 to their immediate value. For other opcodes, unless
1507 the immediate value is decorated with "%u" or "%l"
1508 it must be in the range 0 .. 65535. */
1509 if ((opcode & 0x7fe00000) == 0x04800000
1510 || (opcode & 0x7fe00000) == 0x05000000)
1511 reloc = BFD_RELOC_VISIUM_LO16;
1512 else
1513 reloc = BFD_RELOC_VISIUM_IM16;
1515 str = skip_space (str + 1);
1517 if (*str == '%')
1519 if (str[1] == 'u')
1520 reloc = BFD_RELOC_VISIUM_HI16;
1521 else if (str[1] == 'l')
1522 reloc = BFD_RELOC_VISIUM_LO16;
1523 else
1525 as_bad ("bad char after %%");
1526 return;
1529 str += 2;
1531 str = parse_exp (str, &e1);
1532 if (e1.X_op != O_absent)
1534 if (e1.X_op == O_constant)
1536 int imm = e1.X_add_number;
1538 if (reloc == BFD_RELOC_VISIUM_HI16)
1539 opcode |= ((imm >> 16) & 0xffff);
1540 else if (reloc == BFD_RELOC_VISIUM_LO16)
1541 opcode |= (imm & 0xffff);
1542 else
1544 if (imm < 0 || imm > 0xffff)
1545 as_bad ("immediate value out of range");
1547 opcode |= (imm & 0xffff);
1549 /* No relocation is needed. */
1550 reloc = 0;
1553 else
1555 as_bad ("immediate value missing");
1556 return;
1558 break;
1560 case mode_bax:
1561 /* register * register * 5-bit immediate,
1562 SourceB * SourceA * Index
1563 Examples
1564 write.l (r1),r2
1565 write.l 3(r1),r2 */
1566 str = skip_space (str);
1568 indx = 0;
1569 if (*str != '(')
1571 str = parse_exp (str, &e1);
1572 if (e1.X_op == O_constant)
1574 indx = e1.X_add_number;
1576 if (indx < 0 || indx > 31)
1578 as_bad ("Index out of range");
1579 return;
1582 else
1584 as_bad ("Index(SourceA) required");
1585 return;
1589 str = skip_space (str);
1591 if (*str != '(')
1593 as_bad ("Index(SourceA) required");
1594 return;
1597 str = skip_space (str + 1);
1599 ans = parse_gen_reg (&str, &r1);
1600 if (ans < 0)
1602 as_bad ("SourceA register required");
1603 return;
1605 str = skip_space (str);
1606 if (*str != ')')
1608 as_bad ("(SourceA) required");
1609 return;
1611 str = skip_space (str + 1);
1613 if (*str == ',')
1615 str = skip_space (str + 1);
1616 ans = parse_gen_reg (&str, &r2);
1617 if (ans < 0)
1619 as_bad ("SourceB register required");
1620 return;
1623 else
1625 as_bad ("SourceB register required");
1626 return;
1629 opcode |= (r1 << 16) | (r2 << 4) | ((indx & 0x1f) << 10);
1631 if (indx != 0 && previous_mode == mode_cad)
1633 /* We're in a delay slot.
1634 If the base reg is the destination of the branch, then issue
1635 an error message.
1636 Otherwise it is safe to use the base and index. */
1637 if (previous_dest != 0 && r1 == previous_dest)
1639 as_bad ("base register not ready");
1640 return;
1643 else if (previous_dest != 0
1644 && r1 == previous_dest
1645 && (visium_arch == VISIUM_ARCH_MCM
1646 || visium_arch == VISIUM_ARCH_MCM24
1647 || (visium_arch == VISIUM_ARCH_DEF && indx != 0)))
1649 as_warn ("base register not ready, NOP inserted.");
1650 /* Insert a NOP before the write instruction. */
1651 output = frag_more (4);
1652 memset (output, 0, 4);
1654 break;
1656 case mode_dax:
1657 /* register := register * 5-bit immediate
1658 Examples:
1659 read.b r1,(r2)
1660 read.w r1,3(r2) */
1661 ans = parse_gen_reg (&str, &r1);
1662 if (ans < 0)
1664 as_bad ("Dest register required");
1665 return;
1667 str = skip_space (str);
1668 if (*str != ',')
1670 as_bad ("SourceA required");
1671 return;
1673 str = skip_space (str + 1);
1675 indx = 0;
1676 if (*str != '(')
1678 str = parse_exp (str, &e1);
1679 if (e1.X_op == O_constant)
1681 indx = e1.X_add_number;
1683 if (indx < 0 || indx > 31)
1685 as_bad ("Index out of range");
1686 return;
1689 else
1691 as_bad ("Immediate 0 to 31 required");
1692 return;
1695 if (*str != '(')
1697 as_bad ("(SourceA) required");
1698 return;
1700 str++;
1701 ans = parse_gen_reg (&str, &r2);
1702 if (ans < 0)
1704 as_bad ("SourceA register required");
1705 return;
1707 str = skip_space (str);
1708 if (*str != ')')
1710 as_bad ("(SourceA) required");
1711 return;
1713 str++;
1714 opcode |= (r1 << 10) | (r2 << 16) | ((indx & 0x1f) << 4);
1715 this_dest = r1;
1717 if (indx != 0 && previous_mode == mode_cad)
1719 /* We're in a delay slot.
1720 If the base reg is the destination of the branch, then issue
1721 an error message.
1722 Otherwise it is safe to use the base and index. */
1723 if (previous_dest != 0 && r2 == previous_dest)
1725 as_bad ("base register not ready");
1726 return;
1729 else if (previous_dest != 0
1730 && r2 == previous_dest
1731 && (visium_arch == VISIUM_ARCH_MCM
1732 || visium_arch == VISIUM_ARCH_MCM24
1733 || (visium_arch == VISIUM_ARCH_DEF && indx != 0)))
1735 as_warn ("base register not ready, NOP inserted.");
1736 /* Insert a NOP before the read instruction. */
1737 output = frag_more (4);
1738 memset (output, 0, 4);
1740 break;
1742 case mode_s:
1743 /* special mode
1744 Example:
1745 nop */
1746 str = skip_space (str);
1747 break;
1749 case mode_ci:
1750 /* condition * 16-bit signed word displacement
1751 Example:
1752 brr L1 */
1753 ans = parse_cc (&str, &cc);
1754 if (ans < 0)
1756 as_bad ("condition code required");
1757 return;
1759 opcode |= (cc << 27);
1761 str = skip_space (str);
1762 if (*str == ',')
1764 str = skip_space (str + 1);
1765 str = parse_exp (str, &e1);
1766 if (e1.X_op != O_absent)
1768 if (e1.X_op == O_constant)
1770 int imm = e1.X_add_number;
1772 if (imm < -32768 || imm > 32767)
1773 as_bad ("immediate value out of range");
1775 /* The GR6 doesn't correctly handle a 0 displacement
1776 so we insert a NOP and change it to -1. */
1777 if (imm == 0 && cc != 0 && visium_arch == VISIUM_ARCH_GR6)
1779 output = frag_more (4);
1780 memset (output, 0, 4);
1781 imm = -1;
1784 opcode |= (imm & 0xffff);
1786 else if (e1.X_op == O_symbol)
1788 /* The GR6 doesn't correctly handle a 0 displacement
1789 so the instruction requires relaxation. */
1790 if (cc != 0 && visium_arch == VISIUM_ARCH_GR6)
1791 relax = amode;
1792 else
1793 reloc = BFD_RELOC_VISIUM_REL16;
1795 else
1797 as_bad ("immediate value missing");
1798 return;
1801 else
1803 as_bad ("immediate value missing");
1804 return;
1807 else
1809 as_bad ("immediate value missing");
1810 return;
1813 if (previous_mode == mode_cad || previous_mode == mode_ci)
1814 as_bad ("branch instruction in delay slot");
1816 condition_code = cc;
1817 break;
1819 case mode_fdab:
1820 /* float := float * float
1821 Example
1822 fadd f4,f3,f2 */
1823 ans = parse_fp_reg (&str, &r1);
1824 if (ans < 0)
1826 as_bad ("floating point destination register required");
1827 return;
1829 str = skip_space (str);
1830 if (*str == ',')
1832 str++;
1833 ans = parse_fp_reg (&str, &r2);
1834 if (ans < 0)
1836 as_bad ("floating point SourceA register required");
1837 return;
1839 str = skip_space (str);
1840 if (*str == ',')
1842 str++;
1843 ans = parse_fp_reg (&str, &r3);
1844 if (ans < 0)
1846 as_bad ("floating point SourceB register required");
1847 return;
1850 /* Got 3 floating regs, assemble instruction. */
1851 opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
1853 else
1855 as_bad ("floating point SourceB register required");
1856 return;
1859 else
1861 as_bad ("floating point SourceA register required");
1862 return;
1864 break;
1866 case mode_ifdab:
1867 /* 4-bit immediate * float * float * float
1868 Example
1869 fpinst 10,f1,f2,f3 */
1870 str = parse_exp (str, &e1);
1871 str = skip_space (str);
1872 if (e1.X_op != O_absent && *str == ',')
1874 int finst = e1.X_add_number;
1876 str = skip_space (str + 1);
1877 ans = parse_fp_reg (&str, &r1);
1878 if (ans < 0)
1880 as_bad ("floating point destination register required");
1881 return;
1883 str = skip_space (str);
1884 if (*str == ',')
1886 str++;
1887 ans = parse_fp_reg (&str, &r2);
1888 if (ans < 0)
1890 as_bad ("floating point SourceA register required");
1891 return;
1893 str = skip_space (str);
1894 if (*str == ',')
1896 str++;
1897 ans = parse_fp_reg (&str, &r3);
1898 if (ans < 0)
1900 as_bad ("floating point SourceB register required");
1901 return;
1904 /* Got immediate and 3 floating regs,
1905 assemble instruction. */
1906 if (finst < 0 || finst > 15)
1907 as_bad ("finst out of range");
1909 opcode |=
1910 ((finst & 0xf) << 27) | (r1 << 10) | (r2 << 16) | (r3 <<
1913 else
1915 as_bad ("floating point SourceB register required");
1916 return;
1919 else
1921 as_bad ("floating point SourceA register required");
1922 return;
1925 else
1927 as_bad ("finst missing");
1928 return;
1930 break;
1932 case mode_idfab:
1933 /* 4-bit immediate * register * float * float
1934 Example
1935 fpuread 4,r25,f2,f3 */
1936 str = parse_exp (str, &e1);
1937 str = skip_space (str);
1938 if (e1.X_op != O_absent && *str == ',')
1940 int finst = e1.X_add_number;
1942 str = skip_space (str + 1);
1943 ans = parse_gen_reg (&str, &r1);
1944 if (ans < 0)
1946 as_bad ("destination general register required");
1947 return;
1949 str = skip_space (str);
1950 if (*str == ',')
1952 str++;
1953 ans = parse_fp_reg (&str, &r2);
1954 if (ans < 0)
1956 as_bad ("floating point SourceA register required");
1957 return;
1959 str = skip_space (str);
1960 if (*str == ',')
1962 str++;
1963 ans = parse_fp_reg (&str, &r3);
1964 if (ans < 0)
1966 as_bad ("floating point SourceB register required");
1967 return;
1970 /* Got immediate and 3 floating regs,
1971 assemble instruction. */
1972 if (finst < 0 || finst > 15)
1973 as_bad ("finst out of range");
1975 opcode |=
1976 ((finst & 0xf) << 27) | (r1 << 10) | (r2 << 16) | (r3 <<
1979 else
1981 as_bad ("floating point SourceB register required");
1982 return;
1985 else
1987 as_bad ("floating point SourceA register required");
1988 return;
1991 else
1993 as_bad ("finst missing");
1994 return;
1996 break;
1998 case mode_fda:
1999 /* float := float
2000 Example
2001 fsqrt f4,f3 */
2002 ans = parse_fp_reg (&str, &r1);
2003 if (ans < 0)
2005 as_bad ("floating point destination register required");
2006 return;
2008 str = skip_space (str);
2009 if (*str == ',')
2011 str++;
2012 ans = parse_fp_reg (&str, &r2);
2013 if (ans < 0)
2015 as_bad ("floating point source register required");
2016 return;
2019 /* Got 2 floating regs, assemble instruction. */
2020 opcode |= (r1 << 10) | (r2 << 16);
2022 else
2024 as_bad ("floating point source register required");
2025 return;
2027 break;
2029 case mode_fdra:
2030 /* float := register
2031 Example
2032 fload f15,r6 */
2033 ans = parse_fp_reg (&str, &r1);
2034 if (ans < 0)
2036 as_bad ("floating point destination register required");
2037 return;
2039 str = skip_space (str);
2040 if (*str == ',')
2042 str++;
2043 ans = parse_gen_reg (&str, &r2);
2044 if (ans < 0)
2046 as_bad ("SourceA general register required");
2047 return;
2050 /* Got 2 regs, assemble instruction. */
2051 opcode |= (r1 << 10) | (r2 << 16);
2053 else
2055 as_bad ("SourceA general register required");
2056 return;
2058 break;
2060 case mode_rdfab:
2061 /* register := float * float
2062 Example
2063 fcmp r0,f4,f8
2064 For the GR6, register must be r0 and can be omitted. */
2065 ans = parse_gen_reg (&str, &r1);
2066 if (ans < 0)
2068 if (visium_opcode_arch == VISIUM_OPCODE_ARCH_GR5)
2070 as_bad ("Dest general register required");
2071 return;
2073 r1 = 0;
2075 else
2077 if (r1 != 0 && visium_opcode_arch != VISIUM_OPCODE_ARCH_GR5)
2079 as_bad ("FCMP/FCMPE can only use r0 as Dest register");
2080 return;
2083 str = skip_space (str);
2084 if (*str == ',')
2085 str++;
2086 else
2088 as_bad ("floating point SourceA register required");
2089 return;
2093 ans = parse_fp_reg (&str, &r2);
2094 if (ans < 0)
2096 as_bad ("floating point SourceA register required");
2097 return;
2099 str = skip_space (str);
2100 if (*str == ',')
2102 str++;
2103 ans = parse_fp_reg (&str, &r3);
2104 if (ans < 0)
2106 as_bad ("floating point SourceB register required");
2107 return;
2110 /* Got 3 regs, assemble instruction. */
2111 opcode |= (r1 << 10) | (r2 << 16) | (r3 << 4);
2114 this_dest = r1;
2115 break;
2117 case mode_rdfa:
2118 /* register := float
2119 Example
2120 fstore r5,f12 */
2121 ans = parse_gen_reg (&str, &r1);
2122 if (ans < 0)
2124 as_bad ("Dest general register required");
2125 return;
2127 str = skip_space (str);
2128 if (*str == ',')
2130 str++;
2131 ans = parse_fp_reg (&str, &r2);
2132 if (ans < 0)
2134 as_bad ("floating point source register required");
2135 return;
2138 /* Got 2 regs, assemble instruction. */
2139 opcode |= (r1 << 10) | (r2 << 16);
2141 else
2143 as_bad ("floating point source register required");
2144 return;
2147 this_dest = r1;
2148 break;
2150 case mode_rrr:
2151 /* register register register, all sources and destinations
2152 Example:
2153 bmd r1,r2,r3 */
2155 ans = parse_gen_reg (&str, &r1);
2156 if (ans < 0)
2158 as_bad ("destination address register required");
2159 return;
2161 str = skip_space (str);
2162 if (*str == ',')
2164 str++;
2165 ans = parse_gen_reg (&str, &r2);
2166 if (ans < 0)
2168 as_bad ("source address register required");
2169 return;
2171 str = skip_space (str);
2172 if (*str == ',')
2174 str++;
2175 ans = parse_gen_reg (&str, &r3);
2176 if (ans < 0)
2178 as_bad ("count register required");
2179 return;
2182 /* We insist on three registers but the opcode can only use
2183 r1,r2,r3. */
2184 if (r1 != 1 || r2 != 2 || r3 != 3)
2186 as_bad ("BMI/BMD can only use format op r1,r2,r3");
2187 return;
2190 /* Opcode is unmodified by what comes out of the table. */
2192 else
2194 as_bad ("register required");
2195 return;
2198 else
2200 as_bad ("register required");
2201 return;
2204 this_dest = r1;
2205 break;
2207 default:
2208 break;
2211 if (relax)
2212 output = frag_var (rs_machine_dependent, 8, 4, relax, e1.X_add_symbol,
2213 e1.X_add_number, NULL);
2214 else
2215 output = frag_more (4);
2217 /* Build the 32-bit instruction in a host-endian-neutral fashion. */
2218 output[0] = (opcode >> 24) & 0xff;
2219 output[1] = (opcode >> 16) & 0xff;
2220 output[2] = (opcode >> 8) & 0xff;
2221 output[3] = (opcode >> 0) & 0xff;
2223 if (relax)
2224 /* The size of the instruction is unknown, so tie the debug info to the
2225 start of the instruction. */
2226 dwarf2_emit_insn (0);
2227 else
2229 if (reloc)
2230 fix_new_exp (frag_now, output - frag_now->fr_literal, 4, &e1,
2231 reloc == BFD_RELOC_VISIUM_REL16, reloc);
2232 else
2233 visium_update_parity_bit (output);
2235 dwarf2_emit_insn (4);
2238 if (*str != '\0')
2239 as_bad ("junk after instruction");
2242 void
2243 visium_cfi_frame_initial_instructions (void)
2245 /* The CFA is in SP on function entry. */
2246 cfi_add_CFA_def_cfa (23, 0);
2250 visium_regname_to_dw2regnum (char *regname)
2252 if (!regname[0])
2253 return -1;
2255 if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
2256 return 22;
2258 if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
2259 return 23;
2261 if (regname[0] == 'm' && regname[1] == 'd' && !regname[3])
2262 switch (regname[2])
2264 case 'b': return 32;
2265 case 'a': return 33;
2266 case 'c': return 34;
2267 default : return -1;
2270 if (regname[0] == 'f' || regname[0] == 'r')
2272 char *p;
2273 unsigned int regnum = strtoul (regname + 1, &p, 10);
2274 if (*p)
2275 return -1;
2276 if (regnum >= (regname[0] == 'f' ? 16 : 32))
2277 return -1;
2278 if (regname[0] == 'f')
2279 regnum += 35;
2280 return regnum;
2283 return -1;