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