1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 90-96, 97, 98, 1999 Free Software Foundation, Inc.
3 This file is part of GAS, the GNU Assembler.
5 GAS is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GAS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public
16 License along with GAS; see the file COPYING. If not, write
17 to the Free Software Foundation, 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
26 #include "opcode/sparc.h"
29 #include "elf/sparc.h"
32 static struct sparc_arch
*lookup_arch
PARAMS ((char *));
33 static void init_default_arch
PARAMS ((void));
34 static void sparc_ip
PARAMS ((char *, const struct sparc_opcode
**));
35 static int in_signed_range
PARAMS ((bfd_signed_vma
, bfd_signed_vma
));
36 static int in_unsigned_range
PARAMS ((bfd_vma
, bfd_vma
));
37 static int in_bitfield_range
PARAMS ((bfd_signed_vma
, bfd_signed_vma
));
38 static int sparc_ffs
PARAMS ((unsigned int));
39 static bfd_vma BSR
PARAMS ((bfd_vma
, int));
40 static int cmp_reg_entry
PARAMS ((const PTR
, const PTR
));
41 static int parse_keyword_arg
PARAMS ((int (*) (const char *), char **, int *));
42 static int parse_const_expr_arg
PARAMS ((char **, int *));
43 static int get_expression
PARAMS ((char *str
));
45 /* Default architecture. */
46 /* ??? The default value should be V8, but sparclite support was added
47 by making it the default. GCC now passes -Asparclite, so maybe sometime in
48 the future we can set this to V8. */
50 #define DEFAULT_ARCH "sparclite"
52 static char *default_arch
= DEFAULT_ARCH
;
54 /* Non-zero if the initial values of `max_architecture' and `sparc_arch_size'
56 static int default_init_p
;
58 /* Current architecture. We don't bump up unless necessary. */
59 static enum sparc_opcode_arch_val current_architecture
= SPARC_OPCODE_ARCH_V6
;
61 /* The maximum architecture level we can bump up to.
62 In a 32 bit environment, don't allow bumping up to v9 by default.
63 The native assembler works this way. The user is required to pass
64 an explicit argument before we'll create v9 object files. However, if
65 we don't see any v9 insns, a v8plus object file is not created. */
66 static enum sparc_opcode_arch_val max_architecture
;
68 /* Either 32 or 64, selects file format. */
69 static int sparc_arch_size
;
70 /* Initial (default) value, recorded separately in case a user option
71 changes the value before md_show_usage is called. */
72 static int default_arch_size
;
75 /* The currently selected v9 memory model. Currently only used for
77 static enum { MM_TSO
, MM_PSO
, MM_RMO
} sparc_memory_model
= MM_RMO
;
80 static int architecture_requested
;
81 static int warn_on_bump
;
83 /* If warn_on_bump and the needed architecture is higher than this
84 architecture, issue a warning. */
85 static enum sparc_opcode_arch_val warn_after_architecture
;
87 /* Non-zero if we are generating PIC code. */
90 /* Non-zero if we should give an error when misaligned data is seen. */
91 static int enforce_aligned_data
;
93 extern int target_big_endian
;
95 static int target_little_endian_data
;
97 /* V9 and 86x have big and little endian data, but instructions are always big
98 endian. The sparclet has bi-endian support but both data and insns have
99 the same endianness. Global `target_big_endian' is used for data.
100 The following macro is used for instructions. */
101 #ifndef INSN_BIG_ENDIAN
102 #define INSN_BIG_ENDIAN (target_big_endian \
103 || default_arch_type == sparc86x \
104 || SPARC_OPCODE_ARCH_V9_P (max_architecture))
107 /* handle of the OPCODE hash table */
108 static struct hash_control
*op_hash
;
110 static int log2
PARAMS ((int));
111 static void s_data1
PARAMS ((void));
112 static void s_seg
PARAMS ((int));
113 static void s_proc
PARAMS ((int));
114 static void s_reserve
PARAMS ((int));
115 static void s_common
PARAMS ((int));
116 static void s_empty
PARAMS ((int));
117 static void s_uacons
PARAMS ((int));
118 static void s_ncons
PARAMS ((int));
120 const pseudo_typeS md_pseudo_table
[] =
122 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
123 {"common", s_common
, 0},
124 {"empty", s_empty
, 0},
125 {"global", s_globl
, 0},
127 {"nword", s_ncons
, 0},
128 {"optim", s_ignore
, 0},
130 {"reserve", s_reserve
, 0},
132 {"skip", s_space
, 0},
135 {"uahalf", s_uacons
, 2},
136 {"uaword", s_uacons
, 4},
137 {"uaxword", s_uacons
, 8},
139 /* these are specific to sparc/svr4 */
140 {"pushsection", obj_elf_section
, 0},
141 {"popsection", obj_elf_previous
, 0},
142 {"2byte", s_uacons
, 2},
143 {"4byte", s_uacons
, 4},
144 {"8byte", s_uacons
, 8},
149 const int md_reloc_size
= 12; /* Size of relocation record */
151 /* This array holds the chars that always start a comment. If the
152 pre-processor is disabled, these aren't very useful */
153 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
155 /* This array holds the chars that only start a comment at the beginning of
156 a line. If the line seems to have the form '# 123 filename'
157 .line and .file directives will appear in the pre-processed output */
158 /* Note that input_file.c hand checks for '#' at the beginning of the
159 first line of the input file. This is because the compiler outputs
160 #NO_APP at the beginning of its output. */
161 /* Also note that comments started like this one will always
162 work if '/' isn't otherwise defined. */
163 const char line_comment_chars
[] = "#";
165 const char line_separator_chars
[] = "";
167 /* Chars that can be used to separate mant from exp in floating point nums */
168 const char EXP_CHARS
[] = "eE";
170 /* Chars that mean this number is a floating point constant */
173 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
175 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
176 changed in read.c. Ideally it shouldn't have to know about it at all,
177 but nothing is ideal around here. */
179 #define isoctal(c) ((c) >= '0' && (c) < '8')
184 unsigned long opcode
;
185 struct nlist
*nlistp
;
189 bfd_reloc_code_real_type reloc
;
192 struct sparc_it the_insn
, set_insn
;
194 static void output_insn
195 PARAMS ((const struct sparc_opcode
*, struct sparc_it
*));
197 /* Table of arguments to -A.
198 The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect
199 for this use. That table is for opcodes only. This table is for opcodes
202 enum sparc_arch_types
{v6
, v7
, v8
, sparclet
, sparclite
, sparc86x
, v8plus
,
203 v8plusa
, v9
, v9a
, v9_64
};
205 static struct sparc_arch
{
208 enum sparc_arch_types arch_type
;
209 /* Default word size, as specified during configuration.
210 A value of zero means can't be used to specify default architecture. */
211 int default_arch_size
;
212 /* Allowable arg to -A? */
214 } sparc_arch_table
[] = {
215 { "v6", "v6", v6
, 0, 1 },
216 { "v7", "v7", v7
, 0, 1 },
217 { "v8", "v8", v8
, 32, 1 },
218 { "sparclet", "sparclet", sparclet
, 32, 1 },
219 { "sparclite", "sparclite", sparclite
, 32, 1 },
220 { "sparc86x", "sparclite", sparc86x
, 32, 1 },
221 { "v8plus", "v9", v9
, 0, 1 },
222 { "v8plusa", "v9a", v9
, 0, 1 },
223 { "v9", "v9", v9
, 0, 1 },
224 { "v9a", "v9a", v9
, 0, 1 },
225 /* This exists to allow configure.in/Makefile.in to pass one
226 value to specify both the default machine and default word size. */
227 { "v9-64", "v9", v9
, 64, 0 },
228 { NULL
, NULL
, v8
, 0, 0 }
231 /* Variant of default_arch */
232 static enum sparc_arch_types default_arch_type
;
234 static struct sparc_arch
*
238 struct sparc_arch
*sa
;
240 for (sa
= &sparc_arch_table
[0]; sa
->name
!= NULL
; sa
++)
241 if (strcmp (sa
->name
, name
) == 0)
243 if (sa
->name
== NULL
)
248 /* Initialize the default opcode arch and word size from the default
249 architecture name. */
254 struct sparc_arch
*sa
= lookup_arch (default_arch
);
257 || sa
->default_arch_size
== 0)
258 as_fatal (_("Invalid default architecture, broken assembler."));
260 max_architecture
= sparc_opcode_lookup_arch (sa
->opcode_arch
);
261 if (max_architecture
== SPARC_OPCODE_ARCH_BAD
)
262 as_fatal (_("Bad opcode table, broken assembler."));
263 default_arch_size
= sparc_arch_size
= sa
->default_arch_size
;
265 default_arch_type
= sa
->arch_type
;
268 /* Called by TARGET_FORMAT. */
271 sparc_target_format ()
273 /* We don't get a chance to initialize anything before we're called,
274 so handle that now. */
275 if (! default_init_p
)
276 init_default_arch ();
280 return "a.out-sparc-netbsd";
283 if (target_big_endian
)
284 return "a.out-sunos-big";
285 else if (default_arch_type
== sparc86x
&& target_little_endian_data
)
286 return "a.out-sunos-big";
287 else return "a.out-sparc-little";
289 return "a.out-sunos-big";
300 return "coff-sparc-lynx";
307 return sparc_arch_size
== 64 ? "elf64-sparc" : "elf32-sparc";
315 * Invocation line includes a switch not recognized by the base assembler.
316 * See if it's a processor-specific option. These are:
319 * Warn on architecture bumps. See also -A.
321 * -Av6, -Av7, -Av8, -Asparclite, -Asparclet
322 * Standard 32 bit architectures.
323 * -Av8plus, -Av8plusa
324 * Sparc64 in a 32 bit world.
326 * Sparc64 in either a 32 or 64 bit world (-32/-64 says which).
327 * This used to only mean 64 bits, but properly specifying it
328 * complicated gcc's ASM_SPECs, so now opcode selection is
329 * specified orthogonally to word size (except when specifying
330 * the default, but that is an internal implementation detail).
331 * -xarch=v8plus, -xarch=v8plusa
332 * Same as -Av8plus{,a}, for compatibility with Sun's assembler.
334 * Select the architecture and possibly the file format.
335 * Instructions or features not supported by the selected
336 * architecture cause fatal errors.
338 * The default is to start at v6, and bump the architecture up
339 * whenever an instruction is seen at a higher level. In 32 bit
340 * environments, v9 is not bumped up to, the user must pass
343 * If -bump is specified, a warning is printing when bumping to
346 * If an architecture is specified, all instructions must match
347 * that architecture. Any higher level instructions are flagged
348 * as errors. Note that in the 32 bit environment specifying
349 * -Av8plus does not automatically create a v8plus object file, a
350 * v9 insn must be seen.
352 * If both an architecture and -bump are specified, the
353 * architecture starts at the specified level, but bumps are
354 * warnings. Note that we can't set `current_architecture' to
355 * the requested level in this case: in the 32 bit environment,
356 * we still must avoid creating v8plus object files unless v9
360 * Bumping between incompatible architectures is always an
361 * error. For example, from sparclite to v9.
365 CONST
char *md_shortopts
= "A:K:VQ:sq";
368 CONST
char *md_shortopts
= "A:k";
370 CONST
char *md_shortopts
= "A:";
373 struct option md_longopts
[] = {
374 #define OPTION_BUMP (OPTION_MD_BASE)
375 {"bump", no_argument
, NULL
, OPTION_BUMP
},
376 #define OPTION_SPARC (OPTION_MD_BASE + 1)
377 {"sparc", no_argument
, NULL
, OPTION_SPARC
},
378 #define OPTION_XARCH (OPTION_MD_BASE + 2)
379 {"xarch", required_argument
, NULL
, OPTION_XARCH
},
381 #define OPTION_32 (OPTION_MD_BASE + 3)
382 {"32", no_argument
, NULL
, OPTION_32
},
383 #define OPTION_64 (OPTION_MD_BASE + 4)
384 {"64", no_argument
, NULL
, OPTION_64
},
385 #define OPTION_TSO (OPTION_MD_BASE + 5)
386 {"TSO", no_argument
, NULL
, OPTION_TSO
},
387 #define OPTION_PSO (OPTION_MD_BASE + 6)
388 {"PSO", no_argument
, NULL
, OPTION_PSO
},
389 #define OPTION_RMO (OPTION_MD_BASE + 7)
390 {"RMO", no_argument
, NULL
, OPTION_RMO
},
392 #ifdef SPARC_BIENDIAN
393 #define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8)
394 {"EL", no_argument
, NULL
, OPTION_LITTLE_ENDIAN
},
395 #define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9)
396 {"EB", no_argument
, NULL
, OPTION_BIG_ENDIAN
},
398 #define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10)
399 {"enforce-aligned-data", no_argument
, NULL
, OPTION_ENFORCE_ALIGNED_DATA
},
400 #define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11)
401 {"little-endian-data", no_argument
, NULL
, OPTION_LITTLE_ENDIAN_DATA
},
402 {NULL
, no_argument
, NULL
, 0}
404 size_t md_longopts_size
= sizeof(md_longopts
);
407 md_parse_option (c
, arg
)
411 /* We don't get a chance to initialize anything before we're called,
412 so handle that now. */
413 if (! default_init_p
)
414 init_default_arch ();
420 warn_after_architecture
= SPARC_OPCODE_ARCH_V6
;
424 /* This is for compatibility with Sun's assembler. */
425 if (strcmp (arg
, "v8plus") != 0
426 && strcmp (arg
, "v8plusa") != 0)
428 as_bad (_("invalid architecture -xarch=%s"), arg
);
436 struct sparc_arch
*sa
;
437 enum sparc_opcode_arch_val opcode_arch
;
439 sa
= lookup_arch (arg
);
441 || ! sa
->user_option_p
)
443 as_bad (_("invalid architecture -A%s"), arg
);
447 opcode_arch
= sparc_opcode_lookup_arch (sa
->opcode_arch
);
448 if (opcode_arch
== SPARC_OPCODE_ARCH_BAD
)
449 as_fatal (_("Bad opcode table, broken assembler."));
451 max_architecture
= opcode_arch
;
452 architecture_requested
= 1;
457 /* Ignore -sparc, used by SunOS make default .s.o rule. */
460 case OPTION_ENFORCE_ALIGNED_DATA
:
461 enforce_aligned_data
= 1;
464 #ifdef SPARC_BIENDIAN
465 case OPTION_LITTLE_ENDIAN
:
466 target_big_endian
= 0;
467 if (default_arch_type
!= sparclet
)
468 as_fatal ("This target does not support -EL");
470 case OPTION_LITTLE_ENDIAN_DATA
:
471 target_little_endian_data
= 1;
472 target_big_endian
= 0;
473 if (default_arch_type
!= sparc86x
474 && default_arch_type
!= v9
)
475 as_fatal ("This target does not support --little-endian-data");
477 case OPTION_BIG_ENDIAN
:
478 target_big_endian
= 1;
492 const char **list
, **l
;
494 sparc_arch_size
= c
== OPTION_32
? 32 : 64;
495 list
= bfd_target_list ();
496 for (l
= list
; *l
!= NULL
; l
++)
498 if (sparc_arch_size
== 32)
500 if (strcmp (*l
, "elf32-sparc") == 0)
505 if (strcmp (*l
, "elf64-sparc") == 0)
510 as_fatal (_("No compiled in support for %d bit object file format"),
517 sparc_memory_model
= MM_TSO
;
521 sparc_memory_model
= MM_PSO
;
525 sparc_memory_model
= MM_RMO
;
533 /* Qy - do emit .comment
534 Qn - do not emit .comment */
538 /* use .stab instead of .stab.excl */
542 /* quick -- native assembler does fewer checks */
546 if (strcmp (arg
, "PIC") != 0)
547 as_warn (_("Unrecognized option following -K"));
561 md_show_usage (stream
)
564 const struct sparc_arch
*arch
;
566 /* We don't get a chance to initialize anything before we're called,
567 so handle that now. */
568 if (! default_init_p
)
569 init_default_arch ();
571 fprintf(stream
, _("SPARC options:\n"));
572 for (arch
= &sparc_arch_table
[0]; arch
->name
; arch
++)
574 if (arch
!= &sparc_arch_table
[0])
575 fprintf (stream
, " | ");
576 if (arch
->user_option_p
)
577 fprintf (stream
, "-A%s", arch
->name
);
579 fprintf (stream
, _("\n-xarch=v8plus | -xarch=v8plusa\n"));
580 fprintf (stream
, _("\
581 specify variant of SPARC architecture\n\
582 -bump warn when assembler switches architectures\n\
584 --enforce-aligned-data force .long, etc., to be aligned correctly\n"));
586 fprintf (stream
, _("\
587 -k generate PIC\n"));
590 fprintf (stream
, _("\
591 -32 create 32 bit object file\n\
592 -64 create 64 bit object file\n"));
593 fprintf (stream
, _("\
594 [default is %d]\n"), default_arch_size
);
595 fprintf (stream
, _("\
596 -TSO use Total Store Ordering\n\
597 -PSO use Partial Store Ordering\n\
598 -RMO use Relaxed Memory Ordering\n"));
599 fprintf (stream
, _("\
600 [default is %s]\n"), (default_arch_size
== 64) ? "RMO" : "TSO");
601 fprintf (stream
, _("\
602 -KPIC generate PIC\n\
603 -V print assembler version number\n\
608 #ifdef SPARC_BIENDIAN
609 fprintf (stream
, _("\
610 -EL generate code for a little endian machine\n\
611 -EB generate code for a big endian machine\n\
612 --little-endian-data generate code for a machine having big endian\n\
613 instructions and little endian data."));
617 /* native operand size opcode translation */
623 } native_op_table
[] =
625 {"ldn", "ld", "ldx"},
626 {"ldna", "lda", "ldxa"},
627 {"stn", "st", "stx"},
628 {"stna", "sta", "stxa"},
629 {"slln", "sll", "sllx"},
630 {"srln", "srl", "srlx"},
631 {"sran", "sra", "srax"},
632 {"casn", "cas", "casx"},
633 {"casna", "casa", "casxa"},
634 {"clrn", "clr", "clrx"},
638 /* sparc64 priviledged registers */
640 struct priv_reg_entry
646 struct priv_reg_entry priv_reg_table
[] =
665 {"", -1}, /* end marker */
668 /* v9a specific asrs */
670 struct priv_reg_entry v9a_asr_table
[] =
679 {"clear_softint", 21},
680 {"", -1}, /* end marker */
684 cmp_reg_entry (parg
, qarg
)
688 const struct priv_reg_entry
*p
= (const struct priv_reg_entry
*) parg
;
689 const struct priv_reg_entry
*q
= (const struct priv_reg_entry
*) qarg
;
691 return strcmp (q
->name
, p
->name
);
694 /* This function is called once, at assembler startup time. It should
695 set up all the tables, etc. that the MD part of the assembler will need. */
700 register const char *retval
= NULL
;
702 register unsigned int i
= 0;
704 /* We don't get a chance to initialize anything before md_parse_option
705 is called, and it may not be called, so handle default initialization
706 now if not already done. */
707 if (! default_init_p
)
708 init_default_arch ();
710 op_hash
= hash_new ();
712 while (i
< (unsigned int) sparc_num_opcodes
)
714 const char *name
= sparc_opcodes
[i
].name
;
715 retval
= hash_insert (op_hash
, name
, (PTR
) &sparc_opcodes
[i
]);
718 as_bad (_("Internal error: can't hash `%s': %s\n"),
719 sparc_opcodes
[i
].name
, retval
);
724 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
726 as_bad (_("Internal error: losing opcode: `%s' \"%s\"\n"),
727 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
732 while (i
< (unsigned int) sparc_num_opcodes
733 && !strcmp (sparc_opcodes
[i
].name
, name
));
736 for (i
= 0; native_op_table
[i
].name
; i
++)
738 const struct sparc_opcode
*insn
;
739 char *name
= sparc_arch_size
== 32 ? native_op_table
[i
].name32
:
740 native_op_table
[i
].name64
;
741 insn
= (struct sparc_opcode
*)hash_find (op_hash
, name
);
744 as_bad (_("Internal error: can't find opcode `%s' for `%s'\n"),
745 name
, native_op_table
[i
].name
);
750 retval
= hash_insert (op_hash
, native_op_table
[i
].name
, (PTR
) insn
);
753 as_bad (_("Internal error: can't hash `%s': %s\n"),
754 sparc_opcodes
[i
].name
, retval
);
761 as_fatal (_("Broken assembler. No assembly attempted."));
763 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
764 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
766 /* If -bump, record the architecture level at which we start issuing
767 warnings. The behaviour is different depending upon whether an
768 architecture was explicitly specified. If it wasn't, we issue warnings
769 for all upwards bumps. If it was, we don't start issuing warnings until
770 we need to bump beyond the requested architecture or when we bump between
771 conflicting architectures. */
774 && architecture_requested
)
776 /* `max_architecture' records the requested architecture.
777 Issue warnings if we go above it. */
778 warn_after_architecture
= max_architecture
;
780 /* Find the highest architecture level that doesn't conflict with
781 the requested one. */
782 for (max_architecture
= SPARC_OPCODE_ARCH_MAX
;
783 max_architecture
> warn_after_architecture
;
785 if (! SPARC_OPCODE_CONFLICT_P (max_architecture
,
786 warn_after_architecture
))
791 /* Called after all assembly has been done. */
796 if (sparc_arch_size
== 64)
798 if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
799 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9a
);
801 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9
);
805 if (current_architecture
== SPARC_OPCODE_ARCH_V9
)
806 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v8plus
);
807 else if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
808 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v8plusa
);
809 else if (current_architecture
== SPARC_OPCODE_ARCH_SPARCLET
)
810 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_sparclet
);
811 else if (default_arch_type
== sparc86x
&& target_little_endian_data
)
812 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_sparclite_le
);
815 /* The sparclite is treated like a normal sparc. Perhaps it shouldn't
816 be but for now it is (since that's the way it's always been
818 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc
);
823 /* Return non-zero if VAL is in the range -(MAX+1) to MAX. */
826 in_signed_range (val
, max
)
827 bfd_signed_vma val
, max
;
831 /* Sign-extend the value from the architecture word size, so that
832 0xffffffff is always considered -1 on sparc32. */
833 if (sparc_arch_size
== 32)
835 bfd_signed_vma sign
= (bfd_signed_vma
)1 << 31;
836 val
= ((val
& 0xffffffff) ^ sign
) - sign
;
845 /* Return non-zero if VAL is in the range 0 to MAX. */
848 in_unsigned_range (val
, max
)
856 /* Return non-zero if VAL is in the range -(MAX/2+1) to MAX.
857 (e.g. -15 to +31). */
860 in_bitfield_range (val
, max
)
861 bfd_signed_vma val
, max
;
867 if (val
< ~(max
>> 1))
881 for (i
= 0; (mask
& 1) == 0; ++i
)
886 /* Implement big shift right. */
892 if (sizeof (bfd_vma
) <= 4 && amount
>= 32)
893 as_fatal (_("Support for 64-bit arithmetic not compiled in."));
894 return val
>> amount
;
897 /* For communication between sparc_ip and get_expression. */
898 static char *expr_end
;
900 /* For communication between md_assemble and sparc_ip. */
901 static int special_case
;
903 /* Values for `special_case'.
904 Instructions that require wierd handling because they're longer than
906 #define SPECIAL_CASE_NONE 0
907 #define SPECIAL_CASE_SET 1
908 #define SPECIAL_CASE_SETSW 2
909 #define SPECIAL_CASE_SETX 3
910 /* FIXME: sparc-opc.c doesn't have necessary "S" trigger to enable this. */
911 #define SPECIAL_CASE_FDIV 4
913 /* Bit masks of various insns. */
914 #define NOP_INSN 0x01000000
915 #define OR_INSN 0x80100000
916 #define XOR_INSN 0x80180000
917 #define FMOVS_INSN 0x81A00020
918 #define SETHI_INSN 0x01000000
919 #define SLLX_INSN 0x81281000
920 #define SRA_INSN 0x81380000
922 /* The last instruction to be assembled. */
923 static const struct sparc_opcode
*last_insn
;
924 /* The assembled opcode of `last_insn'. */
925 static unsigned long last_opcode
;
927 /* Main entry point to assemble one instruction. */
933 const struct sparc_opcode
*insn
;
936 special_case
= SPECIAL_CASE_NONE
;
937 sparc_ip (str
, &insn
);
939 /* We warn about attempts to put a floating point branch in a delay slot,
940 unless the delay slot has been annulled. */
943 && (insn
->flags
& F_FBR
) != 0
944 && (last_insn
->flags
& F_DELAYED
) != 0
945 /* ??? This test isn't completely accurate. We assume anything with
946 F_{UNBR,CONDBR,FBR} set is annullable. */
947 && ((last_insn
->flags
& (F_UNBR
| F_CONDBR
| F_FBR
)) == 0
948 || (last_opcode
& ANNUL
) == 0))
949 as_warn (_("FP branch in delay slot"));
951 /* SPARC before v9 requires a nop instruction between a floating
952 point instruction and a floating point branch. We insert one
953 automatically, with a warning. */
954 if (max_architecture
< SPARC_OPCODE_ARCH_V9
957 && (insn
->flags
& F_FBR
) != 0
958 && (last_insn
->flags
& F_FLOAT
) != 0)
960 struct sparc_it nop_insn
;
962 nop_insn
.opcode
= NOP_INSN
;
963 nop_insn
.reloc
= BFD_RELOC_NONE
;
964 output_insn (insn
, &nop_insn
);
965 as_warn (_("FP branch preceded by FP instruction; NOP inserted"));
970 switch (special_case
)
972 case SPECIAL_CASE_NONE
:
974 output_insn (insn
, &the_insn
);
977 case SPECIAL_CASE_SETSW
:
978 if (the_insn
.exp
.X_op
== O_constant
)
981 if (the_insn
.exp
.X_add_number
< -(offsetT
)0x80000000
982 || the_insn
.exp
.X_add_number
> (offsetT
) 0xffffffff)
983 as_warn (_("setsw: number not in -2147483648..4294967295 range"));
985 low32
= the_insn
.exp
.X_add_number
;
989 int rd
= (the_insn
.opcode
& RD (~0)) >> 25;
992 the_insn
.reloc
= BFD_RELOC_NONE
;
993 /* See if operand is absolute and small; skip sethi if so. */
994 if (low32
< -(1 << 12))
996 the_insn
.opcode
= (SETHI_INSN
| RD (rd
)
997 | (((~the_insn
.exp
.X_add_number
) >> 10) & 0x3fffff));
998 output_insn (insn
, &the_insn
);
999 low32
= 0x1c00 | (low32
& 0x3ff);
1000 opc
= RS1 (rd
) | XOR_INSN
;
1003 the_insn
.opcode
= (opc
| RD (rd
) | IMMED
1004 | (low32
& 0x1fff));
1005 output_insn (insn
, &the_insn
);
1011 case SPECIAL_CASE_SET
:
1013 int need_hi22_p
= 0;
1014 int rd
= (the_insn
.opcode
& RD (~0)) >> 25;
1016 if (the_insn
.exp
.X_op
== O_constant
)
1018 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1020 if (the_insn
.exp
.X_add_number
< 0
1021 || the_insn
.exp
.X_add_number
> (offsetT
) 0xffffffff)
1022 as_warn (_("set: number not in 0..4294967295 range"));
1026 if (the_insn
.exp
.X_add_number
< (offsetT
)-0x80000000
1027 || the_insn
.exp
.X_add_number
> (offsetT
) 0xffffffff)
1028 as_warn (_("set: number not in -2147483648..4294967295 range"));
1029 if (the_insn
.exp
.X_add_number
>= (offsetT
)0x80000000)
1030 the_insn
.exp
.X_add_number
-= (offsetT
)0x100000000;
1034 /* See if operand is absolute and small; skip sethi if so. */
1035 if (the_insn
.exp
.X_op
!= O_constant
1036 || the_insn
.exp
.X_add_number
>= (1 << 12)
1037 || the_insn
.exp
.X_add_number
< -(1 << 12))
1039 the_insn
.opcode
= (SETHI_INSN
| RD (rd
)
1040 | ((the_insn
.exp
.X_add_number
>> 10)
1041 & the_insn
.exp
.X_op
== O_constant
? 0x3fffff : 0));
1042 the_insn
.reloc
= BFD_RELOC_HI22
;
1043 output_insn (insn
, &the_insn
);
1047 /* See if operand has no low-order bits; skip OR if so. */
1048 if (the_insn
.exp
.X_op
!= O_constant
1049 || (need_hi22_p
&& (the_insn
.exp
.X_add_number
& 0x3FF) != 0)
1052 the_insn
.opcode
= (OR_INSN
| (need_hi22_p
? RS1 (rd
) : 0)
1055 | (the_insn
.exp
.X_add_number
1056 & (the_insn
.exp
.X_op
!= O_constant
? 0 :
1057 need_hi22_p
? 0x3ff : 0x1fff)));
1058 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1061 output_insn (insn
, &the_insn
);
1064 if (special_case
== SPECIAL_CASE_SETSW
1065 && the_insn
.exp
.X_op
!= O_constant
)
1067 /* Need to sign extend it. */
1068 the_insn
.opcode
= (SRA_INSN
| RS1 (rd
) | RD (rd
));
1069 the_insn
.reloc
= BFD_RELOC_NONE
;
1070 output_insn (insn
, &the_insn
);
1075 case SPECIAL_CASE_SETX
:
1077 int upper32
, lower32
;
1078 int tmpreg
= (the_insn
.opcode
& RS1 (~0)) >> 14;
1079 int dstreg
= (the_insn
.opcode
& RD (~0)) >> 25;
1081 int need_hh22_p
= 0, need_hm10_p
= 0, need_hi22_p
= 0, need_lo10_p
= 0;
1082 int need_xor10_p
= 0;
1084 #define SIGNEXT32(x) ((((x) & 0xffffffff) ^ 0x80000000) - 0x80000000)
1085 lower32
= SIGNEXT32 (the_insn
.exp
.X_add_number
);
1086 upper32
= SIGNEXT32 (BSR (the_insn
.exp
.X_add_number
, 32));
1089 upper_dstreg
= tmpreg
;
1090 /* The tmp reg should not be the dst reg. */
1091 if (tmpreg
== dstreg
)
1092 as_warn (_("setx: temporary register same as destination register"));
1094 /* ??? Obviously there are other optimizations we can do
1095 (e.g. sethi+shift for 0x1f0000000) and perhaps we shouldn't be
1096 doing some of these. Later. If you do change things, try to
1097 change all of this to be table driven as well. */
1099 /* What to output depends on the number if it's constant.
1100 Compute that first, then output what we've decided upon. */
1101 if (the_insn
.exp
.X_op
!= O_constant
)
1103 if (sparc_arch_size
== 32)
1105 /* When arch size is 32, we want setx to be equivalent
1106 to setuw for anything but constants. */
1107 the_insn
.exp
.X_add_number
&= 0xffffffff;
1108 special_case
= SPECIAL_CASE_SET
;
1111 need_hh22_p
= need_hm10_p
= need_hi22_p
= need_lo10_p
= 1;
1112 lower32
= 0; upper32
= 0;
1116 /* Reset X_add_number, we've extracted it as upper32/lower32.
1117 Otherwise fixup_segment will complain about not being able to
1118 write an 8 byte number in a 4 byte field. */
1119 the_insn
.exp
.X_add_number
= 0;
1121 /* Only need hh22 if `or' insn can't handle constant. */
1122 if (upper32
< -(1 << 12) || upper32
>= (1 << 12))
1125 /* Does bottom part (after sethi) have bits? */
1126 if ((need_hh22_p
&& (upper32
& 0x3ff) != 0)
1127 /* No hh22, but does upper32 still have bits we can't set
1129 || (! need_hh22_p
&& upper32
!= 0 && upper32
!= -1))
1132 /* If the lower half is all zero, we build the upper half directly
1133 into the dst reg. */
1135 /* Need lower half if number is zero or 0xffffffff00000000. */
1136 || (! need_hh22_p
&& ! need_hm10_p
))
1138 /* No need for sethi if `or' insn can handle constant. */
1139 if (lower32
< -(1 << 12) || lower32
>= (1 << 12)
1140 /* Note that we can't use a negative constant in the `or'
1141 insn unless the upper 32 bits are all ones. */
1142 || (lower32
< 0 && upper32
!= -1)
1143 || (lower32
>= 0 && upper32
== -1))
1146 if (need_hi22_p
&& upper32
== -1)
1148 /* Does bottom part (after sethi) have bits? */
1149 else if ((need_hi22_p
&& (lower32
& 0x3ff) != 0)
1151 || (! need_hi22_p
&& (lower32
& 0x1fff) != 0)
1152 /* Need `or' if we didn't set anything else. */
1153 || (! need_hi22_p
&& ! need_hh22_p
&& ! need_hm10_p
))
1157 /* Output directly to dst reg if lower 32 bits are all
1159 upper_dstreg
= dstreg
;
1164 the_insn
.opcode
= (SETHI_INSN
| RD (upper_dstreg
)
1165 | ((upper32
>> 10) & 0x3fffff));
1166 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1167 ? BFD_RELOC_SPARC_HH22
: BFD_RELOC_NONE
);
1168 output_insn (insn
, &the_insn
);
1173 the_insn
.opcode
= (SETHI_INSN
| RD (dstreg
)
1174 | (((need_xor10_p
? ~lower32
: lower32
)
1175 >> 10) & 0x3fffff));
1176 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1177 ? BFD_RELOC_SPARC_LM22
: BFD_RELOC_NONE
);
1178 output_insn (insn
, &the_insn
);
1183 the_insn
.opcode
= (OR_INSN
1184 | (need_hh22_p
? RS1 (upper_dstreg
) : 0)
1188 & (need_hh22_p
? 0x3ff : 0x1fff)));
1189 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1190 ? BFD_RELOC_SPARC_HM10
: BFD_RELOC_NONE
);
1191 output_insn (insn
, &the_insn
);
1196 /* FIXME: One nice optimization to do here is to OR the low part
1197 with the highpart if hi22 isn't needed and the low part is
1199 the_insn
.opcode
= (OR_INSN
| (need_hi22_p
? RS1 (dstreg
) : 0)
1203 & (need_hi22_p
? 0x3ff : 0x1fff)));
1204 the_insn
.reloc
= BFD_RELOC_LO10
;
1205 output_insn (insn
, &the_insn
);
1208 /* If we needed to build the upper part, shift it into place. */
1209 if (need_hh22_p
|| need_hm10_p
)
1211 the_insn
.opcode
= (SLLX_INSN
| RS1 (upper_dstreg
) | RD (upper_dstreg
)
1213 the_insn
.reloc
= BFD_RELOC_NONE
;
1214 output_insn (insn
, &the_insn
);
1217 /* To get -1 in upper32, we do sethi %hi(~x), r; xor r, -0x400 | x, r. */
1220 the_insn
.opcode
= (XOR_INSN
| RS1 (dstreg
) | RD (dstreg
) | IMMED
1221 | 0x1c00 | (lower32
& 0x3ff));
1222 the_insn
.reloc
= BFD_RELOC_NONE
;
1223 output_insn (insn
, &the_insn
);
1225 /* If we needed to build both upper and lower parts, OR them together. */
1226 else if ((need_hh22_p
|| need_hm10_p
)
1227 && (need_hi22_p
|| need_lo10_p
))
1229 the_insn
.opcode
= (OR_INSN
| RS1 (dstreg
) | RS2 (upper_dstreg
)
1231 the_insn
.reloc
= BFD_RELOC_NONE
;
1232 output_insn (insn
, &the_insn
);
1237 case SPECIAL_CASE_FDIV
:
1239 int rd
= (the_insn
.opcode
>> 25) & 0x1f;
1241 output_insn (insn
, &the_insn
);
1243 /* According to information leaked from Sun, the "fdiv" instructions
1244 on early SPARC machines would produce incorrect results sometimes.
1245 The workaround is to add an fmovs of the destination register to
1246 itself just after the instruction. This was true on machines
1247 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
1248 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
1249 the_insn
.opcode
= FMOVS_INSN
| rd
| RD (rd
);
1250 output_insn (insn
, &the_insn
);
1255 as_fatal (_("failed special case insn sanity check"));
1260 /* Subroutine of md_assemble to do the actual parsing. */
1263 sparc_ip (str
, pinsn
)
1265 const struct sparc_opcode
**pinsn
;
1267 char *error_message
= "";
1271 const struct sparc_opcode
*insn
;
1273 unsigned long opcode
;
1274 unsigned int mask
= 0;
1280 if (islower ((unsigned char) *s
))
1284 while (islower ((unsigned char) *s
) || isdigit ((unsigned char) *s
));
1302 as_fatal (_("Unknown opcode: `%s'"), str
);
1304 insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
);
1308 as_bad (_("Unknown opcode: `%s'"), str
);
1319 opcode
= insn
->match
;
1320 memset (&the_insn
, '\0', sizeof (the_insn
));
1321 the_insn
.reloc
= BFD_RELOC_NONE
;
1325 * Build the opcode, checking as we go to make
1326 * sure that the operands match
1328 for (args
= insn
->args
;; ++args
)
1336 /* Parse a series of masks. */
1343 if (! parse_keyword_arg (sparc_encode_membar
, &s
,
1346 error_message
= _(": invalid membar mask name");
1350 while (*s
== ' ') { ++s
; continue; }
1351 if (*s
== '|' || *s
== '+')
1353 while (*s
== ' ') { ++s
; continue; }
1358 if (! parse_const_expr_arg (&s
, &kmask
))
1360 error_message
= _(": invalid membar mask expression");
1363 if (kmask
< 0 || kmask
> 127)
1365 error_message
= _(": invalid membar mask number");
1370 opcode
|= MEMBAR (kmask
);
1378 /* Parse a prefetch function. */
1381 if (! parse_keyword_arg (sparc_encode_prefetch
, &s
, &fcn
))
1383 error_message
= _(": invalid prefetch function name");
1389 if (! parse_const_expr_arg (&s
, &fcn
))
1391 error_message
= _(": invalid prefetch function expression");
1394 if (fcn
< 0 || fcn
> 31)
1396 error_message
= _(": invalid prefetch function number");
1406 /* Parse a sparc64 privileged register. */
1409 struct priv_reg_entry
*p
= priv_reg_table
;
1410 unsigned int len
= 9999999; /* init to make gcc happy */
1413 while (p
->name
[0] > s
[0])
1415 while (p
->name
[0] == s
[0])
1417 len
= strlen (p
->name
);
1418 if (strncmp (p
->name
, s
, len
) == 0)
1422 if (p
->name
[0] != s
[0])
1424 error_message
= _(": unrecognizable privileged register");
1428 opcode
|= (p
->regnum
<< 14);
1430 opcode
|= (p
->regnum
<< 25);
1436 error_message
= _(": unrecognizable privileged register");
1442 /* Parse a v9a ancillary state register. */
1445 struct priv_reg_entry
*p
= v9a_asr_table
;
1446 unsigned int len
= 9999999; /* init to make gcc happy */
1449 while (p
->name
[0] > s
[0])
1451 while (p
->name
[0] == s
[0])
1453 len
= strlen (p
->name
);
1454 if (strncmp (p
->name
, s
, len
) == 0)
1458 if (p
->name
[0] != s
[0])
1460 error_message
= _(": unrecognizable v9a ancillary state register");
1463 if (*args
== '/' && (p
->regnum
== 20 || p
->regnum
== 21))
1465 error_message
= _(": rd on write only ancillary state register");
1469 opcode
|= (p
->regnum
<< 14);
1471 opcode
|= (p
->regnum
<< 25);
1477 error_message
= _(": unrecognizable v9a ancillary state register");
1483 if (strncmp (s
, "%asr", 4) == 0)
1487 if (isdigit ((unsigned char) *s
))
1491 while (isdigit ((unsigned char) *s
))
1493 num
= num
* 10 + *s
- '0';
1497 if (current_architecture
>= SPARC_OPCODE_ARCH_V9
)
1499 if (num
< 16 || 31 < num
)
1501 error_message
= _(": asr number must be between 16 and 31");
1507 if (num
< 0 || 31 < num
)
1509 error_message
= _(": asr number must be between 0 and 31");
1514 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
1519 error_message
= _(": expecting %asrN");
1526 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1530 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1534 /* V8 systems don't understand BFD_RELOC_SPARC_5. */
1535 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1536 the_insn
.reloc
= BFD_RELOC_SPARC_5
;
1538 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1539 /* These fields are unsigned, but for upward compatibility,
1540 allow negative values as well. */
1544 /* V8 systems don't understand BFD_RELOC_SPARC_6. */
1545 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1546 the_insn
.reloc
= BFD_RELOC_SPARC_6
;
1548 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1549 /* These fields are unsigned, but for upward compatibility,
1550 allow negative values as well. */
1554 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1559 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1564 if (*s
== 'p' && s
[1] == 'n')
1572 if (*s
== 'p' && s
[1] == 't')
1584 if (strncmp (s
, "%icc", 4) == 0)
1596 if (strncmp (s
, "%xcc", 4) == 0)
1608 if (strncmp (s
, "%fcc0", 5) == 0)
1620 if (strncmp (s
, "%fcc1", 5) == 0)
1632 if (strncmp (s
, "%fcc2", 5) == 0)
1644 if (strncmp (s
, "%fcc3", 5) == 0)
1652 if (strncmp (s
, "%pc", 3) == 0)
1660 if (strncmp (s
, "%tick", 5) == 0)
1667 case '\0': /* end of args */
1686 case '[': /* these must match exactly */
1694 case '#': /* must be at least one digit */
1695 if (isdigit ((unsigned char) *s
++))
1697 while (isdigit ((unsigned char) *s
))
1705 case 'C': /* coprocessor state register */
1706 if (strncmp (s
, "%csr", 4) == 0)
1713 case 'b': /* next operand is a coprocessor register */
1716 if (*s
++ == '%' && *s
++ == 'c' && isdigit ((unsigned char) *s
))
1719 if (isdigit ((unsigned char) *s
))
1721 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1735 opcode
|= mask
<< 14;
1743 opcode
|= mask
<< 25;
1749 case 'r': /* next operand must be a register */
1759 case 'f': /* frame pointer */
1767 case 'g': /* global register */
1768 if (isoctal (c
= *s
++))
1775 case 'i': /* in register */
1776 if (isoctal (c
= *s
++))
1778 mask
= c
- '0' + 24;
1783 case 'l': /* local register */
1784 if (isoctal (c
= *s
++))
1786 mask
= (c
- '0' + 16);
1791 case 'o': /* out register */
1792 if (isoctal (c
= *s
++))
1794 mask
= (c
- '0' + 8);
1799 case 's': /* stack pointer */
1807 case 'r': /* any register */
1808 if (!isdigit ((unsigned char) (c
= *s
++)))
1823 if (isdigit ((unsigned char) *s
))
1825 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1841 /* Got the register, now figure out where
1842 it goes in the opcode. */
1846 opcode
|= mask
<< 14;
1854 opcode
|= mask
<< 25;
1858 opcode
|= (mask
<< 25) | (mask
<< 14);
1862 opcode
|= (mask
<< 25) | (mask
<< 0);
1868 case 'e': /* next operand is a floating point register */
1883 && ((format
= *s
) == 'f')
1884 && isdigit ((unsigned char) *++s
))
1886 for (mask
= 0; isdigit ((unsigned char) *s
); ++s
)
1888 mask
= 10 * mask
+ (*s
- '0');
1889 } /* read the number */
1897 } /* register must be even numbered */
1905 } /* register must be multiple of 4 */
1909 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1910 error_message
= _(": There are only 64 f registers; [0-63]");
1912 error_message
= _(": There are only 32 f registers; [0-31]");
1915 else if (mask
>= 32)
1917 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1920 mask
-= 31; /* wrap high bit */
1924 error_message
= _(": There are only 32 f registers; [0-31]");
1932 } /* if not an 'f' register. */
1939 opcode
|= RS1 (mask
);
1946 opcode
|= RS2 (mask
);
1952 opcode
|= RD (mask
);
1961 if (strncmp (s
, "%fsr", 4) == 0)
1968 case '0': /* 64 bit immediate (set, setsw, setx insn) */
1969 the_insn
.reloc
= BFD_RELOC_NONE
; /* reloc handled elsewhere */
1972 case 'l': /* 22 bit PC relative immediate */
1973 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
1977 case 'L': /* 30 bit immediate */
1978 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
1983 case 'n': /* 22 bit immediate */
1984 the_insn
.reloc
= BFD_RELOC_SPARC22
;
1987 case 'i': /* 13 bit immediate */
1988 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1998 char *op_arg
= NULL
;
2000 bfd_reloc_code_real_type old_reloc
= the_insn
.reloc
;
2002 /* Check for %hi, etc. */
2005 static const struct ops
{
2006 /* The name as it appears in assembler. */
2008 /* strlen (name), precomputed for speed */
2010 /* The reloc this pseudo-op translates to. */
2012 /* Non-zero if for v9 only. */
2014 /* Non-zero if can be used in pc-relative contexts. */
2015 int pcrel_p
;/*FIXME:wip*/
2017 /* hix/lox must appear before hi/lo so %hix won't be
2018 mistaken for %hi. */
2019 { "hix", 3, BFD_RELOC_SPARC_HIX22
, 1, 0 },
2020 { "lox", 3, BFD_RELOC_SPARC_LOX10
, 1, 0 },
2021 { "hi", 2, BFD_RELOC_HI22
, 0, 1 },
2022 { "lo", 2, BFD_RELOC_LO10
, 0, 1 },
2023 { "hh", 2, BFD_RELOC_SPARC_HH22
, 1, 1 },
2024 { "hm", 2, BFD_RELOC_SPARC_HM10
, 1, 1 },
2025 { "lm", 2, BFD_RELOC_SPARC_LM22
, 1, 1 },
2026 { "h44", 3, BFD_RELOC_SPARC_H44
, 1, 0 },
2027 { "m44", 3, BFD_RELOC_SPARC_M44
, 1, 0 },
2028 { "l44", 3, BFD_RELOC_SPARC_L44
, 1, 0 },
2029 { "uhi", 3, BFD_RELOC_SPARC_HH22
, 1, 0 },
2030 { "ulo", 3, BFD_RELOC_SPARC_HM10
, 1, 0 },
2033 const struct ops
*o
;
2035 for (o
= ops
; o
->name
; o
++)
2036 if (strncmp (s
+ 1, o
->name
, o
->len
) == 0)
2038 if (o
->name
== NULL
)
2041 if (s
[o
->len
+ 1] != '(')
2043 as_bad (_("Illegal operands: %%%s requires arguments in ()"), o
->name
);
2048 the_insn
.reloc
= o
->reloc
;
2053 /* Note that if the get_expression() fails, we will still
2054 have created U entries in the symbol table for the
2055 'symbols' in the input string. Try not to create U
2056 symbols for registers, etc. */
2058 /* This stuff checks to see if the expression ends in
2059 +%reg. If it does, it removes the register from
2060 the expression, and re-sets 's' to point to the
2067 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++)
2070 else if (*s1
== ')')
2079 as_bad (_("Illegal operands: %%%s requires arguments in ()"), op_arg
);
2084 (void) get_expression (s
);
2087 if (*s
== ',' || *s
== ']' || !*s
)
2089 if (*s
!= '+' && *s
!= '-')
2091 as_bad (_("Illegal operands: Can't do arithmetics other than + and - involving %%%s()"), op_arg
);
2096 op_exp
= the_insn
.exp
;
2097 memset (&the_insn
.exp
, 0, sizeof(the_insn
.exp
));
2100 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++) ;
2102 if (s1
!= s
&& isdigit ((unsigned char) s1
[-1]))
2104 if (s1
[-2] == '%' && s1
[-3] == '+')
2106 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
2113 (void) get_expression (s
);
2125 (void) get_expression (s
);
2133 the_insn
.exp2
= the_insn
.exp
;
2134 the_insn
.exp
= op_exp
;
2135 if (the_insn
.exp2
.X_op
== O_absent
)
2136 the_insn
.exp2
.X_op
= O_illegal
;
2137 else if (the_insn
.exp
.X_op
== O_absent
)
2139 the_insn
.exp
= the_insn
.exp2
;
2140 the_insn
.exp2
.X_op
= O_illegal
;
2142 else if (the_insn
.exp
.X_op
== O_constant
)
2144 valueT val
= the_insn
.exp
.X_add_number
;
2145 switch (the_insn
.reloc
)
2147 case BFD_RELOC_SPARC_HH22
:
2148 val
= BSR (val
, 32);
2149 /* intentional fallthrough */
2151 case BFD_RELOC_SPARC_LM22
:
2152 case BFD_RELOC_HI22
:
2153 val
= (val
>> 10) & 0x3fffff;
2156 case BFD_RELOC_SPARC_HM10
:
2157 val
= BSR (val
, 32);
2158 /* intentional fallthrough */
2160 case BFD_RELOC_LO10
:
2164 case BFD_RELOC_SPARC_H44
:
2169 case BFD_RELOC_SPARC_M44
:
2174 case BFD_RELOC_SPARC_L44
:
2178 case BFD_RELOC_SPARC_HIX22
:
2180 val
= (val
>> 10) & 0x3fffff;
2183 case BFD_RELOC_SPARC_LOX10
:
2184 val
= (val
& 0x3ff) | 0x1c00;
2187 the_insn
.exp
= the_insn
.exp2
;
2188 the_insn
.exp
.X_add_number
+= val
;
2189 the_insn
.exp2
.X_op
= O_illegal
;
2190 the_insn
.reloc
= old_reloc
;
2192 else if (the_insn
.exp2
.X_op
!= O_constant
)
2194 as_bad (_("Illegal operands: Can't add non-constant expression to %%%s()"), op_arg
);
2199 if (1 || old_reloc
!= BFD_RELOC_SPARC13
2200 || the_insn
.reloc
!= BFD_RELOC_LO10
2201 || sparc_arch_size
!= 64
2204 as_bad (_("Illegal operands: Can't do arithmetics involving %%%s() of a relocatable symbol"), op_arg
);
2207 the_insn
.reloc
= BFD_RELOC_SPARC_OLO10
;
2211 /* Check for constants that don't require emitting a reloc. */
2212 if (the_insn
.exp
.X_op
== O_constant
2213 && the_insn
.exp
.X_add_symbol
== 0
2214 && the_insn
.exp
.X_op_symbol
== 0)
2216 /* For pc-relative call instructions, we reject
2217 constants to get better code. */
2219 && the_insn
.reloc
== BFD_RELOC_32_PCREL_S2
2220 && in_signed_range (the_insn
.exp
.X_add_number
, 0x3fff))
2222 error_message
= _(": PC-relative operand can't be a constant");
2226 /* Constants that won't fit are checked in md_apply_fix3
2227 and bfd_install_relocation.
2228 ??? It would be preferable to install the constants
2229 into the insn here and save having to create a fixS
2230 for each one. There already exists code to handle
2231 all the various cases (e.g. in md_apply_fix3 and
2232 bfd_install_relocation) so duplicating all that code
2233 here isn't right. */
2253 if (! parse_keyword_arg (sparc_encode_asi
, &s
, &asi
))
2255 error_message
= _(": invalid ASI name");
2261 if (! parse_const_expr_arg (&s
, &asi
))
2263 error_message
= _(": invalid ASI expression");
2266 if (asi
< 0 || asi
> 255)
2268 error_message
= _(": invalid ASI number");
2272 opcode
|= ASI (asi
);
2274 } /* alternate space */
2277 if (strncmp (s
, "%psr", 4) == 0)
2284 case 'q': /* floating point queue */
2285 if (strncmp (s
, "%fq", 3) == 0)
2292 case 'Q': /* coprocessor queue */
2293 if (strncmp (s
, "%cq", 3) == 0)
2301 if (strcmp (str
, "set") == 0
2302 || strcmp (str
, "setuw") == 0)
2304 special_case
= SPECIAL_CASE_SET
;
2307 else if (strcmp (str
, "setsw") == 0)
2309 special_case
= SPECIAL_CASE_SETSW
;
2312 else if (strcmp (str
, "setx") == 0)
2314 special_case
= SPECIAL_CASE_SETX
;
2317 else if (strncmp (str
, "fdiv", 4) == 0)
2319 special_case
= SPECIAL_CASE_FDIV
;
2325 if (strncmp (s
, "%asi", 4) != 0)
2331 if (strncmp (s
, "%fprs", 5) != 0)
2337 if (strncmp (s
, "%ccr", 4) != 0)
2343 if (strncmp (s
, "%tbr", 4) != 0)
2349 if (strncmp (s
, "%wim", 4) != 0)
2356 char *push
= input_line_pointer
;
2359 input_line_pointer
= s
;
2361 if (e
.X_op
== O_constant
)
2363 int n
= e
.X_add_number
;
2364 if (n
!= e
.X_add_number
|| (n
& ~0x1ff) != 0)
2365 as_bad (_("OPF immediate operand out of range (0-0x1ff)"));
2367 opcode
|= e
.X_add_number
<< 5;
2370 as_bad (_("non-immediate OPF operand, ignored"));
2371 s
= input_line_pointer
;
2372 input_line_pointer
= push
;
2377 if (strncmp (s
, "%y", 2) != 0)
2385 /* Parse a sparclet cpreg. */
2387 if (! parse_keyword_arg (sparc_encode_sparclet_cpreg
, &s
, &cpreg
))
2389 error_message
= _(": invalid cpreg name");
2392 opcode
|= (*args
== 'U' ? RS1 (cpreg
) : RD (cpreg
));
2397 as_fatal (_("failed sanity check."));
2398 } /* switch on arg code */
2400 /* Break out of for() loop. */
2402 } /* for each arg that we expect */
2407 /* Args don't match. */
2408 if (&insn
[1] - sparc_opcodes
< sparc_num_opcodes
2409 && (insn
->name
== insn
[1].name
2410 || !strcmp (insn
->name
, insn
[1].name
)))
2418 as_bad (_("Illegal operands%s"), error_message
);
2424 /* We have a match. Now see if the architecture is ok. */
2425 int needed_arch_mask
= insn
->architecture
;
2429 needed_arch_mask
&= ~ ((1 << SPARC_OPCODE_ARCH_V9
)
2430 | (1 << SPARC_OPCODE_ARCH_V9A
));
2431 needed_arch_mask
|= (1 << SPARC_OPCODE_ARCH_V9
);
2434 if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (current_architecture
))
2436 /* Can we bump up the architecture? */
2437 else if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (max_architecture
))
2439 enum sparc_opcode_arch_val needed_architecture
=
2440 sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture
)
2441 & needed_arch_mask
);
2443 assert (needed_architecture
<= SPARC_OPCODE_ARCH_MAX
);
2445 && needed_architecture
> warn_after_architecture
)
2447 as_warn (_("architecture bumped from \"%s\" to \"%s\" on \"%s\""),
2448 sparc_opcode_archs
[current_architecture
].name
,
2449 sparc_opcode_archs
[needed_architecture
].name
,
2451 warn_after_architecture
= needed_architecture
;
2453 current_architecture
= needed_architecture
;
2456 /* ??? This seems to be a bit fragile. What if the next entry in
2457 the opcode table is the one we want and it is supported?
2458 It is possible to arrange the table today so that this can't
2459 happen but what about tomorrow? */
2462 int arch
,printed_one_p
= 0;
2464 char required_archs
[SPARC_OPCODE_ARCH_MAX
* 16];
2466 /* Create a list of the architectures that support the insn. */
2467 needed_arch_mask
&= ~ SPARC_OPCODE_SUPPORTED (max_architecture
);
2469 arch
= sparc_ffs (needed_arch_mask
);
2470 while ((1 << arch
) <= needed_arch_mask
)
2472 if ((1 << arch
) & needed_arch_mask
)
2476 strcpy (p
, sparc_opcode_archs
[arch
].name
);
2483 as_bad (_("Architecture mismatch on \"%s\"."), str
);
2484 as_tsktsk (_(" (Requires %s; requested architecture is %s.)"),
2486 sparc_opcode_archs
[max_architecture
].name
);
2492 } /* forever looking for a match */
2494 the_insn
.opcode
= opcode
;
2497 /* Parse an argument that can be expressed as a keyword.
2498 (eg: #StoreStore or %ccfr).
2499 The result is a boolean indicating success.
2500 If successful, INPUT_POINTER is updated. */
2503 parse_keyword_arg (lookup_fn
, input_pointerP
, valueP
)
2504 int (*lookup_fn
) PARAMS ((const char *));
2505 char **input_pointerP
;
2511 p
= *input_pointerP
;
2512 for (q
= p
+ (*p
== '#' || *p
== '%');
2513 isalnum ((unsigned char) *q
) || *q
== '_';
2518 value
= (*lookup_fn
) (p
);
2523 *input_pointerP
= q
;
2527 /* Parse an argument that is a constant expression.
2528 The result is a boolean indicating success. */
2531 parse_const_expr_arg (input_pointerP
, valueP
)
2532 char **input_pointerP
;
2535 char *save
= input_line_pointer
;
2538 input_line_pointer
= *input_pointerP
;
2539 /* The next expression may be something other than a constant
2540 (say if we're not processing the right variant of the insn).
2541 Don't call expression unless we're sure it will succeed as it will
2542 signal an error (which we want to defer until later). */
2543 /* FIXME: It might be better to define md_operand and have it recognize
2544 things like %asi, etc. but continuing that route through to the end
2545 is a lot of work. */
2546 if (*input_line_pointer
== '%')
2548 input_line_pointer
= save
;
2552 *input_pointerP
= input_line_pointer
;
2553 input_line_pointer
= save
;
2554 if (exp
.X_op
!= O_constant
)
2556 *valueP
= exp
.X_add_number
;
2560 /* Subroutine of sparc_ip to parse an expression. */
2563 get_expression (str
)
2569 save_in
= input_line_pointer
;
2570 input_line_pointer
= str
;
2571 seg
= expression (&the_insn
.exp
);
2572 if (seg
!= absolute_section
2573 && seg
!= text_section
2574 && seg
!= data_section
2575 && seg
!= bss_section
2576 && seg
!= undefined_section
)
2578 the_insn
.error
= _("bad segment");
2579 expr_end
= input_line_pointer
;
2580 input_line_pointer
= save_in
;
2583 expr_end
= input_line_pointer
;
2584 input_line_pointer
= save_in
;
2588 /* Subroutine of md_assemble to output one insn. */
2591 output_insn (insn
, the_insn
)
2592 const struct sparc_opcode
*insn
;
2593 struct sparc_it
*the_insn
;
2595 char *toP
= frag_more (4);
2597 /* put out the opcode */
2598 if (INSN_BIG_ENDIAN
)
2599 number_to_chars_bigendian (toP
, (valueT
) the_insn
->opcode
, 4);
2601 number_to_chars_littleendian (toP
, (valueT
) the_insn
->opcode
, 4);
2603 /* put out the symbol-dependent stuff */
2604 if (the_insn
->reloc
!= BFD_RELOC_NONE
)
2606 fixS
*fixP
= fix_new_exp (frag_now
, /* which frag */
2607 (toP
- frag_now
->fr_literal
), /* where */
2612 /* Turn off overflow checking in fixup_segment. We'll do our
2613 own overflow checking in md_apply_fix3. This is necessary because
2614 the insn size is 4 and fixup_segment will signal an overflow for
2615 large 8 byte quantities. */
2616 fixP
->fx_no_overflow
= 1;
2620 last_opcode
= the_insn
->opcode
;
2624 This is identical to the md_atof in m68k.c. I think this is right,
2627 Turn a string in input_line_pointer into a floating point constant of type
2628 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2629 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2632 /* Equal to MAX_PRECISION in atof-ieee.c */
2633 #define MAX_LITTLENUMS 6
2636 md_atof (type
, litP
, sizeP
)
2642 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2673 return _("Bad call to MD_ATOF()");
2676 t
= atof_ieee (input_line_pointer
, type
, words
);
2678 input_line_pointer
= t
;
2679 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2681 if (target_big_endian
)
2683 for (i
= 0; i
< prec
; i
++)
2685 md_number_to_chars (litP
, (valueT
) words
[i
], sizeof (LITTLENUM_TYPE
));
2686 litP
+= sizeof (LITTLENUM_TYPE
);
2691 for (i
= prec
- 1; i
>= 0; i
--)
2693 md_number_to_chars (litP
, (valueT
) words
[i
], sizeof (LITTLENUM_TYPE
));
2694 litP
+= sizeof (LITTLENUM_TYPE
);
2701 /* Write a value out to the object file, using the appropriate
2705 md_number_to_chars (buf
, val
, n
)
2710 if (target_big_endian
)
2711 number_to_chars_bigendian (buf
, val
, n
);
2712 else if (target_little_endian_data
2713 && ((n
== 4 || n
== 2) && ~now_seg
->flags
& SEC_ALLOC
))
2714 /* Output debug words, which are not in allocated sections, as big endian */
2715 number_to_chars_bigendian (buf
, val
, n
);
2716 else if (target_little_endian_data
|| ! target_big_endian
)
2717 number_to_chars_littleendian (buf
, val
, n
);
2720 /* Apply a fixS to the frags, now that we know the value it ought to
2724 md_apply_fix3 (fixP
, value
, segment
)
2729 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2735 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
2737 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
2740 /* FIXME: SPARC ELF relocations don't use an addend in the data
2741 field itself. This whole approach should be somehow combined
2742 with the calls to bfd_install_relocation. Also, the value passed
2743 in by fixup_segment includes the value of a defined symbol. We
2744 don't want to include the value of an externally visible symbol. */
2745 if (fixP
->fx_addsy
!= NULL
)
2747 if (symbol_used_in_reloc_p (fixP
->fx_addsy
)
2748 && (S_IS_EXTERNAL (fixP
->fx_addsy
)
2749 || S_IS_WEAK (fixP
->fx_addsy
)
2750 || (sparc_pic_code
&& ! fixP
->fx_pcrel
)
2751 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
2752 && ((bfd_get_section_flags (stdoutput
,
2753 S_GET_SEGMENT (fixP
->fx_addsy
))
2754 & SEC_LINK_ONCE
) != 0
2755 || strncmp (segment_name (S_GET_SEGMENT (fixP
->fx_addsy
)),
2757 sizeof ".gnu.linkonce" - 1) == 0)))
2758 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
2759 && S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
2760 && ! bfd_is_com_section (S_GET_SEGMENT (fixP
->fx_addsy
)))
2761 fixP
->fx_addnumber
-= S_GET_VALUE (fixP
->fx_addsy
);
2766 /* This is a hack. There should be a better way to
2767 handle this. Probably in terms of howto fields, once
2768 we can look at these fixups in terms of howtos. */
2769 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
2770 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2773 /* FIXME: More ridiculous gas reloc hacking. If we are going to
2774 generate a reloc, then we just want to let the reloc addend set
2775 the value. We do not want to also stuff the addend into the
2776 object file. Including the addend in the object file works when
2777 doing a static link, because the linker will ignore the object
2778 file contents. However, the dynamic linker does not ignore the
2779 object file contents. */
2780 if (fixP
->fx_addsy
!= NULL
2781 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
)
2784 /* When generating PIC code, we do not want an addend for a reloc
2785 against a local symbol. We adjust fx_addnumber to cancel out the
2786 value already included in val, and to also cancel out the
2787 adjustment which bfd_install_relocation will create. */
2789 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
2790 && fixP
->fx_addsy
!= NULL
2791 && ! S_IS_COMMON (fixP
->fx_addsy
)
2792 && symbol_section_p (fixP
->fx_addsy
))
2793 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
2795 /* When generating PIC code, we need to fiddle to get
2796 bfd_install_relocation to do the right thing for a PC relative
2797 reloc against a local symbol which we are going to keep. */
2799 && fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
2800 && fixP
->fx_addsy
!= NULL
2801 && (S_IS_EXTERNAL (fixP
->fx_addsy
)
2802 || S_IS_WEAK (fixP
->fx_addsy
))
2803 && S_IS_DEFINED (fixP
->fx_addsy
)
2804 && ! S_IS_COMMON (fixP
->fx_addsy
))
2807 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
2811 /* If this is a data relocation, just output VAL. */
2813 if (fixP
->fx_r_type
== BFD_RELOC_16
)
2815 md_number_to_chars (buf
, val
, 2);
2817 else if (fixP
->fx_r_type
== BFD_RELOC_32
2818 || fixP
->fx_r_type
== BFD_RELOC_SPARC_REV32
)
2820 md_number_to_chars (buf
, val
, 4);
2822 else if (fixP
->fx_r_type
== BFD_RELOC_64
)
2824 md_number_to_chars (buf
, val
, 8);
2826 else if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2827 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2834 /* It's a relocation against an instruction. */
2836 if (INSN_BIG_ENDIAN
)
2837 insn
= bfd_getb32 ((unsigned char *) buf
);
2839 insn
= bfd_getl32 ((unsigned char *) buf
);
2841 switch (fixP
->fx_r_type
)
2843 case BFD_RELOC_32_PCREL_S2
:
2845 /* FIXME: This increment-by-one deserves a comment of why it's
2847 if (! sparc_pic_code
2848 || fixP
->fx_addsy
== NULL
2849 || symbol_section_p (fixP
->fx_addsy
))
2851 insn
|= val
& 0x3fffffff;
2854 case BFD_RELOC_SPARC_11
:
2855 if (! in_signed_range (val
, 0x7ff))
2856 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2857 _("relocation overflow"));
2858 insn
|= val
& 0x7ff;
2861 case BFD_RELOC_SPARC_10
:
2862 if (! in_signed_range (val
, 0x3ff))
2863 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2864 _("relocation overflow"));
2865 insn
|= val
& 0x3ff;
2868 case BFD_RELOC_SPARC_7
:
2869 if (! in_bitfield_range (val
, 0x7f))
2870 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2871 _("relocation overflow"));
2875 case BFD_RELOC_SPARC_6
:
2876 if (! in_bitfield_range (val
, 0x3f))
2877 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2878 _("relocation overflow"));
2882 case BFD_RELOC_SPARC_5
:
2883 if (! in_bitfield_range (val
, 0x1f))
2884 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2885 _("relocation overflow"));
2889 case BFD_RELOC_SPARC_WDISP16
:
2890 /* FIXME: simplify */
2891 if (((val
> 0) && (val
& ~0x3fffc))
2892 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
2893 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2894 _("relocation overflow"));
2895 /* FIXME: The +1 deserves a comment. */
2896 val
= (val
>> 2) + 1;
2897 insn
|= ((val
& 0xc000) << 6) | (val
& 0x3fff);
2900 case BFD_RELOC_SPARC_WDISP19
:
2901 /* FIXME: simplify */
2902 if (((val
> 0) && (val
& ~0x1ffffc))
2903 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
2904 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2905 _("relocation overflow"));
2906 /* FIXME: The +1 deserves a comment. */
2907 val
= (val
>> 2) + 1;
2908 insn
|= val
& 0x7ffff;
2911 case BFD_RELOC_SPARC_HH22
:
2912 val
= BSR (val
, 32);
2913 /* intentional fallthrough */
2915 case BFD_RELOC_SPARC_LM22
:
2916 case BFD_RELOC_HI22
:
2917 if (!fixP
->fx_addsy
)
2919 insn
|= (val
>> 10) & 0x3fffff;
2923 /* FIXME: Need comment explaining why we do this. */
2928 case BFD_RELOC_SPARC22
:
2929 if (val
& ~0x003fffff)
2930 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2931 _("relocation overflow"));
2932 insn
|= (val
& 0x3fffff);
2935 case BFD_RELOC_SPARC_HM10
:
2936 val
= BSR (val
, 32);
2937 /* intentional fallthrough */
2939 case BFD_RELOC_LO10
:
2940 if (!fixP
->fx_addsy
)
2942 insn
|= val
& 0x3ff;
2946 /* FIXME: Need comment explaining why we do this. */
2951 case BFD_RELOC_SPARC13
:
2952 if (! in_signed_range (val
, 0x1fff))
2953 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2954 _("relocation overflow"));
2955 insn
|= val
& 0x1fff;
2958 case BFD_RELOC_SPARC_WDISP22
:
2959 val
= (val
>> 2) + 1;
2961 case BFD_RELOC_SPARC_BASE22
:
2962 insn
|= val
& 0x3fffff;
2965 case BFD_RELOC_SPARC_H44
:
2966 if (!fixP
->fx_addsy
)
2970 insn
|= tval
& 0x3fffff;
2974 case BFD_RELOC_SPARC_M44
:
2975 if (!fixP
->fx_addsy
)
2976 insn
|= (val
>> 12) & 0x3ff;
2979 case BFD_RELOC_SPARC_L44
:
2980 if (!fixP
->fx_addsy
)
2981 insn
|= val
& 0xfff;
2984 case BFD_RELOC_SPARC_HIX22
:
2985 if (!fixP
->fx_addsy
)
2987 val
^= ~ (offsetT
) 0;
2988 insn
|= (val
>> 10) & 0x3fffff;
2992 case BFD_RELOC_SPARC_LOX10
:
2993 if (!fixP
->fx_addsy
)
2994 insn
|= 0x1c00 | (val
& 0x3ff);
2997 case BFD_RELOC_NONE
:
2999 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3000 _("bad or unhandled relocation type: 0x%02x"),
3005 if (INSN_BIG_ENDIAN
)
3006 bfd_putb32 (insn
, (unsigned char *) buf
);
3008 bfd_putl32 (insn
, (unsigned char *) buf
);
3011 /* Are we finished with this relocation now? */
3012 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
3018 /* Translate internal representation of relocation info to BFD target
3021 tc_gen_reloc (section
, fixp
)
3026 bfd_reloc_code_real_type code
;
3028 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3030 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3031 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3032 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3034 switch (fixp
->fx_r_type
)
3038 case BFD_RELOC_HI22
:
3039 case BFD_RELOC_LO10
:
3040 case BFD_RELOC_32_PCREL_S2
:
3041 case BFD_RELOC_SPARC13
:
3042 case BFD_RELOC_SPARC22
:
3043 case BFD_RELOC_SPARC_BASE13
:
3044 case BFD_RELOC_SPARC_WDISP16
:
3045 case BFD_RELOC_SPARC_WDISP19
:
3046 case BFD_RELOC_SPARC_WDISP22
:
3048 case BFD_RELOC_SPARC_5
:
3049 case BFD_RELOC_SPARC_6
:
3050 case BFD_RELOC_SPARC_7
:
3051 case BFD_RELOC_SPARC_10
:
3052 case BFD_RELOC_SPARC_11
:
3053 case BFD_RELOC_SPARC_HH22
:
3054 case BFD_RELOC_SPARC_HM10
:
3055 case BFD_RELOC_SPARC_LM22
:
3056 case BFD_RELOC_SPARC_PC_HH22
:
3057 case BFD_RELOC_SPARC_PC_HM10
:
3058 case BFD_RELOC_SPARC_PC_LM22
:
3059 case BFD_RELOC_SPARC_H44
:
3060 case BFD_RELOC_SPARC_M44
:
3061 case BFD_RELOC_SPARC_L44
:
3062 case BFD_RELOC_SPARC_HIX22
:
3063 case BFD_RELOC_SPARC_LOX10
:
3064 case BFD_RELOC_SPARC_REV32
:
3065 case BFD_RELOC_VTABLE_ENTRY
:
3066 case BFD_RELOC_VTABLE_INHERIT
:
3067 code
= fixp
->fx_r_type
;
3074 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
3075 /* If we are generating PIC code, we need to generate a different
3079 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
3081 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
3088 case BFD_RELOC_32_PCREL_S2
:
3089 if (! S_IS_DEFINED (fixp
->fx_addsy
)
3090 || S_IS_COMMON (fixp
->fx_addsy
)
3091 || S_IS_EXTERNAL (fixp
->fx_addsy
)
3092 || S_IS_WEAK (fixp
->fx_addsy
))
3093 code
= BFD_RELOC_SPARC_WPLT30
;
3095 case BFD_RELOC_HI22
:
3096 if (fixp
->fx_addsy
!= NULL
3097 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
3098 code
= BFD_RELOC_SPARC_PC22
;
3100 code
= BFD_RELOC_SPARC_GOT22
;
3102 case BFD_RELOC_LO10
:
3103 if (fixp
->fx_addsy
!= NULL
3104 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
3105 code
= BFD_RELOC_SPARC_PC10
;
3107 code
= BFD_RELOC_SPARC_GOT10
;
3109 case BFD_RELOC_SPARC13
:
3110 code
= BFD_RELOC_SPARC_GOT13
;
3116 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
3118 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3119 if (reloc
->howto
== 0)
3121 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3122 _("internal error: can't export reloc type %d (`%s')"),
3123 fixp
->fx_r_type
, bfd_get_reloc_code_name (code
));
3127 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
3130 if (reloc
->howto
->pc_relative
== 0
3131 || code
== BFD_RELOC_SPARC_PC10
3132 || code
== BFD_RELOC_SPARC_PC22
)
3133 reloc
->addend
= fixp
->fx_addnumber
;
3134 else if (sparc_pic_code
3135 && fixp
->fx_r_type
== BFD_RELOC_32_PCREL_S2
3136 && fixp
->fx_addsy
!= NULL
3137 && (S_IS_EXTERNAL (fixp
->fx_addsy
)
3138 || S_IS_WEAK (fixp
->fx_addsy
))
3139 && S_IS_DEFINED (fixp
->fx_addsy
)
3140 && ! S_IS_COMMON (fixp
->fx_addsy
))
3141 reloc
->addend
= fixp
->fx_addnumber
;
3143 reloc
->addend
= fixp
->fx_offset
- reloc
->address
;
3145 #else /* elf or coff */
3147 if (reloc
->howto
->pc_relative
== 0
3148 || code
== BFD_RELOC_SPARC_PC10
3149 || code
== BFD_RELOC_SPARC_PC22
)
3150 reloc
->addend
= fixp
->fx_addnumber
;
3151 else if (symbol_section_p (fixp
->fx_addsy
))
3152 reloc
->addend
= (section
->vma
3153 + fixp
->fx_addnumber
3154 + md_pcrel_from (fixp
));
3156 reloc
->addend
= fixp
->fx_offset
;
3162 /* We have no need to default values of symbols. */
3166 md_undefined_symbol (name
)
3170 } /* md_undefined_symbol() */
3172 /* Round up a section size to the appropriate boundary. */
3174 md_section_align (segment
, size
)
3179 /* This is not right for ELF; a.out wants it, and COFF will force
3180 the alignment anyways. */
3181 valueT align
= ((valueT
) 1
3182 << (valueT
) bfd_get_section_alignment (stdoutput
, segment
));
3184 /* turn alignment value into a mask */
3186 newsize
= (size
+ align
) & ~align
;
3193 /* Exactly what point is a PC-relative offset relative TO?
3194 On the sparc, they're relative to the address of the offset, plus
3195 its size. This gets us to the following instruction.
3196 (??? Is this right? FIXME-SOON) */
3198 md_pcrel_from (fixP
)
3203 ret
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3204 if (! sparc_pic_code
3205 || fixP
->fx_addsy
== NULL
3206 || symbol_section_p (fixP
->fx_addsy
))
3207 ret
+= fixP
->fx_size
;
3211 /* Return log2 (VALUE), or -1 if VALUE is not an exact positive power
3223 for (shift
= 0; (value
& 1) == 0; value
>>= 1)
3226 return (value
== 1) ? shift
: -1;
3230 * sort of like s_lcomm
3234 static int max_alignment
= 15;
3249 name
= input_line_pointer
;
3250 c
= get_symbol_end ();
3251 p
= input_line_pointer
;
3255 if (*input_line_pointer
!= ',')
3257 as_bad (_("Expected comma after name"));
3258 ignore_rest_of_line ();
3262 ++input_line_pointer
;
3264 if ((size
= get_absolute_expression ()) < 0)
3266 as_bad (_("BSS length (%d.) <0! Ignored."), size
);
3267 ignore_rest_of_line ();
3272 symbolP
= symbol_find_or_make (name
);
3275 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
3276 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
3278 as_bad (_("bad .reserve segment -- expected BSS segment"));
3282 if (input_line_pointer
[2] == '.')
3283 input_line_pointer
+= 7;
3285 input_line_pointer
+= 6;
3288 if (*input_line_pointer
== ',')
3290 ++input_line_pointer
;
3293 if (*input_line_pointer
== '\n')
3295 as_bad (_("missing alignment"));
3296 ignore_rest_of_line ();
3300 align
= (int) get_absolute_expression ();
3303 if (align
> max_alignment
)
3305 align
= max_alignment
;
3306 as_warn (_("alignment too large; assuming %d"), align
);
3312 as_bad (_("negative alignment"));
3313 ignore_rest_of_line ();
3319 temp
= log2 (align
);
3322 as_bad (_("alignment not a power of 2"));
3323 ignore_rest_of_line ();
3330 record_alignment (bss_section
, align
);
3335 if (!S_IS_DEFINED (symbolP
)
3337 && S_GET_OTHER (symbolP
) == 0
3338 && S_GET_DESC (symbolP
) == 0
3345 segT current_seg
= now_seg
;
3346 subsegT current_subseg
= now_subseg
;
3348 subseg_set (bss_section
, 1); /* switch to bss */
3351 frag_align (align
, 0, 0); /* do alignment */
3353 /* detach from old frag */
3354 if (S_GET_SEGMENT(symbolP
) == bss_section
)
3355 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
3357 symbol_set_frag (symbolP
, frag_now
);
3358 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3359 (offsetT
) size
, (char *)0);
3362 S_SET_SEGMENT (symbolP
, bss_section
);
3364 subseg_set (current_seg
, current_subseg
);
3367 S_SET_SIZE (symbolP
, size
);
3373 as_warn("Ignoring attempt to re-define symbol %s",
3374 S_GET_NAME (symbolP
));
3375 } /* if not redefining */
3377 demand_empty_rest_of_line ();
3390 name
= input_line_pointer
;
3391 c
= get_symbol_end ();
3392 /* just after name is now '\0' */
3393 p
= input_line_pointer
;
3396 if (*input_line_pointer
!= ',')
3398 as_bad (_("Expected comma after symbol-name"));
3399 ignore_rest_of_line ();
3402 input_line_pointer
++; /* skip ',' */
3403 if ((temp
= get_absolute_expression ()) < 0)
3405 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
3406 ignore_rest_of_line ();
3411 symbolP
= symbol_find_or_make (name
);
3413 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3415 as_bad (_("Ignoring attempt to re-define symbol"));
3416 ignore_rest_of_line ();
3419 if (S_GET_VALUE (symbolP
) != 0)
3421 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
3423 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
3424 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
3430 S_SET_VALUE (symbolP
, (valueT
) size
);
3431 S_SET_EXTERNAL (symbolP
);
3434 know (symbolP
->sy_frag
== &zero_address_frag
);
3435 if (*input_line_pointer
!= ',')
3437 as_bad (_("Expected comma after common length"));
3438 ignore_rest_of_line ();
3441 input_line_pointer
++;
3443 if (*input_line_pointer
!= '"')
3445 temp
= get_absolute_expression ();
3448 if (temp
> max_alignment
)
3450 temp
= max_alignment
;
3451 as_warn (_("alignment too large; assuming %d"), temp
);
3457 as_bad (_("negative alignment"));
3458 ignore_rest_of_line ();
3463 if (symbol_get_obj (symbolP
)->local
)
3471 old_subsec
= now_subseg
;
3476 align
= log2 (temp
);
3480 as_bad (_("alignment not a power of 2"));
3481 ignore_rest_of_line ();
3485 record_alignment (bss_section
, align
);
3486 subseg_set (bss_section
, 0);
3488 frag_align (align
, 0, 0);
3489 if (S_GET_SEGMENT (symbolP
) == bss_section
)
3490 symbol_get_frag (symbolP
)->fr_symbol
= 0;
3491 symbol_set_frag (symbolP
, frag_now
);
3492 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
3493 (offsetT
) size
, (char *) 0);
3495 S_SET_SEGMENT (symbolP
, bss_section
);
3496 S_CLEAR_EXTERNAL (symbolP
);
3497 S_SET_SIZE (symbolP
, size
);
3498 subseg_set (old_sec
, old_subsec
);
3501 #endif /* OBJ_ELF */
3504 S_SET_VALUE (symbolP
, (valueT
) size
);
3506 S_SET_ALIGN (symbolP
, temp
);
3507 S_SET_SIZE (symbolP
, size
);
3509 S_SET_EXTERNAL (symbolP
);
3510 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
3515 input_line_pointer
++;
3516 /* @@ Some use the dot, some don't. Can we get some consistency?? */
3517 if (*input_line_pointer
== '.')
3518 input_line_pointer
++;
3519 /* @@ Some say data, some say bss. */
3520 if (strncmp (input_line_pointer
, "bss\"", 4)
3521 && strncmp (input_line_pointer
, "data\"", 5))
3523 while (*--input_line_pointer
!= '"')
3525 input_line_pointer
--;
3526 goto bad_common_segment
;
3528 while (*input_line_pointer
++ != '"')
3530 goto allocate_common
;
3533 #ifdef BFD_ASSEMBLER
3534 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
3537 demand_empty_rest_of_line ();
3542 p
= input_line_pointer
;
3543 while (*p
&& *p
!= '\n')
3547 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
3549 input_line_pointer
= p
;
3550 ignore_rest_of_line ();
3555 /* Handle the .empty pseudo-op. This supresses the warnings about
3556 invalid delay slot usage. */
3562 /* The easy way to implement is to just forget about the last
3572 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
3574 input_line_pointer
+= 6;
3578 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
3580 input_line_pointer
+= 6;
3584 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
3586 input_line_pointer
+= 7;
3590 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
3592 input_line_pointer
+= 5;
3593 /* We only support 2 segments -- text and data -- for now, so
3594 things in the "bss segment" will have to go into data for now.
3595 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
3596 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
3599 as_bad (_("Unknown segment type"));
3600 demand_empty_rest_of_line ();
3606 subseg_set (data_section
, 1);
3607 demand_empty_rest_of_line ();
3614 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
3616 ++input_line_pointer
;
3618 ++input_line_pointer
;
3621 /* This static variable is set by s_uacons to tell sparc_cons_align
3622 that the expession does not need to be aligned. */
3624 static int sparc_no_align_cons
= 0;
3626 /* This handles the unaligned space allocation pseudo-ops, such as
3627 .uaword. .uaword is just like .word, but the value does not need
3634 /* Tell sparc_cons_align not to align this value. */
3635 sparc_no_align_cons
= 1;
3639 /* This handles the native word allocation pseudo-op .nword.
3640 For sparc_arch_size 32 it is equivalent to .word, for
3641 sparc_arch_size 64 it is equivalent to .xword. */
3647 cons (sparc_arch_size
== 32 ? 4 : 8);
3650 /* If the --enforce-aligned-data option is used, we require .word,
3651 et. al., to be aligned correctly. We do it by setting up an
3652 rs_align_code frag, and checking in HANDLE_ALIGN to make sure that
3653 no unexpected alignment was introduced.
3655 The SunOS and Solaris native assemblers enforce aligned data by
3656 default. We don't want to do that, because gcc can deliberately
3657 generate misaligned data if the packed attribute is used. Instead,
3658 we permit misaligned data by default, and permit the user to set an
3659 option to check for it. */
3662 sparc_cons_align (nbytes
)
3668 /* Only do this if we are enforcing aligned data. */
3669 if (! enforce_aligned_data
)
3672 if (sparc_no_align_cons
)
3674 /* This is an unaligned pseudo-op. */
3675 sparc_no_align_cons
= 0;
3679 nalign
= log2 (nbytes
);
3683 assert (nalign
> 0);
3685 if (now_seg
== absolute_section
)
3687 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
3688 as_bad (_("misaligned data"));
3692 p
= frag_var (rs_align_code
, 1, 1, (relax_substateT
) 0,
3693 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
3695 record_alignment (now_seg
, nalign
);
3698 /* This is where we do the unexpected alignment check.
3699 This is called from HANDLE_ALIGN in tc-sparc.h. */
3702 sparc_handle_align (fragp
)
3705 if (fragp
->fr_type
== rs_align_code
&& !fragp
->fr_subtype
3706 && fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
!= 0)
3707 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("misaligned data"));
3708 if (fragp
->fr_type
== rs_align_code
&& fragp
->fr_subtype
== 1024)
3710 int count
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
3715 && !((long)(fragp
->fr_literal
+ fragp
->fr_fix
) & 3))
3717 unsigned *p
= (unsigned *)(fragp
->fr_literal
+ fragp
->fr_fix
);
3720 for (i
= 0; i
< count
; i
+= 4, p
++)
3721 if (INSN_BIG_ENDIAN
)
3722 number_to_chars_bigendian ((char *)p
, 0x01000000, 4); /* emit nops */
3724 number_to_chars_littleendian ((char *)p
, 0x10000000, 4);
3726 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
) && count
> 8)
3728 char *waddr
= &fragp
->fr_literal
[fragp
->fr_fix
];
3729 unsigned wval
= (0x30680000 | count
>> 2); /* ba,a,pt %xcc, 1f */
3730 if (INSN_BIG_ENDIAN
)
3731 number_to_chars_bigendian (waddr
, wval
, 4);
3733 number_to_chars_littleendian (waddr
, wval
, 4);
3735 fragp
->fr_var
= count
;
3741 /* Some special processing for a Sparc ELF file. */
3744 sparc_elf_final_processing ()
3746 /* Set the Sparc ELF flag bits. FIXME: There should probably be some
3747 sort of BFD interface for this. */
3748 if (sparc_arch_size
== 64)
3750 switch (sparc_memory_model
)
3753 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARCV9_RMO
;
3756 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARCV9_PSO
;
3762 else if (current_architecture
>= SPARC_OPCODE_ARCH_V9
)
3763 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARC_32PLUS
;
3764 if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
3765 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARC_SUN_US1
;
3769 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
3770 reloc for a cons. We could use the definition there, except that
3771 we want to handle little endian relocs specially. */
3774 cons_fix_new_sparc (frag
, where
, nbytes
, exp
)
3777 unsigned int nbytes
;
3780 bfd_reloc_code_real_type r
;
3782 r
= (nbytes
== 1 ? BFD_RELOC_8
:
3783 (nbytes
== 2 ? BFD_RELOC_16
:
3784 (nbytes
== 4 ? BFD_RELOC_32
: BFD_RELOC_64
)));
3786 if (target_little_endian_data
&& nbytes
== 4
3787 && now_seg
->flags
& SEC_ALLOC
)
3788 r
= BFD_RELOC_SPARC_REV32
;
3789 fix_new_exp (frag
, where
, (int) nbytes
, exp
, 0, r
);
3794 elf32_sparc_force_relocation (fixp
)
3797 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3798 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)