1 /* tc-cris.c -- Assembler code for the CRIS CPU core.
2 Copyright 2000, 2001 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)
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 /* Like in ":GOT", ":GOTOFF" etc. Other ports use '@', but that's in
47 line_separator_chars for CRIS, so we avoid it. */
48 #define PIC_SUFFIX_CHAR ':'
50 /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
51 Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL. */
54 CRIS_INSN_NORMAL, CRIS_INSN_NONE, CRIS_INSN_BRANCH
57 /* An instruction will have one of these prefixes.
58 Although the same bit-pattern, we handle BDAP with an immediate
59 expression (eventually quick or [pc+]) different from when we only have
60 register expressions. */
63 PREFIX_NONE, PREFIX_BDAP_IMM, PREFIX_BDAP, PREFIX_BIAP, PREFIX_DIP,
67 /* The prefix for an instruction. */
70 enum prefix_kind kind;
74 /* There might be an expression to be evaluated, like I in [rN+I]. */
77 /* If there's an expression, we might need a relocation. Here's the
78 type of what relocation to start relaxaton with.
79 The relocation is assumed to start immediately after the prefix insn,
80 so we don't provide an offset. */
81 enum bfd_reloc_code_real reloc;
84 /* The description of the instruction being assembled. */
85 struct cris_instruction
87 /* If CRIS_INSN_NONE, then this insn is of zero length. */
88 enum cris_insn_kind insn_type;
90 /* If a special register was mentioned, this is its description, else
92 const struct cris_spec_reg *spec_reg;
96 /* An insn may have at most one expression; theoretically there could be
97 another in its prefix (but I don't see how that could happen). */
100 /* The expression might need a relocation. Here's one to start
102 enum bfd_reloc_code_real reloc;
104 /* The size in bytes of an immediate expression, or zero if
109 static void cris_process_instruction PARAMS ((char *,
110 struct cris_instruction *,
111 struct cris_prefix *));
112 static int get_bwd_size_modifier PARAMS ((char **, int *));
113 static int get_bw_size_modifier PARAMS ((char **, int *));
114 static int get_gen_reg PARAMS ((char **, int *));
115 static int get_spec_reg PARAMS ((char **,
116 const struct cris_spec_reg **));
117 static int get_autoinc_prefix_or_indir_op PARAMS ((char **,
118 struct cris_prefix *,
121 static int get_3op_or_dip_prefix_op PARAMS ((char **,
122 struct cris_prefix *));
123 static int cris_get_expression PARAMS ((char **, expressionS *));
124 static int get_flags PARAMS ((char **, int *));
125 static void gen_bdap PARAMS ((int, expressionS *));
126 static int branch_disp PARAMS ((int));
127 static void gen_cond_branch_32 PARAMS ((char *, char *, fragS *,
128 symbolS *, symbolS *, long int));
129 static void cris_number_to_imm PARAMS ((char *, long, int, fixS *, segT));
130 static void cris_create_short_jump PARAMS ((char *, addressT, addressT,
131 fragS *, symbolS *));
132 static void s_syntax PARAMS ((int));
133 static void s_cris_file PARAMS ((int));
134 static void s_cris_loc PARAMS ((int));
136 /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes. */
137 static void cris_get_pic_suffix PARAMS ((char **,
138 bfd_reloc_code_real_type *,
140 static unsigned int cris_get_pic_reloc_size
141 PARAMS ((bfd_reloc_code_real_type));
143 /* All the .syntax functions. */
144 static void cris_force_reg_prefix PARAMS ((void));
145 static void cris_relax_reg_prefix PARAMS ((void));
146 static void cris_sym_leading_underscore PARAMS ((void));
147 static void cris_sym_no_leading_underscore PARAMS ((void));
149 /* Handle to the opcode hash table. */
150 static struct hash_control *op_hash = NULL;
152 /* Whether we demand that registers have a `$' prefix. Default here. */
153 static boolean demand_register_prefix = false;
155 /* Whether global user symbols have a leading underscore. Default here. */
156 static boolean symbols_have_leading_underscore = true;
158 /* Whether or not we allow PIC, and expand to PIC-friendly constructs. */
159 static boolean pic = false;
161 const pseudo_typeS md_pseudo_table[] =
164 {"syntax", s_syntax, 0},
165 {"file", s_cris_file, 0},
166 {"loc", s_cris_loc, 0},
170 static int warn_for_branch_expansion = 0;
172 const char cris_comment_chars[] = ";";
174 /* This array holds the chars that only start a comment at the beginning of
175 a line. If the line seems to have the form '# 123 filename'
176 .line and .file directives will appear in the pre-processed output. */
177 /* Note that input_file.c hand-checks for '#' at the beginning of the
178 first line of the input file. This is because the compiler outputs
179 #NO_APP at the beginning of its output. */
180 /* Also note that slash-star will always start a comment. */
181 const char line_comment_chars[] = "#";
182 const char line_separator_chars[] = "@";
184 /* Now all floating point support is shut off. See md_atof. */
185 const char EXP_CHARS[] = "";
186 const char FLT_CHARS[] = "";
188 /* For CRIS, we encode the relax_substateTs (in e.g. fr_substate) as:
190 ---/ /--+-----------------+-----------------+-----------------+
191 | what state ? | how long ? |
192 ---/ /--+-----------------+-----------------+-----------------+
194 The "how long" bits are 00 = byte, 01 = word, 10 = dword (long).
195 This is a Un*x convention.
196 Not all lengths are legit for a given value of (what state).
198 Groups for CRIS address relaxing:
201 length: byte, word, 10-byte expansion
204 length: byte, word, dword */
206 #define STATE_CONDITIONAL_BRANCH (1)
207 #define STATE_BASE_PLUS_DISP_PREFIX (2)
209 #define STATE_LENGTH_MASK (3)
210 #define STATE_BYTE (0)
211 #define STATE_WORD (1)
212 #define STATE_DWORD (2)
213 /* Symbol undefined. */
214 #define STATE_UNDF (3)
215 #define STATE_MAX_LENGTH (3)
217 /* These displacements are relative to the adress following the opcode
218 word of the instruction. The first letter is Byte, Word. The 2nd
219 letter is Forward, Backward. */
221 #define BRANCH_BF ( 254)
222 #define BRANCH_BB (-256)
223 #define BRANCH_WF (2 + 32767)
224 #define BRANCH_WB (2 + -32768)
226 #define BDAP_BF ( 127)
227 #define BDAP_BB (-128)
228 #define BDAP_WF ( 32767)
229 #define BDAP_WB (-32768)
231 #define ENCODE_RELAX(what, length) (((what) << 2) + (length))
233 const relax_typeS md_cris_relax_table[] =
235 /* Error sentinel (0, 0). */
248 {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (1, 1)},
250 /* Bcc [PC+] (1, 1). */
251 {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (1, 2)},
253 /* BEXT/BWF, BA, JUMP (external), JUMP (always), Bnot_cc, JUMP (default)
261 {BDAP_BF, BDAP_BB, 0, ENCODE_RELAX (2, 1)},
263 /* BDAP.[bw] [PC+] (2, 1). */
264 {BDAP_WF, BDAP_WB, 2, ENCODE_RELAX (2, 2)},
266 /* BDAP.d [PC+] (2, 2). */
279 /* Target-specific multicharacter options, not const-declared at usage
280 in 2.9.1 and CVS of 2000-02-16. */
281 struct option md_longopts[] =
283 #define OPTION_NO_US (OPTION_MD_BASE + 0)
284 {"no-underscore", no_argument, NULL, OPTION_NO_US},
285 #define OPTION_US (OPTION_MD_BASE + 1)
286 {"underscore", no_argument, NULL, OPTION_US},
287 #define OPTION_PIC (OPTION_MD_BASE + 2)
288 {"pic", no_argument, NULL, OPTION_PIC},
289 {NULL, no_argument, NULL, 0}
292 /* Not const-declared at usage in 2.9.1. */
293 size_t md_longopts_size = sizeof (md_longopts);
294 const char *md_shortopts = "hHN";
296 /* At first glance, this may seems wrong and should be 4 (ba + nop); but
297 since a short_jump must skip a *number* of long jumps, it must also be
298 a long jump. Here, we hope to make it a "ba [16bit_offs]" and a "nop"
299 for the delay slot and hope that the jump table at most needs
300 32767/4=8191 long-jumps. A branch is better than a jump, since it is
301 relative; we will not have a reloc to fix up somewhere.
303 Note that we can't add relocs, because relaxation uses these fixed
304 numbers, and md_create_short_jump is called after relaxation. */
306 const int md_short_jump_size = 6;
307 const int md_long_jump_size = 6;
309 /* Report output format. Small changes in output format (like elf
310 variants below) can happen until all options are parsed, but after
311 that, the output format must remain fixed. */
314 cris_target_format ()
316 switch (OUTPUT_FLAVOR)
318 case bfd_target_aout_flavour:
321 case bfd_target_elf_flavour:
322 if (symbols_have_leading_underscore)
323 return "elf32-us-cris";
332 /* Prepare machine-dependent frags for relaxation.
334 Called just before relaxation starts. Any symbol that is now undefined
335 will not become defined.
337 Return the correct fr_subtype in the frag.
339 Return the initial "guess for fr_var" to caller. The guess for fr_var
340 is *actually* the growth beyond fr_fix. Whatever we do to grow fr_fix
341 or fr_var contributes to our returned value.
343 Although it may not be explicit in the frag, pretend
344 fr_var starts with a value. */
347 md_estimate_size_before_relax (fragP, segment_type)
349 /* The segment is either N_DATA or N_TEXT. */
354 old_fr_fix = fragP->fr_fix;
356 switch (fragP->fr_subtype)
358 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_UNDF):
359 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
361 /* The symbol lies in the same segment - a relaxable case. */
363 = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
367 /* Unknown or not the same segment, so not relaxable. */
370 /* A small branch-always (2 bytes) to the "real" branch
371 instruction, plus a delay-slot nop (2 bytes), plus a
372 jump (2 plus 4 bytes). See gen_cond_branch_32. */
373 fragP->fr_fix += 2 + 2 + 2 + 4;
374 writep = fragP->fr_literal + old_fr_fix;
375 gen_cond_branch_32 (fragP->fr_opcode, writep, fragP,
376 fragP->fr_symbol, (symbolS *) NULL,
382 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
383 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
384 /* We *might* give a better initial guess if we peek at offsets
385 now, but the caller will relax correctly and without this, so
389 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF):
390 /* Note that we can not do anything sane with relaxing
391 [rX + a_known_symbol_in_text], it will have to be a 32-bit
394 We could play tricks with managing a constant pool and make
395 a_known_symbol_in_text a "bdap [pc + offset]" pointing there
396 (like the GOT for ELF shared libraries), but that's no use, it
397 would in general be no shorter or faster code, only more
400 if (S_GET_SEGMENT (fragP->fr_symbol) != absolute_section)
402 /* Go for dword if not absolute or same segment. */
404 = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD);
409 /* Absolute expression. */
411 value = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset;
413 if (value >= -128 && value <= 127)
415 /* Byte displacement. */
416 (fragP->fr_opcode)[0] = value;
420 /* Word or dword displacement. */
421 int pow2_of_size = 1;
424 if (value < -32768 || value > 32767)
426 /* Outside word range, make it a dword. */
430 /* Modify the byte-offset BDAP into a word or dword offset
431 BDAP. Or really, a BDAP rX,8bit into a
432 BDAP.[wd] rX,[PC+] followed by a word or dword. */
433 (fragP->fr_opcode)[0] = BDAP_PC_LOW + pow2_of_size * 16;
435 /* Keep the register number in the highest four bits. */
436 (fragP->fr_opcode)[1] &= 0xF0;
437 (fragP->fr_opcode)[1] |= BDAP_INCR_HIGH;
439 /* It grew by two or four bytes. */
440 fragP->fr_fix += 1 << pow2_of_size;
441 writep = fragP->fr_literal + old_fr_fix;
442 md_number_to_chars (writep, value, 1 << pow2_of_size);
448 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
449 /* When relaxing a section for the second time, we don't need to
454 BAD_CASE (fragP->fr_subtype);
457 return fragP->fr_var + (fragP->fr_fix - old_fr_fix);
460 /* Perform post-processing of machine-dependent frags after relaxation.
461 Called after relaxation is finished.
463 fr_type == rs_machine_dependent.
464 fr_subtype is what the address relaxed to.
466 Out: Any fixS:s and constants are set up.
468 The caller will turn the frag into a ".space 0". */
471 md_convert_frag (abfd, sec, fragP)
472 bfd *abfd ATTRIBUTE_UNUSED;
473 segT sec ATTRIBUTE_UNUSED;
476 /* Pointer to first byte in variable-sized part of the frag. */
479 /* Pointer to first opcode byte in frag. */
482 /* Used to check integrity of the relaxation.
483 One of 2 = long, 1 = word, or 0 = byte. */
486 /* Size in bytes of variable-sized part of frag. */
487 int var_part_size = 0;
489 /* This is part of *fragP. It contains all information about addresses
490 and offsets to varying parts. */
492 unsigned long var_part_offset;
494 /* Where, in file space, is _var of *fragP? */
495 unsigned long address_of_var_part = 0;
497 /* Where, in file space, does addr point? */
498 unsigned long target_address;
500 know (fragP->fr_type == rs_machine_dependent);
502 length_code = fragP->fr_subtype & STATE_LENGTH_MASK;
503 know (length_code >= 0 && length_code < STATE_MAX_LENGTH);
505 var_part_offset = fragP->fr_fix;
506 var_partp = fragP->fr_literal + var_part_offset;
507 opcodep = fragP->fr_opcode;
509 symbolP = fragP->fr_symbol;
512 ? S_GET_VALUE (symbolP) + symbol_get_frag(fragP->fr_symbol)->fr_address
513 : 0 ) + fragP->fr_offset;
514 address_of_var_part = fragP->fr_address + var_part_offset;
516 switch (fragP->fr_subtype)
518 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
519 opcodep[0] = branch_disp ((target_address - address_of_var_part));
523 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
524 /* We had a quick immediate branch, now turn it into a word one i.e. a
526 opcodep[0] = BRANCH_PC_LOW;
528 opcodep[1] |= BRANCH_INCR_HIGH;
529 md_number_to_chars (var_partp,
530 (long) (target_address - (address_of_var_part + 2)),
535 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_DWORD):
536 gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
537 fragP->fr_symbol, (symbolS *) NULL,
539 /* Ten bytes added: a branch, nop and a jump. */
540 var_part_size = 2 + 2 + 4 + 2;
543 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
544 var_partp[0] = target_address - (address_of_var_part + 1);
548 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
549 /* We had a BDAP 8-bit "quick immediate", now turn it into a 16-bit
550 one that uses PC autoincrement. */
551 opcodep[0] = BDAP_PC_LOW + (1 << 4);
553 opcodep[1] |= BDAP_INCR_HIGH;
554 md_number_to_chars (var_partp, (long) (target_address), 2);
558 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
559 /* We had a BDAP 16-bit "word", change the offset to a dword. */
560 opcodep[0] = BDAP_PC_LOW + (2 << 4);
562 opcodep[1] |= BDAP_INCR_HIGH;
563 if (fragP->fr_symbol == NULL)
564 md_number_to_chars (var_partp, fragP->fr_offset, 4);
566 fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol,
567 fragP->fr_offset, 0, BFD_RELOC_32);
572 BAD_CASE (fragP->fr_subtype);
576 fragP->fr_fix += var_part_size;
579 /* Generate a short jump around a secondary jump table.
580 Used by md_create_long_jump.
582 This used to be md_create_short_jump, but is now called from
583 md_create_long_jump instead, when sufficient.
584 since the sizes of the jumps are the same. It used to be brittle,
585 making possibilities for creating bad code. */
588 cris_create_short_jump (storep, from_addr, to_addr, fragP, to_symbol)
592 fragS *fragP ATTRIBUTE_UNUSED;
593 symbolS *to_symbol ATTRIBUTE_UNUSED;
597 distance = to_addr - from_addr;
599 if (-254 <= distance && distance <= 256)
601 /* Create a "short" short jump: "BA distance - 2". */
602 storep[0] = branch_disp (distance - 2);
603 storep[1] = BA_QUICK_HIGH;
605 /* A nop for the delay slot. */
606 md_number_to_chars (storep + 2, NOP_OPCODE, 2);
608 /* The extra word should be filled with something sane too. Make it
609 a nop to keep disassembly sane. */
610 md_number_to_chars (storep + 4, NOP_OPCODE, 2);
614 /* Make it a "long" short jump: "BA (PC+)". */
615 md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2);
617 /* ".WORD distance - 4". */
618 md_number_to_chars (storep + 2, (long) (distance - 4), 2);
620 /* A nop for the delay slot. */
621 md_number_to_chars (storep + 4, NOP_OPCODE, 2);
625 /* Generate a long jump in a secondary jump table.
627 storep Where to store the jump instruction.
628 from_addr Address of the jump instruction.
629 to_addr Destination address of the jump.
630 fragP Which frag the destination address operand
632 to_symbol Destination symbol. */
635 md_create_long_jump (storep, from_addr, to_addr, fragP, to_symbol)
644 distance = to_addr - from_addr;
646 if (-32763 <= distance && distance <= 32772)
648 /* Then make it a "short" long jump. */
649 cris_create_short_jump (storep, from_addr, to_addr, fragP,
654 /* We have a "long" long jump: "JUMP [PC+]".
655 Make it an "ADD [PC+],PC" if we're supposed to emit PIC code. */
656 md_number_to_chars (storep,
657 pic ? ADD_PC_INCR_OPCODE : JUMP_PC_INCR_OPCODE, 2);
659 /* Follow with a ".DWORD to_addr", PC-relative for PIC. */
660 fix_new (fragP, storep + 2 - fragP->fr_literal, 4, to_symbol,
661 0, pic ? 1 : 0, pic ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
665 /* Port-specific assembler initialization. */
670 const char *hashret = NULL;
673 /* Set up a hash table for the instructions. */
674 op_hash = hash_new ();
676 as_fatal (_("Virtual memory exhausted"));
678 while (cris_opcodes[i].name != NULL)
680 const char *name = cris_opcodes[i].name;
681 hashret = hash_insert (op_hash, name, (PTR) &cris_opcodes[i]);
683 if (hashret != NULL && *hashret != '\0')
684 as_fatal (_("Can't hash `%s': %s\n"), cris_opcodes[i].name,
685 *hashret == 0 ? _("(unknown reason)") : hashret);
688 if (cris_opcodes[i].match & cris_opcodes[i].lose)
689 as_fatal (_("Buggy opcode: `%s' \"%s\"\n"), cris_opcodes[i].name,
690 cris_opcodes[i].args);
694 while (cris_opcodes[i].name != NULL
695 && strcmp (cris_opcodes[i].name, name) == 0);
699 /* Assemble a source line. */
705 struct cris_instruction output_instruction;
706 struct cris_prefix prefix;
713 /* Do the low-level grunt - assemble to bits and split up into a prefix
714 and ordinary insn. */
715 cris_process_instruction (str, &output_instruction, &prefix);
717 /* Handle any prefixes to the instruction. */
723 /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
724 extra bytes, so we handle it separately. */
725 case PREFIX_BDAP_IMM:
726 /* We only do it if the relocation is unspecified, i.e. not a PIC
728 if (prefix.reloc == BFD_RELOC_NONE)
730 gen_bdap (prefix.base_reg_number, &prefix.expr);
738 opcodep = frag_more (2);
740 /* Output the prefix opcode. */
741 md_number_to_chars (opcodep, (long) prefix.opcode, 2);
743 /* Having a specified reloc only happens for DIP and for BDAP with
744 PIC operands, but it is ok to drop through here for the other
745 prefixes as they can have no relocs specified. */
746 if (prefix.reloc != BFD_RELOC_NONE)
748 unsigned int relocsize
749 = (prefix.kind == PREFIX_DIP
750 ? 4 : cris_get_pic_reloc_size (prefix.reloc));
752 insn_size += relocsize;
753 p = frag_more (relocsize);
754 fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize,
755 &prefix.expr, 0, prefix.reloc);
761 opcodep = frag_more (2);
763 /* Output the prefix opcode. Being a "push", we add the negative
764 size of the register to "sp". */
765 if (output_instruction.spec_reg != NULL)
767 /* Special register. */
768 opcodep[0] = -output_instruction.spec_reg->reg_size;
772 /* General register. */
775 opcodep[1] = (REG_SP << 4) + (BDAP_QUICK_OPCODE >> 8);
779 BAD_CASE (prefix.kind);
782 /* If we only had a prefix insn, we're done. */
783 if (output_instruction.insn_type == CRIS_INSN_NONE)
786 /* Done with the prefix. Continue with the main instruction. */
788 opcodep = frag_more (2);
790 /* Output the instruction opcode. */
791 md_number_to_chars (opcodep, (long) (output_instruction.opcode), 2);
793 /* Output the symbol-dependent instruction stuff. */
794 if (output_instruction.insn_type == CRIS_INSN_BRANCH)
796 segT to_seg = absolute_section;
797 int is_undefined = 0;
800 if (output_instruction.expr.X_op != O_constant)
802 to_seg = S_GET_SEGMENT (output_instruction.expr.X_add_symbol);
804 if (to_seg == undefined_section)
808 if (output_instruction.expr.X_op == O_constant
809 || to_seg == now_seg || is_undefined)
811 /* Handle complex expressions. */
813 = (output_instruction.expr.X_op_symbol != NULL
814 ? 0 : output_instruction.expr.X_add_number);
816 = (output_instruction.expr.X_op_symbol != NULL
817 ? make_expr_symbol (&output_instruction.expr)
818 : output_instruction.expr.X_add_symbol);
820 /* If is_undefined, then the expression may BECOME now_seg. */
821 length_code = is_undefined ? STATE_UNDF : STATE_BYTE;
823 /* Make room for max ten bytes of variable length. */
824 frag_var (rs_machine_dependent, 10, 0,
825 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, length_code),
826 sym, addvalue, opcodep);
830 /* We have: to_seg != now_seg && to_seg != undefined_section.
831 This means it is a branch to a known symbol in another
832 section. Code in data? Weird but valid. Emit a 32-bit
834 char *cond_jump = frag_more (10);
837 gen_cond_branch_32 (opcodep, cond_jump, frag_now,
838 output_instruction.expr.X_add_symbol,
840 output_instruction.expr.X_add_number);
845 if (output_instruction.imm_oprnd_size > 0)
847 /* The intruction has an immediate operand. */
848 enum bfd_reloc_code_real reloc = BFD_RELOC_NONE;
850 switch (output_instruction.imm_oprnd_size)
852 /* Any byte-size immediate constants are treated as
853 word-size. FIXME: Thus overflow check does not work
857 /* Note that size-check for the explicit reloc has already
858 been done when we get here. */
859 if (output_instruction.reloc != BFD_RELOC_NONE)
860 reloc = output_instruction.reloc;
862 reloc = BFD_RELOC_16;
866 /* Allow a relocation specified in the operand. */
867 if (output_instruction.reloc != BFD_RELOC_NONE)
868 reloc = output_instruction.reloc;
870 reloc = BFD_RELOC_32;
874 BAD_CASE (output_instruction.imm_oprnd_size);
877 insn_size += output_instruction.imm_oprnd_size;
878 p = frag_more (output_instruction.imm_oprnd_size);
879 fix_new_exp (frag_now, (p - frag_now->fr_literal),
880 output_instruction.imm_oprnd_size,
881 &output_instruction.expr, 0, reloc);
883 else if (output_instruction.reloc != BFD_RELOC_NONE)
885 /* An immediate operand that has a relocation and needs to be
886 processed further. */
888 /* It is important to use fix_new_exp here and everywhere else
889 (and not fix_new), as fix_new_exp can handle "difference
890 expressions" - where the expression contains a difference of
891 two symbols in the same segment. */
892 fix_new_exp (frag_now, (opcodep - frag_now->fr_literal), 2,
893 &output_instruction.expr, 0,
894 output_instruction.reloc);
898 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
899 dwarf2_emit_insn (insn_size);
902 /* Low level text-to-bits assembly. */
905 cris_process_instruction (insn_text, out_insnp, prefixp)
907 struct cris_instruction *out_insnp;
908 struct cris_prefix *prefixp;
911 char modified_char = 0;
913 struct cris_opcode *instruction;
920 /* Reset these fields to a harmless state in case we need to return in
922 prefixp->kind = PREFIX_NONE;
923 prefixp->reloc = BFD_RELOC_NONE;
924 out_insnp->insn_type = CRIS_INSN_NORMAL;
925 out_insnp->imm_oprnd_size = 0;
927 /* Find the end of the opcode mnemonic. We assume (true in 2.9.1)
928 that the caller has translated the opcode to lower-case, up to the
930 for (operands = insn_text; islower (*operands); ++operands)
933 /* Terminate the opcode after letters, but save the character there if
934 it was of significance. */
941 /* Put back the modified character later. */
942 modified_char = *operands;
946 /* Consume the character after the mnemonic
947 and replace it with '\0'. */
952 as_bad (_("Unknown opcode: `%s'"), insn_text);
956 /* Find the instruction. */
957 instruction = (struct cris_opcode *) hash_find (op_hash, insn_text);
958 if (instruction == NULL)
960 as_bad (_("Unknown opcode: `%s'"), insn_text);
964 /* Put back the modified character. */
965 switch (modified_char)
971 *--operands = modified_char;
974 /* Try to match an opcode table slot. */
979 /* Initialize *prefixp, perhaps after being modified for a
981 prefixp->kind = PREFIX_NONE;
982 prefixp->reloc = BFD_RELOC_NONE;
984 /* Initialize *out_insnp. */
985 memset (out_insnp, 0, sizeof (*out_insnp));
986 out_insnp->opcode = instruction->match;
987 out_insnp->reloc = BFD_RELOC_NONE;
988 out_insnp->insn_type = CRIS_INSN_NORMAL;
989 out_insnp->imm_oprnd_size = 0;
993 /* Build the opcode, checking as we go to make sure that the
995 for (args = instruction->args;; ++args)
1000 /* If we've come to the end of arguments, we're done. */
1006 /* Non-matcher character for disassembly.
1012 /* These must match exactly. */
1018 /* This is not really an operand, but causes a "BDAP
1019 -size,SP" prefix to be output, for PUSH instructions. */
1020 prefixp->kind = PREFIX_PUSH;
1024 /* This letter marks an operand that should not be matched
1025 in the assembler. It is a branch with 16-bit
1026 displacement. The assembler will create them from the
1027 8-bit flavor when necessary. The assembler does not
1028 support the [rN+] operand, as the [r15+] that is
1029 generated for 16-bit displacements. */
1033 /* A 5-bit unsigned immediate in bits <4:0>. */
1034 if (! cris_get_expression (&s, &out_insnp->expr))
1038 if (out_insnp->expr.X_op == O_constant
1039 && (out_insnp->expr.X_add_number < 0
1040 || out_insnp->expr.X_add_number > 31))
1041 as_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
1042 out_insnp->expr.X_add_number);
1044 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
1049 /* A 4-bit unsigned immediate in bits <3: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 < 0
1056 || out_insnp->expr.X_add_number > 15))
1057 as_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
1058 out_insnp->expr.X_add_number);
1060 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
1065 /* General register in bits <15:12> and <3:0>. */
1066 if (! get_gen_reg (&s, ®no))
1070 out_insnp->opcode |= regno /* << 0 */;
1071 out_insnp->opcode |= regno << 12;
1076 /* Flags from the condition code register. */
1080 if (! get_flags (&s, &flags))
1083 out_insnp->opcode |= ((flags & 0xf0) << 8) | (flags & 0xf);
1088 /* A 6-bit signed immediate in bits <5:0>. */
1089 if (! cris_get_expression (&s, &out_insnp->expr))
1093 if (out_insnp->expr.X_op == O_constant
1094 && (out_insnp->expr.X_add_number < -32
1095 || out_insnp->expr.X_add_number > 31))
1096 as_bad (_("Immediate value not in 6 bit range: %ld"),
1097 out_insnp->expr.X_add_number);
1098 out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
1103 /* A 6-bit unsigned immediate in bits <5:0>. */
1104 if (! cris_get_expression (&s, &out_insnp->expr))
1108 if (out_insnp->expr.X_op == O_constant
1109 && (out_insnp->expr.X_add_number < 0
1110 || out_insnp->expr.X_add_number > 63))
1111 as_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
1112 out_insnp->expr.X_add_number);
1113 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
1118 /* A size modifier, B, W or D, to be put in a bit position
1119 suitable for CLEAR instructions (i.e. reflecting a zero
1121 if (! get_bwd_size_modifier (&s, &size_bits))
1128 out_insnp->opcode |= 0 << 12;
1132 out_insnp->opcode |= 4 << 12;
1136 out_insnp->opcode |= 8 << 12;
1143 /* A size modifier, B, W or D, to be put in bits <5:4>. */
1144 if (! get_bwd_size_modifier (&s, &size_bits))
1148 out_insnp->opcode |= size_bits << 4;
1153 /* A branch expression. */
1154 if (! cris_get_expression (&s, &out_insnp->expr))
1158 out_insnp->insn_type = CRIS_INSN_BRANCH;
1163 /* A BDAP expression for any size, "expr,r". */
1164 if (! cris_get_expression (&s, &prefixp->expr))
1173 if (!get_gen_reg (&s, &prefixp->base_reg_number))
1176 /* Since 'O' is used with an explicit bdap, we have no
1177 "real" instruction. */
1178 prefixp->kind = PREFIX_BDAP_IMM;
1180 = BDAP_QUICK_OPCODE | (prefixp->base_reg_number << 12);
1182 out_insnp->insn_type = CRIS_INSN_NONE;
1187 /* Special register in bits <15:12>. */
1188 if (! get_spec_reg (&s, &out_insnp->spec_reg))
1192 /* Use of some special register names come with a
1193 specific warning. Note that we have no ".cpu type"
1194 pseudo yet, so some of this is just unused
1196 if (out_insnp->spec_reg->warning)
1197 as_warn (out_insnp->spec_reg->warning);
1198 else if (out_insnp->spec_reg->applicable_version
1199 == cris_ver_warning)
1200 /* Others have a generic warning. */
1201 as_warn (_("Unimplemented register `%s' specified"),
1202 out_insnp->spec_reg->name);
1205 |= out_insnp->spec_reg->number << 12;
1210 /* This character is used in the disassembler to
1211 recognize a prefix instruction to fold into the
1212 addressing mode for the next instruction. It is
1217 /* General register in bits <15:12>. */
1218 if (! get_gen_reg (&s, ®no))
1222 out_insnp->opcode |= regno << 12;
1227 /* General register in bits <3:0>. */
1228 if (! get_gen_reg (&s, ®no))
1232 out_insnp->opcode |= regno /* << 0 */;
1237 /* Source operand in bit <10> and a prefix; a 3-operand
1239 if (! get_3op_or_dip_prefix_op (&s, prefixp))
1245 /* Source operand in bits <10>, <3:0> and optionally a
1246 prefix; i.e. an indirect operand or an side-effect
1248 if (! get_autoinc_prefix_or_indir_op (&s, prefixp, &mode,
1255 if (prefixp->kind != PREFIX_NONE)
1257 /* A prefix, so it has the autoincrement bit
1259 out_insnp->opcode |= (AUTOINCR_BIT << 8);
1263 /* No prefix. The "mode" variable contains bits like
1264 whether or not this is autoincrement mode. */
1265 out_insnp->opcode |= (mode << 10);
1267 /* If there was a PIC reloc specifier, then it was
1268 attached to the prefix. Note that we can't check
1269 that the reloc size matches, since we don't have
1270 all the operands yet in all cases. */
1271 if (prefixp->reloc != BFD_RELOC_NONE)
1272 out_insnp->reloc = prefixp->reloc;
1275 out_insnp->opcode |= regno /* << 0 */ ;
1280 /* Rs.m in bits <15:12> and <5:4>. */
1281 if (! get_gen_reg (&s, ®no)
1282 || ! get_bwd_size_modifier (&s, &size_bits))
1286 out_insnp->opcode |= (regno << 12) | (size_bits << 4);
1291 /* Source operand in bits <10>, <3:0> and optionally a
1292 prefix; i.e. an indirect operand or an side-effect
1295 The difference to 's' is that this does not allow an
1296 "immediate" expression. */
1297 if (! get_autoinc_prefix_or_indir_op (&s, prefixp,
1305 if (prefixp->kind != PREFIX_NONE)
1307 /* A prefix, and those matched here always have
1308 side-effects (see 's' case). */
1309 out_insnp->opcode |= (AUTOINCR_BIT << 8);
1313 /* No prefix. The "mode" variable contains bits
1314 like whether or not this is autoincrement
1316 out_insnp->opcode |= (mode << 10);
1319 out_insnp->opcode |= regno /* << 0 */;
1324 /* Size modifier (B or W) in bit <4>. */
1325 if (! get_bw_size_modifier (&s, &size_bits))
1329 out_insnp->opcode |= size_bits << 4;
1337 /* We get here when we fail a match above or we found a
1338 complete match. Break out of this loop. */
1342 /* Was it a match or a miss? */
1345 /* If it's just that the args don't match, maybe the next
1346 item in the table is the same opcode but with
1347 matching operands. */
1348 if (instruction[1].name != NULL
1349 && ! strcmp (instruction->name, instruction[1].name))
1351 /* Yep. Restart and try that one instead. */
1358 /* We've come to the end of instructions with this
1359 opcode, so it must be an error. */
1360 as_bad (_("Illegal operands"));
1366 /* We have a match. Check if there's anything more to do. */
1369 /* There was an immediate mode operand, so we must check
1370 that it has an appropriate size. */
1371 switch (instruction->imm_oprnd_size)
1375 /* Shouldn't happen; this one does not have immediate
1376 operands with different sizes. */
1377 BAD_CASE (instruction->imm_oprnd_size);
1381 out_insnp->imm_oprnd_size = 4;
1385 switch (out_insnp->spec_reg->reg_size)
1388 if (out_insnp->expr.X_op == O_constant
1389 && (out_insnp->expr.X_add_number < -128
1390 || out_insnp->expr.X_add_number > 255))
1391 as_bad (_("Immediate value not in 8 bit range: %ld"),
1392 out_insnp->expr.X_add_number);
1395 /* FIXME: We need an indicator in the instruction
1396 table to pass on, to indicate if we need to check
1397 overflow for a signed or unsigned number. */
1398 if (out_insnp->expr.X_op == O_constant
1399 && (out_insnp->expr.X_add_number < -32768
1400 || out_insnp->expr.X_add_number > 65535))
1401 as_bad (_("Immediate value not in 16 bit range: %ld"),
1402 out_insnp->expr.X_add_number);
1403 out_insnp->imm_oprnd_size = 2;
1407 out_insnp->imm_oprnd_size = 4;
1411 BAD_CASE (out_insnp->spec_reg->reg_size);
1419 if (out_insnp->expr.X_op == O_constant
1420 && (out_insnp->expr.X_add_number < -128
1421 || out_insnp->expr.X_add_number > 255))
1422 as_bad (_("Immediate value not in 8 bit range: %ld"),
1423 out_insnp->expr.X_add_number);
1426 if (out_insnp->expr.X_op == O_constant
1427 && (out_insnp->expr.X_add_number < -32768
1428 || out_insnp->expr.X_add_number > 65535))
1429 as_bad (_("Immediate value not in 16 bit range: %ld"),
1430 out_insnp->expr.X_add_number);
1431 out_insnp->imm_oprnd_size = 2;
1435 out_insnp->imm_oprnd_size = 4;
1439 BAD_CASE (out_insnp->spec_reg->reg_size);
1443 /* If there was a relocation specified for the immediate
1444 expression (i.e. it had a PIC modifier) check that the
1445 size of the PIC relocation matches the size specified by
1447 if (out_insnp->reloc != BFD_RELOC_NONE
1448 && (cris_get_pic_reloc_size (out_insnp->reloc)
1449 != (unsigned int) out_insnp->imm_oprnd_size))
1450 as_bad (_("PIC relocation size does not match operand size"));
1457 /* Get a B, W, or D size modifier from the string pointed out by *cPP,
1458 which must point to a '.' in front of the modifier. On successful
1459 return, *cPP is advanced to the character following the size
1460 modifier, and is undefined otherwise.
1462 cPP Pointer to pointer to string starting
1463 with the size modifier.
1465 size_bitsp Pointer to variable to contain the size bits on
1468 Return 1 iff a correct size modifier is found, else 0. */
1471 get_bwd_size_modifier (cPP, size_bitsp)
1479 /* Consume the '.'. */
1503 /* Consume the size letter. */
1509 /* Get a B or W size modifier from the string pointed out by *cPP,
1510 which must point to a '.' in front of the modifier. On successful
1511 return, *cPP is advanced to the character following the size
1512 modifier, and is undefined otherwise.
1514 cPP Pointer to pointer to string starting
1515 with the size modifier.
1517 size_bitsp Pointer to variable to contain the size bits on
1520 Return 1 iff a correct size modifier is found, else 0. */
1523 get_bw_size_modifier (cPP, size_bitsp)
1531 /* Consume the '.'. */
1550 /* Consume the size letter. */
1556 /* Get a general register from the string pointed out by *cPP. The
1557 variable *cPP is advanced to the character following the general
1558 register name on a successful return, and has its initial position
1561 cPP Pointer to pointer to string, beginning with a general
1564 regnop Pointer to int containing the register number.
1566 Return 1 iff a correct general register designator is found,
1570 get_gen_reg (cPP, regnop)
1577 /* Handle a sometimes-mandatory dollar sign as register prefix. */
1578 if (**cPP == REGISTER_PREFIX_CHAR)
1580 else if (demand_register_prefix)
1587 /* "P" as in "PC"? Consume the "P". */
1590 if ((**cPP == 'C' || **cPP == 'c')
1591 && ! isalnum ((*cPP)[1]))
1593 /* It's "PC": consume the "c" and we're done. */
1602 /* Hopefully r[0-9] or r1[0-5]. Consume 'R' or 'r'. */
1605 if (isdigit (**cPP))
1607 /* It's r[0-9]. Consume and check the next digit. */
1608 *regnop = **cPP - '0';
1611 if (! isalnum (**cPP))
1613 /* No more digits, we're done. */
1618 /* One more digit. Consume and add. */
1619 *regnop = *regnop * 10 + (**cPP - '0');
1621 /* We need to check for a valid register number; Rn,
1622 0 <= n <= MAX_REG. */
1623 if (*regnop <= MAX_REG)
1625 /* Consume second digit. */
1635 /* "S" as in "SP"? Consume the "S". */
1637 if (**cPP == 'P' || **cPP == 'p')
1639 /* It's "SP": consume the "p" and we're done. */
1647 /* Just here to silence compilation warnings. */
1651 /* We get here if we fail. Restore the pointer. */
1656 /* Get a special register from the string pointed out by *cPP. The
1657 variable *cPP is advanced to the character following the special
1658 register name if one is found, and retains its original position
1661 cPP Pointer to pointer to string starting with a special register
1664 sregpp Pointer to Pointer to struct spec_reg, where a pointer to the
1665 register description will be stored.
1667 Return 1 iff a correct special register name is found. */
1670 get_spec_reg (cPP, sregpp)
1672 const struct cris_spec_reg **sregpp;
1676 char *name_begin = *cPP;
1678 const struct cris_spec_reg *sregp;
1680 /* Handle a sometimes-mandatory dollar sign as register prefix. */
1681 if (*name_begin == REGISTER_PREFIX_CHAR)
1683 else if (demand_register_prefix)
1686 /* Loop over all special registers. */
1687 for (sregp = cris_spec_regs; sregp->name != NULL; sregp++)
1689 /* Start over from beginning of the supposed name. */
1694 && (isupper (*s1) ? tolower (*s1) == *s2 : *s1 == *s2))
1700 /* For a match, we must have consumed the name in the table, and we
1701 must be outside what could be part of a name. Assume here that a
1702 test for alphanumerics is sufficient for a name test. */
1703 if (*s2 == 0 && ! isalnum (*s1))
1705 /* We have a match. Update the pointer and be done. */
1712 /* If we got here, we did not find any name. */
1716 /* Get an unprefixed or side-effect-prefix operand from the string pointed
1717 out by *cPP. The pointer *cPP is advanced to the character following
1718 the indirect operand if we have success, else it contains an undefined
1721 cPP Pointer to pointer to string beginning with the first
1722 character of the supposed operand.
1724 prefixp Pointer to structure containing an optional instruction
1727 is_autoincp Pointer to int indicating the indirect or autoincrement
1730 src_regnop Pointer to int containing the source register number in
1733 imm_foundp Pointer to an int indicating if an immediate expression
1736 imm_exprP Pointer to a structure containing an immediate
1737 expression, if success and if *imm_foundp is nonzero.
1739 Return 1 iff a correct indirect operand is found. */
1742 get_autoinc_prefix_or_indir_op (cPP, prefixp, is_autoincp, src_regnop,
1743 imm_foundp, imm_exprP)
1745 struct cris_prefix *prefixp;
1749 expressionS *imm_exprP;
1751 /* Assume there was no immediate mode expression. */
1756 /* So this operand is one of:
1758 Autoincrement: [rN+]
1759 Indexed with assign: [rN=rM+rO.S]
1760 Offset with assign: [rN=rM+I], [rN=rM+[rO].s], [rN=rM+[rO+].s]
1762 Either way, consume the '['. */
1765 /* Get the rN register. */
1766 if (! get_gen_reg (cPP, src_regnop))
1767 /* If there was no register, then this cannot match. */
1771 /* We got the register, now check the next character. */
1775 /* Indirect mode. We're done here. */
1776 prefixp->kind = PREFIX_NONE;
1781 /* This must be an auto-increment mode, if there's a
1783 prefixp->kind = PREFIX_NONE;
1786 /* We consume this character and break out to check the
1792 /* This must be indexed with assign, or offset with assign
1796 /* Either way, the next thing must be a register. */
1797 if (! get_gen_reg (cPP, &prefixp->base_reg_number))
1798 /* No register, no match. */
1802 /* We've consumed "[rN=rM", so we must be looking at
1803 "+rO.s]" or "+I]", or "-I]", or "+[rO].s]" or
1807 int index_reg_number;
1813 /* This must be [rx=ry+[rz].s] or
1814 [rx=ry+[rz+].s] or no match. We must be
1815 looking at rz after consuming the '['. */
1818 if (!get_gen_reg (cPP, &index_reg_number))
1821 prefixp->kind = PREFIX_BDAP;
1823 = (BDAP_INDIR_OPCODE
1824 + (prefixp->base_reg_number << 12)
1825 + index_reg_number);
1829 /* We've seen "[rx=ry+[rz+" here, so now we
1830 know that there must be "].s]" left to
1833 prefixp->opcode |= AUTOINCR_BIT << 8;
1836 /* If it wasn't autoincrement, we don't need to
1839 /* Check the next-to-last ']'. */
1845 /* Check the ".s" modifier. */
1846 if (! get_bwd_size_modifier (cPP, &size_bits))
1849 prefixp->opcode |= size_bits << 4;
1851 /* Now we got [rx=ry+[rz+].s or [rx=ry+[rz].s.
1852 We break out to check the final ']'. */
1855 /* It wasn't an indirection. Check if it's a
1857 else if (get_gen_reg (cPP, &index_reg_number))
1861 /* Indexed with assign mode: "[rN+rM.S]". */
1862 prefixp->kind = PREFIX_BIAP;
1864 = (BIAP_OPCODE + (index_reg_number << 12)
1865 + prefixp->base_reg_number /* << 0 */);
1867 if (! get_bwd_size_modifier (cPP, &size_bits))
1868 /* Size missing, this isn't a match. */
1872 /* Size found, break out to check the
1874 prefixp->opcode |= size_bits << 4;
1878 /* Not a register. Then this must be "[rN+I]". */
1879 else if (cris_get_expression (cPP, &prefixp->expr))
1881 /* We've got offset with assign mode. Fill
1882 in the blanks and break out to match the
1884 prefixp->kind = PREFIX_BDAP_IMM;
1886 /* We tentatively put an opcode corresponding to
1887 a 32-bit operand here, although it may be
1888 relaxed when there's no PIC specifier for the
1891 = (BDAP_INDIR_OPCODE
1892 | (prefixp->base_reg_number << 12)
1893 | (AUTOINCR_BIT << 8)
1895 | REG_PC /* << 0 */);
1897 /* This can have a PIC suffix, specifying reloc
1899 if (pic && **cPP == PIC_SUFFIX_CHAR)
1901 unsigned int relocsize;
1903 cris_get_pic_suffix (cPP, &prefixp->reloc,
1906 /* Tweak the size of the immediate operand
1907 in the prefix opcode if it isn't what we
1910 = cris_get_pic_reloc_size (prefixp->reloc);
1913 = ((prefixp->opcode & ~(3 << 4))
1914 | ((relocsize >> 1) << 4));
1919 /* Neither register nor expression found, so
1920 this can't be a match. */
1923 /* Not "[rN+" but perhaps "[rN-"? */
1924 else if (**cPP == '-')
1926 /* We must have an offset with assign mode. */
1927 if (! cris_get_expression (cPP, &prefixp->expr))
1928 /* No expression, no match. */
1932 /* We've got offset with assign mode. Fill
1933 in the blanks and break out to match the
1936 Note that we don't allow a PIC suffix for an
1937 operand with a minus sign. */
1938 prefixp->kind = PREFIX_BDAP_IMM;
1943 /* Neither '+' nor '-' after "[rN=rM". Lose. */
1947 /* Neither ']' nor '+' nor '=' after "[rN". Lose. */
1952 /* When we get here, we have a match and will just check the closing
1953 ']'. We can still fail though. */
1958 /* Don't forget to consume the final ']'.
1959 Then return in glory. */
1964 /* No indirection. Perhaps a constant? */
1965 else if (cris_get_expression (cPP, imm_exprP))
1967 /* Expression found, this is immediate mode. */
1968 prefixp->kind = PREFIX_NONE;
1970 *src_regnop = REG_PC;
1973 /* This can have a PIC suffix, specifying reloc type to use. The
1974 caller must check that the reloc size matches the operand size. */
1975 if (pic && **cPP == PIC_SUFFIX_CHAR)
1976 cris_get_pic_suffix (cPP, &prefixp->reloc, imm_exprP);
1981 /* No luck today. */
1985 /* This function gets an indirect operand in a three-address operand
1986 combination from the string pointed out by *cPP. The pointer *cPP is
1987 advanced to the character following the indirect operand on success, or
1988 has an unspecified value on failure.
1990 cPP Pointer to pointer to string begining
1993 prefixp Pointer to structure containing an
1996 Returns 1 iff a correct indirect operand is found. */
1999 get_3op_or_dip_prefix_op (cPP, prefixp)
2001 struct cris_prefix *prefixp;
2006 /* We must have a '[' or it's a clean failure. */
2009 /* Eat the first '['. */
2014 /* A second '[', so this must be double-indirect mode. */
2016 prefixp->kind = PREFIX_DIP;
2017 prefixp->opcode = DIP_OPCODE;
2019 /* Get the register or fail entirely. */
2020 if (! get_gen_reg (cPP, ®_number))
2024 prefixp->opcode |= reg_number /* << 0 */ ;
2027 /* Since we found a '+', this must be double-indirect
2028 autoincrement mode. */
2030 prefixp->opcode |= AUTOINCR_BIT << 8;
2033 /* There's nothing particular to do, if this was a
2034 double-indirect *without* autoincrement. */
2037 /* Check the first ']'. The second one is checked at the end. */
2041 /* Eat the first ']', so we'll be looking at a second ']'. */
2044 /* No second '['. Then we should have a register here, making
2046 else if (get_gen_reg (cPP, &prefixp->base_reg_number))
2048 /* This must be indexed or offset mode: "[rN+I]" or
2049 "[rN+rM.S]" or "[rN+[rM].S]" or "[rN+[rM+].S]". */
2052 int index_reg_number;
2058 /* This is "[rx+["... Expect a register next. */
2062 if (!get_gen_reg (cPP, &index_reg_number))
2065 prefixp->kind = PREFIX_BDAP;
2067 = (BDAP_INDIR_OPCODE
2068 + (prefixp->base_reg_number << 12)
2069 + index_reg_number);
2071 /* We've seen "[rx+[ry", so check if this is
2075 /* Yep, now at "[rx+[ry+". */
2077 prefixp->opcode |= AUTOINCR_BIT << 8;
2079 /* If it wasn't autoincrement, we don't need to
2082 /* Check a first closing ']': "[rx+[ry]" or
2088 /* Now expect a size modifier ".S". */
2089 if (! get_bwd_size_modifier (cPP, &size_bits))
2092 prefixp->opcode |= size_bits << 4;
2094 /* Ok, all interesting stuff has been seen:
2095 "[rx+[ry+].S" or "[rx+[ry].S". We only need to
2096 expect a final ']', which we'll do in a common
2099 /* Seen "[rN+", but not a '[', so check if we have a
2101 else if (get_gen_reg (cPP, &index_reg_number))
2103 /* This is indexed mode: "[rN+rM.S]" or
2106 prefixp->kind = PREFIX_BIAP;
2109 | prefixp->base_reg_number /* << 0 */
2110 | (index_reg_number << 12));
2112 /* Consume the ".S". */
2113 if (! get_bwd_size_modifier (cPP, &size_bits))
2114 /* Missing size, so fail. */
2117 /* Size found. Add that piece and drop down to
2118 the common checking of the closing ']'. */
2119 prefixp->opcode |= size_bits << 4;
2121 /* Seen "[rN+", but not a '[' or a register, so then
2122 it must be a constant "I". */
2123 else if (cris_get_expression (cPP, &prefixp->expr))
2125 /* Expression found, so fill in the bits of offset
2126 mode and drop down to check the closing ']'. */
2127 prefixp->kind = PREFIX_BDAP_IMM;
2129 /* We tentatively put an opcode corresponding to a 32-bit
2130 operand here, although it may be relaxed when there's no
2131 PIC specifier for the operand. */
2133 = (BDAP_INDIR_OPCODE
2134 | (prefixp->base_reg_number << 12)
2135 | (AUTOINCR_BIT << 8)
2137 | REG_PC /* << 0 */);
2139 /* This can have a PIC suffix, specifying reloc type to use. */
2140 if (pic && **cPP == PIC_SUFFIX_CHAR)
2142 unsigned int relocsize;
2144 cris_get_pic_suffix (cPP, &prefixp->reloc, &prefixp->expr);
2146 /* Tweak the size of the immediate operand in the prefix
2147 opcode if it isn't what we set. */
2148 relocsize = cris_get_pic_reloc_size (prefixp->reloc);
2151 = ((prefixp->opcode & ~(3 << 4))
2152 | ((relocsize >> 1) << 4));
2156 /* Nothing valid here: lose. */
2159 /* Seen "[rN" but no '+', so check if it's a '-'. */
2160 else if (**cPP == '-')
2162 /* Yep, we must have offset mode. */
2163 if (! cris_get_expression (cPP, &prefixp->expr))
2164 /* No expression, so we lose. */
2168 /* Expression found to make this offset mode, so
2169 fill those bits and drop down to check the
2172 Note that we don't allow a PIC suffix for
2173 an operand with a minus sign like this. */
2174 prefixp->kind = PREFIX_BDAP_IMM;
2179 /* We've seen "[rN", but not '+' or '-'; rather a ']'.
2180 Hmm. Normally this is a simple indirect mode that we
2181 shouldn't match, but if we expect ']', then we have a
2182 zero offset, so it can be a three-address-operand,
2183 like "[rN],rO,rP", thus offset mode.
2185 Don't eat the ']', that will be done in the closing
2187 prefixp->expr.X_op = O_constant;
2188 prefixp->expr.X_add_number = 0;
2189 prefixp->expr.X_add_symbol = NULL;
2190 prefixp->expr.X_op_symbol = NULL;
2191 prefixp->kind = PREFIX_BDAP_IMM;
2194 /* A '[', but no second '[', and no register. Check if we
2195 have an expression, making this "[I]" for a double-indirect
2197 else if (cris_get_expression (cPP, &prefixp->expr))
2199 /* Expression found, the so called absolute mode for a
2200 double-indirect prefix on PC. */
2201 prefixp->kind = PREFIX_DIP;
2202 prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
2203 prefixp->reloc = BFD_RELOC_32;
2206 /* Neither '[' nor register nor expression. We lose. */
2209 /* We get here as a closing ceremony to a successful match. We just
2210 need to check the closing ']'. */
2212 /* Oops. Close but no air-polluter. */
2215 /* Don't forget to consume that ']', before returning in glory. */
2220 /* Get an expression from the string pointed out by *cPP.
2221 The pointer *cPP is advanced to the character following the expression
2222 on a success, or retains its original value otherwise.
2224 cPP Pointer to pointer to string beginning with the expression.
2226 exprP Pointer to structure containing the expression.
2228 Return 1 iff a correct expression is found. */
2231 cris_get_expression (cPP, exprP)
2235 char *saved_input_line_pointer;
2238 /* The "expression" function expects to find an expression at the
2239 global variable input_line_pointer, so we have to save it to give
2240 the impression that we don't fiddle with global variables. */
2241 saved_input_line_pointer = input_line_pointer;
2242 input_line_pointer = *cPP;
2244 exp = expression (exprP);
2245 if (exprP->X_op == O_illegal || exprP->X_op == O_absent)
2247 input_line_pointer = saved_input_line_pointer;
2251 /* Everything seems to be fine, just restore the global
2252 input_line_pointer and say we're successful. */
2253 *cPP = input_line_pointer;
2254 input_line_pointer = saved_input_line_pointer;
2258 /* Get a sequence of flag characters from *spp. The pointer *cPP is
2259 advanced to the character following the expression. The flag
2260 characters are consecutive, no commas or spaces.
2262 cPP Pointer to pointer to string beginning with the expression.
2264 flagp Pointer to int to return the flags expression.
2266 Return 1 iff a correct flags expression is found. */
2269 get_flags (cPP, flagsp)
2322 /* We consider this successful if we stop at a comma or
2323 whitespace. Anything else, and we consider it a failure. */
2326 && ! isspace (**cPP))
2332 /* Don't forget to consume each flag character. */
2337 /* Generate code and fixes for a BDAP prefix.
2339 base_regno Int containing the base register number.
2341 exprP Pointer to structure containing the offset expression. */
2344 gen_bdap (base_regno, exprP)
2348 unsigned int opcode;
2351 /* Put out the prefix opcode; assume quick immediate mode at first. */
2352 opcode = BDAP_QUICK_OPCODE | (base_regno << 12);
2353 opcodep = frag_more (2);
2354 md_number_to_chars (opcodep, opcode, 2);
2356 if (exprP->X_op == O_constant)
2358 /* We have an absolute expression that we know the size of right
2363 value = exprP->X_add_number;
2364 if (value < -32768 || value > 32767)
2365 /* Outside range for a "word", make it a dword. */
2368 /* Assume "word" size. */
2371 /* If this is a signed-byte value, we can fit it into the prefix
2373 if (value >= -128 && value <= 127)
2377 /* This is a word or dword displacement, which will be put in a
2378 word or dword after the prefix. */
2381 opcodep[0] = BDAP_PC_LOW + (size << 4);
2383 opcodep[1] |= BDAP_INCR_HIGH;
2384 p = frag_more (1 << size);
2385 md_number_to_chars (p, value, 1 << size);
2390 /* Handle complex expressions. */
2392 = exprP->X_op_symbol != NULL ? 0 : exprP->X_add_number;
2394 = (exprP->X_op_symbol != NULL
2395 ? make_expr_symbol (exprP) : exprP->X_add_symbol);
2397 /* The expression is not defined yet but may become absolute. We
2398 make it a relocation to be relaxed. */
2399 frag_var (rs_machine_dependent, 4, 0,
2400 ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF),
2401 sym, addvalue, opcodep);
2405 /* Encode a branch displacement in the range -256..254 into the form used
2406 by CRIS conditional branch instructions.
2408 offset The displacement value in bytes. */
2411 branch_disp (offset)
2416 disp = offset & 0xFE;
2424 /* Generate code and fixes for a 32-bit conditional branch instruction
2425 created by "extending" an existing 8-bit branch instruction.
2427 opcodep Pointer to the word containing the original 8-bit branch
2430 writep Pointer to "extension area" following the first instruction
2433 fragP Pointer to the frag containing the instruction.
2435 add_symP, Parts of the destination address expression.
2440 gen_cond_branch_32 (opcodep, writep, fragP, add_symP, sub_symP, add_num)
2448 if (warn_for_branch_expansion)
2449 as_warn_where (fragP->fr_file, fragP->fr_line,
2450 _("32-bit conditional branch generated"));
2452 /* Here, writep points to what will be opcodep + 2. First, we change
2453 the actual branch in opcodep[0] and opcodep[1], so that in the
2454 final insn, it will look like:
2457 This means we don't have to worry about changing the opcode or
2458 messing with the delay-slot instruction. So, we move it to last in
2459 the "extended" branch, and just change the displacement. Admittedly,
2460 it's not the optimal extended construct, but we should get this
2461 rarely enough that it shouldn't matter. */
2463 writep[8] = branch_disp (-2 - 6);
2464 writep[9] = opcodep[1];
2466 /* Then, we change the branch to an unconditional branch over the
2467 extended part, to the new location of the Bcc:
2471 Note that these two writes are to currently different locations,
2474 md_number_to_chars (opcodep, BA_QUICK_OPCODE + 8, 2);
2475 md_number_to_chars (writep, NOP_OPCODE, 2);
2477 /* Then the extended thing, the 32-bit jump insn.
2478 opcodep+4: JUMP [PC+]
2479 or, in the PIC case,
2480 opcodep+4: ADD [PC+],PC. */
2482 md_number_to_chars (writep + 2,
2483 pic ? ADD_PC_INCR_OPCODE : JUMP_PC_INCR_OPCODE, 2);
2485 /* We have to fill in the actual value too.
2487 This is most probably an expression, but we can cope with an absolute
2488 value too. FIXME: Testcase needed with and without pic. */
2490 if (add_symP == NULL && sub_symP == NULL)
2492 /* An absolute address. */
2494 fix_new (fragP, writep + 4 - fragP->fr_literal, 4,
2495 section_symbol (absolute_section),
2496 add_num, 1, BFD_RELOC_32_PCREL);
2498 md_number_to_chars (writep + 4, add_num, 4);
2502 if (sub_symP != NULL)
2503 as_bad_where (fragP->fr_file, fragP->fr_line,
2504 _("Complex expression not supported"));
2506 /* Not absolute, we have to make it a frag for later evaluation. */
2507 fix_new (fragP, writep + 4 - fragP->fr_literal, 4, add_symP,
2508 add_num, pic ? 1 : 0, pic ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
2512 /* Get the size of an immediate-reloc in bytes. Only valid for PIC
2516 cris_get_pic_reloc_size (reloc)
2517 bfd_reloc_code_real_type reloc;
2519 return reloc == BFD_RELOC_CRIS_16_GOTPLT || reloc == BFD_RELOC_CRIS_16_GOT
2523 /* Store a reloc type at *RELOCP corresponding to the PIC suffix at *CPP.
2524 Adjust *EXPRP with any addend found after the PIC suffix. */
2527 cris_get_pic_suffix (cPP, relocp, exprP)
2529 bfd_reloc_code_real_type *relocp;
2534 expressionS const_expr;
2536 const struct pic_suffixes_struct
2538 const char *const suffix;
2540 bfd_reloc_code_real_type reloc;
2544 #define PICMAP(s, r) {s, sizeof (s) - 1, r}
2545 /* Keep this in order with longest unambiguous prefix first. */
2546 PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT),
2547 PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT),
2548 PICMAP ("PLTG", BFD_RELOC_CRIS_32_PLT_GOTREL),
2549 PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL),
2550 PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL),
2551 PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT),
2552 PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT)
2555 /* We've already seen the ':', so consume it. */
2558 for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++)
2560 if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0
2561 && ! is_part_of_name (s[pic_suffixes[i].len]))
2563 /* We have a match. Consume the suffix and set the relocation
2565 s += pic_suffixes[i].len;
2567 /* There can be a constant term appended. If so, we will add it
2569 if (*s == '+' || *s == '-')
2571 if (! cris_get_expression (&s, &const_expr))
2572 /* There was some kind of syntax error. Bail out. */
2575 /* Allow complex expressions as the constant part. It still
2576 has to be a assembly-time constant or there will be an
2577 error emitting the reloc. This makes the PIC qualifiers
2578 idempotent; foo:GOTOFF+32 == foo+32:GOTOFF. The former we
2579 recognize here; the latter is parsed in the incoming
2581 exprP->X_add_symbol = make_expr_symbol (exprP);
2582 exprP->X_op = O_add;
2583 exprP->X_add_number = 0;
2584 exprP->X_op_symbol = make_expr_symbol (&const_expr);
2587 *relocp = pic_suffixes[i].reloc;
2593 /* No match. Don't consume anything; fall back and there will be a
2599 Turn a string in input_line_pointer into a floating point constant
2600 of type TYPE, and store the appropriate bytes in *LITP. The number
2601 of LITTLENUMS emitted is stored in *SIZEP.
2603 type A character from FLTCHARS that describes what kind of
2604 floating-point number is wanted.
2606 litp A pointer to an array that the result should be stored in.
2608 sizep A pointer to an integer where the size of the result is stored.
2610 But we don't support floating point constants in assembly code *at all*,
2611 since it's suboptimal and just opens up bug opportunities. GCC emits
2612 the bit patterns as hex. All we could do here is to emit what GCC
2613 would have done in the first place. *Nobody* writes floating-point
2614 code as assembly code, but if they do, they should be able enough to
2615 find out the correct bit patterns and use them. */
2618 md_atof (type, litp, sizep)
2619 char type ATTRIBUTE_UNUSED;
2620 char *litp ATTRIBUTE_UNUSED;
2621 int *sizep ATTRIBUTE_UNUSED;
2623 /* FIXME: Is this function mentioned in the internals.texi manual? If
2625 return _("Bad call to md_atof () - floating point formats are not supported");
2628 /* Turn a number as a fixS * into a series of bytes that represents the
2629 number on the target machine. The purpose of this procedure is the
2630 same as that of md_number_to_chars but this procedure is supposed to
2631 handle general bit field fixes and machine-dependent fixups.
2633 bufp Pointer to an array where the result should be stored.
2635 val The value to store.
2637 n The number of bytes in "val" that should be stored.
2639 fixP The fix to be applied to the bit field starting at bufp.
2641 seg The segment containing this number. */
2644 cris_number_to_imm (bufp, val, n, fixP, seg)
2656 /* We put the relative "vma" for the other segment for inter-segment
2657 relocations in the object data to stay binary "compatible" (with an
2658 uninteresting old version) for the relocation.
2659 Maybe delete some day. */
2661 && (sym_seg = S_GET_SEGMENT (fixP->fx_addsy)) != seg)
2662 val += sym_seg->vma;
2664 if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
2665 switch (fixP->fx_r_type)
2667 /* These must be fully resolved when getting here. */
2668 case BFD_RELOC_32_PCREL:
2669 case BFD_RELOC_16_PCREL:
2670 case BFD_RELOC_8_PCREL:
2671 as_bad_where (fixP->fx_frag->fr_file, fixP->fx_frag->fr_line,
2672 _("PC-relative relocation must be trivially resolved"));
2677 switch (fixP->fx_r_type)
2679 /* Ditto here, we put the addend into the object code as
2680 well as the reloc addend. Keep it that way for now, to simplify
2681 regression tests on the object file contents. FIXME: Seems
2682 uninteresting now that we have a test suite. */
2684 case BFD_RELOC_CRIS_16_GOT:
2685 case BFD_RELOC_CRIS_32_GOT:
2686 case BFD_RELOC_CRIS_32_GOTREL:
2687 case BFD_RELOC_CRIS_16_GOTPLT:
2688 case BFD_RELOC_CRIS_32_GOTPLT:
2689 case BFD_RELOC_CRIS_32_PLT_GOTREL:
2690 case BFD_RELOC_CRIS_32_PLT_PCREL:
2691 /* We don't want to put in any kind of non-zero bits in the data
2692 being relocated for these. */
2696 case BFD_RELOC_32_PCREL:
2697 /* No use having warnings here, since most hosts have a 32-bit type
2698 for "long" (which will probably change soon, now that I wrote
2700 bufp[3] = (val >> 24) & 0xFF;
2701 bufp[2] = (val >> 16) & 0xFF;
2702 bufp[1] = (val >> 8) & 0xFF;
2703 bufp[0] = val & 0xFF;
2706 /* FIXME: The 16 and 8-bit cases should have a way to check
2707 whether a signed or unsigned (or any signedness) number is
2709 FIXME: Does the as_bad calls find the line number by themselves,
2710 or should we change them into as_bad_where? */
2713 case BFD_RELOC_16_PCREL:
2714 if (val > 0xffff || val < -32768)
2715 as_bad (_("Value not in 16 bit range: %ld"), val);
2716 if (! fixP->fx_addsy)
2718 bufp[1] = (val >> 8) & 0xFF;
2719 bufp[0] = val & 0xFF;
2724 case BFD_RELOC_8_PCREL:
2725 if (val > 255 || val < -128)
2726 as_bad (_("Value not in 8 bit range: %ld"), val);
2727 if (! fixP->fx_addsy)
2728 bufp[0] = val & 0xFF;
2731 case BFD_RELOC_CRIS_UNSIGNED_4:
2732 if (val > 15 || val < 0)
2733 as_bad (_("Value not in 4 bit unsigned range: %ld"), val);
2734 if (! fixP->fx_addsy)
2735 bufp[0] |= val & 0x0F;
2738 case BFD_RELOC_CRIS_UNSIGNED_5:
2739 if (val > 31 || val < 0)
2740 as_bad (_("Value not in 5 bit unsigned range: %ld"), val);
2741 if (! fixP->fx_addsy)
2742 bufp[0] |= val & 0x1F;
2745 case BFD_RELOC_CRIS_SIGNED_6:
2746 if (val > 31 || val < -32)
2747 as_bad (_("Value not in 6 bit range: %ld"), val);
2748 if (! fixP->fx_addsy)
2749 bufp[0] |= val & 0x3F;
2752 case BFD_RELOC_CRIS_UNSIGNED_6:
2753 if (val > 63 || val < 0)
2754 as_bad (_("Value not in 6 bit unsigned range: %ld"), val);
2755 if (! fixP->fx_addsy)
2756 bufp[0] |= val & 0x3F;
2759 case BFD_RELOC_CRIS_BDISP8:
2760 if (! fixP->fx_addsy)
2761 bufp[0] = branch_disp (val);
2764 case BFD_RELOC_NONE:
2765 /* May actually happen automatically. For example at broken
2766 words, if the word turns out not to be broken.
2767 FIXME: When? Which testcase? */
2768 if (! fixP->fx_addsy)
2769 md_number_to_chars (bufp, val, n);
2772 case BFD_RELOC_VTABLE_INHERIT:
2773 /* This borrowed from tc-ppc.c on a whim. */
2775 && !S_IS_DEFINED (fixP->fx_addsy)
2776 && !S_IS_WEAK (fixP->fx_addsy))
2777 S_SET_WEAK (fixP->fx_addsy);
2780 case BFD_RELOC_VTABLE_ENTRY:
2785 BAD_CASE (fixP->fx_r_type);
2789 /* Processes machine-dependent command line options. Called once for
2790 each option on the command line that the machine-independent part of
2791 GAS does not understand. */
2794 md_parse_option (arg, argp)
2796 char *argp ATTRIBUTE_UNUSED;
2802 printf (_("Please use --help to see usage and options for this assembler.\n"));
2803 md_show_usage (stdout);
2804 exit (EXIT_SUCCESS);
2807 warn_for_branch_expansion = 1;
2811 demand_register_prefix = true;
2813 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
2814 as_bad (_("--no-underscore is invalid with a.out format"));
2816 symbols_have_leading_underscore = false;
2820 demand_register_prefix = false;
2821 symbols_have_leading_underscore = true;
2833 /* Round up a section size to the appropriate boundary. */
2835 md_section_align (segment, size)
2839 /* Round all sects to multiple of 4, except the bss section, which
2840 we'll round to word-size.
2842 FIXME: Check if this really matters. All sections should be
2843 rounded up, and all sections should (optionally) be assumed to be
2844 dword-aligned, it's just that there is actual usage of linking to a
2846 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
2848 if (segment == bss_section)
2849 return (size + 1) & ~1;
2850 return (size + 3) & ~3;
2854 /* FIXME: Is this wanted? It matches the testsuite, but that's not
2855 really a valid reason. */
2856 if (segment == text_section)
2857 return (size + 3) & ~3;
2863 /* Generate a machine-dependent relocation. */
2865 tc_gen_reloc (section, fixP)
2866 asection *section ATTRIBUTE_UNUSED;
2870 bfd_reloc_code_real_type code;
2872 switch (fixP->fx_r_type)
2874 case BFD_RELOC_CRIS_16_GOT:
2875 case BFD_RELOC_CRIS_32_GOT:
2876 case BFD_RELOC_CRIS_16_GOTPLT:
2877 case BFD_RELOC_CRIS_32_GOTPLT:
2878 case BFD_RELOC_CRIS_32_GOTREL:
2879 case BFD_RELOC_CRIS_32_PLT_GOTREL:
2880 case BFD_RELOC_CRIS_32_PLT_PCREL:
2884 case BFD_RELOC_VTABLE_INHERIT:
2885 case BFD_RELOC_VTABLE_ENTRY:
2886 code = fixP->fx_r_type;
2889 as_bad_where (fixP->fx_file, fixP->fx_line,
2890 _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant"));
2894 relP = (arelent *) xmalloc (sizeof (arelent));
2896 relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2897 *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
2898 relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
2901 /* FIXME: Is this correct? */
2902 relP->addend = fixP->fx_addnumber;
2904 /* At least *this one* is correct. */
2905 relP->addend = fixP->fx_offset;
2907 /* This is the standard place for KLUDGEs to work around bugs in
2908 bfd_install_relocation (first such note in the documentation
2909 appears with binutils-2.8).
2911 That function bfd_install_relocation does the wrong thing with
2912 putting stuff into the addend of a reloc (it should stay out) for a
2913 weak symbol. The really bad thing is that it adds the
2914 "segment-relative offset" of the symbol into the reloc. In this
2915 case, the reloc should instead be relative to the symbol with no
2916 other offset than the assembly code shows; and since the symbol is
2917 weak, any local definition should be ignored until link time (or
2919 To wit: weaksym+42 should be weaksym+42 in the reloc,
2920 not weaksym+(offset_from_segment_of_local_weaksym_definition)
2922 To "work around" this, we subtract the segment-relative offset of
2923 "known" weak symbols. This evens out the extra offset.
2925 That happens for a.out but not for ELF, since for ELF,
2926 bfd_install_relocation uses the "special function" field of the
2927 howto, and does not execute the code that needs to be undone. */
2929 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
2930 && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
2931 && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
2933 relP->addend -= S_GET_VALUE (fixP->fx_addsy);
2936 relP->howto = bfd_reloc_type_lookup (stdoutput, code);
2941 name = S_GET_NAME (fixP->fx_addsy);
2943 name = _("<unknown>");
2944 as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
2945 name, bfd_get_reloc_code_name (code));
2951 /* Machine-dependent usage-output. */
2954 md_show_usage (stream)
2957 /* The messages are formatted to line up with the generic options. */
2958 fprintf (stream, _("CRIS-specific options:\n"));
2959 fprintf (stream, "%s",
2960 _(" -h, -H Don't execute, print this help text. Deprecated.\n"));
2961 fprintf (stream, "%s",
2962 _(" -N Warn when branches are expanded to jumps.\n"));
2963 fprintf (stream, "%s",
2964 _(" --underscore User symbols are normally prepended with underscore.\n"));
2965 fprintf (stream, "%s",
2966 _(" Registers will not need any prefix.\n"));
2967 fprintf (stream, "%s",
2968 _(" --no-underscore User symbols do not have any prefix.\n"));
2969 fprintf (stream, "%s",
2970 _(" Registers will require a `$'-prefix.\n"));
2971 fprintf (stream, "%s",
2972 _(" --pic Enable generation of position-independent code.\n"));
2975 /* Apply a fixS (fixup of an instruction or data that we didn't have
2976 enough info to complete immediately) to the data in a frag. */
2979 md_apply_fix3 (fixP, valP, seg)
2986 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2988 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
2991 if (fixP->fx_bit_fixP || fixP->fx_im_disp != 0)
2993 as_bad_where (fixP->fx_file, fixP->fx_line, _("Invalid relocation"));
2998 /* I took this from tc-arc.c, since we used to not support
2999 fx_subsy != NULL. I'm not totally sure it's TRT. */
3000 if (fixP->fx_subsy != (symbolS *) NULL)
3002 if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section)
3003 val -= S_GET_VALUE (fixP->fx_subsy);
3006 /* We can't actually support subtracting a symbol. */
3007 as_bad_where (fixP->fx_file, fixP->fx_line,
3008 _("expression too complex"));
3012 cris_number_to_imm (buf, val, fixP->fx_size, fixP, seg);
3018 /* All relocations are relative to the location just after the fixup;
3019 the address of the fixup plus its size. */
3022 md_pcrel_from (fixP)
3025 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
3027 /* FIXME: We get here only at the end of assembly, when X in ".-X" is
3028 still unknown. Since we don't have pc-relative relocations in a.out,
3029 this is invalid. What to do if anything for a.out, is to add
3030 pc-relative relocations everywhere including the elinux program
3031 loader. For ELF, allow straight-forward PC-relative relocations,
3032 which are always relative to the location after the relocation. */
3033 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
3034 || (fixP->fx_r_type != BFD_RELOC_8_PCREL
3035 && fixP->fx_r_type != BFD_RELOC_16_PCREL
3036 && fixP->fx_r_type != BFD_RELOC_32_PCREL))
3037 as_bad_where (fixP->fx_file, fixP->fx_line,
3038 _("Invalid pc-relative relocation"));
3039 return fixP->fx_size + addr;
3042 /* We have no need to give defaults for symbol-values. */
3044 md_undefined_symbol (name)
3045 char *name ATTRIBUTE_UNUSED;
3050 /* Definition of TC_FORCE_RELOCATION.
3051 FIXME: Unsure of this. Can we omit it? Just copied from tc-i386.c
3052 when doing multi-object format with ELF, since it's the only other
3053 multi-object-format target with a.out and ELF. */
3055 md_cris_force_relocation (fixp)
3058 switch (fixp->fx_r_type)
3060 case BFD_RELOC_VTABLE_INHERIT:
3061 case BFD_RELOC_VTABLE_ENTRY:
3062 case BFD_RELOC_CRIS_16_GOT:
3063 case BFD_RELOC_CRIS_32_GOT:
3064 case BFD_RELOC_CRIS_16_GOTPLT:
3065 case BFD_RELOC_CRIS_32_GOTPLT:
3066 case BFD_RELOC_CRIS_32_GOTREL:
3067 case BFD_RELOC_CRIS_32_PLT_GOTREL:
3068 case BFD_RELOC_CRIS_32_PLT_PCREL:
3077 /* Check and emit error if broken-word handling has failed to fix up a
3078 case-table. This is called from write.c, after doing everything it
3079 knows about how to handle broken words. */
3082 tc_cris_check_adjusted_broken_word (new_offset, brokwP)
3084 struct broken_word *brokwP;
3086 if (new_offset > 32767 || new_offset < -32768)
3087 /* We really want a genuine error, not a warning, so make it one. */
3088 as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line,
3089 _("Adjusted signed .word (%ld) overflows: `switch'-statement too large."),
3093 /* Make a leading REGISTER_PREFIX_CHAR mandatory for all registers. */
3095 static void cris_force_reg_prefix ()
3097 demand_register_prefix = true;
3100 /* Do not demand a leading REGISTER_PREFIX_CHAR for all registers. */
3102 static void cris_relax_reg_prefix ()
3104 demand_register_prefix = false;
3107 /* Adjust for having a leading '_' on all user symbols. */
3109 static void cris_sym_leading_underscore ()
3111 /* We can't really do anything more than assert that what the program
3112 thinks symbol starts with agrees with the command-line options, since
3113 the bfd is already created. */
3115 if (symbols_have_leading_underscore == false)
3116 as_bad (".syntax %s requires command-line option `--underscore'",
3117 SYNTAX_USER_SYM_LEADING_UNDERSCORE);
3120 /* Adjust for not having any particular prefix on user symbols. */
3122 static void cris_sym_no_leading_underscore ()
3124 if (symbols_have_leading_underscore == true)
3125 as_bad (".syntax %s requires command-line option `--no-underscore'",
3126 SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE);
3129 /* Handle the .syntax pseudo, which takes an argument that decides what
3130 syntax the assembly code has. */
3134 int ignore ATTRIBUTE_UNUSED;
3136 static const struct syntaxes
3138 const char *operand;
3139 void (*fn) PARAMS ((void));
3141 {{SYNTAX_ENFORCE_REG_PREFIX, cris_force_reg_prefix},
3142 {SYNTAX_RELAX_REG_PREFIX, cris_relax_reg_prefix},
3143 {SYNTAX_USER_SYM_LEADING_UNDERSCORE, cris_sym_leading_underscore},
3144 {SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE, cris_sym_no_leading_underscore}};
3146 const struct syntaxes *sp;
3148 for (sp = syntax_table;
3149 sp < syntax_table + sizeof (syntax_table) / sizeof (syntax_table[0]);
3152 if (strncmp (input_line_pointer, sp->operand,
3153 strlen (sp->operand)) == 0)
3157 input_line_pointer += strlen (sp->operand);
3158 demand_empty_rest_of_line ();
3163 as_bad (_("Unknown .syntax operand"));
3166 /* Wrapper for dwarf2_directive_file to emit error if this is seen when
3167 not emitting ELF. */
3173 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
3174 as_bad ("Pseudodirective .file is only valid when generating ELF");
3176 dwarf2_directive_file (dummy);
3179 /* Wrapper for dwarf2_directive_loc to emit error if this is seen when not
3186 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
3187 as_bad ("Pseudodirective .loc is only valid when generating ELF");
3189 dwarf2_directive_loc (dummy);
3194 * eval: (c-set-style "gnu")
3195 * indent-tabs-mode: t