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