1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright (C) 1999-2019 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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "../opcodes/mcore-opc.h"
25 #include "safe-ctype.h"
28 #include "elf/mcore.h"
32 #define streq(a,b) (strcmp (a, b) == 0)
35 /* Forward declarations for dumb compilers. */
37 /* Several places in this file insert raw instructions into the
38 object. They should use MCORE_INST_XXX macros to get the opcodes
39 and then use these two macros to crack the MCORE_INST value into
40 the appropriate byte values. */
41 #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
42 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF))
44 const char comment_chars
[] = "#/";
45 const char line_separator_chars
[] = ";";
46 const char line_comment_chars
[] = "#/";
48 static int do_jsri2bsr
= 0; /* Change here from 1 by Cruess 19 August 97. */
49 static int sifilter_mode
= 0;
51 const char EXP_CHARS
[] = "eE";
53 /* Chars that mean this number is a floating point constant
56 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
58 #define C(what,length) (((what) << 2) + (length))
59 #define GET_WHAT(x) ((x >> 2))
61 /* These are the two types of relaxable instruction. */
68 #define UNDEF_WORD_DISP 3
71 #define C32_LEN 10 /* Allow for align. */
73 #define U32_LEN 8 /* Allow for align. */
84 /* Initialize the relax table. */
85 const relax_typeS md_relax_table
[] =
93 { 0, 0, 0, 0 }, /* UNDEF_DISP */
94 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* DISP12 */
95 { 0, 0, C32_LEN
, 0 }, /* DISP32 */
96 { 0, 0, C32_LEN
, 0 }, /* UNDEF_WORD_DISP */
99 { 0, 0, 0, 0 }, /* UNDEF_DISP */
100 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* DISP12 */
101 { 0, 0, U32_LEN
, 0 }, /* DISP32 */
102 { 0, 0, U32_LEN
, 0 } /* UNDEF_WORD_DISP */
106 /* Literal pool data structures. */
109 unsigned short refcnt
;
110 unsigned char ispcrel
;
111 unsigned char unused
;
115 #define MAX_POOL_SIZE (1024/4)
116 static struct literal litpool
[MAX_POOL_SIZE
];
117 static unsigned poolsize
;
118 static unsigned poolnumber
;
119 static unsigned long poolspan
;
121 /* SPANPANIC: the point at which we get too scared and force a dump
122 of the literal pool, and perhaps put a branch in place.
124 1024 span of lrw/jmpi/jsri insn (actually span+1)
125 -2 possible alignment at the insn.
126 -2 possible alignment to get the table aligned.
127 -2 an inserted branch around the table.
129 at 1018, we might be in trouble.
130 -- so we have to be smaller than 1018 and since we deal with 2-byte
131 instructions, the next good choice is 1016.
132 -- Note we have a test case that fails when we've got 1018 here. */
133 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
134 #define SPANCLOSE (900)
135 #define SPANEXIT (600)
136 static symbolS
* poolsym
; /* Label for current pool. */
137 static char poolname
[8];
138 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
140 #define POOL_END_LABEL ".LE"
141 #define POOL_START_LABEL ".LS"
144 make_name (char * s
, const char * p
, int n
)
146 static const char hex
[] = "0123456789ABCDEF";
151 s
[3] = hex
[(n
>> 12) & 0xF];
152 s
[4] = hex
[(n
>> 8) & 0xF];
153 s
[5] = hex
[(n
>> 4) & 0xF];
154 s
[6] = hex
[(n
) & 0xF];
159 dump_literals (int isforce
)
163 symbolS
* brarsym
= NULL
;
168 /* Must we branch around the literal table? */
174 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
176 brarsym
= symbol_make (brarname
);
178 symbol_table_insert (brarsym
);
180 output
= frag_var (rs_machine_dependent
,
181 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
182 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
183 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
184 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
185 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
188 /* Make sure that the section is sufficiently aligned and that
189 the literal table is aligned within it. */
190 record_alignment (now_seg
, 2);
191 frag_align (2, 0, 0);
193 colon (S_GET_NAME (poolsym
));
195 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
196 emit_expr (& p
->e
, 4);
199 colon (S_GET_NAME (brarsym
));
205 mcore_s_literals (int ignore ATTRIBUTE_UNUSED
)
208 demand_empty_rest_of_line ();
211 /* Perform FUNC (ARG), and track number of bytes added to frag. */
214 mcore_pool_count (void (*func
) (int), int arg
)
216 const fragS
*curr_frag
= frag_now
;
217 offsetT added
= -frag_now_fix_octets ();
221 while (curr_frag
!= frag_now
)
223 added
+= curr_frag
->fr_fix
;
224 curr_frag
= curr_frag
->fr_next
;
227 added
+= frag_now_fix_octets ();
232 check_literals (int kind
, int offset
)
236 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
237 SPANPANIC means that we must dump now.
238 kind == 0 is any old instruction.
239 kind > 0 means we just had a control transfer instruction.
240 kind == 1 means within a function
241 kind == 2 means we just left a function
243 The dump_literals (1) call inserts a branch around the table, so
244 we first look to see if it's a situation where we won't have to
245 insert a branch (e.g., the previous instruction was an unconditional
248 SPANPANIC is the point where we must dump a single-entry pool.
249 it accounts for alignments and an inserted branch.
250 the 'poolsize*2' accounts for the scenario where we do:
251 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
252 Note that the 'lit2' reference is 2 bytes further along
253 but the literal it references will be 4 bytes further along,
254 so we must consider the poolsize into this equation.
255 This is slightly over-cautious, but guarantees that we won't
256 panic because a relocation is too distant. */
258 if (poolspan
> SPANCLOSE
&& kind
> 0)
260 else if (poolspan
> SPANEXIT
&& kind
> 1)
262 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
267 mcore_cons (int nbytes
)
269 if (now_seg
== text_section
)
270 mcore_pool_count (cons
, nbytes
);
274 /* In theory we ought to call check_literals (2,0) here in case
275 we need to dump the literal table. We cannot do this however,
276 as the directives that we are intercepting may be being used
277 to build a switch table, and we must not interfere with its
278 contents. Instead we cross our fingers and pray... */
282 mcore_float_cons (int float_type
)
284 if (now_seg
== text_section
)
285 mcore_pool_count (float_cons
, float_type
);
287 float_cons (float_type
);
289 /* See the comment in mcore_cons () about calling check_literals.
290 It is unlikely that a switch table will be constructed using
291 floating point values, but it is still likely that an indexed
292 table of floating point constants is being created by these
293 directives, so again we must not interfere with their placement. */
297 mcore_stringer (int append_zero
)
299 if (now_seg
== text_section
)
300 mcore_pool_count (stringer
, append_zero
);
302 stringer (append_zero
);
304 /* We call check_literals here in case a large number of strings are
305 being placed into the text section with a sequence of stringer
306 directives. In theory we could be upsetting something if these
307 strings are actually in an indexed table instead of referenced by
308 individual labels. Let us hope that that never happens. */
309 check_literals (2, 0);
313 mcore_fill (int unused
)
315 if (now_seg
== text_section
)
316 mcore_pool_count (s_fill
, unused
);
320 check_literals (2, 0);
323 /* Handle the section changing pseudo-ops. These call through to the
324 normal implementations, but they dump the literal pool first. */
327 mcore_s_text (int ignore
)
332 obj_elf_text (ignore
);
339 mcore_s_data (int ignore
)
344 obj_elf_data (ignore
);
351 mcore_s_section (int ignore
)
353 /* Scan forwards to find the name of the section. If the section
354 being switched to is ".line" then this is a DWARF1 debug section
355 which is arbitrarily placed inside generated code. In this case
356 do not dump the literal pool because it is a) inefficient and
357 b) would require the generation of extra code to jump around the
359 char * ilp
= input_line_pointer
;
361 while (*ilp
!= 0 && ISSPACE (*ilp
))
364 if (strncmp (ilp
, ".line", 5) == 0
365 && (ISSPACE (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
371 obj_elf_section (ignore
);
374 obj_coff_section (ignore
);
379 mcore_s_bss (int needs_align
)
383 s_lcomm_bytes (needs_align
);
388 mcore_s_comm (int needs_align
)
392 obj_elf_common (needs_align
);
396 /* This table describes all the machine specific pseudo-ops the assembler
397 has to support. The fields are:
398 Pseudo-op name without dot
399 Function to call to execute this pseudo-op
400 Integer arg to pass to the function. */
401 const pseudo_typeS md_pseudo_table
[] =
403 { "export", s_globl
, 0 },
404 { "import", s_ignore
, 0 },
405 { "literals", mcore_s_literals
, 0 },
406 { "page", listing_eject
, 0 },
408 /* The following are to intercept the placement of data into the text
409 section (eg addresses for a switch table), so that the space they
410 occupy can be taken into account when deciding whether or not to
411 dump the current literal pool.
412 XXX - currently we do not cope with the .space and .dcb.d directives. */
413 { "ascii", mcore_stringer
, 8 + 0 },
414 { "asciz", mcore_stringer
, 8 + 1 },
415 { "byte", mcore_cons
, 1 },
416 { "dc", mcore_cons
, 2 },
417 { "dc.b", mcore_cons
, 1 },
418 { "dc.d", mcore_float_cons
, 'd'},
419 { "dc.l", mcore_cons
, 4 },
420 { "dc.s", mcore_float_cons
, 'f'},
421 { "dc.w", mcore_cons
, 2 },
422 { "dc.x", mcore_float_cons
, 'x'},
423 { "double", mcore_float_cons
, 'd'},
424 { "float", mcore_float_cons
, 'f'},
425 { "hword", mcore_cons
, 2 },
426 { "int", mcore_cons
, 4 },
427 { "long", mcore_cons
, 4 },
428 { "octa", mcore_cons
, 16 },
429 { "quad", mcore_cons
, 8 },
430 { "short", mcore_cons
, 2 },
431 { "single", mcore_float_cons
, 'f'},
432 { "string", mcore_stringer
, 8 + 1 },
433 { "word", mcore_cons
, 2 },
434 { "fill", mcore_fill
, 0 },
436 /* Allow for the effect of section changes. */
437 { "text", mcore_s_text
, 0 },
438 { "data", mcore_s_data
, 0 },
439 { "bss", mcore_s_bss
, 1 },
441 { "comm", mcore_s_comm
, 0 },
443 { "section", mcore_s_section
, 0 },
444 { "section.s", mcore_s_section
, 0 },
445 { "sect", mcore_s_section
, 0 },
446 { "sect.s", mcore_s_section
, 0 },
451 /* This function is called once, at assembler startup time. This should
452 set up all the tables, etc that the MD part of the assembler needs. */
457 const char * prev_name
= "";
460 opcode_hash_control
= hash_new ();
462 /* Insert unique names into hash table. */
463 for (i
= 0; i
< ARRAY_SIZE (mcore_table
); i
++)
465 if (! streq (prev_name
, mcore_table
[i
].name
))
467 prev_name
= mcore_table
[i
].name
;
468 hash_insert (opcode_hash_control
, mcore_table
[i
].name
, (char *) &mcore_table
[i
]);
473 /* Get a log2(val). */
476 mylog2 (unsigned int val
)
489 /* Try to parse a reg name. */
492 parse_reg (char * s
, unsigned * reg
)
494 /* Strip leading whitespace. */
495 while (ISSPACE (* s
))
498 if (TOLOWER (s
[0]) == 'r')
500 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
502 *reg
= 10 + s
[2] - '0';
506 if (s
[1] >= '0' && s
[1] <= '9')
512 else if ( TOLOWER (s
[0]) == 's'
513 && TOLOWER (s
[1]) == 'p'
520 as_bad (_("register expected, but saw '%.6s'"), s
);
548 parse_creg (char * s
, unsigned * reg
)
552 /* Strip leading whitespace. */
553 while (ISSPACE (* s
))
556 if ((TOLOWER (s
[0]) == 'c' && TOLOWER (s
[1]) == 'r'))
558 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
560 *reg
= 30 + s
[3] - '0';
564 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
566 *reg
= 20 + s
[3] - '0';
570 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
572 *reg
= 10 + s
[3] - '0';
576 if (s
[2] >= '0' && s
[2] <= '9')
583 /* Look at alternate creg names before giving error. */
584 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
590 length
= strlen (cregs
[i
].name
);
592 for (j
= 0; j
< length
; j
++)
593 buf
[j
] = TOLOWER (s
[j
]);
595 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
597 *reg
= cregs
[i
].crnum
;
602 as_bad (_("control register expected, but saw '%.6s'"), s
);
608 parse_psrmod (char * s
, unsigned * reg
)
612 static struct psrmods
622 { "af", 8 } /* Really 0 and non-combinable. */
625 for (i
= 0; i
< 2; i
++)
626 buf
[i
] = TOLOWER (s
[i
]);
628 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
630 if (! strncmp (psrmods
[i
].name
, buf
, 2))
632 * reg
= psrmods
[i
].value
;
638 as_bad (_("bad/missing psr specifier"));
646 parse_exp (char * s
, expressionS
* e
)
651 /* Skip whitespace. */
652 while (ISSPACE (* s
))
655 save
= input_line_pointer
;
656 input_line_pointer
= s
;
660 if (e
->X_op
== O_absent
)
661 as_bad (_("missing operand"));
663 new_pointer
= input_line_pointer
;
664 input_line_pointer
= save
;
670 enter_literal (expressionS
* e
, int ispcrel
)
675 if (poolsize
>= MAX_POOL_SIZE
- 2)
676 /* The literal pool is as full as we can handle. We have
677 to be 2 entries shy of the 1024/4=256 entries because we
678 have to allow for the branch (2 bytes) and the alignment
679 (2 bytes before the first insn referencing the pool and
680 2 bytes before the pool itself) == 6 bytes, rounds up
686 /* Create new literal pool. */
687 if (++ poolnumber
> 0xFFFF)
688 as_fatal (_("more than 65K literal pools"));
690 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
691 poolsym
= symbol_make (poolname
);
692 symbol_table_insert (poolsym
);
696 /* Search pool for value so we don't have duplicates. */
697 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
699 if (e
->X_op
== p
->e
.X_op
700 && e
->X_add_symbol
== p
->e
.X_add_symbol
701 && e
->X_add_number
== p
->e
.X_add_number
702 && ispcrel
== p
->ispcrel
)
710 p
->ispcrel
= ispcrel
;
718 /* Parse a literal specification. -- either new or old syntax.
719 old syntax: the user supplies the label and places the literal.
720 new syntax: we put it into the literal pool. */
732 /* Indicate nothing there. */
737 s
= parse_exp (s
+ 1, & e
);
742 as_bad (_("missing ']'"));
746 s
= parse_exp (s
, & e
);
748 n
= enter_literal (& e
, ispcrel
);
753 /* Create a reference to pool entry. */
755 e
.X_add_symbol
= poolsym
;
756 e
.X_add_number
= n
<< 2;
759 * outputp
= frag_more (2);
761 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
762 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
776 new_pointer
= parse_exp (s
, & e
);
778 if (e
.X_op
== O_absent
)
779 ; /* An error message has already been emitted. */
780 else if (e
.X_op
!= O_constant
)
781 as_bad (_("operand must be a constant"));
782 else if ((addressT
) e
.X_add_number
< min
|| (addressT
) e
.X_add_number
> max
)
783 as_bad (_("operand must be absolute in range %u..%u, not %ld"),
784 min
, max
, (long) e
.X_add_number
);
786 * val
= e
.X_add_number
;
799 while (ISSPACE (* s
))
804 s
= parse_reg (s
+ 1, reg
);
806 while (ISSPACE (* s
))
811 s
= parse_imm (s
+ 1, off
, 0, 63);
818 as_bad (_("operand must be a multiple of 4"));
825 as_bad (_("operand must be a multiple of 2"));
832 while (ISSPACE (* s
))
839 as_bad (_("base register expected"));
844 /* This is the guts of the machine-dependent assembler. STR points to a
845 machine dependent instruction. This function is supposed to emit
846 the frags/bytes it assembles to. */
849 md_assemble (char * str
)
853 mcore_opcode_info
* opcode
;
863 /* Drop leading whitespace. */
864 while (ISSPACE (* str
))
867 /* Find the op code end. */
868 for (op_start
= op_end
= str
;
869 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
872 name
[nlen
] = op_start
[nlen
];
880 as_bad (_("can't find opcode "));
884 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
887 as_bad (_("unknown opcode \"%s\""), name
);
894 switch (opcode
->opclass
)
897 output
= frag_more (2);
901 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
903 output
= frag_more (2);
907 op_end
= parse_reg (op_end
+ 1, & reg
);
909 output
= frag_more (2);
913 op_end
= parse_reg (op_end
+ 1, & reg
);
915 output
= frag_more (2);
916 /* In a sifilter mode, we emit this insn 2 times,
917 fixes problem of an interrupt during a jmp.. */
920 output
[0] = INST_BYTE0 (inst
);
921 output
[1] = INST_BYTE1 (inst
);
922 output
= frag_more (2);
927 op_end
= parse_reg (op_end
+ 1, & reg
);
930 as_bad (_("invalid register: r15 illegal"));
933 output
= frag_more (2);
937 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx. */
938 inst
= MCORE_INST_BSR
; /* With 0 displacement. */
939 output
[0] = INST_BYTE0 (inst
);
940 output
[1] = INST_BYTE1 (inst
);
942 output
= frag_more (2);
943 inst
= MCORE_INST_ADDI
;
944 inst
|= 15; /* addi r15,6 */
945 inst
|= (6 - 1) << 4; /* Over the jmp's. */
946 output
[0] = INST_BYTE0 (inst
);
947 output
[1] = INST_BYTE1 (inst
);
949 output
= frag_more (2);
950 inst
= MCORE_INST_JMP
| reg
;
951 output
[0] = INST_BYTE0 (inst
);
952 output
[1] = INST_BYTE1 (inst
);
954 /* 2nd emitted in fallthrough. */
955 output
= frag_more (2);
960 op_end
= parse_reg (op_end
+ 1, & reg
);
963 /* Skip whitespace. */
964 while (ISSPACE (* op_end
))
969 op_end
= parse_creg (op_end
+ 1, & reg
);
973 output
= frag_more (2);
979 as_bad (_("M340 specific opcode used when assembling for M210"));
984 op_end
= parse_reg (op_end
+ 1, & reg
);
987 /* Skip whitespace. */
988 while (ISSPACE (* op_end
))
993 op_end
= parse_reg (op_end
+ 1, & reg
);
997 as_bad (_("second operand missing"));
999 output
= frag_more (2);
1003 /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx. */
1004 op_end
= parse_reg (op_end
+ 1, & reg
);
1006 /* Skip whitespace. */
1007 while (ISSPACE (* op_end
))
1010 if (* op_end
== ',') /* xtrb- r1,rx. */
1013 as_bad (_("destination register must be r1"));
1015 op_end
= parse_reg (op_end
+ 1, & reg
);
1019 output
= frag_more (2);
1022 case O1R1
: /* div- rx,r1. */
1023 op_end
= parse_reg (op_end
+ 1, & reg
);
1026 /* Skip whitespace. */
1027 while (ISSPACE (* op_end
))
1030 if (* op_end
== ',')
1032 op_end
= parse_reg (op_end
+ 1, & reg
);
1034 as_bad (_("source register must be r1"));
1037 as_bad (_("second operand missing"));
1039 output
= frag_more (2);
1043 op_end
= parse_reg (op_end
+ 1, & reg
);
1046 /* Skip whitespace. */
1047 while (ISSPACE (* op_end
))
1050 if (* op_end
== ',')
1052 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1053 inst
|= (reg
- 1) << 4;
1056 as_bad (_("second operand missing"));
1058 output
= frag_more (2);
1062 op_end
= parse_reg (op_end
+ 1, & reg
);
1065 /* Skip whitespace. */
1066 while (ISSPACE (* op_end
))
1069 if (* op_end
== ',')
1071 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1075 as_bad (_("second operand missing"));
1077 output
= frag_more (2);
1081 /* Like OB, but arg is 2^n instead of n. */
1082 op_end
= parse_reg (op_end
+ 1, & reg
);
1085 /* Skip whitespace. */
1086 while (ISSPACE (* op_end
))
1089 if (* op_end
== ',')
1091 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1092 /* Further restrict the immediate to a power of two. */
1093 if ((reg
& (reg
- 1)) == 0)
1098 as_bad (_("immediate is not a power of two"));
1103 as_bad (_("second operand missing"));
1105 output
= frag_more (2);
1108 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1111 op_end
= parse_reg (op_end
+ 1, & reg
);
1114 /* Skip whitespace. */
1115 while (ISSPACE (* op_end
))
1118 if (* op_end
== ',')
1120 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1121 /* Immediate values of 0 -> 6 translate to movi. */
1124 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1126 as_warn (_("translating bgeni to movi"));
1132 as_bad (_("second operand missing"));
1134 output
= frag_more (2);
1137 case OBR2
: /* Like OBR, 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);
1149 /* Further restrict the immediate to a power of two. */
1150 if ((reg
& (reg
- 1)) == 0)
1155 as_bad (_("immediate is not a power of two"));
1158 /* Immediate values of 0 -> 6 translate to movi. */
1161 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1163 as_warn (_("translating mgeni to movi"));
1169 as_bad (_("second operand missing"));
1171 output
= frag_more (2);
1174 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1177 op_end
= parse_reg (op_end
+ 1, & reg
);
1180 /* Skip whitespace. */
1181 while (ISSPACE (* op_end
))
1184 if (* op_end
== ',')
1186 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1188 /* Immediate values of 1 -> 7 translate to movi. */
1191 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1192 reg
= (0x1 << reg
) - 1;
1195 as_warn (_("translating bmaski to movi"));
1200 inst
|= (reg
& 0x1F) << 4;
1204 as_bad (_("second operand missing"));
1206 output
= frag_more (2);
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
, 1, 31);
1223 as_bad (_("second operand missing"));
1225 output
= frag_more (2);
1229 op_end
= parse_reg (op_end
+ 1, & reg
);
1232 /* Skip whitespace. */
1233 while (ISSPACE (* op_end
))
1236 if (* op_end
== ',')
1238 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1242 as_bad (_("second operand missing"));
1244 output
= frag_more (2);
1248 op_end
= parse_reg (op_end
+ 1, & reg
);
1251 /* Skip whitespace. */
1252 while (ISSPACE (* op_end
))
1255 if (* op_end
== ',')
1259 if ((inst
& 0x6000) == 0)
1261 else if ((inst
& 0x6000) == 0x4000)
1263 else if ((inst
& 0x6000) == 0x2000)
1268 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1271 as_bad (_("displacement too large (%d)"), off
);
1273 inst
|= (reg
) | (off
<< 4);
1276 as_bad (_("second operand missing"));
1278 output
= frag_more (2);
1282 op_end
= parse_reg (op_end
+ 1, & reg
);
1284 if (reg
== 0 || reg
== 15)
1285 as_bad (_("Invalid register: r0 and r15 illegal"));
1289 /* Skip whitespace. */
1290 while (ISSPACE (* op_end
))
1293 if (* op_end
== ',')
1295 /* parse_rt calls frag_more() for us. */
1296 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1297 op_end
= input_line_pointer
;
1301 as_bad (_("second operand missing"));
1302 output
= frag_more (2); /* save its space */
1307 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1308 /* parse_rt() calls frag_more() for us. */
1309 op_end
= input_line_pointer
;
1313 op_end
= parse_reg (op_end
+ 1, & reg
);
1315 if (reg
== 0 || reg
== 15)
1316 as_bad (_("bad starting register: r0 and r15 invalid"));
1320 /* Skip whitespace. */
1321 while (ISSPACE (* op_end
))
1324 if (* op_end
== '-')
1326 op_end
= parse_reg (op_end
+ 1, & reg
);
1329 as_bad (_("ending register must be r15"));
1331 /* Skip whitespace. */
1332 while (ISSPACE (* op_end
))
1336 if (* op_end
== ',')
1340 /* Skip whitespace. */
1341 while (ISSPACE (* op_end
))
1344 if (* op_end
== '(')
1346 op_end
= parse_reg (op_end
+ 1, & reg
);
1349 as_bad (_("bad base register: must be r0"));
1351 if (* op_end
== ')')
1355 as_bad (_("base register expected"));
1358 as_bad (_("second operand missing"));
1360 output
= frag_more (2);
1364 op_end
= parse_reg (op_end
+ 1, & reg
);
1367 as_fatal (_("first register must be r4"));
1369 /* Skip whitespace. */
1370 while (ISSPACE (* op_end
))
1373 if (* op_end
== '-')
1375 op_end
= parse_reg (op_end
+ 1, & reg
);
1378 as_fatal (_("last register must be r7"));
1380 /* Skip whitespace. */
1381 while (ISSPACE (* op_end
))
1384 if (* op_end
== ',')
1388 /* Skip whitespace. */
1389 while (ISSPACE (* op_end
))
1392 if (* op_end
== '(')
1394 op_end
= parse_reg (op_end
+ 1, & reg
);
1396 if (reg
>= 4 && reg
<= 7)
1397 as_fatal ("base register cannot be r4, r5, r6, or r7");
1401 /* Skip whitespace. */
1402 while (ISSPACE (* op_end
))
1405 if (* op_end
== ')')
1409 as_bad (_("base register expected"));
1412 as_bad (_("second operand missing"));
1415 as_bad (_("reg-reg expected"));
1417 output
= frag_more (2);
1421 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1422 op_end
= input_line_pointer
;
1424 output
= frag_more (2);
1426 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1427 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1431 op_end
= parse_reg (op_end
+ 1, & reg
);
1434 /* Skip whitespace. */
1435 while (ISSPACE (* op_end
))
1438 if (* op_end
== ',')
1440 op_end
= parse_exp (op_end
+ 1, & e
);
1441 output
= frag_more (2);
1443 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1444 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1448 as_bad (_("second operand missing"));
1449 output
= frag_more (2);
1454 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1455 op_end
= input_line_pointer
;
1457 output
= frag_var (rs_machine_dependent
,
1458 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1459 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1460 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1465 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1466 op_end
= input_line_pointer
;
1468 output
= frag_var (rs_machine_dependent
,
1469 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1470 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1471 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1476 inst
= MCORE_INST_JSRI
; /* jsri */
1477 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1478 /* parse_rt() calls frag_more for us. */
1479 op_end
= input_line_pointer
;
1481 /* Only do this if we know how to do it ... */
1482 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1484 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1485 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1486 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1491 /* SI, but imm becomes 32-imm. */
1492 op_end
= parse_reg (op_end
+ 1, & reg
);
1495 /* Skip whitespace. */
1496 while (ISSPACE (* op_end
))
1499 if (* op_end
== ',')
1501 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1507 as_bad (_("second operand missing"));
1509 output
= frag_more (2);
1512 case DO21
: /* O2, dup rd, lit must be 1 */
1513 op_end
= parse_reg (op_end
+ 1, & reg
);
1517 /* Skip whitespace. */
1518 while (ISSPACE (* op_end
))
1521 if (* op_end
== ',')
1523 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1526 as_bad (_("second operand must be 1"));
1529 as_bad (_("second operand missing"));
1531 output
= frag_more (2);
1535 op_end
= parse_reg (op_end
+ 1, & reg
);
1538 /* Skip whitespace. */
1539 while (ISSPACE (* op_end
))
1542 if (* op_end
== ',')
1544 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1547 as_bad (_("zero used as immediate value"));
1552 as_bad (_("second operand missing"));
1554 output
= frag_more (2);
1560 as_bad (_("M340 specific opcode used when assembling for M210"));
1564 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1566 /* Look for further selectors. */
1567 while (* op_end
== ',')
1571 op_end
= parse_psrmod (op_end
+ 1, & value
);
1574 as_bad (_("duplicated psr bit specifier"));
1580 as_bad (_("`af' must appear alone"));
1582 inst
|= (reg
& 0x7);
1583 output
= frag_more (2);
1587 as_bad (_("unimplemented opcode \"%s\""), name
);
1590 /* Drop whitespace after all the operands have been parsed. */
1591 while (ISSPACE (* op_end
))
1594 /* Give warning message if the insn has more operands than required. */
1595 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1596 as_warn (_("ignoring operands: %s "), op_end
);
1598 output
[0] = INST_BYTE0 (inst
);
1599 output
[1] = INST_BYTE1 (inst
);
1602 dwarf2_emit_insn (2);
1604 check_literals (opcode
->transfer
, isize
);
1608 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1617 subseg_set (text_section
, 0);
1620 /* Various routines to kill one day. */
1623 md_atof (int type
, char * litP
, int * sizeP
)
1625 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1628 const char * md_shortopts
= "";
1632 OPTION_JSRI2BSR_ON
= OPTION_MD_BASE
,
1633 OPTION_JSRI2BSR_OFF
,
1635 OPTION_SIFILTER_OFF
,
1641 struct option md_longopts
[] =
1643 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1644 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1645 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1646 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1647 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1648 { "EB", no_argument
, NULL
, OPTION_EB
},
1649 { "EL", no_argument
, NULL
, OPTION_EL
},
1650 { NULL
, no_argument
, NULL
, 0}
1653 size_t md_longopts_size
= sizeof (md_longopts
);
1656 md_parse_option (int c
, const char * arg
)
1661 if (streq (arg
, "210"))
1664 target_big_endian
= 1;
1666 else if (streq (arg
, "340"))
1669 as_warn (_("unrecognised cpu type '%s'"), arg
);
1672 case OPTION_EB
: target_big_endian
= 1; break;
1673 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1674 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1675 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1676 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1677 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1685 md_show_usage (FILE * stream
)
1687 fprintf (stream
, _("\
1688 MCORE specific options:\n\
1689 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1690 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1691 -cpu=[210|340] select CPU type\n\
1692 -EB assemble for a big endian system (default)\n\
1693 -EL assemble for a little endian system\n"));
1696 int md_short_jump_size
;
1699 md_create_short_jump (char * ptr ATTRIBUTE_UNUSED
,
1700 addressT from_Nddr ATTRIBUTE_UNUSED
,
1701 addressT to_Nddr ATTRIBUTE_UNUSED
,
1702 fragS
* frag ATTRIBUTE_UNUSED
,
1703 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1705 as_fatal (_("failed sanity check: short_jump"));
1709 md_create_long_jump (char * ptr ATTRIBUTE_UNUSED
,
1710 addressT from_Nddr ATTRIBUTE_UNUSED
,
1711 addressT to_Nddr ATTRIBUTE_UNUSED
,
1712 fragS
* frag ATTRIBUTE_UNUSED
,
1713 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1715 as_fatal (_("failed sanity check: long_jump"));
1718 /* Called after relaxing, change the frags so they know how big they are. */
1721 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1722 segT sec ATTRIBUTE_UNUSED
,
1726 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1728 buffer
= fragP
->fr_fix
+ fragP
->fr_literal
;
1730 switch (fragP
->fr_subtype
)
1732 case C (COND_JUMP
, DISP12
):
1733 case C (UNCD_JUMP
, DISP12
):
1735 /* Get the address of the end of the instruction. */
1736 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1738 int disp
= targ_addr
- next_inst
;
1741 as_bad (_("odd displacement at %x"), next_inst
- 2);
1745 if (! target_big_endian
)
1747 t0
= buffer
[1] & 0xF8;
1749 md_number_to_chars (buffer
, disp
, 2);
1751 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1755 t0
= buffer
[0] & 0xF8;
1757 md_number_to_chars (buffer
, disp
, 2);
1759 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1766 case C (COND_JUMP
, DISP32
):
1767 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1769 /* A conditional branch won't fit into 12 bits so:
1776 If the b!cond is 4 byte aligned, the literal which would
1777 go at x+4 will also be aligned. */
1778 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1779 int needpad
= (first_inst
& 3);
1781 if (! target_big_endian
)
1784 buffer
[0] ^= 0x08; /* Toggle T/F bit. */
1786 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1787 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1791 if (! target_big_endian
)
1793 buffer
[0] = 4; /* Branch over jmpi, pad, and ptr. */
1794 buffer
[2] = 1; /* Jmpi offset of 1 gets the pointer. */
1798 buffer
[1] = 4; /* Branch over jmpi, pad, and ptr. */
1799 buffer
[3] = 1; /* Jmpi offset of 1 gets the pointer. */
1802 buffer
[4] = 0; /* Alignment/pad. */
1804 buffer
[6] = 0; /* Space for 32 bit address. */
1809 /* Make reloc for the long disp. */
1810 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1811 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1813 fragP
->fr_fix
+= C32_LEN
;
1817 /* See comment below about this given gas' limitations for
1818 shrinking the fragment. '3' is the amount of code that
1819 we inserted here, but '4' is right for the space we reserved
1820 for this fragment. */
1821 if (! target_big_endian
)
1823 buffer
[0] = 3; /* Branch over jmpi, and ptr. */
1824 buffer
[2] = 0; /* Jmpi offset of 0 gets the pointer. */
1828 buffer
[1] = 3; /* Branch over jmpi, and ptr. */
1829 buffer
[3] = 0; /* Jmpi offset of 0 gets the pointer. */
1832 buffer
[4] = 0; /* Space for 32 bit address. */
1837 /* Make reloc for the long disp. */
1838 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1839 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1840 fragP
->fr_fix
+= C32_LEN
;
1842 /* Frag is actually shorter (see the other side of this ifdef)
1843 but gas isn't prepared for that. We have to re-adjust
1844 the branch displacement so that it goes beyond the
1845 full length of the fragment, not just what we actually
1847 if (! target_big_endian
)
1848 buffer
[0] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1850 buffer
[1] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1855 case C (UNCD_JUMP
, DISP32
):
1856 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1858 /* An unconditional branch will not fit in 12 bits, make code which
1863 we need a pad if "first_inst" is 4 byte aligned.
1864 [because the natural literal place is x + 2]. */
1865 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1866 int needpad
= !(first_inst
& 3);
1868 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1869 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1873 if (! target_big_endian
)
1874 buffer
[0] = 1; /* Jmpi offset of 1 since padded. */
1876 buffer
[1] = 1; /* Jmpi offset of 1 since padded. */
1877 buffer
[2] = 0; /* Alignment. */
1879 buffer
[4] = 0; /* Space for 32 bit address. */
1884 /* Make reloc for the long disp. */
1885 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1886 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1888 fragP
->fr_fix
+= U32_LEN
;
1892 if (! target_big_endian
)
1893 buffer
[0] = 0; /* Jmpi offset of 0 if no pad. */
1895 buffer
[1] = 0; /* Jmpi offset of 0 if no pad. */
1896 buffer
[2] = 0; /* Space for 32 bit address. */
1901 /* Make reloc for the long disp. */
1902 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1903 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1904 fragP
->fr_fix
+= U32_LEN
;
1914 /* Applies the desired value to the specified location.
1915 Also sets up addends for 'rela' type relocations. */
1918 md_apply_fix (fixS
* fixP
,
1920 segT segment ATTRIBUTE_UNUSED
)
1922 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1923 const char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1924 const char * symname
;
1925 /* Note: use offsetT because it is signed, valueT is unsigned. */
1926 offsetT val
= *valP
;
1928 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1929 /* Save this for the addend in the relocation record. */
1930 fixP
->fx_addnumber
= val
;
1932 if (fixP
->fx_addsy
!= NULL
)
1935 /* For ELF we can just return and let the reloc that will be generated
1936 take care of everything. For COFF we still have to insert 'val'
1937 into the insn since the addend field will be ignored. */
1944 switch (fixP
->fx_r_type
)
1946 /* Second byte of 2 byte opcode. */
1947 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
1949 as_bad_where (file
, fixP
->fx_line
,
1950 ngettext ("odd distance branch (0x%lx byte)",
1951 "odd distance branch (0x%lx bytes)",
1955 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
1956 as_bad_where (file
, fixP
->fx_line
,
1957 _("pcrel for branch to %s too far (0x%lx)"),
1958 symname
, (long) val
);
1959 if (target_big_endian
)
1961 buf
[0] |= ((val
>> 8) & 0x7);
1962 buf
[1] |= (val
& 0xff);
1966 buf
[1] |= ((val
>> 8) & 0x7);
1967 buf
[0] |= (val
& 0xff);
1971 /* Lower 8 bits of 2 byte opcode. */
1972 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
1976 as_bad_where (file
, fixP
->fx_line
,
1977 _("pcrel for lrw/jmpi/jsri to %s too far (0x%lx)"),
1978 symname
, (long) val
);
1979 else if (! target_big_endian
)
1980 buf
[0] |= (val
& 0xff);
1982 buf
[1] |= (val
& 0xff);
1985 /* Loopt instruction. */
1986 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
1987 if ((val
< -32) || (val
> -2))
1988 as_bad_where (file
, fixP
->fx_line
,
1989 _("pcrel for loopt too far (0x%lx)"), (long) val
);
1991 if (! target_big_endian
)
1992 buf
[0] |= (val
& 0xf);
1994 buf
[1] |= (val
& 0xf);
1997 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
1998 /* Conditional linker map jsri to bsr. */
1999 /* If it's a local target and close enough, fix it.
2000 NB: >= -2k for backwards bsr; < 2k for forwards... */
2001 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2003 long nval
= (val
/ 2) & 0x7ff;
2004 nval
|= MCORE_INST_BSR
;
2006 /* REPLACE the instruction, don't just modify it. */
2007 buf
[0] = INST_BYTE0 (nval
);
2008 buf
[1] = INST_BYTE1 (nval
);
2014 case BFD_RELOC_MCORE_PCREL_32
:
2015 case BFD_RELOC_VTABLE_INHERIT
:
2016 case BFD_RELOC_VTABLE_ENTRY
:
2021 if (fixP
->fx_addsy
!= NULL
)
2023 /* If the fix is an absolute reloc based on a symbol's
2024 address, then it cannot be resolved until the final link. */
2031 if (fixP
->fx_size
== 4)
2033 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2035 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2039 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2046 md_operand (expressionS
* expressionP
)
2048 /* Ignore leading hash symbol, if present. */
2049 if (* input_line_pointer
== '#')
2051 input_line_pointer
++;
2052 expression (expressionP
);
2056 int md_long_jump_size
;
2058 /* Called just before address relaxation, return the length
2059 by which a fragment must grow to reach it's destination. */
2061 md_estimate_size_before_relax (fragS
* fragP
, segT segment_type
)
2063 switch (fragP
->fr_subtype
)
2068 case C (UNCD_JUMP
, UNDEF_DISP
):
2069 /* Used to be a branch to somewhere which was unknown. */
2070 if (!fragP
->fr_symbol
)
2071 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2072 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2073 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2075 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2078 case C (COND_JUMP
, UNDEF_DISP
):
2079 /* Used to be a branch to somewhere which was unknown. */
2080 if (fragP
->fr_symbol
2081 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2082 /* Got a symbol and it's defined in this segment, become byte
2083 sized - maybe it will fix up */
2084 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2085 else if (fragP
->fr_symbol
)
2086 /* It's got a segment, but it's not ours, so it will always be long. */
2087 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2089 /* We know the abs value. */
2090 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2093 case C (UNCD_JUMP
, DISP12
):
2094 case C (UNCD_JUMP
, DISP32
):
2095 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2096 case C (COND_JUMP
, DISP12
):
2097 case C (COND_JUMP
, DISP32
):
2098 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2099 /* When relaxing a section for the second time, we don't need to
2100 do anything besides return the current size. */
2104 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2107 /* Put number into target byte order. */
2110 md_number_to_chars (char * ptr
, valueT use
, int nbytes
)
2112 if (target_big_endian
)
2113 number_to_chars_bigendian (ptr
, use
, nbytes
);
2115 number_to_chars_littleendian (ptr
, use
, nbytes
);
2118 /* Round up a section size to the appropriate boundary. */
2121 md_section_align (segT segment ATTRIBUTE_UNUSED
,
2124 /* Byte alignment is fine. */
2128 /* The location from which a PC relative jump should be calculated,
2129 given a PC relative reloc. */
2132 md_pcrel_from_section (fixS
* fixp
, segT sec ATTRIBUTE_UNUSED
)
2135 /* If the symbol is undefined or defined in another section
2136 we leave the add number alone for the linker to fix it later.
2137 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2138 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2139 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2140 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2143 gas_assert (fixp
->fx_size
== 2); /* must be an insn */
2144 return fixp
->fx_size
;
2148 /* The case where we are going to resolve things... */
2149 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2152 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2153 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2156 tc_gen_reloc (asection
* section ATTRIBUTE_UNUSED
, fixS
* fixp
)
2159 bfd_reloc_code_real_type code
;
2161 switch (fixp
->fx_r_type
)
2163 /* These confuse the size/pcrel macro approach. */
2164 case BFD_RELOC_VTABLE_INHERIT
:
2165 case BFD_RELOC_VTABLE_ENTRY
:
2166 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2167 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2168 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2169 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2171 code
= fixp
->fx_r_type
;
2175 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2177 MAP (1, 0, BFD_RELOC_8
);
2178 MAP (2, 0, BFD_RELOC_16
);
2179 MAP (4, 0, BFD_RELOC_32
);
2180 MAP (1, 1, BFD_RELOC_8_PCREL
);
2181 MAP (2, 1, BFD_RELOC_16_PCREL
);
2182 MAP (4, 1, BFD_RELOC_32_PCREL
);
2184 code
= fixp
->fx_r_type
;
2185 as_bad (_("Can not do %d byte %srelocation"),
2187 fixp
->fx_pcrel
? _("pc-relative ") : "");
2192 rel
= XNEW (arelent
);
2193 rel
->sym_ptr_ptr
= XNEW (asymbol
*);
2194 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2195 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2196 /* Always pass the addend along! */
2197 rel
->addend
= fixp
->fx_addnumber
;
2199 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2201 if (rel
->howto
== NULL
)
2203 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2204 _("Cannot represent relocation type %s"),
2205 bfd_get_reloc_code_name (code
));
2207 /* Set howto to a garbage value so that we can keep going. */
2208 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2209 gas_assert (rel
->howto
!= NULL
);
2216 /* See whether we need to force a relocation into the output file.
2217 This is used to force out switch and PC relative relocations when
2220 mcore_force_relocation (fixS
* fix
)
2222 if (fix
->fx_r_type
== BFD_RELOC_RVA
)
2225 return generic_force_reloc (fix
);
2228 /* Return true if the fix can be handled by GAS, false if it must
2229 be passed through to the linker. */
2232 mcore_fix_adjustable (fixS
* fixP
)
2234 /* We need the symbol name for the VTABLE entries. */
2235 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2236 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2241 #endif /* OBJ_ELF */