1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright (C) 1999 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "../opcodes/mcore-opc.h"
30 #include "elf/mcore.h"
34 #define streq(a,b) (strcmp (a, b) == 0)
37 /* Forward declarations for dumb compilers. */
38 static void mcore_s_literals
PARAMS ((int));
39 static void mcore_cons
PARAMS ((int));
40 static void mcore_float_cons
PARAMS ((int));
41 static void mcore_stringer
PARAMS ((int));
42 static int log2
PARAMS ((unsigned int));
43 static char * parse_reg
PARAMS ((char *, unsigned *));
44 static char * parse_creg
PARAMS ((char *, unsigned *));
45 static char * parse_exp
PARAMS ((char *, expressionS
*));
46 static void make_name
PARAMS ((char *, char *, int));
47 static int enter_literal
PARAMS ((expressionS
*, int));
48 static char * parse_rt
PARAMS ((char *, char **, int, expressionS
*));
49 static char * parse_imm
PARAMS ((char *, unsigned *, unsigned, unsigned));
50 static char * parse_mem
PARAMS ((char *, unsigned *, unsigned *, unsigned));
51 static void dump_literals
PARAMS ((int));
52 static void check_literals
PARAMS ((int, int));
53 static void mcore_s_text
PARAMS ((int));
54 static void mcore_s_data
PARAMS ((int));
55 static void mcore_s_section
PARAMS ((int));
56 static void mcore_s_bss
PARAMS ((int));
58 static void mcore_s_comm
PARAMS ((int));
62 /* Several places in this file insert raw instructions into the
63 object. They should use MCORE_INST_XXX macros to get the opcodes
64 and then use these two macros to crack the MCORE_INST value into
65 the appropriate byte values. */
66 #define INST_BYTE0(x) (((x) >> 8) & 0xFF)
67 #define INST_BYTE1(x) ((x) & 0xFF)
69 const char comment_chars
[] = "#/";
70 const char line_separator_chars
[] = ";";
71 const char line_comment_chars
[] = "#/";
73 const int md_reloc_size
= 8;
75 static int do_jsri2bsr
= 0; /* change here from 1 by Cruess 19 August 97 */
76 static int sifilter_mode
= 0;
78 const char EXP_CHARS
[] = "eE";
80 /* Chars that mean this number is a floating point constant */
83 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
85 #define C(what,length) (((what) << 2) + (length))
86 #define GET_WHAT(x) ((x >> 2))
88 /* These are the two types of relaxable instruction */
97 #define UNDEF_WORD_DISP 4
101 #define C32_LEN 10 /* allow for align */
103 #define U32_LEN 8 /* allow for align */
106 /* Initialize the relax table */
107 const relax_typeS md_relax_table
[] =
109 { 1, 1, 0, 0 }, /* 0: unused */
110 { 1, 1, 0, 0 }, /* 1: unused */
111 { 1, 1, 0, 0 }, /* 2: unused */
112 { 1, 1, 0, 0 }, /* 3: unused */
113 { 1, 1, 0, 0 }, /* 4: unused */
114 { 2048, -2046, C12_LEN
, C(COND_JUMP
, COND32
) }, /* 5: C(COND_JUMP, COND12) */
115 { 0, 0, C32_LEN
, 0 }, /* 6: C(COND_JUMP, COND32) */
116 { 1, 1, 0, 0 }, /* 7: unused */
117 { 1, 1, 0, 0 }, /* 8: unused */
118 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, UNCD32
) }, /* 9: C(UNCD_JUMP, UNCD12) */
119 { 0, 0, U32_LEN
, 0 }, /*10: C(UNCD_JUMP, UNCD32) */
120 { 1, 1, 0, 0 }, /*11: unused */
121 { 0, 0, 0, 0 } /*12: unused */
124 /* LITERAL POOL DATA STRUCTURES */
127 unsigned short refcnt
;
128 unsigned char ispcrel
;
129 unsigned char unused
;
133 #define MAX_POOL_SIZE (1024/4)
134 static struct literal litpool
[MAX_POOL_SIZE
];
135 static unsigned poolsize
;
136 static unsigned poolnumber
;
137 static unsigned long poolspan
;
139 /* SPANPANIC: the point at which we get too scared and force a dump
140 of the literal pool, and perhaps put a branch in place.
142 1024 span of lrw/jmpi/jsri insn (actually span+1)
143 -2 possible alignment at the insn.
144 -2 possible alignment to get the table aligned.
145 -2 an inserted branch around the table.
147 at 1018, we might be in trouble.
148 -- so we have to be smaller than 1018 and since we deal with 2-byte
149 instructions, the next good choice is 1016.
150 -- Note we have a test case that fails when we've got 1018 here. */
151 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding */
152 #define SPANCLOSE (900)
153 #define SPANEXIT (600)
154 static symbolS
* poolsym
; /* label for current pool */
155 static char poolname
[8];
156 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics */
158 /* This table describes all the machine specific pseudo-ops the assembler
159 has to support. The fields are:
160 Pseudo-op name without dot
161 Function to call to execute this pseudo-op
162 Integer arg to pass to the function */
163 const pseudo_typeS md_pseudo_table
[] =
165 { "export", s_globl
, 0 },
166 { "import", s_ignore
, 0 },
167 { "literals", mcore_s_literals
, 0 },
168 { "page", listing_eject
, 0 },
170 /* The following are to intercept the placement of data into the text
171 section (eg addresses for a switch table), so that the space they
172 occupy can be taken into account when deciding whether or not to
173 dump the current literal pool.
174 XXX - currently we do not cope with the .space and .dcb.d directives. */
175 { "ascii", mcore_stringer
, 0 },
176 { "asciz", mcore_stringer
, 1 },
177 { "byte", mcore_cons
, 1 },
178 { "dc", mcore_cons
, 2 },
179 { "dc.b", mcore_cons
, 1 },
180 { "dc.d", mcore_float_cons
, 'd' },
181 { "dc.l", mcore_cons
, 4 },
182 { "dc.s", mcore_float_cons
, 'f' },
183 { "dc.w", mcore_cons
, 2 },
184 { "dc.x", mcore_float_cons
, 'x' },
185 { "double", mcore_float_cons
, 'd'},
186 { "float", mcore_float_cons
, 'f'},
187 { "hword", mcore_cons
, 2 },
188 { "int", mcore_cons
, 4 },
189 { "long", mcore_cons
, 4 },
190 { "octa", mcore_cons
, 16 },
191 { "quad", mcore_cons
, 8 },
192 { "short", mcore_cons
, 2 },
193 { "single", mcore_float_cons
, 'f'},
194 { "string", mcore_stringer
, 1 },
195 { "word", mcore_cons
, 2 },
197 /* Allow for the effect of section changes. */
198 { "text", mcore_s_text
, 0 },
199 { "data", mcore_s_data
, 0 },
200 { "bss", mcore_s_bss
, 1 },
202 { "comm", mcore_s_comm
, 0 },
204 { "section", mcore_s_section
, 0 },
205 { "section.s", mcore_s_section
, 0 },
206 { "sect", mcore_s_section
, 0 },
207 { "sect.s", mcore_s_section
, 0 },
213 mcore_s_literals (ignore
)
217 demand_empty_rest_of_line ();
225 if (now_seg
== text_section
)
227 char * ptr
= input_line_pointer
;
230 /* Count the number of commas on the line. */
231 while (! is_end_of_line
[* ptr
])
232 commas
+= * ptr
++ == ',';
234 poolspan
+= nbytes
* commas
;
239 /* In theory we ought to call check_literals (2,0) here in case
240 we need to dump the literal table. We cannot do this however,
241 as the directives that we are intercepting may be being used
242 to build a switch table, and we must not interfere with its
243 contents. Instead we cross our fingers and pray... */
247 mcore_float_cons (float_type
)
250 if (now_seg
== text_section
)
252 char * ptr
= input_line_pointer
;
255 #ifdef REPEAT_CONS_EXPRESSIONS
256 #error REPEAT_CONS_EXPRESSIONS not handled
259 /* Count the number of commas on the line. */
260 while (! is_end_of_line
[* ptr
])
261 commas
+= * ptr
++ == ',';
263 /* We would like to compute "hex_float (float_type) * commas"
264 but hex_float is not exported from read.c */
265 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
266 poolspan
+= float_type
* commas
;
269 float_cons (float_type
);
271 /* See the comment in mcore_cons () about calling check_literals.
272 It is unlikely that a switch table will be constructed using
273 floating point values, but it is still likely that an indexed
274 table of floating point constants is being created by these
275 directives, so again we must not interfere with their placement. */
279 mcore_stringer (append_zero
)
282 if (now_seg
== text_section
)
284 char * ptr
= input_line_pointer
;
286 /* In theory we should compute how many bytes are going to
287 be occupied by the string(s) and add this to the poolspan.
288 To keep things simple however, we just add the number of
289 bytes left on the current line. This will be an over-
290 estimate, which is OK, and automatically allows for the
291 appending a zero byte, since the real string(s) is/are
292 required to be enclosed in double quotes. */
293 while (! is_end_of_line
[* ptr
])
296 poolspan
+= ptr
- input_line_pointer
;
299 stringer (append_zero
);
301 /* We call check_literals here in case a large number of strings are
302 being placed into the text section with a sequence of stringer
303 directives. In theory we could be upsetting something if these
304 strings are actually in an indexed table instead of referenced by
305 individual labels. Let us hope that that never happens. */
306 check_literals (2, 0);
309 /* Handle the section changing pseudo-ops. These call through to the
310 normal implementations, but they dump the literal pool first. */
313 mcore_s_text (ignore
)
319 obj_elf_text (ignore
);
326 mcore_s_data (ignore
)
332 obj_elf_data (ignore
);
339 mcore_s_section (ignore
)
345 obj_elf_section (ignore
);
348 obj_coff_section (ignore
);
353 mcore_s_bss (needs_align
)
358 s_lcomm_bytes (needs_align
);
363 mcore_s_comm (needs_align
)
368 obj_elf_common (needs_align
);
372 /* This function is called once, at assembler startup time. This should
373 set up all the tables, etc that the MD part of the assembler needs. */
377 mcore_opcode_info
* opcode
;
378 char * prev_name
= "";
380 opcode_hash_control
= hash_new ();
382 /* Insert unique names into hash table */
383 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
385 if (streq (prev_name
, opcode
->name
))
387 /* Make all the opcodes with the same name point to the same
389 opcode
->name
= prev_name
;
393 prev_name
= opcode
->name
;
394 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
401 static expressionS immediate
; /* absolute expression */
403 /* Get a log2(val). */
418 /* Try to parse a reg name. */
424 /* Strip leading whitespace. */
425 while (isspace (* s
))
428 if (tolower (s
[0]) == 'r')
430 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
432 *reg
= 10 + s
[2] - '0';
436 if (s
[1] >= '0' && s
[1] <= '9')
442 else if ( tolower (s
[0]) == 's'
443 && tolower (s
[1]) == 'p'
450 as_bad (_("register expected, but saw '%.6s'"), s
);
484 /* Strip leading whitespace. */
485 while (isspace (* s
))
488 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
490 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
492 *reg
= 30 + s
[3] - '0';
496 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
498 *reg
= 20 + s
[3] - '0';
502 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
504 *reg
= 10 + s
[3] - '0';
508 if (s
[2] >= '0' && s
[2] <= '9')
515 /* Look at alternate creg names before giving error. */
516 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
522 length
= strlen (cregs
[i
].name
);
524 for (j
= 0; j
< length
; j
++)
525 buf
[j
] = tolower (s
[j
]);
527 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
529 *reg
= cregs
[i
].crnum
;
534 as_bad (_("control register expected, but saw '%.6s'"), s
);
547 /* Skip whitespace. */
548 while (isspace (* s
))
551 save
= input_line_pointer
;
552 input_line_pointer
= s
;
556 if (e
->X_op
== O_absent
)
557 as_bad (_("missing operand"));
559 new = input_line_pointer
;
560 input_line_pointer
= save
;
571 static const char hex
[] = "0123456789ABCDEF";
576 s
[3] = hex
[(n
>> 12) & 0xF];
577 s
[4] = hex
[(n
>> 8) & 0xF];
578 s
[5] = hex
[(n
>> 4) & 0xF];
579 s
[6] = hex
[(n
) & 0xF];
583 #define POOL_END_LABEL ".LE"
584 #define POOL_START_LABEL ".LS"
587 dump_literals (isforce
)
597 /* Must we branch around the literal table? */
603 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
605 brarsym
= symbol_make (brarname
);
607 symbol_table_insert (brarsym
);
609 output
= frag_var (rs_machine_dependent
,
610 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
611 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
612 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
613 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
614 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
617 /* Make sure that the section is sufficiently aligned and that
618 the literal table is aligned within it. */
619 record_alignment (now_seg
, 2);
620 frag_align (2, 0, 0);
622 colon (S_GET_NAME (poolsym
));
624 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
625 emit_expr (& p
->e
, 4);
628 colon (S_GET_NAME (brarsym
));
634 check_literals (kind
, offset
)
640 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
641 SPANPANIC means that we must dump now.
642 kind == 0 is any old instruction.
643 kind > 0 means we just had a control transfer instruction.
644 kind == 1 means within a function
645 kind == 2 means we just left a function
647 The dump_literals (1) call inserts a branch around the table, so
648 we first look to see if its a situation where we won't have to
649 insert a branch (e.g., the previous instruction was an unconditional
652 SPANPANIC is the point where we must dump a single-entry pool.
653 it accounts for alignments and an inserted branch.
654 the 'poolsize*2' accounts for the scenario where we do:
655 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
656 Note that the 'lit2' reference is 2 bytes further along
657 but the literal it references will be 4 bytes further along,
658 so we must consider the poolsize into this equation.
659 This is slightly over-cautious, but guarantees that we won't
660 panic because a relocation is too distant. */
662 if (poolspan
> SPANCLOSE
&& kind
> 0)
664 else if (poolspan
> SPANEXIT
&& kind
> 1)
666 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
671 enter_literal (e
, ispcrel
)
678 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
691 /* Create new literal pool. */
692 if (++ poolnumber
> 0xFFFF)
693 as_fatal (_("more than 65K literal pools"));
695 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
696 poolsym
= symbol_make (poolname
);
697 symbol_table_insert (poolsym
);
701 /* Search pool for value so we don't have duplicates. */
702 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
704 if (e
->X_op
== p
->e
.X_op
705 && e
->X_add_symbol
== p
->e
.X_add_symbol
706 && e
->X_add_number
== p
->e
.X_add_number
707 && ispcrel
== p
->ispcrel
)
715 p
->ispcrel
= ispcrel
;
723 /* Parse a literal specification. -- either new or old syntax.
724 old syntax: the user supplies the label and places the literal.
725 new syntax: we put it into the literal pool. */
727 parse_rt (s
, outputp
, ispcrel
, ep
)
737 /* Indicate nothing there. */
742 s
= parse_exp (s
+ 1, & e
);
747 as_bad (_("missing ']'"));
751 s
= parse_exp (s
, & e
);
753 n
= enter_literal (& e
, ispcrel
);
758 /* Create a reference to pool entry. */
760 e
.X_add_symbol
= poolsym
;
761 e
.X_add_number
= n
<< 2;
764 * outputp
= frag_more (2);
766 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
767 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
773 parse_imm (s
, val
, min
, max
)
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 (e
.X_add_number
< min
|| e
.X_add_number
> max
)
789 as_bad (_("operand must be absolute in range %d..%d, not %d"),
790 min
, max
, e
.X_add_number
);
792 * val
= e
.X_add_number
;
798 parse_mem (s
, reg
, off
, siz
)
808 while (isspace (* s
))
813 s
= parse_reg (s
+ 1, reg
);
815 while (isspace (* s
))
820 s
= parse_imm (s
+ 1, off
, 0, 63);
827 as_bad (_("operand must be a multiple of 4"));
834 as_bad (_("operand must be a multiple of 2"));
841 while (isspace (* s
))
848 as_bad (_("base register expected"));
853 /* This is the guts of the machine-dependent assembler. STR points to a
854 machine dependent instruction. This function is supposed to emit
855 the frags/bytes it assembles to. */
863 mcore_opcode_info
* opcode
;
873 /* Drop leading whitespace. */
874 while (isspace (* str
))
877 /* Find the op code end. */
878 for (op_start
= op_end
= str
;
879 * op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
882 name
[nlen
] = op_start
[nlen
];
890 as_bad (_("can't find opcode "));
894 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
897 as_bad (_("unknown opcode \"%s\""), name
);
904 switch (opcode
->opclass
)
907 output
= frag_more (2);
911 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
913 output
= frag_more (2);
917 op_end
= parse_reg (op_end
+ 1, & reg
);
919 output
= frag_more (2);
923 op_end
= parse_reg (op_end
+ 1, & reg
);
925 output
= frag_more (2);
926 /* In a sifilter mode, we emit this insn 2 times,
927 fixes problem of an interrupt during a jmp.. */
930 output
[0] = INST_BYTE0 (inst
);
931 output
[1] = INST_BYTE1 (inst
);
932 output
= frag_more (2);
937 op_end
= parse_reg (op_end
+ 1, & reg
);
940 as_bad (_("invalid register: r15 illegal"));
943 output
= frag_more (2);
947 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
948 inst
= MCORE_INST_BSR
; /* with 0 displacement */
949 output
[0] = INST_BYTE0 (inst
);
950 output
[1] = INST_BYTE1 (inst
);
952 output
= frag_more (2);
953 inst
= MCORE_INST_ADDI
;
954 inst
|= 15; /* addi r15,6 */
955 inst
|= (6 - 1) << 4; /* over the jmp's */
956 output
[0] = INST_BYTE0 (inst
);
957 output
[1] = INST_BYTE1 (inst
);
959 output
= frag_more (2);
960 inst
= MCORE_INST_JMP
| reg
;
961 output
[0] = INST_BYTE0 (inst
);
962 output
[1] = INST_BYTE1 (inst
);
964 output
= frag_more (2); /* 2nd emitted in fallthru */
969 op_end
= parse_reg (op_end
+ 1, & reg
);
972 /* Skip whitespace. */
973 while (isspace (* op_end
))
978 op_end
= parse_creg (op_end
+ 1, & reg
);
982 output
= frag_more (2);
986 op_end
= parse_reg (op_end
+ 1, & reg
);
989 /* Skip whitespace. */
990 while (isspace (* op_end
))
995 op_end
= parse_reg (op_end
+ 1, & reg
);
999 as_bad (_("second operand missing"));
1001 output
= frag_more (2);
1004 case X1
: /* 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);
1081 case OB2
: /* like OB, but arg is 2^n instead of n */
1082 op_end
= parse_reg (op_end
+ 1, & reg
);
1085 /* Skip whitespace. */
1086 while (isspace (* op_end
))
1089 if (* op_end
== ',')
1091 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1092 /* Further restrict the immediate to a power of two. */
1093 if ((reg
& (reg
- 1)) == 0)
1098 as_bad (_("immediate is not a power of two"));
1103 as_bad (_("second operand missing"));
1105 output
= frag_more (2);
1108 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1111 op_end
= parse_reg (op_end
+ 1, & reg
);
1114 /* Skip whitespace. */
1115 while (isspace (* op_end
))
1118 if (* op_end
== ',')
1120 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1121 /* immediate values of 0 -> 6 translate to movi */
1124 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1126 as_warn (_("translating bgeni to movi"));
1132 as_bad (_("second operand missing"));
1134 output
= frag_more (2);
1137 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1138 op_end
= parse_reg (op_end
+ 1, & reg
);
1141 /* Skip whitespace. */
1142 while (isspace (* op_end
))
1145 if (* op_end
== ',')
1147 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1149 /* Further restrict the immediate to a power of two. */
1150 if ((reg
& (reg
- 1)) == 0)
1155 as_bad (_("immediate is not a power of two"));
1158 /* Immediate values of 0 -> 6 translate to movi. */
1161 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1163 as_warn (_("translating mgeni to movi"));
1169 as_bad (_("second operand missing"));
1171 output
= frag_more (2);
1174 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1177 op_end
= parse_reg (op_end
+ 1, & reg
);
1180 /* Skip whitespace. */
1181 while (isspace (* op_end
))
1184 if (* op_end
== ',')
1186 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1188 /* Immediate values of 1 -> 7 translate to movi. */
1191 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1192 reg
= (0x1 << reg
) - 1;
1195 as_warn (_("translating bmaski to movi"));
1200 inst
|= (reg
& 0x1F) << 4;
1204 as_bad (_("second operand missing"));
1206 output
= frag_more (2);
1210 op_end
= parse_reg (op_end
+ 1, & reg
);
1213 /* Skip whitespace. */
1214 while (isspace (* op_end
))
1217 if (* op_end
== ',')
1219 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1223 as_bad (_("second operand missing"));
1225 output
= frag_more (2);
1229 op_end
= parse_reg (op_end
+ 1, & reg
);
1232 /* Skip whitespace. */
1233 while (isspace (* op_end
))
1236 if (* op_end
== ',')
1238 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1242 as_bad (_("second operand missing"));
1244 output
= frag_more (2);
1248 op_end
= parse_reg (op_end
+ 1, & reg
);
1251 /* Skip whitespace. */
1252 while (isspace (* op_end
))
1255 if (* op_end
== ',')
1259 if ((inst
& 0x6000) == 0)
1261 else if ((inst
& 0x6000) == 0x4000)
1263 else if ((inst
& 0x6000) == 0x2000)
1266 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1269 as_bad (_("displacement too large (%d)"), off
);
1271 inst
|= (reg
) | (off
<< 4);
1274 as_bad (_("second operand missing"));
1276 output
= frag_more (2);
1280 op_end
= parse_reg (op_end
+ 1, & reg
);
1282 if (reg
== 0 || reg
== 15)
1283 as_bad (_("Invalid register: r0 and r15 illegal"));
1287 /* Skip whitespace. */
1288 while (isspace (* op_end
))
1291 if (* op_end
== ',')
1292 /* parse_rt calls frag_more() for us. */
1293 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1296 as_bad (_("second operand missing"));
1297 output
= frag_more (2); /* save its space */
1302 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1303 /* parse_rt() calls frag_more() for us. */
1307 op_end
= parse_reg (op_end
+ 1, & reg
);
1309 if (reg
== 0 || reg
== 15)
1310 as_bad (_("bad starting register: r0 and r15 invalid"));
1314 /* Skip whitespace. */
1315 while (isspace (* op_end
))
1318 if (* op_end
== '-')
1320 op_end
= parse_reg (op_end
+ 1, & reg
);
1323 as_bad (_("ending register must be r15"));
1325 /* Skip whitespace. */
1326 while (isspace (* op_end
))
1330 if (* op_end
== ',')
1334 /* Skip whitespace. */
1335 while (isspace (* op_end
))
1338 if (* op_end
== '(')
1340 op_end
= parse_reg (op_end
+ 1, & reg
);
1343 as_bad (_("bad base register: must be r0"));
1345 if (* op_end
== ')')
1349 as_bad (_("base register expected"));
1352 as_bad (_("second operand missing"));
1354 output
= frag_more (2);
1358 op_end
= parse_reg (op_end
+ 1, & reg
);
1361 as_fatal (_("first register must be r4"));
1363 /* Skip whitespace. */
1364 while (isspace (* op_end
))
1367 if (* op_end
== '-')
1369 op_end
= parse_reg (op_end
+ 1, & reg
);
1372 as_fatal (_("last register must be r7"));
1374 /* Skip whitespace. */
1375 while (isspace (* op_end
))
1378 if (* op_end
== ',')
1382 /* Skip whitespace. */
1383 while (isspace (* op_end
))
1386 if (* op_end
== '(')
1388 op_end
= parse_reg (op_end
+ 1, & reg
);
1390 if (reg
>= 4 && reg
<= 7)
1391 as_fatal ("base register cannot be r4, r5, r6, or r7");
1395 /* Skip whitespace. */
1396 while (isspace (* op_end
))
1399 if (* op_end
== ')')
1403 as_bad (_("base register expected"));
1406 as_bad (_("second operand missing"));
1409 as_bad (_("reg-reg expected"));
1411 output
= frag_more (2);
1415 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1417 output
= frag_more (2);
1419 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1420 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1424 op_end
= parse_reg (op_end
+ 1, & reg
);
1427 /* Skip whitespace. */
1428 while (isspace (* op_end
))
1431 if (* op_end
== ',')
1433 op_end
= parse_exp (op_end
+ 1, & e
);
1434 output
= frag_more (2);
1436 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1437 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1441 as_bad (_("second operand missing"));
1442 output
= frag_more (2);
1447 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1449 output
= frag_var (rs_machine_dependent
,
1450 md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
,
1451 md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
,
1452 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1457 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1458 output
= frag_var (rs_machine_dependent
,
1459 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
1460 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
1461 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1466 inst
= MCORE_INST_JSRI
; /* jsri */
1467 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1468 /* parse_rt() calls frag_more for us */
1470 /* Only do this if we know how to do it ... */
1471 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1473 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1474 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1475 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1479 case RSI
: /* SI, but imm becomes 32-imm */
1480 op_end
= parse_reg (op_end
+ 1, & reg
);
1483 /* Skip whitespace. */
1484 while (isspace (* op_end
))
1487 if (* op_end
== ',')
1489 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1495 as_bad (_("second operand missing"));
1497 output
= frag_more (2);
1500 case DO21
: /* O2, dup rd, lit must be 1 */
1501 op_end
= parse_reg (op_end
+ 1, & reg
);
1505 /* Skip whitespace. */
1506 while (isspace (* op_end
))
1509 if (* op_end
== ',')
1511 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1514 as_bad (_("second operand must be 1"));
1517 as_bad (_("second operand missing"));
1519 output
= frag_more (2);
1523 op_end
= parse_reg (op_end
+ 1, & reg
);
1526 /* Skip whitespace. */
1527 while (isspace (* op_end
))
1530 if (* op_end
== ',')
1532 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1535 as_bad (_("zero used as immediate value"));
1540 as_bad (_("second operand missing"));
1542 output
= frag_more (2);
1546 as_bad (_("unimplemented opcode \"%s\""), name
);
1549 output
[0] = INST_BYTE0 (inst
);
1550 output
[1] = INST_BYTE1 (inst
);
1552 check_literals (opcode
->transfer
, isize
);
1556 md_undefined_symbol (name
)
1566 subseg_set (text_section
, 0);
1569 /* Various routines to kill one day. */
1570 /* Equal to MAX_PRECISION in atof-ieee.c */
1571 #define MAX_LITTLENUMS 6
1573 /* Turn a string in input_line_pointer into a floating point constant of type
1574 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1575 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1577 md_atof (type
, litP
, sizeP
)
1583 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1586 char * atof_ieee ();
1616 return _("Bad call to MD_NTOF()");
1619 t
= atof_ieee (input_line_pointer
, type
, words
);
1622 input_line_pointer
= t
;
1624 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1626 for (i
= 0; i
< prec
; i
++)
1628 md_number_to_chars (litP
, (valueT
) words
[i
],
1629 sizeof (LITTLENUM_TYPE
));
1630 litP
+= sizeof (LITTLENUM_TYPE
);
1636 CONST
char * md_shortopts
= "";
1638 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1639 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1640 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1641 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1643 struct option md_longopts
[] =
1645 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1646 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1647 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1648 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1649 { NULL
, no_argument
, NULL
, 0}
1652 size_t md_longopts_size
= sizeof (md_longopts
);
1655 md_parse_option (c
, arg
)
1665 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1666 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1667 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1668 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1676 md_show_usage (stream
)
1679 fprintf (stream
, _("\
1680 MCORE specific options:\n\
1681 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1682 -{no-}sifilter {dis}able silicon filter behavior (def: dis)"));
1685 int md_short_jump_size
;
1688 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1693 symbolS
* to_symbol
;
1695 as_fatal (_("failed sanity check: short_jump"));
1699 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1704 symbolS
* to_symbol
;
1706 as_fatal (_("failed sanity check: long_jump"));
1709 /* Called after relaxing, change the frags so they know how big they are. */
1711 md_convert_frag (abfd
, sec
, fragP
)
1714 register fragS
* fragP
;
1716 unsigned char * buffer
;
1717 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1719 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1720 targ_addr
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
1722 switch (fragP
->fr_subtype
)
1724 case C (COND_JUMP
, COND12
):
1725 case C (UNCD_JUMP
, UNCD12
):
1727 /* Get the address of the end of the instruction */
1728 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1730 int disp
= targ_addr
- next_inst
;
1733 as_bad (_("odd displacement at %x"), next_inst
- 2);
1737 t0
= buffer
[0] & 0xF8;
1739 md_number_to_chars (buffer
, disp
, 2);
1741 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1749 case C (COND_JUMP
, COND32
):
1750 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1752 /* A conditional branch wont fit into 12 bits so:
1759 * if the b!cond is 4 byte aligned, the literal which would
1760 * go at x+4 will also be aligned.
1762 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1763 int needpad
= (first_inst
& 3);
1765 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1767 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1768 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1773 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1774 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1777 buffer
[4] = 0; /* alignment/pad */
1779 buffer
[6] = 0; /* space for 32 bit address */
1784 /* Make reloc for the long disp */
1785 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1786 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1788 fragP
->fr_fix
+= C32_LEN
;
1792 /* See comment below about this given gas' limitations for
1793 shrinking the fragment. '3' is the amount of code that
1794 we inserted here, but '4' is right for the space we reserved
1795 for this fragment. */
1797 buffer
[1] = 3; /* branch over jmpi, and ptr */
1798 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1801 buffer
[4] = 0; /* space for 32 bit address */
1806 /* Make reloc for the long disp. */
1807 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1808 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1809 fragP
->fr_fix
+= C32_LEN
;
1811 /* Frag is actually shorter (see the other side of this ifdef)
1812 but gas isn't prepared for that. We have to re-adjust
1813 the branch displacement so that it goes beyond the
1814 full length of the fragment, not just what we actually
1816 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1823 case C (UNCD_JUMP
, UNCD32
):
1824 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1826 /* An unconditional branch will not fit in 12 bits, make code which
1831 we need a pad if "first_inst" is 4 byte aligned.
1832 [because the natural literal place is x + 2] */
1833 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1834 int needpad
= !(first_inst
& 3);
1836 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1837 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1841 buffer
[1] = 1; /* jmpi offset of 1 since padded */
1842 buffer
[2] = 0; /* alignment */
1844 buffer
[4] = 0; /* space for 32 bit address */
1849 /* Make reloc for the long disp */
1850 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1851 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1853 fragP
->fr_fix
+= U32_LEN
;
1857 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
1858 buffer
[2] = 0; /* space for 32 bit address */
1863 /* Make reloc for the long disp */
1864 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1865 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1866 fragP
->fr_fix
+= U32_LEN
;
1878 /* Applies the desired value to the specified location.
1879 Also sets up addends for 'rela' type relocations. */
1881 md_apply_fix3 (fixP
, valp
, segment
)
1886 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1887 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1888 const char * symname
;
1889 /* Note: use offsetT because it is signed, valueT is unsigned. */
1890 offsetT val
= (offsetT
) * valp
;
1892 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1893 /* Save this for the addend in the relocation record. */
1894 fixP
->fx_addnumber
= val
;
1896 /* If the fix is relative to a symbol which is not defined, or not
1897 in the same segment as the fix, we cannot resolve it here. */
1898 if (fixP
->fx_addsy
!= NULL
1899 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
1900 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
1904 /* For ELF we can just return and let the reloc that will be generated
1905 take care of everything. For COFF we still have to insert 'val'
1906 into the insn since the addend field will be ignored. */
1913 switch (fixP
->fx_r_type
)
1915 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
1917 as_bad_where (file
, fixP
->fx_line
,
1918 _("odd distance branch (0x%x bytes)"), val
);
1920 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
1921 as_bad_where (file
, fixP
->fx_line
,
1922 _("pcrel for branch to %s too far (0x%x)"),
1924 buf
[0] |= ((val
>> 8) & 0x7);
1925 buf
[1] |= (val
& 0xff);
1928 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
1932 as_bad_where (file
, fixP
->fx_line
,
1933 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
1936 buf
[1] |= (val
& 0xff);
1939 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
1940 if ((val
< -32) || (val
> -2))
1941 as_bad_where (file
, fixP
->fx_line
,
1942 _("pcrel for loopt too far (0x%x)"), val
);
1944 buf
[1] |= (val
& 0xf);
1947 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
1948 /* Conditional linker map jsri to bsr. */
1949 /* If its a local target and close enough, fix it.
1950 NB: >= -2k for backwards bsr; < 2k for forwards... */
1951 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
1953 long nval
= (val
/ 2) & 0x7ff;
1954 nval
|= MCORE_INST_BSR
;
1956 /* REPLACE the instruction, don't just modify it. */
1957 buf
[0] = INST_BYTE0 (nval
);
1958 buf
[1] = INST_BYTE1 (nval
);
1964 case BFD_RELOC_MCORE_PCREL_32
:
1965 case BFD_RELOC_VTABLE_INHERIT
:
1966 case BFD_RELOC_VTABLE_ENTRY
:
1971 if (fixP
->fx_addsy
!= NULL
)
1973 /* If the fix is an absolute reloc based on a symbol's
1974 address, then it cannot be resolved until the final link. */
1981 if (fixP
->fx_size
== 4)
1983 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
1985 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
1989 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1994 return 0; /* Return value is ignored. */
1998 md_operand (expressionP
)
1999 expressionS
* expressionP
;
2001 /* Ignore leading hash symbol, if poresent. */
2002 if (* input_line_pointer
== '#')
2004 input_line_pointer
++;
2005 expression (expressionP
);
2009 int md_long_jump_size
;
2011 /* Called just before address relaxation, return the length
2012 by which a fragment must grow to reach it's destination. */
2014 md_estimate_size_before_relax (fragP
, segment_type
)
2015 register fragS
* fragP
;
2016 register segT segment_type
;
2018 switch (fragP
->fr_subtype
)
2020 case C (UNCD_JUMP
, UNDEF_DISP
):
2021 /* Used to be a branch to somewhere which was unknown. */
2022 if (!fragP
->fr_symbol
)
2024 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2025 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2027 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2029 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2030 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2034 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2035 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2036 return md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2043 case C (COND_JUMP
, UNDEF_DISP
):
2044 /* Used to be a branch to somewhere which was unknown. */
2045 if (fragP
->fr_symbol
2046 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2048 /* Got a symbol and it's defined in this segment, become byte
2049 sized - maybe it will fix up */
2050 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2051 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2053 else if (fragP
->fr_symbol
)
2055 /* Its got a segment, but its not ours, so it will always be long. */
2056 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2057 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2058 return md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2062 /* We know the abs value. */
2063 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2064 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2070 return fragP
->fr_var
;
2073 /* Put number into target byte order */
2075 md_number_to_chars (ptr
, use
, nbytes
)
2082 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2083 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2084 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2085 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2090 /* Round up a section size to the appropriate boundary. */
2092 md_section_align (segment
, size
)
2096 return size
; /* Byte alignment is fine */
2100 /* The location from which a PC relative jump should be calculated,
2101 given a PC relative reloc. */
2103 md_pcrel_from_section (fixp
, sec
)
2108 /* If the symbol is undefined or defined in another section
2109 we leave the add number alone for the linker to fix it later.
2110 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2111 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2112 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2113 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2116 assert (fixp
->fx_size
== 2); /* must be an insn */
2117 return fixp
->fx_size
;
2121 /* The case where we are going to resolve things... */
2122 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2125 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2126 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2129 tc_gen_reloc (section
, fixp
)
2134 bfd_reloc_code_real_type code
;
2137 switch (fixp
->fx_r_type
)
2139 /* These confuse the size/pcrel macro approach. */
2140 case BFD_RELOC_VTABLE_INHERIT
:
2141 case BFD_RELOC_VTABLE_ENTRY
:
2142 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2143 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2144 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2145 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2146 code
= fixp
->fx_r_type
;
2150 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2152 MAP (1, 0, BFD_RELOC_8
);
2153 MAP (2, 0, BFD_RELOC_16
);
2154 MAP (4, 0, BFD_RELOC_32
);
2155 MAP (1, 1, BFD_RELOC_8_PCREL
);
2156 MAP (2, 1, BFD_RELOC_16_PCREL
);
2157 MAP (4, 1, BFD_RELOC_32_PCREL
);
2159 code
= fixp
->fx_r_type
;
2160 as_bad (_("Can not do %d byte %srelocation"),
2162 fixp
->fx_pcrel
? _("pc-relative") : "");
2167 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2168 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2169 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2170 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2171 /* Always pass the addend along! */
2172 rel
->addend
= fixp
->fx_addnumber
;
2174 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2176 if (rel
->howto
== NULL
)
2178 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2179 _("Cannot represent relocation type %s"),
2180 bfd_get_reloc_code_name (code
));
2182 /* Set howto to a garbage value so that we can keep going. */
2183 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2184 assert (rel
->howto
!= NULL
);
2191 /* See whether we need to force a relocation into the output file.
2192 This is used to force out switch and PC relative relocations when
2195 mcore_force_relocation (fix
)
2198 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2199 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2205 /* Return true if the fix can be handled by GAS, false if it must
2206 be passed through to the linker. */
2208 mcore_fix_adjustable (fixP
)
2211 if (fixP
->fx_addsy
== NULL
)
2214 /* We need the symbol name for the VTABLE entries. */
2215 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2216 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2221 #endif /* OBJ_ELF */