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