tc-cris.c revision 1.8 1 1.1 christos /* tc-cris.c -- Assembler code for the CRIS CPU core.
2 1.8 christos Copyright (C) 2000-2022 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos Contributed by Axis Communications AB, Lund, Sweden.
5 1.1 christos Originally written for GAS 1.38.1 by Mikael Asker.
6 1.1 christos Updates, BFDizing, GNUifying and ELF support by Hans-Peter Nilsson.
7 1.1 christos
8 1.1 christos This file is part of GAS, the GNU Assembler.
9 1.1 christos
10 1.1 christos GAS is free software; you can redistribute it and/or modify
11 1.1 christos it under the terms of the GNU General Public License as published by
12 1.1 christos the Free Software Foundation; either version 3, or (at your option)
13 1.1 christos any later version.
14 1.1 christos
15 1.1 christos GAS is distributed in the hope that it will be useful,
16 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
17 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 1.1 christos GNU General Public License for more details.
19 1.1 christos
20 1.1 christos You should have received a copy of the GNU General Public License
21 1.1 christos along with GAS; see the file COPYING. If not, write to the
22 1.1 christos Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
23 1.1 christos MA 02110-1301, USA. */
24 1.1 christos
25 1.1 christos #include "as.h"
26 1.1 christos #include "safe-ctype.h"
27 1.1 christos #include "subsegs.h"
28 1.1 christos #include "opcode/cris.h"
29 1.1 christos #include "dwarf2dbg.h"
30 1.1 christos
31 1.1 christos /* Conventions used here:
32 1.1 christos Generally speaking, pointers to binutils types such as "fragS" and
33 1.1 christos "expressionS" get parameter and variable names ending in "P", such as
34 1.1 christos "fragP", to harmonize with the rest of the binutils code. Other
35 1.1 christos pointers get a "p" suffix, such as "bufp". Any function or type-name
36 1.1 christos that could clash with a current or future binutils or GAS function get
37 1.1 christos a "cris_" prefix. */
38 1.1 christos
39 1.1 christos #define SYNTAX_RELAX_REG_PREFIX "no_register_prefix"
40 1.1 christos #define SYNTAX_ENFORCE_REG_PREFIX "register_prefix"
41 1.1 christos #define SYNTAX_USER_SYM_LEADING_UNDERSCORE "leading_underscore"
42 1.1 christos #define SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE "no_leading_underscore"
43 1.1 christos #define REGISTER_PREFIX_CHAR '$'
44 1.1 christos
45 1.1 christos /* True for expressions where getting X_add_symbol and X_add_number is
46 1.1 christos enough to get the "base" and "offset"; no need to make_expr_symbol.
47 1.1 christos It's not enough to check if X_op_symbol is NULL; that misses unary
48 1.1 christos operations like O_uminus. */
49 1.1 christos #define SIMPLE_EXPR(EXP) \
50 1.1 christos ((EXP)->X_op == O_constant || (EXP)->X_op == O_symbol)
51 1.1 christos
52 1.1 christos /* Like in ":GOT", ":GOTOFF" etc. Other ports use '@', but that's in
53 1.1 christos line_separator_chars for CRIS, so we avoid it. */
54 1.1 christos #define RELOC_SUFFIX_CHAR ':'
55 1.1 christos
56 1.1 christos /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
57 1.1 christos Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL. */
58 1.1 christos enum cris_insn_kind
59 1.1 christos {
60 1.1 christos CRIS_INSN_NORMAL, CRIS_INSN_NONE, CRIS_INSN_BRANCH, CRIS_INSN_MUL
61 1.1 christos };
62 1.1 christos
63 1.1 christos /* An instruction will have one of these prefixes.
64 1.1 christos Although the same bit-pattern, we handle BDAP with an immediate
65 1.1 christos expression (eventually quick or [pc+]) different from when we only have
66 1.1 christos register expressions. */
67 1.1 christos enum prefix_kind
68 1.1 christos {
69 1.1 christos PREFIX_NONE, PREFIX_BDAP_IMM, PREFIX_BDAP, PREFIX_BIAP, PREFIX_DIP,
70 1.1 christos PREFIX_PUSH
71 1.1 christos };
72 1.1 christos
73 1.1 christos /* The prefix for an instruction. */
74 1.1 christos struct cris_prefix
75 1.1 christos {
76 1.1 christos enum prefix_kind kind;
77 1.1 christos int base_reg_number;
78 1.1 christos unsigned int opcode;
79 1.1 christos
80 1.1 christos /* There might be an expression to be evaluated, like I in [rN+I]. */
81 1.1 christos expressionS expr;
82 1.1 christos
83 1.1 christos /* If there's an expression, we might need a relocation. Here's the
84 1.6 christos type of what relocation to start relaxation with.
85 1.1 christos The relocation is assumed to start immediately after the prefix insn,
86 1.1 christos so we don't provide an offset. */
87 1.1 christos enum bfd_reloc_code_real reloc;
88 1.1 christos };
89 1.1 christos
90 1.1 christos /* The description of the instruction being assembled. */
91 1.1 christos struct cris_instruction
92 1.1 christos {
93 1.1 christos /* If CRIS_INSN_NONE, then this insn is of zero length. */
94 1.1 christos enum cris_insn_kind insn_type;
95 1.1 christos
96 1.1 christos /* If a special register was mentioned, this is its description, else
97 1.1 christos it is NULL. */
98 1.1 christos const struct cris_spec_reg *spec_reg;
99 1.1 christos
100 1.1 christos unsigned int opcode;
101 1.1 christos
102 1.1 christos /* An insn may have at most one expression; theoretically there could be
103 1.1 christos another in its prefix (but I don't see how that could happen). */
104 1.1 christos expressionS expr;
105 1.1 christos
106 1.1 christos /* The expression might need a relocation. Here's one to start
107 1.1 christos relaxation with. */
108 1.1 christos enum bfd_reloc_code_real reloc;
109 1.1 christos
110 1.1 christos /* The size in bytes of an immediate expression, or zero if
111 1.1 christos nonapplicable. */
112 1.1 christos int imm_oprnd_size;
113 1.1 christos };
114 1.1 christos
115 1.1 christos enum cris_archs
116 1.1 christos {
117 1.1 christos arch_cris_unknown,
118 1.1 christos arch_crisv0, arch_crisv3, arch_crisv8, arch_crisv10,
119 1.1 christos arch_cris_any_v0_v10, arch_crisv32, arch_cris_common_v10_v32
120 1.1 christos };
121 1.1 christos
122 1.5 christos static enum cris_archs cris_arch_from_string (const char **);
123 1.1 christos static int cris_insn_ver_valid_for_arch (enum cris_insn_version_usage,
124 1.1 christos enum cris_archs);
125 1.1 christos
126 1.1 christos static void cris_process_instruction (char *, struct cris_instruction *,
127 1.1 christos struct cris_prefix *);
128 1.1 christos static int get_bwd_size_modifier (char **, int *);
129 1.1 christos static int get_bw_size_modifier (char **, int *);
130 1.1 christos static int get_gen_reg (char **, int *);
131 1.1 christos static int get_spec_reg (char **, const struct cris_spec_reg **);
132 1.1 christos static int get_sup_reg (char **, int *);
133 1.1 christos static int get_autoinc_prefix_or_indir_op (char **, struct cris_prefix *,
134 1.1 christos int *, int *, int *,
135 1.1 christos expressionS *);
136 1.1 christos static int get_3op_or_dip_prefix_op (char **, struct cris_prefix *);
137 1.1 christos static int cris_get_expression (char **, expressionS *);
138 1.1 christos static int get_flags (char **, int *);
139 1.1 christos static void gen_bdap (int, expressionS *);
140 1.1 christos static int branch_disp (int);
141 1.1 christos static void gen_cond_branch_32 (char *, char *, fragS *, symbolS *, symbolS *,
142 1.1 christos long int);
143 1.1 christos static void cris_number_to_imm (char *, long, int, fixS *, segT);
144 1.1 christos static void s_syntax (int);
145 1.1 christos static void s_cris_file (int);
146 1.1 christos static void s_cris_loc (int);
147 1.1 christos static void s_cris_arch (int);
148 1.1 christos static void s_cris_dtpoff (int);
149 1.1 christos
150 1.1 christos /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes. */
151 1.1 christos static void cris_get_reloc_suffix (char **, bfd_reloc_code_real_type *,
152 1.1 christos expressionS *);
153 1.1 christos static unsigned int cris_get_specified_reloc_size (bfd_reloc_code_real_type);
154 1.1 christos
155 1.1 christos /* All the .syntax functions. */
156 1.1 christos static void cris_force_reg_prefix (void);
157 1.1 christos static void cris_relax_reg_prefix (void);
158 1.1 christos static void cris_sym_leading_underscore (void);
159 1.1 christos static void cris_sym_no_leading_underscore (void);
160 1.1 christos static char *cris_insn_first_word_frag (void);
161 1.1 christos
162 1.1 christos /* Handle to the opcode hash table. */
163 1.8 christos static htab_t op_hash = NULL;
164 1.1 christos
165 1.1 christos /* If we target cris-axis-linux-gnu (as opposed to generic cris-axis-elf),
166 1.1 christos we default to no underscore and required register-prefixes. The
167 1.1 christos difference is in the default values. */
168 1.1 christos #ifdef TE_LINUX
169 1.8 christos #define DEFAULT_CRIS_AXIS_LINUX_GNU true
170 1.1 christos #else
171 1.8 christos #define DEFAULT_CRIS_AXIS_LINUX_GNU false
172 1.1 christos #endif
173 1.1 christos
174 1.1 christos /* Whether we demand that registers have a `$' prefix. Default here. */
175 1.8 christos static bool demand_register_prefix = DEFAULT_CRIS_AXIS_LINUX_GNU;
176 1.1 christos
177 1.1 christos /* Whether global user symbols have a leading underscore. Default here. */
178 1.8 christos static bool symbols_have_leading_underscore
179 1.1 christos = !DEFAULT_CRIS_AXIS_LINUX_GNU;
180 1.1 christos
181 1.1 christos /* Whether or not we allow PIC, and expand to PIC-friendly constructs. */
182 1.8 christos static bool pic = false;
183 1.1 christos
184 1.1 christos /* Whether or not we allow TLS suffixes. For the moment, we always do. */
185 1.8 christos static const bool tls = true;
186 1.1 christos
187 1.1 christos /* If we're configured for "cris", default to allow all v0..v10
188 1.1 christos instructions and register names. */
189 1.1 christos #ifndef DEFAULT_CRIS_ARCH
190 1.1 christos #define DEFAULT_CRIS_ARCH cris_any_v0_v10
191 1.1 christos #endif
192 1.1 christos
193 1.1 christos /* No whitespace in the CONCAT2 parameter list. */
194 1.1 christos static enum cris_archs cris_arch = XCONCAT2 (arch_,DEFAULT_CRIS_ARCH);
195 1.1 christos
196 1.1 christos const pseudo_typeS md_pseudo_table[] =
197 1.1 christos {
198 1.1 christos {"dword", cons, 4},
199 1.1 christos {"dtpoffd", s_cris_dtpoff, 4},
200 1.1 christos {"syntax", s_syntax, 0},
201 1.1 christos {"file", s_cris_file, 0},
202 1.1 christos {"loc", s_cris_loc, 0},
203 1.1 christos {"arch", s_cris_arch, 0},
204 1.1 christos {NULL, 0, 0}
205 1.1 christos };
206 1.1 christos
207 1.1 christos static int warn_for_branch_expansion = 0;
208 1.1 christos
209 1.1 christos /* Whether to emit error when a MULS/MULU could be located last on a
210 1.1 christos cache-line. */
211 1.1 christos static int err_for_dangerous_mul_placement
212 1.1 christos = (XCONCAT2 (arch_,DEFAULT_CRIS_ARCH) != arch_crisv32);
213 1.1 christos
214 1.1 christos const char cris_comment_chars[] = ";";
215 1.1 christos
216 1.1 christos /* This array holds the chars that only start a comment at the beginning of
217 1.1 christos a line. If the line seems to have the form '# 123 filename'
218 1.1 christos .line and .file directives will appear in the pre-processed output. */
219 1.1 christos /* Note that input_file.c hand-checks for '#' at the beginning of the
220 1.1 christos first line of the input file. This is because the compiler outputs
221 1.1 christos #NO_APP at the beginning of its output. */
222 1.1 christos /* Also note that slash-star will always start a comment. */
223 1.1 christos const char line_comment_chars[] = "#";
224 1.1 christos const char line_separator_chars[] = "@";
225 1.1 christos
226 1.1 christos /* Now all floating point support is shut off. See md_atof. */
227 1.1 christos const char EXP_CHARS[] = "";
228 1.1 christos const char FLT_CHARS[] = "";
229 1.1 christos
230 1.1 christos /* For CRIS, we encode the relax_substateTs (in e.g. fr_substate) as:
231 1.1 christos 2 1 0
232 1.1 christos ---/ /--+-----------------+-----------------+-----------------+
233 1.1 christos | what state ? | how long ? |
234 1.1 christos ---/ /--+-----------------+-----------------+-----------------+
235 1.1 christos
236 1.1 christos The "how long" bits are 00 = byte, 01 = word, 10 = dword (long).
237 1.1 christos Not all lengths are legit for a given value of (what state).
238 1.1 christos
239 1.1 christos Groups for CRIS address relaxing:
240 1.1 christos
241 1.1 christos 1. Bcc (pre-V32)
242 1.1 christos length: byte, word, 10-byte expansion
243 1.1 christos
244 1.1 christos 2. BDAP
245 1.1 christos length: byte, word, dword
246 1.1 christos
247 1.1 christos 3. MULS/MULU
248 1.1 christos Not really a relaxation (no infrastructure to get delay-slots
249 1.1 christos right), just an alignment and placement checker for the v10
250 1.1 christos multiply/cache-bug.
251 1.1 christos
252 1.1 christos 4. Bcc (V32 and later)
253 1.1 christos length: byte, word, 14-byte expansion
254 1.1 christos
255 1.1 christos 5. Bcc (V10+V32)
256 1.1 christos length: byte, word, error
257 1.1 christos
258 1.1 christos 6. BA (V32)
259 1.1 christos length: byte, word, dword
260 1.1 christos
261 1.1 christos 7. LAPC (V32)
262 1.1 christos length: byte, dword
263 1.1 christos */
264 1.1 christos
265 1.1 christos #define STATE_COND_BRANCH (1)
266 1.1 christos #define STATE_BASE_PLUS_DISP_PREFIX (2)
267 1.1 christos #define STATE_MUL (3)
268 1.1 christos #define STATE_COND_BRANCH_V32 (4)
269 1.1 christos #define STATE_COND_BRANCH_COMMON (5)
270 1.1 christos #define STATE_ABS_BRANCH_V32 (6)
271 1.1 christos #define STATE_LAPC (7)
272 1.1 christos #define STATE_COND_BRANCH_PIC (8)
273 1.1 christos
274 1.1 christos #define STATE_LENGTH_MASK (3)
275 1.1 christos #define STATE_BYTE (0)
276 1.1 christos #define STATE_WORD (1)
277 1.1 christos #define STATE_DWORD (2)
278 1.1 christos /* Symbol undefined. */
279 1.1 christos #define STATE_UNDF (3)
280 1.1 christos #define STATE_MAX_LENGTH (3)
281 1.1 christos
282 1.1 christos /* These displacements are relative to the address following the opcode
283 1.1 christos word of the instruction. The first letter is Byte, Word. The 2nd
284 1.1 christos letter is Forward, Backward. */
285 1.1 christos
286 1.1 christos #define BRANCH_BF ( 254)
287 1.1 christos #define BRANCH_BB (-256)
288 1.1 christos #define BRANCH_BF_V32 ( 252)
289 1.1 christos #define BRANCH_BB_V32 (-258)
290 1.1 christos #define BRANCH_WF (2 + 32767)
291 1.1 christos #define BRANCH_WB (2 + -32768)
292 1.1 christos #define BRANCH_WF_V32 (-2 + 32767)
293 1.1 christos #define BRANCH_WB_V32 (-2 + -32768)
294 1.1 christos
295 1.1 christos #define BDAP_BF ( 127)
296 1.1 christos #define BDAP_BB (-128)
297 1.1 christos #define BDAP_WF ( 32767)
298 1.1 christos #define BDAP_WB (-32768)
299 1.1 christos
300 1.1 christos #define ENCODE_RELAX(what, length) (((what) << 2) + (length))
301 1.1 christos
302 1.1 christos const relax_typeS md_cris_relax_table[] =
303 1.1 christos {
304 1.1 christos /* Error sentinel (0, 0). */
305 1.1 christos {1, 1, 0, 0},
306 1.1 christos
307 1.1 christos /* Unused (0, 1). */
308 1.1 christos {1, 1, 0, 0},
309 1.1 christos
310 1.1 christos /* Unused (0, 2). */
311 1.1 christos {1, 1, 0, 0},
312 1.1 christos
313 1.1 christos /* Unused (0, 3). */
314 1.1 christos {1, 1, 0, 0},
315 1.1 christos
316 1.1 christos /* Bcc o (1, 0). */
317 1.1 christos {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (1, 1)},
318 1.1 christos
319 1.1 christos /* Bcc [PC+] (1, 1). */
320 1.1 christos {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (1, 2)},
321 1.1 christos
322 1.1 christos /* BEXT/BWF, BA, JUMP (external), JUMP (always), Bnot_cc, JUMP (default)
323 1.1 christos (1, 2). */
324 1.1 christos {0, 0, 10, 0},
325 1.1 christos
326 1.1 christos /* Unused (1, 3). */
327 1.1 christos {1, 1, 0, 0},
328 1.1 christos
329 1.1 christos /* BDAP o (2, 0). */
330 1.1 christos {BDAP_BF, BDAP_BB, 0, ENCODE_RELAX (2, 1)},
331 1.1 christos
332 1.1 christos /* BDAP.[bw] [PC+] (2, 1). */
333 1.1 christos {BDAP_WF, BDAP_WB, 2, ENCODE_RELAX (2, 2)},
334 1.1 christos
335 1.1 christos /* BDAP.d [PC+] (2, 2). */
336 1.1 christos {0, 0, 4, 0},
337 1.1 christos
338 1.1 christos /* Unused (2, 3). */
339 1.1 christos {1, 1, 0, 0},
340 1.1 christos
341 1.1 christos /* MULS/MULU (3, 0). Positions (3, 1..3) are unused. */
342 1.1 christos {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
343 1.1 christos
344 1.1 christos /* V32: Bcc o (4, 0). */
345 1.1 christos {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (4, 1)},
346 1.1 christos
347 1.1 christos /* V32: Bcc [PC+] (4, 1). */
348 1.1 christos {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (4, 2)},
349 1.1 christos
350 1.1 christos /* V32: BA .+12; NOP; BA32 target; NOP; Bcc .-6 (4, 2). */
351 1.1 christos {0, 0, 12, 0},
352 1.1 christos
353 1.1 christos /* Unused (4, 3). */
354 1.1 christos {1, 1, 0, 0},
355 1.1 christos
356 1.1 christos /* COMMON: Bcc o (5, 0). The offsets are calculated as for v32. Code
357 1.1 christos should contain two nop insns (or four if offset size is large or
358 1.1 christos unknown) after every label. */
359 1.1 christos {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (5, 1)},
360 1.1 christos
361 1.1 christos /* COMMON: Bcc [PC+] (5, 1). */
362 1.1 christos {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (5, 2)},
363 1.1 christos
364 1.1 christos /* COMMON: FIXME: ???. Treat as error currently. */
365 1.1 christos {0, 0, 12, 0},
366 1.1 christos
367 1.1 christos /* Unused (5, 3). */
368 1.1 christos {1, 1, 0, 0},
369 1.1 christos
370 1.1 christos /* V32: BA o (6, 0). */
371 1.1 christos {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (6, 1)},
372 1.1 christos
373 1.1 christos /* V32: BA.W (6, 1). */
374 1.1 christos {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (6, 2)},
375 1.1 christos
376 1.1 christos /* V32: BA.D (6, 2). */
377 1.1 christos {0, 0, 4, 0},
378 1.1 christos
379 1.1 christos /* Unused (6, 3). */
380 1.1 christos {1, 1, 0, 0},
381 1.1 christos
382 1.1 christos /* LAPC: LAPCQ .+0..15*2,Rn (7, 0). */
383 1.1 christos {14*2, -1*2, 0, ENCODE_RELAX (7, 2)},
384 1.1 christos
385 1.1 christos /* Unused (7, 1).
386 1.1 christos While there's a shorter sequence, e.g. LAPCQ + an ADDQ or SUBQ,
387 1.1 christos that would affect flags, so we can't do that as it wouldn't be a
388 1.1 christos proper insn expansion of LAPCQ. This row is associated with a
389 1.1 christos 2-byte expansion, so it's unused rather than the next. */
390 1.1 christos {1, 1, 0, 0},
391 1.1 christos
392 1.1 christos /* LAPC: LAPC.D (7, 2). */
393 1.1 christos {0, 0, 4, 0},
394 1.1 christos
395 1.1 christos /* Unused (7, 3). */
396 1.1 christos {1, 1, 0, 0},
397 1.1 christos
398 1.1 christos /* PIC for pre-v32: Bcc o (8, 0). */
399 1.1 christos {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (STATE_COND_BRANCH_PIC, 1)},
400 1.1 christos
401 1.1 christos /* Bcc [PC+] (8, 1). */
402 1.1 christos {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (STATE_COND_BRANCH_PIC, 2)},
403 1.1 christos
404 1.1 christos /* 32-bit expansion, PIC (8, 2). */
405 1.1 christos {0, 0, 12, 0},
406 1.1 christos
407 1.1 christos /* Unused (8, 3). */
408 1.1 christos {1, 1, 0, 0}
409 1.1 christos };
410 1.1 christos
411 1.1 christos #undef BDAP_BF
412 1.1 christos #undef BDAP_BB
413 1.1 christos #undef BDAP_WF
414 1.1 christos #undef BDAP_WB
415 1.1 christos
416 1.1 christos /* Target-specific multicharacter options, not const-declared. */
417 1.1 christos struct option md_longopts[] =
418 1.1 christos {
419 1.1 christos #define OPTION_NO_US (OPTION_MD_BASE + 0)
420 1.1 christos {"no-underscore", no_argument, NULL, OPTION_NO_US},
421 1.1 christos #define OPTION_US (OPTION_MD_BASE + 1)
422 1.1 christos {"underscore", no_argument, NULL, OPTION_US},
423 1.1 christos #define OPTION_PIC (OPTION_US + 1)
424 1.1 christos {"pic", no_argument, NULL, OPTION_PIC},
425 1.1 christos #define OPTION_MULBUG_ABORT_ON (OPTION_PIC + 1)
426 1.1 christos {"mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_ON},
427 1.1 christos #define OPTION_MULBUG_ABORT_OFF (OPTION_MULBUG_ABORT_ON + 1)
428 1.1 christos {"no-mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_OFF},
429 1.1 christos #define OPTION_ARCH (OPTION_MULBUG_ABORT_OFF + 1)
430 1.1 christos {"march", required_argument, NULL, OPTION_ARCH},
431 1.1 christos {NULL, no_argument, NULL, 0}
432 1.1 christos };
433 1.1 christos
434 1.1 christos /* Not const-declared. */
435 1.1 christos size_t md_longopts_size = sizeof (md_longopts);
436 1.1 christos const char *md_shortopts = "hHN";
437 1.1 christos
438 1.1 christos /* At first glance, this may seems wrong and should be 4 (ba + nop); but
439 1.1 christos since a short_jump must skip a *number* of long jumps, it must also be
440 1.1 christos a long jump. Here, we hope to make it a "ba [16bit_offs]" and a "nop"
441 1.1 christos for the delay slot and hope that the jump table at most needs
442 1.1 christos 32767/4=8191 long-jumps. A branch is better than a jump, since it is
443 1.1 christos relative; we will not have a reloc to fix up somewhere.
444 1.1 christos
445 1.1 christos Note that we can't add relocs, because relaxation uses these fixed
446 1.1 christos numbers, and md_create_short_jump is called after relaxation. */
447 1.1 christos
448 1.1 christos int md_short_jump_size = 6;
449 1.1 christos
450 1.1 christos /* The v32 version has a delay-slot, hence two bytes longer.
451 1.1 christos The pre-v32 PIC version uses a prefixed insn. */
452 1.1 christos #define cris_any_v0_v10_long_jump_size 6
453 1.1 christos #define cris_any_v0_v10_long_jump_size_pic 8
454 1.1 christos #define crisv32_long_jump_size 8
455 1.1 christos
456 1.1 christos int md_long_jump_size = XCONCAT2 (DEFAULT_CRIS_ARCH,_long_jump_size);
457 1.1 christos
458 1.1 christos /* Report output format. Small changes in output format (like elf
459 1.1 christos variants below) can happen until all options are parsed, but after
460 1.1 christos that, the output format must remain fixed. */
461 1.1 christos
462 1.1 christos const char *
463 1.1 christos cris_target_format (void)
464 1.1 christos {
465 1.1 christos switch (OUTPUT_FLAVOR)
466 1.1 christos {
467 1.1 christos case bfd_target_aout_flavour:
468 1.1 christos return "a.out-cris";
469 1.1 christos
470 1.1 christos case bfd_target_elf_flavour:
471 1.1 christos if (symbols_have_leading_underscore)
472 1.1 christos return "elf32-us-cris";
473 1.1 christos return "elf32-cris";
474 1.1 christos
475 1.1 christos default:
476 1.1 christos abort ();
477 1.1 christos return NULL;
478 1.1 christos }
479 1.1 christos }
480 1.1 christos
481 1.1 christos /* Return a bfd_mach_cris... value corresponding to the value of
482 1.1 christos cris_arch. */
483 1.1 christos
484 1.1 christos unsigned int
485 1.1 christos cris_mach (void)
486 1.1 christos {
487 1.1 christos unsigned int retval = 0;
488 1.1 christos
489 1.1 christos switch (cris_arch)
490 1.1 christos {
491 1.1 christos case arch_cris_common_v10_v32:
492 1.1 christos retval = bfd_mach_cris_v10_v32;
493 1.1 christos break;
494 1.1 christos
495 1.1 christos case arch_crisv32:
496 1.1 christos retval = bfd_mach_cris_v32;
497 1.1 christos break;
498 1.1 christos
499 1.1 christos case arch_crisv10:
500 1.1 christos case arch_cris_any_v0_v10:
501 1.1 christos retval = bfd_mach_cris_v0_v10;
502 1.1 christos break;
503 1.1 christos
504 1.1 christos default:
505 1.1 christos BAD_CASE (cris_arch);
506 1.1 christos }
507 1.1 christos
508 1.1 christos return retval;
509 1.1 christos }
510 1.1 christos
511 1.1 christos /* We need a port-specific relaxation function to cope with sym2 - sym1
512 1.1 christos relative expressions with both symbols in the same segment (but not
513 1.1 christos necessarily in the same frag as this insn), for example:
514 1.1 christos move.d [pc+sym2-(sym1-2)],r10
515 1.1 christos sym1:
516 1.1 christos The offset can be 8, 16 or 32 bits long. */
517 1.1 christos
518 1.1 christos long
519 1.1 christos cris_relax_frag (segT seg ATTRIBUTE_UNUSED, fragS *fragP,
520 1.1 christos long stretch ATTRIBUTE_UNUSED)
521 1.1 christos {
522 1.1 christos long growth;
523 1.1 christos offsetT aim = 0;
524 1.1 christos symbolS *symbolP;
525 1.1 christos const relax_typeS *this_type;
526 1.1 christos const relax_typeS *start_type;
527 1.1 christos relax_substateT next_state;
528 1.1 christos relax_substateT this_state;
529 1.1 christos const relax_typeS *table = TC_GENERIC_RELAX_TABLE;
530 1.1 christos
531 1.1 christos /* We only have to cope with frags as prepared by
532 1.1 christos md_estimate_size_before_relax. The dword cases may get here
533 1.1 christos because of the different reasons that they aren't relaxable. */
534 1.1 christos switch (fragP->fr_subtype)
535 1.1 christos {
536 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD):
537 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
538 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
539 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
540 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD):
541 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_DWORD):
542 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
543 1.1 christos /* When we get to these states, the frag won't grow any more. */
544 1.1 christos return 0;
545 1.1 christos
546 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
547 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
548 1.1 christos if (fragP->fr_symbol == NULL
549 1.1 christos || S_GET_SEGMENT (fragP->fr_symbol) != absolute_section)
550 1.1 christos as_fatal (_("internal inconsistency problem in %s: fr_symbol %lx"),
551 1.1 christos __FUNCTION__, (long) fragP->fr_symbol);
552 1.1 christos symbolP = fragP->fr_symbol;
553 1.1 christos if (symbol_resolved_p (symbolP))
554 1.1 christos as_fatal (_("internal inconsistency problem in %s: resolved symbol"),
555 1.1 christos __FUNCTION__);
556 1.1 christos aim = S_GET_VALUE (symbolP);
557 1.1 christos break;
558 1.1 christos
559 1.1 christos case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
560 1.1 christos /* Nothing to do here. */
561 1.1 christos return 0;
562 1.1 christos
563 1.1 christos default:
564 1.1 christos as_fatal (_("internal inconsistency problem in %s: fr_subtype %d"),
565 1.1 christos __FUNCTION__, fragP->fr_subtype);
566 1.1 christos }
567 1.1 christos
568 1.1 christos /* The rest is stolen from relax_frag. There's no obvious way to
569 1.1 christos share the code, but fortunately no requirement to keep in sync as
570 1.1 christos long as fragP->fr_symbol does not have its segment changed. */
571 1.1 christos
572 1.1 christos this_state = fragP->fr_subtype;
573 1.1 christos start_type = this_type = table + this_state;
574 1.1 christos
575 1.1 christos if (aim < 0)
576 1.1 christos {
577 1.1 christos /* Look backwards. */
578 1.1 christos for (next_state = this_type->rlx_more; next_state;)
579 1.1 christos if (aim >= this_type->rlx_backward)
580 1.1 christos next_state = 0;
581 1.1 christos else
582 1.1 christos {
583 1.1 christos /* Grow to next state. */
584 1.1 christos this_state = next_state;
585 1.1 christos this_type = table + this_state;
586 1.1 christos next_state = this_type->rlx_more;
587 1.1 christos }
588 1.1 christos }
589 1.1 christos else
590 1.1 christos {
591 1.1 christos /* Look forwards. */
592 1.1 christos for (next_state = this_type->rlx_more; next_state;)
593 1.1 christos if (aim <= this_type->rlx_forward)
594 1.1 christos next_state = 0;
595 1.1 christos else
596 1.1 christos {
597 1.1 christos /* Grow to next state. */
598 1.1 christos this_state = next_state;
599 1.1 christos this_type = table + this_state;
600 1.1 christos next_state = this_type->rlx_more;
601 1.1 christos }
602 1.1 christos }
603 1.1 christos
604 1.1 christos growth = this_type->rlx_length - start_type->rlx_length;
605 1.1 christos if (growth != 0)
606 1.1 christos fragP->fr_subtype = this_state;
607 1.1 christos return growth;
608 1.1 christos }
609 1.1 christos
610 1.1 christos /* Prepare machine-dependent frags for relaxation.
611 1.1 christos
612 1.1 christos Called just before relaxation starts. Any symbol that is now undefined
613 1.1 christos will not become defined.
614 1.1 christos
615 1.1 christos Return the correct fr_subtype in the frag.
616 1.1 christos
617 1.1 christos Return the initial "guess for fr_var" to caller. The guess for fr_var
618 1.1 christos is *actually* the growth beyond fr_fix. Whatever we do to grow fr_fix
619 1.1 christos or fr_var contributes to our returned value.
620 1.1 christos
621 1.1 christos Although it may not be explicit in the frag, pretend
622 1.1 christos fr_var starts with a value. */
623 1.1 christos
624 1.1 christos int
625 1.1 christos md_estimate_size_before_relax (fragS *fragP, segT segment_type)
626 1.1 christos {
627 1.1 christos int old_fr_fix;
628 1.1 christos symbolS *symbolP = fragP->fr_symbol;
629 1.1 christos
630 1.1 christos #define HANDLE_RELAXABLE(state) \
631 1.1 christos case ENCODE_RELAX (state, STATE_UNDF): \
632 1.1 christos if (symbolP != NULL \
633 1.1 christos && S_GET_SEGMENT (symbolP) == segment_type \
634 1.1 christos && !S_IS_WEAK (symbolP)) \
635 1.1 christos /* The symbol lies in the same segment - a relaxable \
636 1.1 christos case. */ \
637 1.1 christos fragP->fr_subtype \
638 1.1 christos = ENCODE_RELAX (state, STATE_BYTE); \
639 1.1 christos else \
640 1.1 christos /* Unknown or not the same segment, so not relaxable. */ \
641 1.1 christos fragP->fr_subtype \
642 1.1 christos = ENCODE_RELAX (state, STATE_DWORD); \
643 1.1 christos fragP->fr_var \
644 1.1 christos = md_cris_relax_table[fragP->fr_subtype].rlx_length; \
645 1.1 christos break
646 1.1 christos
647 1.1 christos old_fr_fix = fragP->fr_fix;
648 1.1 christos
649 1.1 christos switch (fragP->fr_subtype)
650 1.1 christos {
651 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH);
652 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH_V32);
653 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH_COMMON);
654 1.1 christos HANDLE_RELAXABLE (STATE_COND_BRANCH_PIC);
655 1.1 christos HANDLE_RELAXABLE (STATE_ABS_BRANCH_V32);
656 1.1 christos
657 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_UNDF):
658 1.1 christos if (symbolP != NULL
659 1.1 christos && S_GET_SEGMENT (symbolP) == segment_type
660 1.1 christos && !S_IS_WEAK (symbolP))
661 1.1 christos {
662 1.1 christos /* The symbol lies in the same segment - a relaxable case.
663 1.1 christos Check if we currently have an odd offset; we can't code
664 1.1 christos that into the instruction. Relaxing presumably only cause
665 1.1 christos multiple-of-two changes, so we should only need to adjust
666 1.1 christos for that here. */
667 1.1 christos bfd_vma target_address
668 1.1 christos = (symbolP
669 1.1 christos ? S_GET_VALUE (symbolP)
670 1.1 christos : 0) + fragP->fr_offset;
671 1.1 christos bfd_vma var_part_offset = fragP->fr_fix;
672 1.1 christos bfd_vma address_of_var_part = fragP->fr_address + var_part_offset;
673 1.1 christos long offset = target_address - (address_of_var_part - 2);
674 1.1 christos
675 1.1 christos fragP->fr_subtype
676 1.1 christos = (offset & 1)
677 1.1 christos ? ENCODE_RELAX (STATE_LAPC, STATE_DWORD)
678 1.1 christos : ENCODE_RELAX (STATE_LAPC, STATE_BYTE);
679 1.1 christos }
680 1.1 christos else
681 1.1 christos /* Unknown or not the same segment, so not relaxable. */
682 1.1 christos fragP->fr_subtype
683 1.1 christos = ENCODE_RELAX (STATE_LAPC, STATE_DWORD);
684 1.1 christos fragP->fr_var
685 1.1 christos = md_cris_relax_table[fragP->fr_subtype].rlx_length;
686 1.1 christos break;
687 1.1 christos
688 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF):
689 1.1 christos /* Note that we can not do anything sane with relaxing
690 1.1 christos [rX + a_known_symbol_in_text], it will have to be a 32-bit
691 1.1 christos value.
692 1.1 christos
693 1.1 christos We could play tricks with managing a constant pool and make
694 1.1 christos a_known_symbol_in_text a "bdap [pc + offset]" pointing there
695 1.1 christos (like the GOT for ELF shared libraries), but that's no use, it
696 1.1 christos would in general be no shorter or faster code, only more
697 1.1 christos complicated. */
698 1.1 christos
699 1.1 christos if (S_GET_SEGMENT (symbolP) != absolute_section)
700 1.1 christos {
701 1.1 christos /* Go for dword if not absolute or same segment. */
702 1.1 christos fragP->fr_subtype
703 1.1 christos = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD);
704 1.1 christos fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
705 1.1 christos }
706 1.1 christos else if (!symbol_resolved_p (fragP->fr_symbol))
707 1.1 christos {
708 1.1 christos /* The symbol will eventually be completely resolved as an
709 1.1 christos absolute expression, but right now it depends on the result
710 1.1 christos of relaxation and we don't know anything else about the
711 1.1 christos value. We start relaxation with the assumption that it'll
712 1.1 christos fit in a byte. */
713 1.1 christos fragP->fr_subtype
714 1.1 christos = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE);
715 1.1 christos fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
716 1.1 christos }
717 1.1 christos else
718 1.1 christos {
719 1.1 christos /* Absolute expression. */
720 1.1 christos long int value;
721 1.1 christos value = (symbolP != NULL
722 1.1 christos ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset;
723 1.1 christos
724 1.1 christos if (value >= -128 && value <= 127)
725 1.1 christos {
726 1.1 christos /* Byte displacement. */
727 1.1 christos (fragP->fr_opcode)[0] = value;
728 1.1 christos }
729 1.1 christos else
730 1.1 christos {
731 1.1 christos /* Word or dword displacement. */
732 1.1 christos int pow2_of_size = 1;
733 1.1 christos char *writep;
734 1.1 christos
735 1.1 christos if (value < -32768 || value > 32767)
736 1.1 christos {
737 1.1 christos /* Outside word range, make it a dword. */
738 1.1 christos pow2_of_size = 2;
739 1.1 christos }
740 1.1 christos
741 1.1 christos /* Modify the byte-offset BDAP into a word or dword offset
742 1.1 christos BDAP. Or really, a BDAP rX,8bit into a
743 1.1 christos BDAP.[wd] rX,[PC+] followed by a word or dword. */
744 1.1 christos (fragP->fr_opcode)[0] = BDAP_PC_LOW + pow2_of_size * 16;
745 1.1 christos
746 1.1 christos /* Keep the register number in the highest four bits. */
747 1.1 christos (fragP->fr_opcode)[1] &= 0xF0;
748 1.1 christos (fragP->fr_opcode)[1] |= BDAP_INCR_HIGH;
749 1.1 christos
750 1.1 christos /* It grew by two or four bytes. */
751 1.1 christos fragP->fr_fix += 1 << pow2_of_size;
752 1.1 christos writep = fragP->fr_literal + old_fr_fix;
753 1.1 christos md_number_to_chars (writep, value, 1 << pow2_of_size);
754 1.1 christos }
755 1.1 christos frag_wane (fragP);
756 1.1 christos }
757 1.1 christos break;
758 1.1 christos
759 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_BYTE):
760 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_WORD):
761 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
762 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_BYTE):
763 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_WORD):
764 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD):
765 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_BYTE):
766 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_WORD):
767 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
768 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_BYTE):
769 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_WORD):
770 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
771 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_BYTE):
772 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_WORD):
773 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD):
774 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_BYTE):
775 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_DWORD):
776 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
777 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
778 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
779 1.1 christos /* When relaxing a section for the second time, we don't need to
780 1.1 christos do anything except making sure that fr_var is set right. */
781 1.1 christos fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
782 1.1 christos break;
783 1.1 christos
784 1.1 christos case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
785 1.1 christos /* Nothing to do here. */
786 1.1 christos break;
787 1.1 christos
788 1.1 christos default:
789 1.1 christos BAD_CASE (fragP->fr_subtype);
790 1.1 christos }
791 1.1 christos
792 1.1 christos return fragP->fr_var + (fragP->fr_fix - old_fr_fix);
793 1.1 christos }
794 1.1 christos
795 1.1 christos /* Perform post-processing of machine-dependent frags after relaxation.
796 1.1 christos Called after relaxation is finished.
797 1.1 christos In: Address of frag.
798 1.1 christos fr_type == rs_machine_dependent.
799 1.1 christos fr_subtype is what the address relaxed to.
800 1.1 christos
801 1.1 christos Out: Any fixS:s and constants are set up.
802 1.1 christos
803 1.1 christos The caller will turn the frag into a ".space 0". */
804 1.1 christos
805 1.1 christos void
806 1.1 christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
807 1.1 christos fragS *fragP)
808 1.1 christos {
809 1.1 christos /* Pointer to first byte in variable-sized part of the frag. */
810 1.1 christos char *var_partp;
811 1.1 christos
812 1.1 christos /* Pointer to first opcode byte in frag. */
813 1.1 christos char *opcodep;
814 1.1 christos
815 1.1 christos /* Used to check integrity of the relaxation.
816 1.1 christos One of 2 = long, 1 = word, or 0 = byte. */
817 1.1 christos int length_code ATTRIBUTE_UNUSED;
818 1.1 christos
819 1.1 christos /* Size in bytes of variable-sized part of frag. */
820 1.1 christos int var_part_size = 0;
821 1.1 christos
822 1.1 christos /* This is part of *fragP. It contains all information about addresses
823 1.1 christos and offsets to varying parts. */
824 1.1 christos symbolS *symbolP;
825 1.1 christos unsigned long var_part_offset;
826 1.1 christos
827 1.1 christos /* Where, in file space, is _var of *fragP? */
828 1.1 christos unsigned long address_of_var_part = 0;
829 1.1 christos
830 1.1 christos /* Where, in file space, does addr point? */
831 1.1 christos unsigned long target_address;
832 1.1 christos
833 1.1 christos know (fragP->fr_type == rs_machine_dependent);
834 1.1 christos
835 1.1 christos length_code = fragP->fr_subtype & STATE_LENGTH_MASK;
836 1.1 christos know (length_code >= 0 && length_code < STATE_MAX_LENGTH);
837 1.1 christos
838 1.1 christos var_part_offset = fragP->fr_fix;
839 1.1 christos var_partp = fragP->fr_literal + var_part_offset;
840 1.1 christos opcodep = fragP->fr_opcode;
841 1.1 christos
842 1.1 christos symbolP = fragP->fr_symbol;
843 1.1 christos target_address = (symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset;
844 1.1 christos address_of_var_part = fragP->fr_address + var_part_offset;
845 1.1 christos
846 1.1 christos switch (fragP->fr_subtype)
847 1.1 christos {
848 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_BYTE):
849 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_BYTE):
850 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_BYTE):
851 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_BYTE):
852 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_BYTE):
853 1.1 christos opcodep[0] = branch_disp ((target_address - address_of_var_part));
854 1.1 christos var_part_size = 0;
855 1.1 christos break;
856 1.1 christos
857 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_WORD):
858 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_WORD):
859 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_WORD):
860 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_WORD):
861 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_WORD):
862 1.1 christos /* We had a quick immediate branch, now turn it into a word one i.e. a
863 1.1 christos PC autoincrement. */
864 1.1 christos opcodep[0] = BRANCH_PC_LOW;
865 1.1 christos opcodep[1] &= 0xF0;
866 1.1 christos opcodep[1] |= BRANCH_INCR_HIGH;
867 1.1 christos md_number_to_chars (var_partp,
868 1.1 christos (long)
869 1.1 christos (target_address
870 1.1 christos - (address_of_var_part
871 1.1 christos + (cris_arch == arch_crisv32
872 1.1 christos || cris_arch == arch_cris_common_v10_v32
873 1.1 christos ? -2 : 2))),
874 1.1 christos 2);
875 1.1 christos var_part_size = 2;
876 1.1 christos break;
877 1.1 christos
878 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
879 1.1 christos gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
880 1.1 christos fragP->fr_symbol, (symbolS *) NULL,
881 1.1 christos fragP->fr_offset);
882 1.1 christos /* Ten bytes added: a branch, nop and a jump. */
883 1.1 christos var_part_size = 2 + 2 + 4 + 2;
884 1.1 christos break;
885 1.1 christos
886 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD):
887 1.1 christos gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
888 1.1 christos fragP->fr_symbol, (symbolS *) NULL,
889 1.1 christos fragP->fr_offset);
890 1.1 christos /* Twelve bytes added: a branch, nop and a pic-branch-32. */
891 1.1 christos var_part_size = 2 + 2 + 4 + 2 + 2;
892 1.1 christos break;
893 1.1 christos
894 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
895 1.1 christos gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
896 1.1 christos fragP->fr_symbol, (symbolS *) NULL,
897 1.1 christos fragP->fr_offset);
898 1.1 christos /* Twelve bytes added: a branch, nop and another branch and nop. */
899 1.1 christos var_part_size = 2 + 2 + 2 + 4 + 2;
900 1.1 christos break;
901 1.1 christos
902 1.1 christos case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
903 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line,
904 1.1 christos _("Relaxation to long branches for .arch common_v10_v32\
905 1.1 christos not implemented"));
906 1.1 christos /* Pretend we have twelve bytes for sake of quelling further
907 1.1 christos errors. */
908 1.1 christos var_part_size = 2 + 2 + 2 + 4 + 2;
909 1.1 christos break;
910 1.1 christos
911 1.1 christos case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD):
912 1.1 christos /* We had a quick immediate branch or a word immediate ba. Now
913 1.1 christos turn it into a dword one. */
914 1.1 christos opcodep[0] = BA_DWORD_OPCODE & 255;
915 1.1 christos opcodep[1] = (BA_DWORD_OPCODE >> 8) & 255;
916 1.1 christos fix_new (fragP, var_partp - fragP->fr_literal, 4, symbolP,
917 1.1 christos fragP->fr_offset + 6, 1, BFD_RELOC_32_PCREL);
918 1.1 christos var_part_size = 4;
919 1.1 christos break;
920 1.1 christos
921 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_BYTE):
922 1.1 christos {
923 1.1 christos long offset = target_address - (address_of_var_part - 2);
924 1.1 christos
925 1.1 christos /* This is mostly a sanity check; useful occurrences (if there
926 1.1 christos really are any) should have been caught in
927 1.1 christos md_estimate_size_before_relax. We can (at least
928 1.1 christos theoretically) stumble over invalid code with odd sizes and
929 1.1 christos .p2aligns within the code, so emit an error if that happens.
930 1.1 christos (The generic relaxation machinery is not fit to check this.) */
931 1.1 christos
932 1.1 christos if (offset & 1)
933 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line,
934 1.1 christos _("Complicated LAPC target operand is not\
935 1.1 christos a multiple of two. Use LAPC.D"));
936 1.1 christos
937 1.1 christos /* FIXME: This *is* a sanity check. Remove when done with. */
938 1.1 christos if (offset > 15*2 || offset < 0)
939 1.1 christos as_fatal (_("Internal error found in md_convert_frag: offset %ld.\
940 1.1 christos Please report this."),
941 1.1 christos offset);
942 1.1 christos
943 1.1 christos opcodep[0] |= (offset / 2) & 0xf;
944 1.1 christos var_part_size = 0;
945 1.1 christos }
946 1.1 christos break;
947 1.1 christos
948 1.1 christos case ENCODE_RELAX (STATE_LAPC, STATE_DWORD):
949 1.1 christos {
950 1.1 christos md_number_to_chars (opcodep,
951 1.1 christos LAPC_DWORD_OPCODE + (opcodep[1] & 0xf0) * 256,
952 1.1 christos 2);
953 1.1 christos /* Remember that the reloc is against the position *after* the
954 1.1 christos relocated contents, so we need to adjust to the start of
955 1.1 christos the insn. */
956 1.1 christos fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol,
957 1.1 christos fragP->fr_offset + 6, 1, BFD_RELOC_32_PCREL);
958 1.1 christos var_part_size = 4;
959 1.1 christos }
960 1.1 christos break;
961 1.1 christos
962 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
963 1.1 christos if (symbolP == NULL)
964 1.1 christos as_fatal (_("internal inconsistency in %s: bdapq no symbol"),
965 1.1 christos __FUNCTION__);
966 1.1 christos opcodep[0] = S_GET_VALUE (symbolP);
967 1.1 christos var_part_size = 0;
968 1.1 christos break;
969 1.1 christos
970 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
971 1.1 christos /* We had a BDAP 8-bit "quick immediate", now turn it into a 16-bit
972 1.1 christos one that uses PC autoincrement. */
973 1.1 christos opcodep[0] = BDAP_PC_LOW + (1 << 4);
974 1.1 christos opcodep[1] &= 0xF0;
975 1.1 christos opcodep[1] |= BDAP_INCR_HIGH;
976 1.1 christos if (symbolP == NULL)
977 1.1 christos as_fatal (_("internal inconsistency in %s: bdap.w with no symbol"),
978 1.1 christos __FUNCTION__);
979 1.1 christos md_number_to_chars (var_partp, S_GET_VALUE (symbolP), 2);
980 1.1 christos var_part_size = 2;
981 1.1 christos break;
982 1.1 christos
983 1.1 christos case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
984 1.1 christos /* We had a BDAP 16-bit "word", change the offset to a dword. */
985 1.1 christos opcodep[0] = BDAP_PC_LOW + (2 << 4);
986 1.1 christos opcodep[1] &= 0xF0;
987 1.1 christos opcodep[1] |= BDAP_INCR_HIGH;
988 1.1 christos if (fragP->fr_symbol == NULL)
989 1.1 christos md_number_to_chars (var_partp, fragP->fr_offset, 4);
990 1.1 christos else
991 1.1 christos fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol,
992 1.1 christos fragP->fr_offset, 0, BFD_RELOC_32);
993 1.1 christos var_part_size = 4;
994 1.1 christos break;
995 1.1 christos
996 1.1 christos case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
997 1.1 christos /* This is the only time we check position and alignment of the
998 1.1 christos placement-tracking frag. */
999 1.1 christos if (sec->alignment_power < 2)
1000 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line,
1001 1.1 christos _("section alignment must be >= 4 bytes to check MULS/MULU safeness"));
1002 1.1 christos else
1003 1.1 christos {
1004 1.1 christos /* If the address after the MULS/MULU has alignment which is
1005 1.1 christos that of the section and may be that of a cache-size of the
1006 1.1 christos buggy versions, then the MULS/MULU can be placed badly. */
1007 1.1 christos if ((address_of_var_part
1008 1.1 christos & ((1 << sec->alignment_power) - 1) & 31) == 0)
1009 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line,
1010 1.1 christos _("dangerous MULS/MULU location; give it higher alignment"));
1011 1.1 christos }
1012 1.1 christos break;
1013 1.1 christos
1014 1.1 christos default:
1015 1.1 christos BAD_CASE (fragP->fr_subtype);
1016 1.1 christos break;
1017 1.1 christos }
1018 1.1 christos
1019 1.1 christos fragP->fr_fix += var_part_size;
1020 1.1 christos }
1021 1.1 christos
1022 1.1 christos /* Generate a short jump around a secondary jump table.
1023 1.1 christos Also called from md_create_long_jump, when sufficient. */
1024 1.1 christos
1025 1.1 christos void
1026 1.1 christos md_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
1027 1.1 christos fragS *fragP ATTRIBUTE_UNUSED,
1028 1.1 christos symbolS *to_symbol ATTRIBUTE_UNUSED)
1029 1.1 christos {
1030 1.1 christos long int distance;
1031 1.1 christos
1032 1.1 christos /* See md_create_long_jump about the comment on the "+ 2". */
1033 1.1 christos long int max_minimal_minus_distance;
1034 1.1 christos long int max_minimal_plus_distance;
1035 1.1 christos long int max_minus_distance;
1036 1.1 christos long int max_plus_distance;
1037 1.1 christos int nop_opcode;
1038 1.1 christos
1039 1.1 christos if (cris_arch == arch_crisv32)
1040 1.1 christos {
1041 1.1 christos max_minimal_minus_distance = BRANCH_BB_V32 + 2;
1042 1.1 christos max_minimal_plus_distance = BRANCH_BF_V32 + 2;
1043 1.1 christos max_minus_distance = BRANCH_WB_V32 + 2;
1044 1.1 christos max_plus_distance = BRANCH_WF_V32 + 2;
1045 1.1 christos nop_opcode = NOP_OPCODE_V32;
1046 1.1 christos }
1047 1.1 christos else if (cris_arch == arch_cris_common_v10_v32)
1048 1.1 christos /* Bail out for compatibility mode. (It seems it can be implemented,
1049 1.1 christos perhaps with a 10-byte sequence: "move.d NNNN,$pc/$acr", "jump
1050 1.1 christos $acr", "nop"; but doesn't seem worth it at the moment.) */
1051 1.1 christos as_fatal (_("Out-of-range .word offset handling\
1052 1.1 christos is not implemented for .arch common_v10_v32"));
1053 1.1 christos else
1054 1.1 christos {
1055 1.1 christos max_minimal_minus_distance = BRANCH_BB + 2;
1056 1.1 christos max_minimal_plus_distance = BRANCH_BF + 2;
1057 1.1 christos max_minus_distance = BRANCH_WB + 2;
1058 1.1 christos max_plus_distance = BRANCH_WF + 2;
1059 1.1 christos nop_opcode = NOP_OPCODE;
1060 1.1 christos }
1061 1.1 christos
1062 1.1 christos distance = to_addr - from_addr;
1063 1.1 christos
1064 1.1 christos if (max_minimal_minus_distance <= distance
1065 1.1 christos && distance <= max_minimal_plus_distance)
1066 1.1 christos {
1067 1.1 christos /* Create a "short" short jump: "BA distance - 2". */
1068 1.1 christos storep[0] = branch_disp (distance - 2);
1069 1.1 christos storep[1] = BA_QUICK_HIGH;
1070 1.1 christos
1071 1.1 christos /* A nop for the delay slot. */
1072 1.1 christos md_number_to_chars (storep + 2, nop_opcode, 2);
1073 1.1 christos
1074 1.1 christos /* The extra word should be filled with something sane too. Make it
1075 1.1 christos a nop to keep disassembly sane. */
1076 1.1 christos md_number_to_chars (storep + 4, nop_opcode, 2);
1077 1.1 christos }
1078 1.1 christos else if (max_minus_distance <= distance
1079 1.1 christos && distance <= max_plus_distance)
1080 1.1 christos {
1081 1.1 christos /* Make it a "long" short jump: "BA (PC+)". */
1082 1.1 christos md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2);
1083 1.1 christos
1084 1.1 christos /* ".WORD distance - 4". */
1085 1.1 christos md_number_to_chars (storep + 2,
1086 1.1 christos (long) (distance - 4
1087 1.1 christos - (cris_arch == arch_crisv32
1088 1.1 christos ? -4 : 0)),
1089 1.1 christos 2);
1090 1.1 christos
1091 1.1 christos /* A nop for the delay slot. */
1092 1.1 christos md_number_to_chars (storep + 4, nop_opcode, 2);
1093 1.1 christos }
1094 1.1 christos else
1095 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line,
1096 1.1 christos _(".word case-table handling failed: table too large"));
1097 1.1 christos }
1098 1.1 christos
1099 1.1 christos /* Generate a long jump in a secondary jump table.
1100 1.1 christos
1101 1.1 christos storep Where to store the jump instruction.
1102 1.1 christos from_addr Address of the jump instruction.
1103 1.1 christos to_addr Destination address of the jump.
1104 1.1 christos fragP Which frag the destination address operand
1105 1.1 christos lies in.
1106 1.1 christos to_symbol Destination symbol. */
1107 1.1 christos
1108 1.1 christos void
1109 1.1 christos md_create_long_jump (char *storep, addressT from_addr, addressT to_addr,
1110 1.1 christos fragS *fragP, symbolS *to_symbol)
1111 1.1 christos {
1112 1.1 christos long int distance;
1113 1.1 christos
1114 1.1 christos /* FIXME: What's that "+ 3"? It comes from the magic numbers that
1115 1.1 christos used to be here, it's just translated to the limit macros used in
1116 1.1 christos the relax table. But why + 3? */
1117 1.1 christos long int max_short_minus_distance
1118 1.1 christos = cris_arch != arch_crisv32 ? BRANCH_WB + 3 : BRANCH_WB_V32 + 3;
1119 1.1 christos
1120 1.1 christos long int max_short_plus_distance
1121 1.1 christos = cris_arch != arch_crisv32 ? BRANCH_WF + 3 : BRANCH_WF_V32 + 3;
1122 1.1 christos
1123 1.1 christos distance = to_addr - from_addr;
1124 1.1 christos
1125 1.1 christos if (max_short_minus_distance <= distance
1126 1.1 christos && distance <= max_short_plus_distance)
1127 1.3 christos {
1128 1.3 christos /* Then make it a "short" long jump. */
1129 1.3 christos md_create_short_jump (storep, from_addr, to_addr, fragP,
1130 1.1 christos to_symbol);
1131 1.3 christos if (cris_arch == arch_crisv32)
1132 1.3 christos md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2);
1133 1.3 christos else
1134 1.3 christos md_number_to_chars (storep + 6, NOP_OPCODE, 2);
1135 1.3 christos }
1136 1.1 christos else
1137 1.1 christos {
1138 1.1 christos /* We have a "long" long jump: "JUMP [PC+]". If CRISv32, always
1139 1.1 christos make it a BA. Else make it an "MOVE [PC=PC+N],P0" if we're supposed
1140 1.1 christos to emit PIC code. */
1141 1.1 christos md_number_to_chars (storep,
1142 1.1 christos cris_arch == arch_crisv32
1143 1.1 christos ? BA_DWORD_OPCODE
1144 1.1 christos : (pic ? MOVE_PC_INCR_OPCODE_PREFIX
1145 1.1 christos : JUMP_PC_INCR_OPCODE),
1146 1.1 christos 2);
1147 1.1 christos
1148 1.1 christos /* Follow with a ".DWORD to_addr", PC-relative for PIC. */
1149 1.1 christos fix_new (fragP, storep + 2 - fragP->fr_literal, 4, to_symbol,
1150 1.1 christos cris_arch == arch_crisv32 ? 6 : 0,
1151 1.1 christos cris_arch == arch_crisv32 || pic ? 1 : 0,
1152 1.1 christos cris_arch == arch_crisv32 || pic
1153 1.1 christos ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
1154 1.1 christos
1155 1.1 christos /* Follow it with a "NOP" for CRISv32. */
1156 1.1 christos if (cris_arch == arch_crisv32)
1157 1.1 christos md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2);
1158 1.1 christos else if (pic)
1159 1.1 christos /* ...and the rest of the move-opcode for pre-v32 PIC. */
1160 1.1 christos md_number_to_chars (storep + 6, MOVE_PC_INCR_OPCODE_SUFFIX, 2);
1161 1.1 christos }
1162 1.1 christos }
1163 1.1 christos
1164 1.1 christos /* Allocate space for the first piece of an insn, and mark it as the
1165 1.1 christos start of the insn for debug-format use. */
1166 1.1 christos
1167 1.1 christos static char *
1168 1.1 christos cris_insn_first_word_frag (void)
1169 1.1 christos {
1170 1.1 christos char *insnp = frag_more (2);
1171 1.1 christos
1172 1.1 christos /* We need to mark the start of the insn by passing dwarf2_emit_insn
1173 1.1 christos the offset from the current fragment position. This must be done
1174 1.1 christos after the first fragment is created but before any other fragments
1175 1.1 christos (fixed or varying) are created. Note that the offset only
1176 1.1 christos corresponds to the "size" of the insn for a fixed-size,
1177 1.1 christos non-expanded insn. */
1178 1.1 christos if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1179 1.1 christos dwarf2_emit_insn (2);
1180 1.1 christos
1181 1.1 christos return insnp;
1182 1.1 christos }
1183 1.1 christos
1184 1.1 christos /* Port-specific assembler initialization. */
1185 1.1 christos
1186 1.1 christos void
1187 1.1 christos md_begin (void)
1188 1.1 christos {
1189 1.1 christos int i = 0;
1190 1.1 christos
1191 1.1 christos /* Set up a hash table for the instructions. */
1192 1.8 christos op_hash = str_htab_create ();
1193 1.1 christos
1194 1.1 christos /* Enable use of ".if ..asm.arch.cris.v32"
1195 1.1 christos and ".if ..asm.arch.cris.common_v10_v32" and a few others. */
1196 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.v32", absolute_section,
1197 1.8 christos &zero_address_frag,
1198 1.8 christos cris_arch == arch_crisv32));
1199 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.v10", absolute_section,
1200 1.8 christos &zero_address_frag,
1201 1.8 christos cris_arch == arch_crisv10));
1202 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.common_v10_v32",
1203 1.1 christos absolute_section,
1204 1.8 christos &zero_address_frag,
1205 1.8 christos cris_arch == arch_cris_common_v10_v32));
1206 1.1 christos symbol_table_insert (symbol_new ("..asm.arch.cris.any_v0_v10",
1207 1.1 christos absolute_section,
1208 1.8 christos &zero_address_frag,
1209 1.8 christos cris_arch == arch_cris_any_v0_v10));
1210 1.1 christos
1211 1.1 christos while (cris_opcodes[i].name != NULL)
1212 1.1 christos {
1213 1.1 christos const char *name = cris_opcodes[i].name;
1214 1.1 christos
1215 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_opcodes[i].applicable_version,
1216 1.1 christos cris_arch))
1217 1.1 christos {
1218 1.1 christos i++;
1219 1.1 christos continue;
1220 1.1 christos }
1221 1.1 christos
1222 1.8 christos if (str_hash_insert (op_hash, name, &cris_opcodes[i], 0) != NULL)
1223 1.8 christos as_fatal (_("duplicate %s"), name);
1224 1.1 christos
1225 1.1 christos do
1226 1.1 christos {
1227 1.1 christos if (cris_opcodes[i].match & cris_opcodes[i].lose)
1228 1.1 christos as_fatal (_("Buggy opcode: `%s' \"%s\"\n"), cris_opcodes[i].name,
1229 1.1 christos cris_opcodes[i].args);
1230 1.1 christos
1231 1.1 christos ++i;
1232 1.1 christos }
1233 1.1 christos while (cris_opcodes[i].name != NULL
1234 1.1 christos && strcmp (cris_opcodes[i].name, name) == 0);
1235 1.1 christos }
1236 1.1 christos }
1237 1.1 christos
1238 1.1 christos /* Assemble a source line. */
1239 1.1 christos
1240 1.1 christos void
1241 1.1 christos md_assemble (char *str)
1242 1.1 christos {
1243 1.1 christos struct cris_instruction output_instruction;
1244 1.1 christos struct cris_prefix prefix;
1245 1.1 christos char *opcodep;
1246 1.1 christos char *p;
1247 1.1 christos
1248 1.1 christos know (str);
1249 1.1 christos
1250 1.1 christos /* Do the low-level grunt - assemble to bits and split up into a prefix
1251 1.1 christos and ordinary insn. */
1252 1.1 christos cris_process_instruction (str, &output_instruction, &prefix);
1253 1.1 christos
1254 1.1 christos /* Handle any prefixes to the instruction. */
1255 1.1 christos switch (prefix.kind)
1256 1.1 christos {
1257 1.1 christos case PREFIX_NONE:
1258 1.1 christos break;
1259 1.1 christos
1260 1.1 christos /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
1261 1.1 christos extra bytes, so we handle it separately. */
1262 1.1 christos case PREFIX_BDAP_IMM:
1263 1.1 christos /* We only do it if the relocation is unspecified, i.e. not a PIC or TLS
1264 1.1 christos relocation. */
1265 1.1 christos if (prefix.reloc == BFD_RELOC_NONE)
1266 1.1 christos {
1267 1.1 christos gen_bdap (prefix.base_reg_number, &prefix.expr);
1268 1.1 christos break;
1269 1.1 christos }
1270 1.1 christos /* Fall through. */
1271 1.1 christos case PREFIX_BDAP:
1272 1.1 christos case PREFIX_BIAP:
1273 1.1 christos case PREFIX_DIP:
1274 1.1 christos opcodep = cris_insn_first_word_frag ();
1275 1.1 christos
1276 1.1 christos /* Output the prefix opcode. */
1277 1.1 christos md_number_to_chars (opcodep, (long) prefix.opcode, 2);
1278 1.1 christos
1279 1.1 christos /* Having a specified reloc only happens for DIP and for BDAP with
1280 1.1 christos PIC or TLS operands, but it is ok to drop through here for the other
1281 1.1 christos prefixes as they can have no relocs specified. */
1282 1.1 christos if (prefix.reloc != BFD_RELOC_NONE)
1283 1.1 christos {
1284 1.1 christos unsigned int relocsize
1285 1.1 christos = (prefix.kind == PREFIX_DIP
1286 1.1 christos ? 4 : cris_get_specified_reloc_size (prefix.reloc));
1287 1.1 christos
1288 1.1 christos p = frag_more (relocsize);
1289 1.1 christos fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize,
1290 1.1 christos &prefix.expr, 0, prefix.reloc);
1291 1.1 christos }
1292 1.1 christos break;
1293 1.1 christos
1294 1.1 christos case PREFIX_PUSH:
1295 1.1 christos opcodep = cris_insn_first_word_frag ();
1296 1.1 christos
1297 1.1 christos /* Output the prefix opcode. Being a "push", we add the negative
1298 1.1 christos size of the register to "sp". */
1299 1.1 christos if (output_instruction.spec_reg != NULL)
1300 1.1 christos {
1301 1.1 christos /* Special register. */
1302 1.1 christos opcodep[0] = -output_instruction.spec_reg->reg_size;
1303 1.1 christos }
1304 1.1 christos else
1305 1.1 christos {
1306 1.1 christos /* General register. */
1307 1.1 christos opcodep[0] = -4;
1308 1.1 christos }
1309 1.1 christos opcodep[1] = (REG_SP << 4) + (BDAP_QUICK_OPCODE >> 8);
1310 1.1 christos break;
1311 1.1 christos
1312 1.1 christos default:
1313 1.1 christos BAD_CASE (prefix.kind);
1314 1.1 christos }
1315 1.1 christos
1316 1.1 christos /* If we only had a prefix insn, we're done. */
1317 1.1 christos if (output_instruction.insn_type == CRIS_INSN_NONE)
1318 1.1 christos return;
1319 1.1 christos
1320 1.1 christos /* Done with the prefix. Continue with the main instruction. */
1321 1.1 christos if (prefix.kind == PREFIX_NONE)
1322 1.1 christos opcodep = cris_insn_first_word_frag ();
1323 1.1 christos else
1324 1.1 christos opcodep = frag_more (2);
1325 1.1 christos
1326 1.1 christos /* Output the instruction opcode. */
1327 1.1 christos md_number_to_chars (opcodep, (long) (output_instruction.opcode), 2);
1328 1.1 christos
1329 1.1 christos /* Output the symbol-dependent instruction stuff. */
1330 1.1 christos if (output_instruction.insn_type == CRIS_INSN_BRANCH)
1331 1.1 christos {
1332 1.1 christos segT to_seg = absolute_section;
1333 1.1 christos int is_undefined = 0;
1334 1.1 christos int length_code;
1335 1.1 christos
1336 1.1 christos if (output_instruction.expr.X_op != O_constant)
1337 1.1 christos {
1338 1.1 christos to_seg = S_GET_SEGMENT (output_instruction.expr.X_add_symbol);
1339 1.1 christos
1340 1.1 christos if (to_seg == undefined_section)
1341 1.1 christos is_undefined = 1;
1342 1.1 christos }
1343 1.1 christos
1344 1.1 christos if (to_seg == now_seg || is_undefined
1345 1.1 christos /* In CRISv32, there *is* a 32-bit absolute branch, so don't
1346 1.1 christos emit the 12-byte sequence for known symbols in other
1347 1.1 christos segments. */
1348 1.1 christos || (cris_arch == arch_crisv32
1349 1.1 christos && output_instruction.opcode == BA_QUICK_OPCODE))
1350 1.1 christos {
1351 1.1 christos /* Handle complex expressions. */
1352 1.1 christos valueT addvalue
1353 1.1 christos = (SIMPLE_EXPR (&output_instruction.expr)
1354 1.1 christos ? output_instruction.expr.X_add_number
1355 1.1 christos : 0);
1356 1.1 christos symbolS *sym
1357 1.1 christos = (SIMPLE_EXPR (&output_instruction.expr)
1358 1.1 christos ? output_instruction.expr.X_add_symbol
1359 1.1 christos : make_expr_symbol (&output_instruction.expr));
1360 1.1 christos
1361 1.1 christos /* If is_undefined, the expression may still become now_seg.
1362 1.1 christos That case is handled by md_estimate_size_before_relax. */
1363 1.1 christos length_code = to_seg == now_seg ? STATE_BYTE : STATE_UNDF;
1364 1.1 christos
1365 1.1 christos /* Make room for max twelve bytes of variable length for v32 mode
1366 1.1 christos or PIC, ten for v10 and older. */
1367 1.1 christos frag_var (rs_machine_dependent,
1368 1.1 christos (cris_arch == arch_crisv32
1369 1.1 christos || cris_arch == arch_cris_common_v10_v32
1370 1.1 christos || pic) ? 12 : 10, 0,
1371 1.1 christos ENCODE_RELAX (cris_arch == arch_crisv32
1372 1.1 christos ? (output_instruction.opcode
1373 1.1 christos == BA_QUICK_OPCODE
1374 1.1 christos ? STATE_ABS_BRANCH_V32
1375 1.1 christos : STATE_COND_BRANCH_V32)
1376 1.1 christos : (cris_arch == arch_cris_common_v10_v32
1377 1.1 christos ? STATE_COND_BRANCH_COMMON
1378 1.1 christos : (pic ? STATE_COND_BRANCH_PIC
1379 1.1 christos : STATE_COND_BRANCH)),
1380 1.1 christos length_code),
1381 1.1 christos sym, addvalue, opcodep);
1382 1.1 christos }
1383 1.1 christos else
1384 1.1 christos {
1385 1.1 christos /* We have: to_seg != now_seg && to_seg != undefined_section.
1386 1.1 christos This means it is a branch to a known symbol in another
1387 1.1 christos section, perhaps an absolute address. Emit a 32-bit branch. */
1388 1.1 christos char *cond_jump
1389 1.1 christos = frag_more ((cris_arch == arch_crisv32
1390 1.1 christos || cris_arch == arch_cris_common_v10_v32
1391 1.1 christos || pic)
1392 1.1 christos ? 12 : 10);
1393 1.1 christos
1394 1.1 christos gen_cond_branch_32 (opcodep, cond_jump, frag_now,
1395 1.1 christos output_instruction.expr.X_add_symbol,
1396 1.1 christos (symbolS *) NULL,
1397 1.1 christos output_instruction.expr.X_add_number);
1398 1.1 christos }
1399 1.1 christos }
1400 1.1 christos else if (output_instruction.insn_type == CRIS_INSN_MUL
1401 1.1 christos && err_for_dangerous_mul_placement)
1402 1.1 christos /* Create a frag which which we track the location of the mul insn
1403 1.1 christos (in the last two bytes before the mul-frag). */
1404 1.1 christos frag_variant (rs_machine_dependent, 0, 0,
1405 1.1 christos ENCODE_RELAX (STATE_MUL, STATE_BYTE),
1406 1.1 christos NULL, 0, opcodep);
1407 1.1 christos else
1408 1.1 christos {
1409 1.1 christos if (output_instruction.imm_oprnd_size > 0)
1410 1.1 christos {
1411 1.1 christos /* The instruction has an immediate operand. */
1412 1.1 christos enum bfd_reloc_code_real reloc = BFD_RELOC_NONE;
1413 1.1 christos
1414 1.1 christos switch (output_instruction.imm_oprnd_size)
1415 1.1 christos {
1416 1.1 christos /* Any byte-size immediate constants are treated as
1417 1.1 christos word-size. FIXME: Thus overflow check does not work
1418 1.1 christos correctly. */
1419 1.1 christos
1420 1.1 christos case 2:
1421 1.1 christos /* Note that size-check for the explicit reloc has already
1422 1.1 christos been done when we get here. */
1423 1.1 christos if (output_instruction.reloc != BFD_RELOC_NONE)
1424 1.1 christos reloc = output_instruction.reloc;
1425 1.1 christos else
1426 1.1 christos reloc = BFD_RELOC_16;
1427 1.1 christos break;
1428 1.1 christos
1429 1.1 christos case 4:
1430 1.1 christos /* Allow a relocation specified in the operand. */
1431 1.1 christos if (output_instruction.reloc != BFD_RELOC_NONE)
1432 1.1 christos reloc = output_instruction.reloc;
1433 1.1 christos else
1434 1.1 christos reloc = BFD_RELOC_32;
1435 1.1 christos break;
1436 1.1 christos
1437 1.1 christos default:
1438 1.1 christos BAD_CASE (output_instruction.imm_oprnd_size);
1439 1.1 christos }
1440 1.1 christos
1441 1.1 christos p = frag_more (output_instruction.imm_oprnd_size);
1442 1.1 christos fix_new_exp (frag_now, (p - frag_now->fr_literal),
1443 1.1 christos output_instruction.imm_oprnd_size,
1444 1.1 christos &output_instruction.expr,
1445 1.1 christos reloc == BFD_RELOC_32_PCREL
1446 1.1 christos || reloc == BFD_RELOC_16_PCREL
1447 1.1 christos || reloc == BFD_RELOC_8_PCREL, reloc);
1448 1.1 christos }
1449 1.1 christos else if (output_instruction.reloc == BFD_RELOC_CRIS_LAPCQ_OFFSET
1450 1.1 christos && output_instruction.expr.X_md != 0)
1451 1.1 christos {
1452 1.1 christos /* Handle complex expressions. */
1453 1.1 christos valueT addvalue
1454 1.1 christos = (output_instruction.expr.X_op_symbol != NULL
1455 1.1 christos ? 0 : output_instruction.expr.X_add_number);
1456 1.1 christos symbolS *sym
1457 1.1 christos = (output_instruction.expr.X_op_symbol != NULL
1458 1.1 christos ? make_expr_symbol (&output_instruction.expr)
1459 1.1 christos : output_instruction.expr.X_add_symbol);
1460 1.1 christos
1461 1.1 christos /* This is a relaxing construct, so we need a frag_var rather
1462 1.1 christos than the fix_new_exp call below. */
1463 1.1 christos frag_var (rs_machine_dependent,
1464 1.1 christos 4, 0,
1465 1.1 christos ENCODE_RELAX (STATE_LAPC, STATE_UNDF),
1466 1.1 christos sym, addvalue, opcodep);
1467 1.1 christos }
1468 1.1 christos else if (output_instruction.reloc != BFD_RELOC_NONE)
1469 1.1 christos {
1470 1.1 christos /* An immediate operand that has a relocation and needs to be
1471 1.1 christos processed further. */
1472 1.1 christos
1473 1.1 christos /* It is important to use fix_new_exp here and everywhere else
1474 1.1 christos (and not fix_new), as fix_new_exp can handle "difference
1475 1.1 christos expressions" - where the expression contains a difference of
1476 1.1 christos two symbols in the same segment. */
1477 1.1 christos fix_new_exp (frag_now, (opcodep - frag_now->fr_literal), 2,
1478 1.1 christos &output_instruction.expr,
1479 1.1 christos output_instruction.reloc == BFD_RELOC_32_PCREL
1480 1.1 christos || output_instruction.reloc == BFD_RELOC_16_PCREL
1481 1.1 christos || output_instruction.reloc == BFD_RELOC_8_PCREL
1482 1.1 christos || (output_instruction.reloc
1483 1.1 christos == BFD_RELOC_CRIS_LAPCQ_OFFSET),
1484 1.1 christos output_instruction.reloc);
1485 1.1 christos }
1486 1.1 christos }
1487 1.1 christos }
1488 1.1 christos
1489 1.3 christos /* Helper error-reporting function: calls as_bad for a format string
1490 1.3 christos for a single value and zeroes the offending value (zero assumed
1491 1.3 christos being a valid value) to avoid repeated error reports in later value
1492 1.3 christos checking. */
1493 1.3 christos
1494 1.3 christos static void
1495 1.3 christos cris_bad (const char *format, offsetT *valp)
1496 1.3 christos {
1497 1.3 christos /* We cast to long so the format string can assume that format. */
1498 1.3 christos as_bad (format, (long) *valp);
1499 1.3 christos *valp = 0;
1500 1.3 christos }
1501 1.3 christos
1502 1.1 christos /* Low level text-to-bits assembly. */
1503 1.1 christos
1504 1.1 christos static void
1505 1.1 christos cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
1506 1.1 christos struct cris_prefix *prefixp)
1507 1.1 christos {
1508 1.1 christos char *s;
1509 1.1 christos char modified_char = 0;
1510 1.1 christos const char *args;
1511 1.1 christos struct cris_opcode *instruction;
1512 1.1 christos char *operands;
1513 1.1 christos int match = 0;
1514 1.1 christos int mode;
1515 1.1 christos int regno;
1516 1.1 christos int size_bits;
1517 1.1 christos
1518 1.1 christos /* Reset these fields to a harmless state in case we need to return in
1519 1.1 christos error. */
1520 1.1 christos prefixp->kind = PREFIX_NONE;
1521 1.1 christos prefixp->reloc = BFD_RELOC_NONE;
1522 1.1 christos out_insnp->insn_type = CRIS_INSN_NONE;
1523 1.1 christos out_insnp->imm_oprnd_size = 0;
1524 1.1 christos
1525 1.1 christos /* Find the end of the opcode mnemonic. We assume (true in 2.9.1)
1526 1.1 christos that the caller has translated the opcode to lower-case, up to the
1527 1.1 christos first non-letter. */
1528 1.1 christos for (operands = insn_text; ISLOWER (*operands); ++operands)
1529 1.1 christos ;
1530 1.1 christos
1531 1.1 christos /* Terminate the opcode after letters, but save the character there if
1532 1.1 christos it was of significance. */
1533 1.1 christos switch (*operands)
1534 1.1 christos {
1535 1.1 christos case '\0':
1536 1.1 christos break;
1537 1.1 christos
1538 1.1 christos case '.':
1539 1.1 christos /* Put back the modified character later. */
1540 1.1 christos modified_char = *operands;
1541 1.1 christos /* Fall through. */
1542 1.1 christos
1543 1.1 christos case ' ':
1544 1.1 christos /* Consume the character after the mnemonic
1545 1.1 christos and replace it with '\0'. */
1546 1.1 christos *operands++ = '\0';
1547 1.1 christos break;
1548 1.1 christos
1549 1.1 christos default:
1550 1.1 christos as_bad (_("Unknown opcode: `%s'"), insn_text);
1551 1.1 christos return;
1552 1.1 christos }
1553 1.1 christos
1554 1.1 christos /* Find the instruction. */
1555 1.8 christos instruction = (struct cris_opcode *) str_hash_find (op_hash, insn_text);
1556 1.1 christos if (instruction == NULL)
1557 1.1 christos {
1558 1.1 christos as_bad (_("Unknown opcode: `%s'"), insn_text);
1559 1.1 christos return;
1560 1.1 christos }
1561 1.1 christos
1562 1.1 christos /* Put back the modified character. */
1563 1.1 christos switch (modified_char)
1564 1.1 christos {
1565 1.1 christos case 0:
1566 1.1 christos break;
1567 1.1 christos
1568 1.1 christos default:
1569 1.1 christos *--operands = modified_char;
1570 1.1 christos }
1571 1.1 christos
1572 1.1 christos /* Try to match an opcode table slot. */
1573 1.1 christos for (s = operands;;)
1574 1.1 christos {
1575 1.1 christos int imm_expr_found;
1576 1.1 christos
1577 1.1 christos /* Initialize *prefixp, perhaps after being modified for a
1578 1.1 christos "near match". */
1579 1.1 christos prefixp->kind = PREFIX_NONE;
1580 1.1 christos prefixp->reloc = BFD_RELOC_NONE;
1581 1.1 christos
1582 1.1 christos /* Initialize *out_insnp. */
1583 1.1 christos memset (out_insnp, 0, sizeof (*out_insnp));
1584 1.1 christos out_insnp->opcode = instruction->match;
1585 1.1 christos out_insnp->reloc = BFD_RELOC_NONE;
1586 1.1 christos out_insnp->insn_type = CRIS_INSN_NORMAL;
1587 1.1 christos out_insnp->imm_oprnd_size = 0;
1588 1.1 christos
1589 1.1 christos imm_expr_found = 0;
1590 1.1 christos
1591 1.1 christos /* Build the opcode, checking as we go to make sure that the
1592 1.1 christos operands match. */
1593 1.1 christos for (args = instruction->args;; ++args)
1594 1.1 christos {
1595 1.1 christos switch (*args)
1596 1.1 christos {
1597 1.1 christos case '\0':
1598 1.1 christos /* If we've come to the end of arguments, we're done. */
1599 1.1 christos if (*s == '\0')
1600 1.1 christos match = 1;
1601 1.1 christos break;
1602 1.1 christos
1603 1.1 christos case '!':
1604 1.1 christos /* Non-matcher character for disassembly.
1605 1.1 christos Ignore it here. */
1606 1.1 christos continue;
1607 1.1 christos
1608 1.1 christos case '[':
1609 1.1 christos case ']':
1610 1.1 christos case ',':
1611 1.1 christos case ' ':
1612 1.1 christos /* These must match exactly. */
1613 1.1 christos if (*s++ == *args)
1614 1.1 christos continue;
1615 1.1 christos break;
1616 1.1 christos
1617 1.1 christos case 'A':
1618 1.1 christos /* "ACR", case-insensitive.
1619 1.1 christos Handle a sometimes-mandatory dollar sign as register
1620 1.1 christos prefix. */
1621 1.1 christos if (*s == REGISTER_PREFIX_CHAR)
1622 1.1 christos s++;
1623 1.1 christos else if (demand_register_prefix)
1624 1.1 christos break;
1625 1.1 christos
1626 1.1 christos if ((*s++ != 'a' && s[-1] != 'A')
1627 1.1 christos || (*s++ != 'c' && s[-1] != 'C')
1628 1.1 christos || (*s++ != 'r' && s[-1] != 'R'))
1629 1.1 christos break;
1630 1.1 christos continue;
1631 1.1 christos
1632 1.1 christos case 'B':
1633 1.1 christos /* This is not really an operand, but causes a "BDAP
1634 1.1 christos -size,SP" prefix to be output, for PUSH instructions. */
1635 1.1 christos prefixp->kind = PREFIX_PUSH;
1636 1.1 christos continue;
1637 1.1 christos
1638 1.1 christos case 'b':
1639 1.1 christos /* This letter marks an operand that should not be matched
1640 1.1 christos in the assembler. It is a branch with 16-bit
1641 1.1 christos displacement. The assembler will create them from the
1642 1.1 christos 8-bit flavor when necessary. The assembler does not
1643 1.1 christos support the [rN+] operand, as the [r15+] that is
1644 1.1 christos generated for 16-bit displacements. */
1645 1.1 christos break;
1646 1.1 christos
1647 1.1 christos case 'c':
1648 1.1 christos /* A 5-bit unsigned immediate in bits <4:0>. */
1649 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr))
1650 1.1 christos break;
1651 1.1 christos else
1652 1.1 christos {
1653 1.1 christos if (out_insnp->expr.X_op == O_constant
1654 1.1 christos && (out_insnp->expr.X_add_number < 0
1655 1.1 christos || out_insnp->expr.X_add_number > 31))
1656 1.3 christos cris_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
1657 1.3 christos &out_insnp->expr.X_add_number);
1658 1.1 christos
1659 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
1660 1.1 christos continue;
1661 1.1 christos }
1662 1.1 christos
1663 1.1 christos case 'C':
1664 1.1 christos /* A 4-bit unsigned immediate in bits <3:0>. */
1665 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr))
1666 1.1 christos break;
1667 1.1 christos else
1668 1.1 christos {
1669 1.1 christos if (out_insnp->expr.X_op == O_constant
1670 1.1 christos && (out_insnp->expr.X_add_number < 0
1671 1.1 christos || out_insnp->expr.X_add_number > 15))
1672 1.3 christos cris_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
1673 1.3 christos &out_insnp->expr.X_add_number);
1674 1.1 christos
1675 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
1676 1.1 christos continue;
1677 1.1 christos }
1678 1.1 christos
1679 1.1 christos /* For 'd', check for an optional ".d" or ".D" at the
1680 1.1 christos start of the operands, followed by a space character. */
1681 1.1 christos case 'd':
1682 1.1 christos if (modified_char == '.' && *s == '.')
1683 1.1 christos {
1684 1.1 christos if ((s[1] != 'd' && s[1] == 'D')
1685 1.1 christos || ! ISSPACE (s[2]))
1686 1.1 christos break;
1687 1.1 christos s += 2;
1688 1.1 christos continue;
1689 1.1 christos }
1690 1.1 christos continue;
1691 1.1 christos
1692 1.1 christos case 'D':
1693 1.1 christos /* General register in bits <15:12> and <3:0>. */
1694 1.1 christos if (! get_gen_reg (&s, ®no))
1695 1.1 christos break;
1696 1.1 christos else
1697 1.1 christos {
1698 1.1 christos out_insnp->opcode |= regno /* << 0 */;
1699 1.1 christos out_insnp->opcode |= regno << 12;
1700 1.1 christos continue;
1701 1.1 christos }
1702 1.1 christos
1703 1.1 christos case 'f':
1704 1.1 christos /* Flags from the condition code register. */
1705 1.1 christos {
1706 1.1 christos int flags = 0;
1707 1.1 christos
1708 1.1 christos if (! get_flags (&s, &flags))
1709 1.1 christos break;
1710 1.1 christos
1711 1.1 christos out_insnp->opcode |= ((flags & 0xf0) << 8) | (flags & 0xf);
1712 1.1 christos continue;
1713 1.1 christos }
1714 1.1 christos
1715 1.1 christos case 'i':
1716 1.1 christos /* A 6-bit signed immediate in bits <5:0>. */
1717 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr))
1718 1.1 christos break;
1719 1.1 christos else
1720 1.1 christos {
1721 1.1 christos if (out_insnp->expr.X_op == O_constant
1722 1.1 christos && (out_insnp->expr.X_add_number < -32
1723 1.1 christos || out_insnp->expr.X_add_number > 31))
1724 1.3 christos cris_bad (_("Immediate value not in 6 bit range: %ld"),
1725 1.3 christos &out_insnp->expr.X_add_number);
1726 1.3 christos
1727 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
1728 1.1 christos continue;
1729 1.1 christos }
1730 1.1 christos
1731 1.1 christos case 'I':
1732 1.1 christos /* A 6-bit unsigned immediate in bits <5:0>. */
1733 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr))
1734 1.1 christos break;
1735 1.1 christos else
1736 1.1 christos {
1737 1.1 christos if (out_insnp->expr.X_op == O_constant
1738 1.1 christos && (out_insnp->expr.X_add_number < 0
1739 1.1 christos || out_insnp->expr.X_add_number > 63))
1740 1.3 christos cris_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
1741 1.3 christos &out_insnp->expr.X_add_number);
1742 1.3 christos
1743 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
1744 1.1 christos continue;
1745 1.1 christos }
1746 1.1 christos
1747 1.1 christos case 'M':
1748 1.1 christos /* A size modifier, B, W or D, to be put in a bit position
1749 1.1 christos suitable for CLEAR instructions (i.e. reflecting a zero
1750 1.1 christos register). */
1751 1.1 christos if (! get_bwd_size_modifier (&s, &size_bits))
1752 1.1 christos break;
1753 1.1 christos else
1754 1.1 christos {
1755 1.1 christos switch (size_bits)
1756 1.1 christos {
1757 1.1 christos case 0:
1758 1.1 christos out_insnp->opcode |= 0 << 12;
1759 1.1 christos break;
1760 1.1 christos
1761 1.1 christos case 1:
1762 1.1 christos out_insnp->opcode |= 4 << 12;
1763 1.1 christos break;
1764 1.1 christos
1765 1.1 christos case 2:
1766 1.1 christos out_insnp->opcode |= 8 << 12;
1767 1.1 christos break;
1768 1.1 christos }
1769 1.1 christos continue;
1770 1.1 christos }
1771 1.1 christos
1772 1.1 christos case 'm':
1773 1.1 christos /* A size modifier, B, W or D, to be put in bits <5:4>. */
1774 1.1 christos if (modified_char != '.'
1775 1.1 christos || ! get_bwd_size_modifier (&s, &size_bits))
1776 1.1 christos break;
1777 1.1 christos else
1778 1.1 christos {
1779 1.1 christos out_insnp->opcode |= size_bits << 4;
1780 1.1 christos continue;
1781 1.1 christos }
1782 1.1 christos
1783 1.1 christos case 'o':
1784 1.1 christos /* A branch expression. */
1785 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr))
1786 1.1 christos break;
1787 1.1 christos else
1788 1.1 christos {
1789 1.1 christos out_insnp->insn_type = CRIS_INSN_BRANCH;
1790 1.1 christos continue;
1791 1.1 christos }
1792 1.1 christos
1793 1.1 christos case 'Q':
1794 1.1 christos /* A 8-bit quick BDAP expression, "expr,R". */
1795 1.1 christos if (! cris_get_expression (&s, &out_insnp->expr))
1796 1.1 christos break;
1797 1.1 christos
1798 1.1 christos if (*s != ',')
1799 1.1 christos break;
1800 1.1 christos
1801 1.1 christos s++;
1802 1.1 christos
1803 1.1 christos if (!get_gen_reg (&s, ®no))
1804 1.1 christos break;
1805 1.1 christos
1806 1.1 christos out_insnp->opcode |= regno << 12;
1807 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_8;
1808 1.1 christos continue;
1809 1.3 christos
1810 1.1 christos case 'O':
1811 1.1 christos /* A BDAP expression for any size, "expr,R". */
1812 1.1 christos if (! cris_get_expression (&s, &prefixp->expr))
1813 1.1 christos break;
1814 1.1 christos else
1815 1.1 christos {
1816 1.1 christos if (*s != ',')
1817 1.1 christos break;
1818 1.1 christos
1819 1.1 christos s++;
1820 1.1 christos
1821 1.1 christos if (!get_gen_reg (&s, &prefixp->base_reg_number))
1822 1.1 christos break;
1823 1.1 christos
1824 1.1 christos /* Since 'O' is used with an explicit bdap, we have no
1825 1.1 christos "real" instruction. */
1826 1.1 christos prefixp->kind = PREFIX_BDAP_IMM;
1827 1.1 christos prefixp->opcode
1828 1.1 christos = BDAP_QUICK_OPCODE | (prefixp->base_reg_number << 12);
1829 1.1 christos
1830 1.1 christos out_insnp->insn_type = CRIS_INSN_NONE;
1831 1.1 christos continue;
1832 1.1 christos }
1833 1.1 christos
1834 1.1 christos case 'P':
1835 1.1 christos /* Special register in bits <15:12>. */
1836 1.1 christos if (! get_spec_reg (&s, &out_insnp->spec_reg))
1837 1.1 christos break;
1838 1.1 christos else
1839 1.1 christos {
1840 1.1 christos /* Use of some special register names come with a
1841 1.1 christos specific warning. Note that we have no ".cpu type"
1842 1.1 christos pseudo yet, so some of this is just unused
1843 1.1 christos framework. */
1844 1.1 christos if (out_insnp->spec_reg->warning)
1845 1.1 christos as_warn ("%s", out_insnp->spec_reg->warning);
1846 1.1 christos else if (out_insnp->spec_reg->applicable_version
1847 1.1 christos == cris_ver_warning)
1848 1.1 christos /* Others have a generic warning. */
1849 1.1 christos as_warn (_("Unimplemented register `%s' specified"),
1850 1.1 christos out_insnp->spec_reg->name);
1851 1.1 christos
1852 1.1 christos out_insnp->opcode
1853 1.1 christos |= out_insnp->spec_reg->number << 12;
1854 1.1 christos continue;
1855 1.1 christos }
1856 1.1 christos
1857 1.1 christos case 'p':
1858 1.1 christos /* This character is used in the disassembler to
1859 1.1 christos recognize a prefix instruction to fold into the
1860 1.1 christos addressing mode for the next instruction. It is
1861 1.1 christos ignored here. */
1862 1.1 christos continue;
1863 1.1 christos
1864 1.1 christos case 'R':
1865 1.1 christos /* General register in bits <15:12>. */
1866 1.1 christos if (! get_gen_reg (&s, ®no))
1867 1.1 christos break;
1868 1.1 christos else
1869 1.1 christos {
1870 1.1 christos out_insnp->opcode |= regno << 12;
1871 1.1 christos continue;
1872 1.1 christos }
1873 1.1 christos
1874 1.1 christos case 'r':
1875 1.1 christos /* General register in bits <3:0>. */
1876 1.1 christos if (! get_gen_reg (&s, ®no))
1877 1.1 christos break;
1878 1.1 christos else
1879 1.1 christos {
1880 1.1 christos out_insnp->opcode |= regno /* << 0 */;
1881 1.1 christos continue;
1882 1.1 christos }
1883 1.1 christos
1884 1.1 christos case 'S':
1885 1.1 christos /* Source operand in bit <10> and a prefix; a 3-operand
1886 1.1 christos prefix. */
1887 1.1 christos if (! get_3op_or_dip_prefix_op (&s, prefixp))
1888 1.1 christos break;
1889 1.1 christos else
1890 1.1 christos continue;
1891 1.1 christos
1892 1.1 christos case 's':
1893 1.1 christos /* Source operand in bits <10>, <3:0> and optionally a
1894 1.1 christos prefix; i.e. an indirect operand or an side-effect
1895 1.1 christos prefix (where valid). */
1896 1.1 christos if (! get_autoinc_prefix_or_indir_op (&s, prefixp, &mode,
1897 1.1 christos ®no,
1898 1.1 christos &imm_expr_found,
1899 1.1 christos &out_insnp->expr))
1900 1.1 christos break;
1901 1.1 christos else
1902 1.1 christos {
1903 1.1 christos if (prefixp->kind != PREFIX_NONE)
1904 1.1 christos {
1905 1.1 christos /* A prefix, so it has the autoincrement bit
1906 1.1 christos set. */
1907 1.1 christos out_insnp->opcode |= (AUTOINCR_BIT << 8);
1908 1.1 christos }
1909 1.1 christos else
1910 1.1 christos {
1911 1.1 christos /* No prefix. The "mode" variable contains bits like
1912 1.1 christos whether or not this is autoincrement mode. */
1913 1.1 christos out_insnp->opcode |= (mode << 10);
1914 1.1 christos
1915 1.1 christos /* If there was a reloc specifier, then it was
1916 1.1 christos attached to the prefix. Note that we can't check
1917 1.1 christos that the reloc size matches, since we don't have
1918 1.1 christos all the operands yet in all cases. */
1919 1.1 christos if (prefixp->reloc != BFD_RELOC_NONE)
1920 1.1 christos out_insnp->reloc = prefixp->reloc;
1921 1.1 christos }
1922 1.1 christos
1923 1.1 christos out_insnp->opcode |= regno /* << 0 */ ;
1924 1.1 christos continue;
1925 1.1 christos }
1926 1.1 christos
1927 1.1 christos case 'N':
1928 1.1 christos case 'Y':
1929 1.1 christos /* Like 's', but immediate operand only. Also do not
1930 1.1 christos modify insn. There are no insns where an explicit reloc
1931 1.1 christos specifier makes sense. */
1932 1.1 christos if (cris_get_expression (&s, &out_insnp->expr))
1933 1.1 christos {
1934 1.1 christos imm_expr_found = 1;
1935 1.1 christos continue;
1936 1.1 christos }
1937 1.1 christos break;
1938 1.1 christos
1939 1.1 christos case 'n':
1940 1.1 christos /* Like 'N', but PC-relative to the start of the insn.
1941 1.1 christos There might be a :PLT to request a PLT entry. */
1942 1.1 christos if (cris_get_expression (&s, &out_insnp->expr))
1943 1.1 christos {
1944 1.1 christos imm_expr_found = 1;
1945 1.1 christos out_insnp->reloc = BFD_RELOC_32_PCREL;
1946 1.1 christos
1947 1.1 christos /* We have to adjust the expression, because that
1948 1.1 christos relocation is to the location *after* the
1949 1.1 christos relocation. So add 2 for the insn and 4 for the
1950 1.1 christos relocation. */
1951 1.1 christos out_insnp->expr.X_add_number += 6;
1952 1.1 christos
1953 1.1 christos /* TLS specifiers do not make sense here. */
1954 1.1 christos if (pic && *s == RELOC_SUFFIX_CHAR)
1955 1.1 christos cris_get_reloc_suffix (&s, &out_insnp->reloc,
1956 1.1 christos &out_insnp->expr);
1957 1.1 christos
1958 1.1 christos continue;
1959 1.1 christos }
1960 1.1 christos break;
1961 1.1 christos
1962 1.1 christos case 'U':
1963 1.1 christos /* Maybe 'u', maybe 'n'. Only for LAPC/LAPCQ. */
1964 1.1 christos if (cris_get_expression (&s, &out_insnp->expr))
1965 1.1 christos {
1966 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_LAPCQ_OFFSET;
1967 1.1 christos
1968 1.1 christos /* Define 1 as relaxing. */
1969 1.1 christos out_insnp->expr.X_md = 1;
1970 1.1 christos continue;
1971 1.1 christos }
1972 1.1 christos break;
1973 1.1 christos
1974 1.1 christos case 'u':
1975 1.1 christos /* Four PC-relative bits in <3:0> representing <4:1>:0 of
1976 1.1 christos an offset relative to the beginning of the current
1977 1.1 christos insn. */
1978 1.1 christos if (cris_get_expression (&s, &out_insnp->expr))
1979 1.1 christos {
1980 1.1 christos out_insnp->reloc = BFD_RELOC_CRIS_LAPCQ_OFFSET;
1981 1.1 christos
1982 1.1 christos /* Define 0 as non-relaxing. */
1983 1.1 christos out_insnp->expr.X_md = 0;
1984 1.1 christos
1985 1.1 christos /* We have to adjust the expression, because that
1986 1.1 christos relocation is to the location *after* the
1987 1.1 christos insn. So add 2 for the insn. */
1988 1.1 christos out_insnp->expr.X_add_number += 2;
1989 1.1 christos continue;
1990 1.1 christos }
1991 1.1 christos break;
1992 1.1 christos
1993 1.1 christos case 'x':
1994 1.1 christos /* Rs.m in bits <15:12> and <5:4>. */
1995 1.1 christos if (! get_gen_reg (&s, ®no)
1996 1.1 christos || ! get_bwd_size_modifier (&s, &size_bits))
1997 1.1 christos break;
1998 1.1 christos else
1999 1.1 christos {
2000 1.1 christos out_insnp->opcode |= (regno << 12) | (size_bits << 4);
2001 1.1 christos continue;
2002 1.1 christos }
2003 1.1 christos
2004 1.1 christos case 'y':
2005 1.1 christos /* Source operand in bits <10>, <3:0> and optionally a
2006 1.1 christos prefix; i.e. an indirect operand or an side-effect
2007 1.1 christos prefix.
2008 1.1 christos
2009 1.1 christos The difference to 's' is that this does not allow an
2010 1.1 christos "immediate" expression. */
2011 1.1 christos if (! get_autoinc_prefix_or_indir_op (&s, prefixp,
2012 1.1 christos &mode, ®no,
2013 1.1 christos &imm_expr_found,
2014 1.1 christos &out_insnp->expr)
2015 1.1 christos || imm_expr_found)
2016 1.1 christos break;
2017 1.1 christos else
2018 1.1 christos {
2019 1.1 christos if (prefixp->kind != PREFIX_NONE)
2020 1.1 christos {
2021 1.1 christos /* A prefix, and those matched here always have
2022 1.1 christos side-effects (see 's' case). */
2023 1.1 christos out_insnp->opcode |= (AUTOINCR_BIT << 8);
2024 1.1 christos }
2025 1.1 christos else
2026 1.1 christos {
2027 1.1 christos /* No prefix. The "mode" variable contains bits
2028 1.1 christos like whether or not this is autoincrement
2029 1.1 christos mode. */
2030 1.1 christos out_insnp->opcode |= (mode << 10);
2031 1.1 christos }
2032 1.1 christos
2033 1.1 christos out_insnp->opcode |= regno /* << 0 */;
2034 1.1 christos continue;
2035 1.1 christos }
2036 1.1 christos
2037 1.1 christos case 'z':
2038 1.1 christos /* Size modifier (B or W) in bit <4>. */
2039 1.1 christos if (! get_bw_size_modifier (&s, &size_bits))
2040 1.1 christos break;
2041 1.1 christos else
2042 1.1 christos {
2043 1.1 christos out_insnp->opcode |= size_bits << 4;
2044 1.1 christos continue;
2045 1.1 christos }
2046 1.1 christos
2047 1.1 christos case 'T':
2048 1.1 christos if (cris_arch == arch_crisv32
2049 1.1 christos && get_sup_reg (&s, ®no))
2050 1.1 christos {
2051 1.1 christos out_insnp->opcode |= regno << 12;
2052 1.1 christos continue;
2053 1.1 christos }
2054 1.1 christos break;
2055 1.1 christos
2056 1.1 christos default:
2057 1.1 christos BAD_CASE (*args);
2058 1.1 christos }
2059 1.1 christos
2060 1.1 christos /* We get here when we fail a match above or we found a
2061 1.1 christos complete match. Break out of this loop. */
2062 1.1 christos break;
2063 1.1 christos }
2064 1.1 christos
2065 1.1 christos /* Was it a match or a miss? */
2066 1.1 christos if (match == 0)
2067 1.1 christos {
2068 1.1 christos /* If it's just that the args don't match, maybe the next
2069 1.1 christos item in the table is the same opcode but with
2070 1.1 christos matching operands. First skip any invalid ones. */
2071 1.1 christos while (instruction[1].name != NULL
2072 1.1 christos && strcmp (instruction->name, instruction[1].name) == 0
2073 1.1 christos && ! cris_insn_ver_valid_for_arch (instruction[1]
2074 1.1 christos .applicable_version,
2075 1.1 christos cris_arch))
2076 1.1 christos ++instruction;
2077 1.1 christos
2078 1.1 christos if (instruction[1].name != NULL
2079 1.1 christos && strcmp (instruction->name, instruction[1].name) == 0
2080 1.1 christos && cris_insn_ver_valid_for_arch (instruction[1]
2081 1.1 christos .applicable_version,
2082 1.1 christos cris_arch))
2083 1.1 christos {
2084 1.1 christos /* Yep. Restart and try that one instead. */
2085 1.1 christos ++instruction;
2086 1.1 christos s = operands;
2087 1.1 christos continue;
2088 1.1 christos }
2089 1.1 christos else
2090 1.1 christos {
2091 1.1 christos /* We've come to the end of instructions with this
2092 1.1 christos opcode, so it must be an error. */
2093 1.1 christos as_bad (_("Illegal operands"));
2094 1.1 christos
2095 1.1 christos /* As discard_rest_of_line, but without continuing to the
2096 1.1 christos next line. */
2097 1.1 christos while (!is_end_of_line[(unsigned char) *input_line_pointer])
2098 1.1 christos input_line_pointer++;
2099 1.1 christos return;
2100 1.1 christos }
2101 1.1 christos }
2102 1.1 christos else
2103 1.1 christos {
2104 1.1 christos /* We have a match. Check if there's anything more to do. */
2105 1.1 christos if (imm_expr_found)
2106 1.1 christos {
2107 1.1 christos /* There was an immediate mode operand, so we must check
2108 1.1 christos that it has an appropriate size. */
2109 1.1 christos switch (instruction->imm_oprnd_size)
2110 1.1 christos {
2111 1.1 christos default:
2112 1.1 christos case SIZE_NONE:
2113 1.1 christos /* Shouldn't happen; this one does not have immediate
2114 1.1 christos operands with different sizes. */
2115 1.1 christos BAD_CASE (instruction->imm_oprnd_size);
2116 1.1 christos break;
2117 1.1 christos
2118 1.1 christos case SIZE_FIX_32:
2119 1.1 christos out_insnp->imm_oprnd_size = 4;
2120 1.1 christos break;
2121 1.1 christos
2122 1.1 christos case SIZE_SPEC_REG:
2123 1.1 christos if (cris_arch == arch_crisv32)
2124 1.1 christos /* All immediate loads of special registers are
2125 1.1 christos 32-bit on CRISv32. */
2126 1.1 christos out_insnp->imm_oprnd_size = 4;
2127 1.1 christos else
2128 1.1 christos switch (out_insnp->spec_reg->reg_size)
2129 1.1 christos {
2130 1.1 christos case 1:
2131 1.1 christos if (out_insnp->expr.X_op == O_constant
2132 1.1 christos && (out_insnp->expr.X_add_number < -128
2133 1.1 christos || out_insnp->expr.X_add_number > 255))
2134 1.3 christos cris_bad (_("Immediate value not in 8 bit range: %ld"),
2135 1.3 christos &out_insnp->expr.X_add_number);
2136 1.1 christos /* Fall through. */
2137 1.1 christos case 2:
2138 1.1 christos /* FIXME: We need an indicator in the instruction
2139 1.1 christos table to pass on, to indicate if we need to check
2140 1.1 christos overflow for a signed or unsigned number. */
2141 1.1 christos if (out_insnp->expr.X_op == O_constant
2142 1.1 christos && (out_insnp->expr.X_add_number < -32768
2143 1.1 christos || out_insnp->expr.X_add_number > 65535))
2144 1.3 christos cris_bad (_("Immediate value not in 16 bit range: %ld"),
2145 1.3 christos &out_insnp->expr.X_add_number);
2146 1.1 christos out_insnp->imm_oprnd_size = 2;
2147 1.1 christos break;
2148 1.1 christos
2149 1.1 christos case 4:
2150 1.1 christos out_insnp->imm_oprnd_size = 4;
2151 1.1 christos break;
2152 1.1 christos
2153 1.1 christos default:
2154 1.1 christos BAD_CASE (out_insnp->spec_reg->reg_size);
2155 1.1 christos }
2156 1.1 christos break;
2157 1.1 christos
2158 1.1 christos case SIZE_FIELD:
2159 1.1 christos case SIZE_FIELD_SIGNED:
2160 1.1 christos case SIZE_FIELD_UNSIGNED:
2161 1.1 christos switch (size_bits)
2162 1.1 christos {
2163 1.1 christos /* FIXME: Find way to pass un/signedness to
2164 1.1 christos caller, and set reloc type instead, postponing
2165 1.1 christos this check until cris_number_to_imm. That
2166 1.1 christos necessarily corrects the reloc type for the
2167 1.1 christos byte case, maybe requiring further changes. */
2168 1.1 christos case 0:
2169 1.1 christos if (out_insnp->expr.X_op == O_constant)
2170 1.1 christos {
2171 1.1 christos if (instruction->imm_oprnd_size == SIZE_FIELD
2172 1.1 christos && (out_insnp->expr.X_add_number < -128
2173 1.1 christos || out_insnp->expr.X_add_number > 255))
2174 1.3 christos cris_bad (_("Immediate value not in 8 bit range: %ld"),
2175 1.3 christos &out_insnp->expr.X_add_number);
2176 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
2177 1.1 christos && (out_insnp->expr.X_add_number < -128
2178 1.1 christos || out_insnp->expr.X_add_number > 127))
2179 1.3 christos cris_bad (_("Immediate value not in 8 bit signed range: %ld"),
2180 1.3 christos &out_insnp->expr.X_add_number);
2181 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
2182 1.1 christos && (out_insnp->expr.X_add_number < 0
2183 1.1 christos || out_insnp->expr.X_add_number > 255))
2184 1.3 christos cris_bad (_("Immediate value not in 8 bit unsigned range: %ld"),
2185 1.3 christos &out_insnp->expr.X_add_number);
2186 1.1 christos }
2187 1.1 christos
2188 1.1 christos /* Fall through. */
2189 1.1 christos case 1:
2190 1.1 christos if (out_insnp->expr.X_op == O_constant)
2191 1.1 christos {
2192 1.1 christos if (instruction->imm_oprnd_size == SIZE_FIELD
2193 1.1 christos && (out_insnp->expr.X_add_number < -32768
2194 1.1 christos || out_insnp->expr.X_add_number > 65535))
2195 1.3 christos cris_bad (_("Immediate value not in 16 bit range: %ld"),
2196 1.3 christos &out_insnp->expr.X_add_number);
2197 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
2198 1.1 christos && (out_insnp->expr.X_add_number < -32768
2199 1.1 christos || out_insnp->expr.X_add_number > 32767))
2200 1.3 christos cris_bad (_("Immediate value not in 16 bit signed range: %ld"),
2201 1.3 christos &out_insnp->expr.X_add_number);
2202 1.1 christos else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
2203 1.1 christos && (out_insnp->expr.X_add_number < 0
2204 1.1 christos || out_insnp->expr.X_add_number > 65535))
2205 1.3 christos cris_bad (_("Immediate value not in 16 bit unsigned range: %ld"),
2206 1.3 christos &out_insnp->expr.X_add_number);
2207 1.1 christos }
2208 1.1 christos out_insnp->imm_oprnd_size = 2;
2209 1.1 christos break;
2210 1.1 christos
2211 1.1 christos case 2:
2212 1.1 christos out_insnp->imm_oprnd_size = 4;
2213 1.1 christos break;
2214 1.1 christos
2215 1.1 christos default:
2216 1.1 christos BAD_CASE (out_insnp->spec_reg->reg_size);
2217 1.1 christos }
2218 1.1 christos }
2219 1.1 christos
2220 1.1 christos /* If there was a relocation specified for the immediate
2221 1.1 christos expression (i.e. it had a PIC or TLS modifier) check that the
2222 1.1 christos size of the relocation matches the size specified by
2223 1.1 christos the opcode. */
2224 1.1 christos if (out_insnp->reloc != BFD_RELOC_NONE
2225 1.1 christos && (cris_get_specified_reloc_size (out_insnp->reloc)
2226 1.1 christos != (unsigned int) out_insnp->imm_oprnd_size))
2227 1.1 christos as_bad (out_insnp->reloc == BFD_RELOC_CRIS_32_GD
2228 1.1 christos || out_insnp->reloc == BFD_RELOC_CRIS_32_TPREL
2229 1.1 christos || out_insnp->reloc == BFD_RELOC_CRIS_16_TPREL
2230 1.1 christos || out_insnp->reloc == BFD_RELOC_CRIS_32_IE
2231 1.1 christos ? _("TLS relocation size does not match operand size")
2232 1.1 christos : _("PIC relocation size does not match operand size"));
2233 1.1 christos }
2234 1.1 christos else if (instruction->op == cris_muls_op
2235 1.1 christos || instruction->op == cris_mulu_op)
2236 1.1 christos out_insnp->insn_type = CRIS_INSN_MUL;
2237 1.1 christos }
2238 1.1 christos break;
2239 1.1 christos }
2240 1.1 christos }
2241 1.1 christos
2242 1.1 christos /* Get a B, W, or D size modifier from the string pointed out by *cPP,
2243 1.1 christos which must point to a '.' in front of the modifier. On successful
2244 1.1 christos return, *cPP is advanced to the character following the size
2245 1.1 christos modifier, and is undefined otherwise.
2246 1.1 christos
2247 1.1 christos cPP Pointer to pointer to string starting
2248 1.1 christos with the size modifier.
2249 1.1 christos
2250 1.1 christos size_bitsp Pointer to variable to contain the size bits on
2251 1.1 christos successful return.
2252 1.1 christos
2253 1.1 christos Return 1 iff a correct size modifier is found, else 0. */
2254 1.1 christos
2255 1.1 christos static int
2256 1.1 christos get_bwd_size_modifier (char **cPP, int *size_bitsp)
2257 1.1 christos {
2258 1.1 christos if (**cPP != '.')
2259 1.1 christos return 0;
2260 1.1 christos else
2261 1.1 christos {
2262 1.1 christos /* Consume the '.'. */
2263 1.1 christos (*cPP)++;
2264 1.1 christos
2265 1.1 christos switch (**cPP)
2266 1.1 christos {
2267 1.1 christos case 'B':
2268 1.1 christos case 'b':
2269 1.1 christos *size_bitsp = 0;
2270 1.1 christos break;
2271 1.1 christos
2272 1.1 christos case 'W':
2273 1.1 christos case 'w':
2274 1.1 christos *size_bitsp = 1;
2275 1.1 christos break;
2276 1.1 christos
2277 1.1 christos case 'D':
2278 1.1 christos case 'd':
2279 1.1 christos *size_bitsp = 2;
2280 1.1 christos break;
2281 1.1 christos
2282 1.1 christos default:
2283 1.1 christos return 0;
2284 1.1 christos }
2285 1.1 christos
2286 1.1 christos /* Consume the size letter. */
2287 1.1 christos (*cPP)++;
2288 1.1 christos return 1;
2289 1.1 christos }
2290 1.1 christos }
2291 1.1 christos
2292 1.1 christos /* Get a B or W size modifier from the string pointed out by *cPP,
2293 1.1 christos which must point to a '.' in front of the modifier. On successful
2294 1.1 christos return, *cPP is advanced to the character following the size
2295 1.1 christos modifier, and is undefined otherwise.
2296 1.1 christos
2297 1.1 christos cPP Pointer to pointer to string starting
2298 1.1 christos with the size modifier.
2299 1.1 christos
2300 1.1 christos size_bitsp Pointer to variable to contain the size bits on
2301 1.1 christos successful return.
2302 1.1 christos
2303 1.1 christos Return 1 iff a correct size modifier is found, else 0. */
2304 1.1 christos
2305 1.1 christos static int
2306 1.1 christos get_bw_size_modifier (char **cPP, int *size_bitsp)
2307 1.1 christos {
2308 1.1 christos if (**cPP != '.')
2309 1.1 christos return 0;
2310 1.1 christos else
2311 1.1 christos {
2312 1.1 christos /* Consume the '.'. */
2313 1.1 christos (*cPP)++;
2314 1.1 christos
2315 1.1 christos switch (**cPP)
2316 1.1 christos {
2317 1.1 christos case 'B':
2318 1.1 christos case 'b':
2319 1.1 christos *size_bitsp = 0;
2320 1.1 christos break;
2321 1.1 christos
2322 1.1 christos case 'W':
2323 1.1 christos case 'w':
2324 1.1 christos *size_bitsp = 1;
2325 1.1 christos break;
2326 1.1 christos
2327 1.1 christos default:
2328 1.1 christos return 0;
2329 1.1 christos }
2330 1.1 christos
2331 1.1 christos /* Consume the size letter. */
2332 1.1 christos (*cPP)++;
2333 1.1 christos return 1;
2334 1.1 christos }
2335 1.1 christos }
2336 1.1 christos
2337 1.1 christos /* Get a general register from the string pointed out by *cPP. The
2338 1.1 christos variable *cPP is advanced to the character following the general
2339 1.1 christos register name on a successful return, and has its initial position
2340 1.1 christos otherwise.
2341 1.1 christos
2342 1.1 christos cPP Pointer to pointer to string, beginning with a general
2343 1.1 christos register name.
2344 1.1 christos
2345 1.1 christos regnop Pointer to int containing the register number.
2346 1.1 christos
2347 1.1 christos Return 1 iff a correct general register designator is found,
2348 1.1 christos else 0. */
2349 1.1 christos
2350 1.1 christos static int
2351 1.1 christos get_gen_reg (char **cPP, int *regnop)
2352 1.1 christos {
2353 1.1 christos char *oldp;
2354 1.1 christos oldp = *cPP;
2355 1.1 christos
2356 1.1 christos /* Handle a sometimes-mandatory dollar sign as register prefix. */
2357 1.1 christos if (**cPP == REGISTER_PREFIX_CHAR)
2358 1.1 christos (*cPP)++;
2359 1.1 christos else if (demand_register_prefix)
2360 1.1 christos return 0;
2361 1.1 christos
2362 1.1 christos switch (**cPP)
2363 1.1 christos {
2364 1.1 christos case 'P':
2365 1.1 christos case 'p':
2366 1.1 christos /* "P" as in "PC"? Consume the "P". */
2367 1.1 christos (*cPP)++;
2368 1.1 christos
2369 1.1 christos if ((**cPP == 'C' || **cPP == 'c')
2370 1.1 christos && ! ISALNUM ((*cPP)[1])
2371 1.1 christos /* Here's a little twist: For v32 and the compatibility mode,
2372 1.1 christos we only recognize PC as a register number if there's '+]'
2373 1.1 christos after. We don't consume that, but the presence can only be
2374 1.1 christos valid after a register in a post-increment context, which
2375 1.1 christos is also the only valid context for PC as a register for
2376 1.1 christos v32. Not that it's used very often, but saying "MOVE.D
2377 1.1 christos [PC+],R5" should remain valid. It's not supported for
2378 1.1 christos jump-type insns or other insns with no [Rn+] mode, though. */
2379 1.1 christos && ((cris_arch != arch_crisv32
2380 1.1 christos && cris_arch != arch_cris_common_v10_v32)
2381 1.1 christos || ((*cPP)[1] == '+' && (*cPP)[2] == ']')))
2382 1.1 christos {
2383 1.1 christos /* It's "PC": consume the "c" and we're done. */
2384 1.1 christos (*cPP)++;
2385 1.1 christos *regnop = REG_PC;
2386 1.1 christos return 1;
2387 1.1 christos }
2388 1.1 christos break;
2389 1.1 christos
2390 1.1 christos /* Like with PC, we recognize ACR, but only if it's *not* followed
2391 1.1 christos by '+', and only for v32. */
2392 1.1 christos case 'A':
2393 1.1 christos case 'a':
2394 1.1 christos if (cris_arch != arch_crisv32
2395 1.1 christos || ((*cPP)[1] != 'c' && (*cPP)[1] != 'C')
2396 1.1 christos || ((*cPP)[2] != 'r' && (*cPP)[2] != 'R')
2397 1.1 christos || ISALNUM ((*cPP)[3])
2398 1.1 christos || (*cPP)[3] == '+')
2399 1.1 christos break;
2400 1.1 christos (*cPP) += 3;
2401 1.1 christos *regnop = 15;
2402 1.1 christos return 1;
2403 1.1 christos
2404 1.1 christos case 'R':
2405 1.1 christos case 'r':
2406 1.1 christos /* Hopefully r[0-9] or r1[0-5]. Consume 'R' or 'r'. */
2407 1.1 christos (*cPP)++;
2408 1.1 christos
2409 1.1 christos if (ISDIGIT (**cPP))
2410 1.1 christos {
2411 1.1 christos /* It's r[0-9]. Consume and check the next digit. */
2412 1.1 christos *regnop = **cPP - '0';
2413 1.1 christos (*cPP)++;
2414 1.1 christos
2415 1.1 christos if (! ISALNUM (**cPP))
2416 1.1 christos {
2417 1.1 christos /* No more digits, we're done. */
2418 1.1 christos return 1;
2419 1.1 christos }
2420 1.1 christos else
2421 1.1 christos {
2422 1.1 christos /* One more digit. Consume and add. */
2423 1.1 christos *regnop = *regnop * 10 + (**cPP - '0');
2424 1.1 christos
2425 1.1 christos /* We need to check for a valid register number; Rn,
2426 1.1 christos 0 <= n <= MAX_REG. */
2427 1.1 christos if (*regnop <= MAX_REG)
2428 1.1 christos {
2429 1.1 christos /* Consume second digit. */
2430 1.1 christos (*cPP)++;
2431 1.1 christos return 1;
2432 1.1 christos }
2433 1.1 christos }
2434 1.1 christos }
2435 1.1 christos break;
2436 1.1 christos
2437 1.1 christos case 'S':
2438 1.1 christos case 's':
2439 1.1 christos /* "S" as in "SP"? Consume the "S". */
2440 1.1 christos (*cPP)++;
2441 1.1 christos if (**cPP == 'P' || **cPP == 'p')
2442 1.1 christos {
2443 1.1 christos /* It's "SP": consume the "p" and we're done. */
2444 1.1 christos (*cPP)++;
2445 1.1 christos *regnop = REG_SP;
2446 1.1 christos return 1;
2447 1.1 christos }
2448 1.1 christos break;
2449 1.1 christos
2450 1.1 christos default:
2451 1.1 christos /* Just here to silence compilation warnings. */
2452 1.1 christos ;
2453 1.1 christos }
2454 1.1 christos
2455 1.1 christos /* We get here if we fail. Restore the pointer. */
2456 1.1 christos *cPP = oldp;
2457 1.1 christos return 0;
2458 1.1 christos }
2459 1.1 christos
2460 1.1 christos /* Get a special register from the string pointed out by *cPP. The
2461 1.1 christos variable *cPP is advanced to the character following the special
2462 1.1 christos register name if one is found, and retains its original position
2463 1.1 christos otherwise.
2464 1.1 christos
2465 1.1 christos cPP Pointer to pointer to string starting with a special register
2466 1.1 christos name.
2467 1.1 christos
2468 1.1 christos sregpp Pointer to Pointer to struct spec_reg, where a pointer to the
2469 1.1 christos register description will be stored.
2470 1.1 christos
2471 1.1 christos Return 1 iff a correct special register name is found. */
2472 1.1 christos
2473 1.1 christos static int
2474 1.1 christos get_spec_reg (char **cPP, const struct cris_spec_reg **sregpp)
2475 1.1 christos {
2476 1.1 christos char *s1;
2477 1.1 christos const char *s2;
2478 1.1 christos char *name_begin = *cPP;
2479 1.1 christos
2480 1.1 christos const struct cris_spec_reg *sregp;
2481 1.1 christos
2482 1.1 christos /* Handle a sometimes-mandatory dollar sign as register prefix. */
2483 1.1 christos if (*name_begin == REGISTER_PREFIX_CHAR)
2484 1.1 christos name_begin++;
2485 1.1 christos else if (demand_register_prefix)
2486 1.1 christos return 0;
2487 1.1 christos
2488 1.1 christos /* Loop over all special registers. */
2489 1.1 christos for (sregp = cris_spec_regs; sregp->name != NULL; sregp++)
2490 1.1 christos {
2491 1.1 christos /* Start over from beginning of the supposed name. */
2492 1.1 christos s1 = name_begin;
2493 1.1 christos s2 = sregp->name;
2494 1.1 christos
2495 1.1 christos while (*s2 != '\0' && TOLOWER (*s1) == *s2)
2496 1.1 christos {
2497 1.1 christos s1++;
2498 1.1 christos s2++;
2499 1.1 christos }
2500 1.1 christos
2501 1.1 christos /* For a match, we must have consumed the name in the table, and we
2502 1.1 christos must be outside what could be part of a name. Assume here that a
2503 1.1 christos test for alphanumerics is sufficient for a name test. */
2504 1.1 christos if (*s2 == 0 && ! ISALNUM (*s1)
2505 1.1 christos && cris_insn_ver_valid_for_arch (sregp->applicable_version,
2506 1.1 christos cris_arch))
2507 1.1 christos {
2508 1.1 christos /* We have a match. Update the pointer and be done. */
2509 1.1 christos *cPP = s1;
2510 1.1 christos *sregpp = sregp;
2511 1.1 christos return 1;
2512 1.1 christos }
2513 1.1 christos }
2514 1.1 christos
2515 1.1 christos /* If we got here, we did not find any name. */
2516 1.1 christos return 0;
2517 1.1 christos }
2518 1.1 christos
2519 1.1 christos /* Get a support register from the string pointed out by *cPP. The
2520 1.1 christos variable *cPP is advanced to the character following the support-
2521 1.1 christos register name if one is found, and retains its original position
2522 1.1 christos otherwise.
2523 1.1 christos
2524 1.1 christos cPP Pointer to pointer to string starting with a support-register
2525 1.1 christos name.
2526 1.1 christos
2527 1.1 christos sregpp Pointer to int containing the register number.
2528 1.1 christos
2529 1.1 christos Return 1 iff a correct support-register name is found. */
2530 1.1 christos
2531 1.1 christos static int
2532 1.1 christos get_sup_reg (char **cPP, int *regnop)
2533 1.1 christos {
2534 1.1 christos char *s1;
2535 1.1 christos const char *s2;
2536 1.1 christos char *name_begin = *cPP;
2537 1.1 christos
2538 1.1 christos const struct cris_support_reg *sregp;
2539 1.1 christos
2540 1.1 christos /* Handle a sometimes-mandatory dollar sign as register prefix. */
2541 1.1 christos if (*name_begin == REGISTER_PREFIX_CHAR)
2542 1.1 christos name_begin++;
2543 1.1 christos else if (demand_register_prefix)
2544 1.1 christos return 0;
2545 1.1 christos
2546 1.1 christos /* Loop over all support-registers. */
2547 1.1 christos for (sregp = cris_support_regs; sregp->name != NULL; sregp++)
2548 1.1 christos {
2549 1.1 christos /* Start over from beginning of the supposed name. */
2550 1.1 christos s1 = name_begin;
2551 1.1 christos s2 = sregp->name;
2552 1.1 christos
2553 1.1 christos while (*s2 != '\0' && TOLOWER (*s1) == *s2)
2554 1.1 christos {
2555 1.1 christos s1++;
2556 1.1 christos s2++;
2557 1.1 christos }
2558 1.1 christos
2559 1.1 christos /* For a match, we must have consumed the name in the table, and we
2560 1.1 christos must be outside what could be part of a name. Assume here that a
2561 1.1 christos test for alphanumerics is sufficient for a name test. */
2562 1.1 christos if (*s2 == 0 && ! ISALNUM (*s1))
2563 1.1 christos {
2564 1.1 christos /* We have a match. Update the pointer and be done. */
2565 1.1 christos *cPP = s1;
2566 1.1 christos *regnop = sregp->number;
2567 1.1 christos return 1;
2568 1.1 christos }
2569 1.1 christos }
2570 1.1 christos
2571 1.1 christos /* If we got here, we did not find any name. */
2572 1.1 christos return 0;
2573 1.1 christos }
2574 1.1 christos
2575 1.1 christos /* Get an unprefixed or side-effect-prefix operand from the string pointed
2576 1.1 christos out by *cPP. The pointer *cPP is advanced to the character following
2577 1.1 christos the indirect operand if we have success, else it contains an undefined
2578 1.1 christos value.
2579 1.1 christos
2580 1.1 christos cPP Pointer to pointer to string beginning with the first
2581 1.1 christos character of the supposed operand.
2582 1.1 christos
2583 1.1 christos prefixp Pointer to structure containing an optional instruction
2584 1.1 christos prefix.
2585 1.1 christos
2586 1.1 christos is_autoincp Pointer to int indicating the indirect or autoincrement
2587 1.1 christos bits.
2588 1.1 christos
2589 1.1 christos src_regnop Pointer to int containing the source register number in
2590 1.1 christos the instruction.
2591 1.1 christos
2592 1.1 christos imm_foundp Pointer to an int indicating if an immediate expression
2593 1.1 christos is found.
2594 1.1 christos
2595 1.1 christos imm_exprP Pointer to a structure containing an immediate
2596 1.1 christos expression, if success and if *imm_foundp is nonzero.
2597 1.1 christos
2598 1.1 christos Return 1 iff a correct indirect operand is found. */
2599 1.1 christos
2600 1.1 christos static int
2601 1.1 christos get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp,
2602 1.1 christos int *is_autoincp, int *src_regnop,
2603 1.1 christos int *imm_foundp, expressionS *imm_exprP)
2604 1.1 christos {
2605 1.1 christos /* Assume there was no immediate mode expression. */
2606 1.1 christos *imm_foundp = 0;
2607 1.1 christos
2608 1.1 christos if (**cPP == '[')
2609 1.1 christos {
2610 1.1 christos /* So this operand is one of:
2611 1.1 christos Indirect: [rN]
2612 1.1 christos Autoincrement: [rN+]
2613 1.1 christos Indexed with assign: [rN=rM+rO.S]
2614 1.1 christos Offset with assign: [rN=rM+I], [rN=rM+[rO].s], [rN=rM+[rO+].s]
2615 1.1 christos
2616 1.1 christos Either way, consume the '['. */
2617 1.1 christos (*cPP)++;
2618 1.1 christos
2619 1.1 christos /* Get the rN register. */
2620 1.1 christos if (! get_gen_reg (cPP, src_regnop))
2621 1.1 christos /* If there was no register, then this cannot match. */
2622 1.1 christos return 0;
2623 1.1 christos else
2624 1.1 christos {
2625 1.1 christos /* We got the register, now check the next character. */
2626 1.1 christos switch (**cPP)
2627 1.1 christos {
2628 1.1 christos case ']':
2629 1.1 christos /* Indirect mode. We're done here. */
2630 1.1 christos prefixp->kind = PREFIX_NONE;
2631 1.1 christos *is_autoincp = 0;
2632 1.1 christos break;
2633 1.1 christos
2634 1.1 christos case '+':
2635 1.1 christos /* This must be an auto-increment mode, if there's a
2636 1.1 christos match. */
2637 1.1 christos prefixp->kind = PREFIX_NONE;
2638 1.1 christos *is_autoincp = 1;
2639 1.1 christos
2640 1.1 christos /* We consume this character and break out to check the
2641 1.1 christos closing ']'. */
2642 1.1 christos (*cPP)++;
2643 1.1 christos break;
2644 1.1 christos
2645 1.1 christos case '=':
2646 1.1 christos /* This must be indexed with assign, or offset with assign
2647 1.1 christos to match. Not supported for crisv32 or in
2648 1.1 christos compatibility mode. */
2649 1.1 christos if (cris_arch == arch_crisv32
2650 1.1 christos || cris_arch == arch_cris_common_v10_v32)
2651 1.1 christos return 0;
2652 1.1 christos
2653 1.1 christos (*cPP)++;
2654 1.1 christos
2655 1.1 christos /* Either way, the next thing must be a register. */
2656 1.1 christos if (! get_gen_reg (cPP, &prefixp->base_reg_number))
2657 1.1 christos /* No register, no match. */
2658 1.1 christos return 0;
2659 1.1 christos else
2660 1.1 christos {
2661 1.1 christos /* We've consumed "[rN=rM", so we must be looking at
2662 1.1 christos "+rO.s]" or "+I]", or "-I]", or "+[rO].s]" or
2663 1.1 christos "+[rO+].s]". */
2664 1.1 christos if (**cPP == '+')
2665 1.1 christos {
2666 1.1 christos int index_reg_number;
2667 1.1 christos (*cPP)++;
2668 1.1 christos
2669 1.1 christos if (**cPP == '[')
2670 1.1 christos {
2671 1.1 christos int size_bits;
2672 1.1 christos /* This must be [rx=ry+[rz].s] or
2673 1.1 christos [rx=ry+[rz+].s] or no match. We must be
2674 1.1 christos looking at rz after consuming the '['. */
2675 1.1 christos (*cPP)++;
2676 1.1 christos
2677 1.1 christos if (!get_gen_reg (cPP, &index_reg_number))
2678 1.1 christos return 0;
2679 1.1 christos
2680 1.1 christos prefixp->kind = PREFIX_BDAP;
2681 1.1 christos prefixp->opcode
2682 1.1 christos = (BDAP_INDIR_OPCODE
2683 1.1 christos + (prefixp->base_reg_number << 12)
2684 1.1 christos + index_reg_number);
2685 1.1 christos
2686 1.1 christos if (**cPP == '+')
2687 1.1 christos {
2688 1.1 christos /* We've seen "[rx=ry+[rz+" here, so now we
2689 1.1 christos know that there must be "].s]" left to
2690 1.1 christos check. */
2691 1.1 christos (*cPP)++;
2692 1.1 christos prefixp->opcode |= AUTOINCR_BIT << 8;
2693 1.1 christos }
2694 1.1 christos
2695 1.1 christos /* If it wasn't autoincrement, we don't need to
2696 1.1 christos add anything. */
2697 1.1 christos
2698 1.1 christos /* Check the next-to-last ']'. */
2699 1.1 christos if (**cPP != ']')
2700 1.1 christos return 0;
2701 1.1 christos
2702 1.1 christos (*cPP)++;
2703 1.1 christos
2704 1.1 christos /* Check the ".s" modifier. */
2705 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits))
2706 1.1 christos return 0;
2707 1.1 christos
2708 1.1 christos prefixp->opcode |= size_bits << 4;
2709 1.1 christos
2710 1.1 christos /* Now we got [rx=ry+[rz+].s or [rx=ry+[rz].s.
2711 1.1 christos We break out to check the final ']'. */
2712 1.1 christos break;
2713 1.1 christos }
2714 1.1 christos /* It wasn't an indirection. Check if it's a
2715 1.1 christos register. */
2716 1.1 christos else if (get_gen_reg (cPP, &index_reg_number))
2717 1.1 christos {
2718 1.1 christos int size_bits;
2719 1.1 christos
2720 1.1 christos /* Indexed with assign mode: "[rN+rM.S]". */
2721 1.1 christos prefixp->kind = PREFIX_BIAP;
2722 1.1 christos prefixp->opcode
2723 1.1 christos = (BIAP_OPCODE + (index_reg_number << 12)
2724 1.1 christos + prefixp->base_reg_number /* << 0 */);
2725 1.1 christos
2726 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits))
2727 1.1 christos /* Size missing, this isn't a match. */
2728 1.1 christos return 0;
2729 1.1 christos else
2730 1.1 christos {
2731 1.1 christos /* Size found, break out to check the
2732 1.1 christos final ']'. */
2733 1.1 christos prefixp->opcode |= size_bits << 4;
2734 1.1 christos break;
2735 1.1 christos }
2736 1.1 christos }
2737 1.1 christos /* Not a register. Then this must be "[rN+I]". */
2738 1.1 christos else if (cris_get_expression (cPP, &prefixp->expr))
2739 1.1 christos {
2740 1.1 christos /* We've got offset with assign mode. Fill
2741 1.1 christos in the blanks and break out to match the
2742 1.1 christos final ']'. */
2743 1.1 christos prefixp->kind = PREFIX_BDAP_IMM;
2744 1.1 christos
2745 1.1 christos /* We tentatively put an opcode corresponding to
2746 1.1 christos a 32-bit operand here, although it may be
2747 1.1 christos relaxed when there's no relocation
2748 1.1 christos specifier for the operand. */
2749 1.1 christos prefixp->opcode
2750 1.1 christos = (BDAP_INDIR_OPCODE
2751 1.1 christos | (prefixp->base_reg_number << 12)
2752 1.1 christos | (AUTOINCR_BIT << 8)
2753 1.1 christos | (2 << 4)
2754 1.1 christos | REG_PC /* << 0 */);
2755 1.1 christos
2756 1.1 christos /* This can have a PIC suffix, specifying reloc
2757 1.1 christos type to use. */
2758 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
2759 1.1 christos {
2760 1.1 christos unsigned int relocsize;
2761 1.1 christos
2762 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc,
2763 1.1 christos &prefixp->expr);
2764 1.1 christos
2765 1.1 christos /* Tweak the size of the immediate operand
2766 1.1 christos in the prefix opcode if it isn't what we
2767 1.1 christos set. */
2768 1.1 christos relocsize
2769 1.1 christos = cris_get_specified_reloc_size (prefixp->reloc);
2770 1.1 christos if (relocsize != 4)
2771 1.1 christos prefixp->opcode
2772 1.1 christos = ((prefixp->opcode & ~(3 << 4))
2773 1.1 christos | ((relocsize >> 1) << 4));
2774 1.1 christos }
2775 1.1 christos break;
2776 1.1 christos }
2777 1.1 christos else
2778 1.1 christos /* Neither register nor expression found, so
2779 1.1 christos this can't be a match. */
2780 1.1 christos return 0;
2781 1.1 christos }
2782 1.1 christos /* Not "[rN+" but perhaps "[rN-"? */
2783 1.1 christos else if (**cPP == '-')
2784 1.1 christos {
2785 1.1 christos /* We must have an offset with assign mode. */
2786 1.1 christos if (! cris_get_expression (cPP, &prefixp->expr))
2787 1.1 christos /* No expression, no match. */
2788 1.1 christos return 0;
2789 1.1 christos else
2790 1.1 christos {
2791 1.1 christos /* We've got offset with assign mode. Fill
2792 1.1 christos in the blanks and break out to match the
2793 1.1 christos final ']'.
2794 1.1 christos
2795 1.1 christos Note that we don't allow a relocation
2796 1.1 christos suffix for an operand with a minus
2797 1.1 christos sign. */
2798 1.1 christos prefixp->kind = PREFIX_BDAP_IMM;
2799 1.1 christos break;
2800 1.1 christos }
2801 1.1 christos }
2802 1.1 christos else
2803 1.1 christos /* Neither '+' nor '-' after "[rN=rM". Lose. */
2804 1.1 christos return 0;
2805 1.1 christos }
2806 1.1 christos default:
2807 1.1 christos /* Neither ']' nor '+' nor '=' after "[rN". Lose. */
2808 1.1 christos return 0;
2809 1.1 christos }
2810 1.1 christos }
2811 1.1 christos
2812 1.1 christos /* When we get here, we have a match and will just check the closing
2813 1.1 christos ']'. We can still fail though. */
2814 1.1 christos if (**cPP != ']')
2815 1.1 christos return 0;
2816 1.1 christos else
2817 1.1 christos {
2818 1.1 christos /* Don't forget to consume the final ']'.
2819 1.1 christos Then return in glory. */
2820 1.1 christos (*cPP)++;
2821 1.1 christos return 1;
2822 1.1 christos }
2823 1.1 christos }
2824 1.1 christos /* No indirection. Perhaps a constant? */
2825 1.1 christos else if (cris_get_expression (cPP, imm_exprP))
2826 1.1 christos {
2827 1.1 christos /* Expression found, this is immediate mode. */
2828 1.1 christos prefixp->kind = PREFIX_NONE;
2829 1.1 christos *is_autoincp = 1;
2830 1.1 christos *src_regnop = REG_PC;
2831 1.1 christos *imm_foundp = 1;
2832 1.1 christos
2833 1.1 christos /* This can have a PIC suffix, specifying reloc type to use. The
2834 1.1 christos caller must check that the reloc size matches the operand size. */
2835 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
2836 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, imm_exprP);
2837 1.1 christos
2838 1.1 christos return 1;
2839 1.1 christos }
2840 1.1 christos
2841 1.1 christos /* No luck today. */
2842 1.1 christos return 0;
2843 1.1 christos }
2844 1.1 christos
2845 1.1 christos /* This function gets an indirect operand in a three-address operand
2846 1.1 christos combination from the string pointed out by *cPP. The pointer *cPP is
2847 1.1 christos advanced to the character following the indirect operand on success, or
2848 1.1 christos has an unspecified value on failure.
2849 1.1 christos
2850 1.1 christos cPP Pointer to pointer to string beginning
2851 1.1 christos with the operand
2852 1.1 christos
2853 1.1 christos prefixp Pointer to structure containing an
2854 1.1 christos instruction prefix
2855 1.1 christos
2856 1.1 christos Returns 1 iff a correct indirect operand is found. */
2857 1.1 christos
2858 1.1 christos static int
2859 1.1 christos get_3op_or_dip_prefix_op (char **cPP, struct cris_prefix *prefixp)
2860 1.1 christos {
2861 1.1 christos int reg_number;
2862 1.1 christos
2863 1.1 christos if (**cPP != '[')
2864 1.1 christos /* We must have a '[' or it's a clean failure. */
2865 1.1 christos return 0;
2866 1.1 christos
2867 1.1 christos /* Eat the first '['. */
2868 1.1 christos (*cPP)++;
2869 1.1 christos
2870 1.1 christos if (**cPP == '[')
2871 1.1 christos {
2872 1.1 christos /* A second '[', so this must be double-indirect mode. */
2873 1.1 christos (*cPP)++;
2874 1.1 christos prefixp->kind = PREFIX_DIP;
2875 1.1 christos prefixp->opcode = DIP_OPCODE;
2876 1.1 christos
2877 1.1 christos /* Get the register or fail entirely. */
2878 1.1 christos if (! get_gen_reg (cPP, ®_number))
2879 1.1 christos return 0;
2880 1.1 christos else
2881 1.1 christos {
2882 1.1 christos prefixp->opcode |= reg_number /* << 0 */ ;
2883 1.1 christos if (**cPP == '+')
2884 1.1 christos {
2885 1.1 christos /* Since we found a '+', this must be double-indirect
2886 1.1 christos autoincrement mode. */
2887 1.1 christos (*cPP)++;
2888 1.1 christos prefixp->opcode |= AUTOINCR_BIT << 8;
2889 1.1 christos }
2890 1.1 christos
2891 1.1 christos /* There's nothing particular to do, if this was a
2892 1.1 christos double-indirect *without* autoincrement. */
2893 1.1 christos }
2894 1.1 christos
2895 1.1 christos /* Check the first ']'. The second one is checked at the end. */
2896 1.1 christos if (**cPP != ']')
2897 1.1 christos return 0;
2898 1.1 christos
2899 1.1 christos /* Eat the first ']', so we'll be looking at a second ']'. */
2900 1.1 christos (*cPP)++;
2901 1.1 christos }
2902 1.1 christos /* No second '['. Then we should have a register here, making
2903 1.1 christos it "[rN". */
2904 1.1 christos else if (get_gen_reg (cPP, &prefixp->base_reg_number))
2905 1.1 christos {
2906 1.1 christos /* This must be indexed or offset mode: "[rN+I]" or
2907 1.1 christos "[rN+rM.S]" or "[rN+[rM].S]" or "[rN+[rM+].S]". */
2908 1.1 christos if (**cPP == '+')
2909 1.1 christos {
2910 1.1 christos int index_reg_number;
2911 1.1 christos
2912 1.1 christos (*cPP)++;
2913 1.1 christos
2914 1.1 christos if (**cPP == '[')
2915 1.1 christos {
2916 1.1 christos /* This is "[rx+["... Expect a register next. */
2917 1.1 christos int size_bits;
2918 1.1 christos (*cPP)++;
2919 1.1 christos
2920 1.1 christos if (!get_gen_reg (cPP, &index_reg_number))
2921 1.1 christos return 0;
2922 1.1 christos
2923 1.1 christos prefixp->kind = PREFIX_BDAP;
2924 1.1 christos prefixp->opcode
2925 1.1 christos = (BDAP_INDIR_OPCODE
2926 1.1 christos + (prefixp->base_reg_number << 12)
2927 1.1 christos + index_reg_number);
2928 1.1 christos
2929 1.1 christos /* We've seen "[rx+[ry", so check if this is
2930 1.1 christos autoincrement. */
2931 1.1 christos if (**cPP == '+')
2932 1.1 christos {
2933 1.1 christos /* Yep, now at "[rx+[ry+". */
2934 1.1 christos (*cPP)++;
2935 1.1 christos prefixp->opcode |= AUTOINCR_BIT << 8;
2936 1.1 christos }
2937 1.1 christos /* If it wasn't autoincrement, we don't need to
2938 1.1 christos add anything. */
2939 1.1 christos
2940 1.1 christos /* Check a first closing ']': "[rx+[ry]" or
2941 1.1 christos "[rx+[ry+]". */
2942 1.1 christos if (**cPP != ']')
2943 1.1 christos return 0;
2944 1.1 christos (*cPP)++;
2945 1.1 christos
2946 1.1 christos /* Now expect a size modifier ".S". */
2947 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits))
2948 1.1 christos return 0;
2949 1.1 christos
2950 1.1 christos prefixp->opcode |= size_bits << 4;
2951 1.1 christos
2952 1.1 christos /* Ok, all interesting stuff has been seen:
2953 1.1 christos "[rx+[ry+].S" or "[rx+[ry].S". We only need to
2954 1.1 christos expect a final ']', which we'll do in a common
2955 1.1 christos closing session. */
2956 1.1 christos }
2957 1.1 christos /* Seen "[rN+", but not a '[', so check if we have a
2958 1.1 christos register. */
2959 1.1 christos else if (get_gen_reg (cPP, &index_reg_number))
2960 1.1 christos {
2961 1.1 christos /* This is indexed mode: "[rN+rM.S]" or
2962 1.1 christos "[rN+rM.S+]". */
2963 1.1 christos int size_bits;
2964 1.1 christos prefixp->kind = PREFIX_BIAP;
2965 1.1 christos prefixp->opcode
2966 1.1 christos = (BIAP_OPCODE
2967 1.1 christos | prefixp->base_reg_number /* << 0 */
2968 1.1 christos | (index_reg_number << 12));
2969 1.1 christos
2970 1.1 christos /* Consume the ".S". */
2971 1.1 christos if (! get_bwd_size_modifier (cPP, &size_bits))
2972 1.1 christos /* Missing size, so fail. */
2973 1.1 christos return 0;
2974 1.1 christos else
2975 1.1 christos /* Size found. Add that piece and drop down to
2976 1.1 christos the common checking of the closing ']'. */
2977 1.1 christos prefixp->opcode |= size_bits << 4;
2978 1.1 christos }
2979 1.1 christos /* Seen "[rN+", but not a '[' or a register, so then
2980 1.1 christos it must be a constant "I".
2981 1.1 christos
2982 1.1 christos As a quality of implementation improvement, we check for a
2983 1.1 christos closing ']', like in an erroneous "[rN+]". If we don't,
2984 1.1 christos the expression parser will emit a confusing "bad
2985 1.1 christos expression" when it sees the ']', probably because it
2986 1.1 christos doesn't like seeing no expression. */
2987 1.1 christos else if (**cPP != ']' && cris_get_expression (cPP, &prefixp->expr))
2988 1.1 christos {
2989 1.1 christos /* Expression found, so fill in the bits of offset
2990 1.1 christos mode and drop down to check the closing ']'. */
2991 1.1 christos prefixp->kind = PREFIX_BDAP_IMM;
2992 1.1 christos
2993 1.1 christos /* We tentatively put an opcode corresponding to a 32-bit
2994 1.1 christos operand here, although it may be relaxed when there's no
2995 1.1 christos PIC specifier for the operand. */
2996 1.1 christos prefixp->opcode
2997 1.1 christos = (BDAP_INDIR_OPCODE
2998 1.1 christos | (prefixp->base_reg_number << 12)
2999 1.1 christos | (AUTOINCR_BIT << 8)
3000 1.1 christos | (2 << 4)
3001 1.1 christos | REG_PC /* << 0 */);
3002 1.1 christos
3003 1.1 christos /* This can have a PIC suffix, specifying reloc type to use. */
3004 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
3005 1.1 christos {
3006 1.1 christos unsigned int relocsize;
3007 1.1 christos
3008 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr);
3009 1.1 christos
3010 1.1 christos /* Tweak the size of the immediate operand in the prefix
3011 1.1 christos opcode if it isn't what we set. */
3012 1.1 christos relocsize = cris_get_specified_reloc_size (prefixp->reloc);
3013 1.1 christos if (relocsize != 4)
3014 1.1 christos prefixp->opcode
3015 1.1 christos = ((prefixp->opcode & ~(3 << 4))
3016 1.1 christos | ((relocsize >> 1) << 4));
3017 1.1 christos }
3018 1.1 christos }
3019 1.1 christos else
3020 1.1 christos /* Nothing valid here: lose. */
3021 1.1 christos return 0;
3022 1.1 christos }
3023 1.1 christos /* Seen "[rN" but no '+', so check if it's a '-'. */
3024 1.1 christos else if (**cPP == '-')
3025 1.1 christos {
3026 1.1 christos /* Yep, we must have offset mode. */
3027 1.1 christos if (! cris_get_expression (cPP, &prefixp->expr))
3028 1.1 christos /* No expression, so we lose. */
3029 1.1 christos return 0;
3030 1.1 christos else
3031 1.1 christos {
3032 1.1 christos /* Expression found to make this offset mode, so
3033 1.1 christos fill those bits and drop down to check the
3034 1.1 christos closing ']'.
3035 1.1 christos
3036 1.1 christos Note that we don't allow a PIC suffix for
3037 1.1 christos an operand with a minus sign like this. */
3038 1.1 christos prefixp->kind = PREFIX_BDAP_IMM;
3039 1.1 christos }
3040 1.1 christos }
3041 1.1 christos else
3042 1.1 christos {
3043 1.1 christos /* We've seen "[rN", but not '+' or '-'; rather a ']'.
3044 1.1 christos Hmm. Normally this is a simple indirect mode that we
3045 1.1 christos shouldn't match, but if we expect ']', then we have a
3046 1.1 christos zero offset, so it can be a three-address-operand,
3047 1.1 christos like "[rN],rO,rP", thus offset mode.
3048 1.1 christos
3049 1.1 christos Don't eat the ']', that will be done in the closing
3050 1.1 christos ceremony. */
3051 1.1 christos prefixp->expr.X_op = O_constant;
3052 1.1 christos prefixp->expr.X_add_number = 0;
3053 1.1 christos prefixp->expr.X_add_symbol = NULL;
3054 1.1 christos prefixp->expr.X_op_symbol = NULL;
3055 1.1 christos prefixp->kind = PREFIX_BDAP_IMM;
3056 1.1 christos }
3057 1.1 christos }
3058 1.1 christos /* A '[', but no second '[', and no register. Check if we
3059 1.1 christos have an expression, making this "[I]" for a double-indirect
3060 1.1 christos prefix. */
3061 1.1 christos else if (cris_get_expression (cPP, &prefixp->expr))
3062 1.1 christos {
3063 1.1 christos /* Expression found, the so called absolute mode for a
3064 1.1 christos double-indirect prefix on PC. */
3065 1.1 christos prefixp->kind = PREFIX_DIP;
3066 1.1 christos prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
3067 1.1 christos prefixp->reloc = BFD_RELOC_32;
3068 1.1 christos
3069 1.1 christos /* For :GD and :IE, it makes sense to have TLS specifiers here. */
3070 1.1 christos if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
3071 1.1 christos cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr);
3072 1.1 christos }
3073 1.1 christos else
3074 1.1 christos /* Neither '[' nor register nor expression. We lose. */
3075 1.1 christos return 0;
3076 1.1 christos
3077 1.1 christos /* We get here as a closing ceremony to a successful match. We just
3078 1.1 christos need to check the closing ']'. */
3079 1.1 christos if (**cPP != ']')
3080 1.1 christos /* Oops. Close but no air-polluter. */
3081 1.1 christos return 0;
3082 1.1 christos
3083 1.1 christos /* Don't forget to consume that ']', before returning in glory. */
3084 1.1 christos (*cPP)++;
3085 1.1 christos return 1;
3086 1.1 christos }
3087 1.1 christos
3088 1.1 christos /* Get an expression from the string pointed out by *cPP.
3089 1.1 christos The pointer *cPP is advanced to the character following the expression
3090 1.1 christos on a success, or retains its original value otherwise.
3091 1.1 christos
3092 1.1 christos cPP Pointer to pointer to string beginning with the expression.
3093 1.1 christos
3094 1.1 christos exprP Pointer to structure containing the expression.
3095 1.1 christos
3096 1.1 christos Return 1 iff a correct expression is found. */
3097 1.1 christos
3098 1.1 christos static int
3099 1.1 christos cris_get_expression (char **cPP, expressionS *exprP)
3100 1.1 christos {
3101 1.1 christos char *saved_input_line_pointer;
3102 1.1 christos
3103 1.1 christos /* The "expression" function expects to find an expression at the
3104 1.1 christos global variable input_line_pointer, so we have to save it to give
3105 1.1 christos the impression that we don't fiddle with global variables. */
3106 1.1 christos saved_input_line_pointer = input_line_pointer;
3107 1.1 christos input_line_pointer = *cPP;
3108 1.1 christos
3109 1.1 christos /* Avoid a common error, confusing addressing modes. Beware that the
3110 1.1 christos call to expression below does not signal that error; it treats []
3111 1.1 christos as parentheses, unless #define NEED_INDEX_OPERATOR in which case it
3112 1.1 christos gives them other confusing semantics rather than plain outlawing
3113 1.1 christos them, which is what we want. */
3114 1.1 christos if (*input_line_pointer == '[')
3115 1.1 christos {
3116 1.1 christos input_line_pointer = saved_input_line_pointer;
3117 1.1 christos return 0;
3118 1.1 christos }
3119 1.1 christos
3120 1.1 christos expression (exprP);
3121 1.1 christos if (exprP->X_op == O_illegal || exprP->X_op == O_absent)
3122 1.1 christos {
3123 1.1 christos input_line_pointer = saved_input_line_pointer;
3124 1.1 christos return 0;
3125 1.1 christos }
3126 1.1 christos
3127 1.1 christos /* Everything seems to be fine, just restore the global
3128 1.1 christos input_line_pointer and say we're successful. */
3129 1.1 christos *cPP = input_line_pointer;
3130 1.1 christos input_line_pointer = saved_input_line_pointer;
3131 1.1 christos return 1;
3132 1.1 christos }
3133 1.1 christos
3134 1.1 christos /* Get a sequence of flag characters from *spp. The pointer *cPP is
3135 1.1 christos advanced to the character following the expression. The flag
3136 1.1 christos characters are consecutive, no commas or spaces.
3137 1.1 christos
3138 1.1 christos cPP Pointer to pointer to string beginning with the expression.
3139 1.1 christos
3140 1.1 christos flagp Pointer to int to return the flags expression.
3141 1.1 christos
3142 1.1 christos Return 1 iff a correct flags expression is found. */
3143 1.1 christos
3144 1.1 christos static int
3145 1.1 christos get_flags (char **cPP, int *flagsp)
3146 1.1 christos {
3147 1.1 christos for (;;)
3148 1.1 christos {
3149 1.1 christos switch (**cPP)
3150 1.1 christos {
3151 1.1 christos case 'd':
3152 1.1 christos case 'D':
3153 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v0_3,
3154 1.1 christos cris_arch))
3155 1.1 christos return 0;
3156 1.1 christos *flagsp |= 0x80;
3157 1.1 christos break;
3158 1.1 christos
3159 1.1 christos case 'm':
3160 1.1 christos case 'M':
3161 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v8_10,
3162 1.1 christos cris_arch))
3163 1.1 christos return 0;
3164 1.1 christos *flagsp |= 0x80;
3165 1.1 christos break;
3166 1.1 christos
3167 1.1 christos case 'e':
3168 1.1 christos case 'E':
3169 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v0_3,
3170 1.1 christos cris_arch))
3171 1.1 christos return 0;
3172 1.1 christos *flagsp |= 0x40;
3173 1.1 christos break;
3174 1.1 christos
3175 1.1 christos case 'b':
3176 1.1 christos case 'B':
3177 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v8_10,
3178 1.1 christos cris_arch))
3179 1.1 christos return 0;
3180 1.1 christos *flagsp |= 0x40;
3181 1.1 christos break;
3182 1.1 christos
3183 1.1 christos case 'p':
3184 1.1 christos case 'P':
3185 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v32p,
3186 1.1 christos cris_arch))
3187 1.1 christos return 0;
3188 1.1 christos *flagsp |= 0x80;
3189 1.1 christos break;
3190 1.1 christos
3191 1.1 christos case 'u':
3192 1.1 christos case 'U':
3193 1.1 christos if (! cris_insn_ver_valid_for_arch (cris_ver_v32p,
3194 1.1 christos cris_arch))
3195 1.1 christos return 0;
3196 1.1 christos *flagsp |= 0x40;
3197 1.1 christos break;
3198 1.1 christos
3199 1.1 christos case 'i':
3200 1.1 christos case 'I':
3201 1.1 christos *flagsp |= 0x20;
3202 1.1 christos break;
3203 1.1 christos
3204 1.1 christos case 'x':
3205 1.1 christos case 'X':
3206 1.1 christos *flagsp |= 0x10;
3207 1.1 christos break;
3208 1.1 christos
3209 1.1 christos case 'n':
3210 1.1 christos case 'N':
3211 1.1 christos *flagsp |= 0x8;
3212 1.1 christos break;
3213 1.1 christos
3214 1.1 christos case 'z':
3215 1.1 christos case 'Z':
3216 1.1 christos *flagsp |= 0x4;
3217 1.1 christos break;
3218 1.1 christos
3219 1.1 christos case 'v':
3220 1.1 christos case 'V':
3221 1.1 christos *flagsp |= 0x2;
3222 1.1 christos break;
3223 1.1 christos
3224 1.1 christos case 'c':
3225 1.1 christos case 'C':
3226 1.1 christos *flagsp |= 1;
3227 1.1 christos break;
3228 1.1 christos
3229 1.1 christos default:
3230 1.1 christos /* We consider this successful if we stop at a comma or
3231 1.1 christos whitespace. Anything else, and we consider it a failure. */
3232 1.1 christos if (**cPP != ','
3233 1.1 christos && **cPP != 0
3234 1.1 christos && ! ISSPACE (**cPP))
3235 1.1 christos return 0;
3236 1.1 christos else
3237 1.1 christos return 1;
3238 1.1 christos }
3239 1.1 christos
3240 1.1 christos /* Don't forget to consume each flag character. */
3241 1.1 christos (*cPP)++;
3242 1.1 christos }
3243 1.1 christos }
3244 1.1 christos
3245 1.1 christos /* Generate code and fixes for a BDAP prefix.
3246 1.1 christos For v32, this handles ADDOQ because thankfully the opcodes are the
3247 1.1 christos same.
3248 1.1 christos
3249 1.1 christos base_regno Int containing the base register number.
3250 1.1 christos
3251 1.1 christos exprP Pointer to structure containing the offset expression. */
3252 1.1 christos
3253 1.1 christos static void
3254 1.1 christos gen_bdap (int base_regno, expressionS *exprP)
3255 1.1 christos {
3256 1.1 christos unsigned int opcode;
3257 1.1 christos char *opcodep;
3258 1.1 christos
3259 1.1 christos /* Put out the prefix opcode; assume quick immediate mode at first. */
3260 1.1 christos opcode = BDAP_QUICK_OPCODE | (base_regno << 12);
3261 1.1 christos opcodep = cris_insn_first_word_frag ();
3262 1.1 christos md_number_to_chars (opcodep, opcode, 2);
3263 1.1 christos
3264 1.1 christos if (exprP->X_op == O_constant)
3265 1.1 christos {
3266 1.1 christos /* We have an absolute expression that we know the size of right
3267 1.1 christos now. */
3268 1.1 christos long int value;
3269 1.1 christos int size;
3270 1.1 christos
3271 1.1 christos value = exprP->X_add_number;
3272 1.1 christos if (value < -32768 || value > 32767)
3273 1.1 christos /* Outside range for a "word", make it a dword. */
3274 1.1 christos size = 2;
3275 1.1 christos else
3276 1.1 christos /* Assume "word" size. */
3277 1.1 christos size = 1;
3278 1.1 christos
3279 1.1 christos /* If this is a signed-byte value, we can fit it into the prefix
3280 1.1 christos insn itself. */
3281 1.1 christos if (value >= -128 && value <= 127)
3282 1.1 christos opcodep[0] = value;
3283 1.1 christos else
3284 1.1 christos {
3285 1.1 christos /* This is a word or dword displacement, which will be put in a
3286 1.1 christos word or dword after the prefix. */
3287 1.1 christos char *p;
3288 1.1 christos
3289 1.1 christos opcodep[0] = BDAP_PC_LOW + (size << 4);
3290 1.1 christos opcodep[1] &= 0xF0;
3291 1.1 christos opcodep[1] |= BDAP_INCR_HIGH;
3292 1.1 christos p = frag_more (1 << size);
3293 1.1 christos md_number_to_chars (p, value, 1 << size);
3294 1.1 christos }
3295 1.1 christos }
3296 1.1 christos else
3297 1.1 christos {
3298 1.1 christos /* Handle complex expressions. */
3299 1.1 christos valueT addvalue
3300 1.1 christos = SIMPLE_EXPR (exprP) ? exprP->X_add_number : 0;
3301 1.1 christos symbolS *sym
3302 1.1 christos = (SIMPLE_EXPR (exprP)
3303 1.1 christos ? exprP->X_add_symbol : make_expr_symbol (exprP));
3304 1.1 christos
3305 1.1 christos /* The expression is not defined yet but may become absolute. We
3306 1.1 christos make it a relocation to be relaxed. */
3307 1.1 christos frag_var (rs_machine_dependent, 4, 0,
3308 1.1 christos ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF),
3309 1.1 christos sym, addvalue, opcodep);
3310 1.1 christos }
3311 1.1 christos }
3312 1.1 christos
3313 1.1 christos /* Encode a branch displacement in the range -256..254 into the form used
3314 1.1 christos by CRIS conditional branch instructions.
3315 1.1 christos
3316 1.1 christos offset The displacement value in bytes. */
3317 1.1 christos
3318 1.1 christos static int
3319 1.1 christos branch_disp (int offset)
3320 1.1 christos {
3321 1.1 christos int disp;
3322 1.1 christos
3323 1.1 christos /* Adjust all short branch offsets here. */
3324 1.1 christos if (cris_arch == arch_crisv32 || cris_arch == arch_cris_common_v10_v32)
3325 1.1 christos offset += 2;
3326 1.1 christos
3327 1.1 christos disp = offset & 0xFE;
3328 1.1 christos
3329 1.1 christos if (offset < 0)
3330 1.1 christos disp |= 1;
3331 1.1 christos
3332 1.1 christos return disp;
3333 1.1 christos }
3334 1.1 christos
3335 1.1 christos /* Generate code and fixes for a 32-bit conditional branch instruction
3336 1.1 christos created by "extending" an existing 8-bit branch instruction.
3337 1.1 christos
3338 1.1 christos opcodep Pointer to the word containing the original 8-bit branch
3339 1.1 christos instruction.
3340 1.1 christos
3341 1.1 christos writep Pointer to "extension area" following the first instruction
3342 1.1 christos word.
3343 1.1 christos
3344 1.1 christos fragP Pointer to the frag containing the instruction.
3345 1.1 christos
3346 1.1 christos add_symP, Parts of the destination address expression.
3347 1.1 christos sub_symP,
3348 1.1 christos add_num. */
3349 1.1 christos
3350 1.1 christos static void
3351 1.1 christos gen_cond_branch_32 (char *opcodep, char *writep, fragS *fragP,
3352 1.1 christos symbolS *add_symP, symbolS *sub_symP, long int add_num)
3353 1.1 christos {
3354 1.1 christos int nop_opcode;
3355 1.1 christos int opc_offset;
3356 1.1 christos int branch_offset;
3357 1.1 christos
3358 1.1 christos if (cris_arch == arch_crisv32)
3359 1.1 christos {
3360 1.1 christos nop_opcode = NOP_OPCODE_V32;
3361 1.1 christos opc_offset = 10;
3362 1.1 christos branch_offset = -2 - 8;
3363 1.1 christos }
3364 1.1 christos else if (pic)
3365 1.1 christos {
3366 1.1 christos nop_opcode = NOP_OPCODE;
3367 1.1 christos opc_offset = 10;
3368 1.1 christos branch_offset = -2 - 8;
3369 1.1 christos }
3370 1.1 christos else
3371 1.1 christos {
3372 1.1 christos nop_opcode = NOP_OPCODE;
3373 1.1 christos opc_offset = 8;
3374 1.1 christos branch_offset = -2 - 6;
3375 1.1 christos }
3376 1.1 christos
3377 1.1 christos /* We should never get here for compatibility mode. */
3378 1.1 christos if (cris_arch == arch_cris_common_v10_v32)
3379 1.1 christos as_fatal (_("Calling gen_cond_branch_32 for .arch common_v10_v32\n"));
3380 1.1 christos
3381 1.1 christos if (warn_for_branch_expansion)
3382 1.1 christos as_warn_where (fragP->fr_file, fragP->fr_line,
3383 1.1 christos _("32-bit conditional branch generated"));
3384 1.1 christos
3385 1.1 christos /* Here, writep points to what will be opcodep + 2. First, we change
3386 1.1 christos the actual branch in opcodep[0] and opcodep[1], so that in the
3387 1.1 christos final insn, it will look like:
3388 1.1 christos opcodep+10: Bcc .-6
3389 1.1 christos
3390 1.1 christos This means we don't have to worry about changing the opcode or
3391 1.1 christos messing with the delay-slot instruction. So, we move it to last in
3392 1.1 christos the "extended" branch, and just change the displacement. Admittedly,
3393 1.1 christos it's not the optimal extended construct, but we should get this
3394 1.1 christos rarely enough that it shouldn't matter. */
3395 1.1 christos
3396 1.1 christos writep[opc_offset] = branch_disp (branch_offset);
3397 1.1 christos writep[opc_offset + 1] = opcodep[1];
3398 1.1 christos
3399 1.1 christos /* Then, we change the branch to an unconditional branch over the
3400 1.1 christos extended part, to the new location of the Bcc:
3401 1.1 christos opcodep: BA .+10
3402 1.1 christos opcodep+2: NOP
3403 1.1 christos
3404 1.1 christos Note that these two writes are to currently different locations,
3405 1.1 christos merged later. */
3406 1.1 christos
3407 1.1 christos md_number_to_chars (opcodep, BA_QUICK_OPCODE
3408 1.1 christos + (cris_arch == arch_crisv32 ? 12 : (pic ? 10 : 8)),
3409 1.1 christos 2);
3410 1.1 christos md_number_to_chars (writep, nop_opcode, 2);
3411 1.1 christos
3412 1.1 christos /* Then the extended thing, the 32-bit jump insn.
3413 1.1 christos opcodep+4: JUMP [PC+]
3414 1.1 christos or, in the PIC case,
3415 1.1 christos opcodep+4: MOVE [PC=PC+N],P0. */
3416 1.1 christos
3417 1.1 christos md_number_to_chars (writep + 2,
3418 1.1 christos cris_arch == arch_crisv32
3419 1.1 christos ? BA_DWORD_OPCODE
3420 1.1 christos : (pic ? MOVE_PC_INCR_OPCODE_PREFIX
3421 1.1 christos : JUMP_PC_INCR_OPCODE), 2);
3422 1.1 christos
3423 1.1 christos /* We have to fill in the actual value too.
3424 1.1 christos opcodep+6: .DWORD
3425 1.1 christos This is most probably an expression, but we can cope with an absolute
3426 1.1 christos value too. FIXME: Testcase needed with and without pic. */
3427 1.1 christos
3428 1.1 christos if (add_symP == NULL && sub_symP == NULL)
3429 1.1 christos {
3430 1.1 christos /* An absolute address. */
3431 1.1 christos if (pic || cris_arch == arch_crisv32)
3432 1.1 christos fix_new (fragP, writep + 4 - fragP->fr_literal, 4,
3433 1.1 christos section_symbol (absolute_section),
3434 1.1 christos add_num
3435 1.1 christos + (cris_arch == arch_crisv32 ? 6 : 0),
3436 1.1 christos 1, BFD_RELOC_32_PCREL);
3437 1.1 christos else
3438 1.1 christos md_number_to_chars (writep + 4, add_num, 4);
3439 1.1 christos }
3440 1.1 christos else
3441 1.1 christos {
3442 1.1 christos if (sub_symP != NULL)
3443 1.1 christos as_bad_where (fragP->fr_file, fragP->fr_line,
3444 1.1 christos _("Complex expression not supported"));
3445 1.1 christos
3446 1.1 christos /* Not absolute, we have to make it a frag for later evaluation. */
3447 1.1 christos fix_new (fragP, writep + 4 - fragP->fr_literal, 4, add_symP,
3448 1.1 christos add_num + (cris_arch == arch_crisv32 ? 6 : 0),
3449 1.1 christos pic || cris_arch == arch_crisv32 ? 1 : 0,
3450 1.1 christos pic || cris_arch == arch_crisv32
3451 1.1 christos ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
3452 1.1 christos }
3453 1.1 christos
3454 1.1 christos if (cris_arch == arch_crisv32)
3455 1.1 christos /* Follow it with a "NOP" for CRISv32. */
3456 1.1 christos md_number_to_chars (writep + 8, NOP_OPCODE_V32, 2);
3457 1.1 christos else if (pic)
3458 1.1 christos /* ...and the rest of the move-opcode for pre-v32 PIC. */
3459 1.1 christos md_number_to_chars (writep + 8, MOVE_PC_INCR_OPCODE_SUFFIX, 2);
3460 1.1 christos }
3461 1.1 christos
3462 1.1 christos /* Get the size of an immediate-reloc in bytes. Only valid for
3463 1.1 christos specified relocs (TLS, PIC). */
3464 1.1 christos
3465 1.1 christos static unsigned int
3466 1.1 christos cris_get_specified_reloc_size (bfd_reloc_code_real_type reloc)
3467 1.1 christos {
3468 1.1 christos return
3469 1.1 christos reloc == BFD_RELOC_CRIS_16_GOTPLT
3470 1.1 christos || reloc == BFD_RELOC_CRIS_16_GOT
3471 1.1 christos || reloc == BFD_RELOC_CRIS_16_GOT_GD
3472 1.1 christos || reloc == BFD_RELOC_CRIS_16_DTPREL
3473 1.1 christos || reloc == BFD_RELOC_CRIS_16_GOT_TPREL
3474 1.1 christos || reloc == BFD_RELOC_CRIS_16_TPREL
3475 1.1 christos ? 2 : 4;
3476 1.1 christos }
3477 1.1 christos
3478 1.1 christos /* Store a reloc type at *RELOCP corresponding to the PIC suffix at *CPP.
3479 1.1 christos Adjust *EXPRP with any addend found after the PIC suffix. */
3480 1.1 christos
3481 1.1 christos static void
3482 1.1 christos cris_get_reloc_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
3483 1.1 christos expressionS *exprP)
3484 1.1 christos {
3485 1.1 christos char *s = *cPP;
3486 1.1 christos unsigned int i;
3487 1.1 christos expressionS const_expr;
3488 1.1 christos
3489 1.1 christos const struct pic_suffixes_struct
3490 1.1 christos {
3491 1.1 christos const char *const suffix;
3492 1.1 christos unsigned int len;
3493 1.1 christos bfd_reloc_code_real_type reloc;
3494 1.8 christos bool pic_p;
3495 1.8 christos bool tls_p;
3496 1.1 christos } pic_suffixes[] =
3497 1.1 christos {
3498 1.1 christos #undef PICMAP
3499 1.8 christos #define PICMAP(s, r) {s, sizeof (s) - 1, r, true, false}
3500 1.8 christos #define PICTLSMAP(s, r) {s, sizeof (s) - 1, r, true, true}
3501 1.8 christos #define TLSMAP(s, r) {s, sizeof (s) - 1, r, false, true}
3502 1.1 christos /* Keep this in order with longest unambiguous prefix first. */
3503 1.1 christos PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT),
3504 1.1 christos PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT),
3505 1.1 christos PICMAP ("PLTG", BFD_RELOC_CRIS_32_PLT_GOTREL),
3506 1.1 christos PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL),
3507 1.1 christos PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL),
3508 1.1 christos PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT),
3509 1.1 christos PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT),
3510 1.1 christos PICTLSMAP ("GDGOTREL16", BFD_RELOC_CRIS_16_GOT_GD),
3511 1.1 christos PICTLSMAP ("GDGOTREL", BFD_RELOC_CRIS_32_GOT_GD),
3512 1.1 christos TLSMAP ("GD", BFD_RELOC_CRIS_32_GD),
3513 1.1 christos PICTLSMAP ("DTPREL16", BFD_RELOC_CRIS_16_DTPREL),
3514 1.1 christos PICTLSMAP ("DTPREL", BFD_RELOC_CRIS_32_DTPREL),
3515 1.1 christos TLSMAP ("IE", BFD_RELOC_CRIS_32_IE),
3516 1.1 christos PICTLSMAP ("TPOFFGOT16", BFD_RELOC_CRIS_16_GOT_TPREL),
3517 1.1 christos PICTLSMAP ("TPOFFGOT", BFD_RELOC_CRIS_32_GOT_TPREL),
3518 1.1 christos TLSMAP ("TPOFF16", BFD_RELOC_CRIS_16_TPREL),
3519 1.1 christos TLSMAP ("TPOFF", BFD_RELOC_CRIS_32_TPREL)
3520 1.1 christos };
3521 1.1 christos
3522 1.1 christos /* We've already seen the ':', so consume it. */
3523 1.1 christos s++;
3524 1.1 christos
3525 1.1 christos for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++)
3526 1.1 christos {
3527 1.1 christos if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0
3528 1.1 christos && ! is_part_of_name (s[pic_suffixes[i].len])
3529 1.1 christos /* PIC and non-PIC relocations are exclusive. */
3530 1.1 christos && (pic != 0) == (pic_suffixes[i].pic_p != 0)
3531 1.1 christos /* But TLS can be active for non-TLS relocations too. */
3532 1.1 christos && (pic_suffixes[i].tls_p == 0 || tls))
3533 1.1 christos {
3534 1.1 christos /* We have a match. Consume the suffix and set the relocation
3535 1.1 christos type. */
3536 1.1 christos s += pic_suffixes[i].len;
3537 1.1 christos
3538 1.1 christos /* There can be a constant term appended. If so, we will add it
3539 1.1 christos to *EXPRP. */
3540 1.1 christos if (*s == '+' || *s == '-')
3541 1.1 christos {
3542 1.1 christos if (! cris_get_expression (&s, &const_expr))
3543 1.1 christos /* There was some kind of syntax error. Bail out. */
3544 1.1 christos break;
3545 1.1 christos
3546 1.1 christos /* Allow complex expressions as the constant part. It still
3547 1.1 christos has to be an assembly-time constant or there will be an
3548 1.1 christos error emitting the reloc. This makes the PIC qualifiers
3549 1.1 christos idempotent; foo:GOTOFF+32 == foo+32:GOTOFF. The former we
3550 1.1 christos recognize here; the latter is parsed in the incoming
3551 1.1 christos expression. */
3552 1.1 christos exprP->X_add_symbol = make_expr_symbol (exprP);
3553 1.1 christos exprP->X_op = O_add;
3554 1.1 christos exprP->X_add_number = 0;
3555 1.1 christos exprP->X_op_symbol = make_expr_symbol (&const_expr);
3556 1.1 christos }
3557 1.1 christos
3558 1.1 christos *relocp = pic_suffixes[i].reloc;
3559 1.1 christos *cPP = s;
3560 1.1 christos return;
3561 1.1 christos }
3562 1.1 christos }
3563 1.1 christos
3564 1.1 christos /* No match. Don't consume anything; fall back and there will be a
3565 1.1 christos syntax error. */
3566 1.1 christos }
3567 1.1 christos
3568 1.1 christos /* This *could* have been:
3569 1.1 christos
3570 1.1 christos Turn a string in input_line_pointer into a floating point constant
3571 1.1 christos of type TYPE, and store the appropriate bytes in *LITP. The number
3572 1.1 christos of LITTLENUMS emitted is stored in *SIZEP.
3573 1.1 christos
3574 1.1 christos type A character from FLTCHARS that describes what kind of
3575 1.1 christos floating-point number is wanted.
3576 1.1 christos
3577 1.1 christos litp A pointer to an array that the result should be stored in.
3578 1.1 christos
3579 1.1 christos sizep A pointer to an integer where the size of the result is stored.
3580 1.1 christos
3581 1.1 christos But we don't support floating point constants in assembly code *at all*,
3582 1.1 christos since it's suboptimal and just opens up bug opportunities. GCC emits
3583 1.1 christos the bit patterns as hex. All we could do here is to emit what GCC
3584 1.1 christos would have done in the first place. *Nobody* writes floating-point
3585 1.1 christos code as assembly code, but if they do, they should be able enough to
3586 1.1 christos find out the correct bit patterns and use them. */
3587 1.1 christos
3588 1.5 christos const char *
3589 1.1 christos md_atof (int type ATTRIBUTE_UNUSED, char *litp ATTRIBUTE_UNUSED,
3590 1.1 christos int *sizep ATTRIBUTE_UNUSED)
3591 1.1 christos {
3592 1.1 christos /* FIXME: Is this function mentioned in the internals.texi manual? If
3593 1.1 christos not, add it. */
3594 1.1 christos return _("Bad call to md_atof () - floating point formats are not supported");
3595 1.1 christos }
3596 1.1 christos
3597 1.1 christos /* Turn a number as a fixS * into a series of bytes that represents the
3598 1.1 christos number on the target machine. The purpose of this procedure is the
3599 1.1 christos same as that of md_number_to_chars but this procedure is supposed to
3600 1.1 christos handle general bit field fixes and machine-dependent fixups.
3601 1.1 christos
3602 1.1 christos bufp Pointer to an array where the result should be stored.
3603 1.1 christos
3604 1.1 christos val The value to store.
3605 1.1 christos
3606 1.1 christos n The number of bytes in "val" that should be stored.
3607 1.1 christos
3608 1.1 christos fixP The fix to be applied to the bit field starting at bufp.
3609 1.1 christos
3610 1.1 christos seg The segment containing this number. */
3611 1.1 christos
3612 1.1 christos static void
3613 1.1 christos cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
3614 1.1 christos {
3615 1.1 christos segT sym_seg;
3616 1.1 christos
3617 1.1 christos know (n <= 4);
3618 1.1 christos know (fixP);
3619 1.1 christos
3620 1.1 christos /* We put the relative "vma" for the other segment for inter-segment
3621 1.1 christos relocations in the object data to stay binary "compatible" (with an
3622 1.1 christos uninteresting old version) for the relocation.
3623 1.1 christos Maybe delete some day. */
3624 1.1 christos if (fixP->fx_addsy
3625 1.1 christos && (sym_seg = S_GET_SEGMENT (fixP->fx_addsy)) != seg)
3626 1.1 christos val += sym_seg->vma;
3627 1.1 christos
3628 1.1 christos if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
3629 1.1 christos switch (fixP->fx_r_type)
3630 1.1 christos {
3631 1.1 christos /* These must be fully resolved when getting here. */
3632 1.1 christos case BFD_RELOC_16_PCREL:
3633 1.1 christos case BFD_RELOC_8_PCREL:
3634 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3635 1.1 christos _("PC-relative relocation must be trivially resolved"));
3636 1.1 christos default:
3637 1.1 christos ;
3638 1.1 christos }
3639 1.1 christos
3640 1.1 christos /* Only use the computed value for old-arch binaries. For all
3641 1.1 christos others, where we're going to output a relocation, put 0 in the
3642 1.1 christos code. */
3643 1.1 christos if (cris_arch != arch_cris_any_v0_v10
3644 1.1 christos && (fixP->fx_addsy != NULL || fixP->fx_pcrel))
3645 1.1 christos val = 0;
3646 1.1 christos
3647 1.1 christos switch (fixP->fx_r_type)
3648 1.1 christos {
3649 1.1 christos /* Ditto here, we put the addend into the object code as
3650 1.1 christos well as the reloc addend. Keep it that way for now, to simplify
3651 1.1 christos regression tests on the object file contents. FIXME: Seems
3652 1.1 christos uninteresting now that we have a test suite. */
3653 1.1 christos
3654 1.1 christos case BFD_RELOC_CRIS_32_GOT_GD:
3655 1.1 christos case BFD_RELOC_CRIS_16_GOT_GD:
3656 1.1 christos case BFD_RELOC_CRIS_32_GD:
3657 1.1 christos case BFD_RELOC_CRIS_32_IE:
3658 1.1 christos case BFD_RELOC_CRIS_32_DTPREL:
3659 1.1 christos case BFD_RELOC_CRIS_16_DTPREL:
3660 1.1 christos case BFD_RELOC_CRIS_32_GOT_TPREL:
3661 1.1 christos case BFD_RELOC_CRIS_16_GOT_TPREL:
3662 1.1 christos case BFD_RELOC_CRIS_32_TPREL:
3663 1.1 christos case BFD_RELOC_CRIS_16_TPREL:
3664 1.1 christos #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3665 1.1 christos if (IS_ELF && fixP->fx_addsy != NULL)
3666 1.1 christos S_SET_THREAD_LOCAL (fixP->fx_addsy);
3667 1.1 christos #endif
3668 1.1 christos /* Fall through. */
3669 1.1 christos
3670 1.1 christos case BFD_RELOC_CRIS_16_GOT:
3671 1.1 christos case BFD_RELOC_CRIS_32_GOT:
3672 1.1 christos case BFD_RELOC_CRIS_32_GOTREL:
3673 1.1 christos case BFD_RELOC_CRIS_16_GOTPLT:
3674 1.1 christos case BFD_RELOC_CRIS_32_GOTPLT:
3675 1.1 christos case BFD_RELOC_CRIS_32_PLT_GOTREL:
3676 1.1 christos case BFD_RELOC_CRIS_32_PLT_PCREL:
3677 1.1 christos /* We don't want to put in any kind of non-zero bits in the data
3678 1.1 christos being relocated for these. */
3679 1.1 christos md_number_to_chars (bufp, 0, n);
3680 1.1 christos break;
3681 1.1 christos
3682 1.1 christos case BFD_RELOC_32_PCREL:
3683 1.1 christos /* If this one isn't fully resolved, we don't want to put non-zero
3684 1.1 christos in the object. */
3685 1.1 christos if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
3686 1.1 christos val = 0;
3687 1.1 christos
3688 1.1 christos /* Fall through. */
3689 1.1 christos case BFD_RELOC_32:
3690 1.1 christos /* No use having warnings here, since most hosts have a 32-bit type
3691 1.1 christos for "long" (which will probably change soon, now that I wrote
3692 1.1 christos this). */
3693 1.1 christos bufp[3] = (val >> 24) & 0xFF;
3694 1.1 christos bufp[2] = (val >> 16) & 0xFF;
3695 1.1 christos bufp[1] = (val >> 8) & 0xFF;
3696 1.1 christos bufp[0] = val & 0xFF;
3697 1.1 christos break;
3698 1.1 christos
3699 1.1 christos /* FIXME: The 16 and 8-bit cases should have a way to check
3700 1.1 christos whether a signed or unsigned (or any signedness) number is
3701 1.1 christos accepted. */
3702 1.1 christos
3703 1.1 christos case BFD_RELOC_16:
3704 1.1 christos case BFD_RELOC_16_PCREL:
3705 1.1 christos if (val > 0xffff || val < -32768)
3706 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3707 1.1 christos _("Value not in 16 bit range: %ld"), val);
3708 1.1 christos bufp[1] = (val >> 8) & 0xFF;
3709 1.1 christos bufp[0] = val & 0xFF;
3710 1.1 christos break;
3711 1.1 christos
3712 1.1 christos case BFD_RELOC_CRIS_SIGNED_16:
3713 1.1 christos if (val > 32767 || val < -32768)
3714 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3715 1.1 christos _("Value not in 16 bit signed range: %ld"), val);
3716 1.1 christos bufp[1] = (val >> 8) & 0xFF;
3717 1.1 christos bufp[0] = val & 0xFF;
3718 1.1 christos break;
3719 1.1 christos
3720 1.1 christos case BFD_RELOC_8:
3721 1.1 christos case BFD_RELOC_8_PCREL:
3722 1.1 christos if (val > 255 || val < -128)
3723 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line, _("Value not in 8 bit range: %ld"), val);
3724 1.1 christos bufp[0] = val & 0xFF;
3725 1.1 christos break;
3726 1.1 christos
3727 1.1 christos case BFD_RELOC_CRIS_SIGNED_8:
3728 1.1 christos if (val > 127 || val < -128)
3729 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3730 1.1 christos _("Value not in 8 bit signed range: %ld"), val);
3731 1.1 christos bufp[0] = val & 0xFF;
3732 1.1 christos break;
3733 1.1 christos
3734 1.1 christos case BFD_RELOC_CRIS_LAPCQ_OFFSET:
3735 1.1 christos /* FIXME: Test-cases for out-of-range values. Probably also need
3736 1.1 christos to use as_bad_where. */
3737 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_4:
3738 1.1 christos if (val > 15 || val < 0)
3739 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3740 1.1 christos _("Value not in 4 bit unsigned range: %ld"), val);
3741 1.1 christos bufp[0] |= val & 0x0F;
3742 1.1 christos break;
3743 1.1 christos
3744 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_5:
3745 1.1 christos if (val > 31 || val < 0)
3746 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3747 1.1 christos _("Value not in 5 bit unsigned range: %ld"), val);
3748 1.1 christos bufp[0] |= val & 0x1F;
3749 1.1 christos break;
3750 1.1 christos
3751 1.1 christos case BFD_RELOC_CRIS_SIGNED_6:
3752 1.1 christos if (val > 31 || val < -32)
3753 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3754 1.1 christos _("Value not in 6 bit range: %ld"), val);
3755 1.1 christos bufp[0] |= val & 0x3F;
3756 1.1 christos break;
3757 1.1 christos
3758 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_6:
3759 1.1 christos if (val > 63 || val < 0)
3760 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3761 1.1 christos _("Value not in 6 bit unsigned range: %ld"), val);
3762 1.1 christos bufp[0] |= val & 0x3F;
3763 1.1 christos break;
3764 1.1 christos
3765 1.1 christos case BFD_RELOC_CRIS_BDISP8:
3766 1.1 christos bufp[0] = branch_disp (val);
3767 1.1 christos break;
3768 1.1 christos
3769 1.1 christos case BFD_RELOC_NONE:
3770 1.1 christos /* May actually happen automatically. For example at broken
3771 1.1 christos words, if the word turns out not to be broken.
3772 1.1 christos FIXME: When? Which testcase? */
3773 1.1 christos if (! fixP->fx_addsy)
3774 1.1 christos md_number_to_chars (bufp, val, n);
3775 1.1 christos break;
3776 1.1 christos
3777 1.1 christos case BFD_RELOC_VTABLE_INHERIT:
3778 1.1 christos /* This borrowed from tc-ppc.c on a whim. */
3779 1.1 christos if (fixP->fx_addsy
3780 1.1 christos && !S_IS_DEFINED (fixP->fx_addsy)
3781 1.1 christos && !S_IS_WEAK (fixP->fx_addsy))
3782 1.1 christos S_SET_WEAK (fixP->fx_addsy);
3783 1.1 christos /* Fall through. */
3784 1.1 christos
3785 1.1 christos case BFD_RELOC_VTABLE_ENTRY:
3786 1.1 christos fixP->fx_done = 0;
3787 1.1 christos break;
3788 1.1 christos
3789 1.1 christos default:
3790 1.1 christos BAD_CASE (fixP->fx_r_type);
3791 1.1 christos }
3792 1.1 christos }
3793 1.1 christos
3794 1.1 christos /* Processes machine-dependent command line options. Called once for
3795 1.1 christos each option on the command line that the machine-independent part of
3796 1.1 christos GAS does not understand. */
3797 1.1 christos
3798 1.1 christos int
3799 1.5 christos md_parse_option (int arg, const char *argp ATTRIBUTE_UNUSED)
3800 1.1 christos {
3801 1.1 christos switch (arg)
3802 1.1 christos {
3803 1.1 christos case 'H':
3804 1.1 christos case 'h':
3805 1.1 christos printf (_("Please use --help to see usage and options for this assembler.\n"));
3806 1.1 christos md_show_usage (stdout);
3807 1.1 christos exit (EXIT_SUCCESS);
3808 1.1 christos
3809 1.1 christos case 'N':
3810 1.1 christos warn_for_branch_expansion = 1;
3811 1.1 christos break;
3812 1.1 christos
3813 1.1 christos case OPTION_NO_US:
3814 1.8 christos demand_register_prefix = true;
3815 1.1 christos
3816 1.1 christos if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
3817 1.1 christos as_bad (_("--no-underscore is invalid with a.out format"));
3818 1.1 christos else
3819 1.8 christos symbols_have_leading_underscore = false;
3820 1.1 christos break;
3821 1.1 christos
3822 1.1 christos case OPTION_US:
3823 1.8 christos demand_register_prefix = false;
3824 1.8 christos symbols_have_leading_underscore = true;
3825 1.1 christos break;
3826 1.1 christos
3827 1.1 christos case OPTION_PIC:
3828 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
3829 1.1 christos as_bad (_("--pic is invalid for this object format"));
3830 1.8 christos pic = true;
3831 1.1 christos if (cris_arch != arch_crisv32)
3832 1.1 christos md_long_jump_size = cris_any_v0_v10_long_jump_size_pic;
3833 1.1 christos else
3834 1.1 christos md_long_jump_size = crisv32_long_jump_size;
3835 1.1 christos break;
3836 1.1 christos
3837 1.1 christos case OPTION_ARCH:
3838 1.1 christos {
3839 1.5 christos const char *str = argp;
3840 1.1 christos enum cris_archs argarch = cris_arch_from_string (&str);
3841 1.1 christos
3842 1.1 christos if (argarch == arch_cris_unknown)
3843 1.1 christos as_bad (_("invalid <arch> in --march=<arch>: %s"), argp);
3844 1.1 christos else
3845 1.1 christos cris_arch = argarch;
3846 1.1 christos
3847 1.1 christos if (argarch == arch_crisv32)
3848 1.1 christos {
3849 1.1 christos err_for_dangerous_mul_placement = 0;
3850 1.1 christos md_long_jump_size = crisv32_long_jump_size;
3851 1.1 christos }
3852 1.1 christos else
3853 1.1 christos {
3854 1.1 christos if (pic)
3855 1.1 christos md_long_jump_size = cris_any_v0_v10_long_jump_size_pic;
3856 1.1 christos else
3857 1.1 christos md_long_jump_size = cris_any_v0_v10_long_jump_size;
3858 1.1 christos }
3859 1.1 christos }
3860 1.1 christos break;
3861 1.1 christos
3862 1.1 christos case OPTION_MULBUG_ABORT_OFF:
3863 1.1 christos err_for_dangerous_mul_placement = 0;
3864 1.1 christos break;
3865 1.1 christos
3866 1.1 christos case OPTION_MULBUG_ABORT_ON:
3867 1.1 christos err_for_dangerous_mul_placement = 1;
3868 1.1 christos break;
3869 1.1 christos
3870 1.1 christos default:
3871 1.1 christos return 0;
3872 1.1 christos }
3873 1.1 christos
3874 1.1 christos return 1;
3875 1.1 christos }
3876 1.1 christos
3877 1.1 christos /* Round up a section size to the appropriate boundary. */
3878 1.1 christos valueT
3879 1.1 christos md_section_align (segT segment, valueT size)
3880 1.1 christos {
3881 1.1 christos /* Round all sects to multiple of 4, except the bss section, which
3882 1.1 christos we'll round to word-size.
3883 1.1 christos
3884 1.1 christos FIXME: Check if this really matters. All sections should be
3885 1.1 christos rounded up, and all sections should (optionally) be assumed to be
3886 1.1 christos dword-aligned, it's just that there is actual usage of linking to a
3887 1.1 christos multiple of two. */
3888 1.1 christos if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
3889 1.1 christos {
3890 1.1 christos if (segment == bss_section)
3891 1.1 christos return (size + 1) & ~1;
3892 1.1 christos return (size + 3) & ~3;
3893 1.1 christos }
3894 1.1 christos else
3895 1.1 christos {
3896 1.1 christos /* FIXME: Is this wanted? It matches the testsuite, but that's not
3897 1.1 christos really a valid reason. */
3898 1.1 christos if (segment == text_section)
3899 1.1 christos return (size + 3) & ~3;
3900 1.1 christos }
3901 1.1 christos
3902 1.1 christos return size;
3903 1.1 christos }
3904 1.1 christos
3905 1.1 christos /* Generate a machine-dependent relocation. */
3906 1.1 christos arelent *
3907 1.1 christos tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
3908 1.1 christos {
3909 1.1 christos arelent *relP;
3910 1.1 christos bfd_reloc_code_real_type code;
3911 1.1 christos
3912 1.1 christos switch (fixP->fx_r_type)
3913 1.1 christos {
3914 1.1 christos case BFD_RELOC_CRIS_SIGNED_8:
3915 1.1 christos code = BFD_RELOC_8;
3916 1.1 christos break;
3917 1.1 christos
3918 1.1 christos case BFD_RELOC_CRIS_SIGNED_16:
3919 1.1 christos code = BFD_RELOC_16;
3920 1.1 christos break;
3921 1.1 christos
3922 1.1 christos case BFD_RELOC_CRIS_16_GOT:
3923 1.1 christos case BFD_RELOC_CRIS_32_GOT:
3924 1.1 christos case BFD_RELOC_CRIS_16_GOTPLT:
3925 1.1 christos case BFD_RELOC_CRIS_32_GOTPLT:
3926 1.1 christos case BFD_RELOC_CRIS_32_GOTREL:
3927 1.1 christos case BFD_RELOC_CRIS_32_PLT_GOTREL:
3928 1.1 christos case BFD_RELOC_CRIS_32_PLT_PCREL:
3929 1.1 christos case BFD_RELOC_32:
3930 1.1 christos case BFD_RELOC_32_PCREL:
3931 1.1 christos case BFD_RELOC_16:
3932 1.1 christos case BFD_RELOC_8:
3933 1.1 christos case BFD_RELOC_VTABLE_INHERIT:
3934 1.1 christos case BFD_RELOC_VTABLE_ENTRY:
3935 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_8:
3936 1.1 christos case BFD_RELOC_CRIS_UNSIGNED_16:
3937 1.1 christos case BFD_RELOC_CRIS_LAPCQ_OFFSET:
3938 1.1 christos case BFD_RELOC_CRIS_32_GOT_GD:
3939 1.1 christos case BFD_RELOC_CRIS_16_GOT_GD:
3940 1.1 christos case BFD_RELOC_CRIS_32_GD:
3941 1.1 christos case BFD_RELOC_CRIS_32_IE:
3942 1.1 christos case BFD_RELOC_CRIS_32_DTPREL:
3943 1.1 christos case BFD_RELOC_CRIS_16_DTPREL:
3944 1.1 christos case BFD_RELOC_CRIS_32_GOT_TPREL:
3945 1.1 christos case BFD_RELOC_CRIS_16_GOT_TPREL:
3946 1.1 christos case BFD_RELOC_CRIS_32_TPREL:
3947 1.1 christos case BFD_RELOC_CRIS_16_TPREL:
3948 1.1 christos code = fixP->fx_r_type;
3949 1.1 christos break;
3950 1.1 christos default:
3951 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
3952 1.1 christos _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant"));
3953 1.1 christos return 0;
3954 1.1 christos }
3955 1.1 christos
3956 1.5 christos relP = XNEW (arelent);
3957 1.1 christos gas_assert (relP != 0);
3958 1.5 christos relP->sym_ptr_ptr = XNEW (asymbol *);
3959 1.1 christos *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
3960 1.1 christos relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
3961 1.1 christos
3962 1.1 christos relP->addend = fixP->fx_offset;
3963 1.1 christos
3964 1.1 christos /* This is the standard place for KLUDGEs to work around bugs in
3965 1.1 christos bfd_install_relocation (first such note in the documentation
3966 1.1 christos appears with binutils-2.8).
3967 1.1 christos
3968 1.1 christos That function bfd_install_relocation does the wrong thing with
3969 1.1 christos putting stuff into the addend of a reloc (it should stay out) for a
3970 1.1 christos weak symbol. The really bad thing is that it adds the
3971 1.1 christos "segment-relative offset" of the symbol into the reloc. In this
3972 1.1 christos case, the reloc should instead be relative to the symbol with no
3973 1.1 christos other offset than the assembly code shows; and since the symbol is
3974 1.1 christos weak, any local definition should be ignored until link time (or
3975 1.1 christos thereafter).
3976 1.1 christos To wit: weaksym+42 should be weaksym+42 in the reloc,
3977 1.1 christos not weaksym+(offset_from_segment_of_local_weaksym_definition)
3978 1.1 christos
3979 1.1 christos To "work around" this, we subtract the segment-relative offset of
3980 1.1 christos "known" weak symbols. This evens out the extra offset.
3981 1.1 christos
3982 1.1 christos That happens for a.out but not for ELF, since for ELF,
3983 1.1 christos bfd_install_relocation uses the "special function" field of the
3984 1.1 christos howto, and does not execute the code that needs to be undone. */
3985 1.1 christos
3986 1.1 christos if (OUTPUT_FLAVOR == bfd_target_aout_flavour
3987 1.1 christos && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
3988 1.1 christos && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
3989 1.1 christos {
3990 1.1 christos relP->addend -= S_GET_VALUE (fixP->fx_addsy);
3991 1.1 christos }
3992 1.1 christos
3993 1.1 christos relP->howto = bfd_reloc_type_lookup (stdoutput, code);
3994 1.1 christos if (! relP->howto)
3995 1.1 christos {
3996 1.1 christos const char *name;
3997 1.1 christos
3998 1.1 christos name = S_GET_NAME (fixP->fx_addsy);
3999 1.1 christos if (name == NULL)
4000 1.1 christos name = _("<unknown>");
4001 1.1 christos as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
4002 1.1 christos name, bfd_get_reloc_code_name (code));
4003 1.1 christos }
4004 1.1 christos
4005 1.1 christos return relP;
4006 1.1 christos }
4007 1.1 christos
4008 1.1 christos /* Machine-dependent usage-output. */
4009 1.1 christos
4010 1.1 christos void
4011 1.1 christos md_show_usage (FILE *stream)
4012 1.1 christos {
4013 1.1 christos /* The messages are formatted to line up with the generic options. */
4014 1.1 christos fprintf (stream, _("CRIS-specific options:\n"));
4015 1.1 christos fprintf (stream, "%s",
4016 1.1 christos _(" -h, -H Don't execute, print this help text. Deprecated.\n"));
4017 1.1 christos fprintf (stream, "%s",
4018 1.1 christos _(" -N Warn when branches are expanded to jumps.\n"));
4019 1.1 christos fprintf (stream, "%s",
4020 1.1 christos _(" --underscore User symbols are normally prepended with underscore.\n"));
4021 1.1 christos fprintf (stream, "%s",
4022 1.1 christos _(" Registers will not need any prefix.\n"));
4023 1.1 christos fprintf (stream, "%s",
4024 1.1 christos _(" --no-underscore User symbols do not have any prefix.\n"));
4025 1.1 christos fprintf (stream, "%s",
4026 1.1 christos _(" Registers will require a `$'-prefix.\n"));
4027 1.1 christos #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
4028 1.1 christos fprintf (stream, "%s",
4029 1.1 christos _(" --pic Enable generation of position-independent code.\n"));
4030 1.1 christos #endif
4031 1.1 christos fprintf (stream, "%s",
4032 1.1 christos _(" --march=<arch> Generate code for <arch>. Valid choices for <arch>\n\
4033 1.1 christos are v0_v10, v10, v32 and common_v10_v32.\n"));
4034 1.1 christos }
4035 1.1 christos
4036 1.1 christos /* Apply a fixS (fixup of an instruction or data that we didn't have
4037 1.1 christos enough info to complete immediately) to the data in a frag. */
4038 1.1 christos
4039 1.1 christos void
4040 1.1 christos md_apply_fix (fixS *fixP, valueT *valP, segT seg)
4041 1.1 christos {
4042 1.1 christos /* This assignment truncates upper bits if valueT is 64 bits (as with
4043 1.1 christos --enable-64-bit-bfd), which is fine here, though we cast to avoid
4044 1.1 christos any compiler warnings. */
4045 1.1 christos long val = (long) *valP;
4046 1.1 christos char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
4047 1.1 christos
4048 1.1 christos if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
4049 1.1 christos fixP->fx_done = 1;
4050 1.1 christos
4051 1.7 christos /* We can't actually support subtracting a symbol. */
4052 1.7 christos if (fixP->fx_subsy != (symbolS *) NULL)
4053 1.8 christos as_bad_subtract (fixP);
4054 1.1 christos
4055 1.7 christos /* This operand-type is scaled. */
4056 1.7 christos if (fixP->fx_r_type == BFD_RELOC_CRIS_LAPCQ_OFFSET)
4057 1.7 christos val /= 2;
4058 1.7 christos cris_number_to_imm (buf, val, fixP->fx_size, fixP, seg);
4059 1.1 christos }
4060 1.1 christos
4061 1.1 christos /* All relocations are relative to the location just after the fixup;
4062 1.1 christos the address of the fixup plus its size. */
4063 1.1 christos
4064 1.1 christos long
4065 1.1 christos md_pcrel_from (fixS *fixP)
4066 1.1 christos {
4067 1.1 christos valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
4068 1.1 christos
4069 1.1 christos /* FIXME: We get here only at the end of assembly, when X in ".-X" is
4070 1.1 christos still unknown. Since we don't have pc-relative relocations in a.out,
4071 1.1 christos this is invalid. What to do if anything for a.out, is to add
4072 1.1 christos pc-relative relocations everywhere including the elinux program
4073 1.1 christos loader. For ELF, allow straight-forward PC-relative relocations,
4074 1.1 christos which are always relative to the location after the relocation. */
4075 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour
4076 1.1 christos || (fixP->fx_r_type != BFD_RELOC_8_PCREL
4077 1.1 christos && fixP->fx_r_type != BFD_RELOC_16_PCREL
4078 1.1 christos && fixP->fx_r_type != BFD_RELOC_32_PCREL
4079 1.1 christos && fixP->fx_r_type != BFD_RELOC_CRIS_LAPCQ_OFFSET))
4080 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
4081 1.1 christos _("Invalid pc-relative relocation"));
4082 1.1 christos return fixP->fx_size + addr;
4083 1.1 christos }
4084 1.1 christos
4085 1.1 christos /* We have no need to give defaults for symbol-values. */
4086 1.1 christos symbolS *
4087 1.1 christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
4088 1.1 christos {
4089 1.1 christos return 0;
4090 1.1 christos }
4091 1.1 christos
4092 1.1 christos /* If this function returns non-zero, it prevents the relocation
4093 1.1 christos against symbol(s) in the FIXP from being replaced with relocations
4094 1.1 christos against section symbols, and guarantees that a relocation will be
4095 1.1 christos emitted even when the value can be resolved locally. */
4096 1.1 christos int
4097 1.1 christos md_cris_force_relocation (struct fix *fixp)
4098 1.1 christos {
4099 1.1 christos switch (fixp->fx_r_type)
4100 1.1 christos {
4101 1.1 christos case BFD_RELOC_CRIS_16_GOT:
4102 1.1 christos case BFD_RELOC_CRIS_32_GOT:
4103 1.1 christos case BFD_RELOC_CRIS_16_GOTPLT:
4104 1.1 christos case BFD_RELOC_CRIS_32_GOTPLT:
4105 1.1 christos case BFD_RELOC_CRIS_32_GOTREL:
4106 1.1 christos case BFD_RELOC_CRIS_32_PLT_GOTREL:
4107 1.1 christos case BFD_RELOC_CRIS_32_PLT_PCREL:
4108 1.1 christos return 1;
4109 1.1 christos default:
4110 1.1 christos ;
4111 1.1 christos }
4112 1.1 christos
4113 1.1 christos return generic_force_reloc (fixp);
4114 1.1 christos }
4115 1.1 christos
4116 1.1 christos /* Check and emit error if broken-word handling has failed to fix up a
4117 1.1 christos case-table. This is called from write.c, after doing everything it
4118 1.1 christos knows about how to handle broken words. */
4119 1.1 christos
4120 1.1 christos void
4121 1.1 christos tc_cris_check_adjusted_broken_word (offsetT new_offset, struct broken_word *brokwP)
4122 1.1 christos {
4123 1.1 christos if (new_offset > 32767 || new_offset < -32768)
4124 1.1 christos /* We really want a genuine error, not a warning, so make it one. */
4125 1.1 christos as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line,
4126 1.1 christos _("Adjusted signed .word (%ld) overflows: `switch'-statement too large."),
4127 1.1 christos (long) new_offset);
4128 1.1 christos }
4129 1.1 christos
4130 1.1 christos /* Make a leading REGISTER_PREFIX_CHAR mandatory for all registers. */
4131 1.1 christos
4132 1.1 christos static void
4133 1.1 christos cris_force_reg_prefix (void)
4134 1.1 christos {
4135 1.8 christos demand_register_prefix = true;
4136 1.1 christos }
4137 1.1 christos
4138 1.1 christos /* Do not demand a leading REGISTER_PREFIX_CHAR for all registers. */
4139 1.1 christos
4140 1.1 christos static void
4141 1.1 christos cris_relax_reg_prefix (void)
4142 1.1 christos {
4143 1.8 christos demand_register_prefix = false;
4144 1.1 christos }
4145 1.1 christos
4146 1.1 christos /* Adjust for having a leading '_' on all user symbols. */
4147 1.1 christos
4148 1.1 christos static void
4149 1.1 christos cris_sym_leading_underscore (void)
4150 1.1 christos {
4151 1.1 christos /* We can't really do anything more than assert that what the program
4152 1.1 christos thinks symbol starts with agrees with the command-line options, since
4153 1.1 christos the bfd is already created. */
4154 1.1 christos
4155 1.1 christos if (!symbols_have_leading_underscore)
4156 1.1 christos as_bad (_(".syntax %s requires command-line option `--underscore'"),
4157 1.1 christos SYNTAX_USER_SYM_LEADING_UNDERSCORE);
4158 1.1 christos }
4159 1.1 christos
4160 1.1 christos /* Adjust for not having any particular prefix on user symbols. */
4161 1.1 christos
4162 1.1 christos static void cris_sym_no_leading_underscore (void)
4163 1.1 christos {
4164 1.1 christos if (symbols_have_leading_underscore)
4165 1.1 christos as_bad (_(".syntax %s requires command-line option `--no-underscore'"),
4166 1.1 christos SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE);
4167 1.1 christos }
4168 1.1 christos
4169 1.1 christos /* Handle the .syntax pseudo, which takes an argument that decides what
4170 1.1 christos syntax the assembly code has. */
4171 1.1 christos
4172 1.1 christos static void
4173 1.1 christos s_syntax (int ignore ATTRIBUTE_UNUSED)
4174 1.1 christos {
4175 1.1 christos static const struct syntaxes
4176 1.1 christos {
4177 1.1 christos const char *const operand;
4178 1.1 christos void (*fn) (void);
4179 1.1 christos } syntax_table[] =
4180 1.1 christos {{SYNTAX_ENFORCE_REG_PREFIX, cris_force_reg_prefix},
4181 1.1 christos {SYNTAX_RELAX_REG_PREFIX, cris_relax_reg_prefix},
4182 1.1 christos {SYNTAX_USER_SYM_LEADING_UNDERSCORE, cris_sym_leading_underscore},
4183 1.1 christos {SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE, cris_sym_no_leading_underscore}};
4184 1.1 christos
4185 1.1 christos const struct syntaxes *sp;
4186 1.1 christos
4187 1.1 christos for (sp = syntax_table;
4188 1.1 christos sp < syntax_table + sizeof (syntax_table) / sizeof (syntax_table[0]);
4189 1.1 christos sp++)
4190 1.1 christos {
4191 1.1 christos if (strncmp (input_line_pointer, sp->operand,
4192 1.1 christos strlen (sp->operand)) == 0)
4193 1.1 christos {
4194 1.1 christos (sp->fn) ();
4195 1.1 christos
4196 1.1 christos input_line_pointer += strlen (sp->operand);
4197 1.1 christos demand_empty_rest_of_line ();
4198 1.1 christos return;
4199 1.1 christos }
4200 1.1 christos }
4201 1.1 christos
4202 1.1 christos as_bad (_("Unknown .syntax operand"));
4203 1.1 christos }
4204 1.1 christos
4205 1.1 christos /* Wrapper for dwarf2_directive_file to emit error if this is seen when
4206 1.1 christos not emitting ELF. */
4207 1.1 christos
4208 1.1 christos static void
4209 1.1 christos s_cris_file (int dummy)
4210 1.1 christos {
4211 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
4212 1.1 christos as_bad (_("Pseudodirective .file is only valid when generating ELF"));
4213 1.1 christos else
4214 1.1 christos dwarf2_directive_file (dummy);
4215 1.1 christos }
4216 1.1 christos
4217 1.1 christos /* Wrapper for dwarf2_directive_loc to emit error if this is seen when not
4218 1.1 christos emitting ELF. */
4219 1.1 christos
4220 1.1 christos static void
4221 1.1 christos s_cris_loc (int dummy)
4222 1.1 christos {
4223 1.1 christos if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
4224 1.1 christos as_bad (_("Pseudodirective .loc is only valid when generating ELF"));
4225 1.1 christos else
4226 1.1 christos dwarf2_directive_loc (dummy);
4227 1.1 christos }
4228 1.1 christos
4229 1.1 christos /* Worker for .dtpoffd: generate a R_CRIS_32_DTPREL reloc, as for
4230 1.1 christos expr:DTPREL but for use in debug info. */
4231 1.1 christos
4232 1.1 christos static void
4233 1.1 christos s_cris_dtpoff (int bytes)
4234 1.1 christos {
4235 1.1 christos expressionS ex;
4236 1.1 christos char *p;
4237 1.1 christos
4238 1.1 christos if (bytes != 4)
4239 1.1 christos as_fatal (_("internal inconsistency problem: %s called for %d bytes"),
4240 1.1 christos __FUNCTION__, bytes);
4241 1.1 christos
4242 1.1 christos expression (&ex);
4243 1.1 christos
4244 1.1 christos p = frag_more (bytes);
4245 1.1 christos md_number_to_chars (p, 0, bytes);
4246 1.8 christos fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, false,
4247 1.1 christos BFD_RELOC_CRIS_32_DTPREL);
4248 1.1 christos
4249 1.1 christos demand_empty_rest_of_line ();
4250 1.1 christos }
4251 1.1 christos
4252 1.1 christos
4253 1.1 christos /* Translate a <arch> string (as common to --march=<arch> and .arch <arch>)
4254 1.1 christos into an enum. If the string *STR is recognized, *STR is updated to point
4255 1.1 christos to the end of the string. If the string is not recognized,
4256 1.1 christos arch_cris_unknown is returned. */
4257 1.1 christos
4258 1.1 christos static enum cris_archs
4259 1.5 christos cris_arch_from_string (const char **str)
4260 1.1 christos {
4261 1.1 christos static const struct cris_arch_struct
4262 1.1 christos {
4263 1.1 christos const char *const name;
4264 1.1 christos enum cris_archs arch;
4265 1.1 christos } arch_table[] =
4266 1.1 christos /* Keep in order longest-first for choices where one is a prefix
4267 1.1 christos of another. */
4268 1.1 christos {{"v0_v10", arch_cris_any_v0_v10},
4269 1.1 christos {"v10", arch_crisv10},
4270 1.1 christos {"v32", arch_crisv32},
4271 1.1 christos {"common_v10_v32", arch_cris_common_v10_v32}};
4272 1.1 christos
4273 1.1 christos const struct cris_arch_struct *ap;
4274 1.1 christos
4275 1.1 christos for (ap = arch_table;
4276 1.1 christos ap < arch_table + sizeof (arch_table) / sizeof (arch_table[0]);
4277 1.1 christos ap++)
4278 1.1 christos {
4279 1.1 christos int len = strlen (ap->name);
4280 1.1 christos
4281 1.1 christos if (strncmp (*str, ap->name, len) == 0
4282 1.1 christos && (str[0][len] == 0 || ISSPACE (str[0][len])))
4283 1.1 christos {
4284 1.1 christos *str += strlen (ap->name);
4285 1.1 christos return ap->arch;
4286 1.1 christos }
4287 1.1 christos }
4288 1.1 christos
4289 1.1 christos return arch_cris_unknown;
4290 1.1 christos }
4291 1.1 christos
4292 1.1 christos /* Return nonzero if architecture version ARCH matches version range in
4293 1.1 christos IVER. */
4294 1.1 christos
4295 1.1 christos static int
4296 1.1 christos cris_insn_ver_valid_for_arch (enum cris_insn_version_usage iver,
4297 1.1 christos enum cris_archs arch)
4298 1.1 christos {
4299 1.1 christos switch (arch)
4300 1.1 christos {
4301 1.1 christos case arch_cris_any_v0_v10:
4302 1.1 christos return
4303 1.1 christos (iver == cris_ver_version_all
4304 1.1 christos || iver == cris_ver_warning
4305 1.1 christos || iver == cris_ver_v0_3
4306 1.1 christos || iver == cris_ver_v3p
4307 1.1 christos || iver == cris_ver_v0_10
4308 1.1 christos || iver == cris_ver_sim_v0_10
4309 1.1 christos || iver == cris_ver_v3_10
4310 1.1 christos || iver == cris_ver_v8
4311 1.1 christos || iver == cris_ver_v8p
4312 1.1 christos || iver == cris_ver_v8_10
4313 1.1 christos || iver == cris_ver_v10
4314 1.1 christos || iver == cris_ver_v10p);
4315 1.3 christos
4316 1.1 christos case arch_crisv32:
4317 1.1 christos return
4318 1.1 christos (iver == cris_ver_version_all
4319 1.1 christos || iver == cris_ver_v3p
4320 1.1 christos || iver == cris_ver_v8p
4321 1.1 christos || iver == cris_ver_v10p
4322 1.1 christos || iver == cris_ver_v32p);
4323 1.1 christos
4324 1.1 christos case arch_cris_common_v10_v32:
4325 1.1 christos return
4326 1.1 christos (iver == cris_ver_version_all
4327 1.1 christos || iver == cris_ver_v3p
4328 1.1 christos || iver == cris_ver_v8p
4329 1.1 christos || iver == cris_ver_v10p);
4330 1.1 christos
4331 1.1 christos case arch_crisv0:
4332 1.1 christos return
4333 1.1 christos (iver == cris_ver_version_all
4334 1.1 christos || iver == cris_ver_v0_3
4335 1.1 christos || iver == cris_ver_v0_10
4336 1.1 christos || iver == cris_ver_sim_v0_10);
4337 1.1 christos
4338 1.1 christos case arch_crisv3:
4339 1.1 christos return
4340 1.1 christos (iver == cris_ver_version_all
4341 1.1 christos || iver == cris_ver_v0_3
4342 1.1 christos || iver == cris_ver_v3p
4343 1.1 christos || iver == cris_ver_v0_10
4344 1.1 christos || iver == cris_ver_sim_v0_10
4345 1.1 christos || iver == cris_ver_v3_10);
4346 1.1 christos
4347 1.1 christos case arch_crisv8:
4348 1.1 christos return
4349 1.1 christos (iver == cris_ver_version_all
4350 1.1 christos || iver == cris_ver_v3p
4351 1.1 christos || iver == cris_ver_v0_10
4352 1.1 christos || iver == cris_ver_sim_v0_10
4353 1.1 christos || iver == cris_ver_v3_10
4354 1.1 christos || iver == cris_ver_v8
4355 1.1 christos || iver == cris_ver_v8p
4356 1.1 christos || iver == cris_ver_v8_10);
4357 1.1 christos
4358 1.1 christos case arch_crisv10:
4359 1.1 christos return
4360 1.1 christos (iver == cris_ver_version_all
4361 1.1 christos || iver == cris_ver_v3p
4362 1.1 christos || iver == cris_ver_v0_10
4363 1.1 christos || iver == cris_ver_sim_v0_10
4364 1.1 christos || iver == cris_ver_v3_10
4365 1.1 christos || iver == cris_ver_v8p
4366 1.1 christos || iver == cris_ver_v8_10
4367 1.1 christos || iver == cris_ver_v10
4368 1.1 christos || iver == cris_ver_v10p);
4369 1.1 christos
4370 1.1 christos default:
4371 1.1 christos BAD_CASE (arch);
4372 1.1 christos }
4373 1.1 christos }
4374 1.1 christos
4375 1.1 christos /* Assert that the .arch ARCHCHOICE1 is compatible with the specified or
4376 1.1 christos default --march=<ARCHCHOICE2> option. */
4377 1.1 christos
4378 1.1 christos static void
4379 1.1 christos s_cris_arch (int dummy ATTRIBUTE_UNUSED)
4380 1.1 christos {
4381 1.1 christos /* Right now we take the easy route and check for sameness. It's not
4382 1.1 christos obvious that allowing e.g. --march=v32 and .arch common_v0_v32
4383 1.1 christos would be more useful than confusing, implementation-wise and
4384 1.1 christos user-wise. */
4385 1.1 christos
4386 1.5 christos const char *str = input_line_pointer;
4387 1.1 christos enum cris_archs arch = cris_arch_from_string (&str);
4388 1.1 christos
4389 1.1 christos if (arch == arch_cris_unknown)
4390 1.1 christos {
4391 1.1 christos as_bad (_("unknown operand to .arch"));
4392 1.1 christos
4393 1.1 christos /* For this one, str does not reflect the end of the operand,
4394 1.1 christos since there was no matching arch. Skip it manually; skip
4395 1.1 christos things that can be part of a word (a name). */
4396 1.1 christos while (is_part_of_name (*str))
4397 1.1 christos str++;
4398 1.1 christos }
4399 1.1 christos else if (arch != cris_arch)
4400 1.1 christos as_bad (_(".arch <arch> requires a matching --march=... option"));
4401 1.1 christos
4402 1.5 christos input_line_pointer = (char *) str;
4403 1.1 christos demand_empty_rest_of_line ();
4404 1.1 christos return;
4405 1.1 christos }
4406 1.1 christos
4407 1.1 christos /*
4408 1.1 christos * Local variables:
4409 1.1 christos * eval: (c-set-style "gnu")
4410 1.1 christos * indent-tabs-mode: t
4411 1.1 christos * End:
4412 1.1 christos */
4413