1 /* tc-iq2000.c -- Assembler for the Sitera IQ2000.
2 Copyright (C) 2003, 2004 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "safe-ctype.h"
26 #include "opcodes/iq2000-desc.h"
27 #include "opcodes/iq2000-opc.h"
29 #include "elf/common.h"
30 #include "elf/iq2000.h"
35 /* Structure to hold all of the different components describing
36 an individual instruction. */
39 const CGEN_INSN
* insn
;
40 const CGEN_INSN
* orig_insn
;
43 CGEN_INSN_INT buffer
[1];
44 #define INSN_VALUE(buf) (*(buf))
46 unsigned char buffer
[CGEN_MAX_INSN_SIZE
];
47 #define INSN_VALUE(buf) (buf)
52 fixS
* fixups
[GAS_CGEN_MAX_FIXUPS
];
53 int indices
[MAX_OPERAND_INSTANCES
];
57 const char comment_chars
[] = "#";
58 const char line_comment_chars
[] = "";
59 const char line_separator_chars
[] = ";";
60 const char EXP_CHARS
[] = "eE";
61 const char FLT_CHARS
[] = "dD";
65 #define DEFAULT_MACHINE bfd_mach_iq2000
66 #define DEFAULT_FLAGS EF_IQ2000_CPU_IQ2000
68 static unsigned long iq2000_mach
= bfd_mach_iq2000
;
69 static int cpu_mach
= (1 << MACH_IQ2000
);
71 /* Flags to set in the elf header */
72 static flagword iq2000_flags
= DEFAULT_FLAGS
;
76 unsigned long reg_mask
;
77 unsigned long reg_offset
;
78 unsigned long fpreg_mask
;
79 unsigned long fpreg_offset
;
80 unsigned long frame_offset
;
81 unsigned long frame_reg
;
85 static procS cur_proc
;
86 static procS
*cur_proc_ptr
;
89 static void s_change_sec
PARAMS ((int));
90 static void s_iq2000_set
PARAMS ((int));
91 static void s_iq2000_mask
PARAMS ((int));
92 static void s_iq2000_frame
PARAMS ((int));
93 static void s_iq2000_ent
PARAMS ((int));
94 static void s_iq2000_end
PARAMS ((int));
95 static int get_number
PARAMS ((void));
96 static symbolS
* get_symbol
PARAMS ((void));
97 static void iq2000_record_hi16
PARAMS((int, fixS
*, segT
));
100 /* The target specific pseudo-ops which we support. */
101 const pseudo_typeS md_pseudo_table
[] =
103 { "align", s_align_bytes
, 0 },
105 { "rdata", s_change_sec
, 'r'},
106 { "sdata", s_change_sec
, 's'},
107 { "set", s_iq2000_set
, 0 },
108 { "ent", s_iq2000_ent
, 0 },
109 { "end", s_iq2000_end
, 0 },
110 { "frame", s_iq2000_frame
, 0 },
111 { "fmask", s_iq2000_mask
, 'F' },
112 { "mask", s_iq2000_mask
, 'R' },
113 { "dword", cons
, 8 },
118 /* Relocations against symbols are done in two
119 parts, with a HI relocation and a LO relocation. Each relocation
120 has only 16 bits of space to store an addend. This means that in
121 order for the linker to handle carries correctly, it must be able
122 to locate both the HI and the LO relocation. This means that the
123 relocations must appear in order in the relocation table.
125 In order to implement this, we keep track of each unmatched HI
126 relocation. We then sort them so that they immediately precede the
127 corresponding LO relocation. */
129 struct iq2000_hi_fixup
131 struct iq2000_hi_fixup
* next
; /* Next HI fixup. */
132 fixS
* fixp
; /* This fixup. */
133 segT seg
; /* The section this fixup is in. */
137 /* The list of unmatched HI relocs. */
138 static struct iq2000_hi_fixup
* iq2000_hi_fixup_list
;
141 /* assembler options */
142 #define OPTION_CPU_2000 (OPTION_MD_BASE)
143 #define OPTION_CPU_10 (OPTION_MD_BASE + 1)
145 struct option md_longopts
[] =
147 { "m2000", no_argument
, NULL
, OPTION_CPU_2000
},
148 { "m10", no_argument
, NULL
, OPTION_CPU_10
},
149 { NULL
, no_argument
, NULL
, 0 },
152 size_t md_longopts_size
= sizeof (md_longopts
);
154 const char * md_shortopts
= "";
156 static void iq2000_add_macro
PARAMS ((const char *, const char *, const char **));
157 static void iq2000_load_macros
PARAMS ((void));
158 static void iq10_load_macros
PARAMS ((void));
160 /* macro hash table, which we will add to. */
161 extern struct hash_control
*macro_hash
;
164 md_parse_option (c
, arg
)
165 int c ATTRIBUTE_UNUSED
;
166 char * arg ATTRIBUTE_UNUSED
;
170 case OPTION_CPU_2000
:
171 iq2000_flags
= (iq2000_flags
& ~EF_IQ2000_CPU_MASK
) | EF_IQ2000_CPU_IQ2000
;
172 iq2000_mach
= bfd_mach_iq2000
;
173 cpu_mach
= (1 << MACH_IQ2000
);
177 iq2000_flags
= (iq2000_flags
& ~EF_IQ2000_CPU_MASK
) | EF_IQ2000_CPU_IQ10
;
178 iq2000_mach
= bfd_mach_iq10
;
179 cpu_mach
= (1 << MACH_IQ10
);
180 /* only the first 3 pseudo ops (word, file, loc) are in IQ10 */
190 md_show_usage (stream
)
193 fprintf (stream
, _("IQ2000 specific command line options:\n"));
194 fprintf (stream
, _("-m2000 <default> IQ2000 processor\n"));
195 fprintf (stream
, _("-m10 IQ10 processor\n"));
202 /* Initialize the `cgen' interface. */
204 /* Set the machine number and endian. */
205 gas_cgen_cpu_desc
= iq2000_cgen_cpu_open (CGEN_CPU_OPEN_MACHS
, cpu_mach
,
206 CGEN_CPU_OPEN_ENDIAN
,
209 iq2000_cgen_init_asm (gas_cgen_cpu_desc
);
211 /* This is a callback from cgen to gas to parse operands. */
212 cgen_set_parse_operand_fn (gas_cgen_cpu_desc
, gas_cgen_parse_operand
);
214 /* Set the ELF flags if desired. */
216 bfd_set_private_flags (stdoutput
, iq2000_flags
);
218 /* Set the machine type */
219 bfd_default_set_arch_mach (stdoutput
, bfd_arch_iq2000
, iq2000_mach
);
221 if (iq2000_mach
== bfd_mach_iq2000
)
222 iq2000_load_macros ();
228 iq2000_add_macro (name
, semantics
, arguments
)
230 const char *semantics
;
231 const char **arguments
;
237 macro
= (macro_entry
*) xmalloc (sizeof (macro_entry
));
238 sb_new (¯o
->sub
);
239 sb_new (¯o_name
);
241 macro
->formal_count
= 0;
244 sb_add_string (¯o
->sub
, semantics
);
246 if (arguments
!= NULL
)
248 formal_entry
**p
= ¯o
->formals
;
250 macro
->formal_count
= 0;
251 macro
->formal_hash
= hash_new ();
252 while (*arguments
!= NULL
)
254 formal_entry
*formal
;
256 formal
= (formal_entry
*) xmalloc (sizeof (formal_entry
));
258 sb_new (&formal
->name
);
259 sb_new (&formal
->def
);
260 sb_new (&formal
->actual
);
262 /* chlm: Added the following to allow defaulted args. */
263 if (strchr (*arguments
,'='))
265 char * tt_args
= strdup(*arguments
);
266 char * tt_dflt
= strchr(tt_args
,'=');
269 sb_add_string (&formal
->name
, tt_args
);
270 sb_add_string (&formal
->def
, tt_dflt
+ 1);
273 sb_add_string (&formal
->name
, *arguments
);
275 /* Add to macro's hash table. */
276 hash_jam (macro
->formal_hash
, sb_terminate (&formal
->name
), formal
);
278 formal
->index
= macro
->formal_count
;
279 macro
->formal_count
++;
287 sb_add_string (¯o_name
, name
);
288 namestr
= sb_terminate (¯o_name
);
289 hash_jam (macro_hash
, namestr
, (PTR
) macro
);
294 /* Automatically enter conditional branch macros. */
297 const char * mnemonic
;
298 const char ** expansion
;
300 } iq2000_macro_defs_s
;
302 static const char * abs_args
[] = { "rd", "rs", "scratch=%1", NULL
};
303 static const char * abs_expn
= "\n sra \\rd,\\rs,31\n xor \\scratch,\\rd,\\rs\n sub \\rd,\\scratch,\\rd\n";
305 static const char * la_expn
= "\n lui \\reg,%hi(\\label)\n ori \\reg,\\reg,%lo(\\label)\n";
306 static const char * la_args
[] = { "reg", "label", NULL
};
308 static const char * bxx_args
[] = { "rs", "rt", "label", "scratch=%1", NULL
};
309 static const char * bge_expn
= "\n slt \\scratch,\\rs,\\rt\n beq %0,\\scratch,\\label\n";
310 static const char * bgeu_expn
= "\n sltu \\scratch,\\rs,\\rt\n beq %0,\\scratch,\\label\n";
311 static const char * bgt_expn
= "\n slt \\scratch,\\rt,\\rs\n bne %0,\\scratch,\\label\n";
312 static const char * bgtu_expn
= "\n sltu \\scratch,\\rt,\\rs\n bne %0,\\scratch,\\label\n";
313 static const char * ble_expn
= "\n slt \\scratch,\\rt,\\rs\n beq %0,\\scratch,\\label\n";
314 static const char * bleu_expn
= "\n sltu \\scratch,\\rt,\\rs\n beq %0,\\scratch,\\label\n";
315 static const char * blt_expn
= "\n slt \\scratch,\\rs,\\rt\n bne %0,\\scratch,\\label\n";
316 static const char * bltu_expn
= "\n sltu \\scratch,\\rs,\\rt\n bne %0,\\scratch,\\label\n";
318 static const char * sxx_args
[] = { "rd", "rs", "rt", NULL
};
319 static const char * sge_expn
= "\n slt \\rd,\\rs,\\rt\n xori \\rd,\\rd,1\n";
320 static const char * sgeu_expn
= "\n sltu \\rd,\\rs,\\rt\n xori \\rd,\\rd,1\n";
321 static const char * sle_expn
= "\n slt \\rd,\\rt,\\rs\n xori \\rd,\\rd,1\n";
322 static const char * sleu_expn
= "\n sltu \\rd,\\rt,\\rs\n xori \\rd,\\rd,1\n";
323 static const char * sgt_expn
= "\n slt \\rd,\\rt,\\rs\n";
324 static const char * sgtu_expn
= "\n sltu \\rd,\\rt,\\rs\n";
325 static const char * sne_expn
= "\n xor \\rd,\\rt,\\rs\n sltu \\rd,%0,\\rd\n";
326 static const char * seq_expn
= "\n xor \\rd,\\rt,\\rs\n sltu \\rd,%0,\\rd\n xori \\rd,\\rd,1\n";
328 static const char * ai32_args
[] = { "rt", "rs", "imm", NULL
};
329 static const char * andi32_expn
= "\n\
330 .if (\\imm & 0xffff0000 == 0xffff0000)\n\
331 andoi \\rt,\\rs,%lo(\\imm)\n\
332 .elseif (\\imm & 0x0000ffff == 0x0000ffff)\n\
333 andoui \\rt,\\rs,%uhi(\\imm)\n\
334 .elseif (\\imm & 0xffff0000 == 0x00000000)\n\
335 andi \\rt,\\rs,%lo(\\imm)\n\
337 andoui \\rt,\\rs,%uhi(\\imm)\n\
338 andoi \\rt,\\rt,%lo(\\imm)\n\
340 static const char * ori32_expn
= "\n\
341 .if (\\imm & 0xffff == 0)\n\
342 orui \\rt,\\rs,%uhi(\\imm)\n\
343 .elseif (\\imm & 0xffff0000 == 0)\n\
344 ori \\rt,\\rs,%lo(\\imm)\n\
346 orui \\rt,\\rs,%uhi(\\imm)\n\
347 ori \\rt,\\rt,%lo(\\imm)\n\
350 static const char * neg_args
[] = { "rd", "rs", NULL
};
351 static const char * neg_expn
= "\n sub \\rd,%0,\\rs\n";
352 static const char * negu_expn
= "\n subu \\rd,%0,\\rs\n";
354 static const char * li_args
[] = { "rt", "imm", NULL
};
355 static const char * li_expn
= "\n\
356 .if (\\imm & 0xffff0000 == 0x0)\n\
358 .elseif (\\imm & 0xffff0000 == 0xffff0000)\n\
359 addi \\rt,%0,\\imm\n\
360 .elseif (\\imm & 0x0000ffff == 0)\n\
361 lui \\rt,%uhi(\\imm)\n\
363 lui \\rt,%uhi(\\imm)\n\
364 ori \\rt,\\rt,%lo(\\imm)\n\
367 static iq2000_macro_defs_s iq2000_macro_defs
[] = {
368 {"abs", (const char **)&abs_expn
, (const char **)&abs_args
},
369 {"la", (const char **)&la_expn
, (const char **)&la_args
},
370 {"bge", (const char **)&bge_expn
, (const char **)&bxx_args
},
371 {"bgeu", (const char **)&bgeu_expn
, (const char **)&bxx_args
},
372 {"bgt", (const char **)&bgt_expn
, (const char **)&bxx_args
},
373 {"bgtu", (const char **)&bgtu_expn
, (const char **)&bxx_args
},
374 {"ble", (const char **)&ble_expn
, (const char **)&bxx_args
},
375 {"bleu", (const char **)&bleu_expn
, (const char **)&bxx_args
},
376 {"blt", (const char **)&blt_expn
, (const char **)&bxx_args
},
377 {"bltu", (const char **)&bltu_expn
, (const char **)&bxx_args
},
378 {"sge", (const char **)&sge_expn
, (const char **)&sxx_args
},
379 {"sgeu", (const char **)&sgeu_expn
, (const char **)&sxx_args
},
380 {"sle", (const char **)&sle_expn
, (const char **)&sxx_args
},
381 {"sleu", (const char **)&sleu_expn
, (const char **)&sxx_args
},
382 {"sgt", (const char **)&sgt_expn
, (const char **)&sxx_args
},
383 {"sgtu", (const char **)&sgtu_expn
, (const char **)&sxx_args
},
384 {"seq", (const char **)&seq_expn
, (const char **)&sxx_args
},
385 {"sne", (const char **)&sne_expn
, (const char **)&sxx_args
},
386 {"neg", (const char **)&neg_expn
, (const char **)&neg_args
},
387 {"negu", (const char **)&negu_expn
, (const char **)&neg_args
},
388 {"li", (const char **)&li_expn
, (const char **)&li_args
},
389 {"ori32", (const char **)&ori32_expn
, (const char **)&ai32_args
},
390 {"andi32",(const char **)&andi32_expn
,(const char **)&ai32_args
},
394 iq2000_load_macros ()
397 int mcnt
= sizeof (iq2000_macro_defs
) / sizeof (iq2000_macro_defs_s
);
399 for (i
= 0; i
< mcnt
; i
++)
400 iq2000_add_macro (iq2000_macro_defs
[i
].mnemonic
,
401 *iq2000_macro_defs
[i
].expansion
,
402 iq2000_macro_defs
[i
].args
);
408 /* Allow all iq2k macros in iq10, instead of just LA. */
409 iq2000_load_macros ();
411 char *la_sem
= "\n lui \\reg,%hi(\\label)\n ori \\reg,\\reg,%lo(\\label)\n";
413 char *la_arg_1
= "reg";
414 char *la_arg_2
= "label";
415 const char *la_args
[3] = { la_arg_1
, la_arg_2
, NULL
};
417 iq2000_add_macro ("la", la_sem
, la_args
);
426 static long delayed_load_register
= 0;
427 static int last_insn_had_delay_slot
= 0;
428 static int last_insn_has_load_delay
= 0;
429 static int last_insn_unconditional_jump
= 0;
430 static int last_insn_was_ldw
= 0;
435 /* Initialize GAS's cgen interface for a new instruction. */
436 gas_cgen_init_parse ();
438 insn
.insn
= iq2000_cgen_assemble_insn
439 (gas_cgen_cpu_desc
, str
, & insn
.fields
, insn
.buffer
, & errmsg
);
443 as_bad ("%s", errmsg
);
447 /* Doesn't really matter what we pass for RELAX_P here. */
448 gas_cgen_finish_insn (insn
.insn
, insn
.buffer
,
449 CGEN_FIELDS_BITSIZE (& insn
.fields
), 1, NULL
);
451 /* We need to generate an error if there's a yielding instruction in the delay
452 slot of a control flow modifying instruction (jump (yes), load (no)) */
453 if ((last_insn_had_delay_slot
&& !last_insn_has_load_delay
) &&
454 CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_YIELD_INSN
))
455 as_bad (_("the yielding instruction %s may not be in a delay slot."),
456 CGEN_INSN_NAME (insn
.insn
));
458 /* Warn about odd numbered base registers for paired-register
459 instructions like LDW. On iq2000, result is always rt. */
460 if (iq2000_mach
== bfd_mach_iq2000
461 && CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_EVEN_REG_NUM
)
462 && (insn
.fields
.f_rt
% 2))
463 as_bad (_("Register number (R%ld) for double word access must be even."),
466 /* Warn about odd numbered base registers for paired-register
467 instructions like LDW. On iq10, result is always rd. */
468 if (iq2000_mach
== bfd_mach_iq10
469 && CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_EVEN_REG_NUM
)
470 && (insn
.fields
.f_rd
% 2))
471 as_bad (_("Register number (R%ld) for double word access must be even."),
474 /* Warn about insns that reference the target of a previous load. */
475 /* NOTE: R0 is a special case and is not subject to load delays (except for ldw). */
476 if (delayed_load_register
&& (last_insn_has_load_delay
|| last_insn_was_ldw
))
478 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_RD
) &&
479 insn
.fields
.f_rd
== delayed_load_register
)
480 as_warn (_("operand references R%ld of previous load."),
483 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_RS
) &&
484 insn
.fields
.f_rs
== delayed_load_register
)
485 as_warn (_("operand references R%ld of previous load."),
488 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_RT
) &&
489 insn
.fields
.f_rt
== delayed_load_register
)
490 as_warn (_("operand references R%ld of previous load."),
493 if (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_R31
) &&
494 delayed_load_register
== 31)
495 as_warn (_("instruction implicitly accesses R31 of previous load."));
498 /* Warn about insns that reference the (target + 1) of a previous ldw */
499 if (last_insn_was_ldw
)
501 if ((CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_RD
)
502 && insn
.fields
.f_rd
== delayed_load_register
+ 1)
503 || (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_RS
)
504 && insn
.fields
.f_rs
== delayed_load_register
+ 1)
505 || (CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_USES_RT
)
506 && insn
.fields
.f_rt
== delayed_load_register
+ 1))
507 as_warn (_("operand references R%ld of previous load."),
508 delayed_load_register
+ 1);
511 last_insn_had_delay_slot
=
512 CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_DELAY_SLOT
);
514 last_insn_has_load_delay
=
515 CGEN_INSN_ATTR_VALUE (insn
.insn
, CGEN_INSN_LOAD_DELAY
);
517 if (last_insn_unconditional_jump
)
518 last_insn_has_load_delay
= last_insn_unconditional_jump
= 0;
519 else if (! strcmp (CGEN_INSN_MNEMONIC (insn
.insn
), "j")
520 || ! strcmp (CGEN_INSN_MNEMONIC (insn
.insn
), "jal"))
521 last_insn_unconditional_jump
= 1;
523 /* The meaning of EVEN_REG_NUM was overloaded to also imply LDW. Since that's
524 not true for IQ10, let's make the above logic specific to LDW. */
525 last_insn_was_ldw
= ! strcmp ("ldw", CGEN_INSN_NAME (insn
.insn
));
527 /* The assumption here is that the target of a load is always rt.
528 That is true for iq2000 & iq10. */
529 delayed_load_register
= insn
.fields
.f_rt
;
533 md_section_align (segment
, size
)
537 int align
= bfd_get_section_alignment (stdoutput
, segment
);
538 return ((size
+ (1 << align
) - 1) & (-1 << align
));
543 md_undefined_symbol (name
)
544 char * name ATTRIBUTE_UNUSED
;
549 /* Interface to relax_segment. */
551 /* Return an initial guess of the length by which a fragment must grow to
552 hold a branch to reach its destination.
553 Also updates fr_type/fr_subtype as necessary.
555 Called just before doing relaxation.
556 Any symbol that is now undefined will not become defined.
557 The guess for fr_var is ACTUALLY the growth beyond fr_fix.
558 Whatever we do to grow fr_fix or fr_var contributes to our returned value.
559 Although it may not be explicit in the frag, pretend fr_var starts with a
563 md_estimate_size_before_relax (fragP
, segment
)
565 segT segment ATTRIBUTE_UNUSED
;
567 int old_fr_fix
= fragP
->fr_fix
;
569 /* The only thing we have to handle here are symbols outside of the
570 current segment. They may be undefined or in a different segment in
571 which case linker scripts may place them anywhere.
572 However, we can't finish the fragment here and emit the reloc as insn
573 alignment requirements may move the insn about. */
575 return (fragP
->fr_var
+ fragP
->fr_fix
- old_fr_fix
);
578 /* *fragP has been relaxed to its final size, and now needs to have
579 the bytes inside it modified to conform to the new size.
581 Called after relaxation is finished.
582 fragP->fr_type == rs_machine_dependent.
583 fragP->fr_subtype is the subtype of what the address relaxed to. */
586 md_convert_frag (abfd
, sec
, fragP
)
587 bfd
* abfd ATTRIBUTE_UNUSED
;
588 segT sec ATTRIBUTE_UNUSED
;
589 fragS
* fragP ATTRIBUTE_UNUSED
;
594 /* Functions concerning relocs. */
597 md_pcrel_from_section (fixP
, sec
)
601 if (fixP
->fx_addsy
!= (symbolS
*) NULL
602 && (! S_IS_DEFINED (fixP
->fx_addsy
)
603 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
605 /* The symbol is undefined (or is defined but not in this section).
606 Let the linker figure it out. */
610 /* return the address of the delay slot */
611 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
614 /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP.
615 Returns BFD_RELOC_NONE if no reloc type can be found.
616 *FIXP may be modified if desired. */
618 bfd_reloc_code_real_type
619 md_cgen_lookup_reloc (insn
, operand
, fixP
)
620 const CGEN_INSN
* insn ATTRIBUTE_UNUSED
;
621 const CGEN_OPERAND
* operand
;
622 fixS
* fixP ATTRIBUTE_UNUSED
;
624 switch (operand
->type
)
626 case IQ2000_OPERAND_OFFSET
:
627 return BFD_RELOC_16_PCREL_S2
;
628 case IQ2000_OPERAND_JMPTARG
:
629 return BFD_RELOC_IQ2000_OFFSET_16
;
630 case IQ2000_OPERAND_JMPTARGQ10
:
631 if (iq2000_mach
== bfd_mach_iq10
)
632 return BFD_RELOC_IQ2000_OFFSET_21
;
633 return BFD_RELOC_NONE
;
634 case IQ2000_OPERAND_HI16
:
635 return BFD_RELOC_HI16
;
636 case IQ2000_OPERAND_LO16
:
637 return BFD_RELOC_LO16
;
639 /* Pacify gcc -Wall. */
640 return BFD_RELOC_NONE
;
643 return BFD_RELOC_NONE
;
646 /* Record a HI16 reloc for later matching with its LO16 cousin. */
649 iq2000_record_hi16 (reloc_type
, fixP
, seg
)
652 segT seg ATTRIBUTE_UNUSED
;
654 struct iq2000_hi_fixup
* hi_fixup
;
656 assert (reloc_type
== BFD_RELOC_HI16
);
658 hi_fixup
= ((struct iq2000_hi_fixup
*)
659 xmalloc (sizeof (struct iq2000_hi_fixup
)));
660 hi_fixup
->fixp
= fixP
;
661 hi_fixup
->seg
= now_seg
;
662 hi_fixup
->next
= iq2000_hi_fixup_list
;
664 iq2000_hi_fixup_list
= hi_fixup
;
667 /* Called while parsing an instruction to create a fixup.
668 We need to check for HI16 relocs and queue them up for later sorting. */
671 iq2000_cgen_record_fixup_exp (frag
, where
, insn
, length
, operand
, opinfo
, exp
)
674 const CGEN_INSN
* insn
;
676 const CGEN_OPERAND
* operand
;
680 fixS
* fixP
= gas_cgen_record_fixup_exp (frag
, where
, insn
, length
,
681 operand
, opinfo
, exp
);
683 switch (operand
->type
)
685 case IQ2000_OPERAND_HI16
:
686 /* If low/high was used, it is recorded in `opinfo'. */
687 if (fixP
->fx_cgen
.opinfo
== BFD_RELOC_HI16
688 || fixP
->fx_cgen
.opinfo
== BFD_RELOC_LO16
)
689 iq2000_record_hi16 (fixP
->fx_cgen
.opinfo
, fixP
, now_seg
);
691 default : /* avoid -Wall warning */
698 /* Return BFD reloc type from opinfo field in a fixS.
699 It's tricky using fx_r_type in iq2000_frob_file because the values
700 are BFD_RELOC_UNUSED + operand number. */
701 #define FX_OPINFO_R_TYPE(f) ((f)->fx_cgen.opinfo)
703 /* Sort any unmatched HI16 relocs so that they immediately precede
704 the corresponding LO16 reloc. This is called before md_apply_fix3 and
710 struct iq2000_hi_fixup
* l
;
712 for (l
= iq2000_hi_fixup_list
; l
!= NULL
; l
= l
->next
)
714 segment_info_type
* seginfo
;
717 assert (FX_OPINFO_R_TYPE (l
->fixp
) == BFD_RELOC_HI16
718 || FX_OPINFO_R_TYPE (l
->fixp
) == BFD_RELOC_LO16
);
720 /* Check quickly whether the next fixup happens to be a matching low. */
721 if (l
->fixp
->fx_next
!= NULL
722 && FX_OPINFO_R_TYPE (l
->fixp
->fx_next
) == BFD_RELOC_LO16
723 && l
->fixp
->fx_addsy
== l
->fixp
->fx_next
->fx_addsy
724 && l
->fixp
->fx_offset
== l
->fixp
->fx_next
->fx_offset
)
727 /* Look through the fixups for this segment for a matching
728 `low'. When we find one, move the high just in front of it.
729 We do this in two passes. In the first pass, we try to find
730 a unique `low'. In the second pass, we permit multiple
731 high's relocs for a single `low'. */
732 seginfo
= seg_info (l
->seg
);
733 for (pass
= 0; pass
< 2; pass
++)
739 for (f
= seginfo
->fix_root
; f
!= NULL
; f
= f
->fx_next
)
741 /* Check whether this is a `low' fixup which matches l->fixp. */
742 if (FX_OPINFO_R_TYPE (f
) == BFD_RELOC_LO16
743 && f
->fx_addsy
== l
->fixp
->fx_addsy
744 && f
->fx_offset
== l
->fixp
->fx_offset
747 || (FX_OPINFO_R_TYPE (prev
) != BFD_RELOC_HI16
)
748 || prev
->fx_addsy
!= f
->fx_addsy
749 || prev
->fx_offset
!= f
->fx_offset
))
753 /* Move l->fixp before f. */
754 for (pf
= &seginfo
->fix_root
;
756 pf
= & (* pf
)->fx_next
)
757 assert (* pf
!= NULL
);
759 * pf
= l
->fixp
->fx_next
;
761 l
->fixp
->fx_next
= f
;
763 seginfo
->fix_root
= l
->fixp
;
765 prev
->fx_next
= l
->fixp
;
777 as_warn_where (l
->fixp
->fx_file
, l
->fixp
->fx_line
,
778 _("Unmatched high relocation"));
783 /* See whether we need to force a relocation into the output file. */
786 iq2000_force_relocation (fix
)
789 if (fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
790 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
796 /* Handle the .set pseudo-op. */
800 int x ATTRIBUTE_UNUSED
;
802 char *name
= input_line_pointer
, ch
;
803 char *save_ILP
= input_line_pointer
;
805 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
806 input_line_pointer
++;
807 ch
= *input_line_pointer
;
808 *input_line_pointer
= '\0';
810 if (strcmp (name
, "reorder") == 0)
813 else if (strcmp (name
, "noreorder") == 0)
816 else if (strcmp (name
, "at") == 0)
819 else if (strcmp (name
, "noat") == 0)
822 else if (strcmp (name
, "macro") == 0)
825 else if (strcmp (name
, "nomacro") == 0)
828 else if (strcmp (name
, "move") == 0 || strcmp (name
, "novolatile") == 0)
831 else if (strcmp (name
, "nomove") == 0 || strcmp (name
, "volatile") == 0)
834 else if (strcmp (name
, "bopt") == 0)
837 else if (strcmp (name
, "nobopt") == 0)
842 /* We'd like to be able to use .set symbol, expn */
843 input_line_pointer
= save_ILP
;
846 /*as_warn (_("Tried to set unrecognized symbol: %s\n"), name);*/
848 *input_line_pointer
= ch
;
849 demand_empty_rest_of_line ();
852 /* Write a value out to the object file, using the appropriate endianness. */
855 md_number_to_chars (buf
, val
, n
)
860 number_to_chars_bigendian (buf
, val
, n
);
867 /* In case of a syntax error, escape back to try next syntax combo. */
868 if (exp
->X_op
== O_absent
)
869 gas_cgen_md_operand (exp
);
872 /* Turn a string in input_line_pointer into a floating point constant
873 of type type, and store the appropriate bytes in *litP. The number
874 of LITTLENUMS emitted is stored in *sizeP . An error message is
875 returned, or NULL on OK. */
877 /* Equal to MAX_PRECISION in atof-ieee.c */
878 #define MAX_LITTLENUMS 6
881 md_atof (type
, litP
, sizeP
)
888 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
907 /* FIXME: Some targets allow other format chars for bigger sizes here. */
911 return _("Bad call to md_atof()");
914 t
= atof_ieee (input_line_pointer
, type
, words
);
916 input_line_pointer
= t
;
917 * sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
919 for (i
= 0; i
< prec
; i
++)
921 md_number_to_chars (litP
, (valueT
) words
[i
],
922 sizeof (LITTLENUM_TYPE
));
923 litP
+= sizeof (LITTLENUM_TYPE
);
931 iq2000_fix_adjustable (fixP
)
934 bfd_reloc_code_real_type reloc_type
;
936 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
938 const CGEN_INSN
*insn
= NULL
;
939 int opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
940 const CGEN_OPERAND
*operand
= cgen_operand_lookup_by_num(gas_cgen_cpu_desc
, opindex
);
941 reloc_type
= md_cgen_lookup_reloc (insn
, operand
, fixP
);
944 reloc_type
= fixP
->fx_r_type
;
946 if (fixP
->fx_addsy
== NULL
)
949 /* Prevent all adjustments to global symbols. */
950 if (S_IS_EXTERN (fixP
->fx_addsy
))
953 if (S_IS_WEAK (fixP
->fx_addsy
))
956 /* We need the symbol name for the VTABLE entries. */
957 if ( reloc_type
== BFD_RELOC_VTABLE_INHERIT
958 || reloc_type
== BFD_RELOC_VTABLE_ENTRY
)
970 /* The ELF backend needs to know that we are changing sections, so
971 that .previous works correctly. We could do something like check
972 for a obj_section_change_hook macro, but that might be confusing
973 as it would not be appropriate to use it in the section changing
974 functions in read.c, since obj-elf.c intercepts those. FIXME:
975 This should be cleaner, somehow. */
976 obj_elf_section_change_hook ();
979 /* iq2000_emit_delays (false); */
993 /* The .end directive. */
997 int x ATTRIBUTE_UNUSED
;
1002 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1005 demand_empty_rest_of_line ();
1010 if (1/*iq2000_mach == bfd_mach_iq2000*/)
1012 #ifdef BFD_ASSEMBLER
1013 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
1018 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
1025 as_warn (_(".end not in text section"));
1029 as_warn (_(".end directive without a preceding .ent directive."));
1030 demand_empty_rest_of_line ();
1036 assert (S_GET_NAME (p
));
1037 if (strcmp (S_GET_NAME (p
), S_GET_NAME (cur_proc_ptr
->isym
)))
1038 as_warn (_(".end symbol does not match .ent symbol."));
1041 as_warn (_(".end directive missing or unknown symbol"));
1045 cur_proc_ptr
= NULL
;
1048 /* The .aent and .ent directives. */
1058 if (1/*iq2000_mach == bfd_mach_iq2000*/)
1060 symbolP
= get_symbol ();
1061 if (*input_line_pointer
== ',')
1062 input_line_pointer
++;
1064 if (ISDIGIT (*input_line_pointer
) || *input_line_pointer
== '-')
1065 number
= get_number ();
1067 #ifdef BFD_ASSEMBLER
1068 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
1073 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
1080 as_warn (_(".ent or .aent not in text section."));
1082 if (!aent
&& cur_proc_ptr
)
1083 as_warn (_("missing `.end'"));
1087 cur_proc_ptr
= &cur_proc
;
1088 memset (cur_proc_ptr
, '\0', sizeof (procS
));
1090 cur_proc_ptr
->isym
= symbolP
;
1092 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
1098 as_bad (_("unknown pseudo-op: `%s'"), ".ent");
1100 demand_empty_rest_of_line ();
1103 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
1104 then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
1105 s_iq2000_frame is used so that we can set the PDR information correctly.
1106 We can't use the ecoff routines because they make reference to the ecoff
1107 symbol table (in the mdebug section). */
1110 s_iq2000_frame (ignore
)
1116 /* The .fmask and .mask directives. If the mdebug section is present
1117 (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
1118 embedded targets, s_iq2000_mask is used so that we can set the PDR
1119 information correctly. We can't use the ecoff routines because they
1120 make reference to the ecoff symbol table (in the mdebug section). */
1123 s_iq2000_mask (reg_type
)
1126 s_ignore (reg_type
);
1136 name
= input_line_pointer
;
1137 c
= get_symbol_end ();
1138 p
= (symbolS
*) symbol_find_or_make (name
);
1139 *input_line_pointer
= c
;
1149 if (*input_line_pointer
== '-')
1151 ++input_line_pointer
;
1155 if (! ISDIGIT (*input_line_pointer
))
1156 as_bad (_("Expected simple number."));
1158 if (input_line_pointer
[0] == '0')
1160 if (input_line_pointer
[1] == 'x')
1162 input_line_pointer
+= 2;
1163 while (ISXDIGIT (*input_line_pointer
))
1166 val
|= hex_value (*input_line_pointer
++);
1168 return negative
? -val
: val
;
1172 ++input_line_pointer
;
1174 while (ISDIGIT (*input_line_pointer
))
1177 val
|= *input_line_pointer
++ - '0';
1179 return negative
? -val
: val
;
1183 if (! ISDIGIT (*input_line_pointer
))
1185 printf (_(" *input_line_pointer == '%c' 0x%02x\n"),
1186 *input_line_pointer
, *input_line_pointer
);
1187 as_warn (_("Invalid number"));
1191 while (ISDIGIT (*input_line_pointer
))
1194 val
+= *input_line_pointer
++ - '0';
1197 return negative
? -val
: val
;