(tc_gen_reloc): Use bfd_get_reloc_code_name in error message.
[deliverable/binutils-gdb.git] / gas / config / tc-sparc.c
1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 1990, 1991, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include <ctype.h>
22
23 #include "as.h"
24 #include "subsegs.h"
25
26 /* careful, this file includes data *declarations* */
27 #include "opcode/sparc.h"
28
29 static void sparc_ip PARAMS ((char *));
30
31 #ifdef sparcv9
32 static enum sparc_architecture current_architecture = v9;
33 #else
34 static enum sparc_architecture current_architecture = v6;
35 #endif
36 static int architecture_requested;
37 static int warn_on_bump;
38
39 extern int target_big_endian;
40
41 const relax_typeS md_relax_table[1];
42
43 /* handle of the OPCODE hash table */
44 static struct hash_control *op_hash;
45
46 static void s_data1 PARAMS ((void));
47 static void s_seg PARAMS ((int));
48 static void s_proc PARAMS ((int));
49 static void s_reserve PARAMS ((int));
50 static void s_common PARAMS ((int));
51
52 const pseudo_typeS md_pseudo_table[] =
53 {
54 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
55 {"common", s_common, 0},
56 {"global", s_globl, 0},
57 {"half", cons, 2},
58 {"optim", s_ignore, 0},
59 {"proc", s_proc, 0},
60 {"reserve", s_reserve, 0},
61 {"seg", s_seg, 0},
62 {"skip", s_space, 0},
63 {"word", cons, 4},
64 #ifndef NO_V9
65 {"xword", cons, 8},
66 #ifdef OBJ_ELF
67 {"uaxword", cons, 8},
68 #endif
69 #endif
70 #ifdef OBJ_ELF
71 /* these are specific to sparc/svr4 */
72 {"pushsection", obj_elf_section, 0},
73 {"popsection", obj_elf_previous, 0},
74 {"uaword", cons, 4},
75 {"uahalf", cons, 2},
76 #endif
77 {NULL, 0, 0},
78 };
79
80 const int md_short_jump_size = 4;
81 const int md_long_jump_size = 4;
82 const int md_reloc_size = 12; /* Size of relocation record */
83
84 /* This array holds the chars that always start a comment. If the
85 pre-processor is disabled, these aren't very useful */
86 const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */
87
88 /* This array holds the chars that only start a comment at the beginning of
89 a line. If the line seems to have the form '# 123 filename'
90 .line and .file directives will appear in the pre-processed output */
91 /* Note that input_file.c hand checks for '#' at the beginning of the
92 first line of the input file. This is because the compiler outputs
93 #NO_APP at the beginning of its output. */
94 /* Also note that comments started like this one will always
95 work if '/' isn't otherwise defined. */
96 const char line_comment_chars[] = "#";
97
98 const char line_separator_chars[] = "";
99
100 /* Chars that can be used to separate mant from exp in floating point nums */
101 const char EXP_CHARS[] = "eE";
102
103 /* Chars that mean this number is a floating point constant */
104 /* As in 0f12.456 */
105 /* or 0d1.2345e12 */
106 const char FLT_CHARS[] = "rRsSfFdDxXpP";
107
108 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
109 changed in read.c. Ideally it shouldn't have to know about it at all,
110 but nothing is ideal around here. */
111
112 static unsigned char octal[256];
113 #define isoctal(c) octal[(unsigned char) (c)]
114 static unsigned char toHex[256];
115
116 struct sparc_it
117 {
118 char *error;
119 unsigned long opcode;
120 struct nlist *nlistp;
121 expressionS exp;
122 int pcrel;
123 bfd_reloc_code_real_type reloc;
124 };
125
126 struct sparc_it the_insn, set_insn;
127
128 static INLINE int
129 in_signed_range (val, max)
130 bfd_signed_vma val, max;
131 {
132 if (max <= 0)
133 abort ();
134 if (val > max)
135 return 0;
136 if (val < ~max)
137 return 0;
138 return 1;
139 }
140
141 #if 0
142 static void print_insn PARAMS ((struct sparc_it *insn));
143 #endif
144 static int getExpression PARAMS ((char *str));
145
146 static char *expr_end;
147 static int special_case;
148
149 /*
150 * Instructions that require wierd handling because they're longer than
151 * 4 bytes.
152 */
153 #define SPECIAL_CASE_SET 1
154 #define SPECIAL_CASE_FDIV 2
155
156 /*
157 * sort of like s_lcomm
158 *
159 */
160 #ifndef OBJ_ELF
161 static int max_alignment = 15;
162 #endif
163
164 static void
165 s_reserve (ignore)
166 int ignore;
167 {
168 char *name;
169 char *p;
170 char c;
171 int align;
172 int size;
173 int temp;
174 symbolS *symbolP;
175
176 name = input_line_pointer;
177 c = get_symbol_end ();
178 p = input_line_pointer;
179 *p = c;
180 SKIP_WHITESPACE ();
181
182 if (*input_line_pointer != ',')
183 {
184 as_bad ("Expected comma after name");
185 ignore_rest_of_line ();
186 return;
187 }
188
189 ++input_line_pointer;
190
191 if ((size = get_absolute_expression ()) < 0)
192 {
193 as_bad ("BSS length (%d.) <0! Ignored.", size);
194 ignore_rest_of_line ();
195 return;
196 } /* bad length */
197
198 *p = 0;
199 symbolP = symbol_find_or_make (name);
200 *p = c;
201
202 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
203 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
204 {
205 as_bad ("bad .reserve segment -- expected BSS segment");
206 return;
207 }
208
209 if (input_line_pointer[2] == '.')
210 input_line_pointer += 7;
211 else
212 input_line_pointer += 6;
213 SKIP_WHITESPACE ();
214
215 if (*input_line_pointer == ',')
216 {
217 ++input_line_pointer;
218
219 SKIP_WHITESPACE ();
220 if (*input_line_pointer == '\n')
221 {
222 as_bad ("Missing alignment");
223 return;
224 }
225
226 align = get_absolute_expression ();
227 #ifndef OBJ_ELF
228 if (align > max_alignment)
229 {
230 align = max_alignment;
231 as_warn ("Alignment too large: %d. assumed.", align);
232 }
233 #endif
234 if (align < 0)
235 {
236 align = 0;
237 as_warn ("Alignment negative. 0 assumed.");
238 }
239
240 record_alignment (bss_section, align);
241
242 /* convert to a power of 2 alignment */
243 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
244
245 if (align != 1)
246 {
247 as_bad ("Alignment not a power of 2");
248 ignore_rest_of_line ();
249 return;
250 } /* not a power of two */
251
252 align = temp;
253 } /* if has optional alignment */
254 else
255 align = 0;
256
257 if ((S_GET_SEGMENT (symbolP) == bss_section
258 || !S_IS_DEFINED (symbolP))
259 #ifdef OBJ_AOUT
260 && S_GET_OTHER (symbolP) == 0
261 && S_GET_DESC (symbolP) == 0
262 #endif
263 )
264 {
265 if (! need_pass_2)
266 {
267 char *pfrag;
268 segT current_seg = now_seg;
269 subsegT current_subseg = now_subseg;
270
271 subseg_set (bss_section, 1); /* switch to bss */
272
273 if (align)
274 frag_align (align, 0); /* do alignment */
275
276 /* detach from old frag */
277 if (S_GET_SEGMENT(symbolP) == bss_section)
278 symbolP->sy_frag->fr_symbol = NULL;
279
280 symbolP->sy_frag = frag_now;
281 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
282 size, (char *)0);
283 *pfrag = 0;
284
285 S_SET_SEGMENT (symbolP, bss_section);
286
287 subseg_set (current_seg, current_subseg);
288 }
289 }
290 else
291 {
292 as_warn("Ignoring attempt to re-define symbol %s.", name);
293 } /* if not redefining */
294
295 demand_empty_rest_of_line ();
296 }
297
298 static void
299 s_common (ignore)
300 int ignore;
301 {
302 char *name;
303 char c;
304 char *p;
305 int temp, size;
306 symbolS *symbolP;
307
308 name = input_line_pointer;
309 c = get_symbol_end ();
310 /* just after name is now '\0' */
311 p = input_line_pointer;
312 *p = c;
313 SKIP_WHITESPACE ();
314 if (*input_line_pointer != ',')
315 {
316 as_bad ("Expected comma after symbol-name");
317 ignore_rest_of_line ();
318 return;
319 }
320 input_line_pointer++; /* skip ',' */
321 if ((temp = get_absolute_expression ()) < 0)
322 {
323 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
324 ignore_rest_of_line ();
325 return;
326 }
327 size = temp;
328 *p = 0;
329 symbolP = symbol_find_or_make (name);
330 *p = c;
331 if (S_IS_DEFINED (symbolP))
332 {
333 as_bad ("Ignoring attempt to re-define symbol");
334 ignore_rest_of_line ();
335 return;
336 }
337 if (S_GET_VALUE (symbolP) != 0)
338 {
339 if (S_GET_VALUE (symbolP) != size)
340 {
341 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
342 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
343 }
344 }
345 else
346 {
347 #ifndef OBJ_ELF
348 S_SET_VALUE (symbolP, (valueT) size);
349 S_SET_EXTERNAL (symbolP);
350 #endif
351 }
352 know (symbolP->sy_frag == &zero_address_frag);
353 if (*input_line_pointer != ',')
354 {
355 as_bad ("Expected comma after common length");
356 ignore_rest_of_line ();
357 return;
358 }
359 input_line_pointer++;
360 SKIP_WHITESPACE ();
361 if (*input_line_pointer != '"')
362 {
363 temp = get_absolute_expression ();
364 #ifndef OBJ_ELF
365 if (temp > max_alignment)
366 {
367 temp = max_alignment;
368 as_warn ("Common alignment too large: %d. assumed", temp);
369 }
370 #endif
371 if (temp < 0)
372 {
373 temp = 0;
374 as_warn ("Common alignment negative; 0 assumed");
375 }
376 #ifdef OBJ_ELF
377 if (symbolP->local)
378 {
379 segT old_sec;
380 int old_subsec;
381 char *p;
382 int align;
383
384 allocate_bss:
385 old_sec = now_seg;
386 old_subsec = now_subseg;
387 align = temp;
388 record_alignment (bss_section, align);
389 subseg_set (bss_section, 0);
390 if (align)
391 frag_align (align, 0);
392 if (S_GET_SEGMENT (symbolP) == bss_section)
393 symbolP->sy_frag->fr_symbol = 0;
394 symbolP->sy_frag = frag_now;
395 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
396 (char *) 0);
397 *p = 0;
398 S_SET_SEGMENT (symbolP, bss_section);
399 S_CLEAR_EXTERNAL (symbolP);
400 subseg_set (old_sec, old_subsec);
401 }
402 else
403 #endif
404 {
405 allocate_common:
406 S_SET_VALUE (symbolP, (valueT) size);
407 #ifdef OBJ_ELF
408 S_SET_ALIGN (symbolP, temp);
409 #endif
410 S_SET_EXTERNAL (symbolP);
411 /* should be common, but this is how gas does it for now */
412 S_SET_SEGMENT (symbolP, bfd_und_section_ptr);
413 }
414 }
415 else
416 {
417 input_line_pointer++;
418 /* @@ Some use the dot, some don't. Can we get some consistency?? */
419 if (*input_line_pointer == '.')
420 input_line_pointer++;
421 /* @@ Some say data, some say bss. */
422 if (strncmp (input_line_pointer, "bss\"", 4)
423 && strncmp (input_line_pointer, "data\"", 5))
424 {
425 while (*--input_line_pointer != '"')
426 ;
427 input_line_pointer--;
428 goto bad_common_segment;
429 }
430 while (*input_line_pointer++ != '"')
431 ;
432 goto allocate_common;
433 }
434 demand_empty_rest_of_line ();
435 return;
436
437 {
438 bad_common_segment:
439 p = input_line_pointer;
440 while (*p && *p != '\n')
441 p++;
442 c = *p;
443 *p = '\0';
444 as_bad ("bad .common segment %s", input_line_pointer + 1);
445 *p = c;
446 input_line_pointer = p;
447 ignore_rest_of_line ();
448 return;
449 }
450 }
451
452 static void
453 s_seg (ignore)
454 int ignore;
455 {
456
457 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
458 {
459 input_line_pointer += 6;
460 s_text (0);
461 return;
462 }
463 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
464 {
465 input_line_pointer += 6;
466 s_data (0);
467 return;
468 }
469 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
470 {
471 input_line_pointer += 7;
472 s_data1 ();
473 return;
474 }
475 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
476 {
477 input_line_pointer += 5;
478 /* We only support 2 segments -- text and data -- for now, so
479 things in the "bss segment" will have to go into data for now.
480 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
481 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
482 return;
483 }
484 as_bad ("Unknown segment type");
485 demand_empty_rest_of_line ();
486 }
487
488 static void
489 s_data1 ()
490 {
491 subseg_set (data_section, 1);
492 demand_empty_rest_of_line ();
493 }
494
495 static void
496 s_proc (ignore)
497 int ignore;
498 {
499 while (!is_end_of_line[(unsigned char) *input_line_pointer])
500 {
501 ++input_line_pointer;
502 }
503 ++input_line_pointer;
504 }
505
506 #ifndef NO_V9
507
508 struct priv_reg_entry
509 {
510 char *name;
511 int regnum;
512 };
513
514 struct priv_reg_entry priv_reg_table[] =
515 {
516 {"tpc", 0},
517 {"tnpc", 1},
518 {"tstate", 2},
519 {"tt", 3},
520 {"tick", 4},
521 {"tba", 5},
522 {"pstate", 6},
523 {"tl", 7},
524 {"pil", 8},
525 {"cwp", 9},
526 {"cansave", 10},
527 {"canrestore", 11},
528 {"cleanwin", 12},
529 {"otherwin", 13},
530 {"wstate", 14},
531 {"fq", 15},
532 {"ver", 31},
533 {"", -1}, /* end marker */
534 };
535
536 struct membar_masks
537 {
538 char *name;
539 unsigned int len;
540 unsigned int mask;
541 };
542
543 #define MEMBAR_MASKS_SIZE 7
544
545 static const struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
546 {
547 {"Sync", 4, 0x40},
548 {"MemIssue", 8, 0x20},
549 {"Lookaside", 9, 0x10},
550 {"StoreStore", 10, 0x08},
551 {"LoadStore", 9, 0x04},
552 {"StoreLoad", 9, 0x02},
553 {"LoadLoad", 8, 0x01},
554 };
555
556 static int
557 cmp_reg_entry (p, q)
558 struct priv_reg_entry *p, *q;
559 {
560 return strcmp (q->name, p->name);
561 }
562
563 #endif
564
565 /* This function is called once, at assembler startup time. It should
566 set up all the tables, etc. that the MD part of the assembler will need. */
567 void
568 md_begin ()
569 {
570 register const char *retval = NULL;
571 int lose = 0;
572 register unsigned int i = 0;
573
574 op_hash = hash_new ();
575
576 while (i < NUMOPCODES)
577 {
578 const char *name = sparc_opcodes[i].name;
579 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
580 if (retval != NULL)
581 {
582 fprintf (stderr, "internal error: can't hash `%s': %s\n",
583 sparc_opcodes[i].name, retval);
584 lose = 1;
585 }
586 do
587 {
588 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
589 {
590 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
591 sparc_opcodes[i].name, sparc_opcodes[i].args);
592 lose = 1;
593 }
594 ++i;
595 }
596 while (i < NUMOPCODES
597 && !strcmp (sparc_opcodes[i].name, name));
598 }
599
600 if (lose)
601 as_fatal ("Broken assembler. No assembly attempted.");
602
603 for (i = '0'; i < '8'; ++i)
604 octal[i] = 1;
605 for (i = '0'; i <= '9'; ++i)
606 toHex[i] = i - '0';
607 for (i = 'a'; i <= 'f'; ++i)
608 toHex[i] = i + 10 - 'a';
609 for (i = 'A'; i <= 'F'; ++i)
610 toHex[i] = i + 10 - 'A';
611
612 #ifndef NO_V9
613 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
614 sizeof (priv_reg_table[0]), cmp_reg_entry);
615 #endif
616
617 target_big_endian = 1;
618 }
619
620 void
621 md_assemble (str)
622 char *str;
623 {
624 char *toP;
625 int rsd;
626
627 know (str);
628 sparc_ip (str);
629
630 /* See if "set" operand is absolute and small; skip sethi if so. */
631 if (special_case == SPECIAL_CASE_SET
632 && the_insn.exp.X_op == O_constant)
633 {
634 if (the_insn.exp.X_add_number >= -(1 << 12)
635 && the_insn.exp.X_add_number < (1 << 12))
636 {
637 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
638 | (the_insn.opcode & 0x3E000000) /* dest reg */
639 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
640 special_case = 0; /* No longer special */
641 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
642 }
643 }
644
645 toP = frag_more (4);
646 /* put out the opcode */
647 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
648
649 /* put out the symbol-dependent stuff */
650 if (the_insn.reloc != BFD_RELOC_NONE)
651 {
652 fix_new_exp (frag_now, /* which frag */
653 (toP - frag_now->fr_literal), /* where */
654 4, /* size */
655 &the_insn.exp,
656 the_insn.pcrel,
657 the_insn.reloc);
658 }
659
660 switch (special_case)
661 {
662 case SPECIAL_CASE_SET:
663 special_case = 0;
664 assert (the_insn.reloc == BFD_RELOC_HI22);
665 /* See if "set" operand has no low-order bits; skip OR if so. */
666 if (the_insn.exp.X_op == O_constant
667 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
668 return;
669 toP = frag_more (4);
670 rsd = (the_insn.opcode >> 25) & 0x1f;
671 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
672 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
673 fix_new_exp (frag_now, /* which frag */
674 (toP - frag_now->fr_literal), /* where */
675 4, /* size */
676 &the_insn.exp,
677 the_insn.pcrel,
678 BFD_RELOC_LO10);
679 return;
680
681 case SPECIAL_CASE_FDIV:
682 /* According to information leaked from Sun, the "fdiv" instructions
683 on early SPARC machines would produce incorrect results sometimes.
684 The workaround is to add an fmovs of the destination register to
685 itself just after the instruction. This was true on machines
686 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
687 special_case = 0;
688 assert (the_insn.reloc == BFD_RELOC_NONE);
689 toP = frag_more (4);
690 rsd = (the_insn.opcode >> 25) & 0x1f;
691 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
692 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
693 return;
694
695 case 0:
696 return;
697
698 default:
699 as_fatal ("failed sanity check.");
700 }
701 }
702
703 /* Implement big shift right. */
704 static bfd_vma
705 BSR (val, amount)
706 bfd_vma val;
707 int amount;
708 {
709 if (sizeof (bfd_vma) <= 4 && amount >= 32)
710 as_fatal ("Support for 64-bit arithmetic not compiled in.");
711 return val >> amount;
712 }
713
714 static void
715 sparc_ip (str)
716 char *str;
717 {
718 char *error_message = "";
719 char *s;
720 const char *args;
721 char c;
722 struct sparc_opcode *insn;
723 char *argsStart;
724 unsigned long opcode;
725 unsigned int mask = 0;
726 int match = 0;
727 int comma = 0;
728 long immediate_max = 0;
729
730 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
731 ;
732 switch (*s)
733 {
734
735 case '\0':
736 break;
737
738 case ',':
739 comma = 1;
740
741 /*FALLTHROUGH */
742
743 case ' ':
744 *s++ = '\0';
745 break;
746
747 default:
748 as_bad ("Unknown opcode: `%s'", str);
749 exit (1);
750 }
751 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
752 {
753 as_bad ("Unknown opcode: `%s'", str);
754 return;
755 }
756 if (comma)
757 {
758 *--s = ',';
759 }
760 argsStart = s;
761 for (;;)
762 {
763 opcode = insn->match;
764 memset (&the_insn, '\0', sizeof (the_insn));
765 the_insn.reloc = BFD_RELOC_NONE;
766
767 /*
768 * Build the opcode, checking as we go to make
769 * sure that the operands match
770 */
771 for (args = insn->args;; ++args)
772 {
773 switch (*args)
774 {
775 #ifndef NO_V9
776 case 'K':
777 {
778 int kmask = 0;
779 int i;
780
781 /* Parse a series of masks. */
782 if (*s == '#')
783 {
784 while (*s == '#')
785 {
786 ++s;
787 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
788 if (!strncmp (s, membar_masks[i].name,
789 membar_masks[i].len))
790 break;
791 if (i < MEMBAR_MASKS_SIZE)
792 {
793 kmask |= membar_masks[i].mask;
794 s += membar_masks[i].len;
795 }
796 else
797 {
798 error_message = ": invalid membar mask name";
799 goto error;
800 }
801 if (*s == '|')
802 ++s;
803 }
804 }
805 else
806 {
807 expressionS exp;
808 char *hold;
809 char *send;
810
811 hold = input_line_pointer;
812 input_line_pointer = s;
813 expression (&exp);
814 send = input_line_pointer;
815 input_line_pointer = hold;
816
817 kmask = exp.X_add_number;
818 if (exp.X_op != O_constant
819 || kmask < 0
820 || kmask > 127)
821 {
822 error_message = ": invalid membar mask number";
823 goto error;
824 }
825
826 s = send;
827 }
828
829 opcode |= SIMM13 (kmask);
830 continue;
831 }
832
833 case '*':
834 {
835 int prefetch_fcn = 0;
836
837 /* Parse a prefetch function. */
838 if (*s == '#')
839 {
840 s += 1;
841 if (!strncmp (s, "n_reads", 7))
842 prefetch_fcn = 0, s += 7;
843 else if (!strncmp (s, "one_read", 8))
844 prefetch_fcn = 1, s += 8;
845 else if (!strncmp (s, "n_writes", 8))
846 prefetch_fcn = 2, s += 8;
847 else if (!strncmp (s, "one_write", 9))
848 prefetch_fcn = 3, s += 9;
849 else if (!strncmp (s, "page", 4))
850 prefetch_fcn = 4, s += 4;
851 else
852 {
853 error_message = ": invalid prefetch function name";
854 goto error;
855 }
856 }
857 else if (isdigit (*s))
858 {
859 while (isdigit (*s))
860 {
861 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
862 ++s;
863 }
864
865 if (prefetch_fcn < 0 || prefetch_fcn > 31)
866 {
867 error_message = ": invalid prefetch function number";
868 goto error;
869 }
870 }
871 else
872 {
873 error_message = ": unrecognizable prefetch function";
874 goto error;
875 }
876 opcode |= RD (prefetch_fcn);
877 continue;
878 }
879
880 case '!':
881 case '?':
882 /* Parse a privileged register. */
883 if (*s == '%')
884 {
885 struct priv_reg_entry *p = priv_reg_table;
886 unsigned int len = 9999999; /* init to make gcc happy */
887
888 s += 1;
889 while (p->name[0] > s[0])
890 p++;
891 while (p->name[0] == s[0])
892 {
893 len = strlen (p->name);
894 if (strncmp (p->name, s, len) == 0)
895 break;
896 p++;
897 }
898 if (p->name[0] != s[0])
899 {
900 error_message = ": unrecognizable privileged register";
901 goto error;
902 }
903 if (*args == '?')
904 opcode |= (p->regnum << 14);
905 else
906 opcode |= (p->regnum << 25);
907 s += len;
908 continue;
909 }
910 else
911 {
912 error_message = ": unrecognizable privileged register";
913 goto error;
914 }
915 #endif
916
917 case 'M':
918 case 'm':
919 if (strncmp (s, "%asr", 4) == 0)
920 {
921 s += 4;
922
923 if (isdigit (*s))
924 {
925 long num = 0;
926
927 while (isdigit (*s))
928 {
929 num = num * 10 + *s - '0';
930 ++s;
931 }
932
933 if (num < 16 || 31 < num)
934 {
935 error_message = ": asr number must be between 15 and 31";
936 goto error;
937 } /* out of range */
938
939 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
940 continue;
941 }
942 else
943 {
944 error_message = ": expecting %asrN";
945 goto error;
946 } /* if %asr followed by a number. */
947
948 } /* if %asr */
949 break;
950
951 #ifndef NO_V9
952 case 'I':
953 the_insn.reloc = BFD_RELOC_SPARC_11;
954 immediate_max = 0x03FF;
955 goto immediate;
956
957 case 'j':
958 the_insn.reloc = BFD_RELOC_SPARC_10;
959 immediate_max = 0x01FF;
960 goto immediate;
961
962 case 'k':
963 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
964 the_insn.pcrel = 1;
965 goto immediate;
966
967 case 'G':
968 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
969 the_insn.pcrel = 1;
970 goto immediate;
971
972 case 'N':
973 if (*s == 'p' && s[1] == 'n')
974 {
975 s += 2;
976 continue;
977 }
978 break;
979
980 case 'T':
981 if (*s == 'p' && s[1] == 't')
982 {
983 s += 2;
984 continue;
985 }
986 break;
987
988 case 'z':
989 if (*s == ' ')
990 {
991 ++s;
992 }
993 if (strncmp (s, "%icc", 4) == 0)
994 {
995 s += 4;
996 continue;
997 }
998 break;
999
1000 case 'Z':
1001 if (*s == ' ')
1002 {
1003 ++s;
1004 }
1005 if (strncmp (s, "%xcc", 4) == 0)
1006 {
1007 s += 4;
1008 continue;
1009 }
1010 break;
1011
1012 case '6':
1013 if (*s == ' ')
1014 {
1015 ++s;
1016 }
1017 if (strncmp (s, "%fcc0", 5) == 0)
1018 {
1019 s += 5;
1020 continue;
1021 }
1022 break;
1023
1024 case '7':
1025 if (*s == ' ')
1026 {
1027 ++s;
1028 }
1029 if (strncmp (s, "%fcc1", 5) == 0)
1030 {
1031 s += 5;
1032 continue;
1033 }
1034 break;
1035
1036 case '8':
1037 if (*s == ' ')
1038 {
1039 ++s;
1040 }
1041 if (strncmp (s, "%fcc2", 5) == 0)
1042 {
1043 s += 5;
1044 continue;
1045 }
1046 break;
1047
1048 case '9':
1049 if (*s == ' ')
1050 {
1051 ++s;
1052 }
1053 if (strncmp (s, "%fcc3", 5) == 0)
1054 {
1055 s += 5;
1056 continue;
1057 }
1058 break;
1059
1060 case 'P':
1061 if (strncmp (s, "%pc", 3) == 0)
1062 {
1063 s += 3;
1064 continue;
1065 }
1066 break;
1067
1068 case 'W':
1069 if (strncmp (s, "%tick", 5) == 0)
1070 {
1071 s += 5;
1072 continue;
1073 }
1074 break;
1075 #endif /* NO_V9 */
1076
1077 case '\0': /* end of args */
1078 if (*s == '\0')
1079 {
1080 match = 1;
1081 }
1082 break;
1083
1084 case '+':
1085 if (*s == '+')
1086 {
1087 ++s;
1088 continue;
1089 }
1090 if (*s == '-')
1091 {
1092 continue;
1093 }
1094 break;
1095
1096 case '[': /* these must match exactly */
1097 case ']':
1098 case ',':
1099 case ' ':
1100 if (*s++ == *args)
1101 continue;
1102 break;
1103
1104 case '#': /* must be at least one digit */
1105 if (isdigit (*s++))
1106 {
1107 while (isdigit (*s))
1108 {
1109 ++s;
1110 }
1111 continue;
1112 }
1113 break;
1114
1115 case 'C': /* coprocessor state register */
1116 if (strncmp (s, "%csr", 4) == 0)
1117 {
1118 s += 4;
1119 continue;
1120 }
1121 break;
1122
1123 case 'b': /* next operand is a coprocessor register */
1124 case 'c':
1125 case 'D':
1126 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1127 {
1128 mask = *s++;
1129 if (isdigit (*s))
1130 {
1131 mask = 10 * (mask - '0') + (*s++ - '0');
1132 if (mask >= 32)
1133 {
1134 break;
1135 }
1136 }
1137 else
1138 {
1139 mask -= '0';
1140 }
1141 switch (*args)
1142 {
1143
1144 case 'b':
1145 opcode |= mask << 14;
1146 continue;
1147
1148 case 'c':
1149 opcode |= mask;
1150 continue;
1151
1152 case 'D':
1153 opcode |= mask << 25;
1154 continue;
1155 }
1156 }
1157 break;
1158
1159 case 'r': /* next operand must be a register */
1160 case '1':
1161 case '2':
1162 case 'd':
1163 if (*s++ == '%')
1164 {
1165 switch (c = *s++)
1166 {
1167
1168 case 'f': /* frame pointer */
1169 if (*s++ == 'p')
1170 {
1171 mask = 0x1e;
1172 break;
1173 }
1174 goto error;
1175
1176 case 'g': /* global register */
1177 if (isoctal (c = *s++))
1178 {
1179 mask = c - '0';
1180 break;
1181 }
1182 goto error;
1183
1184 case 'i': /* in register */
1185 if (isoctal (c = *s++))
1186 {
1187 mask = c - '0' + 24;
1188 break;
1189 }
1190 goto error;
1191
1192 case 'l': /* local register */
1193 if (isoctal (c = *s++))
1194 {
1195 mask = (c - '0' + 16);
1196 break;
1197 }
1198 goto error;
1199
1200 case 'o': /* out register */
1201 if (isoctal (c = *s++))
1202 {
1203 mask = (c - '0' + 8);
1204 break;
1205 }
1206 goto error;
1207
1208 case 's': /* stack pointer */
1209 if (*s++ == 'p')
1210 {
1211 mask = 0xe;
1212 break;
1213 }
1214 goto error;
1215
1216 case 'r': /* any register */
1217 if (!isdigit (c = *s++))
1218 {
1219 goto error;
1220 }
1221 /* FALLTHROUGH */
1222 case '0':
1223 case '1':
1224 case '2':
1225 case '3':
1226 case '4':
1227 case '5':
1228 case '6':
1229 case '7':
1230 case '8':
1231 case '9':
1232 if (isdigit (*s))
1233 {
1234 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1235 {
1236 goto error;
1237 }
1238 }
1239 else
1240 {
1241 c -= '0';
1242 }
1243 mask = c;
1244 break;
1245
1246 default:
1247 goto error;
1248 }
1249 /*
1250 * Got the register, now figure out where
1251 * it goes in the opcode.
1252 */
1253 switch (*args)
1254 {
1255
1256 case '1':
1257 opcode |= mask << 14;
1258 continue;
1259
1260 case '2':
1261 opcode |= mask;
1262 continue;
1263
1264 case 'd':
1265 opcode |= mask << 25;
1266 continue;
1267
1268 case 'r':
1269 opcode |= (mask << 25) | (mask << 14);
1270 continue;
1271 }
1272 }
1273 break;
1274
1275 case 'e': /* next operand is a floating point register */
1276 case 'v':
1277 case 'V':
1278
1279 case 'f':
1280 case 'B':
1281 case 'R':
1282
1283 case 'g':
1284 case 'H':
1285 case 'J':
1286 {
1287 char format;
1288
1289 if (*s++ == '%'
1290 && ((format = *s) == 'f')
1291 && isdigit (*++s))
1292 {
1293 for (mask = 0; isdigit (*s); ++s)
1294 {
1295 mask = 10 * mask + (*s - '0');
1296 } /* read the number */
1297
1298 if ((*args == 'v'
1299 || *args == 'B'
1300 || *args == 'H')
1301 && (mask & 1))
1302 {
1303 break;
1304 } /* register must be even numbered */
1305
1306 if ((*args == 'V'
1307 || *args == 'R'
1308 || *args == 'J')
1309 && (mask & 3))
1310 {
1311 break;
1312 } /* register must be multiple of 4 */
1313
1314 #ifndef NO_V9
1315 if (mask >= 64)
1316 {
1317 error_message = ": There are only 64 f registers; [0-63]";
1318 goto error;
1319 } /* on error */
1320 if (mask >= 32)
1321 {
1322 mask -= 31;
1323 } /* wrap high bit */
1324 #else
1325 if (mask >= 32)
1326 {
1327 error_message = ": There are only 32 f registers; [0-31]";
1328 goto error;
1329 } /* on error */
1330 #endif
1331 }
1332 else
1333 {
1334 break;
1335 } /* if not an 'f' register. */
1336
1337 switch (*args)
1338 {
1339
1340 case 'v':
1341 case 'V':
1342 case 'e':
1343 opcode |= RS1 (mask);
1344 continue;
1345
1346
1347 case 'f':
1348 case 'B':
1349 case 'R':
1350 opcode |= RS2 (mask);
1351 continue;
1352
1353 case 'g':
1354 case 'H':
1355 case 'J':
1356 opcode |= RD (mask);
1357 continue;
1358 } /* pack it in. */
1359
1360 know (0);
1361 break;
1362 } /* float arg */
1363
1364 case 'F':
1365 if (strncmp (s, "%fsr", 4) == 0)
1366 {
1367 s += 4;
1368 continue;
1369 }
1370 break;
1371
1372 case 'h': /* high 22 bits */
1373 the_insn.reloc = BFD_RELOC_HI22;
1374 goto immediate;
1375
1376 case 'l': /* 22 bit PC relative immediate */
1377 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1378 the_insn.pcrel = 1;
1379 goto immediate;
1380
1381 case 'L': /* 30 bit immediate */
1382 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1383 the_insn.pcrel = 1;
1384 goto immediate;
1385
1386 case 'n': /* 22 bit immediate */
1387 the_insn.reloc = BFD_RELOC_SPARC22;
1388 goto immediate;
1389
1390 case 'i': /* 13 bit immediate */
1391 the_insn.reloc = BFD_RELOC_SPARC13;
1392 immediate_max = 0x0FFF;
1393
1394 /*FALLTHROUGH */
1395
1396 immediate:
1397 if (*s == ' ')
1398 s++;
1399 if (*s == '%')
1400 {
1401 if ((c = s[1]) == 'h' && s[2] == 'i')
1402 {
1403 the_insn.reloc = BFD_RELOC_HI22;
1404 s += 3;
1405 }
1406 else if (c == 'l' && s[2] == 'o')
1407 {
1408 the_insn.reloc = BFD_RELOC_LO10;
1409 s += 3;
1410 }
1411 #ifndef NO_V9
1412 else if (c == 'u'
1413 && s[2] == 'h'
1414 && s[3] == 'i')
1415 {
1416 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1417 s += 4;
1418 }
1419 else if (c == 'u'
1420 && s[2] == 'l'
1421 && s[3] == 'o')
1422 {
1423 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1424 s += 4;
1425 }
1426 #endif /* NO_V9 */
1427 else
1428 break;
1429 }
1430 /* Note that if the getExpression() fails, we will still
1431 have created U entries in the symbol table for the
1432 'symbols' in the input string. Try not to create U
1433 symbols for registers, etc. */
1434 {
1435 /* This stuff checks to see if the expression ends in
1436 +%reg. If it does, it removes the register from
1437 the expression, and re-sets 's' to point to the
1438 right place. */
1439
1440 char *s1;
1441
1442 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1443
1444 if (s1 != s && isdigit (s1[-1]))
1445 {
1446 if (s1[-2] == '%' && s1[-3] == '+')
1447 {
1448 s1 -= 3;
1449 *s1 = '\0';
1450 (void) getExpression (s);
1451 *s1 = '+';
1452 s = s1;
1453 continue;
1454 }
1455 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1456 {
1457 s1 -= 4;
1458 *s1 = '\0';
1459 (void) getExpression (s);
1460 *s1 = '+';
1461 s = s1;
1462 continue;
1463 }
1464 }
1465 }
1466 (void) getExpression (s);
1467 s = expr_end;
1468
1469 if (the_insn.exp.X_op == O_constant
1470 && the_insn.exp.X_add_symbol == 0
1471 && the_insn.exp.X_op_symbol == 0)
1472 {
1473 #ifndef NO_V9
1474 /* Handle %uhi/%ulo by moving the upper word to the lower
1475 one and pretending it's %hi/%lo. We also need to watch
1476 for %hi/%lo: the top word needs to be zeroed otherwise
1477 fixup_segment will complain the value is too big. */
1478 switch (the_insn.reloc)
1479 {
1480 case BFD_RELOC_SPARC_HH22:
1481 the_insn.reloc = BFD_RELOC_HI22;
1482 the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
1483 break;
1484 case BFD_RELOC_SPARC_HM10:
1485 the_insn.reloc = BFD_RELOC_LO10;
1486 the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
1487 break;
1488 default:
1489 break;
1490 case BFD_RELOC_HI22:
1491 case BFD_RELOC_LO10:
1492 the_insn.exp.X_add_number &= 0xffffffff;
1493 break;
1494 }
1495 #endif
1496 /* For pc-relative call instructions, we reject
1497 constants to get better code. */
1498 if (the_insn.pcrel
1499 && the_insn.reloc == BFD_RELOC_32_PCREL_S2
1500 && in_signed_range (the_insn.exp.X_add_number, 0x3fff)
1501 )
1502 {
1503 error_message = ": PC-relative operand can't be a constant";
1504 goto error;
1505 }
1506 /* Check for invalid constant values. Don't warn if
1507 constant was inside %hi or %lo, since these
1508 truncate the constant to fit. */
1509 if (immediate_max != 0
1510 && the_insn.reloc != BFD_RELOC_LO10
1511 && the_insn.reloc != BFD_RELOC_HI22
1512 && !in_signed_range (the_insn.exp.X_add_number,
1513 immediate_max)
1514 )
1515 {
1516 if (the_insn.pcrel)
1517 /* Who knows? After relocation, we may be within
1518 range. Let the linker figure it out. */
1519 {
1520 the_insn.exp.X_op = O_symbol;
1521 the_insn.exp.X_add_symbol = section_symbol (absolute_section);
1522 }
1523 else
1524 /* Immediate value is non-pcrel, and out of
1525 range. */
1526 as_bad ("constant value %ld out of range (%ld .. %ld)",
1527 the_insn.exp.X_add_number,
1528 ~immediate_max, immediate_max);
1529 }
1530 }
1531
1532 /* Reset to prevent extraneous range check. */
1533 immediate_max = 0;
1534
1535 continue;
1536
1537 case 'a':
1538 if (*s++ == 'a')
1539 {
1540 opcode |= ANNUL;
1541 continue;
1542 }
1543 break;
1544
1545 case 'A':
1546 {
1547 #ifdef NO_V9
1548 char *push = input_line_pointer;
1549 expressionS e;
1550
1551 input_line_pointer = s;
1552
1553 expression (&e);
1554 if (e.X_op == O_constant)
1555 {
1556 opcode |= e.X_add_number << 5;
1557 s = input_line_pointer;
1558 input_line_pointer = push;
1559 continue;
1560 } /* if absolute */
1561
1562 break;
1563 #else
1564 int asi = 0;
1565
1566 /* Parse an asi. */
1567 if (*s == '#')
1568 {
1569 s += 1;
1570 if (!strncmp (s, "ASI_AIUP", 8))
1571 asi = 0x10, s += 8;
1572 else if (!strncmp (s, "ASI_AIUS", 8))
1573 asi = 0x11, s += 8;
1574 else if (!strncmp (s, "ASI_PNF", 7))
1575 asi = 0x82, s += 7;
1576 else if (!strncmp (s, "ASI_SNF", 7))
1577 asi = 0x83, s += 7;
1578 else if (!strncmp (s, "ASI_P", 5))
1579 asi = 0x80, s += 5;
1580 else if (!strncmp (s, "ASI_S", 5))
1581 asi = 0x81, s += 5;
1582 else
1583 {
1584 error_message = ": invalid asi name";
1585 goto error;
1586 }
1587 }
1588 else if (isdigit (*s))
1589 {
1590 char *push = input_line_pointer;
1591 input_line_pointer = s;
1592 asi = get_absolute_expression ();
1593 s = input_line_pointer;
1594 input_line_pointer = push;
1595
1596 if (asi < 0 || asi > 255)
1597 {
1598 error_message = ": invalid asi number";
1599 goto error;
1600 }
1601 }
1602 else
1603 {
1604 error_message = ": unrecognizable asi";
1605 goto error;
1606 }
1607 opcode |= ASI (asi);
1608 continue;
1609 #endif
1610 } /* alternate space */
1611
1612 case 'p':
1613 if (strncmp (s, "%psr", 4) == 0)
1614 {
1615 s += 4;
1616 continue;
1617 }
1618 break;
1619
1620 case 'q': /* floating point queue */
1621 if (strncmp (s, "%fq", 3) == 0)
1622 {
1623 s += 3;
1624 continue;
1625 }
1626 break;
1627
1628 case 'Q': /* coprocessor queue */
1629 if (strncmp (s, "%cq", 3) == 0)
1630 {
1631 s += 3;
1632 continue;
1633 }
1634 break;
1635
1636 case 'S':
1637 if (strcmp (str, "set") == 0)
1638 {
1639 special_case = SPECIAL_CASE_SET;
1640 continue;
1641 }
1642 else if (strncmp (str, "fdiv", 4) == 0)
1643 {
1644 special_case = SPECIAL_CASE_FDIV;
1645 continue;
1646 }
1647 break;
1648
1649 #ifndef NO_V9
1650 case 'o':
1651 if (strncmp (s, "%asi", 4) != 0)
1652 break;
1653 s += 4;
1654 continue;
1655
1656 case 's':
1657 if (strncmp (s, "%fprs", 5) != 0)
1658 break;
1659 s += 5;
1660 continue;
1661
1662 case 'E':
1663 if (strncmp (s, "%ccr", 4) != 0)
1664 break;
1665 s += 4;
1666 continue;
1667 #endif /* NO_V9 */
1668
1669 case 't':
1670 if (strncmp (s, "%tbr", 4) != 0)
1671 break;
1672 s += 4;
1673 continue;
1674
1675 case 'w':
1676 if (strncmp (s, "%wim", 4) != 0)
1677 break;
1678 s += 4;
1679 continue;
1680
1681 #ifndef NO_V9
1682 case 'x':
1683 {
1684 char *push = input_line_pointer;
1685 expressionS e;
1686
1687 input_line_pointer = s;
1688 expression (&e);
1689 if (e.X_op == O_constant)
1690 {
1691 int n = e.X_add_number;
1692 if (n != e.X_add_number || (n & ~0x1ff) != 0)
1693 as_bad ("OPF immediate operand out of range (0-0x1ff)");
1694 else
1695 opcode |= e.X_add_number << 5;
1696 }
1697 else
1698 as_bad ("non-immediate OPF operand, ignored");
1699 s = input_line_pointer;
1700 input_line_pointer = push;
1701 continue;
1702 }
1703 #endif
1704
1705 case 'y':
1706 if (strncmp (s, "%y", 2) != 0)
1707 break;
1708 s += 2;
1709 continue;
1710
1711 default:
1712 as_fatal ("failed sanity check.");
1713 } /* switch on arg code */
1714 break;
1715 } /* for each arg that we expect */
1716 error:
1717 if (match == 0)
1718 {
1719 /* Args don't match. */
1720 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1721 && !strcmp (insn->name, insn[1].name))
1722 {
1723 ++insn;
1724 s = argsStart;
1725 continue;
1726 }
1727 else
1728 {
1729 as_bad ("Illegal operands%s", error_message);
1730 return;
1731 }
1732 }
1733 else
1734 {
1735 if (insn->architecture > current_architecture
1736 || (insn->architecture != current_architecture
1737 && current_architecture > v8))
1738 {
1739 if ((!architecture_requested || warn_on_bump)
1740 && !ARCHITECTURES_CONFLICT_P (current_architecture,
1741 insn->architecture)
1742 && !ARCHITECTURES_CONFLICT_P (insn->architecture,
1743 current_architecture))
1744 {
1745 if (warn_on_bump)
1746 {
1747 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1748 architecture_pname[current_architecture],
1749 architecture_pname[insn->architecture],
1750 str);
1751 } /* if warning */
1752
1753 current_architecture = insn->architecture;
1754 }
1755 else
1756 {
1757 as_bad ("Architecture mismatch on \"%s\".", str);
1758 as_tsktsk (" (Requires %s; current architecture is %s.)",
1759 architecture_pname[insn->architecture],
1760 architecture_pname[current_architecture]);
1761 return;
1762 } /* if bump ok else error */
1763 } /* if architecture higher */
1764 } /* if no match */
1765
1766 break;
1767 } /* forever looking for a match */
1768
1769 the_insn.opcode = opcode;
1770 }
1771
1772 static int
1773 getExpression (str)
1774 char *str;
1775 {
1776 char *save_in;
1777 segT seg;
1778
1779 save_in = input_line_pointer;
1780 input_line_pointer = str;
1781 seg = expression (&the_insn.exp);
1782 if (seg != absolute_section
1783 && seg != text_section
1784 && seg != data_section
1785 && seg != bss_section
1786 && seg != undefined_section)
1787 {
1788 the_insn.error = "bad segment";
1789 expr_end = input_line_pointer;
1790 input_line_pointer = save_in;
1791 return 1;
1792 }
1793 expr_end = input_line_pointer;
1794 input_line_pointer = save_in;
1795 return 0;
1796 } /* getExpression() */
1797
1798
1799 /*
1800 This is identical to the md_atof in m68k.c. I think this is right,
1801 but I'm not sure.
1802
1803 Turn a string in input_line_pointer into a floating point constant of type
1804 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1805 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1806 */
1807
1808 /* Equal to MAX_PRECISION in atof-ieee.c */
1809 #define MAX_LITTLENUMS 6
1810
1811 char *
1812 md_atof (type, litP, sizeP)
1813 char type;
1814 char *litP;
1815 int *sizeP;
1816 {
1817 int prec;
1818 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1819 LITTLENUM_TYPE *wordP;
1820 char *t;
1821 char *atof_ieee ();
1822
1823 switch (type)
1824 {
1825
1826 case 'f':
1827 case 'F':
1828 case 's':
1829 case 'S':
1830 prec = 2;
1831 break;
1832
1833 case 'd':
1834 case 'D':
1835 case 'r':
1836 case 'R':
1837 prec = 4;
1838 break;
1839
1840 case 'x':
1841 case 'X':
1842 prec = 6;
1843 break;
1844
1845 case 'p':
1846 case 'P':
1847 prec = 6;
1848 break;
1849
1850 default:
1851 *sizeP = 0;
1852 return "Bad call to MD_ATOF()";
1853 }
1854 t = atof_ieee (input_line_pointer, type, words);
1855 if (t)
1856 input_line_pointer = t;
1857 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1858 for (wordP = words; prec--;)
1859 {
1860 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1861 litP += sizeof (LITTLENUM_TYPE);
1862 }
1863 return 0;
1864 }
1865
1866 /*
1867 * Write out big-endian.
1868 */
1869 void
1870 md_number_to_chars (buf, val, n)
1871 char *buf;
1872 valueT val;
1873 int n;
1874 {
1875 number_to_chars_bigendian (buf, val, n);
1876 }
1877
1878 /* Apply a fixS to the frags, now that we know the value it ought to
1879 hold. */
1880
1881 int
1882 md_apply_fix (fixP, value)
1883 fixS *fixP;
1884 valueT *value;
1885 {
1886 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1887 offsetT val;
1888
1889 val = *value;
1890
1891 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1892
1893 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1894
1895 #ifdef OBJ_ELF
1896 /* FIXME: SPARC ELF relocations don't use an addend in the data
1897 field itself. This whole approach should be somehow combined
1898 with the calls to bfd_perform_relocation. */
1899 if (fixP->fx_addsy != NULL)
1900 return 1;
1901 #endif
1902
1903 /* This is a hack. There should be a better way to
1904 handle this. Probably in terms of howto fields, once
1905 we can look at these fixups in terms of howtos. */
1906 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1907 val += fixP->fx_where + fixP->fx_frag->fr_address;
1908
1909 #ifdef OBJ_AOUT
1910 /* FIXME: More ridiculous gas reloc hacking. If we are going to
1911 generate a reloc, then we just want to let the reloc addend set
1912 the value. We do not want to also stuff the addend into the
1913 object file. Including the addend in the object file works when
1914 doing a static link, because the linker will ignore the object
1915 file contents. However, the dynamic linker does not ignore the
1916 object file contents. */
1917 if (fixP->fx_addsy != NULL
1918 && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
1919 val = 0;
1920 #endif
1921
1922 switch (fixP->fx_r_type)
1923 {
1924 case BFD_RELOC_16:
1925 buf[0] = val >> 8;
1926 buf[1] = val;
1927 break;
1928
1929 case BFD_RELOC_32:
1930 buf[0] = val >> 24;
1931 buf[1] = val >> 16;
1932 buf[2] = val >> 8;
1933 buf[3] = val;
1934 break;
1935
1936 case BFD_RELOC_32_PCREL_S2:
1937 val = (val >>= 2) + 1;
1938 buf[0] |= (val >> 24) & 0x3f;
1939 buf[1] = (val >> 16);
1940 buf[2] = val >> 8;
1941 buf[3] = val;
1942 break;
1943
1944 #ifndef NO_V9
1945 case BFD_RELOC_64:
1946 {
1947 bfd_vma valh = BSR (val, 32);
1948 buf[0] = valh >> 24;
1949 buf[1] = valh >> 16;
1950 buf[2] = valh >> 8;
1951 buf[3] = valh;
1952 buf[4] = val >> 24;
1953 buf[5] = val >> 16;
1954 buf[6] = val >> 8;
1955 buf[7] = val;
1956 }
1957 break;
1958
1959 case BFD_RELOC_SPARC_11:
1960 if (((val > 0) && (val & ~0x7ff))
1961 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1962 {
1963 as_bad ("relocation overflow.");
1964 } /* on overflow */
1965
1966 buf[2] |= (val >> 8) & 0x7;
1967 buf[3] = val & 0xff;
1968 break;
1969
1970 case BFD_RELOC_SPARC_10:
1971 if (((val > 0) && (val & ~0x3ff))
1972 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1973 {
1974 as_bad ("relocation overflow.");
1975 } /* on overflow */
1976
1977 buf[2] |= (val >> 8) & 0x3;
1978 buf[3] = val & 0xff;
1979 break;
1980
1981 case BFD_RELOC_SPARC_WDISP16:
1982 if (((val > 0) && (val & ~0x3fffc))
1983 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1984 {
1985 as_bad ("relocation overflow.");
1986 } /* on overflow */
1987
1988 val = (val >>= 2) + 1;
1989 buf[1] |= ((val >> 14) & 0x3) << 4;
1990 buf[2] |= (val >> 8) & 0x3f;
1991 buf[3] = val & 0xff;
1992 break;
1993
1994 case BFD_RELOC_SPARC_WDISP19:
1995 if (((val > 0) && (val & ~0x1ffffc))
1996 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1997 {
1998 as_bad ("relocation overflow.");
1999 } /* on overflow */
2000
2001 val = (val >>= 2) + 1;
2002 buf[1] |= (val >> 16) & 0x7;
2003 buf[2] = (val >> 8) & 0xff;
2004 buf[3] = val & 0xff;
2005 break;
2006
2007 case BFD_RELOC_SPARC_HH22:
2008 val = BSR (val, 32);
2009 /* intentional fallthrough */
2010 #endif /* NO_V9 */
2011
2012 #ifndef NO_V9
2013 case BFD_RELOC_SPARC_LM22:
2014 #endif
2015 case BFD_RELOC_HI22:
2016 if (!fixP->fx_addsy)
2017 {
2018 buf[1] |= (val >> 26) & 0x3f;
2019 buf[2] = val >> 18;
2020 buf[3] = val >> 10;
2021 }
2022 else
2023 {
2024 buf[2] = 0;
2025 buf[3] = 0;
2026 }
2027 break;
2028
2029 case BFD_RELOC_SPARC22:
2030 if (val & ~0x003fffff)
2031 {
2032 as_bad ("relocation overflow");
2033 } /* on overflow */
2034 buf[1] |= (val >> 16) & 0x3f;
2035 buf[2] = val >> 8;
2036 buf[3] = val & 0xff;
2037 break;
2038
2039 #ifndef NO_V9
2040 case BFD_RELOC_SPARC_HM10:
2041 val = BSR (val, 32);
2042 /* intentional fallthrough */
2043 #endif /* NO_V9 */
2044
2045 case BFD_RELOC_LO10:
2046 if (!fixP->fx_addsy)
2047 {
2048 buf[2] |= (val >> 8) & 0x03;
2049 buf[3] = val;
2050 }
2051 else
2052 buf[3] = 0;
2053 break;
2054
2055 case BFD_RELOC_SPARC13:
2056 if (! in_signed_range (val, 0x1fff))
2057 as_bad ("relocation overflow");
2058
2059 buf[2] |= (val >> 8) & 0x1f;
2060 buf[3] = val;
2061 break;
2062
2063 case BFD_RELOC_SPARC_WDISP22:
2064 val = (val >> 2) + 1;
2065 /* FALLTHROUGH */
2066 case BFD_RELOC_SPARC_BASE22:
2067 buf[1] |= (val >> 16) & 0x3f;
2068 buf[2] = val >> 8;
2069 buf[3] = val;
2070 break;
2071
2072 case BFD_RELOC_NONE:
2073 default:
2074 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2075 break;
2076 }
2077
2078 /* Are we finished with this relocation now? */
2079 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
2080 fixP->fx_done = 1;
2081
2082 return 1;
2083 }
2084
2085 /* Translate internal representation of relocation info to BFD target
2086 format. */
2087 arelent *
2088 tc_gen_reloc (section, fixp)
2089 asection *section;
2090 fixS *fixp;
2091 {
2092 arelent *reloc;
2093 bfd_reloc_code_real_type code;
2094
2095 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2096 assert (reloc != 0);
2097
2098 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2099 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2100
2101 switch (fixp->fx_r_type)
2102 {
2103 case BFD_RELOC_16:
2104 case BFD_RELOC_32:
2105 case BFD_RELOC_HI22:
2106 case BFD_RELOC_LO10:
2107 case BFD_RELOC_32_PCREL_S2:
2108 case BFD_RELOC_SPARC13:
2109 case BFD_RELOC_SPARC_BASE13:
2110 case BFD_RELOC_SPARC_WDISP22:
2111 case BFD_RELOC_64:
2112 case BFD_RELOC_SPARC_10:
2113 case BFD_RELOC_SPARC_11:
2114 case BFD_RELOC_SPARC_HH22:
2115 case BFD_RELOC_SPARC_HM10:
2116 case BFD_RELOC_SPARC_LM22:
2117 case BFD_RELOC_SPARC_PC_HH22:
2118 case BFD_RELOC_SPARC_PC_HM10:
2119 case BFD_RELOC_SPARC_PC_LM22:
2120 code = fixp->fx_r_type;
2121 break;
2122 default:
2123 abort ();
2124 }
2125 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2126 if (reloc->howto == 0)
2127 {
2128 as_bad_where (fixp->fx_file, fixp->fx_line,
2129 "internal error: can't export reloc type %d (`%s')",
2130 fixp->fx_r_type, bfd_get_reloc_code_name (code));
2131 return 0;
2132 }
2133 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
2134
2135 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2136 if (reloc->howto->pc_relative == 0)
2137 reloc->addend = fixp->fx_addnumber;
2138 #if defined (OBJ_ELF) || defined (OBJ_COFF)
2139 else if ((fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
2140 reloc->addend = (section->vma
2141 + fixp->fx_addnumber
2142 + md_pcrel_from (fixp));
2143 #endif
2144 else
2145 reloc->addend = fixp->fx_offset - reloc->address;
2146
2147 return reloc;
2148 }
2149
2150
2151 #if 0
2152 /* for debugging only */
2153 static void
2154 print_insn (insn)
2155 struct sparc_it *insn;
2156 {
2157 const char *const Reloc[] = {
2158 "RELOC_8",
2159 "RELOC_16",
2160 "RELOC_32",
2161 "RELOC_DISP8",
2162 "RELOC_DISP16",
2163 "RELOC_DISP32",
2164 "RELOC_WDISP30",
2165 "RELOC_WDISP22",
2166 "RELOC_HI22",
2167 "RELOC_22",
2168 "RELOC_13",
2169 "RELOC_LO10",
2170 "RELOC_SFA_BASE",
2171 "RELOC_SFA_OFF13",
2172 "RELOC_BASE10",
2173 "RELOC_BASE13",
2174 "RELOC_BASE22",
2175 "RELOC_PC10",
2176 "RELOC_PC22",
2177 "RELOC_JMP_TBL",
2178 "RELOC_SEGOFF16",
2179 "RELOC_GLOB_DAT",
2180 "RELOC_JMP_SLOT",
2181 "RELOC_RELATIVE",
2182 "NO_RELOC"
2183 };
2184
2185 if (insn->error)
2186 fprintf (stderr, "ERROR: %s\n");
2187 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2188 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2189 fprintf (stderr, "exp = {\n");
2190 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2191 ((insn->exp.X_add_symbol != NULL)
2192 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2193 ? S_GET_NAME (insn->exp.X_add_symbol)
2194 : "???")
2195 : "0"));
2196 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2197 ((insn->exp.X_op_symbol != NULL)
2198 ? (S_GET_NAME (insn->exp.X_op_symbol)
2199 ? S_GET_NAME (insn->exp.X_op_symbol)
2200 : "???")
2201 : "0"));
2202 fprintf (stderr, "\t\tX_add_number = %d\n",
2203 insn->exp.X_add_number);
2204 fprintf (stderr, "}\n");
2205 }
2206 #endif
2207 \f
2208 /*
2209 * md_parse_option
2210 * Invocation line includes a switch not recognized by the base assembler.
2211 * See if it's a processor-specific option. These are:
2212 *
2213 * -bump
2214 * Warn on architecture bumps. See also -A.
2215 *
2216 * -Av6, -Av7, -Av8, -Av9, -Asparclite
2217 * Select the architecture. Instructions or features not
2218 * supported by the selected architecture cause fatal errors.
2219 *
2220 * The default is to start at v6, and bump the architecture up
2221 * whenever an instruction is seen at a higher level.
2222 *
2223 * If -bump is specified, a warning is printing when bumping to
2224 * higher levels.
2225 *
2226 * If an architecture is specified, all instructions must match
2227 * that architecture. Any higher level instructions are flagged
2228 * as errors.
2229 *
2230 * if both an architecture and -bump are specified, the
2231 * architecture starts at the specified level, but bumps are
2232 * warnings.
2233 *
2234 * Note:
2235 * Bumping between incompatible architectures is always an
2236 * error. For example, from sparclite to v9.
2237 */
2238
2239 #ifdef OBJ_ELF
2240 CONST char *md_shortopts = "A:VQ:sq";
2241 #else
2242 CONST char *md_shortopts = "A:";
2243 #endif
2244 struct option md_longopts[] = {
2245 #define OPTION_BUMP (OPTION_MD_BASE)
2246 {"bump", no_argument, NULL, OPTION_BUMP},
2247 #define OPTION_SPARC (OPTION_MD_BASE + 1)
2248 {"sparc", no_argument, NULL, OPTION_SPARC},
2249 {NULL, no_argument, NULL, 0}
2250 };
2251 size_t md_longopts_size = sizeof(md_longopts);
2252
2253 int
2254 md_parse_option (c, arg)
2255 int c;
2256 char *arg;
2257 {
2258 switch (c)
2259 {
2260 case OPTION_BUMP:
2261 warn_on_bump = 1;
2262 break;
2263
2264 case 'A':
2265 {
2266 char *p = arg;
2267 const char **arch;
2268
2269 for (arch = architecture_pname; *arch != NULL; ++arch)
2270 {
2271 if (strcmp (p, *arch) == 0)
2272 break;
2273 }
2274
2275 if (*arch == NULL)
2276 {
2277 as_bad ("invalid architecture -A%s", p);
2278 return 0;
2279 }
2280 else
2281 {
2282 enum sparc_architecture new_arch = arch - architecture_pname;
2283 #ifdef NO_V9
2284 if (new_arch == v9)
2285 {
2286 as_error ("v9 support not compiled in");
2287 return 0;
2288 }
2289 #endif
2290 current_architecture = new_arch;
2291 architecture_requested = 1;
2292 }
2293 }
2294 break;
2295
2296 case OPTION_SPARC:
2297 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2298 break;
2299
2300 #ifdef OBJ_ELF
2301 case 'V':
2302 print_version_id ();
2303 break;
2304
2305 case 'Q':
2306 /* Qy - do emit .comment
2307 Qn - do not emit .comment */
2308 break;
2309
2310 case 's':
2311 /* use .stab instead of .stab.excl */
2312 break;
2313
2314 case 'q':
2315 /* quick -- native assembler does fewer checks */
2316 break;
2317 #endif
2318
2319 default:
2320 return 0;
2321 }
2322
2323 return 1;
2324 }
2325
2326 void
2327 md_show_usage (stream)
2328 FILE *stream;
2329 {
2330 const char **arch;
2331 fprintf(stream, "SPARC options:\n");
2332 for (arch = architecture_pname; *arch; arch++)
2333 {
2334 if (arch != architecture_pname)
2335 fprintf (stream, " | ");
2336 fprintf (stream, "-A%s", *arch);
2337 }
2338 fprintf (stream, "\n\
2339 specify variant of SPARC architecture\n\
2340 -bump warn when assembler switches architectures\n\
2341 -sparc ignored\n");
2342 #ifdef OBJ_ELF
2343 fprintf(stream, "\
2344 -V print assembler version number\n\
2345 -q ignored\n\
2346 -Qy, -Qn ignored\n\
2347 -s ignored\n");
2348 #endif
2349 }
2350 \f
2351 /* We have no need to default values of symbols. */
2352
2353 /* ARGSUSED */
2354 symbolS *
2355 md_undefined_symbol (name)
2356 char *name;
2357 {
2358 return 0;
2359 } /* md_undefined_symbol() */
2360
2361 /* Parse an operand that is machine-specific.
2362 We just return without modifying the expression if we have nothing
2363 to do. */
2364
2365 /* ARGSUSED */
2366 void
2367 md_operand (expressionP)
2368 expressionS *expressionP;
2369 {
2370 }
2371
2372 /* Round up a section size to the appropriate boundary. */
2373 valueT
2374 md_section_align (segment, size)
2375 segT segment;
2376 valueT size;
2377 {
2378 #ifndef OBJ_ELF
2379 /* This is not right for ELF; a.out wants it, and COFF will force
2380 the alignment anyways. */
2381 valueT align = (valueT) 1 << (valueT) (stdoutput->xvec->align_power_min);
2382 valueT newsize;
2383 /* turn alignment value into a mask */
2384 align--;
2385 newsize = (size + align) & ~align;
2386 return newsize;
2387 #else
2388 return size;
2389 #endif
2390 }
2391
2392 /* Exactly what point is a PC-relative offset relative TO?
2393 On the sparc, they're relative to the address of the offset, plus
2394 its size. This gets us to the following instruction.
2395 (??? Is this right? FIXME-SOON) */
2396 long
2397 md_pcrel_from (fixP)
2398 fixS *fixP;
2399 {
2400 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2401 }
2402
2403 /* end of tc-sparc.c */
This page took 0.082445 seconds and 4 git commands to generate.