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