1 /* tc-cris.c -- Assembler code for the CRIS CPU core.
2 Copyright (C) 2000 Free Software Foundation, Inc.
4 Contributed by Axis Communications AB, Lund, Sweden.
5 Originally written for GAS 1.38.1 by Mikael Asker.
6 Updated, BFDized and GNUified 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)
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, 59 Temple Place - Suite 330, Boston,
23 MA 02111-1307, USA. */
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
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 /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
47 Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL. */
50 CRIS_INSN_NORMAL
, CRIS_INSN_NONE
, CRIS_INSN_BRANCH
53 /* An instruction will have one of these prefixes.
54 Although the same bit-pattern, we handle BDAP with an immediate
55 expression (eventually quick or [pc+]) different from when we only have
56 register expressions. */
59 PREFIX_NONE
, PREFIX_BDAP_IMM
, PREFIX_BDAP
, PREFIX_BIAP
, PREFIX_DIP
,
63 /* The prefix for an instruction. */
66 enum prefix_kind kind
;
70 /* There might be an expression to be evaluated, like I in [rN+I]. */
73 /* If there's an expression, we might need a relocation. Here's the
74 type of what relocation to start relaxaton with.
75 The relocation is assumed to start immediately after the prefix insn,
76 so we don't provide an offset. */
77 enum bfd_reloc_code_real reloc
;
80 /* The description of the instruction being assembled. */
81 struct cris_instruction
83 /* If CRIS_INSN_NONE, then this insn is of zero length. */
84 enum cris_insn_kind insn_type
;
86 /* If a special register was mentioned, this is its description, else
88 const struct cris_spec_reg
*spec_reg
;
92 /* An insn may have at most one expression; theoretically there could be
93 another in its prefix (but I don't see how that could happen). */
96 /* The expression might need a relocation. Here's one to start
98 enum bfd_reloc_code_real reloc
;
100 /* The size in bytes of an immediate expression, or zero in
105 static void cris_process_instruction
PARAMS ((char *,
106 struct cris_instruction
*,
107 struct cris_prefix
*));
108 static int get_bwd_size_modifier
PARAMS ((char **, int *));
109 static int get_bw_size_modifier
PARAMS ((char **, int *));
110 static int get_gen_reg
PARAMS ((char **, int *));
111 static int get_spec_reg
PARAMS ((char **,
112 const struct cris_spec_reg
**));
113 static int get_autoinc_prefix_or_indir_op
PARAMS ((char **,
114 struct cris_prefix
*,
117 static int get_3op_or_dip_prefix_op
PARAMS ((char **,
118 struct cris_prefix
*));
119 static int cris_get_expression
PARAMS ((char **, expressionS
*));
120 static int get_flags
PARAMS ((char **, int *));
121 static void gen_bdap
PARAMS ((int, expressionS
*));
122 static int branch_disp
PARAMS ((int));
123 static void gen_cond_branch_32
PARAMS ((char *, char *, fragS
*,
124 symbolS
*, symbolS
*, long int));
125 static void cris_number_to_imm
PARAMS ((char *, long, int, fixS
*));
126 static void cris_create_short_jump
PARAMS ((char *, addressT
, addressT
,
127 fragS
*, symbolS
*));
128 static void s_syntax
PARAMS ((int));
129 static void s_cris_file
PARAMS ((int));
130 static void s_cris_loc
PARAMS ((int));
132 /* All the .syntax functions. */
133 static void cris_force_reg_prefix
PARAMS ((void));
134 static void cris_relax_reg_prefix
PARAMS ((void));
135 static void cris_sym_leading_underscore
PARAMS ((void));
136 static void cris_sym_no_leading_underscore
PARAMS ((void));
138 /* Handle to the opcode hash table. */
139 static struct hash_control
*op_hash
= NULL
;
141 /* Whether we demand that registers have a `$' prefix. Default here. */
142 static boolean demand_register_prefix
= false;
144 /* Whether global user symbols have a leading underscore. Default here. */
145 static boolean symbols_have_leading_underscore
= true;
147 const pseudo_typeS md_pseudo_table
[] =
150 {"syntax", s_syntax
, 0},
151 {"file", s_cris_file
, 0},
152 {"loc", s_cris_loc
, 0},
156 static int warn_for_branch_expansion
= 0;
158 const char cris_comment_chars
[] = ";";
160 /* This array holds the chars that only start a comment at the beginning of
161 a line. If the line seems to have the form '# 123 filename'
162 .line and .file directives will appear in the pre-processed output. */
163 /* Note that input_file.c hand-checks for '#' at the beginning of the
164 first line of the input file. This is because the compiler outputs
165 #NO_APP at the beginning of its output. */
166 /* Also note that slash-star will always start a comment. */
167 const char line_comment_chars
[] = "#";
168 const char line_separator_chars
[] = "@";
170 /* Now all floating point support is shut off. See md_atof. */
171 const char EXP_CHARS
[] = "";
172 const char FLT_CHARS
[] = "";
174 /* For CRIS, we encode the relax_substateTs (in e.g. fr_substate) as:
176 ---/ /--+-----------------+-----------------+-----------------+
177 | what state ? | how long ? |
178 ---/ /--+-----------------+-----------------+-----------------+
180 The "how long" bits are 00 = byte, 01 = word, 10 = dword (long).
181 This is a Un*x convention.
182 Not all lengths are legit for a given value of (what state).
184 Groups for CRIS address relaxing:
187 length: byte, word, 10-byte expansion
190 length: byte, word, dword */
192 #define STATE_CONDITIONAL_BRANCH (1)
193 #define STATE_BASE_PLUS_DISP_PREFIX (2)
195 #define STATE_LENGTH_MASK (3)
196 #define STATE_BYTE (0)
197 #define STATE_WORD (1)
198 #define STATE_DWORD (2)
199 /* Symbol undefined. */
200 #define STATE_UNDF (3)
201 #define STATE_MAX_LENGTH (3)
203 /* These displacements are relative to the adress following the opcode
204 word of the instruction. The first letter is Byte, Word. The 2nd
205 letter is Forward, Backward. */
207 #define BRANCH_BF ( 254)
208 #define BRANCH_BB (-256)
209 #define BRANCH_WF (2 + 32767)
210 #define BRANCH_WB (2 + -32768)
212 #define BDAP_BF ( 127)
213 #define BDAP_BB (-128)
214 #define BDAP_WF ( 32767)
215 #define BDAP_WB (-32768)
217 #define ENCODE_RELAX(what, length) (((what) << 2) + (length))
219 const relax_typeS md_cris_relax_table
[] =
221 /* Error sentinel (0, 0). */
234 {BRANCH_BF
, BRANCH_BB
, 0, ENCODE_RELAX (1, 1)},
236 /* Bcc [PC+] (1, 1). */
237 {BRANCH_WF
, BRANCH_WB
, 2, ENCODE_RELAX (1, 2)},
239 /* BEXT/BWF, BA, JUMP (external), JUMP (always), Bnot_cc, JUMP (default)
247 {BDAP_BF
, BDAP_BB
, 0, ENCODE_RELAX (2, 1)},
249 /* BDAP.[bw] [PC+] (2, 1). */
250 {BDAP_WF
, BDAP_WB
, 2, ENCODE_RELAX (2, 2)},
252 /* BDAP.d [PC+] (2, 2). */
265 /* Target-specific multicharacter options, not const-declared at usage
266 in 2.9.1 and CVS of 2000-02-16. */
267 struct option md_longopts
[] =
269 #define OPTION_NO_US (OPTION_MD_BASE + 0)
270 {"no-underscore", no_argument
, NULL
, OPTION_NO_US
},
271 #define OPTION_US (OPTION_MD_BASE + 1)
272 {"underscore", no_argument
, NULL
, OPTION_US
},
273 {NULL
, no_argument
, NULL
, 0}
276 /* Not const-declared at usage in 2.9.1. */
277 size_t md_longopts_size
= sizeof (md_longopts
);
278 const char *md_shortopts
= "hHN";
280 /* At first glance, this may seems wrong and should be 4 (ba + nop); but
281 since a short_jump must skip a *number* of long jumps, it must also be
282 a long jump. Here, we hope to make it a "ba [16bit_offs]" and a "nop"
283 for the delay slot and hope that the jump table at most needs
284 32767/4=8191 long-jumps. A branch is better than a jump, since it is
285 relative; we will not have a reloc to fix up somewhere.
287 Note that we can't add relocs, because relaxation uses these fixed
288 numbers, and md_create_short_jump is called after relaxation. */
290 const int md_short_jump_size
= 6;
291 const int md_long_jump_size
= 6;
293 /* Report output format. Small changes in output format (like elf
294 variants below) can happen until all options are parsed. */
297 cris_target_format ()
299 switch (OUTPUT_FLAVOR
)
301 case bfd_target_aout_flavour
:
304 case bfd_target_elf_flavour
:
305 if (symbols_have_leading_underscore
)
306 return "elf32-us-cris";
315 /* Prepare machine-dependent frags for relaxation.
317 Called just before relaxation starts. Any symbol that is now undefined
318 will not become defined.
320 Return the correct fr_subtype in the frag.
322 Return the initial "guess for fr_var" to caller. The guess for fr_var
323 is *actually* the growth beyond fr_fix. Whatever we do to grow fr_fix
324 or fr_var contributes to our returned value.
326 Although it may not be explicit in the frag, pretend
327 fr_var starts with a value. */
330 md_estimate_size_before_relax (fragP
, segment_type
)
332 /* The segment is either N_DATA or N_TEXT. */
337 old_fr_fix
= fragP
->fr_fix
;
339 switch (fragP
->fr_subtype
)
341 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_UNDF
):
342 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
344 /* The symbol lies in the same segment - a relaxable case. */
346 = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
350 /* Unknown or not the same segment, so not relaxable. */
353 /* A small branch-always (2 bytes) to the "real" branch
354 instruction, plus a delay-slot nop (2 bytes), plus a
355 jump (2 plus 4 bytes). See gen_cond_branch_32. */
356 fragP
->fr_fix
+= 2 + 2 + 2 + 4;
357 writep
= fragP
->fr_literal
+ old_fr_fix
;
358 gen_cond_branch_32 (fragP
->fr_opcode
, writep
, fragP
,
359 fragP
->fr_symbol
, (symbolS
*) NULL
,
365 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
366 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
367 /* We *might* give a better initial guess if we peek at offsets
368 now, but the caller will relax correctly and without this, so
372 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX
, STATE_UNDF
):
373 /* Note that we can not do anything sane with relaxing
374 [rX + a_known_symbol_in_text], it will have to be a 32-bit
377 We could play tricks with managing a constant pool and make
378 a_known_symbol_in_text a "bdap [pc + offset]" pointing there, but
379 that's pointless, it can only be longer and slower.
381 Off-topic: If PIC becomes *really* important, and has to be done
382 in the assembler and linker only (which would be weird or
383 clueless), we can so something. Imagine:
384 move.x [r + 32_bit_symbol],r
385 move.x [32_bit_symbol],r
386 move.x 32_bit_symbol,r
387 can be shortened by a word (8-bit offset) if we are close to the
388 symbol or keep its length (16-bit offset) or be a word longer
389 (32-bit offset). Then change the 32_bit_symbol into a "bdap [pc
390 + offset]", and put the offset to the 32_bit_symbol in "offset".
391 Weird, to say the least, and we still have to add support for a
392 PC-relative relocation in the loader (shared libraries). But
393 it's an interesting thought. */
395 if (S_GET_SEGMENT (fragP
->fr_symbol
) != absolute_section
)
397 /* Go for dword if not absolute or same segment. */
399 = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX
, STATE_DWORD
);
404 /* Absolute expression. */
406 value
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
408 if (value
>= -128 && value
<= 127)
410 /* Byte displacement. */
411 (fragP
->fr_opcode
)[0] = value
;
415 /* Word or dword displacement. */
416 int pow2_of_size
= 1;
419 if (value
< -32768 || value
> 32767)
421 /* Outside word range, make it a dword. */
425 /* Modify the byte-offset BDAP into a word or dword offset
426 BDAP. Or really, a BDAP rX,8bit into a
427 BDAP.[wd] rX,[PC+] followed by a word or dword. */
428 (fragP
->fr_opcode
)[0] = BDAP_PC_LOW
+ pow2_of_size
* 16;
430 /* Keep the register number in the highest four bits. */
431 (fragP
->fr_opcode
)[1] &= 0xF0;
432 (fragP
->fr_opcode
)[1] |= BDAP_INCR_HIGH
;
434 /* It grew by two or four bytes. */
435 fragP
->fr_fix
+= 1 << pow2_of_size
;
436 writep
= fragP
->fr_literal
+ old_fr_fix
;
437 md_number_to_chars (writep
, value
, 1 << pow2_of_size
);
444 BAD_CASE (fragP
->fr_subtype
);
447 return fragP
->fr_var
+ (fragP
->fr_fix
- old_fr_fix
);
450 /* Perform post-processing of machine-dependent frags after relaxation.
451 Called after relaxation is finished.
453 fr_type == rs_machine_dependent.
454 fr_subtype is what the address relaxed to.
456 Out: Any fixS:s and constants are set up.
458 The caller will turn the frag into a ".space 0". */
461 md_convert_frag (abfd
, sec
, fragP
)
462 bfd
*abfd ATTRIBUTE_UNUSED
;
463 segT sec ATTRIBUTE_UNUSED
;
466 /* Pointer to first byte in variable-sized part of the frag. */
469 /* Pointer to first opcode byte in frag. */
472 /* Used to check integrity of the relaxation.
473 One of 2 = long, 1 = word, or 0 = byte. */
476 /* Size in bytes of variable-sized part of frag. */
477 int var_part_size
= 0;
479 /* This is part of *fragP. It contains all information about addresses
480 and offsets to varying parts. */
482 unsigned long var_part_offset
;
484 /* Where, in file space, is _var of *fragP? */
485 unsigned long address_of_var_part
= 0;
487 /* Where, in file space, does addr point? */
488 unsigned long target_address
;
490 know (fragP
->fr_type
== rs_machine_dependent
);
492 length_code
= fragP
->fr_subtype
& STATE_LENGTH_MASK
;
493 know (length_code
>= 0 && length_code
< STATE_MAX_LENGTH
);
495 var_part_offset
= fragP
->fr_fix
;
496 var_partp
= fragP
->fr_literal
+ var_part_offset
;
497 opcodep
= fragP
->fr_opcode
;
499 symbolP
= fragP
->fr_symbol
;
502 ? S_GET_VALUE (symbolP
) + symbol_get_frag(fragP
->fr_symbol
)->fr_address
503 : 0 ) + fragP
->fr_offset
;
504 address_of_var_part
= fragP
->fr_address
+ var_part_offset
;
506 switch (fragP
->fr_subtype
)
508 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
509 opcodep
[0] = branch_disp ((target_address
- address_of_var_part
));
513 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
514 /* We had a quick immediate branch, now turn it into a word one i.e. a
516 opcodep
[0] = BRANCH_PC_LOW
;
518 opcodep
[1] |= BRANCH_INCR_HIGH
;
519 md_number_to_chars (var_partp
,
520 (long) (target_address
- (address_of_var_part
+ 2)),
525 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_DWORD
):
526 gen_cond_branch_32 (fragP
->fr_opcode
, var_partp
, fragP
,
527 fragP
->fr_symbol
, (symbolS
*) NULL
,
529 /* Ten bytes added: a branch, nop and a jump. */
530 var_part_size
= 2 + 2 + 4 + 2;
533 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX
, STATE_BYTE
):
534 var_partp
[0] = target_address
- (address_of_var_part
+ 1);
538 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX
, STATE_WORD
):
539 /* We had a BDAP 8-bit "quick immediate", now turn it into a 16-bit
540 one that uses PC autoincrement. */
541 opcodep
[0] = BDAP_PC_LOW
+ (1 << 4);
543 opcodep
[1] |= BDAP_INCR_HIGH
;
544 md_number_to_chars (var_partp
, (long) (target_address
), 2);
548 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX
, STATE_DWORD
):
549 /* We had a BDAP 16-bit "word", change the offset to a dword. */
550 opcodep
[0] = BDAP_PC_LOW
+ (2 << 4);
552 opcodep
[1] |= BDAP_INCR_HIGH
;
553 if (fragP
->fr_symbol
== NULL
)
554 md_number_to_chars (var_partp
, fragP
->fr_offset
, 4);
556 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
557 fragP
->fr_offset
, 0, BFD_RELOC_32
);
562 BAD_CASE (fragP
->fr_subtype
);
566 fragP
->fr_fix
+= var_part_size
;
569 /* Generate a short jump around a secondary jump table.
570 Used by md_create_long_jump.
572 This used to be md_create_short_jump, but is now called from
573 md_create_long_jump instead, when sufficient.
574 since the sizes of the jumps are the same. It used to be brittle,
575 making possibilities for creating bad code. */
578 cris_create_short_jump (storep
, from_addr
, to_addr
, fragP
, to_symbol
)
582 fragS
*fragP ATTRIBUTE_UNUSED
;
583 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
587 distance
= to_addr
- from_addr
;
589 if (-254 <= distance
&& distance
<= 256)
591 /* Create a "short" short jump: "BA distance - 2". */
592 storep
[0] = branch_disp (distance
- 2);
593 storep
[1] = BA_QUICK_HIGH
;
595 /* A nop for the delay slot. */
596 md_number_to_chars (storep
+ 2, NOP_OPCODE
, 2);
598 /* The extra word should be filled with something sane too. Make it
599 a nop to keep disassembly sane. */
600 md_number_to_chars (storep
+ 4, NOP_OPCODE
, 2);
604 /* Make it a "long" short jump: "BA (PC+)". */
605 md_number_to_chars (storep
, BA_PC_INCR_OPCODE
, 2);
607 /* ".WORD distance - 4". */
608 md_number_to_chars (storep
+ 2, (long) (distance
- 4), 2);
610 /* A nop for the delay slot. */
611 md_number_to_chars (storep
+ 4, NOP_OPCODE
, 2);
615 /* Generate a long jump in a secondary jump table.
617 storep Where to store the jump instruction.
618 from_addr Address of the jump instruction.
619 to_addr Destination address of the jump.
620 fragP Which frag the destination address operand
622 to_symbol Destination symbol. */
625 md_create_long_jump (storep
, from_addr
, to_addr
, fragP
, to_symbol
)
634 distance
= to_addr
- from_addr
;
636 if (-32763 <= distance
&& distance
<= 32772)
638 /* Then make it a "short" long jump. */
639 cris_create_short_jump (storep
, from_addr
, to_addr
, fragP
,
644 /* We have a "long" long jump: "JUMP (PC+)". */
645 md_number_to_chars (storep
, JUMP_PC_INCR_OPCODE
, 2);
647 /* Follow with a ".DWORD to_addr". */
648 fix_new (fragP
, storep
+ 2 - fragP
->fr_literal
, 4, to_symbol
,
653 /* Port-specific assembler initialization. */
658 const char *hashret
= NULL
;
661 /* Set up a hash table for the instructions. */
662 op_hash
= hash_new ();
664 as_fatal (_("Virtual memory exhausted"));
666 while (cris_opcodes
[i
].name
!= NULL
)
668 const char *name
= cris_opcodes
[i
].name
;
669 hashret
= hash_insert (op_hash
, name
, (PTR
) &cris_opcodes
[i
]);
671 if (hashret
!= NULL
&& *hashret
!= '\0')
672 as_fatal (_("Can't hash `%s': %s\n"), cris_opcodes
[i
].name
,
673 *hashret
== 0 ? _("(unknown reason)") : hashret
);
676 if (cris_opcodes
[i
].match
& cris_opcodes
[i
].lose
)
677 as_fatal (_("Buggy opcode: `%s' \"%s\"\n"), cris_opcodes
[i
].name
,
678 cris_opcodes
[i
].args
);
682 while (cris_opcodes
[i
].name
!= NULL
683 && strcmp (cris_opcodes
[i
].name
, name
) == 0);
687 /* Assemble a source line. */
693 struct cris_instruction output_instruction
;
694 struct cris_prefix prefix
;
701 /* Do the low-level grunt - assemble to bits and split up into a prefix
702 and ordinary insn. */
703 cris_process_instruction (str
, &output_instruction
, &prefix
);
705 /* Handle any prefixes to the instruction. */
711 /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
712 extra bytes, so we handle it separately. */
713 case PREFIX_BDAP_IMM
:
714 gen_bdap (prefix
.base_reg_number
, &prefix
.expr
);
721 opcodep
= frag_more (2);
723 /* Output the prefix opcode. */
724 md_number_to_chars (opcodep
, (long) prefix
.opcode
, 2);
726 /* This only happens for DIP, but is ok for the others as they have
728 if (prefix
.reloc
!= BFD_RELOC_NONE
)
730 /* Output an absolute mode address. */
733 fix_new_exp (frag_now
, (p
- frag_now
->fr_literal
), 4,
734 &prefix
.expr
, 0, prefix
.reloc
);
740 opcodep
= frag_more (2);
742 /* Output the prefix opcode. Being a "push", we add the negative
743 size of the register to "sp". */
744 if (output_instruction
.spec_reg
!= NULL
)
746 /* Special register. */
747 opcodep
[0] = -output_instruction
.spec_reg
->reg_size
;
751 /* General register. */
754 opcodep
[1] = (REG_SP
<< 4) + (BDAP_QUICK_OPCODE
>> 8);
758 BAD_CASE (prefix
.kind
);
761 /* If we only had a prefix insn, we're done. */
762 if (output_instruction
.insn_type
== CRIS_INSN_NONE
)
765 /* Done with the prefix. Continue with the main instruction. */
767 opcodep
= frag_more (2);
769 /* Output the instruction opcode. */
770 md_number_to_chars (opcodep
, (long) (output_instruction
.opcode
), 2);
772 /* Output the symbol-dependent instruction stuff. */
773 if (output_instruction
.insn_type
== CRIS_INSN_BRANCH
)
775 segT to_seg
= absolute_section
;
776 int is_undefined
= 0;
779 if (output_instruction
.expr
.X_op
!= O_constant
)
781 to_seg
= S_GET_SEGMENT (output_instruction
.expr
.X_add_symbol
);
783 if (to_seg
== undefined_section
)
787 if (output_instruction
.expr
.X_op
== O_constant
788 || to_seg
== now_seg
|| is_undefined
)
790 /* If is_undefined, then the expression may BECOME now_seg. */
791 length_code
= is_undefined
? STATE_UNDF
: STATE_BYTE
;
793 /* Make room for max ten bytes of variable length. */
794 frag_var (rs_machine_dependent
, 10, 0,
795 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, length_code
),
796 output_instruction
.expr
.X_add_symbol
,
797 output_instruction
.expr
.X_add_number
,
802 /* We have: to_seg != now_seg && to_seg != undefined_section.
803 This means it is a branch to a known symbol in another
804 section. Code in data? Weird but valid. Emit a 32-bit
807 gen_cond_branch_32 (opcodep
, frag_more (10), frag_now
,
808 output_instruction
.expr
.X_add_symbol
,
810 output_instruction
.expr
.X_add_number
);
815 if (output_instruction
.imm_oprnd_size
> 0)
817 /* The intruction has an immediate operand. */
818 enum bfd_reloc_code_real reloc
= 0;
820 switch (output_instruction
.imm_oprnd_size
)
822 /* Any byte-size immediate constants are treated as
823 word-size. FIXME: Thus overflow check does not work
827 reloc
= BFD_RELOC_16
;
831 reloc
= BFD_RELOC_32
;
835 BAD_CASE (output_instruction
.imm_oprnd_size
);
838 insn_size
+= output_instruction
.imm_oprnd_size
;
839 p
= frag_more (output_instruction
.imm_oprnd_size
);
840 fix_new_exp (frag_now
, (p
- frag_now
->fr_literal
),
841 output_instruction
.imm_oprnd_size
,
842 &output_instruction
.expr
, 0, reloc
);
844 else if (output_instruction
.reloc
!= BFD_RELOC_NONE
)
846 /* An immediate operand that has a relocation and needs to be
847 processed further. */
849 /* It is important to use fix_new_exp here and everywhere else
850 (and not fix_new), as fix_new_exp can handle "difference
851 expressions" - where the expression contains a difference of
852 two symbols in the same segment. */
853 fix_new_exp (frag_now
, (opcodep
- frag_now
->fr_literal
), 2,
854 &output_instruction
.expr
, 0,
855 output_instruction
.reloc
);
859 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
860 dwarf2_emit_insn (insn_size
);
863 /* Low level text-to-bits assembly. */
866 cris_process_instruction (insn_text
, out_insnp
, prefixp
)
868 struct cris_instruction
*out_insnp
;
869 struct cris_prefix
*prefixp
;
872 char modified_char
= 0;
874 struct cris_opcode
*instruction
;
881 /* Reset these fields to a harmless state in case we need to return in
883 prefixp
->kind
= PREFIX_NONE
;
884 prefixp
->reloc
= BFD_RELOC_NONE
;
885 out_insnp
->insn_type
= CRIS_INSN_NORMAL
;
886 out_insnp
->imm_oprnd_size
= 0;
888 /* Find the end of the opcode mnemonic. We assume (true in 2.9.1)
889 that the caller has translated the opcode to lower-case, up to the
891 for (operands
= insn_text
; islower (*operands
); ++operands
)
894 /* Terminate the opcode after letters, but save the character there if
895 it was of significance. */
902 /* Put back the modified character later. */
903 modified_char
= *operands
;
907 /* Consume the character after the mnemonic
908 and replace it with '\0'. */
913 as_bad (_("Unknown opcode: `%s'"), insn_text
);
917 /* Find the instruction. */
918 instruction
= (struct cris_opcode
*) hash_find (op_hash
, insn_text
);
919 if (instruction
== NULL
)
921 as_bad (_("Unknown opcode: `%s'"), insn_text
);
925 /* Put back the modified character. */
926 switch (modified_char
)
932 *--operands
= modified_char
;
935 /* Try to match an opcode table slot. */
940 /* Initialize *prefixp, perhaps after being modified for a
942 prefixp
->kind
= PREFIX_NONE
;
943 prefixp
->reloc
= BFD_RELOC_NONE
;
945 /* Initialize *out_insnp. */
946 memset (out_insnp
, 0, sizeof (*out_insnp
));
947 out_insnp
->opcode
= instruction
->match
;
948 out_insnp
->reloc
= BFD_RELOC_NONE
;
949 out_insnp
->insn_type
= CRIS_INSN_NORMAL
;
950 out_insnp
->imm_oprnd_size
= 0;
954 /* Build the opcode, checking as we go to make sure that the
956 for (args
= instruction
->args
;; ++args
)
961 /* If we've come to the end of arguments, we're done. */
967 /* Non-matcher character for disassembly.
973 /* These must match exactly. */
979 /* This is not really an operand, but causes a "BDAP
980 -size,SP" prefix to be output, for PUSH instructions. */
981 prefixp
->kind
= PREFIX_PUSH
;
985 /* This letter marks an operand that should not be matched
986 in the assembler. It is a branch with 16-bit
987 displacement. The assembler will create them from the
988 8-bit flavor when necessary. The assembler does not
989 support the [rN+] operand, as the [r15+] that is
990 generated for 16-bit displacements. */
994 /* A 5-bit unsigned immediate in bits <4:0>. */
995 if (! cris_get_expression (&s
, &out_insnp
->expr
))
999 if (out_insnp
->expr
.X_op
== O_constant
1000 && (out_insnp
->expr
.X_add_number
< 0
1001 || out_insnp
->expr
.X_add_number
> 31))
1002 as_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
1003 out_insnp
->expr
.X_add_number
);
1005 out_insnp
->reloc
= BFD_RELOC_CRIS_UNSIGNED_5
;
1010 /* A 4-bit unsigned immediate in bits <3:0>. */
1011 if (! cris_get_expression (&s
, &out_insnp
->expr
))
1015 if (out_insnp
->expr
.X_op
== O_constant
1016 && (out_insnp
->expr
.X_add_number
< 0
1017 || out_insnp
->expr
.X_add_number
> 15))
1018 as_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
1019 out_insnp
->expr
.X_add_number
);
1021 out_insnp
->reloc
= BFD_RELOC_CRIS_UNSIGNED_4
;
1026 /* General register in bits <15:12> and <3:0>. */
1027 if (! get_gen_reg (&s
, ®no
))
1031 out_insnp
->opcode
|= regno
/* << 0 */;
1032 out_insnp
->opcode
|= regno
<< 12;
1037 /* Flags from the condition code register. */
1041 if (! get_flags (&s
, &flags
))
1044 out_insnp
->opcode
|= ((flags
& 0xf0) << 8) | (flags
& 0xf);
1049 /* A 6-bit signed immediate in bits <5:0>. */
1050 if (! cris_get_expression (&s
, &out_insnp
->expr
))
1054 if (out_insnp
->expr
.X_op
== O_constant
1055 && (out_insnp
->expr
.X_add_number
< -32
1056 || out_insnp
->expr
.X_add_number
> 31))
1057 as_bad (_("Immediate value not in 6 bit range: %ld"),
1058 out_insnp
->expr
.X_add_number
);
1059 out_insnp
->reloc
= BFD_RELOC_CRIS_SIGNED_6
;
1064 /* A 6-bit unsigned immediate in bits <5:0>. */
1065 if (! cris_get_expression (&s
, &out_insnp
->expr
))
1069 if (out_insnp
->expr
.X_op
== O_constant
1070 && (out_insnp
->expr
.X_add_number
< 0
1071 || out_insnp
->expr
.X_add_number
> 63))
1072 as_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
1073 out_insnp
->expr
.X_add_number
);
1074 out_insnp
->reloc
= BFD_RELOC_CRIS_UNSIGNED_6
;
1079 /* A size modifier, B, W or D, to be put in a bit position
1080 suitable for CLEAR instructions (i.e. reflecting a zero
1082 if (! get_bwd_size_modifier (&s
, &size_bits
))
1089 out_insnp
->opcode
|= 0 << 12;
1093 out_insnp
->opcode
|= 4 << 12;
1097 out_insnp
->opcode
|= 8 << 12;
1104 /* A size modifier, B, W or D, to be put in bits <5:4>. */
1105 if (! get_bwd_size_modifier (&s
, &size_bits
))
1109 out_insnp
->opcode
|= size_bits
<< 4;
1114 /* A branch expression. */
1115 if (! cris_get_expression (&s
, &out_insnp
->expr
))
1119 out_insnp
->insn_type
= CRIS_INSN_BRANCH
;
1124 /* A BDAP expression for any size, "expr,r". */
1125 if (! cris_get_expression (&s
, &prefixp
->expr
))
1134 if (!get_gen_reg (&s
, &prefixp
->base_reg_number
))
1137 /* Since 'O' is used with an explicit bdap, we have no
1138 "real" instruction. */
1139 prefixp
->kind
= PREFIX_BDAP_IMM
;
1140 out_insnp
->insn_type
= CRIS_INSN_NONE
;
1145 /* Special register in bits <15:12>. */
1146 if (! get_spec_reg (&s
, &out_insnp
->spec_reg
))
1150 /* Use of some special register names come with a
1151 specific warning. Note that we have no ".cpu type"
1152 pseudo yet, so some of this is just unused
1154 if (out_insnp
->spec_reg
->warning
)
1155 as_warn (out_insnp
->spec_reg
->warning
);
1156 else if (out_insnp
->spec_reg
->applicable_version
1157 == cris_ver_warning
)
1158 /* Others have a generic warning. */
1159 as_warn (_("Unimplemented register `%s' specified"),
1160 out_insnp
->spec_reg
->name
);
1163 |= out_insnp
->spec_reg
->number
<< 12;
1168 /* This character is used in the disassembler to
1169 recognize a prefix instruction to fold into the
1170 addressing mode for the next instruction. It is
1175 /* General register in bits <15:12>. */
1176 if (! get_gen_reg (&s
, ®no
))
1180 out_insnp
->opcode
|= regno
<< 12;
1185 /* General register in bits <3:0>. */
1186 if (! get_gen_reg (&s
, ®no
))
1190 out_insnp
->opcode
|= regno
/* << 0 */;
1195 /* Source operand in bit <10> and a prefix; a 3-operand
1197 if (! get_3op_or_dip_prefix_op (&s
, prefixp
))
1203 /* Source operand in bits <10>, <3:0> and optionally a
1204 prefix; i.e. an indirect operand or an side-effect
1206 if (! get_autoinc_prefix_or_indir_op (&s
, prefixp
, &mode
,
1213 if (prefixp
->kind
!= PREFIX_NONE
)
1215 /* A prefix, so it has the autoincrement bit
1217 out_insnp
->opcode
|= (AUTOINCR_BIT
<< 8);
1220 /* No prefix. The "mode" variable contains bits like
1221 whether or not this is autoincrement mode. */
1222 out_insnp
->opcode
|= (mode
<< 10);
1224 out_insnp
->opcode
|= regno
/* << 0 */ ;
1229 /* Rs.m in bits <15:12> and <5:4>. */
1230 if (! get_gen_reg (&s
, ®no
)
1231 || ! get_bwd_size_modifier (&s
, &size_bits
))
1235 out_insnp
->opcode
|= (regno
<< 12) | (size_bits
<< 4);
1240 /* Source operand in bits <10>, <3:0> and optionally a
1241 prefix; i.e. an indirect operand or an side-effect
1244 The difference to 's' is that this does not allow an
1245 "immediate" expression. */
1246 if (! get_autoinc_prefix_or_indir_op (&s
, prefixp
,
1254 if (prefixp
->kind
!= PREFIX_NONE
)
1256 /* A prefix, and those matched here always have
1257 side-effects (see 's' case). */
1258 out_insnp
->opcode
|= (AUTOINCR_BIT
<< 8);
1262 /* No prefix. The "mode" variable contains bits
1263 like whether or not this is autoincrement
1265 out_insnp
->opcode
|= (mode
<< 10);
1268 out_insnp
->opcode
|= regno
/* << 0 */;
1273 /* Size modifier (B or W) in bit <4>. */
1274 if (! get_bw_size_modifier (&s
, &size_bits
))
1278 out_insnp
->opcode
|= size_bits
<< 4;
1286 /* We get here when we fail a match above or we found a
1287 complete match. Break out of this loop. */
1291 /* Was it a match or a miss? */
1294 /* If it's just that the args don't match, maybe the next
1295 item in the table is the same opcode but with
1296 matching operands. */
1297 if (instruction
[1].name
!= NULL
1298 && ! strcmp (instruction
->name
, instruction
[1].name
))
1300 /* Yep. Restart and try that one instead. */
1307 /* We've come to the end of instructions with this
1308 opcode, so it must be an error. */
1309 as_bad (_("Illegal operands"));
1315 /* We have a match. Check if there's anything more to do. */
1318 /* There was an immediate mode operand, so we must check
1319 that it has an appropriate size. */
1321 switch (instruction
->imm_oprnd_size
)
1325 /* Shouldn't happen; this one does not have immediate
1326 operands with different sizes. */
1327 BAD_CASE (instruction
->imm_oprnd_size
);
1331 out_insnp
->imm_oprnd_size
= 4;
1335 switch (out_insnp
->spec_reg
->reg_size
)
1338 if (out_insnp
->expr
.X_op
== O_constant
1339 && (out_insnp
->expr
.X_add_number
< -128
1340 || out_insnp
->expr
.X_add_number
> 255))
1341 as_bad (_("Immediate value not in 8 bit range: %ld"),
1342 out_insnp
->expr
.X_add_number
);
1345 /* FIXME: We need an indicator in the instruction
1346 table to pass on, to indicate if we need to check
1347 overflow for a signed or unsigned number. */
1348 if (out_insnp
->expr
.X_op
== O_constant
1349 && (out_insnp
->expr
.X_add_number
< -32768
1350 || out_insnp
->expr
.X_add_number
> 65535))
1351 as_bad (_("Immediate value not in 16 bit range: %ld"),
1352 out_insnp
->expr
.X_add_number
);
1353 out_insnp
->imm_oprnd_size
= 2;
1357 out_insnp
->imm_oprnd_size
= 4;
1361 BAD_CASE (out_insnp
->spec_reg
->reg_size
);
1369 if (out_insnp
->expr
.X_op
== O_constant
1370 && (out_insnp
->expr
.X_add_number
< -128
1371 || out_insnp
->expr
.X_add_number
> 255))
1372 as_bad (_("Immediate value not in 8 bit range: %ld"),
1373 out_insnp
->expr
.X_add_number
);
1376 if (out_insnp
->expr
.X_op
== O_constant
1377 && (out_insnp
->expr
.X_add_number
< -32768
1378 || out_insnp
->expr
.X_add_number
> 65535))
1379 as_bad (_("Immediate value not in 16 bit range: %ld"),
1380 out_insnp
->expr
.X_add_number
);
1381 out_insnp
->imm_oprnd_size
= 2;
1385 out_insnp
->imm_oprnd_size
= 4;
1389 BAD_CASE (out_insnp
->spec_reg
->reg_size
);
1398 /* Get a B, W, or D size modifier from the string pointed out by *cPP,
1399 which must point to a '.' in front of the modifier. On successful
1400 return, *cPP is advanced to the character following the size
1401 modifier, and is undefined otherwise.
1403 cPP Pointer to pointer to string starting
1404 with the size modifier.
1406 size_bitsp Pointer to variable to contain the size bits on
1409 Return 1 iff a correct size modifier is found, else 0. */
1412 get_bwd_size_modifier (cPP
, size_bitsp
)
1420 /* Consume the '.'. */
1444 /* Consume the size letter. */
1450 /* Get a B or W size modifier from the string pointed out by *cPP,
1451 which must point to a '.' in front of the modifier. On successful
1452 return, *cPP is advanced to the character following the size
1453 modifier, and is undefined otherwise.
1455 cPP Pointer to pointer to string starting
1456 with the size modifier.
1458 size_bitsp Pointer to variable to contain the size bits on
1461 Return 1 iff a correct size modifier is found, else 0. */
1464 get_bw_size_modifier (cPP
, size_bitsp
)
1472 /* Consume the '.'. */
1491 /* Consume the size letter. */
1497 /* Get a general register from the string pointed out by *cPP. The
1498 variable *cPP is advanced to the character following the general
1499 register name on a successful return, and has its initial position
1502 cPP Pointer to pointer to string, beginning with a general
1505 regnop Pointer to int containing the register number.
1507 Return 1 iff a correct general register designator is found,
1511 get_gen_reg (cPP
, regnop
)
1518 /* Handle a sometimes-mandatory dollar sign as register prefix. */
1519 if (**cPP
== REGISTER_PREFIX_CHAR
)
1521 else if (demand_register_prefix
)
1528 /* "P" as in "PC"? Consume the "P". */
1531 if ((**cPP
== 'C' || **cPP
== 'c')
1532 && ! isalnum ((*cPP
)[1]))
1534 /* It's "PC": consume the "c" and we're done. */
1543 /* Hopefully r[0-9] or r1[0-5]. Consume 'R' or 'r'. */
1546 if (isdigit (**cPP
))
1548 /* It's r[0-9]. Consume and check the next digit. */
1549 *regnop
= **cPP
- '0';
1552 if (! isalnum (**cPP
))
1554 /* No more digits, we're done. */
1559 /* One more digit. Consume and add. */
1560 *regnop
= *regnop
* 10 + (**cPP
- '0');
1562 /* We need to check for a valid register number; Rn,
1563 0 <= n <= MAX_REG. */
1564 if (*regnop
<= MAX_REG
)
1566 /* Consume second digit. */
1576 /* "S" as in "SP"? Consume the "S". */
1578 if (**cPP
== 'P' || **cPP
== 'p')
1580 /* It's "SP": consume the "p" and we're done. */
1588 /* Just here to silence compilation warnings. */
1592 /* We get here if we fail. Restore the pointer. */
1597 /* Get a special register from the string pointed out by *cPP. The
1598 variable *cPP is advanced to the character following the special
1599 register name if one is found, and retains its original position
1602 cPP Pointer to pointer to string starting with a special register
1605 sregpp Pointer to Pointer to struct spec_reg, where a pointer to the
1606 register description will be stored.
1608 Return 1 iff a correct special register name is found. */
1611 get_spec_reg (cPP
, sregpp
)
1613 const struct cris_spec_reg
**sregpp
;
1617 char *name_begin
= *cPP
;
1619 const struct cris_spec_reg
*sregp
;
1621 /* Handle a sometimes-mandatory dollar sign as register prefix. */
1622 if (*name_begin
== REGISTER_PREFIX_CHAR
)
1624 else if (demand_register_prefix
)
1627 /* Loop over all special registers. */
1628 for (sregp
= cris_spec_regs
; sregp
->name
!= NULL
; sregp
++)
1630 /* Start over from beginning of the supposed name. */
1635 && (isupper (*s1
) ? tolower (*s1
) == *s2
: *s1
== *s2
))
1641 /* For a match, we must have consumed the name in the table, and we
1642 must be outside what could be part of a name. Assume here that a
1643 test for alphanumerics is sufficient for a name test. */
1644 if (*s2
== 0 && ! isalnum (*s1
))
1646 /* We have a match. Update the pointer and be done. */
1653 /* If we got here, we did not find any name. */
1657 /* Get an unprefixed or side-effect-prefix operand from the string pointed
1658 out by *cPP. The pointer *cPP is advanced to the character following
1659 the indirect operand if we have success, else it contains an undefined
1662 cPP Pointer to pointer to string beginning with the first
1663 character of the supposed operand.
1665 prefixp Pointer to structure containing an optional instruction
1668 is_autoincp Pointer to int indicating the indirect or autoincrement
1671 src_regnop Pointer to int containing the source register number in
1674 imm_foundp Pointer to an int indicating if an immediate expression
1677 imm_exprP Pointer to a structure containing an immediate
1678 expression, if success and if *imm_foundp is nonzero.
1680 Return 1 iff a correct indirect operand is found. */
1683 get_autoinc_prefix_or_indir_op (cPP
, prefixp
, is_autoincp
, src_regnop
,
1684 imm_foundp
, imm_exprP
)
1686 struct cris_prefix
*prefixp
;
1690 expressionS
*imm_exprP
;
1692 /* Assume there was no immediate mode expression. */
1697 /* So this operand is one of:
1699 Autoincrement: [rN+]
1700 Indexed with assign: [rN=rM+rO.S]
1701 Offset with assign: [rN=rM+I], [rN=rM+[rO].s], [rN=rM+[rO+].s]
1703 Either way, consume the '['. */
1706 /* Get the rN register. */
1707 if (! get_gen_reg (cPP
, src_regnop
))
1708 /* If there was no register, then this cannot match. */
1712 /* We got the register, now check the next character. */
1716 /* Indirect mode. We're done here. */
1717 prefixp
->kind
= PREFIX_NONE
;
1722 /* This must be an auto-increment mode, if there's a
1724 prefixp
->kind
= PREFIX_NONE
;
1727 /* We consume this character and break out to check the
1733 /* This must be indexed with assign, or offset with assign
1737 /* Either way, the next thing must be a register. */
1738 if (! get_gen_reg (cPP
, &prefixp
->base_reg_number
))
1739 /* No register, no match. */
1743 /* We've consumed "[rN=rM", so we must be looking at
1744 "+rO.s]" or "+I]", or "-I]", or "+[rO].s]" or
1748 int index_reg_number
;
1754 /* This must be [rx=ry+[rz].s] or
1755 [rx=ry+[rz+].s] or no match. We must be
1756 looking at rz after consuming the '['. */
1759 if (!get_gen_reg (cPP
, &index_reg_number
))
1762 prefixp
->kind
= PREFIX_BDAP
;
1764 = (BDAP_INDIR_OPCODE
1765 + (prefixp
->base_reg_number
<< 12)
1766 + index_reg_number
);
1770 /* We've seen "[rx=ry+[rz+" here, so now we
1771 know that there must be "].s]" left to
1774 prefixp
->opcode
|= AUTOINCR_BIT
<< 8;
1777 /* If it wasn't autoincrement, we don't need to
1780 /* Check the next-to-last ']'. */
1786 /* Check the ".s" modifier. */
1787 if (! get_bwd_size_modifier (cPP
, &size_bits
))
1790 prefixp
->opcode
|= size_bits
<< 4;
1792 /* Now we got [rx=ry+[rz+].s or [rx=ry+[rz].s.
1793 We break out to check the final ']'. */
1796 /* It wasn't an indirection. Check if it's a
1798 else if (get_gen_reg (cPP
, &index_reg_number
))
1802 /* Indexed with assign mode: "[rN+rM.S]". */
1803 prefixp
->kind
= PREFIX_BIAP
;
1805 = (BIAP_OPCODE
+ (index_reg_number
<< 12)
1806 + prefixp
->base_reg_number
/* << 0 */);
1808 if (! get_bwd_size_modifier (cPP
, &size_bits
))
1809 /* Size missing, this isn't a match. */
1813 /* Size found, break out to check the
1815 prefixp
->opcode
|= size_bits
<< 4;
1819 /* Not a register. Then this must be "[rN+I]". */
1820 else if (cris_get_expression (cPP
, &prefixp
->expr
))
1822 /* We've got offset with assign mode. Fill
1823 in the blanks and break out to match the
1825 prefixp
->kind
= PREFIX_BDAP_IMM
;
1829 /* Neither register nor expression found, so
1830 this can't be a match. */
1833 /* Not "[rN+" but perhaps "[rN-"? */
1834 else if (**cPP
== '-')
1836 /* We must have an offset with assign mode. */
1837 if (! cris_get_expression (cPP
, &prefixp
->expr
))
1838 /* No expression, no match. */
1842 /* We've got offset with assign mode. Fill
1843 in the blanks and break out to match the
1845 prefixp
->kind
= PREFIX_BDAP_IMM
;
1850 /* Neither '+' nor '-' after "[rN=rM". Lose. */
1854 /* Neither ']' nor '+' nor '=' after "[rN". Lose. */
1859 /* When we get here, we have a match and will just check the closing
1860 ']'. We can still fail though. */
1865 /* Don't forget to consume the final ']'.
1866 Then return in glory. */
1871 /* No indirection. Perhaps a constant? */
1872 else if (cris_get_expression (cPP
, imm_exprP
))
1874 /* Expression found, this is immediate mode. */
1875 prefixp
->kind
= PREFIX_NONE
;
1877 *src_regnop
= REG_PC
;
1882 /* No luck today. */
1886 /* This function gets an indirect operand in a three-address operand
1887 combination from the string pointed out by *cPP. The pointer *cPP is
1888 advanced to the character following the indirect operand on success, or
1889 has an unspecified value on failure.
1891 cPP Pointer to pointer to string begining
1894 prefixp Pointer to structure containing an
1897 Returns 1 iff a correct indirect operand is found. */
1900 get_3op_or_dip_prefix_op (cPP
, prefixp
)
1902 struct cris_prefix
*prefixp
;
1907 /* We must have a '[' or it's a clean failure. */
1910 /* Eat the first '['. */
1915 /* A second '[', so this must be double-indirect mode. */
1917 prefixp
->kind
= PREFIX_DIP
;
1918 prefixp
->opcode
= DIP_OPCODE
;
1920 /* Get the register or fail entirely. */
1921 if (! get_gen_reg (cPP
, ®_number
))
1925 prefixp
->opcode
|= reg_number
/* << 0 */ ;
1928 /* Since we found a '+', this must be double-indirect
1929 autoincrement mode. */
1931 prefixp
->opcode
|= AUTOINCR_BIT
<< 8;
1934 /* There's nothing particular to do, if this was a
1935 double-indirect *without* autoincrement. */
1938 /* Check the first ']'. The second one is checked at the end. */
1942 /* Eat the first ']', so we'll be looking at a second ']'. */
1945 /* No second '['. Then we should have a register here, making
1947 else if (get_gen_reg (cPP
, &prefixp
->base_reg_number
))
1949 /* This must be indexed or offset mode: "[rN+I]" or
1950 "[rN+rM.S]" or "[rN+[rM].S]" or "[rN+[rM+].S]". */
1953 /* Not the first alternative, must be one of the last
1955 int index_reg_number
;
1961 /* This is "[rx+["... Expect a register next. */
1965 if (!get_gen_reg (cPP
, &index_reg_number
))
1968 prefixp
->kind
= PREFIX_BDAP
;
1970 = (BDAP_INDIR_OPCODE
1971 + (prefixp
->base_reg_number
<< 12)
1972 + index_reg_number
);
1974 /* We've seen "[rx+[ry", so check if this is
1978 /* Yep, now at "[rx+[ry+". */
1980 prefixp
->opcode
|= AUTOINCR_BIT
<< 8;
1982 /* If it wasn't autoincrement, we don't need to
1985 /* Check a first closing ']': "[rx+[ry]" or
1991 /* Now expect a size modifier ".S". */
1992 if (! get_bwd_size_modifier (cPP
, &size_bits
))
1995 prefixp
->opcode
|= size_bits
<< 4;
1997 /* Ok, all interesting stuff has been seen:
1998 "[rx+[ry+].S" or "[rx+[ry].S". We only need to
1999 expect a final ']', which we'll do in a common
2002 /* Seen "[rN+", but not a '[', so check if we have a
2004 else if (get_gen_reg (cPP
, &index_reg_number
))
2006 /* This is indexed mode: "[rN+rM.S]" or
2009 prefixp
->kind
= PREFIX_BIAP
;
2012 | prefixp
->base_reg_number
/* << 0 */
2013 | (index_reg_number
<< 12));
2015 /* Consume the ".S". */
2016 if (! get_bwd_size_modifier (cPP
, &size_bits
))
2017 /* Missing size, so fail. */
2020 /* Size found. Add that piece and drop down to
2021 the common checking of the closing ']'. */
2022 prefixp
->opcode
|= size_bits
<< 4;
2024 /* Seen "[rN+", but not a '[' or a register, so then
2025 it must be a constant "I". */
2026 else if (cris_get_expression (cPP
, &prefixp
->expr
))
2028 /* Expression found, so fill in the bits of offset
2029 mode and drop down to check the closing ']'. */
2030 prefixp
->kind
= PREFIX_BDAP_IMM
;
2033 /* Nothing valid here: lose. */
2036 /* Seen "[rN" but no '+', so check if it's a '-'. */
2037 else if (**cPP
== '-')
2039 /* Yep, we must have offset mode. */
2040 if (! cris_get_expression (cPP
, &prefixp
->expr
))
2041 /* No expression, so we lose. */
2045 /* Expression found to make this offset mode, so
2046 fill those bits and drop down to check the
2048 prefixp
->kind
= PREFIX_BDAP_IMM
;
2053 /* We've seen "[rN", but not '+' or '-'; rather a ']'.
2054 Hmm. Normally this is a simple indirect mode that we
2055 shouldn't match, but if we expect ']', then we have a
2056 zero offset, so it can be a three-address-operand,
2057 like "[rN],rO,rP", thus offset mode.
2059 Don't eat the ']', that will be done in the closing
2061 prefixp
->expr
.X_op
= O_constant
;
2062 prefixp
->expr
.X_add_number
= 0;
2063 prefixp
->expr
.X_add_symbol
= NULL
;
2064 prefixp
->expr
.X_op_symbol
= NULL
;
2065 prefixp
->kind
= PREFIX_BDAP_IMM
;
2068 /* A '[', but no second '[', and no register. Check if we
2069 have an expression, making this "[I]" for a double-indirect
2071 else if (cris_get_expression (cPP
, &prefixp
->expr
))
2073 /* Expression found, the so called absolute mode for a
2074 double-indirect prefix on PC. */
2075 prefixp
->kind
= PREFIX_DIP
;
2076 prefixp
->opcode
= DIP_OPCODE
| (AUTOINCR_BIT
<< 8) | REG_PC
;
2077 prefixp
->reloc
= BFD_RELOC_32
;
2080 /* Neither '[' nor register nor expression. We lose. */
2083 /* We get here as a closing ceremony to a successful match. We just
2084 need to check the closing ']'. */
2086 /* Oops. Close but no air-polluter. */
2089 /* Don't forget to consume that ']', before returning in glory. */
2094 /* Get an expression from the string pointed out by *cPP.
2095 The pointer *cPP is advanced to the character following the expression
2096 on a success, or retains its original value otherwise.
2098 cPP Pointer to pointer to string beginning with the expression.
2100 exprP Pointer to structure containing the expression.
2102 Return 1 iff a correct expression is found. */
2105 cris_get_expression (cPP
, exprP
)
2109 char *saved_input_line_pointer
;
2112 /* The "expression" function expects to find an expression at the
2113 global variable input_line_pointer, so we have to save it to give
2114 the impression that we don't fiddle with global variables. */
2115 saved_input_line_pointer
= input_line_pointer
;
2116 input_line_pointer
= *cPP
;
2118 exp
= expression (exprP
);
2119 if (exprP
->X_op
== O_illegal
|| exprP
->X_op
== O_absent
)
2121 input_line_pointer
= saved_input_line_pointer
;
2125 /* Everything seems to be fine, just restore the global
2126 input_line_pointer and say we're successful. */
2127 *cPP
= input_line_pointer
;
2128 input_line_pointer
= saved_input_line_pointer
;
2132 /* Get a sequence of flag characters from *spp. The pointer *cPP is
2133 advanced to the character following the expression. The flag
2134 characters are consecutive, no commas or spaces.
2136 cPP Pointer to pointer to string beginning with the expression.
2138 flagp Pointer to int to return the flags expression.
2140 Return 1 iff a correct flags expression is found. */
2143 get_flags (cPP
, flagsp
)
2196 /* We consider this successful if we stop at a comma or
2197 whitespace. Anything else, and we consider it a failure. */
2200 && ! isspace (**cPP
))
2206 /* Don't forget to consume each flag character. */
2211 /* Generate code and fixes for a BDAP prefix.
2213 base_regno Int containing the base register number.
2215 exprP Pointer to structure containing the offset expression. */
2218 gen_bdap (base_regno
, exprP
)
2222 unsigned int opcode
;
2225 /* Put out the prefix opcode; assume quick immediate mode at first. */
2226 opcode
= BDAP_QUICK_OPCODE
| (base_regno
<< 12);
2227 opcodep
= frag_more (2);
2228 md_number_to_chars (opcodep
, opcode
, 2);
2230 if (exprP
->X_op
== O_constant
)
2232 /* We have an absolute expression that we know the size of right
2237 value
= exprP
->X_add_number
;
2238 if (value
< -32768 || value
> 32767)
2239 /* Outside range for a "word", make it a dword. */
2242 /* Assume "word" size. */
2245 /* If this is a signed-byte value, we can fit it into the prefix
2247 if (value
>= -128 && value
<= 127)
2251 /* This is a word or dword displacement, which will be put in a
2252 word or dword after the prefix. */
2255 opcodep
[0] = BDAP_PC_LOW
+ (size
<< 4);
2257 opcodep
[1] |= BDAP_INCR_HIGH
;
2258 p
= frag_more (1 << size
);
2259 md_number_to_chars (p
, value
, 1 << size
);
2263 /* The expression is not defined yet but may become absolute. We make
2264 it a relocation to be relaxed. */
2265 frag_var (rs_machine_dependent
, 4, 0,
2266 ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX
, STATE_UNDF
),
2267 exprP
->X_add_symbol
, exprP
->X_add_number
, opcodep
);
2270 /* Encode a branch displacement in the range -256..254 into the form used
2271 by CRIS conditional branch instructions.
2273 offset The displacement value in bytes. */
2276 branch_disp (offset
)
2281 disp
= offset
& 0xFE;
2289 /* Generate code and fixes for a 32-bit conditional branch instruction
2290 created by "extending" an existing 8-bit branch instruction.
2292 opcodep Pointer to the word containing the original 8-bit branch
2295 writep Pointer to "extension area" following the first instruction
2298 fragP Pointer to the frag containing the instruction.
2300 add_symP, Parts of the destination address expression.
2305 gen_cond_branch_32 (opcodep
, writep
, fragP
, add_symP
, sub_symP
, add_num
)
2313 if (warn_for_branch_expansion
)
2315 /* FIXME: Find out and change to as_warn_where. Add testcase. */
2316 as_warn (_("32-bit conditional branch generated"));
2319 /* Here, writep points to what will be opcodep + 2. First, we change
2320 the actual branch in opcodep[0] and opcodep[1], so that in the
2321 final insn, it will look like:
2324 This means we don't have to worry about changing the opcode or
2325 messing with te delay-slot instruction. So, we move it to last in
2326 the "extended" branch, and just change the displacement. Admittedly,
2327 it's not the optimal extended construct, but we should get this
2328 rarely enough that it shouldn't matter. */
2330 writep
[8] = branch_disp (-2 - 6);
2331 writep
[9] = opcodep
[1];
2333 /* Then, we change the branch to an unconditional branch over the
2334 extended part, to the new location of the Bcc:
2338 Note that these two writes are to currently different locations,
2341 md_number_to_chars (opcodep
, BA_QUICK_OPCODE
+ 8, 2);
2342 md_number_to_chars (writep
, NOP_OPCODE
, 2);
2344 /* Then the extended thing, the 32-bit jump insn.
2345 opcodep+4: JUMP [PC+] */
2347 md_number_to_chars (writep
+ 2, JUMP_PC_INCR_OPCODE
, 2);
2349 /* We have to fill in the actual value too.
2351 This is most probably an expression, but we can cope with an absolute
2352 value too. FIXME: Testcase needed. */
2354 if (add_symP
== NULL
&& sub_symP
== NULL
)
2355 /* An absolute address. */
2356 md_number_to_chars (writep
+ 4, add_num
, 4);
2359 /* Not absolute, we have to make it a frag for later evaluation. */
2360 know (sub_symP
== 0);
2362 fix_new (fragP
, writep
+ 4 - fragP
->fr_literal
, 4, add_symP
,
2363 add_num
, 0, BFD_RELOC_32
);
2369 Turn a string in input_line_pointer into a floating point constant
2370 of type TYPE, and store the appropriate bytes in *LITP. The number
2371 of LITTLENUMS emitted is stored in *SIZEP.
2373 type A character from FLTCHARS that describes what kind of
2374 floating-point number is wanted.
2376 litp A pointer to an array that the result should be stored in.
2378 sizep A pointer to an integer where the size of the result is stored.
2380 But we don't support floating point constants in assembly code *at all*,
2381 since it's suboptimal and just opens up bug opportunities. GCC emits
2382 the bit patterns as hex. All we could do here is to emit what GCC
2383 would have done in the first place. *Nobody* writes floating-point
2384 code as assembly code, but if they do, they should be able enough to
2385 find out the correct bit patterns and use them. */
2388 md_atof (type
, litp
, sizep
)
2389 char type ATTRIBUTE_UNUSED
;
2390 char *litp ATTRIBUTE_UNUSED
;
2391 int *sizep ATTRIBUTE_UNUSED
;
2393 /* FIXME: Is this function mentioned in the internals.texi manual? If
2395 return _("Bad call to md_atof () - floating point formats are not supported");
2398 /* Turn a number as a fixS * into a series of bytes that represents the
2399 number on the target machine. The purpose of this procedure is the
2400 same as that of md_number_to_chars but this procedure is supposed to
2401 handle general bit field fixes and machine-dependent fixups.
2403 bufp Pointer to an array where the result should be stored.
2405 val The value to store.
2407 n The number of bytes in "val" that should be stored.
2409 fixP The fix to be applied to the bit field starting at bufp. */
2412 cris_number_to_imm (bufp
, val
, n
, fixP
)
2423 /* We put the relative "vma" for the other segment for inter-segment
2424 relocations in the object data to stay binary "compatible" (with an
2425 uninteresting old version) for the relocation.
2426 Maybe delete some day. */
2428 && (sym_seg
= S_GET_SEGMENT (fixP
->fx_addsy
)) != now_seg
)
2429 val
+= sym_seg
->vma
;
2431 switch (fixP
->fx_r_type
)
2433 /* Ditto here, we put the addend into the object code as
2434 well as the reloc addend. Keep it that way for now, to simplify
2435 regression tests on the object file contents. FIXME: Seems
2436 uninteresting now that we have a test suite. */
2439 /* No use having warnings here, since most hosts have a 32-bit type
2440 for "long" (which will probably change soon, now that I wrote
2442 bufp
[3] = (val
>> 24) & 0xFF;
2443 bufp
[2] = (val
>> 16) & 0xFF;
2444 bufp
[1] = (val
>> 8) & 0xFF;
2445 bufp
[0] = val
& 0xFF;
2448 /* FIXME: The 16 and 8-bit cases should have a way to check
2449 whether a signed or unsigned (or any signedness) number is
2451 FIXME: Does the as_bad calls find the line number by themselves,
2452 or should we change them into as_bad_where? */
2455 if (val
> 0xffff || val
< -32768)
2456 as_bad (_("Value not in 16 bit range: %ld"), val
);
2457 if (! fixP
->fx_addsy
)
2459 bufp
[1] = (val
>> 8) & 0xFF;
2460 bufp
[0] = val
& 0xFF;
2465 if (val
> 255 || val
< -128)
2466 as_bad (_("Value not in 8 bit range: %ld"), val
);
2467 if (! fixP
->fx_addsy
)
2468 bufp
[0] = val
& 0xFF;
2471 case BFD_RELOC_CRIS_UNSIGNED_4
:
2472 if (val
> 15 || val
< 0)
2473 as_bad (_("Value not in 4 bit unsigned range: %ld"), val
);
2474 if (! fixP
->fx_addsy
)
2475 bufp
[0] |= val
& 0x0F;
2478 case BFD_RELOC_CRIS_UNSIGNED_5
:
2479 if (val
> 31 || val
< 0)
2480 as_bad (_("Value not in 5 bit unsigned range: %ld"), val
);
2481 if (! fixP
->fx_addsy
)
2482 bufp
[0] |= val
& 0x1F;
2485 case BFD_RELOC_CRIS_SIGNED_6
:
2486 if (val
> 31 || val
< -32)
2487 as_bad (_("Value not in 6 bit range: %ld"), val
);
2488 if (! fixP
->fx_addsy
)
2489 bufp
[0] |= val
& 0x3F;
2492 case BFD_RELOC_CRIS_UNSIGNED_6
:
2493 if (val
> 63 || val
< 0)
2494 as_bad (_("Value not in 6 bit unsigned range: %ld"), val
);
2495 if (! fixP
->fx_addsy
)
2496 bufp
[0] |= val
& 0x3F;
2499 case BFD_RELOC_CRIS_BDISP8
:
2500 if (! fixP
->fx_addsy
)
2501 bufp
[0] = branch_disp (val
);
2504 case BFD_RELOC_NONE
:
2505 /* May actually happen automatically. For example at broken
2506 words, if the word turns out not to be broken.
2507 FIXME: When? Which testcase? */
2508 if (! fixP
->fx_addsy
)
2509 md_number_to_chars (bufp
, val
, n
);
2512 case BFD_RELOC_VTABLE_INHERIT
:
2513 /* This borrowed from tc-ppc.c on a whim. */
2515 && !S_IS_DEFINED (fixP
->fx_addsy
)
2516 && !S_IS_WEAK (fixP
->fx_addsy
))
2517 S_SET_WEAK (fixP
->fx_addsy
);
2520 case BFD_RELOC_VTABLE_ENTRY
:
2525 BAD_CASE (fixP
->fx_r_type
);
2529 /* Processes machine-dependent command line options. Called once for
2530 each option on the command line that the machine-independent part of
2531 GAS does not understand. */
2534 md_parse_option (arg
, argp
)
2536 char *argp ATTRIBUTE_UNUSED
;
2542 printf (_("Please use --help to see usage and options for this assembler.\n"));
2543 md_show_usage (stdout
);
2544 exit (EXIT_SUCCESS
);
2547 warn_for_branch_expansion
= 1;
2551 demand_register_prefix
= true;
2553 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
2554 as_bad (_("--no-underscore is invalid with a.out format"), arg
);
2556 symbols_have_leading_underscore
= false;
2560 demand_register_prefix
= false;
2561 symbols_have_leading_underscore
= true;
2569 /* Round up a section size to the appropriate boundary. */
2571 md_section_align (segment
, size
)
2575 /* Round all sects to multiple of 4, except the bss section, which
2576 we'll round to word-size.
2578 FIXME: Check if this really matters. All sections should be
2579 rounded up, and all sections should (optionally) be assumed to be
2580 dword-aligned, it's just that there is actual usage of linking to a
2582 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
2584 if (segment
== bss_section
)
2585 return (size
+ 1) & ~1;
2586 return (size
+ 3) & ~3;
2590 /* FIXME: Is this wanted? It matches the testsuite, but that's not
2591 really a valid reason. */
2592 if (segment
== text_section
)
2593 return (size
+ 3) & ~3;
2599 /* Generate a machine-dependent relocation. */
2601 tc_gen_reloc (section
, fixP
)
2602 asection
*section ATTRIBUTE_UNUSED
;
2606 bfd_reloc_code_real_type code
;
2608 switch (fixP
->fx_r_type
)
2613 case BFD_RELOC_VTABLE_INHERIT
:
2614 case BFD_RELOC_VTABLE_ENTRY
:
2615 code
= fixP
->fx_r_type
;
2618 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2619 _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant"));
2623 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2625 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2626 *relP
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
2627 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2630 /* FIXME: Is this correct? */
2631 relP
->addend
= fixP
->fx_addnumber
;
2633 /* At least *this one* is correct. */
2634 relP
->addend
= fixP
->fx_offset
;
2636 /* This is the standard place for KLUDGEs to work around bugs in
2637 bfd_install_relocation (first such note in the documentation
2638 appears with binutils-2.8).
2640 That function bfd_install_relocation does the wrong thing with
2641 putting stuff into the addend of a reloc (it should stay out) for a
2642 weak symbol. The really bad thing is that it adds the
2643 "segment-relative offset" of the symbol into the reloc. In this
2644 case, the reloc should instead be relative to the symbol with no
2645 other offset than the assembly code shows; and since the symbol is
2646 weak, any local definition should be ignored until link time (or
2648 To wit: weaksym+42 should be weaksym+42 in the reloc,
2649 not weaksym+(offset_from_segment_of_local_weaksym_definition)
2651 To "work around" this, we subtract the segment-relative offset of
2652 "known" weak symbols. This evens out the extra offset.
2654 That happens for a.out but not for ELF, since for ELF,
2655 bfd_install_relocation uses the "special function" field of the
2656 howto, and does not execute the code that needs to be undone. */
2658 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
2659 && fixP
->fx_addsy
&& S_IS_WEAK (fixP
->fx_addsy
)
2660 && ! bfd_is_und_section (S_GET_SEGMENT (fixP
->fx_addsy
)))
2662 relP
->addend
-= S_GET_VALUE (fixP
->fx_addsy
);
2665 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2670 name
= S_GET_NAME (fixP
->fx_addsy
);
2672 name
= _("<unknown>");
2673 as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
2674 name
, bfd_get_reloc_code_name (code
));
2680 /* Machine-dependent usage-output. */
2683 md_show_usage (stream
)
2686 fprintf (stream
, _("CRIS-specific options:\n"));
2687 fprintf (stream
, "%s",
2688 _(" -h, -H Don't execute, print this help text. Deprecated.\n"));
2689 fprintf (stream
, "%s",
2690 _(" -N Warn when branches are expanded to jumps.\n"));
2691 fprintf (stream
, "%s",
2692 _(" --underscore User symbols are normally prepended with underscore.\n"));
2693 fprintf (stream
, "%s",
2694 _(" Registers will not need any prefix.\n"));
2695 fprintf (stream
, "%s",
2696 _(" --no-underscore User symbols do not have any prefix.\n"));
2697 fprintf (stream
, "%s",
2698 _(" Registers will require a `$'-prefix.\n"));
2701 /* Apply a fixS (fixup of an instruction or data that we didn't have
2702 enough info to complete immediately) to the data in a frag. */
2705 md_apply_fix (fixP
, valP
)
2711 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2713 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
2716 if (fixP
->fx_bit_fixP
|| fixP
->fx_im_disp
!= 0)
2718 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("Invalid relocation"));
2723 /* I took this from tc-arc.c, since we used to not support
2724 fx_subsy != NULL. I'm not totally sure it's TRT. */
2725 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
2727 if (S_GET_SEGMENT (fixP
->fx_subsy
) == absolute_section
)
2728 val
-= S_GET_VALUE (fixP
->fx_subsy
);
2731 /* We can't actually support subtracting a symbol. */
2732 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2733 _("expression too complex"));
2737 cris_number_to_imm (buf
, val
, fixP
->fx_size
, fixP
);
2743 /* All relocations are relative to the location just after the fixup;
2744 the address of the fixup plus its size. */
2747 md_pcrel_from (fixP
)
2750 valueT addr
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2752 /* FIXME: We get here only at the end of assembly, when X in ".-X" is
2753 still unknown. Since we don't have pc-relative relocations, this
2754 is invalid. What to do if anything for a.out, is to add
2755 pc-relative relocations everywhere including the elinux program
2757 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2758 _("Invalid pc-relative relocation"));
2759 return fixP
->fx_size
+ addr
;
2762 /* We have no need to give defaults for symbol-values. */
2764 md_undefined_symbol (name
)
2765 char *name ATTRIBUTE_UNUSED
;
2770 /* Definition of TC_FORCE_RELOCATION.
2771 FIXME: Unsure of this. Can we omit it? Just copied from tc-i386.c
2772 when doing multi-object format with ELF, since it's the only other
2773 multi-object-format target with a.out and ELF. */
2775 md_cris_force_relocation (fixp
)
2778 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2779 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2784 /* Check and emit error if broken-word handling has failed to fix up a
2785 case-table. This is called from write.c, after doing everything it
2786 knows about how to handle broken words. */
2789 tc_cris_check_adjusted_broken_word (new_offset
, brokwP
)
2791 struct broken_word
*brokwP
;
2793 if (new_offset
> 32767 || new_offset
< -32768)
2794 /* We really want a genuine error, not a warning, so make it one. */
2795 as_bad_where (brokwP
->frag
->fr_file
, brokwP
->frag
->fr_line
,
2796 _("Adjusted signed .word (%ld) overflows: `switch'-statement too large."),
2800 /* Make a leading REGISTER_PREFIX_CHAR mandatory for all registers. */
2802 static void cris_force_reg_prefix ()
2804 demand_register_prefix
= true;
2807 /* Do not demand a leading REGISTER_PREFIX_CHAR for all registers. */
2809 static void cris_relax_reg_prefix ()
2811 demand_register_prefix
= false;
2814 /* Adjust for having a leading '_' on all user symbols. */
2816 static void cris_sym_leading_underscore ()
2818 /* We can't really do anything more than assert that what the program
2819 thinks symbol starts with agrees with the command-line options, since
2820 the bfd is already created. */
2822 if (symbols_have_leading_underscore
== false)
2823 as_bad (".syntax %s requires command-line option `--underscore'",
2824 SYNTAX_USER_SYM_LEADING_UNDERSCORE
);
2827 /* Adjust for not having any particular prefix on user symbols. */
2829 static void cris_sym_no_leading_underscore ()
2831 if (symbols_have_leading_underscore
== true)
2832 as_bad (".syntax %s requires command-line option `--no-underscore'",
2833 SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE
);
2836 /* Handle the .syntax pseudo, which takes an argument that decides what
2837 syntax the assembly code has. */
2841 int ignore ATTRIBUTE_UNUSED
;
2843 static const struct syntaxes
2845 const char *operand
;
2846 void (*fn
) PARAMS ((void));
2848 {{SYNTAX_ENFORCE_REG_PREFIX
, cris_force_reg_prefix
},
2849 {SYNTAX_RELAX_REG_PREFIX
, cris_relax_reg_prefix
},
2850 {SYNTAX_USER_SYM_LEADING_UNDERSCORE
, cris_sym_leading_underscore
},
2851 {SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE
, cris_sym_no_leading_underscore
}};
2853 const struct syntaxes
*sp
;
2855 for (sp
= syntax_table
;
2856 sp
< syntax_table
+ sizeof (syntax_table
) / sizeof (syntax_table
[0]);
2859 if (strncmp (input_line_pointer
, sp
->operand
,
2860 strlen (sp
->operand
)) == 0)
2864 input_line_pointer
+= strlen (sp
->operand
);
2865 demand_empty_rest_of_line ();
2870 as_bad (_("Unknown .syntax operand"));
2873 /* Wrapper for dwarf2_directive_file to emit error if this is seen when
2874 not emitting ELF. */
2880 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
2881 as_bad ("Pseudodirective .file is only valid when generating ELF");
2883 dwarf2_directive_file (dummy
);
2886 /* Wrapper for dwarf2_directive_loc to emit error if this is seen when not
2893 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
2894 as_bad ("Pseudodirective .loc is only valid when generating ELF");
2896 dwarf2_directive_loc (dummy
);
2901 * eval: (c-set-style "gnu")
2902 * indent-tabs-mode: t