1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 1995 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 *));
32 static enum sparc_architecture current_architecture
= v9
;
34 static enum sparc_architecture current_architecture
= v6
;
36 static int architecture_requested
;
37 static int warn_on_bump
;
39 /* Non-zero if we are generating PIC code. */
42 extern int target_big_endian
;
44 /* handle of the OPCODE hash table */
45 static struct hash_control
*op_hash
;
47 static void s_data1
PARAMS ((void));
48 static void s_seg
PARAMS ((int));
49 static void s_proc
PARAMS ((int));
50 static void s_reserve
PARAMS ((int));
51 static void s_common
PARAMS ((int));
53 const pseudo_typeS md_pseudo_table
[] =
55 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
56 {"common", s_common
, 0},
57 {"global", s_globl
, 0},
59 {"optim", s_ignore
, 0},
61 {"reserve", s_reserve
, 0},
72 /* these are specific to sparc/svr4 */
73 {"pushsection", obj_elf_section
, 0},
74 {"popsection", obj_elf_previous
, 0},
81 const int md_reloc_size
= 12; /* Size of relocation record */
83 /* This array holds the chars that always start a comment. If the
84 pre-processor is disabled, these aren't very useful */
85 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
87 /* This array holds the chars that only start a comment at the beginning of
88 a line. If the line seems to have the form '# 123 filename'
89 .line and .file directives will appear in the pre-processed output */
90 /* Note that input_file.c hand checks for '#' at the beginning of the
91 first line of the input file. This is because the compiler outputs
92 #NO_APP at the beginning of its output. */
93 /* Also note that comments started like this one will always
94 work if '/' isn't otherwise defined. */
95 const char line_comment_chars
[] = "#";
97 const char line_separator_chars
[] = "";
99 /* Chars that can be used to separate mant from exp in floating point nums */
100 const char EXP_CHARS
[] = "eE";
102 /* Chars that mean this number is a floating point constant */
105 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
107 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
108 changed in read.c. Ideally it shouldn't have to know about it at all,
109 but nothing is ideal around here. */
111 static unsigned char octal
[256];
112 #define isoctal(c) octal[(unsigned char) (c)]
113 static unsigned char toHex
[256];
118 unsigned long opcode
;
119 struct nlist
*nlistp
;
122 bfd_reloc_code_real_type reloc
;
125 struct sparc_it the_insn
, set_insn
;
128 in_signed_range (val
, max
)
129 bfd_signed_vma val
, max
;
141 static void print_insn
PARAMS ((struct sparc_it
*insn
));
143 static int getExpression
PARAMS ((char *str
));
145 static char *expr_end
;
146 static int special_case
;
149 * Instructions that require wierd handling because they're longer than
152 #define SPECIAL_CASE_SET 1
153 #define SPECIAL_CASE_FDIV 2
156 * sort of like s_lcomm
160 static int max_alignment
= 15;
175 name
= input_line_pointer
;
176 c
= get_symbol_end ();
177 p
= input_line_pointer
;
181 if (*input_line_pointer
!= ',')
183 as_bad ("Expected comma after name");
184 ignore_rest_of_line ();
188 ++input_line_pointer
;
190 if ((size
= get_absolute_expression ()) < 0)
192 as_bad ("BSS length (%d.) <0! Ignored.", size
);
193 ignore_rest_of_line ();
198 symbolP
= symbol_find_or_make (name
);
201 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
202 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
204 as_bad ("bad .reserve segment -- expected BSS segment");
208 if (input_line_pointer
[2] == '.')
209 input_line_pointer
+= 7;
211 input_line_pointer
+= 6;
214 if (*input_line_pointer
== ',')
216 ++input_line_pointer
;
219 if (*input_line_pointer
== '\n')
221 as_bad ("Missing alignment");
225 align
= get_absolute_expression ();
227 if (align
> max_alignment
)
229 align
= max_alignment
;
230 as_warn ("Alignment too large: %d. assumed.", align
);
236 as_warn ("Alignment negative. 0 assumed.");
239 record_alignment (bss_section
, align
);
241 /* convert to a power of 2 alignment */
242 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
246 as_bad ("Alignment not a power of 2");
247 ignore_rest_of_line ();
249 } /* not a power of two */
252 } /* if has optional alignment */
256 if (!S_IS_DEFINED (symbolP
)
258 && S_GET_OTHER (symbolP
) == 0
259 && S_GET_DESC (symbolP
) == 0
266 segT current_seg
= now_seg
;
267 subsegT current_subseg
= now_subseg
;
269 subseg_set (bss_section
, 1); /* switch to bss */
272 frag_align (align
, 0); /* do alignment */
274 /* detach from old frag */
275 if (S_GET_SEGMENT(symbolP
) == bss_section
)
276 symbolP
->sy_frag
->fr_symbol
= NULL
;
278 symbolP
->sy_frag
= frag_now
;
279 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
283 S_SET_SEGMENT (symbolP
, bss_section
);
285 subseg_set (current_seg
, current_subseg
);
290 as_warn("Ignoring attempt to re-define symbol %s",
291 S_GET_NAME (symbolP
));
292 } /* if not redefining */
294 demand_empty_rest_of_line ();
307 name
= input_line_pointer
;
308 c
= get_symbol_end ();
309 /* just after name is now '\0' */
310 p
= input_line_pointer
;
313 if (*input_line_pointer
!= ',')
315 as_bad ("Expected comma after symbol-name");
316 ignore_rest_of_line ();
319 input_line_pointer
++; /* skip ',' */
320 if ((temp
= get_absolute_expression ()) < 0)
322 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
323 ignore_rest_of_line ();
328 symbolP
= symbol_find_or_make (name
);
330 if (S_IS_DEFINED (symbolP
))
332 as_bad ("Ignoring attempt to re-define symbol");
333 ignore_rest_of_line ();
336 if (S_GET_VALUE (symbolP
) != 0)
338 if (S_GET_VALUE (symbolP
) != size
)
340 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
341 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
347 S_SET_VALUE (symbolP
, (valueT
) size
);
348 S_SET_EXTERNAL (symbolP
);
351 know (symbolP
->sy_frag
== &zero_address_frag
);
352 if (*input_line_pointer
!= ',')
354 as_bad ("Expected comma after common length");
355 ignore_rest_of_line ();
358 input_line_pointer
++;
360 if (*input_line_pointer
!= '"')
362 temp
= get_absolute_expression ();
364 if (temp
> max_alignment
)
366 temp
= max_alignment
;
367 as_warn ("Common alignment too large: %d. assumed", temp
);
373 as_warn ("Common alignment negative; 0 assumed");
385 old_subsec
= now_subseg
;
387 record_alignment (bss_section
, align
);
388 subseg_set (bss_section
, 0);
390 frag_align (align
, 0);
391 if (S_GET_SEGMENT (symbolP
) == bss_section
)
392 symbolP
->sy_frag
->fr_symbol
= 0;
393 symbolP
->sy_frag
= frag_now
;
394 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
397 S_SET_SEGMENT (symbolP
, bss_section
);
398 S_CLEAR_EXTERNAL (symbolP
);
399 subseg_set (old_sec
, old_subsec
);
405 S_SET_VALUE (symbolP
, (valueT
) size
);
407 S_SET_ALIGN (symbolP
, temp
);
409 S_SET_EXTERNAL (symbolP
);
410 /* should be common, but this is how gas does it for now */
411 S_SET_SEGMENT (symbolP
, bfd_und_section_ptr
);
416 input_line_pointer
++;
417 /* @@ Some use the dot, some don't. Can we get some consistency?? */
418 if (*input_line_pointer
== '.')
419 input_line_pointer
++;
420 /* @@ Some say data, some say bss. */
421 if (strncmp (input_line_pointer
, "bss\"", 4)
422 && strncmp (input_line_pointer
, "data\"", 5))
424 while (*--input_line_pointer
!= '"')
426 input_line_pointer
--;
427 goto bad_common_segment
;
429 while (*input_line_pointer
++ != '"')
431 goto allocate_common
;
433 demand_empty_rest_of_line ();
438 p
= input_line_pointer
;
439 while (*p
&& *p
!= '\n')
443 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
445 input_line_pointer
= p
;
446 ignore_rest_of_line ();
456 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
458 input_line_pointer
+= 6;
462 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
464 input_line_pointer
+= 6;
468 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
470 input_line_pointer
+= 7;
474 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
476 input_line_pointer
+= 5;
477 /* We only support 2 segments -- text and data -- for now, so
478 things in the "bss segment" will have to go into data for now.
479 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
480 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
483 as_bad ("Unknown segment type");
484 demand_empty_rest_of_line ();
490 subseg_set (data_section
, 1);
491 demand_empty_rest_of_line ();
498 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
500 ++input_line_pointer
;
502 ++input_line_pointer
;
507 struct priv_reg_entry
513 struct priv_reg_entry priv_reg_table
[] =
532 {"", -1}, /* end marker */
542 #define MEMBAR_MASKS_SIZE 7
544 static const struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
547 {"MemIssue", 8, 0x20},
548 {"Lookaside", 9, 0x10},
549 {"StoreStore", 10, 0x08},
550 {"LoadStore", 9, 0x04},
551 {"StoreLoad", 9, 0x02},
552 {"LoadLoad", 8, 0x01},
557 struct priv_reg_entry
*p
, *q
;
559 return strcmp (q
->name
, p
->name
);
564 /* This function is called once, at assembler startup time. It should
565 set up all the tables, etc. that the MD part of the assembler will need. */
569 register const char *retval
= NULL
;
571 register unsigned int i
= 0;
573 op_hash
= hash_new ();
575 while (i
< NUMOPCODES
)
577 const char *name
= sparc_opcodes
[i
].name
;
578 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
581 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
582 sparc_opcodes
[i
].name
, retval
);
587 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
589 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
590 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
595 while (i
< NUMOPCODES
596 && !strcmp (sparc_opcodes
[i
].name
, name
));
600 as_fatal ("Broken assembler. No assembly attempted.");
602 for (i
= '0'; i
< '8'; ++i
)
604 for (i
= '0'; i
<= '9'; ++i
)
606 for (i
= 'a'; i
<= 'f'; ++i
)
607 toHex
[i
] = i
+ 10 - 'a';
608 for (i
= 'A'; i
<= 'F'; ++i
)
609 toHex
[i
] = i
+ 10 - 'A';
612 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
613 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
616 target_big_endian
= 1;
629 /* See if "set" operand is absolute and small; skip sethi if so. */
630 if (special_case
== SPECIAL_CASE_SET
631 && the_insn
.exp
.X_op
== O_constant
)
633 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
634 && the_insn
.exp
.X_add_number
< (1 << 12))
636 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
637 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
638 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
639 special_case
= 0; /* No longer special */
640 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
645 /* put out the opcode */
646 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
648 /* put out the symbol-dependent stuff */
649 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
651 fix_new_exp (frag_now
, /* which frag */
652 (toP
- frag_now
->fr_literal
), /* where */
659 switch (special_case
)
661 case SPECIAL_CASE_SET
:
663 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
664 /* See if "set" operand has no low-order bits; skip OR if so. */
665 if (the_insn
.exp
.X_op
== O_constant
666 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
669 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
670 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
671 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
672 fix_new_exp (frag_now
, /* which frag */
673 (toP
- frag_now
->fr_literal
), /* where */
680 case SPECIAL_CASE_FDIV
:
681 /* According to information leaked from Sun, the "fdiv" instructions
682 on early SPARC machines would produce incorrect results sometimes.
683 The workaround is to add an fmovs of the destination register to
684 itself just after the instruction. This was true on machines
685 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
687 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
689 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
690 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
691 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
698 as_fatal ("failed sanity check.");
702 /* Implement big shift right. */
708 if (sizeof (bfd_vma
) <= 4 && amount
>= 32)
709 as_fatal ("Support for 64-bit arithmetic not compiled in.");
710 return val
>> amount
;
717 char *error_message
= "";
721 const struct sparc_opcode
*insn
;
723 unsigned long opcode
;
724 unsigned int mask
= 0;
727 long immediate_max
= 0;
729 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
747 as_fatal ("Unknown opcode: `%s'", str
);
749 insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
);
752 as_bad ("Unknown opcode: `%s'", str
);
762 opcode
= insn
->match
;
763 memset (&the_insn
, '\0', sizeof (the_insn
));
764 the_insn
.reloc
= BFD_RELOC_NONE
;
767 * Build the opcode, checking as we go to make
768 * sure that the operands match
770 for (args
= insn
->args
;; ++args
)
780 /* Parse a series of masks. */
786 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
787 if (!strncmp (s
, membar_masks
[i
].name
,
788 membar_masks
[i
].len
))
790 if (i
< MEMBAR_MASKS_SIZE
)
792 kmask
|= membar_masks
[i
].mask
;
793 s
+= membar_masks
[i
].len
;
797 error_message
= ": invalid membar mask name";
810 hold
= input_line_pointer
;
811 input_line_pointer
= s
;
813 send
= input_line_pointer
;
814 input_line_pointer
= hold
;
816 kmask
= exp
.X_add_number
;
817 if (exp
.X_op
!= O_constant
821 error_message
= ": invalid membar mask number";
828 opcode
|= SIMM13 (kmask
);
834 int prefetch_fcn
= 0;
836 /* Parse a prefetch function. */
840 if (!strncmp (s
, "n_reads", 7))
841 prefetch_fcn
= 0, s
+= 7;
842 else if (!strncmp (s
, "one_read", 8))
843 prefetch_fcn
= 1, s
+= 8;
844 else if (!strncmp (s
, "n_writes", 8))
845 prefetch_fcn
= 2, s
+= 8;
846 else if (!strncmp (s
, "one_write", 9))
847 prefetch_fcn
= 3, s
+= 9;
848 else if (!strncmp (s
, "page", 4))
849 prefetch_fcn
= 4, s
+= 4;
852 error_message
= ": invalid prefetch function name";
856 else if (isdigit (*s
))
860 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
864 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
866 error_message
= ": invalid prefetch function number";
872 error_message
= ": unrecognizable prefetch function";
875 opcode
|= RD (prefetch_fcn
);
881 /* Parse a privileged register. */
884 struct priv_reg_entry
*p
= priv_reg_table
;
885 unsigned int len
= 9999999; /* init to make gcc happy */
888 while (p
->name
[0] > s
[0])
890 while (p
->name
[0] == s
[0])
892 len
= strlen (p
->name
);
893 if (strncmp (p
->name
, s
, len
) == 0)
897 if (p
->name
[0] != s
[0])
899 error_message
= ": unrecognizable privileged register";
903 opcode
|= (p
->regnum
<< 14);
905 opcode
|= (p
->regnum
<< 25);
911 error_message
= ": unrecognizable privileged register";
918 if (strncmp (s
, "%asr", 4) == 0)
928 num
= num
* 10 + *s
- '0';
932 if (num
< 16 || 31 < num
)
934 error_message
= ": asr number must be between 15 and 31";
938 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
943 error_message
= ": expecting %asrN";
945 } /* if %asr followed by a number. */
952 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
953 immediate_max
= 0x03FF;
957 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
958 immediate_max
= 0x01FF;
962 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
967 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
972 if (*s
== 'p' && s
[1] == 'n')
980 if (*s
== 'p' && s
[1] == 't')
992 if (strncmp (s
, "%icc", 4) == 0)
1004 if (strncmp (s
, "%xcc", 4) == 0)
1016 if (strncmp (s
, "%fcc0", 5) == 0)
1028 if (strncmp (s
, "%fcc1", 5) == 0)
1040 if (strncmp (s
, "%fcc2", 5) == 0)
1052 if (strncmp (s
, "%fcc3", 5) == 0)
1060 if (strncmp (s
, "%pc", 3) == 0)
1068 if (strncmp (s
, "%tick", 5) == 0)
1076 case '\0': /* end of args */
1095 case '[': /* these must match exactly */
1103 case '#': /* must be at least one digit */
1106 while (isdigit (*s
))
1114 case 'C': /* coprocessor state register */
1115 if (strncmp (s
, "%csr", 4) == 0)
1122 case 'b': /* next operand is a coprocessor register */
1125 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1130 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1144 opcode
|= mask
<< 14;
1152 opcode
|= mask
<< 25;
1158 case 'r': /* next operand must be a register */
1167 case 'f': /* frame pointer */
1175 case 'g': /* global register */
1176 if (isoctal (c
= *s
++))
1183 case 'i': /* in register */
1184 if (isoctal (c
= *s
++))
1186 mask
= c
- '0' + 24;
1191 case 'l': /* local register */
1192 if (isoctal (c
= *s
++))
1194 mask
= (c
- '0' + 16);
1199 case 'o': /* out register */
1200 if (isoctal (c
= *s
++))
1202 mask
= (c
- '0' + 8);
1207 case 's': /* stack pointer */
1215 case 'r': /* any register */
1216 if (!isdigit (c
= *s
++))
1233 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1249 * Got the register, now figure out where
1250 * it goes in the opcode.
1256 opcode
|= mask
<< 14;
1264 opcode
|= mask
<< 25;
1268 opcode
|= (mask
<< 25) | (mask
<< 14);
1274 case 'e': /* next operand is a floating point register */
1289 && ((format
= *s
) == 'f')
1292 for (mask
= 0; isdigit (*s
); ++s
)
1294 mask
= 10 * mask
+ (*s
- '0');
1295 } /* read the number */
1303 } /* register must be even numbered */
1311 } /* register must be multiple of 4 */
1316 error_message
= ": There are only 64 f registers; [0-63]";
1322 } /* wrap high bit */
1326 error_message
= ": There are only 32 f registers; [0-31]";
1334 } /* if not an 'f' register. */
1342 opcode
|= RS1 (mask
);
1349 opcode
|= RS2 (mask
);
1355 opcode
|= RD (mask
);
1364 if (strncmp (s
, "%fsr", 4) == 0)
1371 case 'h': /* high 22 bits */
1372 the_insn
.reloc
= BFD_RELOC_HI22
;
1375 case 'l': /* 22 bit PC relative immediate */
1376 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1380 case 'L': /* 30 bit immediate */
1381 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1385 case 'n': /* 22 bit immediate */
1386 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1389 case 'i': /* 13 bit immediate */
1390 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1391 immediate_max
= 0x0FFF;
1400 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1402 the_insn
.reloc
= BFD_RELOC_HI22
;
1405 else if (c
== 'l' && s
[2] == 'o')
1407 the_insn
.reloc
= BFD_RELOC_LO10
;
1415 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1422 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1429 /* Note that if the getExpression() fails, we will still
1430 have created U entries in the symbol table for the
1431 'symbols' in the input string. Try not to create U
1432 symbols for registers, etc. */
1434 /* This stuff checks to see if the expression ends in
1435 +%reg. If it does, it removes the register from
1436 the expression, and re-sets 's' to point to the
1441 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1443 if (s1
!= s
&& isdigit (s1
[-1]))
1445 if (s1
[-2] == '%' && s1
[-3] == '+')
1449 (void) getExpression (s
);
1454 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1458 (void) getExpression (s
);
1465 (void) getExpression (s
);
1468 if (the_insn
.exp
.X_op
== O_constant
1469 && the_insn
.exp
.X_add_symbol
== 0
1470 && the_insn
.exp
.X_op_symbol
== 0)
1473 /* Handle %uhi/%ulo by moving the upper word to the lower
1474 one and pretending it's %hi/%lo. We also need to watch
1475 for %hi/%lo: the top word needs to be zeroed otherwise
1476 fixup_segment will complain the value is too big. */
1477 switch (the_insn
.reloc
)
1479 case BFD_RELOC_SPARC_HH22
:
1480 the_insn
.reloc
= BFD_RELOC_HI22
;
1481 the_insn
.exp
.X_add_number
= BSR (the_insn
.exp
.X_add_number
, 32);
1483 case BFD_RELOC_SPARC_HM10
:
1484 the_insn
.reloc
= BFD_RELOC_LO10
;
1485 the_insn
.exp
.X_add_number
= BSR (the_insn
.exp
.X_add_number
, 32);
1489 case BFD_RELOC_HI22
:
1490 case BFD_RELOC_LO10
:
1491 the_insn
.exp
.X_add_number
&= 0xffffffff;
1495 /* For pc-relative call instructions, we reject
1496 constants to get better code. */
1498 && the_insn
.reloc
== BFD_RELOC_32_PCREL_S2
1499 && in_signed_range (the_insn
.exp
.X_add_number
, 0x3fff)
1502 error_message
= ": PC-relative operand can't be a constant";
1505 /* Check for invalid constant values. Don't warn if
1506 constant was inside %hi or %lo, since these
1507 truncate the constant to fit. */
1508 if (immediate_max
!= 0
1509 && the_insn
.reloc
!= BFD_RELOC_LO10
1510 && the_insn
.reloc
!= BFD_RELOC_HI22
1511 && !in_signed_range (the_insn
.exp
.X_add_number
,
1516 /* Who knows? After relocation, we may be within
1517 range. Let the linker figure it out. */
1519 the_insn
.exp
.X_op
= O_symbol
;
1520 the_insn
.exp
.X_add_symbol
= section_symbol (absolute_section
);
1523 /* Immediate value is non-pcrel, and out of
1525 as_bad ("constant value %ld out of range (%ld .. %ld)",
1526 the_insn
.exp
.X_add_number
,
1527 ~immediate_max
, immediate_max
);
1531 /* Reset to prevent extraneous range check. */
1553 for (p
= s
+ 1; isalpha (*p
) || *p
== '_'; ++p
)
1557 asi
= sparc_encode_asi (s
);
1561 error_message
= ": invalid asi name";
1568 char *push
= input_line_pointer
;
1570 input_line_pointer
= s
;
1573 if (e
.X_op
!= O_constant
)
1575 error_message
= ": constant required for ASI";
1578 asi
= e
.X_add_number
;
1579 s
= input_line_pointer
;
1580 input_line_pointer
= push
;
1582 if (asi
< 0 || asi
> 255)
1584 error_message
= ": invalid asi number";
1588 opcode
|= ASI (asi
);
1590 } /* alternate space */
1593 if (strncmp (s
, "%psr", 4) == 0)
1600 case 'q': /* floating point queue */
1601 if (strncmp (s
, "%fq", 3) == 0)
1608 case 'Q': /* coprocessor queue */
1609 if (strncmp (s
, "%cq", 3) == 0)
1617 if (strcmp (str
, "set") == 0)
1619 special_case
= SPECIAL_CASE_SET
;
1622 else if (strncmp (str
, "fdiv", 4) == 0)
1624 special_case
= SPECIAL_CASE_FDIV
;
1631 if (strncmp (s
, "%asi", 4) != 0)
1637 if (strncmp (s
, "%fprs", 5) != 0)
1643 if (strncmp (s
, "%ccr", 4) != 0)
1650 if (strncmp (s
, "%tbr", 4) != 0)
1656 if (strncmp (s
, "%wim", 4) != 0)
1664 char *push
= input_line_pointer
;
1667 input_line_pointer
= s
;
1669 if (e
.X_op
== O_constant
)
1671 int n
= e
.X_add_number
;
1672 if (n
!= e
.X_add_number
|| (n
& ~0x1ff) != 0)
1673 as_bad ("OPF immediate operand out of range (0-0x1ff)");
1675 opcode
|= e
.X_add_number
<< 5;
1678 as_bad ("non-immediate OPF operand, ignored");
1679 s
= input_line_pointer
;
1680 input_line_pointer
= push
;
1686 if (strncmp (s
, "%y", 2) != 0)
1692 as_fatal ("failed sanity check.");
1693 } /* switch on arg code */
1695 } /* for each arg that we expect */
1699 /* Args don't match. */
1700 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1701 && (insn
->name
== insn
[1].name
1702 || !strcmp (insn
->name
, insn
[1].name
)))
1710 as_bad ("Illegal operands%s", error_message
);
1716 if (insn
->architecture
> current_architecture
1717 || (insn
->architecture
!= current_architecture
1718 && current_architecture
> v8
))
1720 if ((!architecture_requested
|| warn_on_bump
)
1721 && !ARCHITECTURES_CONFLICT_P (current_architecture
,
1723 && !ARCHITECTURES_CONFLICT_P (insn
->architecture
,
1724 current_architecture
))
1728 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1729 architecture_pname
[current_architecture
],
1730 architecture_pname
[insn
->architecture
],
1734 current_architecture
= insn
->architecture
;
1738 as_bad ("Architecture mismatch on \"%s\".", str
);
1739 as_tsktsk (" (Requires %s; current architecture is %s.)",
1740 architecture_pname
[insn
->architecture
],
1741 architecture_pname
[current_architecture
]);
1743 } /* if bump ok else error */
1744 } /* if architecture higher */
1748 } /* forever looking for a match */
1750 the_insn
.opcode
= opcode
;
1760 save_in
= input_line_pointer
;
1761 input_line_pointer
= str
;
1762 seg
= expression (&the_insn
.exp
);
1763 if (seg
!= absolute_section
1764 && seg
!= text_section
1765 && seg
!= data_section
1766 && seg
!= bss_section
1767 && seg
!= undefined_section
)
1769 the_insn
.error
= "bad segment";
1770 expr_end
= input_line_pointer
;
1771 input_line_pointer
= save_in
;
1774 expr_end
= input_line_pointer
;
1775 input_line_pointer
= save_in
;
1777 } /* getExpression() */
1781 This is identical to the md_atof in m68k.c. I think this is right,
1784 Turn a string in input_line_pointer into a floating point constant of type
1785 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1786 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1789 /* Equal to MAX_PRECISION in atof-ieee.c */
1790 #define MAX_LITTLENUMS 6
1793 md_atof (type
, litP
, sizeP
)
1799 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1800 LITTLENUM_TYPE
*wordP
;
1833 return "Bad call to MD_ATOF()";
1835 t
= atof_ieee (input_line_pointer
, type
, words
);
1837 input_line_pointer
= t
;
1838 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1839 for (wordP
= words
; prec
--;)
1841 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1842 litP
+= sizeof (LITTLENUM_TYPE
);
1848 * Write out big-endian.
1851 md_number_to_chars (buf
, val
, n
)
1856 number_to_chars_bigendian (buf
, val
, n
);
1859 /* Apply a fixS to the frags, now that we know the value it ought to
1863 md_apply_fix (fixP
, value
)
1867 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1872 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1874 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1877 /* FIXME: SPARC ELF relocations don't use an addend in the data
1878 field itself. This whole approach should be somehow combined
1879 with the calls to bfd_perform_relocation. Also, the value passed
1880 in by fixup_segment includes the value of a defined symbol. We
1881 don't want to include the value of an externally visible symbol. */
1882 if (fixP
->fx_addsy
!= NULL
)
1884 if ((S_IS_EXTERN (fixP
->fx_addsy
)
1885 || (sparc_pic_code
&& ! fixP
->fx_pcrel
))
1886 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
1887 && S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
1888 && ! bfd_is_com_section (S_GET_SEGMENT (fixP
->fx_addsy
)))
1889 fixP
->fx_addnumber
-= S_GET_VALUE (fixP
->fx_addsy
);
1894 /* This is a hack. There should be a better way to
1895 handle this. Probably in terms of howto fields, once
1896 we can look at these fixups in terms of howtos. */
1897 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1898 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1901 /* FIXME: More ridiculous gas reloc hacking. If we are going to
1902 generate a reloc, then we just want to let the reloc addend set
1903 the value. We do not want to also stuff the addend into the
1904 object file. Including the addend in the object file works when
1905 doing a static link, because the linker will ignore the object
1906 file contents. However, the dynamic linker does not ignore the
1907 object file contents. */
1908 if (fixP
->fx_addsy
!= NULL
1909 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
)
1912 /* When generating PIC code, we do not want an addend for a reloc
1913 against a local symbol. We adjust fx_addnumber to cancel out the
1914 value already included in val, and to also cancel out the
1915 adjustment which bfd_install_relocation will create. */
1917 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
1918 && fixP
->fx_addsy
!= NULL
1919 && ! S_IS_COMMON (fixP
->fx_addsy
)
1920 && (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) == 0)
1921 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
1924 switch (fixP
->fx_r_type
)
1938 case BFD_RELOC_32_PCREL_S2
:
1940 if (! sparc_pic_code
1941 || fixP
->fx_addsy
== NULL
1942 || (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
1944 buf
[0] |= (val
>> 24) & 0x3f;
1945 buf
[1] = (val
>> 16);
1953 bfd_vma valh
= BSR (val
, 32);
1954 buf
[0] = valh
>> 24;
1955 buf
[1] = valh
>> 16;
1965 case BFD_RELOC_SPARC_11
:
1966 if (((val
> 0) && (val
& ~0x7ff))
1967 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1969 as_bad ("relocation overflow.");
1972 buf
[2] |= (val
>> 8) & 0x7;
1973 buf
[3] = val
& 0xff;
1976 case BFD_RELOC_SPARC_10
:
1977 if (((val
> 0) && (val
& ~0x3ff))
1978 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1980 as_bad ("relocation overflow.");
1983 buf
[2] |= (val
>> 8) & 0x3;
1984 buf
[3] = val
& 0xff;
1987 case BFD_RELOC_SPARC_WDISP16
:
1988 if (((val
> 0) && (val
& ~0x3fffc))
1989 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1991 as_bad ("relocation overflow.");
1994 val
= (val
>>= 2) + 1;
1995 buf
[1] |= ((val
>> 14) & 0x3) << 4;
1996 buf
[2] |= (val
>> 8) & 0x3f;
1997 buf
[3] = val
& 0xff;
2000 case BFD_RELOC_SPARC_WDISP19
:
2001 if (((val
> 0) && (val
& ~0x1ffffc))
2002 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2004 as_bad ("relocation overflow.");
2007 val
= (val
>>= 2) + 1;
2008 buf
[1] |= (val
>> 16) & 0x7;
2009 buf
[2] = (val
>> 8) & 0xff;
2010 buf
[3] = val
& 0xff;
2013 case BFD_RELOC_SPARC_HH22
:
2014 val
= BSR (val
, 32);
2015 /* intentional fallthrough */
2019 case BFD_RELOC_SPARC_LM22
:
2021 case BFD_RELOC_HI22
:
2022 if (!fixP
->fx_addsy
)
2024 buf
[1] |= (val
>> 26) & 0x3f;
2035 case BFD_RELOC_SPARC22
:
2036 if (val
& ~0x003fffff)
2038 as_bad ("relocation overflow");
2040 buf
[1] |= (val
>> 16) & 0x3f;
2042 buf
[3] = val
& 0xff;
2046 case BFD_RELOC_SPARC_HM10
:
2047 val
= BSR (val
, 32);
2048 /* intentional fallthrough */
2051 case BFD_RELOC_LO10
:
2052 if (!fixP
->fx_addsy
)
2054 buf
[2] |= (val
>> 8) & 0x03;
2061 case BFD_RELOC_SPARC13
:
2062 if (! in_signed_range (val
, 0x1fff))
2063 as_bad ("relocation overflow");
2065 buf
[2] |= (val
>> 8) & 0x1f;
2069 case BFD_RELOC_SPARC_WDISP22
:
2070 val
= (val
>> 2) + 1;
2072 case BFD_RELOC_SPARC_BASE22
:
2073 buf
[1] |= (val
>> 16) & 0x3f;
2078 case BFD_RELOC_NONE
:
2080 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2084 /* Are we finished with this relocation now? */
2085 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
2091 /* Translate internal representation of relocation info to BFD target
2094 tc_gen_reloc (section
, fixp
)
2099 bfd_reloc_code_real_type code
;
2101 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2102 assert (reloc
!= 0);
2104 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2105 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2107 switch (fixp
->fx_r_type
)
2111 case BFD_RELOC_HI22
:
2112 case BFD_RELOC_LO10
:
2113 case BFD_RELOC_32_PCREL_S2
:
2114 case BFD_RELOC_SPARC13
:
2115 case BFD_RELOC_SPARC_BASE13
:
2116 case BFD_RELOC_SPARC_WDISP16
:
2117 case BFD_RELOC_SPARC_WDISP19
:
2118 case BFD_RELOC_SPARC_WDISP22
:
2120 case BFD_RELOC_SPARC_10
:
2121 case BFD_RELOC_SPARC_11
:
2122 case BFD_RELOC_SPARC_HH22
:
2123 case BFD_RELOC_SPARC_HM10
:
2124 case BFD_RELOC_SPARC_LM22
:
2125 case BFD_RELOC_SPARC_PC_HH22
:
2126 case BFD_RELOC_SPARC_PC_HM10
:
2127 case BFD_RELOC_SPARC_PC_LM22
:
2128 code
= fixp
->fx_r_type
;
2134 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
2135 /* If we are generating PIC code, we need to generate a different
2139 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
2141 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
2148 case BFD_RELOC_32_PCREL_S2
:
2149 if (! S_IS_DEFINED (fixp
->fx_addsy
)
2150 || S_IS_EXTERNAL (fixp
->fx_addsy
))
2151 code
= BFD_RELOC_SPARC_WPLT30
;
2153 case BFD_RELOC_HI22
:
2154 if (fixp
->fx_addsy
!= NULL
2155 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
2156 code
= BFD_RELOC_SPARC_PC22
;
2158 code
= BFD_RELOC_SPARC_GOT22
;
2160 case BFD_RELOC_LO10
:
2161 if (fixp
->fx_addsy
!= NULL
2162 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
2163 code
= BFD_RELOC_SPARC_PC10
;
2165 code
= BFD_RELOC_SPARC_GOT10
;
2167 case BFD_RELOC_SPARC13
:
2168 code
= BFD_RELOC_SPARC_GOT13
;
2174 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
2176 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2177 if (reloc
->howto
== 0)
2179 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2180 "internal error: can't export reloc type %d (`%s')",
2181 fixp
->fx_r_type
, bfd_get_reloc_code_name (code
));
2185 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2188 if (reloc
->howto
->pc_relative
== 0
2189 || code
== BFD_RELOC_SPARC_PC10
2190 || code
== BFD_RELOC_SPARC_PC22
)
2191 reloc
->addend
= fixp
->fx_addnumber
;
2193 reloc
->addend
= fixp
->fx_offset
- reloc
->address
;
2195 #else /* elf or coff */
2197 if (reloc
->howto
->pc_relative
== 0
2198 || code
== BFD_RELOC_SPARC_PC10
2199 || code
== BFD_RELOC_SPARC_PC22
)
2200 reloc
->addend
= fixp
->fx_addnumber
;
2201 else if ((fixp
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2202 reloc
->addend
= (section
->vma
2203 + fixp
->fx_addnumber
2204 + md_pcrel_from (fixp
));
2206 reloc
->addend
= fixp
->fx_offset
;
2214 /* for debugging only */
2217 struct sparc_it
*insn
;
2219 const char *const Reloc
[] = {
2248 fprintf (stderr
, "ERROR: %s\n");
2249 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2250 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2251 fprintf (stderr
, "exp = {\n");
2252 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2253 ((insn
->exp
.X_add_symbol
!= NULL
)
2254 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2255 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2258 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2259 ((insn
->exp
.X_op_symbol
!= NULL
)
2260 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2261 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2264 fprintf (stderr
, "\t\tX_add_number = %d\n",
2265 insn
->exp
.X_add_number
);
2266 fprintf (stderr
, "}\n");
2272 * Invocation line includes a switch not recognized by the base assembler.
2273 * See if it's a processor-specific option. These are:
2276 * Warn on architecture bumps. See also -A.
2278 * -Av6, -Av7, -Av8, -Av9, -Asparclite
2279 * Select the architecture. Instructions or features not
2280 * supported by the selected architecture cause fatal errors.
2282 * The default is to start at v6, and bump the architecture up
2283 * whenever an instruction is seen at a higher level.
2285 * If -bump is specified, a warning is printing when bumping to
2288 * If an architecture is specified, all instructions must match
2289 * that architecture. Any higher level instructions are flagged
2292 * if both an architecture and -bump are specified, the
2293 * architecture starts at the specified level, but bumps are
2297 * Bumping between incompatible architectures is always an
2298 * error. For example, from sparclite to v9.
2302 CONST
char *md_shortopts
= "A:K:VQ:sq";
2305 CONST
char *md_shortopts
= "A:k";
2307 CONST
char *md_shortopts
= "A:";
2310 struct option md_longopts
[] = {
2311 #define OPTION_BUMP (OPTION_MD_BASE)
2312 {"bump", no_argument
, NULL
, OPTION_BUMP
},
2313 #define OPTION_SPARC (OPTION_MD_BASE + 1)
2314 {"sparc", no_argument
, NULL
, OPTION_SPARC
},
2315 {NULL
, no_argument
, NULL
, 0}
2317 size_t md_longopts_size
= sizeof(md_longopts
);
2320 md_parse_option (c
, arg
)
2335 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2337 if (strcmp (p
, *arch
) == 0)
2343 as_bad ("invalid architecture -A%s", p
);
2348 enum sparc_architecture new_arch
= arch
- architecture_pname
;
2352 as_error ("v9 support not compiled in");
2356 current_architecture
= new_arch
;
2357 architecture_requested
= 1;
2363 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2374 print_version_id ();
2378 /* Qy - do emit .comment
2379 Qn - do not emit .comment */
2383 /* use .stab instead of .stab.excl */
2387 /* quick -- native assembler does fewer checks */
2391 if (strcmp (arg
, "PIC") != 0)
2392 as_warn ("Unrecognized option following -K");
2406 md_show_usage (stream
)
2410 fprintf(stream
, "SPARC options:\n");
2411 for (arch
= architecture_pname
; *arch
; arch
++)
2413 if (arch
!= architecture_pname
)
2414 fprintf (stream
, " | ");
2415 fprintf (stream
, "-A%s", *arch
);
2417 fprintf (stream
, "\n\
2418 specify variant of SPARC architecture\n\
2419 -bump warn when assembler switches architectures\n\
2423 -k generate PIC\n");
2427 -KPIC generate PIC\n\
2428 -V print assembler version number\n\
2435 /* We have no need to default values of symbols. */
2439 md_undefined_symbol (name
)
2443 } /* md_undefined_symbol() */
2445 /* Round up a section size to the appropriate boundary. */
2447 md_section_align (segment
, size
)
2452 /* This is not right for ELF; a.out wants it, and COFF will force
2453 the alignment anyways. */
2454 valueT align
= ((valueT
) 1
2455 << (valueT
) bfd_get_section_alignment (stdoutput
, segment
));
2457 /* turn alignment value into a mask */
2459 newsize
= (size
+ align
) & ~align
;
2466 /* Exactly what point is a PC-relative offset relative TO?
2467 On the sparc, they're relative to the address of the offset, plus
2468 its size. This gets us to the following instruction.
2469 (??? Is this right? FIXME-SOON) */
2471 md_pcrel_from (fixP
)
2476 ret
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2477 if (! sparc_pic_code
2478 || fixP
->fx_addsy
== NULL
2479 || (fixP
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
2480 ret
+= fixP
->fx_size
;
2484 /* end of tc-sparc.c */