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