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