]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-sparc.c
2.41 Release sources
[thirdparty/binutils-gdb.git] / gas / config / tc-sparc.c
CommitLineData
252b5132 1/* tc-sparc.c -- Assemble for the SPARC
d87bef3a 2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
252b5132
RH
3 This file is part of GAS, the GNU Assembler.
4
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
ec2655a6 7 the Free Software Foundation; either version 3, or (at your option)
252b5132
RH
8 any later version.
9
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.
14
15 You should have received a copy of the GNU General Public
16 License along with GAS; see the file COPYING. If not, write
4b4da160
NC
17 to the Free Software Foundation, 51 Franklin Street - Fifth Floor,
18 Boston, MA 02110-1301, USA. */
252b5132 19
252b5132 20#include "as.h"
3882b010 21#include "safe-ctype.h"
252b5132
RH
22#include "subsegs.h"
23
24#include "opcode/sparc.h"
364b6d8b 25#include "dw2gencfi.h"
252b5132 26
252b5132 27#include "elf/sparc.h"
732d96b6 28#include "dwarf2dbg.h"
252b5132 29
6c1b24e4
AO
30/* Some ancient Sun C compilers would not take such hex constants as
31 unsigned, and would end up sign-extending them to form an offsetT,
32 so use these constants instead. */
33#define U0xffffffff ((((unsigned long) 1 << 16) << 16) - 1)
34#define U0x80000000 ((((unsigned long) 1 << 16) << 15))
35
5a49b8ac 36static int sparc_ip (char *, const struct sparc_opcode **);
1e9d41d4 37static int parse_sparc_asi (char **, const sparc_asi **);
5a49b8ac
AM
38static int parse_keyword_arg (int (*) (const char *), char **, int *);
39static int parse_const_expr_arg (char **, int *);
40static int get_expression (char *);
252b5132
RH
41
42/* Default architecture. */
43/* ??? The default value should be V8, but sparclite support was added
44 by making it the default. GCC now passes -Asparclite, so maybe sometime in
45 the future we can set this to V8. */
46#ifndef DEFAULT_ARCH
47#define DEFAULT_ARCH "sparclite"
48#endif
e0471c16 49static const char *default_arch = DEFAULT_ARCH;
252b5132
RH
50
51/* Non-zero if the initial values of `max_architecture' and `sparc_arch_size'
52 have been set. */
53static int default_init_p;
54
55/* Current architecture. We don't bump up unless necessary. */
56static enum sparc_opcode_arch_val current_architecture = SPARC_OPCODE_ARCH_V6;
57
58/* The maximum architecture level we can bump up to.
59 In a 32 bit environment, don't allow bumping up to v9 by default.
60 The native assembler works this way. The user is required to pass
61 an explicit argument before we'll create v9 object files. However, if
62 we don't see any v9 insns, a v8plus object file is not created. */
63static enum sparc_opcode_arch_val max_architecture;
64
65/* Either 32 or 64, selects file format. */
66static int sparc_arch_size;
67/* Initial (default) value, recorded separately in case a user option
68 changes the value before md_show_usage is called. */
69static int default_arch_size;
70
252b5132
RH
71/* The currently selected v9 memory model. Currently only used for
72 ELF. */
73static enum { MM_TSO, MM_PSO, MM_RMO } sparc_memory_model = MM_RMO;
9e8c70f9
DM
74
75#ifndef TE_SOLARIS
76/* Bitmask of instruction types seen so far, used to populate the
77 GNU attributes section with hwcap information. */
0e3c1eeb 78static uint64_t hwcap_seen;
9e8c70f9 79#endif
252b5132 80
0e3c1eeb 81static uint64_t hwcap_allowed;
4bafe00e 82
252b5132
RH
83static int architecture_requested;
84static int warn_on_bump;
85
86/* If warn_on_bump and the needed architecture is higher than this
87 architecture, issue a warning. */
88static enum sparc_opcode_arch_val warn_after_architecture;
89
46a2d504
JM
90/* Non-zero if the assembler should generate error if an undeclared
91 g[23] register has been used in -64. */
6d8809aa
RH
92static int no_undeclared_regs;
93
46a2d504
JM
94/* Non-zero if the assembler should generate a warning if an
95 unpredictable DCTI (delayed control transfer instruction) couple is
96 found. */
97static int dcti_couples_detect;
98
6faf3d66
JJ
99/* Non-zero if we should try to relax jumps and calls. */
100static int sparc_relax;
101
252b5132
RH
102/* Non-zero if we are generating PIC code. */
103int sparc_pic_code;
104
105/* Non-zero if we should give an error when misaligned data is seen. */
106static int enforce_aligned_data;
107
108extern int target_big_endian;
109
110static int target_little_endian_data;
111
6d8809aa
RH
112/* Symbols for global registers on v9. */
113static symbolS *globals[8];
114
364b6d8b
JJ
115/* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
116int sparc_cie_data_alignment;
117
252b5132
RH
118/* V9 and 86x have big and little endian data, but instructions are always big
119 endian. The sparclet has bi-endian support but both data and insns have
120 the same endianness. Global `target_big_endian' is used for data.
121 The following macro is used for instructions. */
122#ifndef INSN_BIG_ENDIAN
123#define INSN_BIG_ENDIAN (target_big_endian \
124 || default_arch_type == sparc86x \
125 || SPARC_OPCODE_ARCH_V9_P (max_architecture))
126#endif
127
e0c6ed95 128/* Handle of the OPCODE hash table. */
629310ab 129static htab_t op_hash;
252b5132 130
5a49b8ac
AM
131static void s_data1 (void);
132static void s_seg (int);
133static void s_proc (int);
134static void s_reserve (int);
135static void s_common (int);
136static void s_empty (int);
137static void s_uacons (int);
138static void s_ncons (int);
5a49b8ac 139static void s_register (int);
252b5132
RH
140
141const pseudo_typeS md_pseudo_table[] =
142{
e0c6ed95 143 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0). */
252b5132
RH
144 {"common", s_common, 0},
145 {"empty", s_empty, 0},
146 {"global", s_globl, 0},
147 {"half", cons, 2},
cf9a1301 148 {"nword", s_ncons, 0},
252b5132
RH
149 {"optim", s_ignore, 0},
150 {"proc", s_proc, 0},
151 {"reserve", s_reserve, 0},
152 {"seg", s_seg, 0},
153 {"skip", s_space, 0},
154 {"word", cons, 4},
155 {"xword", cons, 8},
156 {"uahalf", s_uacons, 2},
157 {"uaword", s_uacons, 4},
158 {"uaxword", s_uacons, 8},
e0c6ed95 159 /* These are specific to sparc/svr4. */
252b5132
RH
160 {"2byte", s_uacons, 2},
161 {"4byte", s_uacons, 4},
162 {"8byte", s_uacons, 8},
6d8809aa 163 {"register", s_register, 0},
252b5132
RH
164 {NULL, 0, 0},
165};
166
252b5132 167/* This array holds the chars that always start a comment. If the
e0c6ed95
AM
168 pre-processor is disabled, these aren't very useful. */
169const char comment_chars[] = "!"; /* JF removed '|' from
170 comment_chars. */
252b5132
RH
171
172/* This array holds the chars that only start a comment at the beginning of
173 a line. If the line seems to have the form '# 123 filename'
e0c6ed95 174 .line and .file directives will appear in the pre-processed output. */
252b5132
RH
175/* Note that input_file.c hand checks for '#' at the beginning of the
176 first line of the input file. This is because the compiler outputs
e0c6ed95 177 #NO_APP at the beginning of its output. */
252b5132 178/* Also note that comments started like this one will always
e0c6ed95 179 work if '/' isn't otherwise defined. */
252b5132
RH
180const char line_comment_chars[] = "#";
181
63a0b638 182const char line_separator_chars[] = ";";
252b5132 183
e0c6ed95
AM
184/* Chars that can be used to separate mant from exp in floating point
185 nums. */
252b5132
RH
186const char EXP_CHARS[] = "eE";
187
e0c6ed95
AM
188/* Chars that mean this number is a floating point constant.
189 As in 0f12.456
190 or 0d1.2345e12 */
252b5132
RH
191const char FLT_CHARS[] = "rRsSfFdDxXpP";
192
193/* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
194 changed in read.c. Ideally it shouldn't have to know about it at all,
195 but nothing is ideal around here. */
196
74b56d1f 197#define isoctal(c) ((unsigned) ((c) - '0') < 8)
252b5132
RH
198
199struct sparc_it
200 {
6d4af3c2 201 const char *error;
252b5132
RH
202 unsigned long opcode;
203 struct nlist *nlistp;
204 expressionS exp;
cf9a1301 205 expressionS exp2;
252b5132
RH
206 int pcrel;
207 bfd_reloc_code_real_type reloc;
208 };
209
210struct sparc_it the_insn, set_insn;
211
5a49b8ac 212static void output_insn (const struct sparc_opcode *, struct sparc_it *);
252b5132
RH
213\f
214/* Table of arguments to -A.
215 The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect
216 for this use. That table is for opcodes only. This table is for opcodes
217 and file formats. */
218
d6787ef9 219enum sparc_arch_types {v6, v7, v8, leon, sparclet, sparclite, sparc86x, v8plus,
19f7b010 220 v8plusa, v9, v9a, v9b, v9_64};
252b5132
RH
221
222static struct sparc_arch {
e0471c16
TS
223 const char *name;
224 const char *opcode_arch;
252b5132
RH
225 enum sparc_arch_types arch_type;
226 /* Default word size, as specified during configuration.
227 A value of zero means can't be used to specify default architecture. */
228 int default_arch_size;
229 /* Allowable arg to -A? */
230 int user_option_p;
6884417a
JM
231 /* Extra hardware capabilities allowed. These are added to the
232 hardware capabilities associated with the opcode
233 architecture. */
4bafe00e 234 int hwcap_allowed;
3d68f91c 235 int hwcap2_allowed;
252b5132 236} sparc_arch_table[] = {
3d68f91c
JM
237 { "v6", "v6", v6, 0, 1, 0, 0 },
238 { "v7", "v7", v7, 0, 1, 0, 0 },
6884417a
JM
239 { "v8", "v8", v8, 32, 1, 0, 0 },
240 { "v8a", "v8", v8, 32, 1, 0, 0 },
241 { "sparc", "v9", v9, 0, 1, HWCAP_V8PLUS, 0 },
242 { "sparcvis", "v9a", v9, 0, 1, 0, 0 },
243 { "sparcvis2", "v9b", v9, 0, 1, 0, 0 },
244 { "sparcfmaf", "v9b", v9, 0, 1, HWCAP_FMAF, 0 },
245 { "sparcima", "v9b", v9, 0, 1, HWCAP_FMAF|HWCAP_IMA, 0 },
246 { "sparcvis3", "v9b", v9, 0, 1, HWCAP_FMAF|HWCAP_VIS3|HWCAP_HPC, 0 },
247 { "sparcvis3r", "v9b", v9, 0, 1, HWCAP_FMAF|HWCAP_VIS3|HWCAP_HPC|HWCAP_FJFMAU, 0 },
248
249 { "sparc4", "v9v", v9, 0, 1, 0, 0 },
250 { "sparc5", "v9m", v9, 0, 1, 0, 0 },
64517994 251 { "sparc6", "m8", v9, 0, 1, 0, 0 },
6884417a
JM
252
253 { "leon", "leon", leon, 32, 1, 0, 0 },
254 { "sparclet", "sparclet", sparclet, 32, 1, 0, 0 },
255 { "sparclite", "sparclite", sparclite, 32, 1, 0, 0 },
256 { "sparc86x", "sparclite", sparc86x, 32, 1, 0, 0 },
257
258 { "v8plus", "v9", v9, 0, 1, HWCAP_V8PLUS, 0 },
259 { "v8plusa", "v9a", v9, 0, 1, HWCAP_V8PLUS, 0 },
260 { "v8plusb", "v9b", v9, 0, 1, HWCAP_V8PLUS, 0 },
261 { "v8plusc", "v9c", v9, 0, 1, HWCAP_V8PLUS, 0 },
262 { "v8plusd", "v9d", v9, 0, 1, HWCAP_V8PLUS, 0 },
263 { "v8pluse", "v9e", v9, 0, 1, HWCAP_V8PLUS, 0 },
264 { "v8plusv", "v9v", v9, 0, 1, HWCAP_V8PLUS, 0 },
265 { "v8plusm", "v9m", v9, 0, 1, HWCAP_V8PLUS, 0 },
64517994
JM
266 { "v8plusm8", "m8", v9, 0, 1, HWCAP_V8PLUS, 0 },
267
6884417a
JM
268 { "v9", "v9", v9, 0, 1, 0, 0 },
269 { "v9a", "v9a", v9, 0, 1, 0, 0 },
270 { "v9b", "v9b", v9, 0, 1, 0, 0 },
271 { "v9c", "v9c", v9, 0, 1, 0, 0 },
272 { "v9d", "v9d", v9, 0, 1, 0, 0 },
273 { "v9e", "v9e", v9, 0, 1, 0, 0 },
274 { "v9v", "v9v", v9, 0, 1, 0, 0 },
275 { "v9m", "v9m", v9, 0, 1, 0, 0 },
64517994 276 { "v9m8", "m8", v9, 0, 1, 0, 0 },
3d68f91c 277
1110793a 278 /* This exists to allow configure.tgt to pass one
252b5132 279 value to specify both the default machine and default word size. */
6884417a 280 { "v9-64", "v9", v9, 64, 0, 0, 0 },
3d68f91c 281 { NULL, NULL, v8, 0, 0, 0, 0 }
252b5132
RH
282};
283
284/* Variant of default_arch */
285static enum sparc_arch_types default_arch_type;
286
287static struct sparc_arch *
e0471c16 288lookup_arch (const char *name)
252b5132
RH
289{
290 struct sparc_arch *sa;
291
292 for (sa = &sparc_arch_table[0]; sa->name != NULL; sa++)
293 if (strcmp (sa->name, name) == 0)
294 break;
295 if (sa->name == NULL)
296 return NULL;
297 return sa;
298}
299
300/* Initialize the default opcode arch and word size from the default
301 architecture name. */
302
303static void
5a49b8ac 304init_default_arch (void)
252b5132
RH
305{
306 struct sparc_arch *sa = lookup_arch (default_arch);
307
308 if (sa == NULL
309 || sa->default_arch_size == 0)
310 as_fatal (_("Invalid default architecture, broken assembler."));
311
312 max_architecture = sparc_opcode_lookup_arch (sa->opcode_arch);
313 if (max_architecture == SPARC_OPCODE_ARCH_BAD)
314 as_fatal (_("Bad opcode table, broken assembler."));
315 default_arch_size = sparc_arch_size = sa->default_arch_size;
316 default_init_p = 1;
317 default_arch_type = sa->arch_type;
318}
319
d85815e2
EB
320/* Called by TARGET_MACH. */
321
322unsigned long
323sparc_mach (void)
324{
325 /* We don't get a chance to initialize anything before we're called,
326 so handle that now. */
327 if (! default_init_p)
328 init_default_arch ();
329
330 return sparc_arch_size == 64 ? bfd_mach_sparc_v9 : bfd_mach_sparc;
331}
332
252b5132
RH
333/* Called by TARGET_FORMAT. */
334
335const char *
5a49b8ac 336sparc_target_format (void)
252b5132
RH
337{
338 /* We don't get a chance to initialize anything before we're called,
339 so handle that now. */
340 if (! default_init_p)
341 init_default_arch ();
342
910600e9
RS
343#ifdef TE_VXWORKS
344 return "elf32-sparc-vxworks";
345#endif
346
71a75f6f 347 return sparc_arch_size == 64 ? ELF64_TARGET_FORMAT : ELF_TARGET_FORMAT;
252b5132
RH
348}
349\f
e0c6ed95 350/* md_parse_option
252b5132
RH
351 * Invocation line includes a switch not recognized by the base assembler.
352 * See if it's a processor-specific option. These are:
353 *
354 * -bump
355 * Warn on architecture bumps. See also -A.
356 *
d6787ef9 357 * -Av6, -Av7, -Av8, -Aleon, -Asparclite, -Asparclet
252b5132 358 * Standard 32 bit architectures.
19f7b010 359 * -Av9, -Av9a, -Av9b
252b5132
RH
360 * Sparc64 in either a 32 or 64 bit world (-32/-64 says which).
361 * This used to only mean 64 bits, but properly specifying it
362 * complicated gcc's ASM_SPECs, so now opcode selection is
363 * specified orthogonally to word size (except when specifying
364 * the default, but that is an internal implementation detail).
19f7b010
JJ
365 * -Av8plus, -Av8plusa, -Av8plusb
366 * Same as -Av9{,a,b}.
367 * -xarch=v8plus, -xarch=v8plusa, -xarch=v8plusb
368 * Same as -Av8plus{,a,b} -32, for compatibility with Sun's
369 * assembler.
370 * -xarch=v9, -xarch=v9a, -xarch=v9b
371 * Same as -Av9{,a,b} -64, for compatibility with Sun's
c2158c24 372 * assembler.
252b5132
RH
373 *
374 * Select the architecture and possibly the file format.
375 * Instructions or features not supported by the selected
376 * architecture cause fatal errors.
377 *
378 * The default is to start at v6, and bump the architecture up
379 * whenever an instruction is seen at a higher level. In 32 bit
380 * environments, v9 is not bumped up to, the user must pass
19f7b010 381 * -Av8plus{,a,b}.
252b5132
RH
382 *
383 * If -bump is specified, a warning is printing when bumping to
384 * higher levels.
385 *
386 * If an architecture is specified, all instructions must match
387 * that architecture. Any higher level instructions are flagged
388 * as errors. Note that in the 32 bit environment specifying
389 * -Av8plus does not automatically create a v8plus object file, a
390 * v9 insn must be seen.
391 *
392 * If both an architecture and -bump are specified, the
393 * architecture starts at the specified level, but bumps are
394 * warnings. Note that we can't set `current_architecture' to
395 * the requested level in this case: in the 32 bit environment,
396 * we still must avoid creating v8plus object files unless v9
397 * insns are seen.
398 *
399 * Note:
400 * Bumping between incompatible architectures is always an
401 * error. For example, from sparclite to v9.
402 */
403
5a38dc70 404const char *md_shortopts = "A:K:VQ:sq";
252b5132
RH
405struct option md_longopts[] = {
406#define OPTION_BUMP (OPTION_MD_BASE)
407 {"bump", no_argument, NULL, OPTION_BUMP},
408#define OPTION_SPARC (OPTION_MD_BASE + 1)
409 {"sparc", no_argument, NULL, OPTION_SPARC},
410#define OPTION_XARCH (OPTION_MD_BASE + 2)
411 {"xarch", required_argument, NULL, OPTION_XARCH},
252b5132
RH
412#define OPTION_32 (OPTION_MD_BASE + 3)
413 {"32", no_argument, NULL, OPTION_32},
414#define OPTION_64 (OPTION_MD_BASE + 4)
415 {"64", no_argument, NULL, OPTION_64},
416#define OPTION_TSO (OPTION_MD_BASE + 5)
417 {"TSO", no_argument, NULL, OPTION_TSO},
418#define OPTION_PSO (OPTION_MD_BASE + 6)
419 {"PSO", no_argument, NULL, OPTION_PSO},
420#define OPTION_RMO (OPTION_MD_BASE + 7)
421 {"RMO", no_argument, NULL, OPTION_RMO},
252b5132
RH
422#ifdef SPARC_BIENDIAN
423#define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8)
424 {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},
425#define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9)
426 {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},
427#endif
428#define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10)
429 {"enforce-aligned-data", no_argument, NULL, OPTION_ENFORCE_ALIGNED_DATA},
430#define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11)
431 {"little-endian-data", no_argument, NULL, OPTION_LITTLE_ENDIAN_DATA},
6d8809aa
RH
432#define OPTION_NO_UNDECLARED_REGS (OPTION_MD_BASE + 12)
433 {"no-undeclared-regs", no_argument, NULL, OPTION_NO_UNDECLARED_REGS},
a25fe906
ILT
434#define OPTION_UNDECLARED_REGS (OPTION_MD_BASE + 13)
435 {"undeclared-regs", no_argument, NULL, OPTION_UNDECLARED_REGS},
6faf3d66
JJ
436#define OPTION_RELAX (OPTION_MD_BASE + 14)
437 {"relax", no_argument, NULL, OPTION_RELAX},
438#define OPTION_NO_RELAX (OPTION_MD_BASE + 15)
439 {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
46a2d504
JM
440#define OPTION_DCTI_COUPLES_DETECT (OPTION_MD_BASE + 16)
441 {"dcti-couples-detect", no_argument, NULL, OPTION_DCTI_COUPLES_DETECT},
252b5132
RH
442 {NULL, no_argument, NULL, 0}
443};
e0c6ed95
AM
444
445size_t md_longopts_size = sizeof (md_longopts);
252b5132
RH
446
447int
17b9d67d 448md_parse_option (int c, const char *arg)
252b5132
RH
449{
450 /* We don't get a chance to initialize anything before we're called,
451 so handle that now. */
452 if (! default_init_p)
453 init_default_arch ();
454
455 switch (c)
456 {
457 case OPTION_BUMP:
458 warn_on_bump = 1;
459 warn_after_architecture = SPARC_OPCODE_ARCH_V6;
460 break;
461
462 case OPTION_XARCH:
d34049e8 463 if (startswith (arg, "v9"))
c2158c24 464 md_parse_option (OPTION_64, NULL);
668b27ea
DM
465 else
466 {
d34049e8
ML
467 if (startswith (arg, "v8")
468 || startswith (arg, "v7")
469 || startswith (arg, "v6")
668b27ea
DM
470 || !strcmp (arg, "sparclet")
471 || !strcmp (arg, "sparclite")
472 || !strcmp (arg, "sparc86x"))
473 md_parse_option (OPTION_32, NULL);
474 }
e0c6ed95 475 /* Fall through. */
252b5132
RH
476
477 case 'A':
478 {
479 struct sparc_arch *sa;
480 enum sparc_opcode_arch_val opcode_arch;
481
482 sa = lookup_arch (arg);
483 if (sa == NULL
484 || ! sa->user_option_p)
485 {
c2158c24
JJ
486 if (c == OPTION_XARCH)
487 as_bad (_("invalid architecture -xarch=%s"), arg);
488 else
489 as_bad (_("invalid architecture -A%s"), arg);
252b5132
RH
490 return 0;
491 }
492
493 opcode_arch = sparc_opcode_lookup_arch (sa->opcode_arch);
494 if (opcode_arch == SPARC_OPCODE_ARCH_BAD)
495 as_fatal (_("Bad opcode table, broken assembler."));
496
4bafe00e
DM
497 if (!architecture_requested
498 || opcode_arch > max_architecture)
499 max_architecture = opcode_arch;
6884417a 500
0e3c1eeb
AM
501 /* The allowed hardware capabilities are the implied by the
502 opcodes arch plus any extra capabilities defined in the GAS
503 arch. */
504 hwcap_allowed
505 = (hwcap_allowed
506 | ((uint64_t) sparc_opcode_archs[opcode_arch].hwcaps2 << 32)
507 | ((uint64_t) sa->hwcap2_allowed << 32)
508 | sparc_opcode_archs[opcode_arch].hwcaps
509 | sa->hwcap_allowed);
252b5132
RH
510 architecture_requested = 1;
511 }
512 break;
513
514 case OPTION_SPARC:
515 /* Ignore -sparc, used by SunOS make default .s.o rule. */
516 break;
517
518 case OPTION_ENFORCE_ALIGNED_DATA:
519 enforce_aligned_data = 1;
520 break;
521
522#ifdef SPARC_BIENDIAN
523 case OPTION_LITTLE_ENDIAN:
524 target_big_endian = 0;
525 if (default_arch_type != sparclet)
526 as_fatal ("This target does not support -EL");
527 break;
528 case OPTION_LITTLE_ENDIAN_DATA:
529 target_little_endian_data = 1;
530 target_big_endian = 0;
531 if (default_arch_type != sparc86x
532 && default_arch_type != v9)
533 as_fatal ("This target does not support --little-endian-data");
534 break;
535 case OPTION_BIG_ENDIAN:
536 target_big_endian = 1;
537 break;
538#endif
539
252b5132
RH
540 case OPTION_32:
541 case OPTION_64:
542 {
543 const char **list, **l;
544
545 sparc_arch_size = c == OPTION_32 ? 32 : 64;
546 list = bfd_target_list ();
547 for (l = list; *l != NULL; l++)
548 {
549 if (sparc_arch_size == 32)
550 {
08dedd66 551 if (startswith (*l, "elf32-sparc"))
252b5132
RH
552 break;
553 }
554 else
555 {
08dedd66 556 if (startswith (*l, "elf64-sparc"))
252b5132
RH
557 break;
558 }
559 }
560 if (*l == NULL)
561 as_fatal (_("No compiled in support for %d bit object file format"),
562 sparc_arch_size);
563 free (list);
b7cac25f
DM
564
565 if (sparc_arch_size == 64
566 && max_architecture < SPARC_OPCODE_ARCH_V9)
567 max_architecture = SPARC_OPCODE_ARCH_V9;
252b5132
RH
568 }
569 break;
570
571 case OPTION_TSO:
572 sparc_memory_model = MM_TSO;
573 break;
574
575 case OPTION_PSO:
576 sparc_memory_model = MM_PSO;
577 break;
578
579 case OPTION_RMO:
580 sparc_memory_model = MM_RMO;
581 break;
582
583 case 'V':
584 print_version_id ();
585 break;
586
587 case 'Q':
588 /* Qy - do emit .comment
e0c6ed95 589 Qn - do not emit .comment. */
252b5132
RH
590 break;
591
592 case 's':
e0c6ed95 593 /* Use .stab instead of .stab.excl. */
252b5132
RH
594 break;
595
596 case 'q':
e0c6ed95 597 /* quick -- Native assembler does fewer checks. */
252b5132
RH
598 break;
599
600 case 'K':
601 if (strcmp (arg, "PIC") != 0)
602 as_warn (_("Unrecognized option following -K"));
603 else
604 sparc_pic_code = 1;
605 break;
6d8809aa
RH
606
607 case OPTION_NO_UNDECLARED_REGS:
608 no_undeclared_regs = 1;
609 break;
a25fe906
ILT
610
611 case OPTION_UNDECLARED_REGS:
612 no_undeclared_regs = 0;
613 break;
252b5132 614
6faf3d66
JJ
615 case OPTION_RELAX:
616 sparc_relax = 1;
617 break;
618
619 case OPTION_NO_RELAX:
620 sparc_relax = 0;
621 break;
622
46a2d504
JM
623 case OPTION_DCTI_COUPLES_DETECT:
624 dcti_couples_detect = 1;
625 break;
626
252b5132
RH
627 default:
628 return 0;
629 }
630
631 return 1;
632}
633
634void
5a49b8ac 635md_show_usage (FILE *stream)
252b5132
RH
636{
637 const struct sparc_arch *arch;
c2158c24 638 int column;
252b5132
RH
639
640 /* We don't get a chance to initialize anything before we're called,
641 so handle that now. */
642 if (! default_init_p)
643 init_default_arch ();
644
e0c6ed95 645 fprintf (stream, _("SPARC options:\n"));
c2158c24 646 column = 0;
252b5132
RH
647 for (arch = &sparc_arch_table[0]; arch->name; arch++)
648 {
c2158c24
JJ
649 if (!arch->user_option_p)
650 continue;
252b5132
RH
651 if (arch != &sparc_arch_table[0])
652 fprintf (stream, " | ");
07726851 653 if (column + strlen (arch->name) > 70)
c2158c24
JJ
654 {
655 column = 0;
656 fputc ('\n', stream);
657 }
07726851 658 column += 5 + 2 + strlen (arch->name);
c2158c24 659 fprintf (stream, "-A%s", arch->name);
252b5132 660 }
c2158c24
JJ
661 for (arch = &sparc_arch_table[0]; arch->name; arch++)
662 {
663 if (!arch->user_option_p)
664 continue;
665 fprintf (stream, " | ");
07726851 666 if (column + strlen (arch->name) > 65)
c2158c24
JJ
667 {
668 column = 0;
669 fputc ('\n', stream);
670 }
07726851 671 column += 5 + 7 + strlen (arch->name);
c2158c24
JJ
672 fprintf (stream, "-xarch=%s", arch->name);
673 }
674 fprintf (stream, _("\n\
252b5132
RH
675 specify variant of SPARC architecture\n\
676-bump warn when assembler switches architectures\n\
677-sparc ignored\n\
6faf3d66
JJ
678--enforce-aligned-data force .long, etc., to be aligned correctly\n\
679-relax relax jumps and branches (default)\n\
680-no-relax avoid changing any jumps and branches\n"));
252b5132
RH
681 fprintf (stream, _("\
682-32 create 32 bit object file\n\
683-64 create 64 bit object file\n"));
684 fprintf (stream, _("\
685 [default is %d]\n"), default_arch_size);
686 fprintf (stream, _("\
687-TSO use Total Store Ordering\n\
688-PSO use Partial Store Ordering\n\
689-RMO use Relaxed Memory Ordering\n"));
690 fprintf (stream, _("\
691 [default is %s]\n"), (default_arch_size == 64) ? "RMO" : "TSO");
692 fprintf (stream, _("\
693-KPIC generate PIC\n\
694-V print assembler version number\n\
a25fe906
ILT
695-undeclared-regs ignore application global register usage without\n\
696 appropriate .register directive (default)\n\
697-no-undeclared-regs force error on application global register usage\n\
698 without appropriate .register directive\n\
46a2d504 699--dcti-couples-detect warn when an unpredictable DCTI couple is found\n\
252b5132
RH
700-q ignored\n\
701-Qy, -Qn ignored\n\
702-s ignored\n"));
252b5132
RH
703#ifdef SPARC_BIENDIAN
704 fprintf (stream, _("\
705-EL generate code for a little endian machine\n\
706-EB generate code for a big endian machine\n\
707--little-endian-data generate code for a machine having big endian\n\
c20f4f8c 708 instructions and little endian data.\n"));
252b5132
RH
709#endif
710}
711\f
e0c6ed95 712/* Native operand size opcode translation. */
4f2a7b51 713static struct
cf9a1301 714 {
e0471c16
TS
715 const char *name;
716 const char *name32;
717 const char *name64;
cf9a1301
RH
718 } native_op_table[] =
719{
720 {"ldn", "ld", "ldx"},
721 {"ldna", "lda", "ldxa"},
722 {"stn", "st", "stx"},
723 {"stna", "sta", "stxa"},
724 {"slln", "sll", "sllx"},
725 {"srln", "srl", "srlx"},
726 {"sran", "sra", "srax"},
727 {"casn", "cas", "casx"},
728 {"casna", "casa", "casxa"},
729 {"clrn", "clr", "clrx"},
730 {NULL, NULL, NULL},
731};
732\f
10156f83 733/* sparc64 privileged and hyperprivileged registers. */
252b5132
RH
734
735struct priv_reg_entry
ab3e48dc 736{
e0471c16 737 const char *name;
ab3e48dc
KH
738 int regnum;
739};
252b5132
RH
740
741struct priv_reg_entry priv_reg_table[] =
742{
743 {"tpc", 0},
744 {"tnpc", 1},
745 {"tstate", 2},
746 {"tt", 3},
747 {"tick", 4},
748 {"tba", 5},
749 {"pstate", 6},
750 {"tl", 7},
751 {"pil", 8},
752 {"cwp", 9},
753 {"cansave", 10},
754 {"canrestore", 11},
755 {"cleanwin", 12},
756 {"otherwin", 13},
757 {"wstate", 14},
758 {"fq", 15},
10156f83 759 {"gl", 16},
38074311 760 {"pmcdper", 23},
252b5132 761 {"ver", 31},
8b8c7c9f 762 {NULL, -1}, /* End marker. */
252b5132
RH
763};
764
10156f83
DM
765struct priv_reg_entry hpriv_reg_table[] =
766{
767 {"hpstate", 0},
768 {"htstate", 1},
769 {"hintp", 3},
770 {"htba", 5},
771 {"hver", 6},
96074adc
JM
772 {"hmcdper", 23},
773 {"hmcddfr", 24},
774 {"hva_mask_nz", 27},
ec92c392
JM
775 {"hstick_offset", 28},
776 {"hstick_enable", 29},
10156f83 777 {"hstick_cmpr", 31},
8b8c7c9f 778 {NULL, -1}, /* End marker. */
10156f83
DM
779};
780
8b8c7c9f 781/* v9a or later specific ancillary state registers. */
252b5132
RH
782
783struct priv_reg_entry v9a_asr_table[] =
784{
785 {"tick_cmpr", 23},
19f7b010
JJ
786 {"sys_tick_cmpr", 25},
787 {"sys_tick", 24},
1a6b486f
DM
788 {"stick_cmpr", 25},
789 {"stick", 24},
f04d18b7
DM
790 {"softint_clear", 21},
791 {"softint_set", 20},
2b661f3d 792 {"softint", 22},
252b5132 793 {"set_softint", 20},
58004e23 794 {"pause", 27},
252b5132
RH
795 {"pic", 17},
796 {"pcr", 16},
3d68f91c 797 {"mwait", 28},
252b5132
RH
798 {"gsr", 19},
799 {"dcr", 18},
2e52845b 800 {"cfr", 26},
252b5132 801 {"clear_softint", 21},
8b8c7c9f 802 {NULL, -1}, /* End marker. */
252b5132
RH
803};
804
805static int
5a49b8ac 806cmp_reg_entry (const void *parg, const void *qarg)
252b5132
RH
807{
808 const struct priv_reg_entry *p = (const struct priv_reg_entry *) parg;
809 const struct priv_reg_entry *q = (const struct priv_reg_entry *) qarg;
810
8b8c7c9f
JM
811 if (p->name == q->name)
812 return 0;
813 else if (p->name == NULL)
814 return 1;
815 else if (q->name == NULL)
816 return -1;
817 else
818 return strcmp (q->name, p->name);
819}
820\f
821/* sparc %-pseudo-operations. */
822
823
824#define F_POP_V9 0x1 /* The pseudo-op is for v9 only. */
825#define F_POP_PCREL 0x2 /* The pseudo-op can be used in pc-relative
826 contexts. */
827#define F_POP_TLS_CALL 0x4 /* The pseudo-op marks a tls call. */
828#define F_POP_POSTFIX 0x8 /* The pseudo-op should appear after the
829 last operand of an
830 instruction. (Generally they can appear
831 anywhere an immediate operand is
832 expected. */
833struct pop_entry
834{
835 /* The name as it appears in assembler. */
836 const char *name;
837 /* The reloc this pseudo-op translates to. */
9bceab41 838 bfd_reloc_code_real_type reloc;
8b8c7c9f
JM
839 /* Flags. See F_POP_* above. */
840 int flags;
841};
842
843struct pop_entry pop_table[] =
844{
845 { "hix", BFD_RELOC_SPARC_HIX22, F_POP_V9 },
846 { "lox", BFD_RELOC_SPARC_LOX10, F_POP_V9 },
847 { "hi", BFD_RELOC_HI22, F_POP_PCREL },
848 { "lo", BFD_RELOC_LO10, F_POP_PCREL },
849 { "pc22", BFD_RELOC_SPARC_PC22, F_POP_PCREL },
850 { "pc10", BFD_RELOC_SPARC_PC10, F_POP_PCREL },
851 { "hh", BFD_RELOC_SPARC_HH22, F_POP_V9|F_POP_PCREL },
852 { "hm", BFD_RELOC_SPARC_HM10, F_POP_V9|F_POP_PCREL },
853 { "lm", BFD_RELOC_SPARC_LM22, F_POP_V9|F_POP_PCREL },
854 { "h34", BFD_RELOC_SPARC_H34, F_POP_V9 },
855 { "l34", BFD_RELOC_SPARC_L44, F_POP_V9 },
856 { "h44", BFD_RELOC_SPARC_H44, F_POP_V9 },
857 { "m44", BFD_RELOC_SPARC_M44, F_POP_V9 },
858 { "l44", BFD_RELOC_SPARC_L44, F_POP_V9 },
859 { "uhi", BFD_RELOC_SPARC_HH22, F_POP_V9 },
860 { "ulo", BFD_RELOC_SPARC_HM10, F_POP_V9 },
861 { "tgd_hi22", BFD_RELOC_SPARC_TLS_GD_HI22, 0 },
862 { "tgd_lo10", BFD_RELOC_SPARC_TLS_GD_LO10, 0 },
863 { "tldm_hi22", BFD_RELOC_SPARC_TLS_LDM_HI22, 0 },
864 { "tldm_lo10", BFD_RELOC_SPARC_TLS_LDM_LO10, 0 },
865 { "tldo_hix22", BFD_RELOC_SPARC_TLS_LDO_HIX22, 0 },
866 { "tldo_lox10", BFD_RELOC_SPARC_TLS_LDO_LOX10, 0 },
867 { "tie_hi22", BFD_RELOC_SPARC_TLS_IE_HI22, 0 },
868 { "tie_lo10", BFD_RELOC_SPARC_TLS_IE_LO10, 0 },
869 { "tle_hix22", BFD_RELOC_SPARC_TLS_LE_HIX22, 0 },
870 { "tle_lox10", BFD_RELOC_SPARC_TLS_LE_LOX10, 0 },
871 { "gdop_hix22", BFD_RELOC_SPARC_GOTDATA_OP_HIX22, 0 },
872 { "gdop_lox10", BFD_RELOC_SPARC_GOTDATA_OP_LOX10, 0 },
873 { "tgd_add", BFD_RELOC_SPARC_TLS_GD_ADD, F_POP_POSTFIX },
874 { "tgd_call", BFD_RELOC_SPARC_TLS_GD_CALL, F_POP_POSTFIX|F_POP_TLS_CALL },
875 { "tldm_add", BFD_RELOC_SPARC_TLS_LDM_ADD, F_POP_POSTFIX },
876 { "tldm_call", BFD_RELOC_SPARC_TLS_LDM_CALL, F_POP_POSTFIX|F_POP_TLS_CALL },
877 { "tldo_add", BFD_RELOC_SPARC_TLS_LDO_ADD, F_POP_POSTFIX },
878 { "tie_ldx", BFD_RELOC_SPARC_TLS_IE_LDX, F_POP_POSTFIX },
879 { "tie_ld", BFD_RELOC_SPARC_TLS_IE_LD, F_POP_POSTFIX },
880 { "tie_add", BFD_RELOC_SPARC_TLS_IE_ADD, F_POP_POSTFIX },
cf80913a 881 { "gdop", BFD_RELOC_SPARC_GOTDATA_OP, F_POP_POSTFIX }
8b8c7c9f
JM
882};
883\f
884/* Table of %-names that can appear in a sparc assembly program. This
885 table is initialized in md_begin and contains entries for each
886 privileged/hyperprivileged/alternate register and %-pseudo-op. */
887
888enum perc_entry_type
889{
890 perc_entry_none = 0,
891 perc_entry_reg,
892 perc_entry_post_pop,
893 perc_entry_imm_pop
894};
895
896struct perc_entry
897{
898 /* Entry type. */
899 enum perc_entry_type type;
900 /* Name of the %-entity. */
901 const char *name;
902 /* strlen (name). */
903 int len;
904 /* Value. Either a pop or a reg depending on type.*/
905 union
906 {
907 struct pop_entry *pop;
908 struct priv_reg_entry *reg;
909 };
910};
911
912#define NUM_PERC_ENTRIES \
913 (((sizeof (priv_reg_table) / sizeof (priv_reg_table[0])) - 1) \
914 + ((sizeof (hpriv_reg_table) / sizeof (hpriv_reg_table[0])) - 1) \
915 + ((sizeof (v9a_asr_table) / sizeof (v9a_asr_table[0])) - 1) \
cf80913a 916 + ARRAY_SIZE (pop_table) \
8b8c7c9f
JM
917 + 1)
918
919struct perc_entry perc_table[NUM_PERC_ENTRIES];
920
921static int
922cmp_perc_entry (const void *parg, const void *qarg)
923{
924 const struct perc_entry *p = (const struct perc_entry *) parg;
925 const struct perc_entry *q = (const struct perc_entry *) qarg;
926
927 if (p->name == q->name)
928 return 0;
929 else if (p->name == NULL)
930 return 1;
931 else if (q->name == NULL)
932 return -1;
933 else
934 return strcmp (q->name, p->name);
252b5132
RH
935}
936\f
937/* This function is called once, at assembler startup time. It should
e0c6ed95
AM
938 set up all the tables, etc. that the MD part of the assembler will
939 need. */
252b5132
RH
940
941void
5a49b8ac 942md_begin (void)
252b5132 943{
252b5132 944 int lose = 0;
ed9e98c2 945 unsigned int i = 0;
252b5132
RH
946
947 /* We don't get a chance to initialize anything before md_parse_option
948 is called, and it may not be called, so handle default initialization
949 now if not already done. */
950 if (! default_init_p)
951 init_default_arch ();
952
364b6d8b 953 sparc_cie_data_alignment = sparc_arch_size == 64 ? -8 : -4;
629310ab 954 op_hash = str_htab_create ();
252b5132
RH
955
956 while (i < (unsigned int) sparc_num_opcodes)
957 {
958 const char *name = sparc_opcodes[i].name;
fe0e921f
AM
959 if (str_hash_insert (op_hash, name, &sparc_opcodes[i], 0) != NULL)
960 {
961 as_bad (_("duplicate %s"), name);
962 lose = 1;
963 }
252b5132
RH
964 do
965 {
966 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
967 {
cf9a1301
RH
968 as_bad (_("Internal error: losing opcode: `%s' \"%s\"\n"),
969 sparc_opcodes[i].name, sparc_opcodes[i].args);
252b5132
RH
970 lose = 1;
971 }
972 ++i;
973 }
974 while (i < (unsigned int) sparc_num_opcodes
975 && !strcmp (sparc_opcodes[i].name, name));
976 }
977
cf9a1301
RH
978 for (i = 0; native_op_table[i].name; i++)
979 {
980 const struct sparc_opcode *insn;
e0471c16 981 const char *name = ((sparc_arch_size == 32)
3d4ae3c0
NC
982 ? native_op_table[i].name32
983 : native_op_table[i].name64);
629310ab 984 insn = (struct sparc_opcode *) str_hash_find (op_hash, name);
cf9a1301 985 if (insn == NULL)
e0c6ed95
AM
986 {
987 as_bad (_("Internal error: can't find opcode `%s' for `%s'\n"),
988 name, native_op_table[i].name);
989 lose = 1;
990 }
fe0e921f
AM
991 else if (str_hash_insert (op_hash, native_op_table[i].name, insn, 0))
992 {
993 as_bad (_("duplicate %s"), native_op_table[i].name);
994 lose = 1;
995 }
cf9a1301
RH
996 }
997
252b5132
RH
998 if (lose)
999 as_fatal (_("Broken assembler. No assembly attempted."));
1000
252b5132
RH
1001 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
1002 sizeof (priv_reg_table[0]), cmp_reg_entry);
8b8c7c9f
JM
1003 qsort (hpriv_reg_table, sizeof (hpriv_reg_table) / sizeof (hpriv_reg_table[0]),
1004 sizeof (hpriv_reg_table[0]), cmp_reg_entry);
1005 qsort (v9a_asr_table, sizeof (v9a_asr_table) / sizeof (v9a_asr_table[0]),
1006 sizeof (v9a_asr_table[0]), cmp_reg_entry);
1007
252b5132
RH
1008 /* If -bump, record the architecture level at which we start issuing
1009 warnings. The behaviour is different depending upon whether an
1010 architecture was explicitly specified. If it wasn't, we issue warnings
1011 for all upwards bumps. If it was, we don't start issuing warnings until
1012 we need to bump beyond the requested architecture or when we bump between
1013 conflicting architectures. */
1014
1015 if (warn_on_bump
1016 && architecture_requested)
1017 {
1018 /* `max_architecture' records the requested architecture.
1019 Issue warnings if we go above it. */
1020 warn_after_architecture = max_architecture;
252b5132 1021 }
75ac3a7f
JM
1022
1023 /* Find the highest architecture level that doesn't conflict with
1024 the requested one. */
1025
1026 if (warn_on_bump
1027 || !architecture_requested)
1028 {
1029 enum sparc_opcode_arch_val current_max_architecture
1030 = max_architecture;
1031
1032 for (max_architecture = SPARC_OPCODE_ARCH_MAX;
1033 max_architecture > warn_after_architecture;
1034 --max_architecture)
1035 if (! SPARC_OPCODE_CONFLICT_P (max_architecture,
1036 current_max_architecture))
1037 break;
1038 }
8b8c7c9f
JM
1039
1040 /* Prepare the tables of %-pseudo-ops. */
1041 {
1042 struct priv_reg_entry *reg_tables[]
1043 = {priv_reg_table, hpriv_reg_table, v9a_asr_table, NULL};
1044 struct priv_reg_entry **reg_table;
1045 int entry = 0;
1046
1047 /* Add registers. */
1048 for (reg_table = reg_tables; reg_table[0]; reg_table++)
1049 {
1050 struct priv_reg_entry *reg;
1051 for (reg = *reg_table; reg->name; reg++)
1052 {
1053 struct perc_entry *p = &perc_table[entry++];
1054 p->type = perc_entry_reg;
1055 p->name = reg->name;
1056 p->len = strlen (reg->name);
1057 p->reg = reg;
1058 }
1059 }
1060
1061 /* Add %-pseudo-ops. */
cf80913a
TS
1062 for (i = 0; i < ARRAY_SIZE (pop_table); i++)
1063 {
1064 struct perc_entry *p = &perc_table[entry++];
1065 p->type = (pop_table[i].flags & F_POP_POSTFIX
1066 ? perc_entry_post_pop : perc_entry_imm_pop);
1067 p->name = pop_table[i].name;
1068 p->len = strlen (pop_table[i].name);
1069 p->pop = &pop_table[i];
1070 }
8b8c7c9f 1071
33eaf5de 1072 /* Last entry is the sentinel. */
8b8c7c9f
JM
1073 perc_table[entry].type = perc_entry_none;
1074
1075 qsort (perc_table, sizeof (perc_table) / sizeof (perc_table[0]),
1076 sizeof (perc_table[0]), cmp_perc_entry);
1077
1078 }
252b5132
RH
1079}
1080
1081/* Called after all assembly has been done. */
1082
1083void
ed2917de 1084sparc_md_finish (void)
252b5132 1085{
d85815e2 1086 unsigned long mach;
c9098af4 1087#ifndef TE_SOLARIS
3d68f91c 1088 int hwcaps, hwcaps2;
daf5e10e 1089#endif
19f7b010 1090
252b5132 1091 if (sparc_arch_size == 64)
19f7b010
JJ
1092 switch (current_architecture)
1093 {
1094 case SPARC_OPCODE_ARCH_V9A: mach = bfd_mach_sparc_v9a; break;
1095 case SPARC_OPCODE_ARCH_V9B: mach = bfd_mach_sparc_v9b; break;
7a10c22f
JM
1096 case SPARC_OPCODE_ARCH_V9C: mach = bfd_mach_sparc_v9c; break;
1097 case SPARC_OPCODE_ARCH_V9D: mach = bfd_mach_sparc_v9d; break;
1098 case SPARC_OPCODE_ARCH_V9E: mach = bfd_mach_sparc_v9e; break;
1099 case SPARC_OPCODE_ARCH_V9V: mach = bfd_mach_sparc_v9v; break;
1100 case SPARC_OPCODE_ARCH_V9M: mach = bfd_mach_sparc_v9m; break;
64517994 1101 case SPARC_OPCODE_ARCH_M8: mach = bfd_mach_sparc_v9m8; break;
19f7b010
JJ
1102 default: mach = bfd_mach_sparc_v9; break;
1103 }
252b5132 1104 else
19f7b010
JJ
1105 switch (current_architecture)
1106 {
1107 case SPARC_OPCODE_ARCH_SPARCLET: mach = bfd_mach_sparc_sparclet; break;
1108 case SPARC_OPCODE_ARCH_V9: mach = bfd_mach_sparc_v8plus; break;
1109 case SPARC_OPCODE_ARCH_V9A: mach = bfd_mach_sparc_v8plusa; break;
1110 case SPARC_OPCODE_ARCH_V9B: mach = bfd_mach_sparc_v8plusb; break;
7a10c22f
JM
1111 case SPARC_OPCODE_ARCH_V9C: mach = bfd_mach_sparc_v8plusc; break;
1112 case SPARC_OPCODE_ARCH_V9D: mach = bfd_mach_sparc_v8plusd; break;
1113 case SPARC_OPCODE_ARCH_V9E: mach = bfd_mach_sparc_v8pluse; break;
1114 case SPARC_OPCODE_ARCH_V9V: mach = bfd_mach_sparc_v8plusv; break;
1115 case SPARC_OPCODE_ARCH_V9M: mach = bfd_mach_sparc_v8plusm; break;
64517994 1116 case SPARC_OPCODE_ARCH_M8: mach = bfd_mach_sparc_v8plusm8; break;
19f7b010
JJ
1117 /* The sparclite is treated like a normal sparc. Perhaps it shouldn't
1118 be but for now it is (since that's the way it's always been
1119 treated). */
d85815e2 1120 default: mach = bfd_mach_sparc; break;
19f7b010
JJ
1121 }
1122 bfd_set_arch_mach (stdoutput, bfd_arch_sparc, mach);
9e8c70f9 1123
c9098af4 1124#ifndef TE_SOLARIS
3d68f91c
JM
1125 hwcaps = hwcap_seen & U0xffffffff;
1126 hwcaps2 = hwcap_seen >> 32;
1127
1128 if (hwcaps)
1129 bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_GNU, Tag_GNU_Sparc_HWCAPS, hwcaps);
1130 if (hwcaps2)
1131 bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_GNU, Tag_GNU_Sparc_HWCAPS2, hwcaps2);
9e8c70f9 1132#endif
252b5132
RH
1133}
1134\f
1135/* Return non-zero if VAL is in the range -(MAX+1) to MAX. */
1136
5a49b8ac
AM
1137static inline int
1138in_signed_range (bfd_signed_vma val, bfd_signed_vma max)
252b5132
RH
1139{
1140 if (max <= 0)
1141 abort ();
1142 /* Sign-extend the value from the architecture word size, so that
1143 0xffffffff is always considered -1 on sparc32. */
1144 if (sparc_arch_size == 32)
1145 {
6228e279 1146 bfd_vma sign = (bfd_vma) 1 << 31;
6c1b24e4 1147 val = ((val & U0xffffffff) ^ sign) - sign;
252b5132
RH
1148 }
1149 if (val > max)
1150 return 0;
1151 if (val < ~max)
1152 return 0;
1153 return 1;
1154}
1155
1156/* Return non-zero if VAL is in the range 0 to MAX. */
1157
5a49b8ac
AM
1158static inline int
1159in_unsigned_range (bfd_vma val, bfd_vma max)
252b5132
RH
1160{
1161 if (val > max)
1162 return 0;
1163 return 1;
1164}
1165
1166/* Return non-zero if VAL is in the range -(MAX/2+1) to MAX.
1167 (e.g. -15 to +31). */
1168
5a49b8ac
AM
1169static inline int
1170in_bitfield_range (bfd_signed_vma val, bfd_signed_vma max)
252b5132
RH
1171{
1172 if (max <= 0)
1173 abort ();
1174 if (val > max)
1175 return 0;
1176 if (val < ~(max >> 1))
1177 return 0;
1178 return 1;
1179}
1180
1181static int
5a49b8ac 1182sparc_ffs (unsigned int mask)
252b5132
RH
1183{
1184 int i;
1185
1186 if (mask == 0)
1187 return -1;
1188
1189 for (i = 0; (mask & 1) == 0; ++i)
1190 mask >>= 1;
1191 return i;
1192}
1193
1194/* Implement big shift right. */
1195static bfd_vma
5a49b8ac 1196BSR (bfd_vma val, int amount)
252b5132
RH
1197{
1198 if (sizeof (bfd_vma) <= 4 && amount >= 32)
1199 as_fatal (_("Support for 64-bit arithmetic not compiled in."));
1200 return val >> amount;
1201}
1202\f
1203/* For communication between sparc_ip and get_expression. */
6eb099ae 1204static char *expr_parse_end;
252b5132 1205
252b5132 1206/* Values for `special_case'.
2b0f3761 1207 Instructions that require weird handling because they're longer than
252b5132
RH
1208 4 bytes. */
1209#define SPECIAL_CASE_NONE 0
1210#define SPECIAL_CASE_SET 1
1211#define SPECIAL_CASE_SETSW 2
1212#define SPECIAL_CASE_SETX 3
1213/* FIXME: sparc-opc.c doesn't have necessary "S" trigger to enable this. */
1214#define SPECIAL_CASE_FDIV 4
1215
1216/* Bit masks of various insns. */
1217#define NOP_INSN 0x01000000
1218#define OR_INSN 0x80100000
63fab58c 1219#define XOR_INSN 0x80180000
252b5132
RH
1220#define FMOVS_INSN 0x81A00020
1221#define SETHI_INSN 0x01000000
1222#define SLLX_INSN 0x81281000
1223#define SRA_INSN 0x81380000
1224
1225/* The last instruction to be assembled. */
1226static const struct sparc_opcode *last_insn;
1227/* The assembled opcode of `last_insn'. */
1228static unsigned long last_opcode;
1229\f
a22b281c 1230/* Handle the set and setuw synthetic instructions. */
e0c6ed95 1231
a22b281c 1232static void
5a49b8ac 1233synthetize_setuw (const struct sparc_opcode *insn)
a22b281c
RH
1234{
1235 int need_hi22_p = 0;
1236 int rd = (the_insn.opcode & RD (~0)) >> 25;
1237
1238 if (the_insn.exp.X_op == O_constant)
1239 {
1240 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
1241 {
e0c6ed95 1242 if (sizeof (offsetT) > 4
a22b281c 1243 && (the_insn.exp.X_add_number < 0
6c1b24e4 1244 || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
a22b281c
RH
1245 as_warn (_("set: number not in 0..4294967295 range"));
1246 }
1247 else
1248 {
e0c6ed95 1249 if (sizeof (offsetT) > 4
6c1b24e4
AO
1250 && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
1251 || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
a22b281c 1252 as_warn (_("set: number not in -2147483648..4294967295 range"));
e0c6ed95 1253 the_insn.exp.X_add_number = (int) the_insn.exp.X_add_number;
a22b281c
RH
1254 }
1255 }
1256
1257 /* See if operand is absolute and small; skip sethi if so. */
1258 if (the_insn.exp.X_op != O_constant
1259 || the_insn.exp.X_add_number >= (1 << 12)
1260 || the_insn.exp.X_add_number < -(1 << 12))
1261 {
1262 the_insn.opcode = (SETHI_INSN | RD (rd)
1263 | ((the_insn.exp.X_add_number >> 10)
ab3e48dc
KH
1264 & (the_insn.exp.X_op == O_constant
1265 ? 0x3fffff : 0)));
a22b281c 1266 the_insn.reloc = (the_insn.exp.X_op != O_constant
ab3e48dc 1267 ? BFD_RELOC_HI22 : BFD_RELOC_NONE);
a22b281c
RH
1268 output_insn (insn, &the_insn);
1269 need_hi22_p = 1;
1270 }
1271
1272 /* See if operand has no low-order bits; skip OR if so. */
1273 if (the_insn.exp.X_op != O_constant
1274 || (need_hi22_p && (the_insn.exp.X_add_number & 0x3FF) != 0)
1275 || ! need_hi22_p)
1276 {
1277 the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (rd) : 0)
1278 | RD (rd) | IMMED
1279 | (the_insn.exp.X_add_number
ab3e48dc
KH
1280 & (the_insn.exp.X_op != O_constant
1281 ? 0 : need_hi22_p ? 0x3ff : 0x1fff)));
a22b281c 1282 the_insn.reloc = (the_insn.exp.X_op != O_constant
ab3e48dc 1283 ? BFD_RELOC_LO10 : BFD_RELOC_NONE);
a22b281c
RH
1284 output_insn (insn, &the_insn);
1285 }
1286}
e0c6ed95 1287
a22b281c 1288/* Handle the setsw synthetic instruction. */
e0c6ed95 1289
a22b281c 1290static void
5a49b8ac 1291synthetize_setsw (const struct sparc_opcode *insn)
a22b281c
RH
1292{
1293 int low32, rd, opc;
1294
1295 rd = (the_insn.opcode & RD (~0)) >> 25;
1296
1297 if (the_insn.exp.X_op != O_constant)
1298 {
1299 synthetize_setuw (insn);
1300
1301 /* Need to sign extend it. */
1302 the_insn.opcode = (SRA_INSN | RS1 (rd) | RD (rd));
1303 the_insn.reloc = BFD_RELOC_NONE;
1304 output_insn (insn, &the_insn);
1305 return;
1306 }
1307
e0c6ed95 1308 if (sizeof (offsetT) > 4
6c1b24e4
AO
1309 && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
1310 || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
a22b281c
RH
1311 as_warn (_("setsw: number not in -2147483648..4294967295 range"));
1312
e0c6ed95
AM
1313 low32 = the_insn.exp.X_add_number;
1314
a22b281c
RH
1315 if (low32 >= 0)
1316 {
1317 synthetize_setuw (insn);
1318 return;
1319 }
1320
1321 opc = OR_INSN;
e0c6ed95 1322
a22b281c
RH
1323 the_insn.reloc = BFD_RELOC_NONE;
1324 /* See if operand is absolute and small; skip sethi if so. */
1325 if (low32 < -(1 << 12))
1326 {
1327 the_insn.opcode = (SETHI_INSN | RD (rd)
1328 | (((~the_insn.exp.X_add_number) >> 10) & 0x3fffff));
1329 output_insn (insn, &the_insn);
1330 low32 = 0x1c00 | (low32 & 0x3ff);
1331 opc = RS1 (rd) | XOR_INSN;
1332 }
1333
1334 the_insn.opcode = (opc | RD (rd) | IMMED
1335 | (low32 & 0x1fff));
1336 output_insn (insn, &the_insn);
1337}
1338
0d495746 1339/* Handle the setx synthetic instruction. */
e0c6ed95 1340
a22b281c 1341static void
5a49b8ac 1342synthetize_setx (const struct sparc_opcode *insn)
a22b281c
RH
1343{
1344 int upper32, lower32;
1345 int tmpreg = (the_insn.opcode & RS1 (~0)) >> 14;
1346 int dstreg = (the_insn.opcode & RD (~0)) >> 25;
1347 int upper_dstreg;
1348 int need_hh22_p = 0, need_hm10_p = 0, need_hi22_p = 0, need_lo10_p = 0;
1349 int need_xor10_p = 0;
e0c6ed95 1350
6c1b24e4 1351#define SIGNEXT32(x) ((((x) & U0xffffffff) ^ U0x80000000) - U0x80000000)
a22b281c
RH
1352 lower32 = SIGNEXT32 (the_insn.exp.X_add_number);
1353 upper32 = SIGNEXT32 (BSR (the_insn.exp.X_add_number, 32));
1354#undef SIGNEXT32
1355
1356 upper_dstreg = tmpreg;
1357 /* The tmp reg should not be the dst reg. */
1358 if (tmpreg == dstreg)
1359 as_warn (_("setx: temporary register same as destination register"));
1360
1361 /* ??? Obviously there are other optimizations we can do
1362 (e.g. sethi+shift for 0x1f0000000) and perhaps we shouldn't be
1363 doing some of these. Later. If you do change things, try to
1364 change all of this to be table driven as well. */
1365 /* What to output depends on the number if it's constant.
1366 Compute that first, then output what we've decided upon. */
1367 if (the_insn.exp.X_op != O_constant)
1368 {
1369 if (sparc_arch_size == 32)
1370 {
1371 /* When arch size is 32, we want setx to be equivalent
1372 to setuw for anything but constants. */
1373 the_insn.exp.X_add_number &= 0xffffffff;
1374 synthetize_setuw (insn);
1375 return;
1376 }
1377 need_hh22_p = need_hm10_p = need_hi22_p = need_lo10_p = 1;
ab3e48dc
KH
1378 lower32 = 0;
1379 upper32 = 0;
a22b281c
RH
1380 }
1381 else
1382 {
1383 /* Reset X_add_number, we've extracted it as upper32/lower32.
1384 Otherwise fixup_segment will complain about not being able to
1385 write an 8 byte number in a 4 byte field. */
1386 the_insn.exp.X_add_number = 0;
e0c6ed95 1387
a22b281c
RH
1388 /* Only need hh22 if `or' insn can't handle constant. */
1389 if (upper32 < -(1 << 12) || upper32 >= (1 << 12))
1390 need_hh22_p = 1;
e0c6ed95 1391
a22b281c
RH
1392 /* Does bottom part (after sethi) have bits? */
1393 if ((need_hh22_p && (upper32 & 0x3ff) != 0)
1394 /* No hh22, but does upper32 still have bits we can't set
1395 from lower32? */
1396 || (! need_hh22_p && upper32 != 0 && upper32 != -1))
1397 need_hm10_p = 1;
e0c6ed95 1398
a22b281c
RH
1399 /* If the lower half is all zero, we build the upper half directly
1400 into the dst reg. */
1401 if (lower32 != 0
1402 /* Need lower half if number is zero or 0xffffffff00000000. */
1403 || (! need_hh22_p && ! need_hm10_p))
1404 {
1405 /* No need for sethi if `or' insn can handle constant. */
1406 if (lower32 < -(1 << 12) || lower32 >= (1 << 12)
1407 /* Note that we can't use a negative constant in the `or'
1408 insn unless the upper 32 bits are all ones. */
1409 || (lower32 < 0 && upper32 != -1)
1410 || (lower32 >= 0 && upper32 == -1))
1411 need_hi22_p = 1;
e0c6ed95 1412
a22b281c
RH
1413 if (need_hi22_p && upper32 == -1)
1414 need_xor10_p = 1;
1415
1416 /* Does bottom part (after sethi) have bits? */
1417 else if ((need_hi22_p && (lower32 & 0x3ff) != 0)
1418 /* No sethi. */
1419 || (! need_hi22_p && (lower32 & 0x1fff) != 0)
1420 /* Need `or' if we didn't set anything else. */
1421 || (! need_hi22_p && ! need_hh22_p && ! need_hm10_p))
1422 need_lo10_p = 1;
1423 }
1424 else
1425 /* Output directly to dst reg if lower 32 bits are all zero. */
1426 upper_dstreg = dstreg;
1427 }
e0c6ed95 1428
a22b281c
RH
1429 if (!upper_dstreg && dstreg)
1430 as_warn (_("setx: illegal temporary register g0"));
1431
1432 if (need_hh22_p)
1433 {
1434 the_insn.opcode = (SETHI_INSN | RD (upper_dstreg)
1435 | ((upper32 >> 10) & 0x3fffff));
1436 the_insn.reloc = (the_insn.exp.X_op != O_constant
1437 ? BFD_RELOC_SPARC_HH22 : BFD_RELOC_NONE);
1438 output_insn (insn, &the_insn);
1439 }
e0c6ed95 1440
a22b281c
RH
1441 if (need_hi22_p)
1442 {
1443 the_insn.opcode = (SETHI_INSN | RD (dstreg)
1444 | (((need_xor10_p ? ~lower32 : lower32)
ab3e48dc 1445 >> 10) & 0x3fffff));
a22b281c
RH
1446 the_insn.reloc = (the_insn.exp.X_op != O_constant
1447 ? BFD_RELOC_SPARC_LM22 : BFD_RELOC_NONE);
1448 output_insn (insn, &the_insn);
1449 }
1450
1451 if (need_hm10_p)
1452 {
1453 the_insn.opcode = (OR_INSN
1454 | (need_hh22_p ? RS1 (upper_dstreg) : 0)
1455 | RD (upper_dstreg)
1456 | IMMED
1457 | (upper32 & (need_hh22_p ? 0x3ff : 0x1fff)));
1458 the_insn.reloc = (the_insn.exp.X_op != O_constant
1459 ? BFD_RELOC_SPARC_HM10 : BFD_RELOC_NONE);
1460 output_insn (insn, &the_insn);
1461 }
e0c6ed95 1462
a22b281c
RH
1463 if (need_lo10_p)
1464 {
1465 /* FIXME: One nice optimization to do here is to OR the low part
1466 with the highpart if hi22 isn't needed and the low part is
1467 positive. */
1468 the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (dstreg) : 0)
1469 | RD (dstreg)
1470 | IMMED
1471 | (lower32 & (need_hi22_p ? 0x3ff : 0x1fff)));
1472 the_insn.reloc = (the_insn.exp.X_op != O_constant
1473 ? BFD_RELOC_LO10 : BFD_RELOC_NONE);
1474 output_insn (insn, &the_insn);
1475 }
e0c6ed95 1476
a22b281c
RH
1477 /* If we needed to build the upper part, shift it into place. */
1478 if (need_hh22_p || need_hm10_p)
1479 {
1480 the_insn.opcode = (SLLX_INSN | RS1 (upper_dstreg) | RD (upper_dstreg)
1481 | IMMED | 32);
1482 the_insn.reloc = BFD_RELOC_NONE;
1483 output_insn (insn, &the_insn);
1484 }
e0c6ed95 1485
a22b281c
RH
1486 /* To get -1 in upper32, we do sethi %hi(~x), r; xor r, -0x400 | x, r. */
1487 if (need_xor10_p)
1488 {
1489 the_insn.opcode = (XOR_INSN | RS1 (dstreg) | RD (dstreg) | IMMED
1490 | 0x1c00 | (lower32 & 0x3ff));
1491 the_insn.reloc = BFD_RELOC_NONE;
1492 output_insn (insn, &the_insn);
1493 }
1494
1495 /* If we needed to build both upper and lower parts, OR them together. */
1496 else if ((need_hh22_p || need_hm10_p) && (need_hi22_p || need_lo10_p))
1497 {
1498 the_insn.opcode = (OR_INSN | RS1 (dstreg) | RS2 (upper_dstreg)
1499 | RD (dstreg));
1500 the_insn.reloc = BFD_RELOC_NONE;
1501 output_insn (insn, &the_insn);
1502 }
1503}
1504\f
252b5132
RH
1505/* Main entry point to assemble one instruction. */
1506
1507void
5a49b8ac 1508md_assemble (char *str)
252b5132
RH
1509{
1510 const struct sparc_opcode *insn;
a22b281c 1511 int special_case;
252b5132
RH
1512
1513 know (str);
a22b281c 1514 special_case = sparc_ip (str, &insn);
b0825cc2
DM
1515 if (insn == NULL)
1516 return;
252b5132 1517
46a2d504
JM
1518 /* Certain instructions may not appear on delay slots. Check for
1519 these situations. */
b0825cc2 1520 if (last_insn != NULL
46a2d504
JM
1521 && (last_insn->flags & F_DELAYED) != 0)
1522 {
1523 /* Before SPARC V9 the effect of having a delayed branch
1524 instruction in the delay slot of a conditional delayed branch
1525 was undefined.
1526
1527 In SPARC V9 DCTI couples are well defined.
1528
1529 However, starting with the UltraSPARC Architecture 2005, DCTI
1530 couples (of all kind) are deprecated and should not be used,
1531 as they may be slow or behave differently to what the
1532 programmer expects. */
1533 if (dcti_couples_detect
1534 && (insn->flags & F_DELAYED) != 0
1535 && ((max_architecture < SPARC_OPCODE_ARCH_V9
1536 && (last_insn->flags & F_CONDBR) != 0)
1537 || max_architecture >= SPARC_OPCODE_ARCH_V9C))
1538 as_warn (_("unpredictable DCTI couple"));
1539
1540
1541 /* We warn about attempts to put a floating point branch in a
1542 delay slot, unless the delay slot has been annulled. */
1543 if ((insn->flags & F_FBR) != 0
1544 /* ??? This test isn't completely accurate. We assume anything with
1545 F_{UNBR,CONDBR,FBR} set is annullable. */
1546 && ((last_insn->flags & (F_UNBR | F_CONDBR | F_FBR)) == 0
1547 || (last_opcode & ANNUL) == 0))
1548 as_warn (_("FP branch in delay slot"));
1549 }
252b5132 1550
618a8fdb
DC
1551 /* SPARC before v9 does not allow a floating point compare
1552 directly before a floating point branch. Insert a nop
1553 instruction if needed, with a warning. */
252b5132 1554 if (max_architecture < SPARC_OPCODE_ARCH_V9
252b5132
RH
1555 && last_insn != NULL
1556 && (insn->flags & F_FBR) != 0
618a8fdb
DC
1557 && (last_insn->flags & F_FLOAT) != 0
1558 && (last_insn->match & OP3 (0x35)) == OP3 (0x35))
252b5132
RH
1559 {
1560 struct sparc_it nop_insn;
1561
1562 nop_insn.opcode = NOP_INSN;
1563 nop_insn.reloc = BFD_RELOC_NONE;
1564 output_insn (insn, &nop_insn);
618a8fdb 1565 as_warn (_("FP branch preceded by FP compare; NOP inserted"));
252b5132
RH
1566 }
1567
a22b281c
RH
1568 switch (special_case)
1569 {
1570 case SPECIAL_CASE_NONE:
e0c6ed95 1571 /* Normal insn. */
a22b281c
RH
1572 output_insn (insn, &the_insn);
1573 break;
252b5132 1574
a22b281c
RH
1575 case SPECIAL_CASE_SETSW:
1576 synthetize_setsw (insn);
1577 break;
e0c6ed95 1578
a22b281c
RH
1579 case SPECIAL_CASE_SET:
1580 synthetize_setuw (insn);
1581 break;
252b5132 1582
a22b281c
RH
1583 case SPECIAL_CASE_SETX:
1584 synthetize_setx (insn);
1585 break;
e0c6ed95 1586
a22b281c
RH
1587 case SPECIAL_CASE_FDIV:
1588 {
1589 int rd = (the_insn.opcode >> 25) & 0x1f;
e0c6ed95 1590
a22b281c 1591 output_insn (insn, &the_insn);
e0c6ed95 1592
a22b281c
RH
1593 /* According to information leaked from Sun, the "fdiv" instructions
1594 on early SPARC machines would produce incorrect results sometimes.
1595 The workaround is to add an fmovs of the destination register to
1596 itself just after the instruction. This was true on machines
e0c6ed95 1597 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
9c2799c2 1598 gas_assert (the_insn.reloc == BFD_RELOC_NONE);
a22b281c
RH
1599 the_insn.opcode = FMOVS_INSN | rd | RD (rd);
1600 output_insn (insn, &the_insn);
1601 return;
1602 }
e0c6ed95 1603
a22b281c
RH
1604 default:
1605 as_fatal (_("failed special case insn sanity check"));
252b5132
RH
1606 }
1607}
1608
4bafe00e 1609static const char *
0e3c1eeb 1610get_hwcap_name (uint64_t mask)
4bafe00e 1611{
ec668d69 1612 if (mask & HWCAP_MUL32)
4bafe00e 1613 return "mul32";
ec668d69 1614 if (mask & HWCAP_DIV32)
4bafe00e 1615 return "div32";
ec668d69 1616 if (mask & HWCAP_FSMULD)
4bafe00e 1617 return "fsmuld";
ec668d69 1618 if (mask & HWCAP_V8PLUS)
4bafe00e 1619 return "v8plus";
ec668d69 1620 if (mask & HWCAP_POPC)
4bafe00e 1621 return "popc";
ec668d69 1622 if (mask & HWCAP_VIS)
4bafe00e 1623 return "vis";
ec668d69 1624 if (mask & HWCAP_VIS2)
4bafe00e 1625 return "vis2";
ec668d69 1626 if (mask & HWCAP_ASI_BLK_INIT)
4bafe00e 1627 return "ASIBlkInit";
ec668d69 1628 if (mask & HWCAP_FMAF)
4bafe00e 1629 return "fmaf";
ec668d69 1630 if (mask & HWCAP_VIS3)
4bafe00e 1631 return "vis3";
ec668d69 1632 if (mask & HWCAP_HPC)
4bafe00e 1633 return "hpc";
ec668d69 1634 if (mask & HWCAP_RANDOM)
4bafe00e 1635 return "random";
ec668d69 1636 if (mask & HWCAP_TRANS)
4bafe00e 1637 return "trans";
ec668d69 1638 if (mask & HWCAP_FJFMAU)
4bafe00e 1639 return "fjfmau";
ec668d69 1640 if (mask & HWCAP_IMA)
4bafe00e 1641 return "ima";
ec668d69 1642 if (mask & HWCAP_ASI_CACHE_SPARING)
4bafe00e 1643 return "cspare";
ec668d69
DM
1644 if (mask & HWCAP_AES)
1645 return "aes";
1646 if (mask & HWCAP_DES)
1647 return "des";
1648 if (mask & HWCAP_KASUMI)
1649 return "kasumi";
1650 if (mask & HWCAP_CAMELLIA)
1651 return "camellia";
1652 if (mask & HWCAP_MD5)
1653 return "md5";
1654 if (mask & HWCAP_SHA1)
1655 return "sha1";
1656 if (mask & HWCAP_SHA256)
1657 return "sha256";
1658 if (mask & HWCAP_SHA512)
1659 return "sha512";
1660 if (mask & HWCAP_MPMUL)
1661 return "mpmul";
1662 if (mask & HWCAP_MONT)
1663 return "mont";
1664 if (mask & HWCAP_PAUSE)
1665 return "pause";
1666 if (mask & HWCAP_CBCOND)
1667 return "cbcond";
1668 if (mask & HWCAP_CRC32C)
1669 return "crc32c";
3d68f91c
JM
1670
1671 mask = mask >> 32;
1672 if (mask & HWCAP2_FJATHPLUS)
1673 return "fjathplus";
1674 if (mask & HWCAP2_VIS3B)
1675 return "vis3b";
1676 if (mask & HWCAP2_ADP)
1677 return "adp";
1678 if (mask & HWCAP2_SPARC5)
1679 return "sparc5";
1680 if (mask & HWCAP2_MWAIT)
1681 return "mwait";
1682 if (mask & HWCAP2_XMPMUL)
1683 return "xmpmul";
1684 if (mask & HWCAP2_XMONT)
1685 return "xmont";
1686 if (mask & HWCAP2_NSEC)
1687 return "nsec";
64517994
JM
1688 if (mask & HWCAP2_SPARC6)
1689 return "sparc6";
1690 if (mask & HWCAP2_ONADDSUB)
1691 return "onaddsub";
1692 if (mask & HWCAP2_ONMUL)
1693 return "onmul";
1694 if (mask & HWCAP2_ONDIV)
1695 return "ondiv";
1696 if (mask & HWCAP2_DICTUNP)
1697 return "dictunp";
1698 if (mask & HWCAP2_FPCMPSHL)
1699 return "fpcmpshl";
1700 if (mask & HWCAP2_RLE)
1701 return "rle";
1702 if (mask & HWCAP2_SHA3)
1703 return "sha3";
3d68f91c 1704
4bafe00e
DM
1705 return "UNKNOWN";
1706}
1707
252b5132
RH
1708/* Subroutine of md_assemble to do the actual parsing. */
1709
a22b281c 1710static int
5a49b8ac 1711sparc_ip (char *str, const struct sparc_opcode **pinsn)
252b5132 1712{
e0471c16 1713 const char *error_message = "";
252b5132
RH
1714 char *s;
1715 const char *args;
1716 char c;
1717 const struct sparc_opcode *insn;
1718 char *argsStart;
1719 unsigned long opcode;
1720 unsigned int mask = 0;
1721 int match = 0;
1722 int comma = 0;
1723 int v9_arg_p;
a22b281c 1724 int special_case = SPECIAL_CASE_NONE;
1e9d41d4 1725 const sparc_asi *sasi = NULL;
252b5132
RH
1726
1727 s = str;
3882b010 1728 if (ISLOWER (*s))
252b5132
RH
1729 {
1730 do
1731 ++s;
6cda1326 1732 while (ISLOWER (*s) || ISDIGIT (*s) || *s == '_');
252b5132
RH
1733 }
1734
1735 switch (*s)
1736 {
1737 case '\0':
1738 break;
1739
1740 case ',':
1741 comma = 1;
e0c6ed95 1742 /* Fall through. */
252b5132
RH
1743
1744 case ' ':
1745 *s++ = '\0';
1746 break;
1747
1748 default:
b0825cc2
DM
1749 as_bad (_("Unknown opcode: `%s'"), str);
1750 *pinsn = NULL;
1751 return special_case;
252b5132 1752 }
629310ab 1753 insn = (struct sparc_opcode *) str_hash_find (op_hash, str);
252b5132
RH
1754 *pinsn = insn;
1755 if (insn == NULL)
1756 {
1757 as_bad (_("Unknown opcode: `%s'"), str);
a22b281c 1758 return special_case;
252b5132
RH
1759 }
1760 if (comma)
1761 {
1762 *--s = ',';
1763 }
1764
1765 argsStart = s;
1766 for (;;)
1767 {
1768 opcode = insn->match;
1769 memset (&the_insn, '\0', sizeof (the_insn));
1770 the_insn.reloc = BFD_RELOC_NONE;
1771 v9_arg_p = 0;
1772
e0c6ed95
AM
1773 /* Build the opcode, checking as we go to make sure that the
1774 operands match. */
252b5132
RH
1775 for (args = insn->args;; ++args)
1776 {
1777 switch (*args)
1778 {
1779 case 'K':
1780 {
1781 int kmask = 0;
1782
1783 /* Parse a series of masks. */
1784 if (*s == '#')
1785 {
1786 while (*s == '#')
1787 {
91d6fa6a 1788 int jmask;
252b5132
RH
1789
1790 if (! parse_keyword_arg (sparc_encode_membar, &s,
91d6fa6a 1791 &jmask))
252b5132
RH
1792 {
1793 error_message = _(": invalid membar mask name");
1794 goto error;
1795 }
91d6fa6a 1796 kmask |= jmask;
47926f60
KH
1797 while (*s == ' ')
1798 ++s;
252b5132
RH
1799 if (*s == '|' || *s == '+')
1800 ++s;
47926f60
KH
1801 while (*s == ' ')
1802 ++s;
252b5132
RH
1803 }
1804 }
1805 else
1806 {
1807 if (! parse_const_expr_arg (&s, &kmask))
1808 {
1809 error_message = _(": invalid membar mask expression");
1810 goto error;
1811 }
1812 if (kmask < 0 || kmask > 127)
1813 {
1814 error_message = _(": invalid membar mask number");
1815 goto error;
1816 }
1817 }
1818
1819 opcode |= MEMBAR (kmask);
1820 continue;
1821 }
1822
19f7b010
JJ
1823 case '3':
1824 {
1825 int smask = 0;
1826
1827 if (! parse_const_expr_arg (&s, &smask))
1828 {
1829 error_message = _(": invalid siam mode expression");
1830 goto error;
1831 }
1832 if (smask < 0 || smask > 7)
1833 {
1834 error_message = _(": invalid siam mode number");
1835 goto error;
1836 }
1837 opcode |= smask;
1838 continue;
1839 }
1840
252b5132
RH
1841 case '*':
1842 {
1843 int fcn = 0;
1844
1845 /* Parse a prefetch function. */
1846 if (*s == '#')
1847 {
1848 if (! parse_keyword_arg (sparc_encode_prefetch, &s, &fcn))
1849 {
1850 error_message = _(": invalid prefetch function name");
1851 goto error;
1852 }
1853 }
1854 else
1855 {
1856 if (! parse_const_expr_arg (&s, &fcn))
1857 {
1858 error_message = _(": invalid prefetch function expression");
1859 goto error;
1860 }
1861 if (fcn < 0 || fcn > 31)
1862 {
1863 error_message = _(": invalid prefetch function number");
1864 goto error;
1865 }
1866 }
1867 opcode |= RD (fcn);
1868 continue;
1869 }
1870
1871 case '!':
1872 case '?':
1873 /* Parse a sparc64 privileged register. */
1874 if (*s == '%')
1875 {
8b8c7c9f 1876 struct priv_reg_entry *p;
e0c6ed95 1877 unsigned int len = 9999999; /* Init to make gcc happy. */
252b5132
RH
1878
1879 s += 1;
8b8c7c9f
JM
1880 for (p = priv_reg_table; p->name; p++)
1881 if (p->name[0] == s[0])
1882 {
1883 len = strlen (p->name);
1884 if (strncmp (p->name, s, len) == 0)
1885 break;
1886 }
1887
1888 if (!p->name)
252b5132
RH
1889 {
1890 error_message = _(": unrecognizable privileged register");
1891 goto error;
1892 }
96074adc
JM
1893
1894 if (((opcode >> (*args == '?' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
1895 {
1896 error_message = _(": unrecognizable privileged register");
1897 goto error;
1898 }
1899
252b5132
RH
1900 s += len;
1901 continue;
1902 }
1903 else
1904 {
1905 error_message = _(": unrecognizable privileged register");
1906 goto error;
1907 }
1908
10156f83
DM
1909 case '$':
1910 case '%':
1911 /* Parse a sparc64 hyperprivileged register. */
1912 if (*s == '%')
1913 {
8b8c7c9f 1914 struct priv_reg_entry *p;
10156f83
DM
1915 unsigned int len = 9999999; /* Init to make gcc happy. */
1916
1917 s += 1;
8b8c7c9f
JM
1918 for (p = hpriv_reg_table; p->name; p++)
1919 if (p->name[0] == s[0])
1920 {
1921 len = strlen (p->name);
1922 if (strncmp (p->name, s, len) == 0)
1923 break;
1924 }
1925
1926 if (!p->name)
10156f83
DM
1927 {
1928 error_message = _(": unrecognizable hyperprivileged register");
1929 goto error;
1930 }
96074adc
JM
1931
1932 if (((opcode >> (*args == '$' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
1933 {
1934 error_message = _(": unrecognizable hyperprivileged register");
1935 goto error;
1936 }
1937
1938 s += len;
10156f83
DM
1939 continue;
1940 }
1941 else
1942 {
1943 error_message = _(": unrecognizable hyperprivileged register");
1944 goto error;
1945 }
1946
252b5132
RH
1947 case '_':
1948 case '/':
7a10c22f 1949 /* Parse a v9a or later ancillary state register. */
252b5132
RH
1950 if (*s == '%')
1951 {
8b8c7c9f 1952 struct priv_reg_entry *p;
e0c6ed95 1953 unsigned int len = 9999999; /* Init to make gcc happy. */
252b5132
RH
1954
1955 s += 1;
8b8c7c9f
JM
1956 for (p = v9a_asr_table; p->name; p++)
1957 if (p->name[0] == s[0])
1958 {
1959 len = strlen (p->name);
1960 if (strncmp (p->name, s, len) == 0)
1961 break;
1962 }
1963
1964 if (!p->name)
252b5132 1965 {
7a10c22f 1966 error_message = _(": unrecognizable ancillary state register");
252b5132
RH
1967 goto error;
1968 }
96074adc
JM
1969
1970 if (((opcode >> (*args == '/' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
1971 {
1972 error_message = _(": unrecognizable ancillary state register");
1973 goto error;
1974 }
1975
252b5132
RH
1976 s += len;
1977 continue;
1978 }
1979 else
1980 {
7a10c22f 1981 error_message = _(": unrecognizable ancillary state register");
252b5132
RH
1982 goto error;
1983 }
1984
1985 case 'M':
1986 case 'm':
d34049e8 1987 if (startswith (s, "%asr"))
252b5132
RH
1988 {
1989 s += 4;
1990
3882b010 1991 if (ISDIGIT (*s))
252b5132
RH
1992 {
1993 long num = 0;
1994
3882b010 1995 while (ISDIGIT (*s))
252b5132
RH
1996 {
1997 num = num * 10 + *s - '0';
1998 ++s;
1999 }
2000
f65c3d1b
JM
2001 /* We used to check here for the asr number to
2002 be between 16 and 31 in V9 and later, as
2003 mandated by the section C.1.1 "Register
2004 Names" in the SPARC spec. However, we
2005 decided to remove this restriction as a) it
2006 introduces problems when new V9 asr registers
2007 are introduced, b) the Solaris assembler
2008 doesn't implement this restriction and c) the
2009 restriction will go away in future revisions
2010 of the Oracle SPARC Architecture. */
2011
2012 if (num < 0 || 31 < num)
2013 {
2014 error_message = _(": asr number must be between 0 and 31");
2015 goto error;
2016 }
252b5132
RH
2017
2018 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
2019 continue;
2020 }
2021 else
2022 {
2023 error_message = _(": expecting %asrN");
2024 goto error;
2025 }
e0c6ed95 2026 } /* if %asr */
252b5132
RH
2027 break;
2028
2029 case 'I':
2030 the_insn.reloc = BFD_RELOC_SPARC_11;
2031 goto immediate;
2032
2033 case 'j':
2034 the_insn.reloc = BFD_RELOC_SPARC_10;
2035 goto immediate;
2036
6cda1326
DM
2037 case ')':
2038 if (*s == ' ')
2039 s++;
2040 if ((s[0] == '0' && s[1] == 'x' && ISXDIGIT (s[2]))
2041 || ISDIGIT (*s))
2042 {
2043 long num = 0;
2044
2045 if (s[0] == '0' && s[1] == 'x')
2046 {
2047 s += 2;
2048 while (ISXDIGIT (*s))
2049 {
2050 num <<= 4;
2051 num |= hex_value (*s);
2052 ++s;
2053 }
2054 }
2055 else
2056 {
2057 while (ISDIGIT (*s))
2058 {
2059 num = num * 10 + *s - '0';
2060 ++s;
2061 }
2062 }
2063 if (num < 0 || num > 31)
2064 {
2065 error_message = _(": crypto immediate must be between 0 and 31");
2066 goto error;
2067 }
2068
2069 opcode |= RS3 (num);
2070 continue;
2071 }
2072 else
2073 {
2074 error_message = _(": expecting crypto immediate");
2075 goto error;
2076 }
2077
252b5132
RH
2078 case 'X':
2079 /* V8 systems don't understand BFD_RELOC_SPARC_5. */
2080 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2081 the_insn.reloc = BFD_RELOC_SPARC_5;
2082 else
2083 the_insn.reloc = BFD_RELOC_SPARC13;
2084 /* These fields are unsigned, but for upward compatibility,
2085 allow negative values as well. */
2086 goto immediate;
2087
2088 case 'Y':
2089 /* V8 systems don't understand BFD_RELOC_SPARC_6. */
2090 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2091 the_insn.reloc = BFD_RELOC_SPARC_6;
2092 else
2093 the_insn.reloc = BFD_RELOC_SPARC13;
2094 /* These fields are unsigned, but for upward compatibility,
2095 allow negative values as well. */
2096 goto immediate;
2097
2098 case 'k':
2099 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
2100 the_insn.pcrel = 1;
2101 goto immediate;
2102
2615994e
DM
2103 case '=':
2104 the_insn.reloc = /* RELOC_WDISP2_8 */ BFD_RELOC_SPARC_WDISP10;
2105 the_insn.pcrel = 1;
2106 goto immediate;
2107
252b5132
RH
2108 case 'G':
2109 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
2110 the_insn.pcrel = 1;
2111 goto immediate;
2112
2113 case 'N':
2114 if (*s == 'p' && s[1] == 'n')
2115 {
2116 s += 2;
2117 continue;
2118 }
2119 break;
2120
2121 case 'T':
2122 if (*s == 'p' && s[1] == 't')
2123 {
2124 s += 2;
2125 continue;
2126 }
2127 break;
2128
2129 case 'z':
2130 if (*s == ' ')
2131 {
2132 ++s;
2133 }
d34049e8
ML
2134 if ((startswith (s, "%icc"))
2135 || (sparc_arch_size == 32 && startswith (s, "%ncc")))
252b5132
RH
2136 {
2137 s += 4;
2138 continue;
2139 }
2140 break;
2141
2142 case 'Z':
2143 if (*s == ' ')
2144 {
2145 ++s;
2146 }
d34049e8
ML
2147 if ((startswith (s, "%xcc"))
2148 || (sparc_arch_size == 64 && startswith (s, "%ncc")))
252b5132
RH
2149 {
2150 s += 4;
2151 continue;
2152 }
2153 break;
2154
2155 case '6':
2156 if (*s == ' ')
2157 {
2158 ++s;
2159 }
d34049e8 2160 if (startswith (s, "%fcc0"))
252b5132
RH
2161 {
2162 s += 5;
2163 continue;
2164 }
2165 break;
2166
2167 case '7':
2168 if (*s == ' ')
2169 {
2170 ++s;
2171 }
d34049e8 2172 if (startswith (s, "%fcc1"))
252b5132
RH
2173 {
2174 s += 5;
2175 continue;
2176 }
2177 break;
2178
2179 case '8':
2180 if (*s == ' ')
2181 {
2182 ++s;
2183 }
d34049e8 2184 if (startswith (s, "%fcc2"))
252b5132
RH
2185 {
2186 s += 5;
2187 continue;
2188 }
2189 break;
2190
2191 case '9':
2192 if (*s == ' ')
2193 {
2194 ++s;
2195 }
d34049e8 2196 if (startswith (s, "%fcc3"))
252b5132
RH
2197 {
2198 s += 5;
2199 continue;
2200 }
2201 break;
2202
2203 case 'P':
d34049e8 2204 if (startswith (s, "%pc"))
252b5132
RH
2205 {
2206 s += 3;
2207 continue;
2208 }
2209 break;
2210
2211 case 'W':
d34049e8 2212 if (startswith (s, "%tick"))
252b5132
RH
2213 {
2214 s += 5;
2215 continue;
2216 }
2217 break;
2218
e0c6ed95 2219 case '\0': /* End of args. */
b9734f35 2220 if (s[0] == ',' && s[1] == '%')
252b5132 2221 {
b9734f35
JJ
2222 char *s1;
2223 int npar = 0;
8b8c7c9f 2224 const struct perc_entry *p;
b9734f35 2225
8b8c7c9f
JM
2226 for (p = perc_table; p->type != perc_entry_none; p++)
2227 if ((p->type == perc_entry_post_pop || p->type == perc_entry_reg)
2228 && strncmp (s + 2, p->name, p->len) == 0)
2229 break;
2230 if (p->type == perc_entry_none || p->type == perc_entry_reg)
2231 break;
b9734f35 2232
8b8c7c9f 2233 if (s[p->len + 2] != '(')
b9734f35 2234 {
8b8c7c9f 2235 as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
b9734f35
JJ
2236 return special_case;
2237 }
2238
8b8c7c9f
JM
2239 if (! (p->pop->flags & F_POP_TLS_CALL)
2240 && the_insn.reloc != BFD_RELOC_NONE)
b9734f35
JJ
2241 {
2242 as_bad (_("Illegal operands: %%%s cannot be used together with other relocs in the insn ()"),
8b8c7c9f 2243 p->name);
b9734f35
JJ
2244 return special_case;
2245 }
2246
8b8c7c9f 2247 if ((p->pop->flags & F_POP_TLS_CALL)
b9734f35
JJ
2248 && (the_insn.reloc != BFD_RELOC_32_PCREL_S2
2249 || the_insn.exp.X_add_number != 0
2250 || the_insn.exp.X_add_symbol
2251 != symbol_find_or_make ("__tls_get_addr")))
2252 {
2253 as_bad (_("Illegal operands: %%%s can be only used with call __tls_get_addr"),
8b8c7c9f 2254 p->name);
b9734f35
JJ
2255 return special_case;
2256 }
2257
8b8c7c9f 2258 the_insn.reloc = p->pop->reloc;
b9734f35 2259 memset (&the_insn.exp, 0, sizeof (the_insn.exp));
8b8c7c9f 2260 s += p->len + 3;
b9734f35
JJ
2261
2262 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
2263 if (*s1 == '(')
2264 npar++;
2265 else if (*s1 == ')')
2266 {
2267 if (!npar)
2268 break;
2269 npar--;
2270 }
2271
2272 if (*s1 != ')')
2273 {
8b8c7c9f 2274 as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
b9734f35
JJ
2275 return special_case;
2276 }
2277
2278 *s1 = '\0';
2279 (void) get_expression (s);
2280 *s1 = ')';
2281 s = s1 + 1;
252b5132 2282 }
b9734f35
JJ
2283 if (*s == '\0')
2284 match = 1;
252b5132
RH
2285 break;
2286
2287 case '+':
2288 if (*s == '+')
2289 {
2290 ++s;
2291 continue;
2292 }
2293 if (*s == '-')
2294 {
2295 continue;
2296 }
2297 break;
2298
e0c6ed95 2299 case '[': /* These must match exactly. */
252b5132
RH
2300 case ']':
2301 case ',':
2302 case ' ':
2303 if (*s++ == *args)
2304 continue;
2305 break;
2306
e0c6ed95 2307 case '#': /* Must be at least one digit. */
3882b010 2308 if (ISDIGIT (*s++))
252b5132 2309 {
3882b010 2310 while (ISDIGIT (*s))
252b5132
RH
2311 {
2312 ++s;
2313 }
2314 continue;
2315 }
2316 break;
2317
e0c6ed95 2318 case 'C': /* Coprocessor state register. */
d34049e8 2319 if (startswith (s, "%csr"))
252b5132
RH
2320 {
2321 s += 4;
2322 continue;
2323 }
2324 break;
2325
e0c6ed95 2326 case 'b': /* Next operand is a coprocessor register. */
252b5132
RH
2327 case 'c':
2328 case 'D':
3882b010 2329 if (*s++ == '%' && *s++ == 'c' && ISDIGIT (*s))
252b5132
RH
2330 {
2331 mask = *s++;
3882b010 2332 if (ISDIGIT (*s))
252b5132
RH
2333 {
2334 mask = 10 * (mask - '0') + (*s++ - '0');
2335 if (mask >= 32)
2336 {
2337 break;
2338 }
2339 }
2340 else
2341 {
2342 mask -= '0';
2343 }
2344 switch (*args)
2345 {
2346
2347 case 'b':
2348 opcode |= mask << 14;
2349 continue;
2350
2351 case 'c':
2352 opcode |= mask;
2353 continue;
2354
2355 case 'D':
2356 opcode |= mask << 25;
2357 continue;
2358 }
2359 }
2360 break;
2361
2362 case 'r': /* next operand must be a register */
2363 case 'O':
2364 case '1':
2365 case '2':
2366 case 'd':
2367 if (*s++ == '%')
2368 {
2369 switch (c = *s++)
2370 {
2371
2372 case 'f': /* frame pointer */
2373 if (*s++ == 'p')
2374 {
2375 mask = 0x1e;
2376 break;
2377 }
2378 goto error;
2379
2380 case 'g': /* global register */
a22b281c
RH
2381 c = *s++;
2382 if (isoctal (c))
252b5132
RH
2383 {
2384 mask = c - '0';
2385 break;
2386 }
2387 goto error;
2388
2389 case 'i': /* in register */
a22b281c
RH
2390 c = *s++;
2391 if (isoctal (c))
252b5132
RH
2392 {
2393 mask = c - '0' + 24;
2394 break;
2395 }
2396 goto error;
2397
2398 case 'l': /* local register */
a22b281c
RH
2399 c = *s++;
2400 if (isoctal (c))
252b5132
RH
2401 {
2402 mask = (c - '0' + 16);
2403 break;
2404 }
2405 goto error;
2406
2407 case 'o': /* out register */
a22b281c
RH
2408 c = *s++;
2409 if (isoctal (c))
252b5132
RH
2410 {
2411 mask = (c - '0' + 8);
2412 break;
2413 }
2414 goto error;
2415
2416 case 's': /* stack pointer */
2417 if (*s++ == 'p')
2418 {
2419 mask = 0xe;
2420 break;
2421 }
2422 goto error;
2423
2424 case 'r': /* any register */
3882b010 2425 if (!ISDIGIT ((c = *s++)))
252b5132
RH
2426 {
2427 goto error;
2428 }
2429 /* FALLTHROUGH */
2430 case '0':
2431 case '1':
2432 case '2':
2433 case '3':
2434 case '4':
2435 case '5':
2436 case '6':
2437 case '7':
2438 case '8':
2439 case '9':
3882b010 2440 if (ISDIGIT (*s))
252b5132
RH
2441 {
2442 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
2443 {
2444 goto error;
2445 }
2446 }
2447 else
2448 {
2449 c -= '0';
2450 }
2451 mask = c;
2452 break;
2453
2454 default:
2455 goto error;
2456 }
2457
6d8809aa 2458 if ((mask & ~1) == 2 && sparc_arch_size == 64
e0c6ed95 2459 && no_undeclared_regs && ! globals[mask])
79bd78be 2460 as_bad (_("detected global register use not covered by .register pseudo-op"));
6d8809aa 2461
252b5132
RH
2462 /* Got the register, now figure out where
2463 it goes in the opcode. */
2464 switch (*args)
2465 {
2466 case '1':
2467 opcode |= mask << 14;
2468 continue;
2469
2470 case '2':
2471 opcode |= mask;
2472 continue;
2473
2474 case 'd':
2475 opcode |= mask << 25;
2476 continue;
2477
2478 case 'r':
2479 opcode |= (mask << 25) | (mask << 14);
2480 continue;
2481
2482 case 'O':
2483 opcode |= (mask << 25) | (mask << 0);
2484 continue;
2485 }
2486 }
2487 break;
2488
2489 case 'e': /* next operand is a floating point register */
2490 case 'v':
2491 case 'V':
64517994 2492 case ';':
252b5132
RH
2493
2494 case 'f':
2495 case 'B':
2496 case 'R':
64517994
JM
2497 case ':':
2498 case '\'':
252b5132 2499
ea783ef3
DM
2500 case '4':
2501 case '5':
2502
252b5132
RH
2503 case 'g':
2504 case 'H':
2505 case 'J':
3d68f91c 2506 case '}':
64517994 2507 case '^':
252b5132
RH
2508 {
2509 char format;
2510
2511 if (*s++ == '%'
ec892a07
JM
2512 && ((format = *s) == 'f'
2513 || format == 'd'
2514 || format == 'q')
3882b010 2515 && ISDIGIT (*++s))
252b5132 2516 {
3882b010 2517 for (mask = 0; ISDIGIT (*s); ++s)
252b5132
RH
2518 {
2519 mask = 10 * mask + (*s - '0');
2520 } /* read the number */
2521
2522 if ((*args == 'v'
2523 || *args == 'B'
ea783ef3 2524 || *args == '5'
ec892a07 2525 || *args == 'H'
64517994 2526 || *args == '\''
ec892a07 2527 || format == 'd')
252b5132
RH
2528 && (mask & 1))
2529 {
ec892a07 2530 /* register must be even numbered */
252b5132 2531 break;
ec892a07 2532 }
252b5132
RH
2533
2534 if ((*args == 'V'
2535 || *args == 'R'
ec892a07
JM
2536 || *args == 'J'
2537 || format == 'q')
252b5132
RH
2538 && (mask & 3))
2539 {
ec892a07 2540 /* register must be multiple of 4 */
252b5132 2541 break;
ec892a07 2542 }
252b5132 2543
64517994
JM
2544 if ((*args == ':'
2545 || *args == ';'
2546 || *args == '^')
2547 && (mask & 7))
2548 {
2549 /* register must be multiple of 8 */
2550 break;
2551 }
2552
2553 if (*args == '\'' && mask < 48)
2554 {
2555 /* register must be higher or equal than %f48 */
2556 break;
2557 }
2558
252b5132
RH
2559 if (mask >= 64)
2560 {
2561 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2562 error_message = _(": There are only 64 f registers; [0-63]");
2563 else
2564 error_message = _(": There are only 32 f registers; [0-31]");
2565 goto error;
2566 } /* on error */
2567 else if (mask >= 32)
2568 {
2569 if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
2570 {
26664553
JJ
2571 if (*args == 'e' || *args == 'f' || *args == 'g')
2572 {
2573 error_message
2574 = _(": There are only 32 single precision f registers; [0-31]");
2575 goto error;
2576 }
252b5132
RH
2577 v9_arg_p = 1;
2578 mask -= 31; /* wrap high bit */
2579 }
2580 else
2581 {
2582 error_message = _(": There are only 32 f registers; [0-31]");
2583 goto error;
2584 }
2585 }
2586 }
2587 else
2588 {
2589 break;
ab3e48dc 2590 } /* if not an 'f' register. */
252b5132 2591
3d68f91c
JM
2592 if (*args == '}' && mask != RS2 (opcode))
2593 {
2594 error_message
2595 = _(": Instruction requires frs2 and frsd must be the same register");
2596 goto error;
2597 }
2598
252b5132
RH
2599 switch (*args)
2600 {
2601 case 'v':
2602 case 'V':
2603 case 'e':
64517994 2604 case ';':
252b5132
RH
2605 opcode |= RS1 (mask);
2606 continue;
2607
252b5132
RH
2608 case 'f':
2609 case 'B':
2610 case 'R':
64517994 2611 case ':':
252b5132
RH
2612 opcode |= RS2 (mask);
2613 continue;
2614
64517994
JM
2615 case '\'':
2616 opcode |= RS2 (mask & 0xe);
2617 continue;
2618
ea783ef3
DM
2619 case '4':
2620 case '5':
2621 opcode |= RS3 (mask);
2622 continue;
2623
252b5132
RH
2624 case 'g':
2625 case 'H':
2626 case 'J':
3d68f91c 2627 case '}':
64517994 2628 case '^':
252b5132
RH
2629 opcode |= RD (mask);
2630 continue;
ab3e48dc 2631 } /* Pack it in. */
252b5132
RH
2632
2633 know (0);
2634 break;
ab3e48dc 2635 } /* float arg */
252b5132
RH
2636
2637 case 'F':
d34049e8 2638 if (startswith (s, "%fsr"))
252b5132
RH
2639 {
2640 s += 4;
2641 continue;
2642 }
2643 break;
2644
ea783ef3 2645 case '(':
d34049e8 2646 if (startswith (s, "%efsr"))
ea783ef3
DM
2647 {
2648 s += 5;
2649 continue;
2650 }
2651 break;
2652
ab3e48dc
KH
2653 case '0': /* 64 bit immediate (set, setsw, setx insn) */
2654 the_insn.reloc = BFD_RELOC_NONE; /* reloc handled elsewhere */
252b5132
RH
2655 goto immediate;
2656
ab3e48dc 2657 case 'l': /* 22 bit PC relative immediate */
252b5132
RH
2658 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
2659 the_insn.pcrel = 1;
2660 goto immediate;
2661
ab3e48dc 2662 case 'L': /* 30 bit immediate */
252b5132
RH
2663 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
2664 the_insn.pcrel = 1;
2665 goto immediate;
2666
63fab58c 2667 case 'h':
ab3e48dc 2668 case 'n': /* 22 bit immediate */
252b5132
RH
2669 the_insn.reloc = BFD_RELOC_SPARC22;
2670 goto immediate;
2671
ab3e48dc 2672 case 'i': /* 13 bit immediate */
252b5132
RH
2673 the_insn.reloc = BFD_RELOC_SPARC13;
2674
2675 /* fallthrough */
2676
2677 immediate:
2678 if (*s == ' ')
2679 s++;
2680
cf9a1301
RH
2681 {
2682 char *s1;
e0471c16 2683 const char *op_arg = NULL;
30eb9c17 2684 static expressionS op_exp;
cf9a1301
RH
2685 bfd_reloc_code_real_type old_reloc = the_insn.reloc;
2686
2687 /* Check for %hi, etc. */
2688 if (*s == '%')
2689 {
8b8c7c9f
JM
2690 const struct perc_entry *p;
2691
2692 for (p = perc_table; p->type != perc_entry_none; p++)
2693 if ((p->type == perc_entry_imm_pop || p->type == perc_entry_reg)
2694 && strncmp (s + 1, p->name, p->len) == 0)
2695 break;
2696 if (p->type == perc_entry_none || p->type == perc_entry_reg)
2697 break;
2698
2699 if (s[p->len + 1] != '(')
cf9a1301 2700 {
8b8c7c9f 2701 as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
a22b281c 2702 return special_case;
cf9a1301 2703 }
252b5132 2704
8b8c7c9f
JM
2705 op_arg = p->name;
2706 the_insn.reloc = p->pop->reloc;
2707 s += p->len + 2;
2708 v9_arg_p = p->pop->flags & F_POP_V9;
cf9a1301
RH
2709 }
2710
2711 /* Note that if the get_expression() fails, we will still
2712 have created U entries in the symbol table for the
2713 'symbols' in the input string. Try not to create U
2714 symbols for registers, etc. */
252b5132 2715
252b5132
RH
2716 /* This stuff checks to see if the expression ends in
2717 +%reg. If it does, it removes the register from
2718 the expression, and re-sets 's' to point to the
2719 right place. */
2720
cf9a1301
RH
2721 if (op_arg)
2722 {
2723 int npar = 0;
2724
2725 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
2726 if (*s1 == '(')
2727 npar++;
2728 else if (*s1 == ')')
2729 {
2730 if (!npar)
2731 break;
2732 npar--;
2733 }
2734
2735 if (*s1 != ')')
2736 {
2737 as_bad (_("Illegal operands: %%%s requires arguments in ()"), op_arg);
a22b281c 2738 return special_case;
cf9a1301 2739 }
e0c6ed95 2740
cf9a1301
RH
2741 *s1 = '\0';
2742 (void) get_expression (s);
2743 *s1 = ')';
6eb099ae 2744 if (expr_parse_end != s1)
e140100a
NC
2745 {
2746 as_bad (_("Expression inside %%%s could not be parsed"), op_arg);
2747 return special_case;
2748 }
cf9a1301
RH
2749 s = s1 + 1;
2750 if (*s == ',' || *s == ']' || !*s)
2751 continue;
2752 if (*s != '+' && *s != '-')
2753 {
2754 as_bad (_("Illegal operands: Can't do arithmetics other than + and - involving %%%s()"), op_arg);
a22b281c 2755 return special_case;
cf9a1301
RH
2756 }
2757 *s1 = '0';
2758 s = s1;
2759 op_exp = the_insn.exp;
e0c6ed95 2760 memset (&the_insn.exp, 0, sizeof (the_insn.exp));
cf9a1301 2761 }
252b5132 2762
e0c6ed95
AM
2763 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
2764 ;
252b5132 2765
3882b010 2766 if (s1 != s && ISDIGIT (s1[-1]))
252b5132
RH
2767 {
2768 if (s1[-2] == '%' && s1[-3] == '+')
cf9a1301 2769 s1 -= 3;
f124dd4f 2770 else if (strchr ("golir0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
cf9a1301 2771 s1 -= 4;
f124dd4f
DM
2772 else if (s1[-3] == 'r' && s1[-4] == '%' && s1[-5] == '+')
2773 s1 -= 5;
cf9a1301
RH
2774 else
2775 s1 = NULL;
2776 if (s1)
252b5132 2777 {
252b5132 2778 *s1 = '\0';
1eb7027c
RH
2779 if (op_arg && s1 == s + 1)
2780 the_insn.exp.X_op = O_absent;
2781 else
2782 (void) get_expression (s);
252b5132 2783 *s1 = '+';
cf9a1301
RH
2784 if (op_arg)
2785 *s = ')';
252b5132 2786 s = s1;
252b5132 2787 }
cf9a1301
RH
2788 }
2789 else
2790 s1 = NULL;
2791
2792 if (!s1)
2793 {
2794 (void) get_expression (s);
2795 if (op_arg)
2796 *s = ')';
6eb099ae 2797 s = expr_parse_end;
cf9a1301
RH
2798 }
2799
2800 if (op_arg)
2801 {
2802 the_insn.exp2 = the_insn.exp;
2803 the_insn.exp = op_exp;
2804 if (the_insn.exp2.X_op == O_absent)
2805 the_insn.exp2.X_op = O_illegal;
2806 else if (the_insn.exp.X_op == O_absent)
252b5132 2807 {
cf9a1301
RH
2808 the_insn.exp = the_insn.exp2;
2809 the_insn.exp2.X_op = O_illegal;
2810 }
2811 else if (the_insn.exp.X_op == O_constant)
2812 {
2813 valueT val = the_insn.exp.X_add_number;
2814 switch (the_insn.reloc)
2815 {
1b50c718
ILT
2816 default:
2817 break;
2818
cf9a1301
RH
2819 case BFD_RELOC_SPARC_HH22:
2820 val = BSR (val, 32);
e0c6ed95 2821 /* Fall through. */
cf9a1301
RH
2822
2823 case BFD_RELOC_SPARC_LM22:
2824 case BFD_RELOC_HI22:
2825 val = (val >> 10) & 0x3fffff;
2826 break;
2827
2828 case BFD_RELOC_SPARC_HM10:
2829 val = BSR (val, 32);
e0c6ed95 2830 /* Fall through. */
cf9a1301
RH
2831
2832 case BFD_RELOC_LO10:
2833 val &= 0x3ff;
2834 break;
2835
2615994e
DM
2836 case BFD_RELOC_SPARC_H34:
2837 val >>= 12;
2838 val &= 0x3fffff;
2839 break;
2840
cf9a1301
RH
2841 case BFD_RELOC_SPARC_H44:
2842 val >>= 22;
2843 val &= 0x3fffff;
2844 break;
2845
2846 case BFD_RELOC_SPARC_M44:
2847 val >>= 12;
2848 val &= 0x3ff;
2849 break;
2850
2851 case BFD_RELOC_SPARC_L44:
2852 val &= 0xfff;
2853 break;
2854
2855 case BFD_RELOC_SPARC_HIX22:
ab3e48dc 2856 val = ~val;
cf9a1301
RH
2857 val = (val >> 10) & 0x3fffff;
2858 break;
2859
2860 case BFD_RELOC_SPARC_LOX10:
2861 val = (val & 0x3ff) | 0x1c00;
2862 break;
2863 }
2864 the_insn.exp = the_insn.exp2;
2865 the_insn.exp.X_add_number += val;
2866 the_insn.exp2.X_op = O_illegal;
2867 the_insn.reloc = old_reloc;
2868 }
2869 else if (the_insn.exp2.X_op != O_constant)
2870 {
2871 as_bad (_("Illegal operands: Can't add non-constant expression to %%%s()"), op_arg);
a22b281c 2872 return special_case;
cf9a1301
RH
2873 }
2874 else
2875 {
dabe3bbc 2876 if (old_reloc != BFD_RELOC_SPARC13
cf9a1301
RH
2877 || the_insn.reloc != BFD_RELOC_LO10
2878 || sparc_arch_size != 64
2879 || sparc_pic_code)
2880 {
2881 as_bad (_("Illegal operands: Can't do arithmetics involving %%%s() of a relocatable symbol"), op_arg);
a22b281c 2882 return special_case;
cf9a1301
RH
2883 }
2884 the_insn.reloc = BFD_RELOC_SPARC_OLO10;
252b5132
RH
2885 }
2886 }
2887 }
252b5132
RH
2888 /* Check for constants that don't require emitting a reloc. */
2889 if (the_insn.exp.X_op == O_constant
2890 && the_insn.exp.X_add_symbol == 0
2891 && the_insn.exp.X_op_symbol == 0)
2892 {
2893 /* For pc-relative call instructions, we reject
2894 constants to get better code. */
2895 if (the_insn.pcrel
2896 && the_insn.reloc == BFD_RELOC_32_PCREL_S2
2897 && in_signed_range (the_insn.exp.X_add_number, 0x3fff))
2898 {
2899 error_message = _(": PC-relative operand can't be a constant");
2900 goto error;
2901 }
2902
b9734f35
JJ
2903 if (the_insn.reloc >= BFD_RELOC_SPARC_TLS_GD_HI22
2904 && the_insn.reloc <= BFD_RELOC_SPARC_TLS_TPOFF64)
2905 {
2906 error_message = _(": TLS operand can't be a constant");
2907 goto error;
2908 }
2909
55cf6793 2910 /* Constants that won't fit are checked in md_apply_fix
252b5132
RH
2911 and bfd_install_relocation.
2912 ??? It would be preferable to install the constants
2913 into the insn here and save having to create a fixS
2914 for each one. There already exists code to handle
55cf6793 2915 all the various cases (e.g. in md_apply_fix and
252b5132
RH
2916 bfd_install_relocation) so duplicating all that code
2917 here isn't right. */
698544e1
DM
2918
2919 /* This is a special case to handle cbcond instructions
2920 properly, which can need two relocations. The first
2921 one is for the 5-bit immediate field and the latter
2922 is going to be for the WDISP10 branch part. We
2923 handle the R_SPARC_5 immediate directly here so that
2924 we don't need to add support for multiple relocations
2925 in one instruction just yet. */
65d1cff9
JM
2926 if (the_insn.reloc == BFD_RELOC_SPARC_5
2927 && ((insn->match & OP(0x3)) == 0))
698544e1
DM
2928 {
2929 valueT val = the_insn.exp.X_add_number;
2930
65d1cff9 2931 the_insn.reloc = BFD_RELOC_NONE;
698544e1
DM
2932 if (! in_bitfield_range (val, 0x1f))
2933 {
2934 error_message = _(": Immediate value in cbcond is out of range.");
2935 goto error;
2936 }
2937 opcode |= val & 0x1f;
698544e1 2938 }
252b5132
RH
2939 }
2940
2941 continue;
2942
2943 case 'a':
2944 if (*s++ == 'a')
2945 {
2946 opcode |= ANNUL;
2947 continue;
2948 }
2949 break;
2950
2951 case 'A':
2952 {
2953 int asi = 0;
2954
2955 /* Parse an asi. */
2956 if (*s == '#')
2957 {
1e9d41d4 2958 if (! parse_sparc_asi (&s, &sasi))
252b5132
RH
2959 {
2960 error_message = _(": invalid ASI name");
2961 goto error;
2962 }
1e9d41d4 2963 asi = sasi->value;
252b5132
RH
2964 }
2965 else
2966 {
2967 if (! parse_const_expr_arg (&s, &asi))
2968 {
2969 error_message = _(": invalid ASI expression");
2970 goto error;
2971 }
2972 if (asi < 0 || asi > 255)
2973 {
2974 error_message = _(": invalid ASI number");
2975 goto error;
2976 }
2977 }
2978 opcode |= ASI (asi);
2979 continue;
e0c6ed95 2980 } /* Alternate space. */
252b5132
RH
2981
2982 case 'p':
d34049e8 2983 if (startswith (s, "%psr"))
252b5132
RH
2984 {
2985 s += 4;
2986 continue;
2987 }
2988 break;
2989
e0c6ed95 2990 case 'q': /* Floating point queue. */
d34049e8 2991 if (startswith (s, "%fq"))
252b5132
RH
2992 {
2993 s += 3;
2994 continue;
2995 }
2996 break;
2997
e0c6ed95 2998 case 'Q': /* Coprocessor queue. */
d34049e8 2999 if (startswith (s, "%cq"))
252b5132
RH
3000 {
3001 s += 3;
3002 continue;
3003 }
3004 break;
3005
3006 case 'S':
3007 if (strcmp (str, "set") == 0
3008 || strcmp (str, "setuw") == 0)
3009 {
3010 special_case = SPECIAL_CASE_SET;
3011 continue;
3012 }
3013 else if (strcmp (str, "setsw") == 0)
3014 {
3015 special_case = SPECIAL_CASE_SETSW;
3016 continue;
3017 }
3018 else if (strcmp (str, "setx") == 0)
3019 {
3020 special_case = SPECIAL_CASE_SETX;
3021 continue;
3022 }
d34049e8 3023 else if (startswith (str, "fdiv"))
252b5132
RH
3024 {
3025 special_case = SPECIAL_CASE_FDIV;
3026 continue;
3027 }
3028 break;
3029
3030 case 'o':
d34049e8 3031 if (!startswith (s, "%asi"))
252b5132
RH
3032 break;
3033 s += 4;
3034 continue;
3035
3036 case 's':
d34049e8 3037 if (!startswith (s, "%fprs"))
252b5132
RH
3038 break;
3039 s += 5;
3040 continue;
3041
3d68f91c 3042 case '{':
d34049e8 3043 if (!startswith (s, "%mcdper"))
3d68f91c
JM
3044 break;
3045 s += 7;
3046 continue;
3047
64517994 3048 case '&':
d34049e8 3049 if (!startswith (s, "%entropy"))
64517994
JM
3050 break;
3051 s += 8;
3052 continue;
3053
252b5132 3054 case 'E':
d34049e8 3055 if (!startswith (s, "%ccr"))
252b5132
RH
3056 break;
3057 s += 4;
3058 continue;
3059
3060 case 't':
d34049e8 3061 if (!startswith (s, "%tbr"))
252b5132
RH
3062 break;
3063 s += 4;
3064 continue;
3065
3066 case 'w':
d34049e8 3067 if (!startswith (s, "%wim"))
252b5132
RH
3068 break;
3069 s += 4;
3070 continue;
3071
64517994
JM
3072 case '|':
3073 {
3074 int imm2 = 0;
3075
3076 /* Parse a 2-bit immediate. */
3077 if (! parse_const_expr_arg (&s, &imm2))
3078 {
3079 error_message = _(": non-immdiate imm2 operand");
3080 goto error;
3081 }
3082 if ((imm2 & ~0x3) != 0)
3083 {
3084 error_message = _(": imm2 immediate operand out of range (0-3)");
3085 goto error;
3086 }
3087
3088 opcode |= ((imm2 & 0x2) << 3) | (imm2 & 0x1);
3089 continue;
3090 }
3091
252b5132
RH
3092 case 'x':
3093 {
3094 char *push = input_line_pointer;
3095 expressionS e;
3096
3097 input_line_pointer = s;
3098 expression (&e);
3099 if (e.X_op == O_constant)
3100 {
3101 int n = e.X_add_number;
3102 if (n != e.X_add_number || (n & ~0x1ff) != 0)
3103 as_bad (_("OPF immediate operand out of range (0-0x1ff)"));
3104 else
3105 opcode |= e.X_add_number << 5;
3106 }
3107 else
3108 as_bad (_("non-immediate OPF operand, ignored"));
3109 s = input_line_pointer;
3110 input_line_pointer = push;
3111 continue;
3112 }
3113
3114 case 'y':
d34049e8 3115 if (!startswith (s, "%y"))
252b5132
RH
3116 break;
3117 s += 2;
3118 continue;
3119
3120 case 'u':
3121 case 'U':
3122 {
3123 /* Parse a sparclet cpreg. */
3124 int cpreg;
3125 if (! parse_keyword_arg (sparc_encode_sparclet_cpreg, &s, &cpreg))
3126 {
3127 error_message = _(": invalid cpreg name");
3128 goto error;
3129 }
3130 opcode |= (*args == 'U' ? RS1 (cpreg) : RD (cpreg));
3131 continue;
3132 }
3133
3134 default:
3135 as_fatal (_("failed sanity check."));
e0c6ed95 3136 } /* switch on arg code. */
252b5132
RH
3137
3138 /* Break out of for() loop. */
3139 break;
e0c6ed95 3140 } /* For each arg that we expect. */
252b5132
RH
3141
3142 error:
3143 if (match == 0)
3144 {
e0c6ed95 3145 /* Args don't match. */
252b5132
RH
3146 if (&insn[1] - sparc_opcodes < sparc_num_opcodes
3147 && (insn->name == insn[1].name
3148 || !strcmp (insn->name, insn[1].name)))
3149 {
3150 ++insn;
3151 s = argsStart;
3152 continue;
3153 }
3154 else
3155 {
3156 as_bad (_("Illegal operands%s"), error_message);
a22b281c 3157 return special_case;
252b5132
RH
3158 }
3159 }
3160 else
3161 {
e0c6ed95 3162 /* We have a match. Now see if the architecture is OK. */
1e9d41d4
SL
3163 /* String to use in case of architecture warning. */
3164 const char *msg_str = str;
252b5132 3165 int needed_arch_mask = insn->architecture;
1e9d41d4
SL
3166
3167 /* Include the ASI architecture needed as well */
3168 if (sasi && needed_arch_mask > sasi->architecture)
3169 {
3170 needed_arch_mask = sasi->architecture;
3171 msg_str = sasi->name;
3172 }
3173
0e3c1eeb 3174 uint64_t hwcaps = ((uint64_t) insn->hwcaps2 << 32) | insn->hwcaps;
252b5132 3175
c9098af4 3176#ifndef TE_SOLARIS
9e8c70f9
DM
3177 if (hwcaps)
3178 hwcap_seen |= hwcaps;
3179#endif
252b5132
RH
3180 if (v9_arg_p)
3181 {
19f7b010
JJ
3182 needed_arch_mask &=
3183 ~(SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9) - 1);
3184 if (! needed_arch_mask)
3185 needed_arch_mask =
3186 SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9);
252b5132
RH
3187 }
3188
e0c6ed95
AM
3189 if (needed_arch_mask
3190 & SPARC_OPCODE_SUPPORTED (current_architecture))
3191 /* OK. */
3192 ;
252b5132 3193 /* Can we bump up the architecture? */
e0c6ed95
AM
3194 else if (needed_arch_mask
3195 & SPARC_OPCODE_SUPPORTED (max_architecture))
252b5132
RH
3196 {
3197 enum sparc_opcode_arch_val needed_architecture =
3198 sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture)
3199 & needed_arch_mask);
3200
9c2799c2 3201 gas_assert (needed_architecture <= SPARC_OPCODE_ARCH_MAX);
252b5132
RH
3202 if (warn_on_bump
3203 && needed_architecture > warn_after_architecture)
3204 {
3205 as_warn (_("architecture bumped from \"%s\" to \"%s\" on \"%s\""),
3206 sparc_opcode_archs[current_architecture].name,
3207 sparc_opcode_archs[needed_architecture].name,
1e9d41d4 3208 msg_str);
252b5132
RH
3209 warn_after_architecture = needed_architecture;
3210 }
3211 current_architecture = needed_architecture;
6884417a 3212 hwcap_allowed
0e3c1eeb
AM
3213 = (hwcap_allowed
3214 | hwcaps
3215 | ((uint64_t) sparc_opcode_archs[current_architecture].hwcaps2 << 32)
3216 | sparc_opcode_archs[current_architecture].hwcaps);
252b5132
RH
3217 }
3218 /* Conflict. */
3219 /* ??? This seems to be a bit fragile. What if the next entry in
3220 the opcode table is the one we want and it is supported?
3221 It is possible to arrange the table today so that this can't
3222 happen but what about tomorrow? */
3223 else
3224 {
e0c6ed95 3225 int arch, printed_one_p = 0;
252b5132
RH
3226 char *p;
3227 char required_archs[SPARC_OPCODE_ARCH_MAX * 16];
3228
3229 /* Create a list of the architectures that support the insn. */
e0c6ed95 3230 needed_arch_mask &= ~SPARC_OPCODE_SUPPORTED (max_architecture);
252b5132
RH
3231 p = required_archs;
3232 arch = sparc_ffs (needed_arch_mask);
3233 while ((1 << arch) <= needed_arch_mask)
3234 {
3235 if ((1 << arch) & needed_arch_mask)
3236 {
3237 if (printed_one_p)
3238 *p++ = '|';
3239 strcpy (p, sparc_opcode_archs[arch].name);
3240 p += strlen (p);
3241 printed_one_p = 1;
3242 }
3243 ++arch;
3244 }
3245
fc7514d6 3246 as_bad (_("Architecture mismatch on \"%s %s\"."), str, argsStart);
33eaf5de 3247 as_tsktsk (_("(Requires %s; requested architecture is %s.)"),
252b5132
RH
3248 required_archs,
3249 sparc_opcode_archs[max_architecture].name);
a22b281c 3250 return special_case;
252b5132 3251 }
4bafe00e 3252
9aff4b7a 3253 /* Make sure the hwcaps used by the instruction are
4bafe00e
DM
3254 currently enabled. */
3255 if (hwcaps & ~hwcap_allowed)
3256 {
3257 const char *hwcap_name = get_hwcap_name(hwcaps & ~hwcap_allowed);
3258
3259 as_bad (_("Hardware capability \"%s\" not enabled for \"%s\"."),
3260 hwcap_name, str);
3261 return special_case;
3262 }
e0c6ed95 3263 } /* If no match. */
252b5132
RH
3264
3265 break;
e0c6ed95 3266 } /* Forever looking for a match. */
252b5132
RH
3267
3268 the_insn.opcode = opcode;
a22b281c 3269 return special_case;
252b5132
RH
3270}
3271
1e9d41d4
SL
3272static char *
3273skip_over_keyword (char *q)
3274{
3275 for (q = q + (*q == '#' || *q == '%');
3276 ISALNUM (*q) || *q == '_';
3277 ++q)
3278 continue;
3279 return q;
3280}
3281
3282static int
3283parse_sparc_asi (char **input_pointer_p, const sparc_asi **value_p)
3284{
3285 const sparc_asi *value;
3286 char c, *p, *q;
3287
3288 p = *input_pointer_p;
3289 q = skip_over_keyword(p);
3290 c = *q;
3291 *q = 0;
3292 value = sparc_encode_asi (p);
3293 *q = c;
3294 if (value == NULL)
3295 return 0;
3296 *value_p = value;
3297 *input_pointer_p = q;
3298 return 1;
3299}
3300
252b5132
RH
3301/* Parse an argument that can be expressed as a keyword.
3302 (eg: #StoreStore or %ccfr).
3303 The result is a boolean indicating success.
3304 If successful, INPUT_POINTER is updated. */
3305
3306static int
5a49b8ac
AM
3307parse_keyword_arg (int (*lookup_fn) (const char *),
3308 char **input_pointerP,
3309 int *valueP)
252b5132
RH
3310{
3311 int value;
3312 char c, *p, *q;
3313
3314 p = *input_pointerP;
1e9d41d4 3315 q = skip_over_keyword(p);
252b5132
RH
3316 c = *q;
3317 *q = 0;
3318 value = (*lookup_fn) (p);
3319 *q = c;
3320 if (value == -1)
3321 return 0;
3322 *valueP = value;
3323 *input_pointerP = q;
3324 return 1;
3325}
3326
3327/* Parse an argument that is a constant expression.
3328 The result is a boolean indicating success. */
3329
3330static int
5a49b8ac 3331parse_const_expr_arg (char **input_pointerP, int *valueP)
252b5132
RH
3332{
3333 char *save = input_line_pointer;
3334 expressionS exp;
3335
3336 input_line_pointer = *input_pointerP;
3337 /* The next expression may be something other than a constant
3338 (say if we're not processing the right variant of the insn).
3339 Don't call expression unless we're sure it will succeed as it will
3340 signal an error (which we want to defer until later). */
3341 /* FIXME: It might be better to define md_operand and have it recognize
3342 things like %asi, etc. but continuing that route through to the end
3343 is a lot of work. */
3344 if (*input_line_pointer == '%')
3345 {
3346 input_line_pointer = save;
3347 return 0;
3348 }
3349 expression (&exp);
3350 *input_pointerP = input_line_pointer;
3351 input_line_pointer = save;
3352 if (exp.X_op != O_constant)
3353 return 0;
3354 *valueP = exp.X_add_number;
3355 return 1;
3356}
3357
3358/* Subroutine of sparc_ip to parse an expression. */
3359
3360static int
5a49b8ac 3361get_expression (char *str)
252b5132
RH
3362{
3363 char *save_in;
3364 segT seg;
3365
3366 save_in = input_line_pointer;
3367 input_line_pointer = str;
3368 seg = expression (&the_insn.exp);
3369 if (seg != absolute_section
3370 && seg != text_section
3371 && seg != data_section
3372 && seg != bss_section
3373 && seg != undefined_section)
3374 {
3375 the_insn.error = _("bad segment");
6eb099ae 3376 expr_parse_end = input_line_pointer;
252b5132
RH
3377 input_line_pointer = save_in;
3378 return 1;
3379 }
6eb099ae 3380 expr_parse_end = input_line_pointer;
252b5132
RH
3381 input_line_pointer = save_in;
3382 return 0;
3383}
3384
3385/* Subroutine of md_assemble to output one insn. */
3386
3387static void
91d6fa6a 3388output_insn (const struct sparc_opcode *insn, struct sparc_it *theinsn)
252b5132
RH
3389{
3390 char *toP = frag_more (4);
3391
e0c6ed95 3392 /* Put out the opcode. */
252b5132 3393 if (INSN_BIG_ENDIAN)
91d6fa6a 3394 number_to_chars_bigendian (toP, (valueT) theinsn->opcode, 4);
252b5132 3395 else
91d6fa6a 3396 number_to_chars_littleendian (toP, (valueT) theinsn->opcode, 4);
252b5132 3397
e0c6ed95 3398 /* Put out the symbol-dependent stuff. */
91d6fa6a 3399 if (theinsn->reloc != BFD_RELOC_NONE)
252b5132 3400 {
e0c6ed95
AM
3401 fixS *fixP = fix_new_exp (frag_now, /* Which frag. */
3402 (toP - frag_now->fr_literal), /* Where. */
3403 4, /* Size. */
91d6fa6a
NC
3404 &theinsn->exp,
3405 theinsn->pcrel,
3406 theinsn->reloc);
252b5132 3407 /* Turn off overflow checking in fixup_segment. We'll do our
55cf6793 3408 own overflow checking in md_apply_fix. This is necessary because
252b5132
RH
3409 the insn size is 4 and fixup_segment will signal an overflow for
3410 large 8 byte quantities. */
3411 fixP->fx_no_overflow = 1;
91d6fa6a
NC
3412 if (theinsn->reloc == BFD_RELOC_SPARC_OLO10)
3413 fixP->tc_fix_data = theinsn->exp2.X_add_number;
252b5132
RH
3414 }
3415
3416 last_insn = insn;
91d6fa6a 3417 last_opcode = theinsn->opcode;
732d96b6 3418
732d96b6 3419 dwarf2_emit_insn (4);
252b5132
RH
3420}
3421\f
6d4af3c2 3422const char *
499ac353 3423md_atof (int type, char *litP, int *sizeP)
252b5132 3424{
499ac353 3425 return ieee_md_atof (type, litP, sizeP, target_big_endian);
252b5132
RH
3426}
3427
3428/* Write a value out to the object file, using the appropriate
3429 endianness. */
3430
3431void
5a49b8ac 3432md_number_to_chars (char *buf, valueT val, int n)
252b5132
RH
3433{
3434 if (target_big_endian)
3435 number_to_chars_bigendian (buf, val, n);
3436 else if (target_little_endian_data
3437 && ((n == 4 || n == 2) && ~now_seg->flags & SEC_ALLOC))
e0c6ed95
AM
3438 /* Output debug words, which are not in allocated sections, as big
3439 endian. */
252b5132
RH
3440 number_to_chars_bigendian (buf, val, n);
3441 else if (target_little_endian_data || ! target_big_endian)
3442 number_to_chars_littleendian (buf, val, n);
3443}
3444\f
3445/* Apply a fixS to the frags, now that we know the value it ought to
81d4177b 3446 hold. */
252b5132 3447
94f592af 3448void
5a49b8ac 3449md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
252b5132
RH
3450{
3451 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
94f592af 3452 offsetT val = * (offsetT *) valP;
252b5132
RH
3453 long insn;
3454
9c2799c2 3455 gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
252b5132 3456
e0c6ed95 3457 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
252b5132 3458
a161fe53 3459 /* SPARC ELF relocations don't use an addend in the data field. */
252b5132 3460 if (fixP->fx_addsy != NULL)
7c1d0959
L
3461 {
3462 switch (fixP->fx_r_type)
3463 {
3464 case BFD_RELOC_SPARC_TLS_GD_HI22:
3465 case BFD_RELOC_SPARC_TLS_GD_LO10:
3466 case BFD_RELOC_SPARC_TLS_GD_ADD:
3467 case BFD_RELOC_SPARC_TLS_GD_CALL:
3468 case BFD_RELOC_SPARC_TLS_LDM_HI22:
3469 case BFD_RELOC_SPARC_TLS_LDM_LO10:
3470 case BFD_RELOC_SPARC_TLS_LDM_ADD:
3471 case BFD_RELOC_SPARC_TLS_LDM_CALL:
3472 case BFD_RELOC_SPARC_TLS_LDO_HIX22:
3473 case BFD_RELOC_SPARC_TLS_LDO_LOX10:
3474 case BFD_RELOC_SPARC_TLS_LDO_ADD:
3475 case BFD_RELOC_SPARC_TLS_IE_HI22:
3476 case BFD_RELOC_SPARC_TLS_IE_LO10:
3477 case BFD_RELOC_SPARC_TLS_IE_LD:
3478 case BFD_RELOC_SPARC_TLS_IE_LDX:
3479 case BFD_RELOC_SPARC_TLS_IE_ADD:
3480 case BFD_RELOC_SPARC_TLS_LE_HIX22:
3481 case BFD_RELOC_SPARC_TLS_LE_LOX10:
3482 case BFD_RELOC_SPARC_TLS_DTPMOD32:
3483 case BFD_RELOC_SPARC_TLS_DTPMOD64:
3484 case BFD_RELOC_SPARC_TLS_DTPOFF32:
3485 case BFD_RELOC_SPARC_TLS_DTPOFF64:
3486 case BFD_RELOC_SPARC_TLS_TPOFF32:
3487 case BFD_RELOC_SPARC_TLS_TPOFF64:
3488 S_SET_THREAD_LOCAL (fixP->fx_addsy);
3489
3490 default:
3491 break;
3492 }
3493
3494 return;
3495 }
252b5132
RH
3496
3497 /* This is a hack. There should be a better way to
3498 handle this. Probably in terms of howto fields, once
3499 we can look at these fixups in terms of howtos. */
3500 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
3501 val += fixP->fx_where + fixP->fx_frag->fr_address;
3502
252b5132
RH
3503 /* If this is a data relocation, just output VAL. */
3504
a7bbf4e9
DM
3505 if (fixP->fx_r_type == BFD_RELOC_8)
3506 {
3507 md_number_to_chars (buf, val, 1);
3508 }
3509 else if (fixP->fx_r_type == BFD_RELOC_16
3510 || fixP->fx_r_type == BFD_RELOC_SPARC_UA16)
252b5132
RH
3511 {
3512 md_number_to_chars (buf, val, 2);
3513 }
3514 else if (fixP->fx_r_type == BFD_RELOC_32
0f2712ed 3515 || fixP->fx_r_type == BFD_RELOC_SPARC_UA32
252b5132
RH
3516 || fixP->fx_r_type == BFD_RELOC_SPARC_REV32)
3517 {
3518 md_number_to_chars (buf, val, 4);
3519 }
0f2712ed
NC
3520 else if (fixP->fx_r_type == BFD_RELOC_64
3521 || fixP->fx_r_type == BFD_RELOC_SPARC_UA64)
252b5132
RH
3522 {
3523 md_number_to_chars (buf, val, 8);
3524 }
e0c6ed95 3525 else if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
252b5132
RH
3526 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
3527 {
3528 fixP->fx_done = 0;
94f592af 3529 return;
252b5132
RH
3530 }
3531 else
3532 {
3533 /* It's a relocation against an instruction. */
3534
3535 if (INSN_BIG_ENDIAN)
3536 insn = bfd_getb32 ((unsigned char *) buf);
3537 else
3538 insn = bfd_getl32 ((unsigned char *) buf);
e0c6ed95 3539
252b5132
RH
3540 switch (fixP->fx_r_type)
3541 {
3542 case BFD_RELOC_32_PCREL_S2:
3543 val = val >> 2;
3544 /* FIXME: This increment-by-one deserves a comment of why it's
3545 being done! */
3546 if (! sparc_pic_code
3547 || fixP->fx_addsy == NULL
49309057 3548 || symbol_section_p (fixP->fx_addsy))
252b5132 3549 ++val;
6faf3d66 3550
252b5132 3551 insn |= val & 0x3fffffff;
6faf3d66 3552
d28b6364
JM
3553 /* See if we have a delay slot. In that case we attempt to
3554 optimize several cases transforming CALL instructions
3555 into branches. But we can only do that if the relocation
3556 can be completely resolved here, i.e. if no undefined
3557 symbol is associated with it. */
3558 if (sparc_relax && fixP->fx_addsy == NULL
90bd3c90 3559 && fixP->fx_where + 8 <= fixP->fx_frag->fr_fix)
6faf3d66
JJ
3560 {
3561#define G0 0
3562#define O7 15
3563#define XCC (2 << 20)
3564#define COND(x) (((x)&0xf)<<25)
3565#define CONDA COND(0x8)
3566#define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
3567#define INSN_BA (F2(0,2) | CONDA)
3568#define INSN_OR F3(2, 0x2, 0)
3569#define INSN_NOP F2(0,4)
3570
3571 long delay;
3572
3573 /* If the instruction is a call with either:
3574 restore
3575 arithmetic instruction with rd == %o7
3576 where rs1 != %o7 and rs2 if it is register != %o7
3577 then we can optimize if the call destination is near
3578 by changing the call into a branch always. */
3579 if (INSN_BIG_ENDIAN)
3580 delay = bfd_getb32 ((unsigned char *) buf + 4);
3581 else
3582 delay = bfd_getl32 ((unsigned char *) buf + 4);
e0c6ed95 3583 if ((insn & OP (~0)) != OP (1) || (delay & OP (~0)) != OP (2))
6faf3d66 3584 break;
e0c6ed95
AM
3585 if ((delay & OP3 (~0)) != OP3 (0x3d) /* Restore. */
3586 && ((delay & OP3 (0x28)) != 0 /* Arithmetic. */
3587 || ((delay & RD (~0)) != RD (O7))))
6faf3d66 3588 break;
e0c6ed95
AM
3589 if ((delay & RS1 (~0)) == RS1 (O7)
3590 || ((delay & F3I (~0)) == 0
3591 && (delay & RS2 (~0)) == RS2 (O7)))
6faf3d66
JJ
3592 break;
3593 /* Ensure the branch will fit into simm22. */
3594 if ((val & 0x3fe00000)
3595 && (val & 0x3fe00000) != 0x3fe00000)
3596 break;
3597 /* Check if the arch is v9 and branch will fit
3598 into simm19. */
3599 if (((val & 0x3c0000) == 0
3600 || (val & 0x3c0000) == 0x3c0000)
3601 && (sparc_arch_size == 64
3602 || current_architecture >= SPARC_OPCODE_ARCH_V9))
e0c6ed95 3603 /* ba,pt %xcc */
6faf3d66
JJ
3604 insn = INSN_BPA | (val & 0x7ffff);
3605 else
e0c6ed95 3606 /* ba */
6faf3d66
JJ
3607 insn = INSN_BA | (val & 0x3fffff);
3608 if (fixP->fx_where >= 4
e0c6ed95
AM
3609 && ((delay & (0xffffffff ^ RS1 (~0)))
3610 == (INSN_OR | RD (O7) | RS2 (G0))))
6faf3d66
JJ
3611 {
3612 long setter;
3613 int reg;
3614
3615 if (INSN_BIG_ENDIAN)
3616 setter = bfd_getb32 ((unsigned char *) buf - 4);
3617 else
3618 setter = bfd_getl32 ((unsigned char *) buf - 4);
e0c6ed95 3619 if ((setter & (0xffffffff ^ RD (~0)))
ab3e48dc 3620 != (INSN_OR | RS1 (O7) | RS2 (G0)))
6faf3d66
JJ
3621 break;
3622 /* The sequence was
3623 or %o7, %g0, %rN
3624 call foo
3625 or %rN, %g0, %o7
3626
3627 If call foo was replaced with ba, replace
3628 or %rN, %g0, %o7 with nop. */
e0c6ed95
AM
3629 reg = (delay & RS1 (~0)) >> 14;
3630 if (reg != ((setter & RD (~0)) >> 25)
6faf3d66
JJ
3631 || reg == G0 || reg == O7)
3632 break;
3633
3634 if (INSN_BIG_ENDIAN)
3635 bfd_putb32 (INSN_NOP, (unsigned char *) buf + 4);
3636 else
3637 bfd_putl32 (INSN_NOP, (unsigned char *) buf + 4);
3638 }
3639 }
252b5132
RH
3640 break;
3641
3642 case BFD_RELOC_SPARC_11:
3643 if (! in_signed_range (val, 0x7ff))
3644 as_bad_where (fixP->fx_file, fixP->fx_line,
3645 _("relocation overflow"));
3646 insn |= val & 0x7ff;
3647 break;
3648
3649 case BFD_RELOC_SPARC_10:
3650 if (! in_signed_range (val, 0x3ff))
3651 as_bad_where (fixP->fx_file, fixP->fx_line,
3652 _("relocation overflow"));
3653 insn |= val & 0x3ff;
3654 break;
3655
3656 case BFD_RELOC_SPARC_7:
3657 if (! in_bitfield_range (val, 0x7f))
3658 as_bad_where (fixP->fx_file, fixP->fx_line,
3659 _("relocation overflow"));
3660 insn |= val & 0x7f;
3661 break;
3662
3663 case BFD_RELOC_SPARC_6:
3664 if (! in_bitfield_range (val, 0x3f))
3665 as_bad_where (fixP->fx_file, fixP->fx_line,
3666 _("relocation overflow"));
3667 insn |= val & 0x3f;
3668 break;
3669
3670 case BFD_RELOC_SPARC_5:
3671 if (! in_bitfield_range (val, 0x1f))
3672 as_bad_where (fixP->fx_file, fixP->fx_line,
3673 _("relocation overflow"));
3674 insn |= val & 0x1f;
3675 break;
3676
2615994e
DM
3677 case BFD_RELOC_SPARC_WDISP10:
3678 if ((val & 3)
3679 || val >= 0x007fc
3680 || val <= -(offsetT) 0x808)
3681 as_bad_where (fixP->fx_file, fixP->fx_line,
3682 _("relocation overflow"));
3683 /* FIXME: The +1 deserves a comment. */
3684 val = (val >> 2) + 1;
3685 insn |= ((val & 0x300) << 11)
3686 | ((val & 0xff) << 5);
3687 break;
3688
252b5132 3689 case BFD_RELOC_SPARC_WDISP16:
c699f087
JJ
3690 if ((val & 3)
3691 || val >= 0x1fffc
3692 || val <= -(offsetT) 0x20008)
252b5132
RH
3693 as_bad_where (fixP->fx_file, fixP->fx_line,
3694 _("relocation overflow"));
3695 /* FIXME: The +1 deserves a comment. */
3696 val = (val >> 2) + 1;
3697 insn |= ((val & 0xc000) << 6) | (val & 0x3fff);
3698 break;
3699
3700 case BFD_RELOC_SPARC_WDISP19:
c699f087
JJ
3701 if ((val & 3)
3702 || val >= 0xffffc
3703 || val <= -(offsetT) 0x100008)
252b5132
RH
3704 as_bad_where (fixP->fx_file, fixP->fx_line,
3705 _("relocation overflow"));
3706 /* FIXME: The +1 deserves a comment. */
3707 val = (val >> 2) + 1;
3708 insn |= val & 0x7ffff;
3709 break;
3710
3711 case BFD_RELOC_SPARC_HH22:
3712 val = BSR (val, 32);
e0c6ed95 3713 /* Fall through. */
252b5132
RH
3714
3715 case BFD_RELOC_SPARC_LM22:
3716 case BFD_RELOC_HI22:
3717 if (!fixP->fx_addsy)
94f592af 3718 insn |= (val >> 10) & 0x3fffff;
252b5132 3719 else
94f592af
NC
3720 /* FIXME: Need comment explaining why we do this. */
3721 insn &= ~0xffff;
252b5132
RH
3722 break;
3723
3724 case BFD_RELOC_SPARC22:
3725 if (val & ~0x003fffff)
3726 as_bad_where (fixP->fx_file, fixP->fx_line,
3727 _("relocation overflow"));
3728 insn |= (val & 0x3fffff);
3729 break;
3730
3731 case BFD_RELOC_SPARC_HM10:
3732 val = BSR (val, 32);
e0c6ed95 3733 /* Fall through. */
252b5132
RH
3734
3735 case BFD_RELOC_LO10:
3736 if (!fixP->fx_addsy)
94f592af 3737 insn |= val & 0x3ff;
252b5132 3738 else
94f592af
NC
3739 /* FIXME: Need comment explaining why we do this. */
3740 insn &= ~0xff;
252b5132
RH
3741 break;
3742
dabe3bbc
RH
3743 case BFD_RELOC_SPARC_OLO10:
3744 val &= 0x3ff;
3745 val += fixP->tc_fix_data;
e0c6ed95 3746 /* Fall through. */
dabe3bbc 3747
252b5132
RH
3748 case BFD_RELOC_SPARC13:
3749 if (! in_signed_range (val, 0x1fff))
3750 as_bad_where (fixP->fx_file, fixP->fx_line,
3751 _("relocation overflow"));
3752 insn |= val & 0x1fff;
3753 break;
3754
3755 case BFD_RELOC_SPARC_WDISP22:
3756 val = (val >> 2) + 1;
e0c6ed95 3757 /* Fall through. */
252b5132
RH
3758 case BFD_RELOC_SPARC_BASE22:
3759 insn |= val & 0x3fffff;
3760 break;
3761
2615994e
DM
3762 case BFD_RELOC_SPARC_H34:
3763 if (!fixP->fx_addsy)
3764 {
3765 bfd_vma tval = val;
3766 tval >>= 12;
3767 insn |= tval & 0x3fffff;
3768 }
3769 break;
3770
252b5132
RH
3771 case BFD_RELOC_SPARC_H44:
3772 if (!fixP->fx_addsy)
3773 {
3774 bfd_vma tval = val;
3775 tval >>= 22;
3776 insn |= tval & 0x3fffff;
3777 }
3778 break;
3779
3780 case BFD_RELOC_SPARC_M44:
3781 if (!fixP->fx_addsy)
3782 insn |= (val >> 12) & 0x3ff;
3783 break;
3784
3785 case BFD_RELOC_SPARC_L44:
3786 if (!fixP->fx_addsy)
3787 insn |= val & 0xfff;
3788 break;
3789
3790 case BFD_RELOC_SPARC_HIX22:
3791 if (!fixP->fx_addsy)
3792 {
ab3e48dc 3793 val ^= ~(offsetT) 0;
252b5132
RH
3794 insn |= (val >> 10) & 0x3fffff;
3795 }
3796 break;
3797
3798 case BFD_RELOC_SPARC_LOX10:
3799 if (!fixP->fx_addsy)
3800 insn |= 0x1c00 | (val & 0x3ff);
3801 break;
3802
3803 case BFD_RELOC_NONE:
3804 default:
3805 as_bad_where (fixP->fx_file, fixP->fx_line,
3806 _("bad or unhandled relocation type: 0x%02x"),
3807 fixP->fx_r_type);
3808 break;
3809 }
3810
3811 if (INSN_BIG_ENDIAN)
3812 bfd_putb32 (insn, (unsigned char *) buf);
3813 else
3814 bfd_putl32 (insn, (unsigned char *) buf);
3815 }
3816
3817 /* Are we finished with this relocation now? */
3818 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
3819 fixP->fx_done = 1;
252b5132
RH
3820}
3821
3822/* Translate internal representation of relocation info to BFD target
3823 format. */
e0c6ed95 3824
dabe3bbc 3825arelent **
5a49b8ac 3826tc_gen_reloc (asection *section, fixS *fixp)
252b5132 3827{
dabe3bbc 3828 static arelent *relocs[3];
252b5132
RH
3829 arelent *reloc;
3830 bfd_reloc_code_real_type code;
3831
add39d23 3832 relocs[0] = reloc = XNEW (arelent);
dabe3bbc 3833 relocs[1] = NULL;
252b5132 3834
add39d23 3835 reloc->sym_ptr_ptr = XNEW (asymbol *);
49309057 3836 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
252b5132
RH
3837 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
3838
3839 switch (fixp->fx_r_type)
3840 {
f6a36b0c 3841 case BFD_RELOC_8:
252b5132
RH
3842 case BFD_RELOC_16:
3843 case BFD_RELOC_32:
f6a36b0c
JC
3844 case BFD_RELOC_64:
3845 if (fixp->fx_pcrel)
3846 {
3847 switch (fixp->fx_size)
3848 {
3849 default:
3850 as_bad_where (fixp->fx_file, fixp->fx_line,
3851 _("can not do %d byte pc-relative relocation"),
3852 fixp->fx_size);
3853 code = fixp->fx_r_type;
3854 fixp->fx_pcrel = 0;
3855 break;
3856 case 1: code = BFD_RELOC_8_PCREL; break;
3857 case 2: code = BFD_RELOC_16_PCREL; break;
3858 case 4: code = BFD_RELOC_32_PCREL; break;
3859#ifdef BFD64
3860 case 8: code = BFD_RELOC_64_PCREL; break;
3861#endif
3862 }
3863 if (fixp->fx_pcrel)
3864 fixp->fx_addnumber = fixp->fx_offset;
3865 break;
3866 }
3867 /* Fall through. */
252b5132
RH
3868 case BFD_RELOC_HI22:
3869 case BFD_RELOC_LO10:
3870 case BFD_RELOC_32_PCREL_S2:
3871 case BFD_RELOC_SPARC13:
63fab58c 3872 case BFD_RELOC_SPARC22:
1a6b486f
DM
3873 case BFD_RELOC_SPARC_PC22:
3874 case BFD_RELOC_SPARC_PC10:
252b5132 3875 case BFD_RELOC_SPARC_BASE13:
2615994e 3876 case BFD_RELOC_SPARC_WDISP10:
252b5132
RH
3877 case BFD_RELOC_SPARC_WDISP16:
3878 case BFD_RELOC_SPARC_WDISP19:
3879 case BFD_RELOC_SPARC_WDISP22:
252b5132
RH
3880 case BFD_RELOC_SPARC_5:
3881 case BFD_RELOC_SPARC_6:
3882 case BFD_RELOC_SPARC_7:
3883 case BFD_RELOC_SPARC_10:
3884 case BFD_RELOC_SPARC_11:
3885 case BFD_RELOC_SPARC_HH22:
3886 case BFD_RELOC_SPARC_HM10:
3887 case BFD_RELOC_SPARC_LM22:
3888 case BFD_RELOC_SPARC_PC_HH22:
3889 case BFD_RELOC_SPARC_PC_HM10:
3890 case BFD_RELOC_SPARC_PC_LM22:
2615994e 3891 case BFD_RELOC_SPARC_H34:
252b5132
RH
3892 case BFD_RELOC_SPARC_H44:
3893 case BFD_RELOC_SPARC_M44:
3894 case BFD_RELOC_SPARC_L44:
3895 case BFD_RELOC_SPARC_HIX22:
3896 case BFD_RELOC_SPARC_LOX10:
3897 case BFD_RELOC_SPARC_REV32:
dabe3bbc 3898 case BFD_RELOC_SPARC_OLO10:
0f2712ed
NC
3899 case BFD_RELOC_SPARC_UA16:
3900 case BFD_RELOC_SPARC_UA32:
3901 case BFD_RELOC_SPARC_UA64:
bd5e6e7e
JJ
3902 case BFD_RELOC_8_PCREL:
3903 case BFD_RELOC_16_PCREL:
3904 case BFD_RELOC_32_PCREL:
3905 case BFD_RELOC_64_PCREL:
3906 case BFD_RELOC_SPARC_PLT32:
3907 case BFD_RELOC_SPARC_PLT64:
252b5132
RH
3908 case BFD_RELOC_VTABLE_ENTRY:
3909 case BFD_RELOC_VTABLE_INHERIT:
b9734f35
JJ
3910 case BFD_RELOC_SPARC_TLS_GD_HI22:
3911 case BFD_RELOC_SPARC_TLS_GD_LO10:
3912 case BFD_RELOC_SPARC_TLS_GD_ADD:
3913 case BFD_RELOC_SPARC_TLS_GD_CALL:
3914 case BFD_RELOC_SPARC_TLS_LDM_HI22:
3915 case BFD_RELOC_SPARC_TLS_LDM_LO10:
3916 case BFD_RELOC_SPARC_TLS_LDM_ADD:
3917 case BFD_RELOC_SPARC_TLS_LDM_CALL:
3918 case BFD_RELOC_SPARC_TLS_LDO_HIX22:
3919 case BFD_RELOC_SPARC_TLS_LDO_LOX10:
3920 case BFD_RELOC_SPARC_TLS_LDO_ADD:
3921 case BFD_RELOC_SPARC_TLS_IE_HI22:
3922 case BFD_RELOC_SPARC_TLS_IE_LO10:
3923 case BFD_RELOC_SPARC_TLS_IE_LD:
3924 case BFD_RELOC_SPARC_TLS_IE_LDX:
3925 case BFD_RELOC_SPARC_TLS_IE_ADD:
3926 case BFD_RELOC_SPARC_TLS_LE_HIX22:
3927 case BFD_RELOC_SPARC_TLS_LE_LOX10:
3928 case BFD_RELOC_SPARC_TLS_DTPOFF32:
3929 case BFD_RELOC_SPARC_TLS_DTPOFF64:
739f7f82
DM
3930 case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
3931 case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
3932 case BFD_RELOC_SPARC_GOTDATA_OP:
252b5132
RH
3933 code = fixp->fx_r_type;
3934 break;
3935 default:
3936 abort ();
3937 return NULL;
3938 }
3939
252b5132
RH
3940 /* If we are generating PIC code, we need to generate a different
3941 set of relocs. */
3942
252b5132 3943#define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
910600e9
RS
3944#ifdef TE_VXWORKS
3945#define GOTT_BASE "__GOTT_BASE__"
3946#define GOTT_INDEX "__GOTT_INDEX__"
252b5132
RH
3947#endif
3948
c9098af4 3949 /* This code must be parallel to tc_fix_adjustable. */
153b546a 3950
252b5132
RH
3951 if (sparc_pic_code)
3952 {
3953 switch (code)
3954 {
3955 case BFD_RELOC_32_PCREL_S2:
ae6063d4 3956 if (generic_force_reloc (fixp))
252b5132
RH
3957 code = BFD_RELOC_SPARC_WPLT30;
3958 break;
3959 case BFD_RELOC_HI22:
910600e9
RS
3960 code = BFD_RELOC_SPARC_GOT22;
3961 if (fixp->fx_addsy != NULL)
3962 {
3963 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
3964 code = BFD_RELOC_SPARC_PC22;
3965#ifdef TE_VXWORKS
3966 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_BASE) == 0
3967 || strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_INDEX) == 0)
3968 code = BFD_RELOC_HI22; /* Unchanged. */
3969#endif
3970 }
252b5132
RH
3971 break;
3972 case BFD_RELOC_LO10:
910600e9
RS
3973 code = BFD_RELOC_SPARC_GOT10;
3974 if (fixp->fx_addsy != NULL)
3975 {
3976 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
3977 code = BFD_RELOC_SPARC_PC10;
3978#ifdef TE_VXWORKS
3979 if (strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_BASE) == 0
3980 || strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_INDEX) == 0)
3981 code = BFD_RELOC_LO10; /* Unchanged. */
3982#endif
3983 }
252b5132
RH
3984 break;
3985 case BFD_RELOC_SPARC13:
3986 code = BFD_RELOC_SPARC_GOT13;
3987 break;
3988 default:
3989 break;
3990 }
3991 }
252b5132 3992
062cf837 3993 /* Nothing is aligned in DWARF debugging sections. */
fd361982 3994 if (bfd_section_flags (section) & SEC_DEBUGGING)
062cf837
EB
3995 switch (code)
3996 {
3997 case BFD_RELOC_16: code = BFD_RELOC_SPARC_UA16; break;
3998 case BFD_RELOC_32: code = BFD_RELOC_SPARC_UA32; break;
3999 case BFD_RELOC_64: code = BFD_RELOC_SPARC_UA64; break;
4000 default: break;
4001 }
4002
dabe3bbc
RH
4003 if (code == BFD_RELOC_SPARC_OLO10)
4004 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO10);
4005 else
4006 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
252b5132
RH
4007 if (reloc->howto == 0)
4008 {
4009 as_bad_where (fixp->fx_file, fixp->fx_line,
4010 _("internal error: can't export reloc type %d (`%s')"),
4011 fixp->fx_r_type, bfd_get_reloc_code_name (code));
dabe3bbc
RH
4012 xfree (reloc);
4013 relocs[0] = NULL;
4014 return relocs;
252b5132
RH
4015 }
4016
4017 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
bd5e6e7e
JJ
4018 if (code != BFD_RELOC_32_PCREL_S2
4019 && code != BFD_RELOC_SPARC_WDISP22
4020 && code != BFD_RELOC_SPARC_WDISP16
4021 && code != BFD_RELOC_SPARC_WDISP19
2615994e 4022 && code != BFD_RELOC_SPARC_WDISP10
b9734f35
JJ
4023 && code != BFD_RELOC_SPARC_WPLT30
4024 && code != BFD_RELOC_SPARC_TLS_GD_CALL
4025 && code != BFD_RELOC_SPARC_TLS_LDM_CALL)
252b5132 4026 reloc->addend = fixp->fx_addnumber;
49309057 4027 else if (symbol_section_p (fixp->fx_addsy))
252b5132
RH
4028 reloc->addend = (section->vma
4029 + fixp->fx_addnumber
4030 + md_pcrel_from (fixp));
4031 else
4032 reloc->addend = fixp->fx_offset;
252b5132 4033
dabe3bbc
RH
4034 /* We expand R_SPARC_OLO10 to R_SPARC_LO10 and R_SPARC_13
4035 on the same location. */
4036 if (code == BFD_RELOC_SPARC_OLO10)
4037 {
add39d23 4038 relocs[1] = reloc = XNEW (arelent);
dabe3bbc
RH
4039 relocs[2] = NULL;
4040
add39d23 4041 reloc->sym_ptr_ptr = XNEW (asymbol *);
ab3e48dc
KH
4042 *reloc->sym_ptr_ptr
4043 = symbol_get_bfdsym (section_symbol (absolute_section));
dabe3bbc
RH
4044 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4045 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_SPARC13);
4046 reloc->addend = fixp->tc_fix_data;
4047 }
4048
4049 return relocs;
252b5132
RH
4050}
4051\f
e0c6ed95 4052/* We have no need to default values of symbols. */
252b5132 4053
252b5132 4054symbolS *
5a49b8ac 4055md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
252b5132
RH
4056{
4057 return 0;
e0c6ed95
AM
4058}
4059
4060/* Round up a section size to the appropriate boundary. */
252b5132 4061
252b5132 4062valueT
5a49b8ac 4063md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
252b5132 4064{
252b5132 4065 return size;
252b5132
RH
4066}
4067
4068/* Exactly what point is a PC-relative offset relative TO?
4069 On the sparc, they're relative to the address of the offset, plus
4070 its size. This gets us to the following instruction.
e0c6ed95
AM
4071 (??? Is this right? FIXME-SOON) */
4072long
5a49b8ac 4073md_pcrel_from (fixS *fixP)
252b5132
RH
4074{
4075 long ret;
4076
4077 ret = fixP->fx_where + fixP->fx_frag->fr_address;
4078 if (! sparc_pic_code
4079 || fixP->fx_addsy == NULL
49309057 4080 || symbol_section_p (fixP->fx_addsy))
252b5132
RH
4081 ret += fixP->fx_size;
4082 return ret;
4083}
4084\f
4085/* Return log2 (VALUE), or -1 if VALUE is not an exact positive power
4086 of two. */
4087
4088static int
5a49b8ac 4089mylog2 (int value)
252b5132
RH
4090{
4091 int shift;
4092
4093 if (value <= 0)
4094 return -1;
4095
4096 for (shift = 0; (value & 1) == 0; value >>= 1)
4097 ++shift;
4098
4099 return (value == 1) ? shift : -1;
4100}
4101
e0c6ed95 4102/* Sort of like s_lcomm. */
252b5132 4103
252b5132 4104static void
5a49b8ac 4105s_reserve (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
4106{
4107 char *name;
4108 char *p;
4109 char c;
4110 int align;
4111 int size;
4112 int temp;
4113 symbolS *symbolP;
4114
d02603dc 4115 c = get_symbol_name (&name);
252b5132
RH
4116 p = input_line_pointer;
4117 *p = c;
d02603dc 4118 SKIP_WHITESPACE_AFTER_NAME ();
252b5132
RH
4119
4120 if (*input_line_pointer != ',')
4121 {
4122 as_bad (_("Expected comma after name"));
4123 ignore_rest_of_line ();
4124 return;
4125 }
4126
4127 ++input_line_pointer;
4128
4129 if ((size = get_absolute_expression ()) < 0)
4130 {
4131 as_bad (_("BSS length (%d.) <0! Ignored."), size);
4132 ignore_rest_of_line ();
4133 return;
e0c6ed95 4134 } /* Bad length. */
252b5132
RH
4135
4136 *p = 0;
4137 symbolP = symbol_find_or_make (name);
4138 *p = c;
4139
d34049e8
ML
4140 if (!startswith (input_line_pointer, ",\"bss\"")
4141 && !startswith (input_line_pointer, ",\".bss\""))
252b5132
RH
4142 {
4143 as_bad (_("bad .reserve segment -- expected BSS segment"));
4144 return;
4145 }
4146
4147 if (input_line_pointer[2] == '.')
4148 input_line_pointer += 7;
4149 else
4150 input_line_pointer += 6;
4151 SKIP_WHITESPACE ();
4152
4153 if (*input_line_pointer == ',')
4154 {
4155 ++input_line_pointer;
4156
4157 SKIP_WHITESPACE ();
4158 if (*input_line_pointer == '\n')
4159 {
4160 as_bad (_("missing alignment"));
4161 ignore_rest_of_line ();
4162 return;
4163 }
4164
4165 align = (int) get_absolute_expression ();
4166
252b5132
RH
4167 if (align < 0)
4168 {
4169 as_bad (_("negative alignment"));
4170 ignore_rest_of_line ();
4171 return;
4172 }
4173
4174 if (align != 0)
4175 {
f17c130b 4176 temp = mylog2 (align);
252b5132
RH
4177 if (temp < 0)
4178 {
4179 as_bad (_("alignment not a power of 2"));
4180 ignore_rest_of_line ();
4181 return;
4182 }
4183
4184 align = temp;
4185 }
4186
4187 record_alignment (bss_section, align);
4188 }
4189 else
4190 align = 0;
4191
c9098af4 4192 if (!S_IS_DEFINED (symbolP))
252b5132
RH
4193 {
4194 if (! need_pass_2)
4195 {
4196 char *pfrag;
4197 segT current_seg = now_seg;
4198 subsegT current_subseg = now_subseg;
4199
e0c6ed95
AM
4200 /* Switch to bss. */
4201 subseg_set (bss_section, 1);
252b5132
RH
4202
4203 if (align)
e0c6ed95
AM
4204 /* Do alignment. */
4205 frag_align (align, 0, 0);
252b5132 4206
e0c6ed95 4207 /* Detach from old frag. */
ab3e48dc 4208 if (S_GET_SEGMENT (symbolP) == bss_section)
49309057 4209 symbol_get_frag (symbolP)->fr_symbol = NULL;
252b5132 4210
49309057 4211 symbol_set_frag (symbolP, frag_now);
e0c6ed95
AM
4212 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
4213 (offsetT) size, (char *) 0);
252b5132
RH
4214 *pfrag = 0;
4215
4216 S_SET_SEGMENT (symbolP, bss_section);
4217
4218 subseg_set (current_seg, current_subseg);
4219
252b5132 4220 S_SET_SIZE (symbolP, size);
252b5132
RH
4221 }
4222 }
4223 else
4224 {
20203fb9 4225 as_warn (_("Ignoring attempt to re-define symbol %s"),
ab3e48dc 4226 S_GET_NAME (symbolP));
20203fb9 4227 }
252b5132
RH
4228
4229 demand_empty_rest_of_line ();
4230}
4231
4232static void
5a49b8ac 4233s_common (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
4234{
4235 char *name;
4236 char c;
4237 char *p;
685736be 4238 offsetT temp, size;
252b5132
RH
4239 symbolS *symbolP;
4240
d02603dc 4241 c = get_symbol_name (&name);
e0c6ed95 4242 /* Just after name is now '\0'. */
252b5132
RH
4243 p = input_line_pointer;
4244 *p = c;
d02603dc 4245 SKIP_WHITESPACE_AFTER_NAME ();
252b5132
RH
4246 if (*input_line_pointer != ',')
4247 {
4248 as_bad (_("Expected comma after symbol-name"));
4249 ignore_rest_of_line ();
4250 return;
4251 }
e0c6ed95
AM
4252
4253 /* Skip ','. */
4254 input_line_pointer++;
4255
252b5132
RH
4256 if ((temp = get_absolute_expression ()) < 0)
4257 {
685736be
NC
4258 as_bad (_(".COMMon length (%lu) out of range ignored"),
4259 (unsigned long) temp);
252b5132
RH
4260 ignore_rest_of_line ();
4261 return;
4262 }
4263 size = temp;
4264 *p = 0;
4265 symbolP = symbol_find_or_make (name);
4266 *p = c;
4267 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4268 {
4269 as_bad (_("Ignoring attempt to re-define symbol"));
4270 ignore_rest_of_line ();
4271 return;
4272 }
4273 if (S_GET_VALUE (symbolP) != 0)
4274 {
4275 if (S_GET_VALUE (symbolP) != (valueT) size)
4276 {
364b6d8b
JJ
4277 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4278 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), (long) size);
252b5132
RH
4279 }
4280 }
7dcc9865 4281 know (symbol_get_frag (symbolP) == &zero_address_frag);
252b5132
RH
4282 if (*input_line_pointer != ',')
4283 {
4284 as_bad (_("Expected comma after common length"));
4285 ignore_rest_of_line ();
4286 return;
4287 }
4288 input_line_pointer++;
4289 SKIP_WHITESPACE ();
4290 if (*input_line_pointer != '"')
4291 {
4292 temp = get_absolute_expression ();
4293
252b5132
RH
4294 if (temp < 0)
4295 {
4296 as_bad (_("negative alignment"));
4297 ignore_rest_of_line ();
4298 return;
4299 }
4300
49309057 4301 if (symbol_get_obj (symbolP)->local)
252b5132
RH
4302 {
4303 segT old_sec;
4304 int old_subsec;
252b5132
RH
4305 int align;
4306
4307 old_sec = now_seg;
4308 old_subsec = now_subseg;
4309
4310 if (temp == 0)
4311 align = 0;
4312 else
f17c130b 4313 align = mylog2 (temp);
252b5132
RH
4314
4315 if (align < 0)
4316 {
4317 as_bad (_("alignment not a power of 2"));
4318 ignore_rest_of_line ();
4319 return;
4320 }
4321
4322 record_alignment (bss_section, align);
4323 subseg_set (bss_section, 0);
4324 if (align)
4325 frag_align (align, 0, 0);
4326 if (S_GET_SEGMENT (symbolP) == bss_section)
49309057
ILT
4327 symbol_get_frag (symbolP)->fr_symbol = 0;
4328 symbol_set_frag (symbolP, frag_now);
252b5132
RH
4329 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
4330 (offsetT) size, (char *) 0);
4331 *p = 0;
4332 S_SET_SEGMENT (symbolP, bss_section);
4333 S_CLEAR_EXTERNAL (symbolP);
4334 S_SET_SIZE (symbolP, size);
4335 subseg_set (old_sec, old_subsec);
4336 }
4337 else
252b5132
RH
4338 {
4339 allocate_common:
4340 S_SET_VALUE (symbolP, (valueT) size);
252b5132
RH
4341 S_SET_ALIGN (symbolP, temp);
4342 S_SET_SIZE (symbolP, size);
252b5132
RH
4343 S_SET_EXTERNAL (symbolP);
4344 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
4345 }
4346 }
4347 else
4348 {
4349 input_line_pointer++;
4350 /* @@ Some use the dot, some don't. Can we get some consistency?? */
4351 if (*input_line_pointer == '.')
4352 input_line_pointer++;
4353 /* @@ Some say data, some say bss. */
d34049e8
ML
4354 if (!startswith (input_line_pointer, "bss\"")
4355 && !startswith (input_line_pointer, "data\""))
252b5132
RH
4356 {
4357 while (*--input_line_pointer != '"')
4358 ;
4359 input_line_pointer--;
4360 goto bad_common_segment;
4361 }
4362 while (*input_line_pointer++ != '"')
4363 ;
4364 goto allocate_common;
4365 }
4366
49309057 4367 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
252b5132
RH
4368
4369 demand_empty_rest_of_line ();
4370 return;
4371
4372 {
4373 bad_common_segment:
4374 p = input_line_pointer;
4375 while (*p && *p != '\n')
4376 p++;
4377 c = *p;
4378 *p = '\0';
4379 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
4380 *p = c;
4381 input_line_pointer = p;
4382 ignore_rest_of_line ();
4383 return;
4384 }
4385}
4386
67c1ffbe 4387/* Handle the .empty pseudo-op. This suppresses the warnings about
252b5132
RH
4388 invalid delay slot usage. */
4389
4390static void
5a49b8ac 4391s_empty (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
4392{
4393 /* The easy way to implement is to just forget about the last
4394 instruction. */
4395 last_insn = NULL;
4396}
4397
4398static void
5a49b8ac 4399s_seg (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
4400{
4401
d34049e8 4402 if (startswith (input_line_pointer, "\"text\""))
252b5132
RH
4403 {
4404 input_line_pointer += 6;
4405 s_text (0);
4406 return;
4407 }
d34049e8 4408 if (startswith (input_line_pointer, "\"data\""))
252b5132
RH
4409 {
4410 input_line_pointer += 6;
4411 s_data (0);
4412 return;
4413 }
d34049e8 4414 if (startswith (input_line_pointer, "\"data1\""))
252b5132
RH
4415 {
4416 input_line_pointer += 7;
4417 s_data1 ();
4418 return;
4419 }
d34049e8 4420 if (startswith (input_line_pointer, "\"bss\""))
252b5132
RH
4421 {
4422 input_line_pointer += 5;
4423 /* We only support 2 segments -- text and data -- for now, so
4424 things in the "bss segment" will have to go into data for now.
e0c6ed95
AM
4425 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
4426 subseg_set (data_section, 255); /* FIXME-SOMEDAY. */
252b5132
RH
4427 return;
4428 }
4429 as_bad (_("Unknown segment type"));
4430 demand_empty_rest_of_line ();
4431}
4432
4433static void
5a49b8ac 4434s_data1 (void)
252b5132
RH
4435{
4436 subseg_set (data_section, 1);
4437 demand_empty_rest_of_line ();
4438}
4439
4440static void
5a49b8ac 4441s_proc (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
4442{
4443 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4444 {
4445 ++input_line_pointer;
4446 }
4447 ++input_line_pointer;
4448}
4449
4450/* This static variable is set by s_uacons to tell sparc_cons_align
67c1ffbe 4451 that the expression does not need to be aligned. */
252b5132
RH
4452
4453static int sparc_no_align_cons = 0;
4454
4455/* This handles the unaligned space allocation pseudo-ops, such as
4456 .uaword. .uaword is just like .word, but the value does not need
4457 to be aligned. */
4458
4459static void
5a49b8ac 4460s_uacons (int bytes)
252b5132
RH
4461{
4462 /* Tell sparc_cons_align not to align this value. */
4463 sparc_no_align_cons = 1;
4464 cons (bytes);
4ffadb11 4465 sparc_no_align_cons = 0;
252b5132
RH
4466}
4467
cf9a1301
RH
4468/* This handles the native word allocation pseudo-op .nword.
4469 For sparc_arch_size 32 it is equivalent to .word, for
4470 sparc_arch_size 64 it is equivalent to .xword. */
4471
4472static void
5a49b8ac 4473s_ncons (int bytes ATTRIBUTE_UNUSED)
cf9a1301
RH
4474{
4475 cons (sparc_arch_size == 32 ? 4 : 8);
4476}
4477
6d8809aa
RH
4478/* Handle the SPARC ELF .register pseudo-op. This sets the binding of a
4479 global register.
4480 The syntax is:
e0c6ed95 4481
6d8809aa 4482 .register %g[2367],{#scratch|symbolname|#ignore}
e0c6ed95 4483*/
6d8809aa
RH
4484
4485static void
5a49b8ac 4486s_register (int ignore ATTRIBUTE_UNUSED)
6d8809aa
RH
4487{
4488 char c;
4489 int reg;
4490 int flags;
d02603dc 4491 char *regname;
6d8809aa
RH
4492
4493 if (input_line_pointer[0] != '%'
4494 || input_line_pointer[1] != 'g'
4495 || ((input_line_pointer[2] & ~1) != '2'
4496 && (input_line_pointer[2] & ~1) != '6')
4497 || input_line_pointer[3] != ',')
4498 as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
4499 reg = input_line_pointer[2] - '0';
4500 input_line_pointer += 4;
4501
4502 if (*input_line_pointer == '#')
4503 {
4504 ++input_line_pointer;
d02603dc 4505 c = get_symbol_name (&regname);
6d8809aa
RH
4506 if (strcmp (regname, "scratch") && strcmp (regname, "ignore"))
4507 as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
ab3e48dc 4508 if (regname[0] == 'i')
6d8809aa
RH
4509 regname = NULL;
4510 else
e87de513 4511 regname = (char *) "";
6d8809aa
RH
4512 }
4513 else
4514 {
d02603dc 4515 c = get_symbol_name (&regname);
6d8809aa 4516 }
d02603dc 4517
6d8809aa
RH
4518 if (sparc_arch_size == 64)
4519 {
e0c6ed95 4520 if (globals[reg])
6d8809aa 4521 {
e0c6ed95
AM
4522 if ((regname && globals[reg] != (symbolS *) 1
4523 && strcmp (S_GET_NAME (globals[reg]), regname))
4524 || ((regname != NULL) ^ (globals[reg] != (symbolS *) 1)))
6d8809aa
RH
4525 as_bad (_("redefinition of global register"));
4526 }
4527 else
4528 {
4529 if (regname == NULL)
e0c6ed95 4530 globals[reg] = (symbolS *) 1;
6d8809aa
RH
4531 else
4532 {
4533 if (*regname)
4534 {
4535 if (symbol_find (regname))
4536 as_bad (_("Register symbol %s already defined."),
4537 regname);
4538 }
e0c6ed95
AM
4539 globals[reg] = symbol_make (regname);
4540 flags = symbol_get_bfdsym (globals[reg])->flags;
6d8809aa
RH
4541 if (! *regname)
4542 flags = flags & ~(BSF_GLOBAL|BSF_LOCAL|BSF_WEAK);
4543 if (! (flags & (BSF_GLOBAL|BSF_LOCAL|BSF_WEAK)))
4544 flags |= BSF_GLOBAL;
e0c6ed95
AM
4545 symbol_get_bfdsym (globals[reg])->flags = flags;
4546 S_SET_VALUE (globals[reg], (valueT) reg);
4547 S_SET_ALIGN (globals[reg], reg);
4548 S_SET_SIZE (globals[reg], 0);
6d8809aa
RH
4549 /* Although we actually want undefined_section here,
4550 we have to use absolute_section, because otherwise
4551 generic as code will make it a COM section.
4552 We fix this up in sparc_adjust_symtab. */
e0c6ed95
AM
4553 S_SET_SEGMENT (globals[reg], absolute_section);
4554 S_SET_OTHER (globals[reg], 0);
4555 elf_symbol (symbol_get_bfdsym (globals[reg]))
6d8809aa
RH
4556 ->internal_elf_sym.st_info =
4557 ELF_ST_INFO(STB_GLOBAL, STT_REGISTER);
e0c6ed95 4558 elf_symbol (symbol_get_bfdsym (globals[reg]))
6d8809aa
RH
4559 ->internal_elf_sym.st_shndx = SHN_UNDEF;
4560 }
4561 }
4562 }
4563
d02603dc 4564 (void) restore_line_pointer (c);
6d8809aa
RH
4565
4566 demand_empty_rest_of_line ();
4567}
4568
4569/* Adjust the symbol table. We set undefined sections for STT_REGISTER
4570 symbols which need it. */
e0c6ed95 4571
6d8809aa 4572void
5a49b8ac 4573sparc_adjust_symtab (void)
6d8809aa
RH
4574{
4575 symbolS *sym;
e0c6ed95 4576
6d8809aa
RH
4577 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4578 {
4579 if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym))
4580 ->internal_elf_sym.st_info) != STT_REGISTER)
4581 continue;
4582
4583 if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym))
4584 ->internal_elf_sym.st_shndx != SHN_UNDEF))
4585 continue;
4586
4587 S_SET_SEGMENT (sym, undefined_section);
4588 }
4589}
6d8809aa 4590
252b5132
RH
4591/* If the --enforce-aligned-data option is used, we require .word,
4592 et. al., to be aligned correctly. We do it by setting up an
4593 rs_align_code frag, and checking in HANDLE_ALIGN to make sure that
4594 no unexpected alignment was introduced.
4595
4596 The SunOS and Solaris native assemblers enforce aligned data by
4597 default. We don't want to do that, because gcc can deliberately
4598 generate misaligned data if the packed attribute is used. Instead,
4599 we permit misaligned data by default, and permit the user to set an
4600 option to check for it. */
4601
4602void
5a49b8ac 4603sparc_cons_align (int nbytes)
252b5132
RH
4604{
4605 int nalign;
252b5132
RH
4606
4607 /* Only do this if we are enforcing aligned data. */
4608 if (! enforce_aligned_data)
4609 return;
4610
0f2712ed 4611 /* Don't align if this is an unaligned pseudo-op. */
252b5132 4612 if (sparc_no_align_cons)
0f2712ed 4613 return;
252b5132 4614
f17c130b 4615 nalign = mylog2 (nbytes);
252b5132
RH
4616 if (nalign == 0)
4617 return;
4618
9c2799c2 4619 gas_assert (nalign > 0);
252b5132
RH
4620
4621 if (now_seg == absolute_section)
4622 {
4623 if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
4624 as_bad (_("misaligned data"));
4625 return;
4626 }
4627
87975d2a
AM
4628 frag_var (rs_align_test, 1, 1, (relax_substateT) 0,
4629 (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
252b5132
RH
4630
4631 record_alignment (now_seg, nalign);
4632}
4633
0a9ef439 4634/* This is called from HANDLE_ALIGN in tc-sparc.h. */
252b5132
RH
4635
4636void
5a49b8ac 4637sparc_handle_align (fragS *fragp)
252b5132 4638{
0a9ef439
RH
4639 int count, fix;
4640 char *p;
4641
4642 count = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
bfb32b52 4643
0a9ef439 4644 switch (fragp->fr_type)
252b5132 4645 {
0a9ef439
RH
4646 case rs_align_test:
4647 if (count != 0)
4648 as_bad_where (fragp->fr_file, fragp->fr_line, _("misaligned data"));
4649 break;
e0c6ed95 4650
0a9ef439
RH
4651 case rs_align_code:
4652 p = fragp->fr_literal + fragp->fr_fix;
4653 fix = 0;
e0c6ed95 4654
0a9ef439
RH
4655 if (count & 3)
4656 {
4657 fix = count & 3;
4658 memset (p, 0, fix);
4659 p += fix;
4660 count -= fix;
4661 }
e0c6ed95 4662
0a9ef439
RH
4663 if (SPARC_OPCODE_ARCH_V9_P (max_architecture) && count > 8)
4664 {
4665 unsigned wval = (0x30680000 | count >> 2); /* ba,a,pt %xcc, 1f */
4666 if (INSN_BIG_ENDIAN)
4667 number_to_chars_bigendian (p, wval, 4);
4668 else
4669 number_to_chars_littleendian (p, wval, 4);
4670 p += 4;
4671 count -= 4;
4672 fix += 4;
e0c6ed95 4673 }
0a9ef439
RH
4674
4675 if (INSN_BIG_ENDIAN)
4676 number_to_chars_bigendian (p, 0x01000000, 4);
4677 else
4678 number_to_chars_littleendian (p, 0x01000000, 4);
4679
4680 fragp->fr_fix += fix;
4681 fragp->fr_var = 4;
4682 break;
4683
4684 default:
4685 break;
252b5132
RH
4686 }
4687}
4688
252b5132
RH
4689/* Some special processing for a Sparc ELF file. */
4690
4691void
5a49b8ac 4692sparc_elf_final_processing (void)
252b5132
RH
4693{
4694 /* Set the Sparc ELF flag bits. FIXME: There should probably be some
4695 sort of BFD interface for this. */
4696 if (sparc_arch_size == 64)
4697 {
4698 switch (sparc_memory_model)
4699 {
4700 case MM_RMO:
4701 elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_RMO;
4702 break;
4703 case MM_PSO:
4704 elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_PSO;
4705 break;
4706 default:
4707 break;
4708 }
4709 }
4710 else if (current_architecture >= SPARC_OPCODE_ARCH_V9)
4711 elf_elfheader (stdoutput)->e_flags |= EF_SPARC_32PLUS;
4712 if (current_architecture == SPARC_OPCODE_ARCH_V9A)
4713 elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1;
19f7b010
JJ
4714 else if (current_architecture == SPARC_OPCODE_ARCH_V9B)
4715 elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1|EF_SPARC_SUN_US3;
252b5132 4716}
bd5e6e7e 4717
62ebcb5c 4718const char *
5a49b8ac 4719sparc_cons (expressionS *exp, int size)
bd5e6e7e
JJ
4720{
4721 char *save;
62ebcb5c 4722 const char *sparc_cons_special_reloc = NULL;
bd5e6e7e
JJ
4723
4724 SKIP_WHITESPACE ();
bd5e6e7e
JJ
4725 save = input_line_pointer;
4726 if (input_line_pointer[0] == '%'
4727 && input_line_pointer[1] == 'r'
4728 && input_line_pointer[2] == '_')
4729 {
d34049e8 4730 if (startswith (input_line_pointer + 3, "disp"))
bd5e6e7e
JJ
4731 {
4732 input_line_pointer += 7;
4733 sparc_cons_special_reloc = "disp";
4734 }
d34049e8 4735 else if (startswith (input_line_pointer + 3, "plt"))
bd5e6e7e
JJ
4736 {
4737 if (size != 4 && size != 8)
4738 as_bad (_("Illegal operands: %%r_plt in %d-byte data field"), size);
4739 else
4740 {
4741 input_line_pointer += 6;
4742 sparc_cons_special_reloc = "plt";
4743 }
4744 }
d34049e8 4745 else if (startswith (input_line_pointer + 3, "tls_dtpoff"))
b9734f35
JJ
4746 {
4747 if (size != 4 && size != 8)
4748 as_bad (_("Illegal operands: %%r_tls_dtpoff in %d-byte data field"), size);
4749 else
4750 {
4751 input_line_pointer += 13;
4752 sparc_cons_special_reloc = "tls_dtpoff";
4753 }
4754 }
bd5e6e7e
JJ
4755 if (sparc_cons_special_reloc)
4756 {
4757 int bad = 0;
4758
4759 switch (size)
4760 {
4761 case 1:
4762 if (*input_line_pointer != '8')
4763 bad = 1;
4764 input_line_pointer--;
4765 break;
4766 case 2:
4767 if (input_line_pointer[0] != '1' || input_line_pointer[1] != '6')
4768 bad = 1;
4769 break;
4770 case 4:
4771 if (input_line_pointer[0] != '3' || input_line_pointer[1] != '2')
4772 bad = 1;
4773 break;
4774 case 8:
4775 if (input_line_pointer[0] != '6' || input_line_pointer[1] != '4')
4776 bad = 1;
4777 break;
4778 default:
4779 bad = 1;
4780 break;
4781 }
4782
4783 if (bad)
4784 {
4785 as_bad (_("Illegal operands: Only %%r_%s%d allowed in %d-byte data fields"),
4786 sparc_cons_special_reloc, size * 8, size);
4787 }
4788 else
4789 {
4790 input_line_pointer += 2;
4791 if (*input_line_pointer != '(')
4792 {
4793 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
4794 sparc_cons_special_reloc, size * 8);
4795 bad = 1;
4796 }
4797 }
4798
4799 if (bad)
4800 {
4801 input_line_pointer = save;
4802 sparc_cons_special_reloc = NULL;
4803 }
4804 else
4805 {
4806 int c;
4807 char *end = ++input_line_pointer;
4808 int npar = 0;
4809
4810 while (! is_end_of_line[(c = *end)])
4811 {
4812 if (c == '(')
4813 npar++;
4814 else if (c == ')')
4815 {
4816 if (!npar)
4817 break;
4818 npar--;
4819 }
4820 end++;
4821 }
4822
4823 if (c != ')')
4824 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
4825 sparc_cons_special_reloc, size * 8);
4826 else
4827 {
4828 *end = '\0';
4829 expression (exp);
4830 *end = c;
4831 if (input_line_pointer != end)
4832 {
4833 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
4834 sparc_cons_special_reloc, size * 8);
4835 }
4836 else
4837 {
4838 input_line_pointer++;
4839 SKIP_WHITESPACE ();
4840 c = *input_line_pointer;
4841 if (! is_end_of_line[c] && c != ',')
4842 as_bad (_("Illegal operands: garbage after %%r_%s%d()"),
4843 sparc_cons_special_reloc, size * 8);
4844 }
4845 }
4846 }
4847 }
4848 }
4849 if (sparc_cons_special_reloc == NULL)
4850 expression (exp);
62ebcb5c 4851 return sparc_cons_special_reloc;
bd5e6e7e
JJ
4852}
4853
252b5132
RH
4854/* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
4855 reloc for a cons. We could use the definition there, except that
4856 we want to handle little endian relocs specially. */
4857
4858void
5a49b8ac
AM
4859cons_fix_new_sparc (fragS *frag,
4860 int where,
4861 unsigned int nbytes,
62ebcb5c
AM
4862 expressionS *exp,
4863 const char *sparc_cons_special_reloc)
252b5132
RH
4864{
4865 bfd_reloc_code_real_type r;
4866
4867 r = (nbytes == 1 ? BFD_RELOC_8 :
4868 (nbytes == 2 ? BFD_RELOC_16 :
4869 (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64)));
4870
0f2712ed
NC
4871 if (target_little_endian_data
4872 && nbytes == 4
e0c6ed95 4873 && now_seg->flags & SEC_ALLOC)
252b5132 4874 r = BFD_RELOC_SPARC_REV32;
0f2712ed 4875
02442566
ST
4876#ifdef TE_SOLARIS
4877 /* The Solaris linker does not allow R_SPARC_UA64
4878 relocations for 32-bit executables. */
4879 if (!target_little_endian_data
4880 && sparc_arch_size != 64
4881 && r == BFD_RELOC_64)
4882 r = BFD_RELOC_32;
4883#endif
4884
bd5e6e7e
JJ
4885 if (sparc_cons_special_reloc)
4886 {
4887 if (*sparc_cons_special_reloc == 'd')
4888 switch (nbytes)
4889 {
4890 case 1: r = BFD_RELOC_8_PCREL; break;
4891 case 2: r = BFD_RELOC_16_PCREL; break;
4892 case 4: r = BFD_RELOC_32_PCREL; break;
4893 case 8: r = BFD_RELOC_64_PCREL; break;
4894 default: abort ();
4895 }
b9734f35 4896 else if (*sparc_cons_special_reloc == 'p')
bd5e6e7e
JJ
4897 switch (nbytes)
4898 {
4899 case 4: r = BFD_RELOC_SPARC_PLT32; break;
4900 case 8: r = BFD_RELOC_SPARC_PLT64; break;
4901 }
b9734f35
JJ
4902 else
4903 switch (nbytes)
4904 {
4905 case 4: r = BFD_RELOC_SPARC_TLS_DTPOFF32; break;
4906 case 8: r = BFD_RELOC_SPARC_TLS_DTPOFF64; break;
4907 }
bd5e6e7e 4908 }
93ca3936
NC
4909 else if (sparc_no_align_cons
4910 || /* PR 20803 - relocs in the .eh_frame section
4911 need to support unaligned access. */
4912 strcmp (now_seg->name, ".eh_frame") == 0)
0f2712ed
NC
4913 {
4914 switch (nbytes)
4915 {
4916 case 2: r = BFD_RELOC_SPARC_UA16; break;
4917 case 4: r = BFD_RELOC_SPARC_UA32; break;
02442566
ST
4918#ifdef TE_SOLARIS
4919 /* The Solaris linker does not allow R_SPARC_UA64
4920 relocations for 32-bit executables. */
4921 case 8: r = sparc_arch_size == 64 ?
4922 BFD_RELOC_SPARC_UA64 : BFD_RELOC_SPARC_UA32; break;
4923#else
0f2712ed 4924 case 8: r = BFD_RELOC_SPARC_UA64; break;
02442566 4925#endif
0f2712ed
NC
4926 default: abort ();
4927 }
4ffadb11 4928 }
0f2712ed 4929
252b5132 4930 fix_new_exp (frag, where, (int) nbytes, exp, 0, r);
364b6d8b
JJ
4931}
4932
4933void
5a49b8ac 4934sparc_cfi_frame_initial_instructions (void)
364b6d8b
JJ
4935{
4936 cfi_add_CFA_def_cfa (14, sparc_arch_size == 64 ? 0x7ff : 0);
4937}
4938
4939int
1df69f4f 4940sparc_regname_to_dw2regnum (char *regname)
364b6d8b 4941{
74b4e47a
TS
4942 char *q;
4943 int i;
364b6d8b
JJ
4944
4945 if (!regname[0])
4946 return -1;
4947
74b4e47a
TS
4948 switch (regname[0])
4949 {
4950 case 'g': i = 0; break;
4951 case 'o': i = 1; break;
4952 case 'l': i = 2; break;
4953 case 'i': i = 3; break;
4954 default: i = -1; break;
4955 }
4956 if (i != -1)
364b6d8b
JJ
4957 {
4958 if (regname[1] < '0' || regname[1] > '8' || regname[2])
4959 return -1;
74b4e47a 4960 return i * 8 + regname[1] - '0';
364b6d8b
JJ
4961 }
4962 if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
4963 return 14;
4964 if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
4965 return 30;
4966 if (regname[0] == 'f' || regname[0] == 'r')
4967 {
4968 unsigned int regnum;
4969
4970 regnum = strtoul (regname + 1, &q, 10);
74b4e47a 4971 if (q == NULL || *q)
364b6d8b
JJ
4972 return -1;
4973 if (regnum >= ((regname[0] == 'f'
4974 && SPARC_OPCODE_ARCH_V9_P (max_architecture))
4975 ? 64 : 32))
4976 return -1;
4977 if (regname[0] == 'f')
4978 {
4979 regnum += 32;
4980 if (regnum >= 64 && (regnum & 1))
4981 return -1;
4982 }
4983 return regnum;
4984 }
4985 return -1;
4986}
4987
4988void
4989sparc_cfi_emit_pcrel_expr (expressionS *exp, unsigned int nbytes)
4990{
364b6d8b 4991 sparc_no_align_cons = 1;
62ebcb5c 4992 emit_expr_with_reloc (exp, nbytes, "disp");
364b6d8b 4993 sparc_no_align_cons = 0;
252b5132 4994}