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