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