1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright (C) 1999 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "../opcodes/mcore-opc.h"
31 #include "elf/mcore.h"
35 #define streq(a,b) (strcmp (a, b) == 0)
38 /* Forward declarations for dumb compilers. */
39 static void mcore_s_literals
PARAMS ((int));
40 static void mcore_cons
PARAMS ((int));
41 static void mcore_float_cons
PARAMS ((int));
42 static void mcore_stringer
PARAMS ((int));
43 static void mcore_fill
PARAMS ((int));
44 static int log2
PARAMS ((unsigned int));
45 static char * parse_reg
PARAMS ((char *, unsigned *));
46 static char * parse_creg
PARAMS ((char *, unsigned *));
47 static char * parse_exp
PARAMS ((char *, expressionS
*));
48 static char * parse_rt
PARAMS ((char *, char **, int, expressionS
*));
49 static char * parse_imm
PARAMS ((char *, unsigned *, unsigned, unsigned));
50 static char * parse_mem
PARAMS ((char *, unsigned *, unsigned *, unsigned));
51 static char * parse_psrmod
PARAMS ((char *, unsigned *));
52 static void make_name
PARAMS ((char *, char *, int));
53 static int enter_literal
PARAMS ((expressionS
*, int));
54 static void dump_literals
PARAMS ((int));
55 static void check_literals
PARAMS ((int, int));
56 static void mcore_s_text
PARAMS ((int));
57 static void mcore_s_data
PARAMS ((int));
58 static void mcore_s_section
PARAMS ((int));
59 static void mcore_s_bss
PARAMS ((int));
61 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
;
340 check_literals (1, 0);
345 check_literals (1, 0);
348 /* Handle the section changing pseudo-ops. These call through to the
349 normal implementations, but they dump the literal pool first. */
351 mcore_s_text (ignore
)
357 obj_elf_text (ignore
);
364 mcore_s_data (ignore
)
370 obj_elf_data (ignore
);
377 mcore_s_section (ignore
)
380 /* Scan forwards to find the name of the section. If the section
381 being switched to is ".line" then this is a DWARF1 debug section
382 which is arbitarily placed inside generated code. In this case
383 do not dump the literal pool because it is a) inefficient and
384 b) would require the generation of extra code to jump around the
386 char * ilp
= input_line_pointer
;
388 while (*ilp
!= 0 && isspace(*ilp
))
391 if (strncmp (ilp
, ".line", 5) == 0
392 && (isspace (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
398 obj_elf_section (ignore
);
401 obj_coff_section (ignore
);
406 mcore_s_bss (needs_align
)
411 s_lcomm_bytes (needs_align
);
416 mcore_s_comm (needs_align
)
421 obj_elf_common (needs_align
);
425 /* This function is called once, at assembler startup time. This should
426 set up all the tables, etc that the MD part of the assembler needs. */
430 mcore_opcode_info
* opcode
;
431 char * prev_name
= "";
433 opcode_hash_control
= hash_new ();
435 /* Insert unique names into hash table */
436 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
438 if (streq (prev_name
, opcode
->name
))
440 /* Make all the opcodes with the same name point to the same
442 opcode
->name
= prev_name
;
446 prev_name
= opcode
->name
;
447 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
454 static expressionS immediate
; /* absolute expression */
456 /* Get a log2(val). */
471 /* Try to parse a reg name. */
477 /* Strip leading whitespace. */
478 while (isspace (* s
))
481 if (tolower (s
[0]) == 'r')
483 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
485 *reg
= 10 + s
[2] - '0';
489 if (s
[1] >= '0' && s
[1] <= '9')
495 else if ( tolower (s
[0]) == 's'
496 && tolower (s
[1]) == 'p'
503 as_bad (_("register expected, but saw '%.6s'"), s
);
537 /* Strip leading whitespace. */
538 while (isspace (* s
))
541 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
543 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
545 *reg
= 30 + s
[3] - '0';
549 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
551 *reg
= 20 + s
[3] - '0';
555 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
557 *reg
= 10 + s
[3] - '0';
561 if (s
[2] >= '0' && s
[2] <= '9')
568 /* Look at alternate creg names before giving error. */
569 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
575 length
= strlen (cregs
[i
].name
);
577 for (j
= 0; j
< length
; j
++)
578 buf
[j
] = tolower (s
[j
]);
580 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
582 *reg
= cregs
[i
].crnum
;
587 as_bad (_("control register expected, but saw '%.6s'"), s
);
593 parse_psrmod (s
, reg
)
599 static struct psrmods
609 { "af", 8 } /* really 0 and non-combinable */
612 for (i
= 0; i
< 2; i
++)
613 buf
[i
] = isascii (s
[i
]) ? tolower (s
[i
]) : 0;
615 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
617 if (! strncmp (psrmods
[i
].name
, buf
, 2))
619 * reg
= psrmods
[i
].value
;
625 as_bad (_("bad/missing psr specifier"));
640 /* Skip whitespace. */
641 while (isspace (* s
))
644 save
= input_line_pointer
;
645 input_line_pointer
= s
;
649 if (e
->X_op
== O_absent
)
650 as_bad (_("missing operand"));
652 new = input_line_pointer
;
653 input_line_pointer
= save
;
664 static const char hex
[] = "0123456789ABCDEF";
669 s
[3] = hex
[(n
>> 12) & 0xF];
670 s
[4] = hex
[(n
>> 8) & 0xF];
671 s
[5] = hex
[(n
>> 4) & 0xF];
672 s
[6] = hex
[(n
) & 0xF];
676 #define POOL_END_LABEL ".LE"
677 #define POOL_START_LABEL ".LS"
680 dump_literals (isforce
)
690 /* Must we branch around the literal table? */
696 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
698 brarsym
= symbol_make (brarname
);
700 symbol_table_insert (brarsym
);
702 output
= frag_var (rs_machine_dependent
,
703 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
704 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
705 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
706 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
707 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
710 /* Make sure that the section is sufficiently aligned and that
711 the literal table is aligned within it. */
712 record_alignment (now_seg
, 2);
713 frag_align (2, 0, 0);
715 colon (S_GET_NAME (poolsym
));
717 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
718 emit_expr (& p
->e
, 4);
721 colon (S_GET_NAME (brarsym
));
727 check_literals (kind
, offset
)
733 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
734 SPANPANIC means that we must dump now.
735 kind == 0 is any old instruction.
736 kind > 0 means we just had a control transfer instruction.
737 kind == 1 means within a function
738 kind == 2 means we just left a function
740 The dump_literals (1) call inserts a branch around the table, so
741 we first look to see if its a situation where we won't have to
742 insert a branch (e.g., the previous instruction was an unconditional
745 SPANPANIC is the point where we must dump a single-entry pool.
746 it accounts for alignments and an inserted branch.
747 the 'poolsize*2' accounts for the scenario where we do:
748 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
749 Note that the 'lit2' reference is 2 bytes further along
750 but the literal it references will be 4 bytes further along,
751 so we must consider the poolsize into this equation.
752 This is slightly over-cautious, but guarantees that we won't
753 panic because a relocation is too distant. */
755 if (poolspan
> SPANCLOSE
&& kind
> 0)
757 else if (/* poolspan > SPANEXIT &&*/ kind
> 1)
759 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
764 enter_literal (e
, ispcrel
)
771 if (poolsize
>= MAX_POOL_SIZE
- 2)
773 /* The literal pool is as full as we can handle. We have
774 to be 2 entries shy of the 1024/4=256 entries because we
775 have to allow for the branch (2 bytes) and the alignment
776 (2 bytes before the first insn referencing the pool and
777 2 bytes before the pool itself) == 6 bytes, rounds up
784 /* Create new literal pool. */
785 if (++ poolnumber
> 0xFFFF)
786 as_fatal (_("more than 65K literal pools"));
788 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
789 poolsym
= symbol_make (poolname
);
790 symbol_table_insert (poolsym
);
794 /* Search pool for value so we don't have duplicates. */
795 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
797 if (e
->X_op
== p
->e
.X_op
798 && e
->X_add_symbol
== p
->e
.X_add_symbol
799 && e
->X_add_number
== p
->e
.X_add_number
800 && ispcrel
== p
->ispcrel
)
808 p
->ispcrel
= ispcrel
;
816 /* Parse a literal specification. -- either new or old syntax.
817 old syntax: the user supplies the label and places the literal.
818 new syntax: we put it into the literal pool. */
820 parse_rt (s
, outputp
, ispcrel
, ep
)
830 /* Indicate nothing there. */
835 s
= parse_exp (s
+ 1, & e
);
840 as_bad (_("missing ']'"));
844 s
= parse_exp (s
, & e
);
846 n
= enter_literal (& e
, ispcrel
);
851 /* Create a reference to pool entry. */
853 e
.X_add_symbol
= poolsym
;
854 e
.X_add_number
= n
<< 2;
857 * outputp
= frag_more (2);
859 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
860 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
866 parse_imm (s
, val
, min
, max
)
875 new = parse_exp (s
, & e
);
877 if (e
.X_op
== O_absent
)
878 ; /* An error message has already been emitted. */
879 else if (e
.X_op
!= O_constant
)
880 as_bad (_("operand must be a constant"));
881 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
882 as_bad (_("operand must be absolute in range %d..%d, not %d"),
883 min
, max
, e
.X_add_number
);
885 * val
= e
.X_add_number
;
891 parse_mem (s
, reg
, off
, siz
)
901 while (isspace (* s
))
906 s
= parse_reg (s
+ 1, reg
);
908 while (isspace (* s
))
913 s
= parse_imm (s
+ 1, off
, 0, 63);
920 as_bad (_("operand must be a multiple of 4"));
927 as_bad (_("operand must be a multiple of 2"));
934 while (isspace (* s
))
941 as_bad (_("base register expected"));
946 /* This is the guts of the machine-dependent assembler. STR points to a
947 machine dependent instruction. This function is supposed to emit
948 the frags/bytes it assembles to. */
956 mcore_opcode_info
* opcode
;
966 /* Drop leading whitespace. */
967 while (isspace (* str
))
970 /* Find the op code end. */
971 for (op_start
= op_end
= str
;
972 * op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
975 name
[nlen
] = op_start
[nlen
];
983 as_bad (_("can't find opcode "));
987 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
990 as_bad (_("unknown opcode \"%s\""), name
);
997 switch (opcode
->opclass
)
1000 output
= frag_more (2);
1004 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
1006 output
= frag_more (2);
1010 op_end
= parse_reg (op_end
+ 1, & reg
);
1012 output
= frag_more (2);
1016 op_end
= parse_reg (op_end
+ 1, & reg
);
1018 output
= frag_more (2);
1019 /* In a sifilter mode, we emit this insn 2 times,
1020 fixes problem of an interrupt during a jmp.. */
1023 output
[0] = INST_BYTE0 (inst
);
1024 output
[1] = INST_BYTE1 (inst
);
1025 output
= frag_more (2);
1030 op_end
= parse_reg (op_end
+ 1, & reg
);
1033 as_bad (_("invalid register: r15 illegal"));
1036 output
= frag_more (2);
1040 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
1041 inst
= MCORE_INST_BSR
; /* with 0 displacement */
1042 output
[0] = INST_BYTE0 (inst
);
1043 output
[1] = INST_BYTE1 (inst
);
1045 output
= frag_more (2);
1046 inst
= MCORE_INST_ADDI
;
1047 inst
|= 15; /* addi r15,6 */
1048 inst
|= (6 - 1) << 4; /* over the jmp's */
1049 output
[0] = INST_BYTE0 (inst
);
1050 output
[1] = INST_BYTE1 (inst
);
1052 output
= frag_more (2);
1053 inst
= MCORE_INST_JMP
| reg
;
1054 output
[0] = INST_BYTE0 (inst
);
1055 output
[1] = INST_BYTE1 (inst
);
1057 output
= frag_more (2); /* 2nd emitted in fallthru */
1062 op_end
= parse_reg (op_end
+ 1, & reg
);
1065 /* Skip whitespace. */
1066 while (isspace (* op_end
))
1071 op_end
= parse_creg (op_end
+ 1, & reg
);
1075 output
= frag_more (2);
1079 op_end
= parse_reg (op_end
+ 1, & reg
);
1082 /* Skip whitespace. */
1083 while (isspace (* op_end
))
1086 if (* op_end
== ',')
1088 op_end
= parse_reg (op_end
+ 1, & reg
);
1092 as_bad (_("second operand missing"));
1094 output
= frag_more (2);
1097 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1098 op_end
= parse_reg (op_end
+ 1, & reg
);
1100 /* Skip whitespace. */
1101 while (isspace (* op_end
))
1104 if (* op_end
== ',') /* xtrb- r1,rx */
1107 as_bad (_("destination register must be r1"));
1109 op_end
= parse_reg (op_end
+ 1, & reg
);
1113 output
= frag_more (2);
1116 case O1R1
: /* div- rx,r1 */
1117 op_end
= parse_reg (op_end
+ 1, & reg
);
1120 /* Skip whitespace. */
1121 while (isspace (* op_end
))
1124 if (* op_end
== ',')
1126 op_end
= parse_reg (op_end
+ 1, & reg
);
1128 as_bad (_("source register must be r1"));
1131 as_bad (_("second operand missing"));
1133 output
= frag_more (2);
1137 op_end
= parse_reg (op_end
+ 1, & reg
);
1140 /* Skip whitespace. */
1141 while (isspace (* op_end
))
1144 if (* op_end
== ',')
1146 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1147 inst
|= (reg
- 1) << 4;
1150 as_bad (_("second operand missing"));
1152 output
= frag_more (2);
1156 op_end
= parse_reg (op_end
+ 1, & reg
);
1159 /* Skip whitespace. */
1160 while (isspace (* op_end
))
1163 if (* op_end
== ',')
1165 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1169 as_bad (_("second operand missing"));
1171 output
= frag_more (2);
1174 case OB2
: /* like OB, but arg is 2^n instead of n */
1175 op_end
= parse_reg (op_end
+ 1, & reg
);
1178 /* Skip whitespace. */
1179 while (isspace (* op_end
))
1182 if (* op_end
== ',')
1184 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1185 /* Further restrict the immediate to a power of two. */
1186 if ((reg
& (reg
- 1)) == 0)
1191 as_bad (_("immediate is not a power of two"));
1196 as_bad (_("second operand missing"));
1198 output
= frag_more (2);
1201 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1204 op_end
= parse_reg (op_end
+ 1, & reg
);
1207 /* Skip whitespace. */
1208 while (isspace (* op_end
))
1211 if (* op_end
== ',')
1213 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1214 /* immediate values of 0 -> 6 translate to movi */
1217 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1219 as_warn (_("translating bgeni to movi"));
1225 as_bad (_("second operand missing"));
1227 output
= frag_more (2);
1230 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1231 op_end
= parse_reg (op_end
+ 1, & reg
);
1234 /* Skip whitespace. */
1235 while (isspace (* op_end
))
1238 if (* op_end
== ',')
1240 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1242 /* Further restrict the immediate to a power of two. */
1243 if ((reg
& (reg
- 1)) == 0)
1248 as_bad (_("immediate is not a power of two"));
1251 /* Immediate values of 0 -> 6 translate to movi. */
1254 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1256 as_warn (_("translating mgeni to movi"));
1262 as_bad (_("second operand missing"));
1264 output
= frag_more (2);
1267 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1270 op_end
= parse_reg (op_end
+ 1, & reg
);
1273 /* Skip whitespace. */
1274 while (isspace (* op_end
))
1277 if (* op_end
== ',')
1279 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1281 /* Immediate values of 1 -> 7 translate to movi. */
1284 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1285 reg
= (0x1 << reg
) - 1;
1288 as_warn (_("translating bmaski to movi"));
1293 inst
|= (reg
& 0x1F) << 4;
1297 as_bad (_("second operand missing"));
1299 output
= frag_more (2);
1303 op_end
= parse_reg (op_end
+ 1, & reg
);
1306 /* Skip whitespace. */
1307 while (isspace (* op_end
))
1310 if (* op_end
== ',')
1312 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1316 as_bad (_("second operand missing"));
1318 output
= frag_more (2);
1322 op_end
= parse_reg (op_end
+ 1, & reg
);
1325 /* Skip whitespace. */
1326 while (isspace (* op_end
))
1329 if (* op_end
== ',')
1331 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1335 as_bad (_("second operand missing"));
1337 output
= frag_more (2);
1341 op_end
= parse_reg (op_end
+ 1, & reg
);
1344 /* Skip whitespace. */
1345 while (isspace (* op_end
))
1348 if (* op_end
== ',')
1352 if ((inst
& 0x6000) == 0)
1354 else if ((inst
& 0x6000) == 0x4000)
1356 else if ((inst
& 0x6000) == 0x2000)
1359 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1362 as_bad (_("displacement too large (%d)"), off
);
1364 inst
|= (reg
) | (off
<< 4);
1367 as_bad (_("second operand missing"));
1369 output
= frag_more (2);
1373 op_end
= parse_reg (op_end
+ 1, & reg
);
1375 if (reg
== 0 || reg
== 15)
1376 as_bad (_("Invalid register: r0 and r15 illegal"));
1380 /* Skip whitespace. */
1381 while (isspace (* op_end
))
1384 if (* op_end
== ',')
1385 /* parse_rt calls frag_more() for us. */
1386 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1389 as_bad (_("second operand missing"));
1390 output
= frag_more (2); /* save its space */
1395 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1396 /* parse_rt() calls frag_more() for us. */
1400 op_end
= parse_reg (op_end
+ 1, & reg
);
1402 if (reg
== 0 || reg
== 15)
1403 as_bad (_("bad starting register: r0 and r15 invalid"));
1407 /* Skip whitespace. */
1408 while (isspace (* op_end
))
1411 if (* op_end
== '-')
1413 op_end
= parse_reg (op_end
+ 1, & reg
);
1416 as_bad (_("ending register must be r15"));
1418 /* Skip whitespace. */
1419 while (isspace (* op_end
))
1423 if (* op_end
== ',')
1427 /* Skip whitespace. */
1428 while (isspace (* op_end
))
1431 if (* op_end
== '(')
1433 op_end
= parse_reg (op_end
+ 1, & reg
);
1436 as_bad (_("bad base register: must be r0"));
1438 if (* op_end
== ')')
1442 as_bad (_("base register expected"));
1445 as_bad (_("second operand missing"));
1447 output
= frag_more (2);
1451 op_end
= parse_reg (op_end
+ 1, & reg
);
1454 as_fatal (_("first register must be r4"));
1456 /* Skip whitespace. */
1457 while (isspace (* op_end
))
1460 if (* op_end
== '-')
1462 op_end
= parse_reg (op_end
+ 1, & reg
);
1465 as_fatal (_("last register must be r7"));
1467 /* Skip whitespace. */
1468 while (isspace (* op_end
))
1471 if (* op_end
== ',')
1475 /* Skip whitespace. */
1476 while (isspace (* op_end
))
1479 if (* op_end
== '(')
1481 op_end
= parse_reg (op_end
+ 1, & reg
);
1483 if (reg
>= 4 && reg
<= 7)
1484 as_fatal ("base register cannot be r4, r5, r6, or r7");
1488 /* Skip whitespace. */
1489 while (isspace (* op_end
))
1492 if (* op_end
== ')')
1496 as_bad (_("base register expected"));
1499 as_bad (_("second operand missing"));
1502 as_bad (_("reg-reg expected"));
1504 output
= frag_more (2);
1508 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1510 output
= frag_more (2);
1512 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1513 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1517 op_end
= parse_reg (op_end
+ 1, & reg
);
1520 /* Skip whitespace. */
1521 while (isspace (* op_end
))
1524 if (* op_end
== ',')
1526 op_end
= parse_exp (op_end
+ 1, & e
);
1527 output
= frag_more (2);
1529 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1530 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1534 as_bad (_("second operand missing"));
1535 output
= frag_more (2);
1540 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1542 output
= frag_var (rs_machine_dependent
,
1543 md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
,
1544 md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
,
1545 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1550 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1551 output
= frag_var (rs_machine_dependent
,
1552 md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
,
1553 md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
,
1554 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1559 inst
= MCORE_INST_JSRI
; /* jsri */
1560 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1561 /* parse_rt() calls frag_more for us. */
1563 /* Only do this if we know how to do it ... */
1564 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1566 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1567 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1568 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1572 case RSI
: /* SI, but imm becomes 32-imm */
1573 op_end
= parse_reg (op_end
+ 1, & reg
);
1576 /* Skip whitespace. */
1577 while (isspace (* op_end
))
1580 if (* op_end
== ',')
1582 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1588 as_bad (_("second operand missing"));
1590 output
= frag_more (2);
1593 case DO21
: /* O2, dup rd, lit must be 1 */
1594 op_end
= parse_reg (op_end
+ 1, & reg
);
1598 /* Skip whitespace. */
1599 while (isspace (* op_end
))
1602 if (* op_end
== ',')
1604 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1607 as_bad (_("second operand must be 1"));
1610 as_bad (_("second operand missing"));
1612 output
= frag_more (2);
1616 op_end
= parse_reg (op_end
+ 1, & reg
);
1619 /* Skip whitespace. */
1620 while (isspace (* op_end
))
1623 if (* op_end
== ',')
1625 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1628 as_bad (_("zero used as immediate value"));
1633 as_bad (_("second operand missing"));
1635 output
= frag_more (2);
1639 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1641 /* Look for further selectors. */
1642 while (* op_end
== ',')
1646 op_end
= parse_psrmod (op_end
+ 1, & value
);
1649 as_bad (_("duplicated psr bit specifier"));
1655 as_bad (_("`af' must appear alone"));
1657 inst
|= (reg
& 0x7);
1658 output
= frag_more (2);
1662 as_bad (_("unimplemented opcode \"%s\""), name
);
1665 output
[0] = INST_BYTE0 (inst
);
1666 output
[1] = INST_BYTE1 (inst
);
1668 check_literals (opcode
->transfer
, isize
);
1672 md_undefined_symbol (name
)
1682 subseg_set (text_section
, 0);
1685 /* Various routines to kill one day. */
1686 /* Equal to MAX_PRECISION in atof-ieee.c */
1687 #define MAX_LITTLENUMS 6
1689 /* Turn a string in input_line_pointer into a floating point constant of type
1690 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1691 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1693 md_atof (type
, litP
, sizeP
)
1699 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1702 char * atof_ieee ();
1732 return _("Bad call to MD_NTOF()");
1735 t
= atof_ieee (input_line_pointer
, type
, words
);
1738 input_line_pointer
= t
;
1740 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1742 for (i
= 0; i
< prec
; i
++)
1744 md_number_to_chars (litP
, (valueT
) words
[i
],
1745 sizeof (LITTLENUM_TYPE
));
1746 litP
+= sizeof (LITTLENUM_TYPE
);
1752 CONST
char * md_shortopts
= "";
1754 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1755 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1756 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1757 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1759 struct option md_longopts
[] =
1761 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1762 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1763 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1764 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1765 { NULL
, no_argument
, NULL
, 0}
1768 size_t md_longopts_size
= sizeof (md_longopts
);
1771 md_parse_option (c
, arg
)
1781 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1782 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1783 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1784 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1792 md_show_usage (stream
)
1795 fprintf (stream
, _("\
1796 MCORE specific options:\n\
1797 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1798 -{no-}sifilter {dis}able silicon filter behavior (def: dis)"));
1801 int md_short_jump_size
;
1804 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1809 symbolS
* to_symbol
;
1811 as_fatal (_("failed sanity check: short_jump"));
1815 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1820 symbolS
* to_symbol
;
1822 as_fatal (_("failed sanity check: long_jump"));
1825 /* Called after relaxing, change the frags so they know how big they are. */
1827 md_convert_frag (abfd
, sec
, fragP
)
1830 register fragS
* fragP
;
1832 unsigned char * buffer
;
1833 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1835 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1836 targ_addr
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
1838 switch (fragP
->fr_subtype
)
1840 case C (COND_JUMP
, COND12
):
1841 case C (UNCD_JUMP
, UNCD12
):
1843 /* Get the address of the end of the instruction. */
1844 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1846 int disp
= targ_addr
- next_inst
;
1849 as_bad (_("odd displacement at %x"), next_inst
- 2);
1853 t0
= buffer
[0] & 0xF8;
1855 md_number_to_chars (buffer
, disp
, 2);
1857 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1865 case C (COND_JUMP
, COND32
):
1866 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1868 /* A conditional branch wont fit into 12 bits so:
1875 * if the b!cond is 4 byte aligned, the literal which would
1876 * go at x+4 will also be aligned.
1878 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1879 int needpad
= (first_inst
& 3);
1881 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1883 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1884 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1889 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1890 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1893 buffer
[4] = 0; /* alignment/pad */
1895 buffer
[6] = 0; /* space for 32 bit address */
1900 /* Make reloc for the long disp */
1901 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1902 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1904 fragP
->fr_fix
+= C32_LEN
;
1908 /* See comment below about this given gas' limitations for
1909 shrinking the fragment. '3' is the amount of code that
1910 we inserted here, but '4' is right for the space we reserved
1911 for this fragment. */
1913 buffer
[1] = 3; /* branch over jmpi, and ptr */
1914 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
1917 buffer
[4] = 0; /* space for 32 bit address */
1922 /* Make reloc for the long disp. */
1923 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1924 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1925 fragP
->fr_fix
+= C32_LEN
;
1927 /* Frag is actually shorter (see the other side of this ifdef)
1928 but gas isn't prepared for that. We have to re-adjust
1929 the branch displacement so that it goes beyond the
1930 full length of the fragment, not just what we actually
1932 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1939 case C (UNCD_JUMP
, UNCD32
):
1940 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
1942 /* An unconditional branch will not fit in 12 bits, make code which
1947 we need a pad if "first_inst" is 4 byte aligned.
1948 [because the natural literal place is x + 2] */
1949 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1950 int needpad
= !(first_inst
& 3);
1952 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1953 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
1957 buffer
[1] = 1; /* jmpi offset of 1 since padded */
1958 buffer
[2] = 0; /* alignment */
1960 buffer
[4] = 0; /* space for 32 bit address */
1965 /* Make reloc for the long disp. */
1966 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
1967 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1969 fragP
->fr_fix
+= U32_LEN
;
1973 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
1974 buffer
[2] = 0; /* space for 32 bit address */
1979 /* Make reloc for the long disp. */
1980 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
1981 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1982 fragP
->fr_fix
+= U32_LEN
;
1994 /* Applies the desired value to the specified location.
1995 Also sets up addends for 'rela' type relocations. */
1997 md_apply_fix3 (fixP
, valp
, segment
)
2002 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2003 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
2004 const char * symname
;
2005 /* Note: use offsetT because it is signed, valueT is unsigned. */
2006 offsetT val
= (offsetT
) * valp
;
2008 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
2009 /* Save this for the addend in the relocation record. */
2010 fixP
->fx_addnumber
= val
;
2012 /* If the fix is relative to a symbol which is not defined, or not
2013 in the same segment as the fix, we cannot resolve it here. */
2014 if (fixP
->fx_addsy
!= NULL
2015 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
2016 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
2020 /* For ELF we can just return and let the reloc that will be generated
2021 take care of everything. For COFF we still have to insert 'val'
2022 into the insn since the addend field will be ignored. */
2029 switch (fixP
->fx_r_type
)
2031 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
2033 as_bad_where (file
, fixP
->fx_line
,
2034 _("odd distance branch (0x%x bytes)"), val
);
2036 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2037 as_bad_where (file
, fixP
->fx_line
,
2038 _("pcrel for branch to %s too far (0x%x)"),
2040 buf
[0] |= ((val
>> 8) & 0x7);
2041 buf
[1] |= (val
& 0xff);
2044 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
2048 as_bad_where (file
, fixP
->fx_line
,
2049 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
2052 buf
[1] |= (val
& 0xff);
2055 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
2056 if ((val
< -32) || (val
> -2))
2057 as_bad_where (file
, fixP
->fx_line
,
2058 _("pcrel for loopt too far (0x%x)"), val
);
2060 buf
[1] |= (val
& 0xf);
2063 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2064 /* Conditional linker map jsri to bsr. */
2065 /* If its a local target and close enough, fix it.
2066 NB: >= -2k for backwards bsr; < 2k for forwards... */
2067 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2069 long nval
= (val
/ 2) & 0x7ff;
2070 nval
|= MCORE_INST_BSR
;
2072 /* REPLACE the instruction, don't just modify it. */
2073 buf
[0] = INST_BYTE0 (nval
);
2074 buf
[1] = INST_BYTE1 (nval
);
2080 case BFD_RELOC_MCORE_PCREL_32
:
2081 case BFD_RELOC_VTABLE_INHERIT
:
2082 case BFD_RELOC_VTABLE_ENTRY
:
2087 if (fixP
->fx_addsy
!= NULL
)
2089 /* If the fix is an absolute reloc based on a symbol's
2090 address, then it cannot be resolved until the final link. */
2097 if (fixP
->fx_size
== 4)
2099 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2101 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2105 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2110 return 0; /* Return value is ignored. */
2114 md_operand (expressionP
)
2115 expressionS
* expressionP
;
2117 /* Ignore leading hash symbol, if poresent. */
2118 if (* input_line_pointer
== '#')
2120 input_line_pointer
++;
2121 expression (expressionP
);
2125 int md_long_jump_size
;
2127 /* Called just before address relaxation, return the length
2128 by which a fragment must grow to reach it's destination. */
2130 md_estimate_size_before_relax (fragP
, segment_type
)
2131 register fragS
* fragP
;
2132 register segT segment_type
;
2134 switch (fragP
->fr_subtype
)
2136 case C (UNCD_JUMP
, UNDEF_DISP
):
2137 /* Used to be a branch to somewhere which was unknown. */
2138 if (!fragP
->fr_symbol
)
2140 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2141 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2143 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2145 fragP
->fr_subtype
= C (UNCD_JUMP
, UNCD12
);
2146 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD12
)].rlx_length
;
2150 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2151 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2152 return md_relax_table
[C (UNCD_JUMP
, UNCD32
)].rlx_length
;
2159 case C (COND_JUMP
, UNDEF_DISP
):
2160 /* Used to be a branch to somewhere which was unknown. */
2161 if (fragP
->fr_symbol
2162 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2164 /* Got a symbol and it's defined in this segment, become byte
2165 sized - maybe it will fix up */
2166 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2167 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2169 else if (fragP
->fr_symbol
)
2171 /* Its got a segment, but its not ours, so it will always be long. */
2172 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2173 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2174 return md_relax_table
[C (COND_JUMP
, COND32
)].rlx_length
;
2178 /* We know the abs value. */
2179 fragP
->fr_subtype
= C (COND_JUMP
, COND12
);
2180 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, COND12
)].rlx_length
;
2186 return fragP
->fr_var
;
2189 /* Put number into target byte order. */
2191 md_number_to_chars (ptr
, use
, nbytes
)
2198 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2199 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2200 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2201 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2206 /* Round up a section size to the appropriate boundary. */
2208 md_section_align (segment
, size
)
2212 return size
; /* Byte alignment is fine */
2216 /* The location from which a PC relative jump should be calculated,
2217 given a PC relative reloc. */
2219 md_pcrel_from_section (fixp
, sec
)
2224 /* If the symbol is undefined or defined in another section
2225 we leave the add number alone for the linker to fix it later.
2226 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2227 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2228 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2229 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2232 assert (fixp
->fx_size
== 2); /* must be an insn */
2233 return fixp
->fx_size
;
2237 /* The case where we are going to resolve things... */
2238 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2241 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2242 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2245 tc_gen_reloc (section
, fixp
)
2250 bfd_reloc_code_real_type code
;
2253 switch (fixp
->fx_r_type
)
2255 /* These confuse the size/pcrel macro approach. */
2256 case BFD_RELOC_VTABLE_INHERIT
:
2257 case BFD_RELOC_VTABLE_ENTRY
:
2258 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2259 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2260 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2261 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2262 code
= fixp
->fx_r_type
;
2266 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2268 MAP (1, 0, BFD_RELOC_8
);
2269 MAP (2, 0, BFD_RELOC_16
);
2270 MAP (4, 0, BFD_RELOC_32
);
2271 MAP (1, 1, BFD_RELOC_8_PCREL
);
2272 MAP (2, 1, BFD_RELOC_16_PCREL
);
2273 MAP (4, 1, BFD_RELOC_32_PCREL
);
2275 code
= fixp
->fx_r_type
;
2276 as_bad (_("Can not do %d byte %srelocation"),
2278 fixp
->fx_pcrel
? _("pc-relative") : "");
2283 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2284 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2285 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2286 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2287 /* Always pass the addend along! */
2288 rel
->addend
= fixp
->fx_addnumber
;
2290 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2292 if (rel
->howto
== NULL
)
2294 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2295 _("Cannot represent relocation type %s"),
2296 bfd_get_reloc_code_name (code
));
2298 /* Set howto to a garbage value so that we can keep going. */
2299 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2300 assert (rel
->howto
!= NULL
);
2307 /* See whether we need to force a relocation into the output file.
2308 This is used to force out switch and PC relative relocations when
2311 mcore_force_relocation (fix
)
2314 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2315 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2321 /* Return true if the fix can be handled by GAS, false if it must
2322 be passed through to the linker. */
2324 mcore_fix_adjustable (fixP
)
2327 if (fixP
->fx_addsy
== NULL
)
2330 /* We need the symbol name for the VTABLE entries. */
2331 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2332 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2337 #endif /* OBJ_ELF */