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