* tc.h (struct relax_type, relax_typeS): Move from here..
[deliverable/binutils-gdb.git] / gas / config / tc-mcore.c
1 /* tc-mcore.c -- Assemble code for M*Core
2 Copyright 1999, 2000, 2001, 2002, 2003, 2005
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 #include <stdio.h>
23 #include "as.h"
24 #include "bfd.h"
25 #include "subsegs.h"
26 #define DEFINE_TABLE
27 #include "../opcodes/mcore-opc.h"
28 #include "safe-ctype.h"
29 #include <string.h>
30
31 #ifdef OBJ_ELF
32 #include "elf/mcore.h"
33 #endif
34
35 #ifndef streq
36 #define streq(a,b) (strcmp (a, b) == 0)
37 #endif
38
39 /* Forward declarations for dumb compilers. */
40 static void mcore_s_literals PARAMS ((int));
41 static void mcore_pool_count PARAMS ((void (*) (int), int));
42 static void mcore_cons PARAMS ((int));
43 static void mcore_float_cons PARAMS ((int));
44 static void mcore_stringer PARAMS ((int));
45 static void mcore_fill PARAMS ((int));
46 static int mylog2 PARAMS ((unsigned int));
47 static char * parse_reg PARAMS ((char *, unsigned *));
48 static char * parse_creg PARAMS ((char *, unsigned *));
49 static char * parse_exp PARAMS ((char *, expressionS *));
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 char * parse_psrmod PARAMS ((char *, unsigned *));
54 static void make_name PARAMS ((char *, char *, int));
55 static int enter_literal PARAMS ((expressionS *, int));
56 static void dump_literals PARAMS ((int));
57 static void check_literals PARAMS ((int, int));
58 static void mcore_s_text PARAMS ((int));
59 static void mcore_s_data PARAMS ((int));
60 static void mcore_s_section PARAMS ((int));
61 static void mcore_s_bss PARAMS ((int));
62 #ifdef OBJ_ELF
63 static void mcore_s_comm PARAMS ((int));
64 #endif
65
66 /* Several places in this file insert raw instructions into the
67 object. They should use MCORE_INST_XXX macros to get the opcodes
68 and then use these two macros to crack the MCORE_INST value into
69 the appropriate byte values. */
70 #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF))
71 #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF))
72
73 const char comment_chars[] = "#/";
74 const char line_separator_chars[] = ";";
75 const char line_comment_chars[] = "#/";
76
77 const int md_reloc_size = 8;
78
79 static int do_jsri2bsr = 0; /* Change here from 1 by Cruess 19 August 97. */
80 static int sifilter_mode = 0;
81
82 const char EXP_CHARS[] = "eE";
83
84 /* Chars that mean this number is a floating point constant
85 As in 0f12.456
86 or 0d1.2345e12 */
87 const char FLT_CHARS[] = "rRsSfFdDxXpP";
88
89 #define C(what,length) (((what) << 2) + (length))
90 #define GET_WHAT(x) ((x >> 2))
91
92 /* These are the two types of relaxable instruction */
93 #define COND_JUMP 1
94 #define UNCD_JUMP 2
95
96 #define UNDEF_DISP 0
97 #define DISP12 1
98 #define DISP32 2
99 #define UNDEF_WORD_DISP 3
100
101 #define C12_LEN 2
102 #define C32_LEN 10 /* allow for align */
103 #define U12_LEN 2
104 #define U32_LEN 8 /* allow for align */
105
106 typedef enum
107 {
108 M210,
109 M340
110 }
111 cpu_type;
112
113 cpu_type cpu = M340;
114
115 /* Initialize the relax table. */
116 const relax_typeS md_relax_table[] = {
117 { 0, 0, 0, 0 },
118 { 0, 0, 0, 0 },
119 { 0, 0, 0, 0 },
120 { 0, 0, 0, 0 },
121
122 /* COND_JUMP */
123 { 0, 0, 0, 0 }, /* UNDEF_DISP */
124 { 2048, -2046, C12_LEN, C(COND_JUMP, DISP32) }, /* DISP12 */
125 { 0, 0, C32_LEN, 0 }, /* DISP32 */
126 { 0, 0, C32_LEN, 0 }, /* UNDEF_WORD_DISP */
127
128 /* UNCD_JUMP */
129 { 0, 0, 0, 0 }, /* UNDEF_DISP */
130 { 2048, -2046, U12_LEN, C(UNCD_JUMP, DISP32) }, /* DISP12 */
131 { 0, 0, U32_LEN, 0 }, /* DISP32 */
132 { 0, 0, U32_LEN, 0 } /* UNDEF_WORD_DISP */
133
134 };
135
136 /* Literal pool data structures. */
137 struct literal
138 {
139 unsigned short refcnt;
140 unsigned char ispcrel;
141 unsigned char unused;
142 expressionS e;
143 };
144
145 #define MAX_POOL_SIZE (1024/4)
146 static struct literal litpool [MAX_POOL_SIZE];
147 static unsigned poolsize;
148 static unsigned poolnumber;
149 static unsigned long poolspan;
150
151 /* SPANPANIC: the point at which we get too scared and force a dump
152 of the literal pool, and perhaps put a branch in place.
153 Calculated as:
154 1024 span of lrw/jmpi/jsri insn (actually span+1)
155 -2 possible alignment at the insn.
156 -2 possible alignment to get the table aligned.
157 -2 an inserted branch around the table.
158 == 1018
159 at 1018, we might be in trouble.
160 -- so we have to be smaller than 1018 and since we deal with 2-byte
161 instructions, the next good choice is 1016.
162 -- Note we have a test case that fails when we've got 1018 here. */
163 #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */
164 #define SPANCLOSE (900)
165 #define SPANEXIT (600)
166 static symbolS * poolsym; /* label for current pool. */
167 static char poolname[8];
168 static struct hash_control * opcode_hash_control; /* Opcode mnemonics. */
169
170 /* This table describes all the machine specific pseudo-ops the assembler
171 has to support. The fields are:
172 Pseudo-op name without dot
173 Function to call to execute this pseudo-op
174 Integer arg to pass to the function. */
175 const pseudo_typeS md_pseudo_table[] =
176 {
177 { "export", s_globl, 0 },
178 { "import", s_ignore, 0 },
179 { "literals", mcore_s_literals, 0 },
180 { "page", listing_eject, 0 },
181
182 /* The following are to intercept the placement of data into the text
183 section (eg addresses for a switch table), so that the space they
184 occupy can be taken into account when deciding whether or not to
185 dump the current literal pool.
186 XXX - currently we do not cope with the .space and .dcb.d directives. */
187 { "ascii", mcore_stringer, 0 },
188 { "asciz", mcore_stringer, 1 },
189 { "byte", mcore_cons, 1 },
190 { "dc", mcore_cons, 2 },
191 { "dc.b", mcore_cons, 1 },
192 { "dc.d", mcore_float_cons, 'd'},
193 { "dc.l", mcore_cons, 4 },
194 { "dc.s", mcore_float_cons, 'f'},
195 { "dc.w", mcore_cons, 2 },
196 { "dc.x", mcore_float_cons, 'x'},
197 { "double", mcore_float_cons, 'd'},
198 { "float", mcore_float_cons, 'f'},
199 { "hword", mcore_cons, 2 },
200 { "int", mcore_cons, 4 },
201 { "long", mcore_cons, 4 },
202 { "octa", mcore_cons, 16 },
203 { "quad", mcore_cons, 8 },
204 { "short", mcore_cons, 2 },
205 { "single", mcore_float_cons, 'f'},
206 { "string", mcore_stringer, 1 },
207 { "word", mcore_cons, 2 },
208 { "fill", mcore_fill, 0 },
209
210 /* Allow for the effect of section changes. */
211 { "text", mcore_s_text, 0 },
212 { "data", mcore_s_data, 0 },
213 { "bss", mcore_s_bss, 1 },
214 #ifdef OBJ_ELF
215 { "comm", mcore_s_comm, 0 },
216 #endif
217 { "section", mcore_s_section, 0 },
218 { "section.s", mcore_s_section, 0 },
219 { "sect", mcore_s_section, 0 },
220 { "sect.s", mcore_s_section, 0 },
221
222 { 0, 0, 0 }
223 };
224
225 static void
226 mcore_s_literals (ignore)
227 int ignore ATTRIBUTE_UNUSED;
228 {
229 dump_literals (0);
230 demand_empty_rest_of_line ();
231 }
232
233 /* Perform FUNC (ARG), and track number of bytes added to frag. */
234
235 static void
236 mcore_pool_count (func, arg)
237 void (*func) PARAMS ((int));
238 int arg;
239 {
240 const fragS *curr_frag = frag_now;
241 offsetT added = -frag_now_fix_octets ();
242
243 (*func) (arg);
244
245 while (curr_frag != frag_now)
246 {
247 added += curr_frag->fr_fix;
248 curr_frag = curr_frag->fr_next;
249 }
250
251 added += frag_now_fix_octets ();
252 poolspan += added;
253 }
254
255 static void
256 mcore_cons (nbytes)
257 int nbytes;
258 {
259 if (now_seg == text_section)
260 mcore_pool_count (cons, nbytes);
261 else
262 cons (nbytes);
263
264 /* In theory we ought to call check_literals (2,0) here in case
265 we need to dump the literal table. We cannot do this however,
266 as the directives that we are intercepting may be being used
267 to build a switch table, and we must not interfere with its
268 contents. Instead we cross our fingers and pray... */
269 }
270
271 static void
272 mcore_float_cons (float_type)
273 int float_type;
274 {
275 if (now_seg == text_section)
276 mcore_pool_count (float_cons, float_type);
277 else
278 float_cons (float_type);
279
280 /* See the comment in mcore_cons () about calling check_literals.
281 It is unlikely that a switch table will be constructed using
282 floating point values, but it is still likely that an indexed
283 table of floating point constants is being created by these
284 directives, so again we must not interfere with their placement. */
285 }
286
287 static void
288 mcore_stringer (append_zero)
289 int append_zero;
290 {
291 if (now_seg == text_section)
292 mcore_pool_count (stringer, append_zero);
293 else
294 stringer (append_zero);
295
296 /* We call check_literals here in case a large number of strings are
297 being placed into the text section with a sequence of stringer
298 directives. In theory we could be upsetting something if these
299 strings are actually in an indexed table instead of referenced by
300 individual labels. Let us hope that that never happens. */
301 check_literals (2, 0);
302 }
303
304 static void
305 mcore_fill (unused)
306 int unused;
307 {
308 if (now_seg == text_section)
309 mcore_pool_count (s_fill, unused);
310 else
311 s_fill (unused);
312
313 check_literals (2, 0);
314 }
315
316 /* Handle the section changing pseudo-ops. These call through to the
317 normal implementations, but they dump the literal pool first. */
318 static void
319 mcore_s_text (ignore)
320 int ignore;
321 {
322 dump_literals (0);
323
324 #ifdef OBJ_ELF
325 obj_elf_text (ignore);
326 #else
327 s_text (ignore);
328 #endif
329 }
330
331 static void
332 mcore_s_data (ignore)
333 int ignore;
334 {
335 dump_literals (0);
336
337 #ifdef OBJ_ELF
338 obj_elf_data (ignore);
339 #else
340 s_data (ignore);
341 #endif
342 }
343
344 static void
345 mcore_s_section (ignore)
346 int ignore;
347 {
348 /* Scan forwards to find the name of the section. If the section
349 being switched to is ".line" then this is a DWARF1 debug section
350 which is arbitrarily placed inside generated code. In this case
351 do not dump the literal pool because it is a) inefficient and
352 b) would require the generation of extra code to jump around the
353 pool. */
354 char * ilp = input_line_pointer;
355
356 while (*ilp != 0 && ISSPACE (*ilp))
357 ++ ilp;
358
359 if (strncmp (ilp, ".line", 5) == 0
360 && (ISSPACE (ilp[5]) || *ilp == '\n' || *ilp == '\r'))
361 ;
362 else
363 dump_literals (0);
364
365 #ifdef OBJ_ELF
366 obj_elf_section (ignore);
367 #endif
368 #ifdef OBJ_COFF
369 obj_coff_section (ignore);
370 #endif
371 }
372
373 static void
374 mcore_s_bss (needs_align)
375 int needs_align;
376 {
377 dump_literals (0);
378
379 s_lcomm_bytes (needs_align);
380 }
381
382 #ifdef OBJ_ELF
383 static void
384 mcore_s_comm (needs_align)
385 int needs_align;
386 {
387 dump_literals (0);
388
389 obj_elf_common (needs_align);
390 }
391 #endif
392
393 /* This function is called once, at assembler startup time. This should
394 set up all the tables, etc that the MD part of the assembler needs. */
395 void
396 md_begin ()
397 {
398 const mcore_opcode_info * opcode;
399 char * prev_name = "";
400
401 opcode_hash_control = hash_new ();
402
403 /* Insert unique names into hash table */
404 for (opcode = mcore_table; opcode->name; opcode ++)
405 {
406 if (! streq (prev_name, opcode->name))
407 {
408 prev_name = opcode->name;
409 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
410 }
411 }
412 }
413
414 /* Get a log2(val). */
415 static int
416 mylog2 (val)
417 unsigned int val;
418 {
419 int log = -1;
420 while (val != 0)
421 {
422 log ++;
423 val >>= 1;
424 }
425
426 return log;
427 }
428
429 /* Try to parse a reg name. */
430 static char *
431 parse_reg (s, reg)
432 char * s;
433 unsigned * reg;
434 {
435 /* Strip leading whitespace. */
436 while (ISSPACE (* s))
437 ++ s;
438
439 if (TOLOWER (s[0]) == 'r')
440 {
441 if (s[1] == '1' && s[2] >= '0' && s[2] <= '5')
442 {
443 *reg = 10 + s[2] - '0';
444 return s + 3;
445 }
446
447 if (s[1] >= '0' && s[1] <= '9')
448 {
449 *reg = s[1] - '0';
450 return s + 2;
451 }
452 }
453 else if ( TOLOWER (s[0]) == 's'
454 && TOLOWER (s[1]) == 'p'
455 && ! ISALNUM (s[2]))
456 {
457 * reg = 0;
458 return s + 2;
459 }
460
461 as_bad (_("register expected, but saw '%.6s'"), s);
462 return s;
463 }
464
465 static struct Cregs
466 {
467 char * name;
468 unsigned int crnum;
469 }
470 cregs[] =
471 {
472 { "psr", 0},
473 { "vbr", 1},
474 { "epsr", 2},
475 { "fpsr", 3},
476 { "epc", 4},
477 { "fpc", 5},
478 { "ss0", 6},
479 { "ss1", 7},
480 { "ss2", 8},
481 { "ss3", 9},
482 { "ss4", 10},
483 { "gcr", 11},
484 { "gsr", 12},
485 { "", 0}
486 };
487
488 static char *
489 parse_creg (s, reg)
490 char * s;
491 unsigned * reg;
492 {
493 int i;
494
495 /* Strip leading whitespace. */
496 while (ISSPACE (* s))
497 ++s;
498
499 if ((TOLOWER (s[0]) == 'c' && TOLOWER (s[1]) == 'r'))
500 {
501 if (s[2] == '3' && s[3] >= '0' && s[3] <= '1')
502 {
503 *reg = 30 + s[3] - '0';
504 return s + 4;
505 }
506
507 if (s[2] == '2' && s[3] >= '0' && s[3] <= '9')
508 {
509 *reg = 20 + s[3] - '0';
510 return s + 4;
511 }
512
513 if (s[2] == '1' && s[3] >= '0' && s[3] <= '9')
514 {
515 *reg = 10 + s[3] - '0';
516 return s + 4;
517 }
518
519 if (s[2] >= '0' && s[2] <= '9')
520 {
521 *reg = s[2] - '0';
522 return s + 3;
523 }
524 }
525
526 /* Look at alternate creg names before giving error. */
527 for (i = 0; cregs[i].name[0] != '\0'; i++)
528 {
529 char buf [10];
530 int length;
531 int j;
532
533 length = strlen (cregs[i].name);
534
535 for (j = 0; j < length; j++)
536 buf[j] = TOLOWER (s[j]);
537
538 if (strncmp (cregs[i].name, buf, length) == 0)
539 {
540 *reg = cregs[i].crnum;
541 return s + length;
542 }
543 }
544
545 as_bad (_("control register expected, but saw '%.6s'"), s);
546
547 return s;
548 }
549
550 static char *
551 parse_psrmod (s, reg)
552 char * s;
553 unsigned * reg;
554 {
555 int i;
556 char buf[10];
557 static struct psrmods
558 {
559 char * name;
560 unsigned int value;
561 }
562 psrmods[] =
563 {
564 { "ie", 1 },
565 { "fe", 2 },
566 { "ee", 4 },
567 { "af", 8 } /* Really 0 and non-combinable. */
568 };
569
570 for (i = 0; i < 2; i++)
571 buf[i] = TOLOWER (s[i]);
572
573 for (i = sizeof (psrmods) / sizeof (psrmods[0]); i--;)
574 {
575 if (! strncmp (psrmods[i].name, buf, 2))
576 {
577 * reg = psrmods[i].value;
578
579 return s + 2;
580 }
581 }
582
583 as_bad (_("bad/missing psr specifier"));
584
585 * reg = 0;
586
587 return s;
588 }
589
590 static char *
591 parse_exp (s, e)
592 char * s;
593 expressionS * e;
594 {
595 char * save;
596 char * new;
597
598 /* Skip whitespace. */
599 while (ISSPACE (* s))
600 ++ s;
601
602 save = input_line_pointer;
603 input_line_pointer = s;
604
605 expression (e);
606
607 if (e->X_op == O_absent)
608 as_bad (_("missing operand"));
609
610 new = input_line_pointer;
611 input_line_pointer = save;
612
613 return new;
614 }
615
616 static void
617 make_name (s, p, n)
618 char * s;
619 char * p;
620 int n;
621 {
622 static const char hex[] = "0123456789ABCDEF";
623
624 s[0] = p[0];
625 s[1] = p[1];
626 s[2] = p[2];
627 s[3] = hex[(n >> 12) & 0xF];
628 s[4] = hex[(n >> 8) & 0xF];
629 s[5] = hex[(n >> 4) & 0xF];
630 s[6] = hex[(n) & 0xF];
631 s[7] = 0;
632 }
633
634 #define POOL_END_LABEL ".LE"
635 #define POOL_START_LABEL ".LS"
636
637 static void
638 dump_literals (isforce)
639 int isforce;
640 {
641 unsigned int i;
642 struct literal * p;
643 symbolS * brarsym = NULL;
644
645 if (poolsize == 0)
646 return;
647
648 /* Must we branch around the literal table? */
649 if (isforce)
650 {
651 char * output;
652 char brarname[8];
653
654 make_name (brarname, POOL_END_LABEL, poolnumber);
655
656 brarsym = symbol_make (brarname);
657
658 symbol_table_insert (brarsym);
659
660 output = frag_var (rs_machine_dependent,
661 md_relax_table[C (UNCD_JUMP, DISP32)].rlx_length,
662 md_relax_table[C (UNCD_JUMP, DISP12)].rlx_length,
663 C (UNCD_JUMP, 0), brarsym, 0, 0);
664 output[0] = INST_BYTE0 (MCORE_INST_BR); /* br .+xxx */
665 output[1] = INST_BYTE1 (MCORE_INST_BR);
666 }
667
668 /* Make sure that the section is sufficiently aligned and that
669 the literal table is aligned within it. */
670 record_alignment (now_seg, 2);
671 frag_align (2, 0, 0);
672
673 colon (S_GET_NAME (poolsym));
674
675 for (i = 0, p = litpool; i < poolsize; i++, p++)
676 emit_expr (& p->e, 4);
677
678 if (brarsym != NULL)
679 colon (S_GET_NAME (brarsym));
680
681 poolsize = 0;
682 }
683
684 static void
685 check_literals (kind, offset)
686 int kind;
687 int offset;
688 {
689 poolspan += offset;
690
691 /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC.
692 SPANPANIC means that we must dump now.
693 kind == 0 is any old instruction.
694 kind > 0 means we just had a control transfer instruction.
695 kind == 1 means within a function
696 kind == 2 means we just left a function
697
698 The dump_literals (1) call inserts a branch around the table, so
699 we first look to see if its a situation where we won't have to
700 insert a branch (e.g., the previous instruction was an unconditional
701 branch).
702
703 SPANPANIC is the point where we must dump a single-entry pool.
704 it accounts for alignments and an inserted branch.
705 the 'poolsize*2' accounts for the scenario where we do:
706 lrw r1,lit1; lrw r2,lit2; lrw r3,lit3
707 Note that the 'lit2' reference is 2 bytes further along
708 but the literal it references will be 4 bytes further along,
709 so we must consider the poolsize into this equation.
710 This is slightly over-cautious, but guarantees that we won't
711 panic because a relocation is too distant. */
712
713 if (poolspan > SPANCLOSE && kind > 0)
714 dump_literals (0);
715 else if (poolspan > SPANEXIT && kind > 1)
716 dump_literals (0);
717 else if (poolspan >= (SPANPANIC - poolsize * 2))
718 dump_literals (1);
719 }
720
721 static int
722 enter_literal (e, ispcrel)
723 expressionS * e;
724 int ispcrel;
725 {
726 unsigned int i;
727 struct literal * p;
728
729 if (poolsize >= MAX_POOL_SIZE - 2)
730 {
731 /* The literal pool is as full as we can handle. We have
732 to be 2 entries shy of the 1024/4=256 entries because we
733 have to allow for the branch (2 bytes) and the alignment
734 (2 bytes before the first insn referencing the pool and
735 2 bytes before the pool itself) == 6 bytes, rounds up
736 to 2 entries. */
737 dump_literals (1);
738 }
739
740 if (poolsize == 0)
741 {
742 /* Create new literal pool. */
743 if (++ poolnumber > 0xFFFF)
744 as_fatal (_("more than 65K literal pools"));
745
746 make_name (poolname, POOL_START_LABEL, poolnumber);
747 poolsym = symbol_make (poolname);
748 symbol_table_insert (poolsym);
749 poolspan = 0;
750 }
751
752 /* Search pool for value so we don't have duplicates. */
753 for (p = litpool, i = 0; i < poolsize; i++, p++)
754 {
755 if (e->X_op == p->e.X_op
756 && e->X_add_symbol == p->e.X_add_symbol
757 && e->X_add_number == p->e.X_add_number
758 && ispcrel == p->ispcrel)
759 {
760 p->refcnt ++;
761 return i;
762 }
763 }
764
765 p->refcnt = 1;
766 p->ispcrel = ispcrel;
767 p->e = * e;
768
769 poolsize ++;
770
771 return i;
772 }
773
774 /* Parse a literal specification. -- either new or old syntax.
775 old syntax: the user supplies the label and places the literal.
776 new syntax: we put it into the literal pool. */
777 static char *
778 parse_rt (s, outputp, ispcrel, ep)
779 char * s;
780 char ** outputp;
781 int ispcrel;
782 expressionS * ep;
783 {
784 expressionS e;
785 int n;
786
787 if (ep)
788 /* Indicate nothing there. */
789 ep->X_op = O_absent;
790
791 if (*s == '[')
792 {
793 s = parse_exp (s + 1, & e);
794
795 if (*s == ']')
796 s++;
797 else
798 as_bad (_("missing ']'"));
799 }
800 else
801 {
802 s = parse_exp (s, & e);
803
804 n = enter_literal (& e, ispcrel);
805
806 if (ep)
807 *ep = e;
808
809 /* Create a reference to pool entry. */
810 e.X_op = O_symbol;
811 e.X_add_symbol = poolsym;
812 e.X_add_number = n << 2;
813 }
814
815 * outputp = frag_more (2);
816
817 fix_new_exp (frag_now, (*outputp) - frag_now->fr_literal, 2, & e, 1,
818 BFD_RELOC_MCORE_PCREL_IMM8BY4);
819
820 return s;
821 }
822
823 static char *
824 parse_imm (s, val, min, max)
825 char * s;
826 unsigned * val;
827 unsigned min;
828 unsigned max;
829 {
830 char * new;
831 expressionS e;
832
833 new = parse_exp (s, & e);
834
835 if (e.X_op == O_absent)
836 ; /* An error message has already been emitted. */
837 else if (e.X_op != O_constant)
838 as_bad (_("operand must be a constant"));
839 else if ((addressT) e.X_add_number < min || (addressT) e.X_add_number > max)
840 as_bad (_("operand must be absolute in range %u..%u, not %ld"),
841 min, max, (long) e.X_add_number);
842
843 * val = e.X_add_number;
844
845 return new;
846 }
847
848 static char *
849 parse_mem (s, reg, off, siz)
850 char * s;
851 unsigned * reg;
852 unsigned * off;
853 unsigned siz;
854 {
855 * off = 0;
856
857 while (ISSPACE (* s))
858 ++ s;
859
860 if (* s == '(')
861 {
862 s = parse_reg (s + 1, reg);
863
864 while (ISSPACE (* s))
865 ++ s;
866
867 if (* s == ',')
868 {
869 s = parse_imm (s + 1, off, 0, 63);
870
871 if (siz > 1)
872 {
873 if (siz > 2)
874 {
875 if (* off & 0x3)
876 as_bad (_("operand must be a multiple of 4"));
877
878 * off >>= 2;
879 }
880 else
881 {
882 if (* off & 0x1)
883 as_bad (_("operand must be a multiple of 2"));
884
885 * off >>= 1;
886 }
887 }
888 }
889
890 while (ISSPACE (* s))
891 ++ s;
892
893 if (* s == ')')
894 s ++;
895 }
896 else
897 as_bad (_("base register expected"));
898
899 return s;
900 }
901
902 /* This is the guts of the machine-dependent assembler. STR points to a
903 machine dependent instruction. This function is supposed to emit
904 the frags/bytes it assembles to. */
905
906 void
907 md_assemble (str)
908 char * str;
909 {
910 char * op_start;
911 char * op_end;
912 mcore_opcode_info * opcode;
913 char * output;
914 int nlen = 0;
915 unsigned short inst;
916 unsigned reg;
917 unsigned off;
918 unsigned isize;
919 expressionS e;
920 char name[20];
921
922 /* Drop leading whitespace. */
923 while (ISSPACE (* str))
924 str ++;
925
926 /* Find the op code end. */
927 for (op_start = op_end = str;
928 nlen < 20 && !is_end_of_line [(unsigned char) *op_end] && *op_end != ' ';
929 op_end++)
930 {
931 name[nlen] = op_start[nlen];
932 nlen++;
933 }
934
935 name [nlen] = 0;
936
937 if (nlen == 0)
938 {
939 as_bad (_("can't find opcode "));
940 return;
941 }
942
943 opcode = (mcore_opcode_info *) hash_find (opcode_hash_control, name);
944 if (opcode == NULL)
945 {
946 as_bad (_("unknown opcode \"%s\""), name);
947 return;
948 }
949
950 inst = opcode->inst;
951 isize = 2;
952
953 switch (opcode->opclass)
954 {
955 case O0:
956 output = frag_more (2);
957 break;
958
959 case OT:
960 op_end = parse_imm (op_end + 1, & reg, 0, 3);
961 inst |= reg;
962 output = frag_more (2);
963 break;
964
965 case O1:
966 op_end = parse_reg (op_end + 1, & reg);
967 inst |= reg;
968 output = frag_more (2);
969 break;
970
971 case JMP:
972 op_end = parse_reg (op_end + 1, & reg);
973 inst |= reg;
974 output = frag_more (2);
975 /* In a sifilter mode, we emit this insn 2 times,
976 fixes problem of an interrupt during a jmp.. */
977 if (sifilter_mode)
978 {
979 output[0] = INST_BYTE0 (inst);
980 output[1] = INST_BYTE1 (inst);
981 output = frag_more (2);
982 }
983 break;
984
985 case JSR:
986 op_end = parse_reg (op_end + 1, & reg);
987
988 if (reg == 15)
989 as_bad (_("invalid register: r15 illegal"));
990
991 inst |= reg;
992 output = frag_more (2);
993
994 if (sifilter_mode)
995 {
996 /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */
997 inst = MCORE_INST_BSR; /* with 0 displacement */
998 output[0] = INST_BYTE0 (inst);
999 output[1] = INST_BYTE1 (inst);
1000
1001 output = frag_more (2);
1002 inst = MCORE_INST_ADDI;
1003 inst |= 15; /* addi r15,6 */
1004 inst |= (6 - 1) << 4; /* over the jmp's */
1005 output[0] = INST_BYTE0 (inst);
1006 output[1] = INST_BYTE1 (inst);
1007
1008 output = frag_more (2);
1009 inst = MCORE_INST_JMP | reg;
1010 output[0] = INST_BYTE0 (inst);
1011 output[1] = INST_BYTE1 (inst);
1012
1013 output = frag_more (2); /* 2nd emitted in fallthru */
1014 }
1015 break;
1016
1017 case OC:
1018 op_end = parse_reg (op_end + 1, & reg);
1019 inst |= reg;
1020
1021 /* Skip whitespace. */
1022 while (ISSPACE (* op_end))
1023 ++ op_end;
1024
1025 if (*op_end == ',')
1026 {
1027 op_end = parse_creg (op_end + 1, & reg);
1028 inst |= reg << 4;
1029 }
1030
1031 output = frag_more (2);
1032 break;
1033
1034 case MULSH:
1035 if (cpu == M210)
1036 {
1037 as_bad (_("M340 specific opcode used when assembling for M210"));
1038 break;
1039 }
1040 /* drop through... */
1041 case O2:
1042 op_end = parse_reg (op_end + 1, & reg);
1043 inst |= reg;
1044
1045 /* Skip whitespace. */
1046 while (ISSPACE (* op_end))
1047 ++ op_end;
1048
1049 if (* op_end == ',')
1050 {
1051 op_end = parse_reg (op_end + 1, & reg);
1052 inst |= reg << 4;
1053 }
1054 else
1055 as_bad (_("second operand missing"));
1056
1057 output = frag_more (2);
1058 break;
1059
1060 case X1: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */
1061 op_end = parse_reg (op_end + 1, & reg);
1062
1063 /* Skip whitespace. */
1064 while (ISSPACE (* op_end))
1065 ++ op_end;
1066
1067 if (* op_end == ',') /* xtrb- r1,rx */
1068 {
1069 if (reg != 1)
1070 as_bad (_("destination register must be r1"));
1071
1072 op_end = parse_reg (op_end + 1, & reg);
1073 }
1074
1075 inst |= reg;
1076 output = frag_more (2);
1077 break;
1078
1079 case O1R1: /* div- rx,r1 */
1080 op_end = parse_reg (op_end + 1, & reg);
1081 inst |= reg;
1082
1083 /* Skip whitespace. */
1084 while (ISSPACE (* op_end))
1085 ++ op_end;
1086
1087 if (* op_end == ',')
1088 {
1089 op_end = parse_reg (op_end + 1, & reg);
1090 if (reg != 1)
1091 as_bad (_("source register must be r1"));
1092 }
1093 else
1094 as_bad (_("second operand missing"));
1095
1096 output = frag_more (2);
1097 break;
1098
1099 case OI:
1100 op_end = parse_reg (op_end + 1, & reg);
1101 inst |= reg;
1102
1103 /* Skip whitespace. */
1104 while (ISSPACE (* op_end))
1105 ++ op_end;
1106
1107 if (* op_end == ',')
1108 {
1109 op_end = parse_imm (op_end + 1, & reg, 1, 32);
1110 inst |= (reg - 1) << 4;
1111 }
1112 else
1113 as_bad (_("second operand missing"));
1114
1115 output = frag_more (2);
1116 break;
1117
1118 case OB:
1119 op_end = parse_reg (op_end + 1, & reg);
1120 inst |= reg;
1121
1122 /* Skip whitespace. */
1123 while (ISSPACE (* op_end))
1124 ++ op_end;
1125
1126 if (* op_end == ',')
1127 {
1128 op_end = parse_imm (op_end + 1, & reg, 0, 31);
1129 inst |= reg << 4;
1130 }
1131 else
1132 as_bad (_("second operand missing"));
1133
1134 output = frag_more (2);
1135 break;
1136
1137 case OB2: /* like OB, but arg is 2^n instead of n */
1138 op_end = parse_reg (op_end + 1, & reg);
1139 inst |= reg;
1140
1141 /* Skip whitespace. */
1142 while (ISSPACE (* op_end))
1143 ++ op_end;
1144
1145 if (* op_end == ',')
1146 {
1147 op_end = parse_imm (op_end + 1, & reg, 1, 1 << 31);
1148 /* Further restrict the immediate to a power of two. */
1149 if ((reg & (reg - 1)) == 0)
1150 reg = mylog2 (reg);
1151 else
1152 {
1153 reg = 0;
1154 as_bad (_("immediate is not a power of two"));
1155 }
1156 inst |= (reg) << 4;
1157 }
1158 else
1159 as_bad (_("second operand missing"));
1160
1161 output = frag_more (2);
1162 break;
1163
1164 case OBRa: /* Specific for bgeni: imm of 0->6 translate to movi. */
1165 case OBRb:
1166 case OBRc:
1167 op_end = parse_reg (op_end + 1, & reg);
1168 inst |= reg;
1169
1170 /* Skip whitespace. */
1171 while (ISSPACE (* op_end))
1172 ++ op_end;
1173
1174 if (* op_end == ',')
1175 {
1176 op_end = parse_imm (op_end + 1, & reg, 0, 31);
1177 /* immediate values of 0 -> 6 translate to movi */
1178 if (reg <= 6)
1179 {
1180 inst = (inst & 0xF) | MCORE_INST_BGENI_ALT;
1181 reg = 0x1 << reg;
1182 as_warn (_("translating bgeni to movi"));
1183 }
1184 inst &= ~ 0x01f0;
1185 inst |= reg << 4;
1186 }
1187 else
1188 as_bad (_("second operand missing"));
1189
1190 output = frag_more (2);
1191 break;
1192
1193 case OBR2: /* like OBR, but arg is 2^n instead of n */
1194 op_end = parse_reg (op_end + 1, & reg);
1195 inst |= reg;
1196
1197 /* Skip whitespace. */
1198 while (ISSPACE (* op_end))
1199 ++ op_end;
1200
1201 if (* op_end == ',')
1202 {
1203 op_end = parse_imm (op_end + 1, & reg, 1, 1 << 31);
1204
1205 /* Further restrict the immediate to a power of two. */
1206 if ((reg & (reg - 1)) == 0)
1207 reg = mylog2 (reg);
1208 else
1209 {
1210 reg = 0;
1211 as_bad (_("immediate is not a power of two"));
1212 }
1213
1214 /* Immediate values of 0 -> 6 translate to movi. */
1215 if (reg <= 6)
1216 {
1217 inst = (inst & 0xF) | MCORE_INST_BGENI_ALT;
1218 reg = 0x1 << reg;
1219 as_warn (_("translating mgeni to movi"));
1220 }
1221
1222 inst |= reg << 4;
1223 }
1224 else
1225 as_bad (_("second operand missing"));
1226
1227 output = frag_more (2);
1228 break;
1229
1230 case OMa: /* Specific for bmaski: imm 1->7 translate to movi. */
1231 case OMb:
1232 case OMc:
1233 op_end = parse_reg (op_end + 1, & reg);
1234 inst |= reg;
1235
1236 /* Skip whitespace. */
1237 while (ISSPACE (* op_end))
1238 ++ op_end;
1239
1240 if (* op_end == ',')
1241 {
1242 op_end = parse_imm (op_end + 1, & reg, 1, 32);
1243
1244 /* Immediate values of 1 -> 7 translate to movi. */
1245 if (reg <= 7)
1246 {
1247 inst = (inst & 0xF) | MCORE_INST_BMASKI_ALT;
1248 reg = (0x1 << reg) - 1;
1249 inst |= reg << 4;
1250
1251 as_warn (_("translating bmaski to movi"));
1252 }
1253 else
1254 {
1255 inst &= ~ 0x01F0;
1256 inst |= (reg & 0x1F) << 4;
1257 }
1258 }
1259 else
1260 as_bad (_("second operand missing"));
1261
1262 output = frag_more (2);
1263 break;
1264
1265 case SI:
1266 op_end = parse_reg (op_end + 1, & reg);
1267 inst |= reg;
1268
1269 /* Skip whitespace. */
1270 while (ISSPACE (* op_end))
1271 ++ op_end;
1272
1273 if (* op_end == ',')
1274 {
1275 op_end = parse_imm (op_end + 1, & reg, 1, 31);
1276 inst |= reg << 4;
1277 }
1278 else
1279 as_bad (_("second operand missing"));
1280
1281 output = frag_more (2);
1282 break;
1283
1284 case I7:
1285 op_end = parse_reg (op_end + 1, & reg);
1286 inst |= reg;
1287
1288 /* Skip whitespace. */
1289 while (ISSPACE (* op_end))
1290 ++ op_end;
1291
1292 if (* op_end == ',')
1293 {
1294 op_end = parse_imm (op_end + 1, & reg, 0, 0x7F);
1295 inst |= reg << 4;
1296 }
1297 else
1298 as_bad (_("second operand missing"));
1299
1300 output = frag_more (2);
1301 break;
1302
1303 case LS:
1304 op_end = parse_reg (op_end + 1, & reg);
1305 inst |= reg << 8;
1306
1307 /* Skip whitespace. */
1308 while (ISSPACE (* op_end))
1309 ++ op_end;
1310
1311 if (* op_end == ',')
1312 {
1313 int size;
1314
1315 if ((inst & 0x6000) == 0)
1316 size = 4;
1317 else if ((inst & 0x6000) == 0x4000)
1318 size = 2;
1319 else if ((inst & 0x6000) == 0x2000)
1320 size = 1;
1321 else
1322 abort ();
1323
1324 op_end = parse_mem (op_end + 1, & reg, & off, size);
1325
1326 if (off > 16)
1327 as_bad (_("displacement too large (%d)"), off);
1328 else
1329 inst |= (reg) | (off << 4);
1330 }
1331 else
1332 as_bad (_("second operand missing"));
1333
1334 output = frag_more (2);
1335 break;
1336
1337 case LR:
1338 op_end = parse_reg (op_end + 1, & reg);
1339
1340 if (reg == 0 || reg == 15)
1341 as_bad (_("Invalid register: r0 and r15 illegal"));
1342
1343 inst |= (reg << 8);
1344
1345 /* Skip whitespace. */
1346 while (ISSPACE (* op_end))
1347 ++ op_end;
1348
1349 if (* op_end == ',')
1350 {
1351 /* parse_rt calls frag_more() for us. */
1352 input_line_pointer = parse_rt (op_end + 1, & output, 0, 0);
1353 op_end = input_line_pointer;
1354 }
1355 else
1356 {
1357 as_bad (_("second operand missing"));
1358 output = frag_more (2); /* save its space */
1359 }
1360 break;
1361
1362 case LJ:
1363 input_line_pointer = parse_rt (op_end + 1, & output, 1, 0);
1364 /* parse_rt() calls frag_more() for us. */
1365 op_end = input_line_pointer;
1366 break;
1367
1368 case RM:
1369 op_end = parse_reg (op_end + 1, & reg);
1370
1371 if (reg == 0 || reg == 15)
1372 as_bad (_("bad starting register: r0 and r15 invalid"));
1373
1374 inst |= reg;
1375
1376 /* Skip whitespace. */
1377 while (ISSPACE (* op_end))
1378 ++ op_end;
1379
1380 if (* op_end == '-')
1381 {
1382 op_end = parse_reg (op_end + 1, & reg);
1383
1384 if (reg != 15)
1385 as_bad (_("ending register must be r15"));
1386
1387 /* Skip whitespace. */
1388 while (ISSPACE (* op_end))
1389 ++ op_end;
1390 }
1391
1392 if (* op_end == ',')
1393 {
1394 op_end ++;
1395
1396 /* Skip whitespace. */
1397 while (ISSPACE (* op_end))
1398 ++ op_end;
1399
1400 if (* op_end == '(')
1401 {
1402 op_end = parse_reg (op_end + 1, & reg);
1403
1404 if (reg != 0)
1405 as_bad (_("bad base register: must be r0"));
1406
1407 if (* op_end == ')')
1408 op_end ++;
1409 }
1410 else
1411 as_bad (_("base register expected"));
1412 }
1413 else
1414 as_bad (_("second operand missing"));
1415
1416 output = frag_more (2);
1417 break;
1418
1419 case RQ:
1420 op_end = parse_reg (op_end + 1, & reg);
1421
1422 if (reg != 4)
1423 as_fatal (_("first register must be r4"));
1424
1425 /* Skip whitespace. */
1426 while (ISSPACE (* op_end))
1427 ++ op_end;
1428
1429 if (* op_end == '-')
1430 {
1431 op_end = parse_reg (op_end + 1, & reg);
1432
1433 if (reg != 7)
1434 as_fatal (_("last register must be r7"));
1435
1436 /* Skip whitespace. */
1437 while (ISSPACE (* op_end))
1438 ++ op_end;
1439
1440 if (* op_end == ',')
1441 {
1442 op_end ++;
1443
1444 /* Skip whitespace. */
1445 while (ISSPACE (* op_end))
1446 ++ op_end;
1447
1448 if (* op_end == '(')
1449 {
1450 op_end = parse_reg (op_end + 1, & reg);
1451
1452 if (reg >= 4 && reg <= 7)
1453 as_fatal ("base register cannot be r4, r5, r6, or r7");
1454
1455 inst |= reg;
1456
1457 /* Skip whitespace. */
1458 while (ISSPACE (* op_end))
1459 ++ op_end;
1460
1461 if (* op_end == ')')
1462 op_end ++;
1463 }
1464 else
1465 as_bad (_("base register expected"));
1466 }
1467 else
1468 as_bad (_("second operand missing"));
1469 }
1470 else
1471 as_bad (_("reg-reg expected"));
1472
1473 output = frag_more (2);
1474 break;
1475
1476 case BR:
1477 input_line_pointer = parse_exp (op_end + 1, & e);
1478 op_end = input_line_pointer;
1479
1480 output = frag_more (2);
1481
1482 fix_new_exp (frag_now, output-frag_now->fr_literal,
1483 2, & e, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2);
1484 break;
1485
1486 case BL:
1487 op_end = parse_reg (op_end + 1, & reg);
1488 inst |= reg << 4;
1489
1490 /* Skip whitespace. */
1491 while (ISSPACE (* op_end))
1492 ++ op_end;
1493
1494 if (* op_end == ',')
1495 {
1496 op_end = parse_exp (op_end + 1, & e);
1497 output = frag_more (2);
1498
1499 fix_new_exp (frag_now, output-frag_now->fr_literal,
1500 2, & e, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2);
1501 }
1502 else
1503 {
1504 as_bad (_("second operand missing"));
1505 output = frag_more (2);
1506 }
1507 break;
1508
1509 case JC:
1510 input_line_pointer = parse_exp (op_end + 1, & e);
1511 op_end = input_line_pointer;
1512
1513 output = frag_var (rs_machine_dependent,
1514 md_relax_table[C (COND_JUMP, DISP32)].rlx_length,
1515 md_relax_table[C (COND_JUMP, DISP12)].rlx_length,
1516 C (COND_JUMP, 0), e.X_add_symbol, e.X_add_number, 0);
1517 isize = C32_LEN;
1518 break;
1519
1520 case JU:
1521 input_line_pointer = parse_exp (op_end + 1, & e);
1522 op_end = input_line_pointer;
1523
1524 output = frag_var (rs_machine_dependent,
1525 md_relax_table[C (UNCD_JUMP, DISP32)].rlx_length,
1526 md_relax_table[C (UNCD_JUMP, DISP12)].rlx_length,
1527 C (UNCD_JUMP, 0), e.X_add_symbol, e.X_add_number, 0);
1528 isize = U32_LEN;
1529 break;
1530
1531 case JL:
1532 inst = MCORE_INST_JSRI; /* jsri */
1533 input_line_pointer = parse_rt (op_end + 1, & output, 1, & e);
1534 /* parse_rt() calls frag_more for us. */
1535 op_end = input_line_pointer;
1536
1537 /* Only do this if we know how to do it ... */
1538 if (e.X_op != O_absent && do_jsri2bsr)
1539 {
1540 /* Look at adding the R_PCREL_JSRIMM11BY2. */
1541 fix_new_exp (frag_now, output-frag_now->fr_literal,
1542 2, & e, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2);
1543 }
1544 break;
1545
1546 case RSI: /* SI, but imm becomes 32-imm */
1547 op_end = parse_reg (op_end + 1, & reg);
1548 inst |= reg;
1549
1550 /* Skip whitespace. */
1551 while (ISSPACE (* op_end))
1552 ++ op_end;
1553
1554 if (* op_end == ',')
1555 {
1556 op_end = parse_imm (op_end + 1, & reg, 1, 31);
1557
1558 reg = 32 - reg;
1559 inst |= reg << 4;
1560 }
1561 else
1562 as_bad (_("second operand missing"));
1563
1564 output = frag_more (2);
1565 break;
1566
1567 case DO21: /* O2, dup rd, lit must be 1 */
1568 op_end = parse_reg (op_end + 1, & reg);
1569 inst |= reg;
1570 inst |= reg << 4;
1571
1572 /* Skip whitespace. */
1573 while (ISSPACE (* op_end))
1574 ++ op_end;
1575
1576 if (* op_end == ',')
1577 {
1578 op_end = parse_imm (op_end + 1, & reg, 1, 31);
1579
1580 if (reg != 1)
1581 as_bad (_("second operand must be 1"));
1582 }
1583 else
1584 as_bad (_("second operand missing"));
1585
1586 output = frag_more (2);
1587 break;
1588
1589 case SIa:
1590 op_end = parse_reg (op_end + 1, & reg);
1591 inst |= reg;
1592
1593 /* Skip whitespace. */
1594 while (ISSPACE (* op_end))
1595 ++ op_end;
1596
1597 if (* op_end == ',')
1598 {
1599 op_end = parse_imm (op_end + 1, & reg, 1, 31);
1600
1601 if (reg == 0)
1602 as_bad (_("zero used as immediate value"));
1603
1604 inst |= reg << 4;
1605 }
1606 else
1607 as_bad (_("second operand missing"));
1608
1609 output = frag_more (2);
1610 break;
1611
1612 case OPSR:
1613 if (cpu == M210)
1614 {
1615 as_bad (_("M340 specific opcode used when assembling for M210"));
1616 break;
1617 }
1618
1619 op_end = parse_psrmod (op_end + 1, & reg);
1620
1621 /* Look for further selectors. */
1622 while (* op_end == ',')
1623 {
1624 unsigned value;
1625
1626 op_end = parse_psrmod (op_end + 1, & value);
1627
1628 if (value & reg)
1629 as_bad (_("duplicated psr bit specifier"));
1630
1631 reg |= value;
1632 }
1633
1634 if (reg > 8)
1635 as_bad (_("`af' must appear alone"));
1636
1637 inst |= (reg & 0x7);
1638 output = frag_more (2);
1639 break;
1640
1641 default:
1642 as_bad (_("unimplemented opcode \"%s\""), name);
1643 }
1644
1645 /* Drop whitespace after all the operands have been parsed. */
1646 while (ISSPACE (* op_end))
1647 op_end ++;
1648
1649 /* Give warning message if the insn has more operands than required. */
1650 if (strcmp (op_end, opcode->name) && strcmp (op_end, ""))
1651 as_warn (_("ignoring operands: %s "), op_end);
1652
1653 output[0] = INST_BYTE0 (inst);
1654 output[1] = INST_BYTE1 (inst);
1655
1656 check_literals (opcode->transfer, isize);
1657 }
1658
1659 symbolS *
1660 md_undefined_symbol (name)
1661 char *name ATTRIBUTE_UNUSED;
1662 {
1663 return 0;
1664 }
1665
1666 void
1667 md_mcore_end ()
1668 {
1669 dump_literals (0);
1670 subseg_set (text_section, 0);
1671 }
1672
1673 /* Various routines to kill one day. */
1674 /* Equal to MAX_PRECISION in atof-ieee.c */
1675 #define MAX_LITTLENUMS 6
1676
1677 /* Turn a string in input_line_pointer into a floating point constant of type
1678 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1679 emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/
1680 char *
1681 md_atof (type, litP, sizeP)
1682 int type;
1683 char * litP;
1684 int * sizeP;
1685 {
1686 int prec;
1687 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1688 int i;
1689 char * t;
1690
1691 switch (type)
1692 {
1693 case 'f':
1694 case 'F':
1695 case 's':
1696 case 'S':
1697 prec = 2;
1698 break;
1699
1700 case 'd':
1701 case 'D':
1702 case 'r':
1703 case 'R':
1704 prec = 4;
1705 break;
1706
1707 case 'x':
1708 case 'X':
1709 prec = 6;
1710 break;
1711
1712 case 'p':
1713 case 'P':
1714 prec = 6;
1715 break;
1716
1717 default:
1718 *sizeP = 0;
1719 return _("Bad call to MD_NTOF()");
1720 }
1721
1722 t = atof_ieee (input_line_pointer, type, words);
1723
1724 if (t)
1725 input_line_pointer = t;
1726
1727 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1728
1729 if (! target_big_endian)
1730 {
1731 for (i = prec - 1; i >= 0; i--)
1732 {
1733 md_number_to_chars (litP, (valueT) words[i],
1734 sizeof (LITTLENUM_TYPE));
1735 litP += sizeof (LITTLENUM_TYPE);
1736 }
1737 }
1738 else
1739 for (i = 0; i < prec; i++)
1740 {
1741 md_number_to_chars (litP, (valueT) words[i],
1742 sizeof (LITTLENUM_TYPE));
1743 litP += sizeof (LITTLENUM_TYPE);
1744 }
1745
1746 return 0;
1747 }
1748 \f
1749 const char * md_shortopts = "";
1750
1751 #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0)
1752 #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1)
1753 #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2)
1754 #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3)
1755 #define OPTION_CPU (OPTION_MD_BASE + 4)
1756 #define OPTION_EB (OPTION_MD_BASE + 5)
1757 #define OPTION_EL (OPTION_MD_BASE + 6)
1758
1759 struct option md_longopts[] =
1760 {
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 { "cpu", required_argument, NULL, OPTION_CPU},
1766 { "EB", no_argument, NULL, OPTION_EB},
1767 { "EL", no_argument, NULL, OPTION_EL},
1768 { NULL, no_argument, NULL, 0}
1769 };
1770
1771 size_t md_longopts_size = sizeof (md_longopts);
1772
1773 int
1774 md_parse_option (c, arg)
1775 int c;
1776 char * arg;
1777 {
1778 switch (c)
1779 {
1780 case OPTION_CPU:
1781 if (streq (arg, "210"))
1782 {
1783 cpu = M210;
1784 target_big_endian = 1;
1785 }
1786 else if (streq (arg, "340"))
1787 cpu = M340;
1788 else
1789 as_warn (_("unrecognised cpu type '%s'"), arg);
1790 break;
1791
1792 case OPTION_EB: target_big_endian = 1; break;
1793 case OPTION_EL: target_big_endian = 0; cpu = M340; break;
1794 case OPTION_JSRI2BSR_ON: do_jsri2bsr = 1; break;
1795 case OPTION_JSRI2BSR_OFF: do_jsri2bsr = 0; break;
1796 case OPTION_SIFILTER_ON: sifilter_mode = 1; break;
1797 case OPTION_SIFILTER_OFF: sifilter_mode = 0; break;
1798 default: return 0;
1799 }
1800
1801 return 1;
1802 }
1803
1804 void
1805 md_show_usage (stream)
1806 FILE * stream;
1807 {
1808 fprintf (stream, _("\
1809 MCORE specific options:\n\
1810 -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\
1811 -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\
1812 -cpu=[210|340] select CPU type\n\
1813 -EB assemble for a big endian system (default)\n\
1814 -EL assemble for a little endian system\n"));
1815 }
1816 \f
1817 int md_short_jump_size;
1818
1819 void
1820 md_create_short_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol)
1821 char * ptr ATTRIBUTE_UNUSED;
1822 addressT from_Nddr ATTRIBUTE_UNUSED;
1823 addressT to_Nddr ATTRIBUTE_UNUSED;
1824 fragS * frag ATTRIBUTE_UNUSED;
1825 symbolS * to_symbol ATTRIBUTE_UNUSED;
1826 {
1827 as_fatal (_("failed sanity check: short_jump"));
1828 }
1829
1830 void
1831 md_create_long_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol)
1832 char * ptr ATTRIBUTE_UNUSED;
1833 addressT from_Nddr ATTRIBUTE_UNUSED;
1834 addressT to_Nddr ATTRIBUTE_UNUSED;
1835 fragS * frag ATTRIBUTE_UNUSED;
1836 symbolS * to_symbol ATTRIBUTE_UNUSED;
1837 {
1838 as_fatal (_("failed sanity check: long_jump"));
1839 }
1840
1841 /* Called after relaxing, change the frags so they know how big they are. */
1842 void
1843 md_convert_frag (abfd, sec, fragP)
1844 bfd * abfd ATTRIBUTE_UNUSED;
1845 segT sec ATTRIBUTE_UNUSED;
1846 register fragS * fragP;
1847 {
1848 unsigned char * buffer;
1849 int targ_addr = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset;
1850
1851 buffer = (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1852
1853 switch (fragP->fr_subtype)
1854 {
1855 case C (COND_JUMP, DISP12):
1856 case C (UNCD_JUMP, DISP12):
1857 {
1858 /* Get the address of the end of the instruction. */
1859 int next_inst = fragP->fr_fix + fragP->fr_address + 2;
1860 unsigned char t0;
1861 int disp = targ_addr - next_inst;
1862
1863 if (disp & 1)
1864 as_bad (_("odd displacement at %x"), next_inst - 2);
1865
1866 disp >>= 1;
1867
1868 if (! target_big_endian)
1869 {
1870 t0 = buffer[1] & 0xF8;
1871
1872 md_number_to_chars (buffer, disp, 2);
1873
1874 buffer[1] = (buffer[1] & 0x07) | t0;
1875 }
1876 else
1877 {
1878 t0 = buffer[0] & 0xF8;
1879
1880 md_number_to_chars (buffer, disp, 2);
1881
1882 buffer[0] = (buffer[0] & 0x07) | t0;
1883 }
1884
1885 fragP->fr_fix += 2;
1886 }
1887 break;
1888
1889 case C (COND_JUMP, DISP32):
1890 case C (COND_JUMP, UNDEF_WORD_DISP):
1891 {
1892 /* A conditional branch wont fit into 12 bits so:
1893 * b!cond 1f
1894 * jmpi 0f
1895 * .align 2
1896 * 0: .long disp
1897 * 1:
1898 *
1899 * if the b!cond is 4 byte aligned, the literal which would
1900 * go at x+4 will also be aligned.
1901 */
1902 int first_inst = fragP->fr_fix + fragP->fr_address;
1903 int needpad = (first_inst & 3);
1904
1905 if (! target_big_endian)
1906 buffer[1] ^= 0x08;
1907 else
1908 buffer[0] ^= 0x08; /* Toggle T/F bit */
1909
1910 buffer[2] = INST_BYTE0 (MCORE_INST_JMPI); /* Build jmpi */
1911 buffer[3] = INST_BYTE1 (MCORE_INST_JMPI);
1912
1913 if (needpad)
1914 {
1915 if (! target_big_endian)
1916 {
1917 buffer[0] = 4; /* branch over jmpi, pad, and ptr */
1918 buffer[2] = 1; /* jmpi offset of 1 gets the pointer */
1919 }
1920 else
1921 {
1922 buffer[1] = 4; /* branch over jmpi, pad, and ptr */
1923 buffer[3] = 1; /* jmpi offset of 1 gets the pointer */
1924 }
1925
1926 buffer[4] = 0; /* alignment/pad */
1927 buffer[5] = 0;
1928 buffer[6] = 0; /* space for 32 bit address */
1929 buffer[7] = 0;
1930 buffer[8] = 0;
1931 buffer[9] = 0;
1932
1933 /* Make reloc for the long disp */
1934 fix_new (fragP, fragP->fr_fix + 6, 4,
1935 fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32);
1936
1937 fragP->fr_fix += C32_LEN;
1938 }
1939 else
1940 {
1941 /* See comment below about this given gas' limitations for
1942 shrinking the fragment. '3' is the amount of code that
1943 we inserted here, but '4' is right for the space we reserved
1944 for this fragment. */
1945 if (! target_big_endian)
1946 {
1947 buffer[0] = 3; /* branch over jmpi, and ptr */
1948 buffer[2] = 0; /* jmpi offset of 0 gets the pointer */
1949 }
1950 else
1951 {
1952 buffer[1] = 3; /* branch over jmpi, and ptr */
1953 buffer[3] = 0; /* jmpi offset of 0 gets the pointer */
1954 }
1955
1956 buffer[4] = 0; /* space for 32 bit address */
1957 buffer[5] = 0;
1958 buffer[6] = 0;
1959 buffer[7] = 0;
1960
1961 /* Make reloc for the long disp. */
1962 fix_new (fragP, fragP->fr_fix + 4, 4,
1963 fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32);
1964 fragP->fr_fix += C32_LEN;
1965
1966 /* Frag is actually shorter (see the other side of this ifdef)
1967 but gas isn't prepared for that. We have to re-adjust
1968 the branch displacement so that it goes beyond the
1969 full length of the fragment, not just what we actually
1970 filled in. */
1971 if (! target_big_endian)
1972 buffer[0] = 4; /* jmpi, ptr, and the 'tail pad' */
1973 else
1974 buffer[1] = 4; /* jmpi, ptr, and the 'tail pad' */
1975 }
1976 }
1977 break;
1978
1979 case C (UNCD_JUMP, DISP32):
1980 case C (UNCD_JUMP, UNDEF_WORD_DISP):
1981 {
1982 /* An unconditional branch will not fit in 12 bits, make code which
1983 looks like:
1984 jmpi 0f
1985 .align 2
1986 0: .long disp
1987 we need a pad if "first_inst" is 4 byte aligned.
1988 [because the natural literal place is x + 2] */
1989 int first_inst = fragP->fr_fix + fragP->fr_address;
1990 int needpad = !(first_inst & 3);
1991
1992 buffer[0] = INST_BYTE0 (MCORE_INST_JMPI); /* Build jmpi */
1993 buffer[1] = INST_BYTE1 (MCORE_INST_JMPI);
1994
1995 if (needpad)
1996 {
1997 if (! target_big_endian)
1998 buffer[0] = 1; /* jmpi offset of 1 since padded */
1999 else
2000 buffer[1] = 1; /* jmpi offset of 1 since padded */
2001 buffer[2] = 0; /* alignment */
2002 buffer[3] = 0;
2003 buffer[4] = 0; /* space for 32 bit address */
2004 buffer[5] = 0;
2005 buffer[6] = 0;
2006 buffer[7] = 0;
2007
2008 /* Make reloc for the long disp. */
2009 fix_new (fragP, fragP->fr_fix + 4, 4,
2010 fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32);
2011
2012 fragP->fr_fix += U32_LEN;
2013 }
2014 else
2015 {
2016 if (! target_big_endian)
2017 buffer[0] = 0; /* jmpi offset of 0 if no pad */
2018 else
2019 buffer[1] = 0; /* jmpi offset of 0 if no pad */
2020 buffer[2] = 0; /* space for 32 bit address */
2021 buffer[3] = 0;
2022 buffer[4] = 0;
2023 buffer[5] = 0;
2024
2025 /* Make reloc for the long disp. */
2026 fix_new (fragP, fragP->fr_fix + 2, 4,
2027 fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32);
2028 fragP->fr_fix += U32_LEN;
2029 }
2030 }
2031 break;
2032
2033 default:
2034 abort ();
2035 }
2036 }
2037
2038 /* Applies the desired value to the specified location.
2039 Also sets up addends for 'rela' type relocations. */
2040
2041 void
2042 md_apply_fix3 (fixP, valP, segment)
2043 fixS * fixP;
2044 valueT * valP;
2045 segT segment ATTRIBUTE_UNUSED;
2046 {
2047 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2048 char * file = fixP->fx_file ? fixP->fx_file : _("unknown");
2049 const char * symname;
2050 /* Note: use offsetT because it is signed, valueT is unsigned. */
2051 offsetT val = *valP;
2052
2053 symname = fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : _("<unknown>");
2054 /* Save this for the addend in the relocation record. */
2055 fixP->fx_addnumber = val;
2056
2057 if (fixP->fx_addsy != NULL)
2058 {
2059 #ifdef OBJ_ELF
2060 /* For ELF we can just return and let the reloc that will be generated
2061 take care of everything. For COFF we still have to insert 'val'
2062 into the insn since the addend field will be ignored. */
2063 return;
2064 #endif
2065 }
2066 else
2067 fixP->fx_done = 1;
2068
2069 switch (fixP->fx_r_type)
2070 {
2071 case BFD_RELOC_MCORE_PCREL_IMM11BY2: /* second byte of 2 byte opcode */
2072 if ((val & 1) != 0)
2073 as_bad_where (file, fixP->fx_line,
2074 _("odd distance branch (0x%lx bytes)"), (long) val);
2075 val /= 2;
2076 if (((val & ~0x3ff) != 0) && ((val | 0x3ff) != -1))
2077 as_bad_where (file, fixP->fx_line,
2078 _("pcrel for branch to %s too far (0x%lx)"),
2079 symname, (long) val);
2080 if (target_big_endian)
2081 {
2082 buf[0] |= ((val >> 8) & 0x7);
2083 buf[1] |= (val & 0xff);
2084 }
2085 else
2086 {
2087 buf[1] |= ((val >> 8) & 0x7);
2088 buf[0] |= (val & 0xff);
2089 }
2090 break;
2091
2092 case BFD_RELOC_MCORE_PCREL_IMM8BY4: /* lower 8 bits of 2 byte opcode */
2093 val += 3;
2094 val /= 4;
2095 if (val & ~0xff)
2096 as_bad_where (file, fixP->fx_line,
2097 _("pcrel for lrw/jmpi/jsri to %s too far (0x%lx)"),
2098 symname, (long) val);
2099 else if (! target_big_endian)
2100 buf[0] |= (val & 0xff);
2101 else
2102 buf[1] |= (val & 0xff);
2103 break;
2104
2105 case BFD_RELOC_MCORE_PCREL_IMM4BY2: /* loopt instruction */
2106 if ((val < -32) || (val > -2))
2107 as_bad_where (file, fixP->fx_line,
2108 _("pcrel for loopt too far (0x%lx)"), (long) val);
2109 val /= 2;
2110 if (! target_big_endian)
2111 buf[0] |= (val & 0xf);
2112 else
2113 buf[1] |= (val & 0xf);
2114 break;
2115
2116 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2:
2117 /* Conditional linker map jsri to bsr. */
2118 /* If its a local target and close enough, fix it.
2119 NB: >= -2k for backwards bsr; < 2k for forwards... */
2120 if (fixP->fx_addsy == 0 && val >= -2048 && val < 2048)
2121 {
2122 long nval = (val / 2) & 0x7ff;
2123 nval |= MCORE_INST_BSR;
2124
2125 /* REPLACE the instruction, don't just modify it. */
2126 buf[0] = INST_BYTE0 (nval);
2127 buf[1] = INST_BYTE1 (nval);
2128 }
2129 else
2130 fixP->fx_done = 0;
2131 break;
2132
2133 case BFD_RELOC_MCORE_PCREL_32:
2134 case BFD_RELOC_VTABLE_INHERIT:
2135 case BFD_RELOC_VTABLE_ENTRY:
2136 fixP->fx_done = 0;
2137 break;
2138
2139 default:
2140 if (fixP->fx_addsy != NULL)
2141 {
2142 /* If the fix is an absolute reloc based on a symbol's
2143 address, then it cannot be resolved until the final link. */
2144 fixP->fx_done = 0;
2145 }
2146 #ifdef OBJ_ELF
2147 else
2148 #endif
2149 {
2150 if (fixP->fx_size == 4)
2151 ;
2152 else if (fixP->fx_size == 2 && val >= -32768 && val <= 32767)
2153 ;
2154 else if (fixP->fx_size == 1 && val >= -256 && val <= 255)
2155 ;
2156 else
2157 abort ();
2158 md_number_to_chars (buf, val, fixP->fx_size);
2159 }
2160 break;
2161 }
2162 }
2163
2164 void
2165 md_operand (expressionP)
2166 expressionS * expressionP;
2167 {
2168 /* Ignore leading hash symbol, if poresent. */
2169 if (* input_line_pointer == '#')
2170 {
2171 input_line_pointer ++;
2172 expression (expressionP);
2173 }
2174 }
2175
2176 int md_long_jump_size;
2177
2178 /* Called just before address relaxation, return the length
2179 by which a fragment must grow to reach it's destination. */
2180 int
2181 md_estimate_size_before_relax (fragP, segment_type)
2182 register fragS * fragP;
2183 register segT segment_type;
2184 {
2185 switch (fragP->fr_subtype)
2186 {
2187 default:
2188 abort ();
2189
2190 case C (UNCD_JUMP, UNDEF_DISP):
2191 /* Used to be a branch to somewhere which was unknown. */
2192 if (!fragP->fr_symbol)
2193 {
2194 fragP->fr_subtype = C (UNCD_JUMP, DISP12);
2195 }
2196 else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2197 {
2198 fragP->fr_subtype = C (UNCD_JUMP, DISP12);
2199 }
2200 else
2201 {
2202 fragP->fr_subtype = C (UNCD_JUMP, UNDEF_WORD_DISP);
2203 }
2204 break;
2205
2206 case C (COND_JUMP, UNDEF_DISP):
2207 /* Used to be a branch to somewhere which was unknown. */
2208 if (fragP->fr_symbol
2209 && S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2210 {
2211 /* Got a symbol and it's defined in this segment, become byte
2212 sized - maybe it will fix up */
2213 fragP->fr_subtype = C (COND_JUMP, DISP12);
2214 }
2215 else if (fragP->fr_symbol)
2216 {
2217 /* Its got a segment, but its not ours, so it will always be long. */
2218 fragP->fr_subtype = C (COND_JUMP, UNDEF_WORD_DISP);
2219 }
2220 else
2221 {
2222 /* We know the abs value. */
2223 fragP->fr_subtype = C (COND_JUMP, DISP12);
2224 }
2225 break;
2226
2227 case C (UNCD_JUMP, DISP12):
2228 case C (UNCD_JUMP, DISP32):
2229 case C (UNCD_JUMP, UNDEF_WORD_DISP):
2230 case C (COND_JUMP, DISP12):
2231 case C (COND_JUMP, DISP32):
2232 case C (COND_JUMP, UNDEF_WORD_DISP):
2233 /* When relaxing a section for the second time, we don't need to
2234 do anything besides return the current size. */
2235 break;
2236 }
2237
2238 return md_relax_table[fragP->fr_subtype].rlx_length;
2239 }
2240
2241 /* Put number into target byte order. */
2242 void
2243 md_number_to_chars (ptr, use, nbytes)
2244 char * ptr;
2245 valueT use;
2246 int nbytes;
2247 {
2248 if (! target_big_endian)
2249 switch (nbytes)
2250 {
2251 case 4: ptr[3] = (use >> 24) & 0xff; /* fall through */
2252 case 3: ptr[2] = (use >> 16) & 0xff; /* fall through */
2253 case 2: ptr[1] = (use >> 8) & 0xff; /* fall through */
2254 case 1: ptr[0] = (use >> 0) & 0xff; break;
2255 default: abort ();
2256 }
2257 else
2258 switch (nbytes)
2259 {
2260 case 4: *ptr++ = (use >> 24) & 0xff; /* fall through */
2261 case 3: *ptr++ = (use >> 16) & 0xff; /* fall through */
2262 case 2: *ptr++ = (use >> 8) & 0xff; /* fall through */
2263 case 1: *ptr++ = (use >> 0) & 0xff; break;
2264 default: abort ();
2265 }
2266 }
2267
2268 /* Round up a section size to the appropriate boundary. */
2269 valueT
2270 md_section_align (segment, size)
2271 segT segment ATTRIBUTE_UNUSED;
2272 valueT size;
2273 {
2274 return size; /* Byte alignment is fine */
2275 }
2276
2277 /* The location from which a PC relative jump should be calculated,
2278 given a PC relative reloc. */
2279 long
2280 md_pcrel_from_section (fixp, sec)
2281 fixS * fixp;
2282 segT sec ATTRIBUTE_UNUSED;
2283 {
2284 #ifdef OBJ_ELF
2285 /* If the symbol is undefined or defined in another section
2286 we leave the add number alone for the linker to fix it later.
2287 Only account for the PC pre-bump (which is 2 bytes on the MCore). */
2288 if (fixp->fx_addsy != (symbolS *) NULL
2289 && (! S_IS_DEFINED (fixp->fx_addsy)
2290 || (S_GET_SEGMENT (fixp->fx_addsy) != sec)))
2291
2292 {
2293 assert (fixp->fx_size == 2); /* must be an insn */
2294 return fixp->fx_size;
2295 }
2296 #endif
2297
2298 /* The case where we are going to resolve things... */
2299 return fixp->fx_size + fixp->fx_where + fixp->fx_frag->fr_address;
2300 }
2301
2302 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2303 #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break
2304
2305 arelent *
2306 tc_gen_reloc (section, fixp)
2307 asection * section ATTRIBUTE_UNUSED;
2308 fixS * fixp;
2309 {
2310 arelent * rel;
2311 bfd_reloc_code_real_type code;
2312
2313 switch (fixp->fx_r_type)
2314 {
2315 /* These confuse the size/pcrel macro approach. */
2316 case BFD_RELOC_VTABLE_INHERIT:
2317 case BFD_RELOC_VTABLE_ENTRY:
2318 case BFD_RELOC_MCORE_PCREL_IMM4BY2:
2319 case BFD_RELOC_MCORE_PCREL_IMM8BY4:
2320 case BFD_RELOC_MCORE_PCREL_IMM11BY2:
2321 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2:
2322 case BFD_RELOC_RVA:
2323 code = fixp->fx_r_type;
2324 break;
2325
2326 default:
2327 switch (F (fixp->fx_size, fixp->fx_pcrel))
2328 {
2329 MAP (1, 0, BFD_RELOC_8);
2330 MAP (2, 0, BFD_RELOC_16);
2331 MAP (4, 0, BFD_RELOC_32);
2332 MAP (1, 1, BFD_RELOC_8_PCREL);
2333 MAP (2, 1, BFD_RELOC_16_PCREL);
2334 MAP (4, 1, BFD_RELOC_32_PCREL);
2335 default:
2336 code = fixp->fx_r_type;
2337 as_bad (_("Can not do %d byte %srelocation"),
2338 fixp->fx_size,
2339 fixp->fx_pcrel ? _("pc-relative") : "");
2340 }
2341 break;
2342 }
2343
2344 rel = (arelent *) xmalloc (sizeof (arelent));
2345 rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2346 *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2347 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
2348 /* Always pass the addend along! */
2349 rel->addend = fixp->fx_addnumber;
2350
2351 rel->howto = bfd_reloc_type_lookup (stdoutput, code);
2352
2353 if (rel->howto == NULL)
2354 {
2355 as_bad_where (fixp->fx_file, fixp->fx_line,
2356 _("Cannot represent relocation type %s"),
2357 bfd_get_reloc_code_name (code));
2358
2359 /* Set howto to a garbage value so that we can keep going. */
2360 rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2361 assert (rel->howto != NULL);
2362 }
2363
2364 return rel;
2365 }
2366
2367 #ifdef OBJ_ELF
2368 /* See whether we need to force a relocation into the output file.
2369 This is used to force out switch and PC relative relocations when
2370 relaxing. */
2371 int
2372 mcore_force_relocation (fix)
2373 fixS * fix;
2374 {
2375 if (fix->fx_r_type == BFD_RELOC_RVA)
2376 return 1;
2377
2378 return generic_force_reloc (fix);
2379 }
2380
2381 /* Return true if the fix can be handled by GAS, false if it must
2382 be passed through to the linker. */
2383 bfd_boolean
2384 mcore_fix_adjustable (fixP)
2385 fixS * fixP;
2386 {
2387 /* We need the symbol name for the VTABLE entries. */
2388 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2389 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2390 return 0;
2391
2392 return 1;
2393 }
2394 #endif /* OBJ_ELF */
This page took 0.101678 seconds and 4 git commands to generate.