Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-sparc.c -- Assemble for the SPARC |
49309057 | 2 | Copyright (C) 1989, 90-96, 97, 98, 1999 Free Software Foundation, Inc. |
252b5132 RH |
3 | This file is part of GAS, the GNU Assembler. |
4 | ||
5 | GAS is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2, or (at your option) | |
8 | any later version. | |
9 | ||
10 | GAS is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public | |
16 | License along with GAS; see the file COPYING. If not, write | |
17 | to the Free Software Foundation, 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <ctype.h> | |
22 | ||
23 | #include "as.h" | |
24 | #include "subsegs.h" | |
25 | ||
26 | #include "opcode/sparc.h" | |
27 | ||
28 | #ifdef OBJ_ELF | |
29 | #include "elf/sparc.h" | |
30 | #endif | |
31 | ||
32 | static struct sparc_arch *lookup_arch PARAMS ((char *)); | |
33 | static void init_default_arch PARAMS ((void)); | |
34 | static void sparc_ip PARAMS ((char *, const struct sparc_opcode **)); | |
35 | static int in_signed_range PARAMS ((bfd_signed_vma, bfd_signed_vma)); | |
36 | static int in_unsigned_range PARAMS ((bfd_vma, bfd_vma)); | |
37 | static int in_bitfield_range PARAMS ((bfd_signed_vma, bfd_signed_vma)); | |
38 | static int sparc_ffs PARAMS ((unsigned int)); | |
39 | static bfd_vma BSR PARAMS ((bfd_vma, int)); | |
40 | static int cmp_reg_entry PARAMS ((const PTR, const PTR)); | |
41 | static int parse_keyword_arg PARAMS ((int (*) (const char *), char **, int *)); | |
42 | static int parse_const_expr_arg PARAMS ((char **, int *)); | |
43 | static int get_expression PARAMS ((char *str)); | |
44 | ||
45 | /* Default architecture. */ | |
46 | /* ??? The default value should be V8, but sparclite support was added | |
47 | by making it the default. GCC now passes -Asparclite, so maybe sometime in | |
48 | the future we can set this to V8. */ | |
49 | #ifndef DEFAULT_ARCH | |
50 | #define DEFAULT_ARCH "sparclite" | |
51 | #endif | |
52 | static char *default_arch = DEFAULT_ARCH; | |
53 | ||
54 | /* Non-zero if the initial values of `max_architecture' and `sparc_arch_size' | |
55 | have been set. */ | |
56 | static int default_init_p; | |
57 | ||
58 | /* Current architecture. We don't bump up unless necessary. */ | |
59 | static enum sparc_opcode_arch_val current_architecture = SPARC_OPCODE_ARCH_V6; | |
60 | ||
61 | /* The maximum architecture level we can bump up to. | |
62 | In a 32 bit environment, don't allow bumping up to v9 by default. | |
63 | The native assembler works this way. The user is required to pass | |
64 | an explicit argument before we'll create v9 object files. However, if | |
65 | we don't see any v9 insns, a v8plus object file is not created. */ | |
66 | static enum sparc_opcode_arch_val max_architecture; | |
67 | ||
68 | /* Either 32 or 64, selects file format. */ | |
69 | static int sparc_arch_size; | |
70 | /* Initial (default) value, recorded separately in case a user option | |
71 | changes the value before md_show_usage is called. */ | |
72 | static int default_arch_size; | |
73 | ||
74 | #ifdef OBJ_ELF | |
75 | /* The currently selected v9 memory model. Currently only used for | |
76 | ELF. */ | |
77 | static enum { MM_TSO, MM_PSO, MM_RMO } sparc_memory_model = MM_RMO; | |
78 | #endif | |
79 | ||
80 | static int architecture_requested; | |
81 | static int warn_on_bump; | |
82 | ||
83 | /* If warn_on_bump and the needed architecture is higher than this | |
84 | architecture, issue a warning. */ | |
85 | static enum sparc_opcode_arch_val warn_after_architecture; | |
86 | ||
87 | /* Non-zero if we are generating PIC code. */ | |
88 | int sparc_pic_code; | |
89 | ||
90 | /* Non-zero if we should give an error when misaligned data is seen. */ | |
91 | static int enforce_aligned_data; | |
92 | ||
93 | extern int target_big_endian; | |
94 | ||
95 | static int target_little_endian_data; | |
96 | ||
97 | /* V9 and 86x have big and little endian data, but instructions are always big | |
98 | endian. The sparclet has bi-endian support but both data and insns have | |
99 | the same endianness. Global `target_big_endian' is used for data. | |
100 | The following macro is used for instructions. */ | |
101 | #ifndef INSN_BIG_ENDIAN | |
102 | #define INSN_BIG_ENDIAN (target_big_endian \ | |
103 | || default_arch_type == sparc86x \ | |
104 | || SPARC_OPCODE_ARCH_V9_P (max_architecture)) | |
105 | #endif | |
106 | ||
107 | /* handle of the OPCODE hash table */ | |
108 | static struct hash_control *op_hash; | |
109 | ||
110 | static int log2 PARAMS ((int)); | |
111 | static void s_data1 PARAMS ((void)); | |
112 | static void s_seg PARAMS ((int)); | |
113 | static void s_proc PARAMS ((int)); | |
114 | static void s_reserve PARAMS ((int)); | |
115 | static void s_common PARAMS ((int)); | |
116 | static void s_empty PARAMS ((int)); | |
117 | static void s_uacons PARAMS ((int)); | |
118 | ||
119 | const pseudo_typeS md_pseudo_table[] = | |
120 | { | |
121 | {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */ | |
122 | {"common", s_common, 0}, | |
123 | {"empty", s_empty, 0}, | |
124 | {"global", s_globl, 0}, | |
125 | {"half", cons, 2}, | |
126 | {"optim", s_ignore, 0}, | |
127 | {"proc", s_proc, 0}, | |
128 | {"reserve", s_reserve, 0}, | |
129 | {"seg", s_seg, 0}, | |
130 | {"skip", s_space, 0}, | |
131 | {"word", cons, 4}, | |
132 | {"xword", cons, 8}, | |
133 | {"uahalf", s_uacons, 2}, | |
134 | {"uaword", s_uacons, 4}, | |
135 | {"uaxword", s_uacons, 8}, | |
136 | #ifdef OBJ_ELF | |
137 | /* these are specific to sparc/svr4 */ | |
138 | {"pushsection", obj_elf_section, 0}, | |
139 | {"popsection", obj_elf_previous, 0}, | |
140 | {"2byte", s_uacons, 2}, | |
141 | {"4byte", s_uacons, 4}, | |
142 | {"8byte", s_uacons, 8}, | |
143 | #endif | |
144 | {NULL, 0, 0}, | |
145 | }; | |
146 | ||
147 | const int md_reloc_size = 12; /* Size of relocation record */ | |
148 | ||
149 | /* This array holds the chars that always start a comment. If the | |
150 | pre-processor is disabled, these aren't very useful */ | |
151 | const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */ | |
152 | ||
153 | /* This array holds the chars that only start a comment at the beginning of | |
154 | a line. If the line seems to have the form '# 123 filename' | |
155 | .line and .file directives will appear in the pre-processed output */ | |
156 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
157 | first line of the input file. This is because the compiler outputs | |
158 | #NO_APP at the beginning of its output. */ | |
159 | /* Also note that comments started like this one will always | |
160 | work if '/' isn't otherwise defined. */ | |
161 | const char line_comment_chars[] = "#"; | |
162 | ||
163 | const char line_separator_chars[] = ""; | |
164 | ||
165 | /* Chars that can be used to separate mant from exp in floating point nums */ | |
166 | const char EXP_CHARS[] = "eE"; | |
167 | ||
168 | /* Chars that mean this number is a floating point constant */ | |
169 | /* As in 0f12.456 */ | |
170 | /* or 0d1.2345e12 */ | |
171 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
172 | ||
173 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
174 | changed in read.c. Ideally it shouldn't have to know about it at all, | |
175 | but nothing is ideal around here. */ | |
176 | ||
177 | static unsigned char octal[256]; | |
178 | #define isoctal(c) octal[(unsigned char) (c)] | |
179 | static unsigned char toHex[256]; | |
180 | ||
181 | struct sparc_it | |
182 | { | |
183 | char *error; | |
184 | unsigned long opcode; | |
185 | struct nlist *nlistp; | |
186 | expressionS exp; | |
187 | int pcrel; | |
188 | bfd_reloc_code_real_type reloc; | |
189 | }; | |
190 | ||
191 | struct sparc_it the_insn, set_insn; | |
192 | ||
193 | static void output_insn | |
194 | PARAMS ((const struct sparc_opcode *, struct sparc_it *)); | |
195 | \f | |
196 | /* Table of arguments to -A. | |
197 | The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect | |
198 | for this use. That table is for opcodes only. This table is for opcodes | |
199 | and file formats. */ | |
200 | ||
201 | enum sparc_arch_types {v6, v7, v8, sparclet, sparclite, sparc86x, v8plus, | |
202 | v8plusa, v9, v9a, v9_64}; | |
203 | ||
204 | static struct sparc_arch { | |
205 | char *name; | |
206 | char *opcode_arch; | |
207 | enum sparc_arch_types arch_type; | |
208 | /* Default word size, as specified during configuration. | |
209 | A value of zero means can't be used to specify default architecture. */ | |
210 | int default_arch_size; | |
211 | /* Allowable arg to -A? */ | |
212 | int user_option_p; | |
213 | } sparc_arch_table[] = { | |
214 | { "v6", "v6", v6, 0, 1 }, | |
215 | { "v7", "v7", v7, 0, 1 }, | |
216 | { "v8", "v8", v8, 32, 1 }, | |
217 | { "sparclet", "sparclet", sparclet, 32, 1 }, | |
218 | { "sparclite", "sparclite", sparclite, 32, 1 }, | |
219 | { "sparc86x", "sparclite", sparc86x, 32, 1 }, | |
220 | { "v8plus", "v9", v9, 0, 1 }, | |
221 | { "v8plusa", "v9a", v9, 0, 1 }, | |
222 | { "v9", "v9", v9, 0, 1 }, | |
223 | { "v9a", "v9a", v9, 0, 1 }, | |
224 | /* This exists to allow configure.in/Makefile.in to pass one | |
225 | value to specify both the default machine and default word size. */ | |
226 | { "v9-64", "v9", v9, 64, 0 }, | |
227 | { NULL, NULL, v8, 0, 0 } | |
228 | }; | |
229 | ||
230 | /* Variant of default_arch */ | |
231 | static enum sparc_arch_types default_arch_type; | |
232 | ||
233 | static struct sparc_arch * | |
234 | lookup_arch (name) | |
235 | char *name; | |
236 | { | |
237 | struct sparc_arch *sa; | |
238 | ||
239 | for (sa = &sparc_arch_table[0]; sa->name != NULL; sa++) | |
240 | if (strcmp (sa->name, name) == 0) | |
241 | break; | |
242 | if (sa->name == NULL) | |
243 | return NULL; | |
244 | return sa; | |
245 | } | |
246 | ||
247 | /* Initialize the default opcode arch and word size from the default | |
248 | architecture name. */ | |
249 | ||
250 | static void | |
251 | init_default_arch () | |
252 | { | |
253 | struct sparc_arch *sa = lookup_arch (default_arch); | |
254 | ||
255 | if (sa == NULL | |
256 | || sa->default_arch_size == 0) | |
257 | as_fatal (_("Invalid default architecture, broken assembler.")); | |
258 | ||
259 | max_architecture = sparc_opcode_lookup_arch (sa->opcode_arch); | |
260 | if (max_architecture == SPARC_OPCODE_ARCH_BAD) | |
261 | as_fatal (_("Bad opcode table, broken assembler.")); | |
262 | default_arch_size = sparc_arch_size = sa->default_arch_size; | |
263 | default_init_p = 1; | |
264 | default_arch_type = sa->arch_type; | |
265 | } | |
266 | ||
267 | /* Called by TARGET_FORMAT. */ | |
268 | ||
269 | const char * | |
270 | sparc_target_format () | |
271 | { | |
272 | /* We don't get a chance to initialize anything before we're called, | |
273 | so handle that now. */ | |
274 | if (! default_init_p) | |
275 | init_default_arch (); | |
276 | ||
277 | #ifdef OBJ_AOUT | |
278 | #ifdef TE_NetBSD | |
279 | return "a.out-sparc-netbsd"; | |
280 | #else | |
281 | #ifdef TE_SPARCAOUT | |
282 | if (target_big_endian) | |
283 | return "a.out-sunos-big"; | |
284 | else if (default_arch_type == sparc86x && target_little_endian_data) | |
285 | return "a.out-sunos-big"; | |
286 | else return "a.out-sparc-little"; | |
287 | #else | |
288 | return "a.out-sunos-big"; | |
289 | #endif | |
290 | #endif | |
291 | #endif | |
292 | ||
293 | #ifdef OBJ_BOUT | |
294 | return "b.out.big"; | |
295 | #endif | |
296 | ||
297 | #ifdef OBJ_COFF | |
298 | #ifdef TE_LYNX | |
299 | return "coff-sparc-lynx"; | |
300 | #else | |
301 | return "coff-sparc"; | |
302 | #endif | |
303 | #endif | |
304 | ||
305 | #ifdef OBJ_ELF | |
306 | return sparc_arch_size == 64 ? "elf64-sparc" : "elf32-sparc"; | |
307 | #endif | |
308 | ||
309 | abort (); | |
310 | } | |
311 | \f | |
312 | /* | |
313 | * md_parse_option | |
314 | * Invocation line includes a switch not recognized by the base assembler. | |
315 | * See if it's a processor-specific option. These are: | |
316 | * | |
317 | * -bump | |
318 | * Warn on architecture bumps. See also -A. | |
319 | * | |
320 | * -Av6, -Av7, -Av8, -Asparclite, -Asparclet | |
321 | * Standard 32 bit architectures. | |
322 | * -Av8plus, -Av8plusa | |
323 | * Sparc64 in a 32 bit world. | |
324 | * -Av9, -Av9a | |
325 | * Sparc64 in either a 32 or 64 bit world (-32/-64 says which). | |
326 | * This used to only mean 64 bits, but properly specifying it | |
327 | * complicated gcc's ASM_SPECs, so now opcode selection is | |
328 | * specified orthogonally to word size (except when specifying | |
329 | * the default, but that is an internal implementation detail). | |
330 | * -xarch=v8plus, -xarch=v8plusa | |
331 | * Same as -Av8plus{,a}, for compatibility with Sun's assembler. | |
332 | * | |
333 | * Select the architecture and possibly the file format. | |
334 | * Instructions or features not supported by the selected | |
335 | * architecture cause fatal errors. | |
336 | * | |
337 | * The default is to start at v6, and bump the architecture up | |
338 | * whenever an instruction is seen at a higher level. In 32 bit | |
339 | * environments, v9 is not bumped up to, the user must pass | |
340 | * -Av8plus{,a}. | |
341 | * | |
342 | * If -bump is specified, a warning is printing when bumping to | |
343 | * higher levels. | |
344 | * | |
345 | * If an architecture is specified, all instructions must match | |
346 | * that architecture. Any higher level instructions are flagged | |
347 | * as errors. Note that in the 32 bit environment specifying | |
348 | * -Av8plus does not automatically create a v8plus object file, a | |
349 | * v9 insn must be seen. | |
350 | * | |
351 | * If both an architecture and -bump are specified, the | |
352 | * architecture starts at the specified level, but bumps are | |
353 | * warnings. Note that we can't set `current_architecture' to | |
354 | * the requested level in this case: in the 32 bit environment, | |
355 | * we still must avoid creating v8plus object files unless v9 | |
356 | * insns are seen. | |
357 | * | |
358 | * Note: | |
359 | * Bumping between incompatible architectures is always an | |
360 | * error. For example, from sparclite to v9. | |
361 | */ | |
362 | ||
363 | #ifdef OBJ_ELF | |
364 | CONST char *md_shortopts = "A:K:VQ:sq"; | |
365 | #else | |
366 | #ifdef OBJ_AOUT | |
367 | CONST char *md_shortopts = "A:k"; | |
368 | #else | |
369 | CONST char *md_shortopts = "A:"; | |
370 | #endif | |
371 | #endif | |
372 | struct option md_longopts[] = { | |
373 | #define OPTION_BUMP (OPTION_MD_BASE) | |
374 | {"bump", no_argument, NULL, OPTION_BUMP}, | |
375 | #define OPTION_SPARC (OPTION_MD_BASE + 1) | |
376 | {"sparc", no_argument, NULL, OPTION_SPARC}, | |
377 | #define OPTION_XARCH (OPTION_MD_BASE + 2) | |
378 | {"xarch", required_argument, NULL, OPTION_XARCH}, | |
379 | #ifdef OBJ_ELF | |
380 | #define OPTION_32 (OPTION_MD_BASE + 3) | |
381 | {"32", no_argument, NULL, OPTION_32}, | |
382 | #define OPTION_64 (OPTION_MD_BASE + 4) | |
383 | {"64", no_argument, NULL, OPTION_64}, | |
384 | #define OPTION_TSO (OPTION_MD_BASE + 5) | |
385 | {"TSO", no_argument, NULL, OPTION_TSO}, | |
386 | #define OPTION_PSO (OPTION_MD_BASE + 6) | |
387 | {"PSO", no_argument, NULL, OPTION_PSO}, | |
388 | #define OPTION_RMO (OPTION_MD_BASE + 7) | |
389 | {"RMO", no_argument, NULL, OPTION_RMO}, | |
390 | #endif | |
391 | #ifdef SPARC_BIENDIAN | |
392 | #define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8) | |
393 | {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN}, | |
394 | #define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9) | |
395 | {"EB", no_argument, NULL, OPTION_BIG_ENDIAN}, | |
396 | #endif | |
397 | #define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10) | |
398 | {"enforce-aligned-data", no_argument, NULL, OPTION_ENFORCE_ALIGNED_DATA}, | |
399 | #define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11) | |
400 | {"little-endian-data", no_argument, NULL, OPTION_LITTLE_ENDIAN_DATA}, | |
401 | {NULL, no_argument, NULL, 0} | |
402 | }; | |
403 | size_t md_longopts_size = sizeof(md_longopts); | |
404 | ||
405 | int | |
406 | md_parse_option (c, arg) | |
407 | int c; | |
408 | char *arg; | |
409 | { | |
410 | /* We don't get a chance to initialize anything before we're called, | |
411 | so handle that now. */ | |
412 | if (! default_init_p) | |
413 | init_default_arch (); | |
414 | ||
415 | switch (c) | |
416 | { | |
417 | case OPTION_BUMP: | |
418 | warn_on_bump = 1; | |
419 | warn_after_architecture = SPARC_OPCODE_ARCH_V6; | |
420 | break; | |
421 | ||
422 | case OPTION_XARCH: | |
423 | /* This is for compatibility with Sun's assembler. */ | |
424 | if (strcmp (arg, "v8plus") != 0 | |
425 | && strcmp (arg, "v8plusa") != 0) | |
426 | { | |
427 | as_bad (_("invalid architecture -xarch=%s"), arg); | |
428 | return 0; | |
429 | } | |
430 | ||
431 | /* fall through */ | |
432 | ||
433 | case 'A': | |
434 | { | |
435 | struct sparc_arch *sa; | |
436 | enum sparc_opcode_arch_val opcode_arch; | |
437 | ||
438 | sa = lookup_arch (arg); | |
439 | if (sa == NULL | |
440 | || ! sa->user_option_p) | |
441 | { | |
442 | as_bad (_("invalid architecture -A%s"), arg); | |
443 | return 0; | |
444 | } | |
445 | ||
446 | opcode_arch = sparc_opcode_lookup_arch (sa->opcode_arch); | |
447 | if (opcode_arch == SPARC_OPCODE_ARCH_BAD) | |
448 | as_fatal (_("Bad opcode table, broken assembler.")); | |
449 | ||
450 | max_architecture = opcode_arch; | |
451 | architecture_requested = 1; | |
452 | } | |
453 | break; | |
454 | ||
455 | case OPTION_SPARC: | |
456 | /* Ignore -sparc, used by SunOS make default .s.o rule. */ | |
457 | break; | |
458 | ||
459 | case OPTION_ENFORCE_ALIGNED_DATA: | |
460 | enforce_aligned_data = 1; | |
461 | break; | |
462 | ||
463 | #ifdef SPARC_BIENDIAN | |
464 | case OPTION_LITTLE_ENDIAN: | |
465 | target_big_endian = 0; | |
466 | if (default_arch_type != sparclet) | |
467 | as_fatal ("This target does not support -EL"); | |
468 | break; | |
469 | case OPTION_LITTLE_ENDIAN_DATA: | |
470 | target_little_endian_data = 1; | |
471 | target_big_endian = 0; | |
472 | if (default_arch_type != sparc86x | |
473 | && default_arch_type != v9) | |
474 | as_fatal ("This target does not support --little-endian-data"); | |
475 | break; | |
476 | case OPTION_BIG_ENDIAN: | |
477 | target_big_endian = 1; | |
478 | break; | |
479 | #endif | |
480 | ||
481 | #ifdef OBJ_AOUT | |
482 | case 'k': | |
483 | sparc_pic_code = 1; | |
484 | break; | |
485 | #endif | |
486 | ||
487 | #ifdef OBJ_ELF | |
488 | case OPTION_32: | |
489 | case OPTION_64: | |
490 | { | |
491 | const char **list, **l; | |
492 | ||
493 | sparc_arch_size = c == OPTION_32 ? 32 : 64; | |
494 | list = bfd_target_list (); | |
495 | for (l = list; *l != NULL; l++) | |
496 | { | |
497 | if (sparc_arch_size == 32) | |
498 | { | |
499 | if (strcmp (*l, "elf32-sparc") == 0) | |
500 | break; | |
501 | } | |
502 | else | |
503 | { | |
504 | if (strcmp (*l, "elf64-sparc") == 0) | |
505 | break; | |
506 | } | |
507 | } | |
508 | if (*l == NULL) | |
509 | as_fatal (_("No compiled in support for %d bit object file format"), | |
510 | sparc_arch_size); | |
511 | free (list); | |
512 | } | |
513 | break; | |
514 | ||
515 | case OPTION_TSO: | |
516 | sparc_memory_model = MM_TSO; | |
517 | break; | |
518 | ||
519 | case OPTION_PSO: | |
520 | sparc_memory_model = MM_PSO; | |
521 | break; | |
522 | ||
523 | case OPTION_RMO: | |
524 | sparc_memory_model = MM_RMO; | |
525 | break; | |
526 | ||
527 | case 'V': | |
528 | print_version_id (); | |
529 | break; | |
530 | ||
531 | case 'Q': | |
532 | /* Qy - do emit .comment | |
533 | Qn - do not emit .comment */ | |
534 | break; | |
535 | ||
536 | case 's': | |
537 | /* use .stab instead of .stab.excl */ | |
538 | break; | |
539 | ||
540 | case 'q': | |
541 | /* quick -- native assembler does fewer checks */ | |
542 | break; | |
543 | ||
544 | case 'K': | |
545 | if (strcmp (arg, "PIC") != 0) | |
546 | as_warn (_("Unrecognized option following -K")); | |
547 | else | |
548 | sparc_pic_code = 1; | |
549 | break; | |
550 | #endif | |
551 | ||
552 | default: | |
553 | return 0; | |
554 | } | |
555 | ||
556 | return 1; | |
557 | } | |
558 | ||
559 | void | |
560 | md_show_usage (stream) | |
561 | FILE *stream; | |
562 | { | |
563 | const struct sparc_arch *arch; | |
564 | ||
565 | /* We don't get a chance to initialize anything before we're called, | |
566 | so handle that now. */ | |
567 | if (! default_init_p) | |
568 | init_default_arch (); | |
569 | ||
570 | fprintf(stream, _("SPARC options:\n")); | |
571 | for (arch = &sparc_arch_table[0]; arch->name; arch++) | |
572 | { | |
573 | if (arch != &sparc_arch_table[0]) | |
574 | fprintf (stream, " | "); | |
575 | if (arch->user_option_p) | |
576 | fprintf (stream, "-A%s", arch->name); | |
577 | } | |
578 | fprintf (stream, _("\n-xarch=v8plus | -xarch=v8plusa\n")); | |
579 | fprintf (stream, _("\ | |
580 | specify variant of SPARC architecture\n\ | |
581 | -bump warn when assembler switches architectures\n\ | |
582 | -sparc ignored\n\ | |
583 | --enforce-aligned-data force .long, etc., to be aligned correctly\n")); | |
584 | #ifdef OBJ_AOUT | |
585 | fprintf (stream, _("\ | |
586 | -k generate PIC\n")); | |
587 | #endif | |
588 | #ifdef OBJ_ELF | |
589 | fprintf (stream, _("\ | |
590 | -32 create 32 bit object file\n\ | |
591 | -64 create 64 bit object file\n")); | |
592 | fprintf (stream, _("\ | |
593 | [default is %d]\n"), default_arch_size); | |
594 | fprintf (stream, _("\ | |
595 | -TSO use Total Store Ordering\n\ | |
596 | -PSO use Partial Store Ordering\n\ | |
597 | -RMO use Relaxed Memory Ordering\n")); | |
598 | fprintf (stream, _("\ | |
599 | [default is %s]\n"), (default_arch_size == 64) ? "RMO" : "TSO"); | |
600 | fprintf (stream, _("\ | |
601 | -KPIC generate PIC\n\ | |
602 | -V print assembler version number\n\ | |
603 | -q ignored\n\ | |
604 | -Qy, -Qn ignored\n\ | |
605 | -s ignored\n")); | |
606 | #endif | |
607 | #ifdef SPARC_BIENDIAN | |
608 | fprintf (stream, _("\ | |
609 | -EL generate code for a little endian machine\n\ | |
610 | -EB generate code for a big endian machine\n\ | |
611 | --little-endian-data generate code for a machine having big endian\n\ | |
612 | instructions and little endian data.")); | |
613 | #endif | |
614 | } | |
615 | \f | |
616 | /* sparc64 priviledged registers */ | |
617 | ||
618 | struct priv_reg_entry | |
619 | { | |
620 | char *name; | |
621 | int regnum; | |
622 | }; | |
623 | ||
624 | struct priv_reg_entry priv_reg_table[] = | |
625 | { | |
626 | {"tpc", 0}, | |
627 | {"tnpc", 1}, | |
628 | {"tstate", 2}, | |
629 | {"tt", 3}, | |
630 | {"tick", 4}, | |
631 | {"tba", 5}, | |
632 | {"pstate", 6}, | |
633 | {"tl", 7}, | |
634 | {"pil", 8}, | |
635 | {"cwp", 9}, | |
636 | {"cansave", 10}, | |
637 | {"canrestore", 11}, | |
638 | {"cleanwin", 12}, | |
639 | {"otherwin", 13}, | |
640 | {"wstate", 14}, | |
641 | {"fq", 15}, | |
642 | {"ver", 31}, | |
643 | {"", -1}, /* end marker */ | |
644 | }; | |
645 | ||
646 | /* v9a specific asrs */ | |
647 | ||
648 | struct priv_reg_entry v9a_asr_table[] = | |
649 | { | |
650 | {"tick_cmpr", 23}, | |
651 | {"softint", 22}, | |
652 | {"set_softint", 20}, | |
653 | {"pic", 17}, | |
654 | {"pcr", 16}, | |
655 | {"gsr", 19}, | |
656 | {"dcr", 18}, | |
657 | {"clear_softint", 21}, | |
658 | {"", -1}, /* end marker */ | |
659 | }; | |
660 | ||
661 | static int | |
662 | cmp_reg_entry (parg, qarg) | |
663 | const PTR parg; | |
664 | const PTR qarg; | |
665 | { | |
666 | const struct priv_reg_entry *p = (const struct priv_reg_entry *) parg; | |
667 | const struct priv_reg_entry *q = (const struct priv_reg_entry *) qarg; | |
668 | ||
669 | return strcmp (q->name, p->name); | |
670 | } | |
671 | \f | |
672 | /* This function is called once, at assembler startup time. It should | |
673 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
674 | ||
675 | void | |
676 | md_begin () | |
677 | { | |
678 | register const char *retval = NULL; | |
679 | int lose = 0; | |
680 | register unsigned int i = 0; | |
681 | ||
682 | /* We don't get a chance to initialize anything before md_parse_option | |
683 | is called, and it may not be called, so handle default initialization | |
684 | now if not already done. */ | |
685 | if (! default_init_p) | |
686 | init_default_arch (); | |
687 | ||
688 | op_hash = hash_new (); | |
689 | ||
690 | while (i < (unsigned int) sparc_num_opcodes) | |
691 | { | |
692 | const char *name = sparc_opcodes[i].name; | |
693 | retval = hash_insert (op_hash, name, (PTR) &sparc_opcodes[i]); | |
694 | if (retval != NULL) | |
695 | { | |
696 | fprintf (stderr, _("internal error: can't hash `%s': %s\n"), | |
697 | sparc_opcodes[i].name, retval); | |
698 | lose = 1; | |
699 | } | |
700 | do | |
701 | { | |
702 | if (sparc_opcodes[i].match & sparc_opcodes[i].lose) | |
703 | { | |
704 | fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"), | |
705 | sparc_opcodes[i].name, sparc_opcodes[i].args); | |
706 | lose = 1; | |
707 | } | |
708 | ++i; | |
709 | } | |
710 | while (i < (unsigned int) sparc_num_opcodes | |
711 | && !strcmp (sparc_opcodes[i].name, name)); | |
712 | } | |
713 | ||
714 | if (lose) | |
715 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
716 | ||
717 | for (i = '0'; i < '8'; ++i) | |
718 | octal[i] = 1; | |
719 | for (i = '0'; i <= '9'; ++i) | |
720 | toHex[i] = i - '0'; | |
721 | for (i = 'a'; i <= 'f'; ++i) | |
722 | toHex[i] = i + 10 - 'a'; | |
723 | for (i = 'A'; i <= 'F'; ++i) | |
724 | toHex[i] = i + 10 - 'A'; | |
725 | ||
726 | qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]), | |
727 | sizeof (priv_reg_table[0]), cmp_reg_entry); | |
728 | ||
729 | /* If -bump, record the architecture level at which we start issuing | |
730 | warnings. The behaviour is different depending upon whether an | |
731 | architecture was explicitly specified. If it wasn't, we issue warnings | |
732 | for all upwards bumps. If it was, we don't start issuing warnings until | |
733 | we need to bump beyond the requested architecture or when we bump between | |
734 | conflicting architectures. */ | |
735 | ||
736 | if (warn_on_bump | |
737 | && architecture_requested) | |
738 | { | |
739 | /* `max_architecture' records the requested architecture. | |
740 | Issue warnings if we go above it. */ | |
741 | warn_after_architecture = max_architecture; | |
742 | ||
743 | /* Find the highest architecture level that doesn't conflict with | |
744 | the requested one. */ | |
745 | for (max_architecture = SPARC_OPCODE_ARCH_MAX; | |
746 | max_architecture > warn_after_architecture; | |
747 | --max_architecture) | |
748 | if (! SPARC_OPCODE_CONFLICT_P (max_architecture, | |
749 | warn_after_architecture)) | |
750 | break; | |
751 | } | |
752 | } | |
753 | ||
754 | /* Called after all assembly has been done. */ | |
755 | ||
756 | void | |
757 | sparc_md_end () | |
758 | { | |
759 | if (sparc_arch_size == 64) | |
760 | { | |
761 | if (current_architecture == SPARC_OPCODE_ARCH_V9A) | |
762 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v9a); | |
763 | else | |
764 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v9); | |
765 | } | |
766 | else | |
767 | { | |
768 | if (current_architecture == SPARC_OPCODE_ARCH_V9) | |
769 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v8plus); | |
770 | else if (current_architecture == SPARC_OPCODE_ARCH_V9A) | |
771 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v8plusa); | |
772 | else if (current_architecture == SPARC_OPCODE_ARCH_SPARCLET) | |
773 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_sparclet); | |
774 | else if (default_arch_type == sparc86x && target_little_endian_data) | |
775 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_sparclite_le); | |
776 | else | |
777 | { | |
778 | /* The sparclite is treated like a normal sparc. Perhaps it shouldn't | |
779 | be but for now it is (since that's the way it's always been | |
780 | treated). */ | |
781 | bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc); | |
782 | } | |
783 | } | |
784 | } | |
785 | \f | |
786 | /* Return non-zero if VAL is in the range -(MAX+1) to MAX. */ | |
787 | ||
788 | static INLINE int | |
789 | in_signed_range (val, max) | |
790 | bfd_signed_vma val, max; | |
791 | { | |
792 | if (max <= 0) | |
793 | abort (); | |
794 | /* Sign-extend the value from the architecture word size, so that | |
795 | 0xffffffff is always considered -1 on sparc32. */ | |
796 | if (sparc_arch_size == 32) | |
797 | { | |
798 | bfd_signed_vma sign = (bfd_signed_vma)1 << 31; | |
799 | val = ((val & 0xffffffff) ^ sign) - sign; | |
800 | } | |
801 | if (val > max) | |
802 | return 0; | |
803 | if (val < ~max) | |
804 | return 0; | |
805 | return 1; | |
806 | } | |
807 | ||
808 | /* Return non-zero if VAL is in the range 0 to MAX. */ | |
809 | ||
810 | static INLINE int | |
811 | in_unsigned_range (val, max) | |
812 | bfd_vma val, max; | |
813 | { | |
814 | if (val > max) | |
815 | return 0; | |
816 | return 1; | |
817 | } | |
818 | ||
819 | /* Return non-zero if VAL is in the range -(MAX/2+1) to MAX. | |
820 | (e.g. -15 to +31). */ | |
821 | ||
822 | static INLINE int | |
823 | in_bitfield_range (val, max) | |
824 | bfd_signed_vma val, max; | |
825 | { | |
826 | if (max <= 0) | |
827 | abort (); | |
828 | if (val > max) | |
829 | return 0; | |
830 | if (val < ~(max >> 1)) | |
831 | return 0; | |
832 | return 1; | |
833 | } | |
834 | ||
835 | static int | |
836 | sparc_ffs (mask) | |
837 | unsigned int mask; | |
838 | { | |
839 | int i; | |
840 | ||
841 | if (mask == 0) | |
842 | return -1; | |
843 | ||
844 | for (i = 0; (mask & 1) == 0; ++i) | |
845 | mask >>= 1; | |
846 | return i; | |
847 | } | |
848 | ||
849 | /* Implement big shift right. */ | |
850 | static bfd_vma | |
851 | BSR (val, amount) | |
852 | bfd_vma val; | |
853 | int amount; | |
854 | { | |
855 | if (sizeof (bfd_vma) <= 4 && amount >= 32) | |
856 | as_fatal (_("Support for 64-bit arithmetic not compiled in.")); | |
857 | return val >> amount; | |
858 | } | |
859 | \f | |
860 | /* For communication between sparc_ip and get_expression. */ | |
861 | static char *expr_end; | |
862 | ||
863 | /* For communication between md_assemble and sparc_ip. */ | |
864 | static int special_case; | |
865 | ||
866 | /* Values for `special_case'. | |
867 | Instructions that require wierd handling because they're longer than | |
868 | 4 bytes. */ | |
869 | #define SPECIAL_CASE_NONE 0 | |
870 | #define SPECIAL_CASE_SET 1 | |
871 | #define SPECIAL_CASE_SETSW 2 | |
872 | #define SPECIAL_CASE_SETX 3 | |
873 | /* FIXME: sparc-opc.c doesn't have necessary "S" trigger to enable this. */ | |
874 | #define SPECIAL_CASE_FDIV 4 | |
875 | ||
876 | /* Bit masks of various insns. */ | |
877 | #define NOP_INSN 0x01000000 | |
878 | #define OR_INSN 0x80100000 | |
879 | #define FMOVS_INSN 0x81A00020 | |
880 | #define SETHI_INSN 0x01000000 | |
881 | #define SLLX_INSN 0x81281000 | |
882 | #define SRA_INSN 0x81380000 | |
883 | ||
884 | /* The last instruction to be assembled. */ | |
885 | static const struct sparc_opcode *last_insn; | |
886 | /* The assembled opcode of `last_insn'. */ | |
887 | static unsigned long last_opcode; | |
888 | \f | |
889 | /* Main entry point to assemble one instruction. */ | |
890 | ||
891 | void | |
892 | md_assemble (str) | |
893 | char *str; | |
894 | { | |
895 | const struct sparc_opcode *insn; | |
896 | ||
897 | know (str); | |
898 | special_case = SPECIAL_CASE_NONE; | |
899 | sparc_ip (str, &insn); | |
900 | ||
901 | /* We warn about attempts to put a floating point branch in a delay slot, | |
902 | unless the delay slot has been annulled. */ | |
903 | if (insn != NULL | |
904 | && last_insn != NULL | |
905 | && (insn->flags & F_FBR) != 0 | |
906 | && (last_insn->flags & F_DELAYED) != 0 | |
907 | /* ??? This test isn't completely accurate. We assume anything with | |
908 | F_{UNBR,CONDBR,FBR} set is annullable. */ | |
909 | && ((last_insn->flags & (F_UNBR | F_CONDBR | F_FBR)) == 0 | |
910 | || (last_opcode & ANNUL) == 0)) | |
911 | as_warn (_("FP branch in delay slot")); | |
912 | ||
913 | /* SPARC before v9 requires a nop instruction between a floating | |
914 | point instruction and a floating point branch. We insert one | |
915 | automatically, with a warning. */ | |
916 | if (max_architecture < SPARC_OPCODE_ARCH_V9 | |
917 | && insn != NULL | |
918 | && last_insn != NULL | |
919 | && (insn->flags & F_FBR) != 0 | |
920 | && (last_insn->flags & F_FLOAT) != 0) | |
921 | { | |
922 | struct sparc_it nop_insn; | |
923 | ||
924 | nop_insn.opcode = NOP_INSN; | |
925 | nop_insn.reloc = BFD_RELOC_NONE; | |
926 | output_insn (insn, &nop_insn); | |
927 | as_warn (_("FP branch preceded by FP instruction; NOP inserted")); | |
928 | } | |
929 | ||
930 | switch (special_case) | |
931 | { | |
932 | case SPECIAL_CASE_NONE: | |
933 | /* normal insn */ | |
934 | output_insn (insn, &the_insn); | |
935 | break; | |
936 | ||
937 | case SPECIAL_CASE_SET: | |
938 | { | |
939 | int need_hi22_p = 0; | |
940 | ||
941 | /* "set" is not defined for negative numbers in v9: it doesn't yield | |
942 | what you expect it to. */ | |
943 | if (SPARC_OPCODE_ARCH_V9_P (max_architecture) | |
944 | && the_insn.exp.X_op == O_constant) | |
945 | { | |
946 | if (the_insn.exp.X_add_number < 0) | |
947 | as_warn (_("set: used with negative number")); | |
948 | else if (the_insn.exp.X_add_number > (offsetT) 0xffffffff) | |
949 | as_warn (_("set: number larger than 4294967295")); | |
950 | } | |
951 | ||
952 | /* See if operand is absolute and small; skip sethi if so. */ | |
953 | if (the_insn.exp.X_op != O_constant | |
954 | || the_insn.exp.X_add_number >= (1 << 12) | |
955 | || the_insn.exp.X_add_number < -(1 << 12)) | |
956 | { | |
957 | output_insn (insn, &the_insn); | |
958 | need_hi22_p = 1; | |
959 | } | |
960 | /* See if operand has no low-order bits; skip OR if so. */ | |
961 | if (the_insn.exp.X_op != O_constant | |
962 | || (need_hi22_p && (the_insn.exp.X_add_number & 0x3FF) != 0) | |
963 | || ! need_hi22_p) | |
964 | { | |
965 | int rd = (the_insn.opcode & RD (~0)) >> 25; | |
966 | the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (rd) : 0) | |
967 | | RD (rd) | |
968 | | IMMED | |
969 | | (the_insn.exp.X_add_number | |
970 | & (need_hi22_p ? 0x3ff : 0x1fff))); | |
971 | the_insn.reloc = (the_insn.exp.X_op != O_constant | |
972 | ? BFD_RELOC_LO10 | |
973 | : BFD_RELOC_NONE); | |
974 | output_insn (insn, &the_insn); | |
975 | } | |
976 | break; | |
977 | } | |
978 | ||
979 | case SPECIAL_CASE_SETSW: | |
980 | { | |
981 | /* FIXME: Not finished. */ | |
982 | break; | |
983 | } | |
984 | ||
985 | case SPECIAL_CASE_SETX: | |
986 | { | |
987 | #define SIGNEXT32(x) ((((x) & 0xffffffff) ^ 0x80000000) - 0x80000000) | |
988 | int upper32 = SIGNEXT32 (BSR (the_insn.exp.X_add_number, 32)); | |
989 | int lower32 = SIGNEXT32 (the_insn.exp.X_add_number); | |
990 | #undef SIGNEXT32 | |
991 | int tmpreg = (the_insn.opcode & RS1 (~0)) >> 14; | |
992 | int dstreg = (the_insn.opcode & RD (~0)) >> 25; | |
993 | /* Output directly to dst reg if lower 32 bits are all zero. */ | |
994 | int upper_dstreg = (the_insn.exp.X_op == O_constant | |
995 | && lower32 == 0) ? dstreg : tmpreg; | |
996 | int need_hh22_p = 0, need_hm10_p = 0, need_hi22_p = 0, need_lo10_p = 0; | |
997 | ||
998 | /* The tmp reg should not be the dst reg. */ | |
999 | if (tmpreg == dstreg) | |
1000 | as_warn (_("setx: temporary register same as destination register")); | |
1001 | ||
1002 | /* Reset X_add_number, we've extracted it as upper32/lower32. | |
1003 | Otherwise fixup_segment will complain about not being able to | |
1004 | write an 8 byte number in a 4 byte field. */ | |
1005 | the_insn.exp.X_add_number = 0; | |
1006 | ||
1007 | /* ??? Obviously there are other optimizations we can do | |
1008 | (e.g. sethi+shift for 0x1f0000000) and perhaps we shouldn't be | |
1009 | doing some of these. Later. If you do change things, try to | |
1010 | change all of this to be table driven as well. */ | |
1011 | ||
1012 | /* What to output depends on the number if it's constant. | |
1013 | Compute that first, then output what we've decided upon. */ | |
1014 | if (the_insn.exp.X_op != O_constant) | |
1015 | need_hh22_p = need_hm10_p = need_hi22_p = need_lo10_p = 1; | |
1016 | else | |
1017 | { | |
1018 | /* Only need hh22 if `or' insn can't handle constant. */ | |
1019 | if (upper32 < -(1 << 12) || upper32 >= (1 << 12)) | |
1020 | need_hh22_p = 1; | |
1021 | ||
1022 | /* Does bottom part (after sethi) have bits? */ | |
1023 | if ((need_hh22_p && (upper32 & 0x3ff) != 0) | |
1024 | /* No hh22, but does upper32 still have bits we can't set | |
1025 | from lower32? */ | |
1026 | || (! need_hh22_p | |
1027 | && upper32 != 0 | |
1028 | && (upper32 != -1 || lower32 >= 0))) | |
1029 | need_hm10_p = 1; | |
1030 | ||
1031 | /* If the lower half is all zero, we build the upper half directly | |
1032 | into the dst reg. */ | |
1033 | if (lower32 != 0 | |
1034 | /* Need lower half if number is zero. */ | |
1035 | || (! need_hh22_p && ! need_hm10_p)) | |
1036 | { | |
1037 | /* No need for sethi if `or' insn can handle constant. */ | |
1038 | if (lower32 < -(1 << 12) || lower32 >= (1 << 12) | |
1039 | /* Note that we can't use a negative constant in the `or' | |
1040 | insn unless the upper 32 bits are all ones. */ | |
1041 | || (lower32 < 0 && upper32 != -1)) | |
1042 | need_hi22_p = 1; | |
1043 | ||
1044 | /* Does bottom part (after sethi) have bits? */ | |
1045 | if ((need_hi22_p && (lower32 & 0x3ff) != 0) | |
1046 | /* No sethi. */ | |
1047 | || (! need_hi22_p && (lower32 & 0x1fff) != 0) | |
1048 | /* Need `or' if we didn't set anything else. */ | |
1049 | || (! need_hi22_p && ! need_hh22_p && ! need_hm10_p)) | |
1050 | need_lo10_p = 1; | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | if (need_hh22_p) | |
1055 | { | |
1056 | the_insn.opcode = (SETHI_INSN | RD (upper_dstreg) | |
1057 | | ((upper32 >> 10) & 0x3fffff)); | |
1058 | the_insn.reloc = (the_insn.exp.X_op != O_constant | |
1059 | ? BFD_RELOC_SPARC_HH22 : BFD_RELOC_NONE); | |
1060 | output_insn (insn, &the_insn); | |
1061 | } | |
1062 | ||
1063 | if (need_hm10_p) | |
1064 | { | |
1065 | the_insn.opcode = (OR_INSN | |
1066 | | (need_hh22_p ? RS1 (upper_dstreg) : 0) | |
1067 | | RD (upper_dstreg) | |
1068 | | IMMED | |
1069 | | (upper32 | |
1070 | & (need_hh22_p ? 0x3ff : 0x1fff))); | |
1071 | the_insn.reloc = (the_insn.exp.X_op != O_constant | |
1072 | ? BFD_RELOC_SPARC_HM10 : BFD_RELOC_NONE); | |
1073 | output_insn (insn, &the_insn); | |
1074 | } | |
1075 | ||
1076 | if (need_hi22_p) | |
1077 | { | |
1078 | the_insn.opcode = (SETHI_INSN | RD (dstreg) | |
1079 | | ((lower32 >> 10) & 0x3fffff)); | |
1080 | the_insn.reloc = BFD_RELOC_HI22; | |
1081 | output_insn (insn, &the_insn); | |
1082 | } | |
1083 | ||
1084 | if (need_lo10_p) | |
1085 | { | |
1086 | /* FIXME: One nice optimization to do here is to OR the low part | |
1087 | with the highpart if hi22 isn't needed and the low part is | |
1088 | positive. */ | |
1089 | the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (dstreg) : 0) | |
1090 | | RD (dstreg) | |
1091 | | IMMED | |
1092 | | (lower32 | |
1093 | & (need_hi22_p ? 0x3ff : 0x1fff))); | |
1094 | the_insn.reloc = BFD_RELOC_LO10; | |
1095 | output_insn (insn, &the_insn); | |
1096 | } | |
1097 | ||
1098 | /* If we needed to build the upper part, shift it into place. */ | |
1099 | if (need_hh22_p || need_hm10_p) | |
1100 | { | |
1101 | the_insn.opcode = (SLLX_INSN | RS1 (upper_dstreg) | RD (upper_dstreg) | |
1102 | | IMMED | 32); | |
1103 | the_insn.reloc = BFD_RELOC_NONE; | |
1104 | output_insn (insn, &the_insn); | |
1105 | } | |
1106 | ||
1107 | /* If we needed to build both upper and lower parts, OR them together. */ | |
1108 | if ((need_hh22_p || need_hm10_p) | |
1109 | && (need_hi22_p || need_lo10_p)) | |
1110 | { | |
1111 | the_insn.opcode = (OR_INSN | RS1 (dstreg) | RS2 (upper_dstreg) | |
1112 | | RD (dstreg)); | |
1113 | the_insn.reloc = BFD_RELOC_NONE; | |
1114 | output_insn (insn, &the_insn); | |
1115 | } | |
1116 | /* We didn't need both regs, but we may have to sign extend lower32. */ | |
1117 | else if (need_hi22_p && upper32 == -1) | |
1118 | { | |
1119 | the_insn.opcode = (SRA_INSN | RS1 (dstreg) | RD (dstreg) | |
1120 | | IMMED | 0); | |
1121 | the_insn.reloc = BFD_RELOC_NONE; | |
1122 | output_insn (insn, &the_insn); | |
1123 | } | |
1124 | break; | |
1125 | } | |
1126 | ||
1127 | case SPECIAL_CASE_FDIV: | |
1128 | { | |
1129 | int rd = (the_insn.opcode >> 25) & 0x1f; | |
1130 | ||
1131 | output_insn (insn, &the_insn); | |
1132 | ||
1133 | /* According to information leaked from Sun, the "fdiv" instructions | |
1134 | on early SPARC machines would produce incorrect results sometimes. | |
1135 | The workaround is to add an fmovs of the destination register to | |
1136 | itself just after the instruction. This was true on machines | |
1137 | with Weitek 1165 float chips, such as the Sun-4/260 and /280. */ | |
1138 | assert (the_insn.reloc == BFD_RELOC_NONE); | |
1139 | the_insn.opcode = FMOVS_INSN | rd | RD (rd); | |
1140 | output_insn (insn, &the_insn); | |
1141 | break; | |
1142 | } | |
1143 | ||
1144 | default: | |
1145 | as_fatal (_("failed special case insn sanity check")); | |
1146 | } | |
1147 | } | |
1148 | ||
1149 | /* Subroutine of md_assemble to do the actual parsing. */ | |
1150 | ||
1151 | static void | |
1152 | sparc_ip (str, pinsn) | |
1153 | char *str; | |
1154 | const struct sparc_opcode **pinsn; | |
1155 | { | |
1156 | char *error_message = ""; | |
1157 | char *s; | |
1158 | const char *args; | |
1159 | char c; | |
1160 | const struct sparc_opcode *insn; | |
1161 | char *argsStart; | |
1162 | unsigned long opcode; | |
1163 | unsigned int mask = 0; | |
1164 | int match = 0; | |
1165 | int comma = 0; | |
1166 | int v9_arg_p; | |
1167 | ||
1168 | s = str; | |
1169 | if (islower ((unsigned char) *s)) | |
1170 | { | |
1171 | do | |
1172 | ++s; | |
1173 | while (islower ((unsigned char) *s) || isdigit ((unsigned char) *s)); | |
1174 | } | |
1175 | ||
1176 | switch (*s) | |
1177 | { | |
1178 | case '\0': | |
1179 | break; | |
1180 | ||
1181 | case ',': | |
1182 | comma = 1; | |
1183 | ||
1184 | /*FALLTHROUGH */ | |
1185 | ||
1186 | case ' ': | |
1187 | *s++ = '\0'; | |
1188 | break; | |
1189 | ||
1190 | default: | |
1191 | as_fatal (_("Unknown opcode: `%s'"), str); | |
1192 | } | |
1193 | insn = (struct sparc_opcode *) hash_find (op_hash, str); | |
1194 | *pinsn = insn; | |
1195 | if (insn == NULL) | |
1196 | { | |
1197 | as_bad (_("Unknown opcode: `%s'"), str); | |
1198 | return; | |
1199 | } | |
1200 | if (comma) | |
1201 | { | |
1202 | *--s = ','; | |
1203 | } | |
1204 | ||
1205 | argsStart = s; | |
1206 | for (;;) | |
1207 | { | |
1208 | opcode = insn->match; | |
1209 | memset (&the_insn, '\0', sizeof (the_insn)); | |
1210 | the_insn.reloc = BFD_RELOC_NONE; | |
1211 | v9_arg_p = 0; | |
1212 | ||
1213 | /* | |
1214 | * Build the opcode, checking as we go to make | |
1215 | * sure that the operands match | |
1216 | */ | |
1217 | for (args = insn->args;; ++args) | |
1218 | { | |
1219 | switch (*args) | |
1220 | { | |
1221 | case 'K': | |
1222 | { | |
1223 | int kmask = 0; | |
1224 | ||
1225 | /* Parse a series of masks. */ | |
1226 | if (*s == '#') | |
1227 | { | |
1228 | while (*s == '#') | |
1229 | { | |
1230 | int mask; | |
1231 | ||
1232 | if (! parse_keyword_arg (sparc_encode_membar, &s, | |
1233 | &mask)) | |
1234 | { | |
1235 | error_message = _(": invalid membar mask name"); | |
1236 | goto error; | |
1237 | } | |
1238 | kmask |= mask; | |
1239 | while (*s == ' ') { ++s; continue; } | |
1240 | if (*s == '|' || *s == '+') | |
1241 | ++s; | |
1242 | while (*s == ' ') { ++s; continue; } | |
1243 | } | |
1244 | } | |
1245 | else | |
1246 | { | |
1247 | if (! parse_const_expr_arg (&s, &kmask)) | |
1248 | { | |
1249 | error_message = _(": invalid membar mask expression"); | |
1250 | goto error; | |
1251 | } | |
1252 | if (kmask < 0 || kmask > 127) | |
1253 | { | |
1254 | error_message = _(": invalid membar mask number"); | |
1255 | goto error; | |
1256 | } | |
1257 | } | |
1258 | ||
1259 | opcode |= MEMBAR (kmask); | |
1260 | continue; | |
1261 | } | |
1262 | ||
1263 | case '*': | |
1264 | { | |
1265 | int fcn = 0; | |
1266 | ||
1267 | /* Parse a prefetch function. */ | |
1268 | if (*s == '#') | |
1269 | { | |
1270 | if (! parse_keyword_arg (sparc_encode_prefetch, &s, &fcn)) | |
1271 | { | |
1272 | error_message = _(": invalid prefetch function name"); | |
1273 | goto error; | |
1274 | } | |
1275 | } | |
1276 | else | |
1277 | { | |
1278 | if (! parse_const_expr_arg (&s, &fcn)) | |
1279 | { | |
1280 | error_message = _(": invalid prefetch function expression"); | |
1281 | goto error; | |
1282 | } | |
1283 | if (fcn < 0 || fcn > 31) | |
1284 | { | |
1285 | error_message = _(": invalid prefetch function number"); | |
1286 | goto error; | |
1287 | } | |
1288 | } | |
1289 | opcode |= RD (fcn); | |
1290 | continue; | |
1291 | } | |
1292 | ||
1293 | case '!': | |
1294 | case '?': | |
1295 | /* Parse a sparc64 privileged register. */ | |
1296 | if (*s == '%') | |
1297 | { | |
1298 | struct priv_reg_entry *p = priv_reg_table; | |
1299 | unsigned int len = 9999999; /* init to make gcc happy */ | |
1300 | ||
1301 | s += 1; | |
1302 | while (p->name[0] > s[0]) | |
1303 | p++; | |
1304 | while (p->name[0] == s[0]) | |
1305 | { | |
1306 | len = strlen (p->name); | |
1307 | if (strncmp (p->name, s, len) == 0) | |
1308 | break; | |
1309 | p++; | |
1310 | } | |
1311 | if (p->name[0] != s[0]) | |
1312 | { | |
1313 | error_message = _(": unrecognizable privileged register"); | |
1314 | goto error; | |
1315 | } | |
1316 | if (*args == '?') | |
1317 | opcode |= (p->regnum << 14); | |
1318 | else | |
1319 | opcode |= (p->regnum << 25); | |
1320 | s += len; | |
1321 | continue; | |
1322 | } | |
1323 | else | |
1324 | { | |
1325 | error_message = _(": unrecognizable privileged register"); | |
1326 | goto error; | |
1327 | } | |
1328 | ||
1329 | case '_': | |
1330 | case '/': | |
1331 | /* Parse a v9a ancillary state register. */ | |
1332 | if (*s == '%') | |
1333 | { | |
1334 | struct priv_reg_entry *p = v9a_asr_table; | |
1335 | unsigned int len = 9999999; /* init to make gcc happy */ | |
1336 | ||
1337 | s += 1; | |
1338 | while (p->name[0] > s[0]) | |
1339 | p++; | |
1340 | while (p->name[0] == s[0]) | |
1341 | { | |
1342 | len = strlen (p->name); | |
1343 | if (strncmp (p->name, s, len) == 0) | |
1344 | break; | |
1345 | p++; | |
1346 | } | |
1347 | if (p->name[0] != s[0]) | |
1348 | { | |
1349 | error_message = _(": unrecognizable v9a ancillary state register"); | |
1350 | goto error; | |
1351 | } | |
1352 | if (*args == '/' && (p->regnum == 20 || p->regnum == 21)) | |
1353 | { | |
1354 | error_message = _(": rd on write only ancillary state register"); | |
1355 | goto error; | |
1356 | } | |
1357 | if (*args == '/') | |
1358 | opcode |= (p->regnum << 14); | |
1359 | else | |
1360 | opcode |= (p->regnum << 25); | |
1361 | s += len; | |
1362 | continue; | |
1363 | } | |
1364 | else | |
1365 | { | |
1366 | error_message = _(": unrecognizable v9a ancillary state register"); | |
1367 | goto error; | |
1368 | } | |
1369 | ||
1370 | case 'M': | |
1371 | case 'm': | |
1372 | if (strncmp (s, "%asr", 4) == 0) | |
1373 | { | |
1374 | s += 4; | |
1375 | ||
1376 | if (isdigit ((unsigned char) *s)) | |
1377 | { | |
1378 | long num = 0; | |
1379 | ||
1380 | while (isdigit ((unsigned char) *s)) | |
1381 | { | |
1382 | num = num * 10 + *s - '0'; | |
1383 | ++s; | |
1384 | } | |
1385 | ||
1386 | if (current_architecture >= SPARC_OPCODE_ARCH_V9) | |
1387 | { | |
1388 | if (num < 16 || 31 < num) | |
1389 | { | |
1390 | error_message = _(": asr number must be between 16 and 31"); | |
1391 | goto error; | |
1392 | } | |
1393 | } | |
1394 | else | |
1395 | { | |
1396 | if (num < 0 || 31 < num) | |
1397 | { | |
1398 | error_message = _(": asr number must be between 0 and 31"); | |
1399 | goto error; | |
1400 | } | |
1401 | } | |
1402 | ||
1403 | opcode |= (*args == 'M' ? RS1 (num) : RD (num)); | |
1404 | continue; | |
1405 | } | |
1406 | else | |
1407 | { | |
1408 | error_message = _(": expecting %asrN"); | |
1409 | goto error; | |
1410 | } | |
1411 | } /* if %asr */ | |
1412 | break; | |
1413 | ||
1414 | case 'I': | |
1415 | the_insn.reloc = BFD_RELOC_SPARC_11; | |
1416 | goto immediate; | |
1417 | ||
1418 | case 'j': | |
1419 | the_insn.reloc = BFD_RELOC_SPARC_10; | |
1420 | goto immediate; | |
1421 | ||
1422 | case 'X': | |
1423 | /* V8 systems don't understand BFD_RELOC_SPARC_5. */ | |
1424 | if (SPARC_OPCODE_ARCH_V9_P (max_architecture)) | |
1425 | the_insn.reloc = BFD_RELOC_SPARC_5; | |
1426 | else | |
1427 | the_insn.reloc = BFD_RELOC_SPARC13; | |
1428 | /* These fields are unsigned, but for upward compatibility, | |
1429 | allow negative values as well. */ | |
1430 | goto immediate; | |
1431 | ||
1432 | case 'Y': | |
1433 | /* V8 systems don't understand BFD_RELOC_SPARC_6. */ | |
1434 | if (SPARC_OPCODE_ARCH_V9_P (max_architecture)) | |
1435 | the_insn.reloc = BFD_RELOC_SPARC_6; | |
1436 | else | |
1437 | the_insn.reloc = BFD_RELOC_SPARC13; | |
1438 | /* These fields are unsigned, but for upward compatibility, | |
1439 | allow negative values as well. */ | |
1440 | goto immediate; | |
1441 | ||
1442 | case 'k': | |
1443 | the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16; | |
1444 | the_insn.pcrel = 1; | |
1445 | goto immediate; | |
1446 | ||
1447 | case 'G': | |
1448 | the_insn.reloc = BFD_RELOC_SPARC_WDISP19; | |
1449 | the_insn.pcrel = 1; | |
1450 | goto immediate; | |
1451 | ||
1452 | case 'N': | |
1453 | if (*s == 'p' && s[1] == 'n') | |
1454 | { | |
1455 | s += 2; | |
1456 | continue; | |
1457 | } | |
1458 | break; | |
1459 | ||
1460 | case 'T': | |
1461 | if (*s == 'p' && s[1] == 't') | |
1462 | { | |
1463 | s += 2; | |
1464 | continue; | |
1465 | } | |
1466 | break; | |
1467 | ||
1468 | case 'z': | |
1469 | if (*s == ' ') | |
1470 | { | |
1471 | ++s; | |
1472 | } | |
1473 | if (strncmp (s, "%icc", 4) == 0) | |
1474 | { | |
1475 | s += 4; | |
1476 | continue; | |
1477 | } | |
1478 | break; | |
1479 | ||
1480 | case 'Z': | |
1481 | if (*s == ' ') | |
1482 | { | |
1483 | ++s; | |
1484 | } | |
1485 | if (strncmp (s, "%xcc", 4) == 0) | |
1486 | { | |
1487 | s += 4; | |
1488 | continue; | |
1489 | } | |
1490 | break; | |
1491 | ||
1492 | case '6': | |
1493 | if (*s == ' ') | |
1494 | { | |
1495 | ++s; | |
1496 | } | |
1497 | if (strncmp (s, "%fcc0", 5) == 0) | |
1498 | { | |
1499 | s += 5; | |
1500 | continue; | |
1501 | } | |
1502 | break; | |
1503 | ||
1504 | case '7': | |
1505 | if (*s == ' ') | |
1506 | { | |
1507 | ++s; | |
1508 | } | |
1509 | if (strncmp (s, "%fcc1", 5) == 0) | |
1510 | { | |
1511 | s += 5; | |
1512 | continue; | |
1513 | } | |
1514 | break; | |
1515 | ||
1516 | case '8': | |
1517 | if (*s == ' ') | |
1518 | { | |
1519 | ++s; | |
1520 | } | |
1521 | if (strncmp (s, "%fcc2", 5) == 0) | |
1522 | { | |
1523 | s += 5; | |
1524 | continue; | |
1525 | } | |
1526 | break; | |
1527 | ||
1528 | case '9': | |
1529 | if (*s == ' ') | |
1530 | { | |
1531 | ++s; | |
1532 | } | |
1533 | if (strncmp (s, "%fcc3", 5) == 0) | |
1534 | { | |
1535 | s += 5; | |
1536 | continue; | |
1537 | } | |
1538 | break; | |
1539 | ||
1540 | case 'P': | |
1541 | if (strncmp (s, "%pc", 3) == 0) | |
1542 | { | |
1543 | s += 3; | |
1544 | continue; | |
1545 | } | |
1546 | break; | |
1547 | ||
1548 | case 'W': | |
1549 | if (strncmp (s, "%tick", 5) == 0) | |
1550 | { | |
1551 | s += 5; | |
1552 | continue; | |
1553 | } | |
1554 | break; | |
1555 | ||
1556 | case '\0': /* end of args */ | |
1557 | if (*s == '\0') | |
1558 | { | |
1559 | match = 1; | |
1560 | } | |
1561 | break; | |
1562 | ||
1563 | case '+': | |
1564 | if (*s == '+') | |
1565 | { | |
1566 | ++s; | |
1567 | continue; | |
1568 | } | |
1569 | if (*s == '-') | |
1570 | { | |
1571 | continue; | |
1572 | } | |
1573 | break; | |
1574 | ||
1575 | case '[': /* these must match exactly */ | |
1576 | case ']': | |
1577 | case ',': | |
1578 | case ' ': | |
1579 | if (*s++ == *args) | |
1580 | continue; | |
1581 | break; | |
1582 | ||
1583 | case '#': /* must be at least one digit */ | |
1584 | if (isdigit ((unsigned char) *s++)) | |
1585 | { | |
1586 | while (isdigit ((unsigned char) *s)) | |
1587 | { | |
1588 | ++s; | |
1589 | } | |
1590 | continue; | |
1591 | } | |
1592 | break; | |
1593 | ||
1594 | case 'C': /* coprocessor state register */ | |
1595 | if (strncmp (s, "%csr", 4) == 0) | |
1596 | { | |
1597 | s += 4; | |
1598 | continue; | |
1599 | } | |
1600 | break; | |
1601 | ||
1602 | case 'b': /* next operand is a coprocessor register */ | |
1603 | case 'c': | |
1604 | case 'D': | |
1605 | if (*s++ == '%' && *s++ == 'c' && isdigit ((unsigned char) *s)) | |
1606 | { | |
1607 | mask = *s++; | |
1608 | if (isdigit ((unsigned char) *s)) | |
1609 | { | |
1610 | mask = 10 * (mask - '0') + (*s++ - '0'); | |
1611 | if (mask >= 32) | |
1612 | { | |
1613 | break; | |
1614 | } | |
1615 | } | |
1616 | else | |
1617 | { | |
1618 | mask -= '0'; | |
1619 | } | |
1620 | switch (*args) | |
1621 | { | |
1622 | ||
1623 | case 'b': | |
1624 | opcode |= mask << 14; | |
1625 | continue; | |
1626 | ||
1627 | case 'c': | |
1628 | opcode |= mask; | |
1629 | continue; | |
1630 | ||
1631 | case 'D': | |
1632 | opcode |= mask << 25; | |
1633 | continue; | |
1634 | } | |
1635 | } | |
1636 | break; | |
1637 | ||
1638 | case 'r': /* next operand must be a register */ | |
1639 | case 'O': | |
1640 | case '1': | |
1641 | case '2': | |
1642 | case 'd': | |
1643 | if (*s++ == '%') | |
1644 | { | |
1645 | switch (c = *s++) | |
1646 | { | |
1647 | ||
1648 | case 'f': /* frame pointer */ | |
1649 | if (*s++ == 'p') | |
1650 | { | |
1651 | mask = 0x1e; | |
1652 | break; | |
1653 | } | |
1654 | goto error; | |
1655 | ||
1656 | case 'g': /* global register */ | |
1657 | if (isoctal (c = *s++)) | |
1658 | { | |
1659 | mask = c - '0'; | |
1660 | break; | |
1661 | } | |
1662 | goto error; | |
1663 | ||
1664 | case 'i': /* in register */ | |
1665 | if (isoctal (c = *s++)) | |
1666 | { | |
1667 | mask = c - '0' + 24; | |
1668 | break; | |
1669 | } | |
1670 | goto error; | |
1671 | ||
1672 | case 'l': /* local register */ | |
1673 | if (isoctal (c = *s++)) | |
1674 | { | |
1675 | mask = (c - '0' + 16); | |
1676 | break; | |
1677 | } | |
1678 | goto error; | |
1679 | ||
1680 | case 'o': /* out register */ | |
1681 | if (isoctal (c = *s++)) | |
1682 | { | |
1683 | mask = (c - '0' + 8); | |
1684 | break; | |
1685 | } | |
1686 | goto error; | |
1687 | ||
1688 | case 's': /* stack pointer */ | |
1689 | if (*s++ == 'p') | |
1690 | { | |
1691 | mask = 0xe; | |
1692 | break; | |
1693 | } | |
1694 | goto error; | |
1695 | ||
1696 | case 'r': /* any register */ | |
1697 | if (!isdigit ((unsigned char) (c = *s++))) | |
1698 | { | |
1699 | goto error; | |
1700 | } | |
1701 | /* FALLTHROUGH */ | |
1702 | case '0': | |
1703 | case '1': | |
1704 | case '2': | |
1705 | case '3': | |
1706 | case '4': | |
1707 | case '5': | |
1708 | case '6': | |
1709 | case '7': | |
1710 | case '8': | |
1711 | case '9': | |
1712 | if (isdigit ((unsigned char) *s)) | |
1713 | { | |
1714 | if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32) | |
1715 | { | |
1716 | goto error; | |
1717 | } | |
1718 | } | |
1719 | else | |
1720 | { | |
1721 | c -= '0'; | |
1722 | } | |
1723 | mask = c; | |
1724 | break; | |
1725 | ||
1726 | default: | |
1727 | goto error; | |
1728 | } | |
1729 | ||
1730 | /* Got the register, now figure out where | |
1731 | it goes in the opcode. */ | |
1732 | switch (*args) | |
1733 | { | |
1734 | case '1': | |
1735 | opcode |= mask << 14; | |
1736 | continue; | |
1737 | ||
1738 | case '2': | |
1739 | opcode |= mask; | |
1740 | continue; | |
1741 | ||
1742 | case 'd': | |
1743 | opcode |= mask << 25; | |
1744 | continue; | |
1745 | ||
1746 | case 'r': | |
1747 | opcode |= (mask << 25) | (mask << 14); | |
1748 | continue; | |
1749 | ||
1750 | case 'O': | |
1751 | opcode |= (mask << 25) | (mask << 0); | |
1752 | continue; | |
1753 | } | |
1754 | } | |
1755 | break; | |
1756 | ||
1757 | case 'e': /* next operand is a floating point register */ | |
1758 | case 'v': | |
1759 | case 'V': | |
1760 | ||
1761 | case 'f': | |
1762 | case 'B': | |
1763 | case 'R': | |
1764 | ||
1765 | case 'g': | |
1766 | case 'H': | |
1767 | case 'J': | |
1768 | { | |
1769 | char format; | |
1770 | ||
1771 | if (*s++ == '%' | |
1772 | && ((format = *s) == 'f') | |
1773 | && isdigit ((unsigned char) *++s)) | |
1774 | { | |
1775 | for (mask = 0; isdigit ((unsigned char) *s); ++s) | |
1776 | { | |
1777 | mask = 10 * mask + (*s - '0'); | |
1778 | } /* read the number */ | |
1779 | ||
1780 | if ((*args == 'v' | |
1781 | || *args == 'B' | |
1782 | || *args == 'H') | |
1783 | && (mask & 1)) | |
1784 | { | |
1785 | break; | |
1786 | } /* register must be even numbered */ | |
1787 | ||
1788 | if ((*args == 'V' | |
1789 | || *args == 'R' | |
1790 | || *args == 'J') | |
1791 | && (mask & 3)) | |
1792 | { | |
1793 | break; | |
1794 | } /* register must be multiple of 4 */ | |
1795 | ||
1796 | if (mask >= 64) | |
1797 | { | |
1798 | if (SPARC_OPCODE_ARCH_V9_P (max_architecture)) | |
1799 | error_message = _(": There are only 64 f registers; [0-63]"); | |
1800 | else | |
1801 | error_message = _(": There are only 32 f registers; [0-31]"); | |
1802 | goto error; | |
1803 | } /* on error */ | |
1804 | else if (mask >= 32) | |
1805 | { | |
1806 | if (SPARC_OPCODE_ARCH_V9_P (max_architecture)) | |
1807 | { | |
1808 | v9_arg_p = 1; | |
1809 | mask -= 31; /* wrap high bit */ | |
1810 | } | |
1811 | else | |
1812 | { | |
1813 | error_message = _(": There are only 32 f registers; [0-31]"); | |
1814 | goto error; | |
1815 | } | |
1816 | } | |
1817 | } | |
1818 | else | |
1819 | { | |
1820 | break; | |
1821 | } /* if not an 'f' register. */ | |
1822 | ||
1823 | switch (*args) | |
1824 | { | |
1825 | case 'v': | |
1826 | case 'V': | |
1827 | case 'e': | |
1828 | opcode |= RS1 (mask); | |
1829 | continue; | |
1830 | ||
1831 | ||
1832 | case 'f': | |
1833 | case 'B': | |
1834 | case 'R': | |
1835 | opcode |= RS2 (mask); | |
1836 | continue; | |
1837 | ||
1838 | case 'g': | |
1839 | case 'H': | |
1840 | case 'J': | |
1841 | opcode |= RD (mask); | |
1842 | continue; | |
1843 | } /* pack it in. */ | |
1844 | ||
1845 | know (0); | |
1846 | break; | |
1847 | } /* float arg */ | |
1848 | ||
1849 | case 'F': | |
1850 | if (strncmp (s, "%fsr", 4) == 0) | |
1851 | { | |
1852 | s += 4; | |
1853 | continue; | |
1854 | } | |
1855 | break; | |
1856 | ||
1857 | case '0': /* 64 bit immediate (setx insn) */ | |
1858 | the_insn.reloc = BFD_RELOC_NONE; /* reloc handled elsewhere */ | |
1859 | goto immediate; | |
1860 | ||
1861 | case 'h': /* high 22 bits */ | |
1862 | the_insn.reloc = BFD_RELOC_HI22; | |
1863 | goto immediate; | |
1864 | ||
1865 | case 'l': /* 22 bit PC relative immediate */ | |
1866 | the_insn.reloc = BFD_RELOC_SPARC_WDISP22; | |
1867 | the_insn.pcrel = 1; | |
1868 | goto immediate; | |
1869 | ||
1870 | case 'L': /* 30 bit immediate */ | |
1871 | the_insn.reloc = BFD_RELOC_32_PCREL_S2; | |
1872 | the_insn.pcrel = 1; | |
1873 | goto immediate; | |
1874 | ||
1875 | case 'n': /* 22 bit immediate */ | |
1876 | the_insn.reloc = BFD_RELOC_SPARC22; | |
1877 | goto immediate; | |
1878 | ||
1879 | case 'i': /* 13 bit immediate */ | |
1880 | the_insn.reloc = BFD_RELOC_SPARC13; | |
1881 | ||
1882 | /* fallthrough */ | |
1883 | ||
1884 | immediate: | |
1885 | if (*s == ' ') | |
1886 | s++; | |
1887 | ||
1888 | /* Check for %hi, etc. */ | |
1889 | if (*s == '%') | |
1890 | { | |
1891 | static struct ops { | |
1892 | /* The name as it appears in assembler. */ | |
1893 | char *name; | |
1894 | /* strlen (name), precomputed for speed */ | |
1895 | int len; | |
1896 | /* The reloc this pseudo-op translates to. */ | |
1897 | int reloc; | |
1898 | /* Non-zero if for v9 only. */ | |
1899 | int v9_p; | |
1900 | /* Non-zero if can be used in pc-relative contexts. */ | |
1901 | int pcrel_p;/*FIXME:wip*/ | |
1902 | } ops[] = { | |
1903 | /* hix/lox must appear before hi/lo so %hix won't be | |
1904 | mistaken for %hi. */ | |
1905 | { "hix", 3, BFD_RELOC_SPARC_HIX22, 1, 0 }, | |
1906 | { "lox", 3, BFD_RELOC_SPARC_LOX10, 1, 0 }, | |
1907 | { "hi", 2, BFD_RELOC_HI22, 0, 1 }, | |
1908 | { "lo", 2, BFD_RELOC_LO10, 0, 1 }, | |
1909 | { "hh", 2, BFD_RELOC_SPARC_HH22, 1, 1 }, | |
1910 | { "hm", 2, BFD_RELOC_SPARC_HM10, 1, 1 }, | |
1911 | { "lm", 2, BFD_RELOC_SPARC_LM22, 1, 1 }, | |
1912 | { "h44", 3, BFD_RELOC_SPARC_H44, 1, 0 }, | |
1913 | { "m44", 3, BFD_RELOC_SPARC_M44, 1, 0 }, | |
1914 | { "l44", 3, BFD_RELOC_SPARC_L44, 1, 0 }, | |
1915 | { "uhi", 3, BFD_RELOC_SPARC_HH22, 1, 0 }, | |
1916 | { "ulo", 3, BFD_RELOC_SPARC_HM10, 1, 0 }, | |
1917 | { NULL } | |
1918 | }; | |
1919 | struct ops *o; | |
1920 | ||
1921 | for (o = ops; o->name; o++) | |
1922 | if (strncmp (s + 1, o->name, o->len) == 0) | |
1923 | break; | |
1924 | if (o->name == NULL) | |
1925 | break; | |
1926 | ||
1927 | the_insn.reloc = o->reloc; | |
1928 | s += o->len + 1; | |
1929 | v9_arg_p = o->v9_p; | |
1930 | } | |
1931 | ||
1932 | /* Note that if the get_expression() fails, we will still | |
1933 | have created U entries in the symbol table for the | |
1934 | 'symbols' in the input string. Try not to create U | |
1935 | symbols for registers, etc. */ | |
1936 | { | |
1937 | /* This stuff checks to see if the expression ends in | |
1938 | +%reg. If it does, it removes the register from | |
1939 | the expression, and re-sets 's' to point to the | |
1940 | right place. */ | |
1941 | ||
1942 | char *s1; | |
1943 | ||
1944 | for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++) ; | |
1945 | ||
1946 | if (s1 != s && isdigit ((unsigned char) s1[-1])) | |
1947 | { | |
1948 | if (s1[-2] == '%' && s1[-3] == '+') | |
1949 | { | |
1950 | s1 -= 3; | |
1951 | *s1 = '\0'; | |
1952 | (void) get_expression (s); | |
1953 | *s1 = '+'; | |
1954 | s = s1; | |
1955 | continue; | |
1956 | } | |
1957 | else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+') | |
1958 | { | |
1959 | s1 -= 4; | |
1960 | *s1 = '\0'; | |
1961 | (void) get_expression (s); | |
1962 | *s1 = '+'; | |
1963 | s = s1; | |
1964 | continue; | |
1965 | } | |
1966 | } | |
1967 | } | |
1968 | (void) get_expression (s); | |
1969 | s = expr_end; | |
1970 | ||
1971 | /* Check for constants that don't require emitting a reloc. */ | |
1972 | if (the_insn.exp.X_op == O_constant | |
1973 | && the_insn.exp.X_add_symbol == 0 | |
1974 | && the_insn.exp.X_op_symbol == 0) | |
1975 | { | |
1976 | /* For pc-relative call instructions, we reject | |
1977 | constants to get better code. */ | |
1978 | if (the_insn.pcrel | |
1979 | && the_insn.reloc == BFD_RELOC_32_PCREL_S2 | |
1980 | && in_signed_range (the_insn.exp.X_add_number, 0x3fff)) | |
1981 | { | |
1982 | error_message = _(": PC-relative operand can't be a constant"); | |
1983 | goto error; | |
1984 | } | |
1985 | ||
1986 | /* Constants that won't fit are checked in md_apply_fix3 | |
1987 | and bfd_install_relocation. | |
1988 | ??? It would be preferable to install the constants | |
1989 | into the insn here and save having to create a fixS | |
1990 | for each one. There already exists code to handle | |
1991 | all the various cases (e.g. in md_apply_fix3 and | |
1992 | bfd_install_relocation) so duplicating all that code | |
1993 | here isn't right. */ | |
1994 | } | |
1995 | ||
1996 | continue; | |
1997 | ||
1998 | case 'a': | |
1999 | if (*s++ == 'a') | |
2000 | { | |
2001 | opcode |= ANNUL; | |
2002 | continue; | |
2003 | } | |
2004 | break; | |
2005 | ||
2006 | case 'A': | |
2007 | { | |
2008 | int asi = 0; | |
2009 | ||
2010 | /* Parse an asi. */ | |
2011 | if (*s == '#') | |
2012 | { | |
2013 | if (! parse_keyword_arg (sparc_encode_asi, &s, &asi)) | |
2014 | { | |
2015 | error_message = _(": invalid ASI name"); | |
2016 | goto error; | |
2017 | } | |
2018 | } | |
2019 | else | |
2020 | { | |
2021 | if (! parse_const_expr_arg (&s, &asi)) | |
2022 | { | |
2023 | error_message = _(": invalid ASI expression"); | |
2024 | goto error; | |
2025 | } | |
2026 | if (asi < 0 || asi > 255) | |
2027 | { | |
2028 | error_message = _(": invalid ASI number"); | |
2029 | goto error; | |
2030 | } | |
2031 | } | |
2032 | opcode |= ASI (asi); | |
2033 | continue; | |
2034 | } /* alternate space */ | |
2035 | ||
2036 | case 'p': | |
2037 | if (strncmp (s, "%psr", 4) == 0) | |
2038 | { | |
2039 | s += 4; | |
2040 | continue; | |
2041 | } | |
2042 | break; | |
2043 | ||
2044 | case 'q': /* floating point queue */ | |
2045 | if (strncmp (s, "%fq", 3) == 0) | |
2046 | { | |
2047 | s += 3; | |
2048 | continue; | |
2049 | } | |
2050 | break; | |
2051 | ||
2052 | case 'Q': /* coprocessor queue */ | |
2053 | if (strncmp (s, "%cq", 3) == 0) | |
2054 | { | |
2055 | s += 3; | |
2056 | continue; | |
2057 | } | |
2058 | break; | |
2059 | ||
2060 | case 'S': | |
2061 | if (strcmp (str, "set") == 0 | |
2062 | || strcmp (str, "setuw") == 0) | |
2063 | { | |
2064 | special_case = SPECIAL_CASE_SET; | |
2065 | continue; | |
2066 | } | |
2067 | else if (strcmp (str, "setsw") == 0) | |
2068 | { | |
2069 | special_case = SPECIAL_CASE_SETSW; | |
2070 | continue; | |
2071 | } | |
2072 | else if (strcmp (str, "setx") == 0) | |
2073 | { | |
2074 | special_case = SPECIAL_CASE_SETX; | |
2075 | continue; | |
2076 | } | |
2077 | else if (strncmp (str, "fdiv", 4) == 0) | |
2078 | { | |
2079 | special_case = SPECIAL_CASE_FDIV; | |
2080 | continue; | |
2081 | } | |
2082 | break; | |
2083 | ||
2084 | case 'o': | |
2085 | if (strncmp (s, "%asi", 4) != 0) | |
2086 | break; | |
2087 | s += 4; | |
2088 | continue; | |
2089 | ||
2090 | case 's': | |
2091 | if (strncmp (s, "%fprs", 5) != 0) | |
2092 | break; | |
2093 | s += 5; | |
2094 | continue; | |
2095 | ||
2096 | case 'E': | |
2097 | if (strncmp (s, "%ccr", 4) != 0) | |
2098 | break; | |
2099 | s += 4; | |
2100 | continue; | |
2101 | ||
2102 | case 't': | |
2103 | if (strncmp (s, "%tbr", 4) != 0) | |
2104 | break; | |
2105 | s += 4; | |
2106 | continue; | |
2107 | ||
2108 | case 'w': | |
2109 | if (strncmp (s, "%wim", 4) != 0) | |
2110 | break; | |
2111 | s += 4; | |
2112 | continue; | |
2113 | ||
2114 | case 'x': | |
2115 | { | |
2116 | char *push = input_line_pointer; | |
2117 | expressionS e; | |
2118 | ||
2119 | input_line_pointer = s; | |
2120 | expression (&e); | |
2121 | if (e.X_op == O_constant) | |
2122 | { | |
2123 | int n = e.X_add_number; | |
2124 | if (n != e.X_add_number || (n & ~0x1ff) != 0) | |
2125 | as_bad (_("OPF immediate operand out of range (0-0x1ff)")); | |
2126 | else | |
2127 | opcode |= e.X_add_number << 5; | |
2128 | } | |
2129 | else | |
2130 | as_bad (_("non-immediate OPF operand, ignored")); | |
2131 | s = input_line_pointer; | |
2132 | input_line_pointer = push; | |
2133 | continue; | |
2134 | } | |
2135 | ||
2136 | case 'y': | |
2137 | if (strncmp (s, "%y", 2) != 0) | |
2138 | break; | |
2139 | s += 2; | |
2140 | continue; | |
2141 | ||
2142 | case 'u': | |
2143 | case 'U': | |
2144 | { | |
2145 | /* Parse a sparclet cpreg. */ | |
2146 | int cpreg; | |
2147 | if (! parse_keyword_arg (sparc_encode_sparclet_cpreg, &s, &cpreg)) | |
2148 | { | |
2149 | error_message = _(": invalid cpreg name"); | |
2150 | goto error; | |
2151 | } | |
2152 | opcode |= (*args == 'U' ? RS1 (cpreg) : RD (cpreg)); | |
2153 | continue; | |
2154 | } | |
2155 | ||
2156 | default: | |
2157 | as_fatal (_("failed sanity check.")); | |
2158 | } /* switch on arg code */ | |
2159 | ||
2160 | /* Break out of for() loop. */ | |
2161 | break; | |
2162 | } /* for each arg that we expect */ | |
2163 | ||
2164 | error: | |
2165 | if (match == 0) | |
2166 | { | |
2167 | /* Args don't match. */ | |
2168 | if (&insn[1] - sparc_opcodes < sparc_num_opcodes | |
2169 | && (insn->name == insn[1].name | |
2170 | || !strcmp (insn->name, insn[1].name))) | |
2171 | { | |
2172 | ++insn; | |
2173 | s = argsStart; | |
2174 | continue; | |
2175 | } | |
2176 | else | |
2177 | { | |
2178 | as_bad (_("Illegal operands%s"), error_message); | |
2179 | return; | |
2180 | } | |
2181 | } | |
2182 | else | |
2183 | { | |
2184 | /* We have a match. Now see if the architecture is ok. */ | |
2185 | int needed_arch_mask = insn->architecture; | |
2186 | ||
2187 | if (v9_arg_p) | |
2188 | { | |
2189 | needed_arch_mask &= ~ ((1 << SPARC_OPCODE_ARCH_V9) | |
2190 | | (1 << SPARC_OPCODE_ARCH_V9A)); | |
2191 | needed_arch_mask |= (1 << SPARC_OPCODE_ARCH_V9); | |
2192 | } | |
2193 | ||
2194 | if (needed_arch_mask & SPARC_OPCODE_SUPPORTED (current_architecture)) | |
2195 | ; /* ok */ | |
2196 | /* Can we bump up the architecture? */ | |
2197 | else if (needed_arch_mask & SPARC_OPCODE_SUPPORTED (max_architecture)) | |
2198 | { | |
2199 | enum sparc_opcode_arch_val needed_architecture = | |
2200 | sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture) | |
2201 | & needed_arch_mask); | |
2202 | ||
2203 | assert (needed_architecture <= SPARC_OPCODE_ARCH_MAX); | |
2204 | if (warn_on_bump | |
2205 | && needed_architecture > warn_after_architecture) | |
2206 | { | |
2207 | as_warn (_("architecture bumped from \"%s\" to \"%s\" on \"%s\""), | |
2208 | sparc_opcode_archs[current_architecture].name, | |
2209 | sparc_opcode_archs[needed_architecture].name, | |
2210 | str); | |
2211 | warn_after_architecture = needed_architecture; | |
2212 | } | |
2213 | current_architecture = needed_architecture; | |
2214 | } | |
2215 | /* Conflict. */ | |
2216 | /* ??? This seems to be a bit fragile. What if the next entry in | |
2217 | the opcode table is the one we want and it is supported? | |
2218 | It is possible to arrange the table today so that this can't | |
2219 | happen but what about tomorrow? */ | |
2220 | else | |
2221 | { | |
2222 | int arch,printed_one_p = 0; | |
2223 | char *p; | |
2224 | char required_archs[SPARC_OPCODE_ARCH_MAX * 16]; | |
2225 | ||
2226 | /* Create a list of the architectures that support the insn. */ | |
2227 | needed_arch_mask &= ~ SPARC_OPCODE_SUPPORTED (max_architecture); | |
2228 | p = required_archs; | |
2229 | arch = sparc_ffs (needed_arch_mask); | |
2230 | while ((1 << arch) <= needed_arch_mask) | |
2231 | { | |
2232 | if ((1 << arch) & needed_arch_mask) | |
2233 | { | |
2234 | if (printed_one_p) | |
2235 | *p++ = '|'; | |
2236 | strcpy (p, sparc_opcode_archs[arch].name); | |
2237 | p += strlen (p); | |
2238 | printed_one_p = 1; | |
2239 | } | |
2240 | ++arch; | |
2241 | } | |
2242 | ||
2243 | as_bad (_("Architecture mismatch on \"%s\"."), str); | |
2244 | as_tsktsk (_(" (Requires %s; requested architecture is %s.)"), | |
2245 | required_archs, | |
2246 | sparc_opcode_archs[max_architecture].name); | |
2247 | return; | |
2248 | } | |
2249 | } /* if no match */ | |
2250 | ||
2251 | break; | |
2252 | } /* forever looking for a match */ | |
2253 | ||
2254 | the_insn.opcode = opcode; | |
2255 | } | |
2256 | ||
2257 | /* Parse an argument that can be expressed as a keyword. | |
2258 | (eg: #StoreStore or %ccfr). | |
2259 | The result is a boolean indicating success. | |
2260 | If successful, INPUT_POINTER is updated. */ | |
2261 | ||
2262 | static int | |
2263 | parse_keyword_arg (lookup_fn, input_pointerP, valueP) | |
2264 | int (*lookup_fn) PARAMS ((const char *)); | |
2265 | char **input_pointerP; | |
2266 | int *valueP; | |
2267 | { | |
2268 | int value; | |
2269 | char c, *p, *q; | |
2270 | ||
2271 | p = *input_pointerP; | |
2272 | for (q = p + (*p == '#' || *p == '%'); | |
2273 | isalnum ((unsigned char) *q) || *q == '_'; | |
2274 | ++q) | |
2275 | continue; | |
2276 | c = *q; | |
2277 | *q = 0; | |
2278 | value = (*lookup_fn) (p); | |
2279 | *q = c; | |
2280 | if (value == -1) | |
2281 | return 0; | |
2282 | *valueP = value; | |
2283 | *input_pointerP = q; | |
2284 | return 1; | |
2285 | } | |
2286 | ||
2287 | /* Parse an argument that is a constant expression. | |
2288 | The result is a boolean indicating success. */ | |
2289 | ||
2290 | static int | |
2291 | parse_const_expr_arg (input_pointerP, valueP) | |
2292 | char **input_pointerP; | |
2293 | int *valueP; | |
2294 | { | |
2295 | char *save = input_line_pointer; | |
2296 | expressionS exp; | |
2297 | ||
2298 | input_line_pointer = *input_pointerP; | |
2299 | /* The next expression may be something other than a constant | |
2300 | (say if we're not processing the right variant of the insn). | |
2301 | Don't call expression unless we're sure it will succeed as it will | |
2302 | signal an error (which we want to defer until later). */ | |
2303 | /* FIXME: It might be better to define md_operand and have it recognize | |
2304 | things like %asi, etc. but continuing that route through to the end | |
2305 | is a lot of work. */ | |
2306 | if (*input_line_pointer == '%') | |
2307 | { | |
2308 | input_line_pointer = save; | |
2309 | return 0; | |
2310 | } | |
2311 | expression (&exp); | |
2312 | *input_pointerP = input_line_pointer; | |
2313 | input_line_pointer = save; | |
2314 | if (exp.X_op != O_constant) | |
2315 | return 0; | |
2316 | *valueP = exp.X_add_number; | |
2317 | return 1; | |
2318 | } | |
2319 | ||
2320 | /* Subroutine of sparc_ip to parse an expression. */ | |
2321 | ||
2322 | static int | |
2323 | get_expression (str) | |
2324 | char *str; | |
2325 | { | |
2326 | char *save_in; | |
2327 | segT seg; | |
2328 | ||
2329 | save_in = input_line_pointer; | |
2330 | input_line_pointer = str; | |
2331 | seg = expression (&the_insn.exp); | |
2332 | if (seg != absolute_section | |
2333 | && seg != text_section | |
2334 | && seg != data_section | |
2335 | && seg != bss_section | |
2336 | && seg != undefined_section) | |
2337 | { | |
2338 | the_insn.error = _("bad segment"); | |
2339 | expr_end = input_line_pointer; | |
2340 | input_line_pointer = save_in; | |
2341 | return 1; | |
2342 | } | |
2343 | expr_end = input_line_pointer; | |
2344 | input_line_pointer = save_in; | |
2345 | return 0; | |
2346 | } | |
2347 | ||
2348 | /* Subroutine of md_assemble to output one insn. */ | |
2349 | ||
2350 | static void | |
2351 | output_insn (insn, the_insn) | |
2352 | const struct sparc_opcode *insn; | |
2353 | struct sparc_it *the_insn; | |
2354 | { | |
2355 | char *toP = frag_more (4); | |
2356 | ||
2357 | /* put out the opcode */ | |
2358 | if (INSN_BIG_ENDIAN) | |
2359 | number_to_chars_bigendian (toP, (valueT) the_insn->opcode, 4); | |
2360 | else | |
2361 | number_to_chars_littleendian (toP, (valueT) the_insn->opcode, 4); | |
2362 | ||
2363 | /* put out the symbol-dependent stuff */ | |
2364 | if (the_insn->reloc != BFD_RELOC_NONE) | |
2365 | { | |
2366 | fixS *fixP = fix_new_exp (frag_now, /* which frag */ | |
2367 | (toP - frag_now->fr_literal), /* where */ | |
2368 | 4, /* size */ | |
2369 | &the_insn->exp, | |
2370 | the_insn->pcrel, | |
2371 | the_insn->reloc); | |
2372 | /* Turn off overflow checking in fixup_segment. We'll do our | |
2373 | own overflow checking in md_apply_fix3. This is necessary because | |
2374 | the insn size is 4 and fixup_segment will signal an overflow for | |
2375 | large 8 byte quantities. */ | |
2376 | fixP->fx_no_overflow = 1; | |
2377 | } | |
2378 | ||
2379 | last_insn = insn; | |
2380 | last_opcode = the_insn->opcode; | |
2381 | } | |
2382 | \f | |
2383 | /* | |
2384 | This is identical to the md_atof in m68k.c. I think this is right, | |
2385 | but I'm not sure. | |
2386 | ||
2387 | Turn a string in input_line_pointer into a floating point constant of type | |
2388 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
2389 | emitted is stored in *sizeP . An error message is returned, or NULL on OK. | |
2390 | */ | |
2391 | ||
2392 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
2393 | #define MAX_LITTLENUMS 6 | |
2394 | ||
2395 | char * | |
2396 | md_atof (type, litP, sizeP) | |
2397 | char type; | |
2398 | char *litP; | |
2399 | int *sizeP; | |
2400 | { | |
2401 | int i,prec; | |
2402 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
2403 | char *t; | |
2404 | ||
2405 | switch (type) | |
2406 | { | |
2407 | case 'f': | |
2408 | case 'F': | |
2409 | case 's': | |
2410 | case 'S': | |
2411 | prec = 2; | |
2412 | break; | |
2413 | ||
2414 | case 'd': | |
2415 | case 'D': | |
2416 | case 'r': | |
2417 | case 'R': | |
2418 | prec = 4; | |
2419 | break; | |
2420 | ||
2421 | case 'x': | |
2422 | case 'X': | |
2423 | prec = 6; | |
2424 | break; | |
2425 | ||
2426 | case 'p': | |
2427 | case 'P': | |
2428 | prec = 6; | |
2429 | break; | |
2430 | ||
2431 | default: | |
2432 | *sizeP = 0; | |
2433 | return _("Bad call to MD_ATOF()"); | |
2434 | } | |
2435 | ||
2436 | t = atof_ieee (input_line_pointer, type, words); | |
2437 | if (t) | |
2438 | input_line_pointer = t; | |
2439 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
2440 | ||
2441 | if (target_big_endian) | |
2442 | { | |
2443 | for (i = 0; i < prec; i++) | |
2444 | { | |
2445 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
2446 | litP += sizeof (LITTLENUM_TYPE); | |
2447 | } | |
2448 | } | |
2449 | else | |
2450 | { | |
2451 | for (i = prec - 1; i >= 0; i--) | |
2452 | { | |
2453 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
2454 | litP += sizeof (LITTLENUM_TYPE); | |
2455 | } | |
2456 | } | |
2457 | ||
2458 | return 0; | |
2459 | } | |
2460 | ||
2461 | /* Write a value out to the object file, using the appropriate | |
2462 | endianness. */ | |
2463 | ||
2464 | void | |
2465 | md_number_to_chars (buf, val, n) | |
2466 | char *buf; | |
2467 | valueT val; | |
2468 | int n; | |
2469 | { | |
2470 | if (target_big_endian) | |
2471 | number_to_chars_bigendian (buf, val, n); | |
2472 | else if (target_little_endian_data | |
2473 | && ((n == 4 || n == 2) && ~now_seg->flags & SEC_ALLOC)) | |
2474 | /* Output debug words, which are not in allocated sections, as big endian */ | |
2475 | number_to_chars_bigendian (buf, val, n); | |
2476 | else if (target_little_endian_data || ! target_big_endian) | |
2477 | number_to_chars_littleendian (buf, val, n); | |
2478 | } | |
2479 | \f | |
2480 | /* Apply a fixS to the frags, now that we know the value it ought to | |
2481 | hold. */ | |
2482 | ||
2483 | int | |
2484 | md_apply_fix3 (fixP, value, segment) | |
2485 | fixS *fixP; | |
2486 | valueT *value; | |
2487 | segT segment; | |
2488 | { | |
2489 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
2490 | offsetT val; | |
2491 | long insn; | |
2492 | ||
2493 | val = *value; | |
2494 | ||
2495 | assert (fixP->fx_r_type < BFD_RELOC_UNUSED); | |
2496 | ||
2497 | fixP->fx_addnumber = val; /* Remember value for emit_reloc */ | |
2498 | ||
2499 | #ifdef OBJ_ELF | |
2500 | /* FIXME: SPARC ELF relocations don't use an addend in the data | |
2501 | field itself. This whole approach should be somehow combined | |
2502 | with the calls to bfd_install_relocation. Also, the value passed | |
2503 | in by fixup_segment includes the value of a defined symbol. We | |
2504 | don't want to include the value of an externally visible symbol. */ | |
2505 | if (fixP->fx_addsy != NULL) | |
2506 | { | |
49309057 | 2507 | if (symbol_used_in_reloc_p (fixP->fx_addsy) |
252b5132 RH |
2508 | && (S_IS_EXTERNAL (fixP->fx_addsy) |
2509 | || S_IS_WEAK (fixP->fx_addsy) | |
2510 | || (sparc_pic_code && ! fixP->fx_pcrel) | |
2511 | || (S_GET_SEGMENT (fixP->fx_addsy) != segment | |
2512 | && ((bfd_get_section_flags (stdoutput, | |
2513 | S_GET_SEGMENT (fixP->fx_addsy)) | |
2514 | & SEC_LINK_ONCE) != 0 | |
2515 | || strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)), | |
2516 | ".gnu.linkonce", | |
2517 | sizeof ".gnu.linkonce" - 1) == 0))) | |
2518 | && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section | |
2519 | && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section | |
2520 | && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy))) | |
2521 | fixP->fx_addnumber -= S_GET_VALUE (fixP->fx_addsy); | |
2522 | return 1; | |
2523 | } | |
2524 | #endif | |
2525 | ||
2526 | /* This is a hack. There should be a better way to | |
2527 | handle this. Probably in terms of howto fields, once | |
2528 | we can look at these fixups in terms of howtos. */ | |
2529 | if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy) | |
2530 | val += fixP->fx_where + fixP->fx_frag->fr_address; | |
2531 | ||
2532 | #ifdef OBJ_AOUT | |
2533 | /* FIXME: More ridiculous gas reloc hacking. If we are going to | |
2534 | generate a reloc, then we just want to let the reloc addend set | |
2535 | the value. We do not want to also stuff the addend into the | |
2536 | object file. Including the addend in the object file works when | |
2537 | doing a static link, because the linker will ignore the object | |
2538 | file contents. However, the dynamic linker does not ignore the | |
2539 | object file contents. */ | |
2540 | if (fixP->fx_addsy != NULL | |
2541 | && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2) | |
2542 | val = 0; | |
2543 | ||
2544 | /* When generating PIC code, we do not want an addend for a reloc | |
2545 | against a local symbol. We adjust fx_addnumber to cancel out the | |
2546 | value already included in val, and to also cancel out the | |
2547 | adjustment which bfd_install_relocation will create. */ | |
2548 | if (sparc_pic_code | |
2549 | && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2 | |
2550 | && fixP->fx_addsy != NULL | |
2551 | && ! S_IS_COMMON (fixP->fx_addsy) | |
49309057 | 2552 | && symbol_section_p (fixP->fx_addsy)) |
252b5132 RH |
2553 | fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy); |
2554 | ||
2555 | /* When generating PIC code, we need to fiddle to get | |
2556 | bfd_install_relocation to do the right thing for a PC relative | |
2557 | reloc against a local symbol which we are going to keep. */ | |
2558 | if (sparc_pic_code | |
2559 | && fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 | |
2560 | && fixP->fx_addsy != NULL | |
2561 | && (S_IS_EXTERNAL (fixP->fx_addsy) | |
2562 | || S_IS_WEAK (fixP->fx_addsy)) | |
2563 | && S_IS_DEFINED (fixP->fx_addsy) | |
2564 | && ! S_IS_COMMON (fixP->fx_addsy)) | |
2565 | { | |
2566 | val = 0; | |
2567 | fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy); | |
2568 | } | |
2569 | #endif | |
2570 | ||
2571 | /* If this is a data relocation, just output VAL. */ | |
2572 | ||
2573 | if (fixP->fx_r_type == BFD_RELOC_16) | |
2574 | { | |
2575 | md_number_to_chars (buf, val, 2); | |
2576 | } | |
2577 | else if (fixP->fx_r_type == BFD_RELOC_32 | |
2578 | || fixP->fx_r_type == BFD_RELOC_SPARC_REV32) | |
2579 | { | |
2580 | md_number_to_chars (buf, val, 4); | |
2581 | } | |
2582 | else if (fixP->fx_r_type == BFD_RELOC_64) | |
2583 | { | |
2584 | md_number_to_chars (buf, val, 8); | |
2585 | } | |
2586 | else if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
2587 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
2588 | { | |
2589 | fixP->fx_done = 0; | |
2590 | return 1; | |
2591 | } | |
2592 | else | |
2593 | { | |
2594 | /* It's a relocation against an instruction. */ | |
2595 | ||
2596 | if (INSN_BIG_ENDIAN) | |
2597 | insn = bfd_getb32 ((unsigned char *) buf); | |
2598 | else | |
2599 | insn = bfd_getl32 ((unsigned char *) buf); | |
2600 | ||
2601 | switch (fixP->fx_r_type) | |
2602 | { | |
2603 | case BFD_RELOC_32_PCREL_S2: | |
2604 | val = val >> 2; | |
2605 | /* FIXME: This increment-by-one deserves a comment of why it's | |
2606 | being done! */ | |
2607 | if (! sparc_pic_code | |
2608 | || fixP->fx_addsy == NULL | |
49309057 | 2609 | || symbol_section_p (fixP->fx_addsy)) |
252b5132 RH |
2610 | ++val; |
2611 | insn |= val & 0x3fffffff; | |
2612 | break; | |
2613 | ||
2614 | case BFD_RELOC_SPARC_11: | |
2615 | if (! in_signed_range (val, 0x7ff)) | |
2616 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2617 | _("relocation overflow")); | |
2618 | insn |= val & 0x7ff; | |
2619 | break; | |
2620 | ||
2621 | case BFD_RELOC_SPARC_10: | |
2622 | if (! in_signed_range (val, 0x3ff)) | |
2623 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2624 | _("relocation overflow")); | |
2625 | insn |= val & 0x3ff; | |
2626 | break; | |
2627 | ||
2628 | case BFD_RELOC_SPARC_7: | |
2629 | if (! in_bitfield_range (val, 0x7f)) | |
2630 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2631 | _("relocation overflow")); | |
2632 | insn |= val & 0x7f; | |
2633 | break; | |
2634 | ||
2635 | case BFD_RELOC_SPARC_6: | |
2636 | if (! in_bitfield_range (val, 0x3f)) | |
2637 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2638 | _("relocation overflow")); | |
2639 | insn |= val & 0x3f; | |
2640 | break; | |
2641 | ||
2642 | case BFD_RELOC_SPARC_5: | |
2643 | if (! in_bitfield_range (val, 0x1f)) | |
2644 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2645 | _("relocation overflow")); | |
2646 | insn |= val & 0x1f; | |
2647 | break; | |
2648 | ||
2649 | case BFD_RELOC_SPARC_WDISP16: | |
2650 | /* FIXME: simplify */ | |
2651 | if (((val > 0) && (val & ~0x3fffc)) | |
2652 | || ((val < 0) && (~(val - 1) & ~0x3fffc))) | |
2653 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2654 | _("relocation overflow")); | |
2655 | /* FIXME: The +1 deserves a comment. */ | |
2656 | val = (val >> 2) + 1; | |
2657 | insn |= ((val & 0xc000) << 6) | (val & 0x3fff); | |
2658 | break; | |
2659 | ||
2660 | case BFD_RELOC_SPARC_WDISP19: | |
2661 | /* FIXME: simplify */ | |
2662 | if (((val > 0) && (val & ~0x1ffffc)) | |
2663 | || ((val < 0) && (~(val - 1) & ~0x1ffffc))) | |
2664 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2665 | _("relocation overflow")); | |
2666 | /* FIXME: The +1 deserves a comment. */ | |
2667 | val = (val >> 2) + 1; | |
2668 | insn |= val & 0x7ffff; | |
2669 | break; | |
2670 | ||
2671 | case BFD_RELOC_SPARC_HH22: | |
2672 | val = BSR (val, 32); | |
2673 | /* intentional fallthrough */ | |
2674 | ||
2675 | case BFD_RELOC_SPARC_LM22: | |
2676 | case BFD_RELOC_HI22: | |
2677 | if (!fixP->fx_addsy) | |
2678 | { | |
2679 | insn |= (val >> 10) & 0x3fffff; | |
2680 | } | |
2681 | else | |
2682 | { | |
2683 | /* FIXME: Need comment explaining why we do this. */ | |
2684 | insn &= ~0xffff; | |
2685 | } | |
2686 | break; | |
2687 | ||
2688 | case BFD_RELOC_SPARC22: | |
2689 | if (val & ~0x003fffff) | |
2690 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2691 | _("relocation overflow")); | |
2692 | insn |= (val & 0x3fffff); | |
2693 | break; | |
2694 | ||
2695 | case BFD_RELOC_SPARC_HM10: | |
2696 | val = BSR (val, 32); | |
2697 | /* intentional fallthrough */ | |
2698 | ||
2699 | case BFD_RELOC_LO10: | |
2700 | if (!fixP->fx_addsy) | |
2701 | { | |
2702 | insn |= val & 0x3ff; | |
2703 | } | |
2704 | else | |
2705 | { | |
2706 | /* FIXME: Need comment explaining why we do this. */ | |
2707 | insn &= ~0xff; | |
2708 | } | |
2709 | break; | |
2710 | ||
2711 | case BFD_RELOC_SPARC13: | |
2712 | if (! in_signed_range (val, 0x1fff)) | |
2713 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2714 | _("relocation overflow")); | |
2715 | insn |= val & 0x1fff; | |
2716 | break; | |
2717 | ||
2718 | case BFD_RELOC_SPARC_WDISP22: | |
2719 | val = (val >> 2) + 1; | |
2720 | /* FALLTHROUGH */ | |
2721 | case BFD_RELOC_SPARC_BASE22: | |
2722 | insn |= val & 0x3fffff; | |
2723 | break; | |
2724 | ||
2725 | case BFD_RELOC_SPARC_H44: | |
2726 | if (!fixP->fx_addsy) | |
2727 | { | |
2728 | bfd_vma tval = val; | |
2729 | tval >>= 22; | |
2730 | insn |= tval & 0x3fffff; | |
2731 | } | |
2732 | break; | |
2733 | ||
2734 | case BFD_RELOC_SPARC_M44: | |
2735 | if (!fixP->fx_addsy) | |
2736 | insn |= (val >> 12) & 0x3ff; | |
2737 | break; | |
2738 | ||
2739 | case BFD_RELOC_SPARC_L44: | |
2740 | if (!fixP->fx_addsy) | |
2741 | insn |= val & 0xfff; | |
2742 | break; | |
2743 | ||
2744 | case BFD_RELOC_SPARC_HIX22: | |
2745 | if (!fixP->fx_addsy) | |
2746 | { | |
2747 | val ^= ~ (offsetT) 0; | |
2748 | insn |= (val >> 10) & 0x3fffff; | |
2749 | } | |
2750 | break; | |
2751 | ||
2752 | case BFD_RELOC_SPARC_LOX10: | |
2753 | if (!fixP->fx_addsy) | |
2754 | insn |= 0x1c00 | (val & 0x3ff); | |
2755 | break; | |
2756 | ||
2757 | case BFD_RELOC_NONE: | |
2758 | default: | |
2759 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2760 | _("bad or unhandled relocation type: 0x%02x"), | |
2761 | fixP->fx_r_type); | |
2762 | break; | |
2763 | } | |
2764 | ||
2765 | if (INSN_BIG_ENDIAN) | |
2766 | bfd_putb32 (insn, (unsigned char *) buf); | |
2767 | else | |
2768 | bfd_putl32 (insn, (unsigned char *) buf); | |
2769 | } | |
2770 | ||
2771 | /* Are we finished with this relocation now? */ | |
2772 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) | |
2773 | fixP->fx_done = 1; | |
2774 | ||
2775 | return 1; | |
2776 | } | |
2777 | ||
2778 | /* Translate internal representation of relocation info to BFD target | |
2779 | format. */ | |
2780 | arelent * | |
2781 | tc_gen_reloc (section, fixp) | |
2782 | asection *section; | |
2783 | fixS *fixp; | |
2784 | { | |
2785 | arelent *reloc; | |
2786 | bfd_reloc_code_real_type code; | |
2787 | ||
2788 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
2789 | ||
49309057 ILT |
2790 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
2791 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
2792 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
2793 | ||
2794 | switch (fixp->fx_r_type) | |
2795 | { | |
2796 | case BFD_RELOC_16: | |
2797 | case BFD_RELOC_32: | |
2798 | case BFD_RELOC_HI22: | |
2799 | case BFD_RELOC_LO10: | |
2800 | case BFD_RELOC_32_PCREL_S2: | |
2801 | case BFD_RELOC_SPARC13: | |
2802 | case BFD_RELOC_SPARC_BASE13: | |
2803 | case BFD_RELOC_SPARC_WDISP16: | |
2804 | case BFD_RELOC_SPARC_WDISP19: | |
2805 | case BFD_RELOC_SPARC_WDISP22: | |
2806 | case BFD_RELOC_64: | |
2807 | case BFD_RELOC_SPARC_5: | |
2808 | case BFD_RELOC_SPARC_6: | |
2809 | case BFD_RELOC_SPARC_7: | |
2810 | case BFD_RELOC_SPARC_10: | |
2811 | case BFD_RELOC_SPARC_11: | |
2812 | case BFD_RELOC_SPARC_HH22: | |
2813 | case BFD_RELOC_SPARC_HM10: | |
2814 | case BFD_RELOC_SPARC_LM22: | |
2815 | case BFD_RELOC_SPARC_PC_HH22: | |
2816 | case BFD_RELOC_SPARC_PC_HM10: | |
2817 | case BFD_RELOC_SPARC_PC_LM22: | |
2818 | case BFD_RELOC_SPARC_H44: | |
2819 | case BFD_RELOC_SPARC_M44: | |
2820 | case BFD_RELOC_SPARC_L44: | |
2821 | case BFD_RELOC_SPARC_HIX22: | |
2822 | case BFD_RELOC_SPARC_LOX10: | |
2823 | case BFD_RELOC_SPARC_REV32: | |
2824 | case BFD_RELOC_VTABLE_ENTRY: | |
2825 | case BFD_RELOC_VTABLE_INHERIT: | |
2826 | code = fixp->fx_r_type; | |
2827 | break; | |
2828 | default: | |
2829 | abort (); | |
2830 | return NULL; | |
2831 | } | |
2832 | ||
2833 | #if defined (OBJ_ELF) || defined (OBJ_AOUT) | |
2834 | /* If we are generating PIC code, we need to generate a different | |
2835 | set of relocs. */ | |
2836 | ||
2837 | #ifdef OBJ_ELF | |
2838 | #define GOT_NAME "_GLOBAL_OFFSET_TABLE_" | |
2839 | #else | |
2840 | #define GOT_NAME "__GLOBAL_OFFSET_TABLE_" | |
2841 | #endif | |
2842 | ||
2843 | if (sparc_pic_code) | |
2844 | { | |
2845 | switch (code) | |
2846 | { | |
2847 | case BFD_RELOC_32_PCREL_S2: | |
2848 | if (! S_IS_DEFINED (fixp->fx_addsy) | |
2849 | || S_IS_COMMON (fixp->fx_addsy) | |
2850 | || S_IS_EXTERNAL (fixp->fx_addsy) | |
2851 | || S_IS_WEAK (fixp->fx_addsy)) | |
2852 | code = BFD_RELOC_SPARC_WPLT30; | |
2853 | break; | |
2854 | case BFD_RELOC_HI22: | |
2855 | if (fixp->fx_addsy != NULL | |
2856 | && strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0) | |
2857 | code = BFD_RELOC_SPARC_PC22; | |
2858 | else | |
2859 | code = BFD_RELOC_SPARC_GOT22; | |
2860 | break; | |
2861 | case BFD_RELOC_LO10: | |
2862 | if (fixp->fx_addsy != NULL | |
2863 | && strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0) | |
2864 | code = BFD_RELOC_SPARC_PC10; | |
2865 | else | |
2866 | code = BFD_RELOC_SPARC_GOT10; | |
2867 | break; | |
2868 | case BFD_RELOC_SPARC13: | |
2869 | code = BFD_RELOC_SPARC_GOT13; | |
2870 | break; | |
2871 | default: | |
2872 | break; | |
2873 | } | |
2874 | } | |
2875 | #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */ | |
2876 | ||
2877 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
2878 | if (reloc->howto == 0) | |
2879 | { | |
2880 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
2881 | _("internal error: can't export reloc type %d (`%s')"), | |
2882 | fixp->fx_r_type, bfd_get_reloc_code_name (code)); | |
2883 | return 0; | |
2884 | } | |
2885 | ||
2886 | /* @@ Why fx_addnumber sometimes and fx_offset other times? */ | |
2887 | #ifdef OBJ_AOUT | |
2888 | ||
2889 | if (reloc->howto->pc_relative == 0 | |
2890 | || code == BFD_RELOC_SPARC_PC10 | |
2891 | || code == BFD_RELOC_SPARC_PC22) | |
2892 | reloc->addend = fixp->fx_addnumber; | |
2893 | else if (sparc_pic_code | |
2894 | && fixp->fx_r_type == BFD_RELOC_32_PCREL_S2 | |
2895 | && fixp->fx_addsy != NULL | |
2896 | && (S_IS_EXTERNAL (fixp->fx_addsy) | |
2897 | || S_IS_WEAK (fixp->fx_addsy)) | |
2898 | && S_IS_DEFINED (fixp->fx_addsy) | |
2899 | && ! S_IS_COMMON (fixp->fx_addsy)) | |
2900 | reloc->addend = fixp->fx_addnumber; | |
2901 | else | |
2902 | reloc->addend = fixp->fx_offset - reloc->address; | |
2903 | ||
2904 | #else /* elf or coff */ | |
2905 | ||
2906 | if (reloc->howto->pc_relative == 0 | |
2907 | || code == BFD_RELOC_SPARC_PC10 | |
2908 | || code == BFD_RELOC_SPARC_PC22) | |
2909 | reloc->addend = fixp->fx_addnumber; | |
49309057 | 2910 | else if (symbol_section_p (fixp->fx_addsy)) |
252b5132 RH |
2911 | reloc->addend = (section->vma |
2912 | + fixp->fx_addnumber | |
2913 | + md_pcrel_from (fixp)); | |
2914 | else | |
2915 | reloc->addend = fixp->fx_offset; | |
2916 | #endif | |
2917 | ||
2918 | return reloc; | |
2919 | } | |
2920 | \f | |
2921 | /* We have no need to default values of symbols. */ | |
2922 | ||
2923 | /* ARGSUSED */ | |
2924 | symbolS * | |
2925 | md_undefined_symbol (name) | |
2926 | char *name; | |
2927 | { | |
2928 | return 0; | |
2929 | } /* md_undefined_symbol() */ | |
2930 | ||
2931 | /* Round up a section size to the appropriate boundary. */ | |
2932 | valueT | |
2933 | md_section_align (segment, size) | |
2934 | segT segment; | |
2935 | valueT size; | |
2936 | { | |
2937 | #ifndef OBJ_ELF | |
2938 | /* This is not right for ELF; a.out wants it, and COFF will force | |
2939 | the alignment anyways. */ | |
2940 | valueT align = ((valueT) 1 | |
2941 | << (valueT) bfd_get_section_alignment (stdoutput, segment)); | |
2942 | valueT newsize; | |
2943 | /* turn alignment value into a mask */ | |
2944 | align--; | |
2945 | newsize = (size + align) & ~align; | |
2946 | return newsize; | |
2947 | #else | |
2948 | return size; | |
2949 | #endif | |
2950 | } | |
2951 | ||
2952 | /* Exactly what point is a PC-relative offset relative TO? | |
2953 | On the sparc, they're relative to the address of the offset, plus | |
2954 | its size. This gets us to the following instruction. | |
2955 | (??? Is this right? FIXME-SOON) */ | |
2956 | long | |
2957 | md_pcrel_from (fixP) | |
2958 | fixS *fixP; | |
2959 | { | |
2960 | long ret; | |
2961 | ||
2962 | ret = fixP->fx_where + fixP->fx_frag->fr_address; | |
2963 | if (! sparc_pic_code | |
2964 | || fixP->fx_addsy == NULL | |
49309057 | 2965 | || symbol_section_p (fixP->fx_addsy)) |
252b5132 RH |
2966 | ret += fixP->fx_size; |
2967 | return ret; | |
2968 | } | |
2969 | \f | |
2970 | /* Return log2 (VALUE), or -1 if VALUE is not an exact positive power | |
2971 | of two. */ | |
2972 | ||
2973 | static int | |
2974 | log2 (value) | |
2975 | int value; | |
2976 | { | |
2977 | int shift; | |
2978 | ||
2979 | if (value <= 0) | |
2980 | return -1; | |
2981 | ||
2982 | for (shift = 0; (value & 1) == 0; value >>= 1) | |
2983 | ++shift; | |
2984 | ||
2985 | return (value == 1) ? shift : -1; | |
2986 | } | |
2987 | ||
2988 | /* | |
2989 | * sort of like s_lcomm | |
2990 | */ | |
2991 | ||
2992 | #ifndef OBJ_ELF | |
2993 | static int max_alignment = 15; | |
2994 | #endif | |
2995 | ||
2996 | static void | |
2997 | s_reserve (ignore) | |
2998 | int ignore; | |
2999 | { | |
3000 | char *name; | |
3001 | char *p; | |
3002 | char c; | |
3003 | int align; | |
3004 | int size; | |
3005 | int temp; | |
3006 | symbolS *symbolP; | |
3007 | ||
3008 | name = input_line_pointer; | |
3009 | c = get_symbol_end (); | |
3010 | p = input_line_pointer; | |
3011 | *p = c; | |
3012 | SKIP_WHITESPACE (); | |
3013 | ||
3014 | if (*input_line_pointer != ',') | |
3015 | { | |
3016 | as_bad (_("Expected comma after name")); | |
3017 | ignore_rest_of_line (); | |
3018 | return; | |
3019 | } | |
3020 | ||
3021 | ++input_line_pointer; | |
3022 | ||
3023 | if ((size = get_absolute_expression ()) < 0) | |
3024 | { | |
3025 | as_bad (_("BSS length (%d.) <0! Ignored."), size); | |
3026 | ignore_rest_of_line (); | |
3027 | return; | |
3028 | } /* bad length */ | |
3029 | ||
3030 | *p = 0; | |
3031 | symbolP = symbol_find_or_make (name); | |
3032 | *p = c; | |
3033 | ||
3034 | if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0 | |
3035 | && strncmp (input_line_pointer, ",\".bss\"", 7) != 0) | |
3036 | { | |
3037 | as_bad (_("bad .reserve segment -- expected BSS segment")); | |
3038 | return; | |
3039 | } | |
3040 | ||
3041 | if (input_line_pointer[2] == '.') | |
3042 | input_line_pointer += 7; | |
3043 | else | |
3044 | input_line_pointer += 6; | |
3045 | SKIP_WHITESPACE (); | |
3046 | ||
3047 | if (*input_line_pointer == ',') | |
3048 | { | |
3049 | ++input_line_pointer; | |
3050 | ||
3051 | SKIP_WHITESPACE (); | |
3052 | if (*input_line_pointer == '\n') | |
3053 | { | |
3054 | as_bad (_("missing alignment")); | |
3055 | ignore_rest_of_line (); | |
3056 | return; | |
3057 | } | |
3058 | ||
3059 | align = (int) get_absolute_expression (); | |
3060 | ||
3061 | #ifndef OBJ_ELF | |
3062 | if (align > max_alignment) | |
3063 | { | |
3064 | align = max_alignment; | |
3065 | as_warn (_("alignment too large; assuming %d"), align); | |
3066 | } | |
3067 | #endif | |
3068 | ||
3069 | if (align < 0) | |
3070 | { | |
3071 | as_bad (_("negative alignment")); | |
3072 | ignore_rest_of_line (); | |
3073 | return; | |
3074 | } | |
3075 | ||
3076 | if (align != 0) | |
3077 | { | |
3078 | temp = log2 (align); | |
3079 | if (temp < 0) | |
3080 | { | |
3081 | as_bad (_("alignment not a power of 2")); | |
3082 | ignore_rest_of_line (); | |
3083 | return; | |
3084 | } | |
3085 | ||
3086 | align = temp; | |
3087 | } | |
3088 | ||
3089 | record_alignment (bss_section, align); | |
3090 | } | |
3091 | else | |
3092 | align = 0; | |
3093 | ||
3094 | if (!S_IS_DEFINED (symbolP) | |
3095 | #ifdef OBJ_AOUT | |
3096 | && S_GET_OTHER (symbolP) == 0 | |
3097 | && S_GET_DESC (symbolP) == 0 | |
3098 | #endif | |
3099 | ) | |
3100 | { | |
3101 | if (! need_pass_2) | |
3102 | { | |
3103 | char *pfrag; | |
3104 | segT current_seg = now_seg; | |
3105 | subsegT current_subseg = now_subseg; | |
3106 | ||
3107 | subseg_set (bss_section, 1); /* switch to bss */ | |
3108 | ||
3109 | if (align) | |
3110 | frag_align (align, 0, 0); /* do alignment */ | |
3111 | ||
3112 | /* detach from old frag */ | |
3113 | if (S_GET_SEGMENT(symbolP) == bss_section) | |
49309057 | 3114 | symbol_get_frag (symbolP)->fr_symbol = NULL; |
252b5132 | 3115 | |
49309057 | 3116 | symbol_set_frag (symbolP, frag_now); |
252b5132 RH |
3117 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, |
3118 | (offsetT) size, (char *)0); | |
3119 | *pfrag = 0; | |
3120 | ||
3121 | S_SET_SEGMENT (symbolP, bss_section); | |
3122 | ||
3123 | subseg_set (current_seg, current_subseg); | |
3124 | ||
3125 | #ifdef OBJ_ELF | |
3126 | S_SET_SIZE (symbolP, size); | |
3127 | #endif | |
3128 | } | |
3129 | } | |
3130 | else | |
3131 | { | |
3132 | as_warn("Ignoring attempt to re-define symbol %s", | |
3133 | S_GET_NAME (symbolP)); | |
3134 | } /* if not redefining */ | |
3135 | ||
3136 | demand_empty_rest_of_line (); | |
3137 | } | |
3138 | ||
3139 | static void | |
3140 | s_common (ignore) | |
3141 | int ignore; | |
3142 | { | |
3143 | char *name; | |
3144 | char c; | |
3145 | char *p; | |
3146 | int temp, size; | |
3147 | symbolS *symbolP; | |
3148 | ||
3149 | name = input_line_pointer; | |
3150 | c = get_symbol_end (); | |
3151 | /* just after name is now '\0' */ | |
3152 | p = input_line_pointer; | |
3153 | *p = c; | |
3154 | SKIP_WHITESPACE (); | |
3155 | if (*input_line_pointer != ',') | |
3156 | { | |
3157 | as_bad (_("Expected comma after symbol-name")); | |
3158 | ignore_rest_of_line (); | |
3159 | return; | |
3160 | } | |
3161 | input_line_pointer++; /* skip ',' */ | |
3162 | if ((temp = get_absolute_expression ()) < 0) | |
3163 | { | |
3164 | as_bad (_(".COMMon length (%d.) <0! Ignored."), temp); | |
3165 | ignore_rest_of_line (); | |
3166 | return; | |
3167 | } | |
3168 | size = temp; | |
3169 | *p = 0; | |
3170 | symbolP = symbol_find_or_make (name); | |
3171 | *p = c; | |
3172 | if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) | |
3173 | { | |
3174 | as_bad (_("Ignoring attempt to re-define symbol")); | |
3175 | ignore_rest_of_line (); | |
3176 | return; | |
3177 | } | |
3178 | if (S_GET_VALUE (symbolP) != 0) | |
3179 | { | |
3180 | if (S_GET_VALUE (symbolP) != (valueT) size) | |
3181 | { | |
3182 | as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."), | |
3183 | S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size); | |
3184 | } | |
3185 | } | |
3186 | else | |
3187 | { | |
3188 | #ifndef OBJ_ELF | |
3189 | S_SET_VALUE (symbolP, (valueT) size); | |
3190 | S_SET_EXTERNAL (symbolP); | |
3191 | #endif | |
3192 | } | |
3193 | know (symbolP->sy_frag == &zero_address_frag); | |
3194 | if (*input_line_pointer != ',') | |
3195 | { | |
3196 | as_bad (_("Expected comma after common length")); | |
3197 | ignore_rest_of_line (); | |
3198 | return; | |
3199 | } | |
3200 | input_line_pointer++; | |
3201 | SKIP_WHITESPACE (); | |
3202 | if (*input_line_pointer != '"') | |
3203 | { | |
3204 | temp = get_absolute_expression (); | |
3205 | ||
3206 | #ifndef OBJ_ELF | |
3207 | if (temp > max_alignment) | |
3208 | { | |
3209 | temp = max_alignment; | |
3210 | as_warn (_("alignment too large; assuming %d"), temp); | |
3211 | } | |
3212 | #endif | |
3213 | ||
3214 | if (temp < 0) | |
3215 | { | |
3216 | as_bad (_("negative alignment")); | |
3217 | ignore_rest_of_line (); | |
3218 | return; | |
3219 | } | |
3220 | ||
3221 | #ifdef OBJ_ELF | |
49309057 | 3222 | if (symbol_get_obj (symbolP)->local) |
252b5132 RH |
3223 | { |
3224 | segT old_sec; | |
3225 | int old_subsec; | |
3226 | char *p; | |
3227 | int align; | |
3228 | ||
3229 | old_sec = now_seg; | |
3230 | old_subsec = now_subseg; | |
3231 | ||
3232 | if (temp == 0) | |
3233 | align = 0; | |
3234 | else | |
3235 | align = log2 (temp); | |
3236 | ||
3237 | if (align < 0) | |
3238 | { | |
3239 | as_bad (_("alignment not a power of 2")); | |
3240 | ignore_rest_of_line (); | |
3241 | return; | |
3242 | } | |
3243 | ||
3244 | record_alignment (bss_section, align); | |
3245 | subseg_set (bss_section, 0); | |
3246 | if (align) | |
3247 | frag_align (align, 0, 0); | |
3248 | if (S_GET_SEGMENT (symbolP) == bss_section) | |
49309057 ILT |
3249 | symbol_get_frag (symbolP)->fr_symbol = 0; |
3250 | symbol_set_frag (symbolP, frag_now); | |
252b5132 RH |
3251 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, |
3252 | (offsetT) size, (char *) 0); | |
3253 | *p = 0; | |
3254 | S_SET_SEGMENT (symbolP, bss_section); | |
3255 | S_CLEAR_EXTERNAL (symbolP); | |
3256 | S_SET_SIZE (symbolP, size); | |
3257 | subseg_set (old_sec, old_subsec); | |
3258 | } | |
3259 | else | |
3260 | #endif /* OBJ_ELF */ | |
3261 | { | |
3262 | allocate_common: | |
3263 | S_SET_VALUE (symbolP, (valueT) size); | |
3264 | #ifdef OBJ_ELF | |
3265 | S_SET_ALIGN (symbolP, temp); | |
3266 | S_SET_SIZE (symbolP, size); | |
3267 | #endif | |
3268 | S_SET_EXTERNAL (symbolP); | |
3269 | S_SET_SEGMENT (symbolP, bfd_com_section_ptr); | |
3270 | } | |
3271 | } | |
3272 | else | |
3273 | { | |
3274 | input_line_pointer++; | |
3275 | /* @@ Some use the dot, some don't. Can we get some consistency?? */ | |
3276 | if (*input_line_pointer == '.') | |
3277 | input_line_pointer++; | |
3278 | /* @@ Some say data, some say bss. */ | |
3279 | if (strncmp (input_line_pointer, "bss\"", 4) | |
3280 | && strncmp (input_line_pointer, "data\"", 5)) | |
3281 | { | |
3282 | while (*--input_line_pointer != '"') | |
3283 | ; | |
3284 | input_line_pointer--; | |
3285 | goto bad_common_segment; | |
3286 | } | |
3287 | while (*input_line_pointer++ != '"') | |
3288 | ; | |
3289 | goto allocate_common; | |
3290 | } | |
3291 | ||
3292 | #ifdef BFD_ASSEMBLER | |
49309057 | 3293 | symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT; |
252b5132 RH |
3294 | #endif |
3295 | ||
3296 | demand_empty_rest_of_line (); | |
3297 | return; | |
3298 | ||
3299 | { | |
3300 | bad_common_segment: | |
3301 | p = input_line_pointer; | |
3302 | while (*p && *p != '\n') | |
3303 | p++; | |
3304 | c = *p; | |
3305 | *p = '\0'; | |
3306 | as_bad (_("bad .common segment %s"), input_line_pointer + 1); | |
3307 | *p = c; | |
3308 | input_line_pointer = p; | |
3309 | ignore_rest_of_line (); | |
3310 | return; | |
3311 | } | |
3312 | } | |
3313 | ||
3314 | /* Handle the .empty pseudo-op. This supresses the warnings about | |
3315 | invalid delay slot usage. */ | |
3316 | ||
3317 | static void | |
3318 | s_empty (ignore) | |
3319 | int ignore; | |
3320 | { | |
3321 | /* The easy way to implement is to just forget about the last | |
3322 | instruction. */ | |
3323 | last_insn = NULL; | |
3324 | } | |
3325 | ||
3326 | static void | |
3327 | s_seg (ignore) | |
3328 | int ignore; | |
3329 | { | |
3330 | ||
3331 | if (strncmp (input_line_pointer, "\"text\"", 6) == 0) | |
3332 | { | |
3333 | input_line_pointer += 6; | |
3334 | s_text (0); | |
3335 | return; | |
3336 | } | |
3337 | if (strncmp (input_line_pointer, "\"data\"", 6) == 0) | |
3338 | { | |
3339 | input_line_pointer += 6; | |
3340 | s_data (0); | |
3341 | return; | |
3342 | } | |
3343 | if (strncmp (input_line_pointer, "\"data1\"", 7) == 0) | |
3344 | { | |
3345 | input_line_pointer += 7; | |
3346 | s_data1 (); | |
3347 | return; | |
3348 | } | |
3349 | if (strncmp (input_line_pointer, "\"bss\"", 5) == 0) | |
3350 | { | |
3351 | input_line_pointer += 5; | |
3352 | /* We only support 2 segments -- text and data -- for now, so | |
3353 | things in the "bss segment" will have to go into data for now. | |
3354 | You can still allocate SEG_BSS stuff with .lcomm or .reserve. */ | |
3355 | subseg_set (data_section, 255); /* FIXME-SOMEDAY */ | |
3356 | return; | |
3357 | } | |
3358 | as_bad (_("Unknown segment type")); | |
3359 | demand_empty_rest_of_line (); | |
3360 | } | |
3361 | ||
3362 | static void | |
3363 | s_data1 () | |
3364 | { | |
3365 | subseg_set (data_section, 1); | |
3366 | demand_empty_rest_of_line (); | |
3367 | } | |
3368 | ||
3369 | static void | |
3370 | s_proc (ignore) | |
3371 | int ignore; | |
3372 | { | |
3373 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
3374 | { | |
3375 | ++input_line_pointer; | |
3376 | } | |
3377 | ++input_line_pointer; | |
3378 | } | |
3379 | ||
3380 | /* This static variable is set by s_uacons to tell sparc_cons_align | |
3381 | that the expession does not need to be aligned. */ | |
3382 | ||
3383 | static int sparc_no_align_cons = 0; | |
3384 | ||
3385 | /* This handles the unaligned space allocation pseudo-ops, such as | |
3386 | .uaword. .uaword is just like .word, but the value does not need | |
3387 | to be aligned. */ | |
3388 | ||
3389 | static void | |
3390 | s_uacons (bytes) | |
3391 | int bytes; | |
3392 | { | |
3393 | /* Tell sparc_cons_align not to align this value. */ | |
3394 | sparc_no_align_cons = 1; | |
3395 | cons (bytes); | |
3396 | } | |
3397 | ||
3398 | /* If the --enforce-aligned-data option is used, we require .word, | |
3399 | et. al., to be aligned correctly. We do it by setting up an | |
3400 | rs_align_code frag, and checking in HANDLE_ALIGN to make sure that | |
3401 | no unexpected alignment was introduced. | |
3402 | ||
3403 | The SunOS and Solaris native assemblers enforce aligned data by | |
3404 | default. We don't want to do that, because gcc can deliberately | |
3405 | generate misaligned data if the packed attribute is used. Instead, | |
3406 | we permit misaligned data by default, and permit the user to set an | |
3407 | option to check for it. */ | |
3408 | ||
3409 | void | |
3410 | sparc_cons_align (nbytes) | |
3411 | int nbytes; | |
3412 | { | |
3413 | int nalign; | |
3414 | char *p; | |
3415 | ||
3416 | /* Only do this if we are enforcing aligned data. */ | |
3417 | if (! enforce_aligned_data) | |
3418 | return; | |
3419 | ||
3420 | if (sparc_no_align_cons) | |
3421 | { | |
3422 | /* This is an unaligned pseudo-op. */ | |
3423 | sparc_no_align_cons = 0; | |
3424 | return; | |
3425 | } | |
3426 | ||
3427 | nalign = log2 (nbytes); | |
3428 | if (nalign == 0) | |
3429 | return; | |
3430 | ||
3431 | assert (nalign > 0); | |
3432 | ||
3433 | if (now_seg == absolute_section) | |
3434 | { | |
3435 | if ((abs_section_offset & ((1 << nalign) - 1)) != 0) | |
3436 | as_bad (_("misaligned data")); | |
3437 | return; | |
3438 | } | |
3439 | ||
3440 | p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0, | |
3441 | (symbolS *) NULL, (offsetT) nalign, (char *) NULL); | |
3442 | ||
3443 | record_alignment (now_seg, nalign); | |
3444 | } | |
3445 | ||
3446 | /* This is where we do the unexpected alignment check. | |
3447 | This is called from HANDLE_ALIGN in tc-sparc.h. */ | |
3448 | ||
3449 | void | |
3450 | sparc_handle_align (fragp) | |
3451 | fragS *fragp; | |
3452 | { | |
3453 | if (fragp->fr_type == rs_align_code && !fragp->fr_subtype | |
3454 | && fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix != 0) | |
3455 | as_bad_where (fragp->fr_file, fragp->fr_line, _("misaligned data")); | |
3456 | if (fragp->fr_type == rs_align_code && fragp->fr_subtype == 1024) | |
3457 | { | |
3458 | int count = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; | |
3459 | ||
3460 | if (count >= 4 | |
3461 | && !(count & 3) | |
3462 | && count <= 1024 | |
3463 | && !((long)(fragp->fr_literal + fragp->fr_fix) & 3)) | |
3464 | { | |
3465 | unsigned *p = (unsigned *)(fragp->fr_literal + fragp->fr_fix); | |
3466 | int i; | |
3467 | ||
3468 | for (i = 0; i < count; i += 4, p++) | |
3469 | if (INSN_BIG_ENDIAN) | |
3470 | number_to_chars_bigendian ((char *)p, 0x01000000, 4); /* emit nops */ | |
3471 | else | |
3472 | number_to_chars_littleendian ((char *)p, 0x10000000, 4); | |
3473 | ||
3474 | if (SPARC_OPCODE_ARCH_V9_P (max_architecture) && count > 8) | |
3475 | { | |
3476 | char *waddr = &fragp->fr_literal[fragp->fr_fix]; | |
3477 | unsigned wval = (0x30680000 | count >> 2); /* ba,a,pt %xcc, 1f */ | |
3478 | if (INSN_BIG_ENDIAN) | |
3479 | number_to_chars_bigendian (waddr, wval, 4); | |
3480 | else | |
3481 | number_to_chars_littleendian (waddr, wval, 4); | |
3482 | } | |
3483 | fragp->fr_var = count; | |
3484 | } | |
3485 | } | |
3486 | } | |
3487 | ||
3488 | #ifdef OBJ_ELF | |
3489 | /* Some special processing for a Sparc ELF file. */ | |
3490 | ||
3491 | void | |
3492 | sparc_elf_final_processing () | |
3493 | { | |
3494 | /* Set the Sparc ELF flag bits. FIXME: There should probably be some | |
3495 | sort of BFD interface for this. */ | |
3496 | if (sparc_arch_size == 64) | |
3497 | { | |
3498 | switch (sparc_memory_model) | |
3499 | { | |
3500 | case MM_RMO: | |
3501 | elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_RMO; | |
3502 | break; | |
3503 | case MM_PSO: | |
3504 | elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_PSO; | |
3505 | break; | |
3506 | default: | |
3507 | break; | |
3508 | } | |
3509 | } | |
3510 | else if (current_architecture >= SPARC_OPCODE_ARCH_V9) | |
3511 | elf_elfheader (stdoutput)->e_flags |= EF_SPARC_32PLUS; | |
3512 | if (current_architecture == SPARC_OPCODE_ARCH_V9A) | |
3513 | elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1; | |
3514 | } | |
3515 | #endif | |
3516 | ||
3517 | /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a | |
3518 | reloc for a cons. We could use the definition there, except that | |
3519 | we want to handle little endian relocs specially. */ | |
3520 | ||
3521 | void | |
3522 | cons_fix_new_sparc (frag, where, nbytes, exp) | |
3523 | fragS *frag; | |
3524 | int where; | |
3525 | unsigned int nbytes; | |
3526 | expressionS *exp; | |
3527 | { | |
3528 | bfd_reloc_code_real_type r; | |
3529 | ||
3530 | r = (nbytes == 1 ? BFD_RELOC_8 : | |
3531 | (nbytes == 2 ? BFD_RELOC_16 : | |
3532 | (nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64))); | |
3533 | ||
3534 | if (target_little_endian_data && nbytes == 4 | |
3535 | && now_seg->flags & SEC_ALLOC) | |
3536 | r = BFD_RELOC_SPARC_REV32; | |
3537 | fix_new_exp (frag, where, (int) nbytes, exp, 0, r); | |
3538 | } | |
3539 | ||
3540 | #ifdef OBJ_ELF | |
3541 | int | |
3542 | elf32_sparc_force_relocation (fixp) | |
3543 | struct fix *fixp; | |
3544 | { | |
3545 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
3546 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
3547 | return 1; | |
3548 | ||
3549 | return 0; | |
3550 | } | |
3551 | #endif | |
3552 |