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"
30 static void sparc_ip
PARAMS ((char *));
32 static enum sparc_architecture current_architecture
= v6
;
33 static int architecture_requested
;
34 static int warn_on_bump
;
36 extern int target_big_endian
;
38 const relax_typeS md_relax_table
[1];
40 /* handle of the OPCODE hash table */
41 static struct hash_control
*op_hash
= NULL
;
43 static void s_data1
PARAMS ((void));
44 static void s_seg
PARAMS ((int));
45 static void s_proc
PARAMS ((int));
46 static void s_reserve
PARAMS ((int));
47 static void s_common
PARAMS ((int));
49 const pseudo_typeS md_pseudo_table
[] =
51 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
52 {"common", s_common
, 0},
53 {"global", s_globl
, 0},
55 {"optim", s_ignore
, 0},
57 {"reserve", s_reserve
, 0},
61 /* start-sanitize-v9 */
70 /* these are specific to sparc/svr4 */
71 {"pushsection", obj_elf_section
, 0},
72 {"popsection", obj_elf_previous
, 0},
79 const int md_short_jump_size
= 4;
80 const int md_long_jump_size
= 4;
81 const int md_reloc_size
= 12; /* Size of relocation record */
83 /* This array holds the chars that always start a comment. If the
84 pre-processor is disabled, these aren't very useful */
85 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
87 /* This array holds the chars that only start a comment at the beginning of
88 a line. If the line seems to have the form '# 123 filename'
89 .line and .file directives will appear in the pre-processed output */
90 /* Note that input_file.c hand checks for '#' at the beginning of the
91 first line of the input file. This is because the compiler outputs
92 #NO_APP at the beginning of its output. */
93 /* Also note that comments started like this one will always
94 work if '/' isn't otherwise defined. */
95 const char line_comment_chars
[] = "#";
97 const char line_separator_chars
[] = "";
99 /* Chars that can be used to separate mant from exp in floating point nums */
100 const char EXP_CHARS
[] = "eE";
102 /* Chars that mean this number is a floating point constant */
105 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
107 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
108 changed in read.c. Ideally it shouldn't have to know about it at all,
109 but nothing is ideal around here. */
111 static unsigned char octal
[256];
112 #define isoctal(c) octal[(unsigned char) (c)]
113 static unsigned char toHex
[256];
118 unsigned long opcode
;
119 struct nlist
*nlistp
;
122 bfd_reloc_code_real_type reloc
;
125 struct sparc_it the_insn
, set_insn
;
128 static void print_insn
PARAMS ((struct sparc_it
*insn
));
130 static int getExpression
PARAMS ((char *str
));
132 static char *expr_end
;
133 static int special_case
;
136 * Instructions that require wierd handling because they're longer than
139 #define SPECIAL_CASE_SET 1
140 #define SPECIAL_CASE_FDIV 2
143 * sort of like s_lcomm
147 static int max_alignment
= 15;
162 name
= input_line_pointer
;
163 c
= get_symbol_end ();
164 p
= input_line_pointer
;
168 if (*input_line_pointer
!= ',')
170 as_bad ("Expected comma after name");
171 ignore_rest_of_line ();
175 ++input_line_pointer
;
177 if ((size
= get_absolute_expression ()) < 0)
179 as_bad ("BSS length (%d.) <0! Ignored.", size
);
180 ignore_rest_of_line ();
185 symbolP
= symbol_find_or_make (name
);
188 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
189 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
191 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
195 if (input_line_pointer
[2] == '.')
196 input_line_pointer
+= 7;
198 input_line_pointer
+= 6;
201 if (*input_line_pointer
== ',')
203 ++input_line_pointer
;
206 if (*input_line_pointer
== '\n')
208 as_bad ("Missing alignment");
212 align
= get_absolute_expression ();
214 if (align
> max_alignment
)
216 align
= max_alignment
;
217 as_warn ("Alignment too large: %d. assumed.", align
);
223 as_warn ("Alignment negative. 0 assumed.");
226 record_alignment (bss_section
, align
);
228 /* convert to a power of 2 alignment */
229 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
233 as_bad ("Alignment not a power of 2");
234 ignore_rest_of_line ();
236 } /* not a power of two */
239 } /* if has optional alignment */
243 if ((S_GET_SEGMENT (symbolP
) == bss_section
244 || !S_IS_DEFINED (symbolP
))
246 && S_GET_OTHER (symbolP
) == 0
247 && S_GET_DESC (symbolP
) == 0
254 segT current_seg
= now_seg
;
255 subsegT current_subseg
= now_subseg
;
257 subseg_set (bss_section
, 1); /* switch to bss */
260 frag_align (align
, 0); /* do alignment */
262 /* detach from old frag */
263 if (S_GET_SEGMENT(symbolP
) == bss_section
)
264 symbolP
->sy_frag
->fr_symbol
= NULL
;
266 symbolP
->sy_frag
= frag_now
;
267 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
271 S_SET_SEGMENT (symbolP
, bss_section
);
273 subseg_set (current_seg
, current_subseg
);
278 as_warn("Ignoring attempt to re-define symbol %s.", name
);
279 } /* if not redefining */
281 demand_empty_rest_of_line ();
294 name
= input_line_pointer
;
295 c
= get_symbol_end ();
296 /* just after name is now '\0' */
297 p
= input_line_pointer
;
300 if (*input_line_pointer
!= ',')
302 as_bad ("Expected comma after symbol-name");
303 ignore_rest_of_line ();
306 input_line_pointer
++; /* skip ',' */
307 if ((temp
= get_absolute_expression ()) < 0)
309 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
310 ignore_rest_of_line ();
315 symbolP
= symbol_find_or_make (name
);
317 if (S_IS_DEFINED (symbolP
))
319 as_bad ("Ignoring attempt to re-define symbol");
320 ignore_rest_of_line ();
323 if (S_GET_VALUE (symbolP
) != 0)
325 if (S_GET_VALUE (symbolP
) != size
)
327 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
328 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
334 S_SET_VALUE (symbolP
, (valueT
) size
);
335 S_SET_EXTERNAL (symbolP
);
338 know (symbolP
->sy_frag
== &zero_address_frag
);
339 if (*input_line_pointer
!= ',')
341 as_bad ("Expected comma after common length");
342 ignore_rest_of_line ();
345 input_line_pointer
++;
347 if (*input_line_pointer
!= '"')
349 temp
= get_absolute_expression ();
351 if (temp
> max_alignment
)
353 temp
= max_alignment
;
354 as_warn ("Common alignment too large: %d. assumed", temp
);
360 as_warn ("Common alignment negative; 0 assumed");
372 old_subsec
= now_subseg
;
374 record_alignment (bss_section
, align
);
375 subseg_set (bss_section
, 0);
377 frag_align (align
, 0);
378 if (S_GET_SEGMENT (symbolP
) == bss_section
)
379 symbolP
->sy_frag
->fr_symbol
= 0;
380 symbolP
->sy_frag
= frag_now
;
381 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
384 S_SET_SEGMENT (symbolP
, bss_section
);
385 S_CLEAR_EXTERNAL (symbolP
);
386 subseg_set (old_sec
, old_subsec
);
392 S_SET_VALUE (symbolP
, (valueT
) size
);
393 S_SET_EXTERNAL (symbolP
);
394 /* should be common, but this is how gas does it for now */
395 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
400 input_line_pointer
++;
401 /* @@ Some use the dot, some don't. Can we get some consistency?? */
402 if (*input_line_pointer
== '.')
403 input_line_pointer
++;
404 /* @@ Some say data, some say bss. */
405 if (strncmp (input_line_pointer
, "bss\"", 4)
406 && strncmp (input_line_pointer
, "data\"", 5))
408 while (*--input_line_pointer
!= '"')
410 input_line_pointer
--;
411 goto bad_common_segment
;
413 while (*input_line_pointer
++ != '"')
415 goto allocate_common
;
417 demand_empty_rest_of_line ();
422 p
= input_line_pointer
;
423 while (*p
&& *p
!= '\n')
427 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
429 input_line_pointer
= p
;
430 ignore_rest_of_line ();
440 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
442 input_line_pointer
+= 6;
446 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
448 input_line_pointer
+= 6;
452 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
454 input_line_pointer
+= 7;
458 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
460 input_line_pointer
+= 5;
461 /* We only support 2 segments -- text and data -- for now, so
462 things in the "bss segment" will have to go into data for now.
463 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
464 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
467 as_bad ("Unknown segment type");
468 demand_empty_rest_of_line ();
475 subseg_set (data_section
, 1);
476 demand_empty_rest_of_line ();
484 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
486 ++input_line_pointer
;
488 ++input_line_pointer
;
492 /* start-sanitize-v9 */
495 struct priv_reg_entry
501 struct priv_reg_entry priv_reg_table
[] =
520 {"", -1}, /* end marker */
530 #define MEMBAR_MASKS_SIZE 7
532 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
535 {"MemIssue", 8, 0x20},
536 {"Lookaside", 9, 0x10},
537 {"StoreStore", 10, 0x08},
538 {"LoadStore", 9, 0x04},
539 {"StoreLoad", 9, 0x02},
540 {"LoadLoad", 8, 0x01},
545 struct priv_reg_entry
*p
, *q
;
547 return strcmp (q
->name
, p
->name
);
551 /* end-sanitize-v9 */
553 /* This function is called once, at assembler startup time. It should
554 set up all the tables, etc. that the MD part of the assembler will need. */
558 register const char *retval
= NULL
;
560 register unsigned int i
= 0;
562 op_hash
= hash_new ();
564 as_fatal ("Virtual memory exhausted");
566 while (i
< NUMOPCODES
)
568 const char *name
= sparc_opcodes
[i
].name
;
569 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
572 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
573 sparc_opcodes
[i
].name
, retval
);
578 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
580 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
581 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
586 while (i
< NUMOPCODES
587 && !strcmp (sparc_opcodes
[i
].name
, name
));
591 as_fatal ("Broken assembler. No assembly attempted.");
593 for (i
= '0'; i
< '8'; ++i
)
595 for (i
= '0'; i
<= '9'; ++i
)
597 for (i
= 'a'; i
<= 'f'; ++i
)
598 toHex
[i
] = i
+ 10 - 'a';
599 for (i
= 'A'; i
<= 'F'; ++i
)
600 toHex
[i
] = i
+ 10 - 'A';
602 /* start-sanitize-v9 */
605 current_architecture
= v9
;
608 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
609 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
611 /* end-sanitize-v9 */
613 target_big_endian
= 1;
626 /* See if "set" operand is absolute and small; skip sethi if so. */
627 if (special_case
== SPECIAL_CASE_SET
628 && the_insn
.exp
.X_op
== O_constant
)
630 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
631 && the_insn
.exp
.X_add_number
< (1 << 12))
633 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
634 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
635 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
636 special_case
= 0; /* No longer special */
637 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
642 /* put out the opcode */
643 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
645 /* put out the symbol-dependent stuff */
646 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
648 fix_new_exp (frag_now
, /* which frag */
649 (toP
- frag_now
->fr_literal
), /* where */
656 switch (special_case
)
658 case SPECIAL_CASE_SET
:
660 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
661 /* See if "set" operand has no low-order bits; skip OR if so. */
662 if (the_insn
.exp
.X_op
== O_constant
663 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
666 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
667 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
668 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
669 fix_new_exp (frag_now
, /* which frag */
670 (toP
- frag_now
->fr_literal
), /* where */
677 case SPECIAL_CASE_FDIV
:
678 /* According to information leaked from Sun, the "fdiv" instructions
679 on early SPARC machines would produce incorrect results sometimes.
680 The workaround is to add an fmovs of the destination register to
681 itself just after the instruction. This was true on machines
682 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
684 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
686 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
687 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
688 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
695 as_fatal ("failed sanity check.");
703 char *error_message
= "";
707 struct sparc_opcode
*insn
;
709 unsigned long opcode
;
710 unsigned int mask
= 0;
713 long immediate_max
= 0;
715 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
733 as_bad ("Unknown opcode: `%s'", str
);
736 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
738 as_bad ("Unknown opcode: `%s'", str
);
748 opcode
= insn
->match
;
749 memset (&the_insn
, '\0', sizeof (the_insn
));
750 the_insn
.reloc
= BFD_RELOC_NONE
;
753 * Build the opcode, checking as we go to make
754 * sure that the operands match
756 for (args
= insn
->args
;; ++args
)
761 /* start-sanitize-v9 */
768 /* Parse a series of masks. */
774 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
775 if (!strncmp (s
, membar_masks
[i
].name
,
776 membar_masks
[i
].len
))
778 if (i
< MEMBAR_MASKS_SIZE
)
780 kmask
|= membar_masks
[i
].mask
;
781 s
+= membar_masks
[i
].len
;
785 error_message
= ": invalid membar mask name";
792 else if (isdigit (*s
))
796 if (expression (&exp
) != absolute_section
797 || exp
.X_op
!= O_constant
798 || (kmask
= exp
.X_add_number
) < 0
801 error_message
= ": invalid membar mask number";
807 error_message
= ": unrecognizable membar mask";
810 opcode
|= SIMM13 (kmask
);
816 int prefetch_fcn
= 0;
818 /* Parse a prefetch function. */
822 if (!strncmp (s
, "n_reads", 7))
823 prefetch_fcn
= 0, s
+= 7;
824 else if (!strncmp (s
, "one_read", 8))
825 prefetch_fcn
= 1, s
+= 8;
826 else if (!strncmp (s
, "n_writes", 8))
827 prefetch_fcn
= 2, s
+= 8;
828 else if (!strncmp (s
, "one_write", 9))
829 prefetch_fcn
= 3, s
+= 9;
830 else if (!strncmp (s
, "page", 4))
831 prefetch_fcn
= 4, s
+= 4;
834 error_message
= ": invalid prefetch function name";
838 else if (isdigit (*s
))
842 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
846 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
848 error_message
= ": invalid prefetch function number";
854 error_message
= ": unrecognizable prefetch function";
857 opcode
|= RD (prefetch_fcn
);
863 /* Parse a privileged register. */
866 struct priv_reg_entry
*p
= priv_reg_table
;
867 unsigned int len
= 9999999; /* init to make gcc happy */
870 while (p
->name
[0] > s
[0])
872 while (p
->name
[0] == s
[0])
874 len
= strlen (p
->name
);
875 if (strncmp (p
->name
, s
, len
) == 0)
879 if (p
->name
[0] != s
[0])
881 error_message
= ": unrecognizable privileged register";
885 opcode
|= (p
->regnum
<< 14);
887 opcode
|= (p
->regnum
<< 25);
893 error_message
= ": unrecognizable privileged register";
897 /* end-sanitize-v9 */
901 if (strncmp (s
, "%asr", 4) == 0)
911 num
= num
* 10 + *s
- '0';
915 if (num
< 16 || 31 < num
)
917 error_message
= ": asr number must be between 15 and 31";
921 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
926 error_message
= ": expecting %asrN";
928 } /* if %asr followed by a number. */
933 /* start-sanitize-v9 */
936 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
937 immediate_max
= 0x03FF;
941 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
942 immediate_max
= 0x01FF;
946 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
951 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
956 if (*s
== 'p' && s
[1] == 'n')
964 if (*s
== 'p' && s
[1] == 't')
976 if (strncmp (s
, "%icc", 4) == 0)
988 if (strncmp (s
, "%xcc", 4) == 0)
1000 if (strncmp (s
, "%fcc0", 5) == 0)
1012 if (strncmp (s
, "%fcc1", 5) == 0)
1024 if (strncmp (s
, "%fcc2", 5) == 0)
1036 if (strncmp (s
, "%fcc3", 5) == 0)
1044 if (strncmp (s
, "%pc", 3) == 0)
1052 if (strncmp (s
, "%tick", 5) == 0)
1059 /* end-sanitize-v9 */
1061 case '\0': /* end of args */
1080 case '[': /* these must match exactly */
1088 case '#': /* must be at least one digit */
1091 while (isdigit (*s
))
1099 case 'C': /* coprocessor state register */
1100 if (strncmp (s
, "%csr", 4) == 0)
1107 case 'b': /* next operand is a coprocessor register */
1110 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1115 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1129 opcode
|= mask
<< 14;
1137 opcode
|= mask
<< 25;
1143 case 'r': /* next operand must be a register */
1152 case 'f': /* frame pointer */
1160 case 'g': /* global register */
1161 if (isoctal (c
= *s
++))
1168 case 'i': /* in register */
1169 if (isoctal (c
= *s
++))
1171 mask
= c
- '0' + 24;
1176 case 'l': /* local register */
1177 if (isoctal (c
= *s
++))
1179 mask
= (c
- '0' + 16);
1184 case 'o': /* out register */
1185 if (isoctal (c
= *s
++))
1187 mask
= (c
- '0' + 8);
1192 case 's': /* stack pointer */
1200 case 'r': /* any register */
1201 if (!isdigit (c
= *s
++))
1218 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1234 * Got the register, now figure out where
1235 * it goes in the opcode.
1241 opcode
|= mask
<< 14;
1249 opcode
|= mask
<< 25;
1253 opcode
|= (mask
<< 25) | (mask
<< 14);
1259 case 'e': /* next operand is a floating point register */
1274 && ((format
= *s
) == 'f')
1277 for (mask
= 0; isdigit (*s
); ++s
)
1279 mask
= 10 * mask
+ (*s
- '0');
1280 } /* read the number */
1288 } /* register must be even numbered */
1296 } /* register must be multiple of 4 */
1298 /* start-sanitize-v9 */
1302 error_message
= ": There are only 64 f registers; [0-63]";
1308 } /* wrap high bit */
1310 /* end-sanitize-v9 */
1313 error_message
= ": There are only 32 f registers; [0-31]";
1316 /* start-sanitize-v9 */
1318 /* end-sanitize-v9 */
1323 } /* if not an 'f' register. */
1331 opcode
|= RS1 (mask
);
1338 opcode
|= RS2 (mask
);
1344 opcode
|= RD (mask
);
1353 if (strncmp (s
, "%fsr", 4) == 0)
1360 case 'h': /* high 22 bits */
1361 the_insn
.reloc
= BFD_RELOC_HI22
;
1364 case 'l': /* 22 bit PC relative immediate */
1365 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1369 case 'L': /* 30 bit immediate */
1370 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1374 case 'n': /* 22 bit immediate */
1375 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1378 case 'i': /* 13 bit immediate */
1379 /* What's the difference between base13 and 13? */
1380 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1381 immediate_max
= 0x0FFF;
1390 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1392 the_insn
.reloc
= BFD_RELOC_HI22
;
1395 else if (c
== 'l' && s
[2] == 'o')
1397 the_insn
.reloc
= BFD_RELOC_LO10
;
1400 /* start-sanitize-v9 */
1406 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1413 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1417 /* end-sanitize-v9 */
1421 /* Note that if the getExpression() fails, we will still
1422 have created U entries in the symbol table for the
1423 'symbols' in the input string. Try not to create U
1424 symbols for registers, etc. */
1426 /* This stuff checks to see if the expression ends in
1427 +%reg. If it does, it removes the register from
1428 the expression, and re-sets 's' to point to the
1433 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1435 if (s1
!= s
&& isdigit (s1
[-1]))
1437 if (s1
[-2] == '%' && s1
[-3] == '+')
1441 (void) getExpression (s
);
1446 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1450 (void) getExpression (s
);
1457 (void) getExpression (s
);
1460 if (the_insn
.exp
.X_op
== O_constant
1461 && the_insn
.exp
.X_add_symbol
== 0
1462 && the_insn
.exp
.X_op_symbol
== 0)
1464 /* start-sanitize-v9 */
1466 switch (the_insn
.reloc
)
1468 case BFD_RELOC_SPARC_HH22
:
1469 the_insn
.reloc
= BFD_RELOC_HI22
;
1470 the_insn
.exp
.X_add_number
>>= 32;
1472 case BFD_RELOC_SPARC_HM10
:
1473 the_insn
.reloc
= BFD_RELOC_LO10
;
1474 the_insn
.exp
.X_add_number
>>= 32;
1478 /* end-sanitize-v9 */
1479 /* Check for invalid constant values. Don't warn if
1480 constant was inside %hi or %lo, since these
1481 truncate the constant to fit. */
1482 if (immediate_max
!= 0
1483 && the_insn
.reloc
!= BFD_RELOC_LO10
1484 && the_insn
.reloc
!= BFD_RELOC_HI22
1485 && (the_insn
.exp
.X_add_number
> immediate_max
1486 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1487 as_bad ("constant value must be between %ld and %ld",
1488 ~immediate_max
, immediate_max
);
1491 /* Reset to prevent extraneous range check. */
1506 /* start-sanitize-v9 */
1508 /* end-sanitize-v9 */
1509 char *push
= input_line_pointer
;
1512 input_line_pointer
= s
;
1515 if (e
.X_op
== O_constant
)
1517 opcode
|= e
.X_add_number
<< 5;
1518 s
= input_line_pointer
;
1519 input_line_pointer
= push
;
1524 /* start-sanitize-v9 */
1532 if (!strncmp (s
, "ASI_AIUP", 8))
1534 else if (!strncmp (s
, "ASI_AIUS", 8))
1536 else if (!strncmp (s
, "ASI_PNF", 7))
1538 else if (!strncmp (s
, "ASI_SNF", 7))
1540 else if (!strncmp (s
, "ASI_P", 5))
1542 else if (!strncmp (s
, "ASI_S", 5))
1546 error_message
= ": invalid asi name";
1550 else if (isdigit (*s
))
1552 char *push
= input_line_pointer
;
1553 input_line_pointer
= s
;
1554 asi
= get_absolute_expression ();
1555 s
= input_line_pointer
;
1556 input_line_pointer
= push
;
1558 if (asi
< 0 || asi
> 255)
1560 error_message
= ": invalid asi number";
1566 error_message
= ": unrecognizable asi";
1569 opcode
|= ASI (asi
);
1572 /* end-sanitize-v9 */
1573 } /* alternate space */
1576 if (strncmp (s
, "%psr", 4) == 0)
1583 case 'q': /* floating point queue */
1584 if (strncmp (s
, "%fq", 3) == 0)
1591 case 'Q': /* coprocessor queue */
1592 if (strncmp (s
, "%cq", 3) == 0)
1600 if (strcmp (str
, "set") == 0)
1602 special_case
= SPECIAL_CASE_SET
;
1605 else if (strncmp (str
, "fdiv", 4) == 0)
1607 special_case
= SPECIAL_CASE_FDIV
;
1612 /* start-sanitize-v9 */
1615 if (strncmp (s
, "%asi", 4) != 0)
1621 if (strncmp (s
, "%fprs", 5) != 0)
1627 if (strncmp (s
, "%ccr", 4) != 0)
1632 /* end-sanitize-v9 */
1635 if (strncmp (s
, "%tbr", 4) != 0)
1641 if (strncmp (s
, "%wim", 4) != 0)
1647 if (strncmp (s
, "%y", 2) != 0)
1653 as_fatal ("failed sanity check.");
1654 } /* switch on arg code */
1656 } /* for each arg that we expect */
1660 /* Args don't match. */
1661 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1662 && !strcmp (insn
->name
, insn
[1].name
))
1670 as_bad ("Illegal operands%s", error_message
);
1676 if (insn
->architecture
> current_architecture
)
1678 if ((!architecture_requested
|| warn_on_bump
)
1680 /* start-sanitize-v9 */
1682 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1685 /* end-sanitize-v9 */
1687 /* start-sanitize-v9 */
1689 /* end-sanitize-v9 */
1694 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1695 architecture_pname
[current_architecture
],
1696 architecture_pname
[insn
->architecture
],
1700 current_architecture
= insn
->architecture
;
1704 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1706 architecture_pname
[insn
->architecture
],
1707 architecture_pname
[current_architecture
]);
1709 } /* if bump ok else error */
1710 } /* if architecture higher */
1714 } /* forever looking for a match */
1716 the_insn
.opcode
= opcode
;
1727 save_in
= input_line_pointer
;
1728 input_line_pointer
= str
;
1729 seg
= expression (&the_insn
.exp
);
1730 if (seg
!= absolute_section
1731 && seg
!= text_section
1732 && seg
!= data_section
1733 && seg
!= bss_section
1734 && seg
!= undefined_section
)
1736 the_insn
.error
= "bad segment";
1737 expr_end
= input_line_pointer
;
1738 input_line_pointer
= save_in
;
1741 expr_end
= input_line_pointer
;
1742 input_line_pointer
= save_in
;
1744 } /* getExpression() */
1748 This is identical to the md_atof in m68k.c. I think this is right,
1751 Turn a string in input_line_pointer into a floating point constant of type
1752 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1753 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1756 /* Equal to MAX_PRECISION in atof-ieee.c */
1757 #define MAX_LITTLENUMS 6
1760 md_atof (type
, litP
, sizeP
)
1766 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1767 LITTLENUM_TYPE
*wordP
;
1800 return "Bad call to MD_ATOF()";
1802 t
= atof_ieee (input_line_pointer
, type
, words
);
1804 input_line_pointer
= t
;
1805 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1806 for (wordP
= words
; prec
--;)
1808 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1809 litP
+= sizeof (LITTLENUM_TYPE
);
1815 * Write out big-endian.
1818 md_number_to_chars (buf
, val
, n
)
1826 /* start-sanitize-v9 */
1832 /* end-sanitize-v9 */
1843 as_fatal ("failed sanity check.");
1846 } /* md_number_to_chars() */
1848 /* Apply a fixS to the frags, now that we know the value it ought to
1852 md_apply_fix (fixP
, value
)
1856 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1861 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1863 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1866 /* FIXME: SPARC ELF relocations don't use an addend in the data
1867 field itself. This whole approach should be somehow combined
1868 with the calls to bfd_perform_relocation. */
1869 if (fixP
->fx_addsy
!= NULL
)
1874 * This is a hack. There should be a better way to
1877 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1879 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1882 switch (fixP
->fx_r_type
)
1897 case BFD_RELOC_32_PCREL_S2
:
1898 val
= (val
>>= 2) + 1;
1899 buf
[0] |= (val
>> 24) & 0x3f;
1900 buf
[1] = (val
>> 16);
1905 /* start-sanitize-v9 */
1918 case BFD_RELOC_SPARC_11
:
1919 if (((val
> 0) && (val
& ~0x7ff))
1920 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1922 as_bad ("relocation overflow.");
1925 buf
[2] |= (val
>> 8) & 0x7;
1926 buf
[3] = val
& 0xff;
1929 case BFD_RELOC_SPARC_10
:
1930 if (((val
> 0) && (val
& ~0x3ff))
1931 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1933 as_bad ("relocation overflow.");
1936 buf
[2] |= (val
>> 8) & 0x3;
1937 buf
[3] = val
& 0xff;
1940 case BFD_RELOC_SPARC_WDISP16
:
1941 if (((val
> 0) && (val
& ~0x3fffc))
1942 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1944 as_bad ("relocation overflow.");
1947 val
= (val
>>= 2) + 1;
1948 buf
[1] |= ((val
>> 14) & 0x3) << 4;
1949 buf
[2] |= (val
>> 8) & 0x3f;
1950 buf
[3] = val
& 0xff;
1953 case BFD_RELOC_SPARC_WDISP19
:
1954 if (((val
> 0) && (val
& ~0x1ffffc))
1955 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
1957 as_bad ("relocation overflow.");
1960 val
= (val
>>= 2) + 1;
1961 buf
[1] |= (val
>> 16) & 0x7;
1962 buf
[2] = (val
>> 8) & 0xff;
1963 buf
[3] = val
& 0xff;
1966 case BFD_RELOC_SPARC_HH22
:
1968 /* intentional fallthrough */
1970 /* end-sanitize-v9 */
1972 /* start-sanitize-v9 */
1974 case BFD_RELOC_SPARC_LM22
:
1976 /* end-sanitize-v9 */
1977 case BFD_RELOC_HI22
:
1978 if (!fixP
->fx_addsy
)
1980 buf
[1] |= (val
>> 26) & 0x3f;
1991 case BFD_RELOC_SPARC22
:
1992 if (val
& ~0x003fffff)
1994 as_bad ("relocation overflow");
1996 buf
[1] |= (val
>> 16) & 0x3f;
1998 buf
[3] = val
& 0xff;
2001 case BFD_RELOC_SPARC13
:
2002 if (val
& ~0x00001fff)
2004 as_bad ("relocation overflow");
2006 buf
[2] |= (val
>> 8) & 0x1f;
2007 buf
[3] = val
& 0xff;
2010 /* start-sanitize-v9 */
2012 case BFD_RELOC_SPARC_HM10
:
2014 /* intentional fallthrough */
2016 /* end-sanitize-v9 */
2018 case BFD_RELOC_LO10
:
2019 if (!fixP
->fx_addsy
)
2021 buf
[2] |= (val
>> 8) & 0x03;
2027 case BFD_RELOC_SPARC_BASE13
:
2028 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2029 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2031 as_bad ("relocation overflow");
2033 buf
[2] |= (val
>> 8) & 0x1f;
2037 case BFD_RELOC_SPARC_WDISP22
:
2038 val
= (val
>>= 2) + 1;
2040 case BFD_RELOC_SPARC_BASE22
:
2041 buf
[1] |= (val
>> 16) & 0x3f;
2046 case BFD_RELOC_NONE
:
2048 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2055 /* should never be called for sparc */
2057 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2064 as_fatal ("sparc_create_short_jmp\n");
2067 /* Translate internal representation of relocation info to BFD target
2070 tc_gen_reloc (section
, fixp
)
2075 bfd_reloc_code_real_type code
;
2077 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2078 assert (reloc
!= 0);
2080 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2081 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2083 if (fixp
->fx_pcrel
== 0)
2084 reloc
->addend
+= fixp
->fx_addnumber
;
2087 reloc
->addend
+= fixp
->fx_offset
;
2088 switch (OUTPUT_FLAVOR
)
2090 case bfd_target_elf_flavour
:
2092 case bfd_target_aout_flavour
:
2093 reloc
->addend
-= reloc
->address
;
2096 /* What's a good default here? Is there any?? */
2101 switch (fixp
->fx_r_type
)
2105 case BFD_RELOC_HI22
:
2106 case BFD_RELOC_LO10
:
2107 case BFD_RELOC_32_PCREL_S2
:
2108 case BFD_RELOC_SPARC_BASE13
:
2109 case BFD_RELOC_SPARC_WDISP22
:
2110 /* start-sanitize-v9 */
2112 case BFD_RELOC_SPARC_10
:
2113 case BFD_RELOC_SPARC_11
:
2114 case BFD_RELOC_SPARC_HH22
:
2115 case BFD_RELOC_SPARC_HM10
:
2116 case BFD_RELOC_SPARC_LM22
:
2117 case BFD_RELOC_SPARC_PC_HH22
:
2118 case BFD_RELOC_SPARC_PC_HM10
:
2119 case BFD_RELOC_SPARC_PC_LM22
:
2120 /* end-sanitize-v9 */
2121 code
= fixp
->fx_r_type
;
2126 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2127 assert (reloc
->howto
!= 0);
2132 /* should never be called for sparc */
2134 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2136 addressT from_addr
, to_addr
;
2140 as_fatal ("sparc_create_long_jump\n");
2141 } /* md_create_long_jump() */
2143 /* should never be called for sparc */
2145 md_estimate_size_before_relax (fragP
, segtype
)
2149 as_fatal ("sparc_estimate_size_before_relax\n");
2151 } /* md_estimate_size_before_relax() */
2154 /* for debugging only */
2157 struct sparc_it
*insn
;
2190 fprintf (stderr
, "ERROR: %s\n");
2192 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2193 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2194 fprintf (stderr
, "exp = {\n");
2195 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2196 ((insn
->exp
.X_add_symbol
!= NULL
)
2197 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2198 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2201 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2202 ((insn
->exp
.X_op_symbol
!= NULL
)
2203 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2204 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2207 fprintf (stderr
, "\t\tX_add_number = %d\n",
2208 insn
->exp
.X_add_number
);
2209 fprintf (stderr
, "}\n");
2211 } /* print_insn() */
2217 * Invocation line includes a switch not recognized by the base assembler.
2218 * See if it's a processor-specific option. These are:
2221 * Warn on architecture bumps. See also -A.
2223 * -Av6, -Av7, -Av8, -Asparclite
2224 * Select the architecture. Instructions or features not
2225 * supported by the selected architecture cause fatal errors.
2227 * The default is to start at v6, and bump the architecture up
2228 * whenever an instruction is seen at a higher level.
2230 * If -bump is specified, a warning is printing when bumping to
2233 * If an architecture is specified, all instructions must match
2234 * that architecture. Any higher level instructions are flagged
2237 * if both an architecture and -bump are specified, the
2238 * architecture starts at the specified level, but bumps are
2243 * Another architecture switch.
2246 * Bumping between incompatible architectures is always an
2247 * error. For example, from sparclite to v9.
2252 md_parse_option (argP
, cntP
, vecP
)
2260 if (!strcmp (*argP
, "bump"))
2265 else if (**argP
== 'A')
2269 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2271 if (strcmp (p
, *arch
) == 0)
2274 } /* found a match */
2275 } /* walk the pname table */
2279 as_bad ("unknown architecture: %s", p
);
2283 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2284 architecture_requested
= 1;
2288 else if (**argP
== 'V')
2290 print_version_id ();
2292 else if (**argP
== 'Q')
2294 /* Qy - do emit .comment
2295 Qn - do not emit .comment */
2297 else if (**argP
== 's')
2299 /* use .stab instead of .stab.excl */
2302 else if (strcmp (*argP
, "sparc") == 0)
2304 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2308 /* Unknown option */
2312 **argP
= '\0'; /* Done parsing this switch */
2314 } /* md_parse_option() */
2316 /* We have no need to default values of symbols. */
2320 md_undefined_symbol (name
)
2324 } /* md_undefined_symbol() */
2326 /* Parse an operand that is machine-specific.
2327 We just return without modifying the expression if we have nothing
2332 md_operand (expressionP
)
2333 expressionS
*expressionP
;
2337 /* Round up a section size to the appropriate boundary. */
2339 md_section_align (segment
, size
)
2344 /* Round all sects to multiple of 8 */
2345 size
= (size
+ 7) & (valueT
) ~7;
2350 /* Exactly what point is a PC-relative offset relative TO?
2351 On the sparc, they're relative to the address of the offset, plus
2352 its size. This gets us to the following instruction.
2353 (??? Is this right? FIXME-SOON) */
2355 md_pcrel_from (fixP
)
2358 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2361 /* end of tc-sparc.c */