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));
56 static void mcore_s_section
PARAMS ((int));
59 /* Several places in this file insert raw instructions into the
60 object. They should use MCORE_INST_XXX macros to get the opcodes
61 and then use these two macros to crack the MCORE_INST value into
62 the appropriate byte values. */
63 #define INST_BYTE0(x) (((x) >> 8) & 0xFF)
64 #define INST_BYTE1(x) ((x) & 0xFF)
66 const char comment_chars
[] = "#/";
67 const char line_separator_chars
[] = ";";
68 const char line_comment_chars
[] = "#/";
70 const int md_reloc_size
= 8;
72 static int do_jsri2bsr
= 0; /* change here from 1 by Cruess 19 August 97 */
73 static int sifilter_mode
= 0;
75 const char EXP_CHARS
[] = "eE";
77 /* Chars that mean this number is a floating point constant */
80 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
82 #define C(what,length) (((what) << 2) + (length))
83 #define GET_WHAT(x) ((x >> 2))
85 /* These are the two types of relaxable instruction */
94 #define UNDEF_WORD_DISP 4
98 #define C32_LEN 10 /* allow for align */
100 #define U32_LEN 8 /* allow for align */
103 /* Initialize the relax table */
104 const relax_typeS md_relax_table
[] =
106 { 1, 1, 0, 0 }, /* 0: unused */
107 { 1, 1, 0, 0 }, /* 1: unused */
108 { 1, 1, 0, 0 }, /* 2: unused */
109 { 1, 1, 0, 0 }, /* 3: unused */
110 { 1, 1, 0, 0 }, /* 4: unused */
111 { 2048, -2046, C12_LEN
, C(COND_JUMP
, COND32
) }, /* 5: C(COND_JUMP, COND12) */
112 { 0, 0, C32_LEN
, 0 }, /* 6: C(COND_JUMP, COND32) */
113 { 1, 1, 0, 0 }, /* 7: unused */
114 { 1, 1, 0, 0 }, /* 8: unused */
115 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, UNCD32
) }, /* 9: C(UNCD_JUMP, UNCD12) */
116 { 0, 0, U32_LEN
, 0 }, /*10: C(UNCD_JUMP, UNCD32) */
117 { 1, 1, 0, 0 }, /*11: unused */
118 { 0, 0, 0, 0 } /*12: unused */
121 /* LITERAL POOL DATA STRUCTURES */
124 unsigned short refcnt
;
125 unsigned char ispcrel
;
126 unsigned char unused
;
130 #define MAX_POOL_SIZE (1024/4)
131 static struct literal litpool
[MAX_POOL_SIZE
];
132 static unsigned poolsize
;
133 static unsigned poolnumber
;
134 static unsigned long poolspan
;
136 /* SPANPANIC: the point at which we get too scared and force a dump
137 of the literal pool, and perhaps put a branch in place.
139 1024 span of lrw/jmpi/jsri insn (actually span+1)
140 -2 possible alignment at the insn.
141 -2 possible alignment to get the table aligned.
142 -2 an inserted branch around the table.
144 at 1018, we might be in trouble.
145 -- so we have to be smaller than 1018 and since we deal with 2-byte
146 instructions, the next good choice is 1016.
147 -- Note we have a test case that fails when we've got 1018 here. */
148 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding */
149 #define SPANCLOSE (900)
150 #define SPANEXIT (600)
151 static symbolS
* poolsym
; /* label for current pool */
152 static char poolname
[8];
153 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics */
155 /* This table describes all the machine specific pseudo-ops the assembler
156 has to support. The fields are:
157 Pseudo-op name without dot
158 Function to call to execute this pseudo-op
159 Integer arg to pass to the function */
160 const pseudo_typeS md_pseudo_table
[] =
162 { "export", s_globl
, 0 },
163 { "import", s_ignore
, 0 },
164 { "literals", mcore_s_literals
, 0 },
165 { "page", listing_eject
, 0 },
166 { "bss", s_lcomm_bytes
, 1 },
168 /* The following are to intercept the placement of data into the text
169 section (eg addresses for a switch table), so that the space they
170 occupy can be taken into account when deciding whether or not to
171 dump the current literal pool.
172 XXX - currently we do not cope with the .space and .dcb.d directives. */
173 { "ascii", mcore_stringer
, 0 },
174 { "asciz", mcore_stringer
, 1 },
175 { "byte", mcore_cons
, 1 },
176 { "dc", mcore_cons
, 2 },
177 { "dc.b", mcore_cons
, 1 },
178 { "dc.d", mcore_float_cons
, 'd' },
179 { "dc.l", mcore_cons
, 4 },
180 { "dc.s", mcore_float_cons
, 'f' },
181 { "dc.w", mcore_cons
, 2 },
182 { "dc.x", mcore_float_cons
, 'x' },
183 { "double", mcore_float_cons
, 'd'},
184 { "float", mcore_float_cons
, 'f'},
185 { "hword", mcore_cons
, 2 },
186 { "int", mcore_cons
, 4 },
187 { "long", mcore_cons
, 4 },
188 { "octa", mcore_cons
, 16 },
189 { "quad", mcore_cons
, 8 },
190 { "short", mcore_cons
, 2 },
191 { "single", mcore_float_cons
, 'f'},
192 { "string", mcore_stringer
, 1 },
193 { "word", mcore_cons
, 2 },
195 /* Allow for the effect of section changes. */
196 { "text", mcore_s_text
, 0 },
197 { "data", mcore_s_data
, 0 },
200 { "section", mcore_s_section
, 0 },
201 { "section.s", mcore_s_section
, 0 },
202 { "sect", mcore_s_section
, 0 },
203 { "sect.s", mcore_s_section
, 0 },
209 mcore_s_literals (ignore
)
213 demand_empty_rest_of_line ();
221 if (now_seg
== text_section
)
223 char * ptr
= input_line_pointer
;
226 /* Count the number of commas on the line. */
227 while (! is_end_of_line
[* ptr
])
228 commas
+= * ptr
++ == ',';
230 poolspan
+= nbytes
* commas
;
235 /* In theory we ought to call check_literals (2,0) here in case
236 we need to dump the literal table. We cannot do this however,
237 as the directives that we are intercepting may be being used
238 to build a switch table, and we must not interfere with its
239 contents. Instead we cross our fingers and pray... */
243 mcore_float_cons (float_type
)
246 if (now_seg
== text_section
)
248 char * ptr
= input_line_pointer
;
251 #ifdef REPEAT_CONS_EXPRESSIONS
252 #error REPEAT_CONS_EXPRESSIONS not handled
255 /* Count the number of commas on the line. */
256 while (! is_end_of_line
[* ptr
])
257 commas
+= * ptr
++ == ',';
259 /* We would like to compute "hex_float (float_type) * commas"
260 but hex_float is not exported from read.c */
261 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
262 poolspan
+= float_type
* commas
;
265 float_cons (float_type
);
267 /* See the comment in mcore_cons () about calling check_literals.
268 It is unlikely that a switch table will be constructed using
269 floating point values, but it is still likely that an indexed
270 table of floating point constants is being created by these
271 directives, so again we must not interfere with their placement. */
275 mcore_stringer (append_zero
)
278 if (now_seg
== text_section
)
280 char * ptr
= input_line_pointer
;
282 /* In theory we should compute how many bytes are going to
283 be occupied by the string(s) and add this to the poolspan.
284 To keep things simple however, we just add the number of
285 bytes left on the current line. This will be an over-
286 estimate, which is OK, and automatically allows for the
287 appending a zero byte, since the real string(s) is/are
288 required to be enclosed in double quotes. */
289 while (! is_end_of_line
[* ptr
])
292 poolspan
+= ptr
- input_line_pointer
;
295 stringer (append_zero
);
297 /* We call check_literals here in case a large number of strings are
298 being placed into the text section with a sequence of stringer
299 directives. In theory we could be upsetting something if these
300 strings are actually in an indexed table instead of referenced by
301 individual labels. Let us hope that that never happens. */
302 check_literals (2, 0);
306 mcore_s_text (ignore
)
315 mcore_s_data (ignore
)
323 /* This function is called once, at assembler startup time. This should
324 set up all the tables, etc that the MD part of the assembler needs. */
328 mcore_opcode_info
* opcode
;
329 char * prev_name
= "";
331 opcode_hash_control
= hash_new ();
333 /* Insert unique names into hash table */
334 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
336 if (streq (prev_name
, opcode
->name
))
338 /* Make all the opcodes with the same name point to the same
340 opcode
->name
= prev_name
;
344 prev_name
= opcode
->name
;
345 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
352 static expressionS immediate
; /* absolute expression */
354 /* Get a log2(val). */
369 /* Try to parse a reg name. */
375 /* Strip leading whitespace. */
376 while (isspace (* s
))
379 if (tolower (s
[0]) == 'r')
381 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
383 *reg
= 10 + s
[2] - '0';
387 if (s
[1] >= '0' && s
[1] <= '9')
393 else if ( tolower (s
[0]) == 's'
394 && tolower (s
[1]) == 'p'
401 as_bad (_("register expected, but saw '%.6s'"), s
);
435 /* Strip leading whitespace. */
436 while (isspace (* s
))
439 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
441 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
443 *reg
= 30 + s
[3] - '0';
447 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
449 *reg
= 20 + s
[3] - '0';
453 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
455 *reg
= 10 + s
[3] - '0';
459 if (s
[2] >= '0' && s
[2] <= '9')
466 /* Look at alternate creg names before giving error. */
467 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
473 length
= strlen (cregs
[i
].name
);
475 for (j
= 0; j
< length
; j
++)
476 buf
[j
] = tolower (s
[j
]);
478 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
480 *reg
= cregs
[i
].crnum
;
485 as_bad (_("control register expected, but saw '%.6s'"), s
);
498 /* Skip whitespace. */
499 while (isspace (* s
))
502 save
= input_line_pointer
;
503 input_line_pointer
= s
;
507 if (e
->X_op
== O_absent
)
508 as_bad (_("missing operand"));
510 new = input_line_pointer
;
511 input_line_pointer
= save
;
522 static const char hex
[] = "0123456789ABCDEF";
527 s
[3] = hex
[(n
>> 12) & 0xF];
528 s
[4] = hex
[(n
>> 8) & 0xF];
529 s
[5] = hex
[(n
>> 4) & 0xF];
530 s
[6] = hex
[(n
) & 0xF];
534 #define POOL_END_LABEL ".LE"
535 #define POOL_START_LABEL ".LS"
538 dump_literals (isforce
)
548 /* Must we branch around the literal table? */
554 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
556 brarsym
= symbol_make (brarname
);
558 symbol_table_insert (brarsym
);
560 output
= frag_var (rs_machine_dependent
,
561 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
562 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
563 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
564 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
565 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
568 /* Make sure that the section is sufficiently aligned and that
569 the literal table is aligned within it. */
570 record_alignment (now_seg
, 2);
571 frag_align (2, 0, 0);
573 colon (S_GET_NAME (poolsym
));
575 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
576 emit_expr (& p
->e
, 4);
579 colon (S_GET_NAME (brarsym
));
585 check_literals (kind
, offset
)
591 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
592 SPANPANIC means that we must dump now.
593 kind == 0 is any old instruction.
594 kind > 0 means we just had a control transfer instruction.
595 kind == 1 means within a function
596 kind == 2 means we just left a function
598 The dump_literals (1) call inserts a branch around the table, so
599 we first look to see if its a situation where we won't have to
600 insert a branch (e.g., the previous instruction was an unconditional
603 SPANPANIC is the point where we must dump a single-entry pool.
604 it accounts for alignments and an inserted branch.
605 the 'poolsize*2' accounts for the scenario where we do:
606 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
607 Note that the 'lit2' reference is 2 bytes further along
608 but the literal it references will be 4 bytes further along,
609 so we must consider the poolsize into this equation.
610 This is slightly over-cautious, but guarantees that we won't
611 panic because a relocation is too distant. */
613 if (poolspan
> SPANCLOSE
&& kind
> 0)
615 else if (poolspan
> SPANEXIT
&& kind
> 1)
617 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
622 enter_literal (e
, ispcrel
)
629 if (poolsize
>= MAX_POOL_SIZE
- 2)
631 /* The literal pool is as full as we can handle. We have
632 to be 2 entries shy of the 1024/4=256 entries because we
633 have to allow for the branch (2 bytes) and the alignment
634 (2 bytes before the first insn referencing the pool and
635 2 bytes before the pool itself) == 6 bytes, rounds up
642 /* Create new literal pool. */
643 if (++ poolnumber
> 0xFFFF)
644 as_fatal (_("more than 65K literal pools"));
646 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
647 poolsym
= symbol_make (poolname
);
648 symbol_table_insert (poolsym
);
652 /* Search pool for value so we don't have duplicates. */
653 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
655 if (e
->X_op
== p
->e
.X_op
656 && e
->X_add_symbol
== p
->e
.X_add_symbol
657 && e
->X_add_number
== p
->e
.X_add_number
658 && ispcrel
== p
->ispcrel
)
666 p
->ispcrel
= ispcrel
;
674 /* Parse a literal specification. -- either new or old syntax.
675 old syntax: the user supplies the label and places the literal.
676 new syntax: we put it into the literal pool. */
678 parse_rt (s
, outputp
, ispcrel
, ep
)
688 /* Indicate nothing there. */
693 s
= parse_exp (s
+ 1, & e
);
698 as_bad (_("missing ']'"));
702 s
= parse_exp (s
, & e
);
704 n
= enter_literal (& e
, ispcrel
);
709 /* Create a reference to pool entry. */
711 e
.X_add_symbol
= poolsym
;
712 e
.X_add_number
= n
<< 2;
715 * outputp
= frag_more (2);
717 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
718 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
724 parse_imm (s
, val
, min
, max
)
733 new = parse_exp (s
, & e
);
735 if (e
.X_op
== O_absent
)
736 ; /* An error message has already been emitted. */
737 else if (e
.X_op
!= O_constant
)
738 as_bad (_("operand must be a constant"));
739 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
740 as_bad (_("operand must be absolute in range %d..%d, not %d"),
741 min
, max
, e
.X_add_number
);
743 * val
= e
.X_add_number
;
749 parse_mem (s
, reg
, off
, siz
)
759 while (isspace (* s
))
764 s
= parse_reg (s
+ 1, reg
);
766 while (isspace (* s
))
771 s
= parse_imm (s
+ 1, off
, 0, 63);
778 as_bad (_("operand must be a multiple of 4"));
785 as_bad (_("operand must be a multiple of 2"));
792 while (isspace (* s
))
799 as_bad (_("base register expected"));
804 /* This is the guts of the machine-dependent assembler. STR points to a
805 machine dependent instruction. This function is supposed to emit
806 the frags/bytes it assembles to. */
814 mcore_opcode_info
* opcode
;
824 /* Drop leading whitespace. */
825 while (isspace (* str
))
828 /* Find the op code end. */
829 for (op_start
= op_end
= str
;
830 * op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
833 name
[nlen
] = op_start
[nlen
];
841 as_bad (_("can't find opcode "));
845 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
848 as_bad (_("unknown opcode \"%s\""), name
);
855 switch (opcode
->opclass
)
858 output
= frag_more (2);
862 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
864 output
= frag_more (2);
868 op_end
= parse_reg (op_end
+ 1, & reg
);
870 output
= frag_more (2);
874 op_end
= parse_reg (op_end
+ 1, & reg
);
876 output
= frag_more (2);
877 /* In a sifilter mode, we emit this insn 2 times,
878 fixes problem of an interrupt during a jmp.. */
881 output
[0] = INST_BYTE0 (inst
);
882 output
[1] = INST_BYTE1 (inst
);
883 output
= frag_more (2);
888 op_end
= parse_reg (op_end
+ 1, & reg
);
891 as_bad (_("invalid register: r15 illegal"));
894 output
= frag_more (2);
898 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
899 inst
= MCORE_INST_BSR
; /* with 0 displacement */
900 output
[0] = INST_BYTE0 (inst
);
901 output
[1] = INST_BYTE1 (inst
);
903 output
= frag_more (2);
904 inst
= MCORE_INST_ADDI
;
905 inst
|= 15; /* addi r15,6 */
906 inst
|= (6 - 1) << 4; /* over the jmp's */
907 output
[0] = INST_BYTE0 (inst
);
908 output
[1] = INST_BYTE1 (inst
);
910 output
= frag_more (2);
911 inst
= MCORE_INST_JMP
| reg
;
912 output
[0] = INST_BYTE0 (inst
);
913 output
[1] = INST_BYTE1 (inst
);
915 output
= frag_more (2); /* 2nd emitted in fallthru */
920 op_end
= parse_reg (op_end
+ 1, & reg
);
923 /* Skip whitespace. */
924 while (isspace (* op_end
))
929 op_end
= parse_creg (op_end
+ 1, & reg
);
933 output
= frag_more (2);
937 op_end
= parse_reg (op_end
+ 1, & reg
);
940 /* Skip whitespace. */
941 while (isspace (* op_end
))
946 op_end
= parse_reg (op_end
+ 1, & reg
);
950 as_bad (_("second operand missing"));
952 output
= frag_more (2);
955 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
956 op_end
= parse_reg (op_end
+ 1, & reg
);
958 /* Skip whitespace. */
959 while (isspace (* op_end
))
962 if (* op_end
== ',') /* xtrb- r1,rx */
965 as_bad (_("destination register must be r1"));
967 op_end
= parse_reg (op_end
+ 1, & reg
);
971 output
= frag_more (2);
974 case O1R1
: /* div- rx,r1 */
975 op_end
= parse_reg (op_end
+ 1, & reg
);
978 /* Skip whitespace. */
979 while (isspace (* op_end
))
984 op_end
= parse_reg (op_end
+ 1, & reg
);
986 as_bad (_("source register must be r1"));
989 as_bad (_("second operand missing"));
991 output
= frag_more (2);
995 op_end
= parse_reg (op_end
+ 1, & reg
);
998 /* Skip whitespace. */
999 while (isspace (* op_end
))
1002 if (* op_end
== ',')
1004 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1005 inst
|= (reg
- 1) << 4;
1008 as_bad (_("second operand missing"));
1010 output
= frag_more (2);
1014 op_end
= parse_reg (op_end
+ 1, & reg
);
1017 /* Skip whitespace. */
1018 while (isspace (* op_end
))
1021 if (* op_end
== ',')
1023 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1027 as_bad (_("second operand missing"));
1029 output
= frag_more (2);
1032 case OB2
: /* like OB, but arg is 2^n instead of n */
1033 op_end
= parse_reg (op_end
+ 1, & reg
);
1036 /* Skip whitespace. */
1037 while (isspace (* op_end
))
1040 if (* op_end
== ',')
1042 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1043 /* Further restrict the immediate to a power of two. */
1044 if ((reg
& (reg
- 1)) == 0)
1049 as_bad (_("immediate is not a power of two"));
1054 as_bad (_("second operand missing"));
1056 output
= frag_more (2);
1059 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1062 op_end
= parse_reg (op_end
+ 1, & reg
);
1065 /* Skip whitespace. */
1066 while (isspace (* op_end
))
1069 if (* op_end
== ',')
1071 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1072 /* immediate values of 0 -> 6 translate to movi */
1075 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1077 as_warn (_("translating bgeni to movi"));
1083 as_bad (_("second operand missing"));
1085 output
= frag_more (2);
1088 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1089 op_end
= parse_reg (op_end
+ 1, & reg
);
1092 /* Skip whitespace. */
1093 while (isspace (* op_end
))
1096 if (* op_end
== ',')
1098 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1100 /* Further restrict the immediate to a power of two. */
1101 if ((reg
& (reg
- 1)) == 0)
1106 as_bad (_("immediate is not a power of two"));
1109 /* Immediate values of 0 -> 6 translate to movi. */
1112 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1114 as_warn (_("translating mgeni to movi"));
1120 as_bad (_("second operand missing"));
1122 output
= frag_more (2);
1125 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1128 op_end
= parse_reg (op_end
+ 1, & reg
);
1131 /* Skip whitespace. */
1132 while (isspace (* op_end
))
1135 if (* op_end
== ',')
1137 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1139 /* Immediate values of 1 -> 7 translate to movi. */
1142 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1143 reg
= (0x1 << reg
) - 1;
1146 as_warn (_("translating bmaski to movi"));
1151 inst
|= (reg
& 0x1F) << 4;
1155 as_bad (_("second operand missing"));
1157 output
= frag_more (2);
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
, 1, 31);
1174 as_bad (_("second operand missing"));
1176 output
= frag_more (2);
1180 op_end
= parse_reg (op_end
+ 1, & reg
);
1183 /* Skip whitespace. */
1184 while (isspace (* op_end
))
1187 if (* op_end
== ',')
1189 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1193 as_bad (_("second operand missing"));
1195 output
= frag_more (2);
1199 op_end
= parse_reg (op_end
+ 1, & reg
);
1202 /* Skip whitespace. */
1203 while (isspace (* op_end
))
1206 if (* op_end
== ',')
1210 if ((inst
& 0x6000) == 0)
1212 else if ((inst
& 0x6000) == 0x4000)
1214 else if ((inst
& 0x6000) == 0x2000)
1217 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1220 as_bad (_("displacement too large (%d)"), off
);
1222 inst
|= (reg
) | (off
<< 4);
1225 as_bad (_("second operand missing"));
1227 output
= frag_more (2);
1231 op_end
= parse_reg (op_end
+ 1, & reg
);
1233 if (reg
== 0 || reg
== 15)
1234 as_bad (_("Invalid register: r0 and r15 illegal"));
1238 /* Skip whitespace. */
1239 while (isspace (* op_end
))
1242 if (* op_end
== ',')
1243 /* parse_rt calls frag_more() for us. */
1244 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1247 as_bad (_("second operand missing"));
1248 output
= frag_more (2); /* save its space */
1253 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1254 /* parse_rt() calls frag_more() for us. */
1258 op_end
= parse_reg (op_end
+ 1, & reg
);
1260 if (reg
== 0 || reg
== 15)
1261 as_bad (_("bad starting register: r0 and r15 invalid"));
1265 /* Skip whitespace. */
1266 while (isspace (* op_end
))
1269 if (* op_end
== '-')
1271 op_end
= parse_reg (op_end
+ 1, & reg
);
1274 as_bad (_("ending register must be r15"));
1276 /* Skip whitespace. */
1277 while (isspace (* op_end
))
1281 if (* op_end
== ',')
1285 /* Skip whitespace. */
1286 while (isspace (* op_end
))
1289 if (* op_end
== '(')
1291 op_end
= parse_reg (op_end
+ 1, & reg
);
1294 as_bad (_("bad base register: must be r0"));
1296 if (* op_end
== ')')
1300 as_bad (_("base register expected"));
1303 as_bad (_("second operand missing"));
1305 output
= frag_more (2);
1309 op_end
= parse_reg (op_end
+ 1, & reg
);
1312 as_fatal (_("first register must be r4"));
1314 /* Skip whitespace. */
1315 while (isspace (* op_end
))
1318 if (* op_end
== '-')
1320 op_end
= parse_reg (op_end
+ 1, & reg
);
1323 as_fatal (_("last register must be r7"));
1325 /* Skip whitespace. */
1326 while (isspace (* op_end
))
1329 if (* op_end
== ',')
1333 /* Skip whitespace. */
1334 while (isspace (* op_end
))
1337 if (* op_end
== '(')
1339 op_end
= parse_reg (op_end
+ 1, & reg
);
1341 if (reg
>= 4 && reg
<= 7)
1342 as_fatal ("base register cannot be r4, r5, r6, or r7");
1346 /* Skip whitespace. */
1347 while (isspace (* op_end
))
1350 if (* op_end
== ')')
1354 as_bad (_("base register expected"));
1357 as_bad (_("second operand missing"));
1360 as_bad (_("reg-reg expected"));
1362 output
= frag_more (2);
1366 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1368 output
= frag_more (2);
1370 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1371 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1375 op_end
= parse_reg (op_end
+ 1, & reg
);
1378 /* Skip whitespace. */
1379 while (isspace (* op_end
))
1382 if (* op_end
== ',')
1384 op_end
= parse_exp (op_end
+ 1, & e
);
1385 output
= frag_more (2);
1387 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1388 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1392 as_bad (_("second operand missing"));
1393 output
= frag_more (2);
1398 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1400 output
= frag_var (rs_machine_dependent
,
1401 md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
,
1402 md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
,
1403 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1408 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1409 output
= frag_var (rs_machine_dependent
,
1410 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
1411 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
1412 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1417 inst
= MCORE_INST_JSRI
; /* jsri */
1418 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1419 /* parse_rt() calls frag_more for us */
1421 /* Only do this if we know how to do it ... */
1422 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1424 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1425 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1426 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1430 case RSI
: /* SI, but imm becomes 32-imm */
1431 op_end
= parse_reg (op_end
+ 1, & reg
);
1434 /* Skip whitespace. */
1435 while (isspace (* op_end
))
1438 if (* op_end
== ',')
1440 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1446 as_bad (_("second operand missing"));
1448 output
= frag_more (2);
1451 case DO21
: /* O2, dup rd, lit must be 1 */
1452 op_end
= parse_reg (op_end
+ 1, & reg
);
1456 /* Skip whitespace. */
1457 while (isspace (* op_end
))
1460 if (* op_end
== ',')
1462 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1465 as_bad (_("second operand must be 1"));
1468 as_bad (_("second operand missing"));
1470 output
= frag_more (2);
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_imm (op_end
+ 1, & reg
, 1, 31);
1486 as_bad (_("zero used as immediate value"));
1491 as_bad (_("second operand missing"));
1493 output
= frag_more (2);
1497 as_bad (_("unimplemented opcode \"%s\""), name
);
1500 output
[0] = INST_BYTE0 (inst
);
1501 output
[1] = INST_BYTE1 (inst
);
1503 check_literals (opcode
->transfer
, isize
);
1507 md_undefined_symbol (name
)
1517 subseg_set (text_section
, 0);
1520 /* Various routines to kill one day. */
1521 /* Equal to MAX_PRECISION in atof-ieee.c */
1522 #define MAX_LITTLENUMS 6
1524 /* Turn a string in input_line_pointer into a floating point constant of type
1525 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1526 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1528 md_atof (type
, litP
, sizeP
)
1534 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1537 char * atof_ieee ();
1567 return _("Bad call to MD_NTOF()");
1570 t
= atof_ieee (input_line_pointer
, type
, words
);
1573 input_line_pointer
= t
;
1575 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1577 for (i
= 0; i
< prec
; i
++)
1579 md_number_to_chars (litP
, (valueT
) words
[i
],
1580 sizeof (LITTLENUM_TYPE
));
1581 litP
+= sizeof (LITTLENUM_TYPE
);
1587 CONST
char * md_shortopts
= "";
1589 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1590 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1591 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1592 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1594 struct option md_longopts
[] =
1596 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1597 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1598 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1599 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1600 { NULL
, no_argument
, NULL
, 0}
1603 size_t md_longopts_size
= sizeof (md_longopts
);
1606 md_parse_option (c
, arg
)
1616 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1617 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1618 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1619 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1627 md_show_usage (stream
)
1630 fprintf (stream
, _("\
1631 MCORE specific options:\n\
1632 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1633 -{no-}sifilter {dis}able silicon filter behavior (def: dis)"));
1636 int md_short_jump_size
;
1639 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1644 symbolS
* to_symbol
;
1646 as_fatal (_("failed sanity check: short_jump"));
1650 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1655 symbolS
* to_symbol
;
1657 as_fatal (_("failed sanity check: long_jump"));
1660 /* Called after relaxing, change the frags so they know how big they are. */
1662 md_convert_frag (abfd
, sec
, fragP
)
1665 register fragS
* fragP
;
1667 unsigned char * buffer
;
1668 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1670 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1671 targ_addr
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
1673 switch (fragP
->fr_subtype
)
1675 case C (COND_JUMP
, COND12
):
1676 case C (UNCD_JUMP
, UNCD12
):
1678 /* Get the address of the end of the instruction */
1679 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1681 int disp
= targ_addr
- next_inst
;
1684 as_bad (_("odd displacement at %x"), next_inst
- 2);
1688 t0
= buffer
[0] & 0xF8;
1690 md_number_to_chars (buffer
, disp
, 2);
1692 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1700 case C (COND_JUMP
, COND32
):
1701 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1703 /* A conditional branch wont fit into 12 bits so:
1710 * if the b!cond is 4 byte aligned, the literal which would
1711 * go at x+4 will also be aligned.
1713 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1714 int needpad
= (first_inst
& 3);
1716 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1718 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1719 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1724 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1725 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1728 buffer
[4] = 0; /* alignment/pad */
1730 buffer
[6] = 0; /* space for 32 bit address */
1735 /* Make reloc for the long disp */
1736 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1737 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1739 fragP
->fr_fix
+= C32_LEN
;
1743 /* See comment below about this given gas' limitations for
1744 shrinking the fragment. '3' is the amount of code that
1745 we inserted here, but '4' is right for the space we reserved
1746 for this fragment. */
1748 buffer
[1] = 3; /* branch over jmpi, and ptr */
1749 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1752 buffer
[4] = 0; /* space for 32 bit address */
1757 /* Make reloc for the long disp. */
1758 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1759 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1760 fragP
->fr_fix
+= C32_LEN
;
1762 /* Frag is actually shorter (see the other side of this ifdef)
1763 but gas isn't prepared for that. We have to re-adjust
1764 the branch displacement so that it goes beyond the
1765 full length of the fragment, not just what we actually
1767 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1774 case C (UNCD_JUMP
, UNCD32
):
1775 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1777 /* An unconditional branch will not fit in 12 bits, make code which
1782 we need a pad if "first_inst" is 4 byte aligned.
1783 [because the natural literal place is x + 2] */
1784 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1785 int needpad
= !(first_inst
& 3);
1787 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1788 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1792 buffer
[1] = 1; /* jmpi offset of 1 since padded */
1793 buffer
[2] = 0; /* alignment */
1795 buffer
[4] = 0; /* space for 32 bit address */
1800 /* Make reloc for the long disp */
1801 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1802 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1804 fragP
->fr_fix
+= U32_LEN
;
1808 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
1809 buffer
[2] = 0; /* space for 32 bit address */
1814 /* Make reloc for the long disp */
1815 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1816 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1817 fragP
->fr_fix
+= U32_LEN
;
1829 /* Applies the desired value to the specified location.
1830 Also sets up addends for 'rela' type relocations. */
1832 md_apply_fix3 (fixP
, valp
, segment
)
1837 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1838 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1839 const char * symname
;
1840 /* Note: use offsetT because it is signed, valueT is unsigned. */
1841 offsetT val
= (offsetT
) * valp
;
1843 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1844 /* Save this for the addend in the relocation record. */
1845 fixP
->fx_addnumber
= val
;
1847 /* If the fix is relative to a symbol which is not defined, or not
1848 in the same segment as the fix, we cannot resolve it here. */
1849 if (fixP
->fx_addsy
!= NULL
1850 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
1851 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
1855 /* For ELF we can just return and let the reloc that will be generated
1856 take care of everything. For COFF we still have to insert 'val'
1857 into the insn since the addend field will be ignored. */
1864 switch (fixP
->fx_r_type
)
1866 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
1868 as_bad_where (file
, fixP
->fx_line
,
1869 _("odd distance branch (0x%x bytes)"), val
);
1871 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
1872 as_bad_where (file
, fixP
->fx_line
,
1873 _("pcrel for branch to %s too far (0x%x)"),
1875 buf
[0] |= ((val
>> 8) & 0x7);
1876 buf
[1] |= (val
& 0xff);
1879 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
1883 as_bad_where (file
, fixP
->fx_line
,
1884 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
1887 buf
[1] |= (val
& 0xff);
1890 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
1891 if ((val
< -32) || (val
> -2))
1892 as_bad_where (file
, fixP
->fx_line
,
1893 _("pcrel for loopt too far (0x%x)"), val
);
1895 buf
[1] |= (val
& 0xf);
1898 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
1899 /* Conditional linker map jsri to bsr. */
1900 /* If its a local target and close enough, fix it.
1901 NB: >= -2k for backwards bsr; < 2k for forwards... */
1902 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
1904 long nval
= (val
/ 2) & 0x7ff;
1905 nval
|= MCORE_INST_BSR
;
1907 /* REPLACE the instruction, don't just modify it. */
1908 buf
[0] = INST_BYTE0 (nval
);
1909 buf
[1] = INST_BYTE1 (nval
);
1915 case BFD_RELOC_MCORE_PCREL_32
:
1916 case BFD_RELOC_VTABLE_INHERIT
:
1917 case BFD_RELOC_VTABLE_ENTRY
:
1922 if (fixP
->fx_addsy
!= NULL
)
1924 /* If the fix is an absolute reloc based on a symbol's
1925 address, then it cannot be resolved until the final link. */
1932 if (fixP
->fx_size
== 4)
1934 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
1936 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
1940 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1945 return 0; /* Return value is ignored. */
1949 md_operand (expressionP
)
1950 expressionS
* expressionP
;
1952 /* Ignore leading hash symbol, if poresent. */
1953 if (* input_line_pointer
== '#')
1955 input_line_pointer
++;
1956 expression (expressionP
);
1960 int md_long_jump_size
;
1962 /* Called just before address relaxation, return the length
1963 by which a fragment must grow to reach it's destination. */
1965 md_estimate_size_before_relax (fragP
, segment_type
)
1966 register fragS
* fragP
;
1967 register segT segment_type
;
1969 switch (fragP
->fr_subtype
)
1971 case C (UNCD_JUMP
, UNDEF_DISP
):
1972 /* Used to be a branch to somewhere which was unknown. */
1973 if (!fragP
->fr_symbol
)
1975 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
1976 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
1978 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
1980 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
1981 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
1985 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
1986 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
1987 return md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
1994 case C (COND_JUMP
, UNDEF_DISP
):
1995 /* Used to be a branch to somewhere which was unknown. */
1996 if (fragP
->fr_symbol
1997 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
1999 /* Got a symbol and it's defined in this segment, become byte
2000 sized - maybe it will fix up */
2001 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2002 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2004 else if (fragP
->fr_symbol
)
2006 /* Its got a segment, but its not ours, so it will always be long. */
2007 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2008 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2009 return md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2013 /* We know the abs value. */
2014 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2015 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2021 return fragP
->fr_var
;
2024 /* Put number into target byte order */
2026 md_number_to_chars (ptr
, use
, nbytes
)
2033 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2034 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2035 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2036 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2041 /* Round up a section size to the appropriate boundary. */
2043 md_section_align (segment
, size
)
2047 return size
; /* Byte alignment is fine */
2051 /* The location from which a PC relative jump should be calculated,
2052 given a PC relative reloc. */
2054 md_pcrel_from_section (fixp
, sec
)
2059 /* If the symbol is undefined or defined in another section
2060 we leave the add number alone for the linker to fix it later.
2061 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2062 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2063 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2064 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2067 assert (fixp
->fx_size
== 2); /* must be an insn */
2068 return fixp
->fx_size
;
2072 /* The case where we are going to resolve things... */
2073 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2076 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2077 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2080 tc_gen_reloc (section
, fixp
)
2085 bfd_reloc_code_real_type code
;
2088 switch (fixp
->fx_r_type
)
2090 /* These confuse the size/pcrel macro approach. */
2091 case BFD_RELOC_VTABLE_INHERIT
:
2092 case BFD_RELOC_VTABLE_ENTRY
:
2093 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2094 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2095 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2096 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2097 code
= fixp
->fx_r_type
;
2101 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2103 MAP (1, 0, BFD_RELOC_8
);
2104 MAP (2, 0, BFD_RELOC_16
);
2105 MAP (4, 0, BFD_RELOC_32
);
2106 MAP (1, 1, BFD_RELOC_8_PCREL
);
2107 MAP (2, 1, BFD_RELOC_16_PCREL
);
2108 MAP (4, 1, BFD_RELOC_32_PCREL
);
2110 code
= fixp
->fx_r_type
;
2111 as_bad (_("Can not do %d byte %srelocation"),
2113 fixp
->fx_pcrel
? _("pc-relative") : "");
2118 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2119 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2120 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2121 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2122 /* Always pass the addend along! */
2123 rel
->addend
= fixp
->fx_addnumber
;
2125 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2127 if (rel
->howto
== NULL
)
2129 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2130 _("Cannot represent relocation type %s"),
2131 bfd_get_reloc_code_name (code
));
2133 /* Set howto to a garbage value so that we can keep going. */
2134 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2135 assert (rel
->howto
!= NULL
);
2142 /* See whether we need to force a relocation into the output file.
2143 This is used to force out switch and PC relative relocations when
2146 mcore_force_relocation (fix
)
2149 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2150 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2156 /* Return true if the fix can be handled by GAS, false if it must
2157 be passed through to the linker. */
2159 mcore_fix_adjustable (fixP
)
2162 if (fixP
->fx_addsy
== NULL
)
2165 /* We need the symbol name for the VTABLE entries. */
2166 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2167 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2173 /* Handle the .section pseudo-op. This is like the usual one, but it
2174 dumps the literal pool before changing the section. */
2176 mcore_s_section (ignore
)
2181 obj_elf_section (ignore
);
2183 #endif /* OBJ_ELF */