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, 51 Franklin Street - Fifth Floor, 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. */
41 /* Several places in this file insert raw instructions into the
42 object. They should use MCORE_INST_XXX macros to get the opcodes
43 and then use these two macros to crack the MCORE_INST value into
44 the appropriate byte values. */
45 #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
46 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF))
48 const char comment_chars
[] = "#/";
49 const char line_separator_chars
[] = ";";
50 const char line_comment_chars
[] = "#/";
52 static int do_jsri2bsr
= 0; /* Change here from 1 by Cruess 19 August 97. */
53 static int sifilter_mode
= 0;
55 const char EXP_CHARS
[] = "eE";
57 /* Chars that mean this number is a floating point constant
60 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
62 #define C(what,length) (((what) << 2) + (length))
63 #define GET_WHAT(x) ((x >> 2))
65 /* These are the two types of relaxable instruction. */
72 #define UNDEF_WORD_DISP 3
75 #define C32_LEN 10 /* Allow for align. */
77 #define U32_LEN 8 /* Allow for align. */
88 /* Initialize the relax table. */
89 const relax_typeS md_relax_table
[] =
97 { 0, 0, 0, 0 }, /* UNDEF_DISP */
98 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* DISP12 */
99 { 0, 0, C32_LEN
, 0 }, /* DISP32 */
100 { 0, 0, C32_LEN
, 0 }, /* UNDEF_WORD_DISP */
103 { 0, 0, 0, 0 }, /* UNDEF_DISP */
104 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* DISP12 */
105 { 0, 0, U32_LEN
, 0 }, /* DISP32 */
106 { 0, 0, U32_LEN
, 0 } /* UNDEF_WORD_DISP */
110 /* Literal pool data structures. */
113 unsigned short refcnt
;
114 unsigned char ispcrel
;
115 unsigned char unused
;
119 #define MAX_POOL_SIZE (1024/4)
120 static struct literal litpool
[MAX_POOL_SIZE
];
121 static unsigned poolsize
;
122 static unsigned poolnumber
;
123 static unsigned long poolspan
;
125 /* SPANPANIC: the point at which we get too scared and force a dump
126 of the literal pool, and perhaps put a branch in place.
128 1024 span of lrw/jmpi/jsri insn (actually span+1)
129 -2 possible alignment at the insn.
130 -2 possible alignment to get the table aligned.
131 -2 an inserted branch around the table.
133 at 1018, we might be in trouble.
134 -- so we have to be smaller than 1018 and since we deal with 2-byte
135 instructions, the next good choice is 1016.
136 -- Note we have a test case that fails when we've got 1018 here. */
137 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
138 #define SPANCLOSE (900)
139 #define SPANEXIT (600)
140 static symbolS
* poolsym
; /* Label for current pool. */
141 static char poolname
[8];
142 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
144 #define POOL_END_LABEL ".LE"
145 #define POOL_START_LABEL ".LS"
148 make_name (char * s
, char * p
, int n
)
150 static const char hex
[] = "0123456789ABCDEF";
155 s
[3] = hex
[(n
>> 12) & 0xF];
156 s
[4] = hex
[(n
>> 8) & 0xF];
157 s
[5] = hex
[(n
>> 4) & 0xF];
158 s
[6] = hex
[(n
) & 0xF];
163 dump_literals (int isforce
)
167 symbolS
* brarsym
= NULL
;
172 /* Must we branch around the literal table? */
178 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
180 brarsym
= symbol_make (brarname
);
182 symbol_table_insert (brarsym
);
184 output
= frag_var (rs_machine_dependent
,
185 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
186 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
187 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
188 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
189 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
192 /* Make sure that the section is sufficiently aligned and that
193 the literal table is aligned within it. */
194 record_alignment (now_seg
, 2);
195 frag_align (2, 0, 0);
197 colon (S_GET_NAME (poolsym
));
199 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
200 emit_expr (& p
->e
, 4);
203 colon (S_GET_NAME (brarsym
));
209 mcore_s_literals (int ignore ATTRIBUTE_UNUSED
)
212 demand_empty_rest_of_line ();
215 /* Perform FUNC (ARG), and track number of bytes added to frag. */
218 mcore_pool_count (void (*func
) (int), int arg
)
220 const fragS
*curr_frag
= frag_now
;
221 offsetT added
= -frag_now_fix_octets ();
225 while (curr_frag
!= frag_now
)
227 added
+= curr_frag
->fr_fix
;
228 curr_frag
= curr_frag
->fr_next
;
231 added
+= frag_now_fix_octets ();
236 check_literals (int kind
, int offset
)
240 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
241 SPANPANIC means that we must dump now.
242 kind == 0 is any old instruction.
243 kind > 0 means we just had a control transfer instruction.
244 kind == 1 means within a function
245 kind == 2 means we just left a function
247 The dump_literals (1) call inserts a branch around the table, so
248 we first look to see if its a situation where we won't have to
249 insert a branch (e.g., the previous instruction was an unconditional
252 SPANPANIC is the point where we must dump a single-entry pool.
253 it accounts for alignments and an inserted branch.
254 the 'poolsize*2' accounts for the scenario where we do:
255 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
256 Note that the 'lit2' reference is 2 bytes further along
257 but the literal it references will be 4 bytes further along,
258 so we must consider the poolsize into this equation.
259 This is slightly over-cautious, but guarantees that we won't
260 panic because a relocation is too distant. */
262 if (poolspan
> SPANCLOSE
&& kind
> 0)
264 else if (poolspan
> SPANEXIT
&& kind
> 1)
266 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
271 mcore_cons (int nbytes
)
273 if (now_seg
== text_section
)
274 mcore_pool_count (cons
, nbytes
);
278 /* In theory we ought to call check_literals (2,0) here in case
279 we need to dump the literal table. We cannot do this however,
280 as the directives that we are intercepting may be being used
281 to build a switch table, and we must not interfere with its
282 contents. Instead we cross our fingers and pray... */
286 mcore_float_cons (int float_type
)
288 if (now_seg
== text_section
)
289 mcore_pool_count (float_cons
, float_type
);
291 float_cons (float_type
);
293 /* See the comment in mcore_cons () about calling check_literals.
294 It is unlikely that a switch table will be constructed using
295 floating point values, but it is still likely that an indexed
296 table of floating point constants is being created by these
297 directives, so again we must not interfere with their placement. */
301 mcore_stringer (int append_zero
)
303 if (now_seg
== text_section
)
304 mcore_pool_count (stringer
, append_zero
);
306 stringer (append_zero
);
308 /* We call check_literals here in case a large number of strings are
309 being placed into the text section with a sequence of stringer
310 directives. In theory we could be upsetting something if these
311 strings are actually in an indexed table instead of referenced by
312 individual labels. Let us hope that that never happens. */
313 check_literals (2, 0);
317 mcore_fill (int unused
)
319 if (now_seg
== text_section
)
320 mcore_pool_count (s_fill
, unused
);
324 check_literals (2, 0);
327 /* Handle the section changing pseudo-ops. These call through to the
328 normal implementations, but they dump the literal pool first. */
331 mcore_s_text (int ignore
)
336 obj_elf_text (ignore
);
343 mcore_s_data (int ignore
)
348 obj_elf_data (ignore
);
355 mcore_s_section (int ignore
)
357 /* Scan forwards to find the name of the section. If the section
358 being switched to is ".line" then this is a DWARF1 debug section
359 which is arbitrarily placed inside generated code. In this case
360 do not dump the literal pool because it is a) inefficient and
361 b) would require the generation of extra code to jump around the
363 char * ilp
= input_line_pointer
;
365 while (*ilp
!= 0 && ISSPACE (*ilp
))
368 if (strncmp (ilp
, ".line", 5) == 0
369 && (ISSPACE (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
375 obj_elf_section (ignore
);
378 obj_coff_section (ignore
);
383 mcore_s_bss (int needs_align
)
387 s_lcomm_bytes (needs_align
);
392 mcore_s_comm (int needs_align
)
396 obj_elf_common (needs_align
);
400 /* This table describes all the machine specific pseudo-ops the assembler
401 has to support. The fields are:
402 Pseudo-op name without dot
403 Function to call to execute this pseudo-op
404 Integer arg to pass to the function. */
405 const pseudo_typeS md_pseudo_table
[] =
407 { "export", s_globl
, 0 },
408 { "import", s_ignore
, 0 },
409 { "literals", mcore_s_literals
, 0 },
410 { "page", listing_eject
, 0 },
412 /* The following are to intercept the placement of data into the text
413 section (eg addresses for a switch table), so that the space they
414 occupy can be taken into account when deciding whether or not to
415 dump the current literal pool.
416 XXX - currently we do not cope with the .space and .dcb.d directives. */
417 { "ascii", mcore_stringer
, 0 },
418 { "asciz", mcore_stringer
, 1 },
419 { "byte", mcore_cons
, 1 },
420 { "dc", mcore_cons
, 2 },
421 { "dc.b", mcore_cons
, 1 },
422 { "dc.d", mcore_float_cons
, 'd'},
423 { "dc.l", mcore_cons
, 4 },
424 { "dc.s", mcore_float_cons
, 'f'},
425 { "dc.w", mcore_cons
, 2 },
426 { "dc.x", mcore_float_cons
, 'x'},
427 { "double", mcore_float_cons
, 'd'},
428 { "float", mcore_float_cons
, 'f'},
429 { "hword", mcore_cons
, 2 },
430 { "int", mcore_cons
, 4 },
431 { "long", mcore_cons
, 4 },
432 { "octa", mcore_cons
, 16 },
433 { "quad", mcore_cons
, 8 },
434 { "short", mcore_cons
, 2 },
435 { "single", mcore_float_cons
, 'f'},
436 { "string", mcore_stringer
, 1 },
437 { "word", mcore_cons
, 2 },
438 { "fill", mcore_fill
, 0 },
440 /* Allow for the effect of section changes. */
441 { "text", mcore_s_text
, 0 },
442 { "data", mcore_s_data
, 0 },
443 { "bss", mcore_s_bss
, 1 },
445 { "comm", mcore_s_comm
, 0 },
447 { "section", mcore_s_section
, 0 },
448 { "section.s", mcore_s_section
, 0 },
449 { "sect", mcore_s_section
, 0 },
450 { "sect.s", mcore_s_section
, 0 },
455 /* This function is called once, at assembler startup time. This should
456 set up all the tables, etc that the MD part of the assembler needs. */
461 const mcore_opcode_info
* opcode
;
462 char * prev_name
= "";
464 opcode_hash_control
= hash_new ();
466 /* Insert unique names into hash table. */
467 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
469 if (! streq (prev_name
, opcode
->name
))
471 prev_name
= opcode
->name
;
472 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
477 /* Get a log2(val). */
480 mylog2 (unsigned int val
)
493 /* Try to parse a reg name. */
496 parse_reg (char * s
, unsigned * reg
)
498 /* Strip leading whitespace. */
499 while (ISSPACE (* s
))
502 if (TOLOWER (s
[0]) == 'r')
504 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
506 *reg
= 10 + s
[2] - '0';
510 if (s
[1] >= '0' && s
[1] <= '9')
516 else if ( TOLOWER (s
[0]) == 's'
517 && TOLOWER (s
[1]) == 'p'
524 as_bad (_("register expected, but saw '%.6s'"), s
);
552 parse_creg (char * s
, unsigned * reg
)
556 /* Strip leading whitespace. */
557 while (ISSPACE (* s
))
560 if ((TOLOWER (s
[0]) == 'c' && TOLOWER (s
[1]) == 'r'))
562 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
564 *reg
= 30 + s
[3] - '0';
568 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
570 *reg
= 20 + s
[3] - '0';
574 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
576 *reg
= 10 + s
[3] - '0';
580 if (s
[2] >= '0' && s
[2] <= '9')
587 /* Look at alternate creg names before giving error. */
588 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
594 length
= strlen (cregs
[i
].name
);
596 for (j
= 0; j
< length
; j
++)
597 buf
[j
] = TOLOWER (s
[j
]);
599 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
601 *reg
= cregs
[i
].crnum
;
606 as_bad (_("control register expected, but saw '%.6s'"), s
);
612 parse_psrmod (char * s
, unsigned * reg
)
616 static struct psrmods
626 { "af", 8 } /* Really 0 and non-combinable. */
629 for (i
= 0; i
< 2; i
++)
630 buf
[i
] = TOLOWER (s
[i
]);
632 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
634 if (! strncmp (psrmods
[i
].name
, buf
, 2))
636 * reg
= psrmods
[i
].value
;
642 as_bad (_("bad/missing psr specifier"));
650 parse_exp (char * s
, expressionS
* e
)
655 /* Skip whitespace. */
656 while (ISSPACE (* s
))
659 save
= input_line_pointer
;
660 input_line_pointer
= s
;
664 if (e
->X_op
== O_absent
)
665 as_bad (_("missing operand"));
667 new = input_line_pointer
;
668 input_line_pointer
= save
;
674 enter_literal (expressionS
* e
, int ispcrel
)
679 if (poolsize
>= MAX_POOL_SIZE
- 2)
680 /* The literal pool is as full as we can handle. We have
681 to be 2 entries shy of the 1024/4=256 entries because we
682 have to allow for the branch (2 bytes) and the alignment
683 (2 bytes before the first insn referencing the pool and
684 2 bytes before the pool itself) == 6 bytes, rounds up
690 /* Create new literal pool. */
691 if (++ poolnumber
> 0xFFFF)
692 as_fatal (_("more than 65K literal pools"));
694 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
695 poolsym
= symbol_make (poolname
);
696 symbol_table_insert (poolsym
);
700 /* Search pool for value so we don't have duplicates. */
701 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
703 if (e
->X_op
== p
->e
.X_op
704 && e
->X_add_symbol
== p
->e
.X_add_symbol
705 && e
->X_add_number
== p
->e
.X_add_number
706 && ispcrel
== p
->ispcrel
)
714 p
->ispcrel
= ispcrel
;
722 /* Parse a literal specification. -- either new or old syntax.
723 old syntax: the user supplies the label and places the literal.
724 new syntax: we put it into the literal pool. */
736 /* Indicate nothing there. */
741 s
= parse_exp (s
+ 1, & e
);
746 as_bad (_("missing ']'"));
750 s
= parse_exp (s
, & e
);
752 n
= enter_literal (& e
, ispcrel
);
757 /* Create a reference to pool entry. */
759 e
.X_add_symbol
= poolsym
;
760 e
.X_add_number
= n
<< 2;
763 * outputp
= frag_more (2);
765 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
766 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
780 new = parse_exp (s
, & e
);
782 if (e
.X_op
== O_absent
)
783 ; /* An error message has already been emitted. */
784 else if (e
.X_op
!= O_constant
)
785 as_bad (_("operand must be a constant"));
786 else if ((addressT
) e
.X_add_number
< min
|| (addressT
) e
.X_add_number
> max
)
787 as_bad (_("operand must be absolute in range %u..%u, not %ld"),
788 min
, max
, (long) e
.X_add_number
);
790 * val
= e
.X_add_number
;
803 while (ISSPACE (* s
))
808 s
= parse_reg (s
+ 1, reg
);
810 while (ISSPACE (* s
))
815 s
= parse_imm (s
+ 1, off
, 0, 63);
822 as_bad (_("operand must be a multiple of 4"));
829 as_bad (_("operand must be a multiple of 2"));
836 while (ISSPACE (* s
))
843 as_bad (_("base register expected"));
848 /* This is the guts of the machine-dependent assembler. STR points to a
849 machine dependent instruction. This function is supposed to emit
850 the frags/bytes it assembles to. */
853 md_assemble (char * str
)
857 mcore_opcode_info
* opcode
;
867 /* Drop leading whitespace. */
868 while (ISSPACE (* str
))
871 /* Find the op code end. */
872 for (op_start
= op_end
= str
;
873 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
876 name
[nlen
] = op_start
[nlen
];
884 as_bad (_("can't find opcode "));
888 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
891 as_bad (_("unknown opcode \"%s\""), name
);
898 switch (opcode
->opclass
)
901 output
= frag_more (2);
905 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
907 output
= frag_more (2);
911 op_end
= parse_reg (op_end
+ 1, & reg
);
913 output
= frag_more (2);
917 op_end
= parse_reg (op_end
+ 1, & reg
);
919 output
= frag_more (2);
920 /* In a sifilter mode, we emit this insn 2 times,
921 fixes problem of an interrupt during a jmp.. */
924 output
[0] = INST_BYTE0 (inst
);
925 output
[1] = INST_BYTE1 (inst
);
926 output
= frag_more (2);
931 op_end
= parse_reg (op_end
+ 1, & reg
);
934 as_bad (_("invalid register: r15 illegal"));
937 output
= frag_more (2);
941 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx. */
942 inst
= MCORE_INST_BSR
; /* With 0 displacement. */
943 output
[0] = INST_BYTE0 (inst
);
944 output
[1] = INST_BYTE1 (inst
);
946 output
= frag_more (2);
947 inst
= MCORE_INST_ADDI
;
948 inst
|= 15; /* addi r15,6 */
949 inst
|= (6 - 1) << 4; /* Over the jmp's. */
950 output
[0] = INST_BYTE0 (inst
);
951 output
[1] = INST_BYTE1 (inst
);
953 output
= frag_more (2);
954 inst
= MCORE_INST_JMP
| reg
;
955 output
[0] = INST_BYTE0 (inst
);
956 output
[1] = INST_BYTE1 (inst
);
958 /* 2nd emitted in fallthrough. */
959 output
= frag_more (2);
964 op_end
= parse_reg (op_end
+ 1, & reg
);
967 /* Skip whitespace. */
968 while (ISSPACE (* op_end
))
973 op_end
= parse_creg (op_end
+ 1, & reg
);
977 output
= frag_more (2);
983 as_bad (_("M340 specific opcode used when assembling for M210"));
986 /* drop through... */
988 op_end
= parse_reg (op_end
+ 1, & reg
);
991 /* Skip whitespace. */
992 while (ISSPACE (* op_end
))
997 op_end
= parse_reg (op_end
+ 1, & reg
);
1001 as_bad (_("second operand missing"));
1003 output
= frag_more (2);
1007 /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx. */
1008 op_end
= parse_reg (op_end
+ 1, & reg
);
1010 /* Skip whitespace. */
1011 while (ISSPACE (* op_end
))
1014 if (* op_end
== ',') /* xtrb- r1,rx. */
1017 as_bad (_("destination register must be r1"));
1019 op_end
= parse_reg (op_end
+ 1, & reg
);
1023 output
= frag_more (2);
1026 case O1R1
: /* div- rx,r1. */
1027 op_end
= parse_reg (op_end
+ 1, & reg
);
1030 /* Skip whitespace. */
1031 while (ISSPACE (* op_end
))
1034 if (* op_end
== ',')
1036 op_end
= parse_reg (op_end
+ 1, & reg
);
1038 as_bad (_("source register must be r1"));
1041 as_bad (_("second operand missing"));
1043 output
= frag_more (2);
1047 op_end
= parse_reg (op_end
+ 1, & reg
);
1050 /* Skip whitespace. */
1051 while (ISSPACE (* op_end
))
1054 if (* op_end
== ',')
1056 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1057 inst
|= (reg
- 1) << 4;
1060 as_bad (_("second operand missing"));
1062 output
= frag_more (2);
1066 op_end
= parse_reg (op_end
+ 1, & reg
);
1069 /* Skip whitespace. */
1070 while (ISSPACE (* op_end
))
1073 if (* op_end
== ',')
1075 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1079 as_bad (_("second operand missing"));
1081 output
= frag_more (2);
1085 /* Like OB, but arg is 2^n instead of n. */
1086 op_end
= parse_reg (op_end
+ 1, & reg
);
1089 /* Skip whitespace. */
1090 while (ISSPACE (* op_end
))
1093 if (* op_end
== ',')
1095 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1096 /* Further restrict the immediate to a power of two. */
1097 if ((reg
& (reg
- 1)) == 0)
1102 as_bad (_("immediate is not a power of two"));
1107 as_bad (_("second operand missing"));
1109 output
= frag_more (2);
1112 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1115 op_end
= parse_reg (op_end
+ 1, & reg
);
1118 /* Skip whitespace. */
1119 while (ISSPACE (* op_end
))
1122 if (* op_end
== ',')
1124 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1125 /* Immediate values of 0 -> 6 translate to movi. */
1128 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1130 as_warn (_("translating bgeni to movi"));
1136 as_bad (_("second operand missing"));
1138 output
= frag_more (2);
1141 case OBR2
: /* Like OBR, but arg is 2^n instead of n. */
1142 op_end
= parse_reg (op_end
+ 1, & reg
);
1145 /* Skip whitespace. */
1146 while (ISSPACE (* op_end
))
1149 if (* op_end
== ',')
1151 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1153 /* Further restrict the immediate to a power of two. */
1154 if ((reg
& (reg
- 1)) == 0)
1159 as_bad (_("immediate is not a power of two"));
1162 /* Immediate values of 0 -> 6 translate to movi. */
1165 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1167 as_warn (_("translating mgeni to movi"));
1173 as_bad (_("second operand missing"));
1175 output
= frag_more (2);
1178 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1181 op_end
= parse_reg (op_end
+ 1, & reg
);
1184 /* Skip whitespace. */
1185 while (ISSPACE (* op_end
))
1188 if (* op_end
== ',')
1190 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1192 /* Immediate values of 1 -> 7 translate to movi. */
1195 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1196 reg
= (0x1 << reg
) - 1;
1199 as_warn (_("translating bmaski to movi"));
1204 inst
|= (reg
& 0x1F) << 4;
1208 as_bad (_("second operand missing"));
1210 output
= frag_more (2);
1214 op_end
= parse_reg (op_end
+ 1, & reg
);
1217 /* Skip whitespace. */
1218 while (ISSPACE (* op_end
))
1221 if (* op_end
== ',')
1223 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1227 as_bad (_("second operand missing"));
1229 output
= frag_more (2);
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
, 0, 0x7F);
1246 as_bad (_("second operand missing"));
1248 output
= frag_more (2);
1252 op_end
= parse_reg (op_end
+ 1, & reg
);
1255 /* Skip whitespace. */
1256 while (ISSPACE (* op_end
))
1259 if (* op_end
== ',')
1263 if ((inst
& 0x6000) == 0)
1265 else if ((inst
& 0x6000) == 0x4000)
1267 else if ((inst
& 0x6000) == 0x2000)
1272 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1275 as_bad (_("displacement too large (%d)"), off
);
1277 inst
|= (reg
) | (off
<< 4);
1280 as_bad (_("second operand missing"));
1282 output
= frag_more (2);
1286 op_end
= parse_reg (op_end
+ 1, & reg
);
1288 if (reg
== 0 || reg
== 15)
1289 as_bad (_("Invalid register: r0 and r15 illegal"));
1293 /* Skip whitespace. */
1294 while (ISSPACE (* op_end
))
1297 if (* op_end
== ',')
1299 /* parse_rt calls frag_more() for us. */
1300 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1301 op_end
= input_line_pointer
;
1305 as_bad (_("second operand missing"));
1306 output
= frag_more (2); /* save its space */
1311 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1312 /* parse_rt() calls frag_more() for us. */
1313 op_end
= input_line_pointer
;
1317 op_end
= parse_reg (op_end
+ 1, & reg
);
1319 if (reg
== 0 || reg
== 15)
1320 as_bad (_("bad starting register: r0 and r15 invalid"));
1324 /* Skip whitespace. */
1325 while (ISSPACE (* op_end
))
1328 if (* op_end
== '-')
1330 op_end
= parse_reg (op_end
+ 1, & reg
);
1333 as_bad (_("ending register must be r15"));
1335 /* Skip whitespace. */
1336 while (ISSPACE (* op_end
))
1340 if (* op_end
== ',')
1344 /* Skip whitespace. */
1345 while (ISSPACE (* op_end
))
1348 if (* op_end
== '(')
1350 op_end
= parse_reg (op_end
+ 1, & reg
);
1353 as_bad (_("bad base register: must be r0"));
1355 if (* op_end
== ')')
1359 as_bad (_("base register expected"));
1362 as_bad (_("second operand missing"));
1364 output
= frag_more (2);
1368 op_end
= parse_reg (op_end
+ 1, & reg
);
1371 as_fatal (_("first register must be r4"));
1373 /* Skip whitespace. */
1374 while (ISSPACE (* op_end
))
1377 if (* op_end
== '-')
1379 op_end
= parse_reg (op_end
+ 1, & reg
);
1382 as_fatal (_("last register must be r7"));
1384 /* Skip whitespace. */
1385 while (ISSPACE (* op_end
))
1388 if (* op_end
== ',')
1392 /* Skip whitespace. */
1393 while (ISSPACE (* op_end
))
1396 if (* op_end
== '(')
1398 op_end
= parse_reg (op_end
+ 1, & reg
);
1400 if (reg
>= 4 && reg
<= 7)
1401 as_fatal ("base register cannot be r4, r5, r6, or r7");
1405 /* Skip whitespace. */
1406 while (ISSPACE (* op_end
))
1409 if (* op_end
== ')')
1413 as_bad (_("base register expected"));
1416 as_bad (_("second operand missing"));
1419 as_bad (_("reg-reg expected"));
1421 output
= frag_more (2);
1425 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1426 op_end
= input_line_pointer
;
1428 output
= frag_more (2);
1430 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1431 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1435 op_end
= parse_reg (op_end
+ 1, & reg
);
1438 /* Skip whitespace. */
1439 while (ISSPACE (* op_end
))
1442 if (* op_end
== ',')
1444 op_end
= parse_exp (op_end
+ 1, & e
);
1445 output
= frag_more (2);
1447 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1448 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1452 as_bad (_("second operand missing"));
1453 output
= frag_more (2);
1458 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1459 op_end
= input_line_pointer
;
1461 output
= frag_var (rs_machine_dependent
,
1462 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1463 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1464 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1469 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1470 op_end
= input_line_pointer
;
1472 output
= frag_var (rs_machine_dependent
,
1473 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1474 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1475 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1480 inst
= MCORE_INST_JSRI
; /* jsri */
1481 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1482 /* parse_rt() calls frag_more for us. */
1483 op_end
= input_line_pointer
;
1485 /* Only do this if we know how to do it ... */
1486 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1488 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1489 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1490 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1495 /* SI, but imm becomes 32-imm. */
1496 op_end
= parse_reg (op_end
+ 1, & reg
);
1499 /* Skip whitespace. */
1500 while (ISSPACE (* op_end
))
1503 if (* op_end
== ',')
1505 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1511 as_bad (_("second operand missing"));
1513 output
= frag_more (2);
1516 case DO21
: /* O2, dup rd, lit must be 1 */
1517 op_end
= parse_reg (op_end
+ 1, & reg
);
1521 /* Skip whitespace. */
1522 while (ISSPACE (* op_end
))
1525 if (* op_end
== ',')
1527 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1530 as_bad (_("second operand must be 1"));
1533 as_bad (_("second operand missing"));
1535 output
= frag_more (2);
1539 op_end
= parse_reg (op_end
+ 1, & reg
);
1542 /* Skip whitespace. */
1543 while (ISSPACE (* op_end
))
1546 if (* op_end
== ',')
1548 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1551 as_bad (_("zero used as immediate value"));
1556 as_bad (_("second operand missing"));
1558 output
= frag_more (2);
1564 as_bad (_("M340 specific opcode used when assembling for M210"));
1568 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1570 /* Look for further selectors. */
1571 while (* op_end
== ',')
1575 op_end
= parse_psrmod (op_end
+ 1, & value
);
1578 as_bad (_("duplicated psr bit specifier"));
1584 as_bad (_("`af' must appear alone"));
1586 inst
|= (reg
& 0x7);
1587 output
= frag_more (2);
1591 as_bad (_("unimplemented opcode \"%s\""), name
);
1594 /* Drop whitespace after all the operands have been parsed. */
1595 while (ISSPACE (* op_end
))
1598 /* Give warning message if the insn has more operands than required. */
1599 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1600 as_warn (_("ignoring operands: %s "), op_end
);
1602 output
[0] = INST_BYTE0 (inst
);
1603 output
[1] = INST_BYTE1 (inst
);
1605 check_literals (opcode
->transfer
, isize
);
1609 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1618 subseg_set (text_section
, 0);
1621 /* Various routines to kill one day. */
1622 /* Equal to MAX_PRECISION in atof-ieee.c. */
1623 #define MAX_LITTLENUMS 6
1625 /* Turn a string in input_line_pointer into a floating point constant of type
1626 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1627 emitted is stored in *sizeP. An error message is returned, or NULL on OK. */
1630 md_atof (int type
, char * litP
, int * sizeP
)
1633 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1665 return _("Bad call to MD_NTOF()");
1668 t
= atof_ieee (input_line_pointer
, type
, words
);
1671 input_line_pointer
= t
;
1673 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1675 if (! target_big_endian
)
1677 for (i
= prec
- 1; i
>= 0; i
--)
1679 md_number_to_chars (litP
, (valueT
) words
[i
],
1680 sizeof (LITTLENUM_TYPE
));
1681 litP
+= sizeof (LITTLENUM_TYPE
);
1685 for (i
= 0; i
< prec
; i
++)
1687 md_number_to_chars (litP
, (valueT
) words
[i
],
1688 sizeof (LITTLENUM_TYPE
));
1689 litP
+= sizeof (LITTLENUM_TYPE
);
1695 const char * md_shortopts
= "";
1699 OPTION_JSRI2BSR_ON
= OPTION_MD_BASE
,
1700 OPTION_JSRI2BSR_OFF
,
1702 OPTION_SIFILTER_OFF
,
1708 struct option md_longopts
[] =
1710 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1711 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1712 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1713 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1714 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1715 { "EB", no_argument
, NULL
, OPTION_EB
},
1716 { "EL", no_argument
, NULL
, OPTION_EL
},
1717 { NULL
, no_argument
, NULL
, 0}
1720 size_t md_longopts_size
= sizeof (md_longopts
);
1723 md_parse_option (int c
, char * arg
)
1728 if (streq (arg
, "210"))
1731 target_big_endian
= 1;
1733 else if (streq (arg
, "340"))
1736 as_warn (_("unrecognised cpu type '%s'"), arg
);
1739 case OPTION_EB
: target_big_endian
= 1; break;
1740 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1741 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1742 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1743 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1744 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1752 md_show_usage (FILE * stream
)
1754 fprintf (stream
, _("\
1755 MCORE specific options:\n\
1756 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1757 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1758 -cpu=[210|340] select CPU type\n\
1759 -EB assemble for a big endian system (default)\n\
1760 -EL assemble for a little endian system\n"));
1763 int md_short_jump_size
;
1766 md_create_short_jump (char * ptr ATTRIBUTE_UNUSED
,
1767 addressT from_Nddr ATTRIBUTE_UNUSED
,
1768 addressT to_Nddr ATTRIBUTE_UNUSED
,
1769 fragS
* frag ATTRIBUTE_UNUSED
,
1770 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1772 as_fatal (_("failed sanity check: short_jump"));
1776 md_create_long_jump (char * ptr ATTRIBUTE_UNUSED
,
1777 addressT from_Nddr ATTRIBUTE_UNUSED
,
1778 addressT to_Nddr ATTRIBUTE_UNUSED
,
1779 fragS
* frag ATTRIBUTE_UNUSED
,
1780 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1782 as_fatal (_("failed sanity check: long_jump"));
1785 /* Called after relaxing, change the frags so they know how big they are. */
1788 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1789 segT sec ATTRIBUTE_UNUSED
,
1793 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1795 buffer
= fragP
->fr_fix
+ fragP
->fr_literal
;
1797 switch (fragP
->fr_subtype
)
1799 case C (COND_JUMP
, DISP12
):
1800 case C (UNCD_JUMP
, DISP12
):
1802 /* Get the address of the end of the instruction. */
1803 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1805 int disp
= targ_addr
- next_inst
;
1808 as_bad (_("odd displacement at %x"), next_inst
- 2);
1812 if (! target_big_endian
)
1814 t0
= buffer
[1] & 0xF8;
1816 md_number_to_chars (buffer
, disp
, 2);
1818 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1822 t0
= buffer
[0] & 0xF8;
1824 md_number_to_chars (buffer
, disp
, 2);
1826 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1833 case C (COND_JUMP
, DISP32
):
1834 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1836 /* A conditional branch wont fit into 12 bits so:
1843 If the b!cond is 4 byte aligned, the literal which would
1844 go at x+4 will also be aligned. */
1845 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1846 int needpad
= (first_inst
& 3);
1848 if (! target_big_endian
)
1851 buffer
[0] ^= 0x08; /* Toggle T/F bit. */
1853 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1854 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1858 if (! target_big_endian
)
1860 buffer
[0] = 4; /* Branch over jmpi, pad, and ptr. */
1861 buffer
[2] = 1; /* Jmpi offset of 1 gets the pointer. */
1865 buffer
[1] = 4; /* Branch over jmpi, pad, and ptr. */
1866 buffer
[3] = 1; /* Jmpi offset of 1 gets the pointer. */
1869 buffer
[4] = 0; /* Alignment/pad. */
1871 buffer
[6] = 0; /* Space for 32 bit address. */
1876 /* Make reloc for the long disp. */
1877 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1878 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1880 fragP
->fr_fix
+= C32_LEN
;
1884 /* See comment below about this given gas' limitations for
1885 shrinking the fragment. '3' is the amount of code that
1886 we inserted here, but '4' is right for the space we reserved
1887 for this fragment. */
1888 if (! target_big_endian
)
1890 buffer
[0] = 3; /* Branch over jmpi, and ptr. */
1891 buffer
[2] = 0; /* Jmpi offset of 0 gets the pointer. */
1895 buffer
[1] = 3; /* Branch over jmpi, and ptr. */
1896 buffer
[3] = 0; /* Jmpi offset of 0 gets the pointer. */
1899 buffer
[4] = 0; /* Space for 32 bit address. */
1904 /* Make reloc for the long disp. */
1905 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1906 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1907 fragP
->fr_fix
+= C32_LEN
;
1909 /* Frag is actually shorter (see the other side of this ifdef)
1910 but gas isn't prepared for that. We have to re-adjust
1911 the branch displacement so that it goes beyond the
1912 full length of the fragment, not just what we actually
1914 if (! target_big_endian
)
1915 buffer
[0] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1917 buffer
[1] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1922 case C (UNCD_JUMP
, DISP32
):
1923 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1925 /* An unconditional branch will not fit in 12 bits, make code which
1930 we need a pad if "first_inst" is 4 byte aligned.
1931 [because the natural literal place is x + 2]. */
1932 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1933 int needpad
= !(first_inst
& 3);
1935 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1936 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1940 if (! target_big_endian
)
1941 buffer
[0] = 1; /* Jmpi offset of 1 since padded. */
1943 buffer
[1] = 1; /* Jmpi offset of 1 since padded. */
1944 buffer
[2] = 0; /* Alignment. */
1946 buffer
[4] = 0; /* Space for 32 bit address. */
1951 /* Make reloc for the long disp. */
1952 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1953 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1955 fragP
->fr_fix
+= U32_LEN
;
1959 if (! target_big_endian
)
1960 buffer
[0] = 0; /* Jmpi offset of 0 if no pad. */
1962 buffer
[1] = 0; /* Jmpi offset of 0 if no pad. */
1963 buffer
[2] = 0; /* Space for 32 bit address. */
1968 /* Make reloc for the long disp. */
1969 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1970 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1971 fragP
->fr_fix
+= U32_LEN
;
1981 /* Applies the desired value to the specified location.
1982 Also sets up addends for 'rela' type relocations. */
1985 md_apply_fix (fixS
* fixP
,
1987 segT segment ATTRIBUTE_UNUSED
)
1989 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1990 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1991 const char * symname
;
1992 /* Note: use offsetT because it is signed, valueT is unsigned. */
1993 offsetT val
= *valP
;
1995 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1996 /* Save this for the addend in the relocation record. */
1997 fixP
->fx_addnumber
= val
;
1999 if (fixP
->fx_addsy
!= NULL
)
2002 /* For ELF we can just return and let the reloc that will be generated
2003 take care of everything. For COFF we still have to insert 'val'
2004 into the insn since the addend field will be ignored. */
2011 switch (fixP
->fx_r_type
)
2013 /* Second byte of 2 byte opcode. */
2014 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2016 as_bad_where (file
, fixP
->fx_line
,
2017 _("odd distance branch (0x%lx bytes)"), (long) val
);
2019 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2020 as_bad_where (file
, fixP
->fx_line
,
2021 _("pcrel for branch to %s too far (0x%lx)"),
2022 symname
, (long) val
);
2023 if (target_big_endian
)
2025 buf
[0] |= ((val
>> 8) & 0x7);
2026 buf
[1] |= (val
& 0xff);
2030 buf
[1] |= ((val
>> 8) & 0x7);
2031 buf
[0] |= (val
& 0xff);
2035 /* Lower 8 bits of 2 byte opcode. */
2036 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2040 as_bad_where (file
, fixP
->fx_line
,
2041 _("pcrel for lrw/jmpi/jsri to %s too far (0x%lx)"),
2042 symname
, (long) val
);
2043 else if (! target_big_endian
)
2044 buf
[0] |= (val
& 0xff);
2046 buf
[1] |= (val
& 0xff);
2049 /* Loopt instruction. */
2050 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2051 if ((val
< -32) || (val
> -2))
2052 as_bad_where (file
, fixP
->fx_line
,
2053 _("pcrel for loopt too far (0x%lx)"), (long) val
);
2055 if (! target_big_endian
)
2056 buf
[0] |= (val
& 0xf);
2058 buf
[1] |= (val
& 0xf);
2061 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2062 /* Conditional linker map jsri to bsr. */
2063 /* If its a local target and close enough, fix it.
2064 NB: >= -2k for backwards bsr; < 2k for forwards... */
2065 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2067 long nval
= (val
/ 2) & 0x7ff;
2068 nval
|= MCORE_INST_BSR
;
2070 /* REPLACE the instruction, don't just modify it. */
2071 buf
[0] = INST_BYTE0 (nval
);
2072 buf
[1] = INST_BYTE1 (nval
);
2078 case BFD_RELOC_MCORE_PCREL_32
:
2079 case BFD_RELOC_VTABLE_INHERIT
:
2080 case BFD_RELOC_VTABLE_ENTRY
:
2085 if (fixP
->fx_addsy
!= NULL
)
2087 /* If the fix is an absolute reloc based on a symbol's
2088 address, then it cannot be resolved until the final link. */
2095 if (fixP
->fx_size
== 4)
2097 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2099 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2103 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2110 md_operand (expressionS
* expressionP
)
2112 /* Ignore leading hash symbol, if poresent. */
2113 if (* input_line_pointer
== '#')
2115 input_line_pointer
++;
2116 expression (expressionP
);
2120 int md_long_jump_size
;
2122 /* Called just before address relaxation, return the length
2123 by which a fragment must grow to reach it's destination. */
2125 md_estimate_size_before_relax (fragS
* fragP
, segT segment_type
)
2127 switch (fragP
->fr_subtype
)
2132 case C (UNCD_JUMP
, UNDEF_DISP
):
2133 /* Used to be a branch to somewhere which was unknown. */
2134 if (!fragP
->fr_symbol
)
2135 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2136 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2137 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2139 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2142 case C (COND_JUMP
, UNDEF_DISP
):
2143 /* Used to be a branch to somewhere which was unknown. */
2144 if (fragP
->fr_symbol
2145 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2146 /* Got a symbol and it's defined in this segment, become byte
2147 sized - maybe it will fix up */
2148 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2149 else if (fragP
->fr_symbol
)
2150 /* Its got a segment, but its not ours, so it will always be long. */
2151 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2153 /* We know the abs value. */
2154 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2157 case C (UNCD_JUMP
, DISP12
):
2158 case C (UNCD_JUMP
, DISP32
):
2159 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2160 case C (COND_JUMP
, DISP12
):
2161 case C (COND_JUMP
, DISP32
):
2162 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2163 /* When relaxing a section for the second time, we don't need to
2164 do anything besides return the current size. */
2168 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2171 /* Put number into target byte order. */
2174 md_number_to_chars (char * ptr
, valueT use
, int nbytes
)
2176 if (! target_big_endian
)
2179 case 4: ptr
[3] = (use
>> 24) & 0xff; /* Fall through. */
2180 case 3: ptr
[2] = (use
>> 16) & 0xff; /* Fall through. */
2181 case 2: ptr
[1] = (use
>> 8) & 0xff; /* Fall through. */
2182 case 1: ptr
[0] = (use
>> 0) & 0xff; break;
2188 case 4: *ptr
++ = (use
>> 24) & 0xff; /* Fall through. */
2189 case 3: *ptr
++ = (use
>> 16) & 0xff; /* Fall through. */
2190 case 2: *ptr
++ = (use
>> 8) & 0xff; /* Fall through. */
2191 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2196 /* Round up a section size to the appropriate boundary. */
2199 md_section_align (segT segment ATTRIBUTE_UNUSED
,
2202 /* Byte alignment is fine. */
2206 /* The location from which a PC relative jump should be calculated,
2207 given a PC relative reloc. */
2210 md_pcrel_from_section (fixS
* fixp
, segT sec ATTRIBUTE_UNUSED
)
2213 /* If the symbol is undefined or defined in another section
2214 we leave the add number alone for the linker to fix it later.
2215 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2216 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2217 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2218 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2221 assert (fixp
->fx_size
== 2); /* must be an insn */
2222 return fixp
->fx_size
;
2226 /* The case where we are going to resolve things... */
2227 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2230 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2231 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2234 tc_gen_reloc (asection
* section ATTRIBUTE_UNUSED
, fixS
* fixp
)
2237 bfd_reloc_code_real_type code
;
2239 switch (fixp
->fx_r_type
)
2241 /* These confuse the size/pcrel macro approach. */
2242 case BFD_RELOC_VTABLE_INHERIT
:
2243 case BFD_RELOC_VTABLE_ENTRY
:
2244 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2245 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2246 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2247 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2249 code
= fixp
->fx_r_type
;
2253 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2255 MAP (1, 0, BFD_RELOC_8
);
2256 MAP (2, 0, BFD_RELOC_16
);
2257 MAP (4, 0, BFD_RELOC_32
);
2258 MAP (1, 1, BFD_RELOC_8_PCREL
);
2259 MAP (2, 1, BFD_RELOC_16_PCREL
);
2260 MAP (4, 1, BFD_RELOC_32_PCREL
);
2262 code
= fixp
->fx_r_type
;
2263 as_bad (_("Can not do %d byte %srelocation"),
2265 fixp
->fx_pcrel
? _("pc-relative") : "");
2270 rel
= xmalloc (sizeof (arelent
));
2271 rel
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2272 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2273 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2274 /* Always pass the addend along! */
2275 rel
->addend
= fixp
->fx_addnumber
;
2277 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2279 if (rel
->howto
== NULL
)
2281 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2282 _("Cannot represent relocation type %s"),
2283 bfd_get_reloc_code_name (code
));
2285 /* Set howto to a garbage value so that we can keep going. */
2286 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2287 assert (rel
->howto
!= NULL
);
2294 /* See whether we need to force a relocation into the output file.
2295 This is used to force out switch and PC relative relocations when
2298 mcore_force_relocation (fixS
* fix
)
2300 if (fix
->fx_r_type
== BFD_RELOC_RVA
)
2303 return generic_force_reloc (fix
);
2306 /* Return true if the fix can be handled by GAS, false if it must
2307 be passed through to the linker. */
2310 mcore_fix_adjustable (fixS
* fixP
)
2312 /* We need the symbol name for the VTABLE entries. */
2313 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2314 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2319 #endif /* OBJ_ELF */