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");
421 old_subsec
= now_subseg
;
423 record_alignment (bss_section
, align
);
424 subseg_set (bss_section
, 0);
426 frag_align (align
, 0);
427 if (S_GET_SEGMENT (symbolP
) == bss_section
)
428 symbolP
->sy_frag
->fr_symbol
= 0;
429 symbolP
->sy_frag
= frag_now
;
430 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
433 S_SET_SEGMENT (symbolP
, bss_section
);
434 S_CLEAR_EXTERNAL (symbolP
);
435 subseg_set (old_sec
, old_subsec
);
441 S_SET_VALUE (symbolP
, size
);
442 S_SET_EXTERNAL (symbolP
);
443 /* should be common, but this is how gas does it for now */
444 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
449 input_line_pointer
++;
450 /* @@ Some use the dot, some don't. Can we get some consistency?? */
451 if (*input_line_pointer
== '.')
452 input_line_pointer
++;
453 /* @@ Some say data, some say bss. */
454 if (strncmp (input_line_pointer
, "bss\"", 4)
455 && strncmp (input_line_pointer
, "data\"", 5))
457 while (*--input_line_pointer
!= '"')
459 input_line_pointer
--;
460 goto bad_common_segment
;
462 while (*input_line_pointer
++ != '"')
464 goto allocate_common
;
466 demand_empty_rest_of_line ();
471 p
= input_line_pointer
;
472 while (*p
&& *p
!= '\n')
476 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
478 input_line_pointer
= p
;
479 ignore_rest_of_line ();
488 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
490 input_line_pointer
+= 6;
494 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
496 input_line_pointer
+= 6;
500 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
502 input_line_pointer
+= 7;
506 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
508 input_line_pointer
+= 5;
509 /* We only support 2 segments -- text and data -- for now, so
510 things in the "bss segment" will have to go into data for now.
511 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
512 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
515 as_bad ("Unknown segment type");
516 demand_empty_rest_of_line ();
523 subseg_set (data_section
, 1);
524 demand_empty_rest_of_line ();
531 extern char is_end_of_line
[];
533 while (!is_end_of_line
[*input_line_pointer
])
535 ++input_line_pointer
;
537 ++input_line_pointer
;
541 /* start-sanitize-v9 */
547 if (isdigit (*input_line_pointer
))
553 struct priv_reg_entry
559 struct priv_reg_entry priv_reg_table
[] =
578 {"", -1}, /* end marker */
588 #define MEMBAR_MASKS_SIZE 7
590 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
593 {"MemIssue", 8, 0x20},
594 {"Lookaside", 9, 0x10},
595 {"StoreStore", 10, 0x08},
596 {"LoadStore", 9, 0x04},
597 {"StoreLoad", 9, 0x02},
598 {"LoadLoad", 8, 0x01},
603 struct priv_reg_entry
*p
, *q
;
605 return strcmp (q
->name
, p
->name
);
609 /* end-sanitize-v9 */
611 /* This function is called once, at assembler startup time. It should
612 set up all the tables, etc. that the MD part of the assembler will need. */
616 register char *retval
= NULL
;
618 register unsigned int i
= 0;
620 op_hash
= hash_new ();
622 as_fatal ("Virtual memory exhausted");
624 while (i
< NUMOPCODES
)
626 const char *name
= sparc_opcodes
[i
].name
;
627 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
628 if (retval
!= NULL
&& *retval
!= '\0')
630 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
631 sparc_opcodes
[i
].name
, retval
);
636 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
638 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
639 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
644 while (i
< NUMOPCODES
645 && !strcmp (sparc_opcodes
[i
].name
, name
));
649 as_fatal ("Broken assembler. No assembly attempted.");
651 for (i
= '0'; i
< '8'; ++i
)
653 for (i
= '0'; i
<= '9'; ++i
)
655 for (i
= 'a'; i
<= 'f'; ++i
)
656 toHex
[i
] = i
+ 10 - 'a';
657 for (i
= 'A'; i
<= 'F'; ++i
)
658 toHex
[i
] = i
+ 10 - 'A';
660 /* start-sanitize-v9 */
663 current_architecture
= v9
;
666 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
667 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
669 /* end-sanitize-v9 */
671 target_big_endian
= 1;
690 /* See if "set" operand is absolute and small; skip sethi if so. */
691 if (special_case
== SPECIAL_CASE_SET
692 && the_insn
.exp
.X_op
== O_constant
)
694 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
695 && the_insn
.exp
.X_add_number
< (1 << 12))
697 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
698 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
699 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
700 special_case
= 0; /* No longer special */
701 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
706 /* put out the opcode */
707 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
709 /* put out the symbol-dependent stuff */
710 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
712 fix_new_exp (frag_now
, /* which frag */
713 (toP
- frag_now
->fr_literal
), /* where */
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_op
== O_constant
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_exp (frag_now
, /* which frag */
734 (toP
- frag_now
->fr_literal
), /* where */
741 case SPECIAL_CASE_FDIV
:
742 /* According to information leaked from Sun, the "fdiv" instructions
743 on early SPARC machines would produce incorrect results sometimes.
744 The workaround is to add an fmovs of the destination register to
745 itself just after the instruction. This was true on machines
746 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
748 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
750 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
751 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
752 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
759 as_fatal ("failed sanity check.");
761 } /* md_assemble() */
767 char *error_message
= "";
771 struct sparc_opcode
*insn
;
773 unsigned long opcode
;
774 unsigned int mask
= 0;
777 long immediate_max
= 0;
779 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
797 as_bad ("Unknown opcode: `%s'", str
);
800 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
802 as_bad ("Unknown opcode: `%s'", str
);
812 opcode
= insn
->match
;
813 memset (&the_insn
, '\0', sizeof (the_insn
));
814 the_insn
.reloc
= BFD_RELOC_NONE
;
817 * Build the opcode, checking as we go to make
818 * sure that the operands match
820 for (args
= insn
->args
;; ++args
)
825 /* start-sanitize-v9 */
832 /* Parse a series of masks. */
838 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
839 if (!strncmp (s
, membar_masks
[i
].name
,
840 membar_masks
[i
].len
))
842 if (i
< MEMBAR_MASKS_SIZE
)
844 mask
|= membar_masks
[i
].mask
;
845 s
+= membar_masks
[i
].len
;
849 error_message
= ": invalid membar mask name";
856 else if (isdigit (*s
))
860 mask
= mask
* 10 + *s
- '0';
864 if (mask
< 0 || mask
> 127)
866 error_message
= ": invalid membar mask number";
872 error_message
= ": unrecognizable membar mask";
875 opcode
|= SIMM13 (mask
);
881 int prefetch_fcn
= 0;
883 /* Parse a prefetch function. */
887 if (!strncmp (s
, "n_reads", 7))
888 prefetch_fcn
= 0, s
+= 7;
889 else if (!strncmp (s
, "one_read", 8))
890 prefetch_fcn
= 1, s
+= 8;
891 else if (!strncmp (s
, "n_writes", 8))
892 prefetch_fcn
= 2, s
+= 8;
893 else if (!strncmp (s
, "one_write", 9))
894 prefetch_fcn
= 3, s
+= 9;
895 else if (!strncmp (s
, "page", 4))
896 prefetch_fcn
= 4, s
+= 4;
899 error_message
= ": invalid prefetch function name";
903 else if (isdigit (*s
))
907 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
911 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
913 error_message
= ": invalid prefetch function number";
919 error_message
= ": unrecognizable prefetch function";
922 opcode
|= RD (prefetch_fcn
);
928 /* Parse a privileged register. */
931 struct priv_reg_entry
*p
= priv_reg_table
;
932 int len
= 9999999; /* init to make gcc happy */
935 while (p
->name
[0] > s
[0])
937 while (p
->name
[0] == s
[0])
939 len
= strlen (p
->name
);
940 if (strncmp (p
->name
, s
, len
) == 0)
944 if (p
->name
[0] != s
[0])
946 error_message
= ": unrecognizable privileged register";
950 opcode
|= (p
->regnum
<< 14);
952 opcode
|= (p
->regnum
<< 25);
958 error_message
= ": unrecognizable privileged register";
962 /* end-sanitize-v9 */
966 if (strncmp (s
, "%asr", 4) == 0)
976 num
= num
* 10 + *s
- '0';
980 if (num
< 16 || 31 < num
)
982 error_message
= ": asr number must be between 15 and 31";
986 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
991 error_message
= ": expecting %asrN";
993 } /* if %asr followed by a number. */
998 /* start-sanitize-v9 */
1001 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1002 immediate_max
= 0x03FF;
1006 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1007 immediate_max
= 0x01FF;
1011 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1016 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1021 if (*s
== 'p' && s
[1] == 'n')
1029 if (*s
== 'p' && s
[1] == 't')
1041 if (strncmp (s
, "%icc", 4) == 0)
1053 if (strncmp (s
, "%xcc", 4) == 0)
1065 if (strncmp (s
, "%fcc0", 5) == 0)
1077 if (strncmp (s
, "%fcc1", 5) == 0)
1089 if (strncmp (s
, "%fcc2", 5) == 0)
1101 if (strncmp (s
, "%fcc3", 5) == 0)
1109 if (strncmp (s
, "%pc", 3) == 0)
1117 if (strncmp (s
, "%tick", 5) == 0)
1124 /* end-sanitize-v9 */
1126 case '\0': /* end of args */
1145 case '[': /* these must match exactly */
1153 case '#': /* must be at least one digit */
1156 while (isdigit (*s
))
1164 case 'C': /* coprocessor state register */
1165 if (strncmp (s
, "%csr", 4) == 0)
1172 case 'b': /* next operand is a coprocessor register */
1175 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1180 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1194 opcode
|= mask
<< 14;
1202 opcode
|= mask
<< 25;
1208 case 'r': /* next operand must be a register */
1217 case 'f': /* frame pointer */
1225 case 'g': /* global register */
1226 if (isoctal (c
= *s
++))
1233 case 'i': /* in register */
1234 if (isoctal (c
= *s
++))
1236 mask
= c
- '0' + 24;
1241 case 'l': /* local register */
1242 if (isoctal (c
= *s
++))
1244 mask
= (c
- '0' + 16);
1249 case 'o': /* out register */
1250 if (isoctal (c
= *s
++))
1252 mask
= (c
- '0' + 8);
1257 case 's': /* stack pointer */
1265 case 'r': /* any register */
1266 if (!isdigit (c
= *s
++))
1283 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1299 * Got the register, now figure out where
1300 * it goes in the opcode.
1306 opcode
|= mask
<< 14;
1314 opcode
|= mask
<< 25;
1318 opcode
|= (mask
<< 25) | (mask
<< 14);
1324 case 'e': /* next operand is a floating point register */
1339 && ((format
= *s
) == 'f')
1342 for (mask
= 0; isdigit (*s
); ++s
)
1344 mask
= 10 * mask
+ (*s
- '0');
1345 } /* read the number */
1353 } /* register must be even numbered */
1361 } /* register must be multiple of 4 */
1363 /* start-sanitize-v9 */
1367 error_message
= ": There are only 64 f registers; [0-63]";
1373 } /* wrap high bit */
1375 /* end-sanitize-v9 */
1378 error_message
= ": There are only 32 f registers; [0-31]";
1381 /* start-sanitize-v9 */
1383 /* end-sanitize-v9 */
1388 } /* if not an 'f' register. */
1396 opcode
|= RS1 (mask
);
1403 opcode
|= RS2 (mask
);
1409 opcode
|= RD (mask
);
1418 if (strncmp (s
, "%fsr", 4) == 0)
1425 case 'h': /* high 22 bits */
1426 the_insn
.reloc
= BFD_RELOC_HI22
;
1429 case 'l': /* 22 bit PC relative immediate */
1430 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1434 case 'L': /* 30 bit immediate */
1435 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1439 case 'n': /* 22 bit immediate */
1440 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1443 case 'i': /* 13 bit immediate */
1444 /* What's the difference between base13 and 13? */
1445 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1446 immediate_max
= 0x0FFF;
1455 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1457 the_insn
.reloc
= BFD_RELOC_HI22
;
1460 else if (c
== 'l' && s
[2] == 'o')
1462 the_insn
.reloc
= BFD_RELOC_LO10
;
1464 /* start-sanitize-v9 */
1471 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1478 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1481 /* end-sanitize-v9 */
1486 /* Note that if the getExpression() fails, we
1487 will still have created U entries in the
1488 symbol table for the 'symbols' in the input
1489 string. Try not to create U symbols for
1492 /* This stuff checks to see if the
1493 expression ends in +%reg If it does,
1494 it removes the register from the
1495 expression, and re-sets 's' to point
1496 to the right place */
1500 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1502 if (s1
!= s
&& isdigit (s1
[-1]))
1504 if (s1
[-2] == '%' && s1
[-3] == '+')
1508 (void) getExpression (s
);
1513 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1517 (void) getExpression (s
);
1524 (void) getExpression (s
);
1527 /* Check for invalid constant values. Don't
1528 warn if constant was inside %hi or %lo,
1529 since these truncate the constant to
1531 if (immediate_max
!= 0
1532 && the_insn
.reloc
!= BFD_RELOC_LO10
1533 && the_insn
.reloc
!= BFD_RELOC_HI22
1534 /* start-sanitize-v9 */
1536 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1537 && the_insn
.reloc
!= RELOC_HLO10
1538 && the_insn
.reloc
!= RELOC_HHI22
1541 /* end-sanitize-v9 */
1542 && the_insn
.exp
.X_add_symbol
== 0
1543 && the_insn
.exp
.X_op_symbol
== 0
1544 && the_insn
.exp
.X_op
== O_constant
1545 && (the_insn
.exp
.X_add_number
> immediate_max
1546 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1547 as_bad ("constant value must be between %ld and %ld",
1548 ~immediate_max
, immediate_max
);
1549 /* Reset to prevent extraneous range check. */
1564 /* start-sanitize-v9 */
1566 /* end-sanitize-v9 */
1567 char *push
= input_line_pointer
;
1570 input_line_pointer
= s
;
1573 if (e
.X_op
== O_constant
)
1575 opcode
|= e
.X_add_number
<< 5;
1576 s
= input_line_pointer
;
1577 input_line_pointer
= push
;
1582 /* start-sanitize-v9 */
1590 if (!strncmp (s
, "ASI_AIUP", 8))
1592 else if (!strncmp (s
, "ASI_AIUS", 8))
1594 else if (!strncmp (s
, "ASI_PNF", 7))
1596 else if (!strncmp (s
, "ASI_SNF", 7))
1598 else if (!strncmp (s
, "ASI_P", 5))
1600 else if (!strncmp (s
, "ASI_S", 5))
1604 error_message
= ": invalid asi name";
1608 else if (isdigit (*s
))
1610 char *push
= input_line_pointer
;
1611 input_line_pointer
= s
;
1612 asi
= get_absolute_expression ();
1613 s
= input_line_pointer
;
1614 input_line_pointer
= push
;
1616 if (asi
< 0 || asi
> 255)
1618 error_message
= ": invalid asi number";
1624 error_message
= ": unrecognizable asi";
1627 opcode
|= ASI (asi
);
1630 /* end-sanitize-v9 */
1631 } /* alternate space */
1634 if (strncmp (s
, "%psr", 4) == 0)
1641 case 'q': /* floating point queue */
1642 if (strncmp (s
, "%fq", 3) == 0)
1649 case 'Q': /* coprocessor queue */
1650 if (strncmp (s
, "%cq", 3) == 0)
1658 if (strcmp (str
, "set") == 0)
1660 special_case
= SPECIAL_CASE_SET
;
1663 else if (strncmp (str
, "fdiv", 4) == 0)
1665 special_case
= SPECIAL_CASE_FDIV
;
1670 /* start-sanitize-v9 */
1673 if (strncmp (s
, "%asi", 4) != 0)
1679 if (strncmp (s
, "%fprs", 5) != 0)
1685 if (strncmp (s
, "%ccr", 4) != 0)
1690 /* end-sanitize-v9 */
1693 if (strncmp (s
, "%tbr", 4) != 0)
1699 if (strncmp (s
, "%wim", 4) != 0)
1705 if (strncmp (s
, "%y", 2) != 0)
1711 as_fatal ("failed sanity check.");
1712 } /* switch on arg code */
1714 } /* for each arg that we expect */
1718 /* Args don't match. */
1719 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1720 && !strcmp (insn
->name
, insn
[1].name
))
1728 as_bad ("Illegal operands%s", error_message
);
1734 if (insn
->architecture
> current_architecture
)
1736 if ((!architecture_requested
|| warn_on_bump
)
1738 /* start-sanitize-v9 */
1740 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1743 /* end-sanitize-v9 */
1745 /* start-sanitize-v9 */
1747 /* end-sanitize-v9 */
1752 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1753 architecture_pname
[current_architecture
],
1754 architecture_pname
[insn
->architecture
],
1758 current_architecture
= insn
->architecture
;
1762 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1764 architecture_pname
[insn
->architecture
],
1765 architecture_pname
[current_architecture
]);
1767 } /* if bump ok else error */
1768 } /* if architecture higher */
1772 } /* forever looking for a match */
1774 the_insn
.opcode
= opcode
;
1785 save_in
= input_line_pointer
;
1786 input_line_pointer
= str
;
1787 seg
= expression (&the_insn
.exp
);
1788 if (seg
== absolute_section
1789 || seg
== text_section
1790 || seg
== data_section
1791 || seg
== bss_section
1792 || seg
== undefined_section
)
1796 the_insn
.error
= "bad segment";
1797 expr_end
= input_line_pointer
;
1798 input_line_pointer
= save_in
;
1801 expr_end
= input_line_pointer
;
1802 input_line_pointer
= save_in
;
1804 } /* getExpression() */
1808 This is identical to the md_atof in m68k.c. I think this is right,
1811 Turn a string in input_line_pointer into a floating point constant of type
1812 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1813 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1816 /* Equal to MAX_PRECISION in atof-ieee.c */
1817 #define MAX_LITTLENUMS 6
1820 md_atof (type
, litP
, sizeP
)
1826 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1827 LITTLENUM_TYPE
*wordP
;
1860 return "Bad call to MD_ATOF()";
1862 t
= atof_ieee (input_line_pointer
, type
, words
);
1864 input_line_pointer
= t
;
1865 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1866 for (wordP
= words
; prec
--;)
1868 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1869 litP
+= sizeof (LITTLENUM_TYPE
);
1875 * Write out big-endian.
1878 md_number_to_chars (buf
, val
, n
)
1886 /* start-sanitize-v9 */
1892 /* end-sanitize-v9 */
1903 as_fatal ("failed sanity check.");
1906 } /* md_number_to_chars() */
1908 /* Apply a fixS to the frags, now that we know the value it ought to
1911 #ifdef BFD_ASSEMBLER
1916 md_apply_fix (fixP
, value
)
1918 #ifdef BFD_ASSEMBLER
1924 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1927 #ifdef BFD_ASSEMBLER
1933 #ifdef BFD_ASSEMBLER
1934 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1936 assert (fixP
->fx_r_type
< NO_RELOC
);
1939 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1942 * This is a hack. There should be a better way to
1945 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1947 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1950 switch (fixP
->fx_r_type
)
1954 buf
[0] = 0; /* val >> 24; */
1955 buf
[1] = 0; /* val >> 16; */
1956 buf
[2] = 0; /* val >> 8; */
1957 buf
[3] = 0; /* val; */
1960 case BFD_RELOC_32_PCREL_S2
:
1961 val
= (val
>>= 2) + 1;
1962 buf
[0] |= (val
>> 24) & 0x3f;
1963 buf
[1] = (val
>> 16);
1968 /* start-sanitize-v9 */
1970 case BFD_RELOC_SPARC_11
:
1971 if (((val
> 0) && (val
& ~0x7ff))
1972 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1974 as_bad ("relocation overflow.");
1977 buf
[2] |= (val
>> 8) & 0x7;
1978 buf
[3] = val
& 0xff;
1981 case BFD_RELOC_SPARC_10
:
1982 if (((val
> 0) && (val
& ~0x3ff))
1983 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1985 as_bad ("relocation overflow.");
1988 buf
[2] |= (val
>> 8) & 0x3;
1989 buf
[3] = val
& 0xff;
1992 case BFD_RELOC_SPARC_WDISP16
:
1993 if (((val
> 0) && (val
& ~0x3fffc))
1994 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1996 as_bad ("relocation overflow.");
1999 val
= (val
>>= 2) + 1;
2000 buf
[1] |= ((val
>> 14) & 0x3) << 4;
2001 buf
[2] |= (val
>> 8) & 0x3f;
2002 buf
[3] = val
& 0xff;
2005 case BFD_RELOC_SPARC_WDISP19
:
2006 if (((val
> 0) && (val
& ~0x1ffffc))
2007 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2009 as_bad ("relocation overflow.");
2012 val
= (val
>>= 2) + 1;
2013 buf
[1] |= (val
>> 16) & 0x7;
2014 buf
[2] = (val
>> 8) & 0xff;
2015 buf
[3] = val
& 0xff;
2018 case BFD_RELOC_SPARC_HH22
:
2020 /* intentional fallthrough */
2022 /* end-sanitize-v9 */
2024 /* start-sanitize-v9 */
2026 case BFD_RELOC_SPARC_LM22
:
2028 /* end-sanitize-v9 */
2029 case BFD_RELOC_HI22
:
2030 if (!fixP
->fx_addsy
)
2032 buf
[1] |= (val
>> 26) & 0x3f;
2043 case BFD_RELOC_SPARC22
:
2044 if (val
& ~0x003fffff)
2046 as_bad ("relocation overflow");
2048 buf
[1] |= (val
>> 16) & 0x3f;
2050 buf
[3] = val
& 0xff;
2053 case BFD_RELOC_SPARC13
:
2054 if (val
& ~0x00001fff)
2056 as_bad ("relocation overflow");
2058 buf
[2] |= (val
>> 8) & 0x1f;
2059 buf
[3] = val
& 0xff;
2062 /* start-sanitize-v9 */
2064 case BFD_RELOC_SPARC_HM10
:
2066 /* intentional fallthrough */
2068 /* end-sanitize-v9 */
2070 case BFD_RELOC_LO10
:
2071 if (!fixP
->fx_addsy
)
2073 buf
[2] |= (val
>> 8) & 0x03;
2079 case BFD_RELOC_SPARC_BASE13
:
2080 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2081 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2083 as_bad ("relocation overflow");
2085 buf
[2] |= (val
>> 8) & 0x1f;
2089 case BFD_RELOC_SPARC_WDISP22
:
2090 val
= (val
>>= 2) + 1;
2092 case BFD_RELOC_SPARC_BASE22
:
2093 buf
[1] |= (val
>> 16) & 0x3f;
2098 case BFD_RELOC_NONE
:
2100 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2104 #ifdef BFD_ASSEMBLER
2109 /* should never be called for sparc */
2111 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2118 as_fatal ("sparc_create_short_jmp\n");
2121 #ifdef BFD_ASSEMBLER
2123 /* Translate internal representation of relocation info to BFD target
2126 tc_gen_reloc (section
, fixp
)
2131 bfd_reloc_code_real_type code
;
2133 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2134 assert (reloc
!= 0);
2136 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2137 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2138 if (fixp
->fx_pcrel
== 0)
2139 reloc
->addend
= fixp
->fx_addnumber
;
2141 switch (OUTPUT_FLAVOR
)
2143 case bfd_target_elf_flavour
:
2146 case bfd_target_aout_flavour
:
2147 reloc
->addend
= - reloc
->address
;
2150 /* What's a good default here? Is there any?? */
2154 switch (fixp
->fx_r_type
)
2157 case BFD_RELOC_HI22
:
2158 case BFD_RELOC_LO10
:
2159 case BFD_RELOC_32_PCREL_S2
:
2160 case BFD_RELOC_SPARC_BASE13
:
2161 case BFD_RELOC_SPARC_WDISP22
:
2162 /* start-sanitize-v9 */
2163 case BFD_RELOC_SPARC_10
:
2164 case BFD_RELOC_SPARC_11
:
2165 case BFD_RELOC_SPARC_HH22
:
2166 case BFD_RELOC_SPARC_HM10
:
2167 case BFD_RELOC_SPARC_LM22
:
2168 case BFD_RELOC_SPARC_PC_HH22
:
2169 case BFD_RELOC_SPARC_PC_HM10
:
2170 case BFD_RELOC_SPARC_PC_LM22
:
2171 /* end-sanitize-v9 */
2172 code
= fixp
->fx_r_type
;
2177 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2178 assert (reloc
->howto
!= 0);
2185 /* Translate internal representation of relocation info to target format.
2187 On sparc: first 4 bytes are normal unsigned long address, next three
2188 bytes are index, most sig. byte first. Byte 7 is broken up with
2189 bit 7 as external, bits 6 & 5 unused, and the lower
2190 five bits as relocation type. Next 4 bytes are long addend. */
2191 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2193 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2196 relax_addressT segment_address_in_file
;
2203 know (fixP
->fx_addsy
);
2205 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2208 r_index
= fixP
->fx_addsy
->sy_number
;
2213 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2217 md_number_to_chars (where
,
2218 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2221 /* now the fun stuff */
2222 where
[4] = (r_index
>> 16) & 0x0ff;
2223 where
[5] = (r_index
>> 8) & 0x0ff;
2224 where
[6] = r_index
& 0x0ff;
2225 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2228 if (fixP
->fx_addsy
->sy_frag
)
2230 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2235 r_addend
+= fixP
->fx_offset
- r_address
;
2239 r_addend
= fixP
->fx_addnumber
;
2242 md_number_to_chars (&where
[8], r_addend
, 4);
2245 } /* tc_aout_fix_to_chars() */
2248 /* should never be called for sparc */
2250 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2252 addressT from_addr
, to_addr
;
2256 as_fatal ("sparc_create_long_jump\n");
2257 } /* md_create_long_jump() */
2259 /* should never be called for sparc */
2261 md_estimate_size_before_relax (fragP
, segtype
)
2265 as_fatal ("sparc_estimate_size_before_relax\n");
2267 } /* md_estimate_size_before_relax() */
2270 /* for debugging only */
2273 struct sparc_it
*insn
;
2306 fprintf (stderr
, "ERROR: %s\n");
2308 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2309 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2310 fprintf (stderr
, "exp = {\n");
2311 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2312 ((insn
->exp
.X_add_symbol
!= NULL
)
2313 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2314 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2317 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2318 ((insn
->exp
.X_op_symbol
!= NULL
)
2319 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2320 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2323 fprintf (stderr
, "\t\tX_add_number = %d\n",
2324 insn
->exp
.X_add_number
);
2325 fprintf (stderr
, "}\n");
2327 } /* print_insn() */
2333 * Invocation line includes a switch not recognized by the base assembler.
2334 * See if it's a processor-specific option. These are:
2337 * Warn on architecture bumps. See also -A.
2339 * -Av6, -Av7, -Av8, -Asparclite
2340 * Select the architecture. Instructions or features not
2341 * supported by the selected architecture cause fatal errors.
2343 * The default is to start at v6, and bump the architecture up
2344 * whenever an instruction is seen at a higher level.
2346 * If -bump is specified, a warning is printing when bumping to
2349 * If an architecture is specified, all instructions must match
2350 * that architecture. Any higher level instructions are flagged
2353 * if both an architecture and -bump are specified, the
2354 * architecture starts at the specified level, but bumps are
2359 * Another architecture switch.
2362 * Bumping between incompatible architectures is always an
2363 * error. For example, from sparclite to v9.
2368 md_parse_option (argP
, cntP
, vecP
)
2376 if (!strcmp (*argP
, "bump"))
2381 else if (**argP
== 'A')
2385 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2387 if (strcmp (p
, *arch
) == 0)
2390 } /* found a match */
2391 } /* walk the pname table */
2395 as_bad ("unknown architecture: %s", p
);
2399 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2400 architecture_requested
= 1;
2404 else if (**argP
== 'V')
2406 extern void print_version_id ();
2407 print_version_id ();
2409 else if (**argP
== 'Q')
2411 /* Qy - do emit .comment
2412 Qn - do not emit .comment */
2414 else if (**argP
== 's')
2416 /* use .stab instead of .stab.excl */
2421 /* Unknown option */
2425 **argP
= '\0'; /* Done parsing this switch */
2427 } /* md_parse_option() */
2429 /* We have no need to default values of symbols. */
2433 md_undefined_symbol (name
)
2437 } /* md_undefined_symbol() */
2439 /* Parse an operand that is machine-specific.
2440 We just return without modifying the expression if we have nothing
2445 md_operand (expressionP
)
2446 expressionS
*expressionP
;
2450 /* Round up a section size to the appropriate boundary. */
2452 md_section_align (segment
, size
)
2456 /* Round all sects to multiple of 8 */
2457 return (size
+ 7) & ~7;
2460 /* Exactly what point is a PC-relative offset relative TO?
2461 On the sparc, they're relative to the address of the offset, plus
2462 its size. This gets us to the following instruction.
2463 (??? Is this right? FIXME-SOON) */
2465 md_pcrel_from (fixP
)
2468 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2471 #ifndef BFD_ASSEMBLER
2473 tc_aout_pre_write_hook (headers
)
2474 object_headers
*headers
;
2476 H_SET_VERSION (headers
, 1);
2480 /* end of tc-sparc.c */