1 /* tc-i860.c -- Assembler for the Intel i860 architecture.
2 Copyright 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 Brought back from the dead and completely reworked
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 2, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "safe-ctype.h"
29 #include "opcode/i860.h"
32 /* Defined by default since this is primarily a SVR4/860 assembler.
33 However, I'm trying to leave the door open for Intel syntax. Of course,
34 if full support for anything other than SVR4 is done, then we should
35 select this based on a command-line flag. */
38 /* The opcode hash table. */
39 static struct hash_control *op_hash = NULL;
41 /* These characters always start a comment. */
42 const char comment_chars[] = "#!/";
44 /* These characters start a comment at the beginning of a line. */
45 const char line_comment_chars[] = "#/";
47 const char line_separator_chars[] = ";";
49 /* Characters that can be used to separate the mantissa from the exponent
50 in floating point numbers. */
51 const char EXP_CHARS[] = "eE";
53 /* Characters that indicate this number is a floating point constant.
54 As in 0f12.456 or 0d1.2345e12. */
55 const char FLT_CHARS[] = "rRsSfFdDxXpP";
57 /* Register prefix. */
59 static const char reg_prefix = '%';
61 static const char reg_prefix = 0;
70 enum expand_type expand;
74 bfd_reloc_code_real_type reloc;
80 /* The current fixup count. */
83 static char *expr_end;
85 /* Indicates error if a pseudo operation was expanded after a branch. */
86 static char last_expand;
88 /* If true, then warn if any pseudo operations were expanded. */
89 static int target_warn_expand = 0;
91 /* If true, then XP support is enabled. */
92 static int target_xp = 0;
95 static void i860_process_insn PARAMS ((char *));
96 static void s_dual PARAMS ((int));
97 static void s_enddual PARAMS ((int));
98 static void s_atmp PARAMS ((int));
99 static int i860_get_expression PARAMS ((char *));
100 static bfd_reloc_code_real_type obtain_reloc_for_imm16
101 PARAMS ((fixS *, long *));
103 static void print_insn PARAMS ((struct i860_it *));
106 const pseudo_typeS md_pseudo_table[] =
109 {"align", s_align_bytes, 0},
112 {"enddual", s_enddual, 0},
117 /* Dual-instruction mode handling. */
120 DUAL_OFF = 0, DUAL_ON, DUAL_DDOT, DUAL_ONDDOT,
122 static enum dual dual_mode = DUAL_OFF;
124 /* Handle ".dual" directive. */
127 int ignore ATTRIBUTE_UNUSED;
132 /* Handle ".enddual" directive. */
135 int ignore ATTRIBUTE_UNUSED;
137 dual_mode = DUAL_OFF;
140 /* Temporary register used when expanding assembler pseudo operations. */
141 static int atmp = 31;
145 int ignore ATTRIBUTE_UNUSED;
148 if (strncmp (input_line_pointer, "sp", 2) == 0)
150 input_line_pointer += 2;
153 else if (strncmp (input_line_pointer, "fp", 2) == 0)
155 input_line_pointer += 2;
158 else if (strncmp (input_line_pointer, "r", 1) == 0)
160 input_line_pointer += 1;
161 temp = get_absolute_expression ();
162 if (temp >= 0 && temp <= 31)
165 as_bad (_("Unknown temporary pseudo register"));
169 as_bad (_("Unknown temporary pseudo register"));
171 demand_empty_rest_of_line ();
174 /* This function is called once, at assembler startup time. It should
175 set up all the tables and data structures that the MD part of the
176 assembler will need. */
180 const char *retval = NULL;
184 op_hash = hash_new ();
186 while (i860_opcodes[i].name != NULL)
188 const char *name = i860_opcodes[i].name;
189 retval = hash_insert (op_hash, name, (PTR)&i860_opcodes[i]);
192 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
193 i860_opcodes[i].name, retval);
198 if (i860_opcodes[i].match & i860_opcodes[i].lose)
201 _("internal error: losing opcode: `%s' \"%s\"\n"),
202 i860_opcodes[i].name, i860_opcodes[i].args);
207 while (i860_opcodes[i].name != NULL
208 && strcmp (i860_opcodes[i].name, name) == 0);
212 as_fatal (_("Defective assembler. No assembly attempted."));
215 /* This is the core of the machine-dependent assembler. STR points to a
216 machine dependent instruction. This function emits the frags/bytes
225 struct i860_it pseudo[3];
230 /* Assemble the instruction. */
231 i860_process_insn (str);
233 /* Check for expandable flag to produce pseudo-instructions. This
234 is an undesirable feature that should be avoided. */
235 if (the_insn.expand != 0 && the_insn.expand != XP_ONLY
236 && ! (the_insn.fi[0].fup & (OP_SEL_HA | OP_SEL_H | OP_SEL_L | OP_SEL_GOT
237 | OP_SEL_GOTOFF | OP_SEL_PLT)))
239 for (i = 0; i < 3; i++)
240 pseudo[i] = the_insn;
243 switch (the_insn.expand)
251 if (the_insn.fi[0].exp.X_add_symbol == NULL
252 && the_insn.fi[0].exp.X_op_symbol == NULL
253 && (the_insn.fi[0].exp.X_add_number < (1 << 15)
254 && the_insn.fi[0].exp.X_add_number >= -(1 << 15)))
257 /* Emit "or l%const,r0,ireg_dest". */
258 pseudo[0].opcode = (the_insn.opcode & 0x001f0000) | 0xe4000000;
259 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
261 /* Emit "orh h%const,ireg_dest,ireg_dest". */
262 pseudo[1].opcode = (the_insn.opcode & 0x03ffffff) | 0xec000000
263 | ((the_insn.opcode & 0x001f0000) << 5);
264 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
270 if (the_insn.fi[0].exp.X_add_symbol == NULL
271 && the_insn.fi[0].exp.X_op_symbol == NULL
272 && (the_insn.fi[0].exp.X_add_number < (1 << 15)
273 && the_insn.fi[0].exp.X_add_number >= -(1 << 15)))
276 /* Emit "orh ha%addr_expr,r0,r31". */
277 pseudo[0].opcode = 0xec000000 | (atmp << 16);
278 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_HA);
280 /* Emit "l%addr_expr(r31),ireg_dest". We pick up the fixup
281 information from the original instruction. */
282 pseudo[1].opcode = (the_insn.opcode & ~0x03e00000) | (atmp << 21);
283 pseudo[1].fi[0].fup = the_insn.fi[0].fup | OP_SEL_L;
289 if (the_insn.fi[0].exp.X_add_symbol == NULL
290 && the_insn.fi[0].exp.X_op_symbol == NULL
291 && (the_insn.fi[0].exp.X_add_number < (1 << 16)
292 && the_insn.fi[0].exp.X_add_number >= 0))
295 /* Emit "$(opcode)h h%const,ireg_src2,r31". */
296 pseudo[0].opcode = (the_insn.opcode & 0xf3e0ffff) | 0x0c000000
298 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
300 /* Emit "$(opcode) l%const,r31,ireg_dest". */
301 pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000
303 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
309 if (the_insn.fi[0].exp.X_add_symbol == NULL
310 && the_insn.fi[0].exp.X_op_symbol == NULL
311 && (the_insn.fi[0].exp.X_add_number < (1 << 16)
312 && the_insn.fi[0].exp.X_add_number >= 0))
315 /* Emit "andnot h%const,ireg_src2,r31". */
316 pseudo[0].opcode = (the_insn.opcode & 0x03e0ffff) | 0xd4000000
318 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
319 pseudo[0].fi[0].exp.X_add_number =
320 -1 - the_insn.fi[0].exp.X_add_number;
322 /* Emit "andnot l%const,r31,ireg_dest". */
323 pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000
325 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
326 pseudo[1].fi[0].exp.X_add_number =
327 -1 - the_insn.fi[0].exp.X_add_number;
333 if (the_insn.fi[0].exp.X_add_symbol == NULL
334 && the_insn.fi[0].exp.X_op_symbol == NULL
335 && (the_insn.fi[0].exp.X_add_number < (1 << 15)
336 && the_insn.fi[0].exp.X_add_number >= -(1 << 15)))
339 /* Emit "orh h%const,r0,r31". */
340 pseudo[0].opcode = 0xec000000 | (atmp << 16);
341 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
343 /* Emit "or l%const,r31,r31". */
344 pseudo[1].opcode = 0xe4000000 | (atmp << 21) | (atmp << 16);
345 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
347 /* Emit "r31,ireg_src2,ireg_dest". */
348 pseudo[2].opcode = (the_insn.opcode & ~0x0400ffff) | (atmp << 11);
349 pseudo[2].fi[0].fup = OP_IMM_S16;
355 as_fatal (_("failed sanity check."));
358 the_insn = pseudo[0];
360 /* Warn if an opcode is expanded after a delayed branch. */
361 if (num_opcodes > 1 && last_expand == 1)
362 as_warn (_("Expanded opcode after delayed branch: `%s'"), str);
364 /* Warn if an opcode is expanded in dual mode. */
365 if (num_opcodes > 1 && dual_mode != DUAL_OFF)
366 as_warn (_("Expanded opcode in dual mode: `%s'"), str);
368 /* Notify if any expansions happen. */
369 if (target_warn_expand && num_opcodes > 1)
370 as_warn (_("An instruction was expanded (%s)"), str);
378 /* Output the opcode. Note that the i860 always reads instructions
379 as little-endian data. */
380 destp = frag_more (4);
381 number_to_chars_littleendian (destp, the_insn.opcode, 4);
383 /* Check for expanded opcode after branch or in dual mode. */
384 last_expand = the_insn.fi[0].pcrel;
386 /* Output the symbol-dependent stuff. Only btne and bte will ever
387 loop more than once here, since only they (possibly) have more
389 for (tmp = 0; tmp < fc; tmp++)
391 if (the_insn.fi[tmp].fup != OP_NONE)
394 fix = fix_new_exp (frag_now,
395 destp - frag_now->fr_literal,
397 &the_insn.fi[tmp].exp,
398 the_insn.fi[tmp].pcrel,
399 the_insn.fi[tmp].reloc);
401 /* Despite the odd name, this is a scratch field. We use
402 it to encode operand type information. */
403 fix->fx_addnumber = the_insn.fi[tmp].fup;
406 the_insn = pseudo[++i];
408 while (--num_opcodes > 0);
412 /* Assemble the instruction pointed to by STR. */
414 i860_process_insn (str)
420 struct i860_opcode *insn;
422 unsigned long opcode;
427 #if 1 /* For compiler warnings. */
434 for (s = str; ISLOWER (*s) || *s == '.' || *s == '3'
435 || *s == '2' || *s == '1'; ++s)
453 as_fatal (_("Unknown opcode: `%s'"), str);
456 /* Check for dual mode ("d.") opcode prefix. */
457 if (strncmp (str, "d.", 2) == 0)
459 if (dual_mode == DUAL_ON)
460 dual_mode = DUAL_ONDDOT;
462 dual_mode = DUAL_DDOT;
466 if ((insn = (struct i860_opcode *) hash_find (op_hash, str)) == NULL)
468 if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
470 as_bad (_("Unknown opcode: `%s'"), str);
481 opcode = insn->match;
482 memset (&the_insn, '\0', sizeof (the_insn));
484 for (t = 0; t < MAX_FIXUPS; t++)
486 the_insn.fi[t].reloc = BFD_RELOC_NONE;
487 the_insn.fi[t].pcrel = 0;
488 the_insn.fi[t].fup = OP_NONE;
491 /* Build the opcode, checking as we go that the operands match. */
492 for (args = insn->args; ; ++args)
506 /* These must match exactly. */
516 /* Must be at least one digit. */
526 /* Next operand must be a register. */
530 /* Check for register prefix if necessary. */
531 if (reg_prefix && *s != reg_prefix)
558 /* Any register r0..r31. */
561 if (!ISDIGIT (c = *s++))
567 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
575 /* Not this opcode. */
580 /* Obtained the register, now place it in the opcode. */
584 opcode |= mask << 11;
588 opcode |= mask << 21;
592 opcode |= mask << 16;
598 /* Next operand is a floating point register. */
602 /* Check for register prefix if necessary. */
603 if (reg_prefix && *s != reg_prefix)
608 if (*s++ == 'f' && ISDIGIT (*s))
613 mask = 10 * (mask - '0') + (*s++ - '0');
626 opcode |= mask << 11;
630 opcode |= mask << 21;
634 opcode |= mask << 16;
635 if (dual_mode != DUAL_OFF)
637 if (dual_mode == DUAL_DDOT)
638 dual_mode = DUAL_OFF;
639 if (dual_mode == DUAL_ONDDOT)
641 if ((opcode & (1 << 10)) && mask != 0
642 && (mask == ((opcode >> 11) & 0x1f)))
643 as_warn (_("Pipelined instruction: fsrc1 = fdest"));
649 /* Next operand must be a control register. */
651 /* Check for register prefix if necessary. */
652 if (reg_prefix && *s != reg_prefix)
657 if (strncmp (s, "fir", 3) == 0)
663 if (strncmp (s, "psr", 3) == 0)
669 if (strncmp (s, "dirbase", 7) == 0)
675 if (strncmp (s, "db", 2) == 0)
681 if (strncmp (s, "fsr", 3) == 0)
687 if (strncmp (s, "epsr", 4) == 0)
693 /* The remaining control registers are XP only. */
694 if (target_xp && strncmp (s, "bear", 4) == 0)
700 if (target_xp && strncmp (s, "ccr", 3) == 0)
706 if (target_xp && strncmp (s, "p0", 2) == 0)
712 if (target_xp && strncmp (s, "p1", 2) == 0)
718 if (target_xp && strncmp (s, "p2", 2) == 0)
724 if (target_xp && strncmp (s, "p3", 2) == 0)
732 /* 5-bit immediate in src1. */
734 if (! i860_get_expression (s))
737 the_insn.fi[fc].fup |= OP_IMM_U5;
743 /* 26-bit immediate, relative branch (lbroff). */
745 the_insn.fi[fc].pcrel = 1;
746 the_insn.fi[fc].fup |= OP_IMM_BR26;
749 /* 16-bit split immediate, relative branch (sbroff). */
751 the_insn.fi[fc].pcrel = 1;
752 the_insn.fi[fc].fup |= OP_IMM_BR16;
755 /* 16-bit split immediate. */
757 the_insn.fi[fc].fup |= OP_IMM_SPLIT16;
760 /* 16-bit split immediate, byte aligned (st.b). */
762 the_insn.fi[fc].fup |= OP_IMM_SPLIT16;
765 /* 16-bit split immediate, half-word aligned (st.s). */
767 the_insn.fi[fc].fup |= (OP_IMM_SPLIT16 | OP_ENCODE1 | OP_ALIGN2);
770 /* 16-bit split immediate, word aligned (st.l). */
772 the_insn.fi[fc].fup |= (OP_IMM_SPLIT16 | OP_ENCODE1 | OP_ALIGN4);
775 /* 16-bit immediate. */
777 the_insn.fi[fc].fup |= OP_IMM_S16;
780 /* 16-bit immediate, byte aligned (ld.b). */
782 the_insn.fi[fc].fup |= OP_IMM_S16;
785 /* 16-bit immediate, half-word aligned (ld.s). */
787 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE1 | OP_ALIGN2);
790 /* 16-bit immediate, word aligned (ld.l, {p}fld.l, fst.l). */
792 if (insn->name[0] == 'l')
793 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE1 | OP_ALIGN4);
795 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE2 | OP_ALIGN4);
798 /* 16-bit immediate, double-word aligned ({p}fld.d, fst.d). */
800 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE3 | OP_ALIGN8);
803 /* 16-bit immediate, quad-word aligned (fld.q, fst.q). */
805 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE3 | OP_ALIGN16);
809 /* Handle the immediate for either the Intel syntax or
810 SVR4 syntax. The Intel syntax is "ha%immediate"
811 whereas SVR4 syntax is "[immediate]@ha". */
817 /* Note that if i860_get_expression() fails, we will still
818 have created U entries in the symbol table for the
819 'symbols' in the input string. Try not to create U
820 symbols for registers, etc. */
821 if (! i860_get_expression (s))
826 if (strncmp (s, "@ha", 3) == 0)
828 the_insn.fi[fc].fup |= OP_SEL_HA;
831 else if (strncmp (s, "@h", 2) == 0)
833 the_insn.fi[fc].fup |= OP_SEL_H;
836 else if (strncmp (s, "@l", 2) == 0)
838 the_insn.fi[fc].fup |= OP_SEL_L;
841 else if (strncmp (s, "@gotoff", 7) == 0
842 || strncmp (s, "@GOTOFF", 7) == 0)
844 as_bad (_("Assembler does not yet support PIC"));
845 the_insn.fi[fc].fup |= OP_SEL_GOTOFF;
848 else if (strncmp (s, "@got", 4) == 0
849 || strncmp (s, "@GOT", 4) == 0)
851 as_bad (_("Assembler does not yet support PIC"));
852 the_insn.fi[fc].fup |= OP_SEL_GOT;
855 else if (strncmp (s, "@plt", 4) == 0
856 || strncmp (s, "@PLT", 4) == 0)
858 as_bad (_("Assembler does not yet support PIC"));
859 the_insn.fi[fc].fup |= OP_SEL_PLT;
863 the_insn.expand = insn->expand;
867 #else /* ! SYNTAX_SVR4 */
870 if (strncmp (s, "ha%", 3) == 0)
872 the_insn.fi[fc].fup |= OP_SEL_HA;
875 else if (strncmp (s, "h%", 2) == 0)
877 the_insn.fi[fc].fup |= OP_SEL_H;
880 else if (strncmp (s, "l%", 2) == 0)
882 the_insn.fi[fc].fup |= OP_SEL_L;
885 the_insn.expand = insn->expand;
887 /* Note that if i860_get_expression() fails, we will still
888 have created U entries in the symbol table for the
889 'symbols' in the input string. Try not to create U
890 symbols for registers, etc. */
891 if (! i860_get_expression (s))
898 #endif /* SYNTAX_SVR4 */
902 as_fatal (_("failed sanity check."));
909 /* Args don't match. */
910 if (insn[1].name != NULL
911 && ! strcmp (insn->name, insn[1].name))
919 as_bad (_("Illegal operands for %s"), insn->name);
926 the_insn.opcode = opcode;
928 /* Only recognize XP instructions when the user has requested it. */
929 if (insn->expand == XP_ONLY && ! target_xp)
930 as_bad (_("Unknown opcode: `%s'"), insn->name);
934 i860_get_expression (str)
940 save_in = input_line_pointer;
941 input_line_pointer = str;
942 seg = expression (&the_insn.fi[fc].exp);
943 if (seg != absolute_section
944 && seg != undefined_section
945 && ! SEG_NORMAL (seg))
947 the_insn.error = _("bad segment");
948 expr_end = input_line_pointer;
949 input_line_pointer = save_in;
952 expr_end = input_line_pointer;
953 input_line_pointer = save_in;
957 /* Turn a string in input_line_pointer into a floating point constant of
958 type TYPE, and store the appropriate bytes in *LITP. The number of
959 LITTLENUMS emitted is stored in *SIZEP. An error message is returned,
962 /* Equal to MAX_PRECISION in atof-ieee.c. */
963 #define MAX_LITTLENUMS 6
966 md_atof (type, litP, sizeP)
972 LITTLENUM_TYPE words[MAX_LITTLENUMS];
973 LITTLENUM_TYPE *wordP;
1004 return _("Bad call to MD_ATOF()");
1006 t = atof_ieee (input_line_pointer, type, words);
1008 input_line_pointer = t;
1009 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1010 for (wordP = words; prec--;)
1012 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1013 litP += sizeof (LITTLENUM_TYPE);
1018 /* Write out in current endian mode. */
1020 md_number_to_chars (buf, val, n)
1025 if (target_big_endian)
1026 number_to_chars_bigendian (buf, val, n);
1028 number_to_chars_littleendian (buf, val, n);
1031 /* This should never be called for i860. */
1033 md_estimate_size_before_relax (fragP, segtype)
1034 register fragS *fragP ATTRIBUTE_UNUSED;
1035 segT segtype ATTRIBUTE_UNUSED;
1037 as_fatal (_("i860_estimate_size_before_relax\n"));
1043 struct i860_it *insn;
1046 fprintf (stderr, "ERROR: %s\n", insn->error);
1048 fprintf (stderr, "opcode = 0x%08lx\t", insn->opcode);
1049 fprintf (stderr, "expand = 0x%x\t", insn->expand);
1050 fprintf (stderr, "reloc = %s\t\n",
1051 bfd_get_reloc_code_name (insn->reloc));
1052 fprintf (stderr, "exp = {\n");
1053 fprintf (stderr, "\t\tX_add_symbol = %s\n",
1054 insn->exp.X_add_symbol ?
1055 (S_GET_NAME (insn->exp.X_add_symbol) ?
1056 S_GET_NAME (insn->exp.X_add_symbol) : "???") : "0");
1057 fprintf (stderr, "\t\tX_op_symbol = %s\n",
1058 insn->exp.X_op_symbol ?
1059 (S_GET_NAME (insn->exp.X_op_symbol) ?
1060 S_GET_NAME (insn->exp.X_op_symbol) : "???") : "0");
1061 fprintf (stderr, "\t\tX_add_number = %lx\n",
1062 insn->exp.X_add_number);
1063 fprintf (stderr, "}\n");
1065 #endif /* DEBUG_I860 */
1069 const char *md_shortopts = "VQ:";
1071 const char *md_shortopts = "";
1074 #define OPTION_EB (OPTION_MD_BASE + 0)
1075 #define OPTION_EL (OPTION_MD_BASE + 1)
1076 #define OPTION_WARN_EXPAND (OPTION_MD_BASE + 2)
1077 #define OPTION_XP (OPTION_MD_BASE + 3)
1079 struct option md_longopts[] = {
1080 { "EB", no_argument, NULL, OPTION_EB },
1081 { "EL", no_argument, NULL, OPTION_EL },
1082 { "mwarn-expand", no_argument, NULL, OPTION_WARN_EXPAND },
1083 { "mxp", no_argument, NULL, OPTION_XP },
1084 { NULL, no_argument, NULL, 0 }
1086 size_t md_longopts_size = sizeof (md_longopts);
1089 md_parse_option (c, arg)
1091 char *arg ATTRIBUTE_UNUSED;
1096 target_big_endian = 1;
1100 target_big_endian = 0;
1103 case OPTION_WARN_EXPAND:
1104 target_warn_expand = 1;
1112 /* SVR4 argument compatibility (-V): print version ID. */
1114 print_version_id ();
1117 /* SVR4 argument compatibility (-Qy, -Qn): controls whether
1118 a .comment section should be emitted or not (ignored). */
1131 md_show_usage (stream)
1134 fprintf (stream, _("\
1135 -EL generate code for little endian mode (default)\n\
1136 -EB generate code for big endian mode\n\
1137 -mwarn-expand warn if pseudo operations are expanded\n\
1138 -mxp enable i860XP support (disabled by default)\n"));
1140 /* SVR4 compatibility flags. */
1141 fprintf (stream, _("\
1142 -V print assembler version number\n\
1143 -Qy, -Qn ignored\n"));
1148 /* We have no need to default values of symbols. */
1150 md_undefined_symbol (name)
1151 char *name ATTRIBUTE_UNUSED;
1156 /* The i860 denotes auto-increment with '++'. */
1163 for (s = input_line_pointer; *s; s++)
1165 if (s[0] == '+' && s[1] == '+')
1167 input_line_pointer += 2;
1168 exp->X_op = O_register;
1174 /* Round up a section size to the appropriate boundary. */
1176 md_section_align (segment, size)
1177 segT segment ATTRIBUTE_UNUSED;
1178 valueT size ATTRIBUTE_UNUSED;
1180 /* Byte alignment is fine. */
1184 /* On the i860, a PC-relative offset is relative to the address of the
1185 of the offset plus its size. */
1187 md_pcrel_from (fixP)
1190 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1193 /* Determine the relocation needed for non PC-relative 16-bit immediates.
1194 Also adjust the given immediate as necessary. Finally, check that
1195 all constraints (such as alignment) are satisfied. */
1196 static bfd_reloc_code_real_type
1197 obtain_reloc_for_imm16 (fix, val)
1201 valueT fup = fix->fx_addnumber;
1202 bfd_reloc_code_real_type reloc;
1207 /* Check alignment restrictions. */
1208 if ((fup & OP_ALIGN2) && (*val & 0x1))
1209 as_bad_where (fix->fx_file, fix->fx_line,
1210 _("This immediate requires 0 MOD 2 alignment"));
1211 else if ((fup & OP_ALIGN4) && (*val & 0x3))
1212 as_bad_where (fix->fx_file, fix->fx_line,
1213 _("This immediate requires 0 MOD 4 alignment"));
1214 else if ((fup & OP_ALIGN8) && (*val & 0x7))
1215 as_bad_where (fix->fx_file, fix->fx_line,
1216 _("This immediate requires 0 MOD 8 alignment"));
1217 else if ((fup & OP_ALIGN16) && (*val & 0xf))
1218 as_bad_where (fix->fx_file, fix->fx_line,
1219 _("This immediate requires 0 MOD 16 alignment"));
1221 if (fup & OP_SEL_HA)
1223 *val = (*val >> 16) + (*val & 0x8000 ? 1 : 0);
1224 reloc = BFD_RELOC_860_HIGHADJ;
1226 else if (fup & OP_SEL_H)
1229 reloc = BFD_RELOC_860_HIGH;
1231 else if (fup & OP_SEL_L)
1234 if (fup & OP_IMM_SPLIT16)
1236 if (fup & OP_ENCODE1)
1239 reloc = BFD_RELOC_860_SPLIT1;
1241 else if (fup & OP_ENCODE2)
1244 reloc = BFD_RELOC_860_SPLIT2;
1249 reloc = BFD_RELOC_860_SPLIT0;
1254 if (fup & OP_ENCODE1)
1257 reloc = BFD_RELOC_860_LOW1;
1259 else if (fup & OP_ENCODE2)
1262 reloc = BFD_RELOC_860_LOW2;
1264 else if (fup & OP_ENCODE3)
1267 reloc = BFD_RELOC_860_LOW3;
1272 reloc = BFD_RELOC_860_LOW0;
1276 /* Preserve size encode bits. */
1277 *val &= ~((1 << num_encode) - 1);
1281 /* No selector. What reloc do we generate (???)? */
1282 reloc = BFD_RELOC_32;
1288 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1289 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1290 we will have to generate a reloc entry. */
1293 md_apply_fix3 (fix, valP, seg)
1296 segT seg ATTRIBUTE_UNUSED;
1303 buf = fix->fx_frag->fr_literal + fix->fx_where;
1305 /* Recall that earlier we stored the opcode little-endian. */
1306 insn = bfd_getl32 (buf);
1308 /* We stored a fix-up in this oddly-named scratch field. */
1309 fup = fix->fx_addnumber;
1311 /* Determine the necessary relocations as well as inserting an
1312 immediate into the instruction. */
1313 if (fup & OP_IMM_U5)
1316 as_bad_where (fix->fx_file, fix->fx_line,
1317 _("5-bit immediate too large"));
1319 as_bad_where (fix->fx_file, fix->fx_line,
1320 _("5-bit field must be absolute"));
1322 insn |= (val & 0x1f) << 11;
1323 bfd_putl32 (insn, buf);
1324 fix->fx_r_type = BFD_RELOC_NONE;
1327 else if (fup & OP_IMM_S16)
1329 fix->fx_r_type = obtain_reloc_for_imm16 (fix, &val);
1331 /* Insert the immediate. */
1336 insn |= val & 0xffff;
1337 bfd_putl32 (insn, buf);
1338 fix->fx_r_type = BFD_RELOC_NONE;
1342 else if (fup & OP_IMM_U16)
1345 else if (fup & OP_IMM_SPLIT16)
1347 fix->fx_r_type = obtain_reloc_for_imm16 (fix, &val);
1349 /* Insert the immediate. */
1354 insn |= val & 0x7ff;
1355 insn |= (val & 0xf800) << 5;
1356 bfd_putl32 (insn, buf);
1357 fix->fx_r_type = BFD_RELOC_NONE;
1361 else if (fup & OP_IMM_BR16)
1364 as_bad_where (fix->fx_file, fix->fx_line,
1365 _("A branch offset requires 0 MOD 4 alignment"));
1369 /* Insert the immediate. */
1373 fix->fx_r_type = BFD_RELOC_860_PC16;
1377 insn |= (val & 0x7ff);
1378 insn |= ((val & 0xf800) << 5);
1379 bfd_putl32 (insn, buf);
1380 fix->fx_r_type = BFD_RELOC_NONE;
1384 else if (fup & OP_IMM_BR26)
1387 as_bad_where (fix->fx_file, fix->fx_line,
1388 _("A branch offset requires 0 MOD 4 alignment"));
1392 /* Insert the immediate. */
1395 fix->fx_r_type = BFD_RELOC_860_PC26;
1400 insn |= (val & 0x3ffffff);
1401 bfd_putl32 (insn, buf);
1402 fix->fx_r_type = BFD_RELOC_NONE;
1406 else if (fup != OP_NONE)
1408 as_bad_where (fix->fx_file, fix->fx_line,
1409 _("Unrecognized fix-up (0x%08lx)"), (unsigned long) fup);
1414 /* I believe only fix-ups such as ".long .ep.main-main+0xc8000000"
1415 reach here (???). */
1418 fix->fx_r_type = BFD_RELOC_32;
1423 insn |= (val & 0xffffffff);
1424 bfd_putl32 (insn, buf);
1425 fix->fx_r_type = BFD_RELOC_NONE;
1431 /* Generate a machine dependent reloc from a fixup. */
1433 tc_gen_reloc (section, fixp)
1434 asection *section ATTRIBUTE_UNUSED;
1439 reloc = xmalloc (sizeof (*reloc));
1440 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1441 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1442 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1443 reloc->addend = fixp->fx_offset;
1444 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1448 as_bad_where (fixp->fx_file, fixp->fx_line,
1449 "Cannot represent %s relocation in object file",
1450 bfd_get_reloc_code_name (fixp->fx_r_type));