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
);
390 if (*input_line_pointer
!= ',')
392 as_bad ("Expected comma after common length");
393 ignore_rest_of_line ();
396 input_line_pointer
++;
398 if (*input_line_pointer
!= '"')
400 temp
= get_absolute_expression ();
401 if (temp
> max_alignment
)
403 temp
= max_alignment
;
404 as_warn ("Common alignment too large: %d. assumed", temp
);
409 as_warn ("Common alignment negative; 0 assumed");
420 old_subsec
= now_subseg
;
422 record_alignment (bss_section
, align
);
423 subseg_set (bss_section
, 0);
425 frag_align (align
, 0);
426 if (S_GET_SEGMENT (symbolP
) == bss_section
)
427 symbolP
->sy_frag
->fr_symbol
= 0;
428 symbolP
->sy_frag
= frag_now
;
429 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
432 S_SET_SEGMENT (symbolP
, bss_section
);
433 S_CLEAR_EXTERNAL (symbolP
);
434 subseg_set (old_sec
, old_subsec
);
439 S_SET_VALUE (symbolP
, size
);
440 S_SET_EXTERNAL (symbolP
);
441 /* should be common, but this is how gas does it for now */
442 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
447 input_line_pointer
++;
448 /* @@ Some use the dot, some don't. Can we get some consistency?? */
449 if (*input_line_pointer
== '.')
450 input_line_pointer
++;
451 /* @@ Some say data, some say bss. */
452 if (strncmp (input_line_pointer
, "bss\"", 4)
453 && strncmp (input_line_pointer
, "data\"", 5))
455 while (*--input_line_pointer
!= '"')
457 input_line_pointer
--;
458 goto bad_common_segment
;
460 while (*input_line_pointer
++ != '"')
462 goto allocate_common
;
464 demand_empty_rest_of_line ();
469 p
= input_line_pointer
;
470 while (*p
&& *p
!= '\n')
474 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
476 input_line_pointer
= p
;
477 ignore_rest_of_line ();
486 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
488 input_line_pointer
+= 6;
492 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
494 input_line_pointer
+= 6;
498 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
500 input_line_pointer
+= 7;
504 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
506 input_line_pointer
+= 5;
507 /* We only support 2 segments -- text and data -- for now, so
508 things in the "bss segment" will have to go into data for now.
509 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
510 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
513 as_bad ("Unknown segment type");
514 demand_empty_rest_of_line ();
521 subseg_set (data_section
, 1);
522 demand_empty_rest_of_line ();
529 extern char is_end_of_line
[];
531 while (!is_end_of_line
[*input_line_pointer
])
533 ++input_line_pointer
;
535 ++input_line_pointer
;
539 /* start-sanitize-v9 */
545 if (isdigit (*input_line_pointer
))
551 struct priv_reg_entry
557 struct priv_reg_entry priv_reg_table
[] =
576 {"", -1}, /* end marker */
586 #define MEMBAR_MASKS_SIZE 7
588 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
591 {"MemIssue", 8, 0x20},
592 {"Lookaside", 9, 0x10},
593 {"StoreStore", 10, 0x08},
594 {"LoadStore", 9, 0x04},
595 {"StoreLoad", 9, 0x02},
596 {"LoadLoad", 8, 0x01},
601 struct priv_reg_entry
*p
, *q
;
603 return strcmp (q
->name
, p
->name
);
607 /* end-sanitize-v9 */
609 /* This function is called once, at assembler startup time. It should
610 set up all the tables, etc. that the MD part of the assembler will need. */
614 register char *retval
= NULL
;
616 register unsigned int i
= 0;
618 op_hash
= hash_new ();
620 as_fatal ("Virtual memory exhausted");
622 while (i
< NUMOPCODES
)
624 const char *name
= sparc_opcodes
[i
].name
;
625 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
626 if (retval
!= NULL
&& *retval
!= '\0')
628 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
629 sparc_opcodes
[i
].name
, retval
);
634 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
636 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
637 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
642 while (i
< NUMOPCODES
643 && !strcmp (sparc_opcodes
[i
].name
, name
));
647 as_fatal ("Broken assembler. No assembly attempted.");
649 for (i
= '0'; i
< '8'; ++i
)
651 for (i
= '0'; i
<= '9'; ++i
)
653 for (i
= 'a'; i
<= 'f'; ++i
)
654 toHex
[i
] = i
+ 10 - 'a';
655 for (i
= 'A'; i
<= 'F'; ++i
)
656 toHex
[i
] = i
+ 10 - 'A';
658 /* start-sanitize-v9 */
661 current_architecture
= v9
;
664 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
665 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
667 /* end-sanitize-v9 */
669 target_big_endian
= 1;
688 /* See if "set" operand is absolute and small; skip sethi if so. */
689 if (special_case
== SPECIAL_CASE_SET
690 && the_insn
.exp
.X_seg
== absolute_section
)
692 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
693 && the_insn
.exp
.X_add_number
< (1 << 12))
695 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
696 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
697 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
698 special_case
= 0; /* No longer special */
699 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
704 /* put out the opcode */
705 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
707 /* put out the symbol-dependent stuff */
708 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
710 fix_new (frag_now
, /* which frag */
711 (toP
- frag_now
->fr_literal
), /* where */
713 the_insn
.exp
.X_add_symbol
,
714 the_insn
.exp
.X_subtract_symbol
,
715 the_insn
.exp
.X_add_number
,
720 switch (special_case
)
722 case SPECIAL_CASE_SET
:
724 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
725 /* See if "set" operand has no low-order bits; skip OR if so. */
726 if (the_insn
.exp
.X_seg
== absolute_section
727 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
730 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
731 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
732 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
733 fix_new (frag_now
, /* which frag */
734 (toP
- frag_now
->fr_literal
), /* where */
736 the_insn
.exp
.X_add_symbol
,
737 the_insn
.exp
.X_subtract_symbol
,
738 the_insn
.exp
.X_add_number
,
744 case SPECIAL_CASE_FDIV
:
745 /* According to information leaked from Sun, the "fdiv" instructions
746 on early SPARC machines would produce incorrect results sometimes.
747 The workaround is to add an fmovs of the destination register to
748 itself just after the instruction. This was true on machines
749 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
751 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
753 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
754 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
755 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
762 as_fatal ("failed sanity check.");
764 } /* md_assemble() */
770 char *error_message
= "";
774 struct sparc_opcode
*insn
;
776 unsigned long opcode
;
777 unsigned int mask
= 0;
780 long immediate_max
= 0;
782 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
800 as_bad ("Unknown opcode: `%s'", str
);
803 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
805 as_bad ("Unknown opcode: `%s'", str
);
815 opcode
= insn
->match
;
816 memset (&the_insn
, '\0', sizeof (the_insn
));
817 the_insn
.reloc
= BFD_RELOC_NONE
;
820 * Build the opcode, checking as we go to make
821 * sure that the operands match
823 for (args
= insn
->args
;; ++args
)
828 /* start-sanitize-v9 */
835 /* Parse a series of masks. */
841 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
842 if (!strncmp (s
, membar_masks
[i
].name
,
843 membar_masks
[i
].len
))
845 if (i
< MEMBAR_MASKS_SIZE
)
847 mask
|= membar_masks
[i
].mask
;
848 s
+= membar_masks
[i
].len
;
852 error_message
= ": invalid membar mask name";
859 else if (isdigit (*s
))
863 mask
= mask
* 10 + *s
- '0';
867 if (mask
< 0 || mask
> 127)
869 error_message
= ": invalid membar mask number";
875 error_message
= ": unrecognizable membar mask";
878 opcode
|= SIMM13 (mask
);
884 int prefetch_fcn
= 0;
886 /* Parse a prefetch function. */
890 if (!strncmp (s
, "n_reads", 7))
891 prefetch_fcn
= 0, s
+= 7;
892 else if (!strncmp (s
, "one_read", 8))
893 prefetch_fcn
= 1, s
+= 8;
894 else if (!strncmp (s
, "n_writes", 8))
895 prefetch_fcn
= 2, s
+= 8;
896 else if (!strncmp (s
, "one_write", 9))
897 prefetch_fcn
= 3, s
+= 9;
898 else if (!strncmp (s
, "page", 4))
899 prefetch_fcn
= 4, s
+= 4;
902 error_message
= ": invalid prefetch function name";
906 else if (isdigit (*s
))
910 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
914 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
916 error_message
= ": invalid prefetch function number";
922 error_message
= ": unrecognizable prefetch function";
925 opcode
|= RD (prefetch_fcn
);
931 /* Parse a privileged register. */
934 struct priv_reg_entry
*p
= priv_reg_table
;
935 int len
= 9999999; /* init to make gcc happy */
938 while (p
->name
[0] > s
[0])
940 while (p
->name
[0] == s
[0])
942 len
= strlen (p
->name
);
943 if (strncmp (p
->name
, s
, len
) == 0)
947 if (p
->name
[0] != s
[0])
949 error_message
= ": unrecognizable privileged register";
953 opcode
|= (p
->regnum
<< 14);
955 opcode
|= (p
->regnum
<< 25);
961 error_message
= ": unrecognizable privileged register";
965 /* end-sanitize-v9 */
969 if (strncmp (s
, "%asr", 4) == 0)
979 num
= num
* 10 + *s
- '0';
983 if (num
< 16 || 31 < num
)
985 error_message
= ": asr number must be between 15 and 31";
989 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
994 error_message
= ": expecting %asrN";
996 } /* if %asr followed by a number. */
1001 /* start-sanitize-v9 */
1004 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1005 immediate_max
= 0x03FF;
1009 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1010 immediate_max
= 0x01FF;
1014 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1019 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1024 if (*s
== 'p' && s
[1] == 'n')
1032 if (*s
== 'p' && s
[1] == 't')
1044 if (strncmp (s
, "%icc", 4) == 0)
1056 if (strncmp (s
, "%xcc", 4) == 0)
1068 if (strncmp (s
, "%fcc0", 5) == 0)
1080 if (strncmp (s
, "%fcc1", 5) == 0)
1092 if (strncmp (s
, "%fcc2", 5) == 0)
1104 if (strncmp (s
, "%fcc3", 5) == 0)
1112 if (strncmp (s
, "%pc", 3) == 0)
1120 if (strncmp (s
, "%tick", 5) == 0)
1127 /* end-sanitize-v9 */
1129 case '\0': /* end of args */
1148 case '[': /* these must match exactly */
1156 case '#': /* must be at least one digit */
1159 while (isdigit (*s
))
1167 case 'C': /* coprocessor state register */
1168 if (strncmp (s
, "%csr", 4) == 0)
1175 case 'b': /* next operand is a coprocessor register */
1178 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1183 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1197 opcode
|= mask
<< 14;
1205 opcode
|= mask
<< 25;
1211 case 'r': /* next operand must be a register */
1220 case 'f': /* frame pointer */
1228 case 'g': /* global register */
1229 if (isoctal (c
= *s
++))
1236 case 'i': /* in register */
1237 if (isoctal (c
= *s
++))
1239 mask
= c
- '0' + 24;
1244 case 'l': /* local register */
1245 if (isoctal (c
= *s
++))
1247 mask
= (c
- '0' + 16);
1252 case 'o': /* out register */
1253 if (isoctal (c
= *s
++))
1255 mask
= (c
- '0' + 8);
1260 case 's': /* stack pointer */
1268 case 'r': /* any register */
1269 if (!isdigit (c
= *s
++))
1286 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1302 * Got the register, now figure out where
1303 * it goes in the opcode.
1309 opcode
|= mask
<< 14;
1317 opcode
|= mask
<< 25;
1321 opcode
|= (mask
<< 25) | (mask
<< 14);
1327 case 'e': /* next operand is a floating point register */
1342 && ((format
= *s
) == 'f')
1345 for (mask
= 0; isdigit (*s
); ++s
)
1347 mask
= 10 * mask
+ (*s
- '0');
1348 } /* read the number */
1356 } /* register must be even numbered */
1364 } /* register must be multiple of 4 */
1366 /* start-sanitize-v9 */
1370 error_message
= ": There are only 64 f registers; [0-63]";
1376 } /* wrap high bit */
1378 /* end-sanitize-v9 */
1381 error_message
= ": There are only 32 f registers; [0-31]";
1384 /* start-sanitize-v9 */
1386 /* end-sanitize-v9 */
1391 } /* if not an 'f' register. */
1399 opcode
|= RS1 (mask
);
1406 opcode
|= RS2 (mask
);
1412 opcode
|= RD (mask
);
1421 if (strncmp (s
, "%fsr", 4) == 0)
1428 case 'h': /* high 22 bits */
1429 the_insn
.reloc
= BFD_RELOC_HI22
;
1432 case 'l': /* 22 bit PC relative immediate */
1433 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1437 case 'L': /* 30 bit immediate */
1438 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1442 case 'n': /* 22 bit immediate */
1443 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1446 case 'i': /* 13 bit immediate */
1447 /* What's the difference between base13 and 13? */
1448 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1449 immediate_max
= 0x0FFF;
1458 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1460 the_insn
.reloc
= BFD_RELOC_HI22
;
1463 else if (c
== 'l' && s
[2] == 'o')
1465 the_insn
.reloc
= BFD_RELOC_LO10
;
1467 /* start-sanitize-v9 */
1474 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1481 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1484 /* end-sanitize-v9 */
1489 /* Note that if the getExpression() fails, we
1490 will still have created U entries in the
1491 symbol table for the 'symbols' in the input
1492 string. Try not to create U symbols for
1495 /* This stuff checks to see if the
1496 expression ends in +%reg If it does,
1497 it removes the register from the
1498 expression, and re-sets 's' to point
1499 to the right place */
1503 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1505 if (s1
!= s
&& isdigit (s1
[-1]))
1507 if (s1
[-2] == '%' && s1
[-3] == '+')
1511 (void) getExpression (s
);
1516 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1520 (void) getExpression (s
);
1527 (void) getExpression (s
);
1530 /* Check for invalid constant values. Don't
1531 warn if constant was inside %hi or %lo,
1532 since these truncate the constant to
1534 if (immediate_max
!= 0
1535 && the_insn
.reloc
!= BFD_RELOC_LO10
1536 && the_insn
.reloc
!= BFD_RELOC_HI22
1537 /* start-sanitize-v9 */
1539 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1540 && the_insn
.reloc
!= RELOC_HLO10
1541 && the_insn
.reloc
!= RELOC_HHI22
1544 /* end-sanitize-v9 */
1545 && the_insn
.exp
.X_add_symbol
== 0
1546 && the_insn
.exp
.X_subtract_symbol
== 0
1547 && the_insn
.exp
.X_seg
== absolute_section
1548 && (the_insn
.exp
.X_add_number
> immediate_max
1549 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1550 as_bad ("constant value must be between %ld and %ld",
1551 ~immediate_max
, immediate_max
);
1552 /* Reset to prevent extraneous range check. */
1567 /* start-sanitize-v9 */
1569 /* end-sanitize-v9 */
1570 char *push
= input_line_pointer
;
1573 input_line_pointer
= s
;
1575 if (expression (&e
) == absolute_section
)
1577 opcode
|= e
.X_add_number
<< 5;
1578 s
= input_line_pointer
;
1579 input_line_pointer
= push
;
1584 /* start-sanitize-v9 */
1592 if (!strncmp (s
, "ASI_AIUP", 8))
1594 else if (!strncmp (s
, "ASI_AIUS", 8))
1596 else if (!strncmp (s
, "ASI_PNF", 7))
1598 else if (!strncmp (s
, "ASI_SNF", 7))
1600 else if (!strncmp (s
, "ASI_P", 5))
1602 else if (!strncmp (s
, "ASI_S", 5))
1606 error_message
= ": invalid asi name";
1610 else if (isdigit (*s
))
1612 char *push
= input_line_pointer
;
1613 input_line_pointer
= s
;
1614 asi
= get_absolute_expression ();
1615 s
= input_line_pointer
;
1616 input_line_pointer
= push
;
1618 if (asi
< 0 || asi
> 255)
1620 error_message
= ": invalid asi number";
1626 error_message
= ": unrecognizable asi";
1629 opcode
|= ASI (asi
);
1632 /* end-sanitize-v9 */
1633 } /* alternate space */
1636 if (strncmp (s
, "%psr", 4) == 0)
1643 case 'q': /* floating point queue */
1644 if (strncmp (s
, "%fq", 3) == 0)
1651 case 'Q': /* coprocessor queue */
1652 if (strncmp (s
, "%cq", 3) == 0)
1660 if (strcmp (str
, "set") == 0)
1662 special_case
= SPECIAL_CASE_SET
;
1665 else if (strncmp (str
, "fdiv", 4) == 0)
1667 special_case
= SPECIAL_CASE_FDIV
;
1672 /* start-sanitize-v9 */
1675 if (strncmp (s
, "%asi", 4) != 0)
1681 if (strncmp (s
, "%fprs", 5) != 0)
1687 if (strncmp (s
, "%ccr", 4) != 0)
1692 /* end-sanitize-v9 */
1695 if (strncmp (s
, "%tbr", 4) != 0)
1701 if (strncmp (s
, "%wim", 4) != 0)
1707 if (strncmp (s
, "%y", 2) != 0)
1713 as_fatal ("failed sanity check.");
1714 } /* switch on arg code */
1716 } /* for each arg that we expect */
1720 /* Args don't match. */
1721 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1722 && !strcmp (insn
->name
, insn
[1].name
))
1730 as_bad ("Illegal operands%s", error_message
);
1736 if (insn
->architecture
> current_architecture
)
1738 if ((!architecture_requested
|| warn_on_bump
)
1740 /* start-sanitize-v9 */
1742 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1745 /* end-sanitize-v9 */
1747 /* start-sanitize-v9 */
1749 /* end-sanitize-v9 */
1754 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1755 architecture_pname
[current_architecture
],
1756 architecture_pname
[insn
->architecture
],
1760 current_architecture
= insn
->architecture
;
1764 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1766 architecture_pname
[insn
->architecture
],
1767 architecture_pname
[current_architecture
]);
1769 } /* if bump ok else error */
1770 } /* if architecture higher */
1774 } /* forever looking for a match */
1776 the_insn
.opcode
= opcode
;
1787 save_in
= input_line_pointer
;
1788 input_line_pointer
= str
;
1789 seg
= expression (&the_insn
.exp
);
1790 if (seg
== absolute_section
1791 || seg
== text_section
1792 || seg
== data_section
1793 || seg
== bss_section
1794 || seg
== undefined_section
1795 || seg
== diff_section
1796 || seg
== big_section
1797 || seg
== absent_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 */
1975 case BFD_RELOC_SPARC_11
:
1976 if (((val
> 0) && (val
& ~0x7ff))
1977 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1979 as_bad ("relocation overflow.");
1982 buf
[2] |= (val
>> 8) & 0x7;
1983 buf
[3] = val
& 0xff;
1986 case BFD_RELOC_SPARC_10
:
1987 if (((val
> 0) && (val
& ~0x3ff))
1988 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1990 as_bad ("relocation overflow.");
1993 buf
[2] |= (val
>> 8) & 0x3;
1994 buf
[3] = val
& 0xff;
1997 case BFD_RELOC_SPARC_WDISP16
:
1998 if (((val
> 0) && (val
& ~0x3fffc))
1999 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
2001 as_bad ("relocation overflow.");
2004 val
= (val
>>= 2) + 1;
2005 buf
[1] |= ((val
>> 14) & 0x3) << 4;
2006 buf
[2] |= (val
>> 8) & 0x3f;
2007 buf
[3] = val
& 0xff;
2010 case BFD_RELOC_SPARC_WDISP19
:
2011 if (((val
> 0) && (val
& ~0x1ffffc))
2012 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2014 as_bad ("relocation overflow.");
2017 val
= (val
>>= 2) + 1;
2018 buf
[1] |= (val
>> 16) & 0x7;
2019 buf
[2] = (val
>> 8) & 0xff;
2020 buf
[3] = val
& 0xff;
2023 case BFD_RELOC_SPARC_HH22
:
2025 /* intentional fallthrough */
2027 /* end-sanitize-v9 */
2029 /* start-sanitize-v9 */
2031 case BFD_RELOC_SPARC_LM22
:
2033 /* end-sanitize-v9 */
2034 case BFD_RELOC_HI22
:
2035 if (!fixP
->fx_addsy
)
2037 buf
[1] |= (val
>> 26) & 0x3f;
2048 case BFD_RELOC_SPARC22
:
2049 if (val
& ~0x003fffff)
2051 as_bad ("relocation overflow");
2053 buf
[1] |= (val
>> 16) & 0x3f;
2055 buf
[3] = val
& 0xff;
2058 case BFD_RELOC_SPARC13
:
2059 if (val
& ~0x00001fff)
2061 as_bad ("relocation overflow");
2063 buf
[2] |= (val
>> 8) & 0x1f;
2064 buf
[3] = val
& 0xff;
2067 /* start-sanitize-v9 */
2069 case BFD_RELOC_SPARC_HM10
:
2071 /* intentional fallthrough */
2073 /* end-sanitize-v9 */
2075 case BFD_RELOC_LO10
:
2076 if (!fixP
->fx_addsy
)
2078 buf
[2] |= (val
>> 8) & 0x03;
2084 case BFD_RELOC_SPARC_BASE13
:
2085 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2086 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2088 as_bad ("relocation overflow");
2090 buf
[2] |= (val
>> 8) & 0x1f;
2094 case BFD_RELOC_SPARC_WDISP22
:
2095 val
= (val
>>= 2) + 1;
2097 case BFD_RELOC_SPARC_BASE22
:
2098 buf
[1] |= (val
>> 16) & 0x3f;
2103 case BFD_RELOC_NONE
:
2105 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2109 #ifdef BFD_ASSEMBLER
2114 /* should never be called for sparc */
2116 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2123 as_fatal ("sparc_create_short_jmp\n");
2126 #ifdef BFD_ASSEMBLER
2128 /* Translate internal representation of relocation info to BFD target
2131 tc_gen_reloc (section
, fixp
)
2136 bfd_reloc_code_real_type code
;
2138 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2139 assert (reloc
!= 0);
2141 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2142 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2143 if (fixp
->fx_pcrel
== 0)
2144 reloc
->addend
= fixp
->fx_addnumber
;
2146 switch (OUTPUT_FLAVOR
)
2148 case bfd_target_elf_flavour
:
2151 case bfd_target_aout_flavour
:
2152 reloc
->addend
= - reloc
->address
;
2155 /* What's a good default here? Is there any?? */
2159 switch (fixp
->fx_r_type
)
2162 case BFD_RELOC_HI22
:
2163 case BFD_RELOC_LO10
:
2164 case BFD_RELOC_32_PCREL_S2
:
2165 case BFD_RELOC_SPARC_BASE13
:
2166 case BFD_RELOC_SPARC_WDISP22
:
2167 /* start-sanitize-v9 */
2168 case BFD_RELOC_SPARC_10
:
2169 case BFD_RELOC_SPARC_11
:
2170 case BFD_RELOC_SPARC_HH22
:
2171 case BFD_RELOC_SPARC_HM10
:
2172 case BFD_RELOC_SPARC_LM22
:
2173 case BFD_RELOC_SPARC_PC_HH22
:
2174 case BFD_RELOC_SPARC_PC_HM10
:
2175 case BFD_RELOC_SPARC_PC_LM22
:
2176 /* end-sanitize-v9 */
2177 code
= fixp
->fx_r_type
;
2182 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2183 assert (reloc
->howto
!= 0);
2190 /* Translate internal representation of relocation info to target format.
2192 On sparc: first 4 bytes are normal unsigned long address, next three
2193 bytes are index, most sig. byte first. Byte 7 is broken up with
2194 bit 7 as external, bits 6 & 5 unused, and the lower
2195 five bits as relocation type. Next 4 bytes are long addend. */
2196 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2198 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2201 relax_addressT segment_address_in_file
;
2208 know (fixP
->fx_addsy
);
2210 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2213 r_index
= fixP
->fx_addsy
->sy_number
;
2218 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2222 md_number_to_chars (where
,
2223 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2226 /* now the fun stuff */
2227 where
[4] = (r_index
>> 16) & 0x0ff;
2228 where
[5] = (r_index
>> 8) & 0x0ff;
2229 where
[6] = r_index
& 0x0ff;
2230 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2233 if (fixP
->fx_addsy
->sy_frag
)
2235 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2240 r_addend
+= fixP
->fx_offset
- r_address
;
2244 r_addend
= fixP
->fx_addnumber
;
2247 md_number_to_chars (&where
[8], r_addend
, 4);
2250 } /* tc_aout_fix_to_chars() */
2253 /* should never be called for sparc */
2255 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2257 addressT from_addr
, to_addr
;
2261 as_fatal ("sparc_create_long_jump\n");
2262 } /* md_create_long_jump() */
2264 /* should never be called for sparc */
2266 md_estimate_size_before_relax (fragP
, segtype
)
2270 as_fatal ("sparc_estimate_size_before_relax\n");
2272 } /* md_estimate_size_before_relax() */
2275 /* for debugging only */
2278 struct sparc_it
*insn
;
2311 fprintf (stderr
, "ERROR: %s\n");
2313 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2314 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2315 fprintf (stderr
, "exp = {\n");
2316 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2317 ((insn
->exp
.X_add_symbol
!= NULL
)
2318 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2319 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2322 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2323 ((insn
->exp
.X_subtract_symbol
!= NULL
)
2324 ? (S_GET_NAME (insn
->exp
.X_subtract_symbol
)
2325 ? S_GET_NAME (insn
->exp
.X_subtract_symbol
)
2328 fprintf (stderr
, "\t\tX_add_number = %d\n",
2329 insn
->exp
.X_add_number
);
2330 fprintf (stderr
, "}\n");
2332 } /* print_insn() */
2338 * Invocation line includes a switch not recognized by the base assembler.
2339 * See if it's a processor-specific option. These are:
2342 * Warn on architecture bumps. See also -A.
2344 * -Av6, -Av7, -Av8, -Asparclite
2345 * Select the architecture. Instructions or features not
2346 * supported by the selected architecture cause fatal errors.
2348 * The default is to start at v6, and bump the architecture up
2349 * whenever an instruction is seen at a higher level.
2351 * If -bump is specified, a warning is printing when bumping to
2354 * If an architecture is specified, all instructions must match
2355 * that architecture. Any higher level instructions are flagged
2358 * if both an architecture and -bump are specified, the
2359 * architecture starts at the specified level, but bumps are
2364 * Another architecture switch.
2367 * Bumping between incompatible architectures is always an
2368 * error. For example, from sparclite to v9.
2373 md_parse_option (argP
, cntP
, vecP
)
2381 if (!strcmp (*argP
, "bump"))
2386 else if (**argP
== 'A')
2390 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2392 if (strcmp (p
, *arch
) == 0)
2395 } /* found a match */
2396 } /* walk the pname table */
2400 as_bad ("unknown architecture: %s", p
);
2404 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2405 architecture_requested
= 1;
2409 else if (**argP
== 'V')
2411 extern void print_version_id ();
2412 print_version_id ();
2414 else if (**argP
== 'Q')
2416 /* Qy - do emit .comment
2417 Qn - do not emit .comment */
2419 else if (**argP
== 's')
2421 /* use .stab instead of .stab.excl */
2426 /* Unknown option */
2430 **argP
= '\0'; /* Done parsing this switch */
2432 } /* md_parse_option() */
2434 /* We have no need to default values of symbols. */
2438 md_undefined_symbol (name
)
2442 } /* md_undefined_symbol() */
2444 /* Parse an operand that is machine-specific.
2445 We just return without modifying the expression if we have nothing
2450 md_operand (expressionP
)
2451 expressionS
*expressionP
;
2455 /* Round up a section size to the appropriate boundary. */
2457 md_section_align (segment
, size
)
2461 /* Round all sects to multiple of 8 */
2462 return (size
+ 7) & ~7;
2465 /* Exactly what point is a PC-relative offset relative TO?
2466 On the sparc, they're relative to the address of the offset, plus
2467 its size. This gets us to the following instruction.
2468 (??? Is this right? FIXME-SOON) */
2470 md_pcrel_from (fixP
)
2473 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2476 #ifndef BFD_ASSEMBLER
2478 tc_aout_pre_write_hook (headers
)
2479 object_headers
*headers
;
2481 H_SET_VERSION (headers
, 1);
2485 /* end of tc-sparc.c */