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