1 /* tc-mcore.c -- Assemble code for M*Core
3 Copyright (C) 1993,1994, 1999 Free Software Foundation.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
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 int log2
PARAMS ((unsigned int));
44 static char * parse_reg
PARAMS ((char *, unsigned *));
45 static char * parse_creg
PARAMS ((char *, unsigned *));
46 static char * parse_exp
PARAMS ((char *, expressionS
*));
47 static void make_name
PARAMS ((char *, char *, int));
48 static int enter_literal
PARAMS ((expressionS
*, int));
49 static char * parse_rt
PARAMS ((char *, char **, int, expressionS
*));
50 static char * parse_imm
PARAMS ((char *, unsigned *, unsigned, unsigned));
51 static char * parse_mem
PARAMS ((char *, unsigned *, unsigned *, unsigned));
52 static void dump_literals
PARAMS ((int));
53 static void check_literals
PARAMS ((int, int));
54 static void mcore_s_text
PARAMS ((int));
55 static void mcore_s_data
PARAMS ((int));
57 static void mcore_s_section
PARAMS ((int));
60 /* Several places in this file insert raw instructions into the
61 object. They should use MCORE_INST_XXX macros to get the opcodes
62 and then use these two macros to crack the MCORE_INST value into
63 the appropriate byte values. */
64 #define INST_BYTE0(x) (((x) >> 8) & 0xFF)
65 #define INST_BYTE1(x) ((x) & 0xFF)
67 const char comment_chars
[] = "#/";
68 const char line_separator_chars
[] = ";";
69 const char line_comment_chars
[] = "#/";
71 const int md_reloc_size
= 8;
73 static int do_jsri2bsr
= 0; /* change here from 1 by Cruess 19 August 97 */
74 static int sifilter_mode
= 0;
76 const char EXP_CHARS
[] = "eE";
78 /* Chars that mean this number is a floating point constant */
81 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
83 #define C(what,length) (((what) << 2) + (length))
84 #define GET_WHAT(x) ((x >> 2))
86 /* These are the two types of relaxable instruction */
95 #define UNDEF_WORD_DISP 4
99 #define C32_LEN 10 /* allow for align */
101 #define U32_LEN 8 /* allow for align */
104 /* Initialize the relax table */
105 const relax_typeS md_relax_table
[] =
107 { 1, 1, 0, 0 }, /* 0: unused */
108 { 1, 1, 0, 0 }, /* 1: unused */
109 { 1, 1, 0, 0 }, /* 2: unused */
110 { 1, 1, 0, 0 }, /* 3: unused */
111 { 1, 1, 0, 0 }, /* 4: unused */
112 { 2048, -2046, C12_LEN
, C(COND_JUMP
, COND32
) }, /* 5: C(COND_JUMP, COND12) */
113 { 0, 0, C32_LEN
, 0 }, /* 6: C(COND_JUMP, COND32) */
114 { 1, 1, 0, 0 }, /* 7: unused */
115 { 1, 1, 0, 0 }, /* 8: unused */
116 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, UNCD32
) }, /* 9: C(UNCD_JUMP, UNCD12) */
117 { 0, 0, U32_LEN
, 0 }, /*10: C(UNCD_JUMP, UNCD32) */
118 { 1, 1, 0, 0 }, /*11: unused */
119 { 0, 0, 0, 0 } /*12: unused */
122 /* LITERAL POOL DATA STRUCTURES */
125 unsigned short refcnt
;
126 unsigned char ispcrel
;
127 unsigned char unused
;
131 #define MAX_POOL_SIZE (1024/4)
132 static struct literal litpool
[MAX_POOL_SIZE
];
133 static unsigned poolsize
;
134 static unsigned poolnumber
;
135 static unsigned long poolspan
;
137 /* SPANPANIC: the point at which we get too scared and force a dump
138 of the literal pool, and perhaps put a branch in place.
140 1024 span of lrw/jmpi/jsri insn (actually span+1)
141 -2 possible alignment at the insn.
142 -2 possible alignment to get the table aligned.
143 -2 an inserted branch around the table.
145 at 1018, we might be in trouble.
146 -- so we have to be smaller than 1018 and since we deal with 2-byte
147 instructions, the next good choice is 1016.
148 -- Note we have a test case that fails when we've got 1018 here. */
149 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding */
150 #define SPANCLOSE (900)
151 #define SPANEXIT (600)
152 static symbolS
* poolsym
; /* label for current pool */
153 static char poolname
[8];
154 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics */
156 /* This table describes all the machine specific pseudo-ops the assembler
157 has to support. The fields are:
158 Pseudo-op name without dot
159 Function to call to execute this pseudo-op
160 Integer arg to pass to the function */
161 const pseudo_typeS md_pseudo_table
[] =
163 { "export", s_globl
, 0 },
164 { "import", s_ignore
, 0 },
165 { "literals", mcore_s_literals
, 0 },
166 { "page", listing_eject
, 0 },
167 { "bss", s_lcomm_bytes
, 1 },
169 /* The following are to intercept the placement of data into the text
170 section (eg addresses for a switch table), so that the space they
171 occupy can be taken into account when deciding whether or not to
172 dump the current literal pool.
173 XXX - currently we do not cope with the .space and .dcb.d directives. */
174 { "ascii", mcore_stringer
, 0 },
175 { "asciz", mcore_stringer
, 1 },
176 { "byte", mcore_cons
, 1 },
177 { "dc", mcore_cons
, 2 },
178 { "dc.b", mcore_cons
, 1 },
179 { "dc.d", mcore_float_cons
, 'd' },
180 { "dc.l", mcore_cons
, 4 },
181 { "dc.s", mcore_float_cons
, 'f' },
182 { "dc.w", mcore_cons
, 2 },
183 { "dc.x", mcore_float_cons
, 'x' },
184 { "double", mcore_float_cons
, 'd'},
185 { "float", mcore_float_cons
, 'f'},
186 { "hword", mcore_cons
, 2 },
187 { "int", mcore_cons
, 4 },
188 { "long", mcore_cons
, 4 },
189 { "octa", mcore_cons
, 16 },
190 { "quad", mcore_cons
, 8 },
191 { "short", mcore_cons
, 2 },
192 { "single", mcore_float_cons
, 'f'},
193 { "string", mcore_stringer
, 1 },
194 { "word", mcore_cons
, 2 },
196 /* Allow for the effect of section changes. */
197 { "text", mcore_s_text
, 0 },
198 { "data", mcore_s_data
, 0 },
201 { "section", mcore_s_section
, 0 },
202 { "section.s", mcore_s_section
, 0 },
203 { "sect", mcore_s_section
, 0 },
204 { "sect.s", mcore_s_section
, 0 },
210 mcore_s_literals (ignore
)
214 demand_empty_rest_of_line ();
222 if (now_seg
== text_section
)
224 char * ptr
= input_line_pointer
;
227 /* Count the number of commas on the line. */
228 while (! is_end_of_line
[* ptr
])
229 commas
+= * ptr
++ == ',';
231 poolspan
+= nbytes
* commas
;
236 /* In theory we ought to call check_literals (2,0) here in case
237 we need to dump the literal table. We cannot do this however,
238 as the directives that we are intercepting may be being used
239 to build a switch table, and we must not interfere with its
240 contents. Instead we cross our fingers and pray... */
244 mcore_float_cons (float_type
)
247 if (now_seg
== text_section
)
249 char * ptr
= input_line_pointer
;
252 #ifdef REPEAT_CONS_EXPRESSIONS
253 #error REPEAT_CONS_EXPRESSIONS not handled
256 /* Count the number of commas on the line. */
257 while (! is_end_of_line
[* ptr
])
258 commas
+= * ptr
++ == ',';
260 /* We would like to compute "hex_float (float_type) * commas"
261 but hex_float is not exported from read.c */
262 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
263 poolspan
+= float_type
* commas
;
266 float_cons (float_type
);
268 /* See the comment in mcore_cons () about calling check_literals.
269 It is unlikely that a switch table will be constructed using
270 floating point values, but it is still likely that an indexed
271 table of floating point constants is being created by these
272 directives, so again we must not interfere with their placement. */
276 mcore_stringer (append_zero
)
279 if (now_seg
== text_section
)
281 char * ptr
= input_line_pointer
;
283 /* In theory we should compute how many bytes are going to
284 be occupied by the string(s) and add this to the poolspan.
285 To keep things simple however, we just add the number of
286 bytes left on the current line. This will be an over-
287 estimate, which is OK, and automatically allows for the
288 appending a zero byte, since the real string(s) is/are
289 required to be enclosed in double quotes. */
290 while (! is_end_of_line
[* ptr
])
293 poolspan
+= ptr
- input_line_pointer
;
296 stringer (append_zero
);
298 /* We call check_literals here in case a large number of strings are
299 being placed into the text section with a sequence of stringer
300 directives. In theory we could be upsetting something if these
301 strings are actually in an indexed table instead of referenced by
302 individual labels. Let us hope that that never happens. */
303 check_literals (2, 0);
307 mcore_s_text (ignore
)
316 mcore_s_data (ignore
)
324 /* This function is called once, at assembler startup time. This should
325 set up all the tables, etc that the MD part of the assembler needs. */
329 mcore_opcode_info
* opcode
;
330 char * prev_name
= "";
332 opcode_hash_control
= hash_new ();
334 /* Insert unique names into hash table */
335 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
337 if (streq (prev_name
, opcode
->name
))
339 /* Make all the opcodes with the same name point to the same
341 opcode
->name
= prev_name
;
345 prev_name
= opcode
->name
;
346 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
353 static expressionS immediate
; /* absolute expression */
355 /* Get a log2(val). */
370 /* Try to parse a reg name. */
376 /* Strip leading whitespace. */
377 while (isspace (* s
))
380 if (tolower (s
[0]) == 'r')
382 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
384 *reg
= 10 + s
[2] - '0';
388 if (s
[1] >= '0' && s
[1] <= '9')
394 else if ( tolower (s
[0]) == 's'
395 && tolower (s
[1]) == 'p'
402 as_bad (_("register expected, but saw '%.6s'"), s
);
436 /* Strip leading whitespace. */
437 while (isspace (* s
))
440 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
442 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
444 *reg
= 30 + s
[3] - '0';
448 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
450 *reg
= 20 + s
[3] - '0';
454 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
456 *reg
= 10 + s
[3] - '0';
460 if (s
[2] >= '0' && s
[2] <= '9')
467 /* Look at alternate creg names before giving error. */
468 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
474 length
= strlen (cregs
[i
].name
);
476 for (j
= 0; j
< length
; j
++)
477 buf
[j
] = tolower (s
[j
]);
479 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
481 *reg
= cregs
[i
].crnum
;
486 as_bad (_("control register expected, but saw '%.6s'"), s
);
499 /* Skip whitespace. */
500 while (isspace (* s
))
503 save
= input_line_pointer
;
504 input_line_pointer
= s
;
508 if (e
->X_op
== O_absent
)
509 as_bad (_("missing operand"));
511 new = input_line_pointer
;
512 input_line_pointer
= save
;
523 static const char hex
[] = "0123456789ABCDEF";
528 s
[3] = hex
[(n
>> 12) & 0xF];
529 s
[4] = hex
[(n
>> 8) & 0xF];
530 s
[5] = hex
[(n
>> 4) & 0xF];
531 s
[6] = hex
[(n
) & 0xF];
535 #define POOL_END_LABEL ".LE"
536 #define POOL_START_LABEL ".LS"
539 dump_literals (isforce
)
544 struct symbol
* brarsym
;
549 /* Must we branch around the literal table? */
555 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
557 brarsym
= symbol_make (brarname
);
559 symbol_table_insert (brarsym
);
561 output
= frag_var (rs_machine_dependent
,
562 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
563 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
564 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
565 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
566 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
569 /* Make sure that the section is sufficiently aligned and that
570 the literal table is aligned within it. */
571 record_alignment (now_seg
, 2);
572 frag_align (2, 0, 0);
574 colon (S_GET_NAME (poolsym
));
576 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
577 emit_expr (& p
->e
, 4);
580 colon (S_GET_NAME (brarsym
));
586 check_literals (kind
, offset
)
592 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
593 SPANPANIC means that we must dump now.
594 kind == 0 is any old instruction.
595 kind > 0 means we just had a control transfer instruction.
596 kind == 1 means within a function
597 kind == 2 means we just left a function
599 The dump_literals (1) call inserts a branch around the table, so
600 we first look to see if its a situation where we won't have to
601 insert a branch (e.g., the previous instruction was an unconditional
604 SPANPANIC is the point where we must dump a single-entry pool.
605 it accounts for alignments and an inserted branch.
606 the 'poolsize*2' accounts for the scenario where we do:
607 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
608 Note that the 'lit2' reference is 2 bytes further along
609 but the literal it references will be 4 bytes further along,
610 so we must consider the poolsize into this equation.
611 This is slightly over-cautious, but guarantees that we won't
612 panic because a relocation is too distant. */
614 if (poolspan
> SPANCLOSE
&& kind
> 0)
616 else if (poolspan
> SPANEXIT
&& kind
> 1)
618 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
623 enter_literal (e
, ispcrel
)
630 if (poolsize
>= MAX_POOL_SIZE
- 2)
632 /* The literal pool is as full as we can handle. We have
633 to be 2 entries shy of the 1024/4=256 entries because we
634 have to allow for the branch (2 bytes) and the alignment
635 (2 bytes before the first insn referencing the pool and
636 2 bytes before the pool itself) == 6 bytes, rounds up
643 /* Create new literal pool. */
644 if (++ poolnumber
> 0xFFFF)
645 as_fatal (_("more than 65K literal pools"));
647 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
648 poolsym
= symbol_make (poolname
);
649 symbol_table_insert (poolsym
);
653 /* Search pool for value so we don't have duplicates. */
654 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
656 if (e
->X_op
== p
->e
.X_op
657 && e
->X_add_symbol
== p
->e
.X_add_symbol
658 && e
->X_add_number
== p
->e
.X_add_number
659 && ispcrel
== p
->ispcrel
)
667 p
->ispcrel
= ispcrel
;
675 /* Parse a literal specification. -- either new or old syntax.
676 old syntax: the user supplies the label and places the literal.
677 new syntax: we put it into the literal pool. */
679 parse_rt (s
, outputp
, ispcrel
, ep
)
689 /* Indicate nothing there. */
694 s
= parse_exp (s
+ 1, & e
);
699 as_bad (_("missing ']'"));
703 s
= parse_exp (s
, & e
);
705 n
= enter_literal (& e
, ispcrel
);
710 /* Create a reference to pool entry. */
712 e
.X_add_symbol
= poolsym
;
713 e
.X_add_number
= n
<< 2;
716 * outputp
= frag_more (2);
718 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
719 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
725 parse_imm (s
, val
, min
, max
)
734 new = parse_exp (s
, & e
);
736 if (e
.X_op
== O_absent
)
737 ; /* An error message has already been emitted. */
738 else if (e
.X_op
!= O_constant
)
739 as_bad (_("operand must be a constant"));
740 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
741 as_bad (_("operand must be absolute in range %d..%d, not %d"),
742 min
, max
, e
.X_add_number
);
744 * val
= e
.X_add_number
;
750 parse_mem (s
, reg
, off
, siz
)
760 while (isspace (* s
))
765 s
= parse_reg (s
+ 1, reg
);
767 while (isspace (* s
))
772 s
= parse_imm (s
+ 1, off
, 0, 63);
779 as_bad (_("operand must be a multiple of 4"));
786 as_bad (_("operand must be a multiple of 2"));
793 while (isspace (* s
))
800 as_bad (_("base register expected"));
805 /* This is the guts of the machine-dependent assembler. STR points to a
806 machine dependent instruction. This function is supposed to emit
807 the frags/bytes it assembles to. */
815 mcore_opcode_info
* opcode
;
825 /* Drop leading whitespace. */
826 while (isspace (* str
))
829 /* Find the op code end. */
830 for (op_start
= op_end
= str
;
831 * op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
834 name
[nlen
] = op_start
[nlen
];
842 as_bad (_("can't find opcode "));
846 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
849 as_bad (_("unknown opcode \"%s\""), name
);
856 switch (opcode
->opclass
)
859 output
= frag_more (2);
863 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
865 output
= frag_more (2);
869 op_end
= parse_reg (op_end
+ 1, & reg
);
871 output
= frag_more (2);
875 op_end
= parse_reg (op_end
+ 1, & reg
);
877 output
= frag_more (2);
878 /* In a sifilter mode, we emit this insn 2 times,
879 fixes problem of an interrupt during a jmp.. */
882 output
[0] = INST_BYTE0 (inst
);
883 output
[1] = INST_BYTE1 (inst
);
884 output
= frag_more (2);
889 op_end
= parse_reg (op_end
+ 1, & reg
);
892 as_bad (_("invalid register: r15 illegal"));
895 output
= frag_more (2);
899 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
900 inst
= MCORE_INST_BSR
; /* with 0 displacement */
901 output
[0] = INST_BYTE0 (inst
);
902 output
[1] = INST_BYTE1 (inst
);
904 output
= frag_more (2);
905 inst
= MCORE_INST_ADDI
;
906 inst
|= 15; /* addi r15,6 */
907 inst
|= (6 - 1) << 4; /* over the jmp's */
908 output
[0] = INST_BYTE0 (inst
);
909 output
[1] = INST_BYTE1 (inst
);
911 output
= frag_more (2);
912 inst
= MCORE_INST_JMP
| reg
;
913 output
[0] = INST_BYTE0 (inst
);
914 output
[1] = INST_BYTE1 (inst
);
916 output
= frag_more (2); /* 2nd emitted in fallthru */
921 op_end
= parse_reg (op_end
+ 1, & reg
);
924 /* Skip whitespace. */
925 while (isspace (* op_end
))
930 op_end
= parse_creg (op_end
+ 1, & reg
);
934 output
= frag_more (2);
938 op_end
= parse_reg (op_end
+ 1, & reg
);
941 /* Skip whitespace. */
942 while (isspace (* op_end
))
947 op_end
= parse_reg (op_end
+ 1, & reg
);
951 as_bad (_("second operand missing"));
953 output
= frag_more (2);
956 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
957 op_end
= parse_reg (op_end
+ 1, & reg
);
959 /* Skip whitespace. */
960 while (isspace (* op_end
))
963 if (* op_end
== ',') /* xtrb- r1,rx */
966 as_bad (_("destination register must be r1"));
968 op_end
= parse_reg (op_end
+ 1, & reg
);
972 output
= frag_more (2);
975 case O1R1
: /* div- rx,r1 */
976 op_end
= parse_reg (op_end
+ 1, & reg
);
979 /* Skip whitespace. */
980 while (isspace (* op_end
))
985 op_end
= parse_reg (op_end
+ 1, & reg
);
987 as_bad (_("source register must be r1"));
990 as_bad (_("second operand missing"));
992 output
= frag_more (2);
996 op_end
= parse_reg (op_end
+ 1, & reg
);
999 /* Skip whitespace. */
1000 while (isspace (* op_end
))
1003 if (* op_end
== ',')
1005 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1006 inst
|= (reg
- 1) << 4;
1009 as_bad (_("second operand missing"));
1011 output
= frag_more (2);
1015 op_end
= parse_reg (op_end
+ 1, & reg
);
1018 /* Skip whitespace. */
1019 while (isspace (* op_end
))
1022 if (* op_end
== ',')
1024 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1028 as_bad (_("second operand missing"));
1030 output
= frag_more (2);
1033 case OB2
: /* like OB, but arg is 2^n instead of n */
1034 op_end
= parse_reg (op_end
+ 1, & reg
);
1037 /* Skip whitespace. */
1038 while (isspace (* op_end
))
1041 if (* op_end
== ',')
1043 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1044 /* Further restrict the immediate to a power of two. */
1045 if ((reg
& (reg
- 1)) == 0)
1050 as_bad (_("immediate is not a power of two"));
1055 as_bad (_("second operand missing"));
1057 output
= frag_more (2);
1060 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
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);
1073 /* immediate values of 0 -> 6 translate to movi */
1076 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1078 as_warn (_("translating bgeni to movi"));
1084 as_bad (_("second operand missing"));
1086 output
= frag_more (2);
1089 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1090 op_end
= parse_reg (op_end
+ 1, & reg
);
1093 /* Skip whitespace. */
1094 while (isspace (* op_end
))
1097 if (* op_end
== ',')
1099 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1101 /* Further restrict the immediate to a power of two. */
1102 if ((reg
& (reg
- 1)) == 0)
1107 as_bad (_("immediate is not a power of two"));
1110 /* Immediate values of 0 -> 6 translate to movi. */
1113 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1115 as_warn (_("translating mgeni to movi"));
1121 as_bad (_("second operand missing"));
1123 output
= frag_more (2);
1126 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1129 op_end
= parse_reg (op_end
+ 1, & reg
);
1132 /* Skip whitespace. */
1133 while (isspace (* op_end
))
1136 if (* op_end
== ',')
1138 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1140 /* Immediate values of 1 -> 7 translate to movi. */
1143 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1144 reg
= (0x1 << reg
) - 1;
1147 as_warn (_("translating bmaski to movi"));
1152 inst
|= (reg
& 0x1F) << 4;
1156 as_bad (_("second operand missing"));
1158 output
= frag_more (2);
1162 op_end
= parse_reg (op_end
+ 1, & reg
);
1165 /* Skip whitespace. */
1166 while (isspace (* op_end
))
1169 if (* op_end
== ',')
1171 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1175 as_bad (_("second operand missing"));
1177 output
= frag_more (2);
1181 op_end
= parse_reg (op_end
+ 1, & reg
);
1184 /* Skip whitespace. */
1185 while (isspace (* op_end
))
1188 if (* op_end
== ',')
1190 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1194 as_bad (_("second operand missing"));
1196 output
= frag_more (2);
1200 op_end
= parse_reg (op_end
+ 1, & reg
);
1203 /* Skip whitespace. */
1204 while (isspace (* op_end
))
1207 if (* op_end
== ',')
1211 if ((inst
& 0x6000) == 0)
1213 else if ((inst
& 0x6000) == 0x4000)
1215 else if ((inst
& 0x6000) == 0x2000)
1218 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1221 as_bad (_("displacement too large (%d)"), off
);
1223 inst
|= (reg
) | (off
<< 4);
1226 as_bad (_("second operand missing"));
1228 output
= frag_more (2);
1232 op_end
= parse_reg (op_end
+ 1, & reg
);
1234 if (reg
== 0 || reg
== 15)
1235 as_bad (_("Invalid register: r0 and r15 illegal"));
1239 /* Skip whitespace. */
1240 while (isspace (* op_end
))
1243 if (* op_end
== ',')
1244 /* parse_rt calls frag_more() for us. */
1245 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1248 as_bad (_("second operand missing"));
1249 output
= frag_more (2); /* save its space */
1254 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1255 /* parse_rt() calls frag_more() for us. */
1259 op_end
= parse_reg (op_end
+ 1, & reg
);
1261 if (reg
== 0 || reg
== 15)
1262 as_bad (_("bad starting register: r0 and r15 invalid"));
1266 /* Skip whitespace. */
1267 while (isspace (* op_end
))
1270 if (* op_end
== '-')
1272 op_end
= parse_reg (op_end
+ 1, & reg
);
1275 as_bad (_("ending register must be r15"));
1277 /* Skip whitespace. */
1278 while (isspace (* op_end
))
1282 if (* op_end
== ',')
1286 /* Skip whitespace. */
1287 while (isspace (* op_end
))
1290 if (* op_end
== '(')
1292 op_end
= parse_reg (op_end
+ 1, & reg
);
1295 as_bad (_("bad base register: must be r0"));
1297 if (* op_end
== ')')
1301 as_bad (_("base register expected"));
1304 as_bad (_("second operand missing"));
1306 output
= frag_more (2);
1310 op_end
= parse_reg (op_end
+ 1, & reg
);
1313 as_fatal (_("first register must be r4"));
1315 /* Skip whitespace. */
1316 while (isspace (* op_end
))
1319 if (* op_end
== '-')
1321 op_end
= parse_reg (op_end
+ 1, & reg
);
1324 as_fatal (_("last register must be r7"));
1326 /* Skip whitespace. */
1327 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
);
1342 if (reg
>= 4 && reg
<= 7)
1343 as_fatal ("base register cannot be r4, r5, r6, or r7");
1347 /* Skip whitespace. */
1348 while (isspace (* op_end
))
1351 if (* op_end
== ')')
1355 as_bad (_("base register expected"));
1358 as_bad (_("second operand missing"));
1361 as_bad (_("reg-reg expected"));
1363 output
= frag_more (2);
1367 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1369 output
= frag_more (2);
1371 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1372 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1376 op_end
= parse_reg (op_end
+ 1, & reg
);
1379 /* Skip whitespace. */
1380 while (isspace (* op_end
))
1383 if (* op_end
== ',')
1385 op_end
= parse_exp (op_end
+ 1, & e
);
1386 output
= frag_more (2);
1388 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1389 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1393 as_bad (_("second operand missing"));
1394 output
= frag_more (2);
1399 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1401 output
= frag_var (rs_machine_dependent
,
1402 md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
,
1403 md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
,
1404 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1409 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1410 output
= frag_var (rs_machine_dependent
,
1411 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
1412 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
1413 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1418 inst
= MCORE_INST_JSRI
; /* jsri */
1419 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1420 /* parse_rt() calls frag_more for us */
1422 /* Only do this if we know how to do it ... */
1423 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1425 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1426 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1427 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1431 case RSI
: /* SI, but imm becomes 32-imm */
1432 op_end
= parse_reg (op_end
+ 1, & reg
);
1435 /* Skip whitespace. */
1436 while (isspace (* op_end
))
1439 if (* op_end
== ',')
1441 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1447 as_bad (_("second operand missing"));
1449 output
= frag_more (2);
1452 case DO21
: /* O2, dup rd, lit must be 1 */
1453 op_end
= parse_reg (op_end
+ 1, & reg
);
1457 /* Skip whitespace. */
1458 while (isspace (* op_end
))
1461 if (* op_end
== ',')
1463 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1466 as_bad (_("second operand must be 1"));
1469 as_bad (_("second operand missing"));
1471 output
= frag_more (2);
1475 op_end
= parse_reg (op_end
+ 1, & reg
);
1478 /* Skip whitespace. */
1479 while (isspace (* op_end
))
1482 if (* op_end
== ',')
1484 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1487 as_bad (_("zero used as immediate value"));
1492 as_bad (_("second operand missing"));
1494 output
= frag_more (2);
1498 as_bad (_("unimplemented opcode \"%s\""), name
);
1501 output
[0] = INST_BYTE0 (inst
);
1502 output
[1] = INST_BYTE1 (inst
);
1504 check_literals (opcode
->transfer
, isize
);
1508 md_undefined_symbol (name
)
1518 subseg_set (text_section
, 0);
1521 /* Various routines to kill one day. */
1522 /* Equal to MAX_PRECISION in atof-ieee.c */
1523 #define MAX_LITTLENUMS 6
1525 /* Turn a string in input_line_pointer into a floating point constant of type
1526 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1527 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1529 md_atof (type
, litP
, sizeP
)
1535 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1538 char * atof_ieee ();
1568 return _("Bad call to MD_NTOF()");
1571 t
= atof_ieee (input_line_pointer
, type
, words
);
1574 input_line_pointer
= t
;
1576 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1578 for (i
= 0; i
< prec
; i
++)
1580 md_number_to_chars (litP
, (valueT
) words
[i
],
1581 sizeof (LITTLENUM_TYPE
));
1582 litP
+= sizeof (LITTLENUM_TYPE
);
1588 CONST
char * md_shortopts
= "";
1590 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1591 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1592 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1593 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1595 struct option md_longopts
[] =
1597 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1598 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1599 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1600 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1601 { NULL
, no_argument
, NULL
, 0}
1604 size_t md_longopts_size
= sizeof (md_longopts
);
1607 md_parse_option (c
, arg
)
1617 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1618 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1619 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1620 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1628 md_show_usage (stream
)
1631 fprintf (stream
, _("\
1632 MCORE specific options:\n\
1633 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1634 -{no-}sifilter {dis}able silicon filter behavior (def: dis)"));
1637 int md_short_jump_size
;
1640 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1645 symbolS
* to_symbol
;
1647 as_fatal (_("failed sanity check: short_jump"));
1651 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1656 symbolS
* to_symbol
;
1658 as_fatal (_("failed sanity check: long_jump"));
1661 /* Called after relaxing, change the frags so they know how big they are. */
1663 md_convert_frag (abfd
, sec
, fragP
)
1666 register fragS
* fragP
;
1668 unsigned char * buffer
;
1669 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1671 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1672 targ_addr
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
1674 switch (fragP
->fr_subtype
)
1676 case C (COND_JUMP
, COND12
):
1677 case C (UNCD_JUMP
, UNCD12
):
1679 /* Get the address of the end of the instruction */
1680 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1682 int disp
= targ_addr
- next_inst
;
1685 as_bad (_("odd displacement at %x"), next_inst
- 2);
1689 t0
= buffer
[0] & 0xF8;
1691 md_number_to_chars (buffer
, disp
, 2);
1693 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1701 case C (COND_JUMP
, COND32
):
1702 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1704 /* A conditional branch wont fit into 12 bits so:
1711 * if the b!cond is 4 byte aligned, the literal which would
1712 * go at x+4 will also be aligned.
1714 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1715 int needpad
= (first_inst
& 3);
1717 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1719 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1720 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1725 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1726 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1729 buffer
[4] = 0; /* alignment/pad */
1731 buffer
[6] = 0; /* space for 32 bit address */
1736 /* Make reloc for the long disp */
1737 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1738 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1740 fragP
->fr_fix
+= C32_LEN
;
1744 /* See comment below about this given gas' limitations for
1745 shrinking the fragment. '3' is the amount of code that
1746 we inserted here, but '4' is right for the space we reserved
1747 for this fragment. */
1749 buffer
[1] = 3; /* branch over jmpi, and ptr */
1750 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1753 buffer
[4] = 0; /* space for 32 bit address */
1758 /* Make reloc for the long disp. */
1759 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1760 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1761 fragP
->fr_fix
+= C32_LEN
;
1763 /* Frag is actually shorter (see the other side of this ifdef)
1764 but gas isn't prepared for that. We have to re-adjust
1765 the branch displacement so that it goes beyond the
1766 full length of the fragment, not just what we actually
1768 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1775 case C (UNCD_JUMP
, UNCD32
):
1776 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1778 /* An unconditional branch will not fit in 12 bits, make code which
1783 we need a pad if "first_inst" is 4 byte aligned.
1784 [because the natural literal place is x + 2] */
1785 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1786 int needpad
= !(first_inst
& 3);
1788 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1789 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1793 buffer
[1] = 1; /* jmpi offset of 1 since padded */
1794 buffer
[2] = 0; /* alignment */
1796 buffer
[4] = 0; /* space for 32 bit address */
1801 /* Make reloc for the long disp */
1802 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1803 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1805 fragP
->fr_fix
+= U32_LEN
;
1809 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
1810 buffer
[2] = 0; /* space for 32 bit address */
1815 /* Make reloc for the long disp */
1816 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1817 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1818 fragP
->fr_fix
+= U32_LEN
;
1830 /* Applies the desired value to the specified location.
1831 Also sets up addends for 'rela' type relocations. */
1833 md_apply_fix3 (fixP
, valp
, segment
)
1838 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1839 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1840 const char * symname
;
1841 /* Note: use offsetT because it is signed, valueT is unsigned. */
1842 offsetT val
= (offsetT
) * valp
;
1844 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1845 /* Save this for the addend in the relocation record. */
1846 fixP
->fx_addnumber
= val
;
1848 /* If the fix is relative to a symbol which is not defined, or not
1849 in the same segment as the fix, we cannot resolve it here. */
1850 if (fixP
->fx_addsy
!= NULL
1851 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
1852 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
1856 /* For ELF we can just return and let the reloc that will be generated
1857 take care of everything. For COFF we still have to insert 'val'
1858 into the insn since the addend field will be ignored. */
1865 switch (fixP
->fx_r_type
)
1867 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
1869 as_bad_where (file
, fixP
->fx_line
,
1870 _("odd distance branch (0x%x bytes)"), val
);
1872 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
1873 as_bad_where (file
, fixP
->fx_line
,
1874 _("pcrel for branch to %s too far (0x%x)"),
1876 buf
[0] |= ((val
>> 8) & 0x7);
1877 buf
[1] |= (val
& 0xff);
1880 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
1884 as_bad_where (file
, fixP
->fx_line
,
1885 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
1888 buf
[1] |= (val
& 0xff);
1891 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
1892 if ((val
< -32) || (val
> -2))
1893 as_bad_where (file
, fixP
->fx_line
,
1894 _("pcrel for loopt too far (0x%x)"), val
);
1896 buf
[1] |= (val
& 0xf);
1899 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
1900 /* Conditional linker map jsri to bsr. */
1901 /* If its a local target and close enough, fix it.
1902 NB: >= -2k for backwards bsr; < 2k for forwards... */
1903 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
1905 long nval
= (val
/ 2) & 0x7ff;
1906 nval
|= MCORE_INST_BSR
;
1908 /* REPLACE the instruction, don't just modify it. */
1909 buf
[0] = INST_BYTE0 (nval
);
1910 buf
[1] = INST_BYTE1 (nval
);
1916 case BFD_RELOC_MCORE_PCREL_32
:
1917 case BFD_RELOC_VTABLE_INHERIT
:
1918 case BFD_RELOC_VTABLE_ENTRY
:
1923 if (fixP
->fx_addsy
!= NULL
)
1925 /* If the fix is an absolute reloc based on a symbol's
1926 address, then it cannot be resolved until the final link. */
1933 if (fixP
->fx_size
== 4)
1935 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
1937 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
1941 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1946 return 0; /* Return value is ignored. */
1950 md_operand (expressionP
)
1951 expressionS
* expressionP
;
1953 /* Ignore leading hash symbol, if poresent. */
1954 if (* input_line_pointer
== '#')
1956 input_line_pointer
++;
1957 expression (expressionP
);
1961 int md_long_jump_size
;
1963 /* Called just before address relaxation, return the length
1964 by which a fragment must grow to reach it's destination. */
1966 md_estimate_size_before_relax (fragP
, segment_type
)
1967 register fragS
* fragP
;
1968 register segT segment_type
;
1970 switch (fragP
->fr_subtype
)
1972 case C (UNCD_JUMP
, UNDEF_DISP
):
1973 /* Used to be a branch to somewhere which was unknown. */
1974 if (!fragP
->fr_symbol
)
1976 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
1977 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
1979 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
1981 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
1982 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
1986 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
1987 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
1988 return md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
1995 case C (COND_JUMP
, UNDEF_DISP
):
1996 /* Used to be a branch to somewhere which was unknown. */
1997 if (fragP
->fr_symbol
1998 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2000 /* Got a symbol and it's defined in this segment, become byte
2001 sized - maybe it will fix up */
2002 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2003 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2005 else if (fragP
->fr_symbol
)
2007 /* Its got a segment, but its not ours, so it will always be long. */
2008 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2009 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2010 return md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2014 /* We know the abs value. */
2015 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2016 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2022 return fragP
->fr_var
;
2025 /* Put number into target byte order */
2027 md_number_to_chars (ptr
, use
, nbytes
)
2034 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2035 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2036 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2037 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2042 /* Round up a section size to the appropriate boundary. */
2044 md_section_align (segment
, size
)
2048 return size
; /* Byte alignment is fine */
2052 /* The location from which a PC relative jump should be calculated,
2053 given a PC relative reloc. */
2055 md_pcrel_from_section (fixp
, sec
)
2060 /* If the symbol is undefined or defined in another section
2061 we leave the add number alone for the linker to fix it later.
2062 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2063 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2064 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2065 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2068 assert (fixp
->fx_size
== 2); /* must be an insn */
2069 return fixp
->fx_size
;
2073 /* The case where we are going to resolve things... */
2074 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2077 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2078 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2081 tc_gen_reloc (section
, fixp
)
2086 bfd_reloc_code_real_type code
;
2089 switch (fixp
->fx_r_type
)
2091 /* These confuse the size/pcrel macro approach. */
2092 case BFD_RELOC_VTABLE_INHERIT
:
2093 case BFD_RELOC_VTABLE_ENTRY
:
2094 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2095 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2096 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2097 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2098 code
= fixp
->fx_r_type
;
2102 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2104 MAP (1, 0, BFD_RELOC_8
);
2105 MAP (2, 0, BFD_RELOC_16
);
2106 MAP (4, 0, BFD_RELOC_32
);
2107 MAP (1, 1, BFD_RELOC_8_PCREL
);
2108 MAP (2, 1, BFD_RELOC_16_PCREL
);
2109 MAP (4, 1, BFD_RELOC_32_PCREL
);
2111 code
= fixp
->fx_r_type
;
2112 as_bad (_("Can not do %d byte %srelocation"),
2114 fixp
->fx_pcrel
? _("pc-relative") : "");
2119 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2120 rel
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
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 */