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