1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "../opcodes/mcore-opc.h"
27 #include "safe-ctype.h"
31 #include "elf/mcore.h"
35 #define streq(a,b) (strcmp (a, b) == 0)
38 /* Forward declarations for dumb compilers. */
39 static void mcore_s_literals
PARAMS ((int));
40 static void mcore_cons
PARAMS ((int));
41 static void mcore_float_cons
PARAMS ((int));
42 static void mcore_stringer
PARAMS ((int));
43 static void mcore_fill
PARAMS ((int));
44 static int log2
PARAMS ((unsigned int));
45 static char * parse_reg
PARAMS ((char *, unsigned *));
46 static char * parse_creg
PARAMS ((char *, unsigned *));
47 static char * parse_exp
PARAMS ((char *, expressionS
*));
48 static char * parse_rt
PARAMS ((char *, char **, int, expressionS
*));
49 static char * parse_imm
PARAMS ((char *, unsigned *, unsigned, unsigned));
50 static char * parse_mem
PARAMS ((char *, unsigned *, unsigned *, unsigned));
51 static char * parse_psrmod
PARAMS ((char *, unsigned *));
52 static void make_name
PARAMS ((char *, char *, int));
53 static int enter_literal
PARAMS ((expressionS
*, int));
54 static void dump_literals
PARAMS ((int));
55 static void check_literals
PARAMS ((int, int));
56 static void mcore_s_text
PARAMS ((int));
57 static void mcore_s_data
PARAMS ((int));
58 static void mcore_s_section
PARAMS ((int));
59 static void mcore_s_bss
PARAMS ((int));
61 static void mcore_s_comm
PARAMS ((int));
64 /* Several places in this file insert raw instructions into the
65 object. They should use MCORE_INST_XXX macros to get the opcodes
66 and then use these two macros to crack the MCORE_INST value into
67 the appropriate byte values. */
68 #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
69 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF))
71 const char comment_chars
[] = "#/";
72 const char line_separator_chars
[] = ";";
73 const char line_comment_chars
[] = "#/";
75 const int md_reloc_size
= 8;
77 static int do_jsri2bsr
= 0; /* Change here from 1 by Cruess 19 August 97. */
78 static int sifilter_mode
= 0;
80 const char EXP_CHARS
[] = "eE";
82 /* Chars that mean this number is a floating point constant
85 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
87 #define C(what,length) (((what) << 2) + (length))
88 #define GET_WHAT(x) ((x >> 2))
90 /* These are the two types of relaxable instruction */
97 #define UNDEF_WORD_DISP 3
100 #define C32_LEN 10 /* allow for align */
102 #define U32_LEN 8 /* allow for align */
113 /* Initialize the relax table. */
114 const relax_typeS md_relax_table
[] = {
121 { 0, 0, 0, 0 }, /* UNDEF_DISP */
122 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* DISP12 */
123 { 0, 0, C32_LEN
, 0 }, /* DISP32 */
124 { 0, 0, C32_LEN
, 0 }, /* UNDEF_WORD_DISP */
127 { 0, 0, 0, 0 }, /* UNDEF_DISP */
128 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* DISP12 */
129 { 0, 0, U32_LEN
, 0 }, /* DISP32 */
130 { 0, 0, U32_LEN
, 0 } /* UNDEF_WORD_DISP */
134 /* Literal pool data structures. */
137 unsigned short refcnt
;
138 unsigned char ispcrel
;
139 unsigned char unused
;
143 #define MAX_POOL_SIZE (1024/4)
144 static struct literal litpool
[MAX_POOL_SIZE
];
145 static unsigned poolsize
;
146 static unsigned poolnumber
;
147 static unsigned long poolspan
;
149 /* SPANPANIC: the point at which we get too scared and force a dump
150 of the literal pool, and perhaps put a branch in place.
152 1024 span of lrw/jmpi/jsri insn (actually span+1)
153 -2 possible alignment at the insn.
154 -2 possible alignment to get the table aligned.
155 -2 an inserted branch around the table.
157 at 1018, we might be in trouble.
158 -- so we have to be smaller than 1018 and since we deal with 2-byte
159 instructions, the next good choice is 1016.
160 -- Note we have a test case that fails when we've got 1018 here. */
161 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
162 #define SPANCLOSE (900)
163 #define SPANEXIT (600)
164 static symbolS
* poolsym
; /* label for current pool. */
165 static char poolname
[8];
166 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
168 /* This table describes all the machine specific pseudo-ops the assembler
169 has to support. The fields are:
170 Pseudo-op name without dot
171 Function to call to execute this pseudo-op
172 Integer arg to pass to the function. */
173 const pseudo_typeS md_pseudo_table
[] =
175 { "export", s_globl
, 0 },
176 { "import", s_ignore
, 0 },
177 { "literals", mcore_s_literals
, 0 },
178 { "page", listing_eject
, 0 },
180 /* The following are to intercept the placement of data into the text
181 section (eg addresses for a switch table), so that the space they
182 occupy can be taken into account when deciding whether or not to
183 dump the current literal pool.
184 XXX - currently we do not cope with the .space and .dcb.d directives. */
185 { "ascii", mcore_stringer
, 0 },
186 { "asciz", mcore_stringer
, 1 },
187 { "byte", mcore_cons
, 1 },
188 { "dc", mcore_cons
, 2 },
189 { "dc.b", mcore_cons
, 1 },
190 { "dc.d", mcore_float_cons
, 'd'},
191 { "dc.l", mcore_cons
, 4 },
192 { "dc.s", mcore_float_cons
, 'f'},
193 { "dc.w", mcore_cons
, 2 },
194 { "dc.x", mcore_float_cons
, 'x'},
195 { "double", mcore_float_cons
, 'd'},
196 { "float", mcore_float_cons
, 'f'},
197 { "hword", mcore_cons
, 2 },
198 { "int", mcore_cons
, 4 },
199 { "long", mcore_cons
, 4 },
200 { "octa", mcore_cons
, 16 },
201 { "quad", mcore_cons
, 8 },
202 { "short", mcore_cons
, 2 },
203 { "single", mcore_float_cons
, 'f'},
204 { "string", mcore_stringer
, 1 },
205 { "word", mcore_cons
, 2 },
206 { "fill", mcore_fill
, 0 },
208 /* Allow for the effect of section changes. */
209 { "text", mcore_s_text
, 0 },
210 { "data", mcore_s_data
, 0 },
211 { "bss", mcore_s_bss
, 1 },
213 { "comm", mcore_s_comm
, 0 },
215 { "section", mcore_s_section
, 0 },
216 { "section.s", mcore_s_section
, 0 },
217 { "sect", mcore_s_section
, 0 },
218 { "sect.s", mcore_s_section
, 0 },
224 mcore_s_literals (ignore
)
228 demand_empty_rest_of_line ();
235 if (now_seg
== text_section
)
237 char * ptr
= input_line_pointer
;
240 /* Count the number of commas on the line. */
241 while (! is_end_of_line
[(unsigned char) * ptr
])
242 commas
+= * ptr
++ == ',';
244 poolspan
+= nbytes
* commas
;
249 /* In theory we ought to call check_literals (2,0) here in case
250 we need to dump the literal table. We cannot do this however,
251 as the directives that we are intercepting may be being used
252 to build a switch table, and we must not interfere with its
253 contents. Instead we cross our fingers and pray... */
257 mcore_float_cons (float_type
)
260 if (now_seg
== text_section
)
262 char * ptr
= input_line_pointer
;
265 #ifdef REPEAT_CONS_EXPRESSIONS
266 #error REPEAT_CONS_EXPRESSIONS not handled
269 /* Count the number of commas on the line. */
270 while (! is_end_of_line
[(unsigned char) * ptr
])
271 commas
+= * ptr
++ == ',';
273 /* We would like to compute "hex_float (float_type) * commas"
274 but hex_float is not exported from read.c */
275 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
276 poolspan
+= float_type
* commas
;
279 float_cons (float_type
);
281 /* See the comment in mcore_cons () about calling check_literals.
282 It is unlikely that a switch table will be constructed using
283 floating point values, but it is still likely that an indexed
284 table of floating point constants is being created by these
285 directives, so again we must not interfere with their placement. */
289 mcore_stringer (append_zero
)
292 if (now_seg
== text_section
)
294 char * ptr
= input_line_pointer
;
296 /* In theory we should compute how many bytes are going to
297 be occupied by the string(s) and add this to the poolspan.
298 To keep things simple however, we just add the number of
299 bytes left on the current line. This will be an over-
300 estimate, which is OK, and automatically allows for the
301 appending a zero byte, since the real string(s) is/are
302 required to be enclosed in double quotes. */
303 while (! is_end_of_line
[(unsigned char) * ptr
])
306 poolspan
+= ptr
- input_line_pointer
;
309 stringer (append_zero
);
311 /* We call check_literals here in case a large number of strings are
312 being placed into the text section with a sequence of stringer
313 directives. In theory we could be upsetting something if these
314 strings are actually in an indexed table instead of referenced by
315 individual labels. Let us hope that that never happens. */
316 check_literals (2, 0);
323 if (now_seg
== text_section
)
325 char * str
= input_line_pointer
;
331 /* Look to see if a size has been specified. */
332 while (*str
!= '\n' && *str
!= 0 && *str
!= ',')
337 size
= atoi (str
+ 1);
345 poolspan
+= size
* repeat
;
350 check_literals (2, 0);
353 /* Handle the section changing pseudo-ops. These call through to the
354 normal implementations, but they dump the literal pool first. */
356 mcore_s_text (ignore
)
362 obj_elf_text (ignore
);
369 mcore_s_data (ignore
)
375 obj_elf_data (ignore
);
382 mcore_s_section (ignore
)
385 /* Scan forwards to find the name of the section. If the section
386 being switched to is ".line" then this is a DWARF1 debug section
387 which is arbitarily placed inside generated code. In this case
388 do not dump the literal pool because it is a) inefficient and
389 b) would require the generation of extra code to jump around the
391 char * ilp
= input_line_pointer
;
393 while (*ilp
!= 0 && ISSPACE (*ilp
))
396 if (strncmp (ilp
, ".line", 5) == 0
397 && (ISSPACE (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
403 obj_elf_section (ignore
);
406 obj_coff_section (ignore
);
411 mcore_s_bss (needs_align
)
416 s_lcomm_bytes (needs_align
);
421 mcore_s_comm (needs_align
)
426 obj_elf_common (needs_align
);
430 /* This function is called once, at assembler startup time. This should
431 set up all the tables, etc that the MD part of the assembler needs. */
435 const mcore_opcode_info
* opcode
;
436 char * prev_name
= "";
438 opcode_hash_control
= hash_new ();
440 /* Insert unique names into hash table */
441 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
443 if (! streq (prev_name
, opcode
->name
))
445 prev_name
= opcode
->name
;
446 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
453 static expressionS immediate
; /* absolute expression */
455 /* Get a log2(val). */
470 /* Try to parse a reg name. */
476 /* Strip leading whitespace. */
477 while (ISSPACE (* s
))
480 if (TOLOWER (s
[0]) == 'r')
482 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
484 *reg
= 10 + s
[2] - '0';
488 if (s
[1] >= '0' && s
[1] <= '9')
494 else if ( TOLOWER (s
[0]) == 's'
495 && TOLOWER (s
[1]) == 'p'
502 as_bad (_("register expected, but saw '%.6s'"), s
);
536 /* Strip leading whitespace. */
537 while (ISSPACE (* s
))
540 if ((TOLOWER (s
[0]) == 'c' && TOLOWER (s
[1]) == 'r'))
542 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
544 *reg
= 30 + s
[3] - '0';
548 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
550 *reg
= 20 + s
[3] - '0';
554 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
556 *reg
= 10 + s
[3] - '0';
560 if (s
[2] >= '0' && s
[2] <= '9')
567 /* Look at alternate creg names before giving error. */
568 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
574 length
= strlen (cregs
[i
].name
);
576 for (j
= 0; j
< length
; j
++)
577 buf
[j
] = TOLOWER (s
[j
]);
579 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
581 *reg
= cregs
[i
].crnum
;
586 as_bad (_("control register expected, but saw '%.6s'"), s
);
592 parse_psrmod (s
, reg
)
598 static struct psrmods
608 { "af", 8 } /* Really 0 and non-combinable. */
611 for (i
= 0; i
< 2; i
++)
612 buf
[i
] = TOLOWER (s
[i
]);
614 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
616 if (! strncmp (psrmods
[i
].name
, buf
, 2))
618 * reg
= psrmods
[i
].value
;
624 as_bad (_("bad/missing psr specifier"));
639 /* Skip whitespace. */
640 while (ISSPACE (* s
))
643 save
= input_line_pointer
;
644 input_line_pointer
= s
;
648 if (e
->X_op
== O_absent
)
649 as_bad (_("missing operand"));
651 new = input_line_pointer
;
652 input_line_pointer
= save
;
663 static const char hex
[] = "0123456789ABCDEF";
668 s
[3] = hex
[(n
>> 12) & 0xF];
669 s
[4] = hex
[(n
>> 8) & 0xF];
670 s
[5] = hex
[(n
>> 4) & 0xF];
671 s
[6] = hex
[(n
) & 0xF];
675 #define POOL_END_LABEL ".LE"
676 #define POOL_START_LABEL ".LS"
679 dump_literals (isforce
)
689 /* Must we branch around the literal table? */
695 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
697 brarsym
= symbol_make (brarname
);
699 symbol_table_insert (brarsym
);
701 output
= frag_var (rs_machine_dependent
,
702 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
703 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
704 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
705 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
706 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
709 /* Make sure that the section is sufficiently aligned and that
710 the literal table is aligned within it. */
711 record_alignment (now_seg
, 2);
712 frag_align (2, 0, 0);
714 colon (S_GET_NAME (poolsym
));
716 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
717 emit_expr (& p
->e
, 4);
720 colon (S_GET_NAME (brarsym
));
726 check_literals (kind
, offset
)
732 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
733 SPANPANIC means that we must dump now.
734 kind == 0 is any old instruction.
735 kind > 0 means we just had a control transfer instruction.
736 kind == 1 means within a function
737 kind == 2 means we just left a function
739 The dump_literals (1) call inserts a branch around the table, so
740 we first look to see if its a situation where we won't have to
741 insert a branch (e.g., the previous instruction was an unconditional
744 SPANPANIC is the point where we must dump a single-entry pool.
745 it accounts for alignments and an inserted branch.
746 the 'poolsize*2' accounts for the scenario where we do:
747 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
748 Note that the 'lit2' reference is 2 bytes further along
749 but the literal it references will be 4 bytes further along,
750 so we must consider the poolsize into this equation.
751 This is slightly over-cautious, but guarantees that we won't
752 panic because a relocation is too distant. */
754 if (poolspan
> SPANCLOSE
&& kind
> 0)
756 else if (poolspan
> SPANEXIT
&& kind
> 1)
758 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
763 enter_literal (e
, ispcrel
)
770 if (poolsize
>= MAX_POOL_SIZE
- 2)
772 /* The literal pool is as full as we can handle. We have
773 to be 2 entries shy of the 1024/4=256 entries because we
774 have to allow for the branch (2 bytes) and the alignment
775 (2 bytes before the first insn referencing the pool and
776 2 bytes before the pool itself) == 6 bytes, rounds up
783 /* Create new literal pool. */
784 if (++ poolnumber
> 0xFFFF)
785 as_fatal (_("more than 65K literal pools"));
787 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
788 poolsym
= symbol_make (poolname
);
789 symbol_table_insert (poolsym
);
793 /* Search pool for value so we don't have duplicates. */
794 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
796 if (e
->X_op
== p
->e
.X_op
797 && e
->X_add_symbol
== p
->e
.X_add_symbol
798 && e
->X_add_number
== p
->e
.X_add_number
799 && ispcrel
== p
->ispcrel
)
807 p
->ispcrel
= ispcrel
;
815 /* Parse a literal specification. -- either new or old syntax.
816 old syntax: the user supplies the label and places the literal.
817 new syntax: we put it into the literal pool. */
819 parse_rt (s
, outputp
, ispcrel
, ep
)
829 /* Indicate nothing there. */
834 s
= parse_exp (s
+ 1, & e
);
839 as_bad (_("missing ']'"));
843 s
= parse_exp (s
, & e
);
845 n
= enter_literal (& e
, ispcrel
);
850 /* Create a reference to pool entry. */
852 e
.X_add_symbol
= poolsym
;
853 e
.X_add_number
= n
<< 2;
856 * outputp
= frag_more (2);
858 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
859 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
865 parse_imm (s
, val
, min
, max
)
874 new = parse_exp (s
, & e
);
876 if (e
.X_op
== O_absent
)
877 ; /* An error message has already been emitted. */
878 else if (e
.X_op
!= O_constant
)
879 as_bad (_("operand must be a constant"));
880 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
881 as_bad (_("operand must be absolute in range %d..%d, not %d"),
882 min
, max
, e
.X_add_number
);
884 * val
= e
.X_add_number
;
890 parse_mem (s
, reg
, off
, siz
)
900 while (ISSPACE (* s
))
905 s
= parse_reg (s
+ 1, reg
);
907 while (ISSPACE (* s
))
912 s
= parse_imm (s
+ 1, off
, 0, 63);
919 as_bad (_("operand must be a multiple of 4"));
926 as_bad (_("operand must be a multiple of 2"));
933 while (ISSPACE (* s
))
940 as_bad (_("base register expected"));
945 /* This is the guts of the machine-dependent assembler. STR points to a
946 machine dependent instruction. This function is supposed to emit
947 the frags/bytes it assembles to. */
955 mcore_opcode_info
* opcode
;
965 /* Drop leading whitespace. */
966 while (ISSPACE (* str
))
969 /* Find the op code end. */
970 for (op_start
= op_end
= str
;
971 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
974 name
[nlen
] = op_start
[nlen
];
982 as_bad (_("can't find opcode "));
986 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
989 as_bad (_("unknown opcode \"%s\""), name
);
996 switch (opcode
->opclass
)
999 output
= frag_more (2);
1003 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
1005 output
= frag_more (2);
1009 op_end
= parse_reg (op_end
+ 1, & reg
);
1011 output
= frag_more (2);
1015 op_end
= parse_reg (op_end
+ 1, & reg
);
1017 output
= frag_more (2);
1018 /* In a sifilter mode, we emit this insn 2 times,
1019 fixes problem of an interrupt during a jmp.. */
1022 output
[0] = INST_BYTE0 (inst
);
1023 output
[1] = INST_BYTE1 (inst
);
1024 output
= frag_more (2);
1029 op_end
= parse_reg (op_end
+ 1, & reg
);
1032 as_bad (_("invalid register: r15 illegal"));
1035 output
= frag_more (2);
1039 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
1040 inst
= MCORE_INST_BSR
; /* with 0 displacement */
1041 output
[0] = INST_BYTE0 (inst
);
1042 output
[1] = INST_BYTE1 (inst
);
1044 output
= frag_more (2);
1045 inst
= MCORE_INST_ADDI
;
1046 inst
|= 15; /* addi r15,6 */
1047 inst
|= (6 - 1) << 4; /* over the jmp's */
1048 output
[0] = INST_BYTE0 (inst
);
1049 output
[1] = INST_BYTE1 (inst
);
1051 output
= frag_more (2);
1052 inst
= MCORE_INST_JMP
| reg
;
1053 output
[0] = INST_BYTE0 (inst
);
1054 output
[1] = INST_BYTE1 (inst
);
1056 output
= frag_more (2); /* 2nd emitted in fallthru */
1061 op_end
= parse_reg (op_end
+ 1, & reg
);
1064 /* Skip whitespace. */
1065 while (ISSPACE (* op_end
))
1070 op_end
= parse_creg (op_end
+ 1, & reg
);
1074 output
= frag_more (2);
1080 as_bad (_("M340 specific opcode used when assembling for M210"));
1083 /* drop through... */
1085 op_end
= parse_reg (op_end
+ 1, & reg
);
1088 /* Skip whitespace. */
1089 while (ISSPACE (* op_end
))
1092 if (* op_end
== ',')
1094 op_end
= parse_reg (op_end
+ 1, & reg
);
1098 as_bad (_("second operand missing"));
1100 output
= frag_more (2);
1103 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1104 op_end
= parse_reg (op_end
+ 1, & reg
);
1106 /* Skip whitespace. */
1107 while (ISSPACE (* op_end
))
1110 if (* op_end
== ',') /* xtrb- r1,rx */
1113 as_bad (_("destination register must be r1"));
1115 op_end
= parse_reg (op_end
+ 1, & reg
);
1119 output
= frag_more (2);
1122 case O1R1
: /* div- rx,r1 */
1123 op_end
= parse_reg (op_end
+ 1, & reg
);
1126 /* Skip whitespace. */
1127 while (ISSPACE (* op_end
))
1130 if (* op_end
== ',')
1132 op_end
= parse_reg (op_end
+ 1, & reg
);
1134 as_bad (_("source register must be r1"));
1137 as_bad (_("second operand missing"));
1139 output
= frag_more (2);
1143 op_end
= parse_reg (op_end
+ 1, & reg
);
1146 /* Skip whitespace. */
1147 while (ISSPACE (* op_end
))
1150 if (* op_end
== ',')
1152 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1153 inst
|= (reg
- 1) << 4;
1156 as_bad (_("second operand missing"));
1158 output
= frag_more (2);
1162 op_end
= parse_reg (op_end
+ 1, & reg
);
1165 /* Skip whitespace. */
1166 while (ISSPACE (* op_end
))
1169 if (* op_end
== ',')
1171 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1175 as_bad (_("second operand missing"));
1177 output
= frag_more (2);
1180 case OB2
: /* like OB, but arg is 2^n instead of n */
1181 op_end
= parse_reg (op_end
+ 1, & reg
);
1184 /* Skip whitespace. */
1185 while (ISSPACE (* op_end
))
1188 if (* op_end
== ',')
1190 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1191 /* Further restrict the immediate to a power of two. */
1192 if ((reg
& (reg
- 1)) == 0)
1197 as_bad (_("immediate is not a power of two"));
1202 as_bad (_("second operand missing"));
1204 output
= frag_more (2);
1207 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1210 op_end
= parse_reg (op_end
+ 1, & reg
);
1213 /* Skip whitespace. */
1214 while (ISSPACE (* op_end
))
1217 if (* op_end
== ',')
1219 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1220 /* immediate values of 0 -> 6 translate to movi */
1223 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1225 as_warn (_("translating bgeni to movi"));
1231 as_bad (_("second operand missing"));
1233 output
= frag_more (2);
1236 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1237 op_end
= parse_reg (op_end
+ 1, & reg
);
1240 /* Skip whitespace. */
1241 while (ISSPACE (* op_end
))
1244 if (* op_end
== ',')
1246 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1248 /* Further restrict the immediate to a power of two. */
1249 if ((reg
& (reg
- 1)) == 0)
1254 as_bad (_("immediate is not a power of two"));
1257 /* Immediate values of 0 -> 6 translate to movi. */
1260 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1262 as_warn (_("translating mgeni to movi"));
1268 as_bad (_("second operand missing"));
1270 output
= frag_more (2);
1273 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1276 op_end
= parse_reg (op_end
+ 1, & reg
);
1279 /* Skip whitespace. */
1280 while (ISSPACE (* op_end
))
1283 if (* op_end
== ',')
1285 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1287 /* Immediate values of 1 -> 7 translate to movi. */
1290 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1291 reg
= (0x1 << reg
) - 1;
1294 as_warn (_("translating bmaski to movi"));
1299 inst
|= (reg
& 0x1F) << 4;
1303 as_bad (_("second operand missing"));
1305 output
= frag_more (2);
1309 op_end
= parse_reg (op_end
+ 1, & reg
);
1312 /* Skip whitespace. */
1313 while (ISSPACE (* op_end
))
1316 if (* op_end
== ',')
1318 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1322 as_bad (_("second operand missing"));
1324 output
= frag_more (2);
1328 op_end
= parse_reg (op_end
+ 1, & reg
);
1331 /* Skip whitespace. */
1332 while (ISSPACE (* op_end
))
1335 if (* op_end
== ',')
1337 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1341 as_bad (_("second operand missing"));
1343 output
= frag_more (2);
1347 op_end
= parse_reg (op_end
+ 1, & reg
);
1350 /* Skip whitespace. */
1351 while (ISSPACE (* op_end
))
1354 if (* op_end
== ',')
1358 if ((inst
& 0x6000) == 0)
1360 else if ((inst
& 0x6000) == 0x4000)
1362 else if ((inst
& 0x6000) == 0x2000)
1365 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1368 as_bad (_("displacement too large (%d)"), off
);
1370 inst
|= (reg
) | (off
<< 4);
1373 as_bad (_("second operand missing"));
1375 output
= frag_more (2);
1379 op_end
= parse_reg (op_end
+ 1, & reg
);
1381 if (reg
== 0 || reg
== 15)
1382 as_bad (_("Invalid register: r0 and r15 illegal"));
1386 /* Skip whitespace. */
1387 while (ISSPACE (* op_end
))
1390 if (* op_end
== ',')
1392 /* parse_rt calls frag_more() for us. */
1393 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1394 op_end
= input_line_pointer
;
1398 as_bad (_("second operand missing"));
1399 output
= frag_more (2); /* save its space */
1404 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1405 /* parse_rt() calls frag_more() for us. */
1406 op_end
= input_line_pointer
;
1410 op_end
= parse_reg (op_end
+ 1, & reg
);
1412 if (reg
== 0 || reg
== 15)
1413 as_bad (_("bad starting register: r0 and r15 invalid"));
1417 /* Skip whitespace. */
1418 while (ISSPACE (* op_end
))
1421 if (* op_end
== '-')
1423 op_end
= parse_reg (op_end
+ 1, & reg
);
1426 as_bad (_("ending register must be r15"));
1428 /* Skip whitespace. */
1429 while (ISSPACE (* op_end
))
1433 if (* op_end
== ',')
1437 /* Skip whitespace. */
1438 while (ISSPACE (* op_end
))
1441 if (* op_end
== '(')
1443 op_end
= parse_reg (op_end
+ 1, & reg
);
1446 as_bad (_("bad base register: must be r0"));
1448 if (* op_end
== ')')
1452 as_bad (_("base register expected"));
1455 as_bad (_("second operand missing"));
1457 output
= frag_more (2);
1461 op_end
= parse_reg (op_end
+ 1, & reg
);
1464 as_fatal (_("first register must be r4"));
1466 /* Skip whitespace. */
1467 while (ISSPACE (* op_end
))
1470 if (* op_end
== '-')
1472 op_end
= parse_reg (op_end
+ 1, & reg
);
1475 as_fatal (_("last register must be r7"));
1477 /* Skip whitespace. */
1478 while (ISSPACE (* op_end
))
1481 if (* op_end
== ',')
1485 /* Skip whitespace. */
1486 while (ISSPACE (* op_end
))
1489 if (* op_end
== '(')
1491 op_end
= parse_reg (op_end
+ 1, & reg
);
1493 if (reg
>= 4 && reg
<= 7)
1494 as_fatal ("base register cannot be r4, r5, r6, or r7");
1498 /* Skip whitespace. */
1499 while (ISSPACE (* op_end
))
1502 if (* op_end
== ')')
1506 as_bad (_("base register expected"));
1509 as_bad (_("second operand missing"));
1512 as_bad (_("reg-reg expected"));
1514 output
= frag_more (2);
1518 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1519 op_end
= input_line_pointer
;
1521 output
= frag_more (2);
1523 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1524 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1528 op_end
= parse_reg (op_end
+ 1, & reg
);
1531 /* Skip whitespace. */
1532 while (ISSPACE (* op_end
))
1535 if (* op_end
== ',')
1537 op_end
= parse_exp (op_end
+ 1, & e
);
1538 output
= frag_more (2);
1540 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1541 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1545 as_bad (_("second operand missing"));
1546 output
= frag_more (2);
1551 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1552 op_end
= input_line_pointer
;
1554 output
= frag_var (rs_machine_dependent
,
1555 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1556 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1557 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1562 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1563 op_end
= input_line_pointer
;
1565 output
= frag_var (rs_machine_dependent
,
1566 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1567 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1568 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1573 inst
= MCORE_INST_JSRI
; /* jsri */
1574 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1575 /* parse_rt() calls frag_more for us. */
1576 op_end
= input_line_pointer
;
1578 /* Only do this if we know how to do it ... */
1579 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1581 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1582 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1583 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1587 case RSI
: /* SI, but imm becomes 32-imm */
1588 op_end
= parse_reg (op_end
+ 1, & reg
);
1591 /* Skip whitespace. */
1592 while (ISSPACE (* op_end
))
1595 if (* op_end
== ',')
1597 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1603 as_bad (_("second operand missing"));
1605 output
= frag_more (2);
1608 case DO21
: /* O2, dup rd, lit must be 1 */
1609 op_end
= parse_reg (op_end
+ 1, & reg
);
1613 /* Skip whitespace. */
1614 while (ISSPACE (* op_end
))
1617 if (* op_end
== ',')
1619 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1622 as_bad (_("second operand must be 1"));
1625 as_bad (_("second operand missing"));
1627 output
= frag_more (2);
1631 op_end
= parse_reg (op_end
+ 1, & reg
);
1634 /* Skip whitespace. */
1635 while (ISSPACE (* op_end
))
1638 if (* op_end
== ',')
1640 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1643 as_bad (_("zero used as immediate value"));
1648 as_bad (_("second operand missing"));
1650 output
= frag_more (2);
1656 as_bad (_("M340 specific opcode used when assembling for M210"));
1660 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1662 /* Look for further selectors. */
1663 while (* op_end
== ',')
1667 op_end
= parse_psrmod (op_end
+ 1, & value
);
1670 as_bad (_("duplicated psr bit specifier"));
1676 as_bad (_("`af' must appear alone"));
1678 inst
|= (reg
& 0x7);
1679 output
= frag_more (2);
1683 as_bad (_("unimplemented opcode \"%s\""), name
);
1686 /* Drop whitespace after all the operands have been parsed. */
1687 while (ISSPACE (* op_end
))
1690 /* Give warning message if the insn has more operands than required. */
1691 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1692 as_warn (_("ignoring operands: %s "), op_end
);
1694 output
[0] = INST_BYTE0 (inst
);
1695 output
[1] = INST_BYTE1 (inst
);
1697 check_literals (opcode
->transfer
, isize
);
1701 md_undefined_symbol (name
)
1711 subseg_set (text_section
, 0);
1714 /* Various routines to kill one day. */
1715 /* Equal to MAX_PRECISION in atof-ieee.c */
1716 #define MAX_LITTLENUMS 6
1718 /* Turn a string in input_line_pointer into a floating point constant of type
1719 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1720 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1722 md_atof (type
, litP
, sizeP
)
1728 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1731 char * atof_ieee ();
1761 return _("Bad call to MD_NTOF()");
1764 t
= atof_ieee (input_line_pointer
, type
, words
);
1767 input_line_pointer
= t
;
1769 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1771 if (! target_big_endian
)
1773 for (i
= prec
- 1; i
>= 0; i
--)
1775 md_number_to_chars (litP
, (valueT
) words
[i
],
1776 sizeof (LITTLENUM_TYPE
));
1777 litP
+= sizeof (LITTLENUM_TYPE
);
1781 for (i
= 0; i
< prec
; i
++)
1783 md_number_to_chars (litP
, (valueT
) words
[i
],
1784 sizeof (LITTLENUM_TYPE
));
1785 litP
+= sizeof (LITTLENUM_TYPE
);
1791 const char * md_shortopts
= "";
1793 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1794 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1795 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1796 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1797 #define OPTION_CPU (OPTION_MD_BASE + 4)
1798 #define OPTION_EB (OPTION_MD_BASE + 5)
1799 #define OPTION_EL (OPTION_MD_BASE + 6)
1801 struct option md_longopts
[] =
1803 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1804 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1805 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1806 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1807 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1808 { "EB", no_argument
, NULL
, OPTION_EB
},
1809 { "EL", no_argument
, NULL
, OPTION_EL
},
1810 { NULL
, no_argument
, NULL
, 0}
1813 size_t md_longopts_size
= sizeof (md_longopts
);
1816 md_parse_option (c
, arg
)
1826 if (streq (arg
, "210"))
1829 target_big_endian
= 1;
1831 else if (streq (arg
, "340"))
1834 as_warn (_("unrecognised cpu type '%s'"), arg
);
1837 case OPTION_EB
: target_big_endian
= 1; break;
1838 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1839 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1840 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1841 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1842 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1850 md_show_usage (stream
)
1853 fprintf (stream
, _("\
1854 MCORE specific options:\n\
1855 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1856 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1857 -cpu=[210|340] select CPU type\n\
1858 -EB assemble for a big endian system (default)\n\
1859 -EL assemble for a little endian system\n"));
1862 int md_short_jump_size
;
1865 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1870 symbolS
* to_symbol
;
1872 as_fatal (_("failed sanity check: short_jump"));
1876 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1881 symbolS
* to_symbol
;
1883 as_fatal (_("failed sanity check: long_jump"));
1886 /* Called after relaxing, change the frags so they know how big they are. */
1888 md_convert_frag (abfd
, sec
, fragP
)
1891 register fragS
* fragP
;
1893 unsigned char * buffer
;
1894 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1896 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1898 switch (fragP
->fr_subtype
)
1900 case C (COND_JUMP
, DISP12
):
1901 case C (UNCD_JUMP
, DISP12
):
1903 /* Get the address of the end of the instruction. */
1904 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1906 int disp
= targ_addr
- next_inst
;
1909 as_bad (_("odd displacement at %x"), next_inst
- 2);
1913 if (! target_big_endian
)
1915 t0
= buffer
[1] & 0xF8;
1917 md_number_to_chars (buffer
, disp
, 2);
1919 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1923 t0
= buffer
[0] & 0xF8;
1925 md_number_to_chars (buffer
, disp
, 2);
1927 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1934 case C (COND_JUMP
, DISP32
):
1935 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1937 /* A conditional branch wont fit into 12 bits so:
1944 * if the b!cond is 4 byte aligned, the literal which would
1945 * go at x+4 will also be aligned.
1947 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1948 int needpad
= (first_inst
& 3);
1950 if (! target_big_endian
)
1953 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1955 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1956 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1960 if (! target_big_endian
)
1962 buffer
[0] = 4; /* branch over jmpi, pad, and ptr */
1963 buffer
[2] = 1; /* jmpi offset of 1 gets the pointer */
1967 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1968 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1971 buffer
[4] = 0; /* alignment/pad */
1973 buffer
[6] = 0; /* space for 32 bit address */
1978 /* Make reloc for the long disp */
1979 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1980 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1982 fragP
->fr_fix
+= C32_LEN
;
1986 /* See comment below about this given gas' limitations for
1987 shrinking the fragment. '3' is the amount of code that
1988 we inserted here, but '4' is right for the space we reserved
1989 for this fragment. */
1990 if (! target_big_endian
)
1992 buffer
[0] = 3; /* branch over jmpi, and ptr */
1993 buffer
[2] = 0; /* jmpi offset of 0 gets the pointer */
1997 buffer
[1] = 3; /* branch over jmpi, and ptr */
1998 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
2001 buffer
[4] = 0; /* space for 32 bit address */
2006 /* Make reloc for the long disp. */
2007 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
2008 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2009 fragP
->fr_fix
+= C32_LEN
;
2011 /* Frag is actually shorter (see the other side of this ifdef)
2012 but gas isn't prepared for that. We have to re-adjust
2013 the branch displacement so that it goes beyond the
2014 full length of the fragment, not just what we actually
2016 if (! target_big_endian
)
2017 buffer
[0] = 4; /* jmpi, ptr, and the 'tail pad' */
2019 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
2024 case C (UNCD_JUMP
, DISP32
):
2025 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2027 /* An unconditional branch will not fit in 12 bits, make code which
2032 we need a pad if "first_inst" is 4 byte aligned.
2033 [because the natural literal place is x + 2] */
2034 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
2035 int needpad
= !(first_inst
& 3);
2037 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
2038 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
2042 if (! target_big_endian
)
2043 buffer
[0] = 1; /* jmpi offset of 1 since padded */
2045 buffer
[1] = 1; /* jmpi offset of 1 since padded */
2046 buffer
[2] = 0; /* alignment */
2048 buffer
[4] = 0; /* space for 32 bit address */
2053 /* Make reloc for the long disp. */
2054 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
2055 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2057 fragP
->fr_fix
+= U32_LEN
;
2061 if (! target_big_endian
)
2062 buffer
[0] = 0; /* jmpi offset of 0 if no pad */
2064 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
2065 buffer
[2] = 0; /* space for 32 bit address */
2070 /* Make reloc for the long disp. */
2071 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
2072 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2073 fragP
->fr_fix
+= U32_LEN
;
2083 /* Applies the desired value to the specified location.
2084 Also sets up addends for 'rela' type relocations. */
2087 md_apply_fix3 (fixP
, valP
, segment
)
2092 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2093 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
2094 const char * symname
;
2095 /* Note: use offsetT because it is signed, valueT is unsigned. */
2096 offsetT val
= *valP
;
2098 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
2099 /* Save this for the addend in the relocation record. */
2100 fixP
->fx_addnumber
= val
;
2102 if (fixP
->fx_addsy
!= NULL
)
2105 /* For ELF we can just return and let the reloc that will be generated
2106 take care of everything. For COFF we still have to insert 'val'
2107 into the insn since the addend field will be ignored. */
2114 switch (fixP
->fx_r_type
)
2116 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
2118 as_bad_where (file
, fixP
->fx_line
,
2119 _("odd distance branch (0x%x bytes)"), val
);
2121 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2122 as_bad_where (file
, fixP
->fx_line
,
2123 _("pcrel for branch to %s too far (0x%x)"),
2125 if (target_big_endian
)
2127 buf
[0] |= ((val
>> 8) & 0x7);
2128 buf
[1] |= (val
& 0xff);
2132 buf
[1] |= ((val
>> 8) & 0x7);
2133 buf
[0] |= (val
& 0xff);
2137 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
2141 as_bad_where (file
, fixP
->fx_line
,
2142 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
2144 else if (! target_big_endian
)
2145 buf
[0] |= (val
& 0xff);
2147 buf
[1] |= (val
& 0xff);
2150 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
2151 if ((val
< -32) || (val
> -2))
2152 as_bad_where (file
, fixP
->fx_line
,
2153 _("pcrel for loopt too far (0x%x)"), val
);
2155 if (! target_big_endian
)
2156 buf
[0] |= (val
& 0xf);
2158 buf
[1] |= (val
& 0xf);
2161 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2162 /* Conditional linker map jsri to bsr. */
2163 /* If its a local target and close enough, fix it.
2164 NB: >= -2k for backwards bsr; < 2k for forwards... */
2165 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2167 long nval
= (val
/ 2) & 0x7ff;
2168 nval
|= MCORE_INST_BSR
;
2170 /* REPLACE the instruction, don't just modify it. */
2171 buf
[0] = INST_BYTE0 (nval
);
2172 buf
[1] = INST_BYTE1 (nval
);
2178 case BFD_RELOC_MCORE_PCREL_32
:
2179 case BFD_RELOC_VTABLE_INHERIT
:
2180 case BFD_RELOC_VTABLE_ENTRY
:
2185 if (fixP
->fx_addsy
!= NULL
)
2187 /* If the fix is an absolute reloc based on a symbol's
2188 address, then it cannot be resolved until the final link. */
2195 if (fixP
->fx_size
== 4)
2197 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2199 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2203 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2210 md_operand (expressionP
)
2211 expressionS
* expressionP
;
2213 /* Ignore leading hash symbol, if poresent. */
2214 if (* input_line_pointer
== '#')
2216 input_line_pointer
++;
2217 expression (expressionP
);
2221 int md_long_jump_size
;
2223 /* Called just before address relaxation, return the length
2224 by which a fragment must grow to reach it's destination. */
2226 md_estimate_size_before_relax (fragP
, segment_type
)
2227 register fragS
* fragP
;
2228 register segT segment_type
;
2230 switch (fragP
->fr_subtype
)
2235 case C (UNCD_JUMP
, UNDEF_DISP
):
2236 /* Used to be a branch to somewhere which was unknown. */
2237 if (!fragP
->fr_symbol
)
2239 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2241 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2243 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2247 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2251 case C (COND_JUMP
, UNDEF_DISP
):
2252 /* Used to be a branch to somewhere which was unknown. */
2253 if (fragP
->fr_symbol
2254 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2256 /* Got a symbol and it's defined in this segment, become byte
2257 sized - maybe it will fix up */
2258 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2260 else if (fragP
->fr_symbol
)
2262 /* Its got a segment, but its not ours, so it will always be long. */
2263 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2267 /* We know the abs value. */
2268 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2272 case C (UNCD_JUMP
, DISP12
):
2273 case C (UNCD_JUMP
, DISP32
):
2274 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2275 case C (COND_JUMP
, DISP12
):
2276 case C (COND_JUMP
, DISP32
):
2277 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2278 /* When relaxing a section for the second time, we don't need to
2279 do anything besides return the current size. */
2283 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2286 /* Put number into target byte order. */
2288 md_number_to_chars (ptr
, use
, nbytes
)
2293 if (! target_big_endian
)
2296 case 4: ptr
[3] = (use
>> 24) & 0xff; /* fall through */
2297 case 3: ptr
[2] = (use
>> 16) & 0xff; /* fall through */
2298 case 2: ptr
[1] = (use
>> 8) & 0xff; /* fall through */
2299 case 1: ptr
[0] = (use
>> 0) & 0xff; break;
2305 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2306 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2307 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2308 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2313 /* Round up a section size to the appropriate boundary. */
2315 md_section_align (segment
, size
)
2319 return size
; /* Byte alignment is fine */
2322 /* The location from which a PC relative jump should be calculated,
2323 given a PC relative reloc. */
2325 md_pcrel_from_section (fixp
, sec
)
2330 /* If the symbol is undefined or defined in another section
2331 we leave the add number alone for the linker to fix it later.
2332 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2333 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2334 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2335 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2338 assert (fixp
->fx_size
== 2); /* must be an insn */
2339 return fixp
->fx_size
;
2343 /* The case where we are going to resolve things... */
2344 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2347 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2348 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2351 tc_gen_reloc (section
, fixp
)
2356 bfd_reloc_code_real_type code
;
2359 switch (fixp
->fx_r_type
)
2361 /* These confuse the size/pcrel macro approach. */
2362 case BFD_RELOC_VTABLE_INHERIT
:
2363 case BFD_RELOC_VTABLE_ENTRY
:
2364 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2365 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2366 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2367 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2369 code
= fixp
->fx_r_type
;
2373 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2375 MAP (1, 0, BFD_RELOC_8
);
2376 MAP (2, 0, BFD_RELOC_16
);
2377 MAP (4, 0, BFD_RELOC_32
);
2378 MAP (1, 1, BFD_RELOC_8_PCREL
);
2379 MAP (2, 1, BFD_RELOC_16_PCREL
);
2380 MAP (4, 1, BFD_RELOC_32_PCREL
);
2382 code
= fixp
->fx_r_type
;
2383 as_bad (_("Can not do %d byte %srelocation"),
2385 fixp
->fx_pcrel
? _("pc-relative") : "");
2390 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2391 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2392 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2393 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2394 /* Always pass the addend along! */
2395 rel
->addend
= fixp
->fx_addnumber
;
2397 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2399 if (rel
->howto
== NULL
)
2401 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2402 _("Cannot represent relocation type %s"),
2403 bfd_get_reloc_code_name (code
));
2405 /* Set howto to a garbage value so that we can keep going. */
2406 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2407 assert (rel
->howto
!= NULL
);
2414 /* See whether we need to force a relocation into the output file.
2415 This is used to force out switch and PC relative relocations when
2418 mcore_force_relocation (fix
)
2421 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2422 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2423 || fix
->fx_r_type
== BFD_RELOC_RVA
)
2426 return S_FORCE_RELOC (fix
->fx_addsy
);
2429 /* Return true if the fix can be handled by GAS, false if it must
2430 be passed through to the linker. */
2432 mcore_fix_adjustable (fixP
)
2435 /* We need the symbol name for the VTABLE entries. */
2436 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2437 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2442 #endif /* OBJ_ELF */