1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
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) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
69 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 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 */
97 #define UNDEF_WORD_DISP 3
100 #define C32_LEN 10 /* allow for align */
102 #define U32_LEN 8 /* allow for align */
113 /* Initialize the relax table. */
114 const relax_typeS md_relax_table
[] =
116 { 1, 1, 0, 0 }, /* 0: unused */
117 { 1, 1, 0, 0 }, /* 1: unused */
118 { 1, 1, 0, 0 }, /* 2: unused */
119 { 1, 1, 0, 0 }, /* 3: unused */
120 { 1, 1, 0, 0 }, /* 4: unused */
121 { 2048, -2046, C12_LEN
, C(COND_JUMP
, DISP32
) }, /* 5: C(COND_JUMP, DISP12) */
122 { 0, 0, C32_LEN
, 0 }, /* 6: C(COND_JUMP, DISP32) */
123 { 1, 1, 0, 0 }, /* 7: unused */
124 { 1, 1, 0, 0 }, /* 8: unused */
125 { 2048, -2046, U12_LEN
, C(UNCD_JUMP
, DISP32
) }, /* 9: C(UNCD_JUMP, DISP12) */
126 { 0, 0, U32_LEN
, 0 }, /*10: C(UNCD_JUMP, DISP32) */
127 { 1, 1, 0, 0 }, /*11: unused */
130 /* Literal pool data structures. */
133 unsigned short refcnt
;
134 unsigned char ispcrel
;
135 unsigned char unused
;
139 #define MAX_POOL_SIZE (1024/4)
140 static struct literal litpool
[MAX_POOL_SIZE
];
141 static unsigned poolsize
;
142 static unsigned poolnumber
;
143 static unsigned long poolspan
;
145 /* SPANPANIC: the point at which we get too scared and force a dump
146 of the literal pool, and perhaps put a branch in place.
148 1024 span of lrw/jmpi/jsri insn (actually span+1)
149 -2 possible alignment at the insn.
150 -2 possible alignment to get the table aligned.
151 -2 an inserted branch around the table.
153 at 1018, we might be in trouble.
154 -- so we have to be smaller than 1018 and since we deal with 2-byte
155 instructions, the next good choice is 1016.
156 -- Note we have a test case that fails when we've got 1018 here. */
157 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
158 #define SPANCLOSE (900)
159 #define SPANEXIT (600)
160 static symbolS
* poolsym
; /* label for current pool. */
161 static char poolname
[8];
162 static struct hash_control
* opcode_hash_control
; /* Opcode mnemonics. */
164 /* This table describes all the machine specific pseudo-ops the assembler
165 has to support. The fields are:
166 Pseudo-op name without dot
167 Function to call to execute this pseudo-op
168 Integer arg to pass to the function. */
169 const pseudo_typeS md_pseudo_table
[] =
171 { "export", s_globl
, 0 },
172 { "import", s_ignore
, 0 },
173 { "literals", mcore_s_literals
, 0 },
174 { "page", listing_eject
, 0 },
176 /* The following are to intercept the placement of data into the text
177 section (eg addresses for a switch table), so that the space they
178 occupy can be taken into account when deciding whether or not to
179 dump the current literal pool.
180 XXX - currently we do not cope with the .space and .dcb.d directives. */
181 { "ascii", mcore_stringer
, 0 },
182 { "asciz", mcore_stringer
, 1 },
183 { "byte", mcore_cons
, 1 },
184 { "dc", mcore_cons
, 2 },
185 { "dc.b", mcore_cons
, 1 },
186 { "dc.d", mcore_float_cons
, 'd'},
187 { "dc.l", mcore_cons
, 4 },
188 { "dc.s", mcore_float_cons
, 'f'},
189 { "dc.w", mcore_cons
, 2 },
190 { "dc.x", mcore_float_cons
, 'x'},
191 { "double", mcore_float_cons
, 'd'},
192 { "float", mcore_float_cons
, 'f'},
193 { "hword", mcore_cons
, 2 },
194 { "int", mcore_cons
, 4 },
195 { "long", mcore_cons
, 4 },
196 { "octa", mcore_cons
, 16 },
197 { "quad", mcore_cons
, 8 },
198 { "short", mcore_cons
, 2 },
199 { "single", mcore_float_cons
, 'f'},
200 { "string", mcore_stringer
, 1 },
201 { "word", mcore_cons
, 2 },
202 { "fill", mcore_fill
, 0 },
204 /* Allow for the effect of section changes. */
205 { "text", mcore_s_text
, 0 },
206 { "data", mcore_s_data
, 0 },
207 { "bss", mcore_s_bss
, 1 },
209 { "comm", mcore_s_comm
, 0 },
211 { "section", mcore_s_section
, 0 },
212 { "section.s", mcore_s_section
, 0 },
213 { "sect", mcore_s_section
, 0 },
214 { "sect.s", mcore_s_section
, 0 },
220 mcore_s_literals (ignore
)
224 demand_empty_rest_of_line ();
231 if (now_seg
== text_section
)
233 char * ptr
= input_line_pointer
;
236 /* Count the number of commas on the line. */
237 while (! is_end_of_line
[(unsigned char) * ptr
])
238 commas
+= * ptr
++ == ',';
240 poolspan
+= nbytes
* commas
;
245 /* In theory we ought to call check_literals (2,0) here in case
246 we need to dump the literal table. We cannot do this however,
247 as the directives that we are intercepting may be being used
248 to build a switch table, and we must not interfere with its
249 contents. Instead we cross our fingers and pray... */
253 mcore_float_cons (float_type
)
256 if (now_seg
== text_section
)
258 char * ptr
= input_line_pointer
;
261 #ifdef REPEAT_CONS_EXPRESSIONS
262 #error REPEAT_CONS_EXPRESSIONS not handled
265 /* Count the number of commas on the line. */
266 while (! is_end_of_line
[(unsigned char) * ptr
])
267 commas
+= * ptr
++ == ',';
269 /* We would like to compute "hex_float (float_type) * commas"
270 but hex_float is not exported from read.c */
271 float_type
== 'f' ? 4 : (float_type
== 'd' ? 8 : 12);
272 poolspan
+= float_type
* commas
;
275 float_cons (float_type
);
277 /* See the comment in mcore_cons () about calling check_literals.
278 It is unlikely that a switch table will be constructed using
279 floating point values, but it is still likely that an indexed
280 table of floating point constants is being created by these
281 directives, so again we must not interfere with their placement. */
285 mcore_stringer (append_zero
)
288 if (now_seg
== text_section
)
290 char * ptr
= input_line_pointer
;
292 /* In theory we should compute how many bytes are going to
293 be occupied by the string(s) and add this to the poolspan.
294 To keep things simple however, we just add the number of
295 bytes left on the current line. This will be an over-
296 estimate, which is OK, and automatically allows for the
297 appending a zero byte, since the real string(s) is/are
298 required to be enclosed in double quotes. */
299 while (! is_end_of_line
[(unsigned char) * ptr
])
302 poolspan
+= ptr
- input_line_pointer
;
305 stringer (append_zero
);
307 /* We call check_literals here in case a large number of strings are
308 being placed into the text section with a sequence of stringer
309 directives. In theory we could be upsetting something if these
310 strings are actually in an indexed table instead of referenced by
311 individual labels. Let us hope that that never happens. */
312 check_literals (2, 0);
319 if (now_seg
== text_section
)
321 char * str
= input_line_pointer
;
327 /* Look to see if a size has been specified. */
328 while (*str
!= '\n' && *str
!= 0 && *str
!= ',')
333 size
= atoi (str
+ 1);
341 poolspan
+= size
* repeat
;
346 check_literals (2, 0);
349 /* Handle the section changing pseudo-ops. These call through to the
350 normal implementations, but they dump the literal pool first. */
352 mcore_s_text (ignore
)
358 obj_elf_text (ignore
);
365 mcore_s_data (ignore
)
371 obj_elf_data (ignore
);
378 mcore_s_section (ignore
)
381 /* Scan forwards to find the name of the section. If the section
382 being switched to is ".line" then this is a DWARF1 debug section
383 which is arbitarily placed inside generated code. In this case
384 do not dump the literal pool because it is a) inefficient and
385 b) would require the generation of extra code to jump around the
387 char * ilp
= input_line_pointer
;
389 while (*ilp
!= 0 && isspace(*ilp
))
392 if (strncmp (ilp
, ".line", 5) == 0
393 && (isspace (ilp
[5]) || *ilp
== '\n' || *ilp
== '\r'))
399 obj_elf_section (ignore
);
402 obj_coff_section (ignore
);
407 mcore_s_bss (needs_align
)
412 s_lcomm_bytes (needs_align
);
417 mcore_s_comm (needs_align
)
422 obj_elf_common (needs_align
);
426 /* This function is called once, at assembler startup time. This should
427 set up all the tables, etc that the MD part of the assembler needs. */
431 mcore_opcode_info
* opcode
;
432 char * prev_name
= "";
434 opcode_hash_control
= hash_new ();
436 /* Insert unique names into hash table */
437 for (opcode
= mcore_table
; opcode
->name
; opcode
++)
439 if (streq (prev_name
, opcode
->name
))
441 /* Make all the opcodes with the same name point to the same
443 opcode
->name
= prev_name
;
447 prev_name
= opcode
->name
;
448 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
455 static expressionS immediate
; /* absolute expression */
457 /* Get a log2(val). */
472 /* Try to parse a reg name. */
478 /* Strip leading whitespace. */
479 while (isspace (* s
))
482 if (tolower (s
[0]) == 'r')
484 if (s
[1] == '1' && s
[2] >= '0' && s
[2] <= '5')
486 *reg
= 10 + s
[2] - '0';
490 if (s
[1] >= '0' && s
[1] <= '9')
496 else if ( tolower (s
[0]) == 's'
497 && tolower (s
[1]) == 'p'
504 as_bad (_("register expected, but saw '%.6s'"), s
);
538 /* Strip leading whitespace. */
539 while (isspace (* s
))
542 if ((tolower (s
[0]) == 'c' && tolower (s
[1]) == 'r'))
544 if (s
[2] == '3' && s
[3] >= '0' && s
[3] <= '1')
546 *reg
= 30 + s
[3] - '0';
550 if (s
[2] == '2' && s
[3] >= '0' && s
[3] <= '9')
552 *reg
= 20 + s
[3] - '0';
556 if (s
[2] == '1' && s
[3] >= '0' && s
[3] <= '9')
558 *reg
= 10 + s
[3] - '0';
562 if (s
[2] >= '0' && s
[2] <= '9')
569 /* Look at alternate creg names before giving error. */
570 for (i
= 0; cregs
[i
].name
[0] != '\0'; i
++)
576 length
= strlen (cregs
[i
].name
);
578 for (j
= 0; j
< length
; j
++)
579 buf
[j
] = tolower (s
[j
]);
581 if (strncmp (cregs
[i
].name
, buf
, length
) == 0)
583 *reg
= cregs
[i
].crnum
;
588 as_bad (_("control register expected, but saw '%.6s'"), s
);
594 parse_psrmod (s
, reg
)
600 static struct psrmods
610 { "af", 8 } /* Really 0 and non-combinable. */
613 for (i
= 0; i
< 2; i
++)
614 buf
[i
] = isascii (s
[i
]) ? tolower (s
[i
]) : 0;
616 for (i
= sizeof (psrmods
) / sizeof (psrmods
[0]); i
--;)
618 if (! strncmp (psrmods
[i
].name
, buf
, 2))
620 * reg
= psrmods
[i
].value
;
626 as_bad (_("bad/missing psr specifier"));
641 /* Skip whitespace. */
642 while (isspace (* s
))
645 save
= input_line_pointer
;
646 input_line_pointer
= s
;
650 if (e
->X_op
== O_absent
)
651 as_bad (_("missing operand"));
653 new = input_line_pointer
;
654 input_line_pointer
= save
;
665 static const char hex
[] = "0123456789ABCDEF";
670 s
[3] = hex
[(n
>> 12) & 0xF];
671 s
[4] = hex
[(n
>> 8) & 0xF];
672 s
[5] = hex
[(n
>> 4) & 0xF];
673 s
[6] = hex
[(n
) & 0xF];
677 #define POOL_END_LABEL ".LE"
678 #define POOL_START_LABEL ".LS"
681 dump_literals (isforce
)
691 /* Must we branch around the literal table? */
697 make_name (brarname
, POOL_END_LABEL
, poolnumber
);
699 brarsym
= symbol_make (brarname
);
701 symbol_table_insert (brarsym
);
703 output
= frag_var (rs_machine_dependent
,
704 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
705 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
706 C (UNCD_JUMP
, 0), brarsym
, 0, 0);
707 output
[0] = INST_BYTE0 (MCORE_INST_BR
); /* br .+xxx */
708 output
[1] = INST_BYTE1 (MCORE_INST_BR
);
711 /* Make sure that the section is sufficiently aligned and that
712 the literal table is aligned within it. */
713 record_alignment (now_seg
, 2);
714 frag_align (2, 0, 0);
716 colon (S_GET_NAME (poolsym
));
718 for (i
= 0, p
= litpool
; i
< poolsize
; i
++, p
++)
719 emit_expr (& p
->e
, 4);
722 colon (S_GET_NAME (brarsym
));
728 check_literals (kind
, offset
)
734 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
735 SPANPANIC means that we must dump now.
736 kind == 0 is any old instruction.
737 kind > 0 means we just had a control transfer instruction.
738 kind == 1 means within a function
739 kind == 2 means we just left a function
741 The dump_literals (1) call inserts a branch around the table, so
742 we first look to see if its a situation where we won't have to
743 insert a branch (e.g., the previous instruction was an unconditional
746 SPANPANIC is the point where we must dump a single-entry pool.
747 it accounts for alignments and an inserted branch.
748 the 'poolsize*2' accounts for the scenario where we do:
749 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
750 Note that the 'lit2' reference is 2 bytes further along
751 but the literal it references will be 4 bytes further along,
752 so we must consider the poolsize into this equation.
753 This is slightly over-cautious, but guarantees that we won't
754 panic because a relocation is too distant. */
756 if (poolspan
> SPANCLOSE
&& kind
> 0)
758 else if (poolspan
> SPANEXIT
&& kind
> 1)
760 else if (poolspan
>= (SPANPANIC
- poolsize
* 2))
765 enter_literal (e
, ispcrel
)
772 if (poolsize
>= MAX_POOL_SIZE
- 2)
774 /* The literal pool is as full as we can handle. We have
775 to be 2 entries shy of the 1024/4=256 entries because we
776 have to allow for the branch (2 bytes) and the alignment
777 (2 bytes before the first insn referencing the pool and
778 2 bytes before the pool itself) == 6 bytes, rounds up
785 /* Create new literal pool. */
786 if (++ poolnumber
> 0xFFFF)
787 as_fatal (_("more than 65K literal pools"));
789 make_name (poolname
, POOL_START_LABEL
, poolnumber
);
790 poolsym
= symbol_make (poolname
);
791 symbol_table_insert (poolsym
);
795 /* Search pool for value so we don't have duplicates. */
796 for (p
= litpool
, i
= 0; i
< poolsize
; i
++, p
++)
798 if (e
->X_op
== p
->e
.X_op
799 && e
->X_add_symbol
== p
->e
.X_add_symbol
800 && e
->X_add_number
== p
->e
.X_add_number
801 && ispcrel
== p
->ispcrel
)
809 p
->ispcrel
= ispcrel
;
817 /* Parse a literal specification. -- either new or old syntax.
818 old syntax: the user supplies the label and places the literal.
819 new syntax: we put it into the literal pool. */
821 parse_rt (s
, outputp
, ispcrel
, ep
)
831 /* Indicate nothing there. */
836 s
= parse_exp (s
+ 1, & e
);
841 as_bad (_("missing ']'"));
845 s
= parse_exp (s
, & e
);
847 n
= enter_literal (& e
, ispcrel
);
852 /* Create a reference to pool entry. */
854 e
.X_add_symbol
= poolsym
;
855 e
.X_add_number
= n
<< 2;
858 * outputp
= frag_more (2);
860 fix_new_exp (frag_now
, (*outputp
) - frag_now
->fr_literal
, 2, & e
, 1,
861 BFD_RELOC_MCORE_PCREL_IMM8BY4
);
867 parse_imm (s
, val
, min
, max
)
876 new = parse_exp (s
, & e
);
878 if (e
.X_op
== O_absent
)
879 ; /* An error message has already been emitted. */
880 else if (e
.X_op
!= O_constant
)
881 as_bad (_("operand must be a constant"));
882 else if (e
.X_add_number
< min
|| e
.X_add_number
> max
)
883 as_bad (_("operand must be absolute in range %d..%d, not %d"),
884 min
, max
, e
.X_add_number
);
886 * val
= e
.X_add_number
;
892 parse_mem (s
, reg
, off
, siz
)
902 while (isspace (* s
))
907 s
= parse_reg (s
+ 1, reg
);
909 while (isspace (* s
))
914 s
= parse_imm (s
+ 1, off
, 0, 63);
921 as_bad (_("operand must be a multiple of 4"));
928 as_bad (_("operand must be a multiple of 2"));
935 while (isspace (* s
))
942 as_bad (_("base register expected"));
947 /* This is the guts of the machine-dependent assembler. STR points to a
948 machine dependent instruction. This function is supposed to emit
949 the frags/bytes it assembles to. */
957 mcore_opcode_info
* opcode
;
967 /* Drop leading whitespace. */
968 while (isspace (* str
))
971 /* Find the op code end. */
972 for (op_start
= op_end
= str
;
973 nlen
< 20 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
976 name
[nlen
] = op_start
[nlen
];
984 as_bad (_("can't find opcode "));
988 opcode
= (mcore_opcode_info
*) hash_find (opcode_hash_control
, name
);
991 as_bad (_("unknown opcode \"%s\""), name
);
998 switch (opcode
->opclass
)
1001 output
= frag_more (2);
1005 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 3);
1007 output
= frag_more (2);
1011 op_end
= parse_reg (op_end
+ 1, & reg
);
1013 output
= frag_more (2);
1017 op_end
= parse_reg (op_end
+ 1, & reg
);
1019 output
= frag_more (2);
1020 /* In a sifilter mode, we emit this insn 2 times,
1021 fixes problem of an interrupt during a jmp.. */
1024 output
[0] = INST_BYTE0 (inst
);
1025 output
[1] = INST_BYTE1 (inst
);
1026 output
= frag_more (2);
1031 op_end
= parse_reg (op_end
+ 1, & reg
);
1034 as_bad (_("invalid register: r15 illegal"));
1037 output
= frag_more (2);
1041 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
1042 inst
= MCORE_INST_BSR
; /* with 0 displacement */
1043 output
[0] = INST_BYTE0 (inst
);
1044 output
[1] = INST_BYTE1 (inst
);
1046 output
= frag_more (2);
1047 inst
= MCORE_INST_ADDI
;
1048 inst
|= 15; /* addi r15,6 */
1049 inst
|= (6 - 1) << 4; /* over the jmp's */
1050 output
[0] = INST_BYTE0 (inst
);
1051 output
[1] = INST_BYTE1 (inst
);
1053 output
= frag_more (2);
1054 inst
= MCORE_INST_JMP
| reg
;
1055 output
[0] = INST_BYTE0 (inst
);
1056 output
[1] = INST_BYTE1 (inst
);
1058 output
= frag_more (2); /* 2nd emitted in fallthru */
1063 op_end
= parse_reg (op_end
+ 1, & reg
);
1066 /* Skip whitespace. */
1067 while (isspace (* op_end
))
1072 op_end
= parse_creg (op_end
+ 1, & reg
);
1076 output
= frag_more (2);
1082 as_bad (_("M340 specific opcode used when assembling for M210"));
1085 /* drop through... */
1087 op_end
= parse_reg (op_end
+ 1, & reg
);
1090 /* Skip whitespace. */
1091 while (isspace (* op_end
))
1094 if (* op_end
== ',')
1096 op_end
= parse_reg (op_end
+ 1, & reg
);
1100 as_bad (_("second operand missing"));
1102 output
= frag_more (2);
1105 case X1
: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1106 op_end
= parse_reg (op_end
+ 1, & reg
);
1108 /* Skip whitespace. */
1109 while (isspace (* op_end
))
1112 if (* op_end
== ',') /* xtrb- r1,rx */
1115 as_bad (_("destination register must be r1"));
1117 op_end
= parse_reg (op_end
+ 1, & reg
);
1121 output
= frag_more (2);
1124 case O1R1
: /* div- rx,r1 */
1125 op_end
= parse_reg (op_end
+ 1, & reg
);
1128 /* Skip whitespace. */
1129 while (isspace (* op_end
))
1132 if (* op_end
== ',')
1134 op_end
= parse_reg (op_end
+ 1, & reg
);
1136 as_bad (_("source register must be r1"));
1139 as_bad (_("second operand missing"));
1141 output
= frag_more (2);
1145 op_end
= parse_reg (op_end
+ 1, & reg
);
1148 /* Skip whitespace. */
1149 while (isspace (* op_end
))
1152 if (* op_end
== ',')
1154 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1155 inst
|= (reg
- 1) << 4;
1158 as_bad (_("second operand missing"));
1160 output
= frag_more (2);
1164 op_end
= parse_reg (op_end
+ 1, & reg
);
1167 /* Skip whitespace. */
1168 while (isspace (* op_end
))
1171 if (* op_end
== ',')
1173 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1177 as_bad (_("second operand missing"));
1179 output
= frag_more (2);
1182 case OB2
: /* like OB, but arg is 2^n instead of n */
1183 op_end
= parse_reg (op_end
+ 1, & reg
);
1186 /* Skip whitespace. */
1187 while (isspace (* op_end
))
1190 if (* op_end
== ',')
1192 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1193 /* Further restrict the immediate to a power of two. */
1194 if ((reg
& (reg
- 1)) == 0)
1199 as_bad (_("immediate is not a power of two"));
1204 as_bad (_("second operand missing"));
1206 output
= frag_more (2);
1209 case OBRa
: /* Specific for bgeni: imm of 0->6 translate to movi. */
1212 op_end
= parse_reg (op_end
+ 1, & reg
);
1215 /* Skip whitespace. */
1216 while (isspace (* op_end
))
1219 if (* op_end
== ',')
1221 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 31);
1222 /* immediate values of 0 -> 6 translate to movi */
1225 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1227 as_warn (_("translating bgeni to movi"));
1233 as_bad (_("second operand missing"));
1235 output
= frag_more (2);
1238 case OBR2
: /* like OBR, but arg is 2^n instead of n */
1239 op_end
= parse_reg (op_end
+ 1, & reg
);
1242 /* Skip whitespace. */
1243 while (isspace (* op_end
))
1246 if (* op_end
== ',')
1248 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 1 << 31);
1250 /* Further restrict the immediate to a power of two. */
1251 if ((reg
& (reg
- 1)) == 0)
1256 as_bad (_("immediate is not a power of two"));
1259 /* Immediate values of 0 -> 6 translate to movi. */
1262 inst
= (inst
& 0xF) | MCORE_INST_BGENI_ALT
;
1264 as_warn (_("translating mgeni to movi"));
1270 as_bad (_("second operand missing"));
1272 output
= frag_more (2);
1275 case OMa
: /* Specific for bmaski: imm 1->7 translate to movi. */
1278 op_end
= parse_reg (op_end
+ 1, & reg
);
1281 /* Skip whitespace. */
1282 while (isspace (* op_end
))
1285 if (* op_end
== ',')
1287 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 32);
1289 /* Immediate values of 1 -> 7 translate to movi. */
1292 inst
= (inst
& 0xF) | MCORE_INST_BMASKI_ALT
;
1293 reg
= (0x1 << reg
) - 1;
1296 as_warn (_("translating bmaski to movi"));
1301 inst
|= (reg
& 0x1F) << 4;
1305 as_bad (_("second operand missing"));
1307 output
= frag_more (2);
1311 op_end
= parse_reg (op_end
+ 1, & reg
);
1314 /* Skip whitespace. */
1315 while (isspace (* op_end
))
1318 if (* op_end
== ',')
1320 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1324 as_bad (_("second operand missing"));
1326 output
= frag_more (2);
1330 op_end
= parse_reg (op_end
+ 1, & reg
);
1333 /* Skip whitespace. */
1334 while (isspace (* op_end
))
1337 if (* op_end
== ',')
1339 op_end
= parse_imm (op_end
+ 1, & reg
, 0, 0x7F);
1343 as_bad (_("second operand missing"));
1345 output
= frag_more (2);
1349 op_end
= parse_reg (op_end
+ 1, & reg
);
1352 /* Skip whitespace. */
1353 while (isspace (* op_end
))
1356 if (* op_end
== ',')
1360 if ((inst
& 0x6000) == 0)
1362 else if ((inst
& 0x6000) == 0x4000)
1364 else if ((inst
& 0x6000) == 0x2000)
1367 op_end
= parse_mem (op_end
+ 1, & reg
, & off
, size
);
1370 as_bad (_("displacement too large (%d)"), off
);
1372 inst
|= (reg
) | (off
<< 4);
1375 as_bad (_("second operand missing"));
1377 output
= frag_more (2);
1381 op_end
= parse_reg (op_end
+ 1, & reg
);
1383 if (reg
== 0 || reg
== 15)
1384 as_bad (_("Invalid register: r0 and r15 illegal"));
1388 /* Skip whitespace. */
1389 while (isspace (* op_end
))
1392 if (* op_end
== ',')
1394 /* parse_rt calls frag_more() for us. */
1395 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 0, 0);
1396 op_end
= input_line_pointer
;
1400 as_bad (_("second operand missing"));
1401 output
= frag_more (2); /* save its space */
1406 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, 0);
1407 /* parse_rt() calls frag_more() for us. */
1408 op_end
= input_line_pointer
;
1412 op_end
= parse_reg (op_end
+ 1, & reg
);
1414 if (reg
== 0 || reg
== 15)
1415 as_bad (_("bad starting register: r0 and r15 invalid"));
1419 /* Skip whitespace. */
1420 while (isspace (* op_end
))
1423 if (* op_end
== '-')
1425 op_end
= parse_reg (op_end
+ 1, & reg
);
1428 as_bad (_("ending register must be r15"));
1430 /* Skip whitespace. */
1431 while (isspace (* op_end
))
1435 if (* op_end
== ',')
1439 /* Skip whitespace. */
1440 while (isspace (* op_end
))
1443 if (* op_end
== '(')
1445 op_end
= parse_reg (op_end
+ 1, & reg
);
1448 as_bad (_("bad base register: must be r0"));
1450 if (* op_end
== ')')
1454 as_bad (_("base register expected"));
1457 as_bad (_("second operand missing"));
1459 output
= frag_more (2);
1463 op_end
= parse_reg (op_end
+ 1, & reg
);
1466 as_fatal (_("first register must be r4"));
1468 /* Skip whitespace. */
1469 while (isspace (* op_end
))
1472 if (* op_end
== '-')
1474 op_end
= parse_reg (op_end
+ 1, & reg
);
1477 as_fatal (_("last register must be r7"));
1479 /* Skip whitespace. */
1480 while (isspace (* op_end
))
1483 if (* op_end
== ',')
1487 /* Skip whitespace. */
1488 while (isspace (* op_end
))
1491 if (* op_end
== '(')
1493 op_end
= parse_reg (op_end
+ 1, & reg
);
1495 if (reg
>= 4 && reg
<= 7)
1496 as_fatal ("base register cannot be r4, r5, r6, or r7");
1500 /* Skip whitespace. */
1501 while (isspace (* op_end
))
1504 if (* op_end
== ')')
1508 as_bad (_("base register expected"));
1511 as_bad (_("second operand missing"));
1514 as_bad (_("reg-reg expected"));
1516 output
= frag_more (2);
1520 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1521 op_end
= input_line_pointer
;
1523 output
= frag_more (2);
1525 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1526 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2
);
1530 op_end
= parse_reg (op_end
+ 1, & reg
);
1533 /* Skip whitespace. */
1534 while (isspace (* op_end
))
1537 if (* op_end
== ',')
1539 op_end
= parse_exp (op_end
+ 1, & e
);
1540 output
= frag_more (2);
1542 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1543 2, & e
, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2
);
1547 as_bad (_("second operand missing"));
1548 output
= frag_more (2);
1553 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1554 op_end
= input_line_pointer
;
1556 output
= frag_var (rs_machine_dependent
,
1557 md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
,
1558 md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
,
1559 C (COND_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1564 input_line_pointer
= parse_exp (op_end
+ 1, & e
);
1565 op_end
= input_line_pointer
;
1567 output
= frag_var (rs_machine_dependent
,
1568 md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
,
1569 md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
,
1570 C (UNCD_JUMP
, 0), e
.X_add_symbol
, e
.X_add_number
, 0);
1575 inst
= MCORE_INST_JSRI
; /* jsri */
1576 input_line_pointer
= parse_rt (op_end
+ 1, & output
, 1, & e
);
1577 /* parse_rt() calls frag_more for us. */
1578 op_end
= input_line_pointer
;
1580 /* Only do this if we know how to do it ... */
1581 if (e
.X_op
!= O_absent
&& do_jsri2bsr
)
1583 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1584 fix_new_exp (frag_now
, output
-frag_now
->fr_literal
,
1585 2, & e
, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
);
1589 case RSI
: /* SI, but imm becomes 32-imm */
1590 op_end
= parse_reg (op_end
+ 1, & reg
);
1593 /* Skip whitespace. */
1594 while (isspace (* op_end
))
1597 if (* op_end
== ',')
1599 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1605 as_bad (_("second operand missing"));
1607 output
= frag_more (2);
1610 case DO21
: /* O2, dup rd, lit must be 1 */
1611 op_end
= parse_reg (op_end
+ 1, & reg
);
1615 /* Skip whitespace. */
1616 while (isspace (* op_end
))
1619 if (* op_end
== ',')
1621 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1624 as_bad (_("second operand must be 1"));
1627 as_bad (_("second operand missing"));
1629 output
= frag_more (2);
1633 op_end
= parse_reg (op_end
+ 1, & reg
);
1636 /* Skip whitespace. */
1637 while (isspace (* op_end
))
1640 if (* op_end
== ',')
1642 op_end
= parse_imm (op_end
+ 1, & reg
, 1, 31);
1645 as_bad (_("zero used as immediate value"));
1650 as_bad (_("second operand missing"));
1652 output
= frag_more (2);
1658 as_bad (_("M340 specific opcode used when assembling for M210"));
1662 op_end
= parse_psrmod (op_end
+ 1, & reg
);
1664 /* Look for further selectors. */
1665 while (* op_end
== ',')
1669 op_end
= parse_psrmod (op_end
+ 1, & value
);
1672 as_bad (_("duplicated psr bit specifier"));
1678 as_bad (_("`af' must appear alone"));
1680 inst
|= (reg
& 0x7);
1681 output
= frag_more (2);
1685 as_bad (_("unimplemented opcode \"%s\""), name
);
1688 /* Drop whitespace after all the operands have been parsed. */
1689 while (isspace (* op_end
))
1692 /* Give warning message if the insn has more operands than required. */
1693 if (strcmp (op_end
, opcode
->name
) && strcmp (op_end
, ""))
1694 as_warn (_("ignoring operands: %s "), op_end
);
1696 output
[0] = INST_BYTE0 (inst
);
1697 output
[1] = INST_BYTE1 (inst
);
1699 check_literals (opcode
->transfer
, isize
);
1703 md_undefined_symbol (name
)
1713 subseg_set (text_section
, 0);
1716 /* Various routines to kill one day. */
1717 /* Equal to MAX_PRECISION in atof-ieee.c */
1718 #define MAX_LITTLENUMS 6
1720 /* Turn a string in input_line_pointer into a floating point constant of type
1721 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1722 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1724 md_atof (type
, litP
, sizeP
)
1730 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1733 char * atof_ieee ();
1763 return _("Bad call to MD_NTOF()");
1766 t
= atof_ieee (input_line_pointer
, type
, words
);
1769 input_line_pointer
= t
;
1771 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1773 if (! target_big_endian
)
1775 for (i
= prec
- 1; i
>= 0; i
--)
1777 md_number_to_chars (litP
, (valueT
) words
[i
],
1778 sizeof (LITTLENUM_TYPE
));
1779 litP
+= sizeof (LITTLENUM_TYPE
);
1783 for (i
= 0; i
< prec
; i
++)
1785 md_number_to_chars (litP
, (valueT
) words
[i
],
1786 sizeof (LITTLENUM_TYPE
));
1787 litP
+= sizeof (LITTLENUM_TYPE
);
1793 CONST
char * md_shortopts
= "";
1795 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1796 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1797 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1798 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1799 #define OPTION_CPU (OPTION_MD_BASE + 4)
1800 #define OPTION_EB (OPTION_MD_BASE + 5)
1801 #define OPTION_EL (OPTION_MD_BASE + 6)
1803 struct option md_longopts
[] =
1805 { "no-jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_OFF
},
1806 { "jsri2bsr", no_argument
, NULL
, OPTION_JSRI2BSR_ON
},
1807 { "sifilter", no_argument
, NULL
, OPTION_SIFILTER_ON
},
1808 { "no-sifilter", no_argument
, NULL
, OPTION_SIFILTER_OFF
},
1809 { "cpu", required_argument
, NULL
, OPTION_CPU
},
1810 { "EB", no_argument
, NULL
, OPTION_EB
},
1811 { "EL", no_argument
, NULL
, OPTION_EL
},
1812 { NULL
, no_argument
, NULL
, 0}
1815 size_t md_longopts_size
= sizeof (md_longopts
);
1818 md_parse_option (c
, arg
)
1828 if (streq (arg
, "210"))
1831 target_big_endian
= 1;
1833 else if (streq (arg
, "340"))
1836 as_warn (_("unrecognised cpu type '%s'"), arg
);
1839 case OPTION_EB
: target_big_endian
= 1; break;
1840 case OPTION_EL
: target_big_endian
= 0; cpu
= M340
; break;
1841 case OPTION_JSRI2BSR_ON
: do_jsri2bsr
= 1; break;
1842 case OPTION_JSRI2BSR_OFF
: do_jsri2bsr
= 0; break;
1843 case OPTION_SIFILTER_ON
: sifilter_mode
= 1; break;
1844 case OPTION_SIFILTER_OFF
: sifilter_mode
= 0; break;
1852 md_show_usage (stream
)
1855 fprintf (stream
, _("\
1856 MCORE specific options:\n\
1857 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1858 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1859 -cpu=[210|340] select CPU type\n\
1860 -EB assemble for a big endian system (default)\n\
1861 -EL assemble for a little endian system\n"));
1864 int md_short_jump_size
;
1867 md_create_short_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1872 symbolS
* to_symbol
;
1874 as_fatal (_("failed sanity check: short_jump"));
1878 md_create_long_jump (ptr
, from_Nddr
, to_Nddr
, frag
, to_symbol
)
1883 symbolS
* to_symbol
;
1885 as_fatal (_("failed sanity check: long_jump"));
1888 /* Called after relaxing, change the frags so they know how big they are. */
1890 md_convert_frag (abfd
, sec
, fragP
)
1893 register fragS
* fragP
;
1895 unsigned char * buffer
;
1896 int targ_addr
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
1898 buffer
= (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1899 targ_addr
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
1901 switch (fragP
->fr_subtype
)
1903 case C (COND_JUMP
, DISP12
):
1904 case C (UNCD_JUMP
, DISP12
):
1906 /* Get the address of the end of the instruction. */
1907 int next_inst
= fragP
->fr_fix
+ fragP
->fr_address
+ 2;
1909 int disp
= targ_addr
- next_inst
;
1912 as_bad (_("odd displacement at %x"), next_inst
- 2);
1916 if (! target_big_endian
)
1918 t0
= buffer
[1] & 0xF8;
1920 md_number_to_chars (buffer
, disp
, 2);
1922 buffer
[1] = (buffer
[1] & 0x07) | t0
;
1926 t0
= buffer
[0] & 0xF8;
1928 md_number_to_chars (buffer
, disp
, 2);
1930 buffer
[0] = (buffer
[0] & 0x07) | t0
;
1938 case C (COND_JUMP
, DISP32
):
1939 case C (COND_JUMP
, UNDEF_WORD_DISP
):
1941 /* A conditional branch wont fit into 12 bits so:
1948 * if the b!cond is 4 byte aligned, the literal which would
1949 * go at x+4 will also be aligned.
1951 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
1952 int needpad
= (first_inst
& 3);
1954 if (! target_big_endian
)
1957 buffer
[0] ^= 0x08; /* Toggle T/F bit */
1959 buffer
[2] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
1960 buffer
[3] = INST_BYTE1 (MCORE_INST_JMPI
);
1964 if (! target_big_endian
)
1966 buffer
[0] = 4; /* branch over jmpi, pad, and ptr */
1967 buffer
[2] = 1; /* jmpi offset of 1 gets the pointer */
1971 buffer
[1] = 4; /* branch over jmpi, pad, and ptr */
1972 buffer
[3] = 1; /* jmpi offset of 1 gets the pointer */
1975 buffer
[4] = 0; /* alignment/pad */
1977 buffer
[6] = 0; /* space for 32 bit address */
1982 /* Make reloc for the long disp */
1983 fix_new (fragP
, fragP
->fr_fix
+ 6, 4,
1984 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
1986 fragP
->fr_fix
+= C32_LEN
;
1990 /* See comment below about this given gas' limitations for
1991 shrinking the fragment. '3' is the amount of code that
1992 we inserted here, but '4' is right for the space we reserved
1993 for this fragment. */
1994 if (! target_big_endian
)
1996 buffer
[0] = 3; /* branch over jmpi, and ptr */
1997 buffer
[2] = 0; /* jmpi offset of 0 gets the pointer */
2001 buffer
[1] = 3; /* branch over jmpi, and ptr */
2002 buffer
[3] = 0; /* jmpi offset of 0 gets the pointer */
2005 buffer
[4] = 0; /* space for 32 bit address */
2010 /* Make reloc for the long disp. */
2011 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
2012 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2013 fragP
->fr_fix
+= C32_LEN
;
2015 /* Frag is actually shorter (see the other side of this ifdef)
2016 but gas isn't prepared for that. We have to re-adjust
2017 the branch displacement so that it goes beyond the
2018 full length of the fragment, not just what we actually
2020 if (! target_big_endian
)
2021 buffer
[0] = 4; /* jmpi, ptr, and the 'tail pad' */
2023 buffer
[1] = 4; /* jmpi, ptr, and the 'tail pad' */
2030 case C (UNCD_JUMP
, DISP32
):
2031 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2033 /* An unconditional branch will not fit in 12 bits, make code which
2038 we need a pad if "first_inst" is 4 byte aligned.
2039 [because the natural literal place is x + 2] */
2040 int first_inst
= fragP
->fr_fix
+ fragP
->fr_address
;
2041 int needpad
= !(first_inst
& 3);
2043 buffer
[0] = INST_BYTE0 (MCORE_INST_JMPI
); /* Build jmpi */
2044 buffer
[1] = INST_BYTE1 (MCORE_INST_JMPI
);
2048 if (! target_big_endian
)
2049 buffer
[0] = 1; /* jmpi offset of 1 since padded */
2051 buffer
[1] = 1; /* jmpi offset of 1 since padded */
2052 buffer
[2] = 0; /* alignment */
2054 buffer
[4] = 0; /* space for 32 bit address */
2059 /* Make reloc for the long disp. */
2060 fix_new (fragP
, fragP
->fr_fix
+ 4, 4,
2061 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2063 fragP
->fr_fix
+= U32_LEN
;
2067 if (! target_big_endian
)
2068 buffer
[0] = 0; /* jmpi offset of 0 if no pad */
2070 buffer
[1] = 0; /* jmpi offset of 0 if no pad */
2071 buffer
[2] = 0; /* space for 32 bit address */
2076 /* Make reloc for the long disp. */
2077 fix_new (fragP
, fragP
->fr_fix
+ 2, 4,
2078 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_32
);
2079 fragP
->fr_fix
+= U32_LEN
;
2091 /* Applies the desired value to the specified location.
2092 Also sets up addends for 'rela' type relocations. */
2094 md_apply_fix3 (fixP
, valp
, segment
)
2099 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2100 char * file
= fixP
->fx_file
? fixP
->fx_file
: _("unknown");
2101 const char * symname
;
2102 /* Note: use offsetT because it is signed, valueT is unsigned. */
2103 offsetT val
= (offsetT
) * valp
;
2105 symname
= fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : _("<unknown>");
2106 /* Save this for the addend in the relocation record. */
2107 fixP
->fx_addnumber
= val
;
2109 /* If the fix is relative to a symbol which is not defined, or not
2110 in the same segment as the fix, we cannot resolve it here. */
2111 if (fixP
->fx_addsy
!= NULL
2112 && ( ! S_IS_DEFINED (fixP
->fx_addsy
)
2113 || (S_GET_SEGMENT (fixP
->fx_addsy
) != segment
)))
2117 /* For ELF we can just return and let the reloc that will be generated
2118 take care of everything. For COFF we still have to insert 'val'
2119 into the insn since the addend field will be ignored. */
2126 switch (fixP
->fx_r_type
)
2128 case BFD_RELOC_MCORE_PCREL_IMM11BY2
: /* second byte of 2 byte opcode */
2130 as_bad_where (file
, fixP
->fx_line
,
2131 _("odd distance branch (0x%x bytes)"), val
);
2133 if (((val
& ~0x3ff) != 0) && ((val
| 0x3ff) != -1))
2134 as_bad_where (file
, fixP
->fx_line
,
2135 _("pcrel for branch to %s too far (0x%x)"),
2137 if (target_big_endian
)
2139 buf
[0] |= ((val
>> 8) & 0x7);
2140 buf
[1] |= (val
& 0xff);
2144 buf
[1] |= ((val
>> 8) & 0x7);
2145 buf
[0] |= (val
& 0xff);
2149 case BFD_RELOC_MCORE_PCREL_IMM8BY4
: /* lower 8 bits of 2 byte opcode */
2153 as_bad_where (file
, fixP
->fx_line
,
2154 _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"),
2156 else if (! target_big_endian
)
2157 buf
[0] |= (val
& 0xff);
2159 buf
[1] |= (val
& 0xff);
2162 case BFD_RELOC_MCORE_PCREL_IMM4BY2
: /* loopt instruction */
2163 if ((val
< -32) || (val
> -2))
2164 as_bad_where (file
, fixP
->fx_line
,
2165 _("pcrel for loopt too far (0x%x)"), val
);
2167 if (! target_big_endian
)
2168 buf
[0] |= (val
& 0xf);
2170 buf
[1] |= (val
& 0xf);
2173 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2174 /* Conditional linker map jsri to bsr. */
2175 /* If its a local target and close enough, fix it.
2176 NB: >= -2k for backwards bsr; < 2k for forwards... */
2177 if (fixP
->fx_addsy
== 0 && val
>= -2048 && val
< 2048)
2179 long nval
= (val
/ 2) & 0x7ff;
2180 nval
|= MCORE_INST_BSR
;
2182 /* REPLACE the instruction, don't just modify it. */
2183 buf
[0] = INST_BYTE0 (nval
);
2184 buf
[1] = INST_BYTE1 (nval
);
2190 case BFD_RELOC_MCORE_PCREL_32
:
2191 case BFD_RELOC_VTABLE_INHERIT
:
2192 case BFD_RELOC_VTABLE_ENTRY
:
2197 if (fixP
->fx_addsy
!= NULL
)
2199 /* If the fix is an absolute reloc based on a symbol's
2200 address, then it cannot be resolved until the final link. */
2207 if (fixP
->fx_size
== 4)
2209 else if (fixP
->fx_size
== 2 && val
>= -32768 && val
<= 32767)
2211 else if (fixP
->fx_size
== 1 && val
>= -256 && val
<= 255)
2215 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2220 return 0; /* Return value is ignored. */
2224 md_operand (expressionP
)
2225 expressionS
* expressionP
;
2227 /* Ignore leading hash symbol, if poresent. */
2228 if (* input_line_pointer
== '#')
2230 input_line_pointer
++;
2231 expression (expressionP
);
2235 int md_long_jump_size
;
2237 /* Called just before address relaxation, return the length
2238 by which a fragment must grow to reach it's destination. */
2240 md_estimate_size_before_relax (fragP
, segment_type
)
2241 register fragS
* fragP
;
2242 register segT segment_type
;
2244 switch (fragP
->fr_subtype
)
2249 case C (UNCD_JUMP
, UNDEF_DISP
):
2250 /* Used to be a branch to somewhere which was unknown. */
2251 if (!fragP
->fr_symbol
)
2253 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2254 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
;
2256 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2258 fragP
->fr_subtype
= C (UNCD_JUMP
, DISP12
);
2259 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, DISP12
)].rlx_length
;
2263 fragP
->fr_subtype
= C (UNCD_JUMP
, UNDEF_WORD_DISP
);
2264 fragP
->fr_var
= md_relax_table
[C (UNCD_JUMP
, DISP32
)].rlx_length
;
2268 case C (COND_JUMP
, UNDEF_DISP
):
2269 /* Used to be a branch to somewhere which was unknown. */
2270 if (fragP
->fr_symbol
2271 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
2273 /* Got a symbol and it's defined in this segment, become byte
2274 sized - maybe it will fix up */
2275 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2276 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
;
2278 else if (fragP
->fr_symbol
)
2280 /* Its got a segment, but its not ours, so it will always be long. */
2281 fragP
->fr_subtype
= C (COND_JUMP
, UNDEF_WORD_DISP
);
2282 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, DISP32
)].rlx_length
;
2286 /* We know the abs value. */
2287 fragP
->fr_subtype
= C (COND_JUMP
, DISP12
);
2288 fragP
->fr_var
= md_relax_table
[C (COND_JUMP
, DISP12
)].rlx_length
;
2292 case C (UNCD_JUMP
, DISP12
):
2293 case C (UNCD_JUMP
, UNDEF_WORD_DISP
):
2294 case C (COND_JUMP
, DISP12
):
2295 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2296 /* When relaxing a section for the second time, we don't need to
2301 return fragP
->fr_var
;
2304 /* Put number into target byte order. */
2306 md_number_to_chars (ptr
, use
, nbytes
)
2311 if (! target_big_endian
)
2314 case 4: ptr
[3] = (use
>> 24) & 0xff; /* fall through */
2315 case 3: ptr
[2] = (use
>> 16) & 0xff; /* fall through */
2316 case 2: ptr
[1] = (use
>> 8) & 0xff; /* fall through */
2317 case 1: ptr
[0] = (use
>> 0) & 0xff; break;
2323 case 4: *ptr
++ = (use
>> 24) & 0xff; /* fall through */
2324 case 3: *ptr
++ = (use
>> 16) & 0xff; /* fall through */
2325 case 2: *ptr
++ = (use
>> 8) & 0xff; /* fall through */
2326 case 1: *ptr
++ = (use
>> 0) & 0xff; break;
2331 /* Round up a section size to the appropriate boundary. */
2333 md_section_align (segment
, size
)
2337 return size
; /* Byte alignment is fine */
2340 /* The location from which a PC relative jump should be calculated,
2341 given a PC relative reloc. */
2343 md_pcrel_from_section (fixp
, sec
)
2348 /* If the symbol is undefined or defined in another section
2349 we leave the add number alone for the linker to fix it later.
2350 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2351 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2352 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2353 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
2356 assert (fixp
->fx_size
== 2); /* must be an insn */
2357 return fixp
->fx_size
;
2361 /* The case where we are going to resolve things... */
2362 return fixp
->fx_size
+ fixp
->fx_where
+ fixp
->fx_frag
->fr_address
;
2365 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2366 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2369 tc_gen_reloc (section
, fixp
)
2374 bfd_reloc_code_real_type code
;
2377 switch (fixp
->fx_r_type
)
2379 /* These confuse the size/pcrel macro approach. */
2380 case BFD_RELOC_VTABLE_INHERIT
:
2381 case BFD_RELOC_VTABLE_ENTRY
:
2382 case BFD_RELOC_MCORE_PCREL_IMM4BY2
:
2383 case BFD_RELOC_MCORE_PCREL_IMM8BY4
:
2384 case BFD_RELOC_MCORE_PCREL_IMM11BY2
:
2385 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
:
2387 code
= fixp
->fx_r_type
;
2391 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2393 MAP (1, 0, BFD_RELOC_8
);
2394 MAP (2, 0, BFD_RELOC_16
);
2395 MAP (4, 0, BFD_RELOC_32
);
2396 MAP (1, 1, BFD_RELOC_8_PCREL
);
2397 MAP (2, 1, BFD_RELOC_16_PCREL
);
2398 MAP (4, 1, BFD_RELOC_32_PCREL
);
2400 code
= fixp
->fx_r_type
;
2401 as_bad (_("Can not do %d byte %srelocation"),
2403 fixp
->fx_pcrel
? _("pc-relative") : "");
2408 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2409 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2410 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2411 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2412 /* Always pass the addend along! */
2413 rel
->addend
= fixp
->fx_addnumber
;
2415 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2417 if (rel
->howto
== NULL
)
2419 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2420 _("Cannot represent relocation type %s"),
2421 bfd_get_reloc_code_name (code
));
2423 /* Set howto to a garbage value so that we can keep going. */
2424 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
2425 assert (rel
->howto
!= NULL
);
2432 /* See whether we need to force a relocation into the output file.
2433 This is used to force out switch and PC relative relocations when
2436 mcore_force_relocation (fix
)
2439 if ( fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2440 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2441 || fix
->fx_r_type
== BFD_RELOC_RVA
)
2447 /* Return true if the fix can be handled by GAS, false if it must
2448 be passed through to the linker. */
2450 mcore_fix_adjustable (fixP
)
2453 if (fixP
->fx_addsy
== NULL
)
2456 /* We need the symbol name for the VTABLE entries. */
2457 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2458 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2463 #endif /* OBJ_ELF */