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 *));
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
184 * sort of like s_lcomm
188 static int max_alignment
= 15;
203 name
= input_line_pointer
;
204 c
= get_symbol_end ();
205 p
= input_line_pointer
;
209 if (*input_line_pointer
!= ',')
211 as_bad ("Expected comma after name");
212 ignore_rest_of_line ();
216 ++input_line_pointer
;
218 if ((size
= get_absolute_expression ()) < 0)
220 as_bad ("BSS length (%d.) <0! Ignored.", size
);
221 ignore_rest_of_line ();
226 symbolP
= symbol_find_or_make (name
);
229 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
230 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
232 as_bad ("bad .reserve segment -- expected BSS segment");
236 if (input_line_pointer
[2] == '.')
237 input_line_pointer
+= 7;
239 input_line_pointer
+= 6;
242 if (*input_line_pointer
== ',')
244 ++input_line_pointer
;
247 if (*input_line_pointer
== '\n')
249 as_bad ("Missing alignment");
253 align
= get_absolute_expression ();
255 if (align
> max_alignment
)
257 align
= max_alignment
;
258 as_warn ("Alignment too large: %d. assumed.", align
);
264 as_warn ("Alignment negative. 0 assumed.");
267 record_alignment (bss_section
, align
);
269 /* convert to a power of 2 alignment */
270 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
274 as_bad ("Alignment not a power of 2");
275 ignore_rest_of_line ();
277 } /* not a power of two */
280 } /* if has optional alignment */
284 if (!S_IS_DEFINED (symbolP
)
286 && S_GET_OTHER (symbolP
) == 0
287 && S_GET_DESC (symbolP
) == 0
294 segT current_seg
= now_seg
;
295 subsegT current_subseg
= now_subseg
;
297 subseg_set (bss_section
, 1); /* switch to bss */
300 frag_align (align
, 0); /* do alignment */
302 /* detach from old frag */
303 if (S_GET_SEGMENT(symbolP
) == bss_section
)
304 symbolP
->sy_frag
->fr_symbol
= NULL
;
306 symbolP
->sy_frag
= frag_now
;
307 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
311 S_SET_SEGMENT (symbolP
, bss_section
);
313 subseg_set (current_seg
, current_subseg
);
318 as_warn("Ignoring attempt to re-define symbol %s",
319 S_GET_NAME (symbolP
));
320 } /* if not redefining */
322 demand_empty_rest_of_line ();
335 name
= input_line_pointer
;
336 c
= get_symbol_end ();
337 /* just after name is now '\0' */
338 p
= input_line_pointer
;
341 if (*input_line_pointer
!= ',')
343 as_bad ("Expected comma after symbol-name");
344 ignore_rest_of_line ();
347 input_line_pointer
++; /* skip ',' */
348 if ((temp
= get_absolute_expression ()) < 0)
350 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
351 ignore_rest_of_line ();
356 symbolP
= symbol_find_or_make (name
);
358 if (S_IS_DEFINED (symbolP
))
360 as_bad ("Ignoring attempt to re-define symbol");
361 ignore_rest_of_line ();
364 if (S_GET_VALUE (symbolP
) != 0)
366 if (S_GET_VALUE (symbolP
) != size
)
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
);
375 S_SET_VALUE (symbolP
, (valueT
) size
);
376 S_SET_EXTERNAL (symbolP
);
379 know (symbolP
->sy_frag
== &zero_address_frag
);
380 if (*input_line_pointer
!= ',')
382 as_bad ("Expected comma after common length");
383 ignore_rest_of_line ();
386 input_line_pointer
++;
388 if (*input_line_pointer
!= '"')
390 temp
= get_absolute_expression ();
392 if (temp
> max_alignment
)
394 temp
= max_alignment
;
395 as_warn ("Common alignment too large: %d. assumed", temp
);
401 as_warn ("Common alignment negative; 0 assumed");
413 old_subsec
= now_subseg
;
415 record_alignment (bss_section
, align
);
416 subseg_set (bss_section
, 0);
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
,
425 S_SET_SEGMENT (symbolP
, bss_section
);
426 S_CLEAR_EXTERNAL (symbolP
);
427 subseg_set (old_sec
, old_subsec
);
433 S_SET_VALUE (symbolP
, (valueT
) size
);
435 S_SET_ALIGN (symbolP
, temp
);
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
);
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))
452 while (*--input_line_pointer
!= '"')
454 input_line_pointer
--;
455 goto bad_common_segment
;
457 while (*input_line_pointer
++ != '"')
459 goto allocate_common
;
461 demand_empty_rest_of_line ();
466 p
= input_line_pointer
;
467 while (*p
&& *p
!= '\n')
471 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
473 input_line_pointer
= p
;
474 ignore_rest_of_line ();
484 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
486 input_line_pointer
+= 6;
490 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
492 input_line_pointer
+= 6;
496 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
498 input_line_pointer
+= 7;
502 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
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 */
511 as_bad ("Unknown segment type");
512 demand_empty_rest_of_line ();
518 subseg_set (data_section
, 1);
519 demand_empty_rest_of_line ();
526 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
528 ++input_line_pointer
;
530 ++input_line_pointer
;
533 /* sparc64 priviledged registers */
535 struct priv_reg_entry
541 struct priv_reg_entry priv_reg_table
[] =
560 {"", -1}, /* end marker */
565 struct priv_reg_entry
*p
, *q
;
567 return strcmp (q
->name
, p
->name
);
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. */
576 register const char *retval
= NULL
;
578 register unsigned int i
= 0;
580 op_hash
= hash_new ();
582 while (i
< sparc_num_opcodes
)
584 const char *name
= sparc_opcodes
[i
].name
;
585 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
588 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
589 sparc_opcodes
[i
].name
, retval
);
594 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
596 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
597 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
602 while (i
< sparc_num_opcodes
603 && !strcmp (sparc_opcodes
[i
].name
, name
));
607 as_fatal ("Broken assembler. No assembly attempted.");
609 for (i
= '0'; i
< '8'; ++i
)
611 for (i
= '0'; i
<= '9'; ++i
)
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';
618 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
619 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
621 target_big_endian
= 1;
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. */
631 && architecture_requested
)
633 /* `max_architecture' records the requested architecture.
634 Issue warnings if we go above it. */
635 warn_after_architecture
= max_architecture
;
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
;
642 if (! SPARC_OPCODE_CONFLICT_P (max_architecture
,
643 warn_after_architecture
))
648 /* Called after all assembly has been done. */
654 if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
655 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9a
);
657 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9
);
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
);
664 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc
);
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
)
682 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
683 && the_insn
.exp
.X_add_number
< (1 << 12))
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 */
694 /* put out the opcode */
695 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
697 /* put out the symbol-dependent stuff */
698 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
700 fix_new_exp (frag_now
, /* which frag */
701 (toP
- frag_now
->fr_literal
), /* where */
708 switch (special_case
)
710 case SPECIAL_CASE_SET
:
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))
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 */
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. */
736 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
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);
747 as_fatal ("failed sanity check.");
751 /* Implement big shift right. */
757 if (sizeof (bfd_vma
) <= 4 && amount
>= 32)
758 as_fatal ("Support for 64-bit arithmetic not compiled in.");
759 return val
>> amount
;
762 /* Parse an argument that can be expressed as a keyword.
763 (eg: #StoreStore or %ccfr).
764 The result is a boolean indicating success.
765 If successful, INPUT_POINTER is updated. */
768 parse_keyword_arg (lookup_fn
, input_pointerP
, valueP
)
770 char **input_pointerP
;
777 for (q
= p
+ (*p
== '#' || *p
== '%'); isalpha (*q
) || *q
== '_'; ++q
)
781 value
= (*lookup_fn
) (p
);
790 /* Parse an argument that is a constant expression.
791 The result is a boolean indicating success. */
794 parse_const_expr_arg (input_pointerP
, valueP
)
795 char **input_pointerP
;
798 char *save
= input_line_pointer
;
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
809 if (*input_line_pointer
== '%')
811 input_line_pointer
= save
;
815 *input_pointerP
= input_line_pointer
;
816 input_line_pointer
= save
;
817 if (exp
.X_op
!= O_constant
)
819 *valueP
= exp
.X_add_number
;
827 char *error_message
= "";
831 const struct sparc_opcode
*insn
;
833 unsigned long opcode
;
834 unsigned int mask
= 0;
837 long immediate_max
= 0;
840 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
858 as_fatal ("Unknown opcode: `%s'", str
);
860 insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
);
863 as_bad ("Unknown opcode: `%s'", str
);
874 opcode
= insn
->match
;
875 memset (&the_insn
, '\0', sizeof (the_insn
));
876 the_insn
.reloc
= BFD_RELOC_NONE
;
880 * Build the opcode, checking as we go to make
881 * sure that the operands match
883 for (args
= insn
->args
;; ++args
)
891 /* Parse a series of masks. */
898 if (! parse_keyword_arg (sparc_encode_membar
, &s
,
901 error_message
= ": invalid membar mask name";
905 while (*s
== ' ') { ++s
; continue; }
906 if (*s
== '|' || *s
== '+')
908 while (*s
== ' ') { ++s
; continue; }
913 if (! parse_const_expr_arg (&s
, &kmask
))
915 error_message
= ": invalid membar mask expression";
918 if (kmask
< 0 || kmask
> 127)
920 error_message
= ": invalid membar mask number";
925 opcode
|= MEMBAR (kmask
);
933 /* Parse a prefetch function. */
936 if (! parse_keyword_arg (sparc_encode_prefetch
, &s
, &fcn
))
938 error_message
= ": invalid prefetch function name";
944 if (! parse_const_expr_arg (&s
, &fcn
))
946 error_message
= ": invalid prefetch function expression";
949 if (fcn
< 0 || fcn
> 31)
951 error_message
= ": invalid prefetch function number";
961 /* Parse a sparc64 privileged register. */
964 struct priv_reg_entry
*p
= priv_reg_table
;
965 unsigned int len
= 9999999; /* init to make gcc happy */
968 while (p
->name
[0] > s
[0])
970 while (p
->name
[0] == s
[0])
972 len
= strlen (p
->name
);
973 if (strncmp (p
->name
, s
, len
) == 0)
977 if (p
->name
[0] != s
[0])
979 error_message
= ": unrecognizable privileged register";
983 opcode
|= (p
->regnum
<< 14);
985 opcode
|= (p
->regnum
<< 25);
991 error_message
= ": unrecognizable privileged register";
997 if (strncmp (s
, "%asr", 4) == 0)
1005 while (isdigit (*s
))
1007 num
= num
* 10 + *s
- '0';
1011 if (current_architecture
>= SPARC_OPCODE_ARCH_V9
)
1013 if (num
< 16 || 31 < num
)
1015 error_message
= ": asr number must be between 16 and 31";
1021 if (num
< 0 || 31 < num
)
1023 error_message
= ": asr number must be between 0 and 31";
1028 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
1033 error_message
= ": expecting %asrN";
1040 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1041 immediate_max
= 0x03FF;
1045 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1046 immediate_max
= 0x01FF;
1050 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1055 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1060 if (*s
== 'p' && s
[1] == 'n')
1068 if (*s
== 'p' && s
[1] == 't')
1080 if (strncmp (s
, "%icc", 4) == 0)
1092 if (strncmp (s
, "%xcc", 4) == 0)
1104 if (strncmp (s
, "%fcc0", 5) == 0)
1116 if (strncmp (s
, "%fcc1", 5) == 0)
1128 if (strncmp (s
, "%fcc2", 5) == 0)
1140 if (strncmp (s
, "%fcc3", 5) == 0)
1148 if (strncmp (s
, "%pc", 3) == 0)
1156 if (strncmp (s
, "%tick", 5) == 0)
1163 case '\0': /* end of args */
1182 case '[': /* these must match exactly */
1190 case '#': /* must be at least one digit */
1193 while (isdigit (*s
))
1201 case 'C': /* coprocessor state register */
1202 if (strncmp (s
, "%csr", 4) == 0)
1209 case 'b': /* next operand is a coprocessor register */
1212 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1217 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1231 opcode
|= mask
<< 14;
1239 opcode
|= mask
<< 25;
1245 case 'r': /* next operand must be a register */
1254 case 'f': /* frame pointer */
1262 case 'g': /* global register */
1263 if (isoctal (c
= *s
++))
1270 case 'i': /* in register */
1271 if (isoctal (c
= *s
++))
1273 mask
= c
- '0' + 24;
1278 case 'l': /* local register */
1279 if (isoctal (c
= *s
++))
1281 mask
= (c
- '0' + 16);
1286 case 'o': /* out register */
1287 if (isoctal (c
= *s
++))
1289 mask
= (c
- '0' + 8);
1294 case 's': /* stack pointer */
1302 case 'r': /* any register */
1303 if (!isdigit (c
= *s
++))
1320 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1336 /* Got the register, now figure out where
1337 it goes in the opcode. */
1342 opcode
|= mask
<< 14;
1350 opcode
|= mask
<< 25;
1354 opcode
|= (mask
<< 25) | (mask
<< 14);
1360 case 'e': /* next operand is a floating point register */
1375 && ((format
= *s
) == 'f')
1378 for (mask
= 0; isdigit (*s
); ++s
)
1380 mask
= 10 * mask
+ (*s
- '0');
1381 } /* read the number */
1389 } /* register must be even numbered */
1397 } /* register must be multiple of 4 */
1401 if (max_architecture
>= SPARC_OPCODE_ARCH_V9
)
1402 error_message
= ": There are only 64 f registers; [0-63]";
1404 error_message
= ": There are only 32 f registers; [0-31]";
1407 else if (mask
>= 32)
1409 if (max_architecture
>= SPARC_OPCODE_ARCH_V9
)
1412 mask
-= 31; /* wrap high bit */
1416 error_message
= ": There are only 32 f registers; [0-31]";
1424 } /* if not an 'f' register. */
1431 opcode
|= RS1 (mask
);
1438 opcode
|= RS2 (mask
);
1444 opcode
|= RD (mask
);
1453 if (strncmp (s
, "%fsr", 4) == 0)
1460 case 'h': /* high 22 bits */
1461 the_insn
.reloc
= BFD_RELOC_HI22
;
1464 case 'l': /* 22 bit PC relative immediate */
1465 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1469 case 'L': /* 30 bit immediate */
1470 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1474 case 'n': /* 22 bit immediate */
1475 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1478 case 'i': /* 13 bit immediate */
1479 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1480 immediate_max
= 0x0FFF;
1489 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1491 the_insn
.reloc
= BFD_RELOC_HI22
;
1494 else if (c
== 'l' && s
[2] == 'o')
1496 the_insn
.reloc
= BFD_RELOC_LO10
;
1503 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1511 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1518 /* Note that if the getExpression() fails, we will still
1519 have created U entries in the symbol table for the
1520 'symbols' in the input string. Try not to create U
1521 symbols for registers, etc. */
1523 /* This stuff checks to see if the expression ends in
1524 +%reg. If it does, it removes the register from
1525 the expression, and re-sets 's' to point to the
1530 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1532 if (s1
!= s
&& isdigit (s1
[-1]))
1534 if (s1
[-2] == '%' && s1
[-3] == '+')
1538 (void) getExpression (s
);
1543 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1547 (void) getExpression (s
);
1554 (void) getExpression (s
);
1557 if (the_insn
.exp
.X_op
== O_constant
1558 && the_insn
.exp
.X_add_symbol
== 0
1559 && the_insn
.exp
.X_op_symbol
== 0)
1561 /* Handle %uhi/%ulo by moving the upper word to the lower
1562 one and pretending it's %hi/%lo. We also need to watch
1563 for %hi/%lo: the top word needs to be zeroed otherwise
1564 fixup_segment will complain the value is too big. */
1565 switch (the_insn
.reloc
)
1567 case BFD_RELOC_SPARC_HH22
:
1568 the_insn
.reloc
= BFD_RELOC_HI22
;
1569 the_insn
.exp
.X_add_number
= BSR (the_insn
.exp
.X_add_number
, 32);
1571 case BFD_RELOC_SPARC_HM10
:
1572 the_insn
.reloc
= BFD_RELOC_LO10
;
1573 the_insn
.exp
.X_add_number
= BSR (the_insn
.exp
.X_add_number
, 32);
1575 case BFD_RELOC_HI22
:
1576 case BFD_RELOC_LO10
:
1577 the_insn
.exp
.X_add_number
&= 0xffffffff;
1583 /* For pc-relative call instructions, we reject
1584 constants to get better code. */
1586 && the_insn
.reloc
== BFD_RELOC_32_PCREL_S2
1587 && in_signed_range (the_insn
.exp
.X_add_number
, 0x3fff)
1590 error_message
= ": PC-relative operand can't be a constant";
1593 /* Check for invalid constant values. Don't warn if
1594 constant was inside %hi or %lo, since these
1595 truncate the constant to fit. */
1596 if (immediate_max
!= 0
1597 && the_insn
.reloc
!= BFD_RELOC_LO10
1598 && the_insn
.reloc
!= BFD_RELOC_HI22
1599 && !in_signed_range (the_insn
.exp
.X_add_number
,
1604 /* Who knows? After relocation, we may be within
1605 range. Let the linker figure it out. */
1607 the_insn
.exp
.X_op
= O_symbol
;
1608 the_insn
.exp
.X_add_symbol
= section_symbol (absolute_section
);
1611 /* Immediate value is non-pcrel, and out of
1613 as_bad ("constant value %ld out of range (%ld .. %ld)",
1614 the_insn
.exp
.X_add_number
,
1615 ~immediate_max
, immediate_max
);
1619 /* Reset to prevent extraneous range check. */
1639 if (! parse_keyword_arg (sparc_encode_asi
, &s
, &asi
))
1641 error_message
= ": invalid ASI name";
1647 if (! parse_const_expr_arg (&s
, &asi
))
1649 error_message
= ": invalid ASI expression";
1652 if (asi
< 0 || asi
> 255)
1654 error_message
= ": invalid ASI number";
1658 opcode
|= ASI (asi
);
1660 } /* alternate space */
1663 if (strncmp (s
, "%psr", 4) == 0)
1670 case 'q': /* floating point queue */
1671 if (strncmp (s
, "%fq", 3) == 0)
1678 case 'Q': /* coprocessor queue */
1679 if (strncmp (s
, "%cq", 3) == 0)
1687 if (strcmp (str
, "set") == 0)
1689 special_case
= SPECIAL_CASE_SET
;
1692 else if (strncmp (str
, "fdiv", 4) == 0)
1694 special_case
= SPECIAL_CASE_FDIV
;
1700 if (strncmp (s
, "%asi", 4) != 0)
1706 if (strncmp (s
, "%fprs", 5) != 0)
1712 if (strncmp (s
, "%ccr", 4) != 0)
1718 if (strncmp (s
, "%tbr", 4) != 0)
1724 if (strncmp (s
, "%wim", 4) != 0)
1731 char *push
= input_line_pointer
;
1734 input_line_pointer
= s
;
1736 if (e
.X_op
== O_constant
)
1738 int n
= e
.X_add_number
;
1739 if (n
!= e
.X_add_number
|| (n
& ~0x1ff) != 0)
1740 as_bad ("OPF immediate operand out of range (0-0x1ff)");
1742 opcode
|= e
.X_add_number
<< 5;
1745 as_bad ("non-immediate OPF operand, ignored");
1746 s
= input_line_pointer
;
1747 input_line_pointer
= push
;
1752 if (strncmp (s
, "%y", 2) != 0)
1760 /* Parse a sparclet cpreg. */
1762 if (! parse_keyword_arg (sparc_encode_sparclet_cpreg
, &s
, &cpreg
))
1764 error_message
= ": invalid cpreg name";
1767 opcode
|= (*args
== 'U' ? RS1 (cpreg
) : RD (cpreg
));
1772 as_fatal ("failed sanity check.");
1773 } /* switch on arg code */
1775 /* Break out of for() loop. */
1777 } /* for each arg that we expect */
1782 /* Args don't match. */
1783 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < sparc_num_opcodes
1784 && (insn
->name
== insn
[1].name
1785 || !strcmp (insn
->name
, insn
[1].name
)))
1793 as_bad ("Illegal operands%s", error_message
);
1799 /* We have a match. Now see if the architecture is ok. */
1800 int needed_arch_mask
= insn
->architecture
;
1804 needed_arch_mask
&= ~ ((1 << SPARC_OPCODE_ARCH_V9
)
1805 | (1 << SPARC_OPCODE_ARCH_V9A
));
1806 needed_arch_mask
|= (1 << SPARC_OPCODE_ARCH_V9
);
1809 if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (current_architecture
))
1811 /* Can we bump up the architecture? */
1812 else if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (max_architecture
))
1814 enum sparc_opcode_arch_val needed_architecture
=
1815 sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture
)
1816 & needed_arch_mask
);
1818 assert (needed_architecture
<= SPARC_OPCODE_ARCH_MAX
);
1820 && needed_architecture
> warn_after_architecture
)
1822 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1823 sparc_opcode_archs
[current_architecture
].name
,
1824 sparc_opcode_archs
[needed_architecture
].name
,
1826 warn_after_architecture
= needed_architecture
;
1828 current_architecture
= needed_architecture
;
1831 /* ??? This seems to be a bit fragile. What if the next entry in
1832 the opcode table is the one we want and it is supported?
1833 It is possible to arrange the table today so that this can't
1834 happen but what about tomorrow? */
1837 int arch
,printed_one_p
= 0;
1839 char required_archs
[SPARC_OPCODE_ARCH_MAX
* 16];
1841 /* Create a list of the architectures that support the insn. */
1842 needed_arch_mask
&= ~ SPARC_OPCODE_SUPPORTED (max_architecture
);
1844 arch
= sparc_ffs (needed_arch_mask
);
1845 while ((1 << arch
) <= needed_arch_mask
)
1847 if ((1 << arch
) & needed_arch_mask
)
1851 strcpy (p
, sparc_opcode_archs
[arch
].name
);
1858 as_bad ("Architecture mismatch on \"%s\".", str
);
1859 as_tsktsk (" (Requires %s; requested architecture is %s.)",
1861 sparc_opcode_archs
[max_architecture
].name
);
1867 } /* forever looking for a match */
1869 the_insn
.opcode
= opcode
;
1879 save_in
= input_line_pointer
;
1880 input_line_pointer
= str
;
1881 seg
= expression (&the_insn
.exp
);
1882 if (seg
!= absolute_section
1883 && seg
!= text_section
1884 && seg
!= data_section
1885 && seg
!= bss_section
1886 && seg
!= undefined_section
)
1888 the_insn
.error
= "bad segment";
1889 expr_end
= input_line_pointer
;
1890 input_line_pointer
= save_in
;
1893 expr_end
= input_line_pointer
;
1894 input_line_pointer
= save_in
;
1896 } /* getExpression() */
1900 This is identical to the md_atof in m68k.c. I think this is right,
1903 Turn a string in input_line_pointer into a floating point constant of type
1904 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1905 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1908 /* Equal to MAX_PRECISION in atof-ieee.c */
1909 #define MAX_LITTLENUMS 6
1912 md_atof (type
, litP
, sizeP
)
1918 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1919 LITTLENUM_TYPE
*wordP
;
1952 return "Bad call to MD_ATOF()";
1954 t
= atof_ieee (input_line_pointer
, type
, words
);
1956 input_line_pointer
= t
;
1957 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1958 for (wordP
= words
; prec
--;)
1960 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1961 litP
+= sizeof (LITTLENUM_TYPE
);
1967 * Write out big-endian.
1970 md_number_to_chars (buf
, val
, n
)
1975 number_to_chars_bigendian (buf
, val
, n
);
1978 /* Apply a fixS to the frags, now that we know the value it ought to
1982 md_apply_fix (fixP
, value
)
1986 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1991 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1993 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1996 /* FIXME: SPARC ELF relocations don't use an addend in the data
1997 field itself. This whole approach should be somehow combined
1998 with the calls to bfd_perform_relocation. Also, the value passed
1999 in by fixup_segment includes the value of a defined symbol. We
2000 don't want to include the value of an externally visible symbol. */
2001 if (fixP
->fx_addsy
!= NULL
)
2003 if ((S_IS_EXTERNAL (fixP
->fx_addsy
)
2004 || S_IS_WEAK (fixP
->fx_addsy
)
2005 || (sparc_pic_code
&& ! fixP
->fx_pcrel
))
2006 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
2007 && S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
2008 && ! bfd_is_com_section (S_GET_SEGMENT (fixP
->fx_addsy
)))
2009 fixP
->fx_addnumber
-= S_GET_VALUE (fixP
->fx_addsy
);
2014 /* This is a hack. There should be a better way to
2015 handle this. Probably in terms of howto fields, once
2016 we can look at these fixups in terms of howtos. */
2017 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
2018 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2021 /* FIXME: More ridiculous gas reloc hacking. If we are going to
2022 generate a reloc, then we just want to let the reloc addend set
2023 the value. We do not want to also stuff the addend into the
2024 object file. Including the addend in the object file works when
2025 doing a static link, because the linker will ignore the object
2026 file contents. However, the dynamic linker does not ignore the
2027 object file contents. */
2028 if (fixP
->fx_addsy
!= NULL
2029 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
)
2032 /* When generating PIC code, we do not want an addend for a reloc
2033 against a local symbol. We adjust fx_addnumber to cancel out the
2034 value already included in val, and to also cancel out the
2035 adjustment which bfd_install_relocation will create. */
2037 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
2038 && fixP
->fx_addsy
!= NULL
2039 && ! S_IS_COMMON (fixP
->fx_addsy
)
2040 && (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
2041 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
2044 switch (fixP
->fx_r_type
)
2058 case BFD_RELOC_32_PCREL_S2
:
2060 if (! sparc_pic_code
2061 || fixP
->fx_addsy
== NULL
2062 || (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2064 buf
[0] |= (val
>> 24) & 0x3f;
2065 buf
[1] = (val
>> 16);
2072 bfd_vma valh
= BSR (val
, 32);
2073 buf
[0] = valh
>> 24;
2074 buf
[1] = valh
>> 16;
2084 case BFD_RELOC_SPARC_11
:
2085 if (((val
> 0) && (val
& ~0x7ff))
2086 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
2088 as_bad ("relocation overflow.");
2091 buf
[2] |= (val
>> 8) & 0x7;
2092 buf
[3] = val
& 0xff;
2095 case BFD_RELOC_SPARC_10
:
2096 if (((val
> 0) && (val
& ~0x3ff))
2097 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
2099 as_bad ("relocation overflow.");
2102 buf
[2] |= (val
>> 8) & 0x3;
2103 buf
[3] = val
& 0xff;
2106 case BFD_RELOC_SPARC_WDISP16
:
2107 if (((val
> 0) && (val
& ~0x3fffc))
2108 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
2110 as_bad ("relocation overflow.");
2113 val
= (val
>>= 2) + 1;
2114 buf
[1] |= ((val
>> 14) & 0x3) << 4;
2115 buf
[2] |= (val
>> 8) & 0x3f;
2116 buf
[3] = val
& 0xff;
2119 case BFD_RELOC_SPARC_WDISP19
:
2120 if (((val
> 0) && (val
& ~0x1ffffc))
2121 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2123 as_bad ("relocation overflow.");
2126 val
= (val
>>= 2) + 1;
2127 buf
[1] |= (val
>> 16) & 0x7;
2128 buf
[2] = (val
>> 8) & 0xff;
2129 buf
[3] = val
& 0xff;
2132 case BFD_RELOC_SPARC_HH22
:
2133 val
= BSR (val
, 32);
2134 /* intentional fallthrough */
2136 case BFD_RELOC_SPARC_LM22
:
2137 case BFD_RELOC_HI22
:
2138 if (!fixP
->fx_addsy
)
2140 buf
[1] |= (val
>> 26) & 0x3f;
2151 case BFD_RELOC_SPARC22
:
2152 if (val
& ~0x003fffff)
2154 as_bad ("relocation overflow");
2156 buf
[1] |= (val
>> 16) & 0x3f;
2158 buf
[3] = val
& 0xff;
2161 case BFD_RELOC_SPARC_HM10
:
2162 val
= BSR (val
, 32);
2163 /* intentional fallthrough */
2165 case BFD_RELOC_LO10
:
2166 if (!fixP
->fx_addsy
)
2168 buf
[2] |= (val
>> 8) & 0x03;
2175 case BFD_RELOC_SPARC13
:
2176 if (! in_signed_range (val
, 0x1fff))
2177 as_bad ("relocation overflow");
2179 buf
[2] |= (val
>> 8) & 0x1f;
2183 case BFD_RELOC_SPARC_WDISP22
:
2184 val
= (val
>> 2) + 1;
2186 case BFD_RELOC_SPARC_BASE22
:
2187 buf
[1] |= (val
>> 16) & 0x3f;
2192 case BFD_RELOC_NONE
:
2194 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2198 /* Are we finished with this relocation now? */
2199 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
2205 /* Translate internal representation of relocation info to BFD target
2208 tc_gen_reloc (section
, fixp
)
2213 bfd_reloc_code_real_type code
;
2215 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2216 assert (reloc
!= 0);
2218 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2219 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2221 switch (fixp
->fx_r_type
)
2225 case BFD_RELOC_HI22
:
2226 case BFD_RELOC_LO10
:
2227 case BFD_RELOC_32_PCREL_S2
:
2228 case BFD_RELOC_SPARC13
:
2229 case BFD_RELOC_SPARC_BASE13
:
2230 case BFD_RELOC_SPARC_WDISP16
:
2231 case BFD_RELOC_SPARC_WDISP19
:
2232 case BFD_RELOC_SPARC_WDISP22
:
2234 case BFD_RELOC_SPARC_10
:
2235 case BFD_RELOC_SPARC_11
:
2236 case BFD_RELOC_SPARC_HH22
:
2237 case BFD_RELOC_SPARC_HM10
:
2238 case BFD_RELOC_SPARC_LM22
:
2239 case BFD_RELOC_SPARC_PC_HH22
:
2240 case BFD_RELOC_SPARC_PC_HM10
:
2241 case BFD_RELOC_SPARC_PC_LM22
:
2242 code
= fixp
->fx_r_type
;
2248 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
2249 /* If we are generating PIC code, we need to generate a different
2253 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
2255 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
2262 case BFD_RELOC_32_PCREL_S2
:
2263 if (! S_IS_DEFINED (fixp
->fx_addsy
)
2264 || S_IS_EXTERNAL (fixp
->fx_addsy
)
2265 || S_IS_WEAK (fixp
->fx_addsy
))
2266 code
= BFD_RELOC_SPARC_WPLT30
;
2268 case BFD_RELOC_HI22
:
2269 if (fixp
->fx_addsy
!= NULL
2270 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
2271 code
= BFD_RELOC_SPARC_PC22
;
2273 code
= BFD_RELOC_SPARC_GOT22
;
2275 case BFD_RELOC_LO10
:
2276 if (fixp
->fx_addsy
!= NULL
2277 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
2278 code
= BFD_RELOC_SPARC_PC10
;
2280 code
= BFD_RELOC_SPARC_GOT10
;
2282 case BFD_RELOC_SPARC13
:
2283 code
= BFD_RELOC_SPARC_GOT13
;
2289 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
2291 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2292 if (reloc
->howto
== 0)
2294 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2295 "internal error: can't export reloc type %d (`%s')",
2296 fixp
->fx_r_type
, bfd_get_reloc_code_name (code
));
2300 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2303 if (reloc
->howto
->pc_relative
== 0
2304 || code
== BFD_RELOC_SPARC_PC10
2305 || code
== BFD_RELOC_SPARC_PC22
)
2306 reloc
->addend
= fixp
->fx_addnumber
;
2308 reloc
->addend
= fixp
->fx_offset
- reloc
->address
;
2310 #else /* elf or coff */
2312 if (reloc
->howto
->pc_relative
== 0
2313 || code
== BFD_RELOC_SPARC_PC10
2314 || code
== BFD_RELOC_SPARC_PC22
)
2315 reloc
->addend
= fixp
->fx_addnumber
;
2316 else if ((fixp
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2317 reloc
->addend
= (section
->vma
2318 + fixp
->fx_addnumber
2319 + md_pcrel_from (fixp
));
2321 reloc
->addend
= fixp
->fx_offset
;
2329 /* for debugging only */
2332 struct sparc_it
*insn
;
2334 const char *const Reloc
[] = {
2363 fprintf (stderr
, "ERROR: %s\n");
2364 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2365 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2366 fprintf (stderr
, "exp = {\n");
2367 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2368 ((insn
->exp
.X_add_symbol
!= NULL
)
2369 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2370 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2373 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2374 ((insn
->exp
.X_op_symbol
!= NULL
)
2375 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2376 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2379 fprintf (stderr
, "\t\tX_add_number = %d\n",
2380 insn
->exp
.X_add_number
);
2381 fprintf (stderr
, "}\n");
2387 * Invocation line includes a switch not recognized by the base assembler.
2388 * See if it's a processor-specific option. These are:
2391 * Warn on architecture bumps. See also -A.
2393 * -Av6, -Av7, -Av8, -Av9, -Av9a, -Asparclite
2394 * -xarch=v8plus, -xarch=v8plusa
2395 * Select the architecture. Instructions or features not
2396 * supported by the selected architecture cause fatal errors.
2398 * The default is to start at v6, and bump the architecture up
2399 * whenever an instruction is seen at a higher level. If 32 bit
2400 * environments, v9 is not bumped up to, the user must pass -Av9.
2402 * -xarch=v8plus{,a} is for compatibility with the Sun assembler.
2404 * If -bump is specified, a warning is printing when bumping to
2407 * If an architecture is specified, all instructions must match
2408 * that architecture. Any higher level instructions are flagged
2409 * as errors. Note that in the 32 bit environment specifying
2410 * -Av9 does not automatically create a v9 object file, a v9
2411 * insn must be seen.
2413 * If both an architecture and -bump are specified, the
2414 * architecture starts at the specified level, but bumps are
2415 * warnings. Note that we can't set `current_architecture' to
2416 * the requested level in this case: in the 32 bit environment,
2417 * we still must avoid creating v9 object files unless v9 insns
2421 * Bumping between incompatible architectures is always an
2422 * error. For example, from sparclite to v9.
2426 CONST
char *md_shortopts
= "A:K:VQ:sq";
2429 CONST
char *md_shortopts
= "A:k";
2431 CONST
char *md_shortopts
= "A:";
2434 struct option md_longopts
[] = {
2435 #define OPTION_BUMP (OPTION_MD_BASE)
2436 {"bump", no_argument
, NULL
, OPTION_BUMP
},
2437 #define OPTION_SPARC (OPTION_MD_BASE + 1)
2438 {"sparc", no_argument
, NULL
, OPTION_SPARC
},
2439 #define OPTION_XARCH (OPTION_MD_BASE + 2)
2440 {"xarch", required_argument
, NULL
, OPTION_XARCH
},
2441 {NULL
, no_argument
, NULL
, 0}
2443 size_t md_longopts_size
= sizeof(md_longopts
);
2446 md_parse_option (c
, arg
)
2454 warn_after_architecture
= SPARC_OPCODE_ARCH_V6
;
2458 /* ??? We could add v8plus and v8plusa to sparc_opcode_archs.
2459 But we might want v8plus to mean something different than v9
2460 someday, and we'd recognize more -xarch options than Sun's
2461 assembler does (which may lead to a conflict someday). */
2462 if (strcmp (arg
, "v8plus") == 0)
2464 else if (strcmp (arg
, "v8plusa") == 0)
2468 as_bad ("invalid architecture -xarch=%s", arg
);
2476 enum sparc_opcode_arch_val new_arch
= sparc_opcode_lookup_arch (arg
);
2478 if (new_arch
== SPARC_OPCODE_ARCH_BAD
)
2480 as_bad ("invalid architecture -A%s", arg
);
2485 max_architecture
= new_arch
;
2486 architecture_requested
= 1;
2492 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2503 print_version_id ();
2507 /* Qy - do emit .comment
2508 Qn - do not emit .comment */
2512 /* use .stab instead of .stab.excl */
2516 /* quick -- native assembler does fewer checks */
2520 if (strcmp (arg
, "PIC") != 0)
2521 as_warn ("Unrecognized option following -K");
2535 md_show_usage (stream
)
2538 const struct sparc_opcode_arch
*arch
;
2540 fprintf(stream
, "SPARC options:\n");
2541 for (arch
= &sparc_opcode_archs
[0]; arch
->name
; arch
++)
2543 if (arch
!= &sparc_opcode_archs
[0])
2544 fprintf (stream
, " | ");
2545 fprintf (stream
, "-A%s", arch
->name
);
2547 fprintf (stream
, "\n-xarch=v8plus | -xarch=v8plusa\n");
2549 specify variant of SPARC architecture\n\
2550 -bump warn when assembler switches architectures\n\
2554 -k generate PIC\n");
2558 -KPIC generate PIC\n\
2559 -V print assembler version number\n\
2566 /* We have no need to default values of symbols. */
2570 md_undefined_symbol (name
)
2574 } /* md_undefined_symbol() */
2576 /* Round up a section size to the appropriate boundary. */
2578 md_section_align (segment
, size
)
2583 /* This is not right for ELF; a.out wants it, and COFF will force
2584 the alignment anyways. */
2585 valueT align
= ((valueT
) 1
2586 << (valueT
) bfd_get_section_alignment (stdoutput
, segment
));
2588 /* turn alignment value into a mask */
2590 newsize
= (size
+ align
) & ~align
;
2597 /* Exactly what point is a PC-relative offset relative TO?
2598 On the sparc, they're relative to the address of the offset, plus
2599 its size. This gets us to the following instruction.
2600 (??? Is this right? FIXME-SOON) */
2602 md_pcrel_from (fixP
)
2607 ret
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2608 if (! sparc_pic_code
2609 || fixP
->fx_addsy
== NULL
2610 || (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2611 ret
+= fixP
->fx_size
;
2615 /* end of tc-sparc.c */