1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 1990, 1991, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* careful, this file includes data *declarations* */
28 #include "opcode/sparc.h"
32 void md_number_to_chars ();
35 void md_create_short_jump ();
36 void md_create_long_jump ();
37 int md_estimate_size_before_relax ();
38 void md_ri_to_chars ();
39 symbolS
*md_undefined_symbol ();
40 static void sparc_ip ();
42 static enum sparc_architecture current_architecture
= v6
;
43 static int architecture_requested
;
44 static int warn_on_bump
;
46 extern int target_big_endian
;
48 const relax_typeS md_relax_table
[1];
50 /* handle of the OPCODE hash table */
51 static struct hash_control
*op_hash
= NULL
;
53 static void s_seg (), s_proc (), s_data1 (), s_reserve (), s_common ();
54 extern void s_globl (), s_long (), s_short (), s_space (), cons ();
55 extern void s_align_bytes (), s_ignore (), s_local();
56 /* start-sanitize-v9 */
58 static void s_xword ();
62 /* Ugly hack to keep non-BFD version working. */
64 #define BFD_RELOC_NONE NO_RELOC
65 #define BFD_RELOC_32 RELOC_32
66 #define BFD_RELOC_HI22 RELOC_HI22
67 #define BFD_RELOC_LO10 RELOC_LO10
68 #define BFD_RELOC_SPARC_WDISP22 RELOC_WDISP22
69 #define BFD_RELOC_32_PCREL_S2 RELOC_WDISP30
70 #define BFD_RELOC_SPARC22 RELOC_22
71 #define BFD_RELOC_SPARC_BASE13 RELOC_BASE13
72 #define BFD_RELOC_SPARC13 RELOC_13
73 #define BFD_RELOC_SPARC_BASE22 RELOC_BASE22
74 #define subseg_set subseg_new
77 const pseudo_typeS md_pseudo_table
[] =
79 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
80 {"common", s_common
, 0},
81 {"global", s_globl
, 0},
83 {"optim", s_ignore
, 0},
85 {"reserve", s_reserve
, 0},
89 /* start-sanitize-v9 */
91 {"xword", s_xword
, 0},
98 {"local", s_local
, 0},
99 /* these are specific to sparc/svr4 */
100 {"pushsection", obj_elf_section
, 0},
101 {"popsection", obj_elf_previous
, 0},
108 const int md_short_jump_size
= 4;
109 const int md_long_jump_size
= 4;
110 const int md_reloc_size
= 12; /* Size of relocation record */
112 /* This array holds the chars that always start a comment. If the
113 pre-processor is disabled, these aren't very useful */
114 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
116 /* This array holds the chars that only start a comment at the beginning of
117 a line. If the line seems to have the form '# 123 filename'
118 .line and .file directives will appear in the pre-processed output */
119 /* Note that input_file.c hand checks for '#' at the beginning of the
120 first line of the input file. This is because the compiler outputs
121 #NO_APP at the beginning of its output. */
122 /* Also note that comments started like this one will always
123 work if '/' isn't otherwise defined. */
124 const char line_comment_chars
[] = "#";
126 const char line_separator_chars
[] = "";
128 /* Chars that can be used to separate mant from exp in floating point nums */
129 const char EXP_CHARS
[] = "eE";
131 /* Chars that mean this number is a floating point constant */
134 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
136 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
137 changed in read.c . Ideally it shouldn't have to know about it at all,
138 but nothing is ideal around here.
141 static unsigned char octal
[256];
142 #define isoctal(c) octal[c]
143 static unsigned char toHex
[256];
148 unsigned long opcode
;
149 struct nlist
*nlistp
;
153 bfd_reloc_code_real_type reloc
;
155 enum reloc_type reloc
;
159 struct sparc_it the_insn
, set_insn
;
162 static void print_insn
PARAMS ((struct sparc_it
*insn
));
164 static int getExpression
PARAMS ((char *str
));
166 static char *expr_end
;
167 static int special_case
;
170 * Instructions that require wierd handling because they're longer than
173 #define SPECIAL_CASE_SET 1
174 #define SPECIAL_CASE_FDIV 2
177 * sort of like s_lcomm
180 static int max_alignment
= 15;
193 name
= input_line_pointer
;
194 c
= get_symbol_end ();
195 p
= input_line_pointer
;
199 if (*input_line_pointer
!= ',')
201 as_bad ("Expected comma after name");
202 ignore_rest_of_line ();
206 ++input_line_pointer
;
208 if ((size
= get_absolute_expression ()) < 0)
210 as_bad ("BSS length (%d.) <0! Ignored.", size
);
211 ignore_rest_of_line ();
216 symbolP
= symbol_find_or_make (name
);
219 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
220 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
222 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
226 if (input_line_pointer
[2] == '.')
227 input_line_pointer
+= 7;
229 input_line_pointer
+= 6;
232 if (*input_line_pointer
== ',')
234 ++input_line_pointer
;
237 if (*input_line_pointer
== '\n')
239 as_bad ("Missing alignment");
243 align
= get_absolute_expression ();
244 if (align
> max_alignment
)
246 align
= max_alignment
;
247 as_warn ("Alignment too large: %d. assumed.", align
);
252 as_warn ("Alignment negative. 0 assumed.");
255 record_alignment (bss_section
, align
);
257 /* convert to a power of 2 alignment */
258 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
262 as_bad ("Alignment not a power of 2");
263 ignore_rest_of_line ();
265 } /* not a power of two */
268 } /* if has optional alignment */
272 if ((S_GET_SEGMENT (symbolP
) == bss_section
273 || !S_IS_DEFINED (symbolP
))
275 && S_GET_OTHER (symbolP
) == 0
276 && S_GET_DESC (symbolP
) == 0
283 segT current_seg
= now_seg
;
284 subsegT current_subseg
= now_subseg
;
286 subseg_set (bss_section
, 1); /* switch to bss */
289 frag_align (align
, 0); /* do alignment */
291 /* detach from old frag */
292 if (S_GET_SEGMENT(symbolP
) == bss_section
)
293 symbolP
->sy_frag
->fr_symbol
= NULL
;
295 symbolP
->sy_frag
= frag_now
;
296 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
300 S_SET_SEGMENT (symbolP
, bss_section
);
302 subseg_set (current_seg
, current_subseg
);
307 as_warn("Ignoring attempt to re-define symbol %s.", name
);
308 } /* if not redefining */
310 demand_empty_rest_of_line ();
314 /* Currently used only by Solaris 2. */
324 name
= input_line_pointer
;
325 c
= get_symbol_end ();
326 symbolP
= symbol_find_or_make (name
);
327 *input_line_pointer
= c
;
329 S_CLEAR_EXTERNAL (symbolP
);
333 input_line_pointer
++;
335 if (*input_line_pointer
== '\n')
340 demand_empty_rest_of_line ();
353 name
= input_line_pointer
;
354 c
= get_symbol_end ();
355 /* just after name is now '\0' */
356 p
= input_line_pointer
;
359 if (*input_line_pointer
!= ',')
361 as_bad ("Expected comma after symbol-name");
362 ignore_rest_of_line ();
365 input_line_pointer
++; /* skip ',' */
366 if ((temp
= get_absolute_expression ()) < 0)
368 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
369 ignore_rest_of_line ();
374 symbolP
= symbol_find_or_make (name
);
376 if (S_IS_DEFINED (symbolP
))
378 as_bad ("Ignoring attempt to re-define symbol");
379 ignore_rest_of_line ();
382 if (S_GET_VALUE (symbolP
) != 0)
384 if (S_GET_VALUE (symbolP
) != size
)
386 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
387 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
393 S_SET_VALUE (symbolP
, size
);
394 S_SET_EXTERNAL (symbolP
);
397 know (symbolP
->sy_frag
== &zero_address_frag
);
398 if (*input_line_pointer
!= ',')
400 as_bad ("Expected comma after common length");
401 ignore_rest_of_line ();
404 input_line_pointer
++;
406 if (*input_line_pointer
!= '"')
408 temp
= get_absolute_expression ();
409 if (temp
> max_alignment
)
411 temp
= max_alignment
;
412 as_warn ("Common alignment too large: %d. assumed", temp
);
417 as_warn ("Common alignment negative; 0 assumed");
429 old_subsec
= now_subseg
;
431 record_alignment (bss_section
, align
);
432 subseg_set (bss_section
, 0);
434 frag_align (align
, 0);
435 if (S_GET_SEGMENT (symbolP
) == bss_section
)
436 symbolP
->sy_frag
->fr_symbol
= 0;
437 symbolP
->sy_frag
= frag_now
;
438 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
441 S_SET_SEGMENT (symbolP
, bss_section
);
442 S_CLEAR_EXTERNAL (symbolP
);
443 subseg_set (old_sec
, old_subsec
);
449 S_SET_VALUE (symbolP
, size
);
450 S_SET_EXTERNAL (symbolP
);
451 /* should be common, but this is how gas does it for now */
452 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
457 input_line_pointer
++;
458 /* @@ Some use the dot, some don't. Can we get some consistency?? */
459 if (*input_line_pointer
== '.')
460 input_line_pointer
++;
461 /* @@ Some say data, some say bss. */
462 if (strncmp (input_line_pointer
, "bss\"", 4)
463 && strncmp (input_line_pointer
, "data\"", 5))
465 while (*--input_line_pointer
!= '"')
467 input_line_pointer
--;
468 goto bad_common_segment
;
470 while (*input_line_pointer
++ != '"')
472 goto allocate_common
;
474 demand_empty_rest_of_line ();
479 p
= input_line_pointer
;
480 while (*p
&& *p
!= '\n')
484 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
486 input_line_pointer
= p
;
487 ignore_rest_of_line ();
496 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
498 input_line_pointer
+= 6;
502 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
504 input_line_pointer
+= 6;
508 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
510 input_line_pointer
+= 7;
514 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
516 input_line_pointer
+= 5;
517 /* We only support 2 segments -- text and data -- for now, so
518 things in the "bss segment" will have to go into data for now.
519 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
520 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
523 as_bad ("Unknown segment type");
524 demand_empty_rest_of_line ();
531 subseg_set (data_section
, 1);
532 demand_empty_rest_of_line ();
539 extern char is_end_of_line
[];
541 while (!is_end_of_line
[*input_line_pointer
])
543 ++input_line_pointer
;
545 ++input_line_pointer
;
549 /* start-sanitize-v9 */
555 if (isdigit (*input_line_pointer
))
561 struct priv_reg_entry
567 struct priv_reg_entry priv_reg_table
[] =
586 {"", -1}, /* end marker */
596 #define MEMBAR_MASKS_SIZE 7
598 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
601 {"MemIssue", 8, 0x20},
602 {"Lookaside", 9, 0x10},
603 {"StoreStore", 10, 0x08},
604 {"LoadStore", 9, 0x04},
605 {"StoreLoad", 9, 0x02},
606 {"LoadLoad", 8, 0x01},
611 struct priv_reg_entry
*p
, *q
;
613 return strcmp (q
->name
, p
->name
);
617 /* end-sanitize-v9 */
619 /* This function is called once, at assembler startup time. It should
620 set up all the tables, etc. that the MD part of the assembler will need. */
624 register char *retval
= NULL
;
626 register unsigned int i
= 0;
628 op_hash
= hash_new ();
630 as_fatal ("Virtual memory exhausted");
632 while (i
< NUMOPCODES
)
634 const char *name
= sparc_opcodes
[i
].name
;
635 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
636 if (retval
!= NULL
&& *retval
!= '\0')
638 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
639 sparc_opcodes
[i
].name
, retval
);
644 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
646 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
647 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
652 while (i
< NUMOPCODES
653 && !strcmp (sparc_opcodes
[i
].name
, name
));
657 as_fatal ("Broken assembler. No assembly attempted.");
659 for (i
= '0'; i
< '8'; ++i
)
661 for (i
= '0'; i
<= '9'; ++i
)
663 for (i
= 'a'; i
<= 'f'; ++i
)
664 toHex
[i
] = i
+ 10 - 'a';
665 for (i
= 'A'; i
<= 'F'; ++i
)
666 toHex
[i
] = i
+ 10 - 'A';
668 /* start-sanitize-v9 */
671 current_architecture
= v9
;
674 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
675 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
677 /* end-sanitize-v9 */
679 target_big_endian
= 1;
698 /* See if "set" operand is absolute and small; skip sethi if so. */
699 if (special_case
== SPECIAL_CASE_SET
700 && the_insn
.exp
.X_op
== O_constant
)
702 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
703 && the_insn
.exp
.X_add_number
< (1 << 12))
705 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
706 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
707 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
708 special_case
= 0; /* No longer special */
709 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
714 /* put out the opcode */
715 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
717 /* put out the symbol-dependent stuff */
718 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
720 fix_new_exp (frag_now
, /* which frag */
721 (toP
- frag_now
->fr_literal
), /* where */
728 switch (special_case
)
730 case SPECIAL_CASE_SET
:
732 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
733 /* See if "set" operand has no low-order bits; skip OR if so. */
734 if (the_insn
.exp
.X_op
== O_constant
735 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
738 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
739 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
740 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
741 fix_new_exp (frag_now
, /* which frag */
742 (toP
- frag_now
->fr_literal
), /* where */
749 case SPECIAL_CASE_FDIV
:
750 /* According to information leaked from Sun, the "fdiv" instructions
751 on early SPARC machines would produce incorrect results sometimes.
752 The workaround is to add an fmovs of the destination register to
753 itself just after the instruction. This was true on machines
754 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
756 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
758 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
759 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
760 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
767 as_fatal ("failed sanity check.");
769 } /* md_assemble() */
775 char *error_message
= "";
779 struct sparc_opcode
*insn
;
781 unsigned long opcode
;
782 unsigned int mask
= 0;
785 long immediate_max
= 0;
787 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
805 as_bad ("Unknown opcode: `%s'", str
);
808 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
810 as_bad ("Unknown opcode: `%s'", str
);
820 opcode
= insn
->match
;
821 memset (&the_insn
, '\0', sizeof (the_insn
));
822 the_insn
.reloc
= BFD_RELOC_NONE
;
825 * Build the opcode, checking as we go to make
826 * sure that the operands match
828 for (args
= insn
->args
;; ++args
)
833 /* start-sanitize-v9 */
840 /* Parse a series of masks. */
846 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
847 if (!strncmp (s
, membar_masks
[i
].name
,
848 membar_masks
[i
].len
))
850 if (i
< MEMBAR_MASKS_SIZE
)
852 mask
|= membar_masks
[i
].mask
;
853 s
+= membar_masks
[i
].len
;
857 error_message
= ": invalid membar mask name";
864 else if (isdigit (*s
))
868 mask
= mask
* 10 + *s
- '0';
872 if (mask
< 0 || mask
> 127)
874 error_message
= ": invalid membar mask number";
880 error_message
= ": unrecognizable membar mask";
883 opcode
|= SIMM13 (mask
);
889 int prefetch_fcn
= 0;
891 /* Parse a prefetch function. */
895 if (!strncmp (s
, "n_reads", 7))
896 prefetch_fcn
= 0, s
+= 7;
897 else if (!strncmp (s
, "one_read", 8))
898 prefetch_fcn
= 1, s
+= 8;
899 else if (!strncmp (s
, "n_writes", 8))
900 prefetch_fcn
= 2, s
+= 8;
901 else if (!strncmp (s
, "one_write", 9))
902 prefetch_fcn
= 3, s
+= 9;
903 else if (!strncmp (s
, "page", 4))
904 prefetch_fcn
= 4, s
+= 4;
907 error_message
= ": invalid prefetch function name";
911 else if (isdigit (*s
))
915 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
919 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
921 error_message
= ": invalid prefetch function number";
927 error_message
= ": unrecognizable prefetch function";
930 opcode
|= RD (prefetch_fcn
);
936 /* Parse a privileged register. */
939 struct priv_reg_entry
*p
= priv_reg_table
;
940 int len
= 9999999; /* init to make gcc happy */
943 while (p
->name
[0] > s
[0])
945 while (p
->name
[0] == s
[0])
947 len
= strlen (p
->name
);
948 if (strncmp (p
->name
, s
, len
) == 0)
952 if (p
->name
[0] != s
[0])
954 error_message
= ": unrecognizable privileged register";
958 opcode
|= (p
->regnum
<< 14);
960 opcode
|= (p
->regnum
<< 25);
966 error_message
= ": unrecognizable privileged register";
970 /* end-sanitize-v9 */
974 if (strncmp (s
, "%asr", 4) == 0)
984 num
= num
* 10 + *s
- '0';
988 if (num
< 16 || 31 < num
)
990 error_message
= ": asr number must be between 15 and 31";
994 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
999 error_message
= ": expecting %asrN";
1001 } /* if %asr followed by a number. */
1006 /* start-sanitize-v9 */
1009 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1010 immediate_max
= 0x03FF;
1014 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1015 immediate_max
= 0x01FF;
1019 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1024 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1029 if (*s
== 'p' && s
[1] == 'n')
1037 if (*s
== 'p' && s
[1] == 't')
1049 if (strncmp (s
, "%icc", 4) == 0)
1061 if (strncmp (s
, "%xcc", 4) == 0)
1073 if (strncmp (s
, "%fcc0", 5) == 0)
1085 if (strncmp (s
, "%fcc1", 5) == 0)
1097 if (strncmp (s
, "%fcc2", 5) == 0)
1109 if (strncmp (s
, "%fcc3", 5) == 0)
1117 if (strncmp (s
, "%pc", 3) == 0)
1125 if (strncmp (s
, "%tick", 5) == 0)
1132 /* end-sanitize-v9 */
1134 case '\0': /* end of args */
1153 case '[': /* these must match exactly */
1161 case '#': /* must be at least one digit */
1164 while (isdigit (*s
))
1172 case 'C': /* coprocessor state register */
1173 if (strncmp (s
, "%csr", 4) == 0)
1180 case 'b': /* next operand is a coprocessor register */
1183 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1188 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1202 opcode
|= mask
<< 14;
1210 opcode
|= mask
<< 25;
1216 case 'r': /* next operand must be a register */
1225 case 'f': /* frame pointer */
1233 case 'g': /* global register */
1234 if (isoctal (c
= *s
++))
1241 case 'i': /* in register */
1242 if (isoctal (c
= *s
++))
1244 mask
= c
- '0' + 24;
1249 case 'l': /* local register */
1250 if (isoctal (c
= *s
++))
1252 mask
= (c
- '0' + 16);
1257 case 'o': /* out register */
1258 if (isoctal (c
= *s
++))
1260 mask
= (c
- '0' + 8);
1265 case 's': /* stack pointer */
1273 case 'r': /* any register */
1274 if (!isdigit (c
= *s
++))
1291 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1307 * Got the register, now figure out where
1308 * it goes in the opcode.
1314 opcode
|= mask
<< 14;
1322 opcode
|= mask
<< 25;
1326 opcode
|= (mask
<< 25) | (mask
<< 14);
1332 case 'e': /* next operand is a floating point register */
1347 && ((format
= *s
) == 'f')
1350 for (mask
= 0; isdigit (*s
); ++s
)
1352 mask
= 10 * mask
+ (*s
- '0');
1353 } /* read the number */
1361 } /* register must be even numbered */
1369 } /* register must be multiple of 4 */
1371 /* start-sanitize-v9 */
1375 error_message
= ": There are only 64 f registers; [0-63]";
1381 } /* wrap high bit */
1383 /* end-sanitize-v9 */
1386 error_message
= ": There are only 32 f registers; [0-31]";
1389 /* start-sanitize-v9 */
1391 /* end-sanitize-v9 */
1396 } /* if not an 'f' register. */
1404 opcode
|= RS1 (mask
);
1411 opcode
|= RS2 (mask
);
1417 opcode
|= RD (mask
);
1426 if (strncmp (s
, "%fsr", 4) == 0)
1433 case 'h': /* high 22 bits */
1434 the_insn
.reloc
= BFD_RELOC_HI22
;
1437 case 'l': /* 22 bit PC relative immediate */
1438 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1442 case 'L': /* 30 bit immediate */
1443 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1447 case 'n': /* 22 bit immediate */
1448 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1451 case 'i': /* 13 bit immediate */
1452 /* What's the difference between base13 and 13? */
1453 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1454 immediate_max
= 0x0FFF;
1463 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1465 the_insn
.reloc
= BFD_RELOC_HI22
;
1468 else if (c
== 'l' && s
[2] == 'o')
1470 the_insn
.reloc
= BFD_RELOC_LO10
;
1472 /* start-sanitize-v9 */
1479 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1486 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1489 /* end-sanitize-v9 */
1494 /* Note that if the getExpression() fails, we
1495 will still have created U entries in the
1496 symbol table for the 'symbols' in the input
1497 string. Try not to create U symbols for
1500 /* This stuff checks to see if the
1501 expression ends in +%reg If it does,
1502 it removes the register from the
1503 expression, and re-sets 's' to point
1504 to the right place */
1508 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1510 if (s1
!= s
&& isdigit (s1
[-1]))
1512 if (s1
[-2] == '%' && s1
[-3] == '+')
1516 (void) getExpression (s
);
1521 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1525 (void) getExpression (s
);
1532 (void) getExpression (s
);
1535 /* Check for invalid constant values. Don't
1536 warn if constant was inside %hi or %lo,
1537 since these truncate the constant to
1539 if (immediate_max
!= 0
1540 && the_insn
.reloc
!= BFD_RELOC_LO10
1541 && the_insn
.reloc
!= BFD_RELOC_HI22
1542 /* start-sanitize-v9 */
1544 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1545 && the_insn
.reloc
!= RELOC_HLO10
1546 && the_insn
.reloc
!= RELOC_HHI22
1549 /* end-sanitize-v9 */
1550 && the_insn
.exp
.X_add_symbol
== 0
1551 && the_insn
.exp
.X_op_symbol
== 0
1552 && the_insn
.exp
.X_op
== O_constant
1553 && (the_insn
.exp
.X_add_number
> immediate_max
1554 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1555 as_bad ("constant value must be between %ld and %ld",
1556 ~immediate_max
, immediate_max
);
1557 /* Reset to prevent extraneous range check. */
1572 /* start-sanitize-v9 */
1574 /* end-sanitize-v9 */
1575 char *push
= input_line_pointer
;
1578 input_line_pointer
= s
;
1581 if (e
.X_op
== O_constant
)
1583 opcode
|= e
.X_add_number
<< 5;
1584 s
= input_line_pointer
;
1585 input_line_pointer
= push
;
1590 /* start-sanitize-v9 */
1598 if (!strncmp (s
, "ASI_AIUP", 8))
1600 else if (!strncmp (s
, "ASI_AIUS", 8))
1602 else if (!strncmp (s
, "ASI_PNF", 7))
1604 else if (!strncmp (s
, "ASI_SNF", 7))
1606 else if (!strncmp (s
, "ASI_P", 5))
1608 else if (!strncmp (s
, "ASI_S", 5))
1612 error_message
= ": invalid asi name";
1616 else if (isdigit (*s
))
1618 char *push
= input_line_pointer
;
1619 input_line_pointer
= s
;
1620 asi
= get_absolute_expression ();
1621 s
= input_line_pointer
;
1622 input_line_pointer
= push
;
1624 if (asi
< 0 || asi
> 255)
1626 error_message
= ": invalid asi number";
1632 error_message
= ": unrecognizable asi";
1635 opcode
|= ASI (asi
);
1638 /* end-sanitize-v9 */
1639 } /* alternate space */
1642 if (strncmp (s
, "%psr", 4) == 0)
1649 case 'q': /* floating point queue */
1650 if (strncmp (s
, "%fq", 3) == 0)
1657 case 'Q': /* coprocessor queue */
1658 if (strncmp (s
, "%cq", 3) == 0)
1666 if (strcmp (str
, "set") == 0)
1668 special_case
= SPECIAL_CASE_SET
;
1671 else if (strncmp (str
, "fdiv", 4) == 0)
1673 special_case
= SPECIAL_CASE_FDIV
;
1678 /* start-sanitize-v9 */
1681 if (strncmp (s
, "%asi", 4) != 0)
1687 if (strncmp (s
, "%fprs", 5) != 0)
1693 if (strncmp (s
, "%ccr", 4) != 0)
1698 /* end-sanitize-v9 */
1701 if (strncmp (s
, "%tbr", 4) != 0)
1707 if (strncmp (s
, "%wim", 4) != 0)
1713 if (strncmp (s
, "%y", 2) != 0)
1719 as_fatal ("failed sanity check.");
1720 } /* switch on arg code */
1722 } /* for each arg that we expect */
1726 /* Args don't match. */
1727 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1728 && !strcmp (insn
->name
, insn
[1].name
))
1736 as_bad ("Illegal operands%s", error_message
);
1742 if (insn
->architecture
> current_architecture
)
1744 if ((!architecture_requested
|| warn_on_bump
)
1746 /* start-sanitize-v9 */
1748 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1751 /* end-sanitize-v9 */
1753 /* start-sanitize-v9 */
1755 /* end-sanitize-v9 */
1760 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1761 architecture_pname
[current_architecture
],
1762 architecture_pname
[insn
->architecture
],
1766 current_architecture
= insn
->architecture
;
1770 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1772 architecture_pname
[insn
->architecture
],
1773 architecture_pname
[current_architecture
]);
1775 } /* if bump ok else error */
1776 } /* if architecture higher */
1780 } /* forever looking for a match */
1782 the_insn
.opcode
= opcode
;
1793 save_in
= input_line_pointer
;
1794 input_line_pointer
= str
;
1795 seg
= expression (&the_insn
.exp
);
1796 if (seg
== absolute_section
1797 || seg
== text_section
1798 || seg
== data_section
1799 || seg
== bss_section
1800 || seg
== undefined_section
)
1804 the_insn
.error
= "bad segment";
1805 expr_end
= input_line_pointer
;
1806 input_line_pointer
= save_in
;
1809 expr_end
= input_line_pointer
;
1810 input_line_pointer
= save_in
;
1812 } /* getExpression() */
1816 This is identical to the md_atof in m68k.c. I think this is right,
1819 Turn a string in input_line_pointer into a floating point constant of type
1820 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1821 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1824 /* Equal to MAX_PRECISION in atof-ieee.c */
1825 #define MAX_LITTLENUMS 6
1828 md_atof (type
, litP
, sizeP
)
1834 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1835 LITTLENUM_TYPE
*wordP
;
1868 return "Bad call to MD_ATOF()";
1870 t
= atof_ieee (input_line_pointer
, type
, words
);
1872 input_line_pointer
= t
;
1873 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1874 for (wordP
= words
; prec
--;)
1876 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1877 litP
+= sizeof (LITTLENUM_TYPE
);
1883 * Write out big-endian.
1886 md_number_to_chars (buf
, val
, n
)
1894 /* start-sanitize-v9 */
1900 /* end-sanitize-v9 */
1911 as_fatal ("failed sanity check.");
1914 } /* md_number_to_chars() */
1916 /* Apply a fixS to the frags, now that we know the value it ought to
1919 #ifdef BFD_ASSEMBLER
1924 md_apply_fix (fixP
, value
)
1926 #ifdef BFD_ASSEMBLER
1932 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1935 #ifdef BFD_ASSEMBLER
1941 #ifdef BFD_ASSEMBLER
1942 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1944 assert (fixP
->fx_r_type
< NO_RELOC
);
1947 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1950 * This is a hack. There should be a better way to
1953 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1955 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1958 switch (fixP
->fx_r_type
)
1968 case BFD_RELOC_32_PCREL_S2
:
1969 val
= (val
>>= 2) + 1;
1970 buf
[0] |= (val
>> 24) & 0x3f;
1971 buf
[1] = (val
>> 16);
1976 /* start-sanitize-v9 */
1989 case BFD_RELOC_SPARC_11
:
1990 if (((val
> 0) && (val
& ~0x7ff))
1991 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1993 as_bad ("relocation overflow.");
1996 buf
[2] |= (val
>> 8) & 0x7;
1997 buf
[3] = val
& 0xff;
2000 case BFD_RELOC_SPARC_10
:
2001 if (((val
> 0) && (val
& ~0x3ff))
2002 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
2004 as_bad ("relocation overflow.");
2007 buf
[2] |= (val
>> 8) & 0x3;
2008 buf
[3] = val
& 0xff;
2011 case BFD_RELOC_SPARC_WDISP16
:
2012 if (((val
> 0) && (val
& ~0x3fffc))
2013 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
2015 as_bad ("relocation overflow.");
2018 val
= (val
>>= 2) + 1;
2019 buf
[1] |= ((val
>> 14) & 0x3) << 4;
2020 buf
[2] |= (val
>> 8) & 0x3f;
2021 buf
[3] = val
& 0xff;
2024 case BFD_RELOC_SPARC_WDISP19
:
2025 if (((val
> 0) && (val
& ~0x1ffffc))
2026 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2028 as_bad ("relocation overflow.");
2031 val
= (val
>>= 2) + 1;
2032 buf
[1] |= (val
>> 16) & 0x7;
2033 buf
[2] = (val
>> 8) & 0xff;
2034 buf
[3] = val
& 0xff;
2037 case BFD_RELOC_SPARC_HH22
:
2039 /* intentional fallthrough */
2041 /* end-sanitize-v9 */
2043 /* start-sanitize-v9 */
2045 case BFD_RELOC_SPARC_LM22
:
2047 /* end-sanitize-v9 */
2048 case BFD_RELOC_HI22
:
2049 if (!fixP
->fx_addsy
)
2051 buf
[1] |= (val
>> 26) & 0x3f;
2062 case BFD_RELOC_SPARC22
:
2063 if (val
& ~0x003fffff)
2065 as_bad ("relocation overflow");
2067 buf
[1] |= (val
>> 16) & 0x3f;
2069 buf
[3] = val
& 0xff;
2072 case BFD_RELOC_SPARC13
:
2073 if (val
& ~0x00001fff)
2075 as_bad ("relocation overflow");
2077 buf
[2] |= (val
>> 8) & 0x1f;
2078 buf
[3] = val
& 0xff;
2081 /* start-sanitize-v9 */
2083 case BFD_RELOC_SPARC_HM10
:
2085 /* intentional fallthrough */
2087 /* end-sanitize-v9 */
2089 case BFD_RELOC_LO10
:
2090 if (!fixP
->fx_addsy
)
2092 buf
[2] |= (val
>> 8) & 0x03;
2098 case BFD_RELOC_SPARC_BASE13
:
2099 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2100 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2102 as_bad ("relocation overflow");
2104 buf
[2] |= (val
>> 8) & 0x1f;
2108 case BFD_RELOC_SPARC_WDISP22
:
2109 val
= (val
>>= 2) + 1;
2111 case BFD_RELOC_SPARC_BASE22
:
2112 buf
[1] |= (val
>> 16) & 0x3f;
2117 case BFD_RELOC_NONE
:
2119 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2123 #ifdef BFD_ASSEMBLER
2128 /* should never be called for sparc */
2130 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2137 as_fatal ("sparc_create_short_jmp\n");
2140 #ifdef BFD_ASSEMBLER
2142 /* Translate internal representation of relocation info to BFD target
2145 tc_gen_reloc (section
, fixp
)
2150 bfd_reloc_code_real_type code
;
2152 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2153 assert (reloc
!= 0);
2155 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2156 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2157 if (fixp
->fx_pcrel
== 0)
2158 reloc
->addend
= fixp
->fx_addnumber
;
2160 switch (OUTPUT_FLAVOR
)
2162 case bfd_target_elf_flavour
:
2165 case bfd_target_aout_flavour
:
2166 reloc
->addend
= - reloc
->address
;
2169 /* What's a good default here? Is there any?? */
2173 switch (fixp
->fx_r_type
)
2176 case BFD_RELOC_HI22
:
2177 case BFD_RELOC_LO10
:
2178 case BFD_RELOC_32_PCREL_S2
:
2179 case BFD_RELOC_SPARC_BASE13
:
2180 case BFD_RELOC_SPARC_WDISP22
:
2181 /* start-sanitize-v9 */
2183 case BFD_RELOC_SPARC_10
:
2184 case BFD_RELOC_SPARC_11
:
2185 case BFD_RELOC_SPARC_HH22
:
2186 case BFD_RELOC_SPARC_HM10
:
2187 case BFD_RELOC_SPARC_LM22
:
2188 case BFD_RELOC_SPARC_PC_HH22
:
2189 case BFD_RELOC_SPARC_PC_HM10
:
2190 case BFD_RELOC_SPARC_PC_LM22
:
2191 /* end-sanitize-v9 */
2192 code
= fixp
->fx_r_type
;
2197 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2198 assert (reloc
->howto
!= 0);
2205 /* Translate internal representation of relocation info to target format.
2207 On sparc: first 4 bytes are normal unsigned long address, next three
2208 bytes are index, most sig. byte first. Byte 7 is broken up with
2209 bit 7 as external, bits 6 & 5 unused, and the lower
2210 five bits as relocation type. Next 4 bytes are long addend. */
2211 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2213 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2216 relax_addressT segment_address_in_file
;
2223 know (fixP
->fx_addsy
);
2225 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2228 r_index
= fixP
->fx_addsy
->sy_number
;
2233 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2237 md_number_to_chars (where
,
2238 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2241 /* now the fun stuff */
2242 where
[4] = (r_index
>> 16) & 0x0ff;
2243 where
[5] = (r_index
>> 8) & 0x0ff;
2244 where
[6] = r_index
& 0x0ff;
2245 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2248 if (fixP
->fx_addsy
->sy_frag
)
2250 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2255 r_addend
+= fixP
->fx_offset
- r_address
;
2259 r_addend
= fixP
->fx_addnumber
;
2262 md_number_to_chars (&where
[8], r_addend
, 4);
2265 } /* tc_aout_fix_to_chars() */
2268 /* should never be called for sparc */
2270 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2272 addressT from_addr
, to_addr
;
2276 as_fatal ("sparc_create_long_jump\n");
2277 } /* md_create_long_jump() */
2279 /* should never be called for sparc */
2281 md_estimate_size_before_relax (fragP
, segtype
)
2285 as_fatal ("sparc_estimate_size_before_relax\n");
2287 } /* md_estimate_size_before_relax() */
2290 /* for debugging only */
2293 struct sparc_it
*insn
;
2326 fprintf (stderr
, "ERROR: %s\n");
2328 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2329 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2330 fprintf (stderr
, "exp = {\n");
2331 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2332 ((insn
->exp
.X_add_symbol
!= NULL
)
2333 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2334 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2337 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2338 ((insn
->exp
.X_op_symbol
!= NULL
)
2339 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2340 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2343 fprintf (stderr
, "\t\tX_add_number = %d\n",
2344 insn
->exp
.X_add_number
);
2345 fprintf (stderr
, "}\n");
2347 } /* print_insn() */
2353 * Invocation line includes a switch not recognized by the base assembler.
2354 * See if it's a processor-specific option. These are:
2357 * Warn on architecture bumps. See also -A.
2359 * -Av6, -Av7, -Av8, -Asparclite
2360 * Select the architecture. Instructions or features not
2361 * supported by the selected architecture cause fatal errors.
2363 * The default is to start at v6, and bump the architecture up
2364 * whenever an instruction is seen at a higher level.
2366 * If -bump is specified, a warning is printing when bumping to
2369 * If an architecture is specified, all instructions must match
2370 * that architecture. Any higher level instructions are flagged
2373 * if both an architecture and -bump are specified, the
2374 * architecture starts at the specified level, but bumps are
2379 * Another architecture switch.
2382 * Bumping between incompatible architectures is always an
2383 * error. For example, from sparclite to v9.
2388 md_parse_option (argP
, cntP
, vecP
)
2396 if (!strcmp (*argP
, "bump"))
2401 else if (**argP
== 'A')
2405 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2407 if (strcmp (p
, *arch
) == 0)
2410 } /* found a match */
2411 } /* walk the pname table */
2415 as_bad ("unknown architecture: %s", p
);
2419 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2420 architecture_requested
= 1;
2424 else if (**argP
== 'V')
2426 extern void print_version_id ();
2427 print_version_id ();
2429 else if (**argP
== 'Q')
2431 /* Qy - do emit .comment
2432 Qn - do not emit .comment */
2434 else if (**argP
== 's')
2436 /* use .stab instead of .stab.excl */
2441 /* Unknown option */
2445 **argP
= '\0'; /* Done parsing this switch */
2447 } /* md_parse_option() */
2449 /* We have no need to default values of symbols. */
2453 md_undefined_symbol (name
)
2457 } /* md_undefined_symbol() */
2459 /* Parse an operand that is machine-specific.
2460 We just return without modifying the expression if we have nothing
2465 md_operand (expressionP
)
2466 expressionS
*expressionP
;
2470 /* Round up a section size to the appropriate boundary. */
2472 md_section_align (segment
, size
)
2477 /* Round all sects to multiple of 8 */
2478 size
= (size
+ 7) & ~7;
2483 /* Exactly what point is a PC-relative offset relative TO?
2484 On the sparc, they're relative to the address of the offset, plus
2485 its size. This gets us to the following instruction.
2486 (??? Is this right? FIXME-SOON) */
2488 md_pcrel_from (fixP
)
2491 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2494 #ifndef BFD_ASSEMBLER
2496 tc_aout_pre_write_hook (headers
)
2497 object_headers
*headers
;
2499 H_SET_VERSION (headers
, 1);
2503 /* end of tc-sparc.c */