1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 90-96, 97, 98, 99, 2000 Free Software Foundation, Inc.
3 This file is part of GAS, the GNU Assembler.
5 GAS is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GAS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public
16 License along with GAS; see the file COPYING. If not, write
17 to the Free Software Foundation, 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
26 #include "opcode/sparc.h"
29 #include "elf/sparc.h"
32 static struct sparc_arch
*lookup_arch
PARAMS ((char *));
33 static void init_default_arch
PARAMS ((void));
34 static int sparc_ip
PARAMS ((char *, const struct sparc_opcode
**));
35 static int in_signed_range
PARAMS ((bfd_signed_vma
, bfd_signed_vma
));
36 static int in_unsigned_range
PARAMS ((bfd_vma
, bfd_vma
));
37 static int in_bitfield_range
PARAMS ((bfd_signed_vma
, bfd_signed_vma
));
38 static int sparc_ffs
PARAMS ((unsigned int));
39 static void synthetize_setuw
PARAMS ((const struct sparc_opcode
*));
40 static void synthetize_setsw
PARAMS ((const struct sparc_opcode
*));
41 static void synthetize_setx
PARAMS ((const struct sparc_opcode
*));
42 static bfd_vma BSR
PARAMS ((bfd_vma
, int));
43 static int cmp_reg_entry
PARAMS ((const PTR
, const PTR
));
44 static int parse_keyword_arg
PARAMS ((int (*) (const char *), char **, int *));
45 static int parse_const_expr_arg
PARAMS ((char **, int *));
46 static int get_expression
PARAMS ((char *str
));
48 /* Default architecture. */
49 /* ??? The default value should be V8, but sparclite support was added
50 by making it the default. GCC now passes -Asparclite, so maybe sometime in
51 the future we can set this to V8. */
53 #define DEFAULT_ARCH "sparclite"
55 static char *default_arch
= DEFAULT_ARCH
;
57 /* Non-zero if the initial values of `max_architecture' and `sparc_arch_size'
59 static int default_init_p
;
61 /* Current architecture. We don't bump up unless necessary. */
62 static enum sparc_opcode_arch_val current_architecture
= SPARC_OPCODE_ARCH_V6
;
64 /* The maximum architecture level we can bump up to.
65 In a 32 bit environment, don't allow bumping up to v9 by default.
66 The native assembler works this way. The user is required to pass
67 an explicit argument before we'll create v9 object files. However, if
68 we don't see any v9 insns, a v8plus object file is not created. */
69 static enum sparc_opcode_arch_val max_architecture
;
71 /* Either 32 or 64, selects file format. */
72 static int sparc_arch_size
;
73 /* Initial (default) value, recorded separately in case a user option
74 changes the value before md_show_usage is called. */
75 static int default_arch_size
;
78 /* The currently selected v9 memory model. Currently only used for
80 static enum { MM_TSO
, MM_PSO
, MM_RMO
} sparc_memory_model
= MM_RMO
;
83 static int architecture_requested
;
84 static int warn_on_bump
;
86 /* If warn_on_bump and the needed architecture is higher than this
87 architecture, issue a warning. */
88 static enum sparc_opcode_arch_val warn_after_architecture
;
90 /* Non-zero if as should generate error if an undeclared g[23] register
91 has been used in -64. */
92 static int no_undeclared_regs
;
94 /* Non-zero if we should try to relax jumps and calls. */
95 static int sparc_relax
;
97 /* Non-zero if we are generating PIC code. */
100 /* Non-zero if we should give an error when misaligned data is seen. */
101 static int enforce_aligned_data
;
103 extern int target_big_endian
;
105 static int target_little_endian_data
;
107 /* Symbols for global registers on v9. */
108 static symbolS
*globals
[8];
110 /* V9 and 86x have big and little endian data, but instructions are always big
111 endian. The sparclet has bi-endian support but both data and insns have
112 the same endianness. Global `target_big_endian' is used for data.
113 The following macro is used for instructions. */
114 #ifndef INSN_BIG_ENDIAN
115 #define INSN_BIG_ENDIAN (target_big_endian \
116 || default_arch_type == sparc86x \
117 || SPARC_OPCODE_ARCH_V9_P (max_architecture))
120 /* handle of the OPCODE hash table */
121 static struct hash_control
*op_hash
;
123 static int log2
PARAMS ((int));
124 static void s_data1
PARAMS ((void));
125 static void s_seg
PARAMS ((int));
126 static void s_proc
PARAMS ((int));
127 static void s_reserve
PARAMS ((int));
128 static void s_common
PARAMS ((int));
129 static void s_empty
PARAMS ((int));
130 static void s_uacons
PARAMS ((int));
131 static void s_ncons
PARAMS ((int));
132 static void s_register
PARAMS ((int));
134 const pseudo_typeS md_pseudo_table
[] =
136 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0) */
137 {"common", s_common
, 0},
138 {"empty", s_empty
, 0},
139 {"global", s_globl
, 0},
141 {"nword", s_ncons
, 0},
142 {"optim", s_ignore
, 0},
144 {"reserve", s_reserve
, 0},
146 {"skip", s_space
, 0},
149 {"uahalf", s_uacons
, 2},
150 {"uaword", s_uacons
, 4},
151 {"uaxword", s_uacons
, 8},
153 /* these are specific to sparc/svr4 */
154 {"2byte", s_uacons
, 2},
155 {"4byte", s_uacons
, 4},
156 {"8byte", s_uacons
, 8},
157 {"register", s_register
, 0},
162 const int md_reloc_size
= 12; /* Size of relocation record */
164 /* This array holds the chars that always start a comment. If the
165 pre-processor is disabled, these aren't very useful */
166 const char comment_chars
[] = "!"; /* JF removed '|' from comment_chars */
168 /* This array holds the chars that only start a comment at the beginning of
169 a line. If the line seems to have the form '# 123 filename'
170 .line and .file directives will appear in the pre-processed output */
171 /* Note that input_file.c hand checks for '#' at the beginning of the
172 first line of the input file. This is because the compiler outputs
173 #NO_APP at the beginning of its output. */
174 /* Also note that comments started like this one will always
175 work if '/' isn't otherwise defined. */
176 const char line_comment_chars
[] = "#";
178 const char line_separator_chars
[] = "";
180 /* Chars that can be used to separate mant from exp in floating point nums */
181 const char EXP_CHARS
[] = "eE";
183 /* Chars that mean this number is a floating point constant */
186 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
188 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
189 changed in read.c. Ideally it shouldn't have to know about it at all,
190 but nothing is ideal around here. */
192 #define isoctal(c) ((unsigned)((c) - '0') < '8')
197 unsigned long opcode
;
198 struct nlist
*nlistp
;
202 bfd_reloc_code_real_type reloc
;
205 struct sparc_it the_insn
, set_insn
;
207 static void output_insn
208 PARAMS ((const struct sparc_opcode
*, struct sparc_it
*));
210 /* Table of arguments to -A.
211 The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect
212 for this use. That table is for opcodes only. This table is for opcodes
215 enum sparc_arch_types
{v6
, v7
, v8
, sparclet
, sparclite
, sparc86x
, v8plus
,
216 v8plusa
, v9
, v9a
, v9_64
};
218 static struct sparc_arch
{
221 enum sparc_arch_types arch_type
;
222 /* Default word size, as specified during configuration.
223 A value of zero means can't be used to specify default architecture. */
224 int default_arch_size
;
225 /* Allowable arg to -A? */
227 } sparc_arch_table
[] = {
228 { "v6", "v6", v6
, 0, 1 },
229 { "v7", "v7", v7
, 0, 1 },
230 { "v8", "v8", v8
, 32, 1 },
231 { "sparclet", "sparclet", sparclet
, 32, 1 },
232 { "sparclite", "sparclite", sparclite
, 32, 1 },
233 { "sparc86x", "sparclite", sparc86x
, 32, 1 },
234 { "v8plus", "v9", v9
, 0, 1 },
235 { "v8plusa", "v9a", v9
, 0, 1 },
236 { "v9", "v9", v9
, 0, 1 },
237 { "v9a", "v9a", v9
, 0, 1 },
238 /* This exists to allow configure.in/Makefile.in to pass one
239 value to specify both the default machine and default word size. */
240 { "v9-64", "v9", v9
, 64, 0 },
241 { NULL
, NULL
, v8
, 0, 0 }
244 /* Variant of default_arch */
245 static enum sparc_arch_types default_arch_type
;
247 static struct sparc_arch
*
251 struct sparc_arch
*sa
;
253 for (sa
= &sparc_arch_table
[0]; sa
->name
!= NULL
; sa
++)
254 if (strcmp (sa
->name
, name
) == 0)
256 if (sa
->name
== NULL
)
261 /* Initialize the default opcode arch and word size from the default
262 architecture name. */
267 struct sparc_arch
*sa
= lookup_arch (default_arch
);
270 || sa
->default_arch_size
== 0)
271 as_fatal (_("Invalid default architecture, broken assembler."));
273 max_architecture
= sparc_opcode_lookup_arch (sa
->opcode_arch
);
274 if (max_architecture
== SPARC_OPCODE_ARCH_BAD
)
275 as_fatal (_("Bad opcode table, broken assembler."));
276 default_arch_size
= sparc_arch_size
= sa
->default_arch_size
;
278 default_arch_type
= sa
->arch_type
;
281 /* Called by TARGET_FORMAT. */
284 sparc_target_format ()
286 /* We don't get a chance to initialize anything before we're called,
287 so handle that now. */
288 if (! default_init_p
)
289 init_default_arch ();
293 return "a.out-sparc-netbsd";
296 if (target_big_endian
)
297 return "a.out-sunos-big";
298 else if (default_arch_type
== sparc86x
&& target_little_endian_data
)
299 return "a.out-sunos-big";
300 else return "a.out-sparc-little";
302 return "a.out-sunos-big";
313 return "coff-sparc-lynx";
320 return sparc_arch_size
== 64 ? "elf64-sparc" : "elf32-sparc";
328 * Invocation line includes a switch not recognized by the base assembler.
329 * See if it's a processor-specific option. These are:
332 * Warn on architecture bumps. See also -A.
334 * -Av6, -Av7, -Av8, -Asparclite, -Asparclet
335 * Standard 32 bit architectures.
336 * -Av8plus, -Av8plusa
337 * Sparc64 in a 32 bit world.
339 * Sparc64 in either a 32 or 64 bit world (-32/-64 says which).
340 * This used to only mean 64 bits, but properly specifying it
341 * complicated gcc's ASM_SPECs, so now opcode selection is
342 * specified orthogonally to word size (except when specifying
343 * the default, but that is an internal implementation detail).
344 * -xarch=v8plus, -xarch=v8plusa
345 * Same as -Av8plus{,a}, for compatibility with Sun's assembler.
347 * Select the architecture and possibly the file format.
348 * Instructions or features not supported by the selected
349 * architecture cause fatal errors.
351 * The default is to start at v6, and bump the architecture up
352 * whenever an instruction is seen at a higher level. In 32 bit
353 * environments, v9 is not bumped up to, the user must pass
356 * If -bump is specified, a warning is printing when bumping to
359 * If an architecture is specified, all instructions must match
360 * that architecture. Any higher level instructions are flagged
361 * as errors. Note that in the 32 bit environment specifying
362 * -Av8plus does not automatically create a v8plus object file, a
363 * v9 insn must be seen.
365 * If both an architecture and -bump are specified, the
366 * architecture starts at the specified level, but bumps are
367 * warnings. Note that we can't set `current_architecture' to
368 * the requested level in this case: in the 32 bit environment,
369 * we still must avoid creating v8plus object files unless v9
373 * Bumping between incompatible architectures is always an
374 * error. For example, from sparclite to v9.
378 CONST
char *md_shortopts
= "A:K:VQ:sq";
381 CONST
char *md_shortopts
= "A:k";
383 CONST
char *md_shortopts
= "A:";
386 struct option md_longopts
[] = {
387 #define OPTION_BUMP (OPTION_MD_BASE)
388 {"bump", no_argument
, NULL
, OPTION_BUMP
},
389 #define OPTION_SPARC (OPTION_MD_BASE + 1)
390 {"sparc", no_argument
, NULL
, OPTION_SPARC
},
391 #define OPTION_XARCH (OPTION_MD_BASE + 2)
392 {"xarch", required_argument
, NULL
, OPTION_XARCH
},
394 #define OPTION_32 (OPTION_MD_BASE + 3)
395 {"32", no_argument
, NULL
, OPTION_32
},
396 #define OPTION_64 (OPTION_MD_BASE + 4)
397 {"64", no_argument
, NULL
, OPTION_64
},
398 #define OPTION_TSO (OPTION_MD_BASE + 5)
399 {"TSO", no_argument
, NULL
, OPTION_TSO
},
400 #define OPTION_PSO (OPTION_MD_BASE + 6)
401 {"PSO", no_argument
, NULL
, OPTION_PSO
},
402 #define OPTION_RMO (OPTION_MD_BASE + 7)
403 {"RMO", no_argument
, NULL
, OPTION_RMO
},
405 #ifdef SPARC_BIENDIAN
406 #define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8)
407 {"EL", no_argument
, NULL
, OPTION_LITTLE_ENDIAN
},
408 #define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9)
409 {"EB", no_argument
, NULL
, OPTION_BIG_ENDIAN
},
411 #define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10)
412 {"enforce-aligned-data", no_argument
, NULL
, OPTION_ENFORCE_ALIGNED_DATA
},
413 #define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11)
414 {"little-endian-data", no_argument
, NULL
, OPTION_LITTLE_ENDIAN_DATA
},
416 #define OPTION_NO_UNDECLARED_REGS (OPTION_MD_BASE + 12)
417 {"no-undeclared-regs", no_argument
, NULL
, OPTION_NO_UNDECLARED_REGS
},
418 #define OPTION_UNDECLARED_REGS (OPTION_MD_BASE + 13)
419 {"undeclared-regs", no_argument
, NULL
, OPTION_UNDECLARED_REGS
},
421 #define OPTION_RELAX (OPTION_MD_BASE + 14)
422 {"relax", no_argument
, NULL
, OPTION_RELAX
},
423 #define OPTION_NO_RELAX (OPTION_MD_BASE + 15)
424 {"no-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
425 {NULL
, no_argument
, NULL
, 0}
427 size_t md_longopts_size
= sizeof(md_longopts
);
430 md_parse_option (c
, arg
)
434 /* We don't get a chance to initialize anything before we're called,
435 so handle that now. */
436 if (! default_init_p
)
437 init_default_arch ();
443 warn_after_architecture
= SPARC_OPCODE_ARCH_V6
;
447 /* This is for compatibility with Sun's assembler. */
448 if (strcmp (arg
, "v8plus") != 0
449 && strcmp (arg
, "v8plusa") != 0)
451 as_bad (_("invalid architecture -xarch=%s"), arg
);
459 struct sparc_arch
*sa
;
460 enum sparc_opcode_arch_val opcode_arch
;
462 sa
= lookup_arch (arg
);
464 || ! sa
->user_option_p
)
466 as_bad (_("invalid architecture -A%s"), arg
);
470 opcode_arch
= sparc_opcode_lookup_arch (sa
->opcode_arch
);
471 if (opcode_arch
== SPARC_OPCODE_ARCH_BAD
)
472 as_fatal (_("Bad opcode table, broken assembler."));
474 max_architecture
= opcode_arch
;
475 architecture_requested
= 1;
480 /* Ignore -sparc, used by SunOS make default .s.o rule. */
483 case OPTION_ENFORCE_ALIGNED_DATA
:
484 enforce_aligned_data
= 1;
487 #ifdef SPARC_BIENDIAN
488 case OPTION_LITTLE_ENDIAN
:
489 target_big_endian
= 0;
490 if (default_arch_type
!= sparclet
)
491 as_fatal ("This target does not support -EL");
493 case OPTION_LITTLE_ENDIAN_DATA
:
494 target_little_endian_data
= 1;
495 target_big_endian
= 0;
496 if (default_arch_type
!= sparc86x
497 && default_arch_type
!= v9
)
498 as_fatal ("This target does not support --little-endian-data");
500 case OPTION_BIG_ENDIAN
:
501 target_big_endian
= 1;
515 const char **list
, **l
;
517 sparc_arch_size
= c
== OPTION_32
? 32 : 64;
518 list
= bfd_target_list ();
519 for (l
= list
; *l
!= NULL
; l
++)
521 if (sparc_arch_size
== 32)
523 if (strcmp (*l
, "elf32-sparc") == 0)
528 if (strcmp (*l
, "elf64-sparc") == 0)
533 as_fatal (_("No compiled in support for %d bit object file format"),
540 sparc_memory_model
= MM_TSO
;
544 sparc_memory_model
= MM_PSO
;
548 sparc_memory_model
= MM_RMO
;
556 /* Qy - do emit .comment
557 Qn - do not emit .comment */
561 /* use .stab instead of .stab.excl */
565 /* quick -- native assembler does fewer checks */
569 if (strcmp (arg
, "PIC") != 0)
570 as_warn (_("Unrecognized option following -K"));
575 case OPTION_NO_UNDECLARED_REGS
:
576 no_undeclared_regs
= 1;
579 case OPTION_UNDECLARED_REGS
:
580 no_undeclared_regs
= 0;
588 case OPTION_NO_RELAX
:
600 md_show_usage (stream
)
603 const struct sparc_arch
*arch
;
605 /* We don't get a chance to initialize anything before we're called,
606 so handle that now. */
607 if (! default_init_p
)
608 init_default_arch ();
610 fprintf(stream
, _("SPARC options:\n"));
611 for (arch
= &sparc_arch_table
[0]; arch
->name
; arch
++)
613 if (arch
!= &sparc_arch_table
[0])
614 fprintf (stream
, " | ");
615 if (arch
->user_option_p
)
616 fprintf (stream
, "-A%s", arch
->name
);
618 fprintf (stream
, _("\n-xarch=v8plus | -xarch=v8plusa\n"));
619 fprintf (stream
, _("\
620 specify variant of SPARC architecture\n\
621 -bump warn when assembler switches architectures\n\
623 --enforce-aligned-data force .long, etc., to be aligned correctly\n\
624 -relax relax jumps and branches (default)\n\
625 -no-relax avoid changing any jumps and branches\n"));
627 fprintf (stream
, _("\
628 -k generate PIC\n"));
631 fprintf (stream
, _("\
632 -32 create 32 bit object file\n\
633 -64 create 64 bit object file\n"));
634 fprintf (stream
, _("\
635 [default is %d]\n"), default_arch_size
);
636 fprintf (stream
, _("\
637 -TSO use Total Store Ordering\n\
638 -PSO use Partial Store Ordering\n\
639 -RMO use Relaxed Memory Ordering\n"));
640 fprintf (stream
, _("\
641 [default is %s]\n"), (default_arch_size
== 64) ? "RMO" : "TSO");
642 fprintf (stream
, _("\
643 -KPIC generate PIC\n\
644 -V print assembler version number\n\
645 -undeclared-regs ignore application global register usage without\n\
646 appropriate .register directive (default)\n\
647 -no-undeclared-regs force error on application global register usage\n\
648 without appropriate .register directive\n\
653 #ifdef SPARC_BIENDIAN
654 fprintf (stream
, _("\
655 -EL generate code for a little endian machine\n\
656 -EB generate code for a big endian machine\n\
657 --little-endian-data generate code for a machine having big endian\n\
658 instructions and little endian data.\n"));
662 /* native operand size opcode translation */
668 } native_op_table
[] =
670 {"ldn", "ld", "ldx"},
671 {"ldna", "lda", "ldxa"},
672 {"stn", "st", "stx"},
673 {"stna", "sta", "stxa"},
674 {"slln", "sll", "sllx"},
675 {"srln", "srl", "srlx"},
676 {"sran", "sra", "srax"},
677 {"casn", "cas", "casx"},
678 {"casna", "casa", "casxa"},
679 {"clrn", "clr", "clrx"},
683 /* sparc64 priviledged registers */
685 struct priv_reg_entry
691 struct priv_reg_entry priv_reg_table
[] =
710 {"", -1}, /* end marker */
713 /* v9a specific asrs */
715 struct priv_reg_entry v9a_asr_table
[] =
724 {"clear_softint", 21},
725 {"", -1}, /* end marker */
729 cmp_reg_entry (parg
, qarg
)
733 const struct priv_reg_entry
*p
= (const struct priv_reg_entry
*) parg
;
734 const struct priv_reg_entry
*q
= (const struct priv_reg_entry
*) qarg
;
736 return strcmp (q
->name
, p
->name
);
739 /* This function is called once, at assembler startup time. It should
740 set up all the tables, etc. that the MD part of the assembler will need. */
745 register const char *retval
= NULL
;
747 register unsigned int i
= 0;
749 /* We don't get a chance to initialize anything before md_parse_option
750 is called, and it may not be called, so handle default initialization
751 now if not already done. */
752 if (! default_init_p
)
753 init_default_arch ();
755 op_hash
= hash_new ();
757 while (i
< (unsigned int) sparc_num_opcodes
)
759 const char *name
= sparc_opcodes
[i
].name
;
760 retval
= hash_insert (op_hash
, name
, (PTR
) &sparc_opcodes
[i
]);
763 as_bad (_("Internal error: can't hash `%s': %s\n"),
764 sparc_opcodes
[i
].name
, retval
);
769 if (sparc_opcodes
[i
].match
& sparc_opcodes
[i
].lose
)
771 as_bad (_("Internal error: losing opcode: `%s' \"%s\"\n"),
772 sparc_opcodes
[i
].name
, sparc_opcodes
[i
].args
);
777 while (i
< (unsigned int) sparc_num_opcodes
778 && !strcmp (sparc_opcodes
[i
].name
, name
));
781 for (i
= 0; native_op_table
[i
].name
; i
++)
783 const struct sparc_opcode
*insn
;
784 char *name
= sparc_arch_size
== 32 ? native_op_table
[i
].name32
:
785 native_op_table
[i
].name64
;
786 insn
= (struct sparc_opcode
*)hash_find (op_hash
, name
);
789 as_bad (_("Internal error: can't find opcode `%s' for `%s'\n"),
790 name
, native_op_table
[i
].name
);
795 retval
= hash_insert (op_hash
, native_op_table
[i
].name
, (PTR
) insn
);
798 as_bad (_("Internal error: can't hash `%s': %s\n"),
799 sparc_opcodes
[i
].name
, retval
);
806 as_fatal (_("Broken assembler. No assembly attempted."));
808 qsort (priv_reg_table
, sizeof (priv_reg_table
) / sizeof (priv_reg_table
[0]),
809 sizeof (priv_reg_table
[0]), cmp_reg_entry
);
811 /* If -bump, record the architecture level at which we start issuing
812 warnings. The behaviour is different depending upon whether an
813 architecture was explicitly specified. If it wasn't, we issue warnings
814 for all upwards bumps. If it was, we don't start issuing warnings until
815 we need to bump beyond the requested architecture or when we bump between
816 conflicting architectures. */
819 && architecture_requested
)
821 /* `max_architecture' records the requested architecture.
822 Issue warnings if we go above it. */
823 warn_after_architecture
= max_architecture
;
825 /* Find the highest architecture level that doesn't conflict with
826 the requested one. */
827 for (max_architecture
= SPARC_OPCODE_ARCH_MAX
;
828 max_architecture
> warn_after_architecture
;
830 if (! SPARC_OPCODE_CONFLICT_P (max_architecture
,
831 warn_after_architecture
))
836 /* Called after all assembly has been done. */
841 if (sparc_arch_size
== 64)
843 if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
844 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9a
);
846 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v9
);
850 if (current_architecture
== SPARC_OPCODE_ARCH_V9
)
851 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v8plus
);
852 else if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
853 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_v8plusa
);
854 else if (current_architecture
== SPARC_OPCODE_ARCH_SPARCLET
)
855 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_sparclet
);
856 else if (default_arch_type
== sparc86x
&& target_little_endian_data
)
857 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc_sparclite_le
);
860 /* The sparclite is treated like a normal sparc. Perhaps it shouldn't
861 be but for now it is (since that's the way it's always been
863 bfd_set_arch_mach (stdoutput
, bfd_arch_sparc
, bfd_mach_sparc
);
868 /* Return non-zero if VAL is in the range -(MAX+1) to MAX. */
871 in_signed_range (val
, max
)
872 bfd_signed_vma val
, max
;
876 /* Sign-extend the value from the architecture word size, so that
877 0xffffffff is always considered -1 on sparc32. */
878 if (sparc_arch_size
== 32)
880 bfd_signed_vma sign
= (bfd_signed_vma
)1 << 31;
881 val
= ((val
& 0xffffffff) ^ sign
) - sign
;
890 /* Return non-zero if VAL is in the range 0 to MAX. */
893 in_unsigned_range (val
, max
)
901 /* Return non-zero if VAL is in the range -(MAX/2+1) to MAX.
902 (e.g. -15 to +31). */
905 in_bitfield_range (val
, max
)
906 bfd_signed_vma val
, max
;
912 if (val
< ~(max
>> 1))
926 for (i
= 0; (mask
& 1) == 0; ++i
)
931 /* Implement big shift right. */
937 if (sizeof (bfd_vma
) <= 4 && amount
>= 32)
938 as_fatal (_("Support for 64-bit arithmetic not compiled in."));
939 return val
>> amount
;
942 /* For communication between sparc_ip and get_expression. */
943 static char *expr_end
;
945 /* Values for `special_case'.
946 Instructions that require wierd handling because they're longer than
948 #define SPECIAL_CASE_NONE 0
949 #define SPECIAL_CASE_SET 1
950 #define SPECIAL_CASE_SETSW 2
951 #define SPECIAL_CASE_SETX 3
952 /* FIXME: sparc-opc.c doesn't have necessary "S" trigger to enable this. */
953 #define SPECIAL_CASE_FDIV 4
955 /* Bit masks of various insns. */
956 #define NOP_INSN 0x01000000
957 #define OR_INSN 0x80100000
958 #define XOR_INSN 0x80180000
959 #define FMOVS_INSN 0x81A00020
960 #define SETHI_INSN 0x01000000
961 #define SLLX_INSN 0x81281000
962 #define SRA_INSN 0x81380000
964 /* The last instruction to be assembled. */
965 static const struct sparc_opcode
*last_insn
;
966 /* The assembled opcode of `last_insn'. */
967 static unsigned long last_opcode
;
969 /* Handle the set and setuw synthetic instructions. */
971 synthetize_setuw (insn
)
972 const struct sparc_opcode
*insn
;
975 int rd
= (the_insn
.opcode
& RD (~0)) >> 25;
977 if (the_insn
.exp
.X_op
== O_constant
)
979 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
981 if (sizeof(offsetT
) > 4
982 && (the_insn
.exp
.X_add_number
< 0
983 || the_insn
.exp
.X_add_number
> (offsetT
) 0xffffffff))
984 as_warn (_("set: number not in 0..4294967295 range"));
988 if (sizeof(offsetT
) > 4
989 && (the_insn
.exp
.X_add_number
< -(offsetT
) 0x80000000
990 || the_insn
.exp
.X_add_number
> (offsetT
) 0xffffffff))
991 as_warn (_("set: number not in -2147483648..4294967295 range"));
992 the_insn
.exp
.X_add_number
= (int)the_insn
.exp
.X_add_number
;
996 /* See if operand is absolute and small; skip sethi if so. */
997 if (the_insn
.exp
.X_op
!= O_constant
998 || the_insn
.exp
.X_add_number
>= (1 << 12)
999 || the_insn
.exp
.X_add_number
< -(1 << 12))
1001 the_insn
.opcode
= (SETHI_INSN
| RD (rd
)
1002 | ((the_insn
.exp
.X_add_number
>> 10)
1003 & (the_insn
.exp
.X_op
== O_constant
? 0x3fffff : 0)));
1004 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1007 output_insn (insn
, &the_insn
);
1011 /* See if operand has no low-order bits; skip OR if so. */
1012 if (the_insn
.exp
.X_op
!= O_constant
1013 || (need_hi22_p
&& (the_insn
.exp
.X_add_number
& 0x3FF) != 0)
1016 the_insn
.opcode
= (OR_INSN
| (need_hi22_p
? RS1 (rd
) : 0)
1018 | (the_insn
.exp
.X_add_number
1019 & (the_insn
.exp
.X_op
!= O_constant
? 0 :
1020 need_hi22_p
? 0x3ff : 0x1fff)));
1021 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1024 output_insn (insn
, &the_insn
);
1028 /* Handle the setsw synthetic instruction. */
1030 synthetize_setsw (insn
)
1031 const struct sparc_opcode
*insn
;
1035 rd
= (the_insn
.opcode
& RD (~0)) >> 25;
1037 if (the_insn
.exp
.X_op
!= O_constant
)
1039 synthetize_setuw (insn
);
1041 /* Need to sign extend it. */
1042 the_insn
.opcode
= (SRA_INSN
| RS1 (rd
) | RD (rd
));
1043 the_insn
.reloc
= BFD_RELOC_NONE
;
1044 output_insn (insn
, &the_insn
);
1048 if (sizeof(offsetT
) > 4
1049 && (the_insn
.exp
.X_add_number
< -(offsetT
) 0x80000000
1050 || the_insn
.exp
.X_add_number
> (offsetT
) 0xffffffff))
1051 as_warn (_("setsw: number not in -2147483648..4294967295 range"));
1053 low32
= the_insn
.exp
.X_add_number
;
1057 synthetize_setuw (insn
);
1063 the_insn
.reloc
= BFD_RELOC_NONE
;
1064 /* See if operand is absolute and small; skip sethi if so. */
1065 if (low32
< -(1 << 12))
1067 the_insn
.opcode
= (SETHI_INSN
| RD (rd
)
1068 | (((~the_insn
.exp
.X_add_number
) >> 10) & 0x3fffff));
1069 output_insn (insn
, &the_insn
);
1070 low32
= 0x1c00 | (low32
& 0x3ff);
1071 opc
= RS1 (rd
) | XOR_INSN
;
1074 the_insn
.opcode
= (opc
| RD (rd
) | IMMED
1075 | (low32
& 0x1fff));
1076 output_insn (insn
, &the_insn
);
1079 /* Handle the setsw synthetic instruction. */
1081 synthetize_setx (insn
)
1082 const struct sparc_opcode
*insn
;
1084 int upper32
, lower32
;
1085 int tmpreg
= (the_insn
.opcode
& RS1 (~0)) >> 14;
1086 int dstreg
= (the_insn
.opcode
& RD (~0)) >> 25;
1088 int need_hh22_p
= 0, need_hm10_p
= 0, need_hi22_p
= 0, need_lo10_p
= 0;
1089 int need_xor10_p
= 0;
1091 #define SIGNEXT32(x) ((((x) & 0xffffffff) ^ 0x80000000) - 0x80000000)
1092 lower32
= SIGNEXT32 (the_insn
.exp
.X_add_number
);
1093 upper32
= SIGNEXT32 (BSR (the_insn
.exp
.X_add_number
, 32));
1096 upper_dstreg
= tmpreg
;
1097 /* The tmp reg should not be the dst reg. */
1098 if (tmpreg
== dstreg
)
1099 as_warn (_("setx: temporary register same as destination register"));
1101 /* ??? Obviously there are other optimizations we can do
1102 (e.g. sethi+shift for 0x1f0000000) and perhaps we shouldn't be
1103 doing some of these. Later. If you do change things, try to
1104 change all of this to be table driven as well. */
1105 /* What to output depends on the number if it's constant.
1106 Compute that first, then output what we've decided upon. */
1107 if (the_insn
.exp
.X_op
!= O_constant
)
1109 if (sparc_arch_size
== 32)
1111 /* When arch size is 32, we want setx to be equivalent
1112 to setuw for anything but constants. */
1113 the_insn
.exp
.X_add_number
&= 0xffffffff;
1114 synthetize_setuw (insn
);
1117 need_hh22_p
= need_hm10_p
= need_hi22_p
= need_lo10_p
= 1;
1118 lower32
= 0; upper32
= 0;
1122 /* Reset X_add_number, we've extracted it as upper32/lower32.
1123 Otherwise fixup_segment will complain about not being able to
1124 write an 8 byte number in a 4 byte field. */
1125 the_insn
.exp
.X_add_number
= 0;
1127 /* Only need hh22 if `or' insn can't handle constant. */
1128 if (upper32
< -(1 << 12) || upper32
>= (1 << 12))
1131 /* Does bottom part (after sethi) have bits? */
1132 if ((need_hh22_p
&& (upper32
& 0x3ff) != 0)
1133 /* No hh22, but does upper32 still have bits we can't set
1135 || (! need_hh22_p
&& upper32
!= 0 && upper32
!= -1))
1138 /* If the lower half is all zero, we build the upper half directly
1139 into the dst reg. */
1141 /* Need lower half if number is zero or 0xffffffff00000000. */
1142 || (! need_hh22_p
&& ! need_hm10_p
))
1144 /* No need for sethi if `or' insn can handle constant. */
1145 if (lower32
< -(1 << 12) || lower32
>= (1 << 12)
1146 /* Note that we can't use a negative constant in the `or'
1147 insn unless the upper 32 bits are all ones. */
1148 || (lower32
< 0 && upper32
!= -1)
1149 || (lower32
>= 0 && upper32
== -1))
1152 if (need_hi22_p
&& upper32
== -1)
1155 /* Does bottom part (after sethi) have bits? */
1156 else if ((need_hi22_p
&& (lower32
& 0x3ff) != 0)
1158 || (! need_hi22_p
&& (lower32
& 0x1fff) != 0)
1159 /* Need `or' if we didn't set anything else. */
1160 || (! need_hi22_p
&& ! need_hh22_p
&& ! need_hm10_p
))
1164 /* Output directly to dst reg if lower 32 bits are all zero. */
1165 upper_dstreg
= dstreg
;
1168 if (!upper_dstreg
&& dstreg
)
1169 as_warn (_("setx: illegal temporary register g0"));
1173 the_insn
.opcode
= (SETHI_INSN
| RD (upper_dstreg
)
1174 | ((upper32
>> 10) & 0x3fffff));
1175 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1176 ? BFD_RELOC_SPARC_HH22
: BFD_RELOC_NONE
);
1177 output_insn (insn
, &the_insn
);
1182 the_insn
.opcode
= (SETHI_INSN
| RD (dstreg
)
1183 | (((need_xor10_p
? ~lower32
: lower32
)
1184 >> 10) & 0x3fffff));
1185 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1186 ? BFD_RELOC_SPARC_LM22
: BFD_RELOC_NONE
);
1187 output_insn (insn
, &the_insn
);
1192 the_insn
.opcode
= (OR_INSN
1193 | (need_hh22_p
? RS1 (upper_dstreg
) : 0)
1196 | (upper32
& (need_hh22_p
? 0x3ff : 0x1fff)));
1197 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1198 ? BFD_RELOC_SPARC_HM10
: BFD_RELOC_NONE
);
1199 output_insn (insn
, &the_insn
);
1204 /* FIXME: One nice optimization to do here is to OR the low part
1205 with the highpart if hi22 isn't needed and the low part is
1207 the_insn
.opcode
= (OR_INSN
| (need_hi22_p
? RS1 (dstreg
) : 0)
1210 | (lower32
& (need_hi22_p
? 0x3ff : 0x1fff)));
1211 the_insn
.reloc
= (the_insn
.exp
.X_op
!= O_constant
1212 ? BFD_RELOC_LO10
: BFD_RELOC_NONE
);
1213 output_insn (insn
, &the_insn
);
1216 /* If we needed to build the upper part, shift it into place. */
1217 if (need_hh22_p
|| need_hm10_p
)
1219 the_insn
.opcode
= (SLLX_INSN
| RS1 (upper_dstreg
) | RD (upper_dstreg
)
1221 the_insn
.reloc
= BFD_RELOC_NONE
;
1222 output_insn (insn
, &the_insn
);
1225 /* To get -1 in upper32, we do sethi %hi(~x), r; xor r, -0x400 | x, r. */
1228 the_insn
.opcode
= (XOR_INSN
| RS1 (dstreg
) | RD (dstreg
) | IMMED
1229 | 0x1c00 | (lower32
& 0x3ff));
1230 the_insn
.reloc
= BFD_RELOC_NONE
;
1231 output_insn (insn
, &the_insn
);
1234 /* If we needed to build both upper and lower parts, OR them together. */
1235 else if ((need_hh22_p
|| need_hm10_p
) && (need_hi22_p
|| need_lo10_p
))
1237 the_insn
.opcode
= (OR_INSN
| RS1 (dstreg
) | RS2 (upper_dstreg
)
1239 the_insn
.reloc
= BFD_RELOC_NONE
;
1240 output_insn (insn
, &the_insn
);
1244 /* Main entry point to assemble one instruction. */
1250 const struct sparc_opcode
*insn
;
1254 special_case
= sparc_ip (str
, &insn
);
1256 /* We warn about attempts to put a floating point branch in a delay slot,
1257 unless the delay slot has been annulled. */
1259 && last_insn
!= NULL
1260 && (insn
->flags
& F_FBR
) != 0
1261 && (last_insn
->flags
& F_DELAYED
) != 0
1262 /* ??? This test isn't completely accurate. We assume anything with
1263 F_{UNBR,CONDBR,FBR} set is annullable. */
1264 && ((last_insn
->flags
& (F_UNBR
| F_CONDBR
| F_FBR
)) == 0
1265 || (last_opcode
& ANNUL
) == 0))
1266 as_warn (_("FP branch in delay slot"));
1268 /* SPARC before v9 requires a nop instruction between a floating
1269 point instruction and a floating point branch. We insert one
1270 automatically, with a warning. */
1271 if (max_architecture
< SPARC_OPCODE_ARCH_V9
1273 && last_insn
!= NULL
1274 && (insn
->flags
& F_FBR
) != 0
1275 && (last_insn
->flags
& F_FLOAT
) != 0)
1277 struct sparc_it nop_insn
;
1279 nop_insn
.opcode
= NOP_INSN
;
1280 nop_insn
.reloc
= BFD_RELOC_NONE
;
1281 output_insn (insn
, &nop_insn
);
1282 as_warn (_("FP branch preceded by FP instruction; NOP inserted"));
1285 switch (special_case
)
1287 case SPECIAL_CASE_NONE
:
1289 output_insn (insn
, &the_insn
);
1292 case SPECIAL_CASE_SETSW
:
1293 synthetize_setsw (insn
);
1296 case SPECIAL_CASE_SET
:
1297 synthetize_setuw (insn
);
1300 case SPECIAL_CASE_SETX
:
1301 synthetize_setx (insn
);
1304 case SPECIAL_CASE_FDIV
:
1306 int rd
= (the_insn
.opcode
>> 25) & 0x1f;
1308 output_insn (insn
, &the_insn
);
1310 /* According to information leaked from Sun, the "fdiv" instructions
1311 on early SPARC machines would produce incorrect results sometimes.
1312 The workaround is to add an fmovs of the destination register to
1313 itself just after the instruction. This was true on machines
1314 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
1315 assert (the_insn
.reloc
== BFD_RELOC_NONE
);
1316 the_insn
.opcode
= FMOVS_INSN
| rd
| RD (rd
);
1317 output_insn (insn
, &the_insn
);
1322 as_fatal (_("failed special case insn sanity check"));
1326 /* Subroutine of md_assemble to do the actual parsing. */
1329 sparc_ip (str
, pinsn
)
1331 const struct sparc_opcode
**pinsn
;
1333 char *error_message
= "";
1337 const struct sparc_opcode
*insn
;
1339 unsigned long opcode
;
1340 unsigned int mask
= 0;
1344 int special_case
= SPECIAL_CASE_NONE
;
1347 if (islower ((unsigned char) *s
))
1351 while (islower ((unsigned char) *s
) || isdigit ((unsigned char) *s
));
1369 as_fatal (_("Unknown opcode: `%s'"), str
);
1371 insn
= (struct sparc_opcode
*) hash_find (op_hash
, str
);
1375 as_bad (_("Unknown opcode: `%s'"), str
);
1376 return special_case
;
1386 opcode
= insn
->match
;
1387 memset (&the_insn
, '\0', sizeof (the_insn
));
1388 the_insn
.reloc
= BFD_RELOC_NONE
;
1392 * Build the opcode, checking as we go to make
1393 * sure that the operands match
1395 for (args
= insn
->args
;; ++args
)
1403 /* Parse a series of masks. */
1410 if (! parse_keyword_arg (sparc_encode_membar
, &s
,
1413 error_message
= _(": invalid membar mask name");
1417 while (*s
== ' ') { ++s
; continue; }
1418 if (*s
== '|' || *s
== '+')
1420 while (*s
== ' ') { ++s
; continue; }
1425 if (! parse_const_expr_arg (&s
, &kmask
))
1427 error_message
= _(": invalid membar mask expression");
1430 if (kmask
< 0 || kmask
> 127)
1432 error_message
= _(": invalid membar mask number");
1437 opcode
|= MEMBAR (kmask
);
1445 /* Parse a prefetch function. */
1448 if (! parse_keyword_arg (sparc_encode_prefetch
, &s
, &fcn
))
1450 error_message
= _(": invalid prefetch function name");
1456 if (! parse_const_expr_arg (&s
, &fcn
))
1458 error_message
= _(": invalid prefetch function expression");
1461 if (fcn
< 0 || fcn
> 31)
1463 error_message
= _(": invalid prefetch function number");
1473 /* Parse a sparc64 privileged register. */
1476 struct priv_reg_entry
*p
= priv_reg_table
;
1477 unsigned int len
= 9999999; /* init to make gcc happy */
1480 while (p
->name
[0] > s
[0])
1482 while (p
->name
[0] == s
[0])
1484 len
= strlen (p
->name
);
1485 if (strncmp (p
->name
, s
, len
) == 0)
1489 if (p
->name
[0] != s
[0])
1491 error_message
= _(": unrecognizable privileged register");
1495 opcode
|= (p
->regnum
<< 14);
1497 opcode
|= (p
->regnum
<< 25);
1503 error_message
= _(": unrecognizable privileged register");
1509 /* Parse a v9a ancillary state register. */
1512 struct priv_reg_entry
*p
= v9a_asr_table
;
1513 unsigned int len
= 9999999; /* init to make gcc happy */
1516 while (p
->name
[0] > s
[0])
1518 while (p
->name
[0] == s
[0])
1520 len
= strlen (p
->name
);
1521 if (strncmp (p
->name
, s
, len
) == 0)
1525 if (p
->name
[0] != s
[0])
1527 error_message
= _(": unrecognizable v9a ancillary state register");
1530 if (*args
== '/' && (p
->regnum
== 20 || p
->regnum
== 21))
1532 error_message
= _(": rd on write only ancillary state register");
1536 opcode
|= (p
->regnum
<< 14);
1538 opcode
|= (p
->regnum
<< 25);
1544 error_message
= _(": unrecognizable v9a ancillary state register");
1550 if (strncmp (s
, "%asr", 4) == 0)
1554 if (isdigit ((unsigned char) *s
))
1558 while (isdigit ((unsigned char) *s
))
1560 num
= num
* 10 + *s
- '0';
1564 if (current_architecture
>= SPARC_OPCODE_ARCH_V9
)
1566 if (num
< 16 || 31 < num
)
1568 error_message
= _(": asr number must be between 16 and 31");
1574 if (num
< 0 || 31 < num
)
1576 error_message
= _(": asr number must be between 0 and 31");
1581 opcode
|= (*args
== 'M' ? RS1 (num
) : RD (num
));
1586 error_message
= _(": expecting %asrN");
1593 the_insn
.reloc
= BFD_RELOC_SPARC_11
;
1597 the_insn
.reloc
= BFD_RELOC_SPARC_10
;
1601 /* V8 systems don't understand BFD_RELOC_SPARC_5. */
1602 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1603 the_insn
.reloc
= BFD_RELOC_SPARC_5
;
1605 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1606 /* These fields are unsigned, but for upward compatibility,
1607 allow negative values as well. */
1611 /* V8 systems don't understand BFD_RELOC_SPARC_6. */
1612 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1613 the_insn
.reloc
= BFD_RELOC_SPARC_6
;
1615 the_insn
.reloc
= BFD_RELOC_SPARC13
;
1616 /* These fields are unsigned, but for upward compatibility,
1617 allow negative values as well. */
1621 the_insn
.reloc
= /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16
;
1626 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP19
;
1631 if (*s
== 'p' && s
[1] == 'n')
1639 if (*s
== 'p' && s
[1] == 't')
1651 if (strncmp (s
, "%icc", 4) == 0)
1663 if (strncmp (s
, "%xcc", 4) == 0)
1675 if (strncmp (s
, "%fcc0", 5) == 0)
1687 if (strncmp (s
, "%fcc1", 5) == 0)
1699 if (strncmp (s
, "%fcc2", 5) == 0)
1711 if (strncmp (s
, "%fcc3", 5) == 0)
1719 if (strncmp (s
, "%pc", 3) == 0)
1727 if (strncmp (s
, "%tick", 5) == 0)
1734 case '\0': /* end of args */
1753 case '[': /* these must match exactly */
1761 case '#': /* must be at least one digit */
1762 if (isdigit ((unsigned char) *s
++))
1764 while (isdigit ((unsigned char) *s
))
1772 case 'C': /* coprocessor state register */
1773 if (strncmp (s
, "%csr", 4) == 0)
1780 case 'b': /* next operand is a coprocessor register */
1783 if (*s
++ == '%' && *s
++ == 'c' && isdigit ((unsigned char) *s
))
1786 if (isdigit ((unsigned char) *s
))
1788 mask
= 10 * (mask
- '0') + (*s
++ - '0');
1802 opcode
|= mask
<< 14;
1810 opcode
|= mask
<< 25;
1816 case 'r': /* next operand must be a register */
1826 case 'f': /* frame pointer */
1834 case 'g': /* global register */
1843 case 'i': /* in register */
1847 mask
= c
- '0' + 24;
1852 case 'l': /* local register */
1856 mask
= (c
- '0' + 16);
1861 case 'o': /* out register */
1865 mask
= (c
- '0' + 8);
1870 case 's': /* stack pointer */
1878 case 'r': /* any register */
1879 if (!isdigit ((unsigned char) (c
= *s
++)))
1894 if (isdigit ((unsigned char) *s
))
1896 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
1912 if ((mask
& ~1) == 2 && sparc_arch_size
== 64
1913 && no_undeclared_regs
&& ! globals
[mask
])
1914 as_bad (_("detected global register use not covered by .register pseudo-op"));
1916 /* Got the register, now figure out where
1917 it goes in the opcode. */
1921 opcode
|= mask
<< 14;
1929 opcode
|= mask
<< 25;
1933 opcode
|= (mask
<< 25) | (mask
<< 14);
1937 opcode
|= (mask
<< 25) | (mask
<< 0);
1943 case 'e': /* next operand is a floating point register */
1958 && ((format
= *s
) == 'f')
1959 && isdigit ((unsigned char) *++s
))
1961 for (mask
= 0; isdigit ((unsigned char) *s
); ++s
)
1963 mask
= 10 * mask
+ (*s
- '0');
1964 } /* read the number */
1972 } /* register must be even numbered */
1980 } /* register must be multiple of 4 */
1984 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1985 error_message
= _(": There are only 64 f registers; [0-63]");
1987 error_message
= _(": There are only 32 f registers; [0-31]");
1990 else if (mask
>= 32)
1992 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
))
1995 mask
-= 31; /* wrap high bit */
1999 error_message
= _(": There are only 32 f registers; [0-31]");
2007 } /* if not an 'f' register. */
2014 opcode
|= RS1 (mask
);
2021 opcode
|= RS2 (mask
);
2027 opcode
|= RD (mask
);
2036 if (strncmp (s
, "%fsr", 4) == 0)
2043 case '0': /* 64 bit immediate (set, setsw, setx insn) */
2044 the_insn
.reloc
= BFD_RELOC_NONE
; /* reloc handled elsewhere */
2047 case 'l': /* 22 bit PC relative immediate */
2048 the_insn
.reloc
= BFD_RELOC_SPARC_WDISP22
;
2052 case 'L': /* 30 bit immediate */
2053 the_insn
.reloc
= BFD_RELOC_32_PCREL_S2
;
2058 case 'n': /* 22 bit immediate */
2059 the_insn
.reloc
= BFD_RELOC_SPARC22
;
2062 case 'i': /* 13 bit immediate */
2063 the_insn
.reloc
= BFD_RELOC_SPARC13
;
2073 char *op_arg
= NULL
;
2075 bfd_reloc_code_real_type old_reloc
= the_insn
.reloc
;
2077 /* Check for %hi, etc. */
2080 static const struct ops
{
2081 /* The name as it appears in assembler. */
2083 /* strlen (name), precomputed for speed */
2085 /* The reloc this pseudo-op translates to. */
2087 /* Non-zero if for v9 only. */
2089 /* Non-zero if can be used in pc-relative contexts. */
2090 int pcrel_p
;/*FIXME:wip*/
2092 /* hix/lox must appear before hi/lo so %hix won't be
2093 mistaken for %hi. */
2094 { "hix", 3, BFD_RELOC_SPARC_HIX22
, 1, 0 },
2095 { "lox", 3, BFD_RELOC_SPARC_LOX10
, 1, 0 },
2096 { "hi", 2, BFD_RELOC_HI22
, 0, 1 },
2097 { "lo", 2, BFD_RELOC_LO10
, 0, 1 },
2098 { "hh", 2, BFD_RELOC_SPARC_HH22
, 1, 1 },
2099 { "hm", 2, BFD_RELOC_SPARC_HM10
, 1, 1 },
2100 { "lm", 2, BFD_RELOC_SPARC_LM22
, 1, 1 },
2101 { "h44", 3, BFD_RELOC_SPARC_H44
, 1, 0 },
2102 { "m44", 3, BFD_RELOC_SPARC_M44
, 1, 0 },
2103 { "l44", 3, BFD_RELOC_SPARC_L44
, 1, 0 },
2104 { "uhi", 3, BFD_RELOC_SPARC_HH22
, 1, 0 },
2105 { "ulo", 3, BFD_RELOC_SPARC_HM10
, 1, 0 },
2108 const struct ops
*o
;
2110 for (o
= ops
; o
->name
; o
++)
2111 if (strncmp (s
+ 1, o
->name
, o
->len
) == 0)
2113 if (o
->name
== NULL
)
2116 if (s
[o
->len
+ 1] != '(')
2118 as_bad (_("Illegal operands: %%%s requires arguments in ()"), o
->name
);
2119 return special_case
;
2123 the_insn
.reloc
= o
->reloc
;
2128 /* Note that if the get_expression() fails, we will still
2129 have created U entries in the symbol table for the
2130 'symbols' in the input string. Try not to create U
2131 symbols for registers, etc. */
2133 /* This stuff checks to see if the expression ends in
2134 +%reg. If it does, it removes the register from
2135 the expression, and re-sets 's' to point to the
2142 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++)
2145 else if (*s1
== ')')
2154 as_bad (_("Illegal operands: %%%s requires arguments in ()"), op_arg
);
2155 return special_case
;
2159 (void) get_expression (s
);
2162 if (*s
== ',' || *s
== ']' || !*s
)
2164 if (*s
!= '+' && *s
!= '-')
2166 as_bad (_("Illegal operands: Can't do arithmetics other than + and - involving %%%s()"), op_arg
);
2167 return special_case
;
2171 op_exp
= the_insn
.exp
;
2172 memset (&the_insn
.exp
, 0, sizeof(the_insn
.exp
));
2175 for (s1
= s
; *s1
&& *s1
!= ',' && *s1
!= ']'; s1
++) ;
2177 if (s1
!= s
&& isdigit ((unsigned char) s1
[-1]))
2179 if (s1
[-2] == '%' && s1
[-3] == '+')
2181 else if (strchr ("goli0123456789", s1
[-2]) && s1
[-3] == '%' && s1
[-4] == '+')
2188 if (op_arg
&& s1
== s
+ 1)
2189 the_insn
.exp
.X_op
= O_absent
;
2191 (void) get_expression (s
);
2203 (void) get_expression (s
);
2211 the_insn
.exp2
= the_insn
.exp
;
2212 the_insn
.exp
= op_exp
;
2213 if (the_insn
.exp2
.X_op
== O_absent
)
2214 the_insn
.exp2
.X_op
= O_illegal
;
2215 else if (the_insn
.exp
.X_op
== O_absent
)
2217 the_insn
.exp
= the_insn
.exp2
;
2218 the_insn
.exp2
.X_op
= O_illegal
;
2220 else if (the_insn
.exp
.X_op
== O_constant
)
2222 valueT val
= the_insn
.exp
.X_add_number
;
2223 switch (the_insn
.reloc
)
2228 case BFD_RELOC_SPARC_HH22
:
2229 val
= BSR (val
, 32);
2230 /* intentional fallthrough */
2232 case BFD_RELOC_SPARC_LM22
:
2233 case BFD_RELOC_HI22
:
2234 val
= (val
>> 10) & 0x3fffff;
2237 case BFD_RELOC_SPARC_HM10
:
2238 val
= BSR (val
, 32);
2239 /* intentional fallthrough */
2241 case BFD_RELOC_LO10
:
2245 case BFD_RELOC_SPARC_H44
:
2250 case BFD_RELOC_SPARC_M44
:
2255 case BFD_RELOC_SPARC_L44
:
2259 case BFD_RELOC_SPARC_HIX22
:
2261 val
= (val
>> 10) & 0x3fffff;
2264 case BFD_RELOC_SPARC_LOX10
:
2265 val
= (val
& 0x3ff) | 0x1c00;
2268 the_insn
.exp
= the_insn
.exp2
;
2269 the_insn
.exp
.X_add_number
+= val
;
2270 the_insn
.exp2
.X_op
= O_illegal
;
2271 the_insn
.reloc
= old_reloc
;
2273 else if (the_insn
.exp2
.X_op
!= O_constant
)
2275 as_bad (_("Illegal operands: Can't add non-constant expression to %%%s()"), op_arg
);
2276 return special_case
;
2280 if (old_reloc
!= BFD_RELOC_SPARC13
2281 || the_insn
.reloc
!= BFD_RELOC_LO10
2282 || sparc_arch_size
!= 64
2285 as_bad (_("Illegal operands: Can't do arithmetics involving %%%s() of a relocatable symbol"), op_arg
);
2286 return special_case
;
2288 the_insn
.reloc
= BFD_RELOC_SPARC_OLO10
;
2292 /* Check for constants that don't require emitting a reloc. */
2293 if (the_insn
.exp
.X_op
== O_constant
2294 && the_insn
.exp
.X_add_symbol
== 0
2295 && the_insn
.exp
.X_op_symbol
== 0)
2297 /* For pc-relative call instructions, we reject
2298 constants to get better code. */
2300 && the_insn
.reloc
== BFD_RELOC_32_PCREL_S2
2301 && in_signed_range (the_insn
.exp
.X_add_number
, 0x3fff))
2303 error_message
= _(": PC-relative operand can't be a constant");
2307 /* Constants that won't fit are checked in md_apply_fix3
2308 and bfd_install_relocation.
2309 ??? It would be preferable to install the constants
2310 into the insn here and save having to create a fixS
2311 for each one. There already exists code to handle
2312 all the various cases (e.g. in md_apply_fix3 and
2313 bfd_install_relocation) so duplicating all that code
2314 here isn't right. */
2334 if (! parse_keyword_arg (sparc_encode_asi
, &s
, &asi
))
2336 error_message
= _(": invalid ASI name");
2342 if (! parse_const_expr_arg (&s
, &asi
))
2344 error_message
= _(": invalid ASI expression");
2347 if (asi
< 0 || asi
> 255)
2349 error_message
= _(": invalid ASI number");
2353 opcode
|= ASI (asi
);
2355 } /* alternate space */
2358 if (strncmp (s
, "%psr", 4) == 0)
2365 case 'q': /* floating point queue */
2366 if (strncmp (s
, "%fq", 3) == 0)
2373 case 'Q': /* coprocessor queue */
2374 if (strncmp (s
, "%cq", 3) == 0)
2382 if (strcmp (str
, "set") == 0
2383 || strcmp (str
, "setuw") == 0)
2385 special_case
= SPECIAL_CASE_SET
;
2388 else if (strcmp (str
, "setsw") == 0)
2390 special_case
= SPECIAL_CASE_SETSW
;
2393 else if (strcmp (str
, "setx") == 0)
2395 special_case
= SPECIAL_CASE_SETX
;
2398 else if (strncmp (str
, "fdiv", 4) == 0)
2400 special_case
= SPECIAL_CASE_FDIV
;
2406 if (strncmp (s
, "%asi", 4) != 0)
2412 if (strncmp (s
, "%fprs", 5) != 0)
2418 if (strncmp (s
, "%ccr", 4) != 0)
2424 if (strncmp (s
, "%tbr", 4) != 0)
2430 if (strncmp (s
, "%wim", 4) != 0)
2437 char *push
= input_line_pointer
;
2440 input_line_pointer
= s
;
2442 if (e
.X_op
== O_constant
)
2444 int n
= e
.X_add_number
;
2445 if (n
!= e
.X_add_number
|| (n
& ~0x1ff) != 0)
2446 as_bad (_("OPF immediate operand out of range (0-0x1ff)"));
2448 opcode
|= e
.X_add_number
<< 5;
2451 as_bad (_("non-immediate OPF operand, ignored"));
2452 s
= input_line_pointer
;
2453 input_line_pointer
= push
;
2458 if (strncmp (s
, "%y", 2) != 0)
2466 /* Parse a sparclet cpreg. */
2468 if (! parse_keyword_arg (sparc_encode_sparclet_cpreg
, &s
, &cpreg
))
2470 error_message
= _(": invalid cpreg name");
2473 opcode
|= (*args
== 'U' ? RS1 (cpreg
) : RD (cpreg
));
2478 as_fatal (_("failed sanity check."));
2479 } /* switch on arg code */
2481 /* Break out of for() loop. */
2483 } /* for each arg that we expect */
2488 /* Args don't match. */
2489 if (&insn
[1] - sparc_opcodes
< sparc_num_opcodes
2490 && (insn
->name
== insn
[1].name
2491 || !strcmp (insn
->name
, insn
[1].name
)))
2499 as_bad (_("Illegal operands%s"), error_message
);
2500 return special_case
;
2505 /* We have a match. Now see if the architecture is ok. */
2506 int needed_arch_mask
= insn
->architecture
;
2510 needed_arch_mask
&= ~ ((1 << SPARC_OPCODE_ARCH_V9
)
2511 | (1 << SPARC_OPCODE_ARCH_V9A
));
2512 needed_arch_mask
|= (1 << SPARC_OPCODE_ARCH_V9
);
2515 if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (current_architecture
))
2517 /* Can we bump up the architecture? */
2518 else if (needed_arch_mask
& SPARC_OPCODE_SUPPORTED (max_architecture
))
2520 enum sparc_opcode_arch_val needed_architecture
=
2521 sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture
)
2522 & needed_arch_mask
);
2524 assert (needed_architecture
<= SPARC_OPCODE_ARCH_MAX
);
2526 && needed_architecture
> warn_after_architecture
)
2528 as_warn (_("architecture bumped from \"%s\" to \"%s\" on \"%s\""),
2529 sparc_opcode_archs
[current_architecture
].name
,
2530 sparc_opcode_archs
[needed_architecture
].name
,
2532 warn_after_architecture
= needed_architecture
;
2534 current_architecture
= needed_architecture
;
2537 /* ??? This seems to be a bit fragile. What if the next entry in
2538 the opcode table is the one we want and it is supported?
2539 It is possible to arrange the table today so that this can't
2540 happen but what about tomorrow? */
2543 int arch
,printed_one_p
= 0;
2545 char required_archs
[SPARC_OPCODE_ARCH_MAX
* 16];
2547 /* Create a list of the architectures that support the insn. */
2548 needed_arch_mask
&= ~ SPARC_OPCODE_SUPPORTED (max_architecture
);
2550 arch
= sparc_ffs (needed_arch_mask
);
2551 while ((1 << arch
) <= needed_arch_mask
)
2553 if ((1 << arch
) & needed_arch_mask
)
2557 strcpy (p
, sparc_opcode_archs
[arch
].name
);
2564 as_bad (_("Architecture mismatch on \"%s\"."), str
);
2565 as_tsktsk (_(" (Requires %s; requested architecture is %s.)"),
2567 sparc_opcode_archs
[max_architecture
].name
);
2568 return special_case
;
2573 } /* forever looking for a match */
2575 the_insn
.opcode
= opcode
;
2576 return special_case
;
2579 /* Parse an argument that can be expressed as a keyword.
2580 (eg: #StoreStore or %ccfr).
2581 The result is a boolean indicating success.
2582 If successful, INPUT_POINTER is updated. */
2585 parse_keyword_arg (lookup_fn
, input_pointerP
, valueP
)
2586 int (*lookup_fn
) PARAMS ((const char *));
2587 char **input_pointerP
;
2593 p
= *input_pointerP
;
2594 for (q
= p
+ (*p
== '#' || *p
== '%');
2595 isalnum ((unsigned char) *q
) || *q
== '_';
2600 value
= (*lookup_fn
) (p
);
2605 *input_pointerP
= q
;
2609 /* Parse an argument that is a constant expression.
2610 The result is a boolean indicating success. */
2613 parse_const_expr_arg (input_pointerP
, valueP
)
2614 char **input_pointerP
;
2617 char *save
= input_line_pointer
;
2620 input_line_pointer
= *input_pointerP
;
2621 /* The next expression may be something other than a constant
2622 (say if we're not processing the right variant of the insn).
2623 Don't call expression unless we're sure it will succeed as it will
2624 signal an error (which we want to defer until later). */
2625 /* FIXME: It might be better to define md_operand and have it recognize
2626 things like %asi, etc. but continuing that route through to the end
2627 is a lot of work. */
2628 if (*input_line_pointer
== '%')
2630 input_line_pointer
= save
;
2634 *input_pointerP
= input_line_pointer
;
2635 input_line_pointer
= save
;
2636 if (exp
.X_op
!= O_constant
)
2638 *valueP
= exp
.X_add_number
;
2642 /* Subroutine of sparc_ip to parse an expression. */
2645 get_expression (str
)
2651 save_in
= input_line_pointer
;
2652 input_line_pointer
= str
;
2653 seg
= expression (&the_insn
.exp
);
2654 if (seg
!= absolute_section
2655 && seg
!= text_section
2656 && seg
!= data_section
2657 && seg
!= bss_section
2658 && seg
!= undefined_section
)
2660 the_insn
.error
= _("bad segment");
2661 expr_end
= input_line_pointer
;
2662 input_line_pointer
= save_in
;
2665 expr_end
= input_line_pointer
;
2666 input_line_pointer
= save_in
;
2670 /* Subroutine of md_assemble to output one insn. */
2673 output_insn (insn
, the_insn
)
2674 const struct sparc_opcode
*insn
;
2675 struct sparc_it
*the_insn
;
2677 char *toP
= frag_more (4);
2679 /* put out the opcode */
2680 if (INSN_BIG_ENDIAN
)
2681 number_to_chars_bigendian (toP
, (valueT
) the_insn
->opcode
, 4);
2683 number_to_chars_littleendian (toP
, (valueT
) the_insn
->opcode
, 4);
2685 /* put out the symbol-dependent stuff */
2686 if (the_insn
->reloc
!= BFD_RELOC_NONE
)
2688 fixS
*fixP
= fix_new_exp (frag_now
, /* which frag */
2689 (toP
- frag_now
->fr_literal
), /* where */
2694 /* Turn off overflow checking in fixup_segment. We'll do our
2695 own overflow checking in md_apply_fix3. This is necessary because
2696 the insn size is 4 and fixup_segment will signal an overflow for
2697 large 8 byte quantities. */
2698 fixP
->fx_no_overflow
= 1;
2699 if (the_insn
->reloc
== BFD_RELOC_SPARC_OLO10
)
2700 fixP
->tc_fix_data
= the_insn
->exp2
.X_add_number
;
2704 last_opcode
= the_insn
->opcode
;
2708 This is identical to the md_atof in m68k.c. I think this is right,
2711 Turn a string in input_line_pointer into a floating point constant of type
2712 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2713 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2716 /* Equal to MAX_PRECISION in atof-ieee.c */
2717 #define MAX_LITTLENUMS 6
2720 md_atof (type
, litP
, sizeP
)
2726 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2757 return _("Bad call to MD_ATOF()");
2760 t
= atof_ieee (input_line_pointer
, type
, words
);
2762 input_line_pointer
= t
;
2763 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2765 if (target_big_endian
)
2767 for (i
= 0; i
< prec
; i
++)
2769 md_number_to_chars (litP
, (valueT
) words
[i
], sizeof (LITTLENUM_TYPE
));
2770 litP
+= sizeof (LITTLENUM_TYPE
);
2775 for (i
= prec
- 1; i
>= 0; i
--)
2777 md_number_to_chars (litP
, (valueT
) words
[i
], sizeof (LITTLENUM_TYPE
));
2778 litP
+= sizeof (LITTLENUM_TYPE
);
2785 /* Write a value out to the object file, using the appropriate
2789 md_number_to_chars (buf
, val
, n
)
2794 if (target_big_endian
)
2795 number_to_chars_bigendian (buf
, val
, n
);
2796 else if (target_little_endian_data
2797 && ((n
== 4 || n
== 2) && ~now_seg
->flags
& SEC_ALLOC
))
2798 /* Output debug words, which are not in allocated sections, as big endian */
2799 number_to_chars_bigendian (buf
, val
, n
);
2800 else if (target_little_endian_data
|| ! target_big_endian
)
2801 number_to_chars_littleendian (buf
, val
, n
);
2804 /* Apply a fixS to the frags, now that we know the value it ought to
2808 md_apply_fix3 (fixP
, value
, segment
)
2813 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2819 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
2821 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
2824 /* FIXME: SPARC ELF relocations don't use an addend in the data
2825 field itself. This whole approach should be somehow combined
2826 with the calls to bfd_install_relocation. Also, the value passed
2827 in by fixup_segment includes the value of a defined symbol. We
2828 don't want to include the value of an externally visible symbol. */
2829 if (fixP
->fx_addsy
!= NULL
)
2831 if (symbol_used_in_reloc_p (fixP
->fx_addsy
)
2832 && (S_IS_EXTERNAL (fixP
->fx_addsy
)
2833 || S_IS_WEAK (fixP
->fx_addsy
)
2834 || (sparc_pic_code
&& ! fixP
->fx_pcrel
)
2835 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
2836 && ((bfd_get_section_flags (stdoutput
,
2837 S_GET_SEGMENT (fixP
->fx_addsy
))
2838 & SEC_LINK_ONCE
) != 0
2839 || strncmp (segment_name (S_GET_SEGMENT (fixP
->fx_addsy
)),
2841 sizeof ".gnu.linkonce" - 1) == 0)))
2842 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
2843 && S_GET_SEGMENT (fixP
->fx_addsy
) != undefined_section
2844 && ! bfd_is_com_section (S_GET_SEGMENT (fixP
->fx_addsy
)))
2845 fixP
->fx_addnumber
-= S_GET_VALUE (fixP
->fx_addsy
);
2850 /* This is a hack. There should be a better way to
2851 handle this. Probably in terms of howto fields, once
2852 we can look at these fixups in terms of howtos. */
2853 if (fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
&& fixP
->fx_addsy
)
2854 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2857 /* FIXME: More ridiculous gas reloc hacking. If we are going to
2858 generate a reloc, then we just want to let the reloc addend set
2859 the value. We do not want to also stuff the addend into the
2860 object file. Including the addend in the object file works when
2861 doing a static link, because the linker will ignore the object
2862 file contents. However, the dynamic linker does not ignore the
2863 object file contents. */
2864 if (fixP
->fx_addsy
!= NULL
2865 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
)
2868 /* When generating PIC code, we do not want an addend for a reloc
2869 against a local symbol. We adjust fx_addnumber to cancel out the
2870 value already included in val, and to also cancel out the
2871 adjustment which bfd_install_relocation will create. */
2873 && fixP
->fx_r_type
!= BFD_RELOC_32_PCREL_S2
2874 && fixP
->fx_addsy
!= NULL
2875 && ! S_IS_COMMON (fixP
->fx_addsy
)
2876 && symbol_section_p (fixP
->fx_addsy
))
2877 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
2879 /* When generating PIC code, we need to fiddle to get
2880 bfd_install_relocation to do the right thing for a PC relative
2881 reloc against a local symbol which we are going to keep. */
2883 && fixP
->fx_r_type
== BFD_RELOC_32_PCREL_S2
2884 && fixP
->fx_addsy
!= NULL
2885 && (S_IS_EXTERNAL (fixP
->fx_addsy
)
2886 || S_IS_WEAK (fixP
->fx_addsy
))
2887 && S_IS_DEFINED (fixP
->fx_addsy
)
2888 && ! S_IS_COMMON (fixP
->fx_addsy
))
2891 fixP
->fx_addnumber
-= 2 * S_GET_VALUE (fixP
->fx_addsy
);
2895 /* If this is a data relocation, just output VAL. */
2897 if (fixP
->fx_r_type
== BFD_RELOC_16
)
2899 md_number_to_chars (buf
, val
, 2);
2901 else if (fixP
->fx_r_type
== BFD_RELOC_32
2902 || fixP
->fx_r_type
== BFD_RELOC_SPARC_REV32
)
2904 md_number_to_chars (buf
, val
, 4);
2906 else if (fixP
->fx_r_type
== BFD_RELOC_64
)
2908 md_number_to_chars (buf
, val
, 8);
2910 else if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2911 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2918 /* It's a relocation against an instruction. */
2920 if (INSN_BIG_ENDIAN
)
2921 insn
= bfd_getb32 ((unsigned char *) buf
);
2923 insn
= bfd_getl32 ((unsigned char *) buf
);
2925 switch (fixP
->fx_r_type
)
2927 case BFD_RELOC_32_PCREL_S2
:
2929 /* FIXME: This increment-by-one deserves a comment of why it's
2931 if (! sparc_pic_code
2932 || fixP
->fx_addsy
== NULL
2933 || symbol_section_p (fixP
->fx_addsy
))
2936 insn
|= val
& 0x3fffffff;
2938 /* See if we have a delay slot */
2939 if (sparc_relax
&& fixP
->fx_where
+ 8 <= fixP
->fx_frag
->fr_fix
)
2943 #define XCC (2 << 20)
2944 #define COND(x) (((x)&0xf)<<25)
2945 #define CONDA COND(0x8)
2946 #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
2947 #define INSN_BA (F2(0,2) | CONDA)
2948 #define INSN_OR F3(2, 0x2, 0)
2949 #define INSN_NOP F2(0,4)
2953 /* If the instruction is a call with either:
2955 arithmetic instruction with rd == %o7
2956 where rs1 != %o7 and rs2 if it is register != %o7
2957 then we can optimize if the call destination is near
2958 by changing the call into a branch always. */
2959 if (INSN_BIG_ENDIAN
)
2960 delay
= bfd_getb32 ((unsigned char *) buf
+ 4);
2962 delay
= bfd_getl32 ((unsigned char *) buf
+ 4);
2963 if ((insn
& OP(~0)) != OP(1) || (delay
& OP(~0)) != OP(2))
2965 if ((delay
& OP3(~0)) != OP3(0x3d) /* restore */
2966 && ((delay
& OP3(0x28)) != 0 /* arithmetic */
2967 || ((delay
& RD(~0)) != RD(O7
))))
2969 if ((delay
& RS1(~0)) == RS1(O7
)
2970 || ((delay
& F3I(~0)) == 0
2971 && (delay
& RS2(~0)) == RS2(O7
)))
2973 /* Ensure the branch will fit into simm22. */
2974 if ((val
& 0x3fe00000)
2975 && (val
& 0x3fe00000) != 0x3fe00000)
2977 /* Check if the arch is v9 and branch will fit
2979 if (((val
& 0x3c0000) == 0
2980 || (val
& 0x3c0000) == 0x3c0000)
2981 && (sparc_arch_size
== 64
2982 || current_architecture
>= SPARC_OPCODE_ARCH_V9
))
2984 insn
= INSN_BPA
| (val
& 0x7ffff);
2987 insn
= INSN_BA
| (val
& 0x3fffff);
2988 if (fixP
->fx_where
>= 4
2989 && ((delay
& (0xffffffff ^ RS1(~0)))
2990 == (INSN_OR
| RD(O7
) | RS2(G0
))))
2995 if (INSN_BIG_ENDIAN
)
2996 setter
= bfd_getb32 ((unsigned char *) buf
- 4);
2998 setter
= bfd_getl32 ((unsigned char *) buf
- 4);
2999 if ((setter
& (0xffffffff ^ RD(~0)))
3000 != (INSN_OR
| RS1(O7
) | RS2(G0
)))
3007 If call foo was replaced with ba, replace
3008 or %rN, %g0, %o7 with nop. */
3009 reg
= (delay
& RS1(~0)) >> 14;
3010 if (reg
!= ((setter
& RD(~0)) >> 25)
3011 || reg
== G0
|| reg
== O7
)
3014 if (INSN_BIG_ENDIAN
)
3015 bfd_putb32 (INSN_NOP
, (unsigned char *) buf
+ 4);
3017 bfd_putl32 (INSN_NOP
, (unsigned char *) buf
+ 4);
3022 case BFD_RELOC_SPARC_11
:
3023 if (! in_signed_range (val
, 0x7ff))
3024 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3025 _("relocation overflow"));
3026 insn
|= val
& 0x7ff;
3029 case BFD_RELOC_SPARC_10
:
3030 if (! in_signed_range (val
, 0x3ff))
3031 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3032 _("relocation overflow"));
3033 insn
|= val
& 0x3ff;
3036 case BFD_RELOC_SPARC_7
:
3037 if (! in_bitfield_range (val
, 0x7f))
3038 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3039 _("relocation overflow"));
3043 case BFD_RELOC_SPARC_6
:
3044 if (! in_bitfield_range (val
, 0x3f))
3045 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3046 _("relocation overflow"));
3050 case BFD_RELOC_SPARC_5
:
3051 if (! in_bitfield_range (val
, 0x1f))
3052 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3053 _("relocation overflow"));
3057 case BFD_RELOC_SPARC_WDISP16
:
3058 /* FIXME: simplify */
3059 if (((val
> 0) && (val
& ~0x3fffc))
3060 || ((val
< 0) && (~(val
- 1) & ~0x3fffc)))
3061 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3062 _("relocation overflow"));
3063 /* FIXME: The +1 deserves a comment. */
3064 val
= (val
>> 2) + 1;
3065 insn
|= ((val
& 0xc000) << 6) | (val
& 0x3fff);
3068 case BFD_RELOC_SPARC_WDISP19
:
3069 /* FIXME: simplify */
3070 if (((val
> 0) && (val
& ~0x1ffffc))
3071 || ((val
< 0) && (~(val
- 1) & ~0x1ffffc)))
3072 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3073 _("relocation overflow"));
3074 /* FIXME: The +1 deserves a comment. */
3075 val
= (val
>> 2) + 1;
3076 insn
|= val
& 0x7ffff;
3079 case BFD_RELOC_SPARC_HH22
:
3080 val
= BSR (val
, 32);
3081 /* intentional fallthrough */
3083 case BFD_RELOC_SPARC_LM22
:
3084 case BFD_RELOC_HI22
:
3085 if (!fixP
->fx_addsy
)
3087 insn
|= (val
>> 10) & 0x3fffff;
3091 /* FIXME: Need comment explaining why we do this. */
3096 case BFD_RELOC_SPARC22
:
3097 if (val
& ~0x003fffff)
3098 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3099 _("relocation overflow"));
3100 insn
|= (val
& 0x3fffff);
3103 case BFD_RELOC_SPARC_HM10
:
3104 val
= BSR (val
, 32);
3105 /* intentional fallthrough */
3107 case BFD_RELOC_LO10
:
3108 if (!fixP
->fx_addsy
)
3110 insn
|= val
& 0x3ff;
3114 /* FIXME: Need comment explaining why we do this. */
3119 case BFD_RELOC_SPARC_OLO10
:
3121 val
+= fixP
->tc_fix_data
;
3122 /* intentional fallthrough */
3124 case BFD_RELOC_SPARC13
:
3125 if (! in_signed_range (val
, 0x1fff))
3126 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3127 _("relocation overflow"));
3128 insn
|= val
& 0x1fff;
3131 case BFD_RELOC_SPARC_WDISP22
:
3132 val
= (val
>> 2) + 1;
3134 case BFD_RELOC_SPARC_BASE22
:
3135 insn
|= val
& 0x3fffff;
3138 case BFD_RELOC_SPARC_H44
:
3139 if (!fixP
->fx_addsy
)
3143 insn
|= tval
& 0x3fffff;
3147 case BFD_RELOC_SPARC_M44
:
3148 if (!fixP
->fx_addsy
)
3149 insn
|= (val
>> 12) & 0x3ff;
3152 case BFD_RELOC_SPARC_L44
:
3153 if (!fixP
->fx_addsy
)
3154 insn
|= val
& 0xfff;
3157 case BFD_RELOC_SPARC_HIX22
:
3158 if (!fixP
->fx_addsy
)
3160 val
^= ~ (offsetT
) 0;
3161 insn
|= (val
>> 10) & 0x3fffff;
3165 case BFD_RELOC_SPARC_LOX10
:
3166 if (!fixP
->fx_addsy
)
3167 insn
|= 0x1c00 | (val
& 0x3ff);
3170 case BFD_RELOC_NONE
:
3172 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3173 _("bad or unhandled relocation type: 0x%02x"),
3178 if (INSN_BIG_ENDIAN
)
3179 bfd_putb32 (insn
, (unsigned char *) buf
);
3181 bfd_putl32 (insn
, (unsigned char *) buf
);
3184 /* Are we finished with this relocation now? */
3185 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
3191 /* Translate internal representation of relocation info to BFD target
3194 tc_gen_reloc (section
, fixp
)
3198 static arelent
*relocs
[3];
3200 bfd_reloc_code_real_type code
;
3202 relocs
[0] = reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3205 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3206 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3207 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3209 switch (fixp
->fx_r_type
)
3213 case BFD_RELOC_HI22
:
3214 case BFD_RELOC_LO10
:
3215 case BFD_RELOC_32_PCREL_S2
:
3216 case BFD_RELOC_SPARC13
:
3217 case BFD_RELOC_SPARC22
:
3218 case BFD_RELOC_SPARC_BASE13
:
3219 case BFD_RELOC_SPARC_WDISP16
:
3220 case BFD_RELOC_SPARC_WDISP19
:
3221 case BFD_RELOC_SPARC_WDISP22
:
3223 case BFD_RELOC_SPARC_5
:
3224 case BFD_RELOC_SPARC_6
:
3225 case BFD_RELOC_SPARC_7
:
3226 case BFD_RELOC_SPARC_10
:
3227 case BFD_RELOC_SPARC_11
:
3228 case BFD_RELOC_SPARC_HH22
:
3229 case BFD_RELOC_SPARC_HM10
:
3230 case BFD_RELOC_SPARC_LM22
:
3231 case BFD_RELOC_SPARC_PC_HH22
:
3232 case BFD_RELOC_SPARC_PC_HM10
:
3233 case BFD_RELOC_SPARC_PC_LM22
:
3234 case BFD_RELOC_SPARC_H44
:
3235 case BFD_RELOC_SPARC_M44
:
3236 case BFD_RELOC_SPARC_L44
:
3237 case BFD_RELOC_SPARC_HIX22
:
3238 case BFD_RELOC_SPARC_LOX10
:
3239 case BFD_RELOC_SPARC_REV32
:
3240 case BFD_RELOC_SPARC_OLO10
:
3241 case BFD_RELOC_VTABLE_ENTRY
:
3242 case BFD_RELOC_VTABLE_INHERIT
:
3243 code
= fixp
->fx_r_type
;
3250 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
3251 /* If we are generating PIC code, we need to generate a different
3255 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
3257 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
3260 /* This code must be parallel to the OBJ_ELF tc_fix_adjustable. */
3266 case BFD_RELOC_32_PCREL_S2
:
3267 if (! S_IS_DEFINED (fixp
->fx_addsy
)
3268 || S_IS_COMMON (fixp
->fx_addsy
)
3269 || S_IS_EXTERNAL (fixp
->fx_addsy
)
3270 || S_IS_WEAK (fixp
->fx_addsy
))
3271 code
= BFD_RELOC_SPARC_WPLT30
;
3273 case BFD_RELOC_HI22
:
3274 if (fixp
->fx_addsy
!= NULL
3275 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
3276 code
= BFD_RELOC_SPARC_PC22
;
3278 code
= BFD_RELOC_SPARC_GOT22
;
3280 case BFD_RELOC_LO10
:
3281 if (fixp
->fx_addsy
!= NULL
3282 && strcmp (S_GET_NAME (fixp
->fx_addsy
), GOT_NAME
) == 0)
3283 code
= BFD_RELOC_SPARC_PC10
;
3285 code
= BFD_RELOC_SPARC_GOT10
;
3287 case BFD_RELOC_SPARC13
:
3288 code
= BFD_RELOC_SPARC_GOT13
;
3294 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
3296 if (code
== BFD_RELOC_SPARC_OLO10
)
3297 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_LO10
);
3299 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3300 if (reloc
->howto
== 0)
3302 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3303 _("internal error: can't export reloc type %d (`%s')"),
3304 fixp
->fx_r_type
, bfd_get_reloc_code_name (code
));
3310 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
3313 if (reloc
->howto
->pc_relative
== 0
3314 || code
== BFD_RELOC_SPARC_PC10
3315 || code
== BFD_RELOC_SPARC_PC22
)
3316 reloc
->addend
= fixp
->fx_addnumber
;
3317 else if (sparc_pic_code
3318 && fixp
->fx_r_type
== BFD_RELOC_32_PCREL_S2
3319 && fixp
->fx_addsy
!= NULL
3320 && (S_IS_EXTERNAL (fixp
->fx_addsy
)
3321 || S_IS_WEAK (fixp
->fx_addsy
))
3322 && S_IS_DEFINED (fixp
->fx_addsy
)
3323 && ! S_IS_COMMON (fixp
->fx_addsy
))
3324 reloc
->addend
= fixp
->fx_addnumber
;
3326 reloc
->addend
= fixp
->fx_offset
- reloc
->address
;
3328 #else /* elf or coff */
3330 if (reloc
->howto
->pc_relative
== 0
3331 || code
== BFD_RELOC_SPARC_PC10
3332 || code
== BFD_RELOC_SPARC_PC22
)
3333 reloc
->addend
= fixp
->fx_addnumber
;
3334 else if (symbol_section_p (fixp
->fx_addsy
))
3335 reloc
->addend
= (section
->vma
3336 + fixp
->fx_addnumber
3337 + md_pcrel_from (fixp
));
3339 reloc
->addend
= fixp
->fx_offset
;
3342 /* We expand R_SPARC_OLO10 to R_SPARC_LO10 and R_SPARC_13
3343 on the same location. */
3344 if (code
== BFD_RELOC_SPARC_OLO10
)
3346 relocs
[1] = reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3349 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3350 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (section_symbol (absolute_section
));
3351 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3352 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_SPARC13
);
3353 reloc
->addend
= fixp
->tc_fix_data
;
3359 /* We have no need to default values of symbols. */
3363 md_undefined_symbol (name
)
3367 } /* md_undefined_symbol() */
3369 /* Round up a section size to the appropriate boundary. */
3371 md_section_align (segment
, size
)
3376 /* This is not right for ELF; a.out wants it, and COFF will force
3377 the alignment anyways. */
3378 valueT align
= ((valueT
) 1
3379 << (valueT
) bfd_get_section_alignment (stdoutput
, segment
));
3381 /* turn alignment value into a mask */
3383 newsize
= (size
+ align
) & ~align
;
3390 /* Exactly what point is a PC-relative offset relative TO?
3391 On the sparc, they're relative to the address of the offset, plus
3392 its size. This gets us to the following instruction.
3393 (??? Is this right? FIXME-SOON) */
3395 md_pcrel_from (fixP
)
3400 ret
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3401 if (! sparc_pic_code
3402 || fixP
->fx_addsy
== NULL
3403 || symbol_section_p (fixP
->fx_addsy
))
3404 ret
+= fixP
->fx_size
;
3408 /* Return log2 (VALUE), or -1 if VALUE is not an exact positive power
3420 for (shift
= 0; (value
& 1) == 0; value
>>= 1)
3423 return (value
== 1) ? shift
: -1;
3427 * sort of like s_lcomm
3431 static int max_alignment
= 15;
3446 name
= input_line_pointer
;
3447 c
= get_symbol_end ();
3448 p
= input_line_pointer
;
3452 if (*input_line_pointer
!= ',')
3454 as_bad (_("Expected comma after name"));
3455 ignore_rest_of_line ();
3459 ++input_line_pointer
;
3461 if ((size
= get_absolute_expression ()) < 0)
3463 as_bad (_("BSS length (%d.) <0! Ignored."), size
);
3464 ignore_rest_of_line ();
3469 symbolP
= symbol_find_or_make (name
);
3472 if (strncmp (input_line_pointer
, ",\"bss\"", 6) != 0
3473 && strncmp (input_line_pointer
, ",\".bss\"", 7) != 0)
3475 as_bad (_("bad .reserve segment -- expected BSS segment"));
3479 if (input_line_pointer
[2] == '.')
3480 input_line_pointer
+= 7;
3482 input_line_pointer
+= 6;
3485 if (*input_line_pointer
== ',')
3487 ++input_line_pointer
;
3490 if (*input_line_pointer
== '\n')
3492 as_bad (_("missing alignment"));
3493 ignore_rest_of_line ();
3497 align
= (int) get_absolute_expression ();
3500 if (align
> max_alignment
)
3502 align
= max_alignment
;
3503 as_warn (_("alignment too large; assuming %d"), align
);
3509 as_bad (_("negative alignment"));
3510 ignore_rest_of_line ();
3516 temp
= log2 (align
);
3519 as_bad (_("alignment not a power of 2"));
3520 ignore_rest_of_line ();
3527 record_alignment (bss_section
, align
);
3532 if (!S_IS_DEFINED (symbolP
)
3534 && S_GET_OTHER (symbolP
) == 0
3535 && S_GET_DESC (symbolP
) == 0
3542 segT current_seg
= now_seg
;
3543 subsegT current_subseg
= now_subseg
;
3545 subseg_set (bss_section
, 1); /* switch to bss */
3548 frag_align (align
, 0, 0); /* do alignment */
3550 /* detach from old frag */
3551 if (S_GET_SEGMENT(symbolP
) == bss_section
)
3552 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
3554 symbol_set_frag (symbolP
, frag_now
);
3555 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3556 (offsetT
) size
, (char *)0);
3559 S_SET_SEGMENT (symbolP
, bss_section
);
3561 subseg_set (current_seg
, current_subseg
);
3564 S_SET_SIZE (symbolP
, size
);
3570 as_warn("Ignoring attempt to re-define symbol %s",
3571 S_GET_NAME (symbolP
));
3572 } /* if not redefining */
3574 demand_empty_rest_of_line ();
3587 name
= input_line_pointer
;
3588 c
= get_symbol_end ();
3589 /* just after name is now '\0' */
3590 p
= input_line_pointer
;
3593 if (*input_line_pointer
!= ',')
3595 as_bad (_("Expected comma after symbol-name"));
3596 ignore_rest_of_line ();
3599 input_line_pointer
++; /* skip ',' */
3600 if ((temp
= get_absolute_expression ()) < 0)
3602 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
3603 ignore_rest_of_line ();
3608 symbolP
= symbol_find_or_make (name
);
3610 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3612 as_bad (_("Ignoring attempt to re-define symbol"));
3613 ignore_rest_of_line ();
3616 if (S_GET_VALUE (symbolP
) != 0)
3618 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
3620 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
3621 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
3627 S_SET_VALUE (symbolP
, (valueT
) size
);
3628 S_SET_EXTERNAL (symbolP
);
3631 know (symbol_get_frag (symbolP
) == &zero_address_frag
);
3632 if (*input_line_pointer
!= ',')
3634 as_bad (_("Expected comma after common length"));
3635 ignore_rest_of_line ();
3638 input_line_pointer
++;
3640 if (*input_line_pointer
!= '"')
3642 temp
= get_absolute_expression ();
3645 if (temp
> max_alignment
)
3647 temp
= max_alignment
;
3648 as_warn (_("alignment too large; assuming %d"), temp
);
3654 as_bad (_("negative alignment"));
3655 ignore_rest_of_line ();
3660 if (symbol_get_obj (symbolP
)->local
)
3668 old_subsec
= now_subseg
;
3673 align
= log2 (temp
);
3677 as_bad (_("alignment not a power of 2"));
3678 ignore_rest_of_line ();
3682 record_alignment (bss_section
, align
);
3683 subseg_set (bss_section
, 0);
3685 frag_align (align
, 0, 0);
3686 if (S_GET_SEGMENT (symbolP
) == bss_section
)
3687 symbol_get_frag (symbolP
)->fr_symbol
= 0;
3688 symbol_set_frag (symbolP
, frag_now
);
3689 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
3690 (offsetT
) size
, (char *) 0);
3692 S_SET_SEGMENT (symbolP
, bss_section
);
3693 S_CLEAR_EXTERNAL (symbolP
);
3694 S_SET_SIZE (symbolP
, size
);
3695 subseg_set (old_sec
, old_subsec
);
3698 #endif /* OBJ_ELF */
3701 S_SET_VALUE (symbolP
, (valueT
) size
);
3703 S_SET_ALIGN (symbolP
, temp
);
3704 S_SET_SIZE (symbolP
, size
);
3706 S_SET_EXTERNAL (symbolP
);
3707 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
3712 input_line_pointer
++;
3713 /* @@ Some use the dot, some don't. Can we get some consistency?? */
3714 if (*input_line_pointer
== '.')
3715 input_line_pointer
++;
3716 /* @@ Some say data, some say bss. */
3717 if (strncmp (input_line_pointer
, "bss\"", 4)
3718 && strncmp (input_line_pointer
, "data\"", 5))
3720 while (*--input_line_pointer
!= '"')
3722 input_line_pointer
--;
3723 goto bad_common_segment
;
3725 while (*input_line_pointer
++ != '"')
3727 goto allocate_common
;
3730 #ifdef BFD_ASSEMBLER
3731 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
3734 demand_empty_rest_of_line ();
3739 p
= input_line_pointer
;
3740 while (*p
&& *p
!= '\n')
3744 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
3746 input_line_pointer
= p
;
3747 ignore_rest_of_line ();
3752 /* Handle the .empty pseudo-op. This supresses the warnings about
3753 invalid delay slot usage. */
3759 /* The easy way to implement is to just forget about the last
3769 if (strncmp (input_line_pointer
, "\"text\"", 6) == 0)
3771 input_line_pointer
+= 6;
3775 if (strncmp (input_line_pointer
, "\"data\"", 6) == 0)
3777 input_line_pointer
+= 6;
3781 if (strncmp (input_line_pointer
, "\"data1\"", 7) == 0)
3783 input_line_pointer
+= 7;
3787 if (strncmp (input_line_pointer
, "\"bss\"", 5) == 0)
3789 input_line_pointer
+= 5;
3790 /* We only support 2 segments -- text and data -- for now, so
3791 things in the "bss segment" will have to go into data for now.
3792 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
3793 subseg_set (data_section
, 255); /* FIXME-SOMEDAY */
3796 as_bad (_("Unknown segment type"));
3797 demand_empty_rest_of_line ();
3803 subseg_set (data_section
, 1);
3804 demand_empty_rest_of_line ();
3811 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
3813 ++input_line_pointer
;
3815 ++input_line_pointer
;
3818 /* This static variable is set by s_uacons to tell sparc_cons_align
3819 that the expession does not need to be aligned. */
3821 static int sparc_no_align_cons
= 0;
3823 /* This handles the unaligned space allocation pseudo-ops, such as
3824 .uaword. .uaword is just like .word, but the value does not need
3831 /* Tell sparc_cons_align not to align this value. */
3832 sparc_no_align_cons
= 1;
3836 /* This handles the native word allocation pseudo-op .nword.
3837 For sparc_arch_size 32 it is equivalent to .word, for
3838 sparc_arch_size 64 it is equivalent to .xword. */
3844 cons (sparc_arch_size
== 32 ? 4 : 8);
3848 /* Handle the SPARC ELF .register pseudo-op. This sets the binding of a
3852 .register %g[2367],{#scratch|symbolname|#ignore}
3862 const char *regname
;
3864 if (input_line_pointer
[0] != '%'
3865 || input_line_pointer
[1] != 'g'
3866 || ((input_line_pointer
[2] & ~1) != '2'
3867 && (input_line_pointer
[2] & ~1) != '6')
3868 || input_line_pointer
[3] != ',')
3869 as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
3870 reg
= input_line_pointer
[2] - '0';
3871 input_line_pointer
+= 4;
3873 if (*input_line_pointer
== '#')
3875 ++input_line_pointer
;
3876 regname
= input_line_pointer
;
3877 c
= get_symbol_end ();
3878 if (strcmp (regname
, "scratch") && strcmp (regname
, "ignore"))
3879 as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
3880 if (regname
[0] == 'i')
3887 regname
= input_line_pointer
;
3888 c
= get_symbol_end ();
3890 if (sparc_arch_size
== 64)
3894 if ((regname
&& globals
[reg
] != (symbolS
*)1
3895 && strcmp (S_GET_NAME (globals
[reg
]), regname
))
3896 || ((regname
!= NULL
) ^ (globals
[reg
] != (symbolS
*)1)))
3897 as_bad (_("redefinition of global register"));
3901 if (regname
== NULL
)
3902 globals
[reg
] = (symbolS
*)1;
3907 if (symbol_find (regname
))
3908 as_bad (_("Register symbol %s already defined."),
3911 globals
[reg
] = symbol_make (regname
);
3912 flags
= symbol_get_bfdsym (globals
[reg
])->flags
;
3914 flags
= flags
& ~(BSF_GLOBAL
|BSF_LOCAL
|BSF_WEAK
);
3915 if (! (flags
& (BSF_GLOBAL
|BSF_LOCAL
|BSF_WEAK
)))
3916 flags
|= BSF_GLOBAL
;
3917 symbol_get_bfdsym (globals
[reg
])->flags
= flags
;
3918 S_SET_VALUE (globals
[reg
], (valueT
)reg
);
3919 S_SET_ALIGN (globals
[reg
], reg
);
3920 S_SET_SIZE (globals
[reg
], 0);
3921 /* Although we actually want undefined_section here,
3922 we have to use absolute_section, because otherwise
3923 generic as code will make it a COM section.
3924 We fix this up in sparc_adjust_symtab. */
3925 S_SET_SEGMENT (globals
[reg
], absolute_section
);
3926 S_SET_OTHER (globals
[reg
], 0);
3927 elf_symbol (symbol_get_bfdsym (globals
[reg
]))
3928 ->internal_elf_sym
.st_info
=
3929 ELF_ST_INFO(STB_GLOBAL
, STT_REGISTER
);
3930 elf_symbol (symbol_get_bfdsym (globals
[reg
]))
3931 ->internal_elf_sym
.st_shndx
= SHN_UNDEF
;
3936 *input_line_pointer
= c
;
3938 demand_empty_rest_of_line ();
3941 /* Adjust the symbol table. We set undefined sections for STT_REGISTER
3942 symbols which need it. */
3945 sparc_adjust_symtab ()
3949 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3951 if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym
))
3952 ->internal_elf_sym
.st_info
) != STT_REGISTER
)
3955 if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym
))
3956 ->internal_elf_sym
.st_shndx
!= SHN_UNDEF
))
3959 S_SET_SEGMENT (sym
, undefined_section
);
3964 /* If the --enforce-aligned-data option is used, we require .word,
3965 et. al., to be aligned correctly. We do it by setting up an
3966 rs_align_code frag, and checking in HANDLE_ALIGN to make sure that
3967 no unexpected alignment was introduced.
3969 The SunOS and Solaris native assemblers enforce aligned data by
3970 default. We don't want to do that, because gcc can deliberately
3971 generate misaligned data if the packed attribute is used. Instead,
3972 we permit misaligned data by default, and permit the user to set an
3973 option to check for it. */
3976 sparc_cons_align (nbytes
)
3982 /* Only do this if we are enforcing aligned data. */
3983 if (! enforce_aligned_data
)
3986 if (sparc_no_align_cons
)
3988 /* This is an unaligned pseudo-op. */
3989 sparc_no_align_cons
= 0;
3993 nalign
= log2 (nbytes
);
3997 assert (nalign
> 0);
3999 if (now_seg
== absolute_section
)
4001 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
4002 as_bad (_("misaligned data"));
4006 p
= frag_var (rs_align_code
, 1, 1, (relax_substateT
) 0,
4007 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
4009 record_alignment (now_seg
, nalign
);
4012 /* This is where we do the unexpected alignment check.
4013 This is called from HANDLE_ALIGN in tc-sparc.h. */
4016 sparc_handle_align (fragp
)
4019 if (fragp
->fr_type
== rs_align_code
&& !fragp
->fr_subtype
4020 && fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
!= 0)
4021 as_bad_where (fragp
->fr_file
, fragp
->fr_line
, _("misaligned data"));
4022 if (fragp
->fr_type
== rs_align_code
&& fragp
->fr_subtype
== 1024)
4024 int count
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
4029 && !((long)(fragp
->fr_literal
+ fragp
->fr_fix
) & 3))
4031 unsigned *p
= (unsigned *)(fragp
->fr_literal
+ fragp
->fr_fix
);
4034 for (i
= 0; i
< count
; i
+= 4, p
++)
4035 if (INSN_BIG_ENDIAN
)
4036 number_to_chars_bigendian ((char *)p
, 0x01000000, 4); /* emit nops */
4038 number_to_chars_littleendian ((char *)p
, 0x10000000, 4);
4040 if (SPARC_OPCODE_ARCH_V9_P (max_architecture
) && count
> 8)
4042 char *waddr
= &fragp
->fr_literal
[fragp
->fr_fix
];
4043 unsigned wval
= (0x30680000 | count
>> 2); /* ba,a,pt %xcc, 1f */
4044 if (INSN_BIG_ENDIAN
)
4045 number_to_chars_bigendian (waddr
, wval
, 4);
4047 number_to_chars_littleendian (waddr
, wval
, 4);
4049 fragp
->fr_var
= count
;
4055 /* Some special processing for a Sparc ELF file. */
4058 sparc_elf_final_processing ()
4060 /* Set the Sparc ELF flag bits. FIXME: There should probably be some
4061 sort of BFD interface for this. */
4062 if (sparc_arch_size
== 64)
4064 switch (sparc_memory_model
)
4067 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARCV9_RMO
;
4070 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARCV9_PSO
;
4076 else if (current_architecture
>= SPARC_OPCODE_ARCH_V9
)
4077 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARC_32PLUS
;
4078 if (current_architecture
== SPARC_OPCODE_ARCH_V9A
)
4079 elf_elfheader (stdoutput
)->e_flags
|= EF_SPARC_SUN_US1
;
4083 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
4084 reloc for a cons. We could use the definition there, except that
4085 we want to handle little endian relocs specially. */
4088 cons_fix_new_sparc (frag
, where
, nbytes
, exp
)
4091 unsigned int nbytes
;
4094 bfd_reloc_code_real_type r
;
4096 r
= (nbytes
== 1 ? BFD_RELOC_8
:
4097 (nbytes
== 2 ? BFD_RELOC_16
:
4098 (nbytes
== 4 ? BFD_RELOC_32
: BFD_RELOC_64
)));
4100 if (target_little_endian_data
&& nbytes
== 4
4101 && now_seg
->flags
& SEC_ALLOC
)
4102 r
= BFD_RELOC_SPARC_REV32
;
4103 fix_new_exp (frag
, where
, (int) nbytes
, exp
, 0, r
);
4108 elf32_sparc_force_relocation (fixp
)
4111 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4112 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)