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 /* Ugly hack to keep non-BFD version working. */
51 #define BFD_RELOC_NONE NO_RELOC
52 #define BFD_RELOC_32 RELOC_32
53 #define BFD_RELOC_HI22 RELOC_HI22
54 #define BFD_RELOC_LO10 RELOC_LO10
55 #define BFD_RELOC_SPARC_WDISP22 RELOC_WDISP22
56 #define BFD_RELOC_32_PCREL_S2 RELOC_WDISP30
57 #define BFD_RELOC_SPARC22 RELOC_22
58 #define BFD_RELOC_SPARC_BASE13 RELOC_BASE13
59 #define BFD_RELOC_SPARC13 RELOC_13
60 #define BFD_RELOC_SPARC_BASE22 RELOC_BASE22
63 const pseudo_typeS md_pseudo_table
[] =
65 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
66 {"common", s_common
, 0},
67 {"global", s_globl
, 0},
69 {"optim", s_ignore
, 0},
71 {"reserve", s_reserve
, 0},
75 /* start-sanitize-v9 */
84 /* these are specific to sparc/svr4 */
85 {"pushsection", obj_elf_section
, 0},
86 {"popsection", obj_elf_previous
, 0},
93 const int md_short_jump_size
= 4;
94 const int md_long_jump_size
= 4;
95 const int md_reloc_size
= 12; /* Size of relocation record */
97 /* This array holds the chars that always start a comment. If the
98 pre-processor is disabled, these aren't very useful */
99 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
101 /* This array holds the chars that only start a comment at the beginning of
102 a line. If the line seems to have the form '# 123 filename'
103 .line and .file directives will appear in the pre-processed output */
104 /* Note that input_file.c hand checks for '#' at the beginning of the
105 first line of the input file. This is because the compiler outputs
106 #NO_APP at the beginning of its output. */
107 /* Also note that comments started like this one will always
108 work if '/' isn't otherwise defined. */
109 const char line_comment_chars
[] = "#";
111 const char line_separator_chars
[] = "";
113 /* Chars that can be used to separate mant from exp in floating point nums */
114 const char EXP_CHARS
[] = "eE";
116 /* Chars that mean this number is a floating point constant */
119 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
121 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
122 changed in read.c . Ideally it shouldn't have to know about it at all,
123 but nothing is ideal around here.
126 static unsigned char octal
[256];
127 #define isoctal(c) octal[(unsigned char) (c)]
128 static unsigned char toHex
[256];
133 unsigned long opcode
;
134 struct nlist
*nlistp
;
138 bfd_reloc_code_real_type reloc
;
140 enum reloc_type reloc
;
144 struct sparc_it the_insn
, set_insn
;
147 static void print_insn
PARAMS ((struct sparc_it
*insn
));
149 static int getExpression
PARAMS ((char *str
));
151 static char *expr_end
;
152 static int special_case
;
155 * Instructions that require wierd handling because they're longer than
158 #define SPECIAL_CASE_SET 1
159 #define SPECIAL_CASE_FDIV 2
162 * sort of like s_lcomm
166 static int max_alignment
= 15;
181 name
= input_line_pointer
;
182 c
= get_symbol_end ();
183 p
= input_line_pointer
;
187 if (*input_line_pointer
!= ',')
189 as_bad ("Expected comma after name");
190 ignore_rest_of_line ();
194 ++input_line_pointer
;
196 if ((size
= get_absolute_expression ()) < 0)
198 as_bad ("BSS length (%d.) <0! Ignored.", size
);
199 ignore_rest_of_line ();
204 symbolP
= symbol_find_or_make (name
);
207 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
208 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
210 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
214 if (input_line_pointer
[2] == '.')
215 input_line_pointer
+= 7;
217 input_line_pointer
+= 6;
220 if (*input_line_pointer
== ',')
222 ++input_line_pointer
;
225 if (*input_line_pointer
== '\n')
227 as_bad ("Missing alignment");
231 align
= get_absolute_expression ();
233 if (align
> max_alignment
)
235 align
= max_alignment
;
236 as_warn ("Alignment too large: %d. assumed.", align
);
242 as_warn ("Alignment negative. 0 assumed.");
245 record_alignment (bss_section
, align
);
247 /* convert to a power of 2 alignment */
248 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
252 as_bad ("Alignment not a power of 2");
253 ignore_rest_of_line ();
255 } /* not a power of two */
258 } /* if has optional alignment */
262 if ((S_GET_SEGMENT (symbolP
) == bss_section
263 || !S_IS_DEFINED (symbolP
))
265 && S_GET_OTHER (symbolP
) == 0
266 && S_GET_DESC (symbolP
) == 0
273 segT current_seg
= now_seg
;
274 subsegT current_subseg
= now_subseg
;
276 subseg_set (bss_section
, 1); /* switch to bss */
279 frag_align (align
, 0); /* do alignment */
281 /* detach from old frag */
282 if (S_GET_SEGMENT(symbolP
) == bss_section
)
283 symbolP
->sy_frag
->fr_symbol
= NULL
;
285 symbolP
->sy_frag
= frag_now
;
286 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
290 S_SET_SEGMENT (symbolP
, bss_section
);
292 subseg_set (current_seg
, current_subseg
);
297 as_warn("Ignoring attempt to re-define symbol %s.", name
);
298 } /* if not redefining */
300 demand_empty_rest_of_line ();
313 name
= input_line_pointer
;
314 c
= get_symbol_end ();
315 /* just after name is now '\0' */
316 p
= input_line_pointer
;
319 if (*input_line_pointer
!= ',')
321 as_bad ("Expected comma after symbol-name");
322 ignore_rest_of_line ();
325 input_line_pointer
++; /* skip ',' */
326 if ((temp
= get_absolute_expression ()) < 0)
328 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
329 ignore_rest_of_line ();
334 symbolP
= symbol_find_or_make (name
);
336 if (S_IS_DEFINED (symbolP
))
338 as_bad ("Ignoring attempt to re-define symbol");
339 ignore_rest_of_line ();
342 if (S_GET_VALUE (symbolP
) != 0)
344 if (S_GET_VALUE (symbolP
) != size
)
346 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
347 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
353 S_SET_VALUE (symbolP
, (valueT
) size
);
354 S_SET_EXTERNAL (symbolP
);
357 know (symbolP
->sy_frag
== &zero_address_frag
);
358 if (*input_line_pointer
!= ',')
360 as_bad ("Expected comma after common length");
361 ignore_rest_of_line ();
364 input_line_pointer
++;
366 if (*input_line_pointer
!= '"')
368 temp
= get_absolute_expression ();
370 if (temp
> max_alignment
)
372 temp
= max_alignment
;
373 as_warn ("Common alignment too large: %d. assumed", temp
);
379 as_warn ("Common alignment negative; 0 assumed");
391 old_subsec
= now_subseg
;
393 record_alignment (bss_section
, align
);
394 subseg_set (bss_section
, 0);
396 frag_align (align
, 0);
397 if (S_GET_SEGMENT (symbolP
) == bss_section
)
398 symbolP
->sy_frag
->fr_symbol
= 0;
399 symbolP
->sy_frag
= frag_now
;
400 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
403 S_SET_SEGMENT (symbolP
, bss_section
);
404 S_CLEAR_EXTERNAL (symbolP
);
405 subseg_set (old_sec
, old_subsec
);
411 S_SET_VALUE (symbolP
, (valueT
) size
);
412 S_SET_EXTERNAL (symbolP
);
413 /* should be common, but this is how gas does it for now */
414 S_SET_SEGMENT (symbolP
, &bfd_und_section
);
419 input_line_pointer
++;
420 /* @@ Some use the dot, some don't. Can we get some consistency?? */
421 if (*input_line_pointer
== '.')
422 input_line_pointer
++;
423 /* @@ Some say data, some say bss. */
424 if (strncmp (input_line_pointer
, "bss\"", 4)
425 && strncmp (input_line_pointer
, "data\"", 5))
427 while (*--input_line_pointer
!= '"')
429 input_line_pointer
--;
430 goto bad_common_segment
;
432 while (*input_line_pointer
++ != '"')
434 goto allocate_common
;
436 demand_empty_rest_of_line ();
441 p
= input_line_pointer
;
442 while (*p
&& *p
!= '\n')
446 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
448 input_line_pointer
= p
;
449 ignore_rest_of_line ();
459 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
461 input_line_pointer
+= 6;
465 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
467 input_line_pointer
+= 6;
471 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
473 input_line_pointer
+= 7;
477 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
479 input_line_pointer
+= 5;
480 /* We only support 2 segments -- text and data -- for now, so
481 things in the "bss segment" will have to go into data for now.
482 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
483 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
486 as_bad ("Unknown segment type");
487 demand_empty_rest_of_line ();
494 subseg_set (data_section
, 1);
495 demand_empty_rest_of_line ();
503 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
505 ++input_line_pointer
;
507 ++input_line_pointer
;
511 /* start-sanitize-v9 */
514 struct priv_reg_entry
520 struct priv_reg_entry priv_reg_table
[] =
539 {"", -1}, /* end marker */
549 #define MEMBAR_MASKS_SIZE 7
551 struct membar_masks membar_masks
[MEMBAR_MASKS_SIZE
] =
554 {"MemIssue", 8, 0x20},
555 {"Lookaside", 9, 0x10},
556 {"StoreStore", 10, 0x08},
557 {"LoadStore", 9, 0x04},
558 {"StoreLoad", 9, 0x02},
559 {"LoadLoad", 8, 0x01},
564 struct priv_reg_entry
*p
, *q
;
566 return strcmp (q
->name
, p
->name
);
570 /* end-sanitize-v9 */
572 /* This function is called once, at assembler startup time. It should
573 set up all the tables, etc. that the MD part of the assembler will need. */
577 register const char *retval
= NULL
;
579 register unsigned int i
= 0;
581 op_hash
= hash_new ();
583 as_fatal ("Virtual memory exhausted");
585 while (i
< NUMOPCODES
)
587 const char *name
= sparc_opcodes
[i
].name
;
588 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
591 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
592 sparc_opcodes
[i
].name
, retval
);
597 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
599 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
600 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
605 while (i
< NUMOPCODES
606 && !strcmp (sparc_opcodes
[i
].name
, name
));
610 as_fatal ("Broken assembler. No assembly attempted.");
612 for (i
= '0'; i
< '8'; ++i
)
614 for (i
= '0'; i
<= '9'; ++i
)
616 for (i
= 'a'; i
<= 'f'; ++i
)
617 toHex
[i
] = i
+ 10 - 'a';
618 for (i
= 'A'; i
<= 'F'; ++i
)
619 toHex
[i
] = i
+ 10 - 'A';
621 /* start-sanitize-v9 */
624 current_architecture
= v9
;
627 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
628 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
630 /* end-sanitize-v9 */
632 target_big_endian
= 1;
651 /* See if "set" operand is absolute and small; skip sethi if so. */
652 if (special_case
== SPECIAL_CASE_SET
653 && the_insn
.exp
.X_op
== O_constant
)
655 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
656 && the_insn
.exp
.X_add_number
< (1 << 12))
658 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
659 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
660 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
661 special_case
= 0; /* No longer special */
662 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
667 /* put out the opcode */
668 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
670 /* put out the symbol-dependent stuff */
671 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
673 fix_new_exp (frag_now
, /* which frag */
674 (toP
- frag_now
->fr_literal
), /* where */
681 switch (special_case
)
683 case SPECIAL_CASE_SET
:
685 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
686 /* See if "set" operand has no low-order bits; skip OR if so. */
687 if (the_insn
.exp
.X_op
== O_constant
688 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
691 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
692 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
693 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
694 fix_new_exp (frag_now
, /* which frag */
695 (toP
- frag_now
->fr_literal
), /* where */
702 case SPECIAL_CASE_FDIV
:
703 /* According to information leaked from Sun, the "fdiv" instructions
704 on early SPARC machines would produce incorrect results sometimes.
705 The workaround is to add an fmovs of the destination register to
706 itself just after the instruction. This was true on machines
707 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
709 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
711 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
712 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
713 md_number_to_chars (toP
, (valueT
) the_insn
.opcode
, 4);
720 as_fatal ("failed sanity check.");
722 } /* md_assemble() */
728 char *error_message
= "";
732 struct sparc_opcode
*insn
;
734 unsigned long opcode
;
735 unsigned int mask
= 0;
738 long immediate_max
= 0;
740 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
758 as_bad ("Unknown opcode: `%s'", str
);
761 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
763 as_bad ("Unknown opcode: `%s'", str
);
773 opcode
= insn
->match
;
774 memset (&the_insn
, '\0', sizeof (the_insn
));
775 the_insn
.reloc
= BFD_RELOC_NONE
;
778 * Build the opcode, checking as we go to make
779 * sure that the operands match
781 for (args
= insn
->args
;; ++args
)
786 /* start-sanitize-v9 */
793 /* Parse a series of masks. */
799 for (i
= 0; i
< MEMBAR_MASKS_SIZE
; i
++)
800 if (!strncmp (s
, membar_masks
[i
].name
,
801 membar_masks
[i
].len
))
803 if (i
< MEMBAR_MASKS_SIZE
)
805 kmask
|= membar_masks
[i
].mask
;
806 s
+= membar_masks
[i
].len
;
810 error_message
= ": invalid membar mask name";
817 else if (isdigit (*s
))
821 kmask
= kmask
* 10 + *s
- '0';
825 if (kmask
< 0 || kmask
> 127)
827 error_message
= ": invalid membar mask number";
833 error_message
= ": unrecognizable membar mask";
836 opcode
|= SIMM13 (kmask
);
842 int prefetch_fcn
= 0;
844 /* Parse a prefetch function. */
848 if (!strncmp (s
, "n_reads", 7))
849 prefetch_fcn
= 0, s
+= 7;
850 else if (!strncmp (s
, "one_read", 8))
851 prefetch_fcn
= 1, s
+= 8;
852 else if (!strncmp (s
, "n_writes", 8))
853 prefetch_fcn
= 2, s
+= 8;
854 else if (!strncmp (s
, "one_write", 9))
855 prefetch_fcn
= 3, s
+= 9;
856 else if (!strncmp (s
, "page", 4))
857 prefetch_fcn
= 4, s
+= 4;
860 error_message
= ": invalid prefetch function name";
864 else if (isdigit (*s
))
868 prefetch_fcn
= prefetch_fcn
* 10 + *s
- '0';
872 if (prefetch_fcn
< 0 || prefetch_fcn
> 31)
874 error_message
= ": invalid prefetch function number";
880 error_message
= ": unrecognizable prefetch function";
883 opcode
|= RD (prefetch_fcn
);
889 /* Parse a privileged register. */
892 struct priv_reg_entry
*p
= priv_reg_table
;
893 unsigned int len
= 9999999; /* init to make gcc happy */
896 while (p
->name
[0] > s
[0])
898 while (p
->name
[0] == s
[0])
900 len
= strlen (p
->name
);
901 if (strncmp (p
->name
, s
, len
) == 0)
905 if (p
->name
[0] != s
[0])
907 error_message
= ": unrecognizable privileged register";
911 opcode
|= (p
->regnum
<< 14);
913 opcode
|= (p
->regnum
<< 25);
919 error_message
= ": unrecognizable privileged register";
923 /* end-sanitize-v9 */
927 if (strncmp (s
, "%asr", 4) == 0)
937 num
= num
* 10 + *s
- '0';
941 if (num
< 16 || 31 < num
)
943 error_message
= ": asr number must be between 15 and 31";
947 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
952 error_message
= ": expecting %asrN";
954 } /* if %asr followed by a number. */
959 /* start-sanitize-v9 */
962 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
963 immediate_max
= 0x03FF;
967 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
968 immediate_max
= 0x01FF;
972 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
977 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
982 if (*s
== 'p' && s
[1] == 'n')
990 if (*s
== 'p' && s
[1] == 't')
1002 if (strncmp (s
, "%icc", 4) == 0)
1014 if (strncmp (s
, "%xcc", 4) == 0)
1026 if (strncmp (s
, "%fcc0", 5) == 0)
1038 if (strncmp (s
, "%fcc1", 5) == 0)
1050 if (strncmp (s
, "%fcc2", 5) == 0)
1062 if (strncmp (s
, "%fcc3", 5) == 0)
1070 if (strncmp (s
, "%pc", 3) == 0)
1078 if (strncmp (s
, "%tick", 5) == 0)
1085 /* end-sanitize-v9 */
1087 case '\0': /* end of args */
1106 case '[': /* these must match exactly */
1114 case '#': /* must be at least one digit */
1117 while (isdigit (*s
))
1125 case 'C': /* coprocessor state register */
1126 if (strncmp (s
, "%csr", 4) == 0)
1133 case 'b': /* next operand is a coprocessor register */
1136 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1141 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1155 opcode
|= mask
<< 14;
1163 opcode
|= mask
<< 25;
1169 case 'r': /* next operand must be a register */
1178 case 'f': /* frame pointer */
1186 case 'g': /* global register */
1187 if (isoctal (c
= *s
++))
1194 case 'i': /* in register */
1195 if (isoctal (c
= *s
++))
1197 mask
= c
- '0' + 24;
1202 case 'l': /* local register */
1203 if (isoctal (c
= *s
++))
1205 mask
= (c
- '0' + 16);
1210 case 'o': /* out register */
1211 if (isoctal (c
= *s
++))
1213 mask
= (c
- '0' + 8);
1218 case 's': /* stack pointer */
1226 case 'r': /* any register */
1227 if (!isdigit (c
= *s
++))
1244 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1260 * Got the register, now figure out where
1261 * it goes in the opcode.
1267 opcode
|= mask
<< 14;
1275 opcode
|= mask
<< 25;
1279 opcode
|= (mask
<< 25) | (mask
<< 14);
1285 case 'e': /* next operand is a floating point register */
1300 && ((format
= *s
) == 'f')
1303 for (mask
= 0; isdigit (*s
); ++s
)
1305 mask
= 10 * mask
+ (*s
- '0');
1306 } /* read the number */
1314 } /* register must be even numbered */
1322 } /* register must be multiple of 4 */
1324 /* start-sanitize-v9 */
1328 error_message
= ": There are only 64 f registers; [0-63]";
1334 } /* wrap high bit */
1336 /* end-sanitize-v9 */
1339 error_message
= ": There are only 32 f registers; [0-31]";
1342 /* start-sanitize-v9 */
1344 /* end-sanitize-v9 */
1349 } /* if not an 'f' register. */
1357 opcode
|= RS1 (mask
);
1364 opcode
|= RS2 (mask
);
1370 opcode
|= RD (mask
);
1379 if (strncmp (s
, "%fsr", 4) == 0)
1386 case 'h': /* high 22 bits */
1387 the_insn
.reloc
= BFD_RELOC_HI22
;
1390 case 'l': /* 22 bit PC relative immediate */
1391 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1395 case 'L': /* 30 bit immediate */
1396 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1400 case 'n': /* 22 bit immediate */
1401 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1404 case 'i': /* 13 bit immediate */
1405 /* What's the difference between base13 and 13? */
1406 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1407 immediate_max
= 0x0FFF;
1416 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1418 the_insn
.reloc
= BFD_RELOC_HI22
;
1421 else if (c
== 'l' && s
[2] == 'o')
1423 the_insn
.reloc
= BFD_RELOC_LO10
;
1425 /* start-sanitize-v9 */
1432 the_insn
.reloc
= BFD_RELOC_SPARC_HH22
;
1439 the_insn
.reloc
= BFD_RELOC_SPARC_HM10
;
1442 /* end-sanitize-v9 */
1447 /* Note that if the getExpression() fails, we
1448 will still have created U entries in the
1449 symbol table for the 'symbols' in the input
1450 string. Try not to create U symbols for
1453 /* This stuff checks to see if the
1454 expression ends in +%reg If it does,
1455 it removes the register from the
1456 expression, and re-sets 's' to point
1457 to the right place */
1461 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1463 if (s1
!= s
&& isdigit (s1
[-1]))
1465 if (s1
[-2] == '%' && s1
[-3] == '+')
1469 (void) getExpression (s
);
1474 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1478 (void) getExpression (s
);
1485 (void) getExpression (s
);
1488 /* Check for invalid constant values. Don't
1489 warn if constant was inside %hi or %lo,
1490 since these truncate the constant to
1492 if (immediate_max
!= 0
1493 && the_insn
.reloc
!= BFD_RELOC_LO10
1494 && the_insn
.reloc
!= BFD_RELOC_HI22
1495 /* start-sanitize-v9 */
1497 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1498 && the_insn
.reloc
!= RELOC_HLO10
1499 && the_insn
.reloc
!= RELOC_HHI22
1502 /* end-sanitize-v9 */
1503 && the_insn
.exp
.X_add_symbol
== 0
1504 && the_insn
.exp
.X_op_symbol
== 0
1505 && the_insn
.exp
.X_op
== O_constant
1506 && (the_insn
.exp
.X_add_number
> immediate_max
1507 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1508 as_bad ("constant value must be between %ld and %ld",
1509 ~immediate_max
, immediate_max
);
1510 /* Reset to prevent extraneous range check. */
1525 /* start-sanitize-v9 */
1527 /* end-sanitize-v9 */
1528 char *push
= input_line_pointer
;
1531 input_line_pointer
= s
;
1534 if (e
.X_op
== O_constant
)
1536 opcode
|= e
.X_add_number
<< 5;
1537 s
= input_line_pointer
;
1538 input_line_pointer
= push
;
1543 /* start-sanitize-v9 */
1551 if (!strncmp (s
, "ASI_AIUP", 8))
1553 else if (!strncmp (s
, "ASI_AIUS", 8))
1555 else if (!strncmp (s
, "ASI_PNF", 7))
1557 else if (!strncmp (s
, "ASI_SNF", 7))
1559 else if (!strncmp (s
, "ASI_P", 5))
1561 else if (!strncmp (s
, "ASI_S", 5))
1565 error_message
= ": invalid asi name";
1569 else if (isdigit (*s
))
1571 char *push
= input_line_pointer
;
1572 input_line_pointer
= s
;
1573 asi
= get_absolute_expression ();
1574 s
= input_line_pointer
;
1575 input_line_pointer
= push
;
1577 if (asi
< 0 || asi
> 255)
1579 error_message
= ": invalid asi number";
1585 error_message
= ": unrecognizable asi";
1588 opcode
|= ASI (asi
);
1591 /* end-sanitize-v9 */
1592 } /* alternate space */
1595 if (strncmp (s
, "%psr", 4) == 0)
1602 case 'q': /* floating point queue */
1603 if (strncmp (s
, "%fq", 3) == 0)
1610 case 'Q': /* coprocessor queue */
1611 if (strncmp (s
, "%cq", 3) == 0)
1619 if (strcmp (str
, "set") == 0)
1621 special_case
= SPECIAL_CASE_SET
;
1624 else if (strncmp (str
, "fdiv", 4) == 0)
1626 special_case
= SPECIAL_CASE_FDIV
;
1631 /* start-sanitize-v9 */
1634 if (strncmp (s
, "%asi", 4) != 0)
1640 if (strncmp (s
, "%fprs", 5) != 0)
1646 if (strncmp (s
, "%ccr", 4) != 0)
1651 /* end-sanitize-v9 */
1654 if (strncmp (s
, "%tbr", 4) != 0)
1660 if (strncmp (s
, "%wim", 4) != 0)
1666 if (strncmp (s
, "%y", 2) != 0)
1672 as_fatal ("failed sanity check.");
1673 } /* switch on arg code */
1675 } /* for each arg that we expect */
1679 /* Args don't match. */
1680 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1681 && !strcmp (insn
->name
, insn
[1].name
))
1689 as_bad ("Illegal operands%s", error_message
);
1695 if (insn
->architecture
> current_architecture
)
1697 if ((!architecture_requested
|| warn_on_bump
)
1699 /* start-sanitize-v9 */
1701 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1704 /* end-sanitize-v9 */
1706 /* start-sanitize-v9 */
1708 /* end-sanitize-v9 */
1713 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1714 architecture_pname
[current_architecture
],
1715 architecture_pname
[insn
->architecture
],
1719 current_architecture
= insn
->architecture
;
1723 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1725 architecture_pname
[insn
->architecture
],
1726 architecture_pname
[current_architecture
]);
1728 } /* if bump ok else error */
1729 } /* if architecture higher */
1733 } /* forever looking for a match */
1735 the_insn
.opcode
= opcode
;
1746 save_in
= input_line_pointer
;
1747 input_line_pointer
= str
;
1748 seg
= expression (&the_insn
.exp
);
1749 if (seg
!= absolute_section
1750 && seg
!= text_section
1751 && seg
!= data_section
1752 && seg
!= bss_section
1753 && seg
!= undefined_section
)
1755 the_insn
.error
= "bad segment";
1756 expr_end
= input_line_pointer
;
1757 input_line_pointer
= save_in
;
1760 expr_end
= input_line_pointer
;
1761 input_line_pointer
= save_in
;
1763 } /* getExpression() */
1767 This is identical to the md_atof in m68k.c. I think this is right,
1770 Turn a string in input_line_pointer into a floating point constant of type
1771 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1772 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1775 /* Equal to MAX_PRECISION in atof-ieee.c */
1776 #define MAX_LITTLENUMS 6
1779 md_atof (type
, litP
, sizeP
)
1785 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1786 LITTLENUM_TYPE
*wordP
;
1819 return "Bad call to MD_ATOF()";
1821 t
= atof_ieee (input_line_pointer
, type
, words
);
1823 input_line_pointer
= t
;
1824 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1825 for (wordP
= words
; prec
--;)
1827 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1828 litP
+= sizeof (LITTLENUM_TYPE
);
1834 * Write out big-endian.
1837 md_number_to_chars (buf
, val
, n
)
1845 /* start-sanitize-v9 */
1851 /* end-sanitize-v9 */
1862 as_fatal ("failed sanity check.");
1865 } /* md_number_to_chars() */
1867 /* Apply a fixS to the frags, now that we know the value it ought to
1870 #ifdef BFD_ASSEMBLER
1875 md_apply_fix (fixP
, value
)
1877 #ifdef BFD_ASSEMBLER
1883 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1886 #ifdef BFD_ASSEMBLER
1892 #ifdef BFD_ASSEMBLER
1893 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1895 assert (fixP
->fx_r_type
< NO_RELOC
);
1898 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1901 /* FIXME: SPARC ELF relocations don't use an addend in the data
1902 field itself. This whole approach should be somehow combined
1903 with the calls to bfd_perform_relocation. */
1904 if (fixP
->fx_addsy
!= NULL
)
1909 * This is a hack. There should be a better way to
1912 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1914 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1917 switch (fixP
->fx_r_type
)
1932 case BFD_RELOC_32_PCREL_S2
:
1933 val
= (val
>>= 2) + 1;
1934 buf
[0] |= (val
>> 24) & 0x3f;
1935 buf
[1] = (val
>> 16);
1940 /* start-sanitize-v9 */
1953 case BFD_RELOC_SPARC_11
:
1954 if (((val
> 0) && (val
& ~0x7ff))
1955 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1957 as_bad ("relocation overflow.");
1960 buf
[2] |= (val
>> 8) & 0x7;
1961 buf
[3] = val
& 0xff;
1964 case BFD_RELOC_SPARC_10
:
1965 if (((val
> 0) && (val
& ~0x3ff))
1966 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1968 as_bad ("relocation overflow.");
1971 buf
[2] |= (val
>> 8) & 0x3;
1972 buf
[3] = val
& 0xff;
1975 case BFD_RELOC_SPARC_WDISP16
:
1976 if (((val
> 0) && (val
& ~0x3fffc))
1977 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1979 as_bad ("relocation overflow.");
1982 val
= (val
>>= 2) + 1;
1983 buf
[1] |= ((val
>> 14) & 0x3) << 4;
1984 buf
[2] |= (val
>> 8) & 0x3f;
1985 buf
[3] = val
& 0xff;
1988 case BFD_RELOC_SPARC_WDISP19
:
1989 if (((val
> 0) && (val
& ~0x1ffffc))
1990 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
1992 as_bad ("relocation overflow.");
1995 val
= (val
>>= 2) + 1;
1996 buf
[1] |= (val
>> 16) & 0x7;
1997 buf
[2] = (val
>> 8) & 0xff;
1998 buf
[3] = val
& 0xff;
2001 case BFD_RELOC_SPARC_HH22
:
2003 /* intentional fallthrough */
2005 /* end-sanitize-v9 */
2007 /* start-sanitize-v9 */
2009 case BFD_RELOC_SPARC_LM22
:
2011 /* end-sanitize-v9 */
2012 case BFD_RELOC_HI22
:
2013 if (!fixP
->fx_addsy
)
2015 buf
[1] |= (val
>> 26) & 0x3f;
2026 case BFD_RELOC_SPARC22
:
2027 if (val
& ~0x003fffff)
2029 as_bad ("relocation overflow");
2031 buf
[1] |= (val
>> 16) & 0x3f;
2033 buf
[3] = val
& 0xff;
2036 case BFD_RELOC_SPARC13
:
2037 if (val
& ~0x00001fff)
2039 as_bad ("relocation overflow");
2041 buf
[2] |= (val
>> 8) & 0x1f;
2042 buf
[3] = val
& 0xff;
2045 /* start-sanitize-v9 */
2047 case BFD_RELOC_SPARC_HM10
:
2049 /* intentional fallthrough */
2051 /* end-sanitize-v9 */
2053 case BFD_RELOC_LO10
:
2054 if (!fixP
->fx_addsy
)
2056 buf
[2] |= (val
>> 8) & 0x03;
2062 case BFD_RELOC_SPARC_BASE13
:
2063 if (((val
> 0) && (val
& ~(offsetT
)0x00001fff))
2064 || ((val
< 0) && (~(val
- 1) & ~(offsetT
)0x00001fff)))
2066 as_bad ("relocation overflow");
2068 buf
[2] |= (val
>> 8) & 0x1f;
2072 case BFD_RELOC_SPARC_WDISP22
:
2073 val
= (val
>>= 2) + 1;
2075 case BFD_RELOC_SPARC_BASE22
:
2076 buf
[1] |= (val
>> 16) & 0x3f;
2081 case BFD_RELOC_NONE
:
2083 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
2087 #ifdef BFD_ASSEMBLER
2092 /* should never be called for sparc */
2094 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2101 as_fatal ("sparc_create_short_jmp\n");
2104 #ifdef BFD_ASSEMBLER
2106 /* Translate internal representation of relocation info to BFD target
2109 tc_gen_reloc (section
, fixp
)
2114 bfd_reloc_code_real_type code
;
2116 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2117 assert (reloc
!= 0);
2119 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2120 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2121 if (fixp
->fx_pcrel
== 0)
2122 reloc
->addend
= fixp
->fx_addnumber
;
2124 switch (OUTPUT_FLAVOR
)
2126 case bfd_target_elf_flavour
:
2129 case bfd_target_aout_flavour
:
2130 reloc
->addend
= - reloc
->address
;
2133 /* What's a good default here? Is there any?? */
2137 switch (fixp
->fx_r_type
)
2141 case BFD_RELOC_HI22
:
2142 case BFD_RELOC_LO10
:
2143 case BFD_RELOC_32_PCREL_S2
:
2144 case BFD_RELOC_SPARC_BASE13
:
2145 case BFD_RELOC_SPARC_WDISP22
:
2146 /* start-sanitize-v9 */
2148 case BFD_RELOC_SPARC_10
:
2149 case BFD_RELOC_SPARC_11
:
2150 case BFD_RELOC_SPARC_HH22
:
2151 case BFD_RELOC_SPARC_HM10
:
2152 case BFD_RELOC_SPARC_LM22
:
2153 case BFD_RELOC_SPARC_PC_HH22
:
2154 case BFD_RELOC_SPARC_PC_HM10
:
2155 case BFD_RELOC_SPARC_PC_LM22
:
2156 /* end-sanitize-v9 */
2157 code
= fixp
->fx_r_type
;
2162 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2163 assert (reloc
->howto
!= 0);
2170 /* Translate internal representation of relocation info to target format.
2172 On sparc: first 4 bytes are normal unsigned long address, next three
2173 bytes are index, most sig. byte first. Byte 7 is broken up with
2174 bit 7 as external, bits 6 & 5 unused, and the lower
2175 five bits as relocation type. Next 4 bytes are long addend. */
2176 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2178 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2181 relax_addressT segment_address_in_file
;
2188 know (fixP
->fx_addsy
);
2190 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2193 r_index
= fixP
->fx_addsy
->sy_number
;
2198 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2202 md_number_to_chars (where
,
2203 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2206 /* now the fun stuff */
2207 where
[4] = (r_index
>> 16) & 0x0ff;
2208 where
[5] = (r_index
>> 8) & 0x0ff;
2209 where
[6] = r_index
& 0x0ff;
2210 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2213 if (fixP
->fx_addsy
->sy_frag
)
2215 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2220 r_addend
+= fixP
->fx_offset
- r_address
;
2224 r_addend
= fixP
->fx_addnumber
;
2227 md_number_to_chars (&where
[8], r_addend
, 4);
2230 } /* tc_aout_fix_to_chars() */
2233 /* should never be called for sparc */
2235 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2237 addressT from_addr
, to_addr
;
2241 as_fatal ("sparc_create_long_jump\n");
2242 } /* md_create_long_jump() */
2244 /* should never be called for sparc */
2246 md_estimate_size_before_relax (fragP
, segtype
)
2250 as_fatal ("sparc_estimate_size_before_relax\n");
2252 } /* md_estimate_size_before_relax() */
2255 /* for debugging only */
2258 struct sparc_it
*insn
;
2291 fprintf (stderr
, "ERROR: %s\n");
2293 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2294 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2295 fprintf (stderr
, "exp = {\n");
2296 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2297 ((insn
->exp
.X_add_symbol
!= NULL
)
2298 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2299 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2302 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2303 ((insn
->exp
.X_op_symbol
!= NULL
)
2304 ? (S_GET_NAME (insn
->exp
.X_op_symbol
)
2305 ? S_GET_NAME (insn
->exp
.X_op_symbol
)
2308 fprintf (stderr
, "\t\tX_add_number = %d\n",
2309 insn
->exp
.X_add_number
);
2310 fprintf (stderr
, "}\n");
2312 } /* print_insn() */
2318 * Invocation line includes a switch not recognized by the base assembler.
2319 * See if it's a processor-specific option. These are:
2322 * Warn on architecture bumps. See also -A.
2324 * -Av6, -Av7, -Av8, -Asparclite
2325 * Select the architecture. Instructions or features not
2326 * supported by the selected architecture cause fatal errors.
2328 * The default is to start at v6, and bump the architecture up
2329 * whenever an instruction is seen at a higher level.
2331 * If -bump is specified, a warning is printing when bumping to
2334 * If an architecture is specified, all instructions must match
2335 * that architecture. Any higher level instructions are flagged
2338 * if both an architecture and -bump are specified, the
2339 * architecture starts at the specified level, but bumps are
2344 * Another architecture switch.
2347 * Bumping between incompatible architectures is always an
2348 * error. For example, from sparclite to v9.
2353 md_parse_option (argP
, cntP
, vecP
)
2361 if (!strcmp (*argP
, "bump"))
2366 else if (**argP
== 'A')
2370 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2372 if (strcmp (p
, *arch
) == 0)
2375 } /* found a match */
2376 } /* walk the pname table */
2380 as_bad ("unknown architecture: %s", p
);
2384 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2385 architecture_requested
= 1;
2389 else if (**argP
== 'V')
2391 print_version_id ();
2393 else if (**argP
== 'Q')
2395 /* Qy - do emit .comment
2396 Qn - do not emit .comment */
2398 else if (**argP
== 's')
2400 /* use .stab instead of .stab.excl */
2403 else if (strcmp (*argP
, "sparc") == 0)
2405 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2409 /* Unknown option */
2413 **argP
= '\0'; /* Done parsing this switch */
2415 } /* md_parse_option() */
2417 /* We have no need to default values of symbols. */
2421 md_undefined_symbol (name
)
2425 } /* md_undefined_symbol() */
2427 /* Parse an operand that is machine-specific.
2428 We just return without modifying the expression if we have nothing
2433 md_operand (expressionP
)
2434 expressionS
*expressionP
;
2438 /* Round up a section size to the appropriate boundary. */
2440 md_section_align (segment
, size
)
2445 /* Round all sects to multiple of 8 */
2446 size
= (size
+ 7) & (valueT
) ~7;
2451 /* Exactly what point is a PC-relative offset relative TO?
2452 On the sparc, they're relative to the address of the offset, plus
2453 its size. This gets us to the following instruction.
2454 (??? Is this right? FIXME-SOON) */
2456 md_pcrel_from (fixP
)
2459 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2462 #ifndef BFD_ASSEMBLER
2464 tc_aout_pre_write_hook (headers
)
2465 object_headers
*headers
;
2467 H_SET_VERSION (headers
, 1);
2471 /* end of tc-sparc.c */