* elf32-ppc.c (LWZU_0_X_11): Delete.
[binutils.git] / gas / config / tc-cris.c
blob04dfe4f526da2d5264bf1ac7c990563d306dff52
1 /* tc-cris.c -- Assembler code for the CRIS CPU core.
2 Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Axis Communications AB, Lund, Sweden.
5 Originally written for GAS 1.38.1 by Mikael Asker.
6 Updates, BFDizing, GNUifying and ELF support by Hans-Peter Nilsson.
8 This file is part of GAS, the GNU Assembler.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to the
22 Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
25 #include <stdio.h>
26 #include "as.h"
27 #include "safe-ctype.h"
28 #include "subsegs.h"
29 #include "opcode/cris.h"
30 #include "dwarf2dbg.h"
32 /* Conventions used here:
33 Generally speaking, pointers to binutils types such as "fragS" and
34 "expressionS" get parameter and variable names ending in "P", such as
35 "fragP", to harmonize with the rest of the binutils code. Other
36 pointers get a "p" suffix, such as "bufp". Any function or type-name
37 that could clash with a current or future binutils or GAS function get
38 a "cris_" prefix. */
40 #define SYNTAX_RELAX_REG_PREFIX "no_register_prefix"
41 #define SYNTAX_ENFORCE_REG_PREFIX "register_prefix"
42 #define SYNTAX_USER_SYM_LEADING_UNDERSCORE "leading_underscore"
43 #define SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE "no_leading_underscore"
44 #define REGISTER_PREFIX_CHAR '$'
46 /* True for expressions where getting X_add_symbol and X_add_number is
47 enough to get the "base" and "offset"; no need to make_expr_symbol.
48 It's not enough to check if X_op_symbol is NULL; that misses unary
49 operations like O_uminus. */
50 #define SIMPLE_EXPR(EXP) \
51 ((EXP)->X_op == O_constant || (EXP)->X_op == O_symbol)
53 /* Like in ":GOT", ":GOTOFF" etc. Other ports use '@', but that's in
54 line_separator_chars for CRIS, so we avoid it. */
55 #define PIC_SUFFIX_CHAR ':'
57 /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
58 Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL. */
59 enum cris_insn_kind
61 CRIS_INSN_NORMAL, CRIS_INSN_NONE, CRIS_INSN_BRANCH, CRIS_INSN_MUL
64 /* An instruction will have one of these prefixes.
65 Although the same bit-pattern, we handle BDAP with an immediate
66 expression (eventually quick or [pc+]) different from when we only have
67 register expressions. */
68 enum prefix_kind
70 PREFIX_NONE, PREFIX_BDAP_IMM, PREFIX_BDAP, PREFIX_BIAP, PREFIX_DIP,
71 PREFIX_PUSH
74 /* The prefix for an instruction. */
75 struct cris_prefix
77 enum prefix_kind kind;
78 int base_reg_number;
79 unsigned int opcode;
81 /* There might be an expression to be evaluated, like I in [rN+I]. */
82 expressionS expr;
84 /* If there's an expression, we might need a relocation. Here's the
85 type of what relocation to start relaxaton with.
86 The relocation is assumed to start immediately after the prefix insn,
87 so we don't provide an offset. */
88 enum bfd_reloc_code_real reloc;
91 /* The description of the instruction being assembled. */
92 struct cris_instruction
94 /* If CRIS_INSN_NONE, then this insn is of zero length. */
95 enum cris_insn_kind insn_type;
97 /* If a special register was mentioned, this is its description, else
98 it is NULL. */
99 const struct cris_spec_reg *spec_reg;
101 unsigned int opcode;
103 /* An insn may have at most one expression; theoretically there could be
104 another in its prefix (but I don't see how that could happen). */
105 expressionS expr;
107 /* The expression might need a relocation. Here's one to start
108 relaxation with. */
109 enum bfd_reloc_code_real reloc;
111 /* The size in bytes of an immediate expression, or zero if
112 nonapplicable. */
113 int imm_oprnd_size;
116 enum cris_archs
118 arch_cris_unknown,
119 arch_crisv0, arch_crisv3, arch_crisv8, arch_crisv10,
120 arch_cris_any_v0_v10, arch_crisv32, arch_cris_common_v10_v32
123 static enum cris_archs cris_arch_from_string (char **);
124 static int cris_insn_ver_valid_for_arch (enum cris_insn_version_usage,
125 enum cris_archs);
127 static void cris_process_instruction (char *, struct cris_instruction *,
128 struct cris_prefix *);
129 static int get_bwd_size_modifier (char **, int *);
130 static int get_bw_size_modifier (char **, int *);
131 static int get_gen_reg (char **, int *);
132 static int get_spec_reg (char **, const struct cris_spec_reg **);
133 static int get_sup_reg (char **, int *);
134 static int get_autoinc_prefix_or_indir_op (char **, struct cris_prefix *,
135 int *, int *, int *,
136 expressionS *);
137 static int get_3op_or_dip_prefix_op (char **, struct cris_prefix *);
138 static int cris_get_expression (char **, expressionS *);
139 static int get_flags (char **, int *);
140 static void gen_bdap (int, expressionS *);
141 static int branch_disp (int);
142 static void gen_cond_branch_32 (char *, char *, fragS *, symbolS *, symbolS *,
143 long int);
144 static void cris_number_to_imm (char *, long, int, fixS *, segT);
145 static void cris_create_short_jump (char *, addressT, addressT, fragS *,
146 symbolS *);
147 static void s_syntax (int);
148 static void s_cris_file (int);
149 static void s_cris_loc (int);
150 static void s_cris_arch (int);
152 /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes. */
153 static void cris_get_pic_suffix (char **, bfd_reloc_code_real_type *,
154 expressionS *);
155 static unsigned int cris_get_pic_reloc_size (bfd_reloc_code_real_type);
157 /* All the .syntax functions. */
158 static void cris_force_reg_prefix (void);
159 static void cris_relax_reg_prefix (void);
160 static void cris_sym_leading_underscore (void);
161 static void cris_sym_no_leading_underscore (void);
162 static char *cris_insn_first_word_frag (void);
164 /* Handle to the opcode hash table. */
165 static struct hash_control *op_hash = NULL;
167 /* If we target cris-axis-linux-gnu (as opposed to generic cris-axis-elf),
168 we default to no underscore and required register-prefixes. The
169 difference is in the default values. */
170 #ifdef TE_LINUX
171 #define DEFAULT_CRIS_AXIS_LINUX_GNU TRUE
172 #else
173 #define DEFAULT_CRIS_AXIS_LINUX_GNU FALSE
174 #endif
176 /* Whether we demand that registers have a `$' prefix. Default here. */
177 static bfd_boolean demand_register_prefix = DEFAULT_CRIS_AXIS_LINUX_GNU;
179 /* Whether global user symbols have a leading underscore. Default here. */
180 static bfd_boolean symbols_have_leading_underscore
181 = !DEFAULT_CRIS_AXIS_LINUX_GNU;
183 /* Whether or not we allow PIC, and expand to PIC-friendly constructs. */
184 static bfd_boolean pic = FALSE;
186 /* If we're configured for "cris", default to allow all v0..v10
187 instructions and register names. */
188 #ifndef DEFAULT_CRIS_ARCH
189 #define DEFAULT_CRIS_ARCH cris_any_v0_v10
190 #endif
192 /* No whitespace in the CONCAT2 parameter list. */
193 static enum cris_archs cris_arch = XCONCAT2 (arch_,DEFAULT_CRIS_ARCH);
195 const pseudo_typeS md_pseudo_table[] =
197 {"dword", cons, 4},
198 {"syntax", s_syntax, 0},
199 {"file", s_cris_file, 0},
200 {"loc", s_cris_loc, 0},
201 {"arch", s_cris_arch, 0},
202 {NULL, 0, 0}
205 static int warn_for_branch_expansion = 0;
207 /* Whether to emit error when a MULS/MULU could be located last on a
208 cache-line. */
209 static int err_for_dangerous_mul_placement
210 = (XCONCAT2 (arch_,DEFAULT_CRIS_ARCH) != arch_crisv32);
212 const char cris_comment_chars[] = ";";
214 /* This array holds the chars that only start a comment at the beginning of
215 a line. If the line seems to have the form '# 123 filename'
216 .line and .file directives will appear in the pre-processed output. */
217 /* Note that input_file.c hand-checks for '#' at the beginning of the
218 first line of the input file. This is because the compiler outputs
219 #NO_APP at the beginning of its output. */
220 /* Also note that slash-star will always start a comment. */
221 const char line_comment_chars[] = "#";
222 const char line_separator_chars[] = "@";
224 /* Now all floating point support is shut off. See md_atof. */
225 const char EXP_CHARS[] = "";
226 const char FLT_CHARS[] = "";
228 /* For CRIS, we encode the relax_substateTs (in e.g. fr_substate) as:
229 2 1 0
230 ---/ /--+-----------------+-----------------+-----------------+
231 | what state ? | how long ? |
232 ---/ /--+-----------------+-----------------+-----------------+
234 The "how long" bits are 00 = byte, 01 = word, 10 = dword (long).
235 Not all lengths are legit for a given value of (what state).
237 Groups for CRIS address relaxing:
239 1. Bcc (pre-V32)
240 length: byte, word, 10-byte expansion
242 2. BDAP
243 length: byte, word, dword
245 3. MULS/MULU
246 Not really a relaxation (no infrastructure to get delay-slots
247 right), just an alignment and placement checker for the v10
248 multiply/cache-bug.
250 4. Bcc (V32 and later)
251 length: byte, word, 14-byte expansion
253 5. Bcc (V10+V32)
254 length: byte, word, error
256 6. BA (V32)
257 length: byte, word, dword
259 7. LAPC (V32)
260 length: byte, dword
263 #define STATE_COND_BRANCH (1)
264 #define STATE_BASE_PLUS_DISP_PREFIX (2)
265 #define STATE_MUL (3)
266 #define STATE_COND_BRANCH_V32 (4)
267 #define STATE_COND_BRANCH_COMMON (5)
268 #define STATE_ABS_BRANCH_V32 (6)
269 #define STATE_LAPC (7)
271 #define STATE_LENGTH_MASK (3)
272 #define STATE_BYTE (0)
273 #define STATE_WORD (1)
274 #define STATE_DWORD (2)
275 /* Symbol undefined. */
276 #define STATE_UNDF (3)
277 #define STATE_MAX_LENGTH (3)
279 /* These displacements are relative to the address following the opcode
280 word of the instruction. The first letter is Byte, Word. The 2nd
281 letter is Forward, Backward. */
283 #define BRANCH_BF ( 254)
284 #define BRANCH_BB (-256)
285 #define BRANCH_BF_V32 ( 252)
286 #define BRANCH_BB_V32 (-258)
287 #define BRANCH_WF (2 + 32767)
288 #define BRANCH_WB (2 + -32768)
289 #define BRANCH_WF_V32 (-2 + 32767)
290 #define BRANCH_WB_V32 (-2 + -32768)
292 #define BDAP_BF ( 127)
293 #define BDAP_BB (-128)
294 #define BDAP_WF ( 32767)
295 #define BDAP_WB (-32768)
297 #define ENCODE_RELAX(what, length) (((what) << 2) + (length))
299 const relax_typeS md_cris_relax_table[] =
301 /* Error sentinel (0, 0). */
302 {1, 1, 0, 0},
304 /* Unused (0, 1). */
305 {1, 1, 0, 0},
307 /* Unused (0, 2). */
308 {1, 1, 0, 0},
310 /* Unused (0, 3). */
311 {1, 1, 0, 0},
313 /* Bcc o (1, 0). */
314 {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (1, 1)},
316 /* Bcc [PC+] (1, 1). */
317 {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (1, 2)},
319 /* BEXT/BWF, BA, JUMP (external), JUMP (always), Bnot_cc, JUMP (default)
320 (1, 2). */
321 {0, 0, 10, 0},
323 /* Unused (1, 3). */
324 {1, 1, 0, 0},
326 /* BDAP o (2, 0). */
327 {BDAP_BF, BDAP_BB, 0, ENCODE_RELAX (2, 1)},
329 /* BDAP.[bw] [PC+] (2, 1). */
330 {BDAP_WF, BDAP_WB, 2, ENCODE_RELAX (2, 2)},
332 /* BDAP.d [PC+] (2, 2). */
333 {0, 0, 4, 0},
335 /* Unused (2, 3). */
336 {1, 1, 0, 0},
338 /* MULS/MULU (3, 0). Positions (3, 1..3) are unused. */
339 {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
341 /* V32: Bcc o (4, 0). */
342 {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (4, 1)},
344 /* V32: Bcc [PC+] (4, 1). */
345 {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (4, 2)},
347 /* V32: BA .+12; NOP; BA32 target; NOP; Bcc .-6 (4, 2). */
348 {0, 0, 12, 0},
350 /* Unused (4, 3). */
351 {1, 1, 0, 0},
353 /* COMMON: Bcc o (5, 0). The offsets are calculated as for v32. Code
354 should contain two nop insns (or four if offset size is large or
355 unknown) after every label. */
356 {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (5, 1)},
358 /* COMMON: Bcc [PC+] (5, 1). */
359 {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (5, 2)},
361 /* COMMON: FIXME: ???. Treat as error currently. */
362 {0, 0, 12, 0},
364 /* Unused (5, 3). */
365 {1, 1, 0, 0},
367 /* V32: BA o (6, 0). */
368 {BRANCH_BF_V32, BRANCH_BB_V32, 0, ENCODE_RELAX (6, 1)},
370 /* V32: BA.W (6, 1). */
371 {BRANCH_WF_V32, BRANCH_WB_V32, 2, ENCODE_RELAX (6, 2)},
373 /* V32: BA.D (6, 2). */
374 {0, 0, 4, 0},
376 /* Unused (6, 3). */
377 {1, 1, 0, 0},
379 /* LAPC: LAPCQ .+0..15*2,Rn (7, 0). */
380 {14*2, -1*2, 0, ENCODE_RELAX (7, 2)},
382 /* Unused (7, 1).
383 While there's a shorter sequence, e.g. LAPCQ + an ADDQ or SUBQ,
384 that would affect flags, so we can't do that as it wouldn't be a
385 proper insn expansion of LAPCQ. This row is associated with a
386 2-byte expansion, so it's unused rather than the next. */
387 {1, 1, 0, 0},
389 /* LAPC: LAPC.D (7, 2). */
390 {0, 0, 4, 0},
392 /* Unused (7, 3). */
393 {1, 1, 0, 0}
396 #undef BDAP_BF
397 #undef BDAP_BB
398 #undef BDAP_WF
399 #undef BDAP_WB
401 /* Target-specific multicharacter options, not const-declared. */
402 struct option md_longopts[] =
404 #define OPTION_NO_US (OPTION_MD_BASE + 0)
405 {"no-underscore", no_argument, NULL, OPTION_NO_US},
406 #define OPTION_US (OPTION_MD_BASE + 1)
407 {"underscore", no_argument, NULL, OPTION_US},
408 #define OPTION_PIC (OPTION_US + 1)
409 {"pic", no_argument, NULL, OPTION_PIC},
410 #define OPTION_MULBUG_ABORT_ON (OPTION_PIC + 1)
411 {"mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_ON},
412 #define OPTION_MULBUG_ABORT_OFF (OPTION_MULBUG_ABORT_ON + 1)
413 {"no-mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_OFF},
414 #define OPTION_ARCH (OPTION_MULBUG_ABORT_OFF + 1)
415 {"march", required_argument, NULL, OPTION_ARCH},
416 {NULL, no_argument, NULL, 0}
419 /* Not const-declared. */
420 size_t md_longopts_size = sizeof (md_longopts);
421 const char *md_shortopts = "hHN";
423 /* At first glance, this may seems wrong and should be 4 (ba + nop); but
424 since a short_jump must skip a *number* of long jumps, it must also be
425 a long jump. Here, we hope to make it a "ba [16bit_offs]" and a "nop"
426 for the delay slot and hope that the jump table at most needs
427 32767/4=8191 long-jumps. A branch is better than a jump, since it is
428 relative; we will not have a reloc to fix up somewhere.
430 Note that we can't add relocs, because relaxation uses these fixed
431 numbers, and md_create_short_jump is called after relaxation. */
433 int md_short_jump_size = 6;
435 /* The v32 version has a delay-slot, hence two bytes longer. */
436 #define cris_any_v0_v10_long_jump_size 6
437 #define crisv32_long_jump_size 8
439 int md_long_jump_size = XCONCAT2 (DEFAULT_CRIS_ARCH,_long_jump_size);
441 /* Report output format. Small changes in output format (like elf
442 variants below) can happen until all options are parsed, but after
443 that, the output format must remain fixed. */
445 const char *
446 cris_target_format (void)
448 switch (OUTPUT_FLAVOR)
450 case bfd_target_aout_flavour:
451 return "a.out-cris";
453 case bfd_target_elf_flavour:
454 if (symbols_have_leading_underscore)
455 return "elf32-us-cris";
456 return "elf32-cris";
458 default:
459 abort ();
460 return NULL;
464 /* Return a bfd_mach_cris... value corresponding to the value of
465 cris_arch. */
467 unsigned int
468 cris_mach (void)
470 unsigned int retval = 0;
472 switch (cris_arch)
474 case arch_cris_common_v10_v32:
475 retval = bfd_mach_cris_v10_v32;
476 break;
478 case arch_crisv32:
479 retval = bfd_mach_cris_v32;
480 break;
482 case arch_crisv10:
483 case arch_cris_any_v0_v10:
484 retval = bfd_mach_cris_v0_v10;
485 break;
487 default:
488 BAD_CASE (cris_arch);
491 return retval;
494 /* We need a port-specific relaxation function to cope with sym2 - sym1
495 relative expressions with both symbols in the same segment (but not
496 necessarily in the same frag as this insn), for example:
497 move.d [pc+sym2-(sym1-2)],r10
498 sym1:
499 The offset can be 8, 16 or 32 bits long. */
501 long
502 cris_relax_frag (segT seg ATTRIBUTE_UNUSED, fragS *fragP,
503 long stretch ATTRIBUTE_UNUSED)
505 long growth;
506 offsetT aim = 0;
507 symbolS *symbolP;
508 const relax_typeS *this_type;
509 const relax_typeS *start_type;
510 relax_substateT next_state;
511 relax_substateT this_state;
512 const relax_typeS *table = TC_GENERIC_RELAX_TABLE;
514 /* We only have to cope with frags as prepared by
515 md_estimate_size_before_relax. The dword cases may get here
516 because of the different reasons that they aren't relaxable. */
517 switch (fragP->fr_subtype)
519 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
520 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
521 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
522 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD):
523 case ENCODE_RELAX (STATE_LAPC, STATE_DWORD):
524 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
525 /* When we get to these states, the frag won't grow any more. */
526 return 0;
528 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
529 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
530 if (fragP->fr_symbol == NULL
531 || S_GET_SEGMENT (fragP->fr_symbol) != absolute_section)
532 as_fatal (_("internal inconsistency problem in %s: fr_symbol %lx"),
533 __FUNCTION__, (long) fragP->fr_symbol);
534 symbolP = fragP->fr_symbol;
535 if (symbol_resolved_p (symbolP))
536 as_fatal (_("internal inconsistency problem in %s: resolved symbol"),
537 __FUNCTION__);
538 aim = S_GET_VALUE (symbolP);
539 break;
541 case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
542 /* Nothing to do here. */
543 return 0;
545 default:
546 as_fatal (_("internal inconsistency problem in %s: fr_subtype %d"),
547 __FUNCTION__, fragP->fr_subtype);
550 /* The rest is stolen from relax_frag. There's no obvious way to
551 share the code, but fortunately no requirement to keep in sync as
552 long as fragP->fr_symbol does not have its segment changed. */
554 this_state = fragP->fr_subtype;
555 start_type = this_type = table + this_state;
557 if (aim < 0)
559 /* Look backwards. */
560 for (next_state = this_type->rlx_more; next_state;)
561 if (aim >= this_type->rlx_backward)
562 next_state = 0;
563 else
565 /* Grow to next state. */
566 this_state = next_state;
567 this_type = table + this_state;
568 next_state = this_type->rlx_more;
571 else
573 /* Look forwards. */
574 for (next_state = this_type->rlx_more; next_state;)
575 if (aim <= this_type->rlx_forward)
576 next_state = 0;
577 else
579 /* Grow to next state. */
580 this_state = next_state;
581 this_type = table + this_state;
582 next_state = this_type->rlx_more;
586 growth = this_type->rlx_length - start_type->rlx_length;
587 if (growth != 0)
588 fragP->fr_subtype = this_state;
589 return growth;
592 /* Prepare machine-dependent frags for relaxation.
594 Called just before relaxation starts. Any symbol that is now undefined
595 will not become defined.
597 Return the correct fr_subtype in the frag.
599 Return the initial "guess for fr_var" to caller. The guess for fr_var
600 is *actually* the growth beyond fr_fix. Whatever we do to grow fr_fix
601 or fr_var contributes to our returned value.
603 Although it may not be explicit in the frag, pretend
604 fr_var starts with a value. */
607 md_estimate_size_before_relax (fragS *fragP, segT segment_type)
609 int old_fr_fix;
610 symbolS *symbolP = fragP->fr_symbol;
612 #define HANDLE_RELAXABLE(state) \
613 case ENCODE_RELAX (state, STATE_UNDF): \
614 if (symbolP != NULL \
615 && S_GET_SEGMENT (symbolP) == segment_type \
616 && !S_IS_WEAK (symbolP)) \
617 /* The symbol lies in the same segment - a relaxable \
618 case. */ \
619 fragP->fr_subtype \
620 = ENCODE_RELAX (state, STATE_BYTE); \
621 else \
622 /* Unknown or not the same segment, so not relaxable. */ \
623 fragP->fr_subtype \
624 = ENCODE_RELAX (state, STATE_DWORD); \
625 fragP->fr_var \
626 = md_cris_relax_table[fragP->fr_subtype].rlx_length; \
627 break
629 old_fr_fix = fragP->fr_fix;
631 switch (fragP->fr_subtype)
633 HANDLE_RELAXABLE (STATE_COND_BRANCH);
634 HANDLE_RELAXABLE (STATE_COND_BRANCH_V32);
635 HANDLE_RELAXABLE (STATE_COND_BRANCH_COMMON);
636 HANDLE_RELAXABLE (STATE_ABS_BRANCH_V32);
638 case ENCODE_RELAX (STATE_LAPC, STATE_UNDF):
639 if (symbolP != NULL
640 && S_GET_SEGMENT (symbolP) == segment_type
641 && !S_IS_WEAK (symbolP))
643 /* The symbol lies in the same segment - a relaxable case.
644 Check if we currently have an odd offset; we can't code
645 that into the instruction. Relaxing presumably only cause
646 multiple-of-two changes, so we should only need to adjust
647 for that here. */
648 bfd_vma target_address
649 = (symbolP
650 ? S_GET_VALUE (symbolP)
651 : 0) + fragP->fr_offset;
652 bfd_vma var_part_offset = fragP->fr_fix;
653 bfd_vma address_of_var_part = fragP->fr_address + var_part_offset;
654 long offset = target_address - (address_of_var_part - 2);
656 fragP->fr_subtype
657 = (offset & 1)
658 ? ENCODE_RELAX (STATE_LAPC, STATE_DWORD)
659 : ENCODE_RELAX (STATE_LAPC, STATE_BYTE);
661 else
662 /* Unknown or not the same segment, so not relaxable. */
663 fragP->fr_subtype
664 = ENCODE_RELAX (STATE_LAPC, STATE_DWORD);
665 fragP->fr_var
666 = md_cris_relax_table[fragP->fr_subtype].rlx_length;
667 break;
669 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF):
670 /* Note that we can not do anything sane with relaxing
671 [rX + a_known_symbol_in_text], it will have to be a 32-bit
672 value.
674 We could play tricks with managing a constant pool and make
675 a_known_symbol_in_text a "bdap [pc + offset]" pointing there
676 (like the GOT for ELF shared libraries), but that's no use, it
677 would in general be no shorter or faster code, only more
678 complicated. */
680 if (S_GET_SEGMENT (symbolP) != absolute_section)
682 /* Go for dword if not absolute or same segment. */
683 fragP->fr_subtype
684 = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD);
685 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
687 else if (!symbol_resolved_p (fragP->fr_symbol))
689 /* The symbol will eventually be completely resolved as an
690 absolute expression, but right now it depends on the result
691 of relaxation and we don't know anything else about the
692 value. We start relaxation with the assumption that it'll
693 fit in a byte. */
694 fragP->fr_subtype
695 = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE);
696 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
698 else
700 /* Absolute expression. */
701 long int value;
702 value = (symbolP != NULL
703 ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset;
705 if (value >= -128 && value <= 127)
707 /* Byte displacement. */
708 (fragP->fr_opcode)[0] = value;
710 else
712 /* Word or dword displacement. */
713 int pow2_of_size = 1;
714 char *writep;
716 if (value < -32768 || value > 32767)
718 /* Outside word range, make it a dword. */
719 pow2_of_size = 2;
722 /* Modify the byte-offset BDAP into a word or dword offset
723 BDAP. Or really, a BDAP rX,8bit into a
724 BDAP.[wd] rX,[PC+] followed by a word or dword. */
725 (fragP->fr_opcode)[0] = BDAP_PC_LOW + pow2_of_size * 16;
727 /* Keep the register number in the highest four bits. */
728 (fragP->fr_opcode)[1] &= 0xF0;
729 (fragP->fr_opcode)[1] |= BDAP_INCR_HIGH;
731 /* It grew by two or four bytes. */
732 fragP->fr_fix += 1 << pow2_of_size;
733 writep = fragP->fr_literal + old_fr_fix;
734 md_number_to_chars (writep, value, 1 << pow2_of_size);
736 frag_wane (fragP);
738 break;
740 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_BYTE):
741 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_WORD):
742 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
743 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_BYTE):
744 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_WORD):
745 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
746 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_BYTE):
747 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_WORD):
748 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
749 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_BYTE):
750 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_WORD):
751 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD):
752 case ENCODE_RELAX (STATE_LAPC, STATE_BYTE):
753 case ENCODE_RELAX (STATE_LAPC, STATE_DWORD):
754 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
755 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
756 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
757 /* When relaxing a section for the second time, we don't need to
758 do anything except making sure that fr_var is set right. */
759 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
760 break;
762 case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
763 /* Nothing to do here. */
764 break;
766 default:
767 BAD_CASE (fragP->fr_subtype);
770 return fragP->fr_var + (fragP->fr_fix - old_fr_fix);
773 /* Perform post-processing of machine-dependent frags after relaxation.
774 Called after relaxation is finished.
775 In: Address of frag.
776 fr_type == rs_machine_dependent.
777 fr_subtype is what the address relaxed to.
779 Out: Any fixS:s and constants are set up.
781 The caller will turn the frag into a ".space 0". */
783 void
784 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
785 fragS *fragP)
787 /* Pointer to first byte in variable-sized part of the frag. */
788 char *var_partp;
790 /* Pointer to first opcode byte in frag. */
791 char *opcodep;
793 /* Used to check integrity of the relaxation.
794 One of 2 = long, 1 = word, or 0 = byte. */
795 int length_code;
797 /* Size in bytes of variable-sized part of frag. */
798 int var_part_size = 0;
800 /* This is part of *fragP. It contains all information about addresses
801 and offsets to varying parts. */
802 symbolS *symbolP;
803 unsigned long var_part_offset;
805 /* Where, in file space, is _var of *fragP? */
806 unsigned long address_of_var_part = 0;
808 /* Where, in file space, does addr point? */
809 unsigned long target_address;
811 know (fragP->fr_type == rs_machine_dependent);
813 length_code = fragP->fr_subtype & STATE_LENGTH_MASK;
814 know (length_code >= 0 && length_code < STATE_MAX_LENGTH);
816 var_part_offset = fragP->fr_fix;
817 var_partp = fragP->fr_literal + var_part_offset;
818 opcodep = fragP->fr_opcode;
820 symbolP = fragP->fr_symbol;
821 target_address = (symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset;
822 address_of_var_part = fragP->fr_address + var_part_offset;
824 switch (fragP->fr_subtype)
826 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_BYTE):
827 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_BYTE):
828 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_BYTE):
829 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_BYTE):
830 opcodep[0] = branch_disp ((target_address - address_of_var_part));
831 var_part_size = 0;
832 break;
834 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_WORD):
835 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_WORD):
836 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_WORD):
837 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_WORD):
838 /* We had a quick immediate branch, now turn it into a word one i.e. a
839 PC autoincrement. */
840 opcodep[0] = BRANCH_PC_LOW;
841 opcodep[1] &= 0xF0;
842 opcodep[1] |= BRANCH_INCR_HIGH;
843 md_number_to_chars (var_partp,
844 (long)
845 (target_address
846 - (address_of_var_part
847 + (cris_arch == arch_crisv32
848 || cris_arch == arch_cris_common_v10_v32
849 ? -2 : 2))),
851 var_part_size = 2;
852 break;
854 case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
855 gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
856 fragP->fr_symbol, (symbolS *) NULL,
857 fragP->fr_offset);
858 /* Ten bytes added: a branch, nop and a jump. */
859 var_part_size = 2 + 2 + 4 + 2;
860 break;
862 case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
863 gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
864 fragP->fr_symbol, (symbolS *) NULL,
865 fragP->fr_offset);
866 /* Twelve bytes added: a branch, nop and another branch and nop. */
867 var_part_size = 2 + 2 + 2 + 4 + 2;
868 break;
870 case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
871 as_bad_where (fragP->fr_file, fragP->fr_line,
872 _("Relaxation to long branches for .arch common_v10_v32\
873 not implemented"));
874 /* Pretend we have twelve bytes for sake of quelling further
875 errors. */
876 var_part_size = 2 + 2 + 2 + 4 + 2;
877 break;
879 case ENCODE_RELAX (STATE_ABS_BRANCH_V32, STATE_DWORD):
880 /* We had a quick immediate branch or a word immediate ba. Now
881 turn it into a dword one. */
882 opcodep[0] = BA_DWORD_OPCODE & 255;
883 opcodep[1] = (BA_DWORD_OPCODE >> 8) & 255;
884 fix_new (fragP, var_partp - fragP->fr_literal, 4, symbolP,
885 fragP->fr_offset + 6, 1, BFD_RELOC_32_PCREL);
886 var_part_size = 4;
887 break;
889 case ENCODE_RELAX (STATE_LAPC, STATE_BYTE):
891 long offset = target_address - (address_of_var_part - 2);
893 /* This is mostly a sanity check; useful occurrences (if there
894 really are any) should have been caught in
895 md_estimate_size_before_relax. We can (at least
896 theoretically) stumble over invalid code with odd sizes and
897 .p2aligns within the code, so emit an error if that happens.
898 (The generic relaxation machinery is not fit to check this.) */
900 if (offset & 1)
901 as_bad_where (fragP->fr_file, fragP->fr_line,
902 _("Complicated LAPC target operand is not\
903 a multiple of two. Use LAPC.D"));
905 /* FIXME: This *is* a sanity check. Remove when done with. */
906 if (offset > 15*2 || offset < 0)
907 as_fatal (_("Internal error found in md_convert_frag: offset %ld.\
908 Please report this."),
909 offset);
911 opcodep[0] |= (offset / 2) & 0xf;
912 var_part_size = 0;
914 break;
916 case ENCODE_RELAX (STATE_LAPC, STATE_DWORD):
918 md_number_to_chars (opcodep,
919 LAPC_DWORD_OPCODE + (opcodep[1] & 0xf0) * 256,
921 /* Remember that the reloc is against the position *after* the
922 relocated contents, so we need to adjust to the start of
923 the insn. */
924 fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol,
925 fragP->fr_offset + 6, 1, BFD_RELOC_32_PCREL);
926 var_part_size = 4;
928 break;
930 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
931 if (symbolP == NULL)
932 as_fatal (_("internal inconsistency in %s: bdapq no symbol"),
933 __FUNCTION__);
934 opcodep[0] = S_GET_VALUE (symbolP);
935 var_part_size = 0;
936 break;
938 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
939 /* We had a BDAP 8-bit "quick immediate", now turn it into a 16-bit
940 one that uses PC autoincrement. */
941 opcodep[0] = BDAP_PC_LOW + (1 << 4);
942 opcodep[1] &= 0xF0;
943 opcodep[1] |= BDAP_INCR_HIGH;
944 if (symbolP == NULL)
945 as_fatal (_("internal inconsistency in %s: bdap.w with no symbol"),
946 __FUNCTION__);
947 md_number_to_chars (var_partp, S_GET_VALUE (symbolP), 2);
948 var_part_size = 2;
949 break;
951 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
952 /* We had a BDAP 16-bit "word", change the offset to a dword. */
953 opcodep[0] = BDAP_PC_LOW + (2 << 4);
954 opcodep[1] &= 0xF0;
955 opcodep[1] |= BDAP_INCR_HIGH;
956 if (fragP->fr_symbol == NULL)
957 md_number_to_chars (var_partp, fragP->fr_offset, 4);
958 else
959 fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol,
960 fragP->fr_offset, 0, BFD_RELOC_32);
961 var_part_size = 4;
962 break;
964 case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
965 /* This is the only time we check position and aligmnent of the
966 placement-tracking frag. */
967 if (sec->alignment_power < 2)
968 as_bad_where (fragP->fr_file, fragP->fr_line,
969 _("section alignment must be >= 4 bytes to check MULS/MULU safeness"));
970 else
972 /* If the address after the MULS/MULU has alignment which is
973 that of the section and may be that of a cache-size of the
974 buggy versions, then the MULS/MULU can be placed badly. */
975 if ((address_of_var_part
976 & ((1 << sec->alignment_power) - 1) & 31) == 0)
977 as_bad_where (fragP->fr_file, fragP->fr_line,
978 _("dangerous MULS/MULU location; give it higher alignment"));
980 break;
982 default:
983 BAD_CASE (fragP->fr_subtype);
984 break;
987 fragP->fr_fix += var_part_size;
990 /* Generate a short jump around a secondary jump table.
991 Used by md_create_long_jump.
993 This used to be md_create_short_jump, but is now called from
994 md_create_long_jump instead, when sufficient, since the sizes of the
995 jumps are the same for pre-v32. */
997 static void
998 cris_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
999 fragS *fragP ATTRIBUTE_UNUSED,
1000 symbolS *to_symbol ATTRIBUTE_UNUSED)
1002 long int distance;
1004 /* See md_create_long_jump about the comment on the "+ 2". */
1005 long int max_minimal_minus_distance;
1006 long int max_minimal_plus_distance;
1007 int nop_opcode;
1009 if (cris_arch == arch_crisv32)
1011 max_minimal_minus_distance = BRANCH_BB_V32 + 2;
1012 max_minimal_plus_distance = BRANCH_BF_V32 + 2;
1013 nop_opcode = NOP_OPCODE_V32;
1015 else
1017 max_minimal_minus_distance = BRANCH_BB + 2;
1018 max_minimal_plus_distance = BRANCH_BF + 2;
1019 nop_opcode = NOP_OPCODE;
1022 distance = to_addr - from_addr;
1024 if (max_minimal_minus_distance <= distance
1025 && distance <= max_minimal_plus_distance)
1027 /* Create a "short" short jump: "BA distance - 2". */
1028 storep[0] = branch_disp (distance - 2);
1029 storep[1] = BA_QUICK_HIGH;
1031 /* A nop for the delay slot. */
1032 md_number_to_chars (storep + 2, nop_opcode, 2);
1034 /* The extra word should be filled with something sane too. Make it
1035 a nop to keep disassembly sane. */
1036 md_number_to_chars (storep + 4, nop_opcode, 2);
1038 else
1040 /* Make it a "long" short jump: "BA (PC+)". */
1041 md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2);
1043 /* ".WORD distance - 4". */
1044 md_number_to_chars (storep + 2,
1045 (long) (distance - 4
1046 - (cris_arch == arch_crisv32
1047 ? -4 : 0)),
1050 /* A nop for the delay slot. */
1051 md_number_to_chars (storep + 4, nop_opcode, 2);
1055 /* Generate a long jump in a secondary jump table.
1057 storep Where to store the jump instruction.
1058 from_addr Address of the jump instruction.
1059 to_addr Destination address of the jump.
1060 fragP Which frag the destination address operand
1061 lies in.
1062 to_symbol Destination symbol. */
1064 void
1065 md_create_long_jump (char *storep, addressT from_addr, addressT to_addr,
1066 fragS *fragP, symbolS *to_symbol)
1068 long int distance;
1070 /* FIXME: What's that "+ 3"? It comes from the magic numbers that
1071 used to be here, it's just translated to the limit macros used in
1072 the relax table. But why + 3? */
1073 long int max_short_minus_distance
1074 = cris_arch != arch_crisv32 ? BRANCH_WB + 3 : BRANCH_WB_V32 + 3;
1076 long int max_short_plus_distance
1077 = cris_arch != arch_crisv32 ? BRANCH_WF + 3 : BRANCH_WF_V32 + 3;
1079 /* Bail out for compatibility mode. (It seems it can be implemented,
1080 perhaps with a 10-byte sequence: "move.d NNNN,$pc/$acr", "jump
1081 $acr", "nop"; but doesn't seem worth it at the moment.) */
1082 if (cris_arch == arch_cris_common_v10_v32)
1083 as_fatal (_("Out-of-range .word offset handling\
1084 is not implemented for .arch common_v10_v32"));
1086 distance = to_addr - from_addr;
1088 if (max_short_minus_distance <= distance
1089 && distance <= max_short_plus_distance)
1090 /* Then make it a "short" long jump. */
1091 cris_create_short_jump (storep, from_addr, to_addr, fragP,
1092 to_symbol);
1093 else
1095 /* We have a "long" long jump: "JUMP [PC+]". If CRISv32, always
1096 make it a BA. Else make it an "ADD [PC+],PC" if we're supposed
1097 to emit PIC code. */
1098 md_number_to_chars (storep,
1099 cris_arch == arch_crisv32
1100 ? BA_DWORD_OPCODE
1101 : (pic ? ADD_PC_INCR_OPCODE : JUMP_PC_INCR_OPCODE),
1104 /* Follow with a ".DWORD to_addr", PC-relative for PIC. */
1105 fix_new (fragP, storep + 2 - fragP->fr_literal, 4, to_symbol,
1106 cris_arch == arch_crisv32 ? 6 : 0,
1107 cris_arch == arch_crisv32 || pic ? 1 : 0,
1108 cris_arch == arch_crisv32 || pic
1109 ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
1111 /* Follow it with a "NOP" for CRISv32. */
1112 if (cris_arch == arch_crisv32)
1113 md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2);
1117 /* Allocate space for the first piece of an insn, and mark it as the
1118 start of the insn for debug-format use. */
1120 static char *
1121 cris_insn_first_word_frag (void)
1123 char *insnp = frag_more (2);
1125 /* We need to mark the start of the insn by passing dwarf2_emit_insn
1126 the offset from the current fragment position. This must be done
1127 after the first fragment is created but before any other fragments
1128 (fixed or varying) are created. Note that the offset only
1129 corresponds to the "size" of the insn for a fixed-size,
1130 non-expanded insn. */
1131 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1132 dwarf2_emit_insn (2);
1134 return insnp;
1137 /* Port-specific assembler initialization. */
1139 void
1140 md_begin (void)
1142 const char *hashret = NULL;
1143 int i = 0;
1145 /* Set up a hash table for the instructions. */
1146 op_hash = hash_new ();
1147 if (op_hash == NULL)
1148 as_fatal (_("Virtual memory exhausted"));
1150 /* Enable use of ".if ..asm.arch.cris.v32"
1151 and ".if ..asm.arch.cris.common_v10_v32" and a few others. */
1152 symbol_table_insert (symbol_new ("..asm.arch.cris.v32", absolute_section,
1153 (cris_arch == arch_crisv32),
1154 &zero_address_frag));
1155 symbol_table_insert (symbol_new ("..asm.arch.cris.v10", absolute_section,
1156 (cris_arch == arch_crisv10),
1157 &zero_address_frag));
1158 symbol_table_insert (symbol_new ("..asm.arch.cris.common_v10_v32",
1159 absolute_section,
1160 (cris_arch == arch_cris_common_v10_v32),
1161 &zero_address_frag));
1162 symbol_table_insert (symbol_new ("..asm.arch.cris.any_v0_v10",
1163 absolute_section,
1164 (cris_arch == arch_cris_any_v0_v10),
1165 &zero_address_frag));
1167 while (cris_opcodes[i].name != NULL)
1169 const char *name = cris_opcodes[i].name;
1171 if (! cris_insn_ver_valid_for_arch (cris_opcodes[i].applicable_version,
1172 cris_arch))
1174 i++;
1175 continue;
1178 /* Need to cast to get rid of "const". FIXME: Fix hash_insert instead. */
1179 hashret = hash_insert (op_hash, name, (void *) &cris_opcodes[i]);
1181 if (hashret != NULL && *hashret != '\0')
1182 as_fatal (_("Can't hash `%s': %s\n"), cris_opcodes[i].name,
1183 *hashret == 0 ? _("(unknown reason)") : hashret);
1186 if (cris_opcodes[i].match & cris_opcodes[i].lose)
1187 as_fatal (_("Buggy opcode: `%s' \"%s\"\n"), cris_opcodes[i].name,
1188 cris_opcodes[i].args);
1190 ++i;
1192 while (cris_opcodes[i].name != NULL
1193 && strcmp (cris_opcodes[i].name, name) == 0);
1197 /* Assemble a source line. */
1199 void
1200 md_assemble (char *str)
1202 struct cris_instruction output_instruction;
1203 struct cris_prefix prefix;
1204 char *opcodep;
1205 char *p;
1207 know (str);
1209 /* Do the low-level grunt - assemble to bits and split up into a prefix
1210 and ordinary insn. */
1211 cris_process_instruction (str, &output_instruction, &prefix);
1213 /* Handle any prefixes to the instruction. */
1214 switch (prefix.kind)
1216 case PREFIX_NONE:
1217 break;
1219 /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
1220 extra bytes, so we handle it separately. */
1221 case PREFIX_BDAP_IMM:
1222 /* We only do it if the relocation is unspecified, i.e. not a PIC
1223 relocation. */
1224 if (prefix.reloc == BFD_RELOC_NONE)
1226 gen_bdap (prefix.base_reg_number, &prefix.expr);
1227 break;
1229 /* Fall through. */
1230 case PREFIX_BDAP:
1231 case PREFIX_BIAP:
1232 case PREFIX_DIP:
1233 opcodep = cris_insn_first_word_frag ();
1235 /* Output the prefix opcode. */
1236 md_number_to_chars (opcodep, (long) prefix.opcode, 2);
1238 /* Having a specified reloc only happens for DIP and for BDAP with
1239 PIC operands, but it is ok to drop through here for the other
1240 prefixes as they can have no relocs specified. */
1241 if (prefix.reloc != BFD_RELOC_NONE)
1243 unsigned int relocsize
1244 = (prefix.kind == PREFIX_DIP
1245 ? 4 : cris_get_pic_reloc_size (prefix.reloc));
1247 p = frag_more (relocsize);
1248 fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize,
1249 &prefix.expr, 0, prefix.reloc);
1251 break;
1253 case PREFIX_PUSH:
1254 opcodep = cris_insn_first_word_frag ();
1256 /* Output the prefix opcode. Being a "push", we add the negative
1257 size of the register to "sp". */
1258 if (output_instruction.spec_reg != NULL)
1260 /* Special register. */
1261 opcodep[0] = -output_instruction.spec_reg->reg_size;
1263 else
1265 /* General register. */
1266 opcodep[0] = -4;
1268 opcodep[1] = (REG_SP << 4) + (BDAP_QUICK_OPCODE >> 8);
1269 break;
1271 default:
1272 BAD_CASE (prefix.kind);
1275 /* If we only had a prefix insn, we're done. */
1276 if (output_instruction.insn_type == CRIS_INSN_NONE)
1277 return;
1279 /* Done with the prefix. Continue with the main instruction. */
1280 if (prefix.kind == PREFIX_NONE)
1281 opcodep = cris_insn_first_word_frag ();
1282 else
1283 opcodep = frag_more (2);
1285 /* Output the instruction opcode. */
1286 md_number_to_chars (opcodep, (long) (output_instruction.opcode), 2);
1288 /* Output the symbol-dependent instruction stuff. */
1289 if (output_instruction.insn_type == CRIS_INSN_BRANCH)
1291 segT to_seg = absolute_section;
1292 int is_undefined = 0;
1293 int length_code;
1295 if (output_instruction.expr.X_op != O_constant)
1297 to_seg = S_GET_SEGMENT (output_instruction.expr.X_add_symbol);
1299 if (to_seg == undefined_section)
1300 is_undefined = 1;
1303 if (to_seg == now_seg || is_undefined
1304 /* In CRISv32, there *is* a 32-bit absolute branch, so don't
1305 emit the 12-byte sequence for known symbols in other
1306 segments. */
1307 || (cris_arch == arch_crisv32
1308 && output_instruction.opcode == BA_QUICK_OPCODE))
1310 /* Handle complex expressions. */
1311 valueT addvalue
1312 = (SIMPLE_EXPR (&output_instruction.expr)
1313 ? output_instruction.expr.X_add_number
1314 : 0);
1315 symbolS *sym
1316 = (SIMPLE_EXPR (&output_instruction.expr)
1317 ? output_instruction.expr.X_add_symbol
1318 : make_expr_symbol (&output_instruction.expr));
1320 /* If is_undefined, the expression may still become now_seg.
1321 That case is handled by md_estimate_size_before_relax. */
1322 length_code = to_seg == now_seg ? STATE_BYTE : STATE_UNDF;
1324 /* Make room for max twelve bytes of variable length for v32 mode,
1325 ten for v10 and older. */
1326 frag_var (rs_machine_dependent,
1327 (cris_arch == arch_crisv32
1328 || cris_arch == arch_cris_common_v10_v32) ? 12 : 10, 0,
1329 ENCODE_RELAX (cris_arch == arch_crisv32
1330 ? (output_instruction.opcode
1331 == BA_QUICK_OPCODE
1332 ? STATE_ABS_BRANCH_V32
1333 : STATE_COND_BRANCH_V32)
1334 : (cris_arch == arch_cris_common_v10_v32
1335 ? STATE_COND_BRANCH_COMMON
1336 : STATE_COND_BRANCH),
1337 length_code),
1338 sym, addvalue, opcodep);
1340 else
1342 /* We have: to_seg != now_seg && to_seg != undefined_section.
1343 This means it is a branch to a known symbol in another
1344 section, perhaps an absolute address. Emit a 32-bit branch. */
1345 char *cond_jump
1346 = frag_more ((cris_arch == arch_crisv32
1347 || cris_arch == arch_cris_common_v10_v32)
1348 ? 12 : 10);
1350 gen_cond_branch_32 (opcodep, cond_jump, frag_now,
1351 output_instruction.expr.X_add_symbol,
1352 (symbolS *) NULL,
1353 output_instruction.expr.X_add_number);
1356 else if (output_instruction.insn_type == CRIS_INSN_MUL
1357 && err_for_dangerous_mul_placement)
1358 /* Create a frag which which we track the location of the mul insn
1359 (in the last two bytes before the mul-frag). */
1360 frag_variant (rs_machine_dependent, 0, 0,
1361 ENCODE_RELAX (STATE_MUL, STATE_BYTE),
1362 NULL, 0, opcodep);
1363 else
1365 if (output_instruction.imm_oprnd_size > 0)
1367 /* The instruction has an immediate operand. */
1368 enum bfd_reloc_code_real reloc = BFD_RELOC_NONE;
1370 switch (output_instruction.imm_oprnd_size)
1372 /* Any byte-size immediate constants are treated as
1373 word-size. FIXME: Thus overflow check does not work
1374 correctly. */
1376 case 2:
1377 /* Note that size-check for the explicit reloc has already
1378 been done when we get here. */
1379 if (output_instruction.reloc != BFD_RELOC_NONE)
1380 reloc = output_instruction.reloc;
1381 else
1382 reloc = BFD_RELOC_16;
1383 break;
1385 case 4:
1386 /* Allow a relocation specified in the operand. */
1387 if (output_instruction.reloc != BFD_RELOC_NONE)
1388 reloc = output_instruction.reloc;
1389 else
1390 reloc = BFD_RELOC_32;
1391 break;
1393 default:
1394 BAD_CASE (output_instruction.imm_oprnd_size);
1397 p = frag_more (output_instruction.imm_oprnd_size);
1398 fix_new_exp (frag_now, (p - frag_now->fr_literal),
1399 output_instruction.imm_oprnd_size,
1400 &output_instruction.expr,
1401 reloc == BFD_RELOC_32_PCREL
1402 || reloc == BFD_RELOC_16_PCREL
1403 || reloc == BFD_RELOC_8_PCREL, reloc);
1405 else if (output_instruction.reloc == BFD_RELOC_CRIS_LAPCQ_OFFSET
1406 && output_instruction.expr.X_md != 0)
1408 /* Handle complex expressions. */
1409 valueT addvalue
1410 = (output_instruction.expr.X_op_symbol != NULL
1411 ? 0 : output_instruction.expr.X_add_number);
1412 symbolS *sym
1413 = (output_instruction.expr.X_op_symbol != NULL
1414 ? make_expr_symbol (&output_instruction.expr)
1415 : output_instruction.expr.X_add_symbol);
1417 /* This is a relaxing construct, so we need a frag_var rather
1418 than the fix_new_exp call below. */
1419 frag_var (rs_machine_dependent,
1420 4, 0,
1421 ENCODE_RELAX (STATE_LAPC, STATE_UNDF),
1422 sym, addvalue, opcodep);
1424 else if (output_instruction.reloc != BFD_RELOC_NONE)
1426 /* An immediate operand that has a relocation and needs to be
1427 processed further. */
1429 /* It is important to use fix_new_exp here and everywhere else
1430 (and not fix_new), as fix_new_exp can handle "difference
1431 expressions" - where the expression contains a difference of
1432 two symbols in the same segment. */
1433 fix_new_exp (frag_now, (opcodep - frag_now->fr_literal), 2,
1434 &output_instruction.expr,
1435 output_instruction.reloc == BFD_RELOC_32_PCREL
1436 || output_instruction.reloc == BFD_RELOC_16_PCREL
1437 || output_instruction.reloc == BFD_RELOC_8_PCREL
1438 || (output_instruction.reloc
1439 == BFD_RELOC_CRIS_LAPCQ_OFFSET),
1440 output_instruction.reloc);
1445 /* Low level text-to-bits assembly. */
1447 static void
1448 cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
1449 struct cris_prefix *prefixp)
1451 char *s;
1452 char modified_char = 0;
1453 const char *args;
1454 struct cris_opcode *instruction;
1455 char *operands;
1456 int match = 0;
1457 int mode;
1458 int regno;
1459 int size_bits;
1461 /* Reset these fields to a harmless state in case we need to return in
1462 error. */
1463 prefixp->kind = PREFIX_NONE;
1464 prefixp->reloc = BFD_RELOC_NONE;
1465 out_insnp->insn_type = CRIS_INSN_NONE;
1466 out_insnp->imm_oprnd_size = 0;
1468 /* Find the end of the opcode mnemonic. We assume (true in 2.9.1)
1469 that the caller has translated the opcode to lower-case, up to the
1470 first non-letter. */
1471 for (operands = insn_text; ISLOWER (*operands); ++operands)
1474 /* Terminate the opcode after letters, but save the character there if
1475 it was of significance. */
1476 switch (*operands)
1478 case '\0':
1479 break;
1481 case '.':
1482 /* Put back the modified character later. */
1483 modified_char = *operands;
1484 /* Fall through. */
1486 case ' ':
1487 /* Consume the character after the mnemonic
1488 and replace it with '\0'. */
1489 *operands++ = '\0';
1490 break;
1492 default:
1493 as_bad (_("Unknown opcode: `%s'"), insn_text);
1494 return;
1497 /* Find the instruction. */
1498 instruction = (struct cris_opcode *) hash_find (op_hash, insn_text);
1499 if (instruction == NULL)
1501 as_bad (_("Unknown opcode: `%s'"), insn_text);
1502 return;
1505 /* Put back the modified character. */
1506 switch (modified_char)
1508 case 0:
1509 break;
1511 default:
1512 *--operands = modified_char;
1515 /* Try to match an opcode table slot. */
1516 for (s = operands;;)
1518 int imm_expr_found;
1520 /* Initialize *prefixp, perhaps after being modified for a
1521 "near match". */
1522 prefixp->kind = PREFIX_NONE;
1523 prefixp->reloc = BFD_RELOC_NONE;
1525 /* Initialize *out_insnp. */
1526 memset (out_insnp, 0, sizeof (*out_insnp));
1527 out_insnp->opcode = instruction->match;
1528 out_insnp->reloc = BFD_RELOC_NONE;
1529 out_insnp->insn_type = CRIS_INSN_NORMAL;
1530 out_insnp->imm_oprnd_size = 0;
1532 imm_expr_found = 0;
1534 /* Build the opcode, checking as we go to make sure that the
1535 operands match. */
1536 for (args = instruction->args;; ++args)
1538 switch (*args)
1540 case '\0':
1541 /* If we've come to the end of arguments, we're done. */
1542 if (*s == '\0')
1543 match = 1;
1544 break;
1546 case '!':
1547 /* Non-matcher character for disassembly.
1548 Ignore it here. */
1549 continue;
1551 case '[':
1552 case ']':
1553 case ',':
1554 case ' ':
1555 /* These must match exactly. */
1556 if (*s++ == *args)
1557 continue;
1558 break;
1560 case 'A':
1561 /* "ACR", case-insensitive.
1562 Handle a sometimes-mandatory dollar sign as register
1563 prefix. */
1564 if (*s == REGISTER_PREFIX_CHAR)
1565 s++;
1566 else if (demand_register_prefix)
1567 break;
1569 if ((*s++ != 'a' && s[-1] != 'A')
1570 || (*s++ != 'c' && s[-1] != 'C')
1571 || (*s++ != 'r' && s[-1] != 'R'))
1572 break;
1573 continue;
1575 case 'B':
1576 /* This is not really an operand, but causes a "BDAP
1577 -size,SP" prefix to be output, for PUSH instructions. */
1578 prefixp->kind = PREFIX_PUSH;
1579 continue;
1581 case 'b':
1582 /* This letter marks an operand that should not be matched
1583 in the assembler. It is a branch with 16-bit
1584 displacement. The assembler will create them from the
1585 8-bit flavor when necessary. The assembler does not
1586 support the [rN+] operand, as the [r15+] that is
1587 generated for 16-bit displacements. */
1588 break;
1590 case 'c':
1591 /* A 5-bit unsigned immediate in bits <4:0>. */
1592 if (! cris_get_expression (&s, &out_insnp->expr))
1593 break;
1594 else
1596 if (out_insnp->expr.X_op == O_constant
1597 && (out_insnp->expr.X_add_number < 0
1598 || out_insnp->expr.X_add_number > 31))
1599 as_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
1600 out_insnp->expr.X_add_number);
1602 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
1603 continue;
1606 case 'C':
1607 /* A 4-bit unsigned immediate in bits <3:0>. */
1608 if (! cris_get_expression (&s, &out_insnp->expr))
1609 break;
1610 else
1612 if (out_insnp->expr.X_op == O_constant
1613 && (out_insnp->expr.X_add_number < 0
1614 || out_insnp->expr.X_add_number > 15))
1615 as_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
1616 out_insnp->expr.X_add_number);
1618 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
1619 continue;
1622 /* For 'd', check for an optional ".d" or ".D" at the
1623 start of the operands, followed by a space character. */
1624 case 'd':
1625 if (modified_char == '.' && *s == '.')
1627 if ((s[1] != 'd' && s[1] == 'D')
1628 || ! ISSPACE (s[2]))
1629 break;
1630 s += 2;
1631 continue;
1633 continue;
1635 case 'D':
1636 /* General register in bits <15:12> and <3:0>. */
1637 if (! get_gen_reg (&s, &regno))
1638 break;
1639 else
1641 out_insnp->opcode |= regno /* << 0 */;
1642 out_insnp->opcode |= regno << 12;
1643 continue;
1646 case 'f':
1647 /* Flags from the condition code register. */
1649 int flags = 0;
1651 if (! get_flags (&s, &flags))
1652 break;
1654 out_insnp->opcode |= ((flags & 0xf0) << 8) | (flags & 0xf);
1655 continue;
1658 case 'i':
1659 /* A 6-bit signed immediate in bits <5:0>. */
1660 if (! cris_get_expression (&s, &out_insnp->expr))
1661 break;
1662 else
1664 if (out_insnp->expr.X_op == O_constant
1665 && (out_insnp->expr.X_add_number < -32
1666 || out_insnp->expr.X_add_number > 31))
1667 as_bad (_("Immediate value not in 6 bit range: %ld"),
1668 out_insnp->expr.X_add_number);
1669 out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
1670 continue;
1673 case 'I':
1674 /* A 6-bit unsigned immediate in bits <5:0>. */
1675 if (! cris_get_expression (&s, &out_insnp->expr))
1676 break;
1677 else
1679 if (out_insnp->expr.X_op == O_constant
1680 && (out_insnp->expr.X_add_number < 0
1681 || out_insnp->expr.X_add_number > 63))
1682 as_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
1683 out_insnp->expr.X_add_number);
1684 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
1685 continue;
1688 case 'M':
1689 /* A size modifier, B, W or D, to be put in a bit position
1690 suitable for CLEAR instructions (i.e. reflecting a zero
1691 register). */
1692 if (! get_bwd_size_modifier (&s, &size_bits))
1693 break;
1694 else
1696 switch (size_bits)
1698 case 0:
1699 out_insnp->opcode |= 0 << 12;
1700 break;
1702 case 1:
1703 out_insnp->opcode |= 4 << 12;
1704 break;
1706 case 2:
1707 out_insnp->opcode |= 8 << 12;
1708 break;
1710 continue;
1713 case 'm':
1714 /* A size modifier, B, W or D, to be put in bits <5:4>. */
1715 if (modified_char != '.'
1716 || ! get_bwd_size_modifier (&s, &size_bits))
1717 break;
1718 else
1720 out_insnp->opcode |= size_bits << 4;
1721 continue;
1724 case 'o':
1725 /* A branch expression. */
1726 if (! cris_get_expression (&s, &out_insnp->expr))
1727 break;
1728 else
1730 out_insnp->insn_type = CRIS_INSN_BRANCH;
1731 continue;
1734 case 'Q':
1735 /* A 8-bit quick BDAP expression, "expr,R". */
1736 if (! cris_get_expression (&s, &out_insnp->expr))
1737 break;
1739 if (*s != ',')
1740 break;
1742 s++;
1744 if (!get_gen_reg (&s, &regno))
1745 break;
1747 out_insnp->opcode |= regno << 12;
1748 out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_8;
1749 continue;
1751 case 'O':
1752 /* A BDAP expression for any size, "expr,R". */
1753 if (! cris_get_expression (&s, &prefixp->expr))
1754 break;
1755 else
1757 if (*s != ',')
1758 break;
1760 s++;
1762 if (!get_gen_reg (&s, &prefixp->base_reg_number))
1763 break;
1765 /* Since 'O' is used with an explicit bdap, we have no
1766 "real" instruction. */
1767 prefixp->kind = PREFIX_BDAP_IMM;
1768 prefixp->opcode
1769 = BDAP_QUICK_OPCODE | (prefixp->base_reg_number << 12);
1771 out_insnp->insn_type = CRIS_INSN_NONE;
1772 continue;
1775 case 'P':
1776 /* Special register in bits <15:12>. */
1777 if (! get_spec_reg (&s, &out_insnp->spec_reg))
1778 break;
1779 else
1781 /* Use of some special register names come with a
1782 specific warning. Note that we have no ".cpu type"
1783 pseudo yet, so some of this is just unused
1784 framework. */
1785 if (out_insnp->spec_reg->warning)
1786 as_warn (out_insnp->spec_reg->warning);
1787 else if (out_insnp->spec_reg->applicable_version
1788 == cris_ver_warning)
1789 /* Others have a generic warning. */
1790 as_warn (_("Unimplemented register `%s' specified"),
1791 out_insnp->spec_reg->name);
1793 out_insnp->opcode
1794 |= out_insnp->spec_reg->number << 12;
1795 continue;
1798 case 'p':
1799 /* This character is used in the disassembler to
1800 recognize a prefix instruction to fold into the
1801 addressing mode for the next instruction. It is
1802 ignored here. */
1803 continue;
1805 case 'R':
1806 /* General register in bits <15:12>. */
1807 if (! get_gen_reg (&s, &regno))
1808 break;
1809 else
1811 out_insnp->opcode |= regno << 12;
1812 continue;
1815 case 'r':
1816 /* General register in bits <3:0>. */
1817 if (! get_gen_reg (&s, &regno))
1818 break;
1819 else
1821 out_insnp->opcode |= regno /* << 0 */;
1822 continue;
1825 case 'S':
1826 /* Source operand in bit <10> and a prefix; a 3-operand
1827 prefix. */
1828 if (! get_3op_or_dip_prefix_op (&s, prefixp))
1829 break;
1830 else
1831 continue;
1833 case 's':
1834 /* Source operand in bits <10>, <3:0> and optionally a
1835 prefix; i.e. an indirect operand or an side-effect
1836 prefix (where valid). */
1837 if (! get_autoinc_prefix_or_indir_op (&s, prefixp, &mode,
1838 &regno,
1839 &imm_expr_found,
1840 &out_insnp->expr))
1841 break;
1842 else
1844 if (prefixp->kind != PREFIX_NONE)
1846 /* A prefix, so it has the autoincrement bit
1847 set. */
1848 out_insnp->opcode |= (AUTOINCR_BIT << 8);
1850 else
1852 /* No prefix. The "mode" variable contains bits like
1853 whether or not this is autoincrement mode. */
1854 out_insnp->opcode |= (mode << 10);
1856 /* If there was a PIC reloc specifier, then it was
1857 attached to the prefix. Note that we can't check
1858 that the reloc size matches, since we don't have
1859 all the operands yet in all cases. */
1860 if (prefixp->reloc != BFD_RELOC_NONE)
1861 out_insnp->reloc = prefixp->reloc;
1864 out_insnp->opcode |= regno /* << 0 */ ;
1865 continue;
1868 case 'N':
1869 case 'Y':
1870 /* Like 's', but immediate operand only. Also does not
1871 modify insn. There are no insns where a PIC reloc
1872 specifier makes sense. */
1873 if (cris_get_expression (&s, &out_insnp->expr))
1875 imm_expr_found = 1;
1876 continue;
1878 break;
1880 case 'n':
1881 /* Like 'N', but PC-relative to the start of the insn.
1882 There might be a :PLT to request a PLT entry. */
1883 if (cris_get_expression (&s, &out_insnp->expr))
1885 imm_expr_found = 1;
1886 out_insnp->reloc = BFD_RELOC_32_PCREL;
1888 /* We have to adjust the expression, because that
1889 relocation is to the location *after* the
1890 relocation. So add 2 for the insn and 4 for the
1891 relocation. */
1892 out_insnp->expr.X_add_number += 6;
1894 if (pic && *s == PIC_SUFFIX_CHAR)
1895 cris_get_pic_suffix (&s, &out_insnp->reloc,
1896 &out_insnp->expr);
1898 continue;
1900 break;
1902 case 'U':
1903 /* Maybe 'u', maybe 'n'. Only for LAPC/LAPCQ. */
1904 if (cris_get_expression (&s, &out_insnp->expr))
1906 out_insnp->reloc = BFD_RELOC_CRIS_LAPCQ_OFFSET;
1908 /* Define 1 as relaxing. */
1909 out_insnp->expr.X_md = 1;
1910 continue;
1912 break;
1914 case 'u':
1915 /* Four PC-relative bits in <3:0> representing <4:1>:0 of
1916 an offset relative to the beginning of the current
1917 insn. */
1918 if (cris_get_expression (&s, &out_insnp->expr))
1920 out_insnp->reloc = BFD_RELOC_CRIS_LAPCQ_OFFSET;
1922 /* Define 0 as non-relaxing. */
1923 out_insnp->expr.X_md = 0;
1925 /* We have to adjust the expression, because that
1926 relocation is to the location *after* the
1927 insn. So add 2 for the insn. */
1928 out_insnp->expr.X_add_number += 2;
1929 continue;
1931 break;
1933 case 'x':
1934 /* Rs.m in bits <15:12> and <5:4>. */
1935 if (! get_gen_reg (&s, &regno)
1936 || ! get_bwd_size_modifier (&s, &size_bits))
1937 break;
1938 else
1940 out_insnp->opcode |= (regno << 12) | (size_bits << 4);
1941 continue;
1944 case 'y':
1945 /* Source operand in bits <10>, <3:0> and optionally a
1946 prefix; i.e. an indirect operand or an side-effect
1947 prefix.
1949 The difference to 's' is that this does not allow an
1950 "immediate" expression. */
1951 if (! get_autoinc_prefix_or_indir_op (&s, prefixp,
1952 &mode, &regno,
1953 &imm_expr_found,
1954 &out_insnp->expr)
1955 || imm_expr_found)
1956 break;
1957 else
1959 if (prefixp->kind != PREFIX_NONE)
1961 /* A prefix, and those matched here always have
1962 side-effects (see 's' case). */
1963 out_insnp->opcode |= (AUTOINCR_BIT << 8);
1965 else
1967 /* No prefix. The "mode" variable contains bits
1968 like whether or not this is autoincrement
1969 mode. */
1970 out_insnp->opcode |= (mode << 10);
1973 out_insnp->opcode |= regno /* << 0 */;
1974 continue;
1977 case 'z':
1978 /* Size modifier (B or W) in bit <4>. */
1979 if (! get_bw_size_modifier (&s, &size_bits))
1980 break;
1981 else
1983 out_insnp->opcode |= size_bits << 4;
1984 continue;
1987 case 'T':
1988 if (cris_arch == arch_crisv32
1989 && get_sup_reg (&s, &regno))
1991 out_insnp->opcode |= regno << 12;
1992 continue;
1994 break;
1996 default:
1997 BAD_CASE (*args);
2000 /* We get here when we fail a match above or we found a
2001 complete match. Break out of this loop. */
2002 break;
2005 /* Was it a match or a miss? */
2006 if (match == 0)
2008 /* If it's just that the args don't match, maybe the next
2009 item in the table is the same opcode but with
2010 matching operands. First skip any invalid ones. */
2011 while (instruction[1].name != NULL
2012 && strcmp (instruction->name, instruction[1].name) == 0
2013 && ! cris_insn_ver_valid_for_arch (instruction[1]
2014 .applicable_version,
2015 cris_arch))
2016 ++instruction;
2018 if (instruction[1].name != NULL
2019 && strcmp (instruction->name, instruction[1].name) == 0
2020 && cris_insn_ver_valid_for_arch (instruction[1]
2021 .applicable_version,
2022 cris_arch))
2024 /* Yep. Restart and try that one instead. */
2025 ++instruction;
2026 s = operands;
2027 continue;
2029 else
2031 /* We've come to the end of instructions with this
2032 opcode, so it must be an error. */
2033 as_bad (_("Illegal operands"));
2035 /* As discard_rest_of_line, but without continuing to the
2036 next line. */
2037 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2038 input_line_pointer++;
2039 return;
2042 else
2044 /* We have a match. Check if there's anything more to do. */
2045 if (imm_expr_found)
2047 /* There was an immediate mode operand, so we must check
2048 that it has an appropriate size. */
2049 switch (instruction->imm_oprnd_size)
2051 default:
2052 case SIZE_NONE:
2053 /* Shouldn't happen; this one does not have immediate
2054 operands with different sizes. */
2055 BAD_CASE (instruction->imm_oprnd_size);
2056 break;
2058 case SIZE_FIX_32:
2059 out_insnp->imm_oprnd_size = 4;
2060 break;
2062 case SIZE_SPEC_REG:
2063 if (cris_arch == arch_crisv32)
2064 /* All immediate loads of special registers are
2065 32-bit on CRISv32. */
2066 out_insnp->imm_oprnd_size = 4;
2067 else
2068 switch (out_insnp->spec_reg->reg_size)
2070 case 1:
2071 if (out_insnp->expr.X_op == O_constant
2072 && (out_insnp->expr.X_add_number < -128
2073 || out_insnp->expr.X_add_number > 255))
2074 as_bad (_("Immediate value not in 8 bit range: %ld"),
2075 out_insnp->expr.X_add_number);
2076 /* Fall through. */
2077 case 2:
2078 /* FIXME: We need an indicator in the instruction
2079 table to pass on, to indicate if we need to check
2080 overflow for a signed or unsigned number. */
2081 if (out_insnp->expr.X_op == O_constant
2082 && (out_insnp->expr.X_add_number < -32768
2083 || out_insnp->expr.X_add_number > 65535))
2084 as_bad (_("Immediate value not in 16 bit range: %ld"),
2085 out_insnp->expr.X_add_number);
2086 out_insnp->imm_oprnd_size = 2;
2087 break;
2089 case 4:
2090 out_insnp->imm_oprnd_size = 4;
2091 break;
2093 default:
2094 BAD_CASE (out_insnp->spec_reg->reg_size);
2096 break;
2098 case SIZE_FIELD:
2099 case SIZE_FIELD_SIGNED:
2100 case SIZE_FIELD_UNSIGNED:
2101 switch (size_bits)
2103 /* FIXME: Find way to pass un/signedness to
2104 caller, and set reloc type instead, postponing
2105 this check until cris_number_to_imm. That
2106 necessarily corrects the reloc type for the
2107 byte case, maybe requiring further changes. */
2108 case 0:
2109 if (out_insnp->expr.X_op == O_constant)
2111 if (instruction->imm_oprnd_size == SIZE_FIELD
2112 && (out_insnp->expr.X_add_number < -128
2113 || out_insnp->expr.X_add_number > 255))
2114 as_bad (_("Immediate value not in 8 bit range: %ld"),
2115 out_insnp->expr.X_add_number);
2116 else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
2117 && (out_insnp->expr.X_add_number < -128
2118 || out_insnp->expr.X_add_number > 127))
2119 as_bad (_("Immediate value not in 8 bit signed range: %ld"),
2120 out_insnp->expr.X_add_number);
2121 else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
2122 && (out_insnp->expr.X_add_number < 0
2123 || out_insnp->expr.X_add_number > 255))
2124 as_bad (_("Immediate value not in 8 bit unsigned range: %ld"),
2125 out_insnp->expr.X_add_number);
2128 /* Fall through. */
2129 case 1:
2130 if (out_insnp->expr.X_op == O_constant)
2132 if (instruction->imm_oprnd_size == SIZE_FIELD
2133 && (out_insnp->expr.X_add_number < -32768
2134 || out_insnp->expr.X_add_number > 65535))
2135 as_bad (_("Immediate value not in 16 bit range: %ld"),
2136 out_insnp->expr.X_add_number);
2137 else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
2138 && (out_insnp->expr.X_add_number < -32768
2139 || out_insnp->expr.X_add_number > 32767))
2140 as_bad (_("Immediate value not in 16 bit signed range: %ld"),
2141 out_insnp->expr.X_add_number);
2142 else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
2143 && (out_insnp->expr.X_add_number < 0
2144 || out_insnp->expr.X_add_number > 65535))
2145 as_bad (_("Immediate value not in 16 bit unsigned range: %ld"),
2146 out_insnp->expr.X_add_number);
2148 out_insnp->imm_oprnd_size = 2;
2149 break;
2151 case 2:
2152 out_insnp->imm_oprnd_size = 4;
2153 break;
2155 default:
2156 BAD_CASE (out_insnp->spec_reg->reg_size);
2160 /* If there was a relocation specified for the immediate
2161 expression (i.e. it had a PIC modifier) check that the
2162 size of the PIC relocation matches the size specified by
2163 the opcode. */
2164 if (out_insnp->reloc != BFD_RELOC_NONE
2165 && (cris_get_pic_reloc_size (out_insnp->reloc)
2166 != (unsigned int) out_insnp->imm_oprnd_size))
2167 as_bad (_("PIC relocation size does not match operand size"));
2169 else if (instruction->op == cris_muls_op
2170 || instruction->op == cris_mulu_op)
2171 out_insnp->insn_type = CRIS_INSN_MUL;
2173 break;
2177 /* Get a B, W, or D size modifier from the string pointed out by *cPP,
2178 which must point to a '.' in front of the modifier. On successful
2179 return, *cPP is advanced to the character following the size
2180 modifier, and is undefined otherwise.
2182 cPP Pointer to pointer to string starting
2183 with the size modifier.
2185 size_bitsp Pointer to variable to contain the size bits on
2186 successful return.
2188 Return 1 iff a correct size modifier is found, else 0. */
2190 static int
2191 get_bwd_size_modifier (char **cPP, int *size_bitsp)
2193 if (**cPP != '.')
2194 return 0;
2195 else
2197 /* Consume the '.'. */
2198 (*cPP)++;
2200 switch (**cPP)
2202 case 'B':
2203 case 'b':
2204 *size_bitsp = 0;
2205 break;
2207 case 'W':
2208 case 'w':
2209 *size_bitsp = 1;
2210 break;
2212 case 'D':
2213 case 'd':
2214 *size_bitsp = 2;
2215 break;
2217 default:
2218 return 0;
2221 /* Consume the size letter. */
2222 (*cPP)++;
2223 return 1;
2227 /* Get a B or W size modifier from the string pointed out by *cPP,
2228 which must point to a '.' in front of the modifier. On successful
2229 return, *cPP is advanced to the character following the size
2230 modifier, and is undefined otherwise.
2232 cPP Pointer to pointer to string starting
2233 with the size modifier.
2235 size_bitsp Pointer to variable to contain the size bits on
2236 successful return.
2238 Return 1 iff a correct size modifier is found, else 0. */
2240 static int
2241 get_bw_size_modifier (char **cPP, int *size_bitsp)
2243 if (**cPP != '.')
2244 return 0;
2245 else
2247 /* Consume the '.'. */
2248 (*cPP)++;
2250 switch (**cPP)
2252 case 'B':
2253 case 'b':
2254 *size_bitsp = 0;
2255 break;
2257 case 'W':
2258 case 'w':
2259 *size_bitsp = 1;
2260 break;
2262 default:
2263 return 0;
2266 /* Consume the size letter. */
2267 (*cPP)++;
2268 return 1;
2272 /* Get a general register from the string pointed out by *cPP. The
2273 variable *cPP is advanced to the character following the general
2274 register name on a successful return, and has its initial position
2275 otherwise.
2277 cPP Pointer to pointer to string, beginning with a general
2278 register name.
2280 regnop Pointer to int containing the register number.
2282 Return 1 iff a correct general register designator is found,
2283 else 0. */
2285 static int
2286 get_gen_reg (char **cPP, int *regnop)
2288 char *oldp;
2289 oldp = *cPP;
2291 /* Handle a sometimes-mandatory dollar sign as register prefix. */
2292 if (**cPP == REGISTER_PREFIX_CHAR)
2293 (*cPP)++;
2294 else if (demand_register_prefix)
2295 return 0;
2297 switch (**cPP)
2299 case 'P':
2300 case 'p':
2301 /* "P" as in "PC"? Consume the "P". */
2302 (*cPP)++;
2304 if ((**cPP == 'C' || **cPP == 'c')
2305 && ! ISALNUM ((*cPP)[1])
2306 /* Here's a little twist: For v32 and the compatibility mode,
2307 we only recognize PC as a register number if there's '+]'
2308 after. We don't consume that, but the presence can only be
2309 valid after a register in a post-increment context, which
2310 is also the only valid context for PC as a register for
2311 v32. Not that it's used very often, but saying "MOVE.D
2312 [PC+],R5" should remain valid. It's not supported for
2313 jump-type insns or other insns with no [Rn+] mode, though. */
2314 && ((cris_arch != arch_crisv32
2315 && cris_arch != arch_cris_common_v10_v32)
2316 || ((*cPP)[1] == '+' && (*cPP)[2] == ']')))
2318 /* It's "PC": consume the "c" and we're done. */
2319 (*cPP)++;
2320 *regnop = REG_PC;
2321 return 1;
2323 break;
2325 /* Like with PC, we recognize ACR, but only if it's *not* followed
2326 by '+', and only for v32. */
2327 case 'A':
2328 case 'a':
2329 if (cris_arch != arch_crisv32
2330 || ((*cPP)[1] != 'c' && (*cPP)[1] != 'C')
2331 || ((*cPP)[2] != 'r' && (*cPP)[2] != 'R')
2332 || ISALNUM ((*cPP)[3])
2333 || (*cPP)[3] == '+')
2334 break;
2335 (*cPP) += 3;
2336 *regnop = 15;
2337 return 1;
2339 case 'R':
2340 case 'r':
2341 /* Hopefully r[0-9] or r1[0-5]. Consume 'R' or 'r'. */
2342 (*cPP)++;
2344 if (ISDIGIT (**cPP))
2346 /* It's r[0-9]. Consume and check the next digit. */
2347 *regnop = **cPP - '0';
2348 (*cPP)++;
2350 if (! ISALNUM (**cPP))
2352 /* No more digits, we're done. */
2353 return 1;
2355 else
2357 /* One more digit. Consume and add. */
2358 *regnop = *regnop * 10 + (**cPP - '0');
2360 /* We need to check for a valid register number; Rn,
2361 0 <= n <= MAX_REG. */
2362 if (*regnop <= MAX_REG)
2364 /* Consume second digit. */
2365 (*cPP)++;
2366 return 1;
2370 break;
2372 case 'S':
2373 case 's':
2374 /* "S" as in "SP"? Consume the "S". */
2375 (*cPP)++;
2376 if (**cPP == 'P' || **cPP == 'p')
2378 /* It's "SP": consume the "p" and we're done. */
2379 (*cPP)++;
2380 *regnop = REG_SP;
2381 return 1;
2383 break;
2385 default:
2386 /* Just here to silence compilation warnings. */
2390 /* We get here if we fail. Restore the pointer. */
2391 *cPP = oldp;
2392 return 0;
2395 /* Get a special register from the string pointed out by *cPP. The
2396 variable *cPP is advanced to the character following the special
2397 register name if one is found, and retains its original position
2398 otherwise.
2400 cPP Pointer to pointer to string starting with a special register
2401 name.
2403 sregpp Pointer to Pointer to struct spec_reg, where a pointer to the
2404 register description will be stored.
2406 Return 1 iff a correct special register name is found. */
2408 static int
2409 get_spec_reg (char **cPP, const struct cris_spec_reg **sregpp)
2411 char *s1;
2412 const char *s2;
2413 char *name_begin = *cPP;
2415 const struct cris_spec_reg *sregp;
2417 /* Handle a sometimes-mandatory dollar sign as register prefix. */
2418 if (*name_begin == REGISTER_PREFIX_CHAR)
2419 name_begin++;
2420 else if (demand_register_prefix)
2421 return 0;
2423 /* Loop over all special registers. */
2424 for (sregp = cris_spec_regs; sregp->name != NULL; sregp++)
2426 /* Start over from beginning of the supposed name. */
2427 s1 = name_begin;
2428 s2 = sregp->name;
2430 while (*s2 != '\0' && TOLOWER (*s1) == *s2)
2432 s1++;
2433 s2++;
2436 /* For a match, we must have consumed the name in the table, and we
2437 must be outside what could be part of a name. Assume here that a
2438 test for alphanumerics is sufficient for a name test. */
2439 if (*s2 == 0 && ! ISALNUM (*s1)
2440 && cris_insn_ver_valid_for_arch (sregp->applicable_version,
2441 cris_arch))
2443 /* We have a match. Update the pointer and be done. */
2444 *cPP = s1;
2445 *sregpp = sregp;
2446 return 1;
2450 /* If we got here, we did not find any name. */
2451 return 0;
2454 /* Get a support register from the string pointed out by *cPP. The
2455 variable *cPP is advanced to the character following the support-
2456 register name if one is found, and retains its original position
2457 otherwise.
2459 cPP Pointer to pointer to string starting with a support-register
2460 name.
2462 sregpp Pointer to int containing the register number.
2464 Return 1 iff a correct support-register name is found. */
2466 static int
2467 get_sup_reg (char **cPP, int *regnop)
2469 char *s1;
2470 const char *s2;
2471 char *name_begin = *cPP;
2473 const struct cris_support_reg *sregp;
2475 /* Handle a sometimes-mandatory dollar sign as register prefix. */
2476 if (*name_begin == REGISTER_PREFIX_CHAR)
2477 name_begin++;
2478 else if (demand_register_prefix)
2479 return 0;
2481 /* Loop over all support-registers. */
2482 for (sregp = cris_support_regs; sregp->name != NULL; sregp++)
2484 /* Start over from beginning of the supposed name. */
2485 s1 = name_begin;
2486 s2 = sregp->name;
2488 while (*s2 != '\0' && TOLOWER (*s1) == *s2)
2490 s1++;
2491 s2++;
2494 /* For a match, we must have consumed the name in the table, and we
2495 must be outside what could be part of a name. Assume here that a
2496 test for alphanumerics is sufficient for a name test. */
2497 if (*s2 == 0 && ! ISALNUM (*s1))
2499 /* We have a match. Update the pointer and be done. */
2500 *cPP = s1;
2501 *regnop = sregp->number;
2502 return 1;
2506 /* If we got here, we did not find any name. */
2507 return 0;
2510 /* Get an unprefixed or side-effect-prefix operand from the string pointed
2511 out by *cPP. The pointer *cPP is advanced to the character following
2512 the indirect operand if we have success, else it contains an undefined
2513 value.
2515 cPP Pointer to pointer to string beginning with the first
2516 character of the supposed operand.
2518 prefixp Pointer to structure containing an optional instruction
2519 prefix.
2521 is_autoincp Pointer to int indicating the indirect or autoincrement
2522 bits.
2524 src_regnop Pointer to int containing the source register number in
2525 the instruction.
2527 imm_foundp Pointer to an int indicating if an immediate expression
2528 is found.
2530 imm_exprP Pointer to a structure containing an immediate
2531 expression, if success and if *imm_foundp is nonzero.
2533 Return 1 iff a correct indirect operand is found. */
2535 static int
2536 get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp,
2537 int *is_autoincp, int *src_regnop,
2538 int *imm_foundp, expressionS *imm_exprP)
2540 /* Assume there was no immediate mode expression. */
2541 *imm_foundp = 0;
2543 if (**cPP == '[')
2545 /* So this operand is one of:
2546 Indirect: [rN]
2547 Autoincrement: [rN+]
2548 Indexed with assign: [rN=rM+rO.S]
2549 Offset with assign: [rN=rM+I], [rN=rM+[rO].s], [rN=rM+[rO+].s]
2551 Either way, consume the '['. */
2552 (*cPP)++;
2554 /* Get the rN register. */
2555 if (! get_gen_reg (cPP, src_regnop))
2556 /* If there was no register, then this cannot match. */
2557 return 0;
2558 else
2560 /* We got the register, now check the next character. */
2561 switch (**cPP)
2563 case ']':
2564 /* Indirect mode. We're done here. */
2565 prefixp->kind = PREFIX_NONE;
2566 *is_autoincp = 0;
2567 break;
2569 case '+':
2570 /* This must be an auto-increment mode, if there's a
2571 match. */
2572 prefixp->kind = PREFIX_NONE;
2573 *is_autoincp = 1;
2575 /* We consume this character and break out to check the
2576 closing ']'. */
2577 (*cPP)++;
2578 break;
2580 case '=':
2581 /* This must be indexed with assign, or offset with assign
2582 to match. Not supported for crisv32 or in
2583 compatibility mode. */
2584 if (cris_arch == arch_crisv32
2585 || cris_arch == arch_cris_common_v10_v32)
2586 return 0;
2588 (*cPP)++;
2590 /* Either way, the next thing must be a register. */
2591 if (! get_gen_reg (cPP, &prefixp->base_reg_number))
2592 /* No register, no match. */
2593 return 0;
2594 else
2596 /* We've consumed "[rN=rM", so we must be looking at
2597 "+rO.s]" or "+I]", or "-I]", or "+[rO].s]" or
2598 "+[rO+].s]". */
2599 if (**cPP == '+')
2601 int index_reg_number;
2602 (*cPP)++;
2604 if (**cPP == '[')
2606 int size_bits;
2607 /* This must be [rx=ry+[rz].s] or
2608 [rx=ry+[rz+].s] or no match. We must be
2609 looking at rz after consuming the '['. */
2610 (*cPP)++;
2612 if (!get_gen_reg (cPP, &index_reg_number))
2613 return 0;
2615 prefixp->kind = PREFIX_BDAP;
2616 prefixp->opcode
2617 = (BDAP_INDIR_OPCODE
2618 + (prefixp->base_reg_number << 12)
2619 + index_reg_number);
2621 if (**cPP == '+')
2623 /* We've seen "[rx=ry+[rz+" here, so now we
2624 know that there must be "].s]" left to
2625 check. */
2626 (*cPP)++;
2627 prefixp->opcode |= AUTOINCR_BIT << 8;
2630 /* If it wasn't autoincrement, we don't need to
2631 add anything. */
2633 /* Check the next-to-last ']'. */
2634 if (**cPP != ']')
2635 return 0;
2637 (*cPP)++;
2639 /* Check the ".s" modifier. */
2640 if (! get_bwd_size_modifier (cPP, &size_bits))
2641 return 0;
2643 prefixp->opcode |= size_bits << 4;
2645 /* Now we got [rx=ry+[rz+].s or [rx=ry+[rz].s.
2646 We break out to check the final ']'. */
2647 break;
2649 /* It wasn't an indirection. Check if it's a
2650 register. */
2651 else if (get_gen_reg (cPP, &index_reg_number))
2653 int size_bits;
2655 /* Indexed with assign mode: "[rN+rM.S]". */
2656 prefixp->kind = PREFIX_BIAP;
2657 prefixp->opcode
2658 = (BIAP_OPCODE + (index_reg_number << 12)
2659 + prefixp->base_reg_number /* << 0 */);
2661 if (! get_bwd_size_modifier (cPP, &size_bits))
2662 /* Size missing, this isn't a match. */
2663 return 0;
2664 else
2666 /* Size found, break out to check the
2667 final ']'. */
2668 prefixp->opcode |= size_bits << 4;
2669 break;
2672 /* Not a register. Then this must be "[rN+I]". */
2673 else if (cris_get_expression (cPP, &prefixp->expr))
2675 /* We've got offset with assign mode. Fill
2676 in the blanks and break out to match the
2677 final ']'. */
2678 prefixp->kind = PREFIX_BDAP_IMM;
2680 /* We tentatively put an opcode corresponding to
2681 a 32-bit operand here, although it may be
2682 relaxed when there's no PIC specifier for the
2683 operand. */
2684 prefixp->opcode
2685 = (BDAP_INDIR_OPCODE
2686 | (prefixp->base_reg_number << 12)
2687 | (AUTOINCR_BIT << 8)
2688 | (2 << 4)
2689 | REG_PC /* << 0 */);
2691 /* This can have a PIC suffix, specifying reloc
2692 type to use. */
2693 if (pic && **cPP == PIC_SUFFIX_CHAR)
2695 unsigned int relocsize;
2697 cris_get_pic_suffix (cPP, &prefixp->reloc,
2698 &prefixp->expr);
2700 /* Tweak the size of the immediate operand
2701 in the prefix opcode if it isn't what we
2702 set. */
2703 relocsize
2704 = cris_get_pic_reloc_size (prefixp->reloc);
2705 if (relocsize != 4)
2706 prefixp->opcode
2707 = ((prefixp->opcode & ~(3 << 4))
2708 | ((relocsize >> 1) << 4));
2710 break;
2712 else
2713 /* Neither register nor expression found, so
2714 this can't be a match. */
2715 return 0;
2717 /* Not "[rN+" but perhaps "[rN-"? */
2718 else if (**cPP == '-')
2720 /* We must have an offset with assign mode. */
2721 if (! cris_get_expression (cPP, &prefixp->expr))
2722 /* No expression, no match. */
2723 return 0;
2724 else
2726 /* We've got offset with assign mode. Fill
2727 in the blanks and break out to match the
2728 final ']'.
2730 Note that we don't allow a PIC suffix for an
2731 operand with a minus sign. */
2732 prefixp->kind = PREFIX_BDAP_IMM;
2733 break;
2736 else
2737 /* Neither '+' nor '-' after "[rN=rM". Lose. */
2738 return 0;
2740 default:
2741 /* Neither ']' nor '+' nor '=' after "[rN". Lose. */
2742 return 0;
2746 /* When we get here, we have a match and will just check the closing
2747 ']'. We can still fail though. */
2748 if (**cPP != ']')
2749 return 0;
2750 else
2752 /* Don't forget to consume the final ']'.
2753 Then return in glory. */
2754 (*cPP)++;
2755 return 1;
2758 /* No indirection. Perhaps a constant? */
2759 else if (cris_get_expression (cPP, imm_exprP))
2761 /* Expression found, this is immediate mode. */
2762 prefixp->kind = PREFIX_NONE;
2763 *is_autoincp = 1;
2764 *src_regnop = REG_PC;
2765 *imm_foundp = 1;
2767 /* This can have a PIC suffix, specifying reloc type to use. The
2768 caller must check that the reloc size matches the operand size. */
2769 if (pic && **cPP == PIC_SUFFIX_CHAR)
2770 cris_get_pic_suffix (cPP, &prefixp->reloc, imm_exprP);
2772 return 1;
2775 /* No luck today. */
2776 return 0;
2779 /* This function gets an indirect operand in a three-address operand
2780 combination from the string pointed out by *cPP. The pointer *cPP is
2781 advanced to the character following the indirect operand on success, or
2782 has an unspecified value on failure.
2784 cPP Pointer to pointer to string beginning
2785 with the operand
2787 prefixp Pointer to structure containing an
2788 instruction prefix
2790 Returns 1 iff a correct indirect operand is found. */
2792 static int
2793 get_3op_or_dip_prefix_op (char **cPP, struct cris_prefix *prefixp)
2795 int reg_number;
2797 if (**cPP != '[')
2798 /* We must have a '[' or it's a clean failure. */
2799 return 0;
2801 /* Eat the first '['. */
2802 (*cPP)++;
2804 if (**cPP == '[')
2806 /* A second '[', so this must be double-indirect mode. */
2807 (*cPP)++;
2808 prefixp->kind = PREFIX_DIP;
2809 prefixp->opcode = DIP_OPCODE;
2811 /* Get the register or fail entirely. */
2812 if (! get_gen_reg (cPP, &reg_number))
2813 return 0;
2814 else
2816 prefixp->opcode |= reg_number /* << 0 */ ;
2817 if (**cPP == '+')
2819 /* Since we found a '+', this must be double-indirect
2820 autoincrement mode. */
2821 (*cPP)++;
2822 prefixp->opcode |= AUTOINCR_BIT << 8;
2825 /* There's nothing particular to do, if this was a
2826 double-indirect *without* autoincrement. */
2829 /* Check the first ']'. The second one is checked at the end. */
2830 if (**cPP != ']')
2831 return 0;
2833 /* Eat the first ']', so we'll be looking at a second ']'. */
2834 (*cPP)++;
2836 /* No second '['. Then we should have a register here, making
2837 it "[rN". */
2838 else if (get_gen_reg (cPP, &prefixp->base_reg_number))
2840 /* This must be indexed or offset mode: "[rN+I]" or
2841 "[rN+rM.S]" or "[rN+[rM].S]" or "[rN+[rM+].S]". */
2842 if (**cPP == '+')
2844 int index_reg_number;
2846 (*cPP)++;
2848 if (**cPP == '[')
2850 /* This is "[rx+["... Expect a register next. */
2851 int size_bits;
2852 (*cPP)++;
2854 if (!get_gen_reg (cPP, &index_reg_number))
2855 return 0;
2857 prefixp->kind = PREFIX_BDAP;
2858 prefixp->opcode
2859 = (BDAP_INDIR_OPCODE
2860 + (prefixp->base_reg_number << 12)
2861 + index_reg_number);
2863 /* We've seen "[rx+[ry", so check if this is
2864 autoincrement. */
2865 if (**cPP == '+')
2867 /* Yep, now at "[rx+[ry+". */
2868 (*cPP)++;
2869 prefixp->opcode |= AUTOINCR_BIT << 8;
2871 /* If it wasn't autoincrement, we don't need to
2872 add anything. */
2874 /* Check a first closing ']': "[rx+[ry]" or
2875 "[rx+[ry+]". */
2876 if (**cPP != ']')
2877 return 0;
2878 (*cPP)++;
2880 /* Now expect a size modifier ".S". */
2881 if (! get_bwd_size_modifier (cPP, &size_bits))
2882 return 0;
2884 prefixp->opcode |= size_bits << 4;
2886 /* Ok, all interesting stuff has been seen:
2887 "[rx+[ry+].S" or "[rx+[ry].S". We only need to
2888 expect a final ']', which we'll do in a common
2889 closing session. */
2891 /* Seen "[rN+", but not a '[', so check if we have a
2892 register. */
2893 else if (get_gen_reg (cPP, &index_reg_number))
2895 /* This is indexed mode: "[rN+rM.S]" or
2896 "[rN+rM.S+]". */
2897 int size_bits;
2898 prefixp->kind = PREFIX_BIAP;
2899 prefixp->opcode
2900 = (BIAP_OPCODE
2901 | prefixp->base_reg_number /* << 0 */
2902 | (index_reg_number << 12));
2904 /* Consume the ".S". */
2905 if (! get_bwd_size_modifier (cPP, &size_bits))
2906 /* Missing size, so fail. */
2907 return 0;
2908 else
2909 /* Size found. Add that piece and drop down to
2910 the common checking of the closing ']'. */
2911 prefixp->opcode |= size_bits << 4;
2913 /* Seen "[rN+", but not a '[' or a register, so then
2914 it must be a constant "I".
2916 As a quality of implementation improvement, we check for a
2917 closing ']', like in an erroneous "[rN+]". If we don't,
2918 the expression parser will emit a confusing "bad
2919 expression" when it sees the ']', probably because it
2920 doesn't like seeing no expression. */
2921 else if (**cPP != ']' && cris_get_expression (cPP, &prefixp->expr))
2923 /* Expression found, so fill in the bits of offset
2924 mode and drop down to check the closing ']'. */
2925 prefixp->kind = PREFIX_BDAP_IMM;
2927 /* We tentatively put an opcode corresponding to a 32-bit
2928 operand here, although it may be relaxed when there's no
2929 PIC specifier for the operand. */
2930 prefixp->opcode
2931 = (BDAP_INDIR_OPCODE
2932 | (prefixp->base_reg_number << 12)
2933 | (AUTOINCR_BIT << 8)
2934 | (2 << 4)
2935 | REG_PC /* << 0 */);
2937 /* This can have a PIC suffix, specifying reloc type to use. */
2938 if (pic && **cPP == PIC_SUFFIX_CHAR)
2940 unsigned int relocsize;
2942 cris_get_pic_suffix (cPP, &prefixp->reloc, &prefixp->expr);
2944 /* Tweak the size of the immediate operand in the prefix
2945 opcode if it isn't what we set. */
2946 relocsize = cris_get_pic_reloc_size (prefixp->reloc);
2947 if (relocsize != 4)
2948 prefixp->opcode
2949 = ((prefixp->opcode & ~(3 << 4))
2950 | ((relocsize >> 1) << 4));
2953 else
2954 /* Nothing valid here: lose. */
2955 return 0;
2957 /* Seen "[rN" but no '+', so check if it's a '-'. */
2958 else if (**cPP == '-')
2960 /* Yep, we must have offset mode. */
2961 if (! cris_get_expression (cPP, &prefixp->expr))
2962 /* No expression, so we lose. */
2963 return 0;
2964 else
2966 /* Expression found to make this offset mode, so
2967 fill those bits and drop down to check the
2968 closing ']'.
2970 Note that we don't allow a PIC suffix for
2971 an operand with a minus sign like this. */
2972 prefixp->kind = PREFIX_BDAP_IMM;
2975 else
2977 /* We've seen "[rN", but not '+' or '-'; rather a ']'.
2978 Hmm. Normally this is a simple indirect mode that we
2979 shouldn't match, but if we expect ']', then we have a
2980 zero offset, so it can be a three-address-operand,
2981 like "[rN],rO,rP", thus offset mode.
2983 Don't eat the ']', that will be done in the closing
2984 ceremony. */
2985 prefixp->expr.X_op = O_constant;
2986 prefixp->expr.X_add_number = 0;
2987 prefixp->expr.X_add_symbol = NULL;
2988 prefixp->expr.X_op_symbol = NULL;
2989 prefixp->kind = PREFIX_BDAP_IMM;
2992 /* A '[', but no second '[', and no register. Check if we
2993 have an expression, making this "[I]" for a double-indirect
2994 prefix. */
2995 else if (cris_get_expression (cPP, &prefixp->expr))
2997 /* Expression found, the so called absolute mode for a
2998 double-indirect prefix on PC. */
2999 prefixp->kind = PREFIX_DIP;
3000 prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
3001 prefixp->reloc = BFD_RELOC_32;
3003 else
3004 /* Neither '[' nor register nor expression. We lose. */
3005 return 0;
3007 /* We get here as a closing ceremony to a successful match. We just
3008 need to check the closing ']'. */
3009 if (**cPP != ']')
3010 /* Oops. Close but no air-polluter. */
3011 return 0;
3013 /* Don't forget to consume that ']', before returning in glory. */
3014 (*cPP)++;
3015 return 1;
3018 /* Get an expression from the string pointed out by *cPP.
3019 The pointer *cPP is advanced to the character following the expression
3020 on a success, or retains its original value otherwise.
3022 cPP Pointer to pointer to string beginning with the expression.
3024 exprP Pointer to structure containing the expression.
3026 Return 1 iff a correct expression is found. */
3028 static int
3029 cris_get_expression (char **cPP, expressionS *exprP)
3031 char *saved_input_line_pointer;
3032 segT exp;
3034 /* The "expression" function expects to find an expression at the
3035 global variable input_line_pointer, so we have to save it to give
3036 the impression that we don't fiddle with global variables. */
3037 saved_input_line_pointer = input_line_pointer;
3038 input_line_pointer = *cPP;
3040 /* Avoid a common error, confusing addressing modes. Beware that the
3041 call to expression below does not signal that error; it treats []
3042 as parentheses, unless #define NEED_INDEX_OPERATOR in which case it
3043 gives them other confusing semantics rather than plain outlawing
3044 them, which is what we want. */
3045 if (*input_line_pointer == '[')
3047 input_line_pointer = saved_input_line_pointer;
3048 return 0;
3051 exp = expression (exprP);
3052 if (exprP->X_op == O_illegal || exprP->X_op == O_absent)
3054 input_line_pointer = saved_input_line_pointer;
3055 return 0;
3058 /* Everything seems to be fine, just restore the global
3059 input_line_pointer and say we're successful. */
3060 *cPP = input_line_pointer;
3061 input_line_pointer = saved_input_line_pointer;
3062 return 1;
3065 /* Get a sequence of flag characters from *spp. The pointer *cPP is
3066 advanced to the character following the expression. The flag
3067 characters are consecutive, no commas or spaces.
3069 cPP Pointer to pointer to string beginning with the expression.
3071 flagp Pointer to int to return the flags expression.
3073 Return 1 iff a correct flags expression is found. */
3075 static int
3076 get_flags (char **cPP, int *flagsp)
3078 for (;;)
3080 switch (**cPP)
3082 case 'd':
3083 case 'D':
3084 if (! cris_insn_ver_valid_for_arch (cris_ver_v0_3,
3085 cris_arch))
3086 return 0;
3087 *flagsp |= 0x80;
3088 break;
3090 case 'm':
3091 case 'M':
3092 if (! cris_insn_ver_valid_for_arch (cris_ver_v8_10,
3093 cris_arch))
3094 return 0;
3095 *flagsp |= 0x80;
3096 break;
3098 case 'e':
3099 case 'E':
3100 if (! cris_insn_ver_valid_for_arch (cris_ver_v0_3,
3101 cris_arch))
3102 return 0;
3103 *flagsp |= 0x40;
3104 break;
3106 case 'b':
3107 case 'B':
3108 if (! cris_insn_ver_valid_for_arch (cris_ver_v8_10,
3109 cris_arch))
3110 return 0;
3111 *flagsp |= 0x40;
3112 break;
3114 case 'p':
3115 case 'P':
3116 if (! cris_insn_ver_valid_for_arch (cris_ver_v32p,
3117 cris_arch))
3118 return 0;
3119 *flagsp |= 0x80;
3120 break;
3122 case 'u':
3123 case 'U':
3124 if (! cris_insn_ver_valid_for_arch (cris_ver_v32p,
3125 cris_arch))
3126 return 0;
3127 *flagsp |= 0x40;
3128 break;
3130 case 'i':
3131 case 'I':
3132 *flagsp |= 0x20;
3133 break;
3135 case 'x':
3136 case 'X':
3137 *flagsp |= 0x10;
3138 break;
3140 case 'n':
3141 case 'N':
3142 *flagsp |= 0x8;
3143 break;
3145 case 'z':
3146 case 'Z':
3147 *flagsp |= 0x4;
3148 break;
3150 case 'v':
3151 case 'V':
3152 *flagsp |= 0x2;
3153 break;
3155 case 'c':
3156 case 'C':
3157 *flagsp |= 1;
3158 break;
3160 default:
3161 /* We consider this successful if we stop at a comma or
3162 whitespace. Anything else, and we consider it a failure. */
3163 if (**cPP != ','
3164 && **cPP != 0
3165 && ! ISSPACE (**cPP))
3166 return 0;
3167 else
3168 return 1;
3171 /* Don't forget to consume each flag character. */
3172 (*cPP)++;
3176 /* Generate code and fixes for a BDAP prefix.
3177 For v32, this handles ADDOQ because thankfully the opcodes are the
3178 same.
3180 base_regno Int containing the base register number.
3182 exprP Pointer to structure containing the offset expression. */
3184 static void
3185 gen_bdap (int base_regno, expressionS *exprP)
3187 unsigned int opcode;
3188 char *opcodep;
3190 /* Put out the prefix opcode; assume quick immediate mode at first. */
3191 opcode = BDAP_QUICK_OPCODE | (base_regno << 12);
3192 opcodep = cris_insn_first_word_frag ();
3193 md_number_to_chars (opcodep, opcode, 2);
3195 if (exprP->X_op == O_constant)
3197 /* We have an absolute expression that we know the size of right
3198 now. */
3199 long int value;
3200 int size;
3202 value = exprP->X_add_number;
3203 if (value < -32768 || value > 32767)
3204 /* Outside range for a "word", make it a dword. */
3205 size = 2;
3206 else
3207 /* Assume "word" size. */
3208 size = 1;
3210 /* If this is a signed-byte value, we can fit it into the prefix
3211 insn itself. */
3212 if (value >= -128 && value <= 127)
3213 opcodep[0] = value;
3214 else
3216 /* This is a word or dword displacement, which will be put in a
3217 word or dword after the prefix. */
3218 char *p;
3220 opcodep[0] = BDAP_PC_LOW + (size << 4);
3221 opcodep[1] &= 0xF0;
3222 opcodep[1] |= BDAP_INCR_HIGH;
3223 p = frag_more (1 << size);
3224 md_number_to_chars (p, value, 1 << size);
3227 else
3229 /* Handle complex expressions. */
3230 valueT addvalue
3231 = SIMPLE_EXPR (exprP) ? exprP->X_add_number : 0;
3232 symbolS *sym
3233 = (SIMPLE_EXPR (exprP)
3234 ? exprP->X_add_symbol : make_expr_symbol (exprP));
3236 /* The expression is not defined yet but may become absolute. We
3237 make it a relocation to be relaxed. */
3238 frag_var (rs_machine_dependent, 4, 0,
3239 ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF),
3240 sym, addvalue, opcodep);
3244 /* Encode a branch displacement in the range -256..254 into the form used
3245 by CRIS conditional branch instructions.
3247 offset The displacement value in bytes. */
3249 static int
3250 branch_disp (int offset)
3252 int disp;
3254 /* Adjust all short branch offsets here. */
3255 if (cris_arch == arch_crisv32 || cris_arch == arch_cris_common_v10_v32)
3256 offset += 2;
3258 disp = offset & 0xFE;
3260 if (offset < 0)
3261 disp |= 1;
3263 return disp;
3266 /* Generate code and fixes for a 32-bit conditional branch instruction
3267 created by "extending" an existing 8-bit branch instruction.
3269 opcodep Pointer to the word containing the original 8-bit branch
3270 instruction.
3272 writep Pointer to "extension area" following the first instruction
3273 word.
3275 fragP Pointer to the frag containing the instruction.
3277 add_symP, Parts of the destination address expression.
3278 sub_symP,
3279 add_num. */
3281 static void
3282 gen_cond_branch_32 (char *opcodep, char *writep, fragS *fragP,
3283 symbolS *add_symP, symbolS *sub_symP, long int add_num)
3285 int nop_opcode;
3286 int opc_offset;
3287 int branch_offset;
3289 if (cris_arch == arch_crisv32)
3291 nop_opcode = NOP_OPCODE_V32;
3292 opc_offset = 10;
3293 branch_offset = -2 - 8;
3295 else
3297 nop_opcode = NOP_OPCODE;
3298 opc_offset = 8;
3299 branch_offset = -2 - 6;
3302 /* We should never get here for compatibility mode. */
3303 if (cris_arch == arch_cris_common_v10_v32)
3304 as_fatal (_("Calling gen_cond_branch_32 for .arch common_v10_v32\n"));
3306 if (warn_for_branch_expansion)
3307 as_warn_where (fragP->fr_file, fragP->fr_line,
3308 _("32-bit conditional branch generated"));
3310 /* Here, writep points to what will be opcodep + 2. First, we change
3311 the actual branch in opcodep[0] and opcodep[1], so that in the
3312 final insn, it will look like:
3313 opcodep+10: Bcc .-6
3315 This means we don't have to worry about changing the opcode or
3316 messing with the delay-slot instruction. So, we move it to last in
3317 the "extended" branch, and just change the displacement. Admittedly,
3318 it's not the optimal extended construct, but we should get this
3319 rarely enough that it shouldn't matter. */
3321 writep[opc_offset] = branch_disp (branch_offset);
3322 writep[opc_offset + 1] = opcodep[1];
3324 /* Then, we change the branch to an unconditional branch over the
3325 extended part, to the new location of the Bcc:
3326 opcodep: BA .+10
3327 opcodep+2: NOP
3329 Note that these two writes are to currently different locations,
3330 merged later. */
3332 md_number_to_chars (opcodep, BA_QUICK_OPCODE
3333 + (cris_arch == arch_crisv32 ? 12 : 8), 2);
3334 md_number_to_chars (writep, nop_opcode, 2);
3336 /* Then the extended thing, the 32-bit jump insn.
3337 opcodep+4: JUMP [PC+]
3338 or, in the PIC case,
3339 opcodep+4: ADD [PC+],PC. */
3341 md_number_to_chars (writep + 2,
3342 cris_arch == arch_crisv32
3343 ? BA_DWORD_OPCODE
3344 : (pic ? ADD_PC_INCR_OPCODE : JUMP_PC_INCR_OPCODE), 2);
3346 /* We have to fill in the actual value too.
3347 opcodep+6: .DWORD
3348 This is most probably an expression, but we can cope with an absolute
3349 value too. FIXME: Testcase needed with and without pic. */
3351 if (add_symP == NULL && sub_symP == NULL)
3353 /* An absolute address. */
3354 if (pic || cris_arch == arch_crisv32)
3355 fix_new (fragP, writep + 4 - fragP->fr_literal, 4,
3356 section_symbol (absolute_section),
3357 add_num
3358 + (cris_arch == arch_crisv32 ? 6 : 0),
3359 1, BFD_RELOC_32_PCREL);
3360 else
3361 md_number_to_chars (writep + 4, add_num, 4);
3363 else
3365 if (sub_symP != NULL)
3366 as_bad_where (fragP->fr_file, fragP->fr_line,
3367 _("Complex expression not supported"));
3369 /* Not absolute, we have to make it a frag for later evaluation. */
3370 fix_new (fragP, writep + 4 - fragP->fr_literal, 4, add_symP,
3371 add_num + (cris_arch == arch_crisv32 ? 6 : 0),
3372 pic || cris_arch == arch_crisv32 ? 1 : 0,
3373 pic || cris_arch == arch_crisv32
3374 ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
3377 if (cris_arch == arch_crisv32)
3378 /* Follow it with a "NOP" for CRISv32. */
3379 md_number_to_chars (writep + 8, NOP_OPCODE_V32, 2);
3382 /* Get the size of an immediate-reloc in bytes. Only valid for PIC
3383 relocs. */
3385 static unsigned int
3386 cris_get_pic_reloc_size (bfd_reloc_code_real_type reloc)
3388 return reloc == BFD_RELOC_CRIS_16_GOTPLT || reloc == BFD_RELOC_CRIS_16_GOT
3389 ? 2 : 4;
3392 /* Store a reloc type at *RELOCP corresponding to the PIC suffix at *CPP.
3393 Adjust *EXPRP with any addend found after the PIC suffix. */
3395 static void
3396 cris_get_pic_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
3397 expressionS *exprP)
3399 char *s = *cPP;
3400 unsigned int i;
3401 expressionS const_expr;
3403 const struct pic_suffixes_struct
3405 const char *const suffix;
3406 unsigned int len;
3407 bfd_reloc_code_real_type reloc;
3408 } pic_suffixes[] =
3410 #undef PICMAP
3411 #define PICMAP(s, r) {s, sizeof (s) - 1, r}
3412 /* Keep this in order with longest unambiguous prefix first. */
3413 PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT),
3414 PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT),
3415 PICMAP ("PLTG", BFD_RELOC_CRIS_32_PLT_GOTREL),
3416 PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL),
3417 PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL),
3418 PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT),
3419 PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT)
3422 /* We've already seen the ':', so consume it. */
3423 s++;
3425 for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++)
3427 if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0
3428 && ! is_part_of_name (s[pic_suffixes[i].len]))
3430 /* We have a match. Consume the suffix and set the relocation
3431 type. */
3432 s += pic_suffixes[i].len;
3434 /* There can be a constant term appended. If so, we will add it
3435 to *EXPRP. */
3436 if (*s == '+' || *s == '-')
3438 if (! cris_get_expression (&s, &const_expr))
3439 /* There was some kind of syntax error. Bail out. */
3440 break;
3442 /* Allow complex expressions as the constant part. It still
3443 has to be an assembly-time constant or there will be an
3444 error emitting the reloc. This makes the PIC qualifiers
3445 idempotent; foo:GOTOFF+32 == foo+32:GOTOFF. The former we
3446 recognize here; the latter is parsed in the incoming
3447 expression. */
3448 exprP->X_add_symbol = make_expr_symbol (exprP);
3449 exprP->X_op = O_add;
3450 exprP->X_add_number = 0;
3451 exprP->X_op_symbol = make_expr_symbol (&const_expr);
3454 *relocp = pic_suffixes[i].reloc;
3455 *cPP = s;
3456 return;
3460 /* No match. Don't consume anything; fall back and there will be a
3461 syntax error. */
3464 /* This *could* have been:
3466 Turn a string in input_line_pointer into a floating point constant
3467 of type TYPE, and store the appropriate bytes in *LITP. The number
3468 of LITTLENUMS emitted is stored in *SIZEP.
3470 type A character from FLTCHARS that describes what kind of
3471 floating-point number is wanted.
3473 litp A pointer to an array that the result should be stored in.
3475 sizep A pointer to an integer where the size of the result is stored.
3477 But we don't support floating point constants in assembly code *at all*,
3478 since it's suboptimal and just opens up bug opportunities. GCC emits
3479 the bit patterns as hex. All we could do here is to emit what GCC
3480 would have done in the first place. *Nobody* writes floating-point
3481 code as assembly code, but if they do, they should be able enough to
3482 find out the correct bit patterns and use them. */
3484 char *
3485 md_atof (int type ATTRIBUTE_UNUSED, char *litp ATTRIBUTE_UNUSED,
3486 int *sizep ATTRIBUTE_UNUSED)
3488 /* FIXME: Is this function mentioned in the internals.texi manual? If
3489 not, add it. */
3490 return _("Bad call to md_atof () - floating point formats are not supported");
3493 /* Turn a number as a fixS * into a series of bytes that represents the
3494 number on the target machine. The purpose of this procedure is the
3495 same as that of md_number_to_chars but this procedure is supposed to
3496 handle general bit field fixes and machine-dependent fixups.
3498 bufp Pointer to an array where the result should be stored.
3500 val The value to store.
3502 n The number of bytes in "val" that should be stored.
3504 fixP The fix to be applied to the bit field starting at bufp.
3506 seg The segment containing this number. */
3508 static void
3509 cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
3511 segT sym_seg;
3513 know (n <= 4);
3514 know (fixP);
3516 /* We put the relative "vma" for the other segment for inter-segment
3517 relocations in the object data to stay binary "compatible" (with an
3518 uninteresting old version) for the relocation.
3519 Maybe delete some day. */
3520 if (fixP->fx_addsy
3521 && (sym_seg = S_GET_SEGMENT (fixP->fx_addsy)) != seg)
3522 val += sym_seg->vma;
3524 if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
3525 switch (fixP->fx_r_type)
3527 /* These must be fully resolved when getting here. */
3528 case BFD_RELOC_16_PCREL:
3529 case BFD_RELOC_8_PCREL:
3530 as_bad_where (fixP->fx_file, fixP->fx_line,
3531 _("PC-relative relocation must be trivially resolved"));
3532 default:
3536 /* Only do this for old-arch binaries. */
3537 if (cris_arch != arch_cris_any_v0_v10
3538 && (fixP->fx_addsy != NULL || fixP->fx_pcrel))
3539 return;
3541 switch (fixP->fx_r_type)
3543 /* Ditto here, we put the addend into the object code as
3544 well as the reloc addend. Keep it that way for now, to simplify
3545 regression tests on the object file contents. FIXME: Seems
3546 uninteresting now that we have a test suite. */
3548 case BFD_RELOC_CRIS_16_GOT:
3549 case BFD_RELOC_CRIS_32_GOT:
3550 case BFD_RELOC_CRIS_32_GOTREL:
3551 case BFD_RELOC_CRIS_16_GOTPLT:
3552 case BFD_RELOC_CRIS_32_GOTPLT:
3553 case BFD_RELOC_CRIS_32_PLT_GOTREL:
3554 case BFD_RELOC_CRIS_32_PLT_PCREL:
3555 /* We don't want to put in any kind of non-zero bits in the data
3556 being relocated for these. */
3557 break;
3559 case BFD_RELOC_32_PCREL:
3560 /* If this one isn't fully resolved, we don't want to put anything
3561 in the object. */
3562 if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
3563 break;
3565 /* Fall through. */
3566 case BFD_RELOC_32:
3567 /* No use having warnings here, since most hosts have a 32-bit type
3568 for "long" (which will probably change soon, now that I wrote
3569 this). */
3570 bufp[3] = (val >> 24) & 0xFF;
3571 bufp[2] = (val >> 16) & 0xFF;
3572 bufp[1] = (val >> 8) & 0xFF;
3573 bufp[0] = val & 0xFF;
3574 break;
3576 /* FIXME: The 16 and 8-bit cases should have a way to check
3577 whether a signed or unsigned (or any signedness) number is
3578 accepted. */
3580 case BFD_RELOC_16:
3581 case BFD_RELOC_16_PCREL:
3582 if (val > 0xffff || val < -32768)
3583 as_bad_where (fixP->fx_file, fixP->fx_line,
3584 _("Value not in 16 bit range: %ld"), val);
3585 if (! fixP->fx_addsy)
3587 bufp[1] = (val >> 8) & 0xFF;
3588 bufp[0] = val & 0xFF;
3590 break;
3592 case BFD_RELOC_CRIS_SIGNED_16:
3593 if (val > 32767 || val < -32768)
3594 as_bad_where (fixP->fx_file, fixP->fx_line,
3595 _("Value not in 16 bit signed range: %ld"), val);
3596 if (! fixP->fx_addsy)
3598 bufp[1] = (val >> 8) & 0xFF;
3599 bufp[0] = val & 0xFF;
3601 break;
3603 case BFD_RELOC_8:
3604 case BFD_RELOC_8_PCREL:
3605 if (val > 255 || val < -128)
3606 as_bad_where (fixP->fx_file, fixP->fx_line, _("Value not in 8 bit range: %ld"), val);
3607 if (! fixP->fx_addsy)
3608 bufp[0] = val & 0xFF;
3609 break;
3611 case BFD_RELOC_CRIS_SIGNED_8:
3612 if (val > 127 || val < -128)
3613 as_bad_where (fixP->fx_file, fixP->fx_line,
3614 _("Value not in 8 bit signed range: %ld"), val);
3615 if (! fixP->fx_addsy)
3616 bufp[0] = val & 0xFF;
3617 break;
3619 case BFD_RELOC_CRIS_LAPCQ_OFFSET:
3620 /* FIXME: Test-cases for out-of-range values. Probably also need
3621 to use as_bad_where. */
3622 case BFD_RELOC_CRIS_UNSIGNED_4:
3623 if (val > 15 || val < 0)
3624 as_bad_where (fixP->fx_file, fixP->fx_line,
3625 _("Value not in 4 bit unsigned range: %ld"), val);
3626 if (! fixP->fx_addsy)
3627 bufp[0] |= val & 0x0F;
3628 break;
3630 case BFD_RELOC_CRIS_UNSIGNED_5:
3631 if (val > 31 || val < 0)
3632 as_bad_where (fixP->fx_file, fixP->fx_line,
3633 _("Value not in 5 bit unsigned range: %ld"), val);
3634 if (! fixP->fx_addsy)
3635 bufp[0] |= val & 0x1F;
3636 break;
3638 case BFD_RELOC_CRIS_SIGNED_6:
3639 if (val > 31 || val < -32)
3640 as_bad_where (fixP->fx_file, fixP->fx_line,
3641 _("Value not in 6 bit range: %ld"), val);
3642 if (! fixP->fx_addsy)
3643 bufp[0] |= val & 0x3F;
3644 break;
3646 case BFD_RELOC_CRIS_UNSIGNED_6:
3647 if (val > 63 || val < 0)
3648 as_bad_where (fixP->fx_file, fixP->fx_line,
3649 _("Value not in 6 bit unsigned range: %ld"), val);
3650 if (! fixP->fx_addsy)
3651 bufp[0] |= val & 0x3F;
3652 break;
3654 case BFD_RELOC_CRIS_BDISP8:
3655 if (! fixP->fx_addsy)
3656 bufp[0] = branch_disp (val);
3657 break;
3659 case BFD_RELOC_NONE:
3660 /* May actually happen automatically. For example at broken
3661 words, if the word turns out not to be broken.
3662 FIXME: When? Which testcase? */
3663 if (! fixP->fx_addsy)
3664 md_number_to_chars (bufp, val, n);
3665 break;
3667 case BFD_RELOC_VTABLE_INHERIT:
3668 /* This borrowed from tc-ppc.c on a whim. */
3669 if (fixP->fx_addsy
3670 && !S_IS_DEFINED (fixP->fx_addsy)
3671 && !S_IS_WEAK (fixP->fx_addsy))
3672 S_SET_WEAK (fixP->fx_addsy);
3673 /* Fall through. */
3675 case BFD_RELOC_VTABLE_ENTRY:
3676 fixP->fx_done = 0;
3677 break;
3679 default:
3680 BAD_CASE (fixP->fx_r_type);
3684 /* Processes machine-dependent command line options. Called once for
3685 each option on the command line that the machine-independent part of
3686 GAS does not understand. */
3689 md_parse_option (int arg, char *argp ATTRIBUTE_UNUSED)
3691 switch (arg)
3693 case 'H':
3694 case 'h':
3695 printf (_("Please use --help to see usage and options for this assembler.\n"));
3696 md_show_usage (stdout);
3697 exit (EXIT_SUCCESS);
3699 case 'N':
3700 warn_for_branch_expansion = 1;
3701 break;
3703 case OPTION_NO_US:
3704 demand_register_prefix = TRUE;
3706 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
3707 as_bad (_("--no-underscore is invalid with a.out format"));
3708 else
3709 symbols_have_leading_underscore = FALSE;
3710 break;
3712 case OPTION_US:
3713 demand_register_prefix = FALSE;
3714 symbols_have_leading_underscore = TRUE;
3715 break;
3717 case OPTION_PIC:
3718 pic = TRUE;
3719 break;
3721 case OPTION_ARCH:
3723 char *str = argp;
3724 enum cris_archs argarch = cris_arch_from_string (&str);
3726 if (argarch == arch_cris_unknown)
3727 as_bad (_("invalid <arch> in --march=<arch>: %s"), argp);
3728 else
3729 cris_arch = argarch;
3731 if (argarch == arch_crisv32)
3733 err_for_dangerous_mul_placement = 0;
3734 md_long_jump_size = crisv32_long_jump_size;
3736 else
3737 md_long_jump_size = cris_any_v0_v10_long_jump_size;
3739 break;
3741 case OPTION_MULBUG_ABORT_OFF:
3742 err_for_dangerous_mul_placement = 0;
3743 break;
3745 case OPTION_MULBUG_ABORT_ON:
3746 err_for_dangerous_mul_placement = 1;
3747 break;
3749 default:
3750 return 0;
3753 return 1;
3756 /* Round up a section size to the appropriate boundary. */
3757 valueT
3758 md_section_align (segT segment, valueT size)
3760 /* Round all sects to multiple of 4, except the bss section, which
3761 we'll round to word-size.
3763 FIXME: Check if this really matters. All sections should be
3764 rounded up, and all sections should (optionally) be assumed to be
3765 dword-aligned, it's just that there is actual usage of linking to a
3766 multiple of two. */
3767 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
3769 if (segment == bss_section)
3770 return (size + 1) & ~1;
3771 return (size + 3) & ~3;
3773 else
3775 /* FIXME: Is this wanted? It matches the testsuite, but that's not
3776 really a valid reason. */
3777 if (segment == text_section)
3778 return (size + 3) & ~3;
3781 return size;
3784 /* Generate a machine-dependent relocation. */
3785 arelent *
3786 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
3788 arelent *relP;
3789 bfd_reloc_code_real_type code;
3791 switch (fixP->fx_r_type)
3793 case BFD_RELOC_CRIS_SIGNED_8:
3794 code = BFD_RELOC_8;
3795 break;
3797 case BFD_RELOC_CRIS_SIGNED_16:
3798 code = BFD_RELOC_16;
3799 break;
3801 case BFD_RELOC_CRIS_16_GOT:
3802 case BFD_RELOC_CRIS_32_GOT:
3803 case BFD_RELOC_CRIS_16_GOTPLT:
3804 case BFD_RELOC_CRIS_32_GOTPLT:
3805 case BFD_RELOC_CRIS_32_GOTREL:
3806 case BFD_RELOC_CRIS_32_PLT_GOTREL:
3807 case BFD_RELOC_CRIS_32_PLT_PCREL:
3808 case BFD_RELOC_32:
3809 case BFD_RELOC_32_PCREL:
3810 case BFD_RELOC_16:
3811 case BFD_RELOC_8:
3812 case BFD_RELOC_VTABLE_INHERIT:
3813 case BFD_RELOC_VTABLE_ENTRY:
3814 case BFD_RELOC_CRIS_UNSIGNED_8:
3815 case BFD_RELOC_CRIS_UNSIGNED_16:
3816 case BFD_RELOC_CRIS_LAPCQ_OFFSET:
3817 code = fixP->fx_r_type;
3818 break;
3819 default:
3820 as_bad_where (fixP->fx_file, fixP->fx_line,
3821 _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant"));
3822 return 0;
3825 relP = (arelent *) xmalloc (sizeof (arelent));
3826 assert (relP != 0);
3827 relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3828 *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
3829 relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
3831 relP->addend = fixP->fx_offset;
3833 /* This is the standard place for KLUDGEs to work around bugs in
3834 bfd_install_relocation (first such note in the documentation
3835 appears with binutils-2.8).
3837 That function bfd_install_relocation does the wrong thing with
3838 putting stuff into the addend of a reloc (it should stay out) for a
3839 weak symbol. The really bad thing is that it adds the
3840 "segment-relative offset" of the symbol into the reloc. In this
3841 case, the reloc should instead be relative to the symbol with no
3842 other offset than the assembly code shows; and since the symbol is
3843 weak, any local definition should be ignored until link time (or
3844 thereafter).
3845 To wit: weaksym+42 should be weaksym+42 in the reloc,
3846 not weaksym+(offset_from_segment_of_local_weaksym_definition)
3848 To "work around" this, we subtract the segment-relative offset of
3849 "known" weak symbols. This evens out the extra offset.
3851 That happens for a.out but not for ELF, since for ELF,
3852 bfd_install_relocation uses the "special function" field of the
3853 howto, and does not execute the code that needs to be undone. */
3855 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
3856 && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
3857 && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
3859 relP->addend -= S_GET_VALUE (fixP->fx_addsy);
3862 relP->howto = bfd_reloc_type_lookup (stdoutput, code);
3863 if (! relP->howto)
3865 const char *name;
3867 name = S_GET_NAME (fixP->fx_addsy);
3868 if (name == NULL)
3869 name = _("<unknown>");
3870 as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
3871 name, bfd_get_reloc_code_name (code));
3874 return relP;
3877 /* Machine-dependent usage-output. */
3879 void
3880 md_show_usage (FILE *stream)
3882 /* The messages are formatted to line up with the generic options. */
3883 fprintf (stream, _("CRIS-specific options:\n"));
3884 fprintf (stream, "%s",
3885 _(" -h, -H Don't execute, print this help text. Deprecated.\n"));
3886 fprintf (stream, "%s",
3887 _(" -N Warn when branches are expanded to jumps.\n"));
3888 fprintf (stream, "%s",
3889 _(" --underscore User symbols are normally prepended with underscore.\n"));
3890 fprintf (stream, "%s",
3891 _(" Registers will not need any prefix.\n"));
3892 fprintf (stream, "%s",
3893 _(" --no-underscore User symbols do not have any prefix.\n"));
3894 fprintf (stream, "%s",
3895 _(" Registers will require a `$'-prefix.\n"));
3896 fprintf (stream, "%s",
3897 _(" --pic Enable generation of position-independent code.\n"));
3898 fprintf (stream, "%s",
3899 _(" --march=<arch> Generate code for <arch>. Valid choices for <arch>\n\
3900 are v0_v10, v10, v32 and common_v10_v32.\n"));
3903 /* Apply a fixS (fixup of an instruction or data that we didn't have
3904 enough info to complete immediately) to the data in a frag. */
3906 void
3907 md_apply_fix3 (fixS *fixP, valueT *valP, segT seg)
3909 /* This assignment truncates upper bits if valueT is 64 bits (as with
3910 --enable-64-bit-bfd), which is fine here, though we cast to avoid
3911 any compiler warnings. */
3912 long val = (long) *valP;
3913 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3915 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
3916 fixP->fx_done = 1;
3918 if (fixP->fx_bit_fixP || fixP->fx_im_disp != 0)
3920 as_bad_where (fixP->fx_file, fixP->fx_line, _("Invalid relocation"));
3921 fixP->fx_done = 1;
3923 else
3925 /* We can't actually support subtracting a symbol. */
3926 if (fixP->fx_subsy != (symbolS *) NULL)
3927 as_bad_where (fixP->fx_file, fixP->fx_line,
3928 _("expression too complex"));
3930 /* This operand-type is scaled. */
3931 if (fixP->fx_r_type == BFD_RELOC_CRIS_LAPCQ_OFFSET)
3932 val /= 2;
3933 cris_number_to_imm (buf, val, fixP->fx_size, fixP, seg);
3937 /* All relocations are relative to the location just after the fixup;
3938 the address of the fixup plus its size. */
3940 long
3941 md_pcrel_from (fixS *fixP)
3943 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
3945 /* FIXME: We get here only at the end of assembly, when X in ".-X" is
3946 still unknown. Since we don't have pc-relative relocations in a.out,
3947 this is invalid. What to do if anything for a.out, is to add
3948 pc-relative relocations everywhere including the elinux program
3949 loader. For ELF, allow straight-forward PC-relative relocations,
3950 which are always relative to the location after the relocation. */
3951 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
3952 || (fixP->fx_r_type != BFD_RELOC_8_PCREL
3953 && fixP->fx_r_type != BFD_RELOC_16_PCREL
3954 && fixP->fx_r_type != BFD_RELOC_32_PCREL
3955 && fixP->fx_r_type != BFD_RELOC_CRIS_LAPCQ_OFFSET))
3956 as_bad_where (fixP->fx_file, fixP->fx_line,
3957 _("Invalid pc-relative relocation"));
3958 return fixP->fx_size + addr;
3961 /* We have no need to give defaults for symbol-values. */
3962 symbolS *
3963 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
3965 return 0;
3968 /* If this function returns non-zero, it prevents the relocation
3969 against symbol(s) in the FIXP from being replaced with relocations
3970 against section symbols, and guarantees that a relocation will be
3971 emitted even when the value can be resolved locally. */
3973 md_cris_force_relocation (struct fix *fixp)
3975 switch (fixp->fx_r_type)
3977 case BFD_RELOC_CRIS_16_GOT:
3978 case BFD_RELOC_CRIS_32_GOT:
3979 case BFD_RELOC_CRIS_16_GOTPLT:
3980 case BFD_RELOC_CRIS_32_GOTPLT:
3981 case BFD_RELOC_CRIS_32_GOTREL:
3982 case BFD_RELOC_CRIS_32_PLT_GOTREL:
3983 case BFD_RELOC_CRIS_32_PLT_PCREL:
3984 return 1;
3985 default:
3989 return generic_force_reloc (fixp);
3992 /* Check and emit error if broken-word handling has failed to fix up a
3993 case-table. This is called from write.c, after doing everything it
3994 knows about how to handle broken words. */
3996 void
3997 tc_cris_check_adjusted_broken_word (offsetT new_offset, struct broken_word *brokwP)
3999 if (new_offset > 32767 || new_offset < -32768)
4000 /* We really want a genuine error, not a warning, so make it one. */
4001 as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line,
4002 _("Adjusted signed .word (%ld) overflows: `switch'-statement too large."),
4003 (long) new_offset);
4006 /* Make a leading REGISTER_PREFIX_CHAR mandatory for all registers. */
4008 static void
4009 cris_force_reg_prefix (void)
4011 demand_register_prefix = TRUE;
4014 /* Do not demand a leading REGISTER_PREFIX_CHAR for all registers. */
4016 static void
4017 cris_relax_reg_prefix (void)
4019 demand_register_prefix = FALSE;
4022 /* Adjust for having a leading '_' on all user symbols. */
4024 static void
4025 cris_sym_leading_underscore (void)
4027 /* We can't really do anything more than assert that what the program
4028 thinks symbol starts with agrees with the command-line options, since
4029 the bfd is already created. */
4031 if (!symbols_have_leading_underscore)
4032 as_bad (_(".syntax %s requires command-line option `--underscore'"),
4033 SYNTAX_USER_SYM_LEADING_UNDERSCORE);
4036 /* Adjust for not having any particular prefix on user symbols. */
4038 static void cris_sym_no_leading_underscore (void)
4040 if (symbols_have_leading_underscore)
4041 as_bad (_(".syntax %s requires command-line option `--no-underscore'"),
4042 SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE);
4045 /* Handle the .syntax pseudo, which takes an argument that decides what
4046 syntax the assembly code has. */
4048 static void
4049 s_syntax (int ignore ATTRIBUTE_UNUSED)
4051 static const struct syntaxes
4053 const char *const operand;
4054 void (*fn) (void);
4055 } syntax_table[] =
4056 {{SYNTAX_ENFORCE_REG_PREFIX, cris_force_reg_prefix},
4057 {SYNTAX_RELAX_REG_PREFIX, cris_relax_reg_prefix},
4058 {SYNTAX_USER_SYM_LEADING_UNDERSCORE, cris_sym_leading_underscore},
4059 {SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE, cris_sym_no_leading_underscore}};
4061 const struct syntaxes *sp;
4063 for (sp = syntax_table;
4064 sp < syntax_table + sizeof (syntax_table) / sizeof (syntax_table[0]);
4065 sp++)
4067 if (strncmp (input_line_pointer, sp->operand,
4068 strlen (sp->operand)) == 0)
4070 (sp->fn) ();
4072 input_line_pointer += strlen (sp->operand);
4073 demand_empty_rest_of_line ();
4074 return;
4078 as_bad (_("Unknown .syntax operand"));
4081 /* Wrapper for dwarf2_directive_file to emit error if this is seen when
4082 not emitting ELF. */
4084 static void
4085 s_cris_file (int dummy)
4087 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
4088 as_bad (_("Pseudodirective .file is only valid when generating ELF"));
4089 else
4090 dwarf2_directive_file (dummy);
4093 /* Wrapper for dwarf2_directive_loc to emit error if this is seen when not
4094 emitting ELF. */
4096 static void
4097 s_cris_loc (int dummy)
4099 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
4100 as_bad (_("Pseudodirective .loc is only valid when generating ELF"));
4101 else
4102 dwarf2_directive_loc (dummy);
4105 /* Translate a <arch> string (as common to --march=<arch> and .arch <arch>)
4106 into an enum. If the string *STR is recognized, *STR is updated to point
4107 to the end of the string. If the string is not recognized,
4108 arch_cris_unknown is returned. */
4110 static enum cris_archs
4111 cris_arch_from_string (char **str)
4113 static const struct cris_arch_struct
4115 const char *const name;
4116 enum cris_archs arch;
4117 } arch_table[] =
4118 /* Keep in order longest-first for choices where one is a prefix
4119 of another. */
4120 {{"v0_v10", arch_cris_any_v0_v10},
4121 {"v10", arch_crisv10},
4122 {"v32", arch_crisv32},
4123 {"common_v10_v32", arch_cris_common_v10_v32}};
4125 const struct cris_arch_struct *ap;
4127 for (ap = arch_table;
4128 ap < arch_table + sizeof (arch_table) / sizeof (arch_table[0]);
4129 ap++)
4131 int len = strlen (ap->name);
4133 if (strncmp (*str, ap->name, len) == 0
4134 && (str[0][len] == 0 || ISSPACE (str[0][len])))
4136 *str += strlen (ap->name);
4137 return ap->arch;
4141 return arch_cris_unknown;
4144 /* Return nonzero if architecture version ARCH matches version range in
4145 IVER. */
4147 static int
4148 cris_insn_ver_valid_for_arch (enum cris_insn_version_usage iver,
4149 enum cris_archs arch)
4151 switch (arch)
4153 case arch_cris_any_v0_v10:
4154 return
4155 (iver == cris_ver_version_all
4156 || iver == cris_ver_warning
4157 || iver == cris_ver_v0_3
4158 || iver == cris_ver_v3p
4159 || iver == cris_ver_v0_10
4160 || iver == cris_ver_sim_v0_10
4161 || iver == cris_ver_v3_10
4162 || iver == cris_ver_v8
4163 || iver == cris_ver_v8p
4164 || iver == cris_ver_v8_10
4165 || iver == cris_ver_v10
4166 || iver == cris_ver_v10p);
4168 case arch_crisv32:
4169 return
4170 (iver == cris_ver_version_all
4171 || iver == cris_ver_v3p
4172 || iver == cris_ver_v8p
4173 || iver == cris_ver_v10p
4174 || iver == cris_ver_v32p);
4176 case arch_cris_common_v10_v32:
4177 return
4178 (iver == cris_ver_version_all
4179 || iver == cris_ver_v3p
4180 || iver == cris_ver_v8p
4181 || iver == cris_ver_v10p);
4183 case arch_crisv0:
4184 return
4185 (iver == cris_ver_version_all
4186 || iver == cris_ver_v0_3
4187 || iver == cris_ver_v0_10
4188 || iver == cris_ver_sim_v0_10);
4190 case arch_crisv3:
4191 return
4192 (iver == cris_ver_version_all
4193 || iver == cris_ver_v0_3
4194 || iver == cris_ver_v3p
4195 || iver == cris_ver_v0_10
4196 || iver == cris_ver_sim_v0_10
4197 || iver == cris_ver_v3_10);
4199 case arch_crisv8:
4200 return
4201 (iver == cris_ver_version_all
4202 || iver == cris_ver_v3p
4203 || iver == cris_ver_v0_10
4204 || iver == cris_ver_sim_v0_10
4205 || iver == cris_ver_v3_10
4206 || iver == cris_ver_v8
4207 || iver == cris_ver_v8p
4208 || iver == cris_ver_v8_10);
4210 case arch_crisv10:
4211 return
4212 (iver == cris_ver_version_all
4213 || iver == cris_ver_v3p
4214 || iver == cris_ver_v0_10
4215 || iver == cris_ver_sim_v0_10
4216 || iver == cris_ver_v3_10
4217 || iver == cris_ver_v8p
4218 || iver == cris_ver_v8_10
4219 || iver == cris_ver_v10
4220 || iver == cris_ver_v10p);
4222 default:
4223 BAD_CASE (arch);
4227 /* Assert that the .arch ARCHCHOICE1 is compatible with the specified or
4228 default --march=<ARCHCHOICE2> option. */
4230 static void
4231 s_cris_arch (int dummy ATTRIBUTE_UNUSED)
4233 /* Right now we take the easy route and check for sameness. It's not
4234 obvious that allowing e.g. --march=v32 and .arch common_v0_v32
4235 would be more useful than confusing, implementation-wise and
4236 user-wise. */
4238 char *str = input_line_pointer;
4239 enum cris_archs arch = cris_arch_from_string (&str);
4241 if (arch == arch_cris_unknown)
4243 as_bad (_("unknown operand to .arch"));
4245 /* For this one, str does not reflect the end of the operand,
4246 since there was no matching arch. Skip it manually; skip
4247 things that can be part of a word (a name). */
4248 while (is_part_of_name (*str))
4249 str++;
4251 else if (arch != cris_arch)
4252 as_bad (_(".arch <arch> requires a matching --march=... option"));
4254 input_line_pointer = str;
4255 demand_empty_rest_of_line ();
4256 return;
4260 * Local variables:
4261 * eval: (c-set-style "gnu")
4262 * indent-tabs-mode: t
4263 * End: