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},
84 {"local", s_local
, 0},
86 {"optim", s_ignore
, 0},
88 {"reserve", s_reserve
, 0},
92 /* start-sanitize-v9 */
94 {"xword", s_xword
, 0},
100 const int md_short_jump_size
= 4;
101 const int md_long_jump_size
= 4;
102 const int md_reloc_size
= 12; /* Size of relocation record */
104 /* This array holds the chars that always start a comment. If the
105 pre-processor is disabled, these aren't very useful */
106 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
108 /* This array holds the chars that only start a comment at the beginning of
109 a line. If the line seems to have the form '# 123 filename'
110 .line and .file directives will appear in the pre-processed output */
111 /* Note that input_file.c hand checks for '#' at the beginning of the
112 first line of the input file. This is because the compiler outputs
113 #NO_APP at the beginning of its output. */
114 /* Also note that comments started like this one will always
115 work if '/' isn't otherwise defined. */
116 const char line_comment_chars
[] = "#";
118 const char line_separator_chars
[] = "";
120 /* Chars that can be used to separate mant from exp in floating point nums */
121 const char EXP_CHARS
[] = "eE";
123 /* Chars that mean this number is a floating point constant */
126 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
128 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
129 changed in read.c . Ideally it shouldn't have to know about it at all,
130 but nothing is ideal around here.
133 static unsigned char octal
[256];
134 #define isoctal(c) octal[c]
135 static unsigned char toHex
[256];
140 unsigned long opcode
;
141 struct nlist
*nlistp
;
145 bfd_reloc_code_real_type reloc
;
147 enum reloc_type reloc
;
151 struct sparc_it the_insn
, set_insn
;
154 static void print_insn
PARAMS ((struct sparc_it
*insn
));
156 static int getExpression
PARAMS ((char *str
));
158 static char *expr_end
;
159 static int special_case
;
162 * Instructions that require wierd handling because they're longer than
165 #define SPECIAL_CASE_SET 1
166 #define SPECIAL_CASE_FDIV 2
169 * sort of like s_lcomm
172 static int max_alignment
= 15;
185 name
= input_line_pointer
;
186 c
= get_symbol_end ();
187 p
= input_line_pointer
;
191 if (*input_line_pointer
!= ',')
193 as_bad ("Expected comma after name");
194 ignore_rest_of_line ();
198 ++input_line_pointer
;
200 if ((size
= get_absolute_expression ()) < 0)
202 as_bad ("BSS length (%d.) <0! Ignored.", size
);
203 ignore_rest_of_line ();
208 symbolP
= symbol_find_or_make (name
);
211 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
212 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
214 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
218 if (input_line_pointer
[2] == '.')
219 input_line_pointer
+= 7;
221 input_line_pointer
+= 6;
224 if (*input_line_pointer
== ',')
226 ++input_line_pointer
;
229 if (*input_line_pointer
== '\n')
231 as_bad ("Missing alignment");
235 align
= get_absolute_expression ();
236 if (align
> max_alignment
)
238 align
= max_alignment
;
239 as_warn ("Alignment too large: %d. assumed.", align
);
244 as_warn ("Alignment negative. 0 assumed.");
247 record_alignment (bss_section
, align
);
249 /* convert to a power of 2 alignment */
250 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
254 as_bad ("Alignment not a power of 2");
255 ignore_rest_of_line ();
257 } /* not a power of two */
260 } /* if has optional alignment */
264 if ((S_GET_SEGMENT (symbolP
) == bss_section
265 || !S_IS_DEFINED (symbolP
))
267 && S_GET_OTHER (symbolP
) == 0
268 && S_GET_DESC (symbolP
) == 0
275 segT current_seg
= now_seg
;
276 subsegT current_subseg
= now_subseg
;
278 subseg_set (bss_section
, 1); /* switch to bss */
281 frag_align (align
, 0); /* do alignment */
283 /* detach from old frag */
284 if (S_GET_SEGMENT(symbolP
) == bss_section
)
285 symbolP
->sy_frag
->fr_symbol
= NULL
;
287 symbolP
->sy_frag
= frag_now
;
288 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
292 S_SET_SEGMENT (symbolP
, bss_section
);
294 subseg_set (current_seg
, current_subseg
);
299 as_warn("Ignoring attempt to re-define symbol %s.", name
);
300 } /* if not redefining */
302 demand_empty_rest_of_line ();
306 /* Currently used only by Solaris 2. */
316 name
= input_line_pointer
;
317 c
= get_symbol_end ();
318 symbolP
= symbol_find_or_make (name
);
319 *input_line_pointer
= c
;
321 S_CLEAR_EXTERNAL (symbolP
);
325 input_line_pointer
++;
327 if (*input_line_pointer
== '\n')
332 demand_empty_rest_of_line ();
345 name
= input_line_pointer
;
346 c
= get_symbol_end ();
347 /* just after name is now '\0' */
348 p
= input_line_pointer
;
351 if (*input_line_pointer
!= ',')
353 as_bad ("Expected comma after symbol-name");
354 ignore_rest_of_line ();
357 input_line_pointer
++; /* skip ',' */
358 if ((temp
= get_absolute_expression ()) < 0)
360 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
361 ignore_rest_of_line ();
366 symbolP
= symbol_find_or_make (name
);
368 if (S_IS_DEFINED (symbolP
))
370 as_bad ("Ignoring attempt to re-define symbol");
371 ignore_rest_of_line ();
374 if (S_GET_VALUE (symbolP
) != 0)
376 if (S_GET_VALUE (symbolP
) != size
)
378 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
379 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
385 S_SET_VALUE (symbolP
, size
);
386 S_SET_EXTERNAL (symbolP
);
389 know (symbolP
->sy_frag
== &zero_address_frag
);
391 if (*input_line_pointer
!= ',')
393 as_bad ("Expected comma after common length");
394 ignore_rest_of_line ();
397 input_line_pointer
++;
399 if (*input_line_pointer
!= '"')
401 temp
= get_absolute_expression ();
402 if (temp
> max_alignment
)
404 temp
= max_alignment
;
405 as_warn ("Common alignment too large: %d. assumed", temp
);
410 as_warn ("Common alignment negative; 0 assumed");
414 segT old_sec
= now_seg
;
415 int old_subsec
= now_subseg
;
419 record_alignment (bss_section
, align
);
420 subseg_set (bss_section
, 0);
422 frag_align (align
, 0);
423 if (S_GET_SEGMENT (symbolP
) == bss_section
)
424 symbolP
->sy_frag
->fr_symbol
= 0;
425 symbolP
->sy_frag
= frag_now
;
426 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
429 S_SET_SEGMENT (symbolP
, bss_section
);
430 S_CLEAR_EXTERNAL (symbolP
);
431 subseg_set (old_sec
, old_subsec
);
435 S_SET_VALUE (symbolP
, size
);
436 S_SET_EXTERNAL (symbolP
);
437 /* should be common, but this is how gas does it for now */
438 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
443 input_line_pointer
++;
444 if (strncmp (input_line_pointer
, "bss\"", 4)
445 && strncmp (input_line_pointer
, ".bss\"", 5))
447 input_line_pointer
-= 2;
448 goto bad_common_segment
;
450 while (*input_line_pointer
++ != '"')
452 demand_empty_rest_of_line ();
456 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
457 && strncmp (input_line_pointer
, ",\"data\"", 7) != 0)
460 p
= input_line_pointer
;
461 while (*p
&& *p
!= '\n')
465 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
469 input_line_pointer
+= 6 + (input_line_pointer
[2] == 'd'); /* Skip either */
470 demand_empty_rest_of_line ();
478 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
480 input_line_pointer
+= 6;
484 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
486 input_line_pointer
+= 6;
490 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
492 input_line_pointer
+= 7;
496 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
498 input_line_pointer
+= 5;
499 /* We only support 2 segments -- text and data -- for now, so
500 things in the "bss segment" will have to go into data for now.
501 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
502 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
505 as_bad ("Unknown segment type");
506 demand_empty_rest_of_line ();
513 subseg_set (data_section
, 1);
514 demand_empty_rest_of_line ();
521 extern char is_end_of_line
[];
523 while (!is_end_of_line
[*input_line_pointer
])
525 ++input_line_pointer
;
527 ++input_line_pointer
;
531 /* start-sanitize-v9 */
537 if (isdigit (*input_line_pointer
))
543 struct priv_reg_entry
549 struct priv_reg_entry priv_reg_table
[] =
568 {"", -1}, /* end marker */
578 #define MEMBAR_MASKS_SIZE 7
580 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
583 {"MemIssue", 8, 0x20},
584 {"Lookaside", 9, 0x10},
585 {"StoreStore", 10, 0x08},
586 {"LoadStore", 9, 0x04},
587 {"StoreLoad", 9, 0x02},
588 {"LoadLoad", 8, 0x01},
593 struct priv_reg_entry
*p
, *q
;
595 return strcmp (q
->name
, p
->name
);
599 /* end-sanitize-v9 */
601 /* This function is called once, at assembler startup time. It should
602 set up all the tables, etc. that the MD part of the assembler will need. */
606 register char *retval
= NULL
;
608 register unsigned int i
= 0;
610 op_hash
= hash_new ();
612 as_fatal ("Virtual memory exhausted");
614 while (i
< NUMOPCODES
)
616 const char *name
= sparc_opcodes
[i
].name
;
617 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
618 if (retval
!= NULL
&& *retval
!= '\0')
620 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
621 sparc_opcodes
[i
].name
, retval
);
626 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
628 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
629 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
634 while (i
< NUMOPCODES
635 && !strcmp (sparc_opcodes
[i
].name
, name
));
639 as_fatal ("Broken assembler. No assembly attempted.");
641 for (i
= '0'; i
< '8'; ++i
)
643 for (i
= '0'; i
<= '9'; ++i
)
645 for (i
= 'a'; i
<= 'f'; ++i
)
646 toHex
[i
] = i
+ 10 - 'a';
647 for (i
= 'A'; i
<= 'F'; ++i
)
648 toHex
[i
] = i
+ 10 - 'A';
650 /* start-sanitize-v9 */
653 current_architecture
= v9
;
656 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
657 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
659 /* end-sanitize-v9 */
661 target_big_endian
= 1;
680 /* See if "set" operand is absolute and small; skip sethi if so. */
681 if (special_case
== SPECIAL_CASE_SET
682 && the_insn
.exp
.X_seg
== absolute_section
)
684 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
685 && the_insn
.exp
.X_add_number
< (1 << 12))
687 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
688 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
689 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
690 special_case
= 0; /* No longer special */
691 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
696 /* put out the opcode */
697 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
699 /* put out the symbol-dependent stuff */
700 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
702 fix_new (frag_now
, /* which frag */
703 (toP
- frag_now
->fr_literal
), /* where */
705 the_insn
.exp
.X_add_symbol
,
706 the_insn
.exp
.X_subtract_symbol
,
707 the_insn
.exp
.X_add_number
,
712 switch (special_case
)
714 case SPECIAL_CASE_SET
:
716 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
717 /* See if "set" operand has no low-order bits; skip OR if so. */
718 if (the_insn
.exp
.X_seg
== absolute_section
719 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
722 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
723 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
724 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
725 fix_new (frag_now
, /* which frag */
726 (toP
- frag_now
->fr_literal
), /* where */
728 the_insn
.exp
.X_add_symbol
,
729 the_insn
.exp
.X_subtract_symbol
,
730 the_insn
.exp
.X_add_number
,
736 case SPECIAL_CASE_FDIV
:
737 /* According to information leaked from Sun, the "fdiv" instructions
738 on early SPARC machines would produce incorrect results sometimes.
739 The workaround is to add an fmovs of the destination register to
740 itself just after the instruction. This was true on machines
741 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
743 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
745 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
746 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
747 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
754 as_fatal ("failed sanity check.");
756 } /* md_assemble() */
762 char *error_message
= "";
766 struct sparc_opcode
*insn
;
768 unsigned long opcode
;
769 unsigned int mask
= 0;
772 long immediate_max
= 0;
774 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
792 as_bad ("Unknown opcode: `%s'", str
);
795 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
797 as_bad ("Unknown opcode: `%s'", str
);
807 opcode
= insn
->match
;
808 memset (&the_insn
, '\0', sizeof (the_insn
));
809 the_insn
.reloc
= BFD_RELOC_NONE
;
812 * Build the opcode, checking as we go to make
813 * sure that the operands match
815 for (args
= insn
->args
;; ++args
)
820 /* start-sanitize-v9 */
827 /* Parse a series of masks. */
833 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
834 if (!strncmp (s
, membar_masks
[i
].name
,
835 membar_masks
[i
].len
))
837 if (i
< MEMBAR_MASKS_SIZE
)
839 mask
|= membar_masks
[i
].mask
;
840 s
+= membar_masks
[i
].len
;
844 error_message
= ": invalid membar mask name";
851 else if (isdigit (*s
))
855 mask
= mask
* 10 + *s
- '0';
859 if (mask
< 0 || mask
> 127)
861 error_message
= ": invalid membar mask number";
867 error_message
= ": unrecognizable membar mask";
870 opcode
|= SIMM13 (mask
);
876 int prefetch_fcn
= 0;
878 /* Parse a prefetch function. */
882 if (!strncmp (s
, "n_reads", 7))
883 prefetch_fcn
= 0, s
+= 7;
884 else if (!strncmp (s
, "one_read", 8))
885 prefetch_fcn
= 1, s
+= 8;
886 else if (!strncmp (s
, "n_writes", 8))
887 prefetch_fcn
= 2, s
+= 8;
888 else if (!strncmp (s
, "one_write", 9))
889 prefetch_fcn
= 3, s
+= 9;
890 else if (!strncmp (s
, "page", 4))
891 prefetch_fcn
= 4, s
+= 4;
894 error_message
= ": invalid prefetch function name";
898 else if (isdigit (*s
))
902 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
906 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
908 error_message
= ": invalid prefetch function number";
914 error_message
= ": unrecognizable prefetch function";
917 opcode
|= RD (prefetch_fcn
);
923 /* Parse a privileged register. */
926 struct priv_reg_entry
*p
= priv_reg_table
;
927 int len
= 9999999; /* init to make gcc happy */
930 while (p
->name
[0] > s
[0])
932 while (p
->name
[0] == s
[0])
934 len
= strlen (p
->name
);
935 if (strncmp (p
->name
, s
, len
) == 0)
939 if (p
->name
[0] != s
[0])
941 error_message
= ": unrecognizable privileged register";
945 opcode
|= (p
->regnum
<< 14);
947 opcode
|= (p
->regnum
<< 25);
953 error_message
= ": unrecognizable privileged register";
957 /* end-sanitize-v9 */
961 if (strncmp (s
, "%asr", 4) == 0)
971 num
= num
* 10 + *s
- '0';
975 if (num
< 16 || 31 < num
)
977 error_message
= ": asr number must be between 15 and 31";
981 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
986 error_message
= ": expecting %asrN";
988 } /* if %asr followed by a number. */
993 /* start-sanitize-v9 */
996 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
997 immediate_max
= 0x03FF;
1001 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1002 immediate_max
= 0x01FF;
1006 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1011 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1016 if (*s
== 'p' && s
[1] == 'n')
1024 if (*s
== 'p' && s
[1] == 't')
1036 if (strncmp (s
, "%icc", 4) == 0)
1048 if (strncmp (s
, "%xcc", 4) == 0)
1060 if (strncmp (s
, "%fcc0", 5) == 0)
1072 if (strncmp (s
, "%fcc1", 5) == 0)
1084 if (strncmp (s
, "%fcc2", 5) == 0)
1096 if (strncmp (s
, "%fcc3", 5) == 0)
1104 if (strncmp (s
, "%pc", 3) == 0)
1112 if (strncmp (s
, "%tick", 5) == 0)
1119 /* end-sanitize-v9 */
1121 case '\0': /* end of args */
1140 case '[': /* these must match exactly */
1148 case '#': /* must be at least one digit */
1151 while (isdigit (*s
))
1159 case 'C': /* coprocessor state register */
1160 if (strncmp (s
, "%csr", 4) == 0)
1167 case 'b': /* next operand is a coprocessor register */
1170 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1175 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1189 opcode
|= mask
<< 14;
1197 opcode
|= mask
<< 25;
1203 case 'r': /* next operand must be a register */
1212 case 'f': /* frame pointer */
1220 case 'g': /* global register */
1221 if (isoctal (c
= *s
++))
1228 case 'i': /* in register */
1229 if (isoctal (c
= *s
++))
1231 mask
= c
- '0' + 24;
1236 case 'l': /* local register */
1237 if (isoctal (c
= *s
++))
1239 mask
= (c
- '0' + 16);
1244 case 'o': /* out register */
1245 if (isoctal (c
= *s
++))
1247 mask
= (c
- '0' + 8);
1252 case 's': /* stack pointer */
1260 case 'r': /* any register */
1261 if (!isdigit (c
= *s
++))
1278 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1294 * Got the register, now figure out where
1295 * it goes in the opcode.
1301 opcode
|= mask
<< 14;
1309 opcode
|= mask
<< 25;
1313 opcode
|= (mask
<< 25) | (mask
<< 14);
1319 case 'e': /* next operand is a floating point register */
1334 && ((format
= *s
) == 'f')
1337 for (mask
= 0; isdigit (*s
); ++s
)
1339 mask
= 10 * mask
+ (*s
- '0');
1340 } /* read the number */
1348 } /* register must be even numbered */
1356 } /* register must be multiple of 4 */
1358 /* start-sanitize-v9 */
1362 error_message
= ": There are only 64 f registers; [0-63]";
1368 } /* wrap high bit */
1370 /* end-sanitize-v9 */
1373 error_message
= ": There are only 32 f registers; [0-31]";
1376 /* start-sanitize-v9 */
1378 /* end-sanitize-v9 */
1383 } /* if not an 'f' register. */
1391 opcode
|= RS1 (mask
);
1398 opcode
|= RS2 (mask
);
1404 opcode
|= RD (mask
);
1413 if (strncmp (s
, "%fsr", 4) == 0)
1420 case 'h': /* high 22 bits */
1421 the_insn
.reloc
= BFD_RELOC_HI22
;
1424 case 'l': /* 22 bit PC relative immediate */
1425 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1429 case 'L': /* 30 bit immediate */
1430 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1434 case 'n': /* 22 bit immediate */
1435 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1438 case 'i': /* 13 bit immediate */
1439 /* What's the difference between base13 and 13? */
1440 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1441 immediate_max
= 0x0FFF;
1450 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1452 the_insn
.reloc
= BFD_RELOC_HI22
;
1455 else if (c
== 'l' && s
[2] == 'o')
1457 the_insn
.reloc
= BFD_RELOC_LO10
;
1459 /* start-sanitize-v9 */
1466 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1473 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1476 /* end-sanitize-v9 */
1481 /* Note that if the getExpression() fails, we
1482 will still have created U entries in the
1483 symbol table for the 'symbols' in the input
1484 string. Try not to create U symbols for
1487 /* This stuff checks to see if the
1488 expression ends in +%reg If it does,
1489 it removes the register from the
1490 expression, and re-sets 's' to point
1491 to the right place */
1495 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1497 if (s1
!= s
&& isdigit (s1
[-1]))
1499 if (s1
[-2] == '%' && s1
[-3] == '+')
1503 (void) getExpression (s
);
1508 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1512 (void) getExpression (s
);
1519 (void) getExpression (s
);
1522 /* Check for invalid constant values. Don't
1523 warn if constant was inside %hi or %lo,
1524 since these truncate the constant to
1526 if (immediate_max
!= 0
1527 && the_insn
.reloc
!= BFD_RELOC_LO10
1528 && the_insn
.reloc
!= BFD_RELOC_HI22
1529 /* start-sanitize-v9 */
1531 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1532 && the_insn
.reloc
!= RELOC_HLO10
1533 && the_insn
.reloc
!= RELOC_HHI22
1536 /* end-sanitize-v9 */
1537 && the_insn
.exp
.X_add_symbol
== 0
1538 && the_insn
.exp
.X_subtract_symbol
== 0
1539 && the_insn
.exp
.X_seg
== absolute_section
1540 && (the_insn
.exp
.X_add_number
> immediate_max
1541 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1542 as_bad ("constant value must be between %ld and %ld",
1543 ~immediate_max
, immediate_max
);
1544 /* Reset to prevent extraneous range check. */
1559 /* start-sanitize-v9 */
1561 /* end-sanitize-v9 */
1562 char *push
= input_line_pointer
;
1565 input_line_pointer
= s
;
1567 if (expression (&e
) == absolute_section
)
1569 opcode
|= e
.X_add_number
<< 5;
1570 s
= input_line_pointer
;
1571 input_line_pointer
= push
;
1576 /* start-sanitize-v9 */
1584 if (!strncmp (s
, "ASI_AIUP", 8))
1586 else if (!strncmp (s
, "ASI_AIUS", 8))
1588 else if (!strncmp (s
, "ASI_PNF", 7))
1590 else if (!strncmp (s
, "ASI_SNF", 7))
1592 else if (!strncmp (s
, "ASI_P", 5))
1594 else if (!strncmp (s
, "ASI_S", 5))
1598 error_message
= ": invalid asi name";
1602 else if (isdigit (*s
))
1604 char *push
= input_line_pointer
;
1605 input_line_pointer
= s
;
1606 asi
= get_absolute_expression ();
1607 s
= input_line_pointer
;
1608 input_line_pointer
= push
;
1610 if (asi
< 0 || asi
> 255)
1612 error_message
= ": invalid asi number";
1618 error_message
= ": unrecognizable asi";
1621 opcode
|= ASI (asi
);
1624 /* end-sanitize-v9 */
1625 } /* alternate space */
1628 if (strncmp (s
, "%psr", 4) == 0)
1635 case 'q': /* floating point queue */
1636 if (strncmp (s
, "%fq", 3) == 0)
1643 case 'Q': /* coprocessor queue */
1644 if (strncmp (s
, "%cq", 3) == 0)
1652 if (strcmp (str
, "set") == 0)
1654 special_case
= SPECIAL_CASE_SET
;
1657 else if (strncmp (str
, "fdiv", 4) == 0)
1659 special_case
= SPECIAL_CASE_FDIV
;
1664 /* start-sanitize-v9 */
1667 if (strncmp (s
, "%asi", 4) != 0)
1673 if (strncmp (s
, "%fprs", 5) != 0)
1679 if (strncmp (s
, "%ccr", 4) != 0)
1684 /* end-sanitize-v9 */
1687 if (strncmp (s
, "%tbr", 4) != 0)
1693 if (strncmp (s
, "%wim", 4) != 0)
1699 if (strncmp (s
, "%y", 2) != 0)
1705 as_fatal ("failed sanity check.");
1706 } /* switch on arg code */
1708 } /* for each arg that we expect */
1712 /* Args don't match. */
1713 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1714 && !strcmp (insn
->name
, insn
[1].name
))
1722 as_bad ("Illegal operands%s", error_message
);
1728 if (insn
->architecture
> current_architecture
)
1730 if ((!architecture_requested
|| warn_on_bump
)
1732 /* start-sanitize-v9 */
1734 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1737 /* end-sanitize-v9 */
1739 /* start-sanitize-v9 */
1741 /* end-sanitize-v9 */
1746 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1747 architecture_pname
[current_architecture
],
1748 architecture_pname
[insn
->architecture
],
1752 current_architecture
= insn
->architecture
;
1756 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1758 architecture_pname
[insn
->architecture
],
1759 architecture_pname
[current_architecture
]);
1761 } /* if bump ok else error */
1762 } /* if architecture higher */
1766 } /* forever looking for a match */
1768 the_insn
.opcode
= opcode
;
1779 save_in
= input_line_pointer
;
1780 input_line_pointer
= str
;
1781 seg
= expression (&the_insn
.exp
);
1782 if (seg
== absolute_section
1783 || seg
== text_section
1784 || seg
== data_section
1785 || seg
== bss_section
1786 || seg
== undefined_section
1787 || seg
== diff_section
1788 || seg
== big_section
1789 || seg
== absent_section
)
1793 the_insn
.error
= "bad segment";
1794 expr_end
= input_line_pointer
;
1795 input_line_pointer
= save_in
;
1798 expr_end
= input_line_pointer
;
1799 input_line_pointer
= save_in
;
1801 } /* getExpression() */
1805 This is identical to the md_atof in m68k.c. I think this is right,
1808 Turn a string in input_line_pointer into a floating point constant of type
1809 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1810 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1813 /* Equal to MAX_PRECISION in atof-ieee.c */
1814 #define MAX_LITTLENUMS 6
1817 md_atof (type
, litP
, sizeP
)
1823 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1824 LITTLENUM_TYPE
*wordP
;
1857 return "Bad call to MD_ATOF()";
1859 t
= atof_ieee (input_line_pointer
, type
, words
);
1861 input_line_pointer
= t
;
1862 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1863 for (wordP
= words
; prec
--;)
1865 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1866 litP
+= sizeof (LITTLENUM_TYPE
);
1872 * Write out big-endian.
1875 md_number_to_chars (buf
, val
, n
)
1883 /* start-sanitize-v9 */
1889 /* end-sanitize-v9 */
1900 as_fatal ("failed sanity check.");
1903 } /* md_number_to_chars() */
1905 /* Apply a fixS to the frags, now that we know the value it ought to
1908 #ifdef BFD_ASSEMBLER
1913 md_apply_fix (fixP
, value
)
1915 #ifdef BFD_ASSEMBLER
1921 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1924 #ifdef BFD_ASSEMBLER
1930 #ifdef BFD_ASSEMBLER
1931 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1933 assert (fixP
->fx_r_type
< NO_RELOC
);
1936 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1939 * This is a hack. There should be a better way to
1942 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1944 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1947 switch (fixP
->fx_r_type
)
1951 buf
[0] = 0; /* val >> 24; */
1952 buf
[1] = 0; /* val >> 16; */
1953 buf
[2] = 0; /* val >> 8; */
1954 buf
[3] = 0; /* val; */
1957 case BFD_RELOC_32_PCREL_S2
:
1958 val
= (val
>>= 2) + 1;
1959 buf
[0] |= (val
>> 24) & 0x3f;
1960 buf
[1] = (val
>> 16);
1965 /* start-sanitize-v9 */
1967 case BFD_RELOC_SPARC_11
:
1968 if (((val
> 0) && (val
& ~0x7ff))
1969 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1971 as_bad ("relocation overflow.");
1974 buf
[2] |= (val
>> 8) & 0x7;
1975 buf
[3] = val
& 0xff;
1978 case BFD_RELOC_SPARC_10
:
1979 if (((val
> 0) && (val
& ~0x3ff))
1980 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1982 as_bad ("relocation overflow.");
1985 buf
[2] |= (val
>> 8) & 0x3;
1986 buf
[3] = val
& 0xff;
1989 case BFD_RELOC_SPARC_WDISP16
:
1990 if (((val
> 0) && (val
& ~0x3fffc))
1991 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1993 as_bad ("relocation overflow.");
1996 val
= (val
>>= 2) + 1;
1997 buf
[1] |= ((val
>> 14) & 0x3) << 4;
1998 buf
[2] |= (val
>> 8) & 0x3f;
1999 buf
[3] = val
& 0xff;
2002 case BFD_RELOC_SPARC_WDISP19
:
2003 if (((val
> 0) && (val
& ~0x1ffffc))
2004 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2006 as_bad ("relocation overflow.");
2009 val
= (val
>>= 2) + 1;
2010 buf
[1] |= (val
>> 16) & 0x7;
2011 buf
[2] = (val
>> 8) & 0xff;
2012 buf
[3] = val
& 0xff;
2015 case BFD_RELOC_SPARC_HH22
:
2017 /* intentional fallthrough */
2019 /* end-sanitize-v9 */
2021 /* start-sanitize-v9 */
2023 case BFD_RELOC_SPARC_LM22
:
2025 /* end-sanitize-v9 */
2026 case BFD_RELOC_HI22
:
2027 if (!fixP
->fx_addsy
)
2029 buf
[1] |= (val
>> 26) & 0x3f;
2040 case BFD_RELOC_SPARC22
:
2041 if (val
& ~0x003fffff)
2043 as_bad ("relocation overflow");
2045 buf
[1] |= (val
>> 16) & 0x3f;
2047 buf
[3] = val
& 0xff;
2050 case BFD_RELOC_SPARC13
:
2051 if (val
& ~0x00001fff)
2053 as_bad ("relocation overflow");
2055 buf
[2] |= (val
>> 8) & 0x1f;
2056 buf
[3] = val
& 0xff;
2059 /* start-sanitize-v9 */
2061 case BFD_RELOC_SPARC_HM10
:
2063 /* intentional fallthrough */
2065 /* end-sanitize-v9 */
2067 case BFD_RELOC_LO10
:
2068 if (!fixP
->fx_addsy
)
2070 buf
[2] |= (val
>> 8) & 0x03;
2076 case BFD_RELOC_SPARC_BASE13
:
2077 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2078 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2080 as_bad ("relocation overflow");
2082 buf
[2] |= (val
>> 8) & 0x1f;
2086 case BFD_RELOC_SPARC_WDISP22
:
2087 val
= (val
>>= 2) + 1;
2089 case BFD_RELOC_SPARC_BASE22
:
2090 buf
[1] |= (val
>> 16) & 0x3f;
2095 case BFD_RELOC_NONE
:
2097 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2101 #ifdef BFD_ASSEMBLER
2106 /* should never be called for sparc */
2108 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2115 as_fatal ("sparc_create_short_jmp\n");
2118 #ifdef BFD_ASSEMBLER
2120 /* Translate internal representation of relocation info to BFD target
2123 tc_gen_reloc (section
, fixp
)
2128 bfd_reloc_code_real_type code
;
2130 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2131 assert (reloc
!= 0);
2133 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2134 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2135 if (fixp
->fx_pcrel
== 0)
2136 reloc
->addend
= fixp
->fx_addnumber
;
2138 switch (OUTPUT_FLAVOR
)
2140 case bfd_target_elf_flavour
:
2143 case bfd_target_aout_flavour
:
2144 reloc
->addend
= - reloc
->address
;
2147 /* What's a good default here? Is there any?? */
2151 switch (fixp
->fx_r_type
)
2154 case BFD_RELOC_HI22
:
2155 case BFD_RELOC_LO10
:
2156 case BFD_RELOC_32_PCREL_S2
:
2157 case BFD_RELOC_SPARC_BASE13
:
2158 case BFD_RELOC_SPARC_WDISP22
:
2159 /* start-sanitize-v9 */
2160 case BFD_RELOC_SPARC_10
:
2161 case BFD_RELOC_SPARC_11
:
2162 case BFD_RELOC_SPARC_HH22
:
2163 case BFD_RELOC_SPARC_HM10
:
2164 case BFD_RELOC_SPARC_LM22
:
2165 case BFD_RELOC_SPARC_PC_HH22
:
2166 case BFD_RELOC_SPARC_PC_HM10
:
2167 case BFD_RELOC_SPARC_PC_LM22
:
2168 /* end-sanitize-v9 */
2169 code
= fixp
->fx_r_type
;
2174 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2175 assert (reloc
->howto
!= 0);
2182 /* Translate internal representation of relocation info to target format.
2184 On sparc: first 4 bytes are normal unsigned long address, next three
2185 bytes are index, most sig. byte first. Byte 7 is broken up with
2186 bit 7 as external, bits 6 & 5 unused, and the lower
2187 five bits as relocation type. Next 4 bytes are long addend. */
2188 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2190 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2193 relax_addressT segment_address_in_file
;
2200 know (fixP
->fx_addsy
);
2202 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2205 r_index
= fixP
->fx_addsy
->sy_number
;
2210 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2214 md_number_to_chars (where
,
2215 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2218 /* now the fun stuff */
2219 where
[4] = (r_index
>> 16) & 0x0ff;
2220 where
[5] = (r_index
>> 8) & 0x0ff;
2221 where
[6] = r_index
& 0x0ff;
2222 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2225 if (fixP
->fx_addsy
->sy_frag
)
2227 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2232 r_addend
+= fixP
->fx_offset
- r_address
;
2236 r_addend
= fixP
->fx_addnumber
;
2239 md_number_to_chars (&where
[8], r_addend
, 4);
2242 } /* tc_aout_fix_to_chars() */
2245 /* should never be called for sparc */
2247 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2249 addressT from_addr
, to_addr
;
2253 as_fatal ("sparc_create_long_jump\n");
2254 } /* md_create_long_jump() */
2256 /* should never be called for sparc */
2258 md_estimate_size_before_relax (fragP
, segtype
)
2262 as_fatal ("sparc_estimate_size_before_relax\n");
2264 } /* md_estimate_size_before_relax() */
2267 /* for debugging only */
2270 struct sparc_it
*insn
;
2303 fprintf (stderr
, "ERROR: %s\n");
2305 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2306 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2307 fprintf (stderr
, "exp = {\n");
2308 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2309 ((insn
->exp
.X_add_symbol
!= NULL
)
2310 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2311 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2314 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2315 ((insn
->exp
.X_subtract_symbol
!= NULL
)
2316 ? (S_GET_NAME (insn
->exp
.X_subtract_symbol
)
2317 ? S_GET_NAME (insn
->exp
.X_subtract_symbol
)
2320 fprintf (stderr
, "\t\tX_add_number = %d\n",
2321 insn
->exp
.X_add_number
);
2322 fprintf (stderr
, "}\n");
2324 } /* print_insn() */
2330 * Invocation line includes a switch not recognized by the base assembler.
2331 * See if it's a processor-specific option. These are:
2334 * Warn on architecture bumps. See also -A.
2336 * -Av6, -Av7, -Av8, -Asparclite
2337 * Select the architecture. Instructions or features not
2338 * supported by the selected architecture cause fatal errors.
2340 * The default is to start at v6, and bump the architecture up
2341 * whenever an instruction is seen at a higher level.
2343 * If -bump is specified, a warning is printing when bumping to
2346 * If an architecture is specified, all instructions must match
2347 * that architecture. Any higher level instructions are flagged
2350 * if both an architecture and -bump are specified, the
2351 * architecture starts at the specified level, but bumps are
2356 * Another architecture switch.
2359 * Bumping between incompatible architectures is always an
2360 * error. For example, from sparclite to v9.
2365 md_parse_option (argP
, cntP
, vecP
)
2373 if (!strcmp (*argP
, "bump"))
2378 else if (**argP
== 'A')
2382 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2384 if (strcmp (p
, *arch
) == 0)
2387 } /* found a match */
2388 } /* walk the pname table */
2392 as_bad ("unknown architecture: %s", p
);
2396 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2397 architecture_requested
= 1;
2401 else if (**argP
== 'V')
2403 extern void print_version_id ();
2404 print_version_id ();
2406 else if (**argP
== 'Q')
2408 /* Qy - do emit .comment
2409 Qn - do not emit .comment */
2411 else if (**argP
== 's')
2413 /* use .stab instead of .stab.excl */
2418 /* Unknown option */
2422 **argP
= '\0'; /* Done parsing this switch */
2424 } /* md_parse_option() */
2426 /* We have no need to default values of symbols. */
2430 md_undefined_symbol (name
)
2434 } /* md_undefined_symbol() */
2436 /* Parse an operand that is machine-specific.
2437 We just return without modifying the expression if we have nothing
2442 md_operand (expressionP
)
2443 expressionS
*expressionP
;
2447 /* Round up a section size to the appropriate boundary. */
2449 md_section_align (segment
, size
)
2453 /* Round all sects to multiple of 8 */
2454 return (size
+ 7) & ~7;
2457 /* Exactly what point is a PC-relative offset relative TO?
2458 On the sparc, they're relative to the address of the offset, plus
2459 its size. This gets us to the following instruction.
2460 (??? Is this right? FIXME-SOON) */
2462 md_pcrel_from (fixP
)
2465 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2468 #ifndef BFD_ASSEMBLER
2470 tc_aout_pre_write_hook (headers
)
2471 object_headers
*headers
;
2473 H_SET_VERSION (headers
, 1);
2477 /* end of tc-sparc.c */