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