1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007
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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA
25 #include "../opcodes/mcore-opc.h"
26 #include "safe-ctype.h"
29 #include "elf/mcore.h"
33 #define streq(a,b) (strcmp (a, b) == 0)
36 /* Forward declarations for dumb compilers. */
38 /* Several places in this file insert raw instructions into the
39 object. They should use MCORE_INST_XXX macros to get the opcodes
40 and then use these two macros to crack the MCORE_INST value into
41 the appropriate byte values. */
42 #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
43 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF))
45 const char comment_chars
[] = "#/";
46 const char line_separator_chars
[] = ";";
47 const char line_comment_chars
[] = "#/";
49 static int do_jsri2bsr
= 0; /* Change here from 1 by Cruess 19 August 97. */
50 static int sifilter_mode
= 0;
52 const char EXP_CHARS
[] = "eE";
54 /* Chars that mean this number is a floating point constant
57 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
59 #define C(what,length) (((what) << 2) + (length))
60 #define GET_WHAT(x) ((x >> 2))
62 /* These are the two types of relaxable instruction. */
69 #define UNDEF_WORD_DISP 3
72 #define C32_LEN 10 /* Allow for align. */
74 #define U32_LEN 8 /* Allow for align. */
85 /* Initialize the relax table. */
86 const relax_typeS md_relax_table
[] =
94 { 0, 0, 0, 0 }, /* UNDEF_DISP */
95 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* DISP12 */
96 { 0, 0, C32_LEN
, 0 }, /* DISP32 */
97 { 0, 0, C32_LEN
, 0 }, /* UNDEF_WORD_DISP */
100 { 0, 0, 0, 0 }, /* UNDEF_DISP */
101 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* DISP12 */
102 { 0, 0, U32_LEN
, 0 }, /* DISP32 */
103 { 0, 0, U32_LEN
, 0 } /* UNDEF_WORD_DISP */
107 /* Literal pool data structures. */
110 unsigned short refcnt
;
111 unsigned char ispcrel
;
112 unsigned char unused
;
116 #define MAX_POOL_SIZE (1024/4)
117 static struct literal litpool
[MAX_POOL_SIZE
];
118 static unsigned poolsize
;
119 static unsigned poolnumber
;
120 static unsigned long poolspan
;
122 /* SPANPANIC: the point at which we get too scared and force a dump
123 of the literal pool, and perhaps put a branch in place.
125 1024 span of lrw/jmpi/jsri insn (actually span+1)
126 -2 possible alignment at the insn.
127 -2 possible alignment to get the table aligned.
128 -2 an inserted branch around the table.
130 at 1018, we might be in trouble.
131 -- so we have to be smaller than 1018 and since we deal with 2-byte
132 instructions, the next good choice is 1016.
133 -- Note we have a test case that fails when we've got 1018 here. */
134 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
135 #define SPANCLOSE (900)
136 #define SPANEXIT (600)
137 static symbolS
* poolsym
; /* Label for current pool. */
138 static char poolname
[8];
139 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
141 #define POOL_END_LABEL ".LE"
142 #define POOL_START_LABEL ".LS"
145 make_name (char * s
, char * p
, int n
)
147 static const char hex
[] = "0123456789ABCDEF";
152 s
[3] = hex
[(n
>> 12) & 0xF];
153 s
[4] = hex
[(n
>> 8) & 0xF];
154 s
[5] = hex
[(n
>> 4) & 0xF];
155 s
[6] = hex
[(n
) & 0xF];
160 dump_literals (int isforce
)
164 symbolS
* brarsym
= NULL
;
169 /* Must we branch around the literal table? */
175 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
177 brarsym
= symbol_make (brarname
);
179 symbol_table_insert (brarsym
);
181 output
= frag_var (rs_machine_dependent
,
182 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
183 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
184 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
185 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
186 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
189 /* Make sure that the section is sufficiently aligned and that
190 the literal table is aligned within it. */
191 record_alignment (now_seg
, 2);
192 frag_align (2, 0, 0);
194 colon (S_GET_NAME (poolsym
));
196 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
197 emit_expr (& p
->e
, 4);
200 colon (S_GET_NAME (brarsym
));
206 mcore_s_literals (int ignore ATTRIBUTE_UNUSED
)
209 demand_empty_rest_of_line ();
212 /* Perform FUNC (ARG), and track number of bytes added to frag. */
215 mcore_pool_count (void (*func
) (int), int arg
)
217 const fragS
*curr_frag
= frag_now
;
218 offsetT added
= -frag_now_fix_octets ();
222 while (curr_frag
!= frag_now
)
224 added
+= curr_frag
->fr_fix
;
225 curr_frag
= curr_frag
->fr_next
;
228 added
+= frag_now_fix_octets ();
233 check_literals (int kind
, int offset
)
237 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
238 SPANPANIC means that we must dump now.
239 kind == 0 is any old instruction.
240 kind > 0 means we just had a control transfer instruction.
241 kind == 1 means within a function
242 kind == 2 means we just left a function
244 The dump_literals (1) call inserts a branch around the table, so
245 we first look to see if its a situation where we won't have to
246 insert a branch (e.g., the previous instruction was an unconditional
249 SPANPANIC is the point where we must dump a single-entry pool.
250 it accounts for alignments and an inserted branch.
251 the 'poolsize*2' accounts for the scenario where we do:
252 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
253 Note that the 'lit2' reference is 2 bytes further along
254 but the literal it references will be 4 bytes further along,
255 so we must consider the poolsize into this equation.
256 This is slightly over-cautious, but guarantees that we won't
257 panic because a relocation is too distant. */
259 if (poolspan
> SPANCLOSE
&& kind
> 0)
261 else if (poolspan
> SPANEXIT
&& kind
> 1)
263 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
268 mcore_cons (int nbytes
)
270 if (now_seg
== text_section
)
271 mcore_pool_count (cons
, nbytes
);
275 /* In theory we ought to call check_literals (2,0) here in case
276 we need to dump the literal table. We cannot do this however,
277 as the directives that we are intercepting may be being used
278 to build a switch table, and we must not interfere with its
279 contents. Instead we cross our fingers and pray... */
283 mcore_float_cons (int float_type
)
285 if (now_seg
== text_section
)
286 mcore_pool_count (float_cons
, float_type
);
288 float_cons (float_type
);
290 /* See the comment in mcore_cons () about calling check_literals.
291 It is unlikely that a switch table will be constructed using
292 floating point values, but it is still likely that an indexed
293 table of floating point constants is being created by these
294 directives, so again we must not interfere with their placement. */
298 mcore_stringer (int append_zero
)
300 if (now_seg
== text_section
)
301 mcore_pool_count (stringer
, append_zero
);
303 stringer (append_zero
);
305 /* We call check_literals here in case a large number of strings are
306 being placed into the text section with a sequence of stringer
307 directives. In theory we could be upsetting something if these
308 strings are actually in an indexed table instead of referenced by
309 individual labels. Let us hope that that never happens. */
310 check_literals (2, 0);
314 mcore_fill (int unused
)
316 if (now_seg
== text_section
)
317 mcore_pool_count (s_fill
, unused
);
321 check_literals (2, 0);
324 /* Handle the section changing pseudo-ops. These call through to the
325 normal implementations, but they dump the literal pool first. */
328 mcore_s_text (int ignore
)
333 obj_elf_text (ignore
);
340 mcore_s_data (int ignore
)
345 obj_elf_data (ignore
);
352 mcore_s_section (int ignore
)
354 /* Scan forwards to find the name of the section. If the section
355 being switched to is ".line" then this is a DWARF1 debug section
356 which is arbitrarily placed inside generated code. In this case
357 do not dump the literal pool because it is a) inefficient and
358 b) would require the generation of extra code to jump around the
360 char * ilp
= input_line_pointer
;
362 while (*ilp
!= 0 && ISSPACE (*ilp
))
365 if (strncmp (ilp
, ".line", 5) == 0
366 && (ISSPACE (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
372 obj_elf_section (ignore
);
375 obj_coff_section (ignore
);
380 mcore_s_bss (int needs_align
)
384 s_lcomm_bytes (needs_align
);
389 mcore_s_comm (int needs_align
)
393 obj_elf_common (needs_align
);
397 /* This table describes all the machine specific pseudo-ops the assembler
398 has to support. The fields are:
399 Pseudo-op name without dot
400 Function to call to execute this pseudo-op
401 Integer arg to pass to the function. */
402 const pseudo_typeS md_pseudo_table
[] =
404 { "export", s_globl
, 0 },
405 { "import", s_ignore
, 0 },
406 { "literals", mcore_s_literals
, 0 },
407 { "page", listing_eject
, 0 },
409 /* The following are to intercept the placement of data into the text
410 section (eg addresses for a switch table), so that the space they
411 occupy can be taken into account when deciding whether or not to
412 dump the current literal pool.
413 XXX - currently we do not cope with the .space and .dcb.d directives. */
414 { "ascii", mcore_stringer
, 0 },
415 { "asciz", mcore_stringer
, 1 },
416 { "byte", mcore_cons
, 1 },
417 { "dc", mcore_cons
, 2 },
418 { "dc.b", mcore_cons
, 1 },
419 { "dc.d", mcore_float_cons
, 'd'},
420 { "dc.l", mcore_cons
, 4 },
421 { "dc.s", mcore_float_cons
, 'f'},
422 { "dc.w", mcore_cons
, 2 },
423 { "dc.x", mcore_float_cons
, 'x'},
424 { "double", mcore_float_cons
, 'd'},
425 { "float", mcore_float_cons
, 'f'},
426 { "hword", mcore_cons
, 2 },
427 { "int", mcore_cons
, 4 },
428 { "long", mcore_cons
, 4 },
429 { "octa", mcore_cons
, 16 },
430 { "quad", mcore_cons
, 8 },
431 { "short", mcore_cons
, 2 },
432 { "single", mcore_float_cons
, 'f'},
433 { "string", mcore_stringer
, 1 },
434 { "word", mcore_cons
, 2 },
435 { "fill", mcore_fill
, 0 },
437 /* Allow for the effect of section changes. */
438 { "text", mcore_s_text
, 0 },
439 { "data", mcore_s_data
, 0 },
440 { "bss", mcore_s_bss
, 1 },
442 { "comm", mcore_s_comm
, 0 },
444 { "section", mcore_s_section
, 0 },
445 { "section.s", mcore_s_section
, 0 },
446 { "sect", mcore_s_section
, 0 },
447 { "sect.s", mcore_s_section
, 0 },
452 /* This function is called once, at assembler startup time. This should
453 set up all the tables, etc that the MD part of the assembler needs. */
458 const mcore_opcode_info
* opcode
;
459 char * prev_name
= "";
461 opcode_hash_control
= hash_new ();
463 /* Insert unique names into hash table. */
464 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
466 if (! streq (prev_name
, opcode
->name
))
468 prev_name
= opcode
->name
;
469 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
474 /* Get a log2(val). */
477 mylog2 (unsigned int val
)
490 /* Try to parse a reg name. */
493 parse_reg (char * s
, unsigned * reg
)
495 /* Strip leading whitespace. */
496 while (ISSPACE (* s
))
499 if (TOLOWER (s
[0]) == 'r')
501 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
503 *reg
= 10 + s
[2] - '0';
507 if (s
[1] >= '0' && s
[1] <= '9')
513 else if ( TOLOWER (s
[0]) == 's'
514 && TOLOWER (s
[1]) == 'p'
521 as_bad (_("register expected, but saw '%.6s'"), s
);
549 parse_creg (char * s
, unsigned * reg
)
553 /* Strip leading whitespace. */
554 while (ISSPACE (* s
))
557 if ((TOLOWER (s
[0]) == 'c' && TOLOWER (s
[1]) == 'r'))
559 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
561 *reg
= 30 + s
[3] - '0';
565 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
567 *reg
= 20 + s
[3] - '0';
571 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
573 *reg
= 10 + s
[3] - '0';
577 if (s
[2] >= '0' && s
[2] <= '9')
584 /* Look at alternate creg names before giving error. */
585 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
591 length
= strlen (cregs
[i
].name
);
593 for (j
= 0; j
< length
; j
++)
594 buf
[j
] = TOLOWER (s
[j
]);
596 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
598 *reg
= cregs
[i
].crnum
;
603 as_bad (_("control register expected, but saw '%.6s'"), s
);
609 parse_psrmod (char * s
, unsigned * reg
)
613 static struct psrmods
623 { "af", 8 } /* Really 0 and non-combinable. */
626 for (i
= 0; i
< 2; i
++)
627 buf
[i
] = TOLOWER (s
[i
]);
629 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
631 if (! strncmp (psrmods
[i
].name
, buf
, 2))
633 * reg
= psrmods
[i
].value
;
639 as_bad (_("bad/missing psr specifier"));
647 parse_exp (char * s
, expressionS
* e
)
652 /* Skip whitespace. */
653 while (ISSPACE (* s
))
656 save
= input_line_pointer
;
657 input_line_pointer
= s
;
661 if (e
->X_op
== O_absent
)
662 as_bad (_("missing operand"));
664 new = input_line_pointer
;
665 input_line_pointer
= save
;
671 enter_literal (expressionS
* e
, int ispcrel
)
676 if (poolsize
>= MAX_POOL_SIZE
- 2)
677 /* The literal pool is as full as we can handle. We have
678 to be 2 entries shy of the 1024/4=256 entries because we
679 have to allow for the branch (2 bytes) and the alignment
680 (2 bytes before the first insn referencing the pool and
681 2 bytes before the pool itself) == 6 bytes, rounds up
687 /* Create new literal pool. */
688 if (++ poolnumber
> 0xFFFF)
689 as_fatal (_("more than 65K literal pools"));
691 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
692 poolsym
= symbol_make (poolname
);
693 symbol_table_insert (poolsym
);
697 /* Search pool for value so we don't have duplicates. */
698 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
700 if (e
->X_op
== p
->e
.X_op
701 && e
->X_add_symbol
== p
->e
.X_add_symbol
702 && e
->X_add_number
== p
->e
.X_add_number
703 && ispcrel
== p
->ispcrel
)
711 p
->ispcrel
= ispcrel
;
719 /* Parse a literal specification. -- either new or old syntax.
720 old syntax: the user supplies the label and places the literal.
721 new syntax: we put it into the literal pool. */
733 /* Indicate nothing there. */
738 s
= parse_exp (s
+ 1, & e
);
743 as_bad (_("missing ']'"));
747 s
= parse_exp (s
, & e
);
749 n
= enter_literal (& e
, ispcrel
);
754 /* Create a reference to pool entry. */
756 e
.X_add_symbol
= poolsym
;
757 e
.X_add_number
= n
<< 2;
760 * outputp
= frag_more (2);
762 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
763 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
777 new = parse_exp (s
, & e
);
779 if (e
.X_op
== O_absent
)
780 ; /* An error message has already been emitted. */
781 else if (e
.X_op
!= O_constant
)
782 as_bad (_("operand must be a constant"));
783 else if ((addressT
) e
.X_add_number
< min
|| (addressT
) e
.X_add_number
> max
)
784 as_bad (_("operand must be absolute in range %u..%u, not %ld"),
785 min
, max
, (long) e
.X_add_number
);
787 * val
= e
.X_add_number
;
800 while (ISSPACE (* s
))
805 s
= parse_reg (s
+ 1, reg
);
807 while (ISSPACE (* s
))
812 s
= parse_imm (s
+ 1, off
, 0, 63);
819 as_bad (_("operand must be a multiple of 4"));
826 as_bad (_("operand must be a multiple of 2"));
833 while (ISSPACE (* s
))
840 as_bad (_("base register expected"));
845 /* This is the guts of the machine-dependent assembler. STR points to a
846 machine dependent instruction. This function is supposed to emit
847 the frags/bytes it assembles to. */
850 md_assemble (char * str
)
854 mcore_opcode_info
* opcode
;
864 /* Drop leading whitespace. */
865 while (ISSPACE (* str
))
868 /* Find the op code end. */
869 for (op_start
= op_end
= str
;
870 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
873 name
[nlen
] = op_start
[nlen
];
881 as_bad (_("can't find opcode "));
885 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
888 as_bad (_("unknown opcode \"%s\""), name
);
895 switch (opcode
->opclass
)
898 output
= frag_more (2);
902 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
904 output
= frag_more (2);
908 op_end
= parse_reg (op_end
+ 1, & reg
);
910 output
= frag_more (2);
914 op_end
= parse_reg (op_end
+ 1, & reg
);
916 output
= frag_more (2);
917 /* In a sifilter mode, we emit this insn 2 times,
918 fixes problem of an interrupt during a jmp.. */
921 output
[0] = INST_BYTE0 (inst
);
922 output
[1] = INST_BYTE1 (inst
);
923 output
= frag_more (2);
928 op_end
= parse_reg (op_end
+ 1, & reg
);
931 as_bad (_("invalid register: r15 illegal"));
934 output
= frag_more (2);
938 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx. */
939 inst
= MCORE_INST_BSR
; /* With 0 displacement. */
940 output
[0] = INST_BYTE0 (inst
);
941 output
[1] = INST_BYTE1 (inst
);
943 output
= frag_more (2);
944 inst
= MCORE_INST_ADDI
;
945 inst
|= 15; /* addi r15,6 */
946 inst
|= (6 - 1) << 4; /* Over the jmp's. */
947 output
[0] = INST_BYTE0 (inst
);
948 output
[1] = INST_BYTE1 (inst
);
950 output
= frag_more (2);
951 inst
= MCORE_INST_JMP
| reg
;
952 output
[0] = INST_BYTE0 (inst
);
953 output
[1] = INST_BYTE1 (inst
);
955 /* 2nd emitted in fallthrough. */
956 output
= frag_more (2);
961 op_end
= parse_reg (op_end
+ 1, & reg
);
964 /* Skip whitespace. */
965 while (ISSPACE (* op_end
))
970 op_end
= parse_creg (op_end
+ 1, & reg
);
974 output
= frag_more (2);
980 as_bad (_("M340 specific opcode used when assembling for M210"));
983 /* drop through... */
985 op_end
= parse_reg (op_end
+ 1, & reg
);
988 /* Skip whitespace. */
989 while (ISSPACE (* op_end
))
994 op_end
= parse_reg (op_end
+ 1, & reg
);
998 as_bad (_("second operand missing"));
1000 output
= frag_more (2);
1004 /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx. */
1005 op_end
= parse_reg (op_end
+ 1, & reg
);
1007 /* Skip whitespace. */
1008 while (ISSPACE (* op_end
))
1011 if (* op_end
== ',') /* xtrb- r1,rx. */
1014 as_bad (_("destination register must be r1"));
1016 op_end
= parse_reg (op_end
+ 1, & reg
);
1020 output
= frag_more (2);
1023 case O1R1
: /* div- rx,r1. */
1024 op_end
= parse_reg (op_end
+ 1, & reg
);
1027 /* Skip whitespace. */
1028 while (ISSPACE (* op_end
))
1031 if (* op_end
== ',')
1033 op_end
= parse_reg (op_end
+ 1, & reg
);
1035 as_bad (_("source register must be r1"));
1038 as_bad (_("second operand missing"));
1040 output
= frag_more (2);
1044 op_end
= parse_reg (op_end
+ 1, & reg
);
1047 /* Skip whitespace. */
1048 while (ISSPACE (* op_end
))
1051 if (* op_end
== ',')
1053 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1054 inst
|= (reg
- 1) << 4;
1057 as_bad (_("second operand missing"));
1059 output
= frag_more (2);
1063 op_end
= parse_reg (op_end
+ 1, & reg
);
1066 /* Skip whitespace. */
1067 while (ISSPACE (* op_end
))
1070 if (* op_end
== ',')
1072 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1076 as_bad (_("second operand missing"));
1078 output
= frag_more (2);
1082 /* Like OB, but arg is 2^n instead of n. */
1083 op_end
= parse_reg (op_end
+ 1, & reg
);
1086 /* Skip whitespace. */
1087 while (ISSPACE (* op_end
))
1090 if (* op_end
== ',')
1092 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1093 /* Further restrict the immediate to a power of two. */
1094 if ((reg
& (reg
- 1)) == 0)
1099 as_bad (_("immediate is not a power of two"));
1104 as_bad (_("second operand missing"));
1106 output
= frag_more (2);
1109 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1112 op_end
= parse_reg (op_end
+ 1, & reg
);
1115 /* Skip whitespace. */
1116 while (ISSPACE (* op_end
))
1119 if (* op_end
== ',')
1121 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1122 /* Immediate values of 0 -> 6 translate to movi. */
1125 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1127 as_warn (_("translating bgeni to movi"));
1133 as_bad (_("second operand missing"));
1135 output
= frag_more (2);
1138 case OBR2
: /* Like OBR, but arg is 2^n instead of n. */
1139 op_end
= parse_reg (op_end
+ 1, & reg
);
1142 /* Skip whitespace. */
1143 while (ISSPACE (* op_end
))
1146 if (* op_end
== ',')
1148 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1150 /* Further restrict the immediate to a power of two. */
1151 if ((reg
& (reg
- 1)) == 0)
1156 as_bad (_("immediate is not a power of two"));
1159 /* Immediate values of 0 -> 6 translate to movi. */
1162 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1164 as_warn (_("translating mgeni to movi"));
1170 as_bad (_("second operand missing"));
1172 output
= frag_more (2);
1175 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1178 op_end
= parse_reg (op_end
+ 1, & reg
);
1181 /* Skip whitespace. */
1182 while (ISSPACE (* op_end
))
1185 if (* op_end
== ',')
1187 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1189 /* Immediate values of 1 -> 7 translate to movi. */
1192 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1193 reg
= (0x1 << reg
) - 1;
1196 as_warn (_("translating bmaski to movi"));
1201 inst
|= (reg
& 0x1F) << 4;
1205 as_bad (_("second operand missing"));
1207 output
= frag_more (2);
1211 op_end
= parse_reg (op_end
+ 1, & reg
);
1214 /* Skip whitespace. */
1215 while (ISSPACE (* op_end
))
1218 if (* op_end
== ',')
1220 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1224 as_bad (_("second operand missing"));
1226 output
= frag_more (2);
1230 op_end
= parse_reg (op_end
+ 1, & reg
);
1233 /* Skip whitespace. */
1234 while (ISSPACE (* op_end
))
1237 if (* op_end
== ',')
1239 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1243 as_bad (_("second operand missing"));
1245 output
= frag_more (2);
1249 op_end
= parse_reg (op_end
+ 1, & reg
);
1252 /* Skip whitespace. */
1253 while (ISSPACE (* op_end
))
1256 if (* op_end
== ',')
1260 if ((inst
& 0x6000) == 0)
1262 else if ((inst
& 0x6000) == 0x4000)
1264 else if ((inst
& 0x6000) == 0x2000)
1269 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1272 as_bad (_("displacement too large (%d)"), off
);
1274 inst
|= (reg
) | (off
<< 4);
1277 as_bad (_("second operand missing"));
1279 output
= frag_more (2);
1283 op_end
= parse_reg (op_end
+ 1, & reg
);
1285 if (reg
== 0 || reg
== 15)
1286 as_bad (_("Invalid register: r0 and r15 illegal"));
1290 /* Skip whitespace. */
1291 while (ISSPACE (* op_end
))
1294 if (* op_end
== ',')
1296 /* parse_rt calls frag_more() for us. */
1297 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1298 op_end
= input_line_pointer
;
1302 as_bad (_("second operand missing"));
1303 output
= frag_more (2); /* save its space */
1308 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1309 /* parse_rt() calls frag_more() for us. */
1310 op_end
= input_line_pointer
;
1314 op_end
= parse_reg (op_end
+ 1, & reg
);
1316 if (reg
== 0 || reg
== 15)
1317 as_bad (_("bad starting register: r0 and r15 invalid"));
1321 /* Skip whitespace. */
1322 while (ISSPACE (* op_end
))
1325 if (* op_end
== '-')
1327 op_end
= parse_reg (op_end
+ 1, & reg
);
1330 as_bad (_("ending register must be r15"));
1332 /* Skip whitespace. */
1333 while (ISSPACE (* op_end
))
1337 if (* op_end
== ',')
1341 /* Skip whitespace. */
1342 while (ISSPACE (* op_end
))
1345 if (* op_end
== '(')
1347 op_end
= parse_reg (op_end
+ 1, & reg
);
1350 as_bad (_("bad base register: must be r0"));
1352 if (* op_end
== ')')
1356 as_bad (_("base register expected"));
1359 as_bad (_("second operand missing"));
1361 output
= frag_more (2);
1365 op_end
= parse_reg (op_end
+ 1, & reg
);
1368 as_fatal (_("first register must be r4"));
1370 /* Skip whitespace. */
1371 while (ISSPACE (* op_end
))
1374 if (* op_end
== '-')
1376 op_end
= parse_reg (op_end
+ 1, & reg
);
1379 as_fatal (_("last register must be r7"));
1381 /* Skip whitespace. */
1382 while (ISSPACE (* op_end
))
1385 if (* op_end
== ',')
1389 /* Skip whitespace. */
1390 while (ISSPACE (* op_end
))
1393 if (* op_end
== '(')
1395 op_end
= parse_reg (op_end
+ 1, & reg
);
1397 if (reg
>= 4 && reg
<= 7)
1398 as_fatal ("base register cannot be r4, r5, r6, or r7");
1402 /* Skip whitespace. */
1403 while (ISSPACE (* op_end
))
1406 if (* op_end
== ')')
1410 as_bad (_("base register expected"));
1413 as_bad (_("second operand missing"));
1416 as_bad (_("reg-reg expected"));
1418 output
= frag_more (2);
1422 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1423 op_end
= input_line_pointer
;
1425 output
= frag_more (2);
1427 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1428 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1432 op_end
= parse_reg (op_end
+ 1, & reg
);
1435 /* Skip whitespace. */
1436 while (ISSPACE (* op_end
))
1439 if (* op_end
== ',')
1441 op_end
= parse_exp (op_end
+ 1, & e
);
1442 output
= frag_more (2);
1444 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1445 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1449 as_bad (_("second operand missing"));
1450 output
= frag_more (2);
1455 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1456 op_end
= input_line_pointer
;
1458 output
= frag_var (rs_machine_dependent
,
1459 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1460 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1461 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1466 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1467 op_end
= input_line_pointer
;
1469 output
= frag_var (rs_machine_dependent
,
1470 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1471 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1472 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1477 inst
= MCORE_INST_JSRI
; /* jsri */
1478 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1479 /* parse_rt() calls frag_more for us. */
1480 op_end
= input_line_pointer
;
1482 /* Only do this if we know how to do it ... */
1483 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1485 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1486 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1487 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1492 /* SI, but imm becomes 32-imm. */
1493 op_end
= parse_reg (op_end
+ 1, & reg
);
1496 /* Skip whitespace. */
1497 while (ISSPACE (* op_end
))
1500 if (* op_end
== ',')
1502 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1508 as_bad (_("second operand missing"));
1510 output
= frag_more (2);
1513 case DO21
: /* O2, dup rd, lit must be 1 */
1514 op_end
= parse_reg (op_end
+ 1, & reg
);
1518 /* Skip whitespace. */
1519 while (ISSPACE (* op_end
))
1522 if (* op_end
== ',')
1524 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1527 as_bad (_("second operand must be 1"));
1530 as_bad (_("second operand missing"));
1532 output
= frag_more (2);
1536 op_end
= parse_reg (op_end
+ 1, & reg
);
1539 /* Skip whitespace. */
1540 while (ISSPACE (* op_end
))
1543 if (* op_end
== ',')
1545 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1548 as_bad (_("zero used as immediate value"));
1553 as_bad (_("second operand missing"));
1555 output
= frag_more (2);
1561 as_bad (_("M340 specific opcode used when assembling for M210"));
1565 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1567 /* Look for further selectors. */
1568 while (* op_end
== ',')
1572 op_end
= parse_psrmod (op_end
+ 1, & value
);
1575 as_bad (_("duplicated psr bit specifier"));
1581 as_bad (_("`af' must appear alone"));
1583 inst
|= (reg
& 0x7);
1584 output
= frag_more (2);
1588 as_bad (_("unimplemented opcode \"%s\""), name
);
1591 /* Drop whitespace after all the operands have been parsed. */
1592 while (ISSPACE (* op_end
))
1595 /* Give warning message if the insn has more operands than required. */
1596 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1597 as_warn (_("ignoring operands: %s "), op_end
);
1599 output
[0] = INST_BYTE0 (inst
);
1600 output
[1] = INST_BYTE1 (inst
);
1602 check_literals (opcode
->transfer
, isize
);
1606 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1615 subseg_set (text_section
, 0);
1618 /* Various routines to kill one day. */
1619 /* Equal to MAX_PRECISION in atof-ieee.c. */
1620 #define MAX_LITTLENUMS 6
1622 /* Turn a string in input_line_pointer into a floating point constant of type
1623 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1624 emitted is stored in *sizeP. An error message is returned, or NULL on OK. */
1627 md_atof (int type
, char * litP
, int * sizeP
)
1630 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1662 return _("Bad call to MD_NTOF()");
1665 t
= atof_ieee (input_line_pointer
, type
, words
);
1668 input_line_pointer
= t
;
1670 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1672 if (! target_big_endian
)
1674 for (i
= prec
- 1; i
>= 0; i
--)
1676 md_number_to_chars (litP
, (valueT
) words
[i
],
1677 sizeof (LITTLENUM_TYPE
));
1678 litP
+= sizeof (LITTLENUM_TYPE
);
1682 for (i
= 0; i
< prec
; i
++)
1684 md_number_to_chars (litP
, (valueT
) words
[i
],
1685 sizeof (LITTLENUM_TYPE
));
1686 litP
+= sizeof (LITTLENUM_TYPE
);
1692 const char * md_shortopts
= "";
1696 OPTION_JSRI2BSR_ON
= OPTION_MD_BASE
,
1697 OPTION_JSRI2BSR_OFF
,
1699 OPTION_SIFILTER_OFF
,
1705 struct option md_longopts
[] =
1707 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1708 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1709 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1710 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1711 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1712 { "EB", no_argument
, NULL
, OPTION_EB
},
1713 { "EL", no_argument
, NULL
, OPTION_EL
},
1714 { NULL
, no_argument
, NULL
, 0}
1717 size_t md_longopts_size
= sizeof (md_longopts
);
1720 md_parse_option (int c
, char * arg
)
1725 if (streq (arg
, "210"))
1728 target_big_endian
= 1;
1730 else if (streq (arg
, "340"))
1733 as_warn (_("unrecognised cpu type '%s'"), arg
);
1736 case OPTION_EB
: target_big_endian
= 1; break;
1737 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1738 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1739 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1740 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1741 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1749 md_show_usage (FILE * stream
)
1751 fprintf (stream
, _("\
1752 MCORE specific options:\n\
1753 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1754 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1755 -cpu=[210|340] select CPU type\n\
1756 -EB assemble for a big endian system (default)\n\
1757 -EL assemble for a little endian system\n"));
1760 int md_short_jump_size
;
1763 md_create_short_jump (char * ptr ATTRIBUTE_UNUSED
,
1764 addressT from_Nddr ATTRIBUTE_UNUSED
,
1765 addressT to_Nddr ATTRIBUTE_UNUSED
,
1766 fragS
* frag ATTRIBUTE_UNUSED
,
1767 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1769 as_fatal (_("failed sanity check: short_jump"));
1773 md_create_long_jump (char * ptr ATTRIBUTE_UNUSED
,
1774 addressT from_Nddr ATTRIBUTE_UNUSED
,
1775 addressT to_Nddr ATTRIBUTE_UNUSED
,
1776 fragS
* frag ATTRIBUTE_UNUSED
,
1777 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1779 as_fatal (_("failed sanity check: long_jump"));
1782 /* Called after relaxing, change the frags so they know how big they are. */
1785 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1786 segT sec ATTRIBUTE_UNUSED
,
1790 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1792 buffer
= fragP
->fr_fix
+ fragP
->fr_literal
;
1794 switch (fragP
->fr_subtype
)
1796 case C (COND_JUMP
, DISP12
):
1797 case C (UNCD_JUMP
, DISP12
):
1799 /* Get the address of the end of the instruction. */
1800 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1802 int disp
= targ_addr
- next_inst
;
1805 as_bad (_("odd displacement at %x"), next_inst
- 2);
1809 if (! target_big_endian
)
1811 t0
= buffer
[1] & 0xF8;
1813 md_number_to_chars (buffer
, disp
, 2);
1815 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1819 t0
= buffer
[0] & 0xF8;
1821 md_number_to_chars (buffer
, disp
, 2);
1823 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1830 case C (COND_JUMP
, DISP32
):
1831 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1833 /* A conditional branch wont fit into 12 bits so:
1840 If the b!cond is 4 byte aligned, the literal which would
1841 go at x+4 will also be aligned. */
1842 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1843 int needpad
= (first_inst
& 3);
1845 if (! target_big_endian
)
1848 buffer
[0] ^= 0x08; /* Toggle T/F bit. */
1850 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1851 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1855 if (! target_big_endian
)
1857 buffer
[0] = 4; /* Branch over jmpi, pad, and ptr. */
1858 buffer
[2] = 1; /* Jmpi offset of 1 gets the pointer. */
1862 buffer
[1] = 4; /* Branch over jmpi, pad, and ptr. */
1863 buffer
[3] = 1; /* Jmpi offset of 1 gets the pointer. */
1866 buffer
[4] = 0; /* Alignment/pad. */
1868 buffer
[6] = 0; /* Space for 32 bit address. */
1873 /* Make reloc for the long disp. */
1874 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1875 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1877 fragP
->fr_fix
+= C32_LEN
;
1881 /* See comment below about this given gas' limitations for
1882 shrinking the fragment. '3' is the amount of code that
1883 we inserted here, but '4' is right for the space we reserved
1884 for this fragment. */
1885 if (! target_big_endian
)
1887 buffer
[0] = 3; /* Branch over jmpi, and ptr. */
1888 buffer
[2] = 0; /* Jmpi offset of 0 gets the pointer. */
1892 buffer
[1] = 3; /* Branch over jmpi, and ptr. */
1893 buffer
[3] = 0; /* Jmpi offset of 0 gets the pointer. */
1896 buffer
[4] = 0; /* Space for 32 bit address. */
1901 /* Make reloc for the long disp. */
1902 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1903 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1904 fragP
->fr_fix
+= C32_LEN
;
1906 /* Frag is actually shorter (see the other side of this ifdef)
1907 but gas isn't prepared for that. We have to re-adjust
1908 the branch displacement so that it goes beyond the
1909 full length of the fragment, not just what we actually
1911 if (! target_big_endian
)
1912 buffer
[0] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1914 buffer
[1] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1919 case C (UNCD_JUMP
, DISP32
):
1920 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1922 /* An unconditional branch will not fit in 12 bits, make code which
1927 we need a pad if "first_inst" is 4 byte aligned.
1928 [because the natural literal place is x + 2]. */
1929 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1930 int needpad
= !(first_inst
& 3);
1932 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1933 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1937 if (! target_big_endian
)
1938 buffer
[0] = 1; /* Jmpi offset of 1 since padded. */
1940 buffer
[1] = 1; /* Jmpi offset of 1 since padded. */
1941 buffer
[2] = 0; /* Alignment. */
1943 buffer
[4] = 0; /* Space for 32 bit address. */
1948 /* Make reloc for the long disp. */
1949 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1950 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1952 fragP
->fr_fix
+= U32_LEN
;
1956 if (! target_big_endian
)
1957 buffer
[0] = 0; /* Jmpi offset of 0 if no pad. */
1959 buffer
[1] = 0; /* Jmpi offset of 0 if no pad. */
1960 buffer
[2] = 0; /* Space for 32 bit address. */
1965 /* Make reloc for the long disp. */
1966 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1967 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1968 fragP
->fr_fix
+= U32_LEN
;
1978 /* Applies the desired value to the specified location.
1979 Also sets up addends for 'rela' type relocations. */
1982 md_apply_fix (fixS
* fixP
,
1984 segT segment ATTRIBUTE_UNUSED
)
1986 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1987 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1988 const char * symname
;
1989 /* Note: use offsetT because it is signed, valueT is unsigned. */
1990 offsetT val
= *valP
;
1992 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1993 /* Save this for the addend in the relocation record. */
1994 fixP
->fx_addnumber
= val
;
1996 if (fixP
->fx_addsy
!= NULL
)
1999 /* For ELF we can just return and let the reloc that will be generated
2000 take care of everything. For COFF we still have to insert 'val'
2001 into the insn since the addend field will be ignored. */
2008 switch (fixP
->fx_r_type
)
2010 /* Second byte of 2 byte opcode. */
2011 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2013 as_bad_where (file
, fixP
->fx_line
,
2014 _("odd distance branch (0x%lx bytes)"), (long) val
);
2016 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2017 as_bad_where (file
, fixP
->fx_line
,
2018 _("pcrel for branch to %s too far (0x%lx)"),
2019 symname
, (long) val
);
2020 if (target_big_endian
)
2022 buf
[0] |= ((val
>> 8) & 0x7);
2023 buf
[1] |= (val
& 0xff);
2027 buf
[1] |= ((val
>> 8) & 0x7);
2028 buf
[0] |= (val
& 0xff);
2032 /* Lower 8 bits of 2 byte opcode. */
2033 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2037 as_bad_where (file
, fixP
->fx_line
,
2038 _("pcrel for lrw/jmpi/jsri to %s too far (0x%lx)"),
2039 symname
, (long) val
);
2040 else if (! target_big_endian
)
2041 buf
[0] |= (val
& 0xff);
2043 buf
[1] |= (val
& 0xff);
2046 /* Loopt instruction. */
2047 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2048 if ((val
< -32) || (val
> -2))
2049 as_bad_where (file
, fixP
->fx_line
,
2050 _("pcrel for loopt too far (0x%lx)"), (long) val
);
2052 if (! target_big_endian
)
2053 buf
[0] |= (val
& 0xf);
2055 buf
[1] |= (val
& 0xf);
2058 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2059 /* Conditional linker map jsri to bsr. */
2060 /* If its a local target and close enough, fix it.
2061 NB: >= -2k for backwards bsr; < 2k for forwards... */
2062 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2064 long nval
= (val
/ 2) & 0x7ff;
2065 nval
|= MCORE_INST_BSR
;
2067 /* REPLACE the instruction, don't just modify it. */
2068 buf
[0] = INST_BYTE0 (nval
);
2069 buf
[1] = INST_BYTE1 (nval
);
2075 case BFD_RELOC_MCORE_PCREL_32
:
2076 case BFD_RELOC_VTABLE_INHERIT
:
2077 case BFD_RELOC_VTABLE_ENTRY
:
2082 if (fixP
->fx_addsy
!= NULL
)
2084 /* If the fix is an absolute reloc based on a symbol's
2085 address, then it cannot be resolved until the final link. */
2092 if (fixP
->fx_size
== 4)
2094 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2096 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2100 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2107 md_operand (expressionS
* expressionP
)
2109 /* Ignore leading hash symbol, if poresent. */
2110 if (* input_line_pointer
== '#')
2112 input_line_pointer
++;
2113 expression (expressionP
);
2117 int md_long_jump_size
;
2119 /* Called just before address relaxation, return the length
2120 by which a fragment must grow to reach it's destination. */
2122 md_estimate_size_before_relax (fragS
* fragP
, segT segment_type
)
2124 switch (fragP
->fr_subtype
)
2129 case C (UNCD_JUMP
, UNDEF_DISP
):
2130 /* Used to be a branch to somewhere which was unknown. */
2131 if (!fragP
->fr_symbol
)
2132 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2133 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2134 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2136 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2139 case C (COND_JUMP
, UNDEF_DISP
):
2140 /* Used to be a branch to somewhere which was unknown. */
2141 if (fragP
->fr_symbol
2142 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2143 /* Got a symbol and it's defined in this segment, become byte
2144 sized - maybe it will fix up */
2145 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2146 else if (fragP
->fr_symbol
)
2147 /* Its got a segment, but its not ours, so it will always be long. */
2148 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2150 /* We know the abs value. */
2151 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2154 case C (UNCD_JUMP
, DISP12
):
2155 case C (UNCD_JUMP
, DISP32
):
2156 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2157 case C (COND_JUMP
, DISP12
):
2158 case C (COND_JUMP
, DISP32
):
2159 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2160 /* When relaxing a section for the second time, we don't need to
2161 do anything besides return the current size. */
2165 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2168 /* Put number into target byte order. */
2171 md_number_to_chars (char * ptr
, valueT use
, int nbytes
)
2173 if (target_big_endian
)
2174 number_to_chars_bigendian (ptr
, use
, nbytes
);
2176 number_to_chars_littleendian (ptr
, use
, nbytes
);
2179 /* Round up a section size to the appropriate boundary. */
2182 md_section_align (segT segment ATTRIBUTE_UNUSED
,
2185 /* Byte alignment is fine. */
2189 /* The location from which a PC relative jump should be calculated,
2190 given a PC relative reloc. */
2193 md_pcrel_from_section (fixS
* fixp
, segT sec ATTRIBUTE_UNUSED
)
2196 /* If the symbol is undefined or defined in another section
2197 we leave the add number alone for the linker to fix it later.
2198 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2199 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2200 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2201 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2204 assert (fixp
->fx_size
== 2); /* must be an insn */
2205 return fixp
->fx_size
;
2209 /* The case where we are going to resolve things... */
2210 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2213 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2214 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2217 tc_gen_reloc (asection
* section ATTRIBUTE_UNUSED
, fixS
* fixp
)
2220 bfd_reloc_code_real_type code
;
2222 switch (fixp
->fx_r_type
)
2224 /* These confuse the size/pcrel macro approach. */
2225 case BFD_RELOC_VTABLE_INHERIT
:
2226 case BFD_RELOC_VTABLE_ENTRY
:
2227 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2228 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2229 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2230 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2232 code
= fixp
->fx_r_type
;
2236 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2238 MAP (1, 0, BFD_RELOC_8
);
2239 MAP (2, 0, BFD_RELOC_16
);
2240 MAP (4, 0, BFD_RELOC_32
);
2241 MAP (1, 1, BFD_RELOC_8_PCREL
);
2242 MAP (2, 1, BFD_RELOC_16_PCREL
);
2243 MAP (4, 1, BFD_RELOC_32_PCREL
);
2245 code
= fixp
->fx_r_type
;
2246 as_bad (_("Can not do %d byte %srelocation"),
2248 fixp
->fx_pcrel
? _("pc-relative") : "");
2253 rel
= xmalloc (sizeof (arelent
));
2254 rel
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2255 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2256 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2257 /* Always pass the addend along! */
2258 rel
->addend
= fixp
->fx_addnumber
;
2260 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2262 if (rel
->howto
== NULL
)
2264 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2265 _("Cannot represent relocation type %s"),
2266 bfd_get_reloc_code_name (code
));
2268 /* Set howto to a garbage value so that we can keep going. */
2269 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2270 assert (rel
->howto
!= NULL
);
2277 /* See whether we need to force a relocation into the output file.
2278 This is used to force out switch and PC relative relocations when
2281 mcore_force_relocation (fixS
* fix
)
2283 if (fix
->fx_r_type
== BFD_RELOC_RVA
)
2286 return generic_force_reloc (fix
);
2289 /* Return true if the fix can be handled by GAS, false if it must
2290 be passed through to the linker. */
2293 mcore_fix_adjustable (fixS
* fixP
)
2295 /* We need the symbol name for the VTABLE entries. */
2296 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2297 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2302 #endif /* OBJ_ELF */