1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 90-95, 1996 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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)
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.
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. */
26 /* careful, this file includes data *declarations* */
27 #include "opcode/sparc.h"
29 static void sparc_ip
PARAMS ((char *, const struct sparc_opcode
**));
31 /* Current architecture. We don't bump up unless necessary. */
32 static enum sparc_opcode_arch_val current_architecture
= SPARC_OPCODE_ARCH_V6
;
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. */
40 static enum sparc_opcode_arch_val max_architecture
= SPARC_OPCODE_ARCH_V9
;
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
;
48 static int architecture_requested
;
49 static int warn_on_bump
;
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
;
55 /* Non-zero if we are generating PIC code. */
58 extern int target_big_endian
;
60 /* handle of the OPCODE hash table */
61 static struct hash_control
*op_hash
;
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));
69 const pseudo_typeS md_pseudo_table
[] =
71 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
72 {"common", s_common
, 0},
73 {"global", s_globl
, 0},
75 {"optim", s_ignore
, 0},
77 {"reserve", s_reserve
, 0},
86 /* these are specific to sparc/svr4 */
87 {"pushsection", obj_elf_section
, 0},
88 {"popsection", obj_elf_previous
, 0},
95 const int md_reloc_size
= 12; /* Size of relocation record */
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 */
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
[] = "#";
111 const char line_separator_chars
[] = "";
113 /* Chars that can be used to separate mant from exp in floating point nums */
114 const char EXP_CHARS
[] = "eE";
116 /* Chars that mean this number is a floating point constant */
119 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
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. */
125 static unsigned char octal
[256];
126 #define isoctal(c) octal[(unsigned char) (c)]
127 static unsigned char toHex
[256];
132 unsigned long opcode
;
133 struct nlist
*nlistp
;
136 bfd_reloc_code_real_type reloc
;
139 struct sparc_it the_insn
, set_insn
;
142 in_signed_range (val
, max
)
143 bfd_signed_vma val
, max
;
163 for (i
= 0; (mask
& 1) == 0; ++i
)
169 static void print_insn
PARAMS ((struct sparc_it
*insn
));
171 static int getExpression
PARAMS ((char *str
));
173 static char *expr_end
;
174 static int special_case
;
177 * Instructions that require wierd handling because they're longer than
180 #define SPECIAL_CASE_SET 1
181 #define SPECIAL_CASE_FDIV 2
183 /* The last instruction to be assembled. */
184 static const struct sparc_opcode
*last_insn
;
187 * sort of like s_lcomm
191 static int max_alignment
= 15;
206 name
= input_line_pointer
;
207 c
= get_symbol_end ();
208 p
= input_line_pointer
;
212 if (*input_line_pointer
!= ',')
214 as_bad ("Expected comma after name");
215 ignore_rest_of_line ();
219 ++input_line_pointer
;
221 if ((size
= get_absolute_expression ()) < 0)
223 as_bad ("BSS length (%d.) <0! Ignored.", size
);
224 ignore_rest_of_line ();
229 symbolP
= symbol_find_or_make (name
);
232 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
233 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
235 as_bad ("bad .reserve segment -- expected BSS segment");
239 if (input_line_pointer
[2] == '.')
240 input_line_pointer
+= 7;
242 input_line_pointer
+= 6;
245 if (*input_line_pointer
== ',')
247 ++input_line_pointer
;
250 if (*input_line_pointer
== '\n')
252 as_bad ("Missing alignment");
256 align
= get_absolute_expression ();
258 if (align
> max_alignment
)
260 align
= max_alignment
;
261 as_warn ("Alignment too large: %d. assumed.", align
);
267 as_warn ("Alignment negative. 0 assumed.");
270 record_alignment (bss_section
, align
);
272 /* convert to a power of 2 alignment */
273 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
277 as_bad ("Alignment not a power of 2");
278 ignore_rest_of_line ();
280 } /* not a power of two */
283 } /* if has optional alignment */
287 if (!S_IS_DEFINED (symbolP
)
289 && S_GET_OTHER (symbolP
) == 0
290 && S_GET_DESC (symbolP
) == 0
297 segT current_seg
= now_seg
;
298 subsegT current_subseg
= now_subseg
;
300 subseg_set (bss_section
, 1); /* switch to bss */
303 frag_align (align
, 0); /* do alignment */
305 /* detach from old frag */
306 if (S_GET_SEGMENT(symbolP
) == bss_section
)
307 symbolP
->sy_frag
->fr_symbol
= NULL
;
309 symbolP
->sy_frag
= frag_now
;
310 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
314 S_SET_SEGMENT (symbolP
, bss_section
);
316 subseg_set (current_seg
, current_subseg
);
321 as_warn("Ignoring attempt to re-define symbol %s",
322 S_GET_NAME (symbolP
));
323 } /* if not redefining */
325 demand_empty_rest_of_line ();
338 name
= input_line_pointer
;
339 c
= get_symbol_end ();
340 /* just after name is now '\0' */
341 p
= input_line_pointer
;
344 if (*input_line_pointer
!= ',')
346 as_bad ("Expected comma after symbol-name");
347 ignore_rest_of_line ();
350 input_line_pointer
++; /* skip ',' */
351 if ((temp
= get_absolute_expression ()) < 0)
353 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
354 ignore_rest_of_line ();
359 symbolP
= symbol_find_or_make (name
);
361 if (S_IS_DEFINED (symbolP
))
363 as_bad ("Ignoring attempt to re-define symbol");
364 ignore_rest_of_line ();
367 if (S_GET_VALUE (symbolP
) != 0)
369 if (S_GET_VALUE (symbolP
) != size
)
371 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
372 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
378 S_SET_VALUE (symbolP
, (valueT
) size
);
379 S_SET_EXTERNAL (symbolP
);
382 know (symbolP
->sy_frag
== &zero_address_frag
);
383 if (*input_line_pointer
!= ',')
385 as_bad ("Expected comma after common length");
386 ignore_rest_of_line ();
389 input_line_pointer
++;
391 if (*input_line_pointer
!= '"')
393 temp
= get_absolute_expression ();
395 if (temp
> max_alignment
)
397 temp
= max_alignment
;
398 as_warn ("Common alignment too large: %d. assumed", temp
);
404 as_warn ("Common alignment negative; 0 assumed");
416 old_subsec
= now_subseg
;
418 record_alignment (bss_section
, align
);
419 subseg_set (bss_section
, 0);
421 frag_align (align
, 0);
422 if (S_GET_SEGMENT (symbolP
) == bss_section
)
423 symbolP
->sy_frag
->fr_symbol
= 0;
424 symbolP
->sy_frag
= frag_now
;
425 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
428 S_SET_SEGMENT (symbolP
, bss_section
);
429 S_CLEAR_EXTERNAL (symbolP
);
430 subseg_set (old_sec
, old_subsec
);
436 S_SET_VALUE (symbolP
, (valueT
) size
);
438 S_SET_ALIGN (symbolP
, temp
);
440 S_SET_EXTERNAL (symbolP
);
441 /* should be common, but this is how gas does it for now */
442 S_SET_SEGMENT (symbolP
, bfd_und_section_ptr
);
447 input_line_pointer
++;
448 /* @@ Some use the dot, some don't. Can we get some consistency?? */
449 if (*input_line_pointer
== '.')
450 input_line_pointer
++;
451 /* @@ Some say data, some say bss. */
452 if (strncmp (input_line_pointer
, "bss\"", 4)
453 && strncmp (input_line_pointer
, "data\"", 5))
455 while (*--input_line_pointer
!= '"')
457 input_line_pointer
--;
458 goto bad_common_segment
;
460 while (*input_line_pointer
++ != '"')
462 goto allocate_common
;
464 demand_empty_rest_of_line ();
469 p
= input_line_pointer
;
470 while (*p
&& *p
!= '\n')
474 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
476 input_line_pointer
= p
;
477 ignore_rest_of_line ();
487 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
489 input_line_pointer
+= 6;
493 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
495 input_line_pointer
+= 6;
499 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
501 input_line_pointer
+= 7;
505 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
507 input_line_pointer
+= 5;
508 /* We only support 2 segments -- text and data -- for now, so
509 things in the "bss segment" will have to go into data for now.
510 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
511 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
514 as_bad ("Unknown segment type");
515 demand_empty_rest_of_line ();
521 subseg_set (data_section
, 1);
522 demand_empty_rest_of_line ();
529 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
531 ++input_line_pointer
;
533 ++input_line_pointer
;
536 /* sparc64 priviledged registers */
538 struct priv_reg_entry
544 struct priv_reg_entry priv_reg_table
[] =
563 {"", -1}, /* end marker */
568 struct priv_reg_entry
*p
, *q
;
570 return strcmp (q
->name
, p
->name
);
573 /* This function is called once, at assembler startup time. It should
574 set up all the tables, etc. that the MD part of the assembler will need. */
579 register const char *retval
= NULL
;
581 register unsigned int i
= 0;
583 op_hash
= hash_new ();
585 while (i
< sparc_num_opcodes
)
587 const char *name
= sparc_opcodes
[i
].name
;
588 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
591 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
592 sparc_opcodes
[i
].name
, retval
);
597 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
599 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
600 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
605 while (i
< sparc_num_opcodes
606 && !strcmp (sparc_opcodes
[i
].name
, name
));
610 as_fatal ("Broken assembler. No assembly attempted.");
612 for (i
= '0'; i
< '8'; ++i
)
614 for (i
= '0'; i
<= '9'; ++i
)
616 for (i
= 'a'; i
<= 'f'; ++i
)
617 toHex
[i
] = i
+ 10 - 'a';
618 for (i
= 'A'; i
<= 'F'; ++i
)
619 toHex
[i
] = i
+ 10 - 'A';
621 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
622 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
624 target_big_endian
= 1;
626 /* If -bump, record the architecture level at which we start issuing
627 warnings. The behaviour is different depending upon whether an
628 architecture was explicitly specified. If it wasn't, we issue warnings
629 for all upwards bumps. If it was, we don't start issuing warnings until
630 we need to bump beyond the requested architecture or when we bump between
631 conflicting architectures. */
634 && architecture_requested
)
636 /* `max_architecture' records the requested architecture.
637 Issue warnings if we go above it. */
638 warn_after_architecture
= max_architecture
;
640 /* Find the highest architecture level that doesn't conflict with
641 the requested one. */
642 for (max_architecture
= SPARC_OPCODE_ARCH_MAX
;
643 max_architecture
> warn_after_architecture
;
645 if (! SPARC_OPCODE_CONFLICT_P (max_architecture
,
646 warn_after_architecture
))
651 /* Called after all assembly has been done. */
657 if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
658 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9a
);
660 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9
);
662 if (current_architecture
== SPARC_OPCODE_ARCH_V9
)
663 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v8plus
);
664 else if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
665 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v8plusa
);
666 else if (current_architecture
== SPARC_OPCODE_ARCH_SPARCLET
)
667 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_sparclet
);
670 /* The sparclite is treated like a normal sparc. Perhaps it shouldn't
671 be but for now it is (since that's the way it's always been
673 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc
);
682 const struct sparc_opcode
*insn
;
687 sparc_ip (str
, &insn
);
689 /* We warn about attempts to put a floating point branch in a delay
693 && (insn
->flags
& F_FBR
) != 0
694 && (last_insn
->flags
& F_DELAYED
) != 0)
695 as_warn ("FP branch in delay slot");
697 /* SPARC before v9 requires a nop instruction between a floating
698 point instruction and a floating point branch. We insert one
699 automatically, with a warning. */
700 if (max_architecture
< SPARC_OPCODE_ARCH_V9
703 && (insn
->flags
& F_FBR
) != 0
704 && (last_insn
->flags
& F_FLOAT
) != 0)
706 as_warn ("FP branch preceded by FP instruction; NOP inserted");
708 md_number_to_chars (toP
, (valueT
) 0x01000000, 4);
711 /* See if "set" operand is absolute and small; skip sethi if so. */
712 if (special_case
== SPECIAL_CASE_SET
713 && the_insn
.exp
.X_op
== O_constant
)
715 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
716 && the_insn
.exp
.X_add_number
< (1 << 12))
718 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
719 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
720 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
721 special_case
= 0; /* No longer special */
722 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
727 /* put out the opcode */
728 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
730 /* put out the symbol-dependent stuff */
731 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
733 fix_new_exp (frag_now
, /* which frag */
734 (toP
- frag_now
->fr_literal
), /* where */
743 switch (special_case
)
745 case SPECIAL_CASE_SET
:
747 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
748 /* See if "set" operand has no low-order bits; skip OR if so. */
749 if (the_insn
.exp
.X_op
== O_constant
750 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
753 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
754 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
755 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
756 fix_new_exp (frag_now
, /* which frag */
757 (toP
- frag_now
->fr_literal
), /* where */
764 case SPECIAL_CASE_FDIV
:
765 /* According to information leaked from Sun, the "fdiv" instructions
766 on early SPARC machines would produce incorrect results sometimes.
767 The workaround is to add an fmovs of the destination register to
768 itself just after the instruction. This was true on machines
769 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
771 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
773 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
774 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
775 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
782 as_fatal ("failed sanity check.");
786 /* Implement big shift right. */
792 if (sizeof (bfd_vma
) <= 4 && amount
>= 32)
793 as_fatal ("Support for 64-bit arithmetic not compiled in.");
794 return val
>> amount
;
797 /* Parse an argument that can be expressed as a keyword.
798 (eg: #StoreStore or %ccfr).
799 The result is a boolean indicating success.
800 If successful, INPUT_POINTER is updated. */
803 parse_keyword_arg (lookup_fn
, input_pointerP
, valueP
)
805 char **input_pointerP
;
812 for (q
= p
+ (*p
== '#' || *p
== '%'); isalpha (*q
) || *q
== '_'; ++q
)
816 value
= (*lookup_fn
) (p
);
825 /* Parse an argument that is a constant expression.
826 The result is a boolean indicating success. */
829 parse_const_expr_arg (input_pointerP
, valueP
)
830 char **input_pointerP
;
833 char *save
= input_line_pointer
;
836 input_line_pointer
= *input_pointerP
;
837 /* The next expression may be something other than a constant
838 (say if we're not processing the right variant of the insn).
839 Don't call expression unless we're sure it will succeed as it will
840 signal an error (which we want to defer until later). */
841 /* FIXME: It might be better to define md_operand and have it recognize
842 things like %asi, etc. but continuing that route through to the end
844 if (*input_line_pointer
== '%')
846 input_line_pointer
= save
;
850 *input_pointerP
= input_line_pointer
;
851 input_line_pointer
= save
;
852 if (exp
.X_op
!= O_constant
)
854 *valueP
= exp
.X_add_number
;
859 sparc_ip (str
, pinsn
)
861 const struct sparc_opcode
**pinsn
;
863 char *error_message
= "";
867 const struct sparc_opcode
*insn
;
869 unsigned long opcode
;
870 unsigned int mask
= 0;
873 long immediate_max
= 0;
876 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
894 as_fatal ("Unknown opcode: `%s'", str
);
896 insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
);
900 as_bad ("Unknown opcode: `%s'", str
);
911 opcode
= insn
->match
;
912 memset (&the_insn
, '\0', sizeof (the_insn
));
913 the_insn
.reloc
= BFD_RELOC_NONE
;
917 * Build the opcode, checking as we go to make
918 * sure that the operands match
920 for (args
= insn
->args
;; ++args
)
928 /* Parse a series of masks. */
935 if (! parse_keyword_arg (sparc_encode_membar
, &s
,
938 error_message
= ": invalid membar mask name";
942 while (*s
== ' ') { ++s
; continue; }
943 if (*s
== '|' || *s
== '+')
945 while (*s
== ' ') { ++s
; continue; }
950 if (! parse_const_expr_arg (&s
, &kmask
))
952 error_message
= ": invalid membar mask expression";
955 if (kmask
< 0 || kmask
> 127)
957 error_message
= ": invalid membar mask number";
962 opcode
|= MEMBAR (kmask
);
970 /* Parse a prefetch function. */
973 if (! parse_keyword_arg (sparc_encode_prefetch
, &s
, &fcn
))
975 error_message
= ": invalid prefetch function name";
981 if (! parse_const_expr_arg (&s
, &fcn
))
983 error_message
= ": invalid prefetch function expression";
986 if (fcn
< 0 || fcn
> 31)
988 error_message
= ": invalid prefetch function number";
998 /* Parse a sparc64 privileged register. */
1001 struct priv_reg_entry
*p
= priv_reg_table
;
1002 unsigned int len
= 9999999; /* init to make gcc happy */
1005 while (p
->name
[0] > s
[0])
1007 while (p
->name
[0] == s
[0])
1009 len
= strlen (p
->name
);
1010 if (strncmp (p
->name
, s
, len
) == 0)
1014 if (p
->name
[0] != s
[0])
1016 error_message
= ": unrecognizable privileged register";
1020 opcode
|= (p
->regnum
<< 14);
1022 opcode
|= (p
->regnum
<< 25);
1028 error_message
= ": unrecognizable privileged register";
1034 if (strncmp (s
, "%asr", 4) == 0)
1042 while (isdigit (*s
))
1044 num
= num
* 10 + *s
- '0';
1048 if (current_architecture
>= SPARC_OPCODE_ARCH_V9
)
1050 if (num
< 16 || 31 < num
)
1052 error_message
= ": asr number must be between 16 and 31";
1058 if (num
< 0 || 31 < num
)
1060 error_message
= ": asr number must be between 0 and 31";
1065 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
1070 error_message
= ": expecting %asrN";
1077 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1078 immediate_max
= 0x03FF;
1082 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1083 immediate_max
= 0x01FF;
1087 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1092 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1097 if (*s
== 'p' && s
[1] == 'n')
1105 if (*s
== 'p' && s
[1] == 't')
1117 if (strncmp (s
, "%icc", 4) == 0)
1129 if (strncmp (s
, "%xcc", 4) == 0)
1141 if (strncmp (s
, "%fcc0", 5) == 0)
1153 if (strncmp (s
, "%fcc1", 5) == 0)
1165 if (strncmp (s
, "%fcc2", 5) == 0)
1177 if (strncmp (s
, "%fcc3", 5) == 0)
1185 if (strncmp (s
, "%pc", 3) == 0)
1193 if (strncmp (s
, "%tick", 5) == 0)
1200 case '\0': /* end of args */
1219 case '[': /* these must match exactly */
1227 case '#': /* must be at least one digit */
1230 while (isdigit (*s
))
1238 case 'C': /* coprocessor state register */
1239 if (strncmp (s
, "%csr", 4) == 0)
1246 case 'b': /* next operand is a coprocessor register */
1249 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1254 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1268 opcode
|= mask
<< 14;
1276 opcode
|= mask
<< 25;
1282 case 'r': /* next operand must be a register */
1292 case 'f': /* frame pointer */
1300 case 'g': /* global register */
1301 if (isoctal (c
= *s
++))
1308 case 'i': /* in register */
1309 if (isoctal (c
= *s
++))
1311 mask
= c
- '0' + 24;
1316 case 'l': /* local register */
1317 if (isoctal (c
= *s
++))
1319 mask
= (c
- '0' + 16);
1324 case 'o': /* out register */
1325 if (isoctal (c
= *s
++))
1327 mask
= (c
- '0' + 8);
1332 case 's': /* stack pointer */
1340 case 'r': /* any register */
1341 if (!isdigit (c
= *s
++))
1358 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1374 /* Got the register, now figure out where
1375 it goes in the opcode. */
1379 opcode
|= mask
<< 14;
1387 opcode
|= mask
<< 25;
1391 opcode
|= (mask
<< 25) | (mask
<< 14);
1395 opcode
|= (mask
<< 25) | (mask
<< 0);
1401 case 'e': /* next operand is a floating point register */
1416 && ((format
= *s
) == 'f')
1419 for (mask
= 0; isdigit (*s
); ++s
)
1421 mask
= 10 * mask
+ (*s
- '0');
1422 } /* read the number */
1430 } /* register must be even numbered */
1438 } /* register must be multiple of 4 */
1442 if (max_architecture
>= SPARC_OPCODE_ARCH_V9
)
1443 error_message
= ": There are only 64 f registers; [0-63]";
1445 error_message
= ": There are only 32 f registers; [0-31]";
1448 else if (mask
>= 32)
1450 if (max_architecture
>= SPARC_OPCODE_ARCH_V9
)
1453 mask
-= 31; /* wrap high bit */
1457 error_message
= ": There are only 32 f registers; [0-31]";
1465 } /* if not an 'f' register. */
1472 opcode
|= RS1 (mask
);
1479 opcode
|= RS2 (mask
);
1485 opcode
|= RD (mask
);
1494 if (strncmp (s
, "%fsr", 4) == 0)
1501 case 'h': /* high 22 bits */
1502 the_insn
.reloc
= BFD_RELOC_HI22
;
1505 case 'l': /* 22 bit PC relative immediate */
1506 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1510 case 'L': /* 30 bit immediate */
1511 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1515 case 'n': /* 22 bit immediate */
1516 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1519 case 'i': /* 13 bit immediate */
1520 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1521 immediate_max
= 0x0FFF;
1530 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1532 the_insn
.reloc
= BFD_RELOC_HI22
;
1535 else if (c
== 'l' && s
[2] == 'o')
1537 the_insn
.reloc
= BFD_RELOC_LO10
;
1544 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1552 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1559 /* Note that if the getExpression() fails, we will still
1560 have created U entries in the symbol table for the
1561 'symbols' in the input string. Try not to create U
1562 symbols for registers, etc. */
1564 /* This stuff checks to see if the expression ends in
1565 +%reg. If it does, it removes the register from
1566 the expression, and re-sets 's' to point to the
1571 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1573 if (s1
!= s
&& isdigit (s1
[-1]))
1575 if (s1
[-2] == '%' && s1
[-3] == '+')
1579 (void) getExpression (s
);
1584 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1588 (void) getExpression (s
);
1595 (void) getExpression (s
);
1598 if (the_insn
.exp
.X_op
== O_constant
1599 && the_insn
.exp
.X_add_symbol
== 0
1600 && the_insn
.exp
.X_op_symbol
== 0)
1602 /* Handle %uhi/%ulo by moving the upper word to the lower
1603 one and pretending it's %hi/%lo. We also need to watch
1604 for %hi/%lo: the top word needs to be zeroed otherwise
1605 fixup_segment will complain the value is too big. */
1606 switch (the_insn
.reloc
)
1608 case BFD_RELOC_SPARC_HH22
:
1609 the_insn
.reloc
= BFD_RELOC_HI22
;
1610 the_insn
.exp
.X_add_number
= BSR (the_insn
.exp
.X_add_number
, 32);
1612 case BFD_RELOC_SPARC_HM10
:
1613 the_insn
.reloc
= BFD_RELOC_LO10
;
1614 the_insn
.exp
.X_add_number
= BSR (the_insn
.exp
.X_add_number
, 32);
1616 case BFD_RELOC_HI22
:
1617 case BFD_RELOC_LO10
:
1618 the_insn
.exp
.X_add_number
&= 0xffffffff;
1624 /* For pc-relative call instructions, we reject
1625 constants to get better code. */
1627 && the_insn
.reloc
== BFD_RELOC_32_PCREL_S2
1628 && in_signed_range (the_insn
.exp
.X_add_number
, 0x3fff)
1631 error_message
= ": PC-relative operand can't be a constant";
1634 /* Check for invalid constant values. Don't warn if
1635 constant was inside %hi or %lo, since these
1636 truncate the constant to fit. */
1637 if (immediate_max
!= 0
1638 && the_insn
.reloc
!= BFD_RELOC_LO10
1639 && the_insn
.reloc
!= BFD_RELOC_HI22
1640 && !in_signed_range (the_insn
.exp
.X_add_number
,
1645 /* Who knows? After relocation, we may be within
1646 range. Let the linker figure it out. */
1648 the_insn
.exp
.X_op
= O_symbol
;
1649 the_insn
.exp
.X_add_symbol
= section_symbol (absolute_section
);
1652 /* Immediate value is non-pcrel, and out of
1654 as_bad ("constant value %ld out of range (%ld .. %ld)",
1655 the_insn
.exp
.X_add_number
,
1656 ~immediate_max
, immediate_max
);
1660 /* Reset to prevent extraneous range check. */
1680 if (! parse_keyword_arg (sparc_encode_asi
, &s
, &asi
))
1682 error_message
= ": invalid ASI name";
1688 if (! parse_const_expr_arg (&s
, &asi
))
1690 error_message
= ": invalid ASI expression";
1693 if (asi
< 0 || asi
> 255)
1695 error_message
= ": invalid ASI number";
1699 opcode
|= ASI (asi
);
1701 } /* alternate space */
1704 if (strncmp (s
, "%psr", 4) == 0)
1711 case 'q': /* floating point queue */
1712 if (strncmp (s
, "%fq", 3) == 0)
1719 case 'Q': /* coprocessor queue */
1720 if (strncmp (s
, "%cq", 3) == 0)
1728 if (strcmp (str
, "set") == 0)
1730 special_case
= SPECIAL_CASE_SET
;
1733 else if (strncmp (str
, "fdiv", 4) == 0)
1735 special_case
= SPECIAL_CASE_FDIV
;
1741 if (strncmp (s
, "%asi", 4) != 0)
1747 if (strncmp (s
, "%fprs", 5) != 0)
1753 if (strncmp (s
, "%ccr", 4) != 0)
1759 if (strncmp (s
, "%tbr", 4) != 0)
1765 if (strncmp (s
, "%wim", 4) != 0)
1772 char *push
= input_line_pointer
;
1775 input_line_pointer
= s
;
1777 if (e
.X_op
== O_constant
)
1779 int n
= e
.X_add_number
;
1780 if (n
!= e
.X_add_number
|| (n
& ~0x1ff) != 0)
1781 as_bad ("OPF immediate operand out of range (0-0x1ff)");
1783 opcode
|= e
.X_add_number
<< 5;
1786 as_bad ("non-immediate OPF operand, ignored");
1787 s
= input_line_pointer
;
1788 input_line_pointer
= push
;
1793 if (strncmp (s
, "%y", 2) != 0)
1801 /* Parse a sparclet cpreg. */
1803 if (! parse_keyword_arg (sparc_encode_sparclet_cpreg
, &s
, &cpreg
))
1805 error_message
= ": invalid cpreg name";
1808 opcode
|= (*args
== 'U' ? RS1 (cpreg
) : RD (cpreg
));
1813 as_fatal ("failed sanity check.");
1814 } /* switch on arg code */
1816 /* Break out of for() loop. */
1818 } /* for each arg that we expect */
1823 /* Args don't match. */
1824 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < sparc_num_opcodes
1825 && (insn
->name
== insn
[1].name
1826 || !strcmp (insn
->name
, insn
[1].name
)))
1834 as_bad ("Illegal operands%s", error_message
);
1840 /* We have a match. Now see if the architecture is ok. */
1841 int needed_arch_mask
= insn
->architecture
;
1845 needed_arch_mask
&= ~ ((1 << SPARC_OPCODE_ARCH_V9
)
1846 | (1 << SPARC_OPCODE_ARCH_V9A
));
1847 needed_arch_mask
|= (1 << SPARC_OPCODE_ARCH_V9
);
1850 if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (current_architecture
))
1852 /* Can we bump up the architecture? */
1853 else if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (max_architecture
))
1855 enum sparc_opcode_arch_val needed_architecture
=
1856 sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture
)
1857 & needed_arch_mask
);
1859 assert (needed_architecture
<= SPARC_OPCODE_ARCH_MAX
);
1861 && needed_architecture
> warn_after_architecture
)
1863 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1864 sparc_opcode_archs
[current_architecture
].name
,
1865 sparc_opcode_archs
[needed_architecture
].name
,
1867 warn_after_architecture
= needed_architecture
;
1869 current_architecture
= needed_architecture
;
1872 /* ??? This seems to be a bit fragile. What if the next entry in
1873 the opcode table is the one we want and it is supported?
1874 It is possible to arrange the table today so that this can't
1875 happen but what about tomorrow? */
1878 int arch
,printed_one_p
= 0;
1880 char required_archs
[SPARC_OPCODE_ARCH_MAX
* 16];
1882 /* Create a list of the architectures that support the insn. */
1883 needed_arch_mask
&= ~ SPARC_OPCODE_SUPPORTED (max_architecture
);
1885 arch
= sparc_ffs (needed_arch_mask
);
1886 while ((1 << arch
) <= needed_arch_mask
)
1888 if ((1 << arch
) & needed_arch_mask
)
1892 strcpy (p
, sparc_opcode_archs
[arch
].name
);
1899 as_bad ("Architecture mismatch on \"%s\".", str
);
1900 as_tsktsk (" (Requires %s; requested architecture is %s.)",
1902 sparc_opcode_archs
[max_architecture
].name
);
1908 } /* forever looking for a match */
1910 the_insn
.opcode
= opcode
;
1920 save_in
= input_line_pointer
;
1921 input_line_pointer
= str
;
1922 seg
= expression (&the_insn
.exp
);
1923 if (seg
!= absolute_section
1924 && seg
!= text_section
1925 && seg
!= data_section
1926 && seg
!= bss_section
1927 && seg
!= undefined_section
)
1929 the_insn
.error
= "bad segment";
1930 expr_end
= input_line_pointer
;
1931 input_line_pointer
= save_in
;
1934 expr_end
= input_line_pointer
;
1935 input_line_pointer
= save_in
;
1937 } /* getExpression() */
1941 This is identical to the md_atof in m68k.c. I think this is right,
1944 Turn a string in input_line_pointer into a floating point constant of type
1945 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1946 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1949 /* Equal to MAX_PRECISION in atof-ieee.c */
1950 #define MAX_LITTLENUMS 6
1953 md_atof (type
, litP
, sizeP
)
1959 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1960 LITTLENUM_TYPE
*wordP
;
1993 return "Bad call to MD_ATOF()";
1995 t
= atof_ieee (input_line_pointer
, type
, words
);
1997 input_line_pointer
= t
;
1998 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1999 for (wordP
= words
; prec
--;)
2001 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2002 litP
+= sizeof (LITTLENUM_TYPE
);
2008 * Write out big-endian.
2011 md_number_to_chars (buf
, val
, n
)
2016 number_to_chars_bigendian (buf
, val
, n
);
2019 /* Apply a fixS to the frags, now that we know the value it ought to
2023 md_apply_fix (fixP
, value
)
2027 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2032 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
2034 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
2037 /* FIXME: SPARC ELF relocations don't use an addend in the data
2038 field itself. This whole approach should be somehow combined
2039 with the calls to bfd_perform_relocation. Also, the value passed
2040 in by fixup_segment includes the value of a defined symbol. We
2041 don't want to include the value of an externally visible symbol. */
2042 if (fixP
->fx_addsy
!= NULL
)
2044 if ((S_IS_EXTERNAL (fixP
->fx_addsy
)
2045 || S_IS_WEAK (fixP
->fx_addsy
)
2046 || (sparc_pic_code
&& ! fixP
->fx_pcrel
))
2047 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
2048 && S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
2049 && ! bfd_is_com_section (S_GET_SEGMENT (fixP
->fx_addsy
)))
2050 fixP
->fx_addnumber
-= S_GET_VALUE (fixP
->fx_addsy
);
2055 /* This is a hack. There should be a better way to
2056 handle this. Probably in terms of howto fields, once
2057 we can look at these fixups in terms of howtos. */
2058 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
2059 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2062 /* FIXME: More ridiculous gas reloc hacking. If we are going to
2063 generate a reloc, then we just want to let the reloc addend set
2064 the value. We do not want to also stuff the addend into the
2065 object file. Including the addend in the object file works when
2066 doing a static link, because the linker will ignore the object
2067 file contents. However, the dynamic linker does not ignore the
2068 object file contents. */
2069 if (fixP
->fx_addsy
!= NULL
2070 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
)
2073 /* When generating PIC code, we do not want an addend for a reloc
2074 against a local symbol. We adjust fx_addnumber to cancel out the
2075 value already included in val, and to also cancel out the
2076 adjustment which bfd_install_relocation will create. */
2078 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
2079 && fixP
->fx_addsy
!= NULL
2080 && ! S_IS_COMMON (fixP
->fx_addsy
)
2081 && (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
2082 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
2085 switch (fixP
->fx_r_type
)
2099 case BFD_RELOC_32_PCREL_S2
:
2101 if (! sparc_pic_code
2102 || fixP
->fx_addsy
== NULL
2103 || (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2105 buf
[0] |= (val
>> 24) & 0x3f;
2106 buf
[1] = (val
>> 16);
2113 bfd_vma valh
= BSR (val
, 32);
2114 buf
[0] = valh
>> 24;
2115 buf
[1] = valh
>> 16;
2125 case BFD_RELOC_SPARC_11
:
2126 if (((val
> 0) && (val
& ~0x7ff))
2127 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
2129 as_bad ("relocation overflow.");
2132 buf
[2] |= (val
>> 8) & 0x7;
2133 buf
[3] = val
& 0xff;
2136 case BFD_RELOC_SPARC_10
:
2137 if (((val
> 0) && (val
& ~0x3ff))
2138 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
2140 as_bad ("relocation overflow.");
2143 buf
[2] |= (val
>> 8) & 0x3;
2144 buf
[3] = val
& 0xff;
2147 case BFD_RELOC_SPARC_WDISP16
:
2148 if (((val
> 0) && (val
& ~0x3fffc))
2149 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
2151 as_bad ("relocation overflow.");
2154 val
= (val
>>= 2) + 1;
2155 buf
[1] |= ((val
>> 14) & 0x3) << 4;
2156 buf
[2] |= (val
>> 8) & 0x3f;
2157 buf
[3] = val
& 0xff;
2160 case BFD_RELOC_SPARC_WDISP19
:
2161 if (((val
> 0) && (val
& ~0x1ffffc))
2162 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2164 as_bad ("relocation overflow.");
2167 val
= (val
>>= 2) + 1;
2168 buf
[1] |= (val
>> 16) & 0x7;
2169 buf
[2] = (val
>> 8) & 0xff;
2170 buf
[3] = val
& 0xff;
2173 case BFD_RELOC_SPARC_HH22
:
2174 val
= BSR (val
, 32);
2175 /* intentional fallthrough */
2177 case BFD_RELOC_SPARC_LM22
:
2178 case BFD_RELOC_HI22
:
2179 if (!fixP
->fx_addsy
)
2181 buf
[1] |= (val
>> 26) & 0x3f;
2192 case BFD_RELOC_SPARC22
:
2193 if (val
& ~0x003fffff)
2195 as_bad ("relocation overflow");
2197 buf
[1] |= (val
>> 16) & 0x3f;
2199 buf
[3] = val
& 0xff;
2202 case BFD_RELOC_SPARC_HM10
:
2203 val
= BSR (val
, 32);
2204 /* intentional fallthrough */
2206 case BFD_RELOC_LO10
:
2207 if (!fixP
->fx_addsy
)
2209 buf
[2] |= (val
>> 8) & 0x03;
2216 case BFD_RELOC_SPARC13
:
2217 if (! in_signed_range (val
, 0x1fff))
2218 as_bad ("relocation overflow");
2220 buf
[2] |= (val
>> 8) & 0x1f;
2224 case BFD_RELOC_SPARC_WDISP22
:
2225 val
= (val
>> 2) + 1;
2227 case BFD_RELOC_SPARC_BASE22
:
2228 buf
[1] |= (val
>> 16) & 0x3f;
2233 case BFD_RELOC_NONE
:
2235 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2239 /* Are we finished with this relocation now? */
2240 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
2246 /* Translate internal representation of relocation info to BFD target
2249 tc_gen_reloc (section
, fixp
)
2254 bfd_reloc_code_real_type code
;
2256 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2257 assert (reloc
!= 0);
2259 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2260 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2262 switch (fixp
->fx_r_type
)
2266 case BFD_RELOC_HI22
:
2267 case BFD_RELOC_LO10
:
2268 case BFD_RELOC_32_PCREL_S2
:
2269 case BFD_RELOC_SPARC13
:
2270 case BFD_RELOC_SPARC_BASE13
:
2271 case BFD_RELOC_SPARC_WDISP16
:
2272 case BFD_RELOC_SPARC_WDISP19
:
2273 case BFD_RELOC_SPARC_WDISP22
:
2275 case BFD_RELOC_SPARC_10
:
2276 case BFD_RELOC_SPARC_11
:
2277 case BFD_RELOC_SPARC_HH22
:
2278 case BFD_RELOC_SPARC_HM10
:
2279 case BFD_RELOC_SPARC_LM22
:
2280 case BFD_RELOC_SPARC_PC_HH22
:
2281 case BFD_RELOC_SPARC_PC_HM10
:
2282 case BFD_RELOC_SPARC_PC_LM22
:
2283 code
= fixp
->fx_r_type
;
2289 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
2290 /* If we are generating PIC code, we need to generate a different
2294 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
2296 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
2303 case BFD_RELOC_32_PCREL_S2
:
2304 if (! S_IS_DEFINED (fixp
->fx_addsy
)
2305 || S_IS_EXTERNAL (fixp
->fx_addsy
)
2306 || S_IS_WEAK (fixp
->fx_addsy
))
2307 code
= BFD_RELOC_SPARC_WPLT30
;
2309 case BFD_RELOC_HI22
:
2310 if (fixp
->fx_addsy
!= NULL
2311 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
2312 code
= BFD_RELOC_SPARC_PC22
;
2314 code
= BFD_RELOC_SPARC_GOT22
;
2316 case BFD_RELOC_LO10
:
2317 if (fixp
->fx_addsy
!= NULL
2318 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
2319 code
= BFD_RELOC_SPARC_PC10
;
2321 code
= BFD_RELOC_SPARC_GOT10
;
2323 case BFD_RELOC_SPARC13
:
2324 code
= BFD_RELOC_SPARC_GOT13
;
2330 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
2332 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2333 if (reloc
->howto
== 0)
2335 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2336 "internal error: can't export reloc type %d (`%s')",
2337 fixp
->fx_r_type
, bfd_get_reloc_code_name (code
));
2341 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2344 if (reloc
->howto
->pc_relative
== 0
2345 || code
== BFD_RELOC_SPARC_PC10
2346 || code
== BFD_RELOC_SPARC_PC22
)
2347 reloc
->addend
= fixp
->fx_addnumber
;
2349 reloc
->addend
= fixp
->fx_offset
- reloc
->address
;
2351 #else /* elf or coff */
2353 if (reloc
->howto
->pc_relative
== 0
2354 || code
== BFD_RELOC_SPARC_PC10
2355 || code
== BFD_RELOC_SPARC_PC22
)
2356 reloc
->addend
= fixp
->fx_addnumber
;
2357 else if ((fixp
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2358 reloc
->addend
= (section
->vma
2359 + fixp
->fx_addnumber
2360 + md_pcrel_from (fixp
));
2362 reloc
->addend
= fixp
->fx_offset
;
2370 /* for debugging only */
2373 struct sparc_it
*insn
;
2375 const char *const Reloc
[] = {
2404 fprintf (stderr
, "ERROR: %s\n");
2405 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2406 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2407 fprintf (stderr
, "exp = {\n");
2408 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2409 ((insn
->exp
.X_add_symbol
!= NULL
)
2410 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2411 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2414 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2415 ((insn
->exp
.X_op_symbol
!= NULL
)
2416 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2417 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2420 fprintf (stderr
, "\t\tX_add_number = %d\n",
2421 insn
->exp
.X_add_number
);
2422 fprintf (stderr
, "}\n");
2428 * Invocation line includes a switch not recognized by the base assembler.
2429 * See if it's a processor-specific option. These are:
2432 * Warn on architecture bumps. See also -A.
2434 * -Av6, -Av7, -Av8, -Av9, -Av9a, -Asparclite
2435 * -xarch=v8plus, -xarch=v8plusa
2436 * Select the architecture. Instructions or features not
2437 * supported by the selected architecture cause fatal errors.
2439 * The default is to start at v6, and bump the architecture up
2440 * whenever an instruction is seen at a higher level. If 32 bit
2441 * environments, v9 is not bumped up to, the user must pass -Av9.
2443 * -xarch=v8plus{,a} is for compatibility with the Sun assembler.
2445 * If -bump is specified, a warning is printing when bumping to
2448 * If an architecture is specified, all instructions must match
2449 * that architecture. Any higher level instructions are flagged
2450 * as errors. Note that in the 32 bit environment specifying
2451 * -Av9 does not automatically create a v9 object file, a v9
2452 * insn must be seen.
2454 * If both an architecture and -bump are specified, the
2455 * architecture starts at the specified level, but bumps are
2456 * warnings. Note that we can't set `current_architecture' to
2457 * the requested level in this case: in the 32 bit environment,
2458 * we still must avoid creating v9 object files unless v9 insns
2462 * Bumping between incompatible architectures is always an
2463 * error. For example, from sparclite to v9.
2467 CONST
char *md_shortopts
= "A:K:VQ:sq";
2470 CONST
char *md_shortopts
= "A:k";
2472 CONST
char *md_shortopts
= "A:";
2475 struct option md_longopts
[] = {
2476 #define OPTION_BUMP (OPTION_MD_BASE)
2477 {"bump", no_argument
, NULL
, OPTION_BUMP
},
2478 #define OPTION_SPARC (OPTION_MD_BASE + 1)
2479 {"sparc", no_argument
, NULL
, OPTION_SPARC
},
2480 #define OPTION_XARCH (OPTION_MD_BASE + 2)
2481 {"xarch", required_argument
, NULL
, OPTION_XARCH
},
2482 {NULL
, no_argument
, NULL
, 0}
2484 size_t md_longopts_size
= sizeof(md_longopts
);
2487 md_parse_option (c
, arg
)
2495 warn_after_architecture
= SPARC_OPCODE_ARCH_V6
;
2499 /* ??? We could add v8plus and v8plusa to sparc_opcode_archs.
2500 But we might want v8plus to mean something different than v9
2501 someday, and we'd recognize more -xarch options than Sun's
2502 assembler does (which may lead to a conflict someday). */
2503 if (strcmp (arg
, "v8plus") == 0)
2505 else if (strcmp (arg
, "v8plusa") == 0)
2509 as_bad ("invalid architecture -xarch=%s", arg
);
2517 enum sparc_opcode_arch_val new_arch
= sparc_opcode_lookup_arch (arg
);
2519 if (new_arch
== SPARC_OPCODE_ARCH_BAD
)
2521 as_bad ("invalid architecture -A%s", arg
);
2526 max_architecture
= new_arch
;
2527 architecture_requested
= 1;
2533 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2544 print_version_id ();
2548 /* Qy - do emit .comment
2549 Qn - do not emit .comment */
2553 /* use .stab instead of .stab.excl */
2557 /* quick -- native assembler does fewer checks */
2561 if (strcmp (arg
, "PIC") != 0)
2562 as_warn ("Unrecognized option following -K");
2576 md_show_usage (stream
)
2579 const struct sparc_opcode_arch
*arch
;
2581 fprintf(stream
, "SPARC options:\n");
2582 for (arch
= &sparc_opcode_archs
[0]; arch
->name
; arch
++)
2584 if (arch
!= &sparc_opcode_archs
[0])
2585 fprintf (stream
, " | ");
2586 fprintf (stream
, "-A%s", arch
->name
);
2588 fprintf (stream
, "\n-xarch=v8plus | -xarch=v8plusa\n");
2590 specify variant of SPARC architecture\n\
2591 -bump warn when assembler switches architectures\n\
2595 -k generate PIC\n");
2599 -KPIC generate PIC\n\
2600 -V print assembler version number\n\
2607 /* We have no need to default values of symbols. */
2611 md_undefined_symbol (name
)
2615 } /* md_undefined_symbol() */
2617 /* Round up a section size to the appropriate boundary. */
2619 md_section_align (segment
, size
)
2624 /* This is not right for ELF; a.out wants it, and COFF will force
2625 the alignment anyways. */
2626 valueT align
= ((valueT
) 1
2627 << (valueT
) bfd_get_section_alignment (stdoutput
, segment
));
2629 /* turn alignment value into a mask */
2631 newsize
= (size
+ align
) & ~align
;
2638 /* Exactly what point is a PC-relative offset relative TO?
2639 On the sparc, they're relative to the address of the offset, plus
2640 its size. This gets us to the following instruction.
2641 (??? Is this right? FIXME-SOON) */
2643 md_pcrel_from (fixP
)
2648 ret
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2649 if (! sparc_pic_code
2650 || fixP
->fx_addsy
== NULL
2651 || (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2652 ret
+= fixP
->fx_size
;
2656 /* end of tc-sparc.c */