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 const int md_reloc_size
= 8;
54 static int do_jsri2bsr
= 0; /* Change here from 1 by Cruess 19 August 97. */
55 static int sifilter_mode
= 0;
57 const char EXP_CHARS
[] = "eE";
59 /* Chars that mean this number is a floating point constant
62 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
64 #define C(what,length) (((what) << 2) + (length))
65 #define GET_WHAT(x) ((x >> 2))
67 /* These are the two types of relaxable instruction. */
74 #define UNDEF_WORD_DISP 3
77 #define C32_LEN 10 /* Allow for align. */
79 #define U32_LEN 8 /* Allow for align. */
90 /* Initialize the relax table. */
91 const relax_typeS md_relax_table
[] =
99 { 0, 0, 0, 0 }, /* UNDEF_DISP */
100 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* DISP12 */
101 { 0, 0, C32_LEN
, 0 }, /* DISP32 */
102 { 0, 0, C32_LEN
, 0 }, /* UNDEF_WORD_DISP */
105 { 0, 0, 0, 0 }, /* UNDEF_DISP */
106 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* DISP12 */
107 { 0, 0, U32_LEN
, 0 }, /* DISP32 */
108 { 0, 0, U32_LEN
, 0 } /* UNDEF_WORD_DISP */
112 /* Literal pool data structures. */
115 unsigned short refcnt
;
116 unsigned char ispcrel
;
117 unsigned char unused
;
121 #define MAX_POOL_SIZE (1024/4)
122 static struct literal litpool
[MAX_POOL_SIZE
];
123 static unsigned poolsize
;
124 static unsigned poolnumber
;
125 static unsigned long poolspan
;
127 /* SPANPANIC: the point at which we get too scared and force a dump
128 of the literal pool, and perhaps put a branch in place.
130 1024 span of lrw/jmpi/jsri insn (actually span+1)
131 -2 possible alignment at the insn.
132 -2 possible alignment to get the table aligned.
133 -2 an inserted branch around the table.
135 at 1018, we might be in trouble.
136 -- so we have to be smaller than 1018 and since we deal with 2-byte
137 instructions, the next good choice is 1016.
138 -- Note we have a test case that fails when we've got 1018 here. */
139 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
140 #define SPANCLOSE (900)
141 #define SPANEXIT (600)
142 static symbolS
* poolsym
; /* Label for current pool. */
143 static char poolname
[8];
144 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
146 #define POOL_END_LABEL ".LE"
147 #define POOL_START_LABEL ".LS"
150 make_name (char * s
, char * p
, int n
)
152 static const char hex
[] = "0123456789ABCDEF";
157 s
[3] = hex
[(n
>> 12) & 0xF];
158 s
[4] = hex
[(n
>> 8) & 0xF];
159 s
[5] = hex
[(n
>> 4) & 0xF];
160 s
[6] = hex
[(n
) & 0xF];
165 dump_literals (int isforce
)
169 symbolS
* brarsym
= NULL
;
174 /* Must we branch around the literal table? */
180 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
182 brarsym
= symbol_make (brarname
);
184 symbol_table_insert (brarsym
);
186 output
= frag_var (rs_machine_dependent
,
187 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
188 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
189 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
190 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
191 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
194 /* Make sure that the section is sufficiently aligned and that
195 the literal table is aligned within it. */
196 record_alignment (now_seg
, 2);
197 frag_align (2, 0, 0);
199 colon (S_GET_NAME (poolsym
));
201 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
202 emit_expr (& p
->e
, 4);
205 colon (S_GET_NAME (brarsym
));
211 mcore_s_literals (int ignore ATTRIBUTE_UNUSED
)
214 demand_empty_rest_of_line ();
217 /* Perform FUNC (ARG), and track number of bytes added to frag. */
220 mcore_pool_count (void (*func
) (int), int arg
)
222 const fragS
*curr_frag
= frag_now
;
223 offsetT added
= -frag_now_fix_octets ();
227 while (curr_frag
!= frag_now
)
229 added
+= curr_frag
->fr_fix
;
230 curr_frag
= curr_frag
->fr_next
;
233 added
+= frag_now_fix_octets ();
238 check_literals (int kind
, int offset
)
242 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
243 SPANPANIC means that we must dump now.
244 kind == 0 is any old instruction.
245 kind > 0 means we just had a control transfer instruction.
246 kind == 1 means within a function
247 kind == 2 means we just left a function
249 The dump_literals (1) call inserts a branch around the table, so
250 we first look to see if its a situation where we won't have to
251 insert a branch (e.g., the previous instruction was an unconditional
254 SPANPANIC is the point where we must dump a single-entry pool.
255 it accounts for alignments and an inserted branch.
256 the 'poolsize*2' accounts for the scenario where we do:
257 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
258 Note that the 'lit2' reference is 2 bytes further along
259 but the literal it references will be 4 bytes further along,
260 so we must consider the poolsize into this equation.
261 This is slightly over-cautious, but guarantees that we won't
262 panic because a relocation is too distant. */
264 if (poolspan
> SPANCLOSE
&& kind
> 0)
266 else if (poolspan
> SPANEXIT
&& kind
> 1)
268 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
273 mcore_cons (int nbytes
)
275 if (now_seg
== text_section
)
276 mcore_pool_count (cons
, nbytes
);
280 /* In theory we ought to call check_literals (2,0) here in case
281 we need to dump the literal table. We cannot do this however,
282 as the directives that we are intercepting may be being used
283 to build a switch table, and we must not interfere with its
284 contents. Instead we cross our fingers and pray... */
288 mcore_float_cons (int float_type
)
290 if (now_seg
== text_section
)
291 mcore_pool_count (float_cons
, float_type
);
293 float_cons (float_type
);
295 /* See the comment in mcore_cons () about calling check_literals.
296 It is unlikely that a switch table will be constructed using
297 floating point values, but it is still likely that an indexed
298 table of floating point constants is being created by these
299 directives, so again we must not interfere with their placement. */
303 mcore_stringer (int append_zero
)
305 if (now_seg
== text_section
)
306 mcore_pool_count (stringer
, append_zero
);
308 stringer (append_zero
);
310 /* We call check_literals here in case a large number of strings are
311 being placed into the text section with a sequence of stringer
312 directives. In theory we could be upsetting something if these
313 strings are actually in an indexed table instead of referenced by
314 individual labels. Let us hope that that never happens. */
315 check_literals (2, 0);
319 mcore_fill (int unused
)
321 if (now_seg
== text_section
)
322 mcore_pool_count (s_fill
, unused
);
326 check_literals (2, 0);
329 /* Handle the section changing pseudo-ops. These call through to the
330 normal implementations, but they dump the literal pool first. */
333 mcore_s_text (int ignore
)
338 obj_elf_text (ignore
);
345 mcore_s_data (int ignore
)
350 obj_elf_data (ignore
);
357 mcore_s_section (int ignore
)
359 /* Scan forwards to find the name of the section. If the section
360 being switched to is ".line" then this is a DWARF1 debug section
361 which is arbitrarily placed inside generated code. In this case
362 do not dump the literal pool because it is a) inefficient and
363 b) would require the generation of extra code to jump around the
365 char * ilp
= input_line_pointer
;
367 while (*ilp
!= 0 && ISSPACE (*ilp
))
370 if (strncmp (ilp
, ".line", 5) == 0
371 && (ISSPACE (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
377 obj_elf_section (ignore
);
380 obj_coff_section (ignore
);
385 mcore_s_bss (int needs_align
)
389 s_lcomm_bytes (needs_align
);
394 mcore_s_comm (int needs_align
)
398 obj_elf_common (needs_align
);
402 /* This table describes all the machine specific pseudo-ops the assembler
403 has to support. The fields are:
404 Pseudo-op name without dot
405 Function to call to execute this pseudo-op
406 Integer arg to pass to the function. */
407 const pseudo_typeS md_pseudo_table
[] =
409 { "export", s_globl
, 0 },
410 { "import", s_ignore
, 0 },
411 { "literals", mcore_s_literals
, 0 },
412 { "page", listing_eject
, 0 },
414 /* The following are to intercept the placement of data into the text
415 section (eg addresses for a switch table), so that the space they
416 occupy can be taken into account when deciding whether or not to
417 dump the current literal pool.
418 XXX - currently we do not cope with the .space and .dcb.d directives. */
419 { "ascii", mcore_stringer
, 0 },
420 { "asciz", mcore_stringer
, 1 },
421 { "byte", mcore_cons
, 1 },
422 { "dc", mcore_cons
, 2 },
423 { "dc.b", mcore_cons
, 1 },
424 { "dc.d", mcore_float_cons
, 'd'},
425 { "dc.l", mcore_cons
, 4 },
426 { "dc.s", mcore_float_cons
, 'f'},
427 { "dc.w", mcore_cons
, 2 },
428 { "dc.x", mcore_float_cons
, 'x'},
429 { "double", mcore_float_cons
, 'd'},
430 { "float", mcore_float_cons
, 'f'},
431 { "hword", mcore_cons
, 2 },
432 { "int", mcore_cons
, 4 },
433 { "long", mcore_cons
, 4 },
434 { "octa", mcore_cons
, 16 },
435 { "quad", mcore_cons
, 8 },
436 { "short", mcore_cons
, 2 },
437 { "single", mcore_float_cons
, 'f'},
438 { "string", mcore_stringer
, 1 },
439 { "word", mcore_cons
, 2 },
440 { "fill", mcore_fill
, 0 },
442 /* Allow for the effect of section changes. */
443 { "text", mcore_s_text
, 0 },
444 { "data", mcore_s_data
, 0 },
445 { "bss", mcore_s_bss
, 1 },
447 { "comm", mcore_s_comm
, 0 },
449 { "section", mcore_s_section
, 0 },
450 { "section.s", mcore_s_section
, 0 },
451 { "sect", mcore_s_section
, 0 },
452 { "sect.s", mcore_s_section
, 0 },
457 /* This function is called once, at assembler startup time. This should
458 set up all the tables, etc that the MD part of the assembler needs. */
463 const mcore_opcode_info
* opcode
;
464 char * prev_name
= "";
466 opcode_hash_control
= hash_new ();
468 /* Insert unique names into hash table. */
469 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
471 if (! streq (prev_name
, opcode
->name
))
473 prev_name
= opcode
->name
;
474 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
479 /* Get a log2(val). */
482 mylog2 (unsigned int val
)
495 /* Try to parse a reg name. */
498 parse_reg (char * s
, unsigned * reg
)
500 /* Strip leading whitespace. */
501 while (ISSPACE (* s
))
504 if (TOLOWER (s
[0]) == 'r')
506 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
508 *reg
= 10 + s
[2] - '0';
512 if (s
[1] >= '0' && s
[1] <= '9')
518 else if ( TOLOWER (s
[0]) == 's'
519 && TOLOWER (s
[1]) == 'p'
526 as_bad (_("register expected, but saw '%.6s'"), s
);
554 parse_creg (char * s
, unsigned * reg
)
558 /* Strip leading whitespace. */
559 while (ISSPACE (* s
))
562 if ((TOLOWER (s
[0]) == 'c' && TOLOWER (s
[1]) == 'r'))
564 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
566 *reg
= 30 + s
[3] - '0';
570 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
572 *reg
= 20 + s
[3] - '0';
576 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
578 *reg
= 10 + s
[3] - '0';
582 if (s
[2] >= '0' && s
[2] <= '9')
589 /* Look at alternate creg names before giving error. */
590 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
596 length
= strlen (cregs
[i
].name
);
598 for (j
= 0; j
< length
; j
++)
599 buf
[j
] = TOLOWER (s
[j
]);
601 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
603 *reg
= cregs
[i
].crnum
;
608 as_bad (_("control register expected, but saw '%.6s'"), s
);
614 parse_psrmod (char * s
, unsigned * reg
)
618 static struct psrmods
628 { "af", 8 } /* Really 0 and non-combinable. */
631 for (i
= 0; i
< 2; i
++)
632 buf
[i
] = TOLOWER (s
[i
]);
634 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
636 if (! strncmp (psrmods
[i
].name
, buf
, 2))
638 * reg
= psrmods
[i
].value
;
644 as_bad (_("bad/missing psr specifier"));
652 parse_exp (char * s
, expressionS
* e
)
657 /* Skip whitespace. */
658 while (ISSPACE (* s
))
661 save
= input_line_pointer
;
662 input_line_pointer
= s
;
666 if (e
->X_op
== O_absent
)
667 as_bad (_("missing operand"));
669 new = input_line_pointer
;
670 input_line_pointer
= save
;
676 enter_literal (expressionS
* e
, int ispcrel
)
681 if (poolsize
>= MAX_POOL_SIZE
- 2)
682 /* The literal pool is as full as we can handle. We have
683 to be 2 entries shy of the 1024/4=256 entries because we
684 have to allow for the branch (2 bytes) and the alignment
685 (2 bytes before the first insn referencing the pool and
686 2 bytes before the pool itself) == 6 bytes, rounds up
692 /* Create new literal pool. */
693 if (++ poolnumber
> 0xFFFF)
694 as_fatal (_("more than 65K literal pools"));
696 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
697 poolsym
= symbol_make (poolname
);
698 symbol_table_insert (poolsym
);
702 /* Search pool for value so we don't have duplicates. */
703 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
705 if (e
->X_op
== p
->e
.X_op
706 && e
->X_add_symbol
== p
->e
.X_add_symbol
707 && e
->X_add_number
== p
->e
.X_add_number
708 && ispcrel
== p
->ispcrel
)
716 p
->ispcrel
= ispcrel
;
724 /* Parse a literal specification. -- either new or old syntax.
725 old syntax: the user supplies the label and places the literal.
726 new syntax: we put it into the literal pool. */
738 /* Indicate nothing there. */
743 s
= parse_exp (s
+ 1, & e
);
748 as_bad (_("missing ']'"));
752 s
= parse_exp (s
, & e
);
754 n
= enter_literal (& e
, ispcrel
);
759 /* Create a reference to pool entry. */
761 e
.X_add_symbol
= poolsym
;
762 e
.X_add_number
= n
<< 2;
765 * outputp
= frag_more (2);
767 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
768 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
782 new = parse_exp (s
, & e
);
784 if (e
.X_op
== O_absent
)
785 ; /* An error message has already been emitted. */
786 else if (e
.X_op
!= O_constant
)
787 as_bad (_("operand must be a constant"));
788 else if ((addressT
) e
.X_add_number
< min
|| (addressT
) e
.X_add_number
> max
)
789 as_bad (_("operand must be absolute in range %u..%u, not %ld"),
790 min
, max
, (long) e
.X_add_number
);
792 * val
= e
.X_add_number
;
805 while (ISSPACE (* s
))
810 s
= parse_reg (s
+ 1, reg
);
812 while (ISSPACE (* s
))
817 s
= parse_imm (s
+ 1, off
, 0, 63);
824 as_bad (_("operand must be a multiple of 4"));
831 as_bad (_("operand must be a multiple of 2"));
838 while (ISSPACE (* s
))
845 as_bad (_("base register expected"));
850 /* This is the guts of the machine-dependent assembler. STR points to a
851 machine dependent instruction. This function is supposed to emit
852 the frags/bytes it assembles to. */
855 md_assemble (char * str
)
859 mcore_opcode_info
* opcode
;
869 /* Drop leading whitespace. */
870 while (ISSPACE (* str
))
873 /* Find the op code end. */
874 for (op_start
= op_end
= str
;
875 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
878 name
[nlen
] = op_start
[nlen
];
886 as_bad (_("can't find opcode "));
890 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
893 as_bad (_("unknown opcode \"%s\""), name
);
900 switch (opcode
->opclass
)
903 output
= frag_more (2);
907 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
909 output
= frag_more (2);
913 op_end
= parse_reg (op_end
+ 1, & reg
);
915 output
= frag_more (2);
919 op_end
= parse_reg (op_end
+ 1, & reg
);
921 output
= frag_more (2);
922 /* In a sifilter mode, we emit this insn 2 times,
923 fixes problem of an interrupt during a jmp.. */
926 output
[0] = INST_BYTE0 (inst
);
927 output
[1] = INST_BYTE1 (inst
);
928 output
= frag_more (2);
933 op_end
= parse_reg (op_end
+ 1, & reg
);
936 as_bad (_("invalid register: r15 illegal"));
939 output
= frag_more (2);
943 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx. */
944 inst
= MCORE_INST_BSR
; /* With 0 displacement. */
945 output
[0] = INST_BYTE0 (inst
);
946 output
[1] = INST_BYTE1 (inst
);
948 output
= frag_more (2);
949 inst
= MCORE_INST_ADDI
;
950 inst
|= 15; /* addi r15,6 */
951 inst
|= (6 - 1) << 4; /* Over the jmp's. */
952 output
[0] = INST_BYTE0 (inst
);
953 output
[1] = INST_BYTE1 (inst
);
955 output
= frag_more (2);
956 inst
= MCORE_INST_JMP
| reg
;
957 output
[0] = INST_BYTE0 (inst
);
958 output
[1] = INST_BYTE1 (inst
);
960 /* 2nd emitted in fallthrough. */
961 output
= frag_more (2);
966 op_end
= parse_reg (op_end
+ 1, & reg
);
969 /* Skip whitespace. */
970 while (ISSPACE (* op_end
))
975 op_end
= parse_creg (op_end
+ 1, & reg
);
979 output
= frag_more (2);
985 as_bad (_("M340 specific opcode used when assembling for M210"));
988 /* drop through... */
990 op_end
= parse_reg (op_end
+ 1, & reg
);
993 /* Skip whitespace. */
994 while (ISSPACE (* op_end
))
999 op_end
= parse_reg (op_end
+ 1, & reg
);
1003 as_bad (_("second operand missing"));
1005 output
= frag_more (2);
1009 /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx. */
1010 op_end
= parse_reg (op_end
+ 1, & reg
);
1012 /* Skip whitespace. */
1013 while (ISSPACE (* op_end
))
1016 if (* op_end
== ',') /* xtrb- r1,rx. */
1019 as_bad (_("destination register must be r1"));
1021 op_end
= parse_reg (op_end
+ 1, & reg
);
1025 output
= frag_more (2);
1028 case O1R1
: /* div- rx,r1. */
1029 op_end
= parse_reg (op_end
+ 1, & reg
);
1032 /* Skip whitespace. */
1033 while (ISSPACE (* op_end
))
1036 if (* op_end
== ',')
1038 op_end
= parse_reg (op_end
+ 1, & reg
);
1040 as_bad (_("source register must be r1"));
1043 as_bad (_("second operand missing"));
1045 output
= frag_more (2);
1049 op_end
= parse_reg (op_end
+ 1, & reg
);
1052 /* Skip whitespace. */
1053 while (ISSPACE (* op_end
))
1056 if (* op_end
== ',')
1058 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1059 inst
|= (reg
- 1) << 4;
1062 as_bad (_("second operand missing"));
1064 output
= frag_more (2);
1068 op_end
= parse_reg (op_end
+ 1, & reg
);
1071 /* Skip whitespace. */
1072 while (ISSPACE (* op_end
))
1075 if (* op_end
== ',')
1077 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1081 as_bad (_("second operand missing"));
1083 output
= frag_more (2);
1087 /* Like OB, but arg is 2^n instead of n. */
1088 op_end
= parse_reg (op_end
+ 1, & reg
);
1091 /* Skip whitespace. */
1092 while (ISSPACE (* op_end
))
1095 if (* op_end
== ',')
1097 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1098 /* Further restrict the immediate to a power of two. */
1099 if ((reg
& (reg
- 1)) == 0)
1104 as_bad (_("immediate is not a power of two"));
1109 as_bad (_("second operand missing"));
1111 output
= frag_more (2);
1114 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1117 op_end
= parse_reg (op_end
+ 1, & reg
);
1120 /* Skip whitespace. */
1121 while (ISSPACE (* op_end
))
1124 if (* op_end
== ',')
1126 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1127 /* Immediate values of 0 -> 6 translate to movi. */
1130 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1132 as_warn (_("translating bgeni to movi"));
1138 as_bad (_("second operand missing"));
1140 output
= frag_more (2);
1143 case OBR2
: /* Like OBR, but arg is 2^n instead of n. */
1144 op_end
= parse_reg (op_end
+ 1, & reg
);
1147 /* Skip whitespace. */
1148 while (ISSPACE (* op_end
))
1151 if (* op_end
== ',')
1153 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1155 /* Further restrict the immediate to a power of two. */
1156 if ((reg
& (reg
- 1)) == 0)
1161 as_bad (_("immediate is not a power of two"));
1164 /* Immediate values of 0 -> 6 translate to movi. */
1167 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1169 as_warn (_("translating mgeni to movi"));
1175 as_bad (_("second operand missing"));
1177 output
= frag_more (2);
1180 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1183 op_end
= parse_reg (op_end
+ 1, & reg
);
1186 /* Skip whitespace. */
1187 while (ISSPACE (* op_end
))
1190 if (* op_end
== ',')
1192 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1194 /* Immediate values of 1 -> 7 translate to movi. */
1197 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1198 reg
= (0x1 << reg
) - 1;
1201 as_warn (_("translating bmaski to movi"));
1206 inst
|= (reg
& 0x1F) << 4;
1210 as_bad (_("second operand missing"));
1212 output
= frag_more (2);
1216 op_end
= parse_reg (op_end
+ 1, & reg
);
1219 /* Skip whitespace. */
1220 while (ISSPACE (* op_end
))
1223 if (* op_end
== ',')
1225 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1229 as_bad (_("second operand missing"));
1231 output
= frag_more (2);
1235 op_end
= parse_reg (op_end
+ 1, & reg
);
1238 /* Skip whitespace. */
1239 while (ISSPACE (* op_end
))
1242 if (* op_end
== ',')
1244 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1248 as_bad (_("second operand missing"));
1250 output
= frag_more (2);
1254 op_end
= parse_reg (op_end
+ 1, & reg
);
1257 /* Skip whitespace. */
1258 while (ISSPACE (* op_end
))
1261 if (* op_end
== ',')
1265 if ((inst
& 0x6000) == 0)
1267 else if ((inst
& 0x6000) == 0x4000)
1269 else if ((inst
& 0x6000) == 0x2000)
1274 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1277 as_bad (_("displacement too large (%d)"), off
);
1279 inst
|= (reg
) | (off
<< 4);
1282 as_bad (_("second operand missing"));
1284 output
= frag_more (2);
1288 op_end
= parse_reg (op_end
+ 1, & reg
);
1290 if (reg
== 0 || reg
== 15)
1291 as_bad (_("Invalid register: r0 and r15 illegal"));
1295 /* Skip whitespace. */
1296 while (ISSPACE (* op_end
))
1299 if (* op_end
== ',')
1301 /* parse_rt calls frag_more() for us. */
1302 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1303 op_end
= input_line_pointer
;
1307 as_bad (_("second operand missing"));
1308 output
= frag_more (2); /* save its space */
1313 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1314 /* parse_rt() calls frag_more() for us. */
1315 op_end
= input_line_pointer
;
1319 op_end
= parse_reg (op_end
+ 1, & reg
);
1321 if (reg
== 0 || reg
== 15)
1322 as_bad (_("bad starting register: r0 and r15 invalid"));
1326 /* Skip whitespace. */
1327 while (ISSPACE (* op_end
))
1330 if (* op_end
== '-')
1332 op_end
= parse_reg (op_end
+ 1, & reg
);
1335 as_bad (_("ending register must be r15"));
1337 /* Skip whitespace. */
1338 while (ISSPACE (* op_end
))
1342 if (* op_end
== ',')
1346 /* Skip whitespace. */
1347 while (ISSPACE (* op_end
))
1350 if (* op_end
== '(')
1352 op_end
= parse_reg (op_end
+ 1, & reg
);
1355 as_bad (_("bad base register: must be r0"));
1357 if (* op_end
== ')')
1361 as_bad (_("base register expected"));
1364 as_bad (_("second operand missing"));
1366 output
= frag_more (2);
1370 op_end
= parse_reg (op_end
+ 1, & reg
);
1373 as_fatal (_("first register must be r4"));
1375 /* Skip whitespace. */
1376 while (ISSPACE (* op_end
))
1379 if (* op_end
== '-')
1381 op_end
= parse_reg (op_end
+ 1, & reg
);
1384 as_fatal (_("last register must be r7"));
1386 /* Skip whitespace. */
1387 while (ISSPACE (* op_end
))
1390 if (* op_end
== ',')
1394 /* Skip whitespace. */
1395 while (ISSPACE (* op_end
))
1398 if (* op_end
== '(')
1400 op_end
= parse_reg (op_end
+ 1, & reg
);
1402 if (reg
>= 4 && reg
<= 7)
1403 as_fatal ("base register cannot be r4, r5, r6, or r7");
1407 /* Skip whitespace. */
1408 while (ISSPACE (* op_end
))
1411 if (* op_end
== ')')
1415 as_bad (_("base register expected"));
1418 as_bad (_("second operand missing"));
1421 as_bad (_("reg-reg expected"));
1423 output
= frag_more (2);
1427 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1428 op_end
= input_line_pointer
;
1430 output
= frag_more (2);
1432 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1433 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1437 op_end
= parse_reg (op_end
+ 1, & reg
);
1440 /* Skip whitespace. */
1441 while (ISSPACE (* op_end
))
1444 if (* op_end
== ',')
1446 op_end
= parse_exp (op_end
+ 1, & e
);
1447 output
= frag_more (2);
1449 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1450 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1454 as_bad (_("second operand missing"));
1455 output
= frag_more (2);
1460 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1461 op_end
= input_line_pointer
;
1463 output
= frag_var (rs_machine_dependent
,
1464 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1465 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1466 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1471 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1472 op_end
= input_line_pointer
;
1474 output
= frag_var (rs_machine_dependent
,
1475 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1476 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1477 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1482 inst
= MCORE_INST_JSRI
; /* jsri */
1483 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1484 /* parse_rt() calls frag_more for us. */
1485 op_end
= input_line_pointer
;
1487 /* Only do this if we know how to do it ... */
1488 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1490 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1491 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1492 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1497 /* SI, but imm becomes 32-imm. */
1498 op_end
= parse_reg (op_end
+ 1, & reg
);
1501 /* Skip whitespace. */
1502 while (ISSPACE (* op_end
))
1505 if (* op_end
== ',')
1507 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1513 as_bad (_("second operand missing"));
1515 output
= frag_more (2);
1518 case DO21
: /* O2, dup rd, lit must be 1 */
1519 op_end
= parse_reg (op_end
+ 1, & reg
);
1523 /* Skip whitespace. */
1524 while (ISSPACE (* op_end
))
1527 if (* op_end
== ',')
1529 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1532 as_bad (_("second operand must be 1"));
1535 as_bad (_("second operand missing"));
1537 output
= frag_more (2);
1541 op_end
= parse_reg (op_end
+ 1, & reg
);
1544 /* Skip whitespace. */
1545 while (ISSPACE (* op_end
))
1548 if (* op_end
== ',')
1550 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1553 as_bad (_("zero used as immediate value"));
1558 as_bad (_("second operand missing"));
1560 output
= frag_more (2);
1566 as_bad (_("M340 specific opcode used when assembling for M210"));
1570 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1572 /* Look for further selectors. */
1573 while (* op_end
== ',')
1577 op_end
= parse_psrmod (op_end
+ 1, & value
);
1580 as_bad (_("duplicated psr bit specifier"));
1586 as_bad (_("`af' must appear alone"));
1588 inst
|= (reg
& 0x7);
1589 output
= frag_more (2);
1593 as_bad (_("unimplemented opcode \"%s\""), name
);
1596 /* Drop whitespace after all the operands have been parsed. */
1597 while (ISSPACE (* op_end
))
1600 /* Give warning message if the insn has more operands than required. */
1601 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1602 as_warn (_("ignoring operands: %s "), op_end
);
1604 output
[0] = INST_BYTE0 (inst
);
1605 output
[1] = INST_BYTE1 (inst
);
1607 check_literals (opcode
->transfer
, isize
);
1611 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1620 subseg_set (text_section
, 0);
1623 /* Various routines to kill one day. */
1624 /* Equal to MAX_PRECISION in atof-ieee.c. */
1625 #define MAX_LITTLENUMS 6
1627 /* Turn a string in input_line_pointer into a floating point constant of type
1628 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1629 emitted is stored in *sizeP. An error message is returned, or NULL on OK. */
1632 md_atof (int type
, char * litP
, int * sizeP
)
1635 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1667 return _("Bad call to MD_NTOF()");
1670 t
= atof_ieee (input_line_pointer
, type
, words
);
1673 input_line_pointer
= t
;
1675 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1677 if (! target_big_endian
)
1679 for (i
= prec
- 1; i
>= 0; i
--)
1681 md_number_to_chars (litP
, (valueT
) words
[i
],
1682 sizeof (LITTLENUM_TYPE
));
1683 litP
+= sizeof (LITTLENUM_TYPE
);
1687 for (i
= 0; i
< prec
; i
++)
1689 md_number_to_chars (litP
, (valueT
) words
[i
],
1690 sizeof (LITTLENUM_TYPE
));
1691 litP
+= sizeof (LITTLENUM_TYPE
);
1697 const char * md_shortopts
= "";
1701 OPTION_JSRI2BSR_ON
= OPTION_MD_BASE
,
1702 OPTION_JSRI2BSR_OFF
,
1704 OPTION_SIFILTER_OFF
,
1710 struct option md_longopts
[] =
1712 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1713 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1714 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1715 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1716 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1717 { "EB", no_argument
, NULL
, OPTION_EB
},
1718 { "EL", no_argument
, NULL
, OPTION_EL
},
1719 { NULL
, no_argument
, NULL
, 0}
1722 size_t md_longopts_size
= sizeof (md_longopts
);
1725 md_parse_option (int c
, char * arg
)
1730 if (streq (arg
, "210"))
1733 target_big_endian
= 1;
1735 else if (streq (arg
, "340"))
1738 as_warn (_("unrecognised cpu type '%s'"), arg
);
1741 case OPTION_EB
: target_big_endian
= 1; break;
1742 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1743 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1744 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1745 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1746 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1754 md_show_usage (FILE * stream
)
1756 fprintf (stream
, _("\
1757 MCORE specific options:\n\
1758 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1759 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1760 -cpu=[210|340] select CPU type\n\
1761 -EB assemble for a big endian system (default)\n\
1762 -EL assemble for a little endian system\n"));
1765 int md_short_jump_size
;
1768 md_create_short_jump (char * ptr ATTRIBUTE_UNUSED
,
1769 addressT from_Nddr ATTRIBUTE_UNUSED
,
1770 addressT to_Nddr ATTRIBUTE_UNUSED
,
1771 fragS
* frag ATTRIBUTE_UNUSED
,
1772 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1774 as_fatal (_("failed sanity check: short_jump"));
1778 md_create_long_jump (char * ptr ATTRIBUTE_UNUSED
,
1779 addressT from_Nddr ATTRIBUTE_UNUSED
,
1780 addressT to_Nddr ATTRIBUTE_UNUSED
,
1781 fragS
* frag ATTRIBUTE_UNUSED
,
1782 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1784 as_fatal (_("failed sanity check: long_jump"));
1787 /* Called after relaxing, change the frags so they know how big they are. */
1790 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1791 segT sec ATTRIBUTE_UNUSED
,
1795 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1797 buffer
= fragP
->fr_fix
+ fragP
->fr_literal
;
1799 switch (fragP
->fr_subtype
)
1801 case C (COND_JUMP
, DISP12
):
1802 case C (UNCD_JUMP
, DISP12
):
1804 /* Get the address of the end of the instruction. */
1805 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1807 int disp
= targ_addr
- next_inst
;
1810 as_bad (_("odd displacement at %x"), next_inst
- 2);
1814 if (! target_big_endian
)
1816 t0
= buffer
[1] & 0xF8;
1818 md_number_to_chars (buffer
, disp
, 2);
1820 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1824 t0
= buffer
[0] & 0xF8;
1826 md_number_to_chars (buffer
, disp
, 2);
1828 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1835 case C (COND_JUMP
, DISP32
):
1836 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1838 /* A conditional branch wont fit into 12 bits so:
1845 If the b!cond is 4 byte aligned, the literal which would
1846 go at x+4 will also be aligned. */
1847 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1848 int needpad
= (first_inst
& 3);
1850 if (! target_big_endian
)
1853 buffer
[0] ^= 0x08; /* Toggle T/F bit. */
1855 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1856 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1860 if (! target_big_endian
)
1862 buffer
[0] = 4; /* Branch over jmpi, pad, and ptr. */
1863 buffer
[2] = 1; /* Jmpi offset of 1 gets the pointer. */
1867 buffer
[1] = 4; /* Branch over jmpi, pad, and ptr. */
1868 buffer
[3] = 1; /* Jmpi offset of 1 gets the pointer. */
1871 buffer
[4] = 0; /* Alignment/pad. */
1873 buffer
[6] = 0; /* Space for 32 bit address. */
1878 /* Make reloc for the long disp. */
1879 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1880 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1882 fragP
->fr_fix
+= C32_LEN
;
1886 /* See comment below about this given gas' limitations for
1887 shrinking the fragment. '3' is the amount of code that
1888 we inserted here, but '4' is right for the space we reserved
1889 for this fragment. */
1890 if (! target_big_endian
)
1892 buffer
[0] = 3; /* Branch over jmpi, and ptr. */
1893 buffer
[2] = 0; /* Jmpi offset of 0 gets the pointer. */
1897 buffer
[1] = 3; /* Branch over jmpi, and ptr. */
1898 buffer
[3] = 0; /* Jmpi offset of 0 gets the pointer. */
1901 buffer
[4] = 0; /* Space for 32 bit address. */
1906 /* Make reloc for the long disp. */
1907 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1908 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1909 fragP
->fr_fix
+= C32_LEN
;
1911 /* Frag is actually shorter (see the other side of this ifdef)
1912 but gas isn't prepared for that. We have to re-adjust
1913 the branch displacement so that it goes beyond the
1914 full length of the fragment, not just what we actually
1916 if (! target_big_endian
)
1917 buffer
[0] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1919 buffer
[1] = 4; /* Jmpi, ptr, and the 'tail pad'. */
1924 case C (UNCD_JUMP
, DISP32
):
1925 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1927 /* An unconditional branch will not fit in 12 bits, make code which
1932 we need a pad if "first_inst" is 4 byte aligned.
1933 [because the natural literal place is x + 2]. */
1934 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1935 int needpad
= !(first_inst
& 3);
1937 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi. */
1938 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1942 if (! target_big_endian
)
1943 buffer
[0] = 1; /* Jmpi offset of 1 since padded. */
1945 buffer
[1] = 1; /* Jmpi offset of 1 since padded. */
1946 buffer
[2] = 0; /* Alignment. */
1948 buffer
[4] = 0; /* Space for 32 bit address. */
1953 /* Make reloc for the long disp. */
1954 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1955 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1957 fragP
->fr_fix
+= U32_LEN
;
1961 if (! target_big_endian
)
1962 buffer
[0] = 0; /* Jmpi offset of 0 if no pad. */
1964 buffer
[1] = 0; /* Jmpi offset of 0 if no pad. */
1965 buffer
[2] = 0; /* Space for 32 bit address. */
1970 /* Make reloc for the long disp. */
1971 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1972 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1973 fragP
->fr_fix
+= U32_LEN
;
1983 /* Applies the desired value to the specified location.
1984 Also sets up addends for 'rela' type relocations. */
1987 md_apply_fix3 (fixS
* fixP
,
1989 segT segment ATTRIBUTE_UNUSED
)
1991 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1992 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1993 const char * symname
;
1994 /* Note: use offsetT because it is signed, valueT is unsigned. */
1995 offsetT val
= *valP
;
1997 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1998 /* Save this for the addend in the relocation record. */
1999 fixP
->fx_addnumber
= val
;
2001 if (fixP
->fx_addsy
!= NULL
)
2004 /* For ELF we can just return and let the reloc that will be generated
2005 take care of everything. For COFF we still have to insert 'val'
2006 into the insn since the addend field will be ignored. */
2013 switch (fixP
->fx_r_type
)
2015 /* Second byte of 2 byte opcode. */
2016 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2018 as_bad_where (file
, fixP
->fx_line
,
2019 _("odd distance branch (0x%lx bytes)"), (long) val
);
2021 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2022 as_bad_where (file
, fixP
->fx_line
,
2023 _("pcrel for branch to %s too far (0x%lx)"),
2024 symname
, (long) val
);
2025 if (target_big_endian
)
2027 buf
[0] |= ((val
>> 8) & 0x7);
2028 buf
[1] |= (val
& 0xff);
2032 buf
[1] |= ((val
>> 8) & 0x7);
2033 buf
[0] |= (val
& 0xff);
2037 /* Lower 8 bits of 2 byte opcode. */
2038 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2042 as_bad_where (file
, fixP
->fx_line
,
2043 _("pcrel for lrw/jmpi/jsri to %s too far (0x%lx)"),
2044 symname
, (long) val
);
2045 else if (! target_big_endian
)
2046 buf
[0] |= (val
& 0xff);
2048 buf
[1] |= (val
& 0xff);
2051 /* Loopt instruction. */
2052 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2053 if ((val
< -32) || (val
> -2))
2054 as_bad_where (file
, fixP
->fx_line
,
2055 _("pcrel for loopt too far (0x%lx)"), (long) val
);
2057 if (! target_big_endian
)
2058 buf
[0] |= (val
& 0xf);
2060 buf
[1] |= (val
& 0xf);
2063 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2064 /* Conditional linker map jsri to bsr. */
2065 /* If its a local target and close enough, fix it.
2066 NB: >= -2k for backwards bsr; < 2k for forwards... */
2067 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2069 long nval
= (val
/ 2) & 0x7ff;
2070 nval
|= MCORE_INST_BSR
;
2072 /* REPLACE the instruction, don't just modify it. */
2073 buf
[0] = INST_BYTE0 (nval
);
2074 buf
[1] = INST_BYTE1 (nval
);
2080 case BFD_RELOC_MCORE_PCREL_32
:
2081 case BFD_RELOC_VTABLE_INHERIT
:
2082 case BFD_RELOC_VTABLE_ENTRY
:
2087 if (fixP
->fx_addsy
!= NULL
)
2089 /* If the fix is an absolute reloc based on a symbol's
2090 address, then it cannot be resolved until the final link. */
2097 if (fixP
->fx_size
== 4)
2099 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2101 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2105 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2112 md_operand (expressionS
* expressionP
)
2114 /* Ignore leading hash symbol, if poresent. */
2115 if (* input_line_pointer
== '#')
2117 input_line_pointer
++;
2118 expression (expressionP
);
2122 int md_long_jump_size
;
2124 /* Called just before address relaxation, return the length
2125 by which a fragment must grow to reach it's destination. */
2127 md_estimate_size_before_relax (fragS
* fragP
, segT segment_type
)
2129 switch (fragP
->fr_subtype
)
2134 case C (UNCD_JUMP
, UNDEF_DISP
):
2135 /* Used to be a branch to somewhere which was unknown. */
2136 if (!fragP
->fr_symbol
)
2137 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2138 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2139 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2141 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2144 case C (COND_JUMP
, UNDEF_DISP
):
2145 /* Used to be a branch to somewhere which was unknown. */
2146 if (fragP
->fr_symbol
2147 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2148 /* Got a symbol and it's defined in this segment, become byte
2149 sized - maybe it will fix up */
2150 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2151 else if (fragP
->fr_symbol
)
2152 /* Its got a segment, but its not ours, so it will always be long. */
2153 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2155 /* We know the abs value. */
2156 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2159 case C (UNCD_JUMP
, DISP12
):
2160 case C (UNCD_JUMP
, DISP32
):
2161 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2162 case C (COND_JUMP
, DISP12
):
2163 case C (COND_JUMP
, DISP32
):
2164 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2165 /* When relaxing a section for the second time, we don't need to
2166 do anything besides return the current size. */
2170 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2173 /* Put number into target byte order. */
2176 md_number_to_chars (char * ptr
, valueT use
, int nbytes
)
2178 if (! target_big_endian
)
2181 case 4: ptr
[3] = (use
>> 24) & 0xff; /* Fall through. */
2182 case 3: ptr
[2] = (use
>> 16) & 0xff; /* Fall through. */
2183 case 2: ptr
[1] = (use
>> 8) & 0xff; /* Fall through. */
2184 case 1: ptr
[0] = (use
>> 0) & 0xff; break;
2190 case 4: *ptr
++ = (use
>> 24) & 0xff; /* Fall through. */
2191 case 3: *ptr
++ = (use
>> 16) & 0xff; /* Fall through. */
2192 case 2: *ptr
++ = (use
>> 8) & 0xff; /* Fall through. */
2193 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2198 /* Round up a section size to the appropriate boundary. */
2201 md_section_align (segT segment ATTRIBUTE_UNUSED
,
2204 /* Byte alignment is fine. */
2208 /* The location from which a PC relative jump should be calculated,
2209 given a PC relative reloc. */
2212 md_pcrel_from_section (fixS
* fixp
, segT sec ATTRIBUTE_UNUSED
)
2215 /* If the symbol is undefined or defined in another section
2216 we leave the add number alone for the linker to fix it later.
2217 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2218 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2219 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2220 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2223 assert (fixp
->fx_size
== 2); /* must be an insn */
2224 return fixp
->fx_size
;
2228 /* The case where we are going to resolve things... */
2229 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2232 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2233 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2236 tc_gen_reloc (asection
* section ATTRIBUTE_UNUSED
, fixS
* fixp
)
2239 bfd_reloc_code_real_type code
;
2241 switch (fixp
->fx_r_type
)
2243 /* These confuse the size/pcrel macro approach. */
2244 case BFD_RELOC_VTABLE_INHERIT
:
2245 case BFD_RELOC_VTABLE_ENTRY
:
2246 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2247 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2248 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2249 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2251 code
= fixp
->fx_r_type
;
2255 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2257 MAP (1, 0, BFD_RELOC_8
);
2258 MAP (2, 0, BFD_RELOC_16
);
2259 MAP (4, 0, BFD_RELOC_32
);
2260 MAP (1, 1, BFD_RELOC_8_PCREL
);
2261 MAP (2, 1, BFD_RELOC_16_PCREL
);
2262 MAP (4, 1, BFD_RELOC_32_PCREL
);
2264 code
= fixp
->fx_r_type
;
2265 as_bad (_("Can not do %d byte %srelocation"),
2267 fixp
->fx_pcrel
? _("pc-relative") : "");
2272 rel
= xmalloc (sizeof (arelent
));
2273 rel
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2274 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2275 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2276 /* Always pass the addend along! */
2277 rel
->addend
= fixp
->fx_addnumber
;
2279 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2281 if (rel
->howto
== NULL
)
2283 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2284 _("Cannot represent relocation type %s"),
2285 bfd_get_reloc_code_name (code
));
2287 /* Set howto to a garbage value so that we can keep going. */
2288 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2289 assert (rel
->howto
!= NULL
);
2296 /* See whether we need to force a relocation into the output file.
2297 This is used to force out switch and PC relative relocations when
2300 mcore_force_relocation (fixS
* fix
)
2302 if (fix
->fx_r_type
== BFD_RELOC_RVA
)
2305 return generic_force_reloc (fix
);
2308 /* Return true if the fix can be handled by GAS, false if it must
2309 be passed through to the linker. */
2312 mcore_fix_adjustable (fixS
* fixP
)
2314 /* We need the symbol name for the VTABLE entries. */
2315 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2316 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2321 #endif /* OBJ_ELF */