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