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 const relax_typeS md_relax_table
[1];
48 /* handle of the OPCODE hash table */
49 static struct hash_control
*op_hash
= NULL
;
51 static void s_seg (), s_proc (), s_data1 (), s_reserve (), s_common ();
52 extern void s_globl (), s_long (), s_short (), s_space (), cons ();
53 extern void s_align_bytes (), s_ignore ();
54 /* start-sanitize-v9 */
56 static void s_xword ();
60 /* Ugly hack to keep non-BFD version working. */
62 #define BFD_RELOC_NONE NO_RELOC
63 #define BFD_RELOC_32 RELOC_32
64 #define BFD_RELOC_HI22 RELOC_HI22
65 #define BFD_RELOC_LO10 RELOC_LO10
66 #define BFD_RELOC_SPARC_WDISP22 RELOC_WDISP22
67 #define BFD_RELOC_32_PCREL_S2 RELOC_WDISP30
68 #define BFD_RELOC_SPARC22 RELOC_22
69 #define BFD_RELOC_SPARC_BASE13 RELOC_BASE13
70 #define BFD_RELOC_SPARC13 RELOC_13
71 #define BFD_RELOC_SPARC_BASE22 RELOC_BASE22
72 #define subseg_set subseg_new
75 const pseudo_typeS md_pseudo_table
[] =
77 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
78 {"common", s_common
, 0},
79 {"global", s_globl
, 0},
81 {"optim", s_ignore
, 0},
83 {"reserve", s_reserve
, 0},
87 /* start-sanitize-v9 */
89 {"xword", s_xword
, 0},
95 const int md_short_jump_size
= 4;
96 const int md_long_jump_size
= 4;
97 const int md_reloc_size
= 12; /* Size of relocation record */
99 /* This array holds the chars that always start a comment. If the
100 pre-processor is disabled, these aren't very useful */
101 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
103 /* This array holds the chars that only start a comment at the beginning of
104 a line. If the line seems to have the form '# 123 filename'
105 .line and .file directives will appear in the pre-processed output */
106 /* Note that input_file.c hand checks for '#' at the beginning of the
107 first line of the input file. This is because the compiler outputs
108 #NO_APP at the beginning of its output. */
109 /* Also note that comments started like this one will always
110 work if '/' isn't otherwise defined. */
111 const char line_comment_chars
[] = "#";
113 const char line_separator_chars
[] = "";
115 /* Chars that can be used to separate mant from exp in floating point nums */
116 const char EXP_CHARS
[] = "eE";
118 /* Chars that mean this number is a floating point constant */
121 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
123 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
124 changed in read.c . Ideally it shouldn't have to know about it at all,
125 but nothing is ideal around here.
128 static unsigned char octal
[256];
129 #define isoctal(c) octal[c]
130 static unsigned char toHex
[256];
135 unsigned long opcode
;
136 struct nlist
*nlistp
;
140 bfd_reloc_code_real_type reloc
;
142 enum reloc_type reloc
;
146 struct sparc_it the_insn
, set_insn
;
149 static void print_insn
PARAMS ((struct sparc_it
*insn
));
151 static int getExpression
PARAMS ((char *str
));
153 static char *expr_end
;
154 static int special_case
;
157 * Instructions that require wierd handling because they're longer than
160 #define SPECIAL_CASE_SET 1
161 #define SPECIAL_CASE_FDIV 2
164 * sort of like s_lcomm
167 static int max_alignment
= 15;
173 as_fatal ("s_reserve only defined for a.out");
183 name
= input_line_pointer
;
184 c
= get_symbol_end ();
185 p
= input_line_pointer
;
189 if (*input_line_pointer
!= ',')
191 as_bad ("Expected comma after name");
192 ignore_rest_of_line ();
196 ++input_line_pointer
;
198 if ((size
= get_absolute_expression ()) < 0)
200 as_bad ("BSS length (%d.) <0! Ignored.", size
);
201 ignore_rest_of_line ();
206 symbolP
= symbol_find_or_make (name
);
209 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0)
211 as_bad ("bad .reserve segment: `%s'", input_line_pointer
);
215 input_line_pointer
+= 6;
218 if (*input_line_pointer
== ',')
220 ++input_line_pointer
;
223 if (*input_line_pointer
== '\n')
225 as_bad ("Missing alignment");
229 align
= get_absolute_expression ();
230 if (align
> max_alignment
)
232 align
= max_alignment
;
233 as_warn ("Alignment too large: %d. assumed.", align
);
238 as_warn ("Alignment negative. 0 assumed.");
241 record_alignment (bss_section
, align
);
243 /* convert to a power of 2 alignment */
244 for (temp
= 0; (align
& 1) == 0; align
>>= 1, ++temp
);;
248 as_bad ("Alignment not a power of 2");
249 ignore_rest_of_line ();
251 } /* not a power of two */
254 } /* if has optional alignment */
258 if (S_GET_OTHER (symbolP
) == 0
259 && S_GET_DESC (symbolP
) == 0
260 && (S_GET_SEGMENT (symbolP
) == bss_section
261 || !S_IS_DEFINED (symbolP
)))
266 segT current_seg
= now_seg
;
267 subsegT current_subseg
= now_subseg
;
269 subseg_set (bss_section
, 1); /* switch to bss */
272 frag_align (align
, 0); /* do alignment */
274 /* detach from old frag */
275 if (S_GET_SEGMENT(symbolP
) == bss_section
)
276 symbolP
->sy_frag
->fr_symbol
= NULL
;
278 symbolP
->sy_frag
= frag_now
;
279 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
283 S_SET_SEGMENT (symbolP
, bss_section
);
285 subseg_set (current_seg
, current_subseg
);
290 as_warn("Ignoring attempt to re-define symbol %s.", name
);
291 } /* if not redefining */
293 demand_empty_rest_of_line ();
304 register symbolS
*symbolP
;
306 name
= input_line_pointer
;
307 c
= get_symbol_end ();
308 /* just after name is now '\0' */
309 p
= input_line_pointer
;
312 if (*input_line_pointer
!= ',')
314 as_bad ("Expected comma after symbol-name");
315 ignore_rest_of_line ();
318 input_line_pointer
++; /* skip ',' */
319 if ((temp
= get_absolute_expression ()) < 0)
321 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
322 ignore_rest_of_line ();
326 symbolP
= symbol_find_or_make (name
);
328 if (S_IS_DEFINED (symbolP
))
330 as_bad ("Ignoring attempt to re-define symbol");
331 ignore_rest_of_line ();
334 if (S_GET_VALUE (symbolP
) != 0)
336 if (S_GET_VALUE (symbolP
) != temp
)
338 as_warn ("Length of .comm \"%s\" is already %d. Not changed to %d.",
339 S_GET_NAME (symbolP
), S_GET_VALUE (symbolP
), temp
);
344 S_SET_VALUE (symbolP
, temp
);
345 S_SET_EXTERNAL (symbolP
);
347 /* But not for a.out ... find some sensible way to characterize
349 S_SET_SEGMENT (symbolP
, now_seg
);
352 know (symbolP
->sy_frag
== &zero_address_frag
);
354 if (*input_line_pointer
!= ',')
356 as_bad ("Expected command (and alignment) after common length");
357 ignore_rest_of_line ();
360 input_line_pointer
++;
361 temp
= get_absolute_expression ();
362 if (temp
> max_alignment
)
364 temp
= max_alignment
;
365 as_warn ("Common alignment too large: %d. assumed", temp
);
370 as_warn ("Common alignment negative; 0 assumed");
372 record_alignment (S_GET_SEGMENT (symbolP
), temp
);
374 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
375 && strncmp (input_line_pointer
, ",\"data\"", 7) != 0)
377 p
= input_line_pointer
;
378 while (*p
&& *p
!= '\n')
382 as_bad ("bad .common segment: `%s'", input_line_pointer
);
386 input_line_pointer
+= 6 + (input_line_pointer
[2] == 'd'); /* Skip either */
388 demand_empty_rest_of_line ();
396 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
398 input_line_pointer
+= 6;
402 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
404 input_line_pointer
+= 6;
408 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
410 input_line_pointer
+= 7;
414 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
416 input_line_pointer
+= 5;
417 /* We only support 2 segments -- text and data -- for now, so
418 things in the "bss segment" will have to go into data for now.
419 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
420 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
423 as_bad ("Unknown segment type");
424 demand_empty_rest_of_line ();
431 subseg_set (data_section
, 1);
432 demand_empty_rest_of_line ();
439 extern char is_end_of_line
[];
441 while (!is_end_of_line
[*input_line_pointer
])
443 ++input_line_pointer
;
445 ++input_line_pointer
;
449 /* start-sanitize-v9 */
454 md_number_to_chars (frag_more (4), 0, 4);
458 struct priv_reg_entry
464 struct priv_reg_entry priv_reg_table
[] =
483 {"", -1}, /* end marker */
488 struct priv_reg_entry
*p
, *q
;
490 return strcmp (q
->name
, p
->name
);
494 /* end-sanitize-v9 */
496 /* This function is called once, at assembler startup time. It should
497 set up all the tables, etc. that the MD part of the assembler will need. */
501 register char *retval
= NULL
;
503 register unsigned int i
= 0;
505 op_hash
= hash_new ();
507 as_fatal ("Virtual memory exhausted");
509 while (i
< NUMOPCODES
)
511 const char *name
= sparc_opcodes
[i
].name
;
512 retval
= hash_insert (op_hash
, name
, &sparc_opcodes
[i
]);
513 if (retval
!= NULL
&& *retval
!= '\0')
515 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
516 sparc_opcodes
[i
].name
, retval
);
521 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
523 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
524 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
529 while (i
< NUMOPCODES
530 && !strcmp (sparc_opcodes
[i
].name
, name
));
534 as_fatal ("Broken assembler. No assembly attempted.");
536 for (i
= '0'; i
< '8'; ++i
)
538 for (i
= '0'; i
<= '9'; ++i
)
540 for (i
= 'a'; i
<= 'f'; ++i
)
541 toHex
[i
] = i
+ 10 - 'a';
542 for (i
= 'A'; i
<= 'F'; ++i
)
543 toHex
[i
] = i
+ 10 - 'A';
545 /* start-sanitize-v9 */
547 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
548 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
550 /* end-sanitize-v9 */
569 /* See if "set" operand is absolute and small; skip sethi if so. */
570 if (special_case
== SPECIAL_CASE_SET
571 && the_insn
.exp
.X_seg
== absolute_section
)
573 if (the_insn
.exp
.X_add_number
>= -(1 << 12)
574 && the_insn
.exp
.X_add_number
< (1 << 12))
576 the_insn
.opcode
= 0x80102000 /* or %g0,imm,... */
577 | (the_insn
.opcode
& 0x3E000000) /* dest reg */
578 | (the_insn
.exp
.X_add_number
& 0x1FFF); /* imm */
579 special_case
= 0; /* No longer special */
580 the_insn
.reloc
= BFD_RELOC_NONE
; /* No longer relocated */
585 /* put out the opcode */
586 md_number_to_chars (toP
, the_insn
.opcode
, 4);
588 /* put out the symbol-dependent stuff */
589 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
591 fix_new (frag_now
, /* which frag */
592 (toP
- frag_now
->fr_literal
), /* where */
594 the_insn
.exp
.X_add_symbol
,
595 the_insn
.exp
.X_subtract_symbol
,
596 the_insn
.exp
.X_add_number
,
601 switch (special_case
)
603 case SPECIAL_CASE_SET
:
605 assert (the_insn
.reloc
== BFD_RELOC_HI22
);
606 /* See if "set" operand has no low-order bits; skip OR if so. */
607 if (the_insn
.exp
.X_seg
== absolute_section
608 && ((the_insn
.exp
.X_add_number
& 0x3FF) == 0))
611 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
612 the_insn
.opcode
= 0x80102000 | (rsd
<< 25) | (rsd
<< 14);
613 md_number_to_chars (toP
, the_insn
.opcode
, 4);
614 fix_new (frag_now
, /* which frag */
615 (toP
- frag_now
->fr_literal
), /* where */
617 the_insn
.exp
.X_add_symbol
,
618 the_insn
.exp
.X_subtract_symbol
,
619 the_insn
.exp
.X_add_number
,
625 case SPECIAL_CASE_FDIV
:
626 /* According to information leaked from Sun, the "fdiv" instructions
627 on early SPARC machines would produce incorrect results sometimes.
628 The workaround is to add an fmovs of the destination register to
629 itself just after the instruction. This was true on machines
630 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
632 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
634 rsd
= (the_insn
.opcode
>> 25) & 0x1f;
635 the_insn
.opcode
= 0x81A00020 | (rsd
<< 25) | rsd
; /* fmovs dest,dest */
636 md_number_to_chars (toP
, the_insn
.opcode
, 4);
643 as_fatal ("failed sanity check.");
645 } /* md_assemble() */
651 char *error_message
= "";
655 struct sparc_opcode
*insn
;
657 unsigned long opcode
;
658 unsigned int mask
= 0;
661 long immediate_max
= 0;
663 for (s
= str
; islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
681 as_bad ("Unknown opcode: `%s'", str
);
684 if ((insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
)) == NULL
)
686 as_bad ("Unknown opcode: `%s'", str
);
696 opcode
= insn
->match
;
697 memset (&the_insn
, '\0', sizeof (the_insn
));
698 the_insn
.reloc
= BFD_RELOC_NONE
;
701 * Build the opcode, checking as we go to make
702 * sure that the operands match
704 for (args
= insn
->args
;; ++args
)
709 /* start-sanitize-v9 */
713 /* Load is 0; Store is 1.
714 We compute the mask based on the values
715 we find in S. OK is set set
716 if we see something we don't like. */
725 if (!(lo
= (s
[0] == 'S')))
727 if (!(hi
= (s
[1] == 'S')))
729 mask
|= (1 << ((hi
<< 1) | lo
));
734 /* Parse a number, somehow. */
742 error_message
= "unrecognizable mmask";
745 opcode
|= SIMM13 (mask
);
750 /* Parse a prefetch function. */
753 int prefetch_fcn
= 0;
756 if (!strncmp (s
, "n_reads", 7))
757 prefetch_fcn
= 0, s
+= 7;
758 else if (!strncmp (s
, "one_read", 8))
759 prefetch_fcn
= 1, s
+= 8;
760 else if (!strncmp (s
, "n_writes", 8))
761 prefetch_fcn
= 2, s
+= 8;
762 else if (!strncmp (s
, "one_write", 9))
763 prefetch_fcn
= 3, s
+= 9;
764 else if (!strncmp (s
, "page", 4))
765 prefetch_fcn
= 4, s
+= 4;
768 error_message
= "unrecognizable prefetch fucntion";
774 /* Parse a number, somehow. */
775 error_message
= "unrecognizable prefetch fucntion";
782 /* Parse a privileged register. */
785 struct priv_reg_entry
*p
= priv_reg_table
;
789 while (p
->name
[0] > s
[0])
791 while (p
->name
[0] == s
[0])
793 len
= strlen (p
->name
);
794 if (strncmp (p
->name
, s
, len
) == 0)
798 if (p
->name
[0] != s
[0])
800 error_message
= "unrecognizable privileged register";
804 opcode
|= (p
->regnum
<< 14);
806 opcode
|= (p
->regnum
<< 25);
812 error_message
= "unrecognizable privileged register";
816 /* end-sanitize-v9 */
820 if (strncmp (s
, "%asr", 4) == 0)
830 num
= num
* 10 + *s
- '0';
834 if (num
< 16 || 31 < num
)
836 error_message
= ": asr number must be between 15 and 31";
840 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
845 error_message
= ": expecting %asrN";
847 } /* if %asr followed by a number. */
852 /* start-sanitize-v9 */
856 /* BFD doesn't have support for this reloc type written yet. */
859 the_insn
.reloc
= RELOC_11
;
861 immediate_max
= 0x03FF;
868 the_insn
.reloc
= RELOC_10
;
870 immediate_max
= 0x01FF;
877 the_insn
.reloc
= RELOC_WDISP2_14
;
886 the_insn
.reloc
= RELOC_WDISP19
;
892 if (*s
== 'p' && s
[1] == 'n')
900 if (*s
== 'p' && s
[1] == 't')
912 if (strncmp (s
, "%icc", 4) == 0)
924 if (strncmp (s
, "%xcc", 4) == 0)
936 if (strncmp (s
, "%fcc0", 5) == 0)
948 if (strncmp (s
, "%fcc1", 5) == 0)
960 if (strncmp (s
, "%fcc2", 5) == 0)
972 if (strncmp (s
, "%fcc3", 5) == 0)
980 if (strncmp (s
, "%pc", 3) == 0)
988 if (strncmp (s
, "%tick", 5) == 0)
995 /* end-sanitize-v9 */
997 case '\0': /* end of args */
1016 case '[': /* these must match exactly */
1024 case '#': /* must be at least one digit */
1027 while (isdigit (*s
))
1035 case 'C': /* coprocessor state register */
1036 if (strncmp (s
, "%csr", 4) == 0)
1043 case 'b': /* next operand is a coprocessor register */
1046 if (*s
++ == '%' && *s
++ == 'c' && isdigit (*s
))
1051 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1065 opcode
|= mask
<< 14;
1073 opcode
|= mask
<< 25;
1079 case 'r': /* next operand must be a register */
1088 case 'f': /* frame pointer */
1096 case 'g': /* global register */
1097 if (isoctal (c
= *s
++))
1104 case 'i': /* in register */
1105 if (isoctal (c
= *s
++))
1107 mask
= c
- '0' + 24;
1112 case 'l': /* local register */
1113 if (isoctal (c
= *s
++))
1115 mask
= (c
- '0' + 16);
1120 case 'o': /* out register */
1121 if (isoctal (c
= *s
++))
1123 mask
= (c
- '0' + 8);
1128 case 's': /* stack pointer */
1136 case 'r': /* any register */
1137 if (!isdigit (c
= *s
++))
1154 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1170 * Got the register, now figure out where
1171 * it goes in the opcode.
1177 opcode
|= mask
<< 14;
1185 opcode
|= mask
<< 25;
1189 opcode
|= (mask
<< 25) | (mask
<< 14);
1195 case 'e': /* next operand is a floating point register */
1211 /* start-sanitize-v9 */
1213 && ((format
= *s
) == 'f'
1217 /* end-sanitize-v9 */
1218 && ((format
= *s
) == 'f')
1220 /* start-sanitize-v9 */
1222 /* end-sanitize-v9 */
1228 for (mask
= 0; isdigit (*s
); ++s
)
1230 mask
= 10 * mask
+ (*s
- '0');
1231 } /* read the number */
1239 } /* register must be even numbered */
1247 } /* register must be multiple of 4 */
1253 error_message
= ": There are only 32 f registers; [0-31]";
1256 /* start-sanitize-v9 */
1265 error_message
= ": There are only 32 d registers [0, 2, ... 62].";
1270 error_message
= ": Only even numbered d registers exist.";
1275 else if (format
== 'q')
1280 ": There are only 16 q registers [0, 4, ... 60].";
1286 ": Only q registers evenly divisible by four exist.";
1293 } /* depending on format */
1298 } /* wrap high bit */
1300 /* end-sanitize-v9 */
1301 } /* if not an 'f' register. */
1310 opcode
|= RS1 (mask
);
1317 opcode
|= RS2 (mask
);
1323 opcode
|= RD (mask
);
1332 if (strncmp (s
, "%fsr", 4) == 0)
1339 case 'h': /* high 22 bits */
1340 the_insn
.reloc
= BFD_RELOC_HI22
;
1343 case 'l': /* 22 bit PC relative immediate */
1344 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1348 case 'L': /* 30 bit immediate */
1349 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1353 case 'n': /* 22 bit immediate */
1354 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1357 case 'i': /* 13 bit immediate */
1358 /* What's the difference between base13 and 13? */
1359 the_insn
.reloc
= BFD_RELOC_SPARC_BASE13
;
1360 immediate_max
= 0x0FFF;
1369 if ((c
= s
[1]) == 'h' && s
[2] == 'i')
1371 the_insn
.reloc
= BFD_RELOC_HI22
;
1374 else if (c
== 'l' && s
[2] == 'o')
1376 the_insn
.reloc
= BFD_RELOC_LO10
;
1378 /* start-sanitize-v9 */
1386 #ifdef BFD_ASSEMBLER
1389 the_insn
.reloc
= RELOC_HHI22
;
1390 #endif /* ! BFD_ASSEMBLER */
1392 the_insn
.reloc
= BFD_RELOC_NONE
;
1402 #ifdef BFD_ASSEMBLER
1405 the_insn
.reloc
= RELOC_HLO10
;
1406 #endif /* ! BFD_ASSEMBLER */
1408 the_insn
.reloc
= BFD_RELOC_NONE
;
1412 /* end-sanitize-v9 */
1417 /* Note that if the getExpression() fails, we
1418 will still have created U entries in the
1419 symbol table for the 'symbols' in the input
1420 string. Try not to create U symbols for
1423 /* This stuff checks to see if the
1424 expression ends in +%reg If it does,
1425 it removes the register from the
1426 expression, and re-sets 's' to point
1427 to the right place */
1431 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++);;
1433 if (s1
!= s
&& isdigit (s1
[-1]))
1435 if (s1
[-2] == '%' && s1
[-3] == '+')
1439 (void) getExpression (s
);
1444 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
1448 (void) getExpression (s
);
1455 (void) getExpression (s
);
1458 /* Check for invalid constant values. Don't
1459 warn if constant was inside %hi or %lo,
1460 since these truncate the constant to
1462 if (immediate_max
!= 0
1463 && the_insn
.reloc
!= BFD_RELOC_LO10
1464 && the_insn
.reloc
!= BFD_RELOC_HI22
1465 /* start-sanitize-v9 */
1467 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1468 && the_insn
.reloc
!= RELOC_HLO10
1469 && the_insn
.reloc
!= RELOC_HHI22
1472 /* end-sanitize-v9 */
1473 && the_insn
.exp
.X_add_symbol
== 0
1474 && the_insn
.exp
.X_subtract_symbol
== 0
1475 && the_insn
.exp
.X_seg
== absolute_section
1476 && (the_insn
.exp
.X_add_number
> immediate_max
1477 || the_insn
.exp
.X_add_number
< ~immediate_max
))
1478 as_bad ("constant value must be between %ld and %ld",
1479 ~immediate_max
, immediate_max
);
1480 /* Reset to prevent extraneous range check. */
1495 char *push
= input_line_pointer
;
1498 input_line_pointer
= s
;
1500 if (expression (&e
) == absolute_section
)
1502 opcode
|= e
.X_add_number
<< 5;
1503 s
= input_line_pointer
;
1504 input_line_pointer
= push
;
1509 } /* alternate space */
1512 if (strncmp (s
, "%psr", 4) == 0)
1519 case 'q': /* floating point queue */
1520 if (strncmp (s
, "%fq", 3) == 0)
1527 case 'Q': /* coprocessor queue */
1528 if (strncmp (s
, "%cq", 3) == 0)
1536 if (strcmp (str
, "set") == 0)
1538 special_case
= SPECIAL_CASE_SET
;
1541 else if (strncmp (str
, "fdiv", 4) == 0)
1543 special_case
= SPECIAL_CASE_FDIV
;
1548 /* start-sanitize-v9 */
1551 if (strncmp (s
, "%asi", 4) != 0)
1557 if (strncmp (s
, "%fprs", 5) != 0)
1563 if (strncmp (s
, "%ccr", 4) != 0)
1568 /* end-sanitize-v9 */
1571 if (strncmp (s
, "%tbr", 4) != 0)
1577 if (strncmp (s
, "%wim", 4) != 0)
1583 if (strncmp (s
, "%y", 2) != 0)
1589 as_fatal ("failed sanity check.");
1590 } /* switch on arg code */
1592 } /* for each arg that we expect */
1596 /* Args don't match. */
1597 if (((unsigned) (&insn
[1] - sparc_opcodes
)) < NUMOPCODES
1598 && !strcmp (insn
->name
, insn
[1].name
))
1606 as_bad ("Illegal operands%s", error_message
);
1612 if (insn
->architecture
> current_architecture
)
1614 if ((!architecture_requested
|| warn_on_bump
)
1616 /* start-sanitize-v9 */
1618 !ARCHITECTURES_CONFLICT_P (current_architecture
,
1621 /* end-sanitize-v9 */
1623 /* start-sanitize-v9 */
1625 /* end-sanitize-v9 */
1630 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1631 architecture_pname
[current_architecture
],
1632 architecture_pname
[insn
->architecture
],
1636 current_architecture
= insn
->architecture
;
1640 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1642 architecture_pname
[insn
->architecture
],
1643 architecture_pname
[current_architecture
]);
1645 } /* if bump ok else error */
1646 } /* if architecture higher */
1650 } /* forever looking for a match */
1652 the_insn
.opcode
= opcode
;
1663 save_in
= input_line_pointer
;
1664 input_line_pointer
= str
;
1665 seg
= expression (&the_insn
.exp
);
1666 if (seg
== absolute_section
1667 || seg
== text_section
1668 || seg
== data_section
1669 || seg
== bss_section
1670 || seg
== undefined_section
1671 || seg
== diff_section
1672 || seg
== big_section
1673 || seg
== absent_section
)
1677 the_insn
.error
= "bad segment";
1678 expr_end
= input_line_pointer
;
1679 input_line_pointer
= save_in
;
1682 expr_end
= input_line_pointer
;
1683 input_line_pointer
= save_in
;
1685 } /* getExpression() */
1689 This is identical to the md_atof in m68k.c. I think this is right,
1692 Turn a string in input_line_pointer into a floating point constant of type
1693 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1694 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1697 /* Equal to MAX_PRECISION in atof-ieee.c */
1698 #define MAX_LITTLENUMS 6
1701 md_atof (type
, litP
, sizeP
)
1707 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1708 LITTLENUM_TYPE
*wordP
;
1741 return "Bad call to MD_ATOF()";
1743 t
= atof_ieee (input_line_pointer
, type
, words
);
1745 input_line_pointer
= t
;
1746 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1747 for (wordP
= words
; prec
--;)
1749 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1750 litP
+= sizeof (LITTLENUM_TYPE
);
1752 return ""; /* Someone should teach Dean about null pointers */
1756 * Write out big-endian.
1759 md_number_to_chars (buf
, val
, n
)
1778 as_fatal ("failed sanity check.");
1781 } /* md_number_to_chars() */
1783 /* Apply a fixS to the frags, now that we know the value it ought to
1786 #ifdef BFD_ASSEMBLER
1791 md_apply_fix (fixP
, value
)
1793 #ifdef BFD_ASSEMBLER
1799 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1802 #ifdef BFD_ASSEMBLER
1808 assert (fixP
->fx_size
== 4);
1809 #ifdef BFD_ASSEMBLER
1810 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1812 assert (fixP
->fx_r_type
< NO_RELOC
);
1815 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
1818 * This is a hack. There should be a better way to
1821 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
1823 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1826 switch (fixP
->fx_r_type
)
1830 buf
[0] = 0; /* val >> 24; */
1831 buf
[1] = 0; /* val >> 16; */
1832 buf
[2] = 0; /* val >> 8; */
1833 buf
[3] = 0; /* val; */
1836 case BFD_RELOC_32_PCREL_S2
:
1837 val
= (val
>>= 2) + 1;
1838 buf
[0] |= (val
>> 24) & 0x3f;
1839 buf
[1] = (val
>> 16);
1844 /* start-sanitize-v9 */
1846 #ifndef BFD_ASSEMBLER /* bfd assembler doesn't handle these yet */
1848 if (((val
> 0) && (val
& ~0x7ff))
1849 || ((val
< 0) && (~(val
- 1) & ~0x7ff)))
1851 as_bad ("relocation overflow.");
1854 buf
[2] |= (val
>> 8) & 0x7;
1855 buf
[3] = val
& 0xff;
1859 if (((val
> 0) && (val
& ~0x3ff))
1860 || ((val
< 0) && (~(val
- 1) & ~0x3ff)))
1862 as_bad ("relocation overflow.");
1865 buf
[2] |= (val
>> 8) & 0x3;
1866 buf
[3] = val
& 0xff;
1869 case RELOC_WDISP2_14
:
1870 if (((val
> 0) && (val
& ~0x3fffc))
1871 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
1873 as_bad ("relocation overflow.");
1876 val
= (val
>>= 2) + 1;
1877 buf
[1] |= ((val
>> 14) & 0x3) << 4;
1878 buf
[2] |= (val
>> 8) & 0x3f;
1879 buf
[3] = val
& 0xff;
1883 if (((val
> 0) && (val
& ~0x1ffffc))
1884 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
1886 as_bad ("relocation overflow.");
1889 val
= (val
>>= 2) + 1;
1890 buf
[1] |= (val
>> 16) & 0x7;
1891 buf
[2] = (val
>> 8) & 0xff;
1892 buf
[3] = val
& 0xff;
1897 /* intentional fallthrough */
1898 #endif /* BFD_ASSEMBLER */
1900 /* end-sanitize-v9 */
1902 case BFD_RELOC_HI22
:
1903 if (!fixP
->fx_addsy
)
1905 buf
[1] |= (val
>> 26) & 0x3f;
1916 case BFD_RELOC_SPARC22
:
1917 if (val
& ~0x003fffff)
1919 as_bad ("relocation overflow");
1921 buf
[1] |= (val
>> 16) & 0x3f;
1923 buf
[3] = val
& 0xff;
1926 case BFD_RELOC_SPARC13
:
1927 if (val
& ~0x00001fff)
1929 as_bad ("relocation overflow");
1931 buf
[2] |= (val
>> 8) & 0x1f;
1932 buf
[3] = val
& 0xff;
1935 /* start-sanitize-v9 */
1937 #ifndef BFD_ASSEMBLER
1940 /* intentional fallthrough */
1943 /* end-sanitize-v9 */
1945 case BFD_RELOC_LO10
:
1946 if (!fixP
->fx_addsy
)
1948 buf
[2] |= (val
>> 8) & 0x03;
1954 case BFD_RELOC_SPARC_BASE13
:
1955 if (((val
> 0) && (val
& ~0x00001fff))
1956 || ((val
< 0) && (~(val
- 1) & ~0x00001fff)))
1958 as_bad ("relocation overflow");
1960 buf
[2] |= (val
>> 8) & 0x1f;
1964 case BFD_RELOC_SPARC_WDISP22
:
1965 val
= (val
>>= 2) + 1;
1967 case BFD_RELOC_SPARC_BASE22
:
1968 buf
[1] |= (val
>> 16) & 0x3f;
1973 case BFD_RELOC_NONE
:
1975 as_bad ("bad or unhandled relocation type: 0x%02x", fixP
->fx_r_type
);
1979 #ifdef BFD_ASSEMBLER
1984 /* should never be called for sparc */
1986 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1993 as_fatal ("sparc_create_short_jmp\n");
1996 #ifdef BFD_ASSEMBLER
1998 /* Translate internal representation of relocation info to BFD target
2001 tc_gen_reloc (section
, fixp
)
2006 bfd_reloc_code_real_type code
;
2008 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2009 assert (reloc
!= 0);
2011 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2012 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2013 if (fixp
->fx_pcrel
== 0)
2014 reloc
->addend
= fixp
->fx_addnumber
;
2019 reloc
->addend
= - reloc
->address
;
2023 printf ("addr %04x addend=%08x fx_pcrel=%d fx_addnumber=%08x\n",
2024 reloc
->address
, reloc
->addend
, fixp
->fx_pcrel
, fixp
->fx_addnumber
);
2025 if (fixp
->fx_addsy
->sy_frag
)
2026 printf ("\tsy_frag->fr_address=%08x sym=`%s'\n",
2027 fixp
->fx_addsy
->sy_frag
->fr_address
,
2028 fixp
->fx_addsy
->bsym
->name
);
2031 switch (fixp
->fx_r_type
)
2034 case BFD_RELOC_HI22
:
2035 case BFD_RELOC_LO10
:
2036 case BFD_RELOC_32_PCREL_S2
:
2037 case BFD_RELOC_SPARC_BASE13
:
2038 code
= fixp
->fx_r_type
;
2043 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2044 assert (reloc
->howto
!= 0);
2051 /* Translate internal representation of relocation info to target format.
2053 On sparc: first 4 bytes are normal unsigned long address, next three
2054 bytes are index, most sig. byte first. Byte 7 is broken up with
2055 bit 7 as external, bits 6 & 5 unused, and the lower
2056 five bits as relocation type. Next 4 bytes are long addend. */
2057 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2059 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2062 relax_addressT segment_address_in_file
;
2069 know (fixP
->fx_addsy
);
2071 if (!S_IS_DEFINED (fixP
->fx_addsy
))
2074 r_index
= fixP
->fx_addsy
->sy_number
;
2079 r_index
= S_GET_TYPE (fixP
->fx_addsy
);
2083 md_number_to_chars (where
,
2084 r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2087 /* now the fun stuff */
2088 where
[4] = (r_index
>> 16) & 0x0ff;
2089 where
[5] = (r_index
>> 8) & 0x0ff;
2090 where
[6] = r_index
& 0x0ff;
2091 where
[7] = ((r_extern
<< 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
2094 if (fixP
->fx_addsy
->sy_frag
)
2096 r_addend
= fixP
->fx_addsy
->sy_frag
->fr_address
;
2101 r_addend
+= fixP
->fx_offset
- r_address
;
2105 r_addend
= fixP
->fx_addnumber
;
2108 md_number_to_chars (&where
[8], r_addend
, 4);
2111 } /* tc_aout_fix_to_chars() */
2114 /* should never be called for sparc */
2116 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2118 long from_addr
, to_addr
;
2122 as_fatal ("sparc_create_long_jump\n");
2123 } /* md_create_long_jump() */
2125 /* should never be called for sparc */
2127 md_estimate_size_before_relax (fragP
, segtype
)
2131 as_fatal ("sparc_estimate_size_before_relax\n");
2133 } /* md_estimate_size_before_relax() */
2136 /* for debugging only */
2139 struct sparc_it
*insn
;
2172 fprintf (stderr
, "ERROR: %s\n");
2174 fprintf (stderr
, "opcode=0x%08x\n", insn
->opcode
);
2175 fprintf (stderr
, "reloc = %s\n", Reloc
[insn
->reloc
]);
2176 fprintf (stderr
, "exp = {\n");
2177 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
2178 ((insn
->exp
.X_add_symbol
!= NULL
)
2179 ? ((S_GET_NAME (insn
->exp
.X_add_symbol
) != NULL
)
2180 ? S_GET_NAME (insn
->exp
.X_add_symbol
)
2183 fprintf (stderr
, "\t\tX_sub_symbol = %s\n",
2184 ((insn
->exp
.X_subtract_symbol
!= NULL
)
2185 ? (S_GET_NAME (insn
->exp
.X_subtract_symbol
)
2186 ? S_GET_NAME (insn
->exp
.X_subtract_symbol
)
2189 fprintf (stderr
, "\t\tX_add_number = %d\n",
2190 insn
->exp
.X_add_number
);
2191 fprintf (stderr
, "}\n");
2193 } /* print_insn() */
2199 * Invocation line includes a switch not recognized by the base assembler.
2200 * See if it's a processor-specific option. These are:
2203 * Warn on architecture bumps. See also -A.
2205 * -Av6, -Av7, -Av8, -Asparclite
2206 * Select the architecture. Instructions or features not
2207 * supported by the selected architecture cause fatal errors.
2209 * The default is to start at v6, and bump the architecture up
2210 * whenever an instruction is seen at a higher level.
2212 * If -bump is specified, a warning is printing when bumping to
2215 * If an architecture is specified, all instructions must match
2216 * that architecture. Any higher level instructions are flagged
2219 * if both an architecture and -bump are specified, the
2220 * architecture starts at the specified level, but bumps are
2224 * Bumping between incompatible architectures is always an
2225 * error. For example, from sparclite to v9.
2228 /* start-sanitize-v9 */
2229 /* There is also a -Av9 architecture option. xoxorich. */
2230 /* end-sanitize-v9 */
2232 md_parse_option (argP
, cntP
, vecP
)
2240 if (!strcmp (*argP
, "bump"))
2245 else if (**argP
== 'A')
2249 for (arch
= architecture_pname
; *arch
!= NULL
; ++arch
)
2251 if (strcmp (p
, *arch
) == 0)
2254 } /* found a match */
2255 } /* walk the pname table */
2259 as_bad ("unknown architecture: %s", p
);
2263 current_architecture
= (enum sparc_architecture
) (arch
- architecture_pname
);
2264 architecture_requested
= 1;
2269 /* Unknown option */
2273 **argP
= '\0'; /* Done parsing this switch */
2275 } /* md_parse_option() */
2277 /* We have no need to default values of symbols. */
2281 md_undefined_symbol (name
)
2285 } /* md_undefined_symbol() */
2287 /* Parse an operand that is machine-specific.
2288 We just return without modifying the expression if we have nothing
2293 md_operand (expressionP
)
2294 expressionS
*expressionP
;
2298 /* Round up a section size to the appropriate boundary. */
2300 md_section_align (segment
, size
)
2304 /* Round all sects to multiple of 8 */
2305 return (size
+ 7) & ~7;
2308 /* Exactly what point is a PC-relative offset relative TO?
2309 On the sparc, they're relative to the address of the offset, plus
2310 its size. This gets us to the following instruction.
2311 (??? Is this right? FIXME-SOON) */
2313 md_pcrel_from (fixP
)
2316 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2319 #ifndef BFD_ASSEMBLER
2321 tc_aout_pre_write_hook (headers
)
2322 object_headers
*headers
;
2324 H_SET_VERSION (headers
, 1);
2328 /* end of tc-sparc.c */