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 the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "../opcodes/mcore-opc.h"
31 #include "elf/mcore.h"
35 #define streq(a,b) (strcmp (a, b) == 0)
38 /* Forward declarations for dumb compilers. */
39 static void mcore_s_literals
PARAMS ((int));
40 static void mcore_cons
PARAMS ((int));
41 static void mcore_float_cons
PARAMS ((int));
42 static void mcore_stringer
PARAMS ((int));
43 static void mcore_fill
PARAMS ((int));
44 static int log2
PARAMS ((unsigned int));
45 static char * parse_reg
PARAMS ((char *, unsigned *));
46 static char * parse_creg
PARAMS ((char *, unsigned *));
47 static char * parse_exp
PARAMS ((char *, expressionS
*));
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 make_name
PARAMS ((char *, char *, int));
52 static int enter_literal
PARAMS ((expressionS
*, int));
53 static void dump_literals
PARAMS ((int));
54 static void check_literals
PARAMS ((int, int));
55 static void mcore_s_text
PARAMS ((int));
56 static void mcore_s_data
PARAMS ((int));
57 static void mcore_s_section
PARAMS ((int));
58 static void mcore_s_bss
PARAMS ((int));
60 static void mcore_s_comm
PARAMS ((int));
63 /* Several places in this file insert raw instructions into the
64 object. They should use MCORE_INST_XXX macros to get the opcodes
65 and then use these two macros to crack the MCORE_INST value into
66 the appropriate byte values. */
67 #define INST_BYTE0(x) (((x) >> 8) & 0xFF)
68 #define INST_BYTE1(x) ((x) & 0xFF)
70 const char comment_chars
[] = "#/";
71 const char line_separator_chars
[] = ";";
72 const char line_comment_chars
[] = "#/";
74 const int md_reloc_size
= 8;
76 static int do_jsri2bsr
= 0; /* change here from 1 by Cruess 19 August 97 */
77 static int sifilter_mode
= 0;
79 const char EXP_CHARS
[] = "eE";
81 /* Chars that mean this number is a floating point constant */
84 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
86 #define C(what,length) (((what) << 2) + (length))
87 #define GET_WHAT(x) ((x >> 2))
89 /* These are the two types of relaxable instruction */
98 #define UNDEF_WORD_DISP 4
102 #define C32_LEN 10 /* allow for align */
104 #define U32_LEN 8 /* allow for align */
107 /* Initialize the relax table */
108 const relax_typeS md_relax_table
[] =
110 { 1, 1, 0, 0 }, /* 0: unused */
111 { 1, 1, 0, 0 }, /* 1: unused */
112 { 1, 1, 0, 0 }, /* 2: unused */
113 { 1, 1, 0, 0 }, /* 3: unused */
114 { 1, 1, 0, 0 }, /* 4: unused */
115 { 2048, -2046, C12_LEN
, C(COND_JUMP
, COND32
) }, /* 5: C(COND_JUMP, COND12) */
116 { 0, 0, C32_LEN
, 0 }, /* 6: C(COND_JUMP, COND32) */
117 { 1, 1, 0, 0 }, /* 7: unused */
118 { 1, 1, 0, 0 }, /* 8: unused */
119 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, UNCD32
) }, /* 9: C(UNCD_JUMP, UNCD12) */
120 { 0, 0, U32_LEN
, 0 }, /*10: C(UNCD_JUMP, UNCD32) */
121 { 1, 1, 0, 0 }, /*11: unused */
122 { 0, 0, 0, 0 } /*12: unused */
125 /* LITERAL POOL DATA STRUCTURES */
128 unsigned short refcnt
;
129 unsigned char ispcrel
;
130 unsigned char unused
;
134 #define MAX_POOL_SIZE (1024/4)
135 static struct literal litpool
[MAX_POOL_SIZE
];
136 static unsigned poolsize
;
137 static unsigned poolnumber
;
138 static unsigned long poolspan
;
140 /* SPANPANIC: the point at which we get too scared and force a dump
141 of the literal pool, and perhaps put a branch in place.
143 1024 span of lrw/jmpi/jsri insn (actually span+1)
144 -2 possible alignment at the insn.
145 -2 possible alignment to get the table aligned.
146 -2 an inserted branch around the table.
148 at 1018, we might be in trouble.
149 -- so we have to be smaller than 1018 and since we deal with 2-byte
150 instructions, the next good choice is 1016.
151 -- Note we have a test case that fails when we've got 1018 here. */
152 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding */
153 #define SPANCLOSE (900)
154 #define SPANEXIT (600)
155 static symbolS
* poolsym
; /* label for current pool */
156 static char poolname
[8];
157 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics */
159 /* This table describes all the machine specific pseudo-ops the assembler
160 has to support. The fields are:
161 Pseudo-op name without dot
162 Function to call to execute this pseudo-op
163 Integer arg to pass to the function */
164 const pseudo_typeS md_pseudo_table
[] =
166 { "export", s_globl
, 0 },
167 { "import", s_ignore
, 0 },
168 { "literals", mcore_s_literals
, 0 },
169 { "page", listing_eject
, 0 },
171 /* The following are to intercept the placement of data into the text
172 section (eg addresses for a switch table), so that the space they
173 occupy can be taken into account when deciding whether or not to
174 dump the current literal pool.
175 XXX - currently we do not cope with the .space and .dcb.d directives. */
176 { "ascii", mcore_stringer
, 0 },
177 { "asciz", mcore_stringer
, 1 },
178 { "byte", mcore_cons
, 1 },
179 { "dc", mcore_cons
, 2 },
180 { "dc.b", mcore_cons
, 1 },
181 { "dc.d", mcore_float_cons
, 'd'},
182 { "dc.l", mcore_cons
, 4 },
183 { "dc.s", mcore_float_cons
, 'f'},
184 { "dc.w", mcore_cons
, 2 },
185 { "dc.x", mcore_float_cons
, 'x'},
186 { "double", mcore_float_cons
, 'd'},
187 { "float", mcore_float_cons
, 'f'},
188 { "hword", mcore_cons
, 2 },
189 { "int", mcore_cons
, 4 },
190 { "long", mcore_cons
, 4 },
191 { "octa", mcore_cons
, 16 },
192 { "quad", mcore_cons
, 8 },
193 { "short", mcore_cons
, 2 },
194 { "single", mcore_float_cons
, 'f'},
195 { "string", mcore_stringer
, 1 },
196 { "word", mcore_cons
, 2 },
197 { "fill", mcore_fill
, 0 },
199 /* Allow for the effect of section changes. */
200 { "text", mcore_s_text
, 0 },
201 { "data", mcore_s_data
, 0 },
202 { "bss", mcore_s_bss
, 1 },
204 { "comm", mcore_s_comm
, 0 },
206 { "section", mcore_s_section
, 0 },
207 { "section.s", mcore_s_section
, 0 },
208 { "sect", mcore_s_section
, 0 },
209 { "sect.s", mcore_s_section
, 0 },
215 mcore_s_literals (ignore
)
219 demand_empty_rest_of_line ();
227 if (now_seg
== text_section
)
229 char * ptr
= input_line_pointer
;
232 /* Count the number of commas on the line. */
233 while (! is_end_of_line
[* ptr
])
234 commas
+= * ptr
++ == ',';
236 poolspan
+= nbytes
* commas
;
241 /* In theory we ought to call check_literals (2,0) here in case
242 we need to dump the literal table. We cannot do this however,
243 as the directives that we are intercepting may be being used
244 to build a switch table, and we must not interfere with its
245 contents. Instead we cross our fingers and pray... */
249 mcore_float_cons (float_type
)
252 if (now_seg
== text_section
)
254 char * ptr
= input_line_pointer
;
257 #ifdef REPEAT_CONS_EXPRESSIONS
258 #error REPEAT_CONS_EXPRESSIONS not handled
261 /* Count the number of commas on the line. */
262 while (! is_end_of_line
[* ptr
])
263 commas
+= * ptr
++ == ',';
265 /* We would like to compute "hex_float (float_type) * commas"
266 but hex_float is not exported from read.c */
267 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
268 poolspan
+= float_type
* commas
;
271 float_cons (float_type
);
273 /* See the comment in mcore_cons () about calling check_literals.
274 It is unlikely that a switch table will be constructed using
275 floating point values, but it is still likely that an indexed
276 table of floating point constants is being created by these
277 directives, so again we must not interfere with their placement. */
281 mcore_stringer (append_zero
)
284 if (now_seg
== text_section
)
286 char * ptr
= input_line_pointer
;
288 /* In theory we should compute how many bytes are going to
289 be occupied by the string(s) and add this to the poolspan.
290 To keep things simple however, we just add the number of
291 bytes left on the current line. This will be an over-
292 estimate, which is OK, and automatically allows for the
293 appending a zero byte, since the real string(s) is/are
294 required to be enclosed in double quotes. */
295 while (! is_end_of_line
[* ptr
])
298 poolspan
+= ptr
- input_line_pointer
;
301 stringer (append_zero
);
303 /* We call check_literals here in case a large number of strings are
304 being placed into the text section with a sequence of stringer
305 directives. In theory we could be upsetting something if these
306 strings are actually in an indexed table instead of referenced by
307 individual labels. Let us hope that that never happens. */
308 check_literals (2, 0);
315 if (now_seg
== text_section
)
317 char * str
= input_line_pointer
;
323 /* Look to see if a size has been specified. */
324 while (*str
!= '\n' && *str
!= 0 && *str
!= ',')
329 size
= atoi (str
+ 1);
337 poolspan
+= size
* repeat
;
342 check_literals (2, 0);
345 /* Handle the section changing pseudo-ops. These call through to the
346 normal implementations, but they dump the literal pool first. */
348 mcore_s_text (ignore
)
354 obj_elf_text (ignore
);
361 mcore_s_data (ignore
)
367 obj_elf_data (ignore
);
374 mcore_s_section (ignore
)
377 /* Scan forwards to find the name of the section. If the section
378 being switched to is ".line" then this is a DWARF1 debug section
379 which is arbitarily placed inside generated code. In this case
380 do not dump the literal pool because it is a) inefficient and
381 b) would require the generation of extra code to jump around the
383 char * ilp
= input_line_pointer
;
385 while (*ilp
!= 0 && isspace(*ilp
))
388 if (strncmp (ilp
, ".line", 5) == 0
389 && (isspace (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
395 obj_elf_section (ignore
);
398 obj_coff_section (ignore
);
403 mcore_s_bss (needs_align
)
408 s_lcomm_bytes (needs_align
);
413 mcore_s_comm (needs_align
)
418 obj_elf_common (needs_align
);
422 /* This function is called once, at assembler startup time. This should
423 set up all the tables, etc that the MD part of the assembler needs. */
427 mcore_opcode_info
* opcode
;
428 char * prev_name
= "";
430 opcode_hash_control
= hash_new ();
432 /* Insert unique names into hash table */
433 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
435 if (streq (prev_name
, opcode
->name
))
437 /* Make all the opcodes with the same name point to the same
439 opcode
->name
= prev_name
;
443 prev_name
= opcode
->name
;
444 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
451 static expressionS immediate
; /* absolute expression */
453 /* Get a log2(val). */
468 /* Try to parse a reg name. */
474 /* Strip leading whitespace. */
475 while (isspace (* s
))
478 if (tolower (s
[0]) == 'r')
480 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
482 *reg
= 10 + s
[2] - '0';
486 if (s
[1] >= '0' && s
[1] <= '9')
492 else if ( tolower (s
[0]) == 's'
493 && tolower (s
[1]) == 'p'
500 as_bad (_("register expected, but saw '%.6s'"), s
);
534 /* Strip leading whitespace. */
535 while (isspace (* s
))
538 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
540 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
542 *reg
= 30 + s
[3] - '0';
546 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
548 *reg
= 20 + s
[3] - '0';
552 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
554 *reg
= 10 + s
[3] - '0';
558 if (s
[2] >= '0' && s
[2] <= '9')
565 /* Look at alternate creg names before giving error. */
566 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
572 length
= strlen (cregs
[i
].name
);
574 for (j
= 0; j
< length
; j
++)
575 buf
[j
] = tolower (s
[j
]);
577 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
579 *reg
= cregs
[i
].crnum
;
584 as_bad (_("control register expected, but saw '%.6s'"), s
);
597 /* Skip whitespace. */
598 while (isspace (* s
))
601 save
= input_line_pointer
;
602 input_line_pointer
= s
;
606 if (e
->X_op
== O_absent
)
607 as_bad (_("missing operand"));
609 new = input_line_pointer
;
610 input_line_pointer
= save
;
621 static const char hex
[] = "0123456789ABCDEF";
626 s
[3] = hex
[(n
>> 12) & 0xF];
627 s
[4] = hex
[(n
>> 8) & 0xF];
628 s
[5] = hex
[(n
>> 4) & 0xF];
629 s
[6] = hex
[(n
) & 0xF];
633 #define POOL_END_LABEL ".LE"
634 #define POOL_START_LABEL ".LS"
637 dump_literals (isforce
)
647 /* Must we branch around the literal table? */
653 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
655 brarsym
= symbol_make (brarname
);
657 symbol_table_insert (brarsym
);
659 output
= frag_var (rs_machine_dependent
,
660 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
661 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
662 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
663 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
664 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
667 /* Make sure that the section is sufficiently aligned and that
668 the literal table is aligned within it. */
669 record_alignment (now_seg
, 2);
670 frag_align (2, 0, 0);
672 colon (S_GET_NAME (poolsym
));
674 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
675 emit_expr (& p
->e
, 4);
678 colon (S_GET_NAME (brarsym
));
684 check_literals (kind
, offset
)
690 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
691 SPANPANIC means that we must dump now.
692 kind == 0 is any old instruction.
693 kind > 0 means we just had a control transfer instruction.
694 kind == 1 means within a function
695 kind == 2 means we just left a function
697 The dump_literals (1) call inserts a branch around the table, so
698 we first look to see if its a situation where we won't have to
699 insert a branch (e.g., the previous instruction was an unconditional
702 SPANPANIC is the point where we must dump a single-entry pool.
703 it accounts for alignments and an inserted branch.
704 the 'poolsize*2' accounts for the scenario where we do:
705 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
706 Note that the 'lit2' reference is 2 bytes further along
707 but the literal it references will be 4 bytes further along,
708 so we must consider the poolsize into this equation.
709 This is slightly over-cautious, but guarantees that we won't
710 panic because a relocation is too distant. */
712 if (poolspan
> SPANCLOSE
&& kind
> 0)
714 else if (poolspan
> SPANEXIT
&& kind
> 1)
716 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
721 enter_literal (e
, ispcrel
)
728 if (poolsize
>= MAX_POOL_SIZE
- 2)
730 /* The literal pool is as full as we can handle. We have
731 to be 2 entries shy of the 1024/4=256 entries because we
732 have to allow for the branch (2 bytes) and the alignment
733 (2 bytes before the first insn referencing the pool and
734 2 bytes before the pool itself) == 6 bytes, rounds up
741 /* Create new literal pool. */
742 if (++ poolnumber
> 0xFFFF)
743 as_fatal (_("more than 65K literal pools"));
745 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
746 poolsym
= symbol_make (poolname
);
747 symbol_table_insert (poolsym
);
751 /* Search pool for value so we don't have duplicates. */
752 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
754 if (e
->X_op
== p
->e
.X_op
755 && e
->X_add_symbol
== p
->e
.X_add_symbol
756 && e
->X_add_number
== p
->e
.X_add_number
757 && ispcrel
== p
->ispcrel
)
765 p
->ispcrel
= ispcrel
;
773 /* Parse a literal specification. -- either new or old syntax.
774 old syntax: the user supplies the label and places the literal.
775 new syntax: we put it into the literal pool. */
777 parse_rt (s
, outputp
, ispcrel
, ep
)
787 /* Indicate nothing there. */
792 s
= parse_exp (s
+ 1, & e
);
797 as_bad (_("missing ']'"));
801 s
= parse_exp (s
, & e
);
803 n
= enter_literal (& e
, ispcrel
);
808 /* Create a reference to pool entry. */
810 e
.X_add_symbol
= poolsym
;
811 e
.X_add_number
= n
<< 2;
814 * outputp
= frag_more (2);
816 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
817 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
823 parse_imm (s
, val
, min
, max
)
832 new = parse_exp (s
, & e
);
834 if (e
.X_op
== O_absent
)
835 ; /* An error message has already been emitted. */
836 else if (e
.X_op
!= O_constant
)
837 as_bad (_("operand must be a constant"));
838 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
839 as_bad (_("operand must be absolute in range %d..%d, not %d"),
840 min
, max
, e
.X_add_number
);
842 * val
= e
.X_add_number
;
848 parse_mem (s
, reg
, off
, siz
)
858 while (isspace (* s
))
863 s
= parse_reg (s
+ 1, reg
);
865 while (isspace (* s
))
870 s
= parse_imm (s
+ 1, off
, 0, 63);
877 as_bad (_("operand must be a multiple of 4"));
884 as_bad (_("operand must be a multiple of 2"));
891 while (isspace (* s
))
898 as_bad (_("base register expected"));
903 /* This is the guts of the machine-dependent assembler. STR points to a
904 machine dependent instruction. This function is supposed to emit
905 the frags/bytes it assembles to. */
913 mcore_opcode_info
* opcode
;
923 /* Drop leading whitespace. */
924 while (isspace (* str
))
927 /* Find the op code end. */
928 for (op_start
= op_end
= str
;
929 * op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
932 name
[nlen
] = op_start
[nlen
];
940 as_bad (_("can't find opcode "));
944 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
947 as_bad (_("unknown opcode \"%s\""), name
);
954 switch (opcode
->opclass
)
957 output
= frag_more (2);
961 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
963 output
= frag_more (2);
967 op_end
= parse_reg (op_end
+ 1, & reg
);
969 output
= frag_more (2);
973 op_end
= parse_reg (op_end
+ 1, & reg
);
975 output
= frag_more (2);
976 /* In a sifilter mode, we emit this insn 2 times,
977 fixes problem of an interrupt during a jmp.. */
980 output
[0] = INST_BYTE0 (inst
);
981 output
[1] = INST_BYTE1 (inst
);
982 output
= frag_more (2);
987 op_end
= parse_reg (op_end
+ 1, & reg
);
990 as_bad (_("invalid register: r15 illegal"));
993 output
= frag_more (2);
997 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
998 inst
= MCORE_INST_BSR
; /* with 0 displacement */
999 output
[0] = INST_BYTE0 (inst
);
1000 output
[1] = INST_BYTE1 (inst
);
1002 output
= frag_more (2);
1003 inst
= MCORE_INST_ADDI
;
1004 inst
|= 15; /* addi r15,6 */
1005 inst
|= (6 - 1) << 4; /* over the jmp's */
1006 output
[0] = INST_BYTE0 (inst
);
1007 output
[1] = INST_BYTE1 (inst
);
1009 output
= frag_more (2);
1010 inst
= MCORE_INST_JMP
| reg
;
1011 output
[0] = INST_BYTE0 (inst
);
1012 output
[1] = INST_BYTE1 (inst
);
1014 output
= frag_more (2); /* 2nd emitted in fallthru */
1019 op_end
= parse_reg (op_end
+ 1, & reg
);
1022 /* Skip whitespace. */
1023 while (isspace (* op_end
))
1028 op_end
= parse_creg (op_end
+ 1, & reg
);
1032 output
= frag_more (2);
1036 op_end
= parse_reg (op_end
+ 1, & reg
);
1039 /* Skip whitespace. */
1040 while (isspace (* op_end
))
1043 if (* op_end
== ',')
1045 op_end
= parse_reg (op_end
+ 1, & reg
);
1049 as_bad (_("second operand missing"));
1051 output
= frag_more (2);
1054 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1055 op_end
= parse_reg (op_end
+ 1, & reg
);
1057 /* Skip whitespace. */
1058 while (isspace (* op_end
))
1061 if (* op_end
== ',') /* xtrb- r1,rx */
1064 as_bad (_("destination register must be r1"));
1066 op_end
= parse_reg (op_end
+ 1, & reg
);
1070 output
= frag_more (2);
1073 case O1R1
: /* div- rx,r1 */
1074 op_end
= parse_reg (op_end
+ 1, & reg
);
1077 /* Skip whitespace. */
1078 while (isspace (* op_end
))
1081 if (* op_end
== ',')
1083 op_end
= parse_reg (op_end
+ 1, & reg
);
1085 as_bad (_("source register must be r1"));
1088 as_bad (_("second operand missing"));
1090 output
= frag_more (2);
1094 op_end
= parse_reg (op_end
+ 1, & reg
);
1097 /* Skip whitespace. */
1098 while (isspace (* op_end
))
1101 if (* op_end
== ',')
1103 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1104 inst
|= (reg
- 1) << 4;
1107 as_bad (_("second operand missing"));
1109 output
= frag_more (2);
1113 op_end
= parse_reg (op_end
+ 1, & reg
);
1116 /* Skip whitespace. */
1117 while (isspace (* op_end
))
1120 if (* op_end
== ',')
1122 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1126 as_bad (_("second operand missing"));
1128 output
= frag_more (2);
1131 case OB2
: /* like OB, but arg is 2^n instead of n */
1132 op_end
= parse_reg (op_end
+ 1, & reg
);
1135 /* Skip whitespace. */
1136 while (isspace (* op_end
))
1139 if (* op_end
== ',')
1141 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1142 /* Further restrict the immediate to a power of two. */
1143 if ((reg
& (reg
- 1)) == 0)
1148 as_bad (_("immediate is not a power of two"));
1153 as_bad (_("second operand missing"));
1155 output
= frag_more (2);
1158 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1161 op_end
= parse_reg (op_end
+ 1, & reg
);
1164 /* Skip whitespace. */
1165 while (isspace (* op_end
))
1168 if (* op_end
== ',')
1170 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1171 /* immediate values of 0 -> 6 translate to movi */
1174 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1176 as_warn (_("translating bgeni to movi"));
1182 as_bad (_("second operand missing"));
1184 output
= frag_more (2);
1187 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1188 op_end
= parse_reg (op_end
+ 1, & reg
);
1191 /* Skip whitespace. */
1192 while (isspace (* op_end
))
1195 if (* op_end
== ',')
1197 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1199 /* Further restrict the immediate to a power of two. */
1200 if ((reg
& (reg
- 1)) == 0)
1205 as_bad (_("immediate is not a power of two"));
1208 /* Immediate values of 0 -> 6 translate to movi. */
1211 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1213 as_warn (_("translating mgeni to movi"));
1219 as_bad (_("second operand missing"));
1221 output
= frag_more (2);
1224 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1227 op_end
= parse_reg (op_end
+ 1, & reg
);
1230 /* Skip whitespace. */
1231 while (isspace (* op_end
))
1234 if (* op_end
== ',')
1236 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1238 /* Immediate values of 1 -> 7 translate to movi. */
1241 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1242 reg
= (0x1 << reg
) - 1;
1245 as_warn (_("translating bmaski to movi"));
1250 inst
|= (reg
& 0x1F) << 4;
1254 as_bad (_("second operand missing"));
1256 output
= frag_more (2);
1260 op_end
= parse_reg (op_end
+ 1, & reg
);
1263 /* Skip whitespace. */
1264 while (isspace (* op_end
))
1267 if (* op_end
== ',')
1269 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1273 as_bad (_("second operand missing"));
1275 output
= frag_more (2);
1279 op_end
= parse_reg (op_end
+ 1, & reg
);
1282 /* Skip whitespace. */
1283 while (isspace (* op_end
))
1286 if (* op_end
== ',')
1288 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1292 as_bad (_("second operand missing"));
1294 output
= frag_more (2);
1298 op_end
= parse_reg (op_end
+ 1, & reg
);
1301 /* Skip whitespace. */
1302 while (isspace (* op_end
))
1305 if (* op_end
== ',')
1309 if ((inst
& 0x6000) == 0)
1311 else if ((inst
& 0x6000) == 0x4000)
1313 else if ((inst
& 0x6000) == 0x2000)
1316 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1319 as_bad (_("displacement too large (%d)"), off
);
1321 inst
|= (reg
) | (off
<< 4);
1324 as_bad (_("second operand missing"));
1326 output
= frag_more (2);
1330 op_end
= parse_reg (op_end
+ 1, & reg
);
1332 if (reg
== 0 || reg
== 15)
1333 as_bad (_("Invalid register: r0 and r15 illegal"));
1337 /* Skip whitespace. */
1338 while (isspace (* op_end
))
1341 if (* op_end
== ',')
1342 /* parse_rt calls frag_more() for us. */
1343 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1346 as_bad (_("second operand missing"));
1347 output
= frag_more (2); /* save its space */
1352 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1353 /* parse_rt() calls frag_more() for us. */
1357 op_end
= parse_reg (op_end
+ 1, & reg
);
1359 if (reg
== 0 || reg
== 15)
1360 as_bad (_("bad starting register: r0 and r15 invalid"));
1364 /* Skip whitespace. */
1365 while (isspace (* op_end
))
1368 if (* op_end
== '-')
1370 op_end
= parse_reg (op_end
+ 1, & reg
);
1373 as_bad (_("ending register must be r15"));
1375 /* Skip whitespace. */
1376 while (isspace (* op_end
))
1380 if (* op_end
== ',')
1384 /* Skip whitespace. */
1385 while (isspace (* op_end
))
1388 if (* op_end
== '(')
1390 op_end
= parse_reg (op_end
+ 1, & reg
);
1393 as_bad (_("bad base register: must be r0"));
1395 if (* op_end
== ')')
1399 as_bad (_("base register expected"));
1402 as_bad (_("second operand missing"));
1404 output
= frag_more (2);
1408 op_end
= parse_reg (op_end
+ 1, & reg
);
1411 as_fatal (_("first register must be r4"));
1413 /* Skip whitespace. */
1414 while (isspace (* op_end
))
1417 if (* op_end
== '-')
1419 op_end
= parse_reg (op_end
+ 1, & reg
);
1422 as_fatal (_("last register must be r7"));
1424 /* Skip whitespace. */
1425 while (isspace (* op_end
))
1428 if (* op_end
== ',')
1432 /* Skip whitespace. */
1433 while (isspace (* op_end
))
1436 if (* op_end
== '(')
1438 op_end
= parse_reg (op_end
+ 1, & reg
);
1440 if (reg
>= 4 && reg
<= 7)
1441 as_fatal ("base register cannot be r4, r5, r6, or r7");
1445 /* Skip whitespace. */
1446 while (isspace (* op_end
))
1449 if (* op_end
== ')')
1453 as_bad (_("base register expected"));
1456 as_bad (_("second operand missing"));
1459 as_bad (_("reg-reg expected"));
1461 output
= frag_more (2);
1465 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1467 output
= frag_more (2);
1469 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1470 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1474 op_end
= parse_reg (op_end
+ 1, & reg
);
1477 /* Skip whitespace. */
1478 while (isspace (* op_end
))
1481 if (* op_end
== ',')
1483 op_end
= parse_exp (op_end
+ 1, & e
);
1484 output
= frag_more (2);
1486 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1487 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1491 as_bad (_("second operand missing"));
1492 output
= frag_more (2);
1497 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1499 output
= frag_var (rs_machine_dependent
,
1500 md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
,
1501 md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
,
1502 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1507 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1508 output
= frag_var (rs_machine_dependent
,
1509 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
1510 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
1511 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1516 inst
= MCORE_INST_JSRI
; /* jsri */
1517 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1518 /* parse_rt() calls frag_more for us. */
1520 /* Only do this if we know how to do it ... */
1521 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1523 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1524 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1525 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1529 case RSI
: /* SI, but imm becomes 32-imm */
1530 op_end
= parse_reg (op_end
+ 1, & reg
);
1533 /* Skip whitespace. */
1534 while (isspace (* op_end
))
1537 if (* op_end
== ',')
1539 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1545 as_bad (_("second operand missing"));
1547 output
= frag_more (2);
1550 case DO21
: /* O2, dup rd, lit must be 1 */
1551 op_end
= parse_reg (op_end
+ 1, & reg
);
1555 /* Skip whitespace. */
1556 while (isspace (* op_end
))
1559 if (* op_end
== ',')
1561 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1564 as_bad (_("second operand must be 1"));
1567 as_bad (_("second operand missing"));
1569 output
= frag_more (2);
1573 op_end
= parse_reg (op_end
+ 1, & reg
);
1576 /* Skip whitespace. */
1577 while (isspace (* op_end
))
1580 if (* op_end
== ',')
1582 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1585 as_bad (_("zero used as immediate value"));
1590 as_bad (_("second operand missing"));
1592 output
= frag_more (2);
1596 as_bad (_("unimplemented opcode \"%s\""), name
);
1599 output
[0] = INST_BYTE0 (inst
);
1600 output
[1] = INST_BYTE1 (inst
);
1602 check_literals (opcode
->transfer
, isize
);
1606 md_undefined_symbol (name
)
1616 subseg_set (text_section
, 0);
1619 /* Various routines to kill one day. */
1620 /* Equal to MAX_PRECISION in atof-ieee.c */
1621 #define MAX_LITTLENUMS 6
1623 /* Turn a string in input_line_pointer into a floating point constant of type
1624 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1625 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1627 md_atof (type
, litP
, sizeP
)
1633 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1636 char * atof_ieee ();
1666 return _("Bad call to MD_NTOF()");
1669 t
= atof_ieee (input_line_pointer
, type
, words
);
1672 input_line_pointer
= t
;
1674 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1676 for (i
= 0; i
< prec
; i
++)
1678 md_number_to_chars (litP
, (valueT
) words
[i
],
1679 sizeof (LITTLENUM_TYPE
));
1680 litP
+= sizeof (LITTLENUM_TYPE
);
1686 CONST
char * md_shortopts
= "";
1688 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1689 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1690 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1691 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1693 struct option md_longopts
[] =
1695 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1696 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1697 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1698 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1699 { NULL
, no_argument
, NULL
, 0}
1702 size_t md_longopts_size
= sizeof (md_longopts
);
1705 md_parse_option (c
, arg
)
1715 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1716 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1717 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1718 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1726 md_show_usage (stream
)
1729 fprintf (stream
, _("\
1730 MCORE specific options:\n\
1731 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1732 -{no-}sifilter {dis}able silicon filter behavior (def: dis)"));
1735 int md_short_jump_size
;
1738 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1743 symbolS
* to_symbol
;
1745 as_fatal (_("failed sanity check: short_jump"));
1749 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1754 symbolS
* to_symbol
;
1756 as_fatal (_("failed sanity check: long_jump"));
1759 /* Called after relaxing, change the frags so they know how big they are. */
1761 md_convert_frag (abfd
, sec
, fragP
)
1764 register fragS
* fragP
;
1766 unsigned char * buffer
;
1767 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1769 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1770 targ_addr
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
1772 switch (fragP
->fr_subtype
)
1774 case C (COND_JUMP
, COND12
):
1775 case C (UNCD_JUMP
, UNCD12
):
1777 /* Get the address of the end of the instruction. */
1778 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1780 int disp
= targ_addr
- next_inst
;
1783 as_bad (_("odd displacement at %x"), next_inst
- 2);
1787 t0
= buffer
[0] & 0xF8;
1789 md_number_to_chars (buffer
, disp
, 2);
1791 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1799 case C (COND_JUMP
, COND32
):
1800 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1802 /* A conditional branch wont fit into 12 bits so:
1809 * if the b!cond is 4 byte aligned, the literal which would
1810 * go at x+4 will also be aligned.
1812 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1813 int needpad
= (first_inst
& 3);
1815 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1817 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1818 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1823 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1824 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1827 buffer
[4] = 0; /* alignment/pad */
1829 buffer
[6] = 0; /* space for 32 bit address */
1834 /* Make reloc for the long disp */
1835 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1836 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1838 fragP
->fr_fix
+= C32_LEN
;
1842 /* See comment below about this given gas' limitations for
1843 shrinking the fragment. '3' is the amount of code that
1844 we inserted here, but '4' is right for the space we reserved
1845 for this fragment. */
1847 buffer
[1] = 3; /* branch over jmpi, and ptr */
1848 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1851 buffer
[4] = 0; /* space for 32 bit address */
1856 /* Make reloc for the long disp. */
1857 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1858 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1859 fragP
->fr_fix
+= C32_LEN
;
1861 /* Frag is actually shorter (see the other side of this ifdef)
1862 but gas isn't prepared for that. We have to re-adjust
1863 the branch displacement so that it goes beyond the
1864 full length of the fragment, not just what we actually
1866 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1873 case C (UNCD_JUMP
, UNCD32
):
1874 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1876 /* An unconditional branch will not fit in 12 bits, make code which
1881 we need a pad if "first_inst" is 4 byte aligned.
1882 [because the natural literal place is x + 2] */
1883 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1884 int needpad
= !(first_inst
& 3);
1886 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1887 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1891 buffer
[1] = 1; /* jmpi offset of 1 since padded */
1892 buffer
[2] = 0; /* alignment */
1894 buffer
[4] = 0; /* space for 32 bit address */
1899 /* Make reloc for the long disp. */
1900 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1901 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1903 fragP
->fr_fix
+= U32_LEN
;
1907 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
1908 buffer
[2] = 0; /* space for 32 bit address */
1913 /* Make reloc for the long disp. */
1914 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1915 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1916 fragP
->fr_fix
+= U32_LEN
;
1928 /* Applies the desired value to the specified location.
1929 Also sets up addends for 'rela' type relocations. */
1931 md_apply_fix3 (fixP
, valp
, segment
)
1936 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1937 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1938 const char * symname
;
1939 /* Note: use offsetT because it is signed, valueT is unsigned. */
1940 offsetT val
= (offsetT
) * valp
;
1942 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1943 /* Save this for the addend in the relocation record. */
1944 fixP
->fx_addnumber
= val
;
1946 /* If the fix is relative to a symbol which is not defined, or not
1947 in the same segment as the fix, we cannot resolve it here. */
1948 if (fixP
->fx_addsy
!= NULL
1949 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
1950 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
1954 /* For ELF we can just return and let the reloc that will be generated
1955 take care of everything. For COFF we still have to insert 'val'
1956 into the insn since the addend field will be ignored. */
1963 switch (fixP
->fx_r_type
)
1965 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
1967 as_bad_where (file
, fixP
->fx_line
,
1968 _("odd distance branch (0x%x bytes)"), val
);
1970 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
1971 as_bad_where (file
, fixP
->fx_line
,
1972 _("pcrel for branch to %s too far (0x%x)"),
1974 buf
[0] |= ((val
>> 8) & 0x7);
1975 buf
[1] |= (val
& 0xff);
1978 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
1982 as_bad_where (file
, fixP
->fx_line
,
1983 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
1986 buf
[1] |= (val
& 0xff);
1989 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
1990 if ((val
< -32) || (val
> -2))
1991 as_bad_where (file
, fixP
->fx_line
,
1992 _("pcrel for loopt too far (0x%x)"), val
);
1994 buf
[1] |= (val
& 0xf);
1997 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
1998 /* Conditional linker map jsri to bsr. */
1999 /* If its a local target and close enough, fix it.
2000 NB: >= -2k for backwards bsr; < 2k for forwards... */
2001 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2003 long nval
= (val
/ 2) & 0x7ff;
2004 nval
|= MCORE_INST_BSR
;
2006 /* REPLACE the instruction, don't just modify it. */
2007 buf
[0] = INST_BYTE0 (nval
);
2008 buf
[1] = INST_BYTE1 (nval
);
2014 case BFD_RELOC_MCORE_PCREL_32
:
2015 case BFD_RELOC_VTABLE_INHERIT
:
2016 case BFD_RELOC_VTABLE_ENTRY
:
2021 if (fixP
->fx_addsy
!= NULL
)
2023 /* If the fix is an absolute reloc based on a symbol's
2024 address, then it cannot be resolved until the final link. */
2031 if (fixP
->fx_size
== 4)
2033 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2035 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2039 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2044 return 0; /* Return value is ignored. */
2048 md_operand (expressionP
)
2049 expressionS
* expressionP
;
2051 /* Ignore leading hash symbol, if poresent. */
2052 if (* input_line_pointer
== '#')
2054 input_line_pointer
++;
2055 expression (expressionP
);
2059 int md_long_jump_size
;
2061 /* Called just before address relaxation, return the length
2062 by which a fragment must grow to reach it's destination. */
2064 md_estimate_size_before_relax (fragP
, segment_type
)
2065 register fragS
* fragP
;
2066 register segT segment_type
;
2068 switch (fragP
->fr_subtype
)
2070 case C (UNCD_JUMP
, UNDEF_DISP
):
2071 /* Used to be a branch to somewhere which was unknown. */
2072 if (!fragP
->fr_symbol
)
2074 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2075 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2077 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2079 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2080 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2084 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2085 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2086 return md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2093 case C (COND_JUMP
, UNDEF_DISP
):
2094 /* Used to be a branch to somewhere which was unknown. */
2095 if (fragP
->fr_symbol
2096 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2098 /* Got a symbol and it's defined in this segment, become byte
2099 sized - maybe it will fix up */
2100 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2101 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2103 else if (fragP
->fr_symbol
)
2105 /* Its got a segment, but its not ours, so it will always be long. */
2106 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2107 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2108 return md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2112 /* We know the abs value. */
2113 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2114 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2120 return fragP
->fr_var
;
2123 /* Put number into target byte order. */
2125 md_number_to_chars (ptr
, use
, nbytes
)
2132 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2133 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2134 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2135 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2140 /* Round up a section size to the appropriate boundary. */
2142 md_section_align (segment
, size
)
2146 return size
; /* Byte alignment is fine */
2150 /* The location from which a PC relative jump should be calculated,
2151 given a PC relative reloc. */
2153 md_pcrel_from_section (fixp
, sec
)
2158 /* If the symbol is undefined or defined in another section
2159 we leave the add number alone for the linker to fix it later.
2160 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2161 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2162 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2163 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2166 assert (fixp
->fx_size
== 2); /* must be an insn */
2167 return fixp
->fx_size
;
2171 /* The case where we are going to resolve things... */
2172 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2175 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2176 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2179 tc_gen_reloc (section
, fixp
)
2184 bfd_reloc_code_real_type code
;
2187 switch (fixp
->fx_r_type
)
2189 /* These confuse the size/pcrel macro approach. */
2190 case BFD_RELOC_VTABLE_INHERIT
:
2191 case BFD_RELOC_VTABLE_ENTRY
:
2192 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2193 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2194 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2195 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2196 code
= fixp
->fx_r_type
;
2200 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2202 MAP (1, 0, BFD_RELOC_8
);
2203 MAP (2, 0, BFD_RELOC_16
);
2204 MAP (4, 0, BFD_RELOC_32
);
2205 MAP (1, 1, BFD_RELOC_8_PCREL
);
2206 MAP (2, 1, BFD_RELOC_16_PCREL
);
2207 MAP (4, 1, BFD_RELOC_32_PCREL
);
2209 code
= fixp
->fx_r_type
;
2210 as_bad (_("Can not do %d byte %srelocation"),
2212 fixp
->fx_pcrel
? _("pc-relative") : "");
2217 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2218 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2219 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2220 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2221 /* Always pass the addend along! */
2222 rel
->addend
= fixp
->fx_addnumber
;
2224 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2226 if (rel
->howto
== NULL
)
2228 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2229 _("Cannot represent relocation type %s"),
2230 bfd_get_reloc_code_name (code
));
2232 /* Set howto to a garbage value so that we can keep going. */
2233 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2234 assert (rel
->howto
!= NULL
);
2241 /* See whether we need to force a relocation into the output file.
2242 This is used to force out switch and PC relative relocations when
2245 mcore_force_relocation (fix
)
2248 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2249 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2255 /* Return true if the fix can be handled by GAS, false if it must
2256 be passed through to the linker. */
2258 mcore_fix_adjustable (fixP
)
2261 if (fixP
->fx_addsy
== NULL
)
2264 /* We need the symbol name for the VTABLE entries. */
2265 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2266 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2271 #endif /* OBJ_ELF */