binutils/
[deliverable/binutils-gdb.git] / gas / config / tc-i860.c
CommitLineData
305d537e 1/* tc-i860.c -- Assembler for the Intel i860 architecture.
ebd1c875 2 Copyright 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002,
ec2655a6 3 2003, 2006, 2007 Free Software Foundation, Inc.
305d537e
JE
4
5 Brought back from the dead and completely reworked
6 by Jason Eckhardt <jle@cygnus.com>.
252b5132
RH
7
8 This file is part of GAS, the GNU Assembler.
9
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
ec2655a6 12 the Free Software Foundation; either version 3, or (at your option)
252b5132
RH
13 any later version.
14
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.
19
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
4b4da160 22 Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
23
24#include "as.h"
3882b010 25#include "safe-ctype.h"
305d537e 26#include "subsegs.h"
252b5132 27#include "opcode/i860.h"
305d537e 28#include "elf/i860.h"
252b5132 29
252b5132 30
305d537e 31/* The opcode hash table. */
252b5132
RH
32static struct hash_control *op_hash = NULL;
33
305d537e
JE
34/* These characters always start a comment. */
35const char comment_chars[] = "#!/";
252b5132 36
305d537e 37/* These characters start a comment at the beginning of a line. */
252b5132
RH
38const char line_comment_chars[] = "#/";
39
63a0b638 40const char line_separator_chars[] = ";";
252b5132 41
305d537e
JE
42/* Characters that can be used to separate the mantissa from the exponent
43 in floating point numbers. */
252b5132
RH
44const char EXP_CHARS[] = "eE";
45
305d537e
JE
46/* Characters that indicate this number is a floating point constant.
47 As in 0f12.456 or 0d1.2345e12. */
252b5132
RH
48const char FLT_CHARS[] = "rRsSfFdDxXpP";
49
87505968
JE
50/* Register prefix (depends on syntax). */
51static char reg_prefix;
305d537e 52
673a54e3
JE
53#define MAX_FIXUPS 2
54
252b5132 55struct i860_it
305d537e
JE
56{
57 char *error;
58 unsigned long opcode;
305d537e 59 enum expand_type expand;
673a54e3
JE
60 struct i860_fi
61 {
62 expressionS exp;
63 bfd_reloc_code_real_type reloc;
64 int pcrel;
65 valueT fup;
66 } fi[MAX_FIXUPS];
305d537e
JE
67} the_insn;
68
673a54e3
JE
69/* The current fixup count. */
70static int fc;
71
305d537e 72static char *expr_end;
252b5132 73
305d537e
JE
74/* Indicates error if a pseudo operation was expanded after a branch. */
75static char last_expand;
252b5132 76
305d537e
JE
77/* If true, then warn if any pseudo operations were expanded. */
78static int target_warn_expand = 0;
252b5132 79
14218d5f
JE
80/* If true, then XP support is enabled. */
81static int target_xp = 0;
82
87505968
JE
83/* If true, then Intel syntax is enabled (default to AT&T/SVR4 syntax). */
84static int target_intel_syntax = 0;
85
86
305d537e 87/* Prototypes. */
7734b6e9
JE
88static void i860_process_insn (char *);
89static void s_dual (int);
90static void s_enddual (int);
91static void s_atmp (int);
820aff55 92static void s_align_wrapper (int);
7734b6e9
JE
93static int i860_get_expression (char *);
94static bfd_reloc_code_real_type obtain_reloc_for_imm16 (fixS *, long *);
305d537e 95#ifdef DEBUG_I860
7734b6e9 96static void print_insn (struct i860_it *);
305d537e 97#endif
252b5132 98
305d537e
JE
99const pseudo_typeS md_pseudo_table[] =
100{
820aff55
JE
101 {"align", s_align_wrapper, 0},
102 {"dual", s_dual, 0},
103 {"enddual", s_enddual, 0},
104 {"atmp", s_atmp, 0},
105 {NULL, 0, 0},
305d537e
JE
106};
107
305d537e 108/* Dual-instruction mode handling. */
252b5132
RH
109enum dual
110{
111 DUAL_OFF = 0, DUAL_ON, DUAL_DDOT, DUAL_ONDDOT,
112};
305d537e
JE
113static enum dual dual_mode = DUAL_OFF;
114
305d537e 115/* Handle ".dual" directive. */
252b5132 116static void
7734b6e9 117s_dual (int ignore ATTRIBUTE_UNUSED)
252b5132 118{
5ea0549d
JE
119 if (target_intel_syntax)
120 dual_mode = DUAL_ON;
121 else
122 as_bad (_("Directive .dual available only with -mintel-syntax option"));
252b5132
RH
123}
124
305d537e 125/* Handle ".enddual" directive. */
252b5132 126static void
7734b6e9 127s_enddual (int ignore ATTRIBUTE_UNUSED)
252b5132 128{
5ea0549d
JE
129 if (target_intel_syntax)
130 dual_mode = DUAL_OFF;
131 else
132 as_bad (_("Directive .enddual available only with -mintel-syntax option"));
252b5132
RH
133}
134
305d537e
JE
135/* Temporary register used when expanding assembler pseudo operations. */
136static int atmp = 31;
252b5132
RH
137
138static void
7734b6e9 139s_atmp (int ignore ATTRIBUTE_UNUSED)
252b5132 140{
5ea0549d
JE
141 int temp;
142
143 if (! target_intel_syntax)
144 {
145 as_bad (_("Directive .atmp available only with -mintel-syntax option"));
146 demand_empty_rest_of_line ();
147 return;
148 }
149
252b5132
RH
150 if (strncmp (input_line_pointer, "sp", 2) == 0)
151 {
152 input_line_pointer += 2;
153 atmp = 2;
154 }
155 else if (strncmp (input_line_pointer, "fp", 2) == 0)
156 {
157 input_line_pointer += 2;
158 atmp = 3;
159 }
160 else if (strncmp (input_line_pointer, "r", 1) == 0)
161 {
162 input_line_pointer += 1;
163 temp = get_absolute_expression ();
164 if (temp >= 0 && temp <= 31)
165 atmp = temp;
166 else
167 as_bad (_("Unknown temporary pseudo register"));
168 }
169 else
170 {
171 as_bad (_("Unknown temporary pseudo register"));
172 }
173 demand_empty_rest_of_line ();
174}
175
820aff55
JE
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. */
182static void
183s_align_wrapper (int arg)
184{
185 char *parm = input_line_pointer;
186
187 if (target_intel_syntax)
188 {
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);
201
202 while (*input_line_pointer == ' ')
203 ++input_line_pointer;
204 }
205
206 s_align_bytes (arg);
207}
208
252b5132 209/* This function is called once, at assembler startup time. It should
305d537e
JE
210 set up all the tables and data structures that the MD part of the
211 assembler will need. */
252b5132 212void
7734b6e9 213md_begin (void)
252b5132 214{
305d537e 215 const char *retval = NULL;
252b5132 216 int lose = 0;
305d537e 217 unsigned int i = 0;
252b5132
RH
218
219 op_hash = hash_new ();
220
305d537e 221 while (i860_opcodes[i].name != NULL)
252b5132
RH
222 {
223 const char *name = i860_opcodes[i].name;
305d537e 224 retval = hash_insert (op_hash, name, (PTR)&i860_opcodes[i]);
252b5132
RH
225 if (retval != NULL)
226 {
227 fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
228 i860_opcodes[i].name, retval);
229 lose = 1;
230 }
231 do
232 {
233 if (i860_opcodes[i].match & i860_opcodes[i].lose)
234 {
305d537e
JE
235 fprintf (stderr,
236 _("internal error: losing opcode: `%s' \"%s\"\n"),
252b5132
RH
237 i860_opcodes[i].name, i860_opcodes[i].args);
238 lose = 1;
239 }
240 ++i;
241 }
305d537e
JE
242 while (i860_opcodes[i].name != NULL
243 && strcmp (i860_opcodes[i].name, name) == 0);
252b5132
RH
244 }
245
246 if (lose)
305d537e 247 as_fatal (_("Defective assembler. No assembly attempted."));
87505968
JE
248
249 /* Set the register prefix for either Intel or AT&T/SVR4 syntax. */
250 reg_prefix = target_intel_syntax ? 0 : '%';
252b5132
RH
251}
252
305d537e
JE
253/* This is the core of the machine-dependent assembler. STR points to a
254 machine dependent instruction. This function emits the frags/bytes
255 it assembles to. */
252b5132 256void
7734b6e9 257md_assemble (char *str)
252b5132 258{
305d537e
JE
259 char *destp;
260 int num_opcodes = 1;
252b5132
RH
261 int i;
262 struct i860_it pseudo[3];
263
264 assert (str);
673a54e3 265 fc = 0;
252b5132 266
305d537e
JE
267 /* Assemble the instruction. */
268 i860_process_insn (str);
269
270 /* Check for expandable flag to produce pseudo-instructions. This
271 is an undesirable feature that should be avoided. */
14218d5f 272 if (the_insn.expand != 0 && the_insn.expand != XP_ONLY
673a54e3 273 && ! (the_insn.fi[0].fup & (OP_SEL_HA | OP_SEL_H | OP_SEL_L | OP_SEL_GOT
305d537e 274 | OP_SEL_GOTOFF | OP_SEL_PLT)))
252b5132
RH
275 {
276 for (i = 0; i < 3; i++)
277 pseudo[i] = the_insn;
278
673a54e3 279 fc = 1;
252b5132
RH
280 switch (the_insn.expand)
281 {
282
283 case E_DELAY:
305d537e 284 num_opcodes = 1;
252b5132
RH
285 break;
286
287 case E_MOV:
673a54e3
JE
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)))
252b5132 292 break;
305d537e
JE
293
294 /* Emit "or l%const,r0,ireg_dest". */
252b5132 295 pseudo[0].opcode = (the_insn.opcode & 0x001f0000) | 0xe4000000;
673a54e3 296 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
305d537e
JE
297
298 /* Emit "orh h%const,ireg_dest,ireg_dest". */
299 pseudo[1].opcode = (the_insn.opcode & 0x03ffffff) | 0xec000000
300 | ((the_insn.opcode & 0x001f0000) << 5);
673a54e3 301 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
305d537e
JE
302
303 num_opcodes = 2;
252b5132
RH
304 break;
305
306 case E_ADDR:
673a54e3
JE
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)))
252b5132 311 break;
305d537e 312
af858dae
JE
313 /* Emit "orh ha%addr_expr,ireg_src2,r31". */
314 pseudo[0].opcode = 0xec000000 | (the_insn.opcode & 0x03e00000)
315 | (atmp << 16);
673a54e3 316 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_HA);
305d537e
JE
317
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);
673a54e3 321 pseudo[1].fi[0].fup = the_insn.fi[0].fup | OP_SEL_L;
305d537e
JE
322
323 num_opcodes = 2;
252b5132
RH
324 break;
325
305d537e 326 case E_U32:
673a54e3
JE
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))
252b5132 331 break;
305d537e
JE
332
333 /* Emit "$(opcode)h h%const,ireg_src2,r31". */
334 pseudo[0].opcode = (the_insn.opcode & 0xf3e0ffff) | 0x0c000000
335 | (atmp << 16);
673a54e3 336 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
305d537e
JE
337
338 /* Emit "$(opcode) l%const,r31,ireg_dest". */
339 pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000
340 | (atmp << 21);
673a54e3 341 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
305d537e
JE
342
343 num_opcodes = 2;
252b5132
RH
344 break;
345
305d537e 346 case E_AND:
673a54e3
JE
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))
252b5132 351 break;
305d537e
JE
352
353 /* Emit "andnot h%const,ireg_src2,r31". */
354 pseudo[0].opcode = (the_insn.opcode & 0x03e0ffff) | 0xd4000000
355 | (atmp << 16);
673a54e3
JE
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;
305d537e
JE
359
360 /* Emit "andnot l%const,r31,ireg_dest". */
361 pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000
362 | (atmp << 21);
673a54e3
JE
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;
305d537e
JE
366
367 num_opcodes = 2;
252b5132
RH
368 break;
369
370 case E_S32:
673a54e3
JE
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)))
252b5132 375 break;
305d537e
JE
376
377 /* Emit "orh h%const,r0,r31". */
252b5132 378 pseudo[0].opcode = 0xec000000 | (atmp << 16);
673a54e3 379 pseudo[0].fi[0].fup = (OP_IMM_S16 | OP_SEL_H);
305d537e
JE
380
381 /* Emit "or l%const,r31,r31". */
252b5132 382 pseudo[1].opcode = 0xe4000000 | (atmp << 21) | (atmp << 16);
673a54e3 383 pseudo[1].fi[0].fup = (OP_IMM_S16 | OP_SEL_L);
305d537e
JE
384
385 /* Emit "r31,ireg_src2,ireg_dest". */
252b5132 386 pseudo[2].opcode = (the_insn.opcode & ~0x0400ffff) | (atmp << 11);
673a54e3 387 pseudo[2].fi[0].fup = OP_IMM_S16;
305d537e
JE
388
389 num_opcodes = 3;
252b5132
RH
390 break;
391
392 default:
393 as_fatal (_("failed sanity check."));
394 }
395
396 the_insn = pseudo[0];
305d537e
JE
397
398 /* Warn if an opcode is expanded after a delayed branch. */
399 if (num_opcodes > 1 && last_expand == 1)
252b5132 400 as_warn (_("Expanded opcode after delayed branch: `%s'"), str);
305d537e
JE
401
402 /* Warn if an opcode is expanded in dual mode. */
403 if (num_opcodes > 1 && dual_mode != DUAL_OFF)
252b5132 404 as_warn (_("Expanded opcode in dual mode: `%s'"), str);
305d537e
JE
405
406 /* Notify if any expansions happen. */
407 if (target_warn_expand && num_opcodes > 1)
408 as_warn (_("An instruction was expanded (%s)"), str);
252b5132
RH
409 }
410
411 i = 0;
412 do
305d537e 413 {
673a54e3
JE
414 int tmp;
415
305d537e
JE
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);
252b5132 420
305d537e 421 /* Check for expanded opcode after branch or in dual mode. */
673a54e3
JE
422 last_expand = the_insn.fi[0].pcrel;
423
424 /* Output the symbol-dependent stuff. Only btne and bte will ever
425 loop more than once here, since only they (possibly) have more
426 than one fixup. */
427 for (tmp = 0; tmp < fc; tmp++)
428 {
429 if (the_insn.fi[tmp].fup != OP_NONE)
430 {
431 fixS *fix;
432 fix = fix_new_exp (frag_now,
433 destp - frag_now->fr_literal,
434 4,
435 &the_insn.fi[tmp].exp,
436 the_insn.fi[tmp].pcrel,
437 the_insn.fi[tmp].reloc);
438
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;
442 }
443 }
252b5132
RH
444 the_insn = pseudo[++i];
445 }
305d537e 446 while (--num_opcodes > 0);
252b5132
RH
447
448}
449
305d537e 450/* Assemble the instruction pointed to by STR. */
252b5132 451static void
7734b6e9 452i860_process_insn (char *str)
252b5132
RH
453{
454 char *s;
455 const char *args;
456 char c;
252b5132 457 struct i860_opcode *insn;
305d537e 458 char *args_start;
252b5132
RH
459 unsigned long opcode;
460 unsigned int mask;
461 int match = 0;
462 int comma = 0;
463
305d537e
JE
464#if 1 /* For compiler warnings. */
465 args = 0;
466 insn = 0;
467 args_start = 0;
468 opcode = 0;
469#endif
252b5132 470
3882b010 471 for (s = str; ISLOWER (*s) || *s == '.' || *s == '3'
305d537e 472 || *s == '2' || *s == '1'; ++s)
252b5132 473 ;
305d537e 474
252b5132
RH
475 switch (*s)
476 {
252b5132
RH
477 case '\0':
478 break;
479
480 case ',':
481 comma = 1;
482
483 /*FALLTHROUGH*/
484
485 case ' ':
486 *s++ = '\0';
487 break;
488
489 default:
490 as_fatal (_("Unknown opcode: `%s'"), str);
491 }
492
305d537e 493 /* Check for dual mode ("d.") opcode prefix. */
252b5132 494 if (strncmp (str, "d.", 2) == 0)
305d537e 495 {
252b5132
RH
496 if (dual_mode == DUAL_ON)
497 dual_mode = DUAL_ONDDOT;
498 else
499 dual_mode = DUAL_DDOT;
500 str += 2;
501 }
502
503 if ((insn = (struct i860_opcode *) hash_find (op_hash, str)) == NULL)
504 {
505 if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
506 str -= 2;
507 as_bad (_("Unknown opcode: `%s'"), str);
508 return;
509 }
305d537e 510
252b5132 511 if (comma)
305d537e
JE
512 *--s = ',';
513
514 args_start = s;
252b5132
RH
515 for (;;)
516 {
673a54e3 517 int t;
252b5132
RH
518 opcode = insn->match;
519 memset (&the_insn, '\0', sizeof (the_insn));
b645cb17 520 fc = 0;
673a54e3
JE
521 for (t = 0; t < MAX_FIXUPS; t++)
522 {
523 the_insn.fi[t].reloc = BFD_RELOC_NONE;
524 the_insn.fi[t].pcrel = 0;
525 the_insn.fi[t].fup = OP_NONE;
526 }
252b5132 527
305d537e
JE
528 /* Build the opcode, checking as we go that the operands match. */
529 for (args = insn->args; ; ++args)
252b5132 530 {
673a54e3
JE
531 if (fc > MAX_FIXUPS)
532 abort ();
533
252b5132
RH
534 switch (*args)
535 {
536
305d537e
JE
537 /* End of args. */
538 case '\0':
252b5132 539 if (*s == '\0')
305d537e 540 match = 1;
252b5132
RH
541 break;
542
305d537e 543 /* These must match exactly. */
252b5132 544 case '+':
305d537e 545 case '(':
252b5132
RH
546 case ')':
547 case ',':
548 case ' ':
549 if (*s++ == *args)
550 continue;
551 break;
552
305d537e
JE
553 /* Must be at least one digit. */
554 case '#':
3882b010 555 if (ISDIGIT (*s++))
252b5132 556 {
3882b010 557 while (ISDIGIT (*s))
305d537e 558 ++s;
252b5132
RH
559 continue;
560 }
561 break;
562
305d537e
JE
563 /* Next operand must be a register. */
564 case '1':
252b5132
RH
565 case '2':
566 case 'd':
305d537e
JE
567 /* Check for register prefix if necessary. */
568 if (reg_prefix && *s != reg_prefix)
569 goto error;
87505968 570 else if (reg_prefix)
305d537e
JE
571 s++;
572
252b5132
RH
573 switch (*s)
574 {
305d537e
JE
575 /* Frame pointer. */
576 case 'f':
252b5132
RH
577 s++;
578 if (*s++ == 'p')
579 {
580 mask = 0x3;
581 break;
582 }
583 goto error;
584
305d537e
JE
585 /* Stack pointer. */
586 case 's':
252b5132
RH
587 s++;
588 if (*s++ == 'p')
589 {
590 mask = 0x2;
591 break;
592 }
593 goto error;
594
305d537e
JE
595 /* Any register r0..r31. */
596 case 'r':
252b5132 597 s++;
3882b010 598 if (!ISDIGIT (c = *s++))
252b5132
RH
599 {
600 goto error;
601 }
3882b010 602 if (ISDIGIT (*s))
252b5132
RH
603 {
604 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
305d537e 605 goto error;
252b5132
RH
606 }
607 else
305d537e 608 c -= '0';
252b5132
RH
609 mask = c;
610 break;
611
305d537e
JE
612 /* Not this opcode. */
613 default:
252b5132
RH
614 goto error;
615 }
305d537e
JE
616
617 /* Obtained the register, now place it in the opcode. */
252b5132
RH
618 switch (*args)
619 {
252b5132
RH
620 case '1':
621 opcode |= mask << 11;
622 continue;
623
624 case '2':
625 opcode |= mask << 21;
626 continue;
627
628 case 'd':
629 opcode |= mask << 16;
630 continue;
631
632 }
633 break;
634
305d537e
JE
635 /* Next operand is a floating point register. */
636 case 'e':
252b5132
RH
637 case 'f':
638 case 'g':
305d537e
JE
639 /* Check for register prefix if necessary. */
640 if (reg_prefix && *s != reg_prefix)
641 goto error;
87505968 642 else if (reg_prefix)
305d537e
JE
643 s++;
644
3882b010 645 if (*s++ == 'f' && ISDIGIT (*s))
252b5132
RH
646 {
647 mask = *s++;
3882b010 648 if (ISDIGIT (*s))
252b5132
RH
649 {
650 mask = 10 * (mask - '0') + (*s++ - '0');
651 if (mask >= 32)
652 {
653 break;
654 }
655 }
656 else
305d537e
JE
657 mask -= '0';
658
252b5132
RH
659 switch (*args)
660 {
661
662 case 'e':
663 opcode |= mask << 11;
664 continue;
665
666 case 'f':
667 opcode |= mask << 21;
668 continue;
669
670 case 'g':
671 opcode |= mask << 16;
305d537e
JE
672 if ((opcode & (1 << 10)) && mask != 0
673 && (mask == ((opcode >> 11) & 0x1f)))
674 as_warn (_("Pipelined instruction: fsrc1 = fdest"));
252b5132
RH
675 continue;
676 }
677 }
678 break;
679
305d537e
JE
680 /* Next operand must be a control register. */
681 case 'c':
682 /* Check for register prefix if necessary. */
683 if (reg_prefix && *s != reg_prefix)
684 goto error;
87505968 685 else if (reg_prefix)
305d537e
JE
686 s++;
687
252b5132
RH
688 if (strncmp (s, "fir", 3) == 0)
689 {
690 opcode |= 0x0 << 21;
691 s += 3;
692 continue;
693 }
694 if (strncmp (s, "psr", 3) == 0)
695 {
696 opcode |= 0x1 << 21;
697 s += 3;
698 continue;
699 }
700 if (strncmp (s, "dirbase", 7) == 0)
701 {
702 opcode |= 0x2 << 21;
703 s += 7;
704 continue;
705 }
706 if (strncmp (s, "db", 2) == 0)
707 {
708 opcode |= 0x3 << 21;
709 s += 2;
710 continue;
711 }
712 if (strncmp (s, "fsr", 3) == 0)
713 {
714 opcode |= 0x4 << 21;
715 s += 3;
716 continue;
717 }
718 if (strncmp (s, "epsr", 4) == 0)
719 {
720 opcode |= 0x5 << 21;
721 s += 4;
722 continue;
723 }
14218d5f
JE
724 /* The remaining control registers are XP only. */
725 if (target_xp && strncmp (s, "bear", 4) == 0)
726 {
727 opcode |= 0x6 << 21;
728 s += 4;
729 continue;
730 }
731 if (target_xp && strncmp (s, "ccr", 3) == 0)
732 {
733 opcode |= 0x7 << 21;
734 s += 3;
735 continue;
736 }
737 if (target_xp && strncmp (s, "p0", 2) == 0)
738 {
739 opcode |= 0x8 << 21;
740 s += 2;
741 continue;
742 }
743 if (target_xp && strncmp (s, "p1", 2) == 0)
744 {
745 opcode |= 0x9 << 21;
746 s += 2;
747 continue;
748 }
749 if (target_xp && strncmp (s, "p2", 2) == 0)
750 {
751 opcode |= 0xa << 21;
752 s += 2;
753 continue;
754 }
755 if (target_xp && strncmp (s, "p3", 2) == 0)
756 {
757 opcode |= 0xb << 21;
758 s += 2;
759 continue;
760 }
252b5132
RH
761 break;
762
305d537e
JE
763 /* 5-bit immediate in src1. */
764 case '5':
765 if (! i860_get_expression (s))
252b5132
RH
766 {
767 s = expr_end;
673a54e3
JE
768 the_insn.fi[fc].fup |= OP_IMM_U5;
769 fc++;
252b5132
RH
770 continue;
771 }
772 break;
773
305d537e
JE
774 /* 26-bit immediate, relative branch (lbroff). */
775 case 'l':
673a54e3
JE
776 the_insn.fi[fc].pcrel = 1;
777 the_insn.fi[fc].fup |= OP_IMM_BR26;
252b5132
RH
778 goto immediate;
779
305d537e
JE
780 /* 16-bit split immediate, relative branch (sbroff). */
781 case 'r':
673a54e3
JE
782 the_insn.fi[fc].pcrel = 1;
783 the_insn.fi[fc].fup |= OP_IMM_BR16;
252b5132
RH
784 goto immediate;
785
305d537e
JE
786 /* 16-bit split immediate. */
787 case 's':
673a54e3 788 the_insn.fi[fc].fup |= OP_IMM_SPLIT16;
305d537e
JE
789 goto immediate;
790
791 /* 16-bit split immediate, byte aligned (st.b). */
792 case 'S':
673a54e3 793 the_insn.fi[fc].fup |= OP_IMM_SPLIT16;
305d537e
JE
794 goto immediate;
795
796 /* 16-bit split immediate, half-word aligned (st.s). */
797 case 'T':
673a54e3 798 the_insn.fi[fc].fup |= (OP_IMM_SPLIT16 | OP_ENCODE1 | OP_ALIGN2);
305d537e
JE
799 goto immediate;
800
801 /* 16-bit split immediate, word aligned (st.l). */
802 case 'U':
673a54e3 803 the_insn.fi[fc].fup |= (OP_IMM_SPLIT16 | OP_ENCODE1 | OP_ALIGN4);
305d537e
JE
804 goto immediate;
805
806 /* 16-bit immediate. */
807 case 'i':
673a54e3 808 the_insn.fi[fc].fup |= OP_IMM_S16;
305d537e
JE
809 goto immediate;
810
811 /* 16-bit immediate, byte aligned (ld.b). */
812 case 'I':
673a54e3 813 the_insn.fi[fc].fup |= OP_IMM_S16;
305d537e
JE
814 goto immediate;
815
816 /* 16-bit immediate, half-word aligned (ld.s). */
817 case 'J':
673a54e3 818 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE1 | OP_ALIGN2);
252b5132
RH
819 goto immediate;
820
305d537e
JE
821 /* 16-bit immediate, word aligned (ld.l, {p}fld.l, fst.l). */
822 case 'K':
823 if (insn->name[0] == 'l')
673a54e3 824 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE1 | OP_ALIGN4);
252b5132 825 else
673a54e3 826 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE2 | OP_ALIGN4);
305d537e
JE
827 goto immediate;
828
829 /* 16-bit immediate, double-word aligned ({p}fld.d, fst.d). */
830 case 'L':
673a54e3 831 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE3 | OP_ALIGN8);
252b5132
RH
832 goto immediate;
833
305d537e
JE
834 /* 16-bit immediate, quad-word aligned (fld.q, fst.q). */
835 case 'M':
673a54e3 836 the_insn.fi[fc].fup |= (OP_IMM_S16 | OP_ENCODE3 | OP_ALIGN16);
252b5132
RH
837
838 /*FALLTHROUGH*/
839
305d537e
JE
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". */
252b5132 843 immediate:
87505968 844 if (target_intel_syntax == 0)
305d537e 845 {
87505968
JE
846 /* AT&T/SVR4 syntax. */
847 if (*s == ' ')
848 s++;
849
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))
855 s = expr_end;
856 else
857 goto error;
858
859 if (strncmp (s, "@ha", 3) == 0)
860 {
861 the_insn.fi[fc].fup |= OP_SEL_HA;
862 s += 3;
863 }
864 else if (strncmp (s, "@h", 2) == 0)
865 {
866 the_insn.fi[fc].fup |= OP_SEL_H;
867 s += 2;
868 }
869 else if (strncmp (s, "@l", 2) == 0)
870 {
871 the_insn.fi[fc].fup |= OP_SEL_L;
872 s += 2;
873 }
874 else if (strncmp (s, "@gotoff", 7) == 0
875 || strncmp (s, "@GOTOFF", 7) == 0)
876 {
877 as_bad (_("Assembler does not yet support PIC"));
878 the_insn.fi[fc].fup |= OP_SEL_GOTOFF;
879 s += 7;
880 }
881 else if (strncmp (s, "@got", 4) == 0
882 || strncmp (s, "@GOT", 4) == 0)
883 {
884 as_bad (_("Assembler does not yet support PIC"));
885 the_insn.fi[fc].fup |= OP_SEL_GOT;
886 s += 4;
887 }
888 else if (strncmp (s, "@plt", 4) == 0
889 || strncmp (s, "@PLT", 4) == 0)
890 {
891 as_bad (_("Assembler does not yet support PIC"));
892 the_insn.fi[fc].fup |= OP_SEL_PLT;
893 s += 4;
894 }
305d537e 895
87505968
JE
896 the_insn.expand = insn->expand;
897 fc++;
673a54e3 898
87505968 899 continue;
252b5132 900 }
87505968 901 else
252b5132 902 {
87505968
JE
903 /* Intel syntax. */
904 if (*s == ' ')
905 s++;
906 if (strncmp (s, "ha%", 3) == 0)
907 {
908 the_insn.fi[fc].fup |= OP_SEL_HA;
909 s += 3;
910 }
911 else if (strncmp (s, "h%", 2) == 0)
912 {
913 the_insn.fi[fc].fup |= OP_SEL_H;
914 s += 2;
915 }
916 else if (strncmp (s, "l%", 2) == 0)
917 {
918 the_insn.fi[fc].fup |= OP_SEL_L;
919 s += 2;
920 }
921 the_insn.expand = insn->expand;
922
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))
928 s = expr_end;
929 else
930 goto error;
931
932 fc++;
933 continue;
252b5132 934 }
252b5132
RH
935 break;
936
937 default:
938 as_fatal (_("failed sanity check."));
939 }
940 break;
941 }
942 error:
943 if (match == 0)
944 {
945 /* Args don't match. */
305d537e
JE
946 if (insn[1].name != NULL
947 && ! strcmp (insn->name, insn[1].name))
252b5132
RH
948 {
949 ++insn;
305d537e 950 s = args_start;
252b5132
RH
951 continue;
952 }
953 else
954 {
305d537e 955 as_bad (_("Illegal operands for %s"), insn->name);
252b5132
RH
956 return;
957 }
958 }
959 break;
960 }
961
07c7854e
JE
962 /* Set the dual bit on this instruction if necessary. */
963 if (dual_mode != DUAL_OFF)
964 {
965 if ((opcode & 0xfc000000) == 0x48000000 || opcode == 0xb0000000)
966 {
0acc96e1
JE
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)
970 opcode |= (1 << 9);
971 else
972 as_bad (_("'d.%s' must be 8-byte aligned"), insn->name);
973
07c7854e
JE
974 if (dual_mode == DUAL_DDOT)
975 dual_mode = DUAL_OFF;
976 else if (dual_mode == DUAL_ONDDOT)
977 dual_mode = DUAL_ON;
978 }
979 else if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
980 as_bad (_("Prefix 'd.' invalid for instruction `%s'"), insn->name);
981 }
982
252b5132 983 the_insn.opcode = opcode;
14218d5f
JE
984
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);
252b5132
RH
988}
989
990static int
7734b6e9 991i860_get_expression (char *str)
252b5132
RH
992{
993 char *save_in;
994 segT seg;
995
996 save_in = input_line_pointer;
997 input_line_pointer = str;
673a54e3 998 seg = expression (&the_insn.fi[fc].exp);
252b5132
RH
999 if (seg != absolute_section
1000 && seg != undefined_section
1001 && ! SEG_NORMAL (seg))
1002 {
1003 the_insn.error = _("bad segment");
1004 expr_end = input_line_pointer;
1005 input_line_pointer = save_in;
1006 return 1;
1007 }
1008 expr_end = input_line_pointer;
1009 input_line_pointer = save_in;
1010 return 0;
1011}
1012
305d537e
JE
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,
1016 or NULL on OK. */
252b5132 1017
305d537e 1018/* Equal to MAX_PRECISION in atof-ieee.c. */
252b5132
RH
1019#define MAX_LITTLENUMS 6
1020
1021char *
7734b6e9 1022md_atof (int type, char *litP, int *sizeP)
252b5132
RH
1023{
1024 int prec;
1025 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1026 LITTLENUM_TYPE *wordP;
1027 char *t;
252b5132
RH
1028
1029 switch (type)
1030 {
252b5132
RH
1031 case 'f':
1032 case 'F':
1033 case 's':
1034 case 'S':
1035 prec = 2;
1036 break;
1037
1038 case 'd':
1039 case 'D':
1040 case 'r':
1041 case 'R':
1042 prec = 4;
1043 break;
1044
1045 case 'x':
1046 case 'X':
1047 prec = 6;
1048 break;
1049
1050 case 'p':
1051 case 'P':
1052 prec = 6;
1053 break;
1054
1055 default:
1056 *sizeP = 0;
1057 return _("Bad call to MD_ATOF()");
1058 }
1059 t = atof_ieee (input_line_pointer, type, words);
1060 if (t)
1061 input_line_pointer = t;
1062 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1063 for (wordP = words; prec--;)
1064 {
1065 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1066 litP += sizeof (LITTLENUM_TYPE);
1067 }
1068 return 0;
1069}
1070
305d537e 1071/* Write out in current endian mode. */
252b5132 1072void
7734b6e9 1073md_number_to_chars (char *buf, valueT val, int n)
252b5132 1074{
305d537e
JE
1075 if (target_big_endian)
1076 number_to_chars_bigendian (buf, val, n);
1077 else
1078 number_to_chars_littleendian (buf, val, n);
252b5132
RH
1079}
1080
305d537e 1081/* This should never be called for i860. */
252b5132 1082int
7734b6e9
JE
1083md_estimate_size_before_relax (register fragS *fragP ATTRIBUTE_UNUSED,
1084 segT segtype ATTRIBUTE_UNUSED)
252b5132
RH
1085{
1086 as_fatal (_("i860_estimate_size_before_relax\n"));
1087}
1088
305d537e 1089#ifdef DEBUG_I860
252b5132 1090static void
7734b6e9 1091print_insn (struct i860_it *insn)
252b5132
RH
1092{
1093 if (insn->error)
305d537e
JE
1094 fprintf (stderr, "ERROR: %s\n", insn->error);
1095
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));
252b5132
RH
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");
305d537e 1109 fprintf (stderr, "\t\tX_add_number = %lx\n",
252b5132
RH
1110 insn->exp.X_add_number);
1111 fprintf (stderr, "}\n");
1112}
305d537e
JE
1113#endif /* DEBUG_I860 */
1114
252b5132 1115\f
305d537e 1116#ifdef OBJ_ELF
5a38dc70 1117const char *md_shortopts = "VQ:";
305d537e 1118#else
5a38dc70 1119const char *md_shortopts = "";
305d537e
JE
1120#endif
1121
305d537e
JE
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)
14218d5f 1125#define OPTION_XP (OPTION_MD_BASE + 3)
87505968 1126#define OPTION_INTEL_SYNTAX (OPTION_MD_BASE + 4)
305d537e 1127
252b5132 1128struct option md_longopts[] = {
305d537e
JE
1129 { "EB", no_argument, NULL, OPTION_EB },
1130 { "EL", no_argument, NULL, OPTION_EL },
1131 { "mwarn-expand", no_argument, NULL, OPTION_WARN_EXPAND },
14218d5f 1132 { "mxp", no_argument, NULL, OPTION_XP },
87505968 1133 { "mintel-syntax",no_argument, NULL, OPTION_INTEL_SYNTAX },
305d537e 1134 { NULL, no_argument, NULL, 0 }
252b5132 1135};
305d537e
JE
1136size_t md_longopts_size = sizeof (md_longopts);
1137
252b5132 1138int
7734b6e9 1139md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
252b5132 1140{
305d537e
JE
1141 switch (c)
1142 {
1143 case OPTION_EB:
1144 target_big_endian = 1;
1145 break;
1146
1147 case OPTION_EL:
1148 target_big_endian = 0;
1149 break;
1150
1151 case OPTION_WARN_EXPAND:
1152 target_warn_expand = 1;
1153 break;
1154
14218d5f
JE
1155 case OPTION_XP:
1156 target_xp = 1;
1157 break;
1158
87505968
JE
1159 case OPTION_INTEL_SYNTAX:
1160 target_intel_syntax = 1;
1161 break;
1162
305d537e
JE
1163#ifdef OBJ_ELF
1164 /* SVR4 argument compatibility (-V): print version ID. */
1165 case 'V':
1166 print_version_id ();
1167 break;
1168
1169 /* SVR4 argument compatibility (-Qy, -Qn): controls whether
1170 a .comment section should be emitted or not (ignored). */
1171 case 'Q':
1172 break;
1173#endif
1174
1175 default:
1176 return 0;
1177 }
1178
1179 return 1;
252b5132
RH
1180}
1181
1182void
7734b6e9 1183md_show_usage (FILE *stream)
252b5132 1184{
305d537e
JE
1185 fprintf (stream, _("\
1186 -EL generate code for little endian mode (default)\n\
1187 -EB generate code for big endian mode\n\
14218d5f 1188 -mwarn-expand warn if pseudo operations are expanded\n\
87505968
JE
1189 -mxp enable i860XP support (disabled by default)\n\
1190 -mintel-syntax enable Intel syntax (default to AT&T/SVR4)\n"));
305d537e
JE
1191#ifdef OBJ_ELF
1192 /* SVR4 compatibility flags. */
1193 fprintf (stream, _("\
1194 -V print assembler version number\n\
1195 -Qy, -Qn ignored\n"));
1196#endif
252b5132 1197}
305d537e 1198
252b5132 1199\f
305d537e
JE
1200/* We have no need to default values of symbols. */
1201symbolS *
7734b6e9 1202md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
305d537e
JE
1203{
1204 return 0;
1205}
1206
305d537e 1207/* The i860 denotes auto-increment with '++'. */
252b5132 1208void
7734b6e9 1209md_operand (expressionS *exp)
252b5132 1210{
305d537e 1211 char *s;
252b5132 1212
f869cfc6 1213 for (s = input_line_pointer; *s; s++)
252b5132 1214 {
305d537e 1215 if (s[0] == '+' && s[1] == '+')
252b5132 1216 {
305d537e
JE
1217 input_line_pointer += 2;
1218 exp->X_op = O_register;
1219 break;
252b5132 1220 }
305d537e
JE
1221 }
1222}
1223
305d537e
JE
1224/* Round up a section size to the appropriate boundary. */
1225valueT
7734b6e9
JE
1226md_section_align (segT segment ATTRIBUTE_UNUSED,
1227 valueT size ATTRIBUTE_UNUSED)
305d537e
JE
1228{
1229 /* Byte alignment is fine. */
1230 return size;
1231}
1232
305d537e 1233/* On the i860, a PC-relative offset is relative to the address of the
eb9618da 1234 offset plus its size. */
305d537e 1235long
7734b6e9 1236md_pcrel_from (fixS *fixP)
305d537e
JE
1237{
1238 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1239}
252b5132 1240
305d537e
JE
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. */
1244static bfd_reloc_code_real_type
7734b6e9 1245obtain_reloc_for_imm16 (fixS *fix, long *val)
305d537e
JE
1246{
1247 valueT fup = fix->fx_addnumber;
4a4f25cf 1248 bfd_reloc_code_real_type reloc;
305d537e
JE
1249
1250 if (fix->fx_pcrel)
1251 abort ();
1252
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"));
1266
1267 if (fup & OP_SEL_HA)
1268 {
1269 *val = (*val >> 16) + (*val & 0x8000 ? 1 : 0);
1270 reloc = BFD_RELOC_860_HIGHADJ;
1271 }
1272 else if (fup & OP_SEL_H)
1273 {
1274 *val >>= 16;
1275 reloc = BFD_RELOC_860_HIGH;
1276 }
1277 else if (fup & OP_SEL_L)
1278 {
1279 int num_encode;
1280 if (fup & OP_IMM_SPLIT16)
252b5132 1281 {
305d537e 1282 if (fup & OP_ENCODE1)
252b5132 1283 {
305d537e
JE
1284 num_encode = 1;
1285 reloc = BFD_RELOC_860_SPLIT1;
1286 }
1287 else if (fup & OP_ENCODE2)
1288 {
1289 num_encode = 2;
1290 reloc = BFD_RELOC_860_SPLIT2;
252b5132
RH
1291 }
1292 else
1293 {
305d537e
JE
1294 num_encode = 0;
1295 reloc = BFD_RELOC_860_SPLIT0;
252b5132 1296 }
305d537e
JE
1297 }
1298 else
1299 {
1300 if (fup & OP_ENCODE1)
252b5132 1301 {
305d537e
JE
1302 num_encode = 1;
1303 reloc = BFD_RELOC_860_LOW1;
252b5132 1304 }
305d537e 1305 else if (fup & OP_ENCODE2)
252b5132 1306 {
305d537e
JE
1307 num_encode = 2;
1308 reloc = BFD_RELOC_860_LOW2;
1309 }
1310 else if (fup & OP_ENCODE3)
1311 {
1312 num_encode = 3;
1313 reloc = BFD_RELOC_860_LOW3;
252b5132
RH
1314 }
1315 else
1316 {
305d537e
JE
1317 num_encode = 0;
1318 reloc = BFD_RELOC_860_LOW0;
252b5132 1319 }
252b5132 1320 }
305d537e
JE
1321
1322 /* Preserve size encode bits. */
1323 *val &= ~((1 << num_encode) - 1);
252b5132 1324 }
305d537e
JE
1325 else
1326 {
1327 /* No selector. What reloc do we generate (???)? */
1328 reloc = BFD_RELOC_32;
1329 }
1330
1331 return reloc;
252b5132
RH
1332}
1333
305d537e
JE
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. */
94f592af
NC
1337
1338void
55cf6793 1339md_apply_fix (fixS *fix, valueT *valP, segT seg ATTRIBUTE_UNUSED)
305d537e 1340{
305d537e 1341 char *buf;
a161fe53 1342 long val = *valP;
305d537e
JE
1343 unsigned long insn;
1344 valueT fup;
252b5132 1345
305d537e 1346 buf = fix->fx_frag->fr_literal + fix->fx_where;
252b5132 1347
305d537e
JE
1348 /* Recall that earlier we stored the opcode little-endian. */
1349 insn = bfd_getl32 (buf);
252b5132 1350
305d537e
JE
1351 /* We stored a fix-up in this oddly-named scratch field. */
1352 fup = fix->fx_addnumber;
1353
1354 /* Determine the necessary relocations as well as inserting an
1355 immediate into the instruction. */
673a54e3 1356 if (fup & OP_IMM_U5)
252b5132 1357 {
305d537e
JE
1358 if (val & ~0x1f)
1359 as_bad_where (fix->fx_file, fix->fx_line,
1360 _("5-bit immediate too large"));
1361 if (fix->fx_addsy)
1362 as_bad_where (fix->fx_file, fix->fx_line,
1363 _("5-bit field must be absolute"));
1364
1365 insn |= (val & 0x1f) << 11;
1366 bfd_putl32 (insn, buf);
1367 fix->fx_r_type = BFD_RELOC_NONE;
1368 fix->fx_done = 1;
252b5132 1369 }
305d537e 1370 else if (fup & OP_IMM_S16)
252b5132 1371 {
305d537e 1372 fix->fx_r_type = obtain_reloc_for_imm16 (fix, &val);
252b5132 1373
305d537e 1374 /* Insert the immediate. */
ded0649c
JE
1375 if (fix->fx_addsy)
1376 fix->fx_done = 0;
1377 else
1378 {
1379 insn |= val & 0xffff;
1380 bfd_putl32 (insn, buf);
1381 fix->fx_r_type = BFD_RELOC_NONE;
1382 fix->fx_done = 1;
1383 }
305d537e
JE
1384 }
1385 else if (fup & OP_IMM_U16)
94f592af
NC
1386 abort ();
1387
305d537e
JE
1388 else if (fup & OP_IMM_SPLIT16)
1389 {
1390 fix->fx_r_type = obtain_reloc_for_imm16 (fix, &val);
1391
1392 /* Insert the immediate. */
ded0649c
JE
1393 if (fix->fx_addsy)
1394 fix->fx_done = 0;
1395 else
1396 {
1397 insn |= val & 0x7ff;
1398 insn |= (val & 0xf800) << 5;
1399 bfd_putl32 (insn, buf);
1400 fix->fx_r_type = BFD_RELOC_NONE;
1401 fix->fx_done = 1;
1402 }
4a4f25cf 1403 }
305d537e 1404 else if (fup & OP_IMM_BR16)
252b5132 1405 {
305d537e
JE
1406 if (val & 0x3)
1407 as_bad_where (fix->fx_file, fix->fx_line,
1408 _("A branch offset requires 0 MOD 4 alignment"));
1409
1410 val = val >> 2;
1411
1412 /* Insert the immediate. */
ded0649c
JE
1413 if (fix->fx_addsy)
1414 {
1415 fix->fx_done = 0;
1416 fix->fx_r_type = BFD_RELOC_860_PC16;
1417 }
1418 else
1419 {
1420 insn |= (val & 0x7ff);
1421 insn |= ((val & 0xf800) << 5);
1422 bfd_putl32 (insn, buf);
1423 fix->fx_r_type = BFD_RELOC_NONE;
1424 fix->fx_done = 1;
1425 }
252b5132 1426 }
305d537e 1427 else if (fup & OP_IMM_BR26)
252b5132 1428 {
305d537e
JE
1429 if (val & 0x3)
1430 as_bad_where (fix->fx_file, fix->fx_line,
1431 _("A branch offset requires 0 MOD 4 alignment"));
252b5132 1432
305d537e 1433 val >>= 2;
252b5132 1434
305d537e 1435 /* Insert the immediate. */
ded0649c
JE
1436 if (fix->fx_addsy)
1437 {
1438 fix->fx_r_type = BFD_RELOC_860_PC26;
1439 fix->fx_done = 0;
1440 }
1441 else
1442 {
1443 insn |= (val & 0x3ffffff);
1444 bfd_putl32 (insn, buf);
1445 fix->fx_r_type = BFD_RELOC_NONE;
1446 fix->fx_done = 1;
1447 }
305d537e
JE
1448 }
1449 else if (fup != OP_NONE)
1450 {
4a4f25cf 1451 as_bad_where (fix->fx_file, fix->fx_line,
d444b726 1452 _("Unrecognized fix-up (0x%08lx)"), (unsigned long) fup);
305d537e
JE
1453 abort ();
1454 }
1455 else
1456 {
1457 /* I believe only fix-ups such as ".long .ep.main-main+0xc8000000"
1458 reach here (???). */
ded0649c
JE
1459 if (fix->fx_addsy)
1460 {
1461 fix->fx_r_type = BFD_RELOC_32;
1462 fix->fx_done = 0;
1463 }
1464 else
1465 {
1466 insn |= (val & 0xffffffff);
1467 bfd_putl32 (insn, buf);
1468 fix->fx_r_type = BFD_RELOC_NONE;
1469 fix->fx_done = 1;
1470 }
305d537e 1471 }
252b5132
RH
1472}
1473
305d537e
JE
1474/* Generate a machine dependent reloc from a fixup. */
1475arelent*
7734b6e9
JE
1476tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1477 fixS *fixp)
252b5132 1478{
305d537e 1479 arelent *reloc;
252b5132 1480
305d537e
JE
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);
252b5132 1487
305d537e 1488 if (! reloc->howto)
252b5132 1489 {
305d537e
JE
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));
252b5132 1493 }
305d537e 1494 return reloc;
252b5132 1495}
e15f6d30
JE
1496
1497/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1498 of an rs_align_code fragment. */
1499
1500void
1501i860_handle_align (fragS *fragp)
1502{
1503 /* Instructions are always stored little-endian on the i860. */
1504 static const unsigned char le_nop[] = { 0x00, 0x00, 0x00, 0xA0 };
1505
1506 int bytes;
1507 char *p;
1508
1509 if (fragp->fr_type != rs_align_code)
1510 return;
1511
1512 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
1513 p = fragp->fr_literal + fragp->fr_fix;
1514
1515 /* Make sure we are on a 4-byte boundary, in case someone has been
1516 putting data into a text section. */
1517 if (bytes & 3)
1518 {
1519 int fix = bytes & 3;
1520 memset (p, 0, fix);
1521 p += fix;
1522 fragp->fr_fix += fix;
1523 }
1524
1525 memcpy (p, le_nop, 4);
1526 fragp->fr_var = 4;
1527}
1528
14d3f364
JE
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. */
1532
1533void
1534i860_check_label (symbolS *labelsym)
1535{
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 == ':')
1539 {
1540 S_SET_EXTERNAL (labelsym);
1541 input_line_pointer++;
1542 }
1543}
1544
This page took 0.422534 seconds and 4 git commands to generate.