1 /* tc-cris.c -- Assembler code for the CRIS CPU core.
2 Copyright 2000, 2001, 2002, 2003 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. */
27 #include "safe-ctype.h"
29 #include "opcode/cris.h"
30 #include "dwarf2dbg.h"
32 /* Conventions used here:
33 Generally speaking, pointers to binutils types such as "fragS" and
34 "expressionS" get parameter and variable names ending in "P", such as
35 "fragP", to harmonize with the rest of the binutils code. Other
36 pointers get a "p" suffix, such as "bufp". Any function or type-name
37 that could clash with a current or future binutils or GAS function get
40 #define SYNTAX_RELAX_REG_PREFIX "no_register_prefix"
41 #define SYNTAX_ENFORCE_REG_PREFIX "register_prefix"
42 #define SYNTAX_USER_SYM_LEADING_UNDERSCORE "leading_underscore"
43 #define SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE "no_leading_underscore"
44 #define REGISTER_PREFIX_CHAR '$'
46 /* True for expressions where getting X_add_symbol and X_add_number is
47 enough to get the "base" and "offset"; no need to make_expr_symbol.
48 It's not enough to check if X_op_symbol is NULL; that misses unary
49 operations like O_uminus. */
50 #define SIMPLE_EXPR(EXP) \
51 ((EXP)->X_op == O_constant || (EXP)->X_op == O_symbol)
53 /* Like in ":GOT", ":GOTOFF" etc. Other ports use '@', but that's in
54 line_separator_chars for CRIS, so we avoid it. */
55 #define PIC_SUFFIX_CHAR ':'
57 /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
58 Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL. */
61 CRIS_INSN_NORMAL, CRIS_INSN_NONE, CRIS_INSN_BRANCH, CRIS_INSN_MUL
64 /* An instruction will have one of these prefixes.
65 Although the same bit-pattern, we handle BDAP with an immediate
66 expression (eventually quick or [pc+]) different from when we only have
67 register expressions. */
70 PREFIX_NONE, PREFIX_BDAP_IMM, PREFIX_BDAP, PREFIX_BIAP, PREFIX_DIP,
74 /* The prefix for an instruction. */
77 enum prefix_kind kind;
81 /* There might be an expression to be evaluated, like I in [rN+I]. */
84 /* If there's an expression, we might need a relocation. Here's the
85 type of what relocation to start relaxaton with.
86 The relocation is assumed to start immediately after the prefix insn,
87 so we don't provide an offset. */
88 enum bfd_reloc_code_real reloc;
91 /* The description of the instruction being assembled. */
92 struct cris_instruction
94 /* If CRIS_INSN_NONE, then this insn is of zero length. */
95 enum cris_insn_kind insn_type;
97 /* If a special register was mentioned, this is its description, else
99 const struct cris_spec_reg *spec_reg;
103 /* An insn may have at most one expression; theoretically there could be
104 another in its prefix (but I don't see how that could happen). */
107 /* The expression might need a relocation. Here's one to start
109 enum bfd_reloc_code_real reloc;
111 /* The size in bytes of an immediate expression, or zero if
116 static void cris_process_instruction PARAMS ((char *,
117 struct cris_instruction *,
118 struct cris_prefix *));
119 static int get_bwd_size_modifier PARAMS ((char **, int *));
120 static int get_bw_size_modifier PARAMS ((char **, int *));
121 static int get_gen_reg PARAMS ((char **, int *));
122 static int get_spec_reg PARAMS ((char **,
123 const struct cris_spec_reg **));
124 static int get_autoinc_prefix_or_indir_op PARAMS ((char **,
125 struct cris_prefix *,
128 static int get_3op_or_dip_prefix_op PARAMS ((char **,
129 struct cris_prefix *));
130 static int cris_get_expression PARAMS ((char **, expressionS *));
131 static int get_flags PARAMS ((char **, int *));
132 static void gen_bdap PARAMS ((int, expressionS *));
133 static int branch_disp PARAMS ((int));
134 static void gen_cond_branch_32 PARAMS ((char *, char *, fragS *,
135 symbolS *, symbolS *, long int));
136 static void cris_number_to_imm PARAMS ((char *, long, int, fixS *, segT));
137 static void cris_create_short_jump PARAMS ((char *, addressT, addressT,
138 fragS *, symbolS *));
139 static void s_syntax PARAMS ((int));
140 static void s_cris_file PARAMS ((int));
141 static void s_cris_loc PARAMS ((int));
143 /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes. */
144 static void cris_get_pic_suffix PARAMS ((char **,
145 bfd_reloc_code_real_type *,
147 static unsigned int cris_get_pic_reloc_size
148 PARAMS ((bfd_reloc_code_real_type));
150 /* All the .syntax functions. */
151 static void cris_force_reg_prefix PARAMS ((void));
152 static void cris_relax_reg_prefix PARAMS ((void));
153 static void cris_sym_leading_underscore PARAMS ((void));
154 static void cris_sym_no_leading_underscore PARAMS ((void));
155 static char *cris_insn_first_word_frag PARAMS ((void));
157 /* Handle to the opcode hash table. */
158 static struct hash_control *op_hash = NULL;
160 /* If we target cris-axis-linux-gnu (as opposed to generic cris-axis-elf),
161 we default to no underscore and required register-prefixes. The
162 difference is in the default values. */
164 #define DEFAULT_CRIS_AXIS_LINUX_GNU TRUE
166 #define DEFAULT_CRIS_AXIS_LINUX_GNU FALSE
169 /* Whether we demand that registers have a `$' prefix. Default here. */
170 static bfd_boolean demand_register_prefix = DEFAULT_CRIS_AXIS_LINUX_GNU;
172 /* Whether global user symbols have a leading underscore. Default here. */
173 static bfd_boolean symbols_have_leading_underscore
174 = !DEFAULT_CRIS_AXIS_LINUX_GNU;
176 /* Whether or not we allow PIC, and expand to PIC-friendly constructs. */
177 static bfd_boolean pic = FALSE;
179 const pseudo_typeS md_pseudo_table[] =
182 {"syntax", s_syntax, 0},
183 {"file", s_cris_file, 0},
184 {"loc", s_cris_loc, 0},
188 static int warn_for_branch_expansion = 0;
190 /* Whether to emit error when a MULS/MULU could be located last on a
192 static int err_for_dangerous_mul_placement = 1;
194 const char cris_comment_chars[] = ";";
196 /* This array holds the chars that only start a comment at the beginning of
197 a line. If the line seems to have the form '# 123 filename'
198 .line and .file directives will appear in the pre-processed output. */
199 /* Note that input_file.c hand-checks for '#' at the beginning of the
200 first line of the input file. This is because the compiler outputs
201 #NO_APP at the beginning of its output. */
202 /* Also note that slash-star will always start a comment. */
203 const char line_comment_chars[] = "#";
204 const char line_separator_chars[] = "@";
206 /* Now all floating point support is shut off. See md_atof. */
207 const char EXP_CHARS[] = "";
208 const char FLT_CHARS[] = "";
210 /* For CRIS, we encode the relax_substateTs (in e.g. fr_substate) as:
212 ---/ /--+-----------------+-----------------+-----------------+
213 | what state ? | how long ? |
214 ---/ /--+-----------------+-----------------+-----------------+
216 The "how long" bits are 00 = byte, 01 = word, 10 = dword (long).
217 This is a Un*x convention.
218 Not all lengths are legit for a given value of (what state).
220 Groups for CRIS address relaxing:
223 length: byte, word, 10-byte expansion
226 length: byte, word, dword
229 Not really a relaxation (no infrastructure to get delay-slots
230 right), just an alignment and placement checker for the v10
231 multiply/cache-bug. */
233 #define STATE_CONDITIONAL_BRANCH (1)
234 #define STATE_BASE_PLUS_DISP_PREFIX (2)
235 #define STATE_MUL (3)
237 #define STATE_LENGTH_MASK (3)
238 #define STATE_BYTE (0)
239 #define STATE_WORD (1)
240 #define STATE_DWORD (2)
241 /* Symbol undefined. */
242 #define STATE_UNDF (3)
243 #define STATE_MAX_LENGTH (3)
245 /* These displacements are relative to the address following the opcode
246 word of the instruction. The first letter is Byte, Word. The 2nd
247 letter is Forward, Backward. */
249 #define BRANCH_BF ( 254)
250 #define BRANCH_BB (-256)
251 #define BRANCH_WF (2 + 32767)
252 #define BRANCH_WB (2 + -32768)
254 #define BDAP_BF ( 127)
255 #define BDAP_BB (-128)
256 #define BDAP_WF ( 32767)
257 #define BDAP_WB (-32768)
259 #define ENCODE_RELAX(what, length) (((what) << 2) + (length))
261 const relax_typeS md_cris_relax_table[] =
263 /* Error sentinel (0, 0). */
276 {BRANCH_BF, BRANCH_BB, 0, ENCODE_RELAX (1, 1)},
278 /* Bcc [PC+] (1, 1). */
279 {BRANCH_WF, BRANCH_WB, 2, ENCODE_RELAX (1, 2)},
281 /* BEXT/BWF, BA, JUMP (external), JUMP (always), Bnot_cc, JUMP (default)
289 {BDAP_BF, BDAP_BB, 0, ENCODE_RELAX (2, 1)},
291 /* BDAP.[bw] [PC+] (2, 1). */
292 {BDAP_WF, BDAP_WB, 2, ENCODE_RELAX (2, 2)},
294 /* BDAP.d [PC+] (2, 2). */
300 /* MULS/MULU (3, 0). Positions (3, 1..3) are unused. */
301 {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}
313 /* Target-specific multicharacter options, not const-declared at usage
314 in 2.9.1 and CVS of 2000-02-16. */
315 struct option md_longopts[] =
317 #define OPTION_NO_US (OPTION_MD_BASE + 0)
318 {"no-underscore", no_argument, NULL, OPTION_NO_US},
319 #define OPTION_US (OPTION_MD_BASE + 1)
320 {"underscore", no_argument, NULL, OPTION_US},
321 #define OPTION_PIC (OPTION_MD_BASE + 2)
322 {"pic", no_argument, NULL, OPTION_PIC},
323 #define OPTION_MULBUG_ABORT_ON (OPTION_MD_BASE + 3)
324 {"mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_ON},
325 #define OPTION_MULBUG_ABORT_OFF (OPTION_MD_BASE + 4)
326 {"no-mul-bug-abort", no_argument, NULL, OPTION_MULBUG_ABORT_OFF},
327 {NULL, no_argument, NULL, 0}
330 /* Not const-declared at usage in 2.9.1. */
331 size_t md_longopts_size = sizeof (md_longopts);
332 const char *md_shortopts = "hHN";
334 /* At first glance, this may seems wrong and should be 4 (ba + nop); but
335 since a short_jump must skip a *number* of long jumps, it must also be
336 a long jump. Here, we hope to make it a "ba [16bit_offs]" and a "nop"
337 for the delay slot and hope that the jump table at most needs
338 32767/4=8191 long-jumps. A branch is better than a jump, since it is
339 relative; we will not have a reloc to fix up somewhere.
341 Note that we can't add relocs, because relaxation uses these fixed
342 numbers, and md_create_short_jump is called after relaxation. */
344 const int md_short_jump_size = 6;
345 const int md_long_jump_size = 6;
347 /* Report output format. Small changes in output format (like elf
348 variants below) can happen until all options are parsed, but after
349 that, the output format must remain fixed. */
352 cris_target_format ()
354 switch (OUTPUT_FLAVOR)
356 case bfd_target_aout_flavour:
359 case bfd_target_elf_flavour:
360 if (symbols_have_leading_underscore)
361 return "elf32-us-cris";
370 /* We need a port-specific relaxation function to cope with sym2 - sym1
371 relative expressions with both symbols in the same segment (but not
372 necessarily in the same frag as this insn), for example:
373 move.d [pc+sym2-(sym1-2)],r10
375 The offset can be 8, 16 or 32 bits long. */
378 cris_relax_frag (seg, fragP, stretch)
379 segT seg ATTRIBUTE_UNUSED;
381 long stretch ATTRIBUTE_UNUSED;
386 const relax_typeS *this_type;
387 const relax_typeS *start_type;
388 relax_substateT next_state;
389 relax_substateT this_state;
390 const relax_typeS *table = TC_GENERIC_RELAX_TABLE;
392 /* We only have to cope with frags as prepared by
393 md_estimate_size_before_relax. The dword cases may get here
394 because of the different reasons that they aren't relaxable. */
395 switch (fragP->fr_subtype)
397 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_DWORD):
398 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
399 /* When we get to these states, the frag won't grow any more. */
402 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
403 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
404 if (fragP->fr_symbol == NULL
405 || S_GET_SEGMENT (fragP->fr_symbol) != absolute_section)
406 as_fatal (_("internal inconsistency problem in %s: fr_symbol %lx"),
407 __FUNCTION__, (long) fragP->fr_symbol);
408 symbolP = fragP->fr_symbol;
409 if (symbol_resolved_p (symbolP))
410 as_fatal (_("internal inconsistency problem in %s: resolved symbol"),
412 aim = S_GET_VALUE (symbolP);
415 case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
416 /* Nothing to do here. */
420 as_fatal (_("internal inconsistency problem in %s: fr_subtype %d"),
421 __FUNCTION__, fragP->fr_subtype);
424 /* The rest is stolen from relax_frag. There's no obvious way to
425 share the code, but fortunately no requirement to keep in sync as
426 long as fragP->fr_symbol does not have its segment changed. */
428 this_state = fragP->fr_subtype;
429 start_type = this_type = table + this_state;
433 /* Look backwards. */
434 for (next_state = this_type->rlx_more; next_state;)
435 if (aim >= this_type->rlx_backward)
439 /* Grow to next state. */
440 this_state = next_state;
441 this_type = table + this_state;
442 next_state = this_type->rlx_more;
448 for (next_state = this_type->rlx_more; next_state;)
449 if (aim <= this_type->rlx_forward)
453 /* Grow to next state. */
454 this_state = next_state;
455 this_type = table + this_state;
456 next_state = this_type->rlx_more;
460 growth = this_type->rlx_length - start_type->rlx_length;
462 fragP->fr_subtype = this_state;
466 /* Prepare machine-dependent frags for relaxation.
468 Called just before relaxation starts. Any symbol that is now undefined
469 will not become defined.
471 Return the correct fr_subtype in the frag.
473 Return the initial "guess for fr_var" to caller. The guess for fr_var
474 is *actually* the growth beyond fr_fix. Whatever we do to grow fr_fix
475 or fr_var contributes to our returned value.
477 Although it may not be explicit in the frag, pretend
478 fr_var starts with a value. */
481 md_estimate_size_before_relax (fragP, segment_type)
483 /* The segment is either N_DATA or N_TEXT. */
488 old_fr_fix = fragP->fr_fix;
490 switch (fragP->fr_subtype)
492 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_UNDF):
493 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
494 /* The symbol lies in the same segment - a relaxable case. */
496 = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
498 /* Unknown or not the same segment, so not relaxable. */
500 = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_DWORD);
501 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
504 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF):
505 /* Note that we can not do anything sane with relaxing
506 [rX + a_known_symbol_in_text], it will have to be a 32-bit
509 We could play tricks with managing a constant pool and make
510 a_known_symbol_in_text a "bdap [pc + offset]" pointing there
511 (like the GOT for ELF shared libraries), but that's no use, it
512 would in general be no shorter or faster code, only more
515 if (S_GET_SEGMENT (fragP->fr_symbol) != absolute_section)
517 /* Go for dword if not absolute or same segment. */
519 = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD);
520 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
522 else if (!symbol_resolved_p (fragP->fr_symbol))
524 /* The symbol will eventually be completely resolved as an
525 absolute expression, but right now it depends on the result
526 of relaxation and we don't know anything else about the
527 value. We start relaxation with the assumption that it'll
530 = ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE);
531 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
535 /* Absolute expression. */
537 value = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset;
539 if (value >= -128 && value <= 127)
541 /* Byte displacement. */
542 (fragP->fr_opcode)[0] = value;
546 /* Word or dword displacement. */
547 int pow2_of_size = 1;
550 if (value < -32768 || value > 32767)
552 /* Outside word range, make it a dword. */
556 /* Modify the byte-offset BDAP into a word or dword offset
557 BDAP. Or really, a BDAP rX,8bit into a
558 BDAP.[wd] rX,[PC+] followed by a word or dword. */
559 (fragP->fr_opcode)[0] = BDAP_PC_LOW + pow2_of_size * 16;
561 /* Keep the register number in the highest four bits. */
562 (fragP->fr_opcode)[1] &= 0xF0;
563 (fragP->fr_opcode)[1] |= BDAP_INCR_HIGH;
565 /* It grew by two or four bytes. */
566 fragP->fr_fix += 1 << pow2_of_size;
567 writep = fragP->fr_literal + old_fr_fix;
568 md_number_to_chars (writep, value, 1 << pow2_of_size);
574 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
575 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
576 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_DWORD):
577 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
578 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
579 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
580 /* When relaxing a section for the second time, we don't need to
581 do anything except making sure that fr_var is set right. */
582 fragP->fr_var = md_cris_relax_table[fragP->fr_subtype].rlx_length;
585 case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
586 /* Nothing to do here. */
590 BAD_CASE (fragP->fr_subtype);
593 return fragP->fr_var + (fragP->fr_fix - old_fr_fix);
596 /* Perform post-processing of machine-dependent frags after relaxation.
597 Called after relaxation is finished.
599 fr_type == rs_machine_dependent.
600 fr_subtype is what the address relaxed to.
602 Out: Any fixS:s and constants are set up.
604 The caller will turn the frag into a ".space 0". */
607 md_convert_frag (abfd, sec, fragP)
608 bfd *abfd ATTRIBUTE_UNUSED;
609 segT sec ATTRIBUTE_UNUSED;
612 /* Pointer to first byte in variable-sized part of the frag. */
615 /* Pointer to first opcode byte in frag. */
618 /* Used to check integrity of the relaxation.
619 One of 2 = long, 1 = word, or 0 = byte. */
622 /* Size in bytes of variable-sized part of frag. */
623 int var_part_size = 0;
625 /* This is part of *fragP. It contains all information about addresses
626 and offsets to varying parts. */
628 unsigned long var_part_offset;
630 /* Where, in file space, is _var of *fragP? */
631 unsigned long address_of_var_part = 0;
633 /* Where, in file space, does addr point? */
634 unsigned long target_address;
636 know (fragP->fr_type == rs_machine_dependent);
638 length_code = fragP->fr_subtype & STATE_LENGTH_MASK;
639 know (length_code >= 0 && length_code < STATE_MAX_LENGTH);
641 var_part_offset = fragP->fr_fix;
642 var_partp = fragP->fr_literal + var_part_offset;
643 opcodep = fragP->fr_opcode;
645 symbolP = fragP->fr_symbol;
646 target_address = (symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset;
647 address_of_var_part = fragP->fr_address + var_part_offset;
649 switch (fragP->fr_subtype)
651 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
652 opcodep[0] = branch_disp ((target_address - address_of_var_part));
656 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
657 /* We had a quick immediate branch, now turn it into a word one i.e. a
659 opcodep[0] = BRANCH_PC_LOW;
661 opcodep[1] |= BRANCH_INCR_HIGH;
662 md_number_to_chars (var_partp,
663 (long) (target_address - (address_of_var_part + 2)),
668 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_DWORD):
669 gen_cond_branch_32 (fragP->fr_opcode, var_partp, fragP,
670 fragP->fr_symbol, (symbolS *) NULL,
672 /* Ten bytes added: a branch, nop and a jump. */
673 var_part_size = 2 + 2 + 4 + 2;
676 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_BYTE):
678 as_fatal (_("internal inconsistency in %s: bdapq no symbol"),
680 opcodep[0] = S_GET_VALUE (symbolP);
684 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_WORD):
685 /* We had a BDAP 8-bit "quick immediate", now turn it into a 16-bit
686 one that uses PC autoincrement. */
687 opcodep[0] = BDAP_PC_LOW + (1 << 4);
689 opcodep[1] |= BDAP_INCR_HIGH;
691 as_fatal (_("internal inconsistency in %s: bdap.w with no symbol"),
693 md_number_to_chars (var_partp, S_GET_VALUE (symbolP), 2);
697 case ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_DWORD):
698 /* We had a BDAP 16-bit "word", change the offset to a dword. */
699 opcodep[0] = BDAP_PC_LOW + (2 << 4);
701 opcodep[1] |= BDAP_INCR_HIGH;
702 if (fragP->fr_symbol == NULL)
703 md_number_to_chars (var_partp, fragP->fr_offset, 4);
705 fix_new (fragP, var_partp - fragP->fr_literal, 4, fragP->fr_symbol,
706 fragP->fr_offset, 0, BFD_RELOC_32);
710 case ENCODE_RELAX (STATE_MUL, STATE_BYTE):
711 /* This is the only time we check position and aligmnent of the
712 placement-tracking frag. */
713 if (sec->alignment_power < 2)
714 as_bad_where (fragP->fr_file, fragP->fr_line,
715 _("section alignment must be >= 4 bytes to check MULS/MULU safeness"));
718 /* If the address after the MULS/MULU has alignment which is
719 that of the section and may be that of a cache-size of the
720 buggy versions, then the MULS/MULU can be placed badly. */
721 if ((address_of_var_part
722 & ((1 << sec->alignment_power) - 1) & 31) == 0)
723 as_bad_where (fragP->fr_file, fragP->fr_line,
724 _("dangerous MULS/MULU location; give it higher alignment"));
729 BAD_CASE (fragP->fr_subtype);
733 fragP->fr_fix += var_part_size;
736 /* Generate a short jump around a secondary jump table.
737 Used by md_create_long_jump.
739 This used to be md_create_short_jump, but is now called from
740 md_create_long_jump instead, when sufficient.
741 since the sizes of the jumps are the same. It used to be brittle,
742 making possibilities for creating bad code. */
745 cris_create_short_jump (storep, from_addr, to_addr, fragP, to_symbol)
749 fragS *fragP ATTRIBUTE_UNUSED;
750 symbolS *to_symbol ATTRIBUTE_UNUSED;
754 distance = to_addr - from_addr;
756 if (-254 <= distance && distance <= 256)
758 /* Create a "short" short jump: "BA distance - 2". */
759 storep[0] = branch_disp (distance - 2);
760 storep[1] = BA_QUICK_HIGH;
762 /* A nop for the delay slot. */
763 md_number_to_chars (storep + 2, NOP_OPCODE, 2);
765 /* The extra word should be filled with something sane too. Make it
766 a nop to keep disassembly sane. */
767 md_number_to_chars (storep + 4, NOP_OPCODE, 2);
771 /* Make it a "long" short jump: "BA (PC+)". */
772 md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2);
774 /* ".WORD distance - 4". */
775 md_number_to_chars (storep + 2, (long) (distance - 4), 2);
777 /* A nop for the delay slot. */
778 md_number_to_chars (storep + 4, NOP_OPCODE, 2);
782 /* Generate a long jump in a secondary jump table.
784 storep Where to store the jump instruction.
785 from_addr Address of the jump instruction.
786 to_addr Destination address of the jump.
787 fragP Which frag the destination address operand
789 to_symbol Destination symbol. */
792 md_create_long_jump (storep, from_addr, to_addr, fragP, to_symbol)
801 distance = to_addr - from_addr;
803 if (-32763 <= distance && distance <= 32772)
805 /* Then make it a "short" long jump. */
806 cris_create_short_jump (storep, from_addr, to_addr, fragP,
811 /* We have a "long" long jump: "JUMP [PC+]".
812 Make it an "ADD [PC+],PC" if we're supposed to emit PIC code. */
813 md_number_to_chars (storep,
814 pic ? ADD_PC_INCR_OPCODE : JUMP_PC_INCR_OPCODE, 2);
816 /* Follow with a ".DWORD to_addr", PC-relative for PIC. */
817 fix_new (fragP, storep + 2 - fragP->fr_literal, 4, to_symbol,
818 0, pic ? 1 : 0, pic ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
822 /* Allocate space for the first piece of an insn, and mark it as the
823 start of the insn for debug-format use. */
826 cris_insn_first_word_frag ()
828 char *insnp = frag_more (2);
830 /* We need to mark the start of the insn by passing dwarf2_emit_insn
831 the offset from the current fragment position. This must be done
832 after the first fragment is created but before any other fragments
833 (fixed or varying) are created. Note that the offset only
834 corresponds to the "size" of the insn for a fixed-size,
835 non-expanded insn. */
836 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
837 dwarf2_emit_insn (2);
842 /* Port-specific assembler initialization. */
847 const char *hashret = NULL;
850 /* Set up a hash table for the instructions. */
851 op_hash = hash_new ();
853 as_fatal (_("Virtual memory exhausted"));
855 while (cris_opcodes[i].name != NULL)
857 const char *name = cris_opcodes[i].name;
858 hashret = hash_insert (op_hash, name, (PTR) &cris_opcodes[i]);
860 if (hashret != NULL && *hashret != '\0')
861 as_fatal (_("Can't hash `%s': %s\n"), cris_opcodes[i].name,
862 *hashret == 0 ? _("(unknown reason)") : hashret);
865 if (cris_opcodes[i].match & cris_opcodes[i].lose)
866 as_fatal (_("Buggy opcode: `%s' \"%s\"\n"), cris_opcodes[i].name,
867 cris_opcodes[i].args);
871 while (cris_opcodes[i].name != NULL
872 && strcmp (cris_opcodes[i].name, name) == 0);
876 /* Assemble a source line. */
882 struct cris_instruction output_instruction;
883 struct cris_prefix prefix;
889 /* Do the low-level grunt - assemble to bits and split up into a prefix
890 and ordinary insn. */
891 cris_process_instruction (str, &output_instruction, &prefix);
893 /* Handle any prefixes to the instruction. */
899 /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
900 extra bytes, so we handle it separately. */
901 case PREFIX_BDAP_IMM:
902 /* We only do it if the relocation is unspecified, i.e. not a PIC
904 if (prefix.reloc == BFD_RELOC_NONE)
906 gen_bdap (prefix.base_reg_number, &prefix.expr);
913 opcodep = cris_insn_first_word_frag ();
915 /* Output the prefix opcode. */
916 md_number_to_chars (opcodep, (long) prefix.opcode, 2);
918 /* Having a specified reloc only happens for DIP and for BDAP with
919 PIC operands, but it is ok to drop through here for the other
920 prefixes as they can have no relocs specified. */
921 if (prefix.reloc != BFD_RELOC_NONE)
923 unsigned int relocsize
924 = (prefix.kind == PREFIX_DIP
925 ? 4 : cris_get_pic_reloc_size (prefix.reloc));
927 p = frag_more (relocsize);
928 fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize,
929 &prefix.expr, 0, prefix.reloc);
934 opcodep = cris_insn_first_word_frag ();
936 /* Output the prefix opcode. Being a "push", we add the negative
937 size of the register to "sp". */
938 if (output_instruction.spec_reg != NULL)
940 /* Special register. */
941 opcodep[0] = -output_instruction.spec_reg->reg_size;
945 /* General register. */
948 opcodep[1] = (REG_SP << 4) + (BDAP_QUICK_OPCODE >> 8);
952 BAD_CASE (prefix.kind);
955 /* If we only had a prefix insn, we're done. */
956 if (output_instruction.insn_type == CRIS_INSN_NONE)
959 /* Done with the prefix. Continue with the main instruction. */
960 if (prefix.kind == PREFIX_NONE)
961 opcodep = cris_insn_first_word_frag ();
963 opcodep = frag_more (2);
965 /* Output the instruction opcode. */
966 md_number_to_chars (opcodep, (long) (output_instruction.opcode), 2);
968 /* Output the symbol-dependent instruction stuff. */
969 if (output_instruction.insn_type == CRIS_INSN_BRANCH)
971 segT to_seg = absolute_section;
972 int is_undefined = 0;
975 if (output_instruction.expr.X_op != O_constant)
977 to_seg = S_GET_SEGMENT (output_instruction.expr.X_add_symbol);
979 if (to_seg == undefined_section)
983 if (to_seg == now_seg || is_undefined)
985 /* Handle complex expressions. */
987 = (SIMPLE_EXPR (&output_instruction.expr)
988 ? output_instruction.expr.X_add_number
991 = (SIMPLE_EXPR (&output_instruction.expr)
992 ? output_instruction.expr.X_add_symbol
993 : make_expr_symbol (&output_instruction.expr));
995 /* If is_undefined, then the expression may BECOME now_seg. */
996 length_code = is_undefined ? STATE_UNDF : STATE_BYTE;
998 /* Make room for max ten bytes of variable length. */
999 frag_var (rs_machine_dependent, 10, 0,
1000 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, length_code),
1001 sym, addvalue, opcodep);
1005 /* We have: to_seg != now_seg && to_seg != undefined_section.
1006 This means it is a branch to a known symbol in another
1007 section, perhaps an absolute address. Emit a 32-bit branch. */
1008 char *cond_jump = frag_more (10);
1010 gen_cond_branch_32 (opcodep, cond_jump, frag_now,
1011 output_instruction.expr.X_add_symbol,
1013 output_instruction.expr.X_add_number);
1016 else if (output_instruction.insn_type == CRIS_INSN_MUL
1017 && err_for_dangerous_mul_placement)
1018 /* Create a frag which which we track the location of the mul insn
1019 (in the last two bytes before the mul-frag). */
1020 frag_variant (rs_machine_dependent, 0, 0,
1021 ENCODE_RELAX (STATE_MUL, STATE_BYTE),
1025 if (output_instruction.imm_oprnd_size > 0)
1027 /* The instruction has an immediate operand. */
1028 enum bfd_reloc_code_real reloc = BFD_RELOC_NONE;
1030 switch (output_instruction.imm_oprnd_size)
1032 /* Any byte-size immediate constants are treated as
1033 word-size. FIXME: Thus overflow check does not work
1037 /* Note that size-check for the explicit reloc has already
1038 been done when we get here. */
1039 if (output_instruction.reloc != BFD_RELOC_NONE)
1040 reloc = output_instruction.reloc;
1042 reloc = BFD_RELOC_16;
1046 /* Allow a relocation specified in the operand. */
1047 if (output_instruction.reloc != BFD_RELOC_NONE)
1048 reloc = output_instruction.reloc;
1050 reloc = BFD_RELOC_32;
1054 BAD_CASE (output_instruction.imm_oprnd_size);
1057 p = frag_more (output_instruction.imm_oprnd_size);
1058 fix_new_exp (frag_now, (p - frag_now->fr_literal),
1059 output_instruction.imm_oprnd_size,
1060 &output_instruction.expr, 0, reloc);
1062 else if (output_instruction.reloc != BFD_RELOC_NONE)
1064 /* An immediate operand that has a relocation and needs to be
1065 processed further. */
1067 /* It is important to use fix_new_exp here and everywhere else
1068 (and not fix_new), as fix_new_exp can handle "difference
1069 expressions" - where the expression contains a difference of
1070 two symbols in the same segment. */
1071 fix_new_exp (frag_now, (opcodep - frag_now->fr_literal), 2,
1072 &output_instruction.expr, 0,
1073 output_instruction.reloc);
1078 /* Low level text-to-bits assembly. */
1081 cris_process_instruction (insn_text, out_insnp, prefixp)
1083 struct cris_instruction *out_insnp;
1084 struct cris_prefix *prefixp;
1087 char modified_char = 0;
1089 struct cris_opcode *instruction;
1096 /* Reset these fields to a harmless state in case we need to return in
1098 prefixp->kind = PREFIX_NONE;
1099 prefixp->reloc = BFD_RELOC_NONE;
1100 out_insnp->insn_type = CRIS_INSN_NORMAL;
1101 out_insnp->imm_oprnd_size = 0;
1103 /* Find the end of the opcode mnemonic. We assume (true in 2.9.1)
1104 that the caller has translated the opcode to lower-case, up to the
1105 first non-letter. */
1106 for (operands = insn_text; ISLOWER (*operands); ++operands)
1109 /* Terminate the opcode after letters, but save the character there if
1110 it was of significance. */
1117 /* Put back the modified character later. */
1118 modified_char = *operands;
1122 /* Consume the character after the mnemonic
1123 and replace it with '\0'. */
1128 as_bad (_("Unknown opcode: `%s'"), insn_text);
1132 /* Find the instruction. */
1133 instruction = (struct cris_opcode *) hash_find (op_hash, insn_text);
1134 if (instruction == NULL)
1136 as_bad (_("Unknown opcode: `%s'"), insn_text);
1140 /* Put back the modified character. */
1141 switch (modified_char)
1147 *--operands = modified_char;
1150 /* Try to match an opcode table slot. */
1151 for (s = operands;;)
1155 /* Initialize *prefixp, perhaps after being modified for a
1157 prefixp->kind = PREFIX_NONE;
1158 prefixp->reloc = BFD_RELOC_NONE;
1160 /* Initialize *out_insnp. */
1161 memset (out_insnp, 0, sizeof (*out_insnp));
1162 out_insnp->opcode = instruction->match;
1163 out_insnp->reloc = BFD_RELOC_NONE;
1164 out_insnp->insn_type = CRIS_INSN_NORMAL;
1165 out_insnp->imm_oprnd_size = 0;
1169 /* Build the opcode, checking as we go to make sure that the
1171 for (args = instruction->args;; ++args)
1176 /* If we've come to the end of arguments, we're done. */
1182 /* Non-matcher character for disassembly.
1188 /* These must match exactly. */
1194 /* This is not really an operand, but causes a "BDAP
1195 -size,SP" prefix to be output, for PUSH instructions. */
1196 prefixp->kind = PREFIX_PUSH;
1200 /* This letter marks an operand that should not be matched
1201 in the assembler. It is a branch with 16-bit
1202 displacement. The assembler will create them from the
1203 8-bit flavor when necessary. The assembler does not
1204 support the [rN+] operand, as the [r15+] that is
1205 generated for 16-bit displacements. */
1209 /* A 5-bit unsigned immediate in bits <4:0>. */
1210 if (! cris_get_expression (&s, &out_insnp->expr))
1214 if (out_insnp->expr.X_op == O_constant
1215 && (out_insnp->expr.X_add_number < 0
1216 || out_insnp->expr.X_add_number > 31))
1217 as_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
1218 out_insnp->expr.X_add_number);
1220 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
1225 /* A 4-bit unsigned immediate in bits <3:0>. */
1226 if (! cris_get_expression (&s, &out_insnp->expr))
1230 if (out_insnp->expr.X_op == O_constant
1231 && (out_insnp->expr.X_add_number < 0
1232 || out_insnp->expr.X_add_number > 15))
1233 as_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
1234 out_insnp->expr.X_add_number);
1236 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
1241 /* General register in bits <15:12> and <3:0>. */
1242 if (! get_gen_reg (&s, ®no))
1246 out_insnp->opcode |= regno /* << 0 */;
1247 out_insnp->opcode |= regno << 12;
1252 /* Flags from the condition code register. */
1256 if (! get_flags (&s, &flags))
1259 out_insnp->opcode |= ((flags & 0xf0) << 8) | (flags & 0xf);
1264 /* A 6-bit signed immediate in bits <5:0>. */
1265 if (! cris_get_expression (&s, &out_insnp->expr))
1269 if (out_insnp->expr.X_op == O_constant
1270 && (out_insnp->expr.X_add_number < -32
1271 || out_insnp->expr.X_add_number > 31))
1272 as_bad (_("Immediate value not in 6 bit range: %ld"),
1273 out_insnp->expr.X_add_number);
1274 out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
1279 /* A 6-bit unsigned immediate in bits <5:0>. */
1280 if (! cris_get_expression (&s, &out_insnp->expr))
1284 if (out_insnp->expr.X_op == O_constant
1285 && (out_insnp->expr.X_add_number < 0
1286 || out_insnp->expr.X_add_number > 63))
1287 as_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
1288 out_insnp->expr.X_add_number);
1289 out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
1294 /* A size modifier, B, W or D, to be put in a bit position
1295 suitable for CLEAR instructions (i.e. reflecting a zero
1297 if (! get_bwd_size_modifier (&s, &size_bits))
1304 out_insnp->opcode |= 0 << 12;
1308 out_insnp->opcode |= 4 << 12;
1312 out_insnp->opcode |= 8 << 12;
1319 /* A size modifier, B, W or D, to be put in bits <5:4>. */
1320 if (! get_bwd_size_modifier (&s, &size_bits))
1324 out_insnp->opcode |= size_bits << 4;
1329 /* A branch expression. */
1330 if (! cris_get_expression (&s, &out_insnp->expr))
1334 out_insnp->insn_type = CRIS_INSN_BRANCH;
1339 /* A BDAP expression for any size, "expr,r". */
1340 if (! cris_get_expression (&s, &prefixp->expr))
1349 if (!get_gen_reg (&s, &prefixp->base_reg_number))
1352 /* Since 'O' is used with an explicit bdap, we have no
1353 "real" instruction. */
1354 prefixp->kind = PREFIX_BDAP_IMM;
1356 = BDAP_QUICK_OPCODE | (prefixp->base_reg_number << 12);
1358 out_insnp->insn_type = CRIS_INSN_NONE;
1363 /* Special register in bits <15:12>. */
1364 if (! get_spec_reg (&s, &out_insnp->spec_reg))
1368 /* Use of some special register names come with a
1369 specific warning. Note that we have no ".cpu type"
1370 pseudo yet, so some of this is just unused
1372 if (out_insnp->spec_reg->warning)
1373 as_warn (out_insnp->spec_reg->warning);
1374 else if (out_insnp->spec_reg->applicable_version
1375 == cris_ver_warning)
1376 /* Others have a generic warning. */
1377 as_warn (_("Unimplemented register `%s' specified"),
1378 out_insnp->spec_reg->name);
1381 |= out_insnp->spec_reg->number << 12;
1386 /* This character is used in the disassembler to
1387 recognize a prefix instruction to fold into the
1388 addressing mode for the next instruction. It is
1393 /* General register in bits <15:12>. */
1394 if (! get_gen_reg (&s, ®no))
1398 out_insnp->opcode |= regno << 12;
1403 /* General register in bits <3:0>. */
1404 if (! get_gen_reg (&s, ®no))
1408 out_insnp->opcode |= regno /* << 0 */;
1413 /* Source operand in bit <10> and a prefix; a 3-operand
1415 if (! get_3op_or_dip_prefix_op (&s, prefixp))
1421 /* Source operand in bits <10>, <3:0> and optionally a
1422 prefix; i.e. an indirect operand or an side-effect
1424 if (! get_autoinc_prefix_or_indir_op (&s, prefixp, &mode,
1431 if (prefixp->kind != PREFIX_NONE)
1433 /* A prefix, so it has the autoincrement bit
1435 out_insnp->opcode |= (AUTOINCR_BIT << 8);
1439 /* No prefix. The "mode" variable contains bits like
1440 whether or not this is autoincrement mode. */
1441 out_insnp->opcode |= (mode << 10);
1443 /* If there was a PIC reloc specifier, then it was
1444 attached to the prefix. Note that we can't check
1445 that the reloc size matches, since we don't have
1446 all the operands yet in all cases. */
1447 if (prefixp->reloc != BFD_RELOC_NONE)
1448 out_insnp->reloc = prefixp->reloc;
1451 out_insnp->opcode |= regno /* << 0 */ ;
1456 /* Rs.m in bits <15:12> and <5:4>. */
1457 if (! get_gen_reg (&s, ®no)
1458 || ! get_bwd_size_modifier (&s, &size_bits))
1462 out_insnp->opcode |= (regno << 12) | (size_bits << 4);
1467 /* Source operand in bits <10>, <3:0> and optionally a
1468 prefix; i.e. an indirect operand or an side-effect
1471 The difference to 's' is that this does not allow an
1472 "immediate" expression. */
1473 if (! get_autoinc_prefix_or_indir_op (&s, prefixp,
1481 if (prefixp->kind != PREFIX_NONE)
1483 /* A prefix, and those matched here always have
1484 side-effects (see 's' case). */
1485 out_insnp->opcode |= (AUTOINCR_BIT << 8);
1489 /* No prefix. The "mode" variable contains bits
1490 like whether or not this is autoincrement
1492 out_insnp->opcode |= (mode << 10);
1495 out_insnp->opcode |= regno /* << 0 */;
1500 /* Size modifier (B or W) in bit <4>. */
1501 if (! get_bw_size_modifier (&s, &size_bits))
1505 out_insnp->opcode |= size_bits << 4;
1513 /* We get here when we fail a match above or we found a
1514 complete match. Break out of this loop. */
1518 /* Was it a match or a miss? */
1521 /* If it's just that the args don't match, maybe the next
1522 item in the table is the same opcode but with
1523 matching operands. */
1524 if (instruction[1].name != NULL
1525 && ! strcmp (instruction->name, instruction[1].name))
1527 /* Yep. Restart and try that one instead. */
1534 /* We've come to the end of instructions with this
1535 opcode, so it must be an error. */
1536 as_bad (_("Illegal operands"));
1542 /* We have a match. Check if there's anything more to do. */
1545 /* There was an immediate mode operand, so we must check
1546 that it has an appropriate size. */
1547 switch (instruction->imm_oprnd_size)
1551 /* Shouldn't happen; this one does not have immediate
1552 operands with different sizes. */
1553 BAD_CASE (instruction->imm_oprnd_size);
1557 out_insnp->imm_oprnd_size = 4;
1561 switch (out_insnp->spec_reg->reg_size)
1564 if (out_insnp->expr.X_op == O_constant
1565 && (out_insnp->expr.X_add_number < -128
1566 || out_insnp->expr.X_add_number > 255))
1567 as_bad (_("Immediate value not in 8 bit range: %ld"),
1568 out_insnp->expr.X_add_number);
1571 /* FIXME: We need an indicator in the instruction
1572 table to pass on, to indicate if we need to check
1573 overflow for a signed or unsigned number. */
1574 if (out_insnp->expr.X_op == O_constant
1575 && (out_insnp->expr.X_add_number < -32768
1576 || out_insnp->expr.X_add_number > 65535))
1577 as_bad (_("Immediate value not in 16 bit range: %ld"),
1578 out_insnp->expr.X_add_number);
1579 out_insnp->imm_oprnd_size = 2;
1583 out_insnp->imm_oprnd_size = 4;
1587 BAD_CASE (out_insnp->spec_reg->reg_size);
1595 if (out_insnp->expr.X_op == O_constant
1596 && (out_insnp->expr.X_add_number < -128
1597 || out_insnp->expr.X_add_number > 255))
1598 as_bad (_("Immediate value not in 8 bit range: %ld"),
1599 out_insnp->expr.X_add_number);
1602 if (out_insnp->expr.X_op == O_constant
1603 && (out_insnp->expr.X_add_number < -32768
1604 || out_insnp->expr.X_add_number > 65535))
1605 as_bad (_("Immediate value not in 16 bit range: %ld"),
1606 out_insnp->expr.X_add_number);
1607 out_insnp->imm_oprnd_size = 2;
1611 out_insnp->imm_oprnd_size = 4;
1615 BAD_CASE (out_insnp->spec_reg->reg_size);
1619 /* If there was a relocation specified for the immediate
1620 expression (i.e. it had a PIC modifier) check that the
1621 size of the PIC relocation matches the size specified by
1623 if (out_insnp->reloc != BFD_RELOC_NONE
1624 && (cris_get_pic_reloc_size (out_insnp->reloc)
1625 != (unsigned int) out_insnp->imm_oprnd_size))
1626 as_bad (_("PIC relocation size does not match operand size"));
1628 else if (instruction->op == cris_muls_op
1629 || instruction->op == cris_mulu_op)
1630 out_insnp->insn_type = CRIS_INSN_MUL;
1636 /* Get a B, W, or D size modifier from the string pointed out by *cPP,
1637 which must point to a '.' in front of the modifier. On successful
1638 return, *cPP is advanced to the character following the size
1639 modifier, and is undefined otherwise.
1641 cPP Pointer to pointer to string starting
1642 with the size modifier.
1644 size_bitsp Pointer to variable to contain the size bits on
1647 Return 1 iff a correct size modifier is found, else 0. */
1650 get_bwd_size_modifier (cPP, size_bitsp)
1658 /* Consume the '.'. */
1682 /* Consume the size letter. */
1688 /* Get a B or W size modifier from the string pointed out by *cPP,
1689 which must point to a '.' in front of the modifier. On successful
1690 return, *cPP is advanced to the character following the size
1691 modifier, and is undefined otherwise.
1693 cPP Pointer to pointer to string starting
1694 with the size modifier.
1696 size_bitsp Pointer to variable to contain the size bits on
1699 Return 1 iff a correct size modifier is found, else 0. */
1702 get_bw_size_modifier (cPP, size_bitsp)
1710 /* Consume the '.'. */
1729 /* Consume the size letter. */
1735 /* Get a general register from the string pointed out by *cPP. The
1736 variable *cPP is advanced to the character following the general
1737 register name on a successful return, and has its initial position
1740 cPP Pointer to pointer to string, beginning with a general
1743 regnop Pointer to int containing the register number.
1745 Return 1 iff a correct general register designator is found,
1749 get_gen_reg (cPP, regnop)
1756 /* Handle a sometimes-mandatory dollar sign as register prefix. */
1757 if (**cPP == REGISTER_PREFIX_CHAR)
1759 else if (demand_register_prefix)
1766 /* "P" as in "PC"? Consume the "P". */
1769 if ((**cPP == 'C' || **cPP == 'c')
1770 && ! ISALNUM ((*cPP)[1]))
1772 /* It's "PC": consume the "c" and we're done. */
1781 /* Hopefully r[0-9] or r1[0-5]. Consume 'R' or 'r'. */
1784 if (ISDIGIT (**cPP))
1786 /* It's r[0-9]. Consume and check the next digit. */
1787 *regnop = **cPP - '0';
1790 if (! ISALNUM (**cPP))
1792 /* No more digits, we're done. */
1797 /* One more digit. Consume and add. */
1798 *regnop = *regnop * 10 + (**cPP - '0');
1800 /* We need to check for a valid register number; Rn,
1801 0 <= n <= MAX_REG. */
1802 if (*regnop <= MAX_REG)
1804 /* Consume second digit. */
1814 /* "S" as in "SP"? Consume the "S". */
1816 if (**cPP == 'P' || **cPP == 'p')
1818 /* It's "SP": consume the "p" and we're done. */
1826 /* Just here to silence compilation warnings. */
1830 /* We get here if we fail. Restore the pointer. */
1835 /* Get a special register from the string pointed out by *cPP. The
1836 variable *cPP is advanced to the character following the special
1837 register name if one is found, and retains its original position
1840 cPP Pointer to pointer to string starting with a special register
1843 sregpp Pointer to Pointer to struct spec_reg, where a pointer to the
1844 register description will be stored.
1846 Return 1 iff a correct special register name is found. */
1849 get_spec_reg (cPP, sregpp)
1851 const struct cris_spec_reg **sregpp;
1855 char *name_begin = *cPP;
1857 const struct cris_spec_reg *sregp;
1859 /* Handle a sometimes-mandatory dollar sign as register prefix. */
1860 if (*name_begin == REGISTER_PREFIX_CHAR)
1862 else if (demand_register_prefix)
1865 /* Loop over all special registers. */
1866 for (sregp = cris_spec_regs; sregp->name != NULL; sregp++)
1868 /* Start over from beginning of the supposed name. */
1872 while (*s2 != '\0' && TOLOWER (*s1) == *s2)
1878 /* For a match, we must have consumed the name in the table, and we
1879 must be outside what could be part of a name. Assume here that a
1880 test for alphanumerics is sufficient for a name test. */
1881 if (*s2 == 0 && ! ISALNUM (*s1))
1883 /* We have a match. Update the pointer and be done. */
1890 /* If we got here, we did not find any name. */
1894 /* Get an unprefixed or side-effect-prefix operand from the string pointed
1895 out by *cPP. The pointer *cPP is advanced to the character following
1896 the indirect operand if we have success, else it contains an undefined
1899 cPP Pointer to pointer to string beginning with the first
1900 character of the supposed operand.
1902 prefixp Pointer to structure containing an optional instruction
1905 is_autoincp Pointer to int indicating the indirect or autoincrement
1908 src_regnop Pointer to int containing the source register number in
1911 imm_foundp Pointer to an int indicating if an immediate expression
1914 imm_exprP Pointer to a structure containing an immediate
1915 expression, if success and if *imm_foundp is nonzero.
1917 Return 1 iff a correct indirect operand is found. */
1920 get_autoinc_prefix_or_indir_op (cPP, prefixp, is_autoincp, src_regnop,
1921 imm_foundp, imm_exprP)
1923 struct cris_prefix *prefixp;
1927 expressionS *imm_exprP;
1929 /* Assume there was no immediate mode expression. */
1934 /* So this operand is one of:
1936 Autoincrement: [rN+]
1937 Indexed with assign: [rN=rM+rO.S]
1938 Offset with assign: [rN=rM+I], [rN=rM+[rO].s], [rN=rM+[rO+].s]
1940 Either way, consume the '['. */
1943 /* Get the rN register. */
1944 if (! get_gen_reg (cPP, src_regnop))
1945 /* If there was no register, then this cannot match. */
1949 /* We got the register, now check the next character. */
1953 /* Indirect mode. We're done here. */
1954 prefixp->kind = PREFIX_NONE;
1959 /* This must be an auto-increment mode, if there's a
1961 prefixp->kind = PREFIX_NONE;
1964 /* We consume this character and break out to check the
1970 /* This must be indexed with assign, or offset with assign
1974 /* Either way, the next thing must be a register. */
1975 if (! get_gen_reg (cPP, &prefixp->base_reg_number))
1976 /* No register, no match. */
1980 /* We've consumed "[rN=rM", so we must be looking at
1981 "+rO.s]" or "+I]", or "-I]", or "+[rO].s]" or
1985 int index_reg_number;
1991 /* This must be [rx=ry+[rz].s] or
1992 [rx=ry+[rz+].s] or no match. We must be
1993 looking at rz after consuming the '['. */
1996 if (!get_gen_reg (cPP, &index_reg_number))
1999 prefixp->kind = PREFIX_BDAP;
2001 = (BDAP_INDIR_OPCODE
2002 + (prefixp->base_reg_number << 12)
2003 + index_reg_number);
2007 /* We've seen "[rx=ry+[rz+" here, so now we
2008 know that there must be "].s]" left to
2011 prefixp->opcode |= AUTOINCR_BIT << 8;
2014 /* If it wasn't autoincrement, we don't need to
2017 /* Check the next-to-last ']'. */
2023 /* Check the ".s" modifier. */
2024 if (! get_bwd_size_modifier (cPP, &size_bits))
2027 prefixp->opcode |= size_bits << 4;
2029 /* Now we got [rx=ry+[rz+].s or [rx=ry+[rz].s.
2030 We break out to check the final ']'. */
2033 /* It wasn't an indirection. Check if it's a
2035 else if (get_gen_reg (cPP, &index_reg_number))
2039 /* Indexed with assign mode: "[rN+rM.S]". */
2040 prefixp->kind = PREFIX_BIAP;
2042 = (BIAP_OPCODE + (index_reg_number << 12)
2043 + prefixp->base_reg_number /* << 0 */);
2045 if (! get_bwd_size_modifier (cPP, &size_bits))
2046 /* Size missing, this isn't a match. */
2050 /* Size found, break out to check the
2052 prefixp->opcode |= size_bits << 4;
2056 /* Not a register. Then this must be "[rN+I]". */
2057 else if (cris_get_expression (cPP, &prefixp->expr))
2059 /* We've got offset with assign mode. Fill
2060 in the blanks and break out to match the
2062 prefixp->kind = PREFIX_BDAP_IMM;
2064 /* We tentatively put an opcode corresponding to
2065 a 32-bit operand here, although it may be
2066 relaxed when there's no PIC specifier for the
2069 = (BDAP_INDIR_OPCODE
2070 | (prefixp->base_reg_number << 12)
2071 | (AUTOINCR_BIT << 8)
2073 | REG_PC /* << 0 */);
2075 /* This can have a PIC suffix, specifying reloc
2077 if (pic && **cPP == PIC_SUFFIX_CHAR)
2079 unsigned int relocsize;
2081 cris_get_pic_suffix (cPP, &prefixp->reloc,
2084 /* Tweak the size of the immediate operand
2085 in the prefix opcode if it isn't what we
2088 = cris_get_pic_reloc_size (prefixp->reloc);
2091 = ((prefixp->opcode & ~(3 << 4))
2092 | ((relocsize >> 1) << 4));
2097 /* Neither register nor expression found, so
2098 this can't be a match. */
2101 /* Not "[rN+" but perhaps "[rN-"? */
2102 else if (**cPP == '-')
2104 /* We must have an offset with assign mode. */
2105 if (! cris_get_expression (cPP, &prefixp->expr))
2106 /* No expression, no match. */
2110 /* We've got offset with assign mode. Fill
2111 in the blanks and break out to match the
2114 Note that we don't allow a PIC suffix for an
2115 operand with a minus sign. */
2116 prefixp->kind = PREFIX_BDAP_IMM;
2121 /* Neither '+' nor '-' after "[rN=rM". Lose. */
2125 /* Neither ']' nor '+' nor '=' after "[rN". Lose. */
2130 /* When we get here, we have a match and will just check the closing
2131 ']'. We can still fail though. */
2136 /* Don't forget to consume the final ']'.
2137 Then return in glory. */
2142 /* No indirection. Perhaps a constant? */
2143 else if (cris_get_expression (cPP, imm_exprP))
2145 /* Expression found, this is immediate mode. */
2146 prefixp->kind = PREFIX_NONE;
2148 *src_regnop = REG_PC;
2151 /* This can have a PIC suffix, specifying reloc type to use. The
2152 caller must check that the reloc size matches the operand size. */
2153 if (pic && **cPP == PIC_SUFFIX_CHAR)
2154 cris_get_pic_suffix (cPP, &prefixp->reloc, imm_exprP);
2159 /* No luck today. */
2163 /* This function gets an indirect operand in a three-address operand
2164 combination from the string pointed out by *cPP. The pointer *cPP is
2165 advanced to the character following the indirect operand on success, or
2166 has an unspecified value on failure.
2168 cPP Pointer to pointer to string beginning
2171 prefixp Pointer to structure containing an
2174 Returns 1 iff a correct indirect operand is found. */
2177 get_3op_or_dip_prefix_op (cPP, prefixp)
2179 struct cris_prefix *prefixp;
2184 /* We must have a '[' or it's a clean failure. */
2187 /* Eat the first '['. */
2192 /* A second '[', so this must be double-indirect mode. */
2194 prefixp->kind = PREFIX_DIP;
2195 prefixp->opcode = DIP_OPCODE;
2197 /* Get the register or fail entirely. */
2198 if (! get_gen_reg (cPP, ®_number))
2202 prefixp->opcode |= reg_number /* << 0 */ ;
2205 /* Since we found a '+', this must be double-indirect
2206 autoincrement mode. */
2208 prefixp->opcode |= AUTOINCR_BIT << 8;
2211 /* There's nothing particular to do, if this was a
2212 double-indirect *without* autoincrement. */
2215 /* Check the first ']'. The second one is checked at the end. */
2219 /* Eat the first ']', so we'll be looking at a second ']'. */
2222 /* No second '['. Then we should have a register here, making
2224 else if (get_gen_reg (cPP, &prefixp->base_reg_number))
2226 /* This must be indexed or offset mode: "[rN+I]" or
2227 "[rN+rM.S]" or "[rN+[rM].S]" or "[rN+[rM+].S]". */
2230 int index_reg_number;
2236 /* This is "[rx+["... Expect a register next. */
2240 if (!get_gen_reg (cPP, &index_reg_number))
2243 prefixp->kind = PREFIX_BDAP;
2245 = (BDAP_INDIR_OPCODE
2246 + (prefixp->base_reg_number << 12)
2247 + index_reg_number);
2249 /* We've seen "[rx+[ry", so check if this is
2253 /* Yep, now at "[rx+[ry+". */
2255 prefixp->opcode |= AUTOINCR_BIT << 8;
2257 /* If it wasn't autoincrement, we don't need to
2260 /* Check a first closing ']': "[rx+[ry]" or
2266 /* Now expect a size modifier ".S". */
2267 if (! get_bwd_size_modifier (cPP, &size_bits))
2270 prefixp->opcode |= size_bits << 4;
2272 /* Ok, all interesting stuff has been seen:
2273 "[rx+[ry+].S" or "[rx+[ry].S". We only need to
2274 expect a final ']', which we'll do in a common
2277 /* Seen "[rN+", but not a '[', so check if we have a
2279 else if (get_gen_reg (cPP, &index_reg_number))
2281 /* This is indexed mode: "[rN+rM.S]" or
2284 prefixp->kind = PREFIX_BIAP;
2287 | prefixp->base_reg_number /* << 0 */
2288 | (index_reg_number << 12));
2290 /* Consume the ".S". */
2291 if (! get_bwd_size_modifier (cPP, &size_bits))
2292 /* Missing size, so fail. */
2295 /* Size found. Add that piece and drop down to
2296 the common checking of the closing ']'. */
2297 prefixp->opcode |= size_bits << 4;
2299 /* Seen "[rN+", but not a '[' or a register, so then
2300 it must be a constant "I". */
2301 else if (cris_get_expression (cPP, &prefixp->expr))
2303 /* Expression found, so fill in the bits of offset
2304 mode and drop down to check the closing ']'. */
2305 prefixp->kind = PREFIX_BDAP_IMM;
2307 /* We tentatively put an opcode corresponding to a 32-bit
2308 operand here, although it may be relaxed when there's no
2309 PIC specifier for the operand. */
2311 = (BDAP_INDIR_OPCODE
2312 | (prefixp->base_reg_number << 12)
2313 | (AUTOINCR_BIT << 8)
2315 | REG_PC /* << 0 */);
2317 /* This can have a PIC suffix, specifying reloc type to use. */
2318 if (pic && **cPP == PIC_SUFFIX_CHAR)
2320 unsigned int relocsize;
2322 cris_get_pic_suffix (cPP, &prefixp->reloc, &prefixp->expr);
2324 /* Tweak the size of the immediate operand in the prefix
2325 opcode if it isn't what we set. */
2326 relocsize = cris_get_pic_reloc_size (prefixp->reloc);
2329 = ((prefixp->opcode & ~(3 << 4))
2330 | ((relocsize >> 1) << 4));
2334 /* Nothing valid here: lose. */
2337 /* Seen "[rN" but no '+', so check if it's a '-'. */
2338 else if (**cPP == '-')
2340 /* Yep, we must have offset mode. */
2341 if (! cris_get_expression (cPP, &prefixp->expr))
2342 /* No expression, so we lose. */
2346 /* Expression found to make this offset mode, so
2347 fill those bits and drop down to check the
2350 Note that we don't allow a PIC suffix for
2351 an operand with a minus sign like this. */
2352 prefixp->kind = PREFIX_BDAP_IMM;
2357 /* We've seen "[rN", but not '+' or '-'; rather a ']'.
2358 Hmm. Normally this is a simple indirect mode that we
2359 shouldn't match, but if we expect ']', then we have a
2360 zero offset, so it can be a three-address-operand,
2361 like "[rN],rO,rP", thus offset mode.
2363 Don't eat the ']', that will be done in the closing
2365 prefixp->expr.X_op = O_constant;
2366 prefixp->expr.X_add_number = 0;
2367 prefixp->expr.X_add_symbol = NULL;
2368 prefixp->expr.X_op_symbol = NULL;
2369 prefixp->kind = PREFIX_BDAP_IMM;
2372 /* A '[', but no second '[', and no register. Check if we
2373 have an expression, making this "[I]" for a double-indirect
2375 else if (cris_get_expression (cPP, &prefixp->expr))
2377 /* Expression found, the so called absolute mode for a
2378 double-indirect prefix on PC. */
2379 prefixp->kind = PREFIX_DIP;
2380 prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
2381 prefixp->reloc = BFD_RELOC_32;
2384 /* Neither '[' nor register nor expression. We lose. */
2387 /* We get here as a closing ceremony to a successful match. We just
2388 need to check the closing ']'. */
2390 /* Oops. Close but no air-polluter. */
2393 /* Don't forget to consume that ']', before returning in glory. */
2398 /* Get an expression from the string pointed out by *cPP.
2399 The pointer *cPP is advanced to the character following the expression
2400 on a success, or retains its original value otherwise.
2402 cPP Pointer to pointer to string beginning with the expression.
2404 exprP Pointer to structure containing the expression.
2406 Return 1 iff a correct expression is found. */
2409 cris_get_expression (cPP, exprP)
2413 char *saved_input_line_pointer;
2416 /* The "expression" function expects to find an expression at the
2417 global variable input_line_pointer, so we have to save it to give
2418 the impression that we don't fiddle with global variables. */
2419 saved_input_line_pointer = input_line_pointer;
2420 input_line_pointer = *cPP;
2422 exp = expression (exprP);
2423 if (exprP->X_op == O_illegal || exprP->X_op == O_absent)
2425 input_line_pointer = saved_input_line_pointer;
2429 /* Everything seems to be fine, just restore the global
2430 input_line_pointer and say we're successful. */
2431 *cPP = input_line_pointer;
2432 input_line_pointer = saved_input_line_pointer;
2436 /* Get a sequence of flag characters from *spp. The pointer *cPP is
2437 advanced to the character following the expression. The flag
2438 characters are consecutive, no commas or spaces.
2440 cPP Pointer to pointer to string beginning with the expression.
2442 flagp Pointer to int to return the flags expression.
2444 Return 1 iff a correct flags expression is found. */
2447 get_flags (cPP, flagsp)
2500 /* We consider this successful if we stop at a comma or
2501 whitespace. Anything else, and we consider it a failure. */
2504 && ! ISSPACE (**cPP))
2510 /* Don't forget to consume each flag character. */
2515 /* Generate code and fixes for a BDAP prefix.
2517 base_regno Int containing the base register number.
2519 exprP Pointer to structure containing the offset expression. */
2522 gen_bdap (base_regno, exprP)
2526 unsigned int opcode;
2529 /* Put out the prefix opcode; assume quick immediate mode at first. */
2530 opcode = BDAP_QUICK_OPCODE | (base_regno << 12);
2531 opcodep = cris_insn_first_word_frag ();
2532 md_number_to_chars (opcodep, opcode, 2);
2534 if (exprP->X_op == O_constant)
2536 /* We have an absolute expression that we know the size of right
2541 value = exprP->X_add_number;
2542 if (value < -32768 || value > 32767)
2543 /* Outside range for a "word", make it a dword. */
2546 /* Assume "word" size. */
2549 /* If this is a signed-byte value, we can fit it into the prefix
2551 if (value >= -128 && value <= 127)
2555 /* This is a word or dword displacement, which will be put in a
2556 word or dword after the prefix. */
2559 opcodep[0] = BDAP_PC_LOW + (size << 4);
2561 opcodep[1] |= BDAP_INCR_HIGH;
2562 p = frag_more (1 << size);
2563 md_number_to_chars (p, value, 1 << size);
2568 /* Handle complex expressions. */
2570 = SIMPLE_EXPR (exprP) ? exprP->X_add_number : 0;
2572 = (SIMPLE_EXPR (exprP)
2573 ? exprP->X_add_symbol : make_expr_symbol (exprP));
2575 /* The expression is not defined yet but may become absolute. We
2576 make it a relocation to be relaxed. */
2577 frag_var (rs_machine_dependent, 4, 0,
2578 ENCODE_RELAX (STATE_BASE_PLUS_DISP_PREFIX, STATE_UNDF),
2579 sym, addvalue, opcodep);
2583 /* Encode a branch displacement in the range -256..254 into the form used
2584 by CRIS conditional branch instructions.
2586 offset The displacement value in bytes. */
2589 branch_disp (offset)
2594 disp = offset & 0xFE;
2602 /* Generate code and fixes for a 32-bit conditional branch instruction
2603 created by "extending" an existing 8-bit branch instruction.
2605 opcodep Pointer to the word containing the original 8-bit branch
2608 writep Pointer to "extension area" following the first instruction
2611 fragP Pointer to the frag containing the instruction.
2613 add_symP, Parts of the destination address expression.
2618 gen_cond_branch_32 (opcodep, writep, fragP, add_symP, sub_symP, add_num)
2626 if (warn_for_branch_expansion)
2627 as_warn_where (fragP->fr_file, fragP->fr_line,
2628 _("32-bit conditional branch generated"));
2630 /* Here, writep points to what will be opcodep + 2. First, we change
2631 the actual branch in opcodep[0] and opcodep[1], so that in the
2632 final insn, it will look like:
2635 This means we don't have to worry about changing the opcode or
2636 messing with the delay-slot instruction. So, we move it to last in
2637 the "extended" branch, and just change the displacement. Admittedly,
2638 it's not the optimal extended construct, but we should get this
2639 rarely enough that it shouldn't matter. */
2641 writep[8] = branch_disp (-2 - 6);
2642 writep[9] = opcodep[1];
2644 /* Then, we change the branch to an unconditional branch over the
2645 extended part, to the new location of the Bcc:
2649 Note that these two writes are to currently different locations,
2652 md_number_to_chars (opcodep, BA_QUICK_OPCODE + 8, 2);
2653 md_number_to_chars (writep, NOP_OPCODE, 2);
2655 /* Then the extended thing, the 32-bit jump insn.
2656 opcodep+4: JUMP [PC+]
2657 or, in the PIC case,
2658 opcodep+4: ADD [PC+],PC. */
2660 md_number_to_chars (writep + 2,
2661 pic ? ADD_PC_INCR_OPCODE : JUMP_PC_INCR_OPCODE, 2);
2663 /* We have to fill in the actual value too.
2665 This is most probably an expression, but we can cope with an absolute
2666 value too. FIXME: Testcase needed with and without pic. */
2668 if (add_symP == NULL && sub_symP == NULL)
2670 /* An absolute address. */
2672 fix_new (fragP, writep + 4 - fragP->fr_literal, 4,
2673 section_symbol (absolute_section),
2674 add_num, 1, BFD_RELOC_32_PCREL);
2676 md_number_to_chars (writep + 4, add_num, 4);
2680 if (sub_symP != NULL)
2681 as_bad_where (fragP->fr_file, fragP->fr_line,
2682 _("Complex expression not supported"));
2684 /* Not absolute, we have to make it a frag for later evaluation. */
2685 fix_new (fragP, writep + 4 - fragP->fr_literal, 4, add_symP,
2686 add_num, pic ? 1 : 0, pic ? BFD_RELOC_32_PCREL : BFD_RELOC_32);
2690 /* Get the size of an immediate-reloc in bytes. Only valid for PIC
2694 cris_get_pic_reloc_size (reloc)
2695 bfd_reloc_code_real_type reloc;
2697 return reloc == BFD_RELOC_CRIS_16_GOTPLT || reloc == BFD_RELOC_CRIS_16_GOT
2701 /* Store a reloc type at *RELOCP corresponding to the PIC suffix at *CPP.
2702 Adjust *EXPRP with any addend found after the PIC suffix. */
2705 cris_get_pic_suffix (cPP, relocp, exprP)
2707 bfd_reloc_code_real_type *relocp;
2712 expressionS const_expr;
2714 const struct pic_suffixes_struct
2716 const char *const suffix;
2718 bfd_reloc_code_real_type reloc;
2722 #define PICMAP(s, r) {s, sizeof (s) - 1, r}
2723 /* Keep this in order with longest unambiguous prefix first. */
2724 PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT),
2725 PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT),
2726 PICMAP ("PLTG", BFD_RELOC_CRIS_32_PLT_GOTREL),
2727 PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL),
2728 PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL),
2729 PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT),
2730 PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT)
2733 /* We've already seen the ':', so consume it. */
2736 for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++)
2738 if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0
2739 && ! is_part_of_name (s[pic_suffixes[i].len]))
2741 /* We have a match. Consume the suffix and set the relocation
2743 s += pic_suffixes[i].len;
2745 /* There can be a constant term appended. If so, we will add it
2747 if (*s == '+' || *s == '-')
2749 if (! cris_get_expression (&s, &const_expr))
2750 /* There was some kind of syntax error. Bail out. */
2753 /* Allow complex expressions as the constant part. It still
2754 has to be an assembly-time constant or there will be an
2755 error emitting the reloc. This makes the PIC qualifiers
2756 idempotent; foo:GOTOFF+32 == foo+32:GOTOFF. The former we
2757 recognize here; the latter is parsed in the incoming
2759 exprP->X_add_symbol = make_expr_symbol (exprP);
2760 exprP->X_op = O_add;
2761 exprP->X_add_number = 0;
2762 exprP->X_op_symbol = make_expr_symbol (&const_expr);
2765 *relocp = pic_suffixes[i].reloc;
2771 /* No match. Don't consume anything; fall back and there will be a
2777 Turn a string in input_line_pointer into a floating point constant
2778 of type TYPE, and store the appropriate bytes in *LITP. The number
2779 of LITTLENUMS emitted is stored in *SIZEP.
2781 type A character from FLTCHARS that describes what kind of
2782 floating-point number is wanted.
2784 litp A pointer to an array that the result should be stored in.
2786 sizep A pointer to an integer where the size of the result is stored.
2788 But we don't support floating point constants in assembly code *at all*,
2789 since it's suboptimal and just opens up bug opportunities. GCC emits
2790 the bit patterns as hex. All we could do here is to emit what GCC
2791 would have done in the first place. *Nobody* writes floating-point
2792 code as assembly code, but if they do, they should be able enough to
2793 find out the correct bit patterns and use them. */
2796 md_atof (type, litp, sizep)
2797 char type ATTRIBUTE_UNUSED;
2798 char *litp ATTRIBUTE_UNUSED;
2799 int *sizep ATTRIBUTE_UNUSED;
2801 /* FIXME: Is this function mentioned in the internals.texi manual? If
2803 return _("Bad call to md_atof () - floating point formats are not supported");
2806 /* Turn a number as a fixS * into a series of bytes that represents the
2807 number on the target machine. The purpose of this procedure is the
2808 same as that of md_number_to_chars but this procedure is supposed to
2809 handle general bit field fixes and machine-dependent fixups.
2811 bufp Pointer to an array where the result should be stored.
2813 val The value to store.
2815 n The number of bytes in "val" that should be stored.
2817 fixP The fix to be applied to the bit field starting at bufp.
2819 seg The segment containing this number. */
2822 cris_number_to_imm (bufp, val, n, fixP, seg)
2834 /* We put the relative "vma" for the other segment for inter-segment
2835 relocations in the object data to stay binary "compatible" (with an
2836 uninteresting old version) for the relocation.
2837 Maybe delete some day. */
2839 && (sym_seg = S_GET_SEGMENT (fixP->fx_addsy)) != seg)
2840 val += sym_seg->vma;
2842 if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
2843 switch (fixP->fx_r_type)
2845 /* These must be fully resolved when getting here. */
2846 case BFD_RELOC_32_PCREL:
2847 case BFD_RELOC_16_PCREL:
2848 case BFD_RELOC_8_PCREL:
2849 as_bad_where (fixP->fx_frag->fr_file, fixP->fx_frag->fr_line,
2850 _("PC-relative relocation must be trivially resolved"));
2855 switch (fixP->fx_r_type)
2857 /* Ditto here, we put the addend into the object code as
2858 well as the reloc addend. Keep it that way for now, to simplify
2859 regression tests on the object file contents. FIXME: Seems
2860 uninteresting now that we have a test suite. */
2862 case BFD_RELOC_CRIS_16_GOT:
2863 case BFD_RELOC_CRIS_32_GOT:
2864 case BFD_RELOC_CRIS_32_GOTREL:
2865 case BFD_RELOC_CRIS_16_GOTPLT:
2866 case BFD_RELOC_CRIS_32_GOTPLT:
2867 case BFD_RELOC_CRIS_32_PLT_GOTREL:
2868 case BFD_RELOC_CRIS_32_PLT_PCREL:
2869 /* We don't want to put in any kind of non-zero bits in the data
2870 being relocated for these. */
2874 case BFD_RELOC_32_PCREL:
2875 /* No use having warnings here, since most hosts have a 32-bit type
2876 for "long" (which will probably change soon, now that I wrote
2878 bufp[3] = (val >> 24) & 0xFF;
2879 bufp[2] = (val >> 16) & 0xFF;
2880 bufp[1] = (val >> 8) & 0xFF;
2881 bufp[0] = val & 0xFF;
2884 /* FIXME: The 16 and 8-bit cases should have a way to check
2885 whether a signed or unsigned (or any signedness) number is
2887 FIXME: Does the as_bad calls find the line number by themselves,
2888 or should we change them into as_bad_where? */
2891 case BFD_RELOC_16_PCREL:
2892 if (val > 0xffff || val < -32768)
2893 as_bad (_("Value not in 16 bit range: %ld"), val);
2894 if (! fixP->fx_addsy)
2896 bufp[1] = (val >> 8) & 0xFF;
2897 bufp[0] = val & 0xFF;
2902 case BFD_RELOC_8_PCREL:
2903 if (val > 255 || val < -128)
2904 as_bad (_("Value not in 8 bit range: %ld"), val);
2905 if (! fixP->fx_addsy)
2906 bufp[0] = val & 0xFF;
2909 case BFD_RELOC_CRIS_UNSIGNED_4:
2910 if (val > 15 || val < 0)
2911 as_bad (_("Value not in 4 bit unsigned range: %ld"), val);
2912 if (! fixP->fx_addsy)
2913 bufp[0] |= val & 0x0F;
2916 case BFD_RELOC_CRIS_UNSIGNED_5:
2917 if (val > 31 || val < 0)
2918 as_bad (_("Value not in 5 bit unsigned range: %ld"), val);
2919 if (! fixP->fx_addsy)
2920 bufp[0] |= val & 0x1F;
2923 case BFD_RELOC_CRIS_SIGNED_6:
2924 if (val > 31 || val < -32)
2925 as_bad (_("Value not in 6 bit range: %ld"), val);
2926 if (! fixP->fx_addsy)
2927 bufp[0] |= val & 0x3F;
2930 case BFD_RELOC_CRIS_UNSIGNED_6:
2931 if (val > 63 || val < 0)
2932 as_bad (_("Value not in 6 bit unsigned range: %ld"), val);
2933 if (! fixP->fx_addsy)
2934 bufp[0] |= val & 0x3F;
2937 case BFD_RELOC_CRIS_BDISP8:
2938 if (! fixP->fx_addsy)
2939 bufp[0] = branch_disp (val);
2942 case BFD_RELOC_NONE:
2943 /* May actually happen automatically. For example at broken
2944 words, if the word turns out not to be broken.
2945 FIXME: When? Which testcase? */
2946 if (! fixP->fx_addsy)
2947 md_number_to_chars (bufp, val, n);
2950 case BFD_RELOC_VTABLE_INHERIT:
2951 /* This borrowed from tc-ppc.c on a whim. */
2953 && !S_IS_DEFINED (fixP->fx_addsy)
2954 && !S_IS_WEAK (fixP->fx_addsy))
2955 S_SET_WEAK (fixP->fx_addsy);
2958 case BFD_RELOC_VTABLE_ENTRY:
2963 BAD_CASE (fixP->fx_r_type);
2967 /* Processes machine-dependent command line options. Called once for
2968 each option on the command line that the machine-independent part of
2969 GAS does not understand. */
2972 md_parse_option (arg, argp)
2974 char *argp ATTRIBUTE_UNUSED;
2980 printf (_("Please use --help to see usage and options for this assembler.\n"));
2981 md_show_usage (stdout);
2982 exit (EXIT_SUCCESS);
2985 warn_for_branch_expansion = 1;
2989 demand_register_prefix = TRUE;
2991 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
2992 as_bad (_("--no-underscore is invalid with a.out format"));
2994 symbols_have_leading_underscore = FALSE;
2998 demand_register_prefix = FALSE;
2999 symbols_have_leading_underscore = TRUE;
3006 case OPTION_MULBUG_ABORT_OFF:
3007 err_for_dangerous_mul_placement = 0;
3010 case OPTION_MULBUG_ABORT_ON:
3011 err_for_dangerous_mul_placement = 1;
3019 /* Round up a section size to the appropriate boundary. */
3021 md_section_align (segment, size)
3025 /* Round all sects to multiple of 4, except the bss section, which
3026 we'll round to word-size.
3028 FIXME: Check if this really matters. All sections should be
3029 rounded up, and all sections should (optionally) be assumed to be
3030 dword-aligned, it's just that there is actual usage of linking to a
3032 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
3034 if (segment == bss_section)
3035 return (size + 1) & ~1;
3036 return (size + 3) & ~3;
3040 /* FIXME: Is this wanted? It matches the testsuite, but that's not
3041 really a valid reason. */
3042 if (segment == text_section)
3043 return (size + 3) & ~3;
3049 /* Generate a machine-dependent relocation. */
3051 tc_gen_reloc (section, fixP)
3052 asection *section ATTRIBUTE_UNUSED;
3056 bfd_reloc_code_real_type code;
3058 switch (fixP->fx_r_type)
3060 case BFD_RELOC_CRIS_16_GOT:
3061 case BFD_RELOC_CRIS_32_GOT:
3062 case BFD_RELOC_CRIS_16_GOTPLT:
3063 case BFD_RELOC_CRIS_32_GOTPLT:
3064 case BFD_RELOC_CRIS_32_GOTREL:
3065 case BFD_RELOC_CRIS_32_PLT_GOTREL:
3066 case BFD_RELOC_CRIS_32_PLT_PCREL:
3070 case BFD_RELOC_VTABLE_INHERIT:
3071 case BFD_RELOC_VTABLE_ENTRY:
3072 code = fixP->fx_r_type;
3075 as_bad_where (fixP->fx_file, fixP->fx_line,
3076 _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant"));
3080 relP = (arelent *) xmalloc (sizeof (arelent));
3082 relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3083 *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
3084 relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
3089 relP->addend = fixP->fx_offset;
3091 /* This is the standard place for KLUDGEs to work around bugs in
3092 bfd_install_relocation (first such note in the documentation
3093 appears with binutils-2.8).
3095 That function bfd_install_relocation does the wrong thing with
3096 putting stuff into the addend of a reloc (it should stay out) for a
3097 weak symbol. The really bad thing is that it adds the
3098 "segment-relative offset" of the symbol into the reloc. In this
3099 case, the reloc should instead be relative to the symbol with no
3100 other offset than the assembly code shows; and since the symbol is
3101 weak, any local definition should be ignored until link time (or
3103 To wit: weaksym+42 should be weaksym+42 in the reloc,
3104 not weaksym+(offset_from_segment_of_local_weaksym_definition)
3106 To "work around" this, we subtract the segment-relative offset of
3107 "known" weak symbols. This evens out the extra offset.
3109 That happens for a.out but not for ELF, since for ELF,
3110 bfd_install_relocation uses the "special function" field of the
3111 howto, and does not execute the code that needs to be undone. */
3113 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
3114 && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
3115 && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
3117 relP->addend -= S_GET_VALUE (fixP->fx_addsy);
3120 relP->howto = bfd_reloc_type_lookup (stdoutput, code);
3125 name = S_GET_NAME (fixP->fx_addsy);
3127 name = _("<unknown>");
3128 as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
3129 name, bfd_get_reloc_code_name (code));
3135 /* Machine-dependent usage-output. */
3138 md_show_usage (stream)
3141 /* The messages are formatted to line up with the generic options. */
3142 fprintf (stream, _("CRIS-specific options:\n"));
3143 fprintf (stream, "%s",
3144 _(" -h, -H Don't execute, print this help text. Deprecated.\n"));
3145 fprintf (stream, "%s",
3146 _(" -N Warn when branches are expanded to jumps.\n"));
3147 fprintf (stream, "%s",
3148 _(" --underscore User symbols are normally prepended with underscore.\n"));
3149 fprintf (stream, "%s",
3150 _(" Registers will not need any prefix.\n"));
3151 fprintf (stream, "%s",
3152 _(" --no-underscore User symbols do not have any prefix.\n"));
3153 fprintf (stream, "%s",
3154 _(" Registers will require a `$'-prefix.\n"));
3155 fprintf (stream, "%s",
3156 _(" --pic Enable generation of position-independent code.\n"));
3159 /* Apply a fixS (fixup of an instruction or data that we didn't have
3160 enough info to complete immediately) to the data in a frag. */
3163 md_apply_fix3 (fixP, valP, seg)
3168 /* This assignment truncates upper bits if valueT is 64 bits (as with
3169 --enable-64-bit-bfd), which is fine here, though we cast to avoid
3170 any compiler warnings. */
3171 long val = (long) *valP;
3172 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3174 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
3177 if (fixP->fx_bit_fixP || fixP->fx_im_disp != 0)
3179 as_bad_where (fixP->fx_file, fixP->fx_line, _("Invalid relocation"));
3184 /* We can't actually support subtracting a symbol. */
3185 if (fixP->fx_subsy != (symbolS *) NULL)
3186 as_bad_where (fixP->fx_file, fixP->fx_line,
3187 _("expression too complex"));
3189 cris_number_to_imm (buf, val, fixP->fx_size, fixP, seg);
3193 /* All relocations are relative to the location just after the fixup;
3194 the address of the fixup plus its size. */
3197 md_pcrel_from (fixP)
3200 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
3202 /* FIXME: We get here only at the end of assembly, when X in ".-X" is
3203 still unknown. Since we don't have pc-relative relocations in a.out,
3204 this is invalid. What to do if anything for a.out, is to add
3205 pc-relative relocations everywhere including the elinux program
3206 loader. For ELF, allow straight-forward PC-relative relocations,
3207 which are always relative to the location after the relocation. */
3208 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
3209 || (fixP->fx_r_type != BFD_RELOC_8_PCREL
3210 && fixP->fx_r_type != BFD_RELOC_16_PCREL
3211 && fixP->fx_r_type != BFD_RELOC_32_PCREL))
3212 as_bad_where (fixP->fx_file, fixP->fx_line,
3213 _("Invalid pc-relative relocation"));
3214 return fixP->fx_size + addr;
3217 /* We have no need to give defaults for symbol-values. */
3219 md_undefined_symbol (name)
3220 char *name ATTRIBUTE_UNUSED;
3225 /* If this function returns non-zero, it prevents the relocation
3226 against symbol(s) in the FIXP from being replaced with relocations
3227 against section symbols, and guarantees that a relocation will be
3228 emitted even when the value can be resolved locally. */
3230 md_cris_force_relocation (fixp)
3233 switch (fixp->fx_r_type)
3235 case BFD_RELOC_CRIS_16_GOT:
3236 case BFD_RELOC_CRIS_32_GOT:
3237 case BFD_RELOC_CRIS_16_GOTPLT:
3238 case BFD_RELOC_CRIS_32_GOTPLT:
3239 case BFD_RELOC_CRIS_32_GOTREL:
3240 case BFD_RELOC_CRIS_32_PLT_GOTREL:
3241 case BFD_RELOC_CRIS_32_PLT_PCREL:
3247 return generic_force_reloc (fixp);
3250 /* Check and emit error if broken-word handling has failed to fix up a
3251 case-table. This is called from write.c, after doing everything it
3252 knows about how to handle broken words. */
3255 tc_cris_check_adjusted_broken_word (new_offset, brokwP)
3257 struct broken_word *brokwP;
3259 if (new_offset > 32767 || new_offset < -32768)
3260 /* We really want a genuine error, not a warning, so make it one. */
3261 as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line,
3262 _("Adjusted signed .word (%ld) overflows: `switch'-statement too large."),
3266 /* Make a leading REGISTER_PREFIX_CHAR mandatory for all registers. */
3268 static void cris_force_reg_prefix ()
3270 demand_register_prefix = TRUE;
3273 /* Do not demand a leading REGISTER_PREFIX_CHAR for all registers. */
3275 static void cris_relax_reg_prefix ()
3277 demand_register_prefix = FALSE;
3280 /* Adjust for having a leading '_' on all user symbols. */
3282 static void cris_sym_leading_underscore ()
3284 /* We can't really do anything more than assert that what the program
3285 thinks symbol starts with agrees with the command-line options, since
3286 the bfd is already created. */
3288 if (!symbols_have_leading_underscore)
3289 as_bad (_(".syntax %s requires command-line option `--underscore'"),
3290 SYNTAX_USER_SYM_LEADING_UNDERSCORE);
3293 /* Adjust for not having any particular prefix on user symbols. */
3295 static void cris_sym_no_leading_underscore ()
3297 if (symbols_have_leading_underscore)
3298 as_bad (_(".syntax %s requires command-line option `--no-underscore'"),
3299 SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE);
3302 /* Handle the .syntax pseudo, which takes an argument that decides what
3303 syntax the assembly code has. */
3307 int ignore ATTRIBUTE_UNUSED;
3309 static const struct syntaxes
3311 const char *operand;
3312 void (*fn) PARAMS ((void));
3314 {{SYNTAX_ENFORCE_REG_PREFIX, cris_force_reg_prefix},
3315 {SYNTAX_RELAX_REG_PREFIX, cris_relax_reg_prefix},
3316 {SYNTAX_USER_SYM_LEADING_UNDERSCORE, cris_sym_leading_underscore},
3317 {SYNTAX_USER_SYM_NO_LEADING_UNDERSCORE, cris_sym_no_leading_underscore}};
3319 const struct syntaxes *sp;
3321 for (sp = syntax_table;
3322 sp < syntax_table + sizeof (syntax_table) / sizeof (syntax_table[0]);
3325 if (strncmp (input_line_pointer, sp->operand,
3326 strlen (sp->operand)) == 0)
3330 input_line_pointer += strlen (sp->operand);
3331 demand_empty_rest_of_line ();
3336 as_bad (_("Unknown .syntax operand"));
3339 /* Wrapper for dwarf2_directive_file to emit error if this is seen when
3340 not emitting ELF. */
3346 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
3347 as_bad (_("Pseudodirective .file is only valid when generating ELF"));
3349 dwarf2_directive_file (dummy);
3352 /* Wrapper for dwarf2_directive_loc to emit error if this is seen when not
3359 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
3360 as_bad (_("Pseudodirective .loc is only valid when generating ELF"));
3362 dwarf2_directive_loc (dummy);
3367 * eval: (c-set-style "gnu")
3368 * indent-tabs-mode: t