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 /* these are specific to sparc/svr4 */
99 {"pushsection", obj_elf_section
, 0},
100 {"popsection", obj_elf_previous
, 0},
107 const int md_short_jump_size
= 4;
108 const int md_long_jump_size
= 4;
109 const int md_reloc_size
= 12; /* Size of relocation record */
111 /* This array holds the chars that always start a comment. If the
112 pre-processor is disabled, these aren't very useful */
113 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
115 /* This array holds the chars that only start a comment at the beginning of
116 a line. If the line seems to have the form '# 123 filename'
117 .line and .file directives will appear in the pre-processed output */
118 /* Note that input_file.c hand checks for '#' at the beginning of the
119 first line of the input file. This is because the compiler outputs
120 #NO_APP at the beginning of its output. */
121 /* Also note that comments started like this one will always
122 work if '/' isn't otherwise defined. */
123 const char line_comment_chars
[] = "#";
125 const char line_separator_chars
[] = "";
127 /* Chars that can be used to separate mant from exp in floating point nums */
128 const char EXP_CHARS
[] = "eE";
130 /* Chars that mean this number is a floating point constant */
133 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
135 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
136 changed in read.c . Ideally it shouldn't have to know about it at all,
137 but nothing is ideal around here.
140 static unsigned char octal
[256];
141 #define isoctal(c) octal[(unsigned char) (c)]
142 static unsigned char toHex
[256];
147 unsigned long opcode
;
148 struct nlist
*nlistp
;
152 bfd_reloc_code_real_type reloc
;
154 enum reloc_type reloc
;
158 struct sparc_it the_insn
, set_insn
;
161 static void print_insn
PARAMS ((struct sparc_it
*insn
));
163 static int getExpression
PARAMS ((char *str
));
165 static char *expr_end
;
166 static int special_case
;
169 * Instructions that require wierd handling because they're longer than
172 #define SPECIAL_CASE_SET 1
173 #define SPECIAL_CASE_FDIV 2
176 * sort of like s_lcomm
180 static int max_alignment
= 15;
194 name
= input_line_pointer
;
195 c
= get_symbol_end ();
196 p
= input_line_pointer
;
200 if (*input_line_pointer
!= ',')
202 as_bad ("Expected comma after name");
203 ignore_rest_of_line ();
207 ++input_line_pointer
;
209 if ((size
= get_absolute_expression ()) < 0)
211 as_bad ("BSS length (%d.) <0! Ignored.", size
);
212 ignore_rest_of_line ();
217 symbolP
= symbol_find_or_make (name
);
220 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
221 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
223 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
227 if (input_line_pointer
[2] == '.')
228 input_line_pointer
+= 7;
230 input_line_pointer
+= 6;
233 if (*input_line_pointer
== ',')
235 ++input_line_pointer
;
238 if (*input_line_pointer
== '\n')
240 as_bad ("Missing alignment");
244 align
= get_absolute_expression ();
246 if (align
> max_alignment
)
248 align
= max_alignment
;
249 as_warn ("Alignment too large: %d. assumed.", align
);
255 as_warn ("Alignment negative. 0 assumed.");
258 record_alignment (bss_section
, align
);
260 /* convert to a power of 2 alignment */
261 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
265 as_bad ("Alignment not a power of 2");
266 ignore_rest_of_line ();
268 } /* not a power of two */
271 } /* if has optional alignment */
275 if ((S_GET_SEGMENT (symbolP
) == bss_section
276 || !S_IS_DEFINED (symbolP
))
278 && S_GET_OTHER (symbolP
) == 0
279 && S_GET_DESC (symbolP
) == 0
286 segT current_seg
= now_seg
;
287 subsegT current_subseg
= now_subseg
;
289 subseg_set (bss_section
, 1); /* switch to bss */
292 frag_align (align
, 0); /* do alignment */
294 /* detach from old frag */
295 if (S_GET_SEGMENT(symbolP
) == bss_section
)
296 symbolP
->sy_frag
->fr_symbol
= NULL
;
298 symbolP
->sy_frag
= frag_now
;
299 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
303 S_SET_SEGMENT (symbolP
, bss_section
);
305 subseg_set (current_seg
, current_subseg
);
310 as_warn("Ignoring attempt to re-define symbol %s.", name
);
311 } /* if not redefining */
313 demand_empty_rest_of_line ();
325 name
= input_line_pointer
;
326 c
= get_symbol_end ();
327 /* just after name is now '\0' */
328 p
= input_line_pointer
;
331 if (*input_line_pointer
!= ',')
333 as_bad ("Expected comma after symbol-name");
334 ignore_rest_of_line ();
337 input_line_pointer
++; /* skip ',' */
338 if ((temp
= get_absolute_expression ()) < 0)
340 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
341 ignore_rest_of_line ();
346 symbolP
= symbol_find_or_make (name
);
348 if (S_IS_DEFINED (symbolP
))
350 as_bad ("Ignoring attempt to re-define symbol");
351 ignore_rest_of_line ();
354 if (S_GET_VALUE (symbolP
) != 0)
356 if (S_GET_VALUE (symbolP
) != size
)
358 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
359 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
365 S_SET_VALUE (symbolP
, size
);
366 S_SET_EXTERNAL (symbolP
);
369 know (symbolP
->sy_frag
== &zero_address_frag
);
370 if (*input_line_pointer
!= ',')
372 as_bad ("Expected comma after common length");
373 ignore_rest_of_line ();
376 input_line_pointer
++;
378 if (*input_line_pointer
!= '"')
380 temp
= get_absolute_expression ();
382 if (temp
> max_alignment
)
384 temp
= max_alignment
;
385 as_warn ("Common alignment too large: %d. assumed", temp
);
391 as_warn ("Common alignment negative; 0 assumed");
403 old_subsec
= now_subseg
;
405 record_alignment (bss_section
, align
);
406 subseg_set (bss_section
, 0);
408 frag_align (align
, 0);
409 if (S_GET_SEGMENT (symbolP
) == bss_section
)
410 symbolP
->sy_frag
->fr_symbol
= 0;
411 symbolP
->sy_frag
= frag_now
;
412 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
415 S_SET_SEGMENT (symbolP
, bss_section
);
416 S_CLEAR_EXTERNAL (symbolP
);
417 subseg_set (old_sec
, old_subsec
);
423 S_SET_VALUE (symbolP
, size
);
424 S_SET_EXTERNAL (symbolP
);
425 /* should be common, but this is how gas does it for now */
426 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
431 input_line_pointer
++;
432 /* @@ Some use the dot, some don't. Can we get some consistency?? */
433 if (*input_line_pointer
== '.')
434 input_line_pointer
++;
435 /* @@ Some say data, some say bss. */
436 if (strncmp (input_line_pointer
, "bss\"", 4)
437 && strncmp (input_line_pointer
, "data\"", 5))
439 while (*--input_line_pointer
!= '"')
441 input_line_pointer
--;
442 goto bad_common_segment
;
444 while (*input_line_pointer
++ != '"')
446 goto allocate_common
;
448 demand_empty_rest_of_line ();
453 p
= input_line_pointer
;
454 while (*p
&& *p
!= '\n')
458 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
460 input_line_pointer
= p
;
461 ignore_rest_of_line ();
470 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
472 input_line_pointer
+= 6;
476 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
478 input_line_pointer
+= 6;
482 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
484 input_line_pointer
+= 7;
488 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
490 input_line_pointer
+= 5;
491 /* We only support 2 segments -- text and data -- for now, so
492 things in the "bss segment" will have to go into data for now.
493 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
494 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
497 as_bad ("Unknown segment type");
498 demand_empty_rest_of_line ();
505 subseg_set (data_section
, 1);
506 demand_empty_rest_of_line ();
513 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
515 ++input_line_pointer
;
517 ++input_line_pointer
;
521 /* start-sanitize-v9 */
527 if (isdigit (*input_line_pointer
))
533 struct priv_reg_entry
539 struct priv_reg_entry priv_reg_table
[] =
558 {"", -1}, /* end marker */
568 #define MEMBAR_MASKS_SIZE 7
570 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
573 {"MemIssue", 8, 0x20},
574 {"Lookaside", 9, 0x10},
575 {"StoreStore", 10, 0x08},
576 {"LoadStore", 9, 0x04},
577 {"StoreLoad", 9, 0x02},
578 {"LoadLoad", 8, 0x01},
583 struct priv_reg_entry
*p
, *q
;
585 return strcmp (q
->name
, p
->name
);
589 /* end-sanitize-v9 */
591 /* This function is called once, at assembler startup time. It should
592 set up all the tables, etc. that the MD part of the assembler will need. */
596 register char *retval
= NULL
;
598 register unsigned int i
= 0;
600 op_hash
= hash_new ();
602 as_fatal ("Virtual memory exhausted");
604 while (i
< NUMOPCODES
)
606 const char *name
= sparc_opcodes
[i
].name
;
607 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
608 if (retval
!= NULL
&& *retval
!= '\0')
610 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
611 sparc_opcodes
[i
].name
, retval
);
616 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
618 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
619 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
624 while (i
< NUMOPCODES
625 && !strcmp (sparc_opcodes
[i
].name
, name
));
629 as_fatal ("Broken assembler. No assembly attempted.");
631 for (i
= '0'; i
< '8'; ++i
)
633 for (i
= '0'; i
<= '9'; ++i
)
635 for (i
= 'a'; i
<= 'f'; ++i
)
636 toHex
[i
] = i
+ 10 - 'a';
637 for (i
= 'A'; i
<= 'F'; ++i
)
638 toHex
[i
] = i
+ 10 - 'A';
640 /* start-sanitize-v9 */
643 current_architecture
= v9
;
646 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
647 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
649 /* end-sanitize-v9 */
651 target_big_endian
= 1;
670 /* See if "set" operand is absolute and small; skip sethi if so. */
671 if (special_case
== SPECIAL_CASE_SET
672 && the_insn
.exp
.X_op
== O_constant
)
674 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
675 && the_insn
.exp
.X_add_number
< (1 << 12))
677 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
678 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
679 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
680 special_case
= 0; /* No longer special */
681 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
686 /* put out the opcode */
687 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
689 /* put out the symbol-dependent stuff */
690 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
692 fix_new_exp (frag_now
, /* which frag */
693 (toP
- frag_now
->fr_literal
), /* where */
700 switch (special_case
)
702 case SPECIAL_CASE_SET
:
704 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
705 /* See if "set" operand has no low-order bits; skip OR if so. */
706 if (the_insn
.exp
.X_op
== O_constant
707 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
710 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
711 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
712 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
713 fix_new_exp (frag_now
, /* which frag */
714 (toP
- frag_now
->fr_literal
), /* where */
721 case SPECIAL_CASE_FDIV
:
722 /* According to information leaked from Sun, the "fdiv" instructions
723 on early SPARC machines would produce incorrect results sometimes.
724 The workaround is to add an fmovs of the destination register to
725 itself just after the instruction. This was true on machines
726 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
728 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
730 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
731 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
732 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
739 as_fatal ("failed sanity check.");
741 } /* md_assemble() */
747 char *error_message
= "";
751 struct sparc_opcode
*insn
;
753 unsigned long opcode
;
754 unsigned int mask
= 0;
757 long immediate_max
= 0;
759 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
777 as_bad ("Unknown opcode: `%s'", str
);
780 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
782 as_bad ("Unknown opcode: `%s'", str
);
792 opcode
= insn
->match
;
793 memset (&the_insn
, '\0', sizeof (the_insn
));
794 the_insn
.reloc
= BFD_RELOC_NONE
;
797 * Build the opcode, checking as we go to make
798 * sure that the operands match
800 for (args
= insn
->args
;; ++args
)
805 /* start-sanitize-v9 */
812 /* Parse a series of masks. */
818 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
819 if (!strncmp (s
, membar_masks
[i
].name
,
820 membar_masks
[i
].len
))
822 if (i
< MEMBAR_MASKS_SIZE
)
824 mask
|= membar_masks
[i
].mask
;
825 s
+= membar_masks
[i
].len
;
829 error_message
= ": invalid membar mask name";
836 else if (isdigit (*s
))
840 mask
= mask
* 10 + *s
- '0';
844 if (mask
< 0 || mask
> 127)
846 error_message
= ": invalid membar mask number";
852 error_message
= ": unrecognizable membar mask";
855 opcode
|= SIMM13 (mask
);
861 int prefetch_fcn
= 0;
863 /* Parse a prefetch function. */
867 if (!strncmp (s
, "n_reads", 7))
868 prefetch_fcn
= 0, s
+= 7;
869 else if (!strncmp (s
, "one_read", 8))
870 prefetch_fcn
= 1, s
+= 8;
871 else if (!strncmp (s
, "n_writes", 8))
872 prefetch_fcn
= 2, s
+= 8;
873 else if (!strncmp (s
, "one_write", 9))
874 prefetch_fcn
= 3, s
+= 9;
875 else if (!strncmp (s
, "page", 4))
876 prefetch_fcn
= 4, s
+= 4;
879 error_message
= ": invalid prefetch function name";
883 else if (isdigit (*s
))
887 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
891 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
893 error_message
= ": invalid prefetch function number";
899 error_message
= ": unrecognizable prefetch function";
902 opcode
|= RD (prefetch_fcn
);
908 /* Parse a privileged register. */
911 struct priv_reg_entry
*p
= priv_reg_table
;
912 int len
= 9999999; /* init to make gcc happy */
915 while (p
->name
[0] > s
[0])
917 while (p
->name
[0] == s
[0])
919 len
= strlen (p
->name
);
920 if (strncmp (p
->name
, s
, len
) == 0)
924 if (p
->name
[0] != s
[0])
926 error_message
= ": unrecognizable privileged register";
930 opcode
|= (p
->regnum
<< 14);
932 opcode
|= (p
->regnum
<< 25);
938 error_message
= ": unrecognizable privileged register";
942 /* end-sanitize-v9 */
946 if (strncmp (s
, "%asr", 4) == 0)
956 num
= num
* 10 + *s
- '0';
960 if (num
< 16 || 31 < num
)
962 error_message
= ": asr number must be between 15 and 31";
966 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
971 error_message
= ": expecting %asrN";
973 } /* if %asr followed by a number. */
978 /* start-sanitize-v9 */
981 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
982 immediate_max
= 0x03FF;
986 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
987 immediate_max
= 0x01FF;
991 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
996 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1001 if (*s
== 'p' && s
[1] == 'n')
1009 if (*s
== 'p' && s
[1] == 't')
1021 if (strncmp (s
, "%icc", 4) == 0)
1033 if (strncmp (s
, "%xcc", 4) == 0)
1045 if (strncmp (s
, "%fcc0", 5) == 0)
1057 if (strncmp (s
, "%fcc1", 5) == 0)
1069 if (strncmp (s
, "%fcc2", 5) == 0)
1081 if (strncmp (s
, "%fcc3", 5) == 0)
1089 if (strncmp (s
, "%pc", 3) == 0)
1097 if (strncmp (s
, "%tick", 5) == 0)
1104 /* end-sanitize-v9 */
1106 case '\0': /* end of args */
1125 case '[': /* these must match exactly */
1133 case '#': /* must be at least one digit */
1136 while (isdigit (*s
))
1144 case 'C': /* coprocessor state register */
1145 if (strncmp (s
, "%csr", 4) == 0)
1152 case 'b': /* next operand is a coprocessor register */
1155 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1160 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1174 opcode
|= mask
<< 14;
1182 opcode
|= mask
<< 25;
1188 case 'r': /* next operand must be a register */
1197 case 'f': /* frame pointer */
1205 case 'g': /* global register */
1206 if (isoctal (c
= *s
++))
1213 case 'i': /* in register */
1214 if (isoctal (c
= *s
++))
1216 mask
= c
- '0' + 24;
1221 case 'l': /* local register */
1222 if (isoctal (c
= *s
++))
1224 mask
= (c
- '0' + 16);
1229 case 'o': /* out register */
1230 if (isoctal (c
= *s
++))
1232 mask
= (c
- '0' + 8);
1237 case 's': /* stack pointer */
1245 case 'r': /* any register */
1246 if (!isdigit (c
= *s
++))
1263 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1279 * Got the register, now figure out where
1280 * it goes in the opcode.
1286 opcode
|= mask
<< 14;
1294 opcode
|= mask
<< 25;
1298 opcode
|= (mask
<< 25) | (mask
<< 14);
1304 case 'e': /* next operand is a floating point register */
1319 && ((format
= *s
) == 'f')
1322 for (mask
= 0; isdigit (*s
); ++s
)
1324 mask
= 10 * mask
+ (*s
- '0');
1325 } /* read the number */
1333 } /* register must be even numbered */
1341 } /* register must be multiple of 4 */
1343 /* start-sanitize-v9 */
1347 error_message
= ": There are only 64 f registers; [0-63]";
1353 } /* wrap high bit */
1355 /* end-sanitize-v9 */
1358 error_message
= ": There are only 32 f registers; [0-31]";
1361 /* start-sanitize-v9 */
1363 /* end-sanitize-v9 */
1368 } /* if not an 'f' register. */
1376 opcode
|= RS1 (mask
);
1383 opcode
|= RS2 (mask
);
1389 opcode
|= RD (mask
);
1398 if (strncmp (s
, "%fsr", 4) == 0)
1405 case 'h': /* high 22 bits */
1406 the_insn
.reloc
= BFD_RELOC_HI22
;
1409 case 'l': /* 22 bit PC relative immediate */
1410 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1414 case 'L': /* 30 bit immediate */
1415 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1419 case 'n': /* 22 bit immediate */
1420 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1423 case 'i': /* 13 bit immediate */
1424 /* What's the difference between base13 and 13? */
1425 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1426 immediate_max
= 0x0FFF;
1435 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1437 the_insn
.reloc
= BFD_RELOC_HI22
;
1440 else if (c
== 'l' && s
[2] == 'o')
1442 the_insn
.reloc
= BFD_RELOC_LO10
;
1444 /* start-sanitize-v9 */
1451 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1458 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1461 /* end-sanitize-v9 */
1466 /* Note that if the getExpression() fails, we
1467 will still have created U entries in the
1468 symbol table for the 'symbols' in the input
1469 string. Try not to create U symbols for
1472 /* This stuff checks to see if the
1473 expression ends in +%reg If it does,
1474 it removes the register from the
1475 expression, and re-sets 's' to point
1476 to the right place */
1480 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1482 if (s1
!= s
&& isdigit (s1
[-1]))
1484 if (s1
[-2] == '%' && s1
[-3] == '+')
1488 (void) getExpression (s
);
1493 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1497 (void) getExpression (s
);
1504 (void) getExpression (s
);
1507 /* Check for invalid constant values. Don't
1508 warn if constant was inside %hi or %lo,
1509 since these truncate the constant to
1511 if (immediate_max
!= 0
1512 && the_insn
.reloc
!= BFD_RELOC_LO10
1513 && the_insn
.reloc
!= BFD_RELOC_HI22
1514 /* start-sanitize-v9 */
1516 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1517 && the_insn
.reloc
!= RELOC_HLO10
1518 && the_insn
.reloc
!= RELOC_HHI22
1521 /* end-sanitize-v9 */
1522 && the_insn
.exp
.X_add_symbol
== 0
1523 && the_insn
.exp
.X_op_symbol
== 0
1524 && the_insn
.exp
.X_op
== O_constant
1525 && (the_insn
.exp
.X_add_number
> immediate_max
1526 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1527 as_bad ("constant value must be between %ld and %ld",
1528 ~immediate_max
, immediate_max
);
1529 /* Reset to prevent extraneous range check. */
1544 /* start-sanitize-v9 */
1546 /* end-sanitize-v9 */
1547 char *push
= input_line_pointer
;
1550 input_line_pointer
= s
;
1553 if (e
.X_op
== O_constant
)
1555 opcode
|= e
.X_add_number
<< 5;
1556 s
= input_line_pointer
;
1557 input_line_pointer
= push
;
1562 /* start-sanitize-v9 */
1570 if (!strncmp (s
, "ASI_AIUP", 8))
1572 else if (!strncmp (s
, "ASI_AIUS", 8))
1574 else if (!strncmp (s
, "ASI_PNF", 7))
1576 else if (!strncmp (s
, "ASI_SNF", 7))
1578 else if (!strncmp (s
, "ASI_P", 5))
1580 else if (!strncmp (s
, "ASI_S", 5))
1584 error_message
= ": invalid asi name";
1588 else if (isdigit (*s
))
1590 char *push
= input_line_pointer
;
1591 input_line_pointer
= s
;
1592 asi
= get_absolute_expression ();
1593 s
= input_line_pointer
;
1594 input_line_pointer
= push
;
1596 if (asi
< 0 || asi
> 255)
1598 error_message
= ": invalid asi number";
1604 error_message
= ": unrecognizable asi";
1607 opcode
|= ASI (asi
);
1610 /* end-sanitize-v9 */
1611 } /* alternate space */
1614 if (strncmp (s
, "%psr", 4) == 0)
1621 case 'q': /* floating point queue */
1622 if (strncmp (s
, "%fq", 3) == 0)
1629 case 'Q': /* coprocessor queue */
1630 if (strncmp (s
, "%cq", 3) == 0)
1638 if (strcmp (str
, "set") == 0)
1640 special_case
= SPECIAL_CASE_SET
;
1643 else if (strncmp (str
, "fdiv", 4) == 0)
1645 special_case
= SPECIAL_CASE_FDIV
;
1650 /* start-sanitize-v9 */
1653 if (strncmp (s
, "%asi", 4) != 0)
1659 if (strncmp (s
, "%fprs", 5) != 0)
1665 if (strncmp (s
, "%ccr", 4) != 0)
1670 /* end-sanitize-v9 */
1673 if (strncmp (s
, "%tbr", 4) != 0)
1679 if (strncmp (s
, "%wim", 4) != 0)
1685 if (strncmp (s
, "%y", 2) != 0)
1691 as_fatal ("failed sanity check.");
1692 } /* switch on arg code */
1694 } /* for each arg that we expect */
1698 /* Args don't match. */
1699 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1700 && !strcmp (insn
->name
, insn
[1].name
))
1708 as_bad ("Illegal operands%s", error_message
);
1714 if (insn
->architecture
> current_architecture
)
1716 if ((!architecture_requested
|| warn_on_bump
)
1718 /* start-sanitize-v9 */
1720 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1723 /* end-sanitize-v9 */
1725 /* start-sanitize-v9 */
1727 /* end-sanitize-v9 */
1732 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1733 architecture_pname
[current_architecture
],
1734 architecture_pname
[insn
->architecture
],
1738 current_architecture
= insn
->architecture
;
1742 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1744 architecture_pname
[insn
->architecture
],
1745 architecture_pname
[current_architecture
]);
1747 } /* if bump ok else error */
1748 } /* if architecture higher */
1752 } /* forever looking for a match */
1754 the_insn
.opcode
= opcode
;
1765 save_in
= input_line_pointer
;
1766 input_line_pointer
= str
;
1767 seg
= expression (&the_insn
.exp
);
1768 if (seg
!= absolute_section
1769 && seg
!= text_section
1770 && seg
!= data_section
1771 && seg
!= bss_section
1772 && seg
!= undefined_section
)
1774 the_insn
.error
= "bad segment";
1775 expr_end
= input_line_pointer
;
1776 input_line_pointer
= save_in
;
1779 expr_end
= input_line_pointer
;
1780 input_line_pointer
= save_in
;
1782 } /* getExpression() */
1786 This is identical to the md_atof in m68k.c. I think this is right,
1789 Turn a string in input_line_pointer into a floating point constant of type
1790 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1791 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1794 /* Equal to MAX_PRECISION in atof-ieee.c */
1795 #define MAX_LITTLENUMS 6
1798 md_atof (type
, litP
, sizeP
)
1804 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1805 LITTLENUM_TYPE
*wordP
;
1838 return "Bad call to MD_ATOF()";
1840 t
= atof_ieee (input_line_pointer
, type
, words
);
1842 input_line_pointer
= t
;
1843 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1844 for (wordP
= words
; prec
--;)
1846 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1847 litP
+= sizeof (LITTLENUM_TYPE
);
1853 * Write out big-endian.
1856 md_number_to_chars (buf
, val
, n
)
1864 /* start-sanitize-v9 */
1870 /* end-sanitize-v9 */
1881 as_fatal ("failed sanity check.");
1884 } /* md_number_to_chars() */
1886 /* Apply a fixS to the frags, now that we know the value it ought to
1889 #ifdef BFD_ASSEMBLER
1894 md_apply_fix (fixP
, value
)
1896 #ifdef BFD_ASSEMBLER
1902 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1905 #ifdef BFD_ASSEMBLER
1911 #ifdef BFD_ASSEMBLER
1912 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1914 assert (fixP
->fx_r_type
< NO_RELOC
);
1917 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1920 * This is a hack. There should be a better way to
1923 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1925 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1928 switch (fixP
->fx_r_type
)
1943 case BFD_RELOC_32_PCREL_S2
:
1944 val
= (val
>>= 2) + 1;
1945 buf
[0] |= (val
>> 24) & 0x3f;
1946 buf
[1] = (val
>> 16);
1951 /* start-sanitize-v9 */
1964 case BFD_RELOC_SPARC_11
:
1965 if (((val
> 0) && (val
& ~0x7ff))
1966 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1968 as_bad ("relocation overflow.");
1971 buf
[2] |= (val
>> 8) & 0x7;
1972 buf
[3] = val
& 0xff;
1975 case BFD_RELOC_SPARC_10
:
1976 if (((val
> 0) && (val
& ~0x3ff))
1977 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1979 as_bad ("relocation overflow.");
1982 buf
[2] |= (val
>> 8) & 0x3;
1983 buf
[3] = val
& 0xff;
1986 case BFD_RELOC_SPARC_WDISP16
:
1987 if (((val
> 0) && (val
& ~0x3fffc))
1988 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1990 as_bad ("relocation overflow.");
1993 val
= (val
>>= 2) + 1;
1994 buf
[1] |= ((val
>> 14) & 0x3) << 4;
1995 buf
[2] |= (val
>> 8) & 0x3f;
1996 buf
[3] = val
& 0xff;
1999 case BFD_RELOC_SPARC_WDISP19
:
2000 if (((val
> 0) && (val
& ~0x1ffffc))
2001 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2003 as_bad ("relocation overflow.");
2006 val
= (val
>>= 2) + 1;
2007 buf
[1] |= (val
>> 16) & 0x7;
2008 buf
[2] = (val
>> 8) & 0xff;
2009 buf
[3] = val
& 0xff;
2012 case BFD_RELOC_SPARC_HH22
:
2014 /* intentional fallthrough */
2016 /* end-sanitize-v9 */
2018 /* start-sanitize-v9 */
2020 case BFD_RELOC_SPARC_LM22
:
2022 /* end-sanitize-v9 */
2023 case BFD_RELOC_HI22
:
2024 if (!fixP
->fx_addsy
)
2026 buf
[1] |= (val
>> 26) & 0x3f;
2037 case BFD_RELOC_SPARC22
:
2038 if (val
& ~0x003fffff)
2040 as_bad ("relocation overflow");
2042 buf
[1] |= (val
>> 16) & 0x3f;
2044 buf
[3] = val
& 0xff;
2047 case BFD_RELOC_SPARC13
:
2048 if (val
& ~0x00001fff)
2050 as_bad ("relocation overflow");
2052 buf
[2] |= (val
>> 8) & 0x1f;
2053 buf
[3] = val
& 0xff;
2056 /* start-sanitize-v9 */
2058 case BFD_RELOC_SPARC_HM10
:
2060 /* intentional fallthrough */
2062 /* end-sanitize-v9 */
2064 case BFD_RELOC_LO10
:
2065 if (!fixP
->fx_addsy
)
2067 buf
[2] |= (val
>> 8) & 0x03;
2073 case BFD_RELOC_SPARC_BASE13
:
2074 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2075 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2077 as_bad ("relocation overflow");
2079 buf
[2] |= (val
>> 8) & 0x1f;
2083 case BFD_RELOC_SPARC_WDISP22
:
2084 val
= (val
>>= 2) + 1;
2086 case BFD_RELOC_SPARC_BASE22
:
2087 buf
[1] |= (val
>> 16) & 0x3f;
2092 case BFD_RELOC_NONE
:
2094 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2098 #ifdef BFD_ASSEMBLER
2103 /* should never be called for sparc */
2105 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2112 as_fatal ("sparc_create_short_jmp\n");
2115 #ifdef BFD_ASSEMBLER
2117 /* Translate internal representation of relocation info to BFD target
2120 tc_gen_reloc (section
, fixp
)
2125 bfd_reloc_code_real_type code
;
2127 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2128 assert (reloc
!= 0);
2130 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2131 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2132 if (fixp
->fx_pcrel
== 0)
2133 reloc
->addend
= fixp
->fx_addnumber
;
2135 switch (OUTPUT_FLAVOR
)
2137 case bfd_target_elf_flavour
:
2140 case bfd_target_aout_flavour
:
2141 reloc
->addend
= - reloc
->address
;
2144 /* What's a good default here? Is there any?? */
2148 switch (fixp
->fx_r_type
)
2152 case BFD_RELOC_HI22
:
2153 case BFD_RELOC_LO10
:
2154 case BFD_RELOC_32_PCREL_S2
:
2155 case BFD_RELOC_SPARC_BASE13
:
2156 case BFD_RELOC_SPARC_WDISP22
:
2157 /* start-sanitize-v9 */
2159 case BFD_RELOC_SPARC_10
:
2160 case BFD_RELOC_SPARC_11
:
2161 case BFD_RELOC_SPARC_HH22
:
2162 case BFD_RELOC_SPARC_HM10
:
2163 case BFD_RELOC_SPARC_LM22
:
2164 case BFD_RELOC_SPARC_PC_HH22
:
2165 case BFD_RELOC_SPARC_PC_HM10
:
2166 case BFD_RELOC_SPARC_PC_LM22
:
2167 /* end-sanitize-v9 */
2168 code
= fixp
->fx_r_type
;
2173 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2174 assert (reloc
->howto
!= 0);
2181 /* Translate internal representation of relocation info to target format.
2183 On sparc: first 4 bytes are normal unsigned long address, next three
2184 bytes are index, most sig. byte first. Byte 7 is broken up with
2185 bit 7 as external, bits 6 & 5 unused, and the lower
2186 five bits as relocation type. Next 4 bytes are long addend. */
2187 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2189 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2192 relax_addressT segment_address_in_file
;
2199 know (fixP
->fx_addsy
);
2201 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2204 r_index
= fixP
->fx_addsy
->sy_number
;
2209 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2213 md_number_to_chars (where
,
2214 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2217 /* now the fun stuff */
2218 where
[4] = (r_index
>> 16) & 0x0ff;
2219 where
[5] = (r_index
>> 8) & 0x0ff;
2220 where
[6] = r_index
& 0x0ff;
2221 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2224 if (fixP
->fx_addsy
->sy_frag
)
2226 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2231 r_addend
+= fixP
->fx_offset
- r_address
;
2235 r_addend
= fixP
->fx_addnumber
;
2238 md_number_to_chars (&where
[8], r_addend
, 4);
2241 } /* tc_aout_fix_to_chars() */
2244 /* should never be called for sparc */
2246 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2248 addressT from_addr
, to_addr
;
2252 as_fatal ("sparc_create_long_jump\n");
2253 } /* md_create_long_jump() */
2255 /* should never be called for sparc */
2257 md_estimate_size_before_relax (fragP
, segtype
)
2261 as_fatal ("sparc_estimate_size_before_relax\n");
2263 } /* md_estimate_size_before_relax() */
2266 /* for debugging only */
2269 struct sparc_it
*insn
;
2302 fprintf (stderr
, "ERROR: %s\n");
2304 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2305 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2306 fprintf (stderr
, "exp = {\n");
2307 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2308 ((insn
->exp
.X_add_symbol
!= NULL
)
2309 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2310 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2313 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2314 ((insn
->exp
.X_op_symbol
!= NULL
)
2315 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2316 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2319 fprintf (stderr
, "\t\tX_add_number = %d\n",
2320 insn
->exp
.X_add_number
);
2321 fprintf (stderr
, "}\n");
2323 } /* print_insn() */
2329 * Invocation line includes a switch not recognized by the base assembler.
2330 * See if it's a processor-specific option. These are:
2333 * Warn on architecture bumps. See also -A.
2335 * -Av6, -Av7, -Av8, -Asparclite
2336 * Select the architecture. Instructions or features not
2337 * supported by the selected architecture cause fatal errors.
2339 * The default is to start at v6, and bump the architecture up
2340 * whenever an instruction is seen at a higher level.
2342 * If -bump is specified, a warning is printing when bumping to
2345 * If an architecture is specified, all instructions must match
2346 * that architecture. Any higher level instructions are flagged
2349 * if both an architecture and -bump are specified, the
2350 * architecture starts at the specified level, but bumps are
2355 * Another architecture switch.
2358 * Bumping between incompatible architectures is always an
2359 * error. For example, from sparclite to v9.
2364 md_parse_option (argP
, cntP
, vecP
)
2372 if (!strcmp (*argP
, "bump"))
2377 else if (**argP
== 'A')
2381 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2383 if (strcmp (p
, *arch
) == 0)
2386 } /* found a match */
2387 } /* walk the pname table */
2391 as_bad ("unknown architecture: %s", p
);
2395 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2396 architecture_requested
= 1;
2400 else if (**argP
== 'V')
2402 extern void print_version_id ();
2403 print_version_id ();
2405 else if (**argP
== 'Q')
2407 /* Qy - do emit .comment
2408 Qn - do not emit .comment */
2410 else if (**argP
== 's')
2412 /* use .stab instead of .stab.excl */
2417 /* Unknown option */
2421 **argP
= '\0'; /* Done parsing this switch */
2423 } /* md_parse_option() */
2425 /* We have no need to default values of symbols. */
2429 md_undefined_symbol (name
)
2433 } /* md_undefined_symbol() */
2435 /* Parse an operand that is machine-specific.
2436 We just return without modifying the expression if we have nothing
2441 md_operand (expressionP
)
2442 expressionS
*expressionP
;
2446 /* Round up a section size to the appropriate boundary. */
2448 md_section_align (segment
, size
)
2453 /* Round all sects to multiple of 8 */
2454 size
= (size
+ 7) & ~7;
2459 /* Exactly what point is a PC-relative offset relative TO?
2460 On the sparc, they're relative to the address of the offset, plus
2461 its size. This gets us to the following instruction.
2462 (??? Is this right? FIXME-SOON) */
2464 md_pcrel_from (fixP
)
2467 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2470 #ifndef BFD_ASSEMBLER
2472 tc_aout_pre_write_hook (headers
)
2473 object_headers
*headers
;
2475 H_SET_VERSION (headers
, 1);
2479 /* end of tc-sparc.c */