1 /* tc-i860.c -- Assembler for the Intel i860 architecture.
2 Copyright 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002,
3 2003, 2006, 2007 Free Software Foundation, Inc.
5 Brought back from the dead and completely reworked
6 by Jason Eckhardt <jle@cygnus.com>.
8 This file is part of GAS, the GNU Assembler.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License along
21 with GAS; see the file COPYING. If not, write to the Free Software
22 Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "safe-ctype.h"
27 #include "opcode/i860.h"
31 /* The opcode hash table. */
32 static struct hash_control *op_hash = NULL;
34 /* These characters always start a comment. */
35 const char comment_chars[] = "#!/";
37 /* These characters start a comment at the beginning of a line. */
38 const char line_comment_chars[] = "#/";
40 const char line_separator_chars[] = ";";
42 /* Characters that can be used to separate the mantissa from the exponent
43 in floating point numbers. */
44 const char EXP_CHARS[] = "eE";
46 /* Characters that indicate this number is a floating point constant.
47 As in 0f12.456 or 0d1.2345e12. */
48 const char FLT_CHARS[] = "rRsSfFdDxXpP";
50 /* Register prefix (depends on syntax). */
51 static char reg_prefix;
59 enum expand_type expand;
63 bfd_reloc_code_real_type reloc;
69 /* The current fixup count. */
72 static char *expr_end;
74 /* Indicates error if a pseudo operation was expanded after a branch. */
75 static char last_expand;
77 /* If true, then warn if any pseudo operations were expanded. */
78 static int target_warn_expand = 0;
80 /* If true, then XP support is enabled. */
81 static int target_xp = 0;
83 /* If true, then Intel syntax is enabled (default to AT&T/SVR4 syntax). */
84 static int target_intel_syntax = 0;
88 static void i860_process_insn (char *);
89 static void s_dual (int);
90 static void s_enddual (int);
91 static void s_atmp (int);
92 static void s_align_wrapper (int);
93 static int i860_get_expression (char *);
94 static bfd_reloc_code_real_type obtain_reloc_for_imm16 (fixS *, long *);
96 static void print_insn (struct i860_it *);
99 const pseudo_typeS md_pseudo_table[] =
101 {"align", s_align_wrapper, 0},
103 {"enddual", s_enddual, 0},
108 /* Dual-instruction mode handling. */
111 DUAL_OFF = 0, DUAL_ON, DUAL_DDOT, DUAL_ONDDOT,
113 static enum dual dual_mode = DUAL_OFF;
115 /* Handle ".dual" directive. */
117 s_dual (int ignore ATTRIBUTE_UNUSED)
119 if (target_intel_syntax)
122 as_bad (_("Directive .dual available only with -mintel-syntax option"));
125 /* Handle ".enddual" directive. */
127 s_enddual (int ignore ATTRIBUTE_UNUSED)
129 if (target_intel_syntax)
130 dual_mode = DUAL_OFF;
132 as_bad (_("Directive .enddual available only with -mintel-syntax option"));
135 /* Temporary register used when expanding assembler pseudo operations. */
136 static int atmp = 31;
139 s_atmp (int ignore ATTRIBUTE_UNUSED)
143 if (! target_intel_syntax)
145 as_bad (_("Directive .atmp available only with -mintel-syntax option"));
146 demand_empty_rest_of_line ();
150 if (strncmp (input_line_pointer, "sp", 2) == 0)
152 input_line_pointer += 2;
155 else if (strncmp (input_line_pointer, "fp", 2) == 0)
157 input_line_pointer += 2;
160 else if (strncmp (input_line_pointer, "r", 1) == 0)
162 input_line_pointer += 1;
163 temp = get_absolute_expression ();
164 if (temp >= 0 && temp <= 31)
167 as_bad (_("Unknown temporary pseudo register"));
171 as_bad (_("Unknown temporary pseudo register"));
173 demand_empty_rest_of_line ();
176 /* Handle ".align" directive depending on syntax mode.
177 AT&T/SVR4 syntax uses the standard align directive. However,
178 the Intel syntax additionally allows keywords for the alignment
179 parameter: ".align type", where type is one of {.short, .long,
180 .quad, .single, .double} representing alignments of 2, 4,
181 16, 4, and 8, respectively. */
183 s_align_wrapper (int arg)
185 char *parm = input_line_pointer;
187 if (target_intel_syntax)
189 /* Replace a keyword with the equivalent integer so the
190 standard align routine can parse the directive. */
191 if (strncmp (parm, ".short", 6) == 0)
192 strncpy (parm, " 2", 6);
193 else if (strncmp (parm, ".long", 5) == 0)
194 strncpy (parm, " 4", 5);
195 else if (strncmp (parm, ".quad", 5) == 0)
196 strncpy (parm, " 16", 5);
197 else if (strncmp (parm, ".single", 7) == 0)
198 strncpy (parm, " 4", 7);
199 else if (strncmp (parm, ".double", 7) == 0)
200 strncpy (parm, " 8", 7);
202 while (*input_line_pointer == ' ')
203 ++input_line_pointer;
209 /* This function is called once, at assembler startup time. It should
210 set up all the tables and data structures that the MD part of the
211 assembler will need. */
215 const char *retval = NULL;
219 op_hash = hash_new ();
221 while (i860_opcodes[i].name != NULL)
223 const char *name = i860_opcodes[i].name;
224 retval = hash_insert (op_hash, name, (PTR)&i860_opcodes[i]);
227 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
228 i860_opcodes[i].name, retval);
233 if (i860_opcodes[i].match & i860_opcodes[i].lose)
236 _("internal error: losing opcode: `%s' \"%s\"\n"),
237 i860_opcodes[i].name, i860_opcodes[i].args);
242 while (i860_opcodes[i].name != NULL
243 && strcmp (i860_opcodes[i].name, name) == 0);
247 as_fatal (_("Defective assembler. No assembly attempted."));
249 /* Set the register prefix for either Intel or AT&T/SVR4 syntax. */
250 reg_prefix = target_intel_syntax ? 0 : '%';
253 /* This is the core of the machine-dependent assembler. STR points to a
254 machine dependent instruction. This function emits the frags/bytes
257 md_assemble (char *str)
262 struct i860_it pseudo[3];
267 /* Assemble the instruction. */
268 i860_process_insn (str);
270 /* Check for expandable flag to produce pseudo-instructions. This
271 is an undesirable feature that should be avoided. */
272 if (the_insn.expand != 0 && the_insn.expand != XP_ONLY
273 && ! (the_insn.fi[0].fup & (OP_SEL_HA | OP_SEL_H | OP_SEL_L | OP_SEL_GOT
274 | OP_SEL_GOTOFF | OP_SEL_PLT)))
276 for (i = 0; i < 3; i++)
277 pseudo[i] = the_insn;
280 switch (the_insn.expand)
288 if (the_insn.fi[0].exp.X_add_symbol == NULL
289 && the_insn.fi[0].exp.X_op_symbol == NULL
290 && (the_insn.fi[0].exp.X_add_number < (1 << 15)
291 && the_insn.fi[0].exp.X_add_number >= -(1 << 15)))
294 /* Emit "or l%const,r0,ireg_dest". */
295 pseudo[0].opcode = (the_insn.opcode & 0x001f0000) | 0xe4000000;
296 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
298 /* Emit "orh h%const,ireg_dest,ireg_dest". */
299 pseudo[1].opcode = (the_insn.opcode & 0x03ffffff) | 0xec000000
300 | ((the_insn.opcode & 0x001f0000) << 5);
301 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
307 if (the_insn.fi[0].exp.X_add_symbol == NULL
308 && the_insn.fi[0].exp.X_op_symbol == NULL
309 && (the_insn.fi[0].exp.X_add_number < (1 << 15)
310 && the_insn.fi[0].exp.X_add_number >= -(1 << 15)))
313 /* Emit "orh ha%addr_expr,ireg_src2,r31". */
314 pseudo[0].opcode = 0xec000000 | (the_insn.opcode & 0x03e00000)
316 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_HA);
318 /* Emit "l%addr_expr(r31),ireg_dest". We pick up the fixup
319 information from the original instruction. */
320 pseudo[1].opcode = (the_insn.opcode & ~0x03e00000) | (atmp << 21);
321 pseudo[1].fi[0].fup = the_insn.fi[0].fup | OP_SEL_L;
327 if (the_insn.fi[0].exp.X_add_symbol == NULL
328 && the_insn.fi[0].exp.X_op_symbol == NULL
329 && (the_insn.fi[0].exp.X_add_number < (1 << 16)
330 && the_insn.fi[0].exp.X_add_number >= 0))
333 /* Emit "$(opcode)h h%const,ireg_src2,r31". */
334 pseudo[0].opcode = (the_insn.opcode & 0xf3e0ffff) | 0x0c000000
336 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
338 /* Emit "$(opcode) l%const,r31,ireg_dest". */
339 pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000
341 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
347 if (the_insn.fi[0].exp.X_add_symbol == NULL
348 && the_insn.fi[0].exp.X_op_symbol == NULL
349 && (the_insn.fi[0].exp.X_add_number < (1 << 16)
350 && the_insn.fi[0].exp.X_add_number >= 0))
353 /* Emit "andnot h%const,ireg_src2,r31". */
354 pseudo[0].opcode = (the_insn.opcode & 0x03e0ffff) | 0xd4000000
356 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
357 pseudo[0].fi[0].exp.X_add_number =
358 -1 - the_insn.fi[0].exp.X_add_number;
360 /* Emit "andnot l%const,r31,ireg_dest". */
361 pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000
363 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
364 pseudo[1].fi[0].exp.X_add_number =
365 -1 - the_insn.fi[0].exp.X_add_number;
371 if (the_insn.fi[0].exp.X_add_symbol == NULL
372 && the_insn.fi[0].exp.X_op_symbol == NULL
373 && (the_insn.fi[0].exp.X_add_number < (1 << 15)
374 && the_insn.fi[0].exp.X_add_number >= -(1 << 15)))
377 /* Emit "orh h%const,r0,r31". */
378 pseudo[0].opcode = 0xec000000 | (atmp << 16);
379 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
381 /* Emit "or l%const,r31,r31". */
382 pseudo[1].opcode = 0xe4000000 | (atmp << 21) | (atmp << 16);
383 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
385 /* Emit "r31,ireg_src2,ireg_dest". */
386 pseudo[2].opcode = (the_insn.opcode & ~0x0400ffff) | (atmp << 11);
387 pseudo[2].fi[0].fup = OP_IMM_S16;
393 as_fatal (_("failed sanity check."));
396 the_insn = pseudo[0];
398 /* Warn if an opcode is expanded after a delayed branch. */
399 if (num_opcodes > 1 && last_expand == 1)
400 as_warn (_("Expanded opcode after delayed branch: `%s'"), str);
402 /* Warn if an opcode is expanded in dual mode. */
403 if (num_opcodes > 1 && dual_mode != DUAL_OFF)
404 as_warn (_("Expanded opcode in dual mode: `%s'"), str);
406 /* Notify if any expansions happen. */
407 if (target_warn_expand && num_opcodes > 1)
408 as_warn (_("An instruction was expanded (%s)"), str);
416 /* Output the opcode. Note that the i860 always reads instructions
417 as little-endian data. */
418 destp = frag_more (4);
419 number_to_chars_littleendian (destp, the_insn.opcode, 4);
421 /* Check for expanded opcode after branch or in dual mode. */
422 last_expand = the_insn.fi[0].pcrel;
424 /* Output the symbol-dependent stuff. Only btne and bte will ever
425 loop more than once here, since only they (possibly) have more
427 for (tmp = 0; tmp < fc; tmp++)
429 if (the_insn.fi[tmp].fup != OP_NONE)
432 fix = fix_new_exp (frag_now,
433 destp - frag_now->fr_literal,
435 &the_insn.fi[tmp].exp,
436 the_insn.fi[tmp].pcrel,
437 the_insn.fi[tmp].reloc);
439 /* Despite the odd name, this is a scratch field. We use
440 it to encode operand type information. */
441 fix->fx_addnumber = the_insn.fi[tmp].fup;
444 the_insn = pseudo[++i];
446 while (--num_opcodes > 0);
450 /* Assemble the instruction pointed to by STR. */
452 i860_process_insn (char *str)
457 struct i860_opcode *insn;
459 unsigned long opcode;
464 #if 1 /* For compiler warnings. */
471 for (s = str; ISLOWER (*s) || *s == '.' || *s == '3'
472 || *s == '2' || *s == '1'; ++s)
490 as_fatal (_("Unknown opcode: `%s'"), str);
493 /* Check for dual mode ("d.") opcode prefix. */
494 if (strncmp (str, "d.", 2) == 0)
496 if (dual_mode == DUAL_ON)
497 dual_mode = DUAL_ONDDOT;
499 dual_mode = DUAL_DDOT;
503 if ((insn = (struct i860_opcode *) hash_find (op_hash, str)) == NULL)
505 if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
507 as_bad (_("Unknown opcode: `%s'"), str);
518 opcode = insn->match;
519 memset (&the_insn, '\0', sizeof (the_insn));
521 for (t = 0; t < MAX_FIXUPS; t++)
523 the_insn.fi[t].reloc = BFD_RELOC_NONE;
524 the_insn.fi[t].pcrel = 0;
525 the_insn.fi[t].fup = OP_NONE;
528 /* Build the opcode, checking as we go that the operands match. */
529 for (args = insn->args; ; ++args)
543 /* These must match exactly. */
553 /* Must be at least one digit. */
563 /* Next operand must be a register. */
567 /* Check for register prefix if necessary. */
568 if (reg_prefix && *s != reg_prefix)
595 /* Any register r0..r31. */
598 if (!ISDIGIT (c = *s++))
604 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
612 /* Not this opcode. */
617 /* Obtained the register, now place it in the opcode. */
621 opcode |= mask << 11;
625 opcode |= mask << 21;
629 opcode |= mask << 16;
635 /* Next operand is a floating point register. */
639 /* Check for register prefix if necessary. */
640 if (reg_prefix && *s != reg_prefix)
645 if (*s++ == 'f' && ISDIGIT (*s))
650 mask = 10 * (mask - '0') + (*s++ - '0');
663 opcode |= mask << 11;
667 opcode |= mask << 21;
671 opcode |= mask << 16;
672 if ((opcode & (1 << 10)) && mask != 0
673 && (mask == ((opcode >> 11) & 0x1f)))
674 as_warn (_("Pipelined instruction: fsrc1 = fdest"));
680 /* Next operand must be a control register. */
682 /* Check for register prefix if necessary. */
683 if (reg_prefix && *s != reg_prefix)
688 if (strncmp (s, "fir", 3) == 0)
694 if (strncmp (s, "psr", 3) == 0)
700 if (strncmp (s, "dirbase", 7) == 0)
706 if (strncmp (s, "db", 2) == 0)
712 if (strncmp (s, "fsr", 3) == 0)
718 if (strncmp (s, "epsr", 4) == 0)
724 /* The remaining control registers are XP only. */
725 if (target_xp && strncmp (s, "bear", 4) == 0)
731 if (target_xp && strncmp (s, "ccr", 3) == 0)
737 if (target_xp && strncmp (s, "p0", 2) == 0)
743 if (target_xp && strncmp (s, "p1", 2) == 0)
749 if (target_xp && strncmp (s, "p2", 2) == 0)
755 if (target_xp && strncmp (s, "p3", 2) == 0)
763 /* 5-bit immediate in src1. */
765 if (! i860_get_expression (s))
768 the_insn.fi[fc].fup |= OP_IMM_U5;
774 /* 26-bit immediate, relative branch (lbroff). */
776 the_insn.fi[fc].pcrel = 1;
777 the_insn.fi[fc].fup |= OP_IMM_BR26;
780 /* 16-bit split immediate, relative branch (sbroff). */
782 the_insn.fi[fc].pcrel = 1;
783 the_insn.fi[fc].fup |= OP_IMM_BR16;
786 /* 16-bit split immediate. */
788 the_insn.fi[fc].fup |= OP_IMM_SPLIT16;
791 /* 16-bit split immediate, byte aligned (st.b). */
793 the_insn.fi[fc].fup |= OP_IMM_SPLIT16;
796 /* 16-bit split immediate, half-word aligned (st.s). */
798 the_insn.fi[fc].fup |= (OP_IMM_SPLIT16 | OP_ENCODE1 | OP_ALIGN2);
801 /* 16-bit split immediate, word aligned (st.l). */
803 the_insn.fi[fc].fup |= (OP_IMM_SPLIT16 | OP_ENCODE1 | OP_ALIGN4);
806 /* 16-bit immediate. */
808 the_insn.fi[fc].fup |= OP_IMM_S16;
811 /* 16-bit immediate, byte aligned (ld.b). */
813 the_insn.fi[fc].fup |= OP_IMM_S16;
816 /* 16-bit immediate, half-word aligned (ld.s). */
818 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE1 | OP_ALIGN2);
821 /* 16-bit immediate, word aligned (ld.l, {p}fld.l, fst.l). */
823 if (insn->name[0] == 'l')
824 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE1 | OP_ALIGN4);
826 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE2 | OP_ALIGN4);
829 /* 16-bit immediate, double-word aligned ({p}fld.d, fst.d). */
831 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE3 | OP_ALIGN8);
834 /* 16-bit immediate, quad-word aligned (fld.q, fst.q). */
836 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE3 | OP_ALIGN16);
840 /* Handle the immediate for either the Intel syntax or
841 SVR4 syntax. The Intel syntax is "ha%immediate"
842 whereas SVR4 syntax is "[immediate]@ha". */
844 if (target_intel_syntax == 0)
846 /* AT&T/SVR4 syntax. */
850 /* Note that if i860_get_expression() fails, we will still
851 have created U entries in the symbol table for the
852 'symbols' in the input string. Try not to create U
853 symbols for registers, etc. */
854 if (! i860_get_expression (s))
859 if (strncmp (s, "@ha", 3) == 0)
861 the_insn.fi[fc].fup |= OP_SEL_HA;
864 else if (strncmp (s, "@h", 2) == 0)
866 the_insn.fi[fc].fup |= OP_SEL_H;
869 else if (strncmp (s, "@l", 2) == 0)
871 the_insn.fi[fc].fup |= OP_SEL_L;
874 else if (strncmp (s, "@gotoff", 7) == 0
875 || strncmp (s, "@GOTOFF", 7) == 0)
877 as_bad (_("Assembler does not yet support PIC"));
878 the_insn.fi[fc].fup |= OP_SEL_GOTOFF;
881 else if (strncmp (s, "@got", 4) == 0
882 || strncmp (s, "@GOT", 4) == 0)
884 as_bad (_("Assembler does not yet support PIC"));
885 the_insn.fi[fc].fup |= OP_SEL_GOT;
888 else if (strncmp (s, "@plt", 4) == 0
889 || strncmp (s, "@PLT", 4) == 0)
891 as_bad (_("Assembler does not yet support PIC"));
892 the_insn.fi[fc].fup |= OP_SEL_PLT;
896 the_insn.expand = insn->expand;
906 if (strncmp (s, "ha%", 3) == 0)
908 the_insn.fi[fc].fup |= OP_SEL_HA;
911 else if (strncmp (s, "h%", 2) == 0)
913 the_insn.fi[fc].fup |= OP_SEL_H;
916 else if (strncmp (s, "l%", 2) == 0)
918 the_insn.fi[fc].fup |= OP_SEL_L;
921 the_insn.expand = insn->expand;
923 /* Note that if i860_get_expression() fails, we will still
924 have created U entries in the symbol table for the
925 'symbols' in the input string. Try not to create U
926 symbols for registers, etc. */
927 if (! i860_get_expression (s))
938 as_fatal (_("failed sanity check."));
945 /* Args don't match. */
946 if (insn[1].name != NULL
947 && ! strcmp (insn->name, insn[1].name))
955 as_bad (_("Illegal operands for %s"), insn->name);
962 /* Set the dual bit on this instruction if necessary. */
963 if (dual_mode != DUAL_OFF)
965 if ((opcode & 0xfc000000) == 0x48000000 || opcode == 0xb0000000)
967 /* The instruction is a flop or a fnop, so set its dual bit
968 (but check that it is 8-byte aligned). */
969 if (((frag_now->fr_address + frag_now_fix_octets ()) & 7) == 0)
972 as_bad (_("'d.%s' must be 8-byte aligned"), insn->name);
974 if (dual_mode == DUAL_DDOT)
975 dual_mode = DUAL_OFF;
976 else if (dual_mode == DUAL_ONDDOT)
979 else if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
980 as_bad (_("Prefix 'd.' invalid for instruction `%s'"), insn->name);
983 the_insn.opcode = opcode;
985 /* Only recognize XP instructions when the user has requested it. */
986 if (insn->expand == XP_ONLY && ! target_xp)
987 as_bad (_("Unknown opcode: `%s'"), insn->name);
991 i860_get_expression (char *str)
996 save_in = input_line_pointer;
997 input_line_pointer = str;
998 seg = expression (&the_insn.fi[fc].exp);
999 if (seg != absolute_section
1000 && seg != undefined_section
1001 && ! SEG_NORMAL (seg))
1003 the_insn.error = _("bad segment");
1004 expr_end = input_line_pointer;
1005 input_line_pointer = save_in;
1008 expr_end = input_line_pointer;
1009 input_line_pointer = save_in;
1013 /* Turn a string in input_line_pointer into a floating point constant of
1014 type TYPE, and store the appropriate bytes in *LITP. The number of
1015 LITTLENUMS emitted is stored in *SIZEP. An error message is returned,
1018 /* Equal to MAX_PRECISION in atof-ieee.c. */
1019 #define MAX_LITTLENUMS 6
1022 md_atof (int type, char *litP, int *sizeP)
1025 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1026 LITTLENUM_TYPE *wordP;
1057 return _("Bad call to MD_ATOF()");
1059 t = atof_ieee (input_line_pointer, type, words);
1061 input_line_pointer = t;
1062 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1063 for (wordP = words; prec--;)
1065 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1066 litP += sizeof (LITTLENUM_TYPE);
1071 /* Write out in current endian mode. */
1073 md_number_to_chars (char *buf, valueT val, int n)
1075 if (target_big_endian)
1076 number_to_chars_bigendian (buf, val, n);
1078 number_to_chars_littleendian (buf, val, n);
1081 /* This should never be called for i860. */
1083 md_estimate_size_before_relax (register fragS *fragP ATTRIBUTE_UNUSED,
1084 segT segtype ATTRIBUTE_UNUSED)
1086 as_fatal (_("i860_estimate_size_before_relax\n"));
1091 print_insn (struct i860_it *insn)
1094 fprintf (stderr, "ERROR: %s\n", insn->error);
1096 fprintf (stderr, "opcode = 0x%08lx\t", insn->opcode);
1097 fprintf (stderr, "expand = 0x%x\t", insn->expand);
1098 fprintf (stderr, "reloc = %s\t\n",
1099 bfd_get_reloc_code_name (insn->reloc));
1100 fprintf (stderr, "exp = {\n");
1101 fprintf (stderr, "\t\tX_add_symbol = %s\n",
1102 insn->exp.X_add_symbol ?
1103 (S_GET_NAME (insn->exp.X_add_symbol) ?
1104 S_GET_NAME (insn->exp.X_add_symbol) : "???") : "0");
1105 fprintf (stderr, "\t\tX_op_symbol = %s\n",
1106 insn->exp.X_op_symbol ?
1107 (S_GET_NAME (insn->exp.X_op_symbol) ?
1108 S_GET_NAME (insn->exp.X_op_symbol) : "???") : "0");
1109 fprintf (stderr, "\t\tX_add_number = %lx\n",
1110 insn->exp.X_add_number);
1111 fprintf (stderr, "}\n");
1113 #endif /* DEBUG_I860 */
1117 const char *md_shortopts = "VQ:";
1119 const char *md_shortopts = "";
1122 #define OPTION_EB (OPTION_MD_BASE + 0)
1123 #define OPTION_EL (OPTION_MD_BASE + 1)
1124 #define OPTION_WARN_EXPAND (OPTION_MD_BASE + 2)
1125 #define OPTION_XP (OPTION_MD_BASE + 3)
1126 #define OPTION_INTEL_SYNTAX (OPTION_MD_BASE + 4)
1128 struct option md_longopts[] = {
1129 { "EB", no_argument, NULL, OPTION_EB },
1130 { "EL", no_argument, NULL, OPTION_EL },
1131 { "mwarn-expand", no_argument, NULL, OPTION_WARN_EXPAND },
1132 { "mxp", no_argument, NULL, OPTION_XP },
1133 { "mintel-syntax",no_argument, NULL, OPTION_INTEL_SYNTAX },
1134 { NULL, no_argument, NULL, 0 }
1136 size_t md_longopts_size = sizeof (md_longopts);
1139 md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
1144 target_big_endian = 1;
1148 target_big_endian = 0;
1151 case OPTION_WARN_EXPAND:
1152 target_warn_expand = 1;
1159 case OPTION_INTEL_SYNTAX:
1160 target_intel_syntax = 1;
1164 /* SVR4 argument compatibility (-V): print version ID. */
1166 print_version_id ();
1169 /* SVR4 argument compatibility (-Qy, -Qn): controls whether
1170 a .comment section should be emitted or not (ignored). */
1183 md_show_usage (FILE *stream)
1185 fprintf (stream, _("\
1186 -EL generate code for little endian mode (default)\n\
1187 -EB generate code for big endian mode\n\
1188 -mwarn-expand warn if pseudo operations are expanded\n\
1189 -mxp enable i860XP support (disabled by default)\n\
1190 -mintel-syntax enable Intel syntax (default to AT&T/SVR4)\n"));
1192 /* SVR4 compatibility flags. */
1193 fprintf (stream, _("\
1194 -V print assembler version number\n\
1195 -Qy, -Qn ignored\n"));
1200 /* We have no need to default values of symbols. */
1202 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1207 /* The i860 denotes auto-increment with '++'. */
1209 md_operand (expressionS *exp)
1213 for (s = input_line_pointer; *s; s++)
1215 if (s[0] == '+' && s[1] == '+')
1217 input_line_pointer += 2;
1218 exp->X_op = O_register;
1224 /* Round up a section size to the appropriate boundary. */
1226 md_section_align (segT segment ATTRIBUTE_UNUSED,
1227 valueT size ATTRIBUTE_UNUSED)
1229 /* Byte alignment is fine. */
1233 /* On the i860, a PC-relative offset is relative to the address of the
1234 offset plus its size. */
1236 md_pcrel_from (fixS *fixP)
1238 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1241 /* Determine the relocation needed for non PC-relative 16-bit immediates.
1242 Also adjust the given immediate as necessary. Finally, check that
1243 all constraints (such as alignment) are satisfied. */
1244 static bfd_reloc_code_real_type
1245 obtain_reloc_for_imm16 (fixS *fix, long *val)
1247 valueT fup = fix->fx_addnumber;
1248 bfd_reloc_code_real_type reloc;
1253 /* Check alignment restrictions. */
1254 if ((fup & OP_ALIGN2) && (*val & 0x1))
1255 as_bad_where (fix->fx_file, fix->fx_line,
1256 _("This immediate requires 0 MOD 2 alignment"));
1257 else if ((fup & OP_ALIGN4) && (*val & 0x3))
1258 as_bad_where (fix->fx_file, fix->fx_line,
1259 _("This immediate requires 0 MOD 4 alignment"));
1260 else if ((fup & OP_ALIGN8) && (*val & 0x7))
1261 as_bad_where (fix->fx_file, fix->fx_line,
1262 _("This immediate requires 0 MOD 8 alignment"));
1263 else if ((fup & OP_ALIGN16) && (*val & 0xf))
1264 as_bad_where (fix->fx_file, fix->fx_line,
1265 _("This immediate requires 0 MOD 16 alignment"));
1267 if (fup & OP_SEL_HA)
1269 *val = (*val >> 16) + (*val & 0x8000 ? 1 : 0);
1270 reloc = BFD_RELOC_860_HIGHADJ;
1272 else if (fup & OP_SEL_H)
1275 reloc = BFD_RELOC_860_HIGH;
1277 else if (fup & OP_SEL_L)
1280 if (fup & OP_IMM_SPLIT16)
1282 if (fup & OP_ENCODE1)
1285 reloc = BFD_RELOC_860_SPLIT1;
1287 else if (fup & OP_ENCODE2)
1290 reloc = BFD_RELOC_860_SPLIT2;
1295 reloc = BFD_RELOC_860_SPLIT0;
1300 if (fup & OP_ENCODE1)
1303 reloc = BFD_RELOC_860_LOW1;
1305 else if (fup & OP_ENCODE2)
1308 reloc = BFD_RELOC_860_LOW2;
1310 else if (fup & OP_ENCODE3)
1313 reloc = BFD_RELOC_860_LOW3;
1318 reloc = BFD_RELOC_860_LOW0;
1322 /* Preserve size encode bits. */
1323 *val &= ~((1 << num_encode) - 1);
1327 /* No selector. What reloc do we generate (???)? */
1328 reloc = BFD_RELOC_32;
1334 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1335 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1336 we will have to generate a reloc entry. */
1339 md_apply_fix (fixS *fix, valueT *valP, segT seg ATTRIBUTE_UNUSED)
1346 buf = fix->fx_frag->fr_literal + fix->fx_where;
1348 /* Recall that earlier we stored the opcode little-endian. */
1349 insn = bfd_getl32 (buf);
1351 /* We stored a fix-up in this oddly-named scratch field. */
1352 fup = fix->fx_addnumber;
1354 /* Determine the necessary relocations as well as inserting an
1355 immediate into the instruction. */
1356 if (fup & OP_IMM_U5)
1359 as_bad_where (fix->fx_file, fix->fx_line,
1360 _("5-bit immediate too large"));
1362 as_bad_where (fix->fx_file, fix->fx_line,
1363 _("5-bit field must be absolute"));
1365 insn |= (val & 0x1f) << 11;
1366 bfd_putl32 (insn, buf);
1367 fix->fx_r_type = BFD_RELOC_NONE;
1370 else if (fup & OP_IMM_S16)
1372 fix->fx_r_type = obtain_reloc_for_imm16 (fix, &val);
1374 /* Insert the immediate. */
1379 insn |= val & 0xffff;
1380 bfd_putl32 (insn, buf);
1381 fix->fx_r_type = BFD_RELOC_NONE;
1385 else if (fup & OP_IMM_U16)
1388 else if (fup & OP_IMM_SPLIT16)
1390 fix->fx_r_type = obtain_reloc_for_imm16 (fix, &val);
1392 /* Insert the immediate. */
1397 insn |= val & 0x7ff;
1398 insn |= (val & 0xf800) << 5;
1399 bfd_putl32 (insn, buf);
1400 fix->fx_r_type = BFD_RELOC_NONE;
1404 else if (fup & OP_IMM_BR16)
1407 as_bad_where (fix->fx_file, fix->fx_line,
1408 _("A branch offset requires 0 MOD 4 alignment"));
1412 /* Insert the immediate. */
1416 fix->fx_r_type = BFD_RELOC_860_PC16;
1420 insn |= (val & 0x7ff);
1421 insn |= ((val & 0xf800) << 5);
1422 bfd_putl32 (insn, buf);
1423 fix->fx_r_type = BFD_RELOC_NONE;
1427 else if (fup & OP_IMM_BR26)
1430 as_bad_where (fix->fx_file, fix->fx_line,
1431 _("A branch offset requires 0 MOD 4 alignment"));
1435 /* Insert the immediate. */
1438 fix->fx_r_type = BFD_RELOC_860_PC26;
1443 insn |= (val & 0x3ffffff);
1444 bfd_putl32 (insn, buf);
1445 fix->fx_r_type = BFD_RELOC_NONE;
1449 else if (fup != OP_NONE)
1451 as_bad_where (fix->fx_file, fix->fx_line,
1452 _("Unrecognized fix-up (0x%08lx)"), (unsigned long) fup);
1457 /* I believe only fix-ups such as ".long .ep.main-main+0xc8000000"
1458 reach here (???). */
1461 fix->fx_r_type = BFD_RELOC_32;
1466 insn |= (val & 0xffffffff);
1467 bfd_putl32 (insn, buf);
1468 fix->fx_r_type = BFD_RELOC_NONE;
1474 /* Generate a machine dependent reloc from a fixup. */
1476 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1481 reloc = xmalloc (sizeof (*reloc));
1482 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1483 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1484 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1485 reloc->addend = fixp->fx_offset;
1486 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1490 as_bad_where (fixp->fx_file, fixp->fx_line,
1491 "Cannot represent %s relocation in object file",
1492 bfd_get_reloc_code_name (fixp->fx_r_type));
1497 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1498 of an rs_align_code fragment. */
1501 i860_handle_align (fragS *fragp)
1503 /* Instructions are always stored little-endian on the i860. */
1504 static const unsigned char le_nop[] = { 0x00, 0x00, 0x00, 0xA0 };
1509 if (fragp->fr_type != rs_align_code)
1512 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
1513 p = fragp->fr_literal + fragp->fr_fix;
1515 /* Make sure we are on a 4-byte boundary, in case someone has been
1516 putting data into a text section. */
1519 int fix = bytes & 3;
1522 fragp->fr_fix += fix;
1525 memcpy (p, le_nop, 4);
1529 /* This is called after a user-defined label is seen. We check
1530 if the label has a double colon (valid in Intel syntax mode only),
1531 in which case it should be externalized. */
1534 i860_check_label (symbolS *labelsym)
1536 /* At this point, the current line pointer is sitting on the character
1537 just after the first colon on the label. */
1538 if (target_intel_syntax && *input_line_pointer == ':')
1540 S_SET_EXTERNAL (labelsym);
1541 input_line_pointer++;