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
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 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"
33 /* The opcode hash table. */
34 static struct hash_control
*op_hash
= NULL
;
36 /* These characters always start a comment. */
37 const char comment_chars
[] = "#!/";
39 /* These characters start a comment at the beginning of a line. */
40 const char line_comment_chars
[] = "#/";
42 const char line_separator_chars
[] = ";";
44 /* Characters that can be used to separate the mantissa from the exponent
45 in floating point numbers. */
46 const char EXP_CHARS
[] = "eE";
48 /* Characters that indicate this number is a floating point constant.
49 As in 0f12.456 or 0d1.2345e12. */
50 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
52 /* Register prefix (depends on syntax). */
53 static char reg_prefix
;
61 enum expand_type expand
;
65 bfd_reloc_code_real_type reloc
;
71 /* The current fixup count. */
74 static char *expr_end
;
76 /* Indicates error if a pseudo operation was expanded after a branch. */
77 static char last_expand
;
79 /* If true, then warn if any pseudo operations were expanded. */
80 static int target_warn_expand
= 0;
82 /* If true, then XP support is enabled. */
83 static int target_xp
= 0;
85 /* If true, then Intel syntax is enabled (default to AT&T/SVR4 syntax). */
86 static int target_intel_syntax
= 0;
90 static void i860_process_insn (char *);
91 static void s_dual (int);
92 static void s_enddual (int);
93 static void s_atmp (int);
94 static int i860_get_expression (char *);
95 static bfd_reloc_code_real_type
obtain_reloc_for_imm16 (fixS
*, long *);
97 static void print_insn (struct i860_it
*);
100 const pseudo_typeS md_pseudo_table
[] =
103 {"align", s_align_bytes
, 0},
106 {"enddual", s_enddual
, 0},
111 /* Dual-instruction mode handling. */
114 DUAL_OFF
= 0, DUAL_ON
, DUAL_DDOT
, DUAL_ONDDOT
,
116 static enum dual dual_mode
= DUAL_OFF
;
118 /* Handle ".dual" directive. */
120 s_dual (int ignore ATTRIBUTE_UNUSED
)
125 /* Handle ".enddual" directive. */
127 s_enddual (int ignore ATTRIBUTE_UNUSED
)
129 dual_mode
= DUAL_OFF
;
132 /* Temporary register used when expanding assembler pseudo operations. */
133 static int atmp
= 31;
136 s_atmp (int ignore ATTRIBUTE_UNUSED
)
139 if (strncmp (input_line_pointer
, "sp", 2) == 0)
141 input_line_pointer
+= 2;
144 else if (strncmp (input_line_pointer
, "fp", 2) == 0)
146 input_line_pointer
+= 2;
149 else if (strncmp (input_line_pointer
, "r", 1) == 0)
151 input_line_pointer
+= 1;
152 temp
= get_absolute_expression ();
153 if (temp
>= 0 && temp
<= 31)
156 as_bad (_("Unknown temporary pseudo register"));
160 as_bad (_("Unknown temporary pseudo register"));
162 demand_empty_rest_of_line ();
165 /* This function is called once, at assembler startup time. It should
166 set up all the tables and data structures that the MD part of the
167 assembler will need. */
171 const char *retval
= NULL
;
175 op_hash
= hash_new ();
177 while (i860_opcodes
[i
].name
!= NULL
)
179 const char *name
= i860_opcodes
[i
].name
;
180 retval
= hash_insert (op_hash
, name
, (PTR
)&i860_opcodes
[i
]);
183 fprintf (stderr
, _("internal error: can't hash `%s': %s\n"),
184 i860_opcodes
[i
].name
, retval
);
189 if (i860_opcodes
[i
].match
& i860_opcodes
[i
].lose
)
192 _("internal error: losing opcode: `%s' \"%s\"\n"),
193 i860_opcodes
[i
].name
, i860_opcodes
[i
].args
);
198 while (i860_opcodes
[i
].name
!= NULL
199 && strcmp (i860_opcodes
[i
].name
, name
) == 0);
203 as_fatal (_("Defective assembler. No assembly attempted."));
205 /* Set the register prefix for either Intel or AT&T/SVR4 syntax. */
206 reg_prefix
= target_intel_syntax
? 0 : '%';
209 /* This is the core of the machine-dependent assembler. STR points to a
210 machine dependent instruction. This function emits the frags/bytes
213 md_assemble (char *str
)
218 struct i860_it pseudo
[3];
223 /* Assemble the instruction. */
224 i860_process_insn (str
);
226 /* Check for expandable flag to produce pseudo-instructions. This
227 is an undesirable feature that should be avoided. */
228 if (the_insn
.expand
!= 0 && the_insn
.expand
!= XP_ONLY
229 && ! (the_insn
.fi
[0].fup
& (OP_SEL_HA
| OP_SEL_H
| OP_SEL_L
| OP_SEL_GOT
230 | OP_SEL_GOTOFF
| OP_SEL_PLT
)))
232 for (i
= 0; i
< 3; i
++)
233 pseudo
[i
] = the_insn
;
236 switch (the_insn
.expand
)
244 if (the_insn
.fi
[0].exp
.X_add_symbol
== NULL
245 && the_insn
.fi
[0].exp
.X_op_symbol
== NULL
246 && (the_insn
.fi
[0].exp
.X_add_number
< (1 << 15)
247 && the_insn
.fi
[0].exp
.X_add_number
>= -(1 << 15)))
250 /* Emit "or l%const,r0,ireg_dest". */
251 pseudo
[0].opcode
= (the_insn
.opcode
& 0x001f0000) | 0xe4000000;
252 pseudo
[0].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_L
);
254 /* Emit "orh h%const,ireg_dest,ireg_dest". */
255 pseudo
[1].opcode
= (the_insn
.opcode
& 0x03ffffff) | 0xec000000
256 | ((the_insn
.opcode
& 0x001f0000) << 5);
257 pseudo
[1].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_H
);
263 if (the_insn
.fi
[0].exp
.X_add_symbol
== NULL
264 && the_insn
.fi
[0].exp
.X_op_symbol
== NULL
265 && (the_insn
.fi
[0].exp
.X_add_number
< (1 << 15)
266 && the_insn
.fi
[0].exp
.X_add_number
>= -(1 << 15)))
269 /* Emit "orh ha%addr_expr,r0,r31". */
270 pseudo
[0].opcode
= 0xec000000 | (atmp
<< 16);
271 pseudo
[0].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_HA
);
273 /* Emit "l%addr_expr(r31),ireg_dest". We pick up the fixup
274 information from the original instruction. */
275 pseudo
[1].opcode
= (the_insn
.opcode
& ~0x03e00000) | (atmp
<< 21);
276 pseudo
[1].fi
[0].fup
= the_insn
.fi
[0].fup
| OP_SEL_L
;
282 if (the_insn
.fi
[0].exp
.X_add_symbol
== NULL
283 && the_insn
.fi
[0].exp
.X_op_symbol
== NULL
284 && (the_insn
.fi
[0].exp
.X_add_number
< (1 << 16)
285 && the_insn
.fi
[0].exp
.X_add_number
>= 0))
288 /* Emit "$(opcode)h h%const,ireg_src2,r31". */
289 pseudo
[0].opcode
= (the_insn
.opcode
& 0xf3e0ffff) | 0x0c000000
291 pseudo
[0].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_H
);
293 /* Emit "$(opcode) l%const,r31,ireg_dest". */
294 pseudo
[1].opcode
= (the_insn
.opcode
& 0xf01f0000) | 0x04000000
296 pseudo
[1].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_L
);
302 if (the_insn
.fi
[0].exp
.X_add_symbol
== NULL
303 && the_insn
.fi
[0].exp
.X_op_symbol
== NULL
304 && (the_insn
.fi
[0].exp
.X_add_number
< (1 << 16)
305 && the_insn
.fi
[0].exp
.X_add_number
>= 0))
308 /* Emit "andnot h%const,ireg_src2,r31". */
309 pseudo
[0].opcode
= (the_insn
.opcode
& 0x03e0ffff) | 0xd4000000
311 pseudo
[0].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_H
);
312 pseudo
[0].fi
[0].exp
.X_add_number
=
313 -1 - the_insn
.fi
[0].exp
.X_add_number
;
315 /* Emit "andnot l%const,r31,ireg_dest". */
316 pseudo
[1].opcode
= (the_insn
.opcode
& 0x001f0000) | 0xd4000000
318 pseudo
[1].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_L
);
319 pseudo
[1].fi
[0].exp
.X_add_number
=
320 -1 - the_insn
.fi
[0].exp
.X_add_number
;
326 if (the_insn
.fi
[0].exp
.X_add_symbol
== NULL
327 && the_insn
.fi
[0].exp
.X_op_symbol
== NULL
328 && (the_insn
.fi
[0].exp
.X_add_number
< (1 << 15)
329 && the_insn
.fi
[0].exp
.X_add_number
>= -(1 << 15)))
332 /* Emit "orh h%const,r0,r31". */
333 pseudo
[0].opcode
= 0xec000000 | (atmp
<< 16);
334 pseudo
[0].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_H
);
336 /* Emit "or l%const,r31,r31". */
337 pseudo
[1].opcode
= 0xe4000000 | (atmp
<< 21) | (atmp
<< 16);
338 pseudo
[1].fi
[0].fup
= (OP_IMM_S16
| OP_SEL_L
);
340 /* Emit "r31,ireg_src2,ireg_dest". */
341 pseudo
[2].opcode
= (the_insn
.opcode
& ~0x0400ffff) | (atmp
<< 11);
342 pseudo
[2].fi
[0].fup
= OP_IMM_S16
;
348 as_fatal (_("failed sanity check."));
351 the_insn
= pseudo
[0];
353 /* Warn if an opcode is expanded after a delayed branch. */
354 if (num_opcodes
> 1 && last_expand
== 1)
355 as_warn (_("Expanded opcode after delayed branch: `%s'"), str
);
357 /* Warn if an opcode is expanded in dual mode. */
358 if (num_opcodes
> 1 && dual_mode
!= DUAL_OFF
)
359 as_warn (_("Expanded opcode in dual mode: `%s'"), str
);
361 /* Notify if any expansions happen. */
362 if (target_warn_expand
&& num_opcodes
> 1)
363 as_warn (_("An instruction was expanded (%s)"), str
);
371 /* Output the opcode. Note that the i860 always reads instructions
372 as little-endian data. */
373 destp
= frag_more (4);
374 number_to_chars_littleendian (destp
, the_insn
.opcode
, 4);
376 /* Check for expanded opcode after branch or in dual mode. */
377 last_expand
= the_insn
.fi
[0].pcrel
;
379 /* Output the symbol-dependent stuff. Only btne and bte will ever
380 loop more than once here, since only they (possibly) have more
382 for (tmp
= 0; tmp
< fc
; tmp
++)
384 if (the_insn
.fi
[tmp
].fup
!= OP_NONE
)
387 fix
= fix_new_exp (frag_now
,
388 destp
- frag_now
->fr_literal
,
390 &the_insn
.fi
[tmp
].exp
,
391 the_insn
.fi
[tmp
].pcrel
,
392 the_insn
.fi
[tmp
].reloc
);
394 /* Despite the odd name, this is a scratch field. We use
395 it to encode operand type information. */
396 fix
->fx_addnumber
= the_insn
.fi
[tmp
].fup
;
399 the_insn
= pseudo
[++i
];
401 while (--num_opcodes
> 0);
405 /* Assemble the instruction pointed to by STR. */
407 i860_process_insn (char *str
)
412 struct i860_opcode
*insn
;
414 unsigned long opcode
;
419 #if 1 /* For compiler warnings. */
426 for (s
= str
; ISLOWER (*s
) || *s
== '.' || *s
== '3'
427 || *s
== '2' || *s
== '1'; ++s
)
445 as_fatal (_("Unknown opcode: `%s'"), str
);
448 /* Check for dual mode ("d.") opcode prefix. */
449 if (strncmp (str
, "d.", 2) == 0)
451 if (dual_mode
== DUAL_ON
)
452 dual_mode
= DUAL_ONDDOT
;
454 dual_mode
= DUAL_DDOT
;
458 if ((insn
= (struct i860_opcode
*) hash_find (op_hash
, str
)) == NULL
)
460 if (dual_mode
== DUAL_DDOT
|| dual_mode
== DUAL_ONDDOT
)
462 as_bad (_("Unknown opcode: `%s'"), str
);
473 opcode
= insn
->match
;
474 memset (&the_insn
, '\0', sizeof (the_insn
));
476 for (t
= 0; t
< MAX_FIXUPS
; t
++)
478 the_insn
.fi
[t
].reloc
= BFD_RELOC_NONE
;
479 the_insn
.fi
[t
].pcrel
= 0;
480 the_insn
.fi
[t
].fup
= OP_NONE
;
483 /* Build the opcode, checking as we go that the operands match. */
484 for (args
= insn
->args
; ; ++args
)
498 /* These must match exactly. */
508 /* Must be at least one digit. */
518 /* Next operand must be a register. */
522 /* Check for register prefix if necessary. */
523 if (reg_prefix
&& *s
!= reg_prefix
)
550 /* Any register r0..r31. */
553 if (!ISDIGIT (c
= *s
++))
559 if ((c
= 10 * (c
- '0') + (*s
++ - '0')) >= 32)
567 /* Not this opcode. */
572 /* Obtained the register, now place it in the opcode. */
576 opcode
|= mask
<< 11;
580 opcode
|= mask
<< 21;
584 opcode
|= mask
<< 16;
590 /* Next operand is a floating point register. */
594 /* Check for register prefix if necessary. */
595 if (reg_prefix
&& *s
!= reg_prefix
)
600 if (*s
++ == 'f' && ISDIGIT (*s
))
605 mask
= 10 * (mask
- '0') + (*s
++ - '0');
618 opcode
|= mask
<< 11;
622 opcode
|= mask
<< 21;
626 opcode
|= mask
<< 16;
627 if (dual_mode
!= DUAL_OFF
)
629 if (dual_mode
== DUAL_DDOT
)
630 dual_mode
= DUAL_OFF
;
631 if (dual_mode
== DUAL_ONDDOT
)
633 if ((opcode
& (1 << 10)) && mask
!= 0
634 && (mask
== ((opcode
>> 11) & 0x1f)))
635 as_warn (_("Pipelined instruction: fsrc1 = fdest"));
641 /* Next operand must be a control register. */
643 /* Check for register prefix if necessary. */
644 if (reg_prefix
&& *s
!= reg_prefix
)
649 if (strncmp (s
, "fir", 3) == 0)
655 if (strncmp (s
, "psr", 3) == 0)
661 if (strncmp (s
, "dirbase", 7) == 0)
667 if (strncmp (s
, "db", 2) == 0)
673 if (strncmp (s
, "fsr", 3) == 0)
679 if (strncmp (s
, "epsr", 4) == 0)
685 /* The remaining control registers are XP only. */
686 if (target_xp
&& strncmp (s
, "bear", 4) == 0)
692 if (target_xp
&& strncmp (s
, "ccr", 3) == 0)
698 if (target_xp
&& strncmp (s
, "p0", 2) == 0)
704 if (target_xp
&& strncmp (s
, "p1", 2) == 0)
710 if (target_xp
&& strncmp (s
, "p2", 2) == 0)
716 if (target_xp
&& strncmp (s
, "p3", 2) == 0)
724 /* 5-bit immediate in src1. */
726 if (! i860_get_expression (s
))
729 the_insn
.fi
[fc
].fup
|= OP_IMM_U5
;
735 /* 26-bit immediate, relative branch (lbroff). */
737 the_insn
.fi
[fc
].pcrel
= 1;
738 the_insn
.fi
[fc
].fup
|= OP_IMM_BR26
;
741 /* 16-bit split immediate, relative branch (sbroff). */
743 the_insn
.fi
[fc
].pcrel
= 1;
744 the_insn
.fi
[fc
].fup
|= OP_IMM_BR16
;
747 /* 16-bit split immediate. */
749 the_insn
.fi
[fc
].fup
|= OP_IMM_SPLIT16
;
752 /* 16-bit split immediate, byte aligned (st.b). */
754 the_insn
.fi
[fc
].fup
|= OP_IMM_SPLIT16
;
757 /* 16-bit split immediate, half-word aligned (st.s). */
759 the_insn
.fi
[fc
].fup
|= (OP_IMM_SPLIT16
| OP_ENCODE1
| OP_ALIGN2
);
762 /* 16-bit split immediate, word aligned (st.l). */
764 the_insn
.fi
[fc
].fup
|= (OP_IMM_SPLIT16
| OP_ENCODE1
| OP_ALIGN4
);
767 /* 16-bit immediate. */
769 the_insn
.fi
[fc
].fup
|= OP_IMM_S16
;
772 /* 16-bit immediate, byte aligned (ld.b). */
774 the_insn
.fi
[fc
].fup
|= OP_IMM_S16
;
777 /* 16-bit immediate, half-word aligned (ld.s). */
779 the_insn
.fi
[fc
].fup
|= (OP_IMM_S16
| OP_ENCODE1
| OP_ALIGN2
);
782 /* 16-bit immediate, word aligned (ld.l, {p}fld.l, fst.l). */
784 if (insn
->name
[0] == 'l')
785 the_insn
.fi
[fc
].fup
|= (OP_IMM_S16
| OP_ENCODE1
| OP_ALIGN4
);
787 the_insn
.fi
[fc
].fup
|= (OP_IMM_S16
| OP_ENCODE2
| OP_ALIGN4
);
790 /* 16-bit immediate, double-word aligned ({p}fld.d, fst.d). */
792 the_insn
.fi
[fc
].fup
|= (OP_IMM_S16
| OP_ENCODE3
| OP_ALIGN8
);
795 /* 16-bit immediate, quad-word aligned (fld.q, fst.q). */
797 the_insn
.fi
[fc
].fup
|= (OP_IMM_S16
| OP_ENCODE3
| OP_ALIGN16
);
801 /* Handle the immediate for either the Intel syntax or
802 SVR4 syntax. The Intel syntax is "ha%immediate"
803 whereas SVR4 syntax is "[immediate]@ha". */
805 if (target_intel_syntax
== 0)
807 /* AT&T/SVR4 syntax. */
811 /* Note that if i860_get_expression() fails, we will still
812 have created U entries in the symbol table for the
813 'symbols' in the input string. Try not to create U
814 symbols for registers, etc. */
815 if (! i860_get_expression (s
))
820 if (strncmp (s
, "@ha", 3) == 0)
822 the_insn
.fi
[fc
].fup
|= OP_SEL_HA
;
825 else if (strncmp (s
, "@h", 2) == 0)
827 the_insn
.fi
[fc
].fup
|= OP_SEL_H
;
830 else if (strncmp (s
, "@l", 2) == 0)
832 the_insn
.fi
[fc
].fup
|= OP_SEL_L
;
835 else if (strncmp (s
, "@gotoff", 7) == 0
836 || strncmp (s
, "@GOTOFF", 7) == 0)
838 as_bad (_("Assembler does not yet support PIC"));
839 the_insn
.fi
[fc
].fup
|= OP_SEL_GOTOFF
;
842 else if (strncmp (s
, "@got", 4) == 0
843 || strncmp (s
, "@GOT", 4) == 0)
845 as_bad (_("Assembler does not yet support PIC"));
846 the_insn
.fi
[fc
].fup
|= OP_SEL_GOT
;
849 else if (strncmp (s
, "@plt", 4) == 0
850 || strncmp (s
, "@PLT", 4) == 0)
852 as_bad (_("Assembler does not yet support PIC"));
853 the_insn
.fi
[fc
].fup
|= OP_SEL_PLT
;
857 the_insn
.expand
= insn
->expand
;
867 if (strncmp (s
, "ha%", 3) == 0)
869 the_insn
.fi
[fc
].fup
|= OP_SEL_HA
;
872 else if (strncmp (s
, "h%", 2) == 0)
874 the_insn
.fi
[fc
].fup
|= OP_SEL_H
;
877 else if (strncmp (s
, "l%", 2) == 0)
879 the_insn
.fi
[fc
].fup
|= OP_SEL_L
;
882 the_insn
.expand
= insn
->expand
;
884 /* Note that if i860_get_expression() fails, we will still
885 have created U entries in the symbol table for the
886 'symbols' in the input string. Try not to create U
887 symbols for registers, etc. */
888 if (! i860_get_expression (s
))
899 as_fatal (_("failed sanity check."));
906 /* Args don't match. */
907 if (insn
[1].name
!= NULL
908 && ! strcmp (insn
->name
, insn
[1].name
))
916 as_bad (_("Illegal operands for %s"), insn
->name
);
923 the_insn
.opcode
= opcode
;
925 /* Only recognize XP instructions when the user has requested it. */
926 if (insn
->expand
== XP_ONLY
&& ! target_xp
)
927 as_bad (_("Unknown opcode: `%s'"), insn
->name
);
931 i860_get_expression (char *str
)
936 save_in
= input_line_pointer
;
937 input_line_pointer
= str
;
938 seg
= expression (&the_insn
.fi
[fc
].exp
);
939 if (seg
!= absolute_section
940 && seg
!= undefined_section
941 && ! SEG_NORMAL (seg
))
943 the_insn
.error
= _("bad segment");
944 expr_end
= input_line_pointer
;
945 input_line_pointer
= save_in
;
948 expr_end
= input_line_pointer
;
949 input_line_pointer
= save_in
;
953 /* Turn a string in input_line_pointer into a floating point constant of
954 type TYPE, and store the appropriate bytes in *LITP. The number of
955 LITTLENUMS emitted is stored in *SIZEP. An error message is returned,
958 /* Equal to MAX_PRECISION in atof-ieee.c. */
959 #define MAX_LITTLENUMS 6
962 md_atof (int type
, char *litP
, int *sizeP
)
965 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
966 LITTLENUM_TYPE
*wordP
;
997 return _("Bad call to MD_ATOF()");
999 t
= atof_ieee (input_line_pointer
, type
, words
);
1001 input_line_pointer
= t
;
1002 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1003 for (wordP
= words
; prec
--;)
1005 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1006 litP
+= sizeof (LITTLENUM_TYPE
);
1011 /* Write out in current endian mode. */
1013 md_number_to_chars (char *buf
, valueT val
, int n
)
1015 if (target_big_endian
)
1016 number_to_chars_bigendian (buf
, val
, n
);
1018 number_to_chars_littleendian (buf
, val
, n
);
1021 /* This should never be called for i860. */
1023 md_estimate_size_before_relax (register fragS
*fragP ATTRIBUTE_UNUSED
,
1024 segT segtype ATTRIBUTE_UNUSED
)
1026 as_fatal (_("i860_estimate_size_before_relax\n"));
1031 print_insn (struct i860_it
*insn
)
1034 fprintf (stderr
, "ERROR: %s\n", insn
->error
);
1036 fprintf (stderr
, "opcode = 0x%08lx\t", insn
->opcode
);
1037 fprintf (stderr
, "expand = 0x%x\t", insn
->expand
);
1038 fprintf (stderr
, "reloc = %s\t\n",
1039 bfd_get_reloc_code_name (insn
->reloc
));
1040 fprintf (stderr
, "exp = {\n");
1041 fprintf (stderr
, "\t\tX_add_symbol = %s\n",
1042 insn
->exp
.X_add_symbol
?
1043 (S_GET_NAME (insn
->exp
.X_add_symbol
) ?
1044 S_GET_NAME (insn
->exp
.X_add_symbol
) : "???") : "0");
1045 fprintf (stderr
, "\t\tX_op_symbol = %s\n",
1046 insn
->exp
.X_op_symbol
?
1047 (S_GET_NAME (insn
->exp
.X_op_symbol
) ?
1048 S_GET_NAME (insn
->exp
.X_op_symbol
) : "???") : "0");
1049 fprintf (stderr
, "\t\tX_add_number = %lx\n",
1050 insn
->exp
.X_add_number
);
1051 fprintf (stderr
, "}\n");
1053 #endif /* DEBUG_I860 */
1057 const char *md_shortopts
= "VQ:";
1059 const char *md_shortopts
= "";
1062 #define OPTION_EB (OPTION_MD_BASE + 0)
1063 #define OPTION_EL (OPTION_MD_BASE + 1)
1064 #define OPTION_WARN_EXPAND (OPTION_MD_BASE + 2)
1065 #define OPTION_XP (OPTION_MD_BASE + 3)
1066 #define OPTION_INTEL_SYNTAX (OPTION_MD_BASE + 4)
1068 struct option md_longopts
[] = {
1069 { "EB", no_argument
, NULL
, OPTION_EB
},
1070 { "EL", no_argument
, NULL
, OPTION_EL
},
1071 { "mwarn-expand", no_argument
, NULL
, OPTION_WARN_EXPAND
},
1072 { "mxp", no_argument
, NULL
, OPTION_XP
},
1073 { "mintel-syntax",no_argument
, NULL
, OPTION_INTEL_SYNTAX
},
1074 { NULL
, no_argument
, NULL
, 0 }
1076 size_t md_longopts_size
= sizeof (md_longopts
);
1079 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
1084 target_big_endian
= 1;
1088 target_big_endian
= 0;
1091 case OPTION_WARN_EXPAND
:
1092 target_warn_expand
= 1;
1099 case OPTION_INTEL_SYNTAX
:
1100 target_intel_syntax
= 1;
1104 /* SVR4 argument compatibility (-V): print version ID. */
1106 print_version_id ();
1109 /* SVR4 argument compatibility (-Qy, -Qn): controls whether
1110 a .comment section should be emitted or not (ignored). */
1123 md_show_usage (FILE *stream
)
1125 fprintf (stream
, _("\
1126 -EL generate code for little endian mode (default)\n\
1127 -EB generate code for big endian mode\n\
1128 -mwarn-expand warn if pseudo operations are expanded\n\
1129 -mxp enable i860XP support (disabled by default)\n\
1130 -mintel-syntax enable Intel syntax (default to AT&T/SVR4)\n"));
1132 /* SVR4 compatibility flags. */
1133 fprintf (stream
, _("\
1134 -V print assembler version number\n\
1135 -Qy, -Qn ignored\n"));
1140 /* We have no need to default values of symbols. */
1142 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1147 /* The i860 denotes auto-increment with '++'. */
1149 md_operand (expressionS
*exp
)
1153 for (s
= input_line_pointer
; *s
; s
++)
1155 if (s
[0] == '+' && s
[1] == '+')
1157 input_line_pointer
+= 2;
1158 exp
->X_op
= O_register
;
1164 /* Round up a section size to the appropriate boundary. */
1166 md_section_align (segT segment ATTRIBUTE_UNUSED
,
1167 valueT size ATTRIBUTE_UNUSED
)
1169 /* Byte alignment is fine. */
1173 /* On the i860, a PC-relative offset is relative to the address of the
1174 of the offset plus its size. */
1176 md_pcrel_from (fixS
*fixP
)
1178 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1181 /* Determine the relocation needed for non PC-relative 16-bit immediates.
1182 Also adjust the given immediate as necessary. Finally, check that
1183 all constraints (such as alignment) are satisfied. */
1184 static bfd_reloc_code_real_type
1185 obtain_reloc_for_imm16 (fixS
*fix
, long *val
)
1187 valueT fup
= fix
->fx_addnumber
;
1188 bfd_reloc_code_real_type reloc
;
1193 /* Check alignment restrictions. */
1194 if ((fup
& OP_ALIGN2
) && (*val
& 0x1))
1195 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1196 _("This immediate requires 0 MOD 2 alignment"));
1197 else if ((fup
& OP_ALIGN4
) && (*val
& 0x3))
1198 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1199 _("This immediate requires 0 MOD 4 alignment"));
1200 else if ((fup
& OP_ALIGN8
) && (*val
& 0x7))
1201 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1202 _("This immediate requires 0 MOD 8 alignment"));
1203 else if ((fup
& OP_ALIGN16
) && (*val
& 0xf))
1204 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1205 _("This immediate requires 0 MOD 16 alignment"));
1207 if (fup
& OP_SEL_HA
)
1209 *val
= (*val
>> 16) + (*val
& 0x8000 ? 1 : 0);
1210 reloc
= BFD_RELOC_860_HIGHADJ
;
1212 else if (fup
& OP_SEL_H
)
1215 reloc
= BFD_RELOC_860_HIGH
;
1217 else if (fup
& OP_SEL_L
)
1220 if (fup
& OP_IMM_SPLIT16
)
1222 if (fup
& OP_ENCODE1
)
1225 reloc
= BFD_RELOC_860_SPLIT1
;
1227 else if (fup
& OP_ENCODE2
)
1230 reloc
= BFD_RELOC_860_SPLIT2
;
1235 reloc
= BFD_RELOC_860_SPLIT0
;
1240 if (fup
& OP_ENCODE1
)
1243 reloc
= BFD_RELOC_860_LOW1
;
1245 else if (fup
& OP_ENCODE2
)
1248 reloc
= BFD_RELOC_860_LOW2
;
1250 else if (fup
& OP_ENCODE3
)
1253 reloc
= BFD_RELOC_860_LOW3
;
1258 reloc
= BFD_RELOC_860_LOW0
;
1262 /* Preserve size encode bits. */
1263 *val
&= ~((1 << num_encode
) - 1);
1267 /* No selector. What reloc do we generate (???)? */
1268 reloc
= BFD_RELOC_32
;
1274 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1275 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1276 we will have to generate a reloc entry. */
1279 md_apply_fix3 (fixS
*fix
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
1286 buf
= fix
->fx_frag
->fr_literal
+ fix
->fx_where
;
1288 /* Recall that earlier we stored the opcode little-endian. */
1289 insn
= bfd_getl32 (buf
);
1291 /* We stored a fix-up in this oddly-named scratch field. */
1292 fup
= fix
->fx_addnumber
;
1294 /* Determine the necessary relocations as well as inserting an
1295 immediate into the instruction. */
1296 if (fup
& OP_IMM_U5
)
1299 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1300 _("5-bit immediate too large"));
1302 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1303 _("5-bit field must be absolute"));
1305 insn
|= (val
& 0x1f) << 11;
1306 bfd_putl32 (insn
, buf
);
1307 fix
->fx_r_type
= BFD_RELOC_NONE
;
1310 else if (fup
& OP_IMM_S16
)
1312 fix
->fx_r_type
= obtain_reloc_for_imm16 (fix
, &val
);
1314 /* Insert the immediate. */
1319 insn
|= val
& 0xffff;
1320 bfd_putl32 (insn
, buf
);
1321 fix
->fx_r_type
= BFD_RELOC_NONE
;
1325 else if (fup
& OP_IMM_U16
)
1328 else if (fup
& OP_IMM_SPLIT16
)
1330 fix
->fx_r_type
= obtain_reloc_for_imm16 (fix
, &val
);
1332 /* Insert the immediate. */
1337 insn
|= val
& 0x7ff;
1338 insn
|= (val
& 0xf800) << 5;
1339 bfd_putl32 (insn
, buf
);
1340 fix
->fx_r_type
= BFD_RELOC_NONE
;
1344 else if (fup
& OP_IMM_BR16
)
1347 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1348 _("A branch offset requires 0 MOD 4 alignment"));
1352 /* Insert the immediate. */
1356 fix
->fx_r_type
= BFD_RELOC_860_PC16
;
1360 insn
|= (val
& 0x7ff);
1361 insn
|= ((val
& 0xf800) << 5);
1362 bfd_putl32 (insn
, buf
);
1363 fix
->fx_r_type
= BFD_RELOC_NONE
;
1367 else if (fup
& OP_IMM_BR26
)
1370 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1371 _("A branch offset requires 0 MOD 4 alignment"));
1375 /* Insert the immediate. */
1378 fix
->fx_r_type
= BFD_RELOC_860_PC26
;
1383 insn
|= (val
& 0x3ffffff);
1384 bfd_putl32 (insn
, buf
);
1385 fix
->fx_r_type
= BFD_RELOC_NONE
;
1389 else if (fup
!= OP_NONE
)
1391 as_bad_where (fix
->fx_file
, fix
->fx_line
,
1392 _("Unrecognized fix-up (0x%08lx)"), (unsigned long) fup
);
1397 /* I believe only fix-ups such as ".long .ep.main-main+0xc8000000"
1398 reach here (???). */
1401 fix
->fx_r_type
= BFD_RELOC_32
;
1406 insn
|= (val
& 0xffffffff);
1407 bfd_putl32 (insn
, buf
);
1408 fix
->fx_r_type
= BFD_RELOC_NONE
;
1414 /* Generate a machine dependent reloc from a fixup. */
1416 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
,
1421 reloc
= xmalloc (sizeof (*reloc
));
1422 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1423 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1424 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1425 reloc
->addend
= fixp
->fx_offset
;
1426 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1430 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1431 "Cannot represent %s relocation in object file",
1432 bfd_get_reloc_code_name (fixp
->fx_r_type
));