1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989-2016 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 3, 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, 51 Franklin Street - Fifth Floor,
18 Boston, MA 02110-1301, USA. */
21 #include "safe-ctype.h"
24 #include "opcode/sparc.h"
25 #include "dw2gencfi.h"
28 #include "elf/sparc.h"
29 #include "dwarf2dbg.h"
32 /* Some ancient Sun C compilers would not take such hex constants as
33 unsigned, and would end up sign-extending them to form an offsetT,
34 so use these constants instead. */
35 #define U0xffffffff ((((unsigned long) 1 << 16) << 16) - 1)
36 #define U0x80000000 ((((unsigned long) 1 << 16) << 15))
38 static int sparc_ip (char *, const struct sparc_opcode **);
39 static int parse_keyword_arg (int (*) (const char *), char **, int *);
40 static int parse_const_expr_arg (char **, int *);
41 static int get_expression (char *);
43 /* Default architecture. */
44 /* ??? The default value should be V8, but sparclite support was added
45 by making it the default. GCC now passes -Asparclite, so maybe sometime in
46 the future we can set this to V8. */
48 #define DEFAULT_ARCH "sparclite"
50 static const char *default_arch = DEFAULT_ARCH;
52 /* Non-zero if the initial values of `max_architecture' and `sparc_arch_size'
54 static int default_init_p;
56 /* Current architecture. We don't bump up unless necessary. */
57 static enum sparc_opcode_arch_val current_architecture = SPARC_OPCODE_ARCH_V6;
59 /* The maximum architecture level we can bump up to.
60 In a 32 bit environment, don't allow bumping up to v9 by default.
61 The native assembler works this way. The user is required to pass
62 an explicit argument before we'll create v9 object files. However, if
63 we don't see any v9 insns, a v8plus object file is not created. */
64 static enum sparc_opcode_arch_val max_architecture;
66 /* Either 32 or 64, selects file format. */
67 static int sparc_arch_size;
68 /* Initial (default) value, recorded separately in case a user option
69 changes the value before md_show_usage is called. */
70 static int default_arch_size;
73 /* The currently selected v9 memory model. Currently only used for
75 static enum { MM_TSO, MM_PSO, MM_RMO } sparc_memory_model = MM_RMO;
78 /* Bitmask of instruction types seen so far, used to populate the
79 GNU attributes section with hwcap information. */
80 static bfd_uint64_t hwcap_seen;
84 static bfd_uint64_t hwcap_allowed;
86 static int architecture_requested;
87 static int warn_on_bump;
89 /* If warn_on_bump and the needed architecture is higher than this
90 architecture, issue a warning. */
91 static enum sparc_opcode_arch_val warn_after_architecture;
93 /* Non-zero if the assembler should generate error if an undeclared
94 g[23] register has been used in -64. */
95 static int no_undeclared_regs;
97 /* Non-zero if the assembler should generate a warning if an
98 unpredictable DCTI (delayed control transfer instruction) couple is
100 static int dcti_couples_detect;
102 /* Non-zero if we should try to relax jumps and calls. */
103 static int sparc_relax;
105 /* Non-zero if we are generating PIC code. */
108 /* Non-zero if we should give an error when misaligned data is seen. */
109 static int enforce_aligned_data;
111 extern int target_big_endian;
113 static int target_little_endian_data;
115 /* Symbols for global registers on v9. */
116 static symbolS *globals[8];
118 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
119 int sparc_cie_data_alignment;
121 /* V9 and 86x have big and little endian data, but instructions are always big
122 endian. The sparclet has bi-endian support but both data and insns have
123 the same endianness. Global `target_big_endian' is used for data.
124 The following macro is used for instructions. */
125 #ifndef INSN_BIG_ENDIAN
126 #define INSN_BIG_ENDIAN (target_big_endian \
127 || default_arch_type == sparc86x \
128 || SPARC_OPCODE_ARCH_V9_P (max_architecture))
131 /* Handle of the OPCODE hash table. */
132 static struct hash_control *op_hash;
134 static void s_data1 (void);
135 static void s_seg (int);
136 static void s_proc (int);
137 static void s_reserve (int);
138 static void s_common (int);
139 static void s_empty (int);
140 static void s_uacons (int);
141 static void s_ncons (int);
143 static void s_register (int);
146 const pseudo_typeS md_pseudo_table[] =
148 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0). */
149 {"common", s_common, 0},
150 {"empty", s_empty, 0},
151 {"global", s_globl, 0},
153 {"nword", s_ncons, 0},
154 {"optim", s_ignore, 0},
156 {"reserve", s_reserve, 0},
158 {"skip", s_space, 0},
161 {"uahalf", s_uacons, 2},
162 {"uaword", s_uacons, 4},
163 {"uaxword", s_uacons, 8},
165 /* These are specific to sparc/svr4. */
166 {"2byte", s_uacons, 2},
167 {"4byte", s_uacons, 4},
168 {"8byte", s_uacons, 8},
169 {"register", s_register, 0},
174 /* This array holds the chars that always start a comment. If the
175 pre-processor is disabled, these aren't very useful. */
176 const char comment_chars[] = "!"; /* JF removed '|' from
179 /* This array holds the chars that only start a comment at the beginning of
180 a line. If the line seems to have the form '# 123 filename'
181 .line and .file directives will appear in the pre-processed output. */
182 /* Note that input_file.c hand checks for '#' at the beginning of the
183 first line of the input file. This is because the compiler outputs
184 #NO_APP at the beginning of its output. */
185 /* Also note that comments started like this one will always
186 work if '/' isn't otherwise defined. */
187 const char line_comment_chars[] = "#";
189 const char line_separator_chars[] = ";";
191 /* Chars that can be used to separate mant from exp in floating point
193 const char EXP_CHARS[] = "eE";
195 /* Chars that mean this number is a floating point constant.
198 const char FLT_CHARS[] = "rRsSfFdDxXpP";
200 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
201 changed in read.c. Ideally it shouldn't have to know about it at all,
202 but nothing is ideal around here. */
204 #define isoctal(c) ((unsigned) ((c) - '0') < 8)
209 unsigned long opcode;
210 struct nlist *nlistp;
214 bfd_reloc_code_real_type reloc;
217 struct sparc_it the_insn, set_insn;
219 static void output_insn (const struct sparc_opcode *, struct sparc_it *);
221 /* Table of arguments to -A.
222 The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect
223 for this use. That table is for opcodes only. This table is for opcodes
226 enum sparc_arch_types {v6, v7, v8, leon, sparclet, sparclite, sparc86x, v8plus,
227 v8plusa, v9, v9a, v9b, v9_64};
229 static struct sparc_arch {
231 const char *opcode_arch;
232 enum sparc_arch_types arch_type;
233 /* Default word size, as specified during configuration.
234 A value of zero means can't be used to specify default architecture. */
235 int default_arch_size;
236 /* Allowable arg to -A? */
238 /* Extra hardware capabilities allowed. These are added to the
239 hardware capabilities associated with the opcode
243 } sparc_arch_table[] = {
244 { "v6", "v6", v6, 0, 1, 0, 0 },
245 { "v7", "v7", v7, 0, 1, 0, 0 },
246 { "v8", "v8", v8, 32, 1, 0, 0 },
247 { "v8a", "v8", v8, 32, 1, 0, 0 },
248 { "sparc", "v9", v9, 0, 1, HWCAP_V8PLUS, 0 },
249 { "sparcvis", "v9a", v9, 0, 1, 0, 0 },
250 { "sparcvis2", "v9b", v9, 0, 1, 0, 0 },
251 { "sparcfmaf", "v9b", v9, 0, 1, HWCAP_FMAF, 0 },
252 { "sparcima", "v9b", v9, 0, 1, HWCAP_FMAF|HWCAP_IMA, 0 },
253 { "sparcvis3", "v9b", v9, 0, 1, HWCAP_FMAF|HWCAP_VIS3|HWCAP_HPC, 0 },
254 { "sparcvis3r", "v9b", v9, 0, 1, HWCAP_FMAF|HWCAP_VIS3|HWCAP_HPC|HWCAP_FJFMAU, 0 },
256 { "sparc4", "v9v", v9, 0, 1, 0, 0 },
257 { "sparc5", "v9m", v9, 0, 1, 0, 0 },
259 { "leon", "leon", leon, 32, 1, 0, 0 },
260 { "sparclet", "sparclet", sparclet, 32, 1, 0, 0 },
261 { "sparclite", "sparclite", sparclite, 32, 1, 0, 0 },
262 { "sparc86x", "sparclite", sparc86x, 32, 1, 0, 0 },
264 { "v8plus", "v9", v9, 0, 1, HWCAP_V8PLUS, 0 },
265 { "v8plusa", "v9a", v9, 0, 1, HWCAP_V8PLUS, 0 },
266 { "v8plusb", "v9b", v9, 0, 1, HWCAP_V8PLUS, 0 },
267 { "v8plusc", "v9c", v9, 0, 1, HWCAP_V8PLUS, 0 },
268 { "v8plusd", "v9d", v9, 0, 1, HWCAP_V8PLUS, 0 },
269 { "v8pluse", "v9e", v9, 0, 1, HWCAP_V8PLUS, 0 },
270 { "v8plusv", "v9v", v9, 0, 1, HWCAP_V8PLUS, 0 },
271 { "v8plusm", "v9m", v9, 0, 1, HWCAP_V8PLUS, 0 },
273 { "v9", "v9", v9, 0, 1, 0, 0 },
274 { "v9a", "v9a", v9, 0, 1, 0, 0 },
275 { "v9b", "v9b", v9, 0, 1, 0, 0 },
276 { "v9c", "v9c", v9, 0, 1, 0, 0 },
277 { "v9d", "v9d", v9, 0, 1, 0, 0 },
278 { "v9e", "v9e", v9, 0, 1, 0, 0 },
279 { "v9v", "v9v", v9, 0, 1, 0, 0 },
280 { "v9m", "v9m", v9, 0, 1, 0, 0 },
282 /* This exists to allow configure.tgt to pass one
283 value to specify both the default machine and default word size. */
284 { "v9-64", "v9", v9, 64, 0, 0, 0 },
285 { NULL, NULL, v8, 0, 0, 0, 0 }
288 /* Variant of default_arch */
289 static enum sparc_arch_types default_arch_type;
291 static struct sparc_arch *
292 lookup_arch (const char *name)
294 struct sparc_arch *sa;
296 for (sa = &sparc_arch_table[0]; sa->name != NULL; sa++)
297 if (strcmp (sa->name, name) == 0)
299 if (sa->name == NULL)
304 /* Initialize the default opcode arch and word size from the default
305 architecture name. */
308 init_default_arch (void)
310 struct sparc_arch *sa = lookup_arch (default_arch);
313 || sa->default_arch_size == 0)
314 as_fatal (_("Invalid default architecture, broken assembler."));
316 max_architecture = sparc_opcode_lookup_arch (sa->opcode_arch);
317 if (max_architecture == SPARC_OPCODE_ARCH_BAD)
318 as_fatal (_("Bad opcode table, broken assembler."));
319 default_arch_size = sparc_arch_size = sa->default_arch_size;
321 default_arch_type = sa->arch_type;
324 /* Called by TARGET_FORMAT. */
327 sparc_target_format (void)
329 /* We don't get a chance to initialize anything before we're called,
330 so handle that now. */
331 if (! default_init_p)
332 init_default_arch ();
336 return "a.out-sparc-netbsd";
339 if (target_big_endian)
340 return "a.out-sunos-big";
341 else if (default_arch_type == sparc86x && target_little_endian_data)
342 return "a.out-sunos-big";
344 return "a.out-sparc-little";
346 return "a.out-sunos-big";
357 return "coff-sparc-lynx";
364 return "elf32-sparc-vxworks";
368 return sparc_arch_size == 64 ? ELF64_TARGET_FORMAT : ELF_TARGET_FORMAT;
375 * Invocation line includes a switch not recognized by the base assembler.
376 * See if it's a processor-specific option. These are:
379 * Warn on architecture bumps. See also -A.
381 * -Av6, -Av7, -Av8, -Aleon, -Asparclite, -Asparclet
382 * Standard 32 bit architectures.
384 * Sparc64 in either a 32 or 64 bit world (-32/-64 says which).
385 * This used to only mean 64 bits, but properly specifying it
386 * complicated gcc's ASM_SPECs, so now opcode selection is
387 * specified orthogonally to word size (except when specifying
388 * the default, but that is an internal implementation detail).
389 * -Av8plus, -Av8plusa, -Av8plusb
390 * Same as -Av9{,a,b}.
391 * -xarch=v8plus, -xarch=v8plusa, -xarch=v8plusb
392 * Same as -Av8plus{,a,b} -32, for compatibility with Sun's
394 * -xarch=v9, -xarch=v9a, -xarch=v9b
395 * Same as -Av9{,a,b} -64, for compatibility with Sun's
398 * Select the architecture and possibly the file format.
399 * Instructions or features not supported by the selected
400 * architecture cause fatal errors.
402 * The default is to start at v6, and bump the architecture up
403 * whenever an instruction is seen at a higher level. In 32 bit
404 * environments, v9 is not bumped up to, the user must pass
407 * If -bump is specified, a warning is printing when bumping to
410 * If an architecture is specified, all instructions must match
411 * that architecture. Any higher level instructions are flagged
412 * as errors. Note that in the 32 bit environment specifying
413 * -Av8plus does not automatically create a v8plus object file, a
414 * v9 insn must be seen.
416 * If both an architecture and -bump are specified, the
417 * architecture starts at the specified level, but bumps are
418 * warnings. Note that we can't set `current_architecture' to
419 * the requested level in this case: in the 32 bit environment,
420 * we still must avoid creating v8plus object files unless v9
424 * Bumping between incompatible architectures is always an
425 * error. For example, from sparclite to v9.
429 const char *md_shortopts = "A:K:VQ:sq";
432 const char *md_shortopts = "A:k";
434 const char *md_shortopts = "A:";
437 struct option md_longopts[] = {
438 #define OPTION_BUMP (OPTION_MD_BASE)
439 {"bump", no_argument, NULL, OPTION_BUMP},
440 #define OPTION_SPARC (OPTION_MD_BASE + 1)
441 {"sparc", no_argument, NULL, OPTION_SPARC},
442 #define OPTION_XARCH (OPTION_MD_BASE + 2)
443 {"xarch", required_argument, NULL, OPTION_XARCH},
445 #define OPTION_32 (OPTION_MD_BASE + 3)
446 {"32", no_argument, NULL, OPTION_32},
447 #define OPTION_64 (OPTION_MD_BASE + 4)
448 {"64", no_argument, NULL, OPTION_64},
449 #define OPTION_TSO (OPTION_MD_BASE + 5)
450 {"TSO", no_argument, NULL, OPTION_TSO},
451 #define OPTION_PSO (OPTION_MD_BASE + 6)
452 {"PSO", no_argument, NULL, OPTION_PSO},
453 #define OPTION_RMO (OPTION_MD_BASE + 7)
454 {"RMO", no_argument, NULL, OPTION_RMO},
456 #ifdef SPARC_BIENDIAN
457 #define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8)
458 {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},
459 #define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9)
460 {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},
462 #define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10)
463 {"enforce-aligned-data", no_argument, NULL, OPTION_ENFORCE_ALIGNED_DATA},
464 #define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11)
465 {"little-endian-data", no_argument, NULL, OPTION_LITTLE_ENDIAN_DATA},
467 #define OPTION_NO_UNDECLARED_REGS (OPTION_MD_BASE + 12)
468 {"no-undeclared-regs", no_argument, NULL, OPTION_NO_UNDECLARED_REGS},
469 #define OPTION_UNDECLARED_REGS (OPTION_MD_BASE + 13)
470 {"undeclared-regs", no_argument, NULL, OPTION_UNDECLARED_REGS},
472 #define OPTION_RELAX (OPTION_MD_BASE + 14)
473 {"relax", no_argument, NULL, OPTION_RELAX},
474 #define OPTION_NO_RELAX (OPTION_MD_BASE + 15)
475 {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
476 #define OPTION_DCTI_COUPLES_DETECT (OPTION_MD_BASE + 16)
477 {"dcti-couples-detect", no_argument, NULL, OPTION_DCTI_COUPLES_DETECT},
478 {NULL, no_argument, NULL, 0}
481 size_t md_longopts_size = sizeof (md_longopts);
484 md_parse_option (int c, const char *arg)
486 /* We don't get a chance to initialize anything before we're called,
487 so handle that now. */
488 if (! default_init_p)
489 init_default_arch ();
495 warn_after_architecture = SPARC_OPCODE_ARCH_V6;
500 if (!strncmp (arg, "v9", 2))
501 md_parse_option (OPTION_64, NULL);
504 if (!strncmp (arg, "v8", 2)
505 || !strncmp (arg, "v7", 2)
506 || !strncmp (arg, "v6", 2)
507 || !strcmp (arg, "sparclet")
508 || !strcmp (arg, "sparclite")
509 || !strcmp (arg, "sparc86x"))
510 md_parse_option (OPTION_32, NULL);
517 struct sparc_arch *sa;
518 enum sparc_opcode_arch_val opcode_arch;
520 sa = lookup_arch (arg);
522 || ! sa->user_option_p)
524 if (c == OPTION_XARCH)
525 as_bad (_("invalid architecture -xarch=%s"), arg);
527 as_bad (_("invalid architecture -A%s"), arg);
531 opcode_arch = sparc_opcode_lookup_arch (sa->opcode_arch);
532 if (opcode_arch == SPARC_OPCODE_ARCH_BAD)
533 as_fatal (_("Bad opcode table, broken assembler."));
535 if (!architecture_requested
536 || opcode_arch > max_architecture)
537 max_architecture = opcode_arch;
539 /* The allowed hardware capabilities are the implied by the
540 opcodes arch plus any extra capabilities defined in the GAS
544 | (((bfd_uint64_t) sparc_opcode_archs[opcode_arch].hwcaps2) << 32)
545 | (((bfd_uint64_t) sa->hwcap2_allowed) << 32)
546 | sparc_opcode_archs[opcode_arch].hwcaps
547 | sa->hwcap_allowed);
548 architecture_requested = 1;
553 /* Ignore -sparc, used by SunOS make default .s.o rule. */
556 case OPTION_ENFORCE_ALIGNED_DATA:
557 enforce_aligned_data = 1;
560 #ifdef SPARC_BIENDIAN
561 case OPTION_LITTLE_ENDIAN:
562 target_big_endian = 0;
563 if (default_arch_type != sparclet)
564 as_fatal ("This target does not support -EL");
566 case OPTION_LITTLE_ENDIAN_DATA:
567 target_little_endian_data = 1;
568 target_big_endian = 0;
569 if (default_arch_type != sparc86x
570 && default_arch_type != v9)
571 as_fatal ("This target does not support --little-endian-data");
573 case OPTION_BIG_ENDIAN:
574 target_big_endian = 1;
588 const char **list, **l;
590 sparc_arch_size = c == OPTION_32 ? 32 : 64;
591 list = bfd_target_list ();
592 for (l = list; *l != NULL; l++)
594 if (sparc_arch_size == 32)
596 if (CONST_STRNEQ (*l, "elf32-sparc"))
601 if (CONST_STRNEQ (*l, "elf64-sparc"))
606 as_fatal (_("No compiled in support for %d bit object file format"),
610 if (sparc_arch_size == 64
611 && max_architecture < SPARC_OPCODE_ARCH_V9)
612 max_architecture = SPARC_OPCODE_ARCH_V9;
617 sparc_memory_model = MM_TSO;
621 sparc_memory_model = MM_PSO;
625 sparc_memory_model = MM_RMO;
633 /* Qy - do emit .comment
634 Qn - do not emit .comment. */
638 /* Use .stab instead of .stab.excl. */
642 /* quick -- Native assembler does fewer checks. */
646 if (strcmp (arg, "PIC") != 0)
647 as_warn (_("Unrecognized option following -K"));
652 case OPTION_NO_UNDECLARED_REGS:
653 no_undeclared_regs = 1;
656 case OPTION_UNDECLARED_REGS:
657 no_undeclared_regs = 0;
665 case OPTION_NO_RELAX:
669 case OPTION_DCTI_COUPLES_DETECT:
670 dcti_couples_detect = 1;
681 md_show_usage (FILE *stream)
683 const struct sparc_arch *arch;
686 /* We don't get a chance to initialize anything before we're called,
687 so handle that now. */
688 if (! default_init_p)
689 init_default_arch ();
691 fprintf (stream, _("SPARC options:\n"));
693 for (arch = &sparc_arch_table[0]; arch->name; arch++)
695 if (!arch->user_option_p)
697 if (arch != &sparc_arch_table[0])
698 fprintf (stream, " | ");
699 if (column + strlen (arch->name) > 70)
702 fputc ('\n', stream);
704 column += 5 + 2 + strlen (arch->name);
705 fprintf (stream, "-A%s", arch->name);
707 for (arch = &sparc_arch_table[0]; arch->name; arch++)
709 if (!arch->user_option_p)
711 fprintf (stream, " | ");
712 if (column + strlen (arch->name) > 65)
715 fputc ('\n', stream);
717 column += 5 + 7 + strlen (arch->name);
718 fprintf (stream, "-xarch=%s", arch->name);
720 fprintf (stream, _("\n\
721 specify variant of SPARC architecture\n\
722 -bump warn when assembler switches architectures\n\
724 --enforce-aligned-data force .long, etc., to be aligned correctly\n\
725 -relax relax jumps and branches (default)\n\
726 -no-relax avoid changing any jumps and branches\n"));
728 fprintf (stream, _("\
729 -k generate PIC\n"));
732 fprintf (stream, _("\
733 -32 create 32 bit object file\n\
734 -64 create 64 bit object file\n"));
735 fprintf (stream, _("\
736 [default is %d]\n"), default_arch_size);
737 fprintf (stream, _("\
738 -TSO use Total Store Ordering\n\
739 -PSO use Partial Store Ordering\n\
740 -RMO use Relaxed Memory Ordering\n"));
741 fprintf (stream, _("\
742 [default is %s]\n"), (default_arch_size == 64) ? "RMO" : "TSO");
743 fprintf (stream, _("\
744 -KPIC generate PIC\n\
745 -V print assembler version number\n\
746 -undeclared-regs ignore application global register usage without\n\
747 appropriate .register directive (default)\n\
748 -no-undeclared-regs force error on application global register usage\n\
749 without appropriate .register directive\n\
750 --dcti-couples-detect warn when an unpredictable DCTI couple is found\n\
755 #ifdef SPARC_BIENDIAN
756 fprintf (stream, _("\
757 -EL generate code for a little endian machine\n\
758 -EB generate code for a big endian machine\n\
759 --little-endian-data generate code for a machine having big endian\n\
760 instructions and little endian data.\n"));
764 /* Native operand size opcode translation. */
770 } native_op_table[] =
772 {"ldn", "ld", "ldx"},
773 {"ldna", "lda", "ldxa"},
774 {"stn", "st", "stx"},
775 {"stna", "sta", "stxa"},
776 {"slln", "sll", "sllx"},
777 {"srln", "srl", "srlx"},
778 {"sran", "sra", "srax"},
779 {"casn", "cas", "casx"},
780 {"casna", "casa", "casxa"},
781 {"clrn", "clr", "clrx"},
785 /* sparc64 privileged and hyperprivileged registers. */
787 struct priv_reg_entry
793 struct priv_reg_entry priv_reg_table[] =
814 {NULL, -1}, /* End marker. */
817 struct priv_reg_entry hpriv_reg_table[] =
827 {"hstick_offset", 28},
828 {"hstick_enable", 29},
830 {NULL, -1}, /* End marker. */
833 /* v9a or later specific ancillary state registers. */
835 struct priv_reg_entry v9a_asr_table[] =
838 {"sys_tick_cmpr", 25},
842 {"softint_clear", 21},
853 {"clear_softint", 21},
854 {NULL, -1}, /* End marker. */
858 cmp_reg_entry (const void *parg, const void *qarg)
860 const struct priv_reg_entry *p = (const struct priv_reg_entry *) parg;
861 const struct priv_reg_entry *q = (const struct priv_reg_entry *) qarg;
863 if (p->name == q->name)
865 else if (p->name == NULL)
867 else if (q->name == NULL)
870 return strcmp (q->name, p->name);
873 /* sparc %-pseudo-operations. */
876 #define F_POP_V9 0x1 /* The pseudo-op is for v9 only. */
877 #define F_POP_PCREL 0x2 /* The pseudo-op can be used in pc-relative
879 #define F_POP_TLS_CALL 0x4 /* The pseudo-op marks a tls call. */
880 #define F_POP_POSTFIX 0x8 /* The pseudo-op should appear after the
882 instruction. (Generally they can appear
883 anywhere an immediate operand is
887 /* The name as it appears in assembler. */
889 /* The reloc this pseudo-op translates to. */
890 bfd_reloc_code_real_type reloc;
891 /* Flags. See F_POP_* above. */
895 struct pop_entry pop_table[] =
897 { "hix", BFD_RELOC_SPARC_HIX22, F_POP_V9 },
898 { "lox", BFD_RELOC_SPARC_LOX10, F_POP_V9 },
899 { "hi", BFD_RELOC_HI22, F_POP_PCREL },
900 { "lo", BFD_RELOC_LO10, F_POP_PCREL },
901 { "pc22", BFD_RELOC_SPARC_PC22, F_POP_PCREL },
902 { "pc10", BFD_RELOC_SPARC_PC10, F_POP_PCREL },
903 { "hh", BFD_RELOC_SPARC_HH22, F_POP_V9|F_POP_PCREL },
904 { "hm", BFD_RELOC_SPARC_HM10, F_POP_V9|F_POP_PCREL },
905 { "lm", BFD_RELOC_SPARC_LM22, F_POP_V9|F_POP_PCREL },
906 { "h34", BFD_RELOC_SPARC_H34, F_POP_V9 },
907 { "l34", BFD_RELOC_SPARC_L44, F_POP_V9 },
908 { "h44", BFD_RELOC_SPARC_H44, F_POP_V9 },
909 { "m44", BFD_RELOC_SPARC_M44, F_POP_V9 },
910 { "l44", BFD_RELOC_SPARC_L44, F_POP_V9 },
911 { "uhi", BFD_RELOC_SPARC_HH22, F_POP_V9 },
912 { "ulo", BFD_RELOC_SPARC_HM10, F_POP_V9 },
913 { "tgd_hi22", BFD_RELOC_SPARC_TLS_GD_HI22, 0 },
914 { "tgd_lo10", BFD_RELOC_SPARC_TLS_GD_LO10, 0 },
915 { "tldm_hi22", BFD_RELOC_SPARC_TLS_LDM_HI22, 0 },
916 { "tldm_lo10", BFD_RELOC_SPARC_TLS_LDM_LO10, 0 },
917 { "tldo_hix22", BFD_RELOC_SPARC_TLS_LDO_HIX22, 0 },
918 { "tldo_lox10", BFD_RELOC_SPARC_TLS_LDO_LOX10, 0 },
919 { "tie_hi22", BFD_RELOC_SPARC_TLS_IE_HI22, 0 },
920 { "tie_lo10", BFD_RELOC_SPARC_TLS_IE_LO10, 0 },
921 { "tle_hix22", BFD_RELOC_SPARC_TLS_LE_HIX22, 0 },
922 { "tle_lox10", BFD_RELOC_SPARC_TLS_LE_LOX10, 0 },
923 { "gdop_hix22", BFD_RELOC_SPARC_GOTDATA_OP_HIX22, 0 },
924 { "gdop_lox10", BFD_RELOC_SPARC_GOTDATA_OP_LOX10, 0 },
925 { "tgd_add", BFD_RELOC_SPARC_TLS_GD_ADD, F_POP_POSTFIX },
926 { "tgd_call", BFD_RELOC_SPARC_TLS_GD_CALL, F_POP_POSTFIX|F_POP_TLS_CALL },
927 { "tldm_add", BFD_RELOC_SPARC_TLS_LDM_ADD, F_POP_POSTFIX },
928 { "tldm_call", BFD_RELOC_SPARC_TLS_LDM_CALL, F_POP_POSTFIX|F_POP_TLS_CALL },
929 { "tldo_add", BFD_RELOC_SPARC_TLS_LDO_ADD, F_POP_POSTFIX },
930 { "tie_ldx", BFD_RELOC_SPARC_TLS_IE_LDX, F_POP_POSTFIX },
931 { "tie_ld", BFD_RELOC_SPARC_TLS_IE_LD, F_POP_POSTFIX },
932 { "tie_add", BFD_RELOC_SPARC_TLS_IE_ADD, F_POP_POSTFIX },
933 { "gdop", BFD_RELOC_SPARC_GOTDATA_OP, F_POP_POSTFIX }
936 /* Table of %-names that can appear in a sparc assembly program. This
937 table is initialized in md_begin and contains entries for each
938 privileged/hyperprivileged/alternate register and %-pseudo-op. */
951 enum perc_entry_type type;
952 /* Name of the %-entity. */
956 /* Value. Either a pop or a reg depending on type.*/
959 struct pop_entry *pop;
960 struct priv_reg_entry *reg;
964 #define NUM_PERC_ENTRIES \
965 (((sizeof (priv_reg_table) / sizeof (priv_reg_table[0])) - 1) \
966 + ((sizeof (hpriv_reg_table) / sizeof (hpriv_reg_table[0])) - 1) \
967 + ((sizeof (v9a_asr_table) / sizeof (v9a_asr_table[0])) - 1) \
968 + ARRAY_SIZE (pop_table) \
971 struct perc_entry perc_table[NUM_PERC_ENTRIES];
974 cmp_perc_entry (const void *parg, const void *qarg)
976 const struct perc_entry *p = (const struct perc_entry *) parg;
977 const struct perc_entry *q = (const struct perc_entry *) qarg;
979 if (p->name == q->name)
981 else if (p->name == NULL)
983 else if (q->name == NULL)
986 return strcmp (q->name, p->name);
989 /* This function is called once, at assembler startup time. It should
990 set up all the tables, etc. that the MD part of the assembler will
996 const char *retval = NULL;
1000 /* We don't get a chance to initialize anything before md_parse_option
1001 is called, and it may not be called, so handle default initialization
1002 now if not already done. */
1003 if (! default_init_p)
1004 init_default_arch ();
1006 sparc_cie_data_alignment = sparc_arch_size == 64 ? -8 : -4;
1007 op_hash = hash_new ();
1009 while (i < (unsigned int) sparc_num_opcodes)
1011 const char *name = sparc_opcodes[i].name;
1012 retval = hash_insert (op_hash, name, (void *) &sparc_opcodes[i]);
1015 as_bad (_("Internal error: can't hash `%s': %s\n"),
1016 sparc_opcodes[i].name, retval);
1021 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
1023 as_bad (_("Internal error: losing opcode: `%s' \"%s\"\n"),
1024 sparc_opcodes[i].name, sparc_opcodes[i].args);
1029 while (i < (unsigned int) sparc_num_opcodes
1030 && !strcmp (sparc_opcodes[i].name, name));
1033 for (i = 0; native_op_table[i].name; i++)
1035 const struct sparc_opcode *insn;
1036 const char *name = ((sparc_arch_size == 32)
1037 ? native_op_table[i].name32
1038 : native_op_table[i].name64);
1039 insn = (struct sparc_opcode *) hash_find (op_hash, name);
1042 as_bad (_("Internal error: can't find opcode `%s' for `%s'\n"),
1043 name, native_op_table[i].name);
1048 retval = hash_insert (op_hash, native_op_table[i].name,
1052 as_bad (_("Internal error: can't hash `%s': %s\n"),
1053 sparc_opcodes[i].name, retval);
1060 as_fatal (_("Broken assembler. No assembly attempted."));
1062 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
1063 sizeof (priv_reg_table[0]), cmp_reg_entry);
1064 qsort (hpriv_reg_table, sizeof (hpriv_reg_table) / sizeof (hpriv_reg_table[0]),
1065 sizeof (hpriv_reg_table[0]), cmp_reg_entry);
1066 qsort (v9a_asr_table, sizeof (v9a_asr_table) / sizeof (v9a_asr_table[0]),
1067 sizeof (v9a_asr_table[0]), cmp_reg_entry);
1069 /* If -bump, record the architecture level at which we start issuing
1070 warnings. The behaviour is different depending upon whether an
1071 architecture was explicitly specified. If it wasn't, we issue warnings
1072 for all upwards bumps. If it was, we don't start issuing warnings until
1073 we need to bump beyond the requested architecture or when we bump between
1074 conflicting architectures. */
1077 && architecture_requested)
1079 /* `max_architecture' records the requested architecture.
1080 Issue warnings if we go above it. */
1081 warn_after_architecture = max_architecture;
1084 /* Find the highest architecture level that doesn't conflict with
1085 the requested one. */
1088 || !architecture_requested)
1090 enum sparc_opcode_arch_val current_max_architecture
1093 for (max_architecture = SPARC_OPCODE_ARCH_MAX;
1094 max_architecture > warn_after_architecture;
1096 if (! SPARC_OPCODE_CONFLICT_P (max_architecture,
1097 current_max_architecture))
1101 /* Prepare the tables of %-pseudo-ops. */
1103 struct priv_reg_entry *reg_tables[]
1104 = {priv_reg_table, hpriv_reg_table, v9a_asr_table, NULL};
1105 struct priv_reg_entry **reg_table;
1108 /* Add registers. */
1109 for (reg_table = reg_tables; reg_table[0]; reg_table++)
1111 struct priv_reg_entry *reg;
1112 for (reg = *reg_table; reg->name; reg++)
1114 struct perc_entry *p = &perc_table[entry++];
1115 p->type = perc_entry_reg;
1116 p->name = reg->name;
1117 p->len = strlen (reg->name);
1122 /* Add %-pseudo-ops. */
1123 for (i = 0; i < ARRAY_SIZE (pop_table); i++)
1125 struct perc_entry *p = &perc_table[entry++];
1126 p->type = (pop_table[i].flags & F_POP_POSTFIX
1127 ? perc_entry_post_pop : perc_entry_imm_pop);
1128 p->name = pop_table[i].name;
1129 p->len = strlen (pop_table[i].name);
1130 p->pop = &pop_table[i];
1133 /* Last entry is the centinel. */
1134 perc_table[entry].type = perc_entry_none;
1136 qsort (perc_table, sizeof (perc_table) / sizeof (perc_table[0]),
1137 sizeof (perc_table[0]), cmp_perc_entry);
1142 /* Called after all assembly has been done. */
1147 unsigned long mach = bfd_mach_sparc;
1148 #if defined(OBJ_ELF) && !defined(TE_SOLARIS)
1149 int hwcaps, hwcaps2;
1152 if (sparc_arch_size == 64)
1153 switch (current_architecture)
1155 case SPARC_OPCODE_ARCH_V9A: mach = bfd_mach_sparc_v9a; break;
1156 case SPARC_OPCODE_ARCH_V9B: mach = bfd_mach_sparc_v9b; break;
1157 case SPARC_OPCODE_ARCH_V9C: mach = bfd_mach_sparc_v9c; break;
1158 case SPARC_OPCODE_ARCH_V9D: mach = bfd_mach_sparc_v9d; break;
1159 case SPARC_OPCODE_ARCH_V9E: mach = bfd_mach_sparc_v9e; break;
1160 case SPARC_OPCODE_ARCH_V9V: mach = bfd_mach_sparc_v9v; break;
1161 case SPARC_OPCODE_ARCH_V9M: mach = bfd_mach_sparc_v9m; break;
1162 default: mach = bfd_mach_sparc_v9; break;
1165 switch (current_architecture)
1167 case SPARC_OPCODE_ARCH_SPARCLET: mach = bfd_mach_sparc_sparclet; break;
1168 case SPARC_OPCODE_ARCH_V9: mach = bfd_mach_sparc_v8plus; break;
1169 case SPARC_OPCODE_ARCH_V9A: mach = bfd_mach_sparc_v8plusa; break;
1170 case SPARC_OPCODE_ARCH_V9B: mach = bfd_mach_sparc_v8plusb; break;
1171 case SPARC_OPCODE_ARCH_V9C: mach = bfd_mach_sparc_v8plusc; break;
1172 case SPARC_OPCODE_ARCH_V9D: mach = bfd_mach_sparc_v8plusd; break;
1173 case SPARC_OPCODE_ARCH_V9E: mach = bfd_mach_sparc_v8pluse; break;
1174 case SPARC_OPCODE_ARCH_V9V: mach = bfd_mach_sparc_v8plusv; break;
1175 case SPARC_OPCODE_ARCH_V9M: mach = bfd_mach_sparc_v8plusm; break;
1176 /* The sparclite is treated like a normal sparc. Perhaps it shouldn't
1177 be but for now it is (since that's the way it's always been
1181 bfd_set_arch_mach (stdoutput, bfd_arch_sparc, mach);
1183 #if defined(OBJ_ELF) && !defined(TE_SOLARIS)
1184 hwcaps = hwcap_seen & U0xffffffff;
1185 hwcaps2 = hwcap_seen >> 32;
1188 bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_GNU, Tag_GNU_Sparc_HWCAPS, hwcaps);
1190 bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_GNU, Tag_GNU_Sparc_HWCAPS2, hwcaps2);
1194 /* Return non-zero if VAL is in the range -(MAX+1) to MAX. */
1197 in_signed_range (bfd_signed_vma val, bfd_signed_vma max)
1201 /* Sign-extend the value from the architecture word size, so that
1202 0xffffffff is always considered -1 on sparc32. */
1203 if (sparc_arch_size == 32)
1205 bfd_signed_vma sign = (bfd_signed_vma) 1 << 31;
1206 val = ((val & U0xffffffff) ^ sign) - sign;
1215 /* Return non-zero if VAL is in the range 0 to MAX. */
1218 in_unsigned_range (bfd_vma val, bfd_vma max)
1225 /* Return non-zero if VAL is in the range -(MAX/2+1) to MAX.
1226 (e.g. -15 to +31). */
1229 in_bitfield_range (bfd_signed_vma val, bfd_signed_vma max)
1235 if (val < ~(max >> 1))
1241 sparc_ffs (unsigned int mask)
1248 for (i = 0; (mask & 1) == 0; ++i)
1253 /* Implement big shift right. */
1255 BSR (bfd_vma val, int amount)
1257 if (sizeof (bfd_vma) <= 4 && amount >= 32)
1258 as_fatal (_("Support for 64-bit arithmetic not compiled in."));
1259 return val >> amount;
1262 /* For communication between sparc_ip and get_expression. */
1263 static char *expr_end;
1265 /* Values for `special_case'.
1266 Instructions that require weird handling because they're longer than
1268 #define SPECIAL_CASE_NONE 0
1269 #define SPECIAL_CASE_SET 1
1270 #define SPECIAL_CASE_SETSW 2
1271 #define SPECIAL_CASE_SETX 3
1272 /* FIXME: sparc-opc.c doesn't have necessary "S" trigger to enable this. */
1273 #define SPECIAL_CASE_FDIV 4
1275 /* Bit masks of various insns. */
1276 #define NOP_INSN 0x01000000
1277 #define OR_INSN 0x80100000
1278 #define XOR_INSN 0x80180000
1279 #define FMOVS_INSN 0x81A00020
1280 #define SETHI_INSN 0x01000000
1281 #define SLLX_INSN 0x81281000
1282 #define SRA_INSN 0x81380000
1284 /* The last instruction to be assembled. */
1285 static const struct sparc_opcode *last_insn;
1286 /* The assembled opcode of `last_insn'. */
1287 static unsigned long last_opcode;
1289 /* Handle the set and setuw synthetic instructions. */
1292 synthetize_setuw (const struct sparc_opcode *insn)
1294 int need_hi22_p = 0;
1295 int rd = (the_insn.opcode & RD (~0)) >> 25;
1297 if (the_insn.exp.X_op == O_constant)
1299 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
1301 if (sizeof (offsetT) > 4
1302 && (the_insn.exp.X_add_number < 0
1303 || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
1304 as_warn (_("set: number not in 0..4294967295 range"));
1308 if (sizeof (offsetT) > 4
1309 && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
1310 || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
1311 as_warn (_("set: number not in -2147483648..4294967295 range"));
1312 the_insn.exp.X_add_number = (int) the_insn.exp.X_add_number;
1316 /* See if operand is absolute and small; skip sethi if so. */
1317 if (the_insn.exp.X_op != O_constant
1318 || the_insn.exp.X_add_number >= (1 << 12)
1319 || the_insn.exp.X_add_number < -(1 << 12))
1321 the_insn.opcode = (SETHI_INSN | RD (rd)
1322 | ((the_insn.exp.X_add_number >> 10)
1323 & (the_insn.exp.X_op == O_constant
1325 the_insn.reloc = (the_insn.exp.X_op != O_constant
1326 ? BFD_RELOC_HI22 : BFD_RELOC_NONE);
1327 output_insn (insn, &the_insn);
1331 /* See if operand has no low-order bits; skip OR if so. */
1332 if (the_insn.exp.X_op != O_constant
1333 || (need_hi22_p && (the_insn.exp.X_add_number & 0x3FF) != 0)
1336 the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (rd) : 0)
1338 | (the_insn.exp.X_add_number
1339 & (the_insn.exp.X_op != O_constant
1340 ? 0 : need_hi22_p ? 0x3ff : 0x1fff)));
1341 the_insn.reloc = (the_insn.exp.X_op != O_constant
1342 ? BFD_RELOC_LO10 : BFD_RELOC_NONE);
1343 output_insn (insn, &the_insn);
1347 /* Handle the setsw synthetic instruction. */
1350 synthetize_setsw (const struct sparc_opcode *insn)
1354 rd = (the_insn.opcode & RD (~0)) >> 25;
1356 if (the_insn.exp.X_op != O_constant)
1358 synthetize_setuw (insn);
1360 /* Need to sign extend it. */
1361 the_insn.opcode = (SRA_INSN | RS1 (rd) | RD (rd));
1362 the_insn.reloc = BFD_RELOC_NONE;
1363 output_insn (insn, &the_insn);
1367 if (sizeof (offsetT) > 4
1368 && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
1369 || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
1370 as_warn (_("setsw: number not in -2147483648..4294967295 range"));
1372 low32 = the_insn.exp.X_add_number;
1376 synthetize_setuw (insn);
1382 the_insn.reloc = BFD_RELOC_NONE;
1383 /* See if operand is absolute and small; skip sethi if so. */
1384 if (low32 < -(1 << 12))
1386 the_insn.opcode = (SETHI_INSN | RD (rd)
1387 | (((~the_insn.exp.X_add_number) >> 10) & 0x3fffff));
1388 output_insn (insn, &the_insn);
1389 low32 = 0x1c00 | (low32 & 0x3ff);
1390 opc = RS1 (rd) | XOR_INSN;
1393 the_insn.opcode = (opc | RD (rd) | IMMED
1394 | (low32 & 0x1fff));
1395 output_insn (insn, &the_insn);
1398 /* Handle the setx synthetic instruction. */
1401 synthetize_setx (const struct sparc_opcode *insn)
1403 int upper32, lower32;
1404 int tmpreg = (the_insn.opcode & RS1 (~0)) >> 14;
1405 int dstreg = (the_insn.opcode & RD (~0)) >> 25;
1407 int need_hh22_p = 0, need_hm10_p = 0, need_hi22_p = 0, need_lo10_p = 0;
1408 int need_xor10_p = 0;
1410 #define SIGNEXT32(x) ((((x) & U0xffffffff) ^ U0x80000000) - U0x80000000)
1411 lower32 = SIGNEXT32 (the_insn.exp.X_add_number);
1412 upper32 = SIGNEXT32 (BSR (the_insn.exp.X_add_number, 32));
1415 upper_dstreg = tmpreg;
1416 /* The tmp reg should not be the dst reg. */
1417 if (tmpreg == dstreg)
1418 as_warn (_("setx: temporary register same as destination register"));
1420 /* ??? Obviously there are other optimizations we can do
1421 (e.g. sethi+shift for 0x1f0000000) and perhaps we shouldn't be
1422 doing some of these. Later. If you do change things, try to
1423 change all of this to be table driven as well. */
1424 /* What to output depends on the number if it's constant.
1425 Compute that first, then output what we've decided upon. */
1426 if (the_insn.exp.X_op != O_constant)
1428 if (sparc_arch_size == 32)
1430 /* When arch size is 32, we want setx to be equivalent
1431 to setuw for anything but constants. */
1432 the_insn.exp.X_add_number &= 0xffffffff;
1433 synthetize_setuw (insn);
1436 need_hh22_p = need_hm10_p = need_hi22_p = need_lo10_p = 1;
1442 /* Reset X_add_number, we've extracted it as upper32/lower32.
1443 Otherwise fixup_segment will complain about not being able to
1444 write an 8 byte number in a 4 byte field. */
1445 the_insn.exp.X_add_number = 0;
1447 /* Only need hh22 if `or' insn can't handle constant. */
1448 if (upper32 < -(1 << 12) || upper32 >= (1 << 12))
1451 /* Does bottom part (after sethi) have bits? */
1452 if ((need_hh22_p && (upper32 & 0x3ff) != 0)
1453 /* No hh22, but does upper32 still have bits we can't set
1455 || (! need_hh22_p && upper32 != 0 && upper32 != -1))
1458 /* If the lower half is all zero, we build the upper half directly
1459 into the dst reg. */
1461 /* Need lower half if number is zero or 0xffffffff00000000. */
1462 || (! need_hh22_p && ! need_hm10_p))
1464 /* No need for sethi if `or' insn can handle constant. */
1465 if (lower32 < -(1 << 12) || lower32 >= (1 << 12)
1466 /* Note that we can't use a negative constant in the `or'
1467 insn unless the upper 32 bits are all ones. */
1468 || (lower32 < 0 && upper32 != -1)
1469 || (lower32 >= 0 && upper32 == -1))
1472 if (need_hi22_p && upper32 == -1)
1475 /* Does bottom part (after sethi) have bits? */
1476 else if ((need_hi22_p && (lower32 & 0x3ff) != 0)
1478 || (! need_hi22_p && (lower32 & 0x1fff) != 0)
1479 /* Need `or' if we didn't set anything else. */
1480 || (! need_hi22_p && ! need_hh22_p && ! need_hm10_p))
1484 /* Output directly to dst reg if lower 32 bits are all zero. */
1485 upper_dstreg = dstreg;
1488 if (!upper_dstreg && dstreg)
1489 as_warn (_("setx: illegal temporary register g0"));
1493 the_insn.opcode = (SETHI_INSN | RD (upper_dstreg)
1494 | ((upper32 >> 10) & 0x3fffff));
1495 the_insn.reloc = (the_insn.exp.X_op != O_constant
1496 ? BFD_RELOC_SPARC_HH22 : BFD_RELOC_NONE);
1497 output_insn (insn, &the_insn);
1502 the_insn.opcode = (SETHI_INSN | RD (dstreg)
1503 | (((need_xor10_p ? ~lower32 : lower32)
1504 >> 10) & 0x3fffff));
1505 the_insn.reloc = (the_insn.exp.X_op != O_constant
1506 ? BFD_RELOC_SPARC_LM22 : BFD_RELOC_NONE);
1507 output_insn (insn, &the_insn);
1512 the_insn.opcode = (OR_INSN
1513 | (need_hh22_p ? RS1 (upper_dstreg) : 0)
1516 | (upper32 & (need_hh22_p ? 0x3ff : 0x1fff)));
1517 the_insn.reloc = (the_insn.exp.X_op != O_constant
1518 ? BFD_RELOC_SPARC_HM10 : BFD_RELOC_NONE);
1519 output_insn (insn, &the_insn);
1524 /* FIXME: One nice optimization to do here is to OR the low part
1525 with the highpart if hi22 isn't needed and the low part is
1527 the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (dstreg) : 0)
1530 | (lower32 & (need_hi22_p ? 0x3ff : 0x1fff)));
1531 the_insn.reloc = (the_insn.exp.X_op != O_constant
1532 ? BFD_RELOC_LO10 : BFD_RELOC_NONE);
1533 output_insn (insn, &the_insn);
1536 /* If we needed to build the upper part, shift it into place. */
1537 if (need_hh22_p || need_hm10_p)
1539 the_insn.opcode = (SLLX_INSN | RS1 (upper_dstreg) | RD (upper_dstreg)
1541 the_insn.reloc = BFD_RELOC_NONE;
1542 output_insn (insn, &the_insn);
1545 /* To get -1 in upper32, we do sethi %hi(~x), r; xor r, -0x400 | x, r. */
1548 the_insn.opcode = (XOR_INSN | RS1 (dstreg) | RD (dstreg) | IMMED
1549 | 0x1c00 | (lower32 & 0x3ff));
1550 the_insn.reloc = BFD_RELOC_NONE;
1551 output_insn (insn, &the_insn);
1554 /* If we needed to build both upper and lower parts, OR them together. */
1555 else if ((need_hh22_p || need_hm10_p) && (need_hi22_p || need_lo10_p))
1557 the_insn.opcode = (OR_INSN | RS1 (dstreg) | RS2 (upper_dstreg)
1559 the_insn.reloc = BFD_RELOC_NONE;
1560 output_insn (insn, &the_insn);
1564 /* Main entry point to assemble one instruction. */
1567 md_assemble (char *str)
1569 const struct sparc_opcode *insn;
1573 special_case = sparc_ip (str, &insn);
1577 /* Certain instructions may not appear on delay slots. Check for
1578 these situations. */
1579 if (last_insn != NULL
1580 && (last_insn->flags & F_DELAYED) != 0)
1582 /* Before SPARC V9 the effect of having a delayed branch
1583 instruction in the delay slot of a conditional delayed branch
1586 In SPARC V9 DCTI couples are well defined.
1588 However, starting with the UltraSPARC Architecture 2005, DCTI
1589 couples (of all kind) are deprecated and should not be used,
1590 as they may be slow or behave differently to what the
1591 programmer expects. */
1592 if (dcti_couples_detect
1593 && (insn->flags & F_DELAYED) != 0
1594 && ((max_architecture < SPARC_OPCODE_ARCH_V9
1595 && (last_insn->flags & F_CONDBR) != 0)
1596 || max_architecture >= SPARC_OPCODE_ARCH_V9C))
1597 as_warn (_("unpredictable DCTI couple"));
1600 /* We warn about attempts to put a floating point branch in a
1601 delay slot, unless the delay slot has been annulled. */
1602 if ((insn->flags & F_FBR) != 0
1603 /* ??? This test isn't completely accurate. We assume anything with
1604 F_{UNBR,CONDBR,FBR} set is annullable. */
1605 && ((last_insn->flags & (F_UNBR | F_CONDBR | F_FBR)) == 0
1606 || (last_opcode & ANNUL) == 0))
1607 as_warn (_("FP branch in delay slot"));
1610 /* SPARC before v9 requires a nop instruction between a floating
1611 point instruction and a floating point branch. We insert one
1612 automatically, with a warning. */
1613 if (max_architecture < SPARC_OPCODE_ARCH_V9
1614 && last_insn != NULL
1615 && (insn->flags & F_FBR) != 0
1616 && (last_insn->flags & F_FLOAT) != 0)
1618 struct sparc_it nop_insn;
1620 nop_insn.opcode = NOP_INSN;
1621 nop_insn.reloc = BFD_RELOC_NONE;
1622 output_insn (insn, &nop_insn);
1623 as_warn (_("FP branch preceded by FP instruction; NOP inserted"));
1626 switch (special_case)
1628 case SPECIAL_CASE_NONE:
1630 output_insn (insn, &the_insn);
1633 case SPECIAL_CASE_SETSW:
1634 synthetize_setsw (insn);
1637 case SPECIAL_CASE_SET:
1638 synthetize_setuw (insn);
1641 case SPECIAL_CASE_SETX:
1642 synthetize_setx (insn);
1645 case SPECIAL_CASE_FDIV:
1647 int rd = (the_insn.opcode >> 25) & 0x1f;
1649 output_insn (insn, &the_insn);
1651 /* According to information leaked from Sun, the "fdiv" instructions
1652 on early SPARC machines would produce incorrect results sometimes.
1653 The workaround is to add an fmovs of the destination register to
1654 itself just after the instruction. This was true on machines
1655 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
1656 gas_assert (the_insn.reloc == BFD_RELOC_NONE);
1657 the_insn.opcode = FMOVS_INSN | rd | RD (rd);
1658 output_insn (insn, &the_insn);
1663 as_fatal (_("failed special case insn sanity check"));
1668 get_hwcap_name (bfd_uint64_t mask)
1670 if (mask & HWCAP_MUL32)
1672 if (mask & HWCAP_DIV32)
1674 if (mask & HWCAP_FSMULD)
1676 if (mask & HWCAP_V8PLUS)
1678 if (mask & HWCAP_POPC)
1680 if (mask & HWCAP_VIS)
1682 if (mask & HWCAP_VIS2)
1684 if (mask & HWCAP_ASI_BLK_INIT)
1685 return "ASIBlkInit";
1686 if (mask & HWCAP_FMAF)
1688 if (mask & HWCAP_VIS3)
1690 if (mask & HWCAP_HPC)
1692 if (mask & HWCAP_RANDOM)
1694 if (mask & HWCAP_TRANS)
1696 if (mask & HWCAP_FJFMAU)
1698 if (mask & HWCAP_IMA)
1700 if (mask & HWCAP_ASI_CACHE_SPARING)
1702 if (mask & HWCAP_AES)
1704 if (mask & HWCAP_DES)
1706 if (mask & HWCAP_KASUMI)
1708 if (mask & HWCAP_CAMELLIA)
1710 if (mask & HWCAP_MD5)
1712 if (mask & HWCAP_SHA1)
1714 if (mask & HWCAP_SHA256)
1716 if (mask & HWCAP_SHA512)
1718 if (mask & HWCAP_MPMUL)
1720 if (mask & HWCAP_MONT)
1722 if (mask & HWCAP_PAUSE)
1724 if (mask & HWCAP_CBCOND)
1726 if (mask & HWCAP_CRC32C)
1730 if (mask & HWCAP2_FJATHPLUS)
1732 if (mask & HWCAP2_VIS3B)
1734 if (mask & HWCAP2_ADP)
1736 if (mask & HWCAP2_SPARC5)
1738 if (mask & HWCAP2_MWAIT)
1740 if (mask & HWCAP2_XMPMUL)
1742 if (mask & HWCAP2_XMONT)
1744 if (mask & HWCAP2_NSEC)
1750 /* Subroutine of md_assemble to do the actual parsing. */
1753 sparc_ip (char *str, const struct sparc_opcode **pinsn)
1755 const char *error_message = "";
1759 const struct sparc_opcode *insn;
1761 unsigned long opcode;
1762 unsigned int mask = 0;
1766 int special_case = SPECIAL_CASE_NONE;
1773 while (ISLOWER (*s) || ISDIGIT (*s) || *s == '_');
1790 as_bad (_("Unknown opcode: `%s'"), str);
1792 return special_case;
1794 insn = (struct sparc_opcode *) hash_find (op_hash, str);
1798 as_bad (_("Unknown opcode: `%s'"), str);
1799 return special_case;
1809 opcode = insn->match;
1810 memset (&the_insn, '\0', sizeof (the_insn));
1811 the_insn.reloc = BFD_RELOC_NONE;
1814 /* Build the opcode, checking as we go to make sure that the
1816 for (args = insn->args;; ++args)
1824 /* Parse a series of masks. */
1831 if (! parse_keyword_arg (sparc_encode_membar, &s,
1834 error_message = _(": invalid membar mask name");
1840 if (*s == '|' || *s == '+')
1848 if (! parse_const_expr_arg (&s, &kmask))
1850 error_message = _(": invalid membar mask expression");
1853 if (kmask < 0 || kmask > 127)
1855 error_message = _(": invalid membar mask number");
1860 opcode |= MEMBAR (kmask);
1868 if (! parse_const_expr_arg (&s, &smask))
1870 error_message = _(": invalid siam mode expression");
1873 if (smask < 0 || smask > 7)
1875 error_message = _(": invalid siam mode number");
1886 /* Parse a prefetch function. */
1889 if (! parse_keyword_arg (sparc_encode_prefetch, &s, &fcn))
1891 error_message = _(": invalid prefetch function name");
1897 if (! parse_const_expr_arg (&s, &fcn))
1899 error_message = _(": invalid prefetch function expression");
1902 if (fcn < 0 || fcn > 31)
1904 error_message = _(": invalid prefetch function number");
1914 /* Parse a sparc64 privileged register. */
1917 struct priv_reg_entry *p;
1918 unsigned int len = 9999999; /* Init to make gcc happy. */
1921 for (p = priv_reg_table; p->name; p++)
1922 if (p->name[0] == s[0])
1924 len = strlen (p->name);
1925 if (strncmp (p->name, s, len) == 0)
1931 error_message = _(": unrecognizable privileged register");
1935 if (((opcode >> (*args == '?' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
1937 error_message = _(": unrecognizable privileged register");
1946 error_message = _(": unrecognizable privileged register");
1952 /* Parse a sparc64 hyperprivileged register. */
1955 struct priv_reg_entry *p;
1956 unsigned int len = 9999999; /* Init to make gcc happy. */
1959 for (p = hpriv_reg_table; p->name; p++)
1960 if (p->name[0] == s[0])
1962 len = strlen (p->name);
1963 if (strncmp (p->name, s, len) == 0)
1969 error_message = _(": unrecognizable hyperprivileged register");
1973 if (((opcode >> (*args == '$' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
1975 error_message = _(": unrecognizable hyperprivileged register");
1984 error_message = _(": unrecognizable hyperprivileged register");
1990 /* Parse a v9a or later ancillary state register. */
1993 struct priv_reg_entry *p;
1994 unsigned int len = 9999999; /* Init to make gcc happy. */
1997 for (p = v9a_asr_table; p->name; p++)
1998 if (p->name[0] == s[0])
2000 len = strlen (p->name);
2001 if (strncmp (p->name, s, len) == 0)
2007 error_message = _(": unrecognizable ancillary state register");
2011 if (((opcode >> (*args == '/' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
2013 error_message = _(": unrecognizable ancillary state register");
2022 error_message = _(": unrecognizable ancillary state register");
2028 if (strncmp (s, "%asr", 4) == 0)
2036 while (ISDIGIT (*s))
2038 num = num * 10 + *s - '0';
2042 /* We used to check here for the asr number to
2043 be between 16 and 31 in V9 and later, as
2044 mandated by the section C.1.1 "Register
2045 Names" in the SPARC spec. However, we
2046 decided to remove this restriction as a) it
2047 introduces problems when new V9 asr registers
2048 are introduced, b) the Solaris assembler
2049 doesn't implement this restriction and c) the
2050 restriction will go away in future revisions
2051 of the Oracle SPARC Architecture. */
2053 if (num < 0 || 31 < num)
2055 error_message = _(": asr number must be between 0 and 31");
2059 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
2064 error_message = _(": expecting %asrN");
2071 the_insn.reloc = BFD_RELOC_SPARC_11;
2075 the_insn.reloc = BFD_RELOC_SPARC_10;
2081 if ((s[0] == '0' && s[1] == 'x' && ISXDIGIT (s[2]))
2086 if (s[0] == '0' && s[1] == 'x')
2089 while (ISXDIGIT (*s))
2092 num |= hex_value (*s);
2098 while (ISDIGIT (*s))
2100 num = num * 10 + *s - '0';
2104 if (num < 0 || num > 31)
2106 error_message = _(": crypto immediate must be between 0 and 31");
2110 opcode |= RS3 (num);
2115 error_message = _(": expecting crypto immediate");
2120 /* V8 systems don't understand BFD_RELOC_SPARC_5. */
2121 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2122 the_insn.reloc = BFD_RELOC_SPARC_5;
2124 the_insn.reloc = BFD_RELOC_SPARC13;
2125 /* These fields are unsigned, but for upward compatibility,
2126 allow negative values as well. */
2130 /* V8 systems don't understand BFD_RELOC_SPARC_6. */
2131 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2132 the_insn.reloc = BFD_RELOC_SPARC_6;
2134 the_insn.reloc = BFD_RELOC_SPARC13;
2135 /* These fields are unsigned, but for upward compatibility,
2136 allow negative values as well. */
2140 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
2145 the_insn.reloc = /* RELOC_WDISP2_8 */ BFD_RELOC_SPARC_WDISP10;
2150 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
2155 if (*s == 'p' && s[1] == 'n')
2163 if (*s == 'p' && s[1] == 't')
2175 if ((strncmp (s, "%icc", 4) == 0)
2176 || (sparc_arch_size == 32 && strncmp (s, "%ncc", 4) == 0))
2188 if ((strncmp (s, "%xcc", 4) == 0)
2189 || (sparc_arch_size == 64 && strncmp (s, "%ncc", 4) == 0))
2201 if (strncmp (s, "%fcc0", 5) == 0)
2213 if (strncmp (s, "%fcc1", 5) == 0)
2225 if (strncmp (s, "%fcc2", 5) == 0)
2237 if (strncmp (s, "%fcc3", 5) == 0)
2245 if (strncmp (s, "%pc", 3) == 0)
2253 if (strncmp (s, "%tick", 5) == 0)
2260 case '\0': /* End of args. */
2261 if (s[0] == ',' && s[1] == '%')
2265 const struct perc_entry *p;
2267 for (p = perc_table; p->type != perc_entry_none; p++)
2268 if ((p->type == perc_entry_post_pop || p->type == perc_entry_reg)
2269 && strncmp (s + 2, p->name, p->len) == 0)
2271 if (p->type == perc_entry_none || p->type == perc_entry_reg)
2274 if (s[p->len + 2] != '(')
2276 as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
2277 return special_case;
2280 if (! (p->pop->flags & F_POP_TLS_CALL)
2281 && the_insn.reloc != BFD_RELOC_NONE)
2283 as_bad (_("Illegal operands: %%%s cannot be used together with other relocs in the insn ()"),
2285 return special_case;
2288 if ((p->pop->flags & F_POP_TLS_CALL)
2289 && (the_insn.reloc != BFD_RELOC_32_PCREL_S2
2290 || the_insn.exp.X_add_number != 0
2291 || the_insn.exp.X_add_symbol
2292 != symbol_find_or_make ("__tls_get_addr")))
2294 as_bad (_("Illegal operands: %%%s can be only used with call __tls_get_addr"),
2296 return special_case;
2299 the_insn.reloc = p->pop->reloc;
2300 memset (&the_insn.exp, 0, sizeof (the_insn.exp));
2303 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
2306 else if (*s1 == ')')
2315 as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
2316 return special_case;
2320 (void) get_expression (s);
2340 case '[': /* These must match exactly. */
2348 case '#': /* Must be at least one digit. */
2351 while (ISDIGIT (*s))
2359 case 'C': /* Coprocessor state register. */
2360 if (strncmp (s, "%csr", 4) == 0)
2367 case 'b': /* Next operand is a coprocessor register. */
2370 if (*s++ == '%' && *s++ == 'c' && ISDIGIT (*s))
2375 mask = 10 * (mask - '0') + (*s++ - '0');
2389 opcode |= mask << 14;
2397 opcode |= mask << 25;
2403 case 'r': /* next operand must be a register */
2413 case 'f': /* frame pointer */
2421 case 'g': /* global register */
2430 case 'i': /* in register */
2434 mask = c - '0' + 24;
2439 case 'l': /* local register */
2443 mask = (c - '0' + 16);
2448 case 'o': /* out register */
2452 mask = (c - '0' + 8);
2457 case 's': /* stack pointer */
2465 case 'r': /* any register */
2466 if (!ISDIGIT ((c = *s++)))
2483 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
2499 if ((mask & ~1) == 2 && sparc_arch_size == 64
2500 && no_undeclared_regs && ! globals[mask])
2501 as_bad (_("detected global register use not covered by .register pseudo-op"));
2503 /* Got the register, now figure out where
2504 it goes in the opcode. */
2508 opcode |= mask << 14;
2516 opcode |= mask << 25;
2520 opcode |= (mask << 25) | (mask << 14);
2524 opcode |= (mask << 25) | (mask << 0);
2530 case 'e': /* next operand is a floating point register */
2549 && ((format = *s) == 'f'
2554 for (mask = 0; ISDIGIT (*s); ++s)
2556 mask = 10 * mask + (*s - '0');
2557 } /* read the number */
2566 /* register must be even numbered */
2576 /* register must be multiple of 4 */
2582 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2583 error_message = _(": There are only 64 f registers; [0-63]");
2585 error_message = _(": There are only 32 f registers; [0-31]");
2588 else if (mask >= 32)
2590 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2592 if (*args == 'e' || *args == 'f' || *args == 'g')
2595 = _(": There are only 32 single precision f registers; [0-31]");
2599 mask -= 31; /* wrap high bit */
2603 error_message = _(": There are only 32 f registers; [0-31]");
2611 } /* if not an 'f' register. */
2613 if (*args == '}' && mask != RS2 (opcode))
2616 = _(": Instruction requires frs2 and frsd must be the same register");
2625 opcode |= RS1 (mask);
2631 opcode |= RS2 (mask);
2636 opcode |= RS3 (mask);
2643 opcode |= RD (mask);
2652 if (strncmp (s, "%fsr", 4) == 0)
2660 if (strncmp (s, "%efsr", 5) == 0)
2667 case '0': /* 64 bit immediate (set, setsw, setx insn) */
2668 the_insn.reloc = BFD_RELOC_NONE; /* reloc handled elsewhere */
2671 case 'l': /* 22 bit PC relative immediate */
2672 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
2676 case 'L': /* 30 bit immediate */
2677 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
2682 case 'n': /* 22 bit immediate */
2683 the_insn.reloc = BFD_RELOC_SPARC22;
2686 case 'i': /* 13 bit immediate */
2687 the_insn.reloc = BFD_RELOC_SPARC13;
2697 const char *op_arg = NULL;
2698 static expressionS op_exp;
2699 bfd_reloc_code_real_type old_reloc = the_insn.reloc;
2701 /* Check for %hi, etc. */
2704 const struct perc_entry *p;
2706 for (p = perc_table; p->type != perc_entry_none; p++)
2707 if ((p->type == perc_entry_imm_pop || p->type == perc_entry_reg)
2708 && strncmp (s + 1, p->name, p->len) == 0)
2710 if (p->type == perc_entry_none || p->type == perc_entry_reg)
2713 if (s[p->len + 1] != '(')
2715 as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
2716 return special_case;
2720 the_insn.reloc = p->pop->reloc;
2722 v9_arg_p = p->pop->flags & F_POP_V9;
2725 /* Note that if the get_expression() fails, we will still
2726 have created U entries in the symbol table for the
2727 'symbols' in the input string. Try not to create U
2728 symbols for registers, etc. */
2730 /* This stuff checks to see if the expression ends in
2731 +%reg. If it does, it removes the register from
2732 the expression, and re-sets 's' to point to the
2739 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
2742 else if (*s1 == ')')
2751 as_bad (_("Illegal operands: %%%s requires arguments in ()"), op_arg);
2752 return special_case;
2756 (void) get_expression (s);
2760 as_bad (_("Expression inside %%%s could not be parsed"), op_arg);
2761 return special_case;
2764 if (*s == ',' || *s == ']' || !*s)
2766 if (*s != '+' && *s != '-')
2768 as_bad (_("Illegal operands: Can't do arithmetics other than + and - involving %%%s()"), op_arg);
2769 return special_case;
2773 op_exp = the_insn.exp;
2774 memset (&the_insn.exp, 0, sizeof (the_insn.exp));
2777 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
2780 if (s1 != s && ISDIGIT (s1[-1]))
2782 if (s1[-2] == '%' && s1[-3] == '+')
2784 else if (strchr ("golir0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
2786 else if (s1[-3] == 'r' && s1[-4] == '%' && s1[-5] == '+')
2793 if (op_arg && s1 == s + 1)
2794 the_insn.exp.X_op = O_absent;
2796 (void) get_expression (s);
2808 (void) get_expression (s);
2816 the_insn.exp2 = the_insn.exp;
2817 the_insn.exp = op_exp;
2818 if (the_insn.exp2.X_op == O_absent)
2819 the_insn.exp2.X_op = O_illegal;
2820 else if (the_insn.exp.X_op == O_absent)
2822 the_insn.exp = the_insn.exp2;
2823 the_insn.exp2.X_op = O_illegal;
2825 else if (the_insn.exp.X_op == O_constant)
2827 valueT val = the_insn.exp.X_add_number;
2828 switch (the_insn.reloc)
2833 case BFD_RELOC_SPARC_HH22:
2834 val = BSR (val, 32);
2837 case BFD_RELOC_SPARC_LM22:
2838 case BFD_RELOC_HI22:
2839 val = (val >> 10) & 0x3fffff;
2842 case BFD_RELOC_SPARC_HM10:
2843 val = BSR (val, 32);
2846 case BFD_RELOC_LO10:
2850 case BFD_RELOC_SPARC_H34:
2855 case BFD_RELOC_SPARC_H44:
2860 case BFD_RELOC_SPARC_M44:
2865 case BFD_RELOC_SPARC_L44:
2869 case BFD_RELOC_SPARC_HIX22:
2871 val = (val >> 10) & 0x3fffff;
2874 case BFD_RELOC_SPARC_LOX10:
2875 val = (val & 0x3ff) | 0x1c00;
2878 the_insn.exp = the_insn.exp2;
2879 the_insn.exp.X_add_number += val;
2880 the_insn.exp2.X_op = O_illegal;
2881 the_insn.reloc = old_reloc;
2883 else if (the_insn.exp2.X_op != O_constant)
2885 as_bad (_("Illegal operands: Can't add non-constant expression to %%%s()"), op_arg);
2886 return special_case;
2890 if (old_reloc != BFD_RELOC_SPARC13
2891 || the_insn.reloc != BFD_RELOC_LO10
2892 || sparc_arch_size != 64
2895 as_bad (_("Illegal operands: Can't do arithmetics involving %%%s() of a relocatable symbol"), op_arg);
2896 return special_case;
2898 the_insn.reloc = BFD_RELOC_SPARC_OLO10;
2902 /* Check for constants that don't require emitting a reloc. */
2903 if (the_insn.exp.X_op == O_constant
2904 && the_insn.exp.X_add_symbol == 0
2905 && the_insn.exp.X_op_symbol == 0)
2907 /* For pc-relative call instructions, we reject
2908 constants to get better code. */
2910 && the_insn.reloc == BFD_RELOC_32_PCREL_S2
2911 && in_signed_range (the_insn.exp.X_add_number, 0x3fff))
2913 error_message = _(": PC-relative operand can't be a constant");
2917 if (the_insn.reloc >= BFD_RELOC_SPARC_TLS_GD_HI22
2918 && the_insn.reloc <= BFD_RELOC_SPARC_TLS_TPOFF64)
2920 error_message = _(": TLS operand can't be a constant");
2924 /* Constants that won't fit are checked in md_apply_fix
2925 and bfd_install_relocation.
2926 ??? It would be preferable to install the constants
2927 into the insn here and save having to create a fixS
2928 for each one. There already exists code to handle
2929 all the various cases (e.g. in md_apply_fix and
2930 bfd_install_relocation) so duplicating all that code
2931 here isn't right. */
2933 /* This is a special case to handle cbcond instructions
2934 properly, which can need two relocations. The first
2935 one is for the 5-bit immediate field and the latter
2936 is going to be for the WDISP10 branch part. We
2937 handle the R_SPARC_5 immediate directly here so that
2938 we don't need to add support for multiple relocations
2939 in one instruction just yet. */
2940 if (the_insn.reloc == BFD_RELOC_SPARC_5
2941 && ((insn->match & OP(0x3)) == 0))
2943 valueT val = the_insn.exp.X_add_number;
2945 the_insn.reloc = BFD_RELOC_NONE;
2946 if (! in_bitfield_range (val, 0x1f))
2948 error_message = _(": Immediate value in cbcond is out of range.");
2951 opcode |= val & 0x1f;
2972 if (! parse_keyword_arg (sparc_encode_asi, &s, &asi))
2974 error_message = _(": invalid ASI name");
2980 if (! parse_const_expr_arg (&s, &asi))
2982 error_message = _(": invalid ASI expression");
2985 if (asi < 0 || asi > 255)
2987 error_message = _(": invalid ASI number");
2991 opcode |= ASI (asi);
2993 } /* Alternate space. */
2996 if (strncmp (s, "%psr", 4) == 0)
3003 case 'q': /* Floating point queue. */
3004 if (strncmp (s, "%fq", 3) == 0)
3011 case 'Q': /* Coprocessor queue. */
3012 if (strncmp (s, "%cq", 3) == 0)
3020 if (strcmp (str, "set") == 0
3021 || strcmp (str, "setuw") == 0)
3023 special_case = SPECIAL_CASE_SET;
3026 else if (strcmp (str, "setsw") == 0)
3028 special_case = SPECIAL_CASE_SETSW;
3031 else if (strcmp (str, "setx") == 0)
3033 special_case = SPECIAL_CASE_SETX;
3036 else if (strncmp (str, "fdiv", 4) == 0)
3038 special_case = SPECIAL_CASE_FDIV;
3044 if (strncmp (s, "%asi", 4) != 0)
3050 if (strncmp (s, "%fprs", 5) != 0)
3056 if (strncmp (s, "%mcdper",7) != 0)
3062 if (strncmp (s, "%ccr", 4) != 0)
3068 if (strncmp (s, "%tbr", 4) != 0)
3074 if (strncmp (s, "%wim", 4) != 0)
3081 char *push = input_line_pointer;
3084 input_line_pointer = s;
3086 if (e.X_op == O_constant)
3088 int n = e.X_add_number;
3089 if (n != e.X_add_number || (n & ~0x1ff) != 0)
3090 as_bad (_("OPF immediate operand out of range (0-0x1ff)"));
3092 opcode |= e.X_add_number << 5;
3095 as_bad (_("non-immediate OPF operand, ignored"));
3096 s = input_line_pointer;
3097 input_line_pointer = push;
3102 if (strncmp (s, "%y", 2) != 0)
3110 /* Parse a sparclet cpreg. */
3112 if (! parse_keyword_arg (sparc_encode_sparclet_cpreg, &s, &cpreg))
3114 error_message = _(": invalid cpreg name");
3117 opcode |= (*args == 'U' ? RS1 (cpreg) : RD (cpreg));
3122 as_fatal (_("failed sanity check."));
3123 } /* switch on arg code. */
3125 /* Break out of for() loop. */
3127 } /* For each arg that we expect. */
3132 /* Args don't match. */
3133 if (&insn[1] - sparc_opcodes < sparc_num_opcodes
3134 && (insn->name == insn[1].name
3135 || !strcmp (insn->name, insn[1].name)))
3143 as_bad (_("Illegal operands%s"), error_message);
3144 return special_case;
3149 /* We have a match. Now see if the architecture is OK. */
3150 int needed_arch_mask = insn->architecture;
3152 = (((bfd_uint64_t) insn->hwcaps2) << 32) | insn->hwcaps;
3154 #if defined(OBJ_ELF) && !defined(TE_SOLARIS)
3156 hwcap_seen |= hwcaps;
3161 ~(SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9) - 1);
3162 if (! needed_arch_mask)
3164 SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9);
3167 if (needed_arch_mask
3168 & SPARC_OPCODE_SUPPORTED (current_architecture))
3171 /* Can we bump up the architecture? */
3172 else if (needed_arch_mask
3173 & SPARC_OPCODE_SUPPORTED (max_architecture))
3175 enum sparc_opcode_arch_val needed_architecture =
3176 sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture)
3177 & needed_arch_mask);
3179 gas_assert (needed_architecture <= SPARC_OPCODE_ARCH_MAX);
3181 && needed_architecture > warn_after_architecture)
3183 as_warn (_("architecture bumped from \"%s\" to \"%s\" on \"%s\""),
3184 sparc_opcode_archs[current_architecture].name,
3185 sparc_opcode_archs[needed_architecture].name,
3187 warn_after_architecture = needed_architecture;
3189 current_architecture = needed_architecture;
3193 | (((bfd_uint64_t) sparc_opcode_archs[current_architecture].hwcaps2) << 32)
3194 | sparc_opcode_archs[current_architecture].hwcaps);
3197 /* ??? This seems to be a bit fragile. What if the next entry in
3198 the opcode table is the one we want and it is supported?
3199 It is possible to arrange the table today so that this can't
3200 happen but what about tomorrow? */
3203 int arch, printed_one_p = 0;
3205 char required_archs[SPARC_OPCODE_ARCH_MAX * 16];
3207 /* Create a list of the architectures that support the insn. */
3208 needed_arch_mask &= ~SPARC_OPCODE_SUPPORTED (max_architecture);
3210 arch = sparc_ffs (needed_arch_mask);
3211 while ((1 << arch) <= needed_arch_mask)
3213 if ((1 << arch) & needed_arch_mask)
3217 strcpy (p, sparc_opcode_archs[arch].name);
3224 as_bad (_("Architecture mismatch on \"%s %s\"."), str, argsStart);
3225 as_tsktsk (_(" (Requires %s; requested architecture is %s.)"),
3227 sparc_opcode_archs[max_architecture].name);
3228 return special_case;
3231 /* Make sure the hwcaps used by the instruction are
3232 currently enabled. */
3233 if (hwcaps & ~hwcap_allowed)
3235 const char *hwcap_name = get_hwcap_name(hwcaps & ~hwcap_allowed);
3237 as_bad (_("Hardware capability \"%s\" not enabled for \"%s\"."),
3239 return special_case;
3241 } /* If no match. */
3244 } /* Forever looking for a match. */
3246 the_insn.opcode = opcode;
3247 return special_case;
3250 /* Parse an argument that can be expressed as a keyword.
3251 (eg: #StoreStore or %ccfr).
3252 The result is a boolean indicating success.
3253 If successful, INPUT_POINTER is updated. */
3256 parse_keyword_arg (int (*lookup_fn) (const char *),
3257 char **input_pointerP,
3263 p = *input_pointerP;
3264 for (q = p + (*p == '#' || *p == '%');
3265 ISALNUM (*q) || *q == '_';
3270 value = (*lookup_fn) (p);
3275 *input_pointerP = q;
3279 /* Parse an argument that is a constant expression.
3280 The result is a boolean indicating success. */
3283 parse_const_expr_arg (char **input_pointerP, int *valueP)
3285 char *save = input_line_pointer;
3288 input_line_pointer = *input_pointerP;
3289 /* The next expression may be something other than a constant
3290 (say if we're not processing the right variant of the insn).
3291 Don't call expression unless we're sure it will succeed as it will
3292 signal an error (which we want to defer until later). */
3293 /* FIXME: It might be better to define md_operand and have it recognize
3294 things like %asi, etc. but continuing that route through to the end
3295 is a lot of work. */
3296 if (*input_line_pointer == '%')
3298 input_line_pointer = save;
3302 *input_pointerP = input_line_pointer;
3303 input_line_pointer = save;
3304 if (exp.X_op != O_constant)
3306 *valueP = exp.X_add_number;
3310 /* Subroutine of sparc_ip to parse an expression. */
3313 get_expression (char *str)
3318 save_in = input_line_pointer;
3319 input_line_pointer = str;
3320 seg = expression (&the_insn.exp);
3321 if (seg != absolute_section
3322 && seg != text_section
3323 && seg != data_section
3324 && seg != bss_section
3325 && seg != undefined_section)
3327 the_insn.error = _("bad segment");
3328 expr_end = input_line_pointer;
3329 input_line_pointer = save_in;
3332 expr_end = input_line_pointer;
3333 input_line_pointer = save_in;
3337 /* Subroutine of md_assemble to output one insn. */
3340 output_insn (const struct sparc_opcode *insn, struct sparc_it *theinsn)
3342 char *toP = frag_more (4);
3344 /* Put out the opcode. */
3345 if (INSN_BIG_ENDIAN)
3346 number_to_chars_bigendian (toP, (valueT) theinsn->opcode, 4);
3348 number_to_chars_littleendian (toP, (valueT) theinsn->opcode, 4);
3350 /* Put out the symbol-dependent stuff. */
3351 if (theinsn->reloc != BFD_RELOC_NONE)
3353 fixS *fixP = fix_new_exp (frag_now, /* Which frag. */
3354 (toP - frag_now->fr_literal), /* Where. */
3359 /* Turn off overflow checking in fixup_segment. We'll do our
3360 own overflow checking in md_apply_fix. This is necessary because
3361 the insn size is 4 and fixup_segment will signal an overflow for
3362 large 8 byte quantities. */
3363 fixP->fx_no_overflow = 1;
3364 if (theinsn->reloc == BFD_RELOC_SPARC_OLO10)
3365 fixP->tc_fix_data = theinsn->exp2.X_add_number;
3369 last_opcode = theinsn->opcode;
3372 dwarf2_emit_insn (4);
3377 md_atof (int type, char *litP, int *sizeP)
3379 return ieee_md_atof (type, litP, sizeP, target_big_endian);
3382 /* Write a value out to the object file, using the appropriate
3386 md_number_to_chars (char *buf, valueT val, int n)
3388 if (target_big_endian)
3389 number_to_chars_bigendian (buf, val, n);
3390 else if (target_little_endian_data
3391 && ((n == 4 || n == 2) && ~now_seg->flags & SEC_ALLOC))
3392 /* Output debug words, which are not in allocated sections, as big
3394 number_to_chars_bigendian (buf, val, n);
3395 else if (target_little_endian_data || ! target_big_endian)
3396 number_to_chars_littleendian (buf, val, n);
3399 /* Apply a fixS to the frags, now that we know the value it ought to
3403 md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
3405 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3406 offsetT val = * (offsetT *) valP;
3409 gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
3411 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
3414 /* SPARC ELF relocations don't use an addend in the data field. */
3415 if (fixP->fx_addsy != NULL)
3417 switch (fixP->fx_r_type)
3419 case BFD_RELOC_SPARC_TLS_GD_HI22:
3420 case BFD_RELOC_SPARC_TLS_GD_LO10:
3421 case BFD_RELOC_SPARC_TLS_GD_ADD:
3422 case BFD_RELOC_SPARC_TLS_GD_CALL:
3423 case BFD_RELOC_SPARC_TLS_LDM_HI22:
3424 case BFD_RELOC_SPARC_TLS_LDM_LO10:
3425 case BFD_RELOC_SPARC_TLS_LDM_ADD:
3426 case BFD_RELOC_SPARC_TLS_LDM_CALL:
3427 case BFD_RELOC_SPARC_TLS_LDO_HIX22:
3428 case BFD_RELOC_SPARC_TLS_LDO_LOX10:
3429 case BFD_RELOC_SPARC_TLS_LDO_ADD:
3430 case BFD_RELOC_SPARC_TLS_IE_HI22:
3431 case BFD_RELOC_SPARC_TLS_IE_LO10:
3432 case BFD_RELOC_SPARC_TLS_IE_LD:
3433 case BFD_RELOC_SPARC_TLS_IE_LDX:
3434 case BFD_RELOC_SPARC_TLS_IE_ADD:
3435 case BFD_RELOC_SPARC_TLS_LE_HIX22:
3436 case BFD_RELOC_SPARC_TLS_LE_LOX10:
3437 case BFD_RELOC_SPARC_TLS_DTPMOD32:
3438 case BFD_RELOC_SPARC_TLS_DTPMOD64:
3439 case BFD_RELOC_SPARC_TLS_DTPOFF32:
3440 case BFD_RELOC_SPARC_TLS_DTPOFF64:
3441 case BFD_RELOC_SPARC_TLS_TPOFF32:
3442 case BFD_RELOC_SPARC_TLS_TPOFF64:
3443 S_SET_THREAD_LOCAL (fixP->fx_addsy);
3453 /* This is a hack. There should be a better way to
3454 handle this. Probably in terms of howto fields, once
3455 we can look at these fixups in terms of howtos. */
3456 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
3457 val += fixP->fx_where + fixP->fx_frag->fr_address;
3460 /* FIXME: More ridiculous gas reloc hacking. If we are going to
3461 generate a reloc, then we just want to let the reloc addend set
3462 the value. We do not want to also stuff the addend into the
3463 object file. Including the addend in the object file works when
3464 doing a static link, because the linker will ignore the object
3465 file contents. However, the dynamic linker does not ignore the
3466 object file contents. */
3467 if (fixP->fx_addsy != NULL
3468 && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
3471 /* When generating PIC code, we do not want an addend for a reloc
3472 against a local symbol. We adjust fx_addnumber to cancel out the
3473 value already included in val, and to also cancel out the
3474 adjustment which bfd_install_relocation will create. */
3476 && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2
3477 && fixP->fx_addsy != NULL
3478 && ! S_IS_COMMON (fixP->fx_addsy)
3479 && symbol_section_p (fixP->fx_addsy))
3480 fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy);
3482 /* When generating PIC code, we need to fiddle to get
3483 bfd_install_relocation to do the right thing for a PC relative
3484 reloc against a local symbol which we are going to keep. */
3486 && fixP->fx_r_type == BFD_RELOC_32_PCREL_S2
3487 && fixP->fx_addsy != NULL
3488 && (S_IS_EXTERNAL (fixP->fx_addsy)
3489 || S_IS_WEAK (fixP->fx_addsy))
3490 && S_IS_DEFINED (fixP->fx_addsy)
3491 && ! S_IS_COMMON (fixP->fx_addsy))
3494 fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy);
3498 /* If this is a data relocation, just output VAL. */
3500 if (fixP->fx_r_type == BFD_RELOC_8)
3502 md_number_to_chars (buf, val, 1);
3504 else if (fixP->fx_r_type == BFD_RELOC_16
3505 || fixP->fx_r_type == BFD_RELOC_SPARC_UA16)
3507 md_number_to_chars (buf, val, 2);
3509 else if (fixP->fx_r_type == BFD_RELOC_32
3510 || fixP->fx_r_type == BFD_RELOC_SPARC_UA32
3511 || fixP->fx_r_type == BFD_RELOC_SPARC_REV32)
3513 md_number_to_chars (buf, val, 4);
3515 else if (fixP->fx_r_type == BFD_RELOC_64
3516 || fixP->fx_r_type == BFD_RELOC_SPARC_UA64)
3518 md_number_to_chars (buf, val, 8);
3520 else if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
3521 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
3528 /* It's a relocation against an instruction. */
3530 if (INSN_BIG_ENDIAN)
3531 insn = bfd_getb32 ((unsigned char *) buf);
3533 insn = bfd_getl32 ((unsigned char *) buf);
3535 switch (fixP->fx_r_type)
3537 case BFD_RELOC_32_PCREL_S2:
3539 /* FIXME: This increment-by-one deserves a comment of why it's
3541 if (! sparc_pic_code
3542 || fixP->fx_addsy == NULL
3543 || symbol_section_p (fixP->fx_addsy))
3546 insn |= val & 0x3fffffff;
3548 /* See if we have a delay slot. */
3549 if (sparc_relax && fixP->fx_where + 8 <= fixP->fx_frag->fr_fix)
3553 #define XCC (2 << 20)
3554 #define COND(x) (((x)&0xf)<<25)
3555 #define CONDA COND(0x8)
3556 #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
3557 #define INSN_BA (F2(0,2) | CONDA)
3558 #define INSN_OR F3(2, 0x2, 0)
3559 #define INSN_NOP F2(0,4)
3563 /* If the instruction is a call with either:
3565 arithmetic instruction with rd == %o7
3566 where rs1 != %o7 and rs2 if it is register != %o7
3567 then we can optimize if the call destination is near
3568 by changing the call into a branch always. */
3569 if (INSN_BIG_ENDIAN)
3570 delay = bfd_getb32 ((unsigned char *) buf + 4);
3572 delay = bfd_getl32 ((unsigned char *) buf + 4);
3573 if ((insn & OP (~0)) != OP (1) || (delay & OP (~0)) != OP (2))
3575 if ((delay & OP3 (~0)) != OP3 (0x3d) /* Restore. */
3576 && ((delay & OP3 (0x28)) != 0 /* Arithmetic. */
3577 || ((delay & RD (~0)) != RD (O7))))
3579 if ((delay & RS1 (~0)) == RS1 (O7)
3580 || ((delay & F3I (~0)) == 0
3581 && (delay & RS2 (~0)) == RS2 (O7)))
3583 /* Ensure the branch will fit into simm22. */
3584 if ((val & 0x3fe00000)
3585 && (val & 0x3fe00000) != 0x3fe00000)
3587 /* Check if the arch is v9 and branch will fit
3589 if (((val & 0x3c0000) == 0
3590 || (val & 0x3c0000) == 0x3c0000)
3591 && (sparc_arch_size == 64
3592 || current_architecture >= SPARC_OPCODE_ARCH_V9))
3594 insn = INSN_BPA | (val & 0x7ffff);
3597 insn = INSN_BA | (val & 0x3fffff);
3598 if (fixP->fx_where >= 4
3599 && ((delay & (0xffffffff ^ RS1 (~0)))
3600 == (INSN_OR | RD (O7) | RS2 (G0))))
3605 if (INSN_BIG_ENDIAN)
3606 setter = bfd_getb32 ((unsigned char *) buf - 4);
3608 setter = bfd_getl32 ((unsigned char *) buf - 4);
3609 if ((setter & (0xffffffff ^ RD (~0)))
3610 != (INSN_OR | RS1 (O7) | RS2 (G0)))
3617 If call foo was replaced with ba, replace
3618 or %rN, %g0, %o7 with nop. */
3619 reg = (delay & RS1 (~0)) >> 14;
3620 if (reg != ((setter & RD (~0)) >> 25)
3621 || reg == G0 || reg == O7)
3624 if (INSN_BIG_ENDIAN)
3625 bfd_putb32 (INSN_NOP, (unsigned char *) buf + 4);
3627 bfd_putl32 (INSN_NOP, (unsigned char *) buf + 4);
3632 case BFD_RELOC_SPARC_11:
3633 if (! in_signed_range (val, 0x7ff))
3634 as_bad_where (fixP->fx_file, fixP->fx_line,
3635 _("relocation overflow"));
3636 insn |= val & 0x7ff;
3639 case BFD_RELOC_SPARC_10:
3640 if (! in_signed_range (val, 0x3ff))
3641 as_bad_where (fixP->fx_file, fixP->fx_line,
3642 _("relocation overflow"));
3643 insn |= val & 0x3ff;
3646 case BFD_RELOC_SPARC_7:
3647 if (! in_bitfield_range (val, 0x7f))
3648 as_bad_where (fixP->fx_file, fixP->fx_line,
3649 _("relocation overflow"));
3653 case BFD_RELOC_SPARC_6:
3654 if (! in_bitfield_range (val, 0x3f))
3655 as_bad_where (fixP->fx_file, fixP->fx_line,
3656 _("relocation overflow"));
3660 case BFD_RELOC_SPARC_5:
3661 if (! in_bitfield_range (val, 0x1f))
3662 as_bad_where (fixP->fx_file, fixP->fx_line,
3663 _("relocation overflow"));
3667 case BFD_RELOC_SPARC_WDISP10:
3670 || val <= -(offsetT) 0x808)
3671 as_bad_where (fixP->fx_file, fixP->fx_line,
3672 _("relocation overflow"));
3673 /* FIXME: The +1 deserves a comment. */
3674 val = (val >> 2) + 1;
3675 insn |= ((val & 0x300) << 11)
3676 | ((val & 0xff) << 5);
3679 case BFD_RELOC_SPARC_WDISP16:
3682 || val <= -(offsetT) 0x20008)
3683 as_bad_where (fixP->fx_file, fixP->fx_line,
3684 _("relocation overflow"));
3685 /* FIXME: The +1 deserves a comment. */
3686 val = (val >> 2) + 1;
3687 insn |= ((val & 0xc000) << 6) | (val & 0x3fff);
3690 case BFD_RELOC_SPARC_WDISP19:
3693 || val <= -(offsetT) 0x100008)
3694 as_bad_where (fixP->fx_file, fixP->fx_line,
3695 _("relocation overflow"));
3696 /* FIXME: The +1 deserves a comment. */
3697 val = (val >> 2) + 1;
3698 insn |= val & 0x7ffff;
3701 case BFD_RELOC_SPARC_HH22:
3702 val = BSR (val, 32);
3705 case BFD_RELOC_SPARC_LM22:
3706 case BFD_RELOC_HI22:
3707 if (!fixP->fx_addsy)
3708 insn |= (val >> 10) & 0x3fffff;
3710 /* FIXME: Need comment explaining why we do this. */
3714 case BFD_RELOC_SPARC22:
3715 if (val & ~0x003fffff)
3716 as_bad_where (fixP->fx_file, fixP->fx_line,
3717 _("relocation overflow"));
3718 insn |= (val & 0x3fffff);
3721 case BFD_RELOC_SPARC_HM10:
3722 val = BSR (val, 32);
3725 case BFD_RELOC_LO10:
3726 if (!fixP->fx_addsy)
3727 insn |= val & 0x3ff;
3729 /* FIXME: Need comment explaining why we do this. */
3733 case BFD_RELOC_SPARC_OLO10:
3735 val += fixP->tc_fix_data;
3738 case BFD_RELOC_SPARC13:
3739 if (! in_signed_range (val, 0x1fff))
3740 as_bad_where (fixP->fx_file, fixP->fx_line,
3741 _("relocation overflow"));
3742 insn |= val & 0x1fff;
3745 case BFD_RELOC_SPARC_WDISP22:
3746 val = (val >> 2) + 1;
3748 case BFD_RELOC_SPARC_BASE22:
3749 insn |= val & 0x3fffff;
3752 case BFD_RELOC_SPARC_H34:
3753 if (!fixP->fx_addsy)
3757 insn |= tval & 0x3fffff;
3761 case BFD_RELOC_SPARC_H44:
3762 if (!fixP->fx_addsy)
3766 insn |= tval & 0x3fffff;
3770 case BFD_RELOC_SPARC_M44:
3771 if (!fixP->fx_addsy)
3772 insn |= (val >> 12) & 0x3ff;
3775 case BFD_RELOC_SPARC_L44:
3776 if (!fixP->fx_addsy)
3777 insn |= val & 0xfff;
3780 case BFD_RELOC_SPARC_HIX22:
3781 if (!fixP->fx_addsy)
3783 val ^= ~(offsetT) 0;
3784 insn |= (val >> 10) & 0x3fffff;
3788 case BFD_RELOC_SPARC_LOX10:
3789 if (!fixP->fx_addsy)
3790 insn |= 0x1c00 | (val & 0x3ff);
3793 case BFD_RELOC_NONE:
3795 as_bad_where (fixP->fx_file, fixP->fx_line,
3796 _("bad or unhandled relocation type: 0x%02x"),
3801 if (INSN_BIG_ENDIAN)
3802 bfd_putb32 (insn, (unsigned char *) buf);
3804 bfd_putl32 (insn, (unsigned char *) buf);
3807 /* Are we finished with this relocation now? */
3808 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
3812 /* Translate internal representation of relocation info to BFD target
3816 tc_gen_reloc (asection *section, fixS *fixp)
3818 static arelent *relocs[3];
3820 bfd_reloc_code_real_type code;
3822 relocs[0] = reloc = XNEW (arelent);
3825 reloc->sym_ptr_ptr = XNEW (asymbol *);
3826 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
3827 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
3829 switch (fixp->fx_r_type)
3833 case BFD_RELOC_HI22:
3834 case BFD_RELOC_LO10:
3835 case BFD_RELOC_32_PCREL_S2:
3836 case BFD_RELOC_SPARC13:
3837 case BFD_RELOC_SPARC22:
3838 case BFD_RELOC_SPARC_PC22:
3839 case BFD_RELOC_SPARC_PC10:
3840 case BFD_RELOC_SPARC_BASE13:
3841 case BFD_RELOC_SPARC_WDISP10:
3842 case BFD_RELOC_SPARC_WDISP16:
3843 case BFD_RELOC_SPARC_WDISP19:
3844 case BFD_RELOC_SPARC_WDISP22:
3846 case BFD_RELOC_SPARC_5:
3847 case BFD_RELOC_SPARC_6:
3848 case BFD_RELOC_SPARC_7:
3849 case BFD_RELOC_SPARC_10:
3850 case BFD_RELOC_SPARC_11:
3851 case BFD_RELOC_SPARC_HH22:
3852 case BFD_RELOC_SPARC_HM10:
3853 case BFD_RELOC_SPARC_LM22:
3854 case BFD_RELOC_SPARC_PC_HH22:
3855 case BFD_RELOC_SPARC_PC_HM10:
3856 case BFD_RELOC_SPARC_PC_LM22:
3857 case BFD_RELOC_SPARC_H34:
3858 case BFD_RELOC_SPARC_H44:
3859 case BFD_RELOC_SPARC_M44:
3860 case BFD_RELOC_SPARC_L44:
3861 case BFD_RELOC_SPARC_HIX22:
3862 case BFD_RELOC_SPARC_LOX10:
3863 case BFD_RELOC_SPARC_REV32:
3864 case BFD_RELOC_SPARC_OLO10:
3865 case BFD_RELOC_SPARC_UA16:
3866 case BFD_RELOC_SPARC_UA32:
3867 case BFD_RELOC_SPARC_UA64:
3868 case BFD_RELOC_8_PCREL:
3869 case BFD_RELOC_16_PCREL:
3870 case BFD_RELOC_32_PCREL:
3871 case BFD_RELOC_64_PCREL:
3872 case BFD_RELOC_SPARC_PLT32:
3873 case BFD_RELOC_SPARC_PLT64:
3874 case BFD_RELOC_VTABLE_ENTRY:
3875 case BFD_RELOC_VTABLE_INHERIT:
3876 case BFD_RELOC_SPARC_TLS_GD_HI22:
3877 case BFD_RELOC_SPARC_TLS_GD_LO10:
3878 case BFD_RELOC_SPARC_TLS_GD_ADD:
3879 case BFD_RELOC_SPARC_TLS_GD_CALL:
3880 case BFD_RELOC_SPARC_TLS_LDM_HI22:
3881 case BFD_RELOC_SPARC_TLS_LDM_LO10:
3882 case BFD_RELOC_SPARC_TLS_LDM_ADD:
3883 case BFD_RELOC_SPARC_TLS_LDM_CALL:
3884 case BFD_RELOC_SPARC_TLS_LDO_HIX22:
3885 case BFD_RELOC_SPARC_TLS_LDO_LOX10:
3886 case BFD_RELOC_SPARC_TLS_LDO_ADD:
3887 case BFD_RELOC_SPARC_TLS_IE_HI22:
3888 case BFD_RELOC_SPARC_TLS_IE_LO10:
3889 case BFD_RELOC_SPARC_TLS_IE_LD:
3890 case BFD_RELOC_SPARC_TLS_IE_LDX:
3891 case BFD_RELOC_SPARC_TLS_IE_ADD:
3892 case BFD_RELOC_SPARC_TLS_LE_HIX22:
3893 case BFD_RELOC_SPARC_TLS_LE_LOX10:
3894 case BFD_RELOC_SPARC_TLS_DTPOFF32:
3895 case BFD_RELOC_SPARC_TLS_DTPOFF64:
3896 case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
3897 case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
3898 case BFD_RELOC_SPARC_GOTDATA_OP:
3899 code = fixp->fx_r_type;
3906 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
3907 /* If we are generating PIC code, we need to generate a different
3911 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
3913 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
3916 #define GOTT_BASE "__GOTT_BASE__"
3917 #define GOTT_INDEX "__GOTT_INDEX__"
3920 /* This code must be parallel to the OBJ_ELF tc_fix_adjustable. */
3926 case BFD_RELOC_32_PCREL_S2:
3927 if (generic_force_reloc (fixp))
3928 code = BFD_RELOC_SPARC_WPLT30;
3930 case BFD_RELOC_HI22:
3931 code = BFD_RELOC_SPARC_GOT22;
3932 if (fixp->fx_addsy != NULL)
3934 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
3935 code = BFD_RELOC_SPARC_PC22;
3937 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_BASE) == 0
3938 || strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_INDEX) == 0)
3939 code = BFD_RELOC_HI22; /* Unchanged. */
3943 case BFD_RELOC_LO10:
3944 code = BFD_RELOC_SPARC_GOT10;
3945 if (fixp->fx_addsy != NULL)
3947 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
3948 code = BFD_RELOC_SPARC_PC10;
3950 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_BASE) == 0
3951 || strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_INDEX) == 0)
3952 code = BFD_RELOC_LO10; /* Unchanged. */
3956 case BFD_RELOC_SPARC13:
3957 code = BFD_RELOC_SPARC_GOT13;
3963 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
3965 /* Nothing is aligned in DWARF debugging sections. */
3966 if (bfd_get_section_flags (stdoutput, section) & SEC_DEBUGGING)
3969 case BFD_RELOC_16: code = BFD_RELOC_SPARC_UA16; break;
3970 case BFD_RELOC_32: code = BFD_RELOC_SPARC_UA32; break;
3971 case BFD_RELOC_64: code = BFD_RELOC_SPARC_UA64; break;
3975 if (code == BFD_RELOC_SPARC_OLO10)
3976 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO10);
3978 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
3979 if (reloc->howto == 0)
3981 as_bad_where (fixp->fx_file, fixp->fx_line,
3982 _("internal error: can't export reloc type %d (`%s')"),
3983 fixp->fx_r_type, bfd_get_reloc_code_name (code));
3989 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
3992 if (reloc->howto->pc_relative == 0
3993 || code == BFD_RELOC_SPARC_PC10
3994 || code == BFD_RELOC_SPARC_PC22)
3995 reloc->addend = fixp->fx_addnumber;
3996 else if (sparc_pic_code
3997 && fixp->fx_r_type == BFD_RELOC_32_PCREL_S2
3998 && fixp->fx_addsy != NULL
3999 && (S_IS_EXTERNAL (fixp->fx_addsy)
4000 || S_IS_WEAK (fixp->fx_addsy))
4001 && S_IS_DEFINED (fixp->fx_addsy)
4002 && ! S_IS_COMMON (fixp->fx_addsy))
4003 reloc->addend = fixp->fx_addnumber;
4005 reloc->addend = fixp->fx_offset - reloc->address;
4007 #else /* elf or coff */
4009 if (code != BFD_RELOC_32_PCREL_S2
4010 && code != BFD_RELOC_SPARC_WDISP22
4011 && code != BFD_RELOC_SPARC_WDISP16
4012 && code != BFD_RELOC_SPARC_WDISP19
4013 && code != BFD_RELOC_SPARC_WDISP10
4014 && code != BFD_RELOC_SPARC_WPLT30
4015 && code != BFD_RELOC_SPARC_TLS_GD_CALL
4016 && code != BFD_RELOC_SPARC_TLS_LDM_CALL)
4017 reloc->addend = fixp->fx_addnumber;
4018 else if (symbol_section_p (fixp->fx_addsy))
4019 reloc->addend = (section->vma
4020 + fixp->fx_addnumber
4021 + md_pcrel_from (fixp));
4023 reloc->addend = fixp->fx_offset;
4026 /* We expand R_SPARC_OLO10 to R_SPARC_LO10 and R_SPARC_13
4027 on the same location. */
4028 if (code == BFD_RELOC_SPARC_OLO10)
4030 relocs[1] = reloc = XNEW (arelent);
4033 reloc->sym_ptr_ptr = XNEW (asymbol *);
4035 = symbol_get_bfdsym (section_symbol (absolute_section));
4036 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4037 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_SPARC13);
4038 reloc->addend = fixp->tc_fix_data;
4044 /* We have no need to default values of symbols. */
4047 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
4052 /* Round up a section size to the appropriate boundary. */
4055 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
4058 /* This is not right for ELF; a.out wants it, and COFF will force
4059 the alignment anyways. */
4060 valueT align = ((valueT) 1
4061 << (valueT) bfd_get_section_alignment (stdoutput, segment));
4064 /* Turn alignment value into a mask. */
4066 newsize = (size + align) & ~align;
4073 /* Exactly what point is a PC-relative offset relative TO?
4074 On the sparc, they're relative to the address of the offset, plus
4075 its size. This gets us to the following instruction.
4076 (??? Is this right? FIXME-SOON) */
4078 md_pcrel_from (fixS *fixP)
4082 ret = fixP->fx_where + fixP->fx_frag->fr_address;
4083 if (! sparc_pic_code
4084 || fixP->fx_addsy == NULL
4085 || symbol_section_p (fixP->fx_addsy))
4086 ret += fixP->fx_size;
4090 /* Return log2 (VALUE), or -1 if VALUE is not an exact positive power
4101 for (shift = 0; (value & 1) == 0; value >>= 1)
4104 return (value == 1) ? shift : -1;
4107 /* Sort of like s_lcomm. */
4110 static int max_alignment = 15;
4114 s_reserve (int ignore ATTRIBUTE_UNUSED)
4124 c = get_symbol_name (&name);
4125 p = input_line_pointer;
4127 SKIP_WHITESPACE_AFTER_NAME ();
4129 if (*input_line_pointer != ',')
4131 as_bad (_("Expected comma after name"));
4132 ignore_rest_of_line ();
4136 ++input_line_pointer;
4138 if ((size = get_absolute_expression ()) < 0)
4140 as_bad (_("BSS length (%d.) <0! Ignored."), size);
4141 ignore_rest_of_line ();
4146 symbolP = symbol_find_or_make (name);
4149 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
4150 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
4152 as_bad (_("bad .reserve segment -- expected BSS segment"));
4156 if (input_line_pointer[2] == '.')
4157 input_line_pointer += 7;
4159 input_line_pointer += 6;
4162 if (*input_line_pointer == ',')
4164 ++input_line_pointer;
4167 if (*input_line_pointer == '\n')
4169 as_bad (_("missing alignment"));
4170 ignore_rest_of_line ();
4174 align = (int) get_absolute_expression ();
4177 if (align > max_alignment)
4179 align = max_alignment;
4180 as_warn (_("alignment too large; assuming %d"), align);
4186 as_bad (_("negative alignment"));
4187 ignore_rest_of_line ();
4193 temp = mylog2 (align);
4196 as_bad (_("alignment not a power of 2"));
4197 ignore_rest_of_line ();
4204 record_alignment (bss_section, align);
4209 if (!S_IS_DEFINED (symbolP)
4211 && S_GET_OTHER (symbolP) == 0
4212 && S_GET_DESC (symbolP) == 0
4219 segT current_seg = now_seg;
4220 subsegT current_subseg = now_subseg;
4222 /* Switch to bss. */
4223 subseg_set (bss_section, 1);
4227 frag_align (align, 0, 0);
4229 /* Detach from old frag. */
4230 if (S_GET_SEGMENT (symbolP) == bss_section)
4231 symbol_get_frag (symbolP)->fr_symbol = NULL;
4233 symbol_set_frag (symbolP, frag_now);
4234 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
4235 (offsetT) size, (char *) 0);
4238 S_SET_SEGMENT (symbolP, bss_section);
4240 subseg_set (current_seg, current_subseg);
4243 S_SET_SIZE (symbolP, size);
4249 as_warn (_("Ignoring attempt to re-define symbol %s"),
4250 S_GET_NAME (symbolP));
4253 demand_empty_rest_of_line ();
4257 s_common (int ignore ATTRIBUTE_UNUSED)
4265 c = get_symbol_name (&name);
4266 /* Just after name is now '\0'. */
4267 p = input_line_pointer;
4269 SKIP_WHITESPACE_AFTER_NAME ();
4270 if (*input_line_pointer != ',')
4272 as_bad (_("Expected comma after symbol-name"));
4273 ignore_rest_of_line ();
4278 input_line_pointer++;
4280 if ((temp = get_absolute_expression ()) < 0)
4282 as_bad (_(".COMMon length (%lu) out of range ignored"),
4283 (unsigned long) temp);
4284 ignore_rest_of_line ();
4289 symbolP = symbol_find_or_make (name);
4291 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4293 as_bad (_("Ignoring attempt to re-define symbol"));
4294 ignore_rest_of_line ();
4297 if (S_GET_VALUE (symbolP) != 0)
4299 if (S_GET_VALUE (symbolP) != (valueT) size)
4301 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4302 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), (long) size);
4308 S_SET_VALUE (symbolP, (valueT) size);
4309 S_SET_EXTERNAL (symbolP);
4312 know (symbol_get_frag (symbolP) == &zero_address_frag);
4313 if (*input_line_pointer != ',')
4315 as_bad (_("Expected comma after common length"));
4316 ignore_rest_of_line ();
4319 input_line_pointer++;
4321 if (*input_line_pointer != '"')
4323 temp = get_absolute_expression ();
4326 if (temp > max_alignment)
4328 temp = max_alignment;
4329 as_warn (_("alignment too large; assuming %ld"), (long) temp);
4335 as_bad (_("negative alignment"));
4336 ignore_rest_of_line ();
4341 if (symbol_get_obj (symbolP)->local)
4348 old_subsec = now_subseg;
4353 align = mylog2 (temp);
4357 as_bad (_("alignment not a power of 2"));
4358 ignore_rest_of_line ();
4362 record_alignment (bss_section, align);
4363 subseg_set (bss_section, 0);
4365 frag_align (align, 0, 0);
4366 if (S_GET_SEGMENT (symbolP) == bss_section)
4367 symbol_get_frag (symbolP)->fr_symbol = 0;
4368 symbol_set_frag (symbolP, frag_now);
4369 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
4370 (offsetT) size, (char *) 0);
4372 S_SET_SEGMENT (symbolP, bss_section);
4373 S_CLEAR_EXTERNAL (symbolP);
4374 S_SET_SIZE (symbolP, size);
4375 subseg_set (old_sec, old_subsec);
4378 #endif /* OBJ_ELF */
4381 S_SET_VALUE (symbolP, (valueT) size);
4383 S_SET_ALIGN (symbolP, temp);
4384 S_SET_SIZE (symbolP, size);
4386 S_SET_EXTERNAL (symbolP);
4387 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
4392 input_line_pointer++;
4393 /* @@ Some use the dot, some don't. Can we get some consistency?? */
4394 if (*input_line_pointer == '.')
4395 input_line_pointer++;
4396 /* @@ Some say data, some say bss. */
4397 if (strncmp (input_line_pointer, "bss\"", 4)
4398 && strncmp (input_line_pointer, "data\"", 5))
4400 while (*--input_line_pointer != '"')
4402 input_line_pointer--;
4403 goto bad_common_segment;
4405 while (*input_line_pointer++ != '"')
4407 goto allocate_common;
4410 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
4412 demand_empty_rest_of_line ();
4417 p = input_line_pointer;
4418 while (*p && *p != '\n')
4422 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
4424 input_line_pointer = p;
4425 ignore_rest_of_line ();
4430 /* Handle the .empty pseudo-op. This suppresses the warnings about
4431 invalid delay slot usage. */
4434 s_empty (int ignore ATTRIBUTE_UNUSED)
4436 /* The easy way to implement is to just forget about the last
4442 s_seg (int ignore ATTRIBUTE_UNUSED)
4445 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
4447 input_line_pointer += 6;
4451 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
4453 input_line_pointer += 6;
4457 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
4459 input_line_pointer += 7;
4463 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
4465 input_line_pointer += 5;
4466 /* We only support 2 segments -- text and data -- for now, so
4467 things in the "bss segment" will have to go into data for now.
4468 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
4469 subseg_set (data_section, 255); /* FIXME-SOMEDAY. */
4472 as_bad (_("Unknown segment type"));
4473 demand_empty_rest_of_line ();
4479 subseg_set (data_section, 1);
4480 demand_empty_rest_of_line ();
4484 s_proc (int ignore ATTRIBUTE_UNUSED)
4486 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4488 ++input_line_pointer;
4490 ++input_line_pointer;
4493 /* This static variable is set by s_uacons to tell sparc_cons_align
4494 that the expression does not need to be aligned. */
4496 static int sparc_no_align_cons = 0;
4498 /* This handles the unaligned space allocation pseudo-ops, such as
4499 .uaword. .uaword is just like .word, but the value does not need
4503 s_uacons (int bytes)
4505 /* Tell sparc_cons_align not to align this value. */
4506 sparc_no_align_cons = 1;
4508 sparc_no_align_cons = 0;
4511 /* This handles the native word allocation pseudo-op .nword.
4512 For sparc_arch_size 32 it is equivalent to .word, for
4513 sparc_arch_size 64 it is equivalent to .xword. */
4516 s_ncons (int bytes ATTRIBUTE_UNUSED)
4518 cons (sparc_arch_size == 32 ? 4 : 8);
4522 /* Handle the SPARC ELF .register pseudo-op. This sets the binding of a
4526 .register %g[2367],{#scratch|symbolname|#ignore}
4530 s_register (int ignore ATTRIBUTE_UNUSED)
4537 if (input_line_pointer[0] != '%'
4538 || input_line_pointer[1] != 'g'
4539 || ((input_line_pointer[2] & ~1) != '2'
4540 && (input_line_pointer[2] & ~1) != '6')
4541 || input_line_pointer[3] != ',')
4542 as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
4543 reg = input_line_pointer[2] - '0';
4544 input_line_pointer += 4;
4546 if (*input_line_pointer == '#')
4548 ++input_line_pointer;
4549 c = get_symbol_name (®name);
4550 if (strcmp (regname, "scratch") && strcmp (regname, "ignore"))
4551 as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
4552 if (regname[0] == 'i')
4555 regname = (char *) "";
4559 c = get_symbol_name (®name);
4562 if (sparc_arch_size == 64)
4566 if ((regname && globals[reg] != (symbolS *) 1
4567 && strcmp (S_GET_NAME (globals[reg]), regname))
4568 || ((regname != NULL) ^ (globals[reg] != (symbolS *) 1)))
4569 as_bad (_("redefinition of global register"));
4573 if (regname == NULL)
4574 globals[reg] = (symbolS *) 1;
4579 if (symbol_find (regname))
4580 as_bad (_("Register symbol %s already defined."),
4583 globals[reg] = symbol_make (regname);
4584 flags = symbol_get_bfdsym (globals[reg])->flags;
4586 flags = flags & ~(BSF_GLOBAL|BSF_LOCAL|BSF_WEAK);
4587 if (! (flags & (BSF_GLOBAL|BSF_LOCAL|BSF_WEAK)))
4588 flags |= BSF_GLOBAL;
4589 symbol_get_bfdsym (globals[reg])->flags = flags;
4590 S_SET_VALUE (globals[reg], (valueT) reg);
4591 S_SET_ALIGN (globals[reg], reg);
4592 S_SET_SIZE (globals[reg], 0);
4593 /* Although we actually want undefined_section here,
4594 we have to use absolute_section, because otherwise
4595 generic as code will make it a COM section.
4596 We fix this up in sparc_adjust_symtab. */
4597 S_SET_SEGMENT (globals[reg], absolute_section);
4598 S_SET_OTHER (globals[reg], 0);
4599 elf_symbol (symbol_get_bfdsym (globals[reg]))
4600 ->internal_elf_sym.st_info =
4601 ELF_ST_INFO(STB_GLOBAL, STT_REGISTER);
4602 elf_symbol (symbol_get_bfdsym (globals[reg]))
4603 ->internal_elf_sym.st_shndx = SHN_UNDEF;
4608 (void) restore_line_pointer (c);
4610 demand_empty_rest_of_line ();
4613 /* Adjust the symbol table. We set undefined sections for STT_REGISTER
4614 symbols which need it. */
4617 sparc_adjust_symtab (void)
4621 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4623 if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym))
4624 ->internal_elf_sym.st_info) != STT_REGISTER)
4627 if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym))
4628 ->internal_elf_sym.st_shndx != SHN_UNDEF))
4631 S_SET_SEGMENT (sym, undefined_section);
4636 /* If the --enforce-aligned-data option is used, we require .word,
4637 et. al., to be aligned correctly. We do it by setting up an
4638 rs_align_code frag, and checking in HANDLE_ALIGN to make sure that
4639 no unexpected alignment was introduced.
4641 The SunOS and Solaris native assemblers enforce aligned data by
4642 default. We don't want to do that, because gcc can deliberately
4643 generate misaligned data if the packed attribute is used. Instead,
4644 we permit misaligned data by default, and permit the user to set an
4645 option to check for it. */
4648 sparc_cons_align (int nbytes)
4652 /* Only do this if we are enforcing aligned data. */
4653 if (! enforce_aligned_data)
4656 /* Don't align if this is an unaligned pseudo-op. */
4657 if (sparc_no_align_cons)
4660 nalign = mylog2 (nbytes);
4664 gas_assert (nalign > 0);
4666 if (now_seg == absolute_section)
4668 if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
4669 as_bad (_("misaligned data"));
4673 frag_var (rs_align_test, 1, 1, (relax_substateT) 0,
4674 (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
4676 record_alignment (now_seg, nalign);
4679 /* This is called from HANDLE_ALIGN in tc-sparc.h. */
4682 sparc_handle_align (fragS *fragp)
4687 count = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
4689 switch (fragp->fr_type)
4693 as_bad_where (fragp->fr_file, fragp->fr_line, _("misaligned data"));
4697 p = fragp->fr_literal + fragp->fr_fix;
4708 if (SPARC_OPCODE_ARCH_V9_P (max_architecture) && count > 8)
4710 unsigned wval = (0x30680000 | count >> 2); /* ba,a,pt %xcc, 1f */
4711 if (INSN_BIG_ENDIAN)
4712 number_to_chars_bigendian (p, wval, 4);
4714 number_to_chars_littleendian (p, wval, 4);
4720 if (INSN_BIG_ENDIAN)
4721 number_to_chars_bigendian (p, 0x01000000, 4);
4723 number_to_chars_littleendian (p, 0x01000000, 4);
4725 fragp->fr_fix += fix;
4735 /* Some special processing for a Sparc ELF file. */
4738 sparc_elf_final_processing (void)
4740 /* Set the Sparc ELF flag bits. FIXME: There should probably be some
4741 sort of BFD interface for this. */
4742 if (sparc_arch_size == 64)
4744 switch (sparc_memory_model)
4747 elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_RMO;
4750 elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_PSO;
4756 else if (current_architecture >= SPARC_OPCODE_ARCH_V9)
4757 elf_elfheader (stdoutput)->e_flags |= EF_SPARC_32PLUS;
4758 if (current_architecture == SPARC_OPCODE_ARCH_V9A)
4759 elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1;
4760 else if (current_architecture == SPARC_OPCODE_ARCH_V9B)
4761 elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1|EF_SPARC_SUN_US3;
4765 sparc_cons (expressionS *exp, int size)
4768 const char *sparc_cons_special_reloc = NULL;
4771 save = input_line_pointer;
4772 if (input_line_pointer[0] == '%'
4773 && input_line_pointer[1] == 'r'
4774 && input_line_pointer[2] == '_')
4776 if (strncmp (input_line_pointer + 3, "disp", 4) == 0)
4778 input_line_pointer += 7;
4779 sparc_cons_special_reloc = "disp";
4781 else if (strncmp (input_line_pointer + 3, "plt", 3) == 0)
4783 if (size != 4 && size != 8)
4784 as_bad (_("Illegal operands: %%r_plt in %d-byte data field"), size);
4787 input_line_pointer += 6;
4788 sparc_cons_special_reloc = "plt";
4791 else if (strncmp (input_line_pointer + 3, "tls_dtpoff", 10) == 0)
4793 if (size != 4 && size != 8)
4794 as_bad (_("Illegal operands: %%r_tls_dtpoff in %d-byte data field"), size);
4797 input_line_pointer += 13;
4798 sparc_cons_special_reloc = "tls_dtpoff";
4801 if (sparc_cons_special_reloc)
4808 if (*input_line_pointer != '8')
4810 input_line_pointer--;
4813 if (input_line_pointer[0] != '1' || input_line_pointer[1] != '6')
4817 if (input_line_pointer[0] != '3' || input_line_pointer[1] != '2')
4821 if (input_line_pointer[0] != '6' || input_line_pointer[1] != '4')
4831 as_bad (_("Illegal operands: Only %%r_%s%d allowed in %d-byte data fields"),
4832 sparc_cons_special_reloc, size * 8, size);
4836 input_line_pointer += 2;
4837 if (*input_line_pointer != '(')
4839 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
4840 sparc_cons_special_reloc, size * 8);
4847 input_line_pointer = save;
4848 sparc_cons_special_reloc = NULL;
4853 char *end = ++input_line_pointer;
4856 while (! is_end_of_line[(c = *end)])
4870 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
4871 sparc_cons_special_reloc, size * 8);
4877 if (input_line_pointer != end)
4879 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
4880 sparc_cons_special_reloc, size * 8);
4884 input_line_pointer++;
4886 c = *input_line_pointer;
4887 if (! is_end_of_line[c] && c != ',')
4888 as_bad (_("Illegal operands: garbage after %%r_%s%d()"),
4889 sparc_cons_special_reloc, size * 8);
4895 if (sparc_cons_special_reloc == NULL)
4897 return sparc_cons_special_reloc;
4902 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
4903 reloc for a cons. We could use the definition there, except that
4904 we want to handle little endian relocs specially. */
4907 cons_fix_new_sparc (fragS *frag,
4909 unsigned int nbytes,
4911 const char *sparc_cons_special_reloc)
4913 bfd_reloc_code_real_type r;
4915 r = (nbytes == 1 ? BFD_RELOC_8 :
4916 (nbytes == 2 ? BFD_RELOC_16 :
4917 (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64)));
4919 if (target_little_endian_data
4921 && now_seg->flags & SEC_ALLOC)
4922 r = BFD_RELOC_SPARC_REV32;
4925 /* The Solaris linker does not allow R_SPARC_UA64
4926 relocations for 32-bit executables. */
4927 if (!target_little_endian_data
4928 && sparc_arch_size != 64
4929 && r == BFD_RELOC_64)
4933 if (sparc_cons_special_reloc)
4935 if (*sparc_cons_special_reloc == 'd')
4938 case 1: r = BFD_RELOC_8_PCREL; break;
4939 case 2: r = BFD_RELOC_16_PCREL; break;
4940 case 4: r = BFD_RELOC_32_PCREL; break;
4941 case 8: r = BFD_RELOC_64_PCREL; break;
4944 else if (*sparc_cons_special_reloc == 'p')
4947 case 4: r = BFD_RELOC_SPARC_PLT32; break;
4948 case 8: r = BFD_RELOC_SPARC_PLT64; break;
4953 case 4: r = BFD_RELOC_SPARC_TLS_DTPOFF32; break;
4954 case 8: r = BFD_RELOC_SPARC_TLS_DTPOFF64; break;
4957 else if (sparc_no_align_cons
4958 || /* PR 20803 - relocs in the .eh_frame section
4959 need to support unaligned access. */
4960 strcmp (now_seg->name, ".eh_frame") == 0)
4964 case 2: r = BFD_RELOC_SPARC_UA16; break;
4965 case 4: r = BFD_RELOC_SPARC_UA32; break;
4967 /* The Solaris linker does not allow R_SPARC_UA64
4968 relocations for 32-bit executables. */
4969 case 8: r = sparc_arch_size == 64 ?
4970 BFD_RELOC_SPARC_UA64 : BFD_RELOC_SPARC_UA32; break;
4972 case 8: r = BFD_RELOC_SPARC_UA64; break;
4978 fix_new_exp (frag, where, (int) nbytes, exp, 0, r);
4982 sparc_cfi_frame_initial_instructions (void)
4984 cfi_add_CFA_def_cfa (14, sparc_arch_size == 64 ? 0x7ff : 0);
4988 sparc_regname_to_dw2regnum (char *regname)
4998 case 'g': i = 0; break;
4999 case 'o': i = 1; break;
5000 case 'l': i = 2; break;
5001 case 'i': i = 3; break;
5002 default: i = -1; break;
5006 if (regname[1] < '0' || regname[1] > '8' || regname[2])
5008 return i * 8 + regname[1] - '0';
5010 if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
5012 if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
5014 if (regname[0] == 'f' || regname[0] == 'r')
5016 unsigned int regnum;
5018 regnum = strtoul (regname + 1, &q, 10);
5019 if (q == NULL || *q)
5021 if (regnum >= ((regname[0] == 'f'
5022 && SPARC_OPCODE_ARCH_V9_P (max_architecture))
5025 if (regname[0] == 'f')
5028 if (regnum >= 64 && (regnum & 1))
5037 sparc_cfi_emit_pcrel_expr (expressionS *exp, unsigned int nbytes)
5039 sparc_no_align_cons = 1;
5040 emit_expr_with_reloc (exp, nbytes, "disp");
5041 sparc_no_align_cons = 0;