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},
95 {"local", s_local
, 0},
96 /* these are specific to sparc/svr4 */
97 {"pushsection", obj_elf_section
, 0},
98 {"popsection", obj_elf_previous
, 0},
105 const int md_short_jump_size
= 4;
106 const int md_long_jump_size
= 4;
107 const int md_reloc_size
= 12; /* Size of relocation record */
109 /* This array holds the chars that always start a comment. If the
110 pre-processor is disabled, these aren't very useful */
111 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
113 /* This array holds the chars that only start a comment at the beginning of
114 a line. If the line seems to have the form '# 123 filename'
115 .line and .file directives will appear in the pre-processed output */
116 /* Note that input_file.c hand checks for '#' at the beginning of the
117 first line of the input file. This is because the compiler outputs
118 #NO_APP at the beginning of its output. */
119 /* Also note that comments started like this one will always
120 work if '/' isn't otherwise defined. */
121 const char line_comment_chars
[] = "#";
123 const char line_separator_chars
[] = "";
125 /* Chars that can be used to separate mant from exp in floating point nums */
126 const char EXP_CHARS
[] = "eE";
128 /* Chars that mean this number is a floating point constant */
131 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
133 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
134 changed in read.c . Ideally it shouldn't have to know about it at all,
135 but nothing is ideal around here.
138 static unsigned char octal
[256];
139 #define isoctal(c) octal[c]
140 static unsigned char toHex
[256];
145 unsigned long opcode
;
146 struct nlist
*nlistp
;
150 bfd_reloc_code_real_type reloc
;
152 enum reloc_type reloc
;
156 struct sparc_it the_insn
, set_insn
;
159 static void print_insn
PARAMS ((struct sparc_it
*insn
));
161 static int getExpression
PARAMS ((char *str
));
163 static char *expr_end
;
164 static int special_case
;
167 * Instructions that require wierd handling because they're longer than
170 #define SPECIAL_CASE_SET 1
171 #define SPECIAL_CASE_FDIV 2
174 * sort of like s_lcomm
177 static int max_alignment
= 15;
190 name
= input_line_pointer
;
191 c
= get_symbol_end ();
192 p
= input_line_pointer
;
196 if (*input_line_pointer
!= ',')
198 as_bad ("Expected comma after name");
199 ignore_rest_of_line ();
203 ++input_line_pointer
;
205 if ((size
= get_absolute_expression ()) < 0)
207 as_bad ("BSS length (%d.) <0! Ignored.", size
);
208 ignore_rest_of_line ();
213 symbolP
= symbol_find_or_make (name
);
216 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
217 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
219 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
223 if (input_line_pointer
[2] == '.')
224 input_line_pointer
+= 7;
226 input_line_pointer
+= 6;
229 if (*input_line_pointer
== ',')
231 ++input_line_pointer
;
234 if (*input_line_pointer
== '\n')
236 as_bad ("Missing alignment");
240 align
= get_absolute_expression ();
241 if (align
> max_alignment
)
243 align
= max_alignment
;
244 as_warn ("Alignment too large: %d. assumed.", align
);
249 as_warn ("Alignment negative. 0 assumed.");
252 record_alignment (bss_section
, align
);
254 /* convert to a power of 2 alignment */
255 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
259 as_bad ("Alignment not a power of 2");
260 ignore_rest_of_line ();
262 } /* not a power of two */
265 } /* if has optional alignment */
269 if ((S_GET_SEGMENT (symbolP
) == bss_section
270 || !S_IS_DEFINED (symbolP
))
272 && S_GET_OTHER (symbolP
) == 0
273 && S_GET_DESC (symbolP
) == 0
280 segT current_seg
= now_seg
;
281 subsegT current_subseg
= now_subseg
;
283 subseg_set (bss_section
, 1); /* switch to bss */
286 frag_align (align
, 0); /* do alignment */
288 /* detach from old frag */
289 if (S_GET_SEGMENT(symbolP
) == bss_section
)
290 symbolP
->sy_frag
->fr_symbol
= NULL
;
292 symbolP
->sy_frag
= frag_now
;
293 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
297 S_SET_SEGMENT (symbolP
, bss_section
);
299 subseg_set (current_seg
, current_subseg
);
304 as_warn("Ignoring attempt to re-define symbol %s.", name
);
305 } /* if not redefining */
307 demand_empty_rest_of_line ();
311 /* Currently used only by Solaris 2. */
321 name
= input_line_pointer
;
322 c
= get_symbol_end ();
323 symbolP
= symbol_find_or_make (name
);
324 *input_line_pointer
= c
;
326 S_CLEAR_EXTERNAL (symbolP
);
330 input_line_pointer
++;
332 if (*input_line_pointer
== '\n')
337 demand_empty_rest_of_line ();
350 name
= input_line_pointer
;
351 c
= get_symbol_end ();
352 /* just after name is now '\0' */
353 p
= input_line_pointer
;
356 if (*input_line_pointer
!= ',')
358 as_bad ("Expected comma after symbol-name");
359 ignore_rest_of_line ();
362 input_line_pointer
++; /* skip ',' */
363 if ((temp
= get_absolute_expression ()) < 0)
365 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
366 ignore_rest_of_line ();
371 symbolP
= symbol_find_or_make (name
);
373 if (S_IS_DEFINED (symbolP
))
375 as_bad ("Ignoring attempt to re-define symbol");
376 ignore_rest_of_line ();
379 if (S_GET_VALUE (symbolP
) != 0)
381 if (S_GET_VALUE (symbolP
) != size
)
383 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
384 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
390 S_SET_VALUE (symbolP
, size
);
391 S_SET_EXTERNAL (symbolP
);
394 know (symbolP
->sy_frag
== &zero_address_frag
);
395 if (*input_line_pointer
!= ',')
397 as_bad ("Expected comma after common length");
398 ignore_rest_of_line ();
401 input_line_pointer
++;
403 if (*input_line_pointer
!= '"')
405 temp
= get_absolute_expression ();
406 if (temp
> max_alignment
)
408 temp
= max_alignment
;
409 as_warn ("Common alignment too large: %d. assumed", temp
);
414 as_warn ("Common alignment negative; 0 assumed");
426 old_subsec
= now_subseg
;
428 record_alignment (bss_section
, align
);
429 subseg_set (bss_section
, 0);
431 frag_align (align
, 0);
432 if (S_GET_SEGMENT (symbolP
) == bss_section
)
433 symbolP
->sy_frag
->fr_symbol
= 0;
434 symbolP
->sy_frag
= frag_now
;
435 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
438 S_SET_SEGMENT (symbolP
, bss_section
);
439 S_CLEAR_EXTERNAL (symbolP
);
440 subseg_set (old_sec
, old_subsec
);
446 S_SET_VALUE (symbolP
, size
);
447 S_SET_EXTERNAL (symbolP
);
448 /* should be common, but this is how gas does it for now */
449 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
454 input_line_pointer
++;
455 /* @@ Some use the dot, some don't. Can we get some consistency?? */
456 if (*input_line_pointer
== '.')
457 input_line_pointer
++;
458 /* @@ Some say data, some say bss. */
459 if (strncmp (input_line_pointer
, "bss\"", 4)
460 && strncmp (input_line_pointer
, "data\"", 5))
462 while (*--input_line_pointer
!= '"')
464 input_line_pointer
--;
465 goto bad_common_segment
;
467 while (*input_line_pointer
++ != '"')
469 goto allocate_common
;
471 demand_empty_rest_of_line ();
476 p
= input_line_pointer
;
477 while (*p
&& *p
!= '\n')
481 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
483 input_line_pointer
= p
;
484 ignore_rest_of_line ();
493 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
495 input_line_pointer
+= 6;
499 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
501 input_line_pointer
+= 6;
505 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
507 input_line_pointer
+= 7;
511 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
513 input_line_pointer
+= 5;
514 /* We only support 2 segments -- text and data -- for now, so
515 things in the "bss segment" will have to go into data for now.
516 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
517 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
520 as_bad ("Unknown segment type");
521 demand_empty_rest_of_line ();
528 subseg_set (data_section
, 1);
529 demand_empty_rest_of_line ();
536 extern char is_end_of_line
[];
538 while (!is_end_of_line
[*input_line_pointer
])
540 ++input_line_pointer
;
542 ++input_line_pointer
;
546 /* start-sanitize-v9 */
552 if (isdigit (*input_line_pointer
))
558 struct priv_reg_entry
564 struct priv_reg_entry priv_reg_table
[] =
583 {"", -1}, /* end marker */
593 #define MEMBAR_MASKS_SIZE 7
595 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
598 {"MemIssue", 8, 0x20},
599 {"Lookaside", 9, 0x10},
600 {"StoreStore", 10, 0x08},
601 {"LoadStore", 9, 0x04},
602 {"StoreLoad", 9, 0x02},
603 {"LoadLoad", 8, 0x01},
608 struct priv_reg_entry
*p
, *q
;
610 return strcmp (q
->name
, p
->name
);
614 /* end-sanitize-v9 */
616 /* This function is called once, at assembler startup time. It should
617 set up all the tables, etc. that the MD part of the assembler will need. */
621 register char *retval
= NULL
;
623 register unsigned int i
= 0;
625 op_hash
= hash_new ();
627 as_fatal ("Virtual memory exhausted");
629 while (i
< NUMOPCODES
)
631 const char *name
= sparc_opcodes
[i
].name
;
632 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
633 if (retval
!= NULL
&& *retval
!= '\0')
635 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
636 sparc_opcodes
[i
].name
, retval
);
641 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
643 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
644 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
649 while (i
< NUMOPCODES
650 && !strcmp (sparc_opcodes
[i
].name
, name
));
654 as_fatal ("Broken assembler. No assembly attempted.");
656 for (i
= '0'; i
< '8'; ++i
)
658 for (i
= '0'; i
<= '9'; ++i
)
660 for (i
= 'a'; i
<= 'f'; ++i
)
661 toHex
[i
] = i
+ 10 - 'a';
662 for (i
= 'A'; i
<= 'F'; ++i
)
663 toHex
[i
] = i
+ 10 - 'A';
665 /* start-sanitize-v9 */
668 current_architecture
= v9
;
671 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
672 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
674 /* end-sanitize-v9 */
676 target_big_endian
= 1;
695 /* See if "set" operand is absolute and small; skip sethi if so. */
696 if (special_case
== SPECIAL_CASE_SET
697 && the_insn
.exp
.X_op
== O_constant
)
699 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
700 && the_insn
.exp
.X_add_number
< (1 << 12))
702 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
703 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
704 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
705 special_case
= 0; /* No longer special */
706 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
711 /* put out the opcode */
712 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
714 /* put out the symbol-dependent stuff */
715 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
717 fix_new_exp (frag_now
, /* which frag */
718 (toP
- frag_now
->fr_literal
), /* where */
725 switch (special_case
)
727 case SPECIAL_CASE_SET
:
729 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
730 /* See if "set" operand has no low-order bits; skip OR if so. */
731 if (the_insn
.exp
.X_op
== O_constant
732 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
735 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
736 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
737 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
738 fix_new_exp (frag_now
, /* which frag */
739 (toP
- frag_now
->fr_literal
), /* where */
746 case SPECIAL_CASE_FDIV
:
747 /* According to information leaked from Sun, the "fdiv" instructions
748 on early SPARC machines would produce incorrect results sometimes.
749 The workaround is to add an fmovs of the destination register to
750 itself just after the instruction. This was true on machines
751 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
753 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
755 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
756 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
757 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
764 as_fatal ("failed sanity check.");
766 } /* md_assemble() */
772 char *error_message
= "";
776 struct sparc_opcode
*insn
;
778 unsigned long opcode
;
779 unsigned int mask
= 0;
782 long immediate_max
= 0;
784 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
802 as_bad ("Unknown opcode: `%s'", str
);
805 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
807 as_bad ("Unknown opcode: `%s'", str
);
817 opcode
= insn
->match
;
818 memset (&the_insn
, '\0', sizeof (the_insn
));
819 the_insn
.reloc
= BFD_RELOC_NONE
;
822 * Build the opcode, checking as we go to make
823 * sure that the operands match
825 for (args
= insn
->args
;; ++args
)
830 /* start-sanitize-v9 */
837 /* Parse a series of masks. */
843 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
844 if (!strncmp (s
, membar_masks
[i
].name
,
845 membar_masks
[i
].len
))
847 if (i
< MEMBAR_MASKS_SIZE
)
849 mask
|= membar_masks
[i
].mask
;
850 s
+= membar_masks
[i
].len
;
854 error_message
= ": invalid membar mask name";
861 else if (isdigit (*s
))
865 mask
= mask
* 10 + *s
- '0';
869 if (mask
< 0 || mask
> 127)
871 error_message
= ": invalid membar mask number";
877 error_message
= ": unrecognizable membar mask";
880 opcode
|= SIMM13 (mask
);
886 int prefetch_fcn
= 0;
888 /* Parse a prefetch function. */
892 if (!strncmp (s
, "n_reads", 7))
893 prefetch_fcn
= 0, s
+= 7;
894 else if (!strncmp (s
, "one_read", 8))
895 prefetch_fcn
= 1, s
+= 8;
896 else if (!strncmp (s
, "n_writes", 8))
897 prefetch_fcn
= 2, s
+= 8;
898 else if (!strncmp (s
, "one_write", 9))
899 prefetch_fcn
= 3, s
+= 9;
900 else if (!strncmp (s
, "page", 4))
901 prefetch_fcn
= 4, s
+= 4;
904 error_message
= ": invalid prefetch function name";
908 else if (isdigit (*s
))
912 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
916 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
918 error_message
= ": invalid prefetch function number";
924 error_message
= ": unrecognizable prefetch function";
927 opcode
|= RD (prefetch_fcn
);
933 /* Parse a privileged register. */
936 struct priv_reg_entry
*p
= priv_reg_table
;
937 int len
= 9999999; /* init to make gcc happy */
940 while (p
->name
[0] > s
[0])
942 while (p
->name
[0] == s
[0])
944 len
= strlen (p
->name
);
945 if (strncmp (p
->name
, s
, len
) == 0)
949 if (p
->name
[0] != s
[0])
951 error_message
= ": unrecognizable privileged register";
955 opcode
|= (p
->regnum
<< 14);
957 opcode
|= (p
->regnum
<< 25);
963 error_message
= ": unrecognizable privileged register";
967 /* end-sanitize-v9 */
971 if (strncmp (s
, "%asr", 4) == 0)
981 num
= num
* 10 + *s
- '0';
985 if (num
< 16 || 31 < num
)
987 error_message
= ": asr number must be between 15 and 31";
991 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
996 error_message
= ": expecting %asrN";
998 } /* if %asr followed by a number. */
1003 /* start-sanitize-v9 */
1006 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1007 immediate_max
= 0x03FF;
1011 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1012 immediate_max
= 0x01FF;
1016 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1021 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1026 if (*s
== 'p' && s
[1] == 'n')
1034 if (*s
== 'p' && s
[1] == 't')
1046 if (strncmp (s
, "%icc", 4) == 0)
1058 if (strncmp (s
, "%xcc", 4) == 0)
1070 if (strncmp (s
, "%fcc0", 5) == 0)
1082 if (strncmp (s
, "%fcc1", 5) == 0)
1094 if (strncmp (s
, "%fcc2", 5) == 0)
1106 if (strncmp (s
, "%fcc3", 5) == 0)
1114 if (strncmp (s
, "%pc", 3) == 0)
1122 if (strncmp (s
, "%tick", 5) == 0)
1129 /* end-sanitize-v9 */
1131 case '\0': /* end of args */
1150 case '[': /* these must match exactly */
1158 case '#': /* must be at least one digit */
1161 while (isdigit (*s
))
1169 case 'C': /* coprocessor state register */
1170 if (strncmp (s
, "%csr", 4) == 0)
1177 case 'b': /* next operand is a coprocessor register */
1180 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1185 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1199 opcode
|= mask
<< 14;
1207 opcode
|= mask
<< 25;
1213 case 'r': /* next operand must be a register */
1222 case 'f': /* frame pointer */
1230 case 'g': /* global register */
1231 if (isoctal (c
= *s
++))
1238 case 'i': /* in register */
1239 if (isoctal (c
= *s
++))
1241 mask
= c
- '0' + 24;
1246 case 'l': /* local register */
1247 if (isoctal (c
= *s
++))
1249 mask
= (c
- '0' + 16);
1254 case 'o': /* out register */
1255 if (isoctal (c
= *s
++))
1257 mask
= (c
- '0' + 8);
1262 case 's': /* stack pointer */
1270 case 'r': /* any register */
1271 if (!isdigit (c
= *s
++))
1288 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1304 * Got the register, now figure out where
1305 * it goes in the opcode.
1311 opcode
|= mask
<< 14;
1319 opcode
|= mask
<< 25;
1323 opcode
|= (mask
<< 25) | (mask
<< 14);
1329 case 'e': /* next operand is a floating point register */
1344 && ((format
= *s
) == 'f')
1347 for (mask
= 0; isdigit (*s
); ++s
)
1349 mask
= 10 * mask
+ (*s
- '0');
1350 } /* read the number */
1358 } /* register must be even numbered */
1366 } /* register must be multiple of 4 */
1368 /* start-sanitize-v9 */
1372 error_message
= ": There are only 64 f registers; [0-63]";
1378 } /* wrap high bit */
1380 /* end-sanitize-v9 */
1383 error_message
= ": There are only 32 f registers; [0-31]";
1386 /* start-sanitize-v9 */
1388 /* end-sanitize-v9 */
1393 } /* if not an 'f' register. */
1401 opcode
|= RS1 (mask
);
1408 opcode
|= RS2 (mask
);
1414 opcode
|= RD (mask
);
1423 if (strncmp (s
, "%fsr", 4) == 0)
1430 case 'h': /* high 22 bits */
1431 the_insn
.reloc
= BFD_RELOC_HI22
;
1434 case 'l': /* 22 bit PC relative immediate */
1435 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1439 case 'L': /* 30 bit immediate */
1440 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1444 case 'n': /* 22 bit immediate */
1445 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1448 case 'i': /* 13 bit immediate */
1449 /* What's the difference between base13 and 13? */
1450 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1451 immediate_max
= 0x0FFF;
1460 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1462 the_insn
.reloc
= BFD_RELOC_HI22
;
1465 else if (c
== 'l' && s
[2] == 'o')
1467 the_insn
.reloc
= BFD_RELOC_LO10
;
1469 /* start-sanitize-v9 */
1476 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1483 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1486 /* end-sanitize-v9 */
1491 /* Note that if the getExpression() fails, we
1492 will still have created U entries in the
1493 symbol table for the 'symbols' in the input
1494 string. Try not to create U symbols for
1497 /* This stuff checks to see if the
1498 expression ends in +%reg If it does,
1499 it removes the register from the
1500 expression, and re-sets 's' to point
1501 to the right place */
1505 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1507 if (s1
!= s
&& isdigit (s1
[-1]))
1509 if (s1
[-2] == '%' && s1
[-3] == '+')
1513 (void) getExpression (s
);
1518 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1522 (void) getExpression (s
);
1529 (void) getExpression (s
);
1532 /* Check for invalid constant values. Don't
1533 warn if constant was inside %hi or %lo,
1534 since these truncate the constant to
1536 if (immediate_max
!= 0
1537 && the_insn
.reloc
!= BFD_RELOC_LO10
1538 && the_insn
.reloc
!= BFD_RELOC_HI22
1539 /* start-sanitize-v9 */
1541 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1542 && the_insn
.reloc
!= RELOC_HLO10
1543 && the_insn
.reloc
!= RELOC_HHI22
1546 /* end-sanitize-v9 */
1547 && the_insn
.exp
.X_add_symbol
== 0
1548 && the_insn
.exp
.X_op_symbol
== 0
1549 && the_insn
.exp
.X_op
== O_constant
1550 && (the_insn
.exp
.X_add_number
> immediate_max
1551 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1552 as_bad ("constant value must be between %ld and %ld",
1553 ~immediate_max
, immediate_max
);
1554 /* Reset to prevent extraneous range check. */
1569 /* start-sanitize-v9 */
1571 /* end-sanitize-v9 */
1572 char *push
= input_line_pointer
;
1575 input_line_pointer
= s
;
1578 if (e
.X_op
== O_constant
)
1580 opcode
|= e
.X_add_number
<< 5;
1581 s
= input_line_pointer
;
1582 input_line_pointer
= push
;
1587 /* start-sanitize-v9 */
1595 if (!strncmp (s
, "ASI_AIUP", 8))
1597 else if (!strncmp (s
, "ASI_AIUS", 8))
1599 else if (!strncmp (s
, "ASI_PNF", 7))
1601 else if (!strncmp (s
, "ASI_SNF", 7))
1603 else if (!strncmp (s
, "ASI_P", 5))
1605 else if (!strncmp (s
, "ASI_S", 5))
1609 error_message
= ": invalid asi name";
1613 else if (isdigit (*s
))
1615 char *push
= input_line_pointer
;
1616 input_line_pointer
= s
;
1617 asi
= get_absolute_expression ();
1618 s
= input_line_pointer
;
1619 input_line_pointer
= push
;
1621 if (asi
< 0 || asi
> 255)
1623 error_message
= ": invalid asi number";
1629 error_message
= ": unrecognizable asi";
1632 opcode
|= ASI (asi
);
1635 /* end-sanitize-v9 */
1636 } /* alternate space */
1639 if (strncmp (s
, "%psr", 4) == 0)
1646 case 'q': /* floating point queue */
1647 if (strncmp (s
, "%fq", 3) == 0)
1654 case 'Q': /* coprocessor queue */
1655 if (strncmp (s
, "%cq", 3) == 0)
1663 if (strcmp (str
, "set") == 0)
1665 special_case
= SPECIAL_CASE_SET
;
1668 else if (strncmp (str
, "fdiv", 4) == 0)
1670 special_case
= SPECIAL_CASE_FDIV
;
1675 /* start-sanitize-v9 */
1678 if (strncmp (s
, "%asi", 4) != 0)
1684 if (strncmp (s
, "%fprs", 5) != 0)
1690 if (strncmp (s
, "%ccr", 4) != 0)
1695 /* end-sanitize-v9 */
1698 if (strncmp (s
, "%tbr", 4) != 0)
1704 if (strncmp (s
, "%wim", 4) != 0)
1710 if (strncmp (s
, "%y", 2) != 0)
1716 as_fatal ("failed sanity check.");
1717 } /* switch on arg code */
1719 } /* for each arg that we expect */
1723 /* Args don't match. */
1724 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1725 && !strcmp (insn
->name
, insn
[1].name
))
1733 as_bad ("Illegal operands%s", error_message
);
1739 if (insn
->architecture
> current_architecture
)
1741 if ((!architecture_requested
|| warn_on_bump
)
1743 /* start-sanitize-v9 */
1745 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1748 /* end-sanitize-v9 */
1750 /* start-sanitize-v9 */
1752 /* end-sanitize-v9 */
1757 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1758 architecture_pname
[current_architecture
],
1759 architecture_pname
[insn
->architecture
],
1763 current_architecture
= insn
->architecture
;
1767 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1769 architecture_pname
[insn
->architecture
],
1770 architecture_pname
[current_architecture
]);
1772 } /* if bump ok else error */
1773 } /* if architecture higher */
1777 } /* forever looking for a match */
1779 the_insn
.opcode
= opcode
;
1790 save_in
= input_line_pointer
;
1791 input_line_pointer
= str
;
1792 seg
= expression (&the_insn
.exp
);
1793 if (seg
== absolute_section
1794 || seg
== text_section
1795 || seg
== data_section
1796 || seg
== bss_section
1797 || seg
== undefined_section
)
1801 the_insn
.error
= "bad segment";
1802 expr_end
= input_line_pointer
;
1803 input_line_pointer
= save_in
;
1806 expr_end
= input_line_pointer
;
1807 input_line_pointer
= save_in
;
1809 } /* getExpression() */
1813 This is identical to the md_atof in m68k.c. I think this is right,
1816 Turn a string in input_line_pointer into a floating point constant of type
1817 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1818 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1821 /* Equal to MAX_PRECISION in atof-ieee.c */
1822 #define MAX_LITTLENUMS 6
1825 md_atof (type
, litP
, sizeP
)
1831 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1832 LITTLENUM_TYPE
*wordP
;
1865 return "Bad call to MD_ATOF()";
1867 t
= atof_ieee (input_line_pointer
, type
, words
);
1869 input_line_pointer
= t
;
1870 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1871 for (wordP
= words
; prec
--;)
1873 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1874 litP
+= sizeof (LITTLENUM_TYPE
);
1880 * Write out big-endian.
1883 md_number_to_chars (buf
, val
, n
)
1891 /* start-sanitize-v9 */
1897 /* end-sanitize-v9 */
1908 as_fatal ("failed sanity check.");
1911 } /* md_number_to_chars() */
1913 /* Apply a fixS to the frags, now that we know the value it ought to
1916 #ifdef BFD_ASSEMBLER
1921 md_apply_fix (fixP
, value
)
1923 #ifdef BFD_ASSEMBLER
1929 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1932 #ifdef BFD_ASSEMBLER
1938 #ifdef BFD_ASSEMBLER
1939 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1941 assert (fixP
->fx_r_type
< NO_RELOC
);
1944 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1947 * This is a hack. There should be a better way to
1950 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1952 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1955 switch (fixP
->fx_r_type
)
1959 buf
[0] = 0; /* val >> 24; */
1960 buf
[1] = 0; /* val >> 16; */
1961 buf
[2] = 0; /* val >> 8; */
1962 buf
[3] = 0; /* val; */
1965 case BFD_RELOC_32_PCREL_S2
:
1966 val
= (val
>>= 2) + 1;
1967 buf
[0] |= (val
>> 24) & 0x3f;
1968 buf
[1] = (val
>> 16);
1973 /* start-sanitize-v9 */
1986 case BFD_RELOC_SPARC_11
:
1987 if (((val
> 0) && (val
& ~0x7ff))
1988 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1990 as_bad ("relocation overflow.");
1993 buf
[2] |= (val
>> 8) & 0x7;
1994 buf
[3] = val
& 0xff;
1997 case BFD_RELOC_SPARC_10
:
1998 if (((val
> 0) && (val
& ~0x3ff))
1999 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
2001 as_bad ("relocation overflow.");
2004 buf
[2] |= (val
>> 8) & 0x3;
2005 buf
[3] = val
& 0xff;
2008 case BFD_RELOC_SPARC_WDISP16
:
2009 if (((val
> 0) && (val
& ~0x3fffc))
2010 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
2012 as_bad ("relocation overflow.");
2015 val
= (val
>>= 2) + 1;
2016 buf
[1] |= ((val
>> 14) & 0x3) << 4;
2017 buf
[2] |= (val
>> 8) & 0x3f;
2018 buf
[3] = val
& 0xff;
2021 case BFD_RELOC_SPARC_WDISP19
:
2022 if (((val
> 0) && (val
& ~0x1ffffc))
2023 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2025 as_bad ("relocation overflow.");
2028 val
= (val
>>= 2) + 1;
2029 buf
[1] |= (val
>> 16) & 0x7;
2030 buf
[2] = (val
>> 8) & 0xff;
2031 buf
[3] = val
& 0xff;
2034 case BFD_RELOC_SPARC_HH22
:
2036 /* intentional fallthrough */
2038 /* end-sanitize-v9 */
2040 /* start-sanitize-v9 */
2042 case BFD_RELOC_SPARC_LM22
:
2044 /* end-sanitize-v9 */
2045 case BFD_RELOC_HI22
:
2046 if (!fixP
->fx_addsy
)
2048 buf
[1] |= (val
>> 26) & 0x3f;
2059 case BFD_RELOC_SPARC22
:
2060 if (val
& ~0x003fffff)
2062 as_bad ("relocation overflow");
2064 buf
[1] |= (val
>> 16) & 0x3f;
2066 buf
[3] = val
& 0xff;
2069 case BFD_RELOC_SPARC13
:
2070 if (val
& ~0x00001fff)
2072 as_bad ("relocation overflow");
2074 buf
[2] |= (val
>> 8) & 0x1f;
2075 buf
[3] = val
& 0xff;
2078 /* start-sanitize-v9 */
2080 case BFD_RELOC_SPARC_HM10
:
2082 /* intentional fallthrough */
2084 /* end-sanitize-v9 */
2086 case BFD_RELOC_LO10
:
2087 if (!fixP
->fx_addsy
)
2089 buf
[2] |= (val
>> 8) & 0x03;
2095 case BFD_RELOC_SPARC_BASE13
:
2096 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2097 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2099 as_bad ("relocation overflow");
2101 buf
[2] |= (val
>> 8) & 0x1f;
2105 case BFD_RELOC_SPARC_WDISP22
:
2106 val
= (val
>>= 2) + 1;
2108 case BFD_RELOC_SPARC_BASE22
:
2109 buf
[1] |= (val
>> 16) & 0x3f;
2114 case BFD_RELOC_NONE
:
2116 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2120 #ifdef BFD_ASSEMBLER
2125 /* should never be called for sparc */
2127 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2134 as_fatal ("sparc_create_short_jmp\n");
2137 #ifdef BFD_ASSEMBLER
2139 /* Translate internal representation of relocation info to BFD target
2142 tc_gen_reloc (section
, fixp
)
2147 bfd_reloc_code_real_type code
;
2149 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2150 assert (reloc
!= 0);
2152 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2153 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2154 if (fixp
->fx_pcrel
== 0)
2155 reloc
->addend
= fixp
->fx_addnumber
;
2157 switch (OUTPUT_FLAVOR
)
2159 case bfd_target_elf_flavour
:
2162 case bfd_target_aout_flavour
:
2163 reloc
->addend
= - reloc
->address
;
2166 /* What's a good default here? Is there any?? */
2170 switch (fixp
->fx_r_type
)
2173 case BFD_RELOC_HI22
:
2174 case BFD_RELOC_LO10
:
2175 case BFD_RELOC_32_PCREL_S2
:
2176 case BFD_RELOC_SPARC_BASE13
:
2177 case BFD_RELOC_SPARC_WDISP22
:
2178 /* start-sanitize-v9 */
2180 case BFD_RELOC_SPARC_10
:
2181 case BFD_RELOC_SPARC_11
:
2182 case BFD_RELOC_SPARC_HH22
:
2183 case BFD_RELOC_SPARC_HM10
:
2184 case BFD_RELOC_SPARC_LM22
:
2185 case BFD_RELOC_SPARC_PC_HH22
:
2186 case BFD_RELOC_SPARC_PC_HM10
:
2187 case BFD_RELOC_SPARC_PC_LM22
:
2188 /* end-sanitize-v9 */
2189 code
= fixp
->fx_r_type
;
2194 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2195 assert (reloc
->howto
!= 0);
2202 /* Translate internal representation of relocation info to target format.
2204 On sparc: first 4 bytes are normal unsigned long address, next three
2205 bytes are index, most sig. byte first. Byte 7 is broken up with
2206 bit 7 as external, bits 6 & 5 unused, and the lower
2207 five bits as relocation type. Next 4 bytes are long addend. */
2208 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2210 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2213 relax_addressT segment_address_in_file
;
2220 know (fixP
->fx_addsy
);
2222 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2225 r_index
= fixP
->fx_addsy
->sy_number
;
2230 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2234 md_number_to_chars (where
,
2235 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2238 /* now the fun stuff */
2239 where
[4] = (r_index
>> 16) & 0x0ff;
2240 where
[5] = (r_index
>> 8) & 0x0ff;
2241 where
[6] = r_index
& 0x0ff;
2242 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2245 if (fixP
->fx_addsy
->sy_frag
)
2247 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2252 r_addend
+= fixP
->fx_offset
- r_address
;
2256 r_addend
= fixP
->fx_addnumber
;
2259 md_number_to_chars (&where
[8], r_addend
, 4);
2262 } /* tc_aout_fix_to_chars() */
2265 /* should never be called for sparc */
2267 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2269 addressT from_addr
, to_addr
;
2273 as_fatal ("sparc_create_long_jump\n");
2274 } /* md_create_long_jump() */
2276 /* should never be called for sparc */
2278 md_estimate_size_before_relax (fragP
, segtype
)
2282 as_fatal ("sparc_estimate_size_before_relax\n");
2284 } /* md_estimate_size_before_relax() */
2287 /* for debugging only */
2290 struct sparc_it
*insn
;
2323 fprintf (stderr
, "ERROR: %s\n");
2325 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2326 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2327 fprintf (stderr
, "exp = {\n");
2328 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2329 ((insn
->exp
.X_add_symbol
!= NULL
)
2330 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2331 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2334 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2335 ((insn
->exp
.X_op_symbol
!= NULL
)
2336 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2337 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2340 fprintf (stderr
, "\t\tX_add_number = %d\n",
2341 insn
->exp
.X_add_number
);
2342 fprintf (stderr
, "}\n");
2344 } /* print_insn() */
2350 * Invocation line includes a switch not recognized by the base assembler.
2351 * See if it's a processor-specific option. These are:
2354 * Warn on architecture bumps. See also -A.
2356 * -Av6, -Av7, -Av8, -Asparclite
2357 * Select the architecture. Instructions or features not
2358 * supported by the selected architecture cause fatal errors.
2360 * The default is to start at v6, and bump the architecture up
2361 * whenever an instruction is seen at a higher level.
2363 * If -bump is specified, a warning is printing when bumping to
2366 * If an architecture is specified, all instructions must match
2367 * that architecture. Any higher level instructions are flagged
2370 * if both an architecture and -bump are specified, the
2371 * architecture starts at the specified level, but bumps are
2376 * Another architecture switch.
2379 * Bumping between incompatible architectures is always an
2380 * error. For example, from sparclite to v9.
2385 md_parse_option (argP
, cntP
, vecP
)
2393 if (!strcmp (*argP
, "bump"))
2398 else if (**argP
== 'A')
2402 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2404 if (strcmp (p
, *arch
) == 0)
2407 } /* found a match */
2408 } /* walk the pname table */
2412 as_bad ("unknown architecture: %s", p
);
2416 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2417 architecture_requested
= 1;
2421 else if (**argP
== 'V')
2423 extern void print_version_id ();
2424 print_version_id ();
2426 else if (**argP
== 'Q')
2428 /* Qy - do emit .comment
2429 Qn - do not emit .comment */
2431 else if (**argP
== 's')
2433 /* use .stab instead of .stab.excl */
2438 /* Unknown option */
2442 **argP
= '\0'; /* Done parsing this switch */
2444 } /* md_parse_option() */
2446 /* We have no need to default values of symbols. */
2450 md_undefined_symbol (name
)
2454 } /* md_undefined_symbol() */
2456 /* Parse an operand that is machine-specific.
2457 We just return without modifying the expression if we have nothing
2462 md_operand (expressionP
)
2463 expressionS
*expressionP
;
2467 /* Round up a section size to the appropriate boundary. */
2469 md_section_align (segment
, size
)
2474 /* Round all sects to multiple of 8 */
2475 size
= (size
+ 7) & ~7;
2480 /* Exactly what point is a PC-relative offset relative TO?
2481 On the sparc, they're relative to the address of the offset, plus
2482 its size. This gets us to the following instruction.
2483 (??? Is this right? FIXME-SOON) */
2485 md_pcrel_from (fixP
)
2488 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2491 #ifndef BFD_ASSEMBLER
2493 tc_aout_pre_write_hook (headers
)
2494 object_headers
*headers
;
2496 H_SET_VERSION (headers
, 1);
2500 /* end of tc-sparc.c */