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 void make_name
PARAMS ((char *, char *, int));
49 static int enter_literal
PARAMS ((expressionS
*, int));
50 static char * parse_rt
PARAMS ((char *, char **, int, expressionS
*));
51 static char * parse_imm
PARAMS ((char *, unsigned *, unsigned, unsigned));
52 static char * parse_mem
PARAMS ((char *, unsigned *, unsigned *, unsigned));
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));
64 /* Several places in this file insert raw instructions into the
65 object. They should use MCORE_INST_XXX macros to get the opcodes
66 and then use these two macros to crack the MCORE_INST value into
67 the appropriate byte values. */
68 #define INST_BYTE0(x) (((x) >> 8) & 0xFF)
69 #define INST_BYTE1(x) ((x) & 0xFF)
71 const char comment_chars
[] = "#/";
72 const char line_separator_chars
[] = ";";
73 const char line_comment_chars
[] = "#/";
75 const int md_reloc_size
= 8;
77 static int do_jsri2bsr
= 0; /* change here from 1 by Cruess 19 August 97 */
78 static int sifilter_mode
= 0;
80 const char EXP_CHARS
[] = "eE";
82 /* Chars that mean this number is a floating point constant */
85 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
87 #define C(what,length) (((what) << 2) + (length))
88 #define GET_WHAT(x) ((x >> 2))
90 /* These are the two types of relaxable instruction */
99 #define UNDEF_WORD_DISP 4
103 #define C32_LEN 10 /* allow for align */
105 #define U32_LEN 8 /* allow for align */
108 /* Initialize the relax table */
109 const relax_typeS md_relax_table
[] =
111 { 1, 1, 0, 0 }, /* 0: unused */
112 { 1, 1, 0, 0 }, /* 1: unused */
113 { 1, 1, 0, 0 }, /* 2: unused */
114 { 1, 1, 0, 0 }, /* 3: unused */
115 { 1, 1, 0, 0 }, /* 4: unused */
116 { 2048, -2046, C12_LEN
, C(COND_JUMP
, COND32
) }, /* 5: C(COND_JUMP, COND12) */
117 { 0, 0, C32_LEN
, 0 }, /* 6: C(COND_JUMP, COND32) */
118 { 1, 1, 0, 0 }, /* 7: unused */
119 { 1, 1, 0, 0 }, /* 8: unused */
120 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, UNCD32
) }, /* 9: C(UNCD_JUMP, UNCD12) */
121 { 0, 0, U32_LEN
, 0 }, /*10: C(UNCD_JUMP, UNCD32) */
122 { 1, 1, 0, 0 }, /*11: unused */
123 { 0, 0, 0, 0 } /*12: unused */
126 /* LITERAL POOL DATA STRUCTURES */
129 unsigned short refcnt
;
130 unsigned char ispcrel
;
131 unsigned char unused
;
135 #define MAX_POOL_SIZE (1024/4)
136 static struct literal litpool
[MAX_POOL_SIZE
];
137 static unsigned poolsize
;
138 static unsigned poolnumber
;
139 static unsigned long poolspan
;
141 /* SPANPANIC: the point at which we get too scared and force a dump
142 of the literal pool, and perhaps put a branch in place.
144 1024 span of lrw/jmpi/jsri insn (actually span+1)
145 -2 possible alignment at the insn.
146 -2 possible alignment to get the table aligned.
147 -2 an inserted branch around the table.
149 at 1018, we might be in trouble.
150 -- so we have to be smaller than 1018 and since we deal with 2-byte
151 instructions, the next good choice is 1016.
152 -- Note we have a test case that fails when we've got 1018 here. */
153 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding */
154 #define SPANCLOSE (900)
155 #define SPANEXIT (600)
156 static symbolS
* poolsym
; /* label for current pool */
157 static char poolname
[8];
158 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics */
160 /* This table describes all the machine specific pseudo-ops the assembler
161 has to support. The fields are:
162 Pseudo-op name without dot
163 Function to call to execute this pseudo-op
164 Integer arg to pass to the function */
165 const pseudo_typeS md_pseudo_table
[] =
167 { "export", s_globl
, 0 },
168 { "import", s_ignore
, 0 },
169 { "literals", mcore_s_literals
, 0 },
170 { "page", listing_eject
, 0 },
172 /* The following are to intercept the placement of data into the text
173 section (eg addresses for a switch table), so that the space they
174 occupy can be taken into account when deciding whether or not to
175 dump the current literal pool.
176 XXX - currently we do not cope with the .space and .dcb.d directives. */
177 { "ascii", mcore_stringer
, 0 },
178 { "asciz", mcore_stringer
, 1 },
179 { "byte", mcore_cons
, 1 },
180 { "dc", mcore_cons
, 2 },
181 { "dc.b", mcore_cons
, 1 },
182 { "dc.d", mcore_float_cons
, 'd'},
183 { "dc.l", mcore_cons
, 4 },
184 { "dc.s", mcore_float_cons
, 'f'},
185 { "dc.w", mcore_cons
, 2 },
186 { "dc.x", mcore_float_cons
, 'x'},
187 { "double", mcore_float_cons
, 'd'},
188 { "float", mcore_float_cons
, 'f'},
189 { "hword", mcore_cons
, 2 },
190 { "int", mcore_cons
, 4 },
191 { "long", mcore_cons
, 4 },
192 { "octa", mcore_cons
, 16 },
193 { "quad", mcore_cons
, 8 },
194 { "short", mcore_cons
, 2 },
195 { "single", mcore_float_cons
, 'f'},
196 { "string", mcore_stringer
, 1 },
197 { "word", mcore_cons
, 2 },
198 { "fill", mcore_fill
, 0 },
200 /* Allow for the effect of section changes. */
201 { "text", mcore_s_text
, 0 },
202 { "data", mcore_s_data
, 0 },
203 { "bss", mcore_s_bss
, 1 },
205 { "comm", mcore_s_comm
, 0 },
207 { "section", mcore_s_section
, 0 },
208 { "section.s", mcore_s_section
, 0 },
209 { "sect", mcore_s_section
, 0 },
210 { "sect.s", mcore_s_section
, 0 },
216 mcore_s_literals (ignore
)
220 demand_empty_rest_of_line ();
228 if (now_seg
== text_section
)
230 char * ptr
= input_line_pointer
;
233 /* Count the number of commas on the line. */
234 while (! is_end_of_line
[* ptr
])
235 commas
+= * ptr
++ == ',';
237 poolspan
+= nbytes
* commas
;
242 /* In theory we ought to call check_literals (2,0) here in case
243 we need to dump the literal table. We cannot do this however,
244 as the directives that we are intercepting may be being used
245 to build a switch table, and we must not interfere with its
246 contents. Instead we cross our fingers and pray... */
250 mcore_float_cons (float_type
)
253 if (now_seg
== text_section
)
255 char * ptr
= input_line_pointer
;
258 #ifdef REPEAT_CONS_EXPRESSIONS
259 #error REPEAT_CONS_EXPRESSIONS not handled
262 /* Count the number of commas on the line. */
263 while (! is_end_of_line
[* ptr
])
264 commas
+= * ptr
++ == ',';
266 /* We would like to compute "hex_float (float_type) * commas"
267 but hex_float is not exported from read.c */
268 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
269 poolspan
+= float_type
* commas
;
272 float_cons (float_type
);
274 /* See the comment in mcore_cons () about calling check_literals.
275 It is unlikely that a switch table will be constructed using
276 floating point values, but it is still likely that an indexed
277 table of floating point constants is being created by these
278 directives, so again we must not interfere with their placement. */
282 mcore_stringer (append_zero
)
285 if (now_seg
== text_section
)
287 char * ptr
= input_line_pointer
;
289 /* In theory we should compute how many bytes are going to
290 be occupied by the string(s) and add this to the poolspan.
291 To keep things simple however, we just add the number of
292 bytes left on the current line. This will be an over-
293 estimate, which is OK, and automatically allows for the
294 appending a zero byte, since the real string(s) is/are
295 required to be enclosed in double quotes. */
296 while (! is_end_of_line
[* ptr
])
299 poolspan
+= ptr
- input_line_pointer
;
302 stringer (append_zero
);
304 /* We call check_literals here in case a large number of strings are
305 being placed into the text section with a sequence of stringer
306 directives. In theory we could be upsetting something if these
307 strings are actually in an indexed table instead of referenced by
308 individual labels. Let us hope that that never happens. */
309 check_literals (2, 0);
316 if (now_seg
== text_section
)
318 char * str
= input_line_pointer
;
324 /* Look to see if a size has been specified. */
325 while (*str
!= '\n' && *str
!= 0 && *str
!= ',')
330 size
= atoi (str
+ 1);
338 poolspan
+= size
* repeat
;
343 check_literals (2, 0);
346 /* Handle the section changing pseudo-ops. These call through to the
347 normal implementations, but they dump the literal pool first. */
350 mcore_s_text (ignore
)
356 obj_elf_text (ignore
);
363 mcore_s_data (ignore
)
369 obj_elf_data (ignore
);
376 mcore_s_section (ignore
)
379 /* Scan forwards to find the name of the section. If the section
380 being switched to is ".line" then this is a DWARF1 debug section
381 which is arbitarily placed inside generated code. In this case
382 do not dump the literal pool because it is a) inefficient and
383 b) would require the generation of extra code to jump around the
385 char * ilp
= input_line_pointer
;
387 while (*ilp
!= 0 && isspace(*ilp
))
390 if (strncmp (ilp
, ".line", 5) == 0
391 && (isspace (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
397 obj_elf_section (ignore
);
400 obj_coff_section (ignore
);
405 mcore_s_bss (needs_align
)
410 s_lcomm_bytes (needs_align
);
415 mcore_s_comm (needs_align
)
420 obj_elf_common (needs_align
);
424 /* This function is called once, at assembler startup time. This should
425 set up all the tables, etc that the MD part of the assembler needs. */
429 mcore_opcode_info
* opcode
;
430 char * prev_name
= "";
432 opcode_hash_control
= hash_new ();
434 /* Insert unique names into hash table */
435 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
437 if (streq (prev_name
, opcode
->name
))
439 /* Make all the opcodes with the same name point to the same
441 opcode
->name
= prev_name
;
445 prev_name
= opcode
->name
;
446 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
453 static expressionS immediate
; /* absolute expression */
455 /* Get a log2(val). */
470 /* Try to parse a reg name. */
476 /* Strip leading whitespace. */
477 while (isspace (* s
))
480 if (tolower (s
[0]) == 'r')
482 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
484 *reg
= 10 + s
[2] - '0';
488 if (s
[1] >= '0' && s
[1] <= '9')
494 else if ( tolower (s
[0]) == 's'
495 && tolower (s
[1]) == 'p'
502 as_bad (_("register expected, but saw '%.6s'"), s
);
536 /* Strip leading whitespace. */
537 while (isspace (* s
))
540 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
542 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
544 *reg
= 30 + s
[3] - '0';
548 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
550 *reg
= 20 + s
[3] - '0';
554 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
556 *reg
= 10 + s
[3] - '0';
560 if (s
[2] >= '0' && s
[2] <= '9')
567 /* Look at alternate creg names before giving error. */
568 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
574 length
= strlen (cregs
[i
].name
);
576 for (j
= 0; j
< length
; j
++)
577 buf
[j
] = tolower (s
[j
]);
579 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
581 *reg
= cregs
[i
].crnum
;
586 as_bad (_("control register expected, but saw '%.6s'"), s
);
599 /* Skip whitespace. */
600 while (isspace (* s
))
603 save
= input_line_pointer
;
604 input_line_pointer
= s
;
608 if (e
->X_op
== O_absent
)
609 as_bad (_("missing operand"));
611 new = input_line_pointer
;
612 input_line_pointer
= save
;
623 static const char hex
[] = "0123456789ABCDEF";
628 s
[3] = hex
[(n
>> 12) & 0xF];
629 s
[4] = hex
[(n
>> 8) & 0xF];
630 s
[5] = hex
[(n
>> 4) & 0xF];
631 s
[6] = hex
[(n
) & 0xF];
635 #define POOL_END_LABEL ".LE"
636 #define POOL_START_LABEL ".LS"
639 dump_literals (isforce
)
649 /* Must we branch around the literal table? */
655 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
657 brarsym
= symbol_make (brarname
);
659 symbol_table_insert (brarsym
);
661 output
= frag_var (rs_machine_dependent
,
662 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
663 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
664 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
665 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
666 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
669 /* Make sure that the section is sufficiently aligned and that
670 the literal table is aligned within it. */
671 record_alignment (now_seg
, 2);
672 frag_align (2, 0, 0);
674 colon (S_GET_NAME (poolsym
));
676 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
677 emit_expr (& p
->e
, 4);
680 colon (S_GET_NAME (brarsym
));
686 check_literals (kind
, offset
)
692 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
693 SPANPANIC means that we must dump now.
694 kind == 0 is any old instruction.
695 kind > 0 means we just had a control transfer instruction.
696 kind == 1 means within a function
697 kind == 2 means we just left a function
699 The dump_literals (1) call inserts a branch around the table, so
700 we first look to see if its a situation where we won't have to
701 insert a branch (e.g., the previous instruction was an unconditional
704 SPANPANIC is the point where we must dump a single-entry pool.
705 it accounts for alignments and an inserted branch.
706 the 'poolsize*2' accounts for the scenario where we do:
707 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
708 Note that the 'lit2' reference is 2 bytes further along
709 but the literal it references will be 4 bytes further along,
710 so we must consider the poolsize into this equation.
711 This is slightly over-cautious, but guarantees that we won't
712 panic because a relocation is too distant. */
714 if (poolspan
> SPANCLOSE
&& kind
> 0)
716 else if (poolspan
> SPANEXIT
&& kind
> 1)
718 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
723 enter_literal (e
, ispcrel
)
730 if (poolsize
>= MAX_POOL_SIZE
- 2)
732 /* The literal pool is as full as we can handle. We have
733 to be 2 entries shy of the 1024/4=256 entries because we
734 have to allow for the branch (2 bytes) and the alignment
735 (2 bytes before the first insn referencing the pool and
736 2 bytes before the pool itself) == 6 bytes, rounds up
743 /* Create new literal pool. */
744 if (++ poolnumber
> 0xFFFF)
745 as_fatal (_("more than 65K literal pools"));
747 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
748 poolsym
= symbol_make (poolname
);
749 symbol_table_insert (poolsym
);
753 /* Search pool for value so we don't have duplicates. */
754 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
756 if (e
->X_op
== p
->e
.X_op
757 && e
->X_add_symbol
== p
->e
.X_add_symbol
758 && e
->X_add_number
== p
->e
.X_add_number
759 && ispcrel
== p
->ispcrel
)
767 p
->ispcrel
= ispcrel
;
775 /* Parse a literal specification. -- either new or old syntax.
776 old syntax: the user supplies the label and places the literal.
777 new syntax: we put it into the literal pool. */
779 parse_rt (s
, outputp
, ispcrel
, ep
)
789 /* Indicate nothing there. */
794 s
= parse_exp (s
+ 1, & e
);
799 as_bad (_("missing ']'"));
803 s
= parse_exp (s
, & e
);
805 n
= enter_literal (& e
, ispcrel
);
810 /* Create a reference to pool entry. */
812 e
.X_add_symbol
= poolsym
;
813 e
.X_add_number
= n
<< 2;
816 * outputp
= frag_more (2);
818 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
819 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
825 parse_imm (s
, val
, min
, max
)
834 new = parse_exp (s
, & e
);
836 if (e
.X_op
== O_absent
)
837 ; /* An error message has already been emitted. */
838 else if (e
.X_op
!= O_constant
)
839 as_bad (_("operand must be a constant"));
840 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
841 as_bad (_("operand must be absolute in range %d..%d, not %d"),
842 min
, max
, e
.X_add_number
);
844 * val
= e
.X_add_number
;
850 parse_mem (s
, reg
, off
, siz
)
860 while (isspace (* s
))
865 s
= parse_reg (s
+ 1, reg
);
867 while (isspace (* s
))
872 s
= parse_imm (s
+ 1, off
, 0, 63);
879 as_bad (_("operand must be a multiple of 4"));
886 as_bad (_("operand must be a multiple of 2"));
893 while (isspace (* s
))
900 as_bad (_("base register expected"));
905 /* This is the guts of the machine-dependent assembler. STR points to a
906 machine dependent instruction. This function is supposed to emit
907 the frags/bytes it assembles to. */
915 mcore_opcode_info
* opcode
;
925 /* Drop leading whitespace. */
926 while (isspace (* str
))
929 /* Find the op code end. */
930 for (op_start
= op_end
= str
;
931 * op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
934 name
[nlen
] = op_start
[nlen
];
942 as_bad (_("can't find opcode "));
946 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
949 as_bad (_("unknown opcode \"%s\""), name
);
956 switch (opcode
->opclass
)
959 output
= frag_more (2);
963 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
965 output
= frag_more (2);
969 op_end
= parse_reg (op_end
+ 1, & reg
);
971 output
= frag_more (2);
975 op_end
= parse_reg (op_end
+ 1, & reg
);
977 output
= frag_more (2);
978 /* In a sifilter mode, we emit this insn 2 times,
979 fixes problem of an interrupt during a jmp.. */
982 output
[0] = INST_BYTE0 (inst
);
983 output
[1] = INST_BYTE1 (inst
);
984 output
= frag_more (2);
989 op_end
= parse_reg (op_end
+ 1, & reg
);
992 as_bad (_("invalid register: r15 illegal"));
995 output
= frag_more (2);
999 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
1000 inst
= MCORE_INST_BSR
; /* with 0 displacement */
1001 output
[0] = INST_BYTE0 (inst
);
1002 output
[1] = INST_BYTE1 (inst
);
1004 output
= frag_more (2);
1005 inst
= MCORE_INST_ADDI
;
1006 inst
|= 15; /* addi r15,6 */
1007 inst
|= (6 - 1) << 4; /* over the jmp's */
1008 output
[0] = INST_BYTE0 (inst
);
1009 output
[1] = INST_BYTE1 (inst
);
1011 output
= frag_more (2);
1012 inst
= MCORE_INST_JMP
| reg
;
1013 output
[0] = INST_BYTE0 (inst
);
1014 output
[1] = INST_BYTE1 (inst
);
1016 output
= frag_more (2); /* 2nd emitted in fallthru */
1021 op_end
= parse_reg (op_end
+ 1, & reg
);
1024 /* Skip whitespace. */
1025 while (isspace (* op_end
))
1030 op_end
= parse_creg (op_end
+ 1, & reg
);
1034 output
= frag_more (2);
1038 op_end
= parse_reg (op_end
+ 1, & reg
);
1041 /* Skip whitespace. */
1042 while (isspace (* op_end
))
1045 if (* op_end
== ',')
1047 op_end
= parse_reg (op_end
+ 1, & reg
);
1051 as_bad (_("second operand missing"));
1053 output
= frag_more (2);
1056 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1057 op_end
= parse_reg (op_end
+ 1, & reg
);
1059 /* Skip whitespace. */
1060 while (isspace (* op_end
))
1063 if (* op_end
== ',') /* xtrb- r1,rx */
1066 as_bad (_("destination register must be r1"));
1068 op_end
= parse_reg (op_end
+ 1, & reg
);
1072 output
= frag_more (2);
1075 case O1R1
: /* div- rx,r1 */
1076 op_end
= parse_reg (op_end
+ 1, & reg
);
1079 /* Skip whitespace. */
1080 while (isspace (* op_end
))
1083 if (* op_end
== ',')
1085 op_end
= parse_reg (op_end
+ 1, & reg
);
1087 as_bad (_("source register must be r1"));
1090 as_bad (_("second operand missing"));
1092 output
= frag_more (2);
1096 op_end
= parse_reg (op_end
+ 1, & reg
);
1099 /* Skip whitespace. */
1100 while (isspace (* op_end
))
1103 if (* op_end
== ',')
1105 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1106 inst
|= (reg
- 1) << 4;
1109 as_bad (_("second operand missing"));
1111 output
= frag_more (2);
1115 op_end
= parse_reg (op_end
+ 1, & reg
);
1118 /* Skip whitespace. */
1119 while (isspace (* op_end
))
1122 if (* op_end
== ',')
1124 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1128 as_bad (_("second operand missing"));
1130 output
= frag_more (2);
1133 case OB2
: /* like OB, but arg is 2^n instead of n */
1134 op_end
= parse_reg (op_end
+ 1, & reg
);
1137 /* Skip whitespace. */
1138 while (isspace (* op_end
))
1141 if (* op_end
== ',')
1143 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1144 /* Further restrict the immediate to a power of two. */
1145 if ((reg
& (reg
- 1)) == 0)
1150 as_bad (_("immediate is not a power of two"));
1155 as_bad (_("second operand missing"));
1157 output
= frag_more (2);
1160 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1163 op_end
= parse_reg (op_end
+ 1, & reg
);
1166 /* Skip whitespace. */
1167 while (isspace (* op_end
))
1170 if (* op_end
== ',')
1172 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1173 /* immediate values of 0 -> 6 translate to movi */
1176 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1178 as_warn (_("translating bgeni to movi"));
1184 as_bad (_("second operand missing"));
1186 output
= frag_more (2);
1189 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1190 op_end
= parse_reg (op_end
+ 1, & reg
);
1193 /* Skip whitespace. */
1194 while (isspace (* op_end
))
1197 if (* op_end
== ',')
1199 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1201 /* Further restrict the immediate to a power of two. */
1202 if ((reg
& (reg
- 1)) == 0)
1207 as_bad (_("immediate is not a power of two"));
1210 /* Immediate values of 0 -> 6 translate to movi. */
1213 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1215 as_warn (_("translating mgeni to movi"));
1221 as_bad (_("second operand missing"));
1223 output
= frag_more (2);
1226 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1229 op_end
= parse_reg (op_end
+ 1, & reg
);
1232 /* Skip whitespace. */
1233 while (isspace (* op_end
))
1236 if (* op_end
== ',')
1238 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1240 /* Immediate values of 1 -> 7 translate to movi. */
1243 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1244 reg
= (0x1 << reg
) - 1;
1247 as_warn (_("translating bmaski to movi"));
1252 inst
|= (reg
& 0x1F) << 4;
1256 as_bad (_("second operand missing"));
1258 output
= frag_more (2);
1262 op_end
= parse_reg (op_end
+ 1, & reg
);
1265 /* Skip whitespace. */
1266 while (isspace (* op_end
))
1269 if (* op_end
== ',')
1271 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1275 as_bad (_("second operand missing"));
1277 output
= frag_more (2);
1281 op_end
= parse_reg (op_end
+ 1, & reg
);
1284 /* Skip whitespace. */
1285 while (isspace (* op_end
))
1288 if (* op_end
== ',')
1290 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1294 as_bad (_("second operand missing"));
1296 output
= frag_more (2);
1300 op_end
= parse_reg (op_end
+ 1, & reg
);
1303 /* Skip whitespace. */
1304 while (isspace (* op_end
))
1307 if (* op_end
== ',')
1311 if ((inst
& 0x6000) == 0)
1313 else if ((inst
& 0x6000) == 0x4000)
1315 else if ((inst
& 0x6000) == 0x2000)
1318 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1321 as_bad (_("displacement too large (%d)"), off
);
1323 inst
|= (reg
) | (off
<< 4);
1326 as_bad (_("second operand missing"));
1328 output
= frag_more (2);
1332 op_end
= parse_reg (op_end
+ 1, & reg
);
1334 if (reg
== 0 || reg
== 15)
1335 as_bad (_("Invalid register: r0 and r15 illegal"));
1339 /* Skip whitespace. */
1340 while (isspace (* op_end
))
1343 if (* op_end
== ',')
1344 /* parse_rt calls frag_more() for us. */
1345 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1348 as_bad (_("second operand missing"));
1349 output
= frag_more (2); /* save its space */
1354 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1355 /* parse_rt() calls frag_more() for us. */
1359 op_end
= parse_reg (op_end
+ 1, & reg
);
1361 if (reg
== 0 || reg
== 15)
1362 as_bad (_("bad starting register: r0 and r15 invalid"));
1366 /* Skip whitespace. */
1367 while (isspace (* op_end
))
1370 if (* op_end
== '-')
1372 op_end
= parse_reg (op_end
+ 1, & reg
);
1375 as_bad (_("ending register must be r15"));
1377 /* Skip whitespace. */
1378 while (isspace (* op_end
))
1382 if (* op_end
== ',')
1386 /* Skip whitespace. */
1387 while (isspace (* op_end
))
1390 if (* op_end
== '(')
1392 op_end
= parse_reg (op_end
+ 1, & reg
);
1395 as_bad (_("bad base register: must be r0"));
1397 if (* op_end
== ')')
1401 as_bad (_("base register expected"));
1404 as_bad (_("second operand missing"));
1406 output
= frag_more (2);
1410 op_end
= parse_reg (op_end
+ 1, & reg
);
1413 as_fatal (_("first register must be r4"));
1415 /* Skip whitespace. */
1416 while (isspace (* op_end
))
1419 if (* op_end
== '-')
1421 op_end
= parse_reg (op_end
+ 1, & reg
);
1424 as_fatal (_("last register must be r7"));
1426 /* Skip whitespace. */
1427 while (isspace (* op_end
))
1430 if (* op_end
== ',')
1434 /* Skip whitespace. */
1435 while (isspace (* op_end
))
1438 if (* op_end
== '(')
1440 op_end
= parse_reg (op_end
+ 1, & reg
);
1442 if (reg
>= 4 && reg
<= 7)
1443 as_fatal ("base register cannot be r4, r5, r6, or r7");
1447 /* Skip whitespace. */
1448 while (isspace (* op_end
))
1451 if (* op_end
== ')')
1455 as_bad (_("base register expected"));
1458 as_bad (_("second operand missing"));
1461 as_bad (_("reg-reg expected"));
1463 output
= frag_more (2);
1467 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1469 output
= frag_more (2);
1471 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1472 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1476 op_end
= parse_reg (op_end
+ 1, & reg
);
1479 /* Skip whitespace. */
1480 while (isspace (* op_end
))
1483 if (* op_end
== ',')
1485 op_end
= parse_exp (op_end
+ 1, & e
);
1486 output
= frag_more (2);
1488 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1489 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1493 as_bad (_("second operand missing"));
1494 output
= frag_more (2);
1499 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1501 output
= frag_var (rs_machine_dependent
,
1502 md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
,
1503 md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
,
1504 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1509 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1510 output
= frag_var (rs_machine_dependent
,
1511 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
1512 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
1513 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1518 inst
= MCORE_INST_JSRI
; /* jsri */
1519 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1520 /* parse_rt() calls frag_more for us. */
1522 /* Only do this if we know how to do it ... */
1523 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1525 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1526 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1527 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1531 case RSI
: /* SI, but imm becomes 32-imm */
1532 op_end
= parse_reg (op_end
+ 1, & reg
);
1535 /* Skip whitespace. */
1536 while (isspace (* op_end
))
1539 if (* op_end
== ',')
1541 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1547 as_bad (_("second operand missing"));
1549 output
= frag_more (2);
1552 case DO21
: /* O2, dup rd, lit must be 1 */
1553 op_end
= parse_reg (op_end
+ 1, & reg
);
1557 /* Skip whitespace. */
1558 while (isspace (* op_end
))
1561 if (* op_end
== ',')
1563 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1566 as_bad (_("second operand must be 1"));
1569 as_bad (_("second operand missing"));
1571 output
= frag_more (2);
1575 op_end
= parse_reg (op_end
+ 1, & reg
);
1578 /* Skip whitespace. */
1579 while (isspace (* op_end
))
1582 if (* op_end
== ',')
1584 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1587 as_bad (_("zero used as immediate value"));
1592 as_bad (_("second operand missing"));
1594 output
= frag_more (2);
1598 as_bad (_("unimplemented opcode \"%s\""), name
);
1601 output
[0] = INST_BYTE0 (inst
);
1602 output
[1] = INST_BYTE1 (inst
);
1604 check_literals (opcode
->transfer
, isize
);
1608 md_undefined_symbol (name
)
1618 subseg_set (text_section
, 0);
1621 /* Various routines to kill one day. */
1622 /* Equal to MAX_PRECISION in atof-ieee.c */
1623 #define MAX_LITTLENUMS 6
1625 /* Turn a string in input_line_pointer into a floating point constant of type
1626 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1627 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1629 md_atof (type
, litP
, sizeP
)
1635 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1638 char * atof_ieee ();
1668 return _("Bad call to MD_NTOF()");
1671 t
= atof_ieee (input_line_pointer
, type
, words
);
1674 input_line_pointer
= t
;
1676 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1678 for (i
= 0; i
< prec
; i
++)
1680 md_number_to_chars (litP
, (valueT
) words
[i
],
1681 sizeof (LITTLENUM_TYPE
));
1682 litP
+= sizeof (LITTLENUM_TYPE
);
1688 CONST
char * md_shortopts
= "";
1690 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1691 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1692 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1693 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1695 struct option md_longopts
[] =
1697 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1698 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1699 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1700 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1701 { NULL
, no_argument
, NULL
, 0}
1704 size_t md_longopts_size
= sizeof (md_longopts
);
1707 md_parse_option (c
, arg
)
1717 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1718 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1719 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1720 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1728 md_show_usage (stream
)
1731 fprintf (stream
, _("\
1732 MCORE specific options:\n\
1733 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1734 -{no-}sifilter {dis}able silicon filter behavior (def: dis)"));
1737 int md_short_jump_size
;
1740 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1745 symbolS
* to_symbol
;
1747 as_fatal (_("failed sanity check: short_jump"));
1751 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1756 symbolS
* to_symbol
;
1758 as_fatal (_("failed sanity check: long_jump"));
1761 /* Called after relaxing, change the frags so they know how big they are. */
1763 md_convert_frag (abfd
, sec
, fragP
)
1766 register fragS
* fragP
;
1768 unsigned char * buffer
;
1769 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1771 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1772 targ_addr
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
1774 switch (fragP
->fr_subtype
)
1776 case C (COND_JUMP
, COND12
):
1777 case C (UNCD_JUMP
, UNCD12
):
1779 /* Get the address of the end of the instruction. */
1780 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1782 int disp
= targ_addr
- next_inst
;
1785 as_bad (_("odd displacement at %x"), next_inst
- 2);
1789 t0
= buffer
[0] & 0xF8;
1791 md_number_to_chars (buffer
, disp
, 2);
1793 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1801 case C (COND_JUMP
, COND32
):
1802 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1804 /* A conditional branch wont fit into 12 bits so:
1811 * if the b!cond is 4 byte aligned, the literal which would
1812 * go at x+4 will also be aligned.
1814 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1815 int needpad
= (first_inst
& 3);
1817 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1819 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1820 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1825 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1826 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1829 buffer
[4] = 0; /* alignment/pad */
1831 buffer
[6] = 0; /* space for 32 bit address */
1836 /* Make reloc for the long disp */
1837 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1838 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1840 fragP
->fr_fix
+= C32_LEN
;
1844 /* See comment below about this given gas' limitations for
1845 shrinking the fragment. '3' is the amount of code that
1846 we inserted here, but '4' is right for the space we reserved
1847 for this fragment. */
1849 buffer
[1] = 3; /* branch over jmpi, and ptr */
1850 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1853 buffer
[4] = 0; /* space for 32 bit address */
1858 /* Make reloc for the long disp. */
1859 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1860 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1861 fragP
->fr_fix
+= C32_LEN
;
1863 /* Frag is actually shorter (see the other side of this ifdef)
1864 but gas isn't prepared for that. We have to re-adjust
1865 the branch displacement so that it goes beyond the
1866 full length of the fragment, not just what we actually
1868 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1875 case C (UNCD_JUMP
, UNCD32
):
1876 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1878 /* An unconditional branch will not fit in 12 bits, make code which
1883 we need a pad if "first_inst" is 4 byte aligned.
1884 [because the natural literal place is x + 2] */
1885 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1886 int needpad
= !(first_inst
& 3);
1888 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1889 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1893 buffer
[1] = 1; /* jmpi offset of 1 since padded */
1894 buffer
[2] = 0; /* alignment */
1896 buffer
[4] = 0; /* space for 32 bit address */
1901 /* Make reloc for the long disp. */
1902 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1903 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1905 fragP
->fr_fix
+= U32_LEN
;
1909 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
1910 buffer
[2] = 0; /* space for 32 bit address */
1915 /* Make reloc for the long disp. */
1916 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1917 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1918 fragP
->fr_fix
+= U32_LEN
;
1930 /* Applies the desired value to the specified location.
1931 Also sets up addends for 'rela' type relocations. */
1933 md_apply_fix3 (fixP
, valp
, segment
)
1938 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1939 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
1940 const char * symname
;
1941 /* Note: use offsetT because it is signed, valueT is unsigned. */
1942 offsetT val
= (offsetT
) * valp
;
1944 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
1945 /* Save this for the addend in the relocation record. */
1946 fixP
->fx_addnumber
= val
;
1948 /* If the fix is relative to a symbol which is not defined, or not
1949 in the same segment as the fix, we cannot resolve it here. */
1950 if (fixP
->fx_addsy
!= NULL
1951 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
1952 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
1956 /* For ELF we can just return and let the reloc that will be generated
1957 take care of everything. For COFF we still have to insert 'val'
1958 into the insn since the addend field will be ignored. */
1965 switch (fixP
->fx_r_type
)
1967 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
1969 as_bad_where (file
, fixP
->fx_line
,
1970 _("odd distance branch (0x%x bytes)"), val
);
1972 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
1973 as_bad_where (file
, fixP
->fx_line
,
1974 _("pcrel for branch to %s too far (0x%x)"),
1976 buf
[0] |= ((val
>> 8) & 0x7);
1977 buf
[1] |= (val
& 0xff);
1980 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
1984 as_bad_where (file
, fixP
->fx_line
,
1985 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
1988 buf
[1] |= (val
& 0xff);
1991 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
1992 if ((val
< -32) || (val
> -2))
1993 as_bad_where (file
, fixP
->fx_line
,
1994 _("pcrel for loopt too far (0x%x)"), val
);
1996 buf
[1] |= (val
& 0xf);
1999 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2000 /* Conditional linker map jsri to bsr. */
2001 /* If its a local target and close enough, fix it.
2002 NB: >= -2k for backwards bsr; < 2k for forwards... */
2003 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2005 long nval
= (val
/ 2) & 0x7ff;
2006 nval
|= MCORE_INST_BSR
;
2008 /* REPLACE the instruction, don't just modify it. */
2009 buf
[0] = INST_BYTE0 (nval
);
2010 buf
[1] = INST_BYTE1 (nval
);
2016 case BFD_RELOC_MCORE_PCREL_32
:
2017 case BFD_RELOC_VTABLE_INHERIT
:
2018 case BFD_RELOC_VTABLE_ENTRY
:
2023 if (fixP
->fx_addsy
!= NULL
)
2025 /* If the fix is an absolute reloc based on a symbol's
2026 address, then it cannot be resolved until the final link. */
2033 if (fixP
->fx_size
== 4)
2035 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2037 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2041 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2046 return 0; /* Return value is ignored. */
2050 md_operand (expressionP
)
2051 expressionS
* expressionP
;
2053 /* Ignore leading hash symbol, if poresent. */
2054 if (* input_line_pointer
== '#')
2056 input_line_pointer
++;
2057 expression (expressionP
);
2061 int md_long_jump_size
;
2063 /* Called just before address relaxation, return the length
2064 by which a fragment must grow to reach it's destination. */
2066 md_estimate_size_before_relax (fragP
, segment_type
)
2067 register fragS
* fragP
;
2068 register segT segment_type
;
2070 switch (fragP
->fr_subtype
)
2072 case C (UNCD_JUMP
, UNDEF_DISP
):
2073 /* Used to be a branch to somewhere which was unknown. */
2074 if (!fragP
->fr_symbol
)
2076 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2077 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2079 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2081 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2082 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2086 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2087 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2088 return md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2095 case C (COND_JUMP
, UNDEF_DISP
):
2096 /* Used to be a branch to somewhere which was unknown. */
2097 if (fragP
->fr_symbol
2098 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2100 /* Got a symbol and it's defined in this segment, become byte
2101 sized - maybe it will fix up */
2102 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2103 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2105 else if (fragP
->fr_symbol
)
2107 /* Its got a segment, but its not ours, so it will always be long. */
2108 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2109 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2110 return md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2114 /* We know the abs value. */
2115 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2116 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2122 return fragP
->fr_var
;
2125 /* Put number into target byte order. */
2127 md_number_to_chars (ptr
, use
, nbytes
)
2134 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2135 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2136 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2137 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2142 /* Round up a section size to the appropriate boundary. */
2144 md_section_align (segment
, size
)
2148 return size
; /* Byte alignment is fine */
2152 /* The location from which a PC relative jump should be calculated,
2153 given a PC relative reloc. */
2155 md_pcrel_from_section (fixp
, sec
)
2160 /* If the symbol is undefined or defined in another section
2161 we leave the add number alone for the linker to fix it later.
2162 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2163 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2164 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2165 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2168 assert (fixp
->fx_size
== 2); /* must be an insn */
2169 return fixp
->fx_size
;
2173 /* The case where we are going to resolve things... */
2174 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2177 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2178 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2181 tc_gen_reloc (section
, fixp
)
2186 bfd_reloc_code_real_type code
;
2189 switch (fixp
->fx_r_type
)
2191 /* These confuse the size/pcrel macro approach. */
2192 case BFD_RELOC_VTABLE_INHERIT
:
2193 case BFD_RELOC_VTABLE_ENTRY
:
2194 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2195 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2196 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2197 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2198 code
= fixp
->fx_r_type
;
2202 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2204 MAP (1, 0, BFD_RELOC_8
);
2205 MAP (2, 0, BFD_RELOC_16
);
2206 MAP (4, 0, BFD_RELOC_32
);
2207 MAP (1, 1, BFD_RELOC_8_PCREL
);
2208 MAP (2, 1, BFD_RELOC_16_PCREL
);
2209 MAP (4, 1, BFD_RELOC_32_PCREL
);
2211 code
= fixp
->fx_r_type
;
2212 as_bad (_("Can not do %d byte %srelocation"),
2214 fixp
->fx_pcrel
? _("pc-relative") : "");
2219 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2220 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2221 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2222 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2223 /* Always pass the addend along! */
2224 rel
->addend
= fixp
->fx_addnumber
;
2226 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2228 if (rel
->howto
== NULL
)
2230 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2231 _("Cannot represent relocation type %s"),
2232 bfd_get_reloc_code_name (code
));
2234 /* Set howto to a garbage value so that we can keep going. */
2235 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2236 assert (rel
->howto
!= NULL
);
2243 /* See whether we need to force a relocation into the output file.
2244 This is used to force out switch and PC relative relocations when
2247 mcore_force_relocation (fix
)
2250 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2251 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2257 /* Return true if the fix can be handled by GAS, false if it must
2258 be passed through to the linker. */
2260 mcore_fix_adjustable (fixP
)
2263 if (fixP
->fx_addsy
== NULL
)
2266 /* We need the symbol name for the VTABLE entries. */
2267 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2268 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2273 #endif /* OBJ_ELF */