1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright 1999, 2000, 2001, 2002, 2003, 2005
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "../opcodes/mcore-opc.h"
28 #include "safe-ctype.h"
32 #include "elf/mcore.h"
36 #define streq(a,b) (strcmp (a, b) == 0)
39 /* Forward declarations for dumb compilers. */
40 static void mcore_s_literals
PARAMS ((int));
41 static void mcore_pool_count
PARAMS ((void (*) (int), int));
42 static void mcore_cons
PARAMS ((int));
43 static void mcore_float_cons
PARAMS ((int));
44 static void mcore_stringer
PARAMS ((int));
45 static void mcore_fill
PARAMS ((int));
46 static int mylog2
PARAMS ((unsigned int));
47 static char * parse_reg
PARAMS ((char *, unsigned *));
48 static char * parse_creg
PARAMS ((char *, unsigned *));
49 static char * parse_exp
PARAMS ((char *, expressionS
*));
50 static char * parse_rt
PARAMS ((char *, char **, int, expressionS
*));
51 static char * parse_imm
PARAMS ((char *, unsigned *, unsigned, unsigned));
52 static char * parse_mem
PARAMS ((char *, unsigned *, unsigned *, unsigned));
53 static char * parse_psrmod
PARAMS ((char *, unsigned *));
54 static void make_name
PARAMS ((char *, char *, int));
55 static int enter_literal
PARAMS ((expressionS
*, int));
56 static void dump_literals
PARAMS ((int));
57 static void check_literals
PARAMS ((int, int));
58 static void mcore_s_text
PARAMS ((int));
59 static void mcore_s_data
PARAMS ((int));
60 static void mcore_s_section
PARAMS ((int));
61 static void mcore_s_bss
PARAMS ((int));
63 static void mcore_s_comm
PARAMS ((int));
66 /* Several places in this file insert raw instructions into the
67 object. They should use MCORE_INST_XXX macros to get the opcodes
68 and then use these two macros to crack the MCORE_INST value into
69 the appropriate byte values. */
70 #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
71 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF))
73 const char comment_chars
[] = "#/";
74 const char line_separator_chars
[] = ";";
75 const char line_comment_chars
[] = "#/";
77 const int md_reloc_size
= 8;
79 static int do_jsri2bsr
= 0; /* Change here from 1 by Cruess 19 August 97. */
80 static int sifilter_mode
= 0;
82 const char EXP_CHARS
[] = "eE";
84 /* Chars that mean this number is a floating point constant
87 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
89 #define C(what,length) (((what) << 2) + (length))
90 #define GET_WHAT(x) ((x >> 2))
92 /* These are the two types of relaxable instruction */
99 #define UNDEF_WORD_DISP 3
102 #define C32_LEN 10 /* allow for align */
104 #define U32_LEN 8 /* allow for align */
115 /* Initialize the relax table. */
116 const relax_typeS md_relax_table
[] = {
123 { 0, 0, 0, 0 }, /* UNDEF_DISP */
124 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* DISP12 */
125 { 0, 0, C32_LEN
, 0 }, /* DISP32 */
126 { 0, 0, C32_LEN
, 0 }, /* UNDEF_WORD_DISP */
129 { 0, 0, 0, 0 }, /* UNDEF_DISP */
130 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* DISP12 */
131 { 0, 0, U32_LEN
, 0 }, /* DISP32 */
132 { 0, 0, U32_LEN
, 0 } /* UNDEF_WORD_DISP */
136 /* Literal pool data structures. */
139 unsigned short refcnt
;
140 unsigned char ispcrel
;
141 unsigned char unused
;
145 #define MAX_POOL_SIZE (1024/4)
146 static struct literal litpool
[MAX_POOL_SIZE
];
147 static unsigned poolsize
;
148 static unsigned poolnumber
;
149 static unsigned long poolspan
;
151 /* SPANPANIC: the point at which we get too scared and force a dump
152 of the literal pool, and perhaps put a branch in place.
154 1024 span of lrw/jmpi/jsri insn (actually span+1)
155 -2 possible alignment at the insn.
156 -2 possible alignment to get the table aligned.
157 -2 an inserted branch around the table.
159 at 1018, we might be in trouble.
160 -- so we have to be smaller than 1018 and since we deal with 2-byte
161 instructions, the next good choice is 1016.
162 -- Note we have a test case that fails when we've got 1018 here. */
163 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
164 #define SPANCLOSE (900)
165 #define SPANEXIT (600)
166 static symbolS
* poolsym
; /* label for current pool. */
167 static char poolname
[8];
168 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
170 /* This table describes all the machine specific pseudo-ops the assembler
171 has to support. The fields are:
172 Pseudo-op name without dot
173 Function to call to execute this pseudo-op
174 Integer arg to pass to the function. */
175 const pseudo_typeS md_pseudo_table
[] =
177 { "export", s_globl
, 0 },
178 { "import", s_ignore
, 0 },
179 { "literals", mcore_s_literals
, 0 },
180 { "page", listing_eject
, 0 },
182 /* The following are to intercept the placement of data into the text
183 section (eg addresses for a switch table), so that the space they
184 occupy can be taken into account when deciding whether or not to
185 dump the current literal pool.
186 XXX - currently we do not cope with the .space and .dcb.d directives. */
187 { "ascii", mcore_stringer
, 0 },
188 { "asciz", mcore_stringer
, 1 },
189 { "byte", mcore_cons
, 1 },
190 { "dc", mcore_cons
, 2 },
191 { "dc.b", mcore_cons
, 1 },
192 { "dc.d", mcore_float_cons
, 'd'},
193 { "dc.l", mcore_cons
, 4 },
194 { "dc.s", mcore_float_cons
, 'f'},
195 { "dc.w", mcore_cons
, 2 },
196 { "dc.x", mcore_float_cons
, 'x'},
197 { "double", mcore_float_cons
, 'd'},
198 { "float", mcore_float_cons
, 'f'},
199 { "hword", mcore_cons
, 2 },
200 { "int", mcore_cons
, 4 },
201 { "long", mcore_cons
, 4 },
202 { "octa", mcore_cons
, 16 },
203 { "quad", mcore_cons
, 8 },
204 { "short", mcore_cons
, 2 },
205 { "single", mcore_float_cons
, 'f'},
206 { "string", mcore_stringer
, 1 },
207 { "word", mcore_cons
, 2 },
208 { "fill", mcore_fill
, 0 },
210 /* Allow for the effect of section changes. */
211 { "text", mcore_s_text
, 0 },
212 { "data", mcore_s_data
, 0 },
213 { "bss", mcore_s_bss
, 1 },
215 { "comm", mcore_s_comm
, 0 },
217 { "section", mcore_s_section
, 0 },
218 { "section.s", mcore_s_section
, 0 },
219 { "sect", mcore_s_section
, 0 },
220 { "sect.s", mcore_s_section
, 0 },
226 mcore_s_literals (ignore
)
227 int ignore ATTRIBUTE_UNUSED
;
230 demand_empty_rest_of_line ();
233 /* Perform FUNC (ARG), and track number of bytes added to frag. */
236 mcore_pool_count (func
, arg
)
237 void (*func
) PARAMS ((int));
240 const fragS
*curr_frag
= frag_now
;
241 offsetT added
= -frag_now_fix_octets ();
245 while (curr_frag
!= frag_now
)
247 added
+= curr_frag
->fr_fix
;
248 curr_frag
= curr_frag
->fr_next
;
251 added
+= frag_now_fix_octets ();
259 if (now_seg
== text_section
)
260 mcore_pool_count (cons
, nbytes
);
264 /* In theory we ought to call check_literals (2,0) here in case
265 we need to dump the literal table. We cannot do this however,
266 as the directives that we are intercepting may be being used
267 to build a switch table, and we must not interfere with its
268 contents. Instead we cross our fingers and pray... */
272 mcore_float_cons (float_type
)
275 if (now_seg
== text_section
)
276 mcore_pool_count (float_cons
, float_type
);
278 float_cons (float_type
);
280 /* See the comment in mcore_cons () about calling check_literals.
281 It is unlikely that a switch table will be constructed using
282 floating point values, but it is still likely that an indexed
283 table of floating point constants is being created by these
284 directives, so again we must not interfere with their placement. */
288 mcore_stringer (append_zero
)
291 if (now_seg
== text_section
)
292 mcore_pool_count (stringer
, append_zero
);
294 stringer (append_zero
);
296 /* We call check_literals here in case a large number of strings are
297 being placed into the text section with a sequence of stringer
298 directives. In theory we could be upsetting something if these
299 strings are actually in an indexed table instead of referenced by
300 individual labels. Let us hope that that never happens. */
301 check_literals (2, 0);
308 if (now_seg
== text_section
)
309 mcore_pool_count (s_fill
, unused
);
313 check_literals (2, 0);
316 /* Handle the section changing pseudo-ops. These call through to the
317 normal implementations, but they dump the literal pool first. */
319 mcore_s_text (ignore
)
325 obj_elf_text (ignore
);
332 mcore_s_data (ignore
)
338 obj_elf_data (ignore
);
345 mcore_s_section (ignore
)
348 /* Scan forwards to find the name of the section. If the section
349 being switched to is ".line" then this is a DWARF1 debug section
350 which is arbitrarily placed inside generated code. In this case
351 do not dump the literal pool because it is a) inefficient and
352 b) would require the generation of extra code to jump around the
354 char * ilp
= input_line_pointer
;
356 while (*ilp
!= 0 && ISSPACE (*ilp
))
359 if (strncmp (ilp
, ".line", 5) == 0
360 && (ISSPACE (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
366 obj_elf_section (ignore
);
369 obj_coff_section (ignore
);
374 mcore_s_bss (needs_align
)
379 s_lcomm_bytes (needs_align
);
384 mcore_s_comm (needs_align
)
389 obj_elf_common (needs_align
);
393 /* This function is called once, at assembler startup time. This should
394 set up all the tables, etc that the MD part of the assembler needs. */
398 const mcore_opcode_info
* opcode
;
399 char * prev_name
= "";
401 opcode_hash_control
= hash_new ();
403 /* Insert unique names into hash table */
404 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
406 if (! streq (prev_name
, opcode
->name
))
408 prev_name
= opcode
->name
;
409 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
414 /* Get a log2(val). */
429 /* Try to parse a reg name. */
435 /* Strip leading whitespace. */
436 while (ISSPACE (* s
))
439 if (TOLOWER (s
[0]) == 'r')
441 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
443 *reg
= 10 + s
[2] - '0';
447 if (s
[1] >= '0' && s
[1] <= '9')
453 else if ( TOLOWER (s
[0]) == 's'
454 && TOLOWER (s
[1]) == 'p'
461 as_bad (_("register expected, but saw '%.6s'"), s
);
495 /* Strip leading whitespace. */
496 while (ISSPACE (* s
))
499 if ((TOLOWER (s
[0]) == 'c' && TOLOWER (s
[1]) == 'r'))
501 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
503 *reg
= 30 + s
[3] - '0';
507 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
509 *reg
= 20 + s
[3] - '0';
513 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
515 *reg
= 10 + s
[3] - '0';
519 if (s
[2] >= '0' && s
[2] <= '9')
526 /* Look at alternate creg names before giving error. */
527 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
533 length
= strlen (cregs
[i
].name
);
535 for (j
= 0; j
< length
; j
++)
536 buf
[j
] = TOLOWER (s
[j
]);
538 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
540 *reg
= cregs
[i
].crnum
;
545 as_bad (_("control register expected, but saw '%.6s'"), s
);
551 parse_psrmod (s
, reg
)
557 static struct psrmods
567 { "af", 8 } /* Really 0 and non-combinable. */
570 for (i
= 0; i
< 2; i
++)
571 buf
[i
] = TOLOWER (s
[i
]);
573 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
575 if (! strncmp (psrmods
[i
].name
, buf
, 2))
577 * reg
= psrmods
[i
].value
;
583 as_bad (_("bad/missing psr specifier"));
598 /* Skip whitespace. */
599 while (ISSPACE (* s
))
602 save
= input_line_pointer
;
603 input_line_pointer
= s
;
607 if (e
->X_op
== O_absent
)
608 as_bad (_("missing operand"));
610 new = input_line_pointer
;
611 input_line_pointer
= save
;
622 static const char hex
[] = "0123456789ABCDEF";
627 s
[3] = hex
[(n
>> 12) & 0xF];
628 s
[4] = hex
[(n
>> 8) & 0xF];
629 s
[5] = hex
[(n
>> 4) & 0xF];
630 s
[6] = hex
[(n
) & 0xF];
634 #define POOL_END_LABEL ".LE"
635 #define POOL_START_LABEL ".LS"
638 dump_literals (isforce
)
643 symbolS
* brarsym
= NULL
;
648 /* Must we branch around the literal table? */
654 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
656 brarsym
= symbol_make (brarname
);
658 symbol_table_insert (brarsym
);
660 output
= frag_var (rs_machine_dependent
,
661 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
662 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
663 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
664 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
665 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
668 /* Make sure that the section is sufficiently aligned and that
669 the literal table is aligned within it. */
670 record_alignment (now_seg
, 2);
671 frag_align (2, 0, 0);
673 colon (S_GET_NAME (poolsym
));
675 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
676 emit_expr (& p
->e
, 4);
679 colon (S_GET_NAME (brarsym
));
685 check_literals (kind
, offset
)
691 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
692 SPANPANIC means that we must dump now.
693 kind == 0 is any old instruction.
694 kind > 0 means we just had a control transfer instruction.
695 kind == 1 means within a function
696 kind == 2 means we just left a function
698 The dump_literals (1) call inserts a branch around the table, so
699 we first look to see if its a situation where we won't have to
700 insert a branch (e.g., the previous instruction was an unconditional
703 SPANPANIC is the point where we must dump a single-entry pool.
704 it accounts for alignments and an inserted branch.
705 the 'poolsize*2' accounts for the scenario where we do:
706 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
707 Note that the 'lit2' reference is 2 bytes further along
708 but the literal it references will be 4 bytes further along,
709 so we must consider the poolsize into this equation.
710 This is slightly over-cautious, but guarantees that we won't
711 panic because a relocation is too distant. */
713 if (poolspan
> SPANCLOSE
&& kind
> 0)
715 else if (poolspan
> SPANEXIT
&& kind
> 1)
717 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
722 enter_literal (e
, ispcrel
)
729 if (poolsize
>= MAX_POOL_SIZE
- 2)
731 /* The literal pool is as full as we can handle. We have
732 to be 2 entries shy of the 1024/4=256 entries because we
733 have to allow for the branch (2 bytes) and the alignment
734 (2 bytes before the first insn referencing the pool and
735 2 bytes before the pool itself) == 6 bytes, rounds up
742 /* Create new literal pool. */
743 if (++ poolnumber
> 0xFFFF)
744 as_fatal (_("more than 65K literal pools"));
746 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
747 poolsym
= symbol_make (poolname
);
748 symbol_table_insert (poolsym
);
752 /* Search pool for value so we don't have duplicates. */
753 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
755 if (e
->X_op
== p
->e
.X_op
756 && e
->X_add_symbol
== p
->e
.X_add_symbol
757 && e
->X_add_number
== p
->e
.X_add_number
758 && ispcrel
== p
->ispcrel
)
766 p
->ispcrel
= ispcrel
;
774 /* Parse a literal specification. -- either new or old syntax.
775 old syntax: the user supplies the label and places the literal.
776 new syntax: we put it into the literal pool. */
778 parse_rt (s
, outputp
, ispcrel
, ep
)
788 /* Indicate nothing there. */
793 s
= parse_exp (s
+ 1, & e
);
798 as_bad (_("missing ']'"));
802 s
= parse_exp (s
, & e
);
804 n
= enter_literal (& e
, ispcrel
);
809 /* Create a reference to pool entry. */
811 e
.X_add_symbol
= poolsym
;
812 e
.X_add_number
= n
<< 2;
815 * outputp
= frag_more (2);
817 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
818 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
824 parse_imm (s
, val
, min
, max
)
833 new = parse_exp (s
, & e
);
835 if (e
.X_op
== O_absent
)
836 ; /* An error message has already been emitted. */
837 else if (e
.X_op
!= O_constant
)
838 as_bad (_("operand must be a constant"));
839 else if ((addressT
) e
.X_add_number
< min
|| (addressT
) e
.X_add_number
> max
)
840 as_bad (_("operand must be absolute in range %u..%u, not %ld"),
841 min
, max
, (long) e
.X_add_number
);
843 * val
= e
.X_add_number
;
849 parse_mem (s
, reg
, off
, siz
)
857 while (ISSPACE (* s
))
862 s
= parse_reg (s
+ 1, reg
);
864 while (ISSPACE (* s
))
869 s
= parse_imm (s
+ 1, off
, 0, 63);
876 as_bad (_("operand must be a multiple of 4"));
883 as_bad (_("operand must be a multiple of 2"));
890 while (ISSPACE (* s
))
897 as_bad (_("base register expected"));
902 /* This is the guts of the machine-dependent assembler. STR points to a
903 machine dependent instruction. This function is supposed to emit
904 the frags/bytes it assembles to. */
912 mcore_opcode_info
* opcode
;
922 /* Drop leading whitespace. */
923 while (ISSPACE (* str
))
926 /* Find the op code end. */
927 for (op_start
= op_end
= str
;
928 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
931 name
[nlen
] = op_start
[nlen
];
939 as_bad (_("can't find opcode "));
943 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
946 as_bad (_("unknown opcode \"%s\""), name
);
953 switch (opcode
->opclass
)
956 output
= frag_more (2);
960 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
962 output
= frag_more (2);
966 op_end
= parse_reg (op_end
+ 1, & reg
);
968 output
= frag_more (2);
972 op_end
= parse_reg (op_end
+ 1, & reg
);
974 output
= frag_more (2);
975 /* In a sifilter mode, we emit this insn 2 times,
976 fixes problem of an interrupt during a jmp.. */
979 output
[0] = INST_BYTE0 (inst
);
980 output
[1] = INST_BYTE1 (inst
);
981 output
= frag_more (2);
986 op_end
= parse_reg (op_end
+ 1, & reg
);
989 as_bad (_("invalid register: r15 illegal"));
992 output
= frag_more (2);
996 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
997 inst
= MCORE_INST_BSR
; /* with 0 displacement */
998 output
[0] = INST_BYTE0 (inst
);
999 output
[1] = INST_BYTE1 (inst
);
1001 output
= frag_more (2);
1002 inst
= MCORE_INST_ADDI
;
1003 inst
|= 15; /* addi r15,6 */
1004 inst
|= (6 - 1) << 4; /* over the jmp's */
1005 output
[0] = INST_BYTE0 (inst
);
1006 output
[1] = INST_BYTE1 (inst
);
1008 output
= frag_more (2);
1009 inst
= MCORE_INST_JMP
| reg
;
1010 output
[0] = INST_BYTE0 (inst
);
1011 output
[1] = INST_BYTE1 (inst
);
1013 output
= frag_more (2); /* 2nd emitted in fallthru */
1018 op_end
= parse_reg (op_end
+ 1, & reg
);
1021 /* Skip whitespace. */
1022 while (ISSPACE (* op_end
))
1027 op_end
= parse_creg (op_end
+ 1, & reg
);
1031 output
= frag_more (2);
1037 as_bad (_("M340 specific opcode used when assembling for M210"));
1040 /* drop through... */
1042 op_end
= parse_reg (op_end
+ 1, & reg
);
1045 /* Skip whitespace. */
1046 while (ISSPACE (* op_end
))
1049 if (* op_end
== ',')
1051 op_end
= parse_reg (op_end
+ 1, & reg
);
1055 as_bad (_("second operand missing"));
1057 output
= frag_more (2);
1060 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1061 op_end
= parse_reg (op_end
+ 1, & reg
);
1063 /* Skip whitespace. */
1064 while (ISSPACE (* op_end
))
1067 if (* op_end
== ',') /* xtrb- r1,rx */
1070 as_bad (_("destination register must be r1"));
1072 op_end
= parse_reg (op_end
+ 1, & reg
);
1076 output
= frag_more (2);
1079 case O1R1
: /* div- rx,r1 */
1080 op_end
= parse_reg (op_end
+ 1, & reg
);
1083 /* Skip whitespace. */
1084 while (ISSPACE (* op_end
))
1087 if (* op_end
== ',')
1089 op_end
= parse_reg (op_end
+ 1, & reg
);
1091 as_bad (_("source register must be r1"));
1094 as_bad (_("second operand missing"));
1096 output
= frag_more (2);
1100 op_end
= parse_reg (op_end
+ 1, & reg
);
1103 /* Skip whitespace. */
1104 while (ISSPACE (* op_end
))
1107 if (* op_end
== ',')
1109 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1110 inst
|= (reg
- 1) << 4;
1113 as_bad (_("second operand missing"));
1115 output
= frag_more (2);
1119 op_end
= parse_reg (op_end
+ 1, & reg
);
1122 /* Skip whitespace. */
1123 while (ISSPACE (* op_end
))
1126 if (* op_end
== ',')
1128 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1132 as_bad (_("second operand missing"));
1134 output
= frag_more (2);
1137 case OB2
: /* like OB, but arg is 2^n instead of n */
1138 op_end
= parse_reg (op_end
+ 1, & reg
);
1141 /* Skip whitespace. */
1142 while (ISSPACE (* op_end
))
1145 if (* op_end
== ',')
1147 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1148 /* Further restrict the immediate to a power of two. */
1149 if ((reg
& (reg
- 1)) == 0)
1154 as_bad (_("immediate is not a power of two"));
1159 as_bad (_("second operand missing"));
1161 output
= frag_more (2);
1164 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1167 op_end
= parse_reg (op_end
+ 1, & reg
);
1170 /* Skip whitespace. */
1171 while (ISSPACE (* op_end
))
1174 if (* op_end
== ',')
1176 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1177 /* immediate values of 0 -> 6 translate to movi */
1180 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1182 as_warn (_("translating bgeni to movi"));
1188 as_bad (_("second operand missing"));
1190 output
= frag_more (2);
1193 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1194 op_end
= parse_reg (op_end
+ 1, & reg
);
1197 /* Skip whitespace. */
1198 while (ISSPACE (* op_end
))
1201 if (* op_end
== ',')
1203 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1205 /* Further restrict the immediate to a power of two. */
1206 if ((reg
& (reg
- 1)) == 0)
1211 as_bad (_("immediate is not a power of two"));
1214 /* Immediate values of 0 -> 6 translate to movi. */
1217 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1219 as_warn (_("translating mgeni to movi"));
1225 as_bad (_("second operand missing"));
1227 output
= frag_more (2);
1230 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1233 op_end
= parse_reg (op_end
+ 1, & reg
);
1236 /* Skip whitespace. */
1237 while (ISSPACE (* op_end
))
1240 if (* op_end
== ',')
1242 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1244 /* Immediate values of 1 -> 7 translate to movi. */
1247 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1248 reg
= (0x1 << reg
) - 1;
1251 as_warn (_("translating bmaski to movi"));
1256 inst
|= (reg
& 0x1F) << 4;
1260 as_bad (_("second operand missing"));
1262 output
= frag_more (2);
1266 op_end
= parse_reg (op_end
+ 1, & reg
);
1269 /* Skip whitespace. */
1270 while (ISSPACE (* op_end
))
1273 if (* op_end
== ',')
1275 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1279 as_bad (_("second operand missing"));
1281 output
= frag_more (2);
1285 op_end
= parse_reg (op_end
+ 1, & reg
);
1288 /* Skip whitespace. */
1289 while (ISSPACE (* op_end
))
1292 if (* op_end
== ',')
1294 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1298 as_bad (_("second operand missing"));
1300 output
= frag_more (2);
1304 op_end
= parse_reg (op_end
+ 1, & reg
);
1307 /* Skip whitespace. */
1308 while (ISSPACE (* op_end
))
1311 if (* op_end
== ',')
1315 if ((inst
& 0x6000) == 0)
1317 else if ((inst
& 0x6000) == 0x4000)
1319 else if ((inst
& 0x6000) == 0x2000)
1324 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1327 as_bad (_("displacement too large (%d)"), off
);
1329 inst
|= (reg
) | (off
<< 4);
1332 as_bad (_("second operand missing"));
1334 output
= frag_more (2);
1338 op_end
= parse_reg (op_end
+ 1, & reg
);
1340 if (reg
== 0 || reg
== 15)
1341 as_bad (_("Invalid register: r0 and r15 illegal"));
1345 /* Skip whitespace. */
1346 while (ISSPACE (* op_end
))
1349 if (* op_end
== ',')
1351 /* parse_rt calls frag_more() for us. */
1352 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1353 op_end
= input_line_pointer
;
1357 as_bad (_("second operand missing"));
1358 output
= frag_more (2); /* save its space */
1363 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1364 /* parse_rt() calls frag_more() for us. */
1365 op_end
= input_line_pointer
;
1369 op_end
= parse_reg (op_end
+ 1, & reg
);
1371 if (reg
== 0 || reg
== 15)
1372 as_bad (_("bad starting register: r0 and r15 invalid"));
1376 /* Skip whitespace. */
1377 while (ISSPACE (* op_end
))
1380 if (* op_end
== '-')
1382 op_end
= parse_reg (op_end
+ 1, & reg
);
1385 as_bad (_("ending register must be r15"));
1387 /* Skip whitespace. */
1388 while (ISSPACE (* op_end
))
1392 if (* op_end
== ',')
1396 /* Skip whitespace. */
1397 while (ISSPACE (* op_end
))
1400 if (* op_end
== '(')
1402 op_end
= parse_reg (op_end
+ 1, & reg
);
1405 as_bad (_("bad base register: must be r0"));
1407 if (* op_end
== ')')
1411 as_bad (_("base register expected"));
1414 as_bad (_("second operand missing"));
1416 output
= frag_more (2);
1420 op_end
= parse_reg (op_end
+ 1, & reg
);
1423 as_fatal (_("first register must be r4"));
1425 /* Skip whitespace. */
1426 while (ISSPACE (* op_end
))
1429 if (* op_end
== '-')
1431 op_end
= parse_reg (op_end
+ 1, & reg
);
1434 as_fatal (_("last register must be r7"));
1436 /* Skip whitespace. */
1437 while (ISSPACE (* op_end
))
1440 if (* op_end
== ',')
1444 /* Skip whitespace. */
1445 while (ISSPACE (* op_end
))
1448 if (* op_end
== '(')
1450 op_end
= parse_reg (op_end
+ 1, & reg
);
1452 if (reg
>= 4 && reg
<= 7)
1453 as_fatal ("base register cannot be r4, r5, r6, or r7");
1457 /* Skip whitespace. */
1458 while (ISSPACE (* op_end
))
1461 if (* op_end
== ')')
1465 as_bad (_("base register expected"));
1468 as_bad (_("second operand missing"));
1471 as_bad (_("reg-reg expected"));
1473 output
= frag_more (2);
1477 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1478 op_end
= input_line_pointer
;
1480 output
= frag_more (2);
1482 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1483 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1487 op_end
= parse_reg (op_end
+ 1, & reg
);
1490 /* Skip whitespace. */
1491 while (ISSPACE (* op_end
))
1494 if (* op_end
== ',')
1496 op_end
= parse_exp (op_end
+ 1, & e
);
1497 output
= frag_more (2);
1499 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1500 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1504 as_bad (_("second operand missing"));
1505 output
= frag_more (2);
1510 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1511 op_end
= input_line_pointer
;
1513 output
= frag_var (rs_machine_dependent
,
1514 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1515 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1516 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1521 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1522 op_end
= input_line_pointer
;
1524 output
= frag_var (rs_machine_dependent
,
1525 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1526 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1527 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1532 inst
= MCORE_INST_JSRI
; /* jsri */
1533 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1534 /* parse_rt() calls frag_more for us. */
1535 op_end
= input_line_pointer
;
1537 /* Only do this if we know how to do it ... */
1538 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1540 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1541 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1542 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1546 case RSI
: /* SI, but imm becomes 32-imm */
1547 op_end
= parse_reg (op_end
+ 1, & reg
);
1550 /* Skip whitespace. */
1551 while (ISSPACE (* op_end
))
1554 if (* op_end
== ',')
1556 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1562 as_bad (_("second operand missing"));
1564 output
= frag_more (2);
1567 case DO21
: /* O2, dup rd, lit must be 1 */
1568 op_end
= parse_reg (op_end
+ 1, & reg
);
1572 /* Skip whitespace. */
1573 while (ISSPACE (* op_end
))
1576 if (* op_end
== ',')
1578 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1581 as_bad (_("second operand must be 1"));
1584 as_bad (_("second operand missing"));
1586 output
= frag_more (2);
1590 op_end
= parse_reg (op_end
+ 1, & reg
);
1593 /* Skip whitespace. */
1594 while (ISSPACE (* op_end
))
1597 if (* op_end
== ',')
1599 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1602 as_bad (_("zero used as immediate value"));
1607 as_bad (_("second operand missing"));
1609 output
= frag_more (2);
1615 as_bad (_("M340 specific opcode used when assembling for M210"));
1619 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1621 /* Look for further selectors. */
1622 while (* op_end
== ',')
1626 op_end
= parse_psrmod (op_end
+ 1, & value
);
1629 as_bad (_("duplicated psr bit specifier"));
1635 as_bad (_("`af' must appear alone"));
1637 inst
|= (reg
& 0x7);
1638 output
= frag_more (2);
1642 as_bad (_("unimplemented opcode \"%s\""), name
);
1645 /* Drop whitespace after all the operands have been parsed. */
1646 while (ISSPACE (* op_end
))
1649 /* Give warning message if the insn has more operands than required. */
1650 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1651 as_warn (_("ignoring operands: %s "), op_end
);
1653 output
[0] = INST_BYTE0 (inst
);
1654 output
[1] = INST_BYTE1 (inst
);
1656 check_literals (opcode
->transfer
, isize
);
1660 md_undefined_symbol (name
)
1661 char *name ATTRIBUTE_UNUSED
;
1670 subseg_set (text_section
, 0);
1673 /* Various routines to kill one day. */
1674 /* Equal to MAX_PRECISION in atof-ieee.c */
1675 #define MAX_LITTLENUMS 6
1677 /* Turn a string in input_line_pointer into a floating point constant of type
1678 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1679 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1681 md_atof (type
, litP
, sizeP
)
1687 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1719 return _("Bad call to MD_NTOF()");
1722 t
= atof_ieee (input_line_pointer
, type
, words
);
1725 input_line_pointer
= t
;
1727 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1729 if (! target_big_endian
)
1731 for (i
= prec
- 1; i
>= 0; i
--)
1733 md_number_to_chars (litP
, (valueT
) words
[i
],
1734 sizeof (LITTLENUM_TYPE
));
1735 litP
+= sizeof (LITTLENUM_TYPE
);
1739 for (i
= 0; i
< prec
; i
++)
1741 md_number_to_chars (litP
, (valueT
) words
[i
],
1742 sizeof (LITTLENUM_TYPE
));
1743 litP
+= sizeof (LITTLENUM_TYPE
);
1749 const char * md_shortopts
= "";
1751 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1752 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1753 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1754 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1755 #define OPTION_CPU (OPTION_MD_BASE + 4)
1756 #define OPTION_EB (OPTION_MD_BASE + 5)
1757 #define OPTION_EL (OPTION_MD_BASE + 6)
1759 struct option md_longopts
[] =
1761 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1762 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1763 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1764 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1765 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1766 { "EB", no_argument
, NULL
, OPTION_EB
},
1767 { "EL", no_argument
, NULL
, OPTION_EL
},
1768 { NULL
, no_argument
, NULL
, 0}
1771 size_t md_longopts_size
= sizeof (md_longopts
);
1774 md_parse_option (c
, arg
)
1781 if (streq (arg
, "210"))
1784 target_big_endian
= 1;
1786 else if (streq (arg
, "340"))
1789 as_warn (_("unrecognised cpu type '%s'"), arg
);
1792 case OPTION_EB
: target_big_endian
= 1; break;
1793 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1794 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1795 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1796 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1797 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1805 md_show_usage (stream
)
1808 fprintf (stream
, _("\
1809 MCORE specific options:\n\
1810 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1811 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1812 -cpu=[210|340] select CPU type\n\
1813 -EB assemble for a big endian system (default)\n\
1814 -EL assemble for a little endian system\n"));
1817 int md_short_jump_size
;
1820 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1821 char * ptr ATTRIBUTE_UNUSED
;
1822 addressT from_Nddr ATTRIBUTE_UNUSED
;
1823 addressT to_Nddr ATTRIBUTE_UNUSED
;
1824 fragS
* frag ATTRIBUTE_UNUSED
;
1825 symbolS
* to_symbol ATTRIBUTE_UNUSED
;
1827 as_fatal (_("failed sanity check: short_jump"));
1831 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1832 char * ptr ATTRIBUTE_UNUSED
;
1833 addressT from_Nddr ATTRIBUTE_UNUSED
;
1834 addressT to_Nddr ATTRIBUTE_UNUSED
;
1835 fragS
* frag ATTRIBUTE_UNUSED
;
1836 symbolS
* to_symbol ATTRIBUTE_UNUSED
;
1838 as_fatal (_("failed sanity check: long_jump"));
1841 /* Called after relaxing, change the frags so they know how big they are. */
1843 md_convert_frag (abfd
, sec
, fragP
)
1844 bfd
* abfd ATTRIBUTE_UNUSED
;
1845 segT sec ATTRIBUTE_UNUSED
;
1846 register fragS
* fragP
;
1848 unsigned char * buffer
;
1849 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1851 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1853 switch (fragP
->fr_subtype
)
1855 case C (COND_JUMP
, DISP12
):
1856 case C (UNCD_JUMP
, DISP12
):
1858 /* Get the address of the end of the instruction. */
1859 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1861 int disp
= targ_addr
- next_inst
;
1864 as_bad (_("odd displacement at %x"), next_inst
- 2);
1868 if (! target_big_endian
)
1870 t0
= buffer
[1] & 0xF8;
1872 md_number_to_chars (buffer
, disp
, 2);
1874 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1878 t0
= buffer
[0] & 0xF8;
1880 md_number_to_chars (buffer
, disp
, 2);
1882 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1889 case C (COND_JUMP
, DISP32
):
1890 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1892 /* A conditional branch wont fit into 12 bits so:
1899 * if the b!cond is 4 byte aligned, the literal which would
1900 * go at x+4 will also be aligned.
1902 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1903 int needpad
= (first_inst
& 3);
1905 if (! target_big_endian
)
1908 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1910 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1911 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1915 if (! target_big_endian
)
1917 buffer
[0] = 4; /* branch over jmpi, pad, and ptr */
1918 buffer
[2] = 1; /* jmpi offset of 1 gets the pointer */
1922 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1923 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1926 buffer
[4] = 0; /* alignment/pad */
1928 buffer
[6] = 0; /* space for 32 bit address */
1933 /* Make reloc for the long disp */
1934 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1935 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1937 fragP
->fr_fix
+= C32_LEN
;
1941 /* See comment below about this given gas' limitations for
1942 shrinking the fragment. '3' is the amount of code that
1943 we inserted here, but '4' is right for the space we reserved
1944 for this fragment. */
1945 if (! target_big_endian
)
1947 buffer
[0] = 3; /* branch over jmpi, and ptr */
1948 buffer
[2] = 0; /* jmpi offset of 0 gets the pointer */
1952 buffer
[1] = 3; /* branch over jmpi, and ptr */
1953 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1956 buffer
[4] = 0; /* space for 32 bit address */
1961 /* Make reloc for the long disp. */
1962 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1963 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1964 fragP
->fr_fix
+= C32_LEN
;
1966 /* Frag is actually shorter (see the other side of this ifdef)
1967 but gas isn't prepared for that. We have to re-adjust
1968 the branch displacement so that it goes beyond the
1969 full length of the fragment, not just what we actually
1971 if (! target_big_endian
)
1972 buffer
[0] = 4; /* jmpi, ptr, and the 'tail pad' */
1974 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1979 case C (UNCD_JUMP
, DISP32
):
1980 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1982 /* An unconditional branch will not fit in 12 bits, make code which
1987 we need a pad if "first_inst" is 4 byte aligned.
1988 [because the natural literal place is x + 2] */
1989 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1990 int needpad
= !(first_inst
& 3);
1992 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1993 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1997 if (! target_big_endian
)
1998 buffer
[0] = 1; /* jmpi offset of 1 since padded */
2000 buffer
[1] = 1; /* jmpi offset of 1 since padded */
2001 buffer
[2] = 0; /* alignment */
2003 buffer
[4] = 0; /* space for 32 bit address */
2008 /* Make reloc for the long disp. */
2009 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
2010 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2012 fragP
->fr_fix
+= U32_LEN
;
2016 if (! target_big_endian
)
2017 buffer
[0] = 0; /* jmpi offset of 0 if no pad */
2019 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
2020 buffer
[2] = 0; /* space for 32 bit address */
2025 /* Make reloc for the long disp. */
2026 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
2027 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2028 fragP
->fr_fix
+= U32_LEN
;
2038 /* Applies the desired value to the specified location.
2039 Also sets up addends for 'rela' type relocations. */
2042 md_apply_fix3 (fixP
, valP
, segment
)
2045 segT segment ATTRIBUTE_UNUSED
;
2047 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2048 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
2049 const char * symname
;
2050 /* Note: use offsetT because it is signed, valueT is unsigned. */
2051 offsetT val
= *valP
;
2053 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
2054 /* Save this for the addend in the relocation record. */
2055 fixP
->fx_addnumber
= val
;
2057 if (fixP
->fx_addsy
!= NULL
)
2060 /* For ELF we can just return and let the reloc that will be generated
2061 take care of everything. For COFF we still have to insert 'val'
2062 into the insn since the addend field will be ignored. */
2069 switch (fixP
->fx_r_type
)
2071 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
2073 as_bad_where (file
, fixP
->fx_line
,
2074 _("odd distance branch (0x%lx bytes)"), (long) val
);
2076 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2077 as_bad_where (file
, fixP
->fx_line
,
2078 _("pcrel for branch to %s too far (0x%lx)"),
2079 symname
, (long) val
);
2080 if (target_big_endian
)
2082 buf
[0] |= ((val
>> 8) & 0x7);
2083 buf
[1] |= (val
& 0xff);
2087 buf
[1] |= ((val
>> 8) & 0x7);
2088 buf
[0] |= (val
& 0xff);
2092 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
2096 as_bad_where (file
, fixP
->fx_line
,
2097 _("pcrel for lrw/jmpi/jsri to %s too far (0x%lx)"),
2098 symname
, (long) val
);
2099 else if (! target_big_endian
)
2100 buf
[0] |= (val
& 0xff);
2102 buf
[1] |= (val
& 0xff);
2105 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
2106 if ((val
< -32) || (val
> -2))
2107 as_bad_where (file
, fixP
->fx_line
,
2108 _("pcrel for loopt too far (0x%lx)"), (long) val
);
2110 if (! target_big_endian
)
2111 buf
[0] |= (val
& 0xf);
2113 buf
[1] |= (val
& 0xf);
2116 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2117 /* Conditional linker map jsri to bsr. */
2118 /* If its a local target and close enough, fix it.
2119 NB: >= -2k for backwards bsr; < 2k for forwards... */
2120 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2122 long nval
= (val
/ 2) & 0x7ff;
2123 nval
|= MCORE_INST_BSR
;
2125 /* REPLACE the instruction, don't just modify it. */
2126 buf
[0] = INST_BYTE0 (nval
);
2127 buf
[1] = INST_BYTE1 (nval
);
2133 case BFD_RELOC_MCORE_PCREL_32
:
2134 case BFD_RELOC_VTABLE_INHERIT
:
2135 case BFD_RELOC_VTABLE_ENTRY
:
2140 if (fixP
->fx_addsy
!= NULL
)
2142 /* If the fix is an absolute reloc based on a symbol's
2143 address, then it cannot be resolved until the final link. */
2150 if (fixP
->fx_size
== 4)
2152 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2154 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2158 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2165 md_operand (expressionP
)
2166 expressionS
* expressionP
;
2168 /* Ignore leading hash symbol, if poresent. */
2169 if (* input_line_pointer
== '#')
2171 input_line_pointer
++;
2172 expression (expressionP
);
2176 int md_long_jump_size
;
2178 /* Called just before address relaxation, return the length
2179 by which a fragment must grow to reach it's destination. */
2181 md_estimate_size_before_relax (fragP
, segment_type
)
2182 register fragS
* fragP
;
2183 register segT segment_type
;
2185 switch (fragP
->fr_subtype
)
2190 case C (UNCD_JUMP
, UNDEF_DISP
):
2191 /* Used to be a branch to somewhere which was unknown. */
2192 if (!fragP
->fr_symbol
)
2194 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2196 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2198 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2202 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2206 case C (COND_JUMP
, UNDEF_DISP
):
2207 /* Used to be a branch to somewhere which was unknown. */
2208 if (fragP
->fr_symbol
2209 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2211 /* Got a symbol and it's defined in this segment, become byte
2212 sized - maybe it will fix up */
2213 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2215 else if (fragP
->fr_symbol
)
2217 /* Its got a segment, but its not ours, so it will always be long. */
2218 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2222 /* We know the abs value. */
2223 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2227 case C (UNCD_JUMP
, DISP12
):
2228 case C (UNCD_JUMP
, DISP32
):
2229 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2230 case C (COND_JUMP
, DISP12
):
2231 case C (COND_JUMP
, DISP32
):
2232 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2233 /* When relaxing a section for the second time, we don't need to
2234 do anything besides return the current size. */
2238 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2241 /* Put number into target byte order. */
2243 md_number_to_chars (ptr
, use
, nbytes
)
2248 if (! target_big_endian
)
2251 case 4: ptr
[3] = (use
>> 24) & 0xff; /* fall through */
2252 case 3: ptr
[2] = (use
>> 16) & 0xff; /* fall through */
2253 case 2: ptr
[1] = (use
>> 8) & 0xff; /* fall through */
2254 case 1: ptr
[0] = (use
>> 0) & 0xff; break;
2260 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2261 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2262 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2263 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2268 /* Round up a section size to the appropriate boundary. */
2270 md_section_align (segment
, size
)
2271 segT segment ATTRIBUTE_UNUSED
;
2274 return size
; /* Byte alignment is fine */
2277 /* The location from which a PC relative jump should be calculated,
2278 given a PC relative reloc. */
2280 md_pcrel_from_section (fixp
, sec
)
2282 segT sec ATTRIBUTE_UNUSED
;
2285 /* If the symbol is undefined or defined in another section
2286 we leave the add number alone for the linker to fix it later.
2287 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2288 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2289 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2290 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2293 assert (fixp
->fx_size
== 2); /* must be an insn */
2294 return fixp
->fx_size
;
2298 /* The case where we are going to resolve things... */
2299 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2302 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2303 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2306 tc_gen_reloc (section
, fixp
)
2307 asection
* section ATTRIBUTE_UNUSED
;
2311 bfd_reloc_code_real_type code
;
2313 switch (fixp
->fx_r_type
)
2315 /* These confuse the size/pcrel macro approach. */
2316 case BFD_RELOC_VTABLE_INHERIT
:
2317 case BFD_RELOC_VTABLE_ENTRY
:
2318 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2319 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2320 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2321 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2323 code
= fixp
->fx_r_type
;
2327 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2329 MAP (1, 0, BFD_RELOC_8
);
2330 MAP (2, 0, BFD_RELOC_16
);
2331 MAP (4, 0, BFD_RELOC_32
);
2332 MAP (1, 1, BFD_RELOC_8_PCREL
);
2333 MAP (2, 1, BFD_RELOC_16_PCREL
);
2334 MAP (4, 1, BFD_RELOC_32_PCREL
);
2336 code
= fixp
->fx_r_type
;
2337 as_bad (_("Can not do %d byte %srelocation"),
2339 fixp
->fx_pcrel
? _("pc-relative") : "");
2344 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2345 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2346 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2347 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2348 /* Always pass the addend along! */
2349 rel
->addend
= fixp
->fx_addnumber
;
2351 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2353 if (rel
->howto
== NULL
)
2355 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2356 _("Cannot represent relocation type %s"),
2357 bfd_get_reloc_code_name (code
));
2359 /* Set howto to a garbage value so that we can keep going. */
2360 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2361 assert (rel
->howto
!= NULL
);
2368 /* See whether we need to force a relocation into the output file.
2369 This is used to force out switch and PC relative relocations when
2372 mcore_force_relocation (fix
)
2375 if (fix
->fx_r_type
== BFD_RELOC_RVA
)
2378 return generic_force_reloc (fix
);
2381 /* Return true if the fix can be handled by GAS, false if it must
2382 be passed through to the linker. */
2384 mcore_fix_adjustable (fixP
)
2387 /* We need the symbol name for the VTABLE entries. */
2388 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2389 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2394 #endif /* OBJ_ELF */