1 /* tc-i960.c - All the i80960-specific stuff
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* See comment on md_parse_option for 80960-specific invocation options. */
25 /* There are 4 different lengths of (potentially) symbol-based displacements
26 in the 80960 instruction set, each of which could require address fix-ups
27 and (in the case of external symbols) emission of relocation directives:
30 This is a standard length for the base assembler and requires no
34 This is a non-standard length, but the base assembler has a
35 hook for bit field address fixups: the fixS structure can
36 point to a descriptor of the field, in which case our
37 md_number_to_field() routine gets called to process it.
39 I made the hook a little cleaner by having fix_new() (in the base
40 assembler) return a pointer to the fixS in question. And I made it a
41 little simpler by storing the field size (in this case 13) instead of
42 of a pointer to another structure: 80960 displacements are ALWAYS
43 stored in the low-order bits of a 4-byte word.
45 Since the target of a COBR cannot be external, no relocation
46 directives for this size displacement have to be generated.
47 But the base assembler had to be modified to issue error
48 messages if the symbol did turn out to be external.
51 Fixups are handled as for the 13-bit case (except that 24 is stored
54 The relocation directive generated is the same as that for the 32-bit
55 displacement, except that it's PC-relative (the 32-bit displacement
56 never is). The i80960 version of the linker needs a mod to
57 distinguish and handle the 24-bit case.
60 MEMA formats are always promoted to MEMB (32-bit) if the displacement
61 is based on a symbol, because it could be relocated at link time.
62 The only time we use the 12-bit format is if an absolute value of
63 less than 4096 is specified, in which case we need neither a fixup nor
64 a relocation directive. */
70 #include "safe-ctype.h"
73 #include "opcode/i960.h"
75 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
77 #define TC_S_IS_SYSPROC(s) ((1<=S_GET_OTHER(s)) && (S_GET_OTHER(s)<=32))
78 #define TC_S_IS_BALNAME(s) (S_GET_OTHER(s) == N_BALNAME)
79 #define TC_S_IS_CALLNAME(s) (S_GET_OTHER(s) == N_CALLNAME)
80 #define TC_S_IS_BADPROC(s) ((S_GET_OTHER(s) != 0) && !TC_S_IS_CALLNAME(s) && !TC_S_IS_BALNAME(s) && !TC_S_IS_SYSPROC(s))
82 #define TC_S_SET_SYSPROC(s, p) (S_SET_OTHER((s), (p)+1))
83 #define TC_S_GET_SYSPROC(s) (S_GET_OTHER(s)-1)
85 #define TC_S_FORCE_TO_BALNAME(s) (S_SET_OTHER((s), N_BALNAME))
86 #define TC_S_FORCE_TO_CALLNAME(s) (S_SET_OTHER((s), N_CALLNAME))
87 #define TC_S_FORCE_TO_SYSPROC(s) {;}
89 #else /* ! OBJ_A/BOUT */
92 #define TC_S_IS_SYSPROC(s) (S_GET_STORAGE_CLASS(s) == C_SCALL)
93 #define TC_S_IS_BALNAME(s) (SF_GET_BALNAME(s))
94 #define TC_S_IS_CALLNAME(s) (SF_GET_CALLNAME(s))
95 #define TC_S_IS_BADPROC(s) (TC_S_IS_SYSPROC(s) && TC_S_GET_SYSPROC(s) < 0 && 31 < TC_S_GET_SYSPROC(s))
97 #define TC_S_SET_SYSPROC(s, p) ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx = (p))
98 #define TC_S_GET_SYSPROC(s) ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx)
100 #define TC_S_FORCE_TO_BALNAME(s) (SF_SET_BALNAME(s))
101 #define TC_S_FORCE_TO_CALLNAME(s) (SF_SET_CALLNAME(s))
102 #define TC_S_FORCE_TO_SYSPROC(s) (S_SET_STORAGE_CLASS((s), C_SCALL))
104 #else /* ! OBJ_COFF */
106 #define TC_S_IS_SYSPROC(s) 0
108 #define TC_S_IS_BALNAME(s) 0
109 #define TC_S_IS_CALLNAME(s) 0
110 #define TC_S_IS_BADPROC(s) 0
112 #define TC_S_SET_SYSPROC(s, p)
113 #define TC_S_GET_SYSPROC(s) 0
115 #define TC_S_FORCE_TO_BALNAME(s)
116 #define TC_S_FORCE_TO_CALLNAME(s)
117 #define TC_S_FORCE_TO_SYSPROC(s)
119 #error COFF, a.out, b.out, and ELF are the only supported formats.
120 #endif /* ! OBJ_ELF */
121 #endif /* ! OBJ_COFF */
122 #endif /* ! OBJ_A/BOUT */
124 extern char *input_line_pointer
;
126 #if !defined (BFD_ASSEMBLER) && !defined (BFD)
128 const int md_reloc_size
= sizeof (struct reloc
);
130 const int md_reloc_size
= sizeof (struct relocation_info
);
131 #endif /* OBJ_COFF */
134 /* Local i80960 routines. */
136 static void brcnt_emit (); /* Emit branch-prediction instrumentation code */
137 static char *brlab_next (); /* Return next branch local label */
138 void brtab_emit (); /* Emit br-predict instrumentation table */
139 static void cobr_fmt (); /* Generate COBR instruction */
140 static void ctrl_fmt (); /* Generate CTRL instruction */
141 static char *emit (); /* Emit (internally) binary */
142 static int get_args (); /* Break arguments out of comma-separated list */
143 static void get_cdisp (); /* Handle COBR or CTRL displacement */
144 static char *get_ispec (); /* Find index specification string */
145 static int get_regnum (); /* Translate text to register number */
146 static int i_scan (); /* Lexical scan of instruction source */
147 static void mem_fmt (); /* Generate MEMA or MEMB instruction */
148 static void mema_to_memb (); /* Convert MEMA instruction to MEMB format */
149 static void parse_expr (); /* Parse an expression */
150 static int parse_ldconst (); /* Parse and replace a 'ldconst' pseudo-op */
151 static void parse_memop (); /* Parse a memory operand */
152 static void parse_po (); /* Parse machine-dependent pseudo-op */
153 static void parse_regop (); /* Parse a register operand */
154 static void reg_fmt (); /* Generate a REG format instruction */
155 static void relax_cobr (); /* "De-optimize" cobr into compare/branch */
156 static void s_leafproc (); /* Process '.leafproc' pseudo-op */
157 static void s_sysproc (); /* Process '.sysproc' pseudo-op */
158 static int shift_ok (); /* Will a 'shlo' substiture for a 'ldconst'? */
159 static void syntax (); /* Give syntax error */
160 static int targ_has_sfr (); /* Target chip supports spec-func register? */
161 static int targ_has_iclass (); /* Target chip supports instruction set? */
163 /* See md_parse_option() for meanings of these options */
164 static char norelax
; /* True if -norelax switch seen */
165 static char instrument_branches
; /* True if -b switch seen */
167 /* Characters that always start a comment.
168 If the pre-processor is disabled, these aren't very useful.
170 const char comment_chars
[] = "#";
172 /* Characters that only start a comment at the beginning of
173 a line. If the line seems to have the form '# 123 filename'
174 .line and .file directives will appear in the pre-processed output.
176 Note that input_file.c hand checks for '#' at the beginning of the
177 first line of the input file. This is because the compiler outputs
178 #NO_APP at the beginning of its output.
181 /* Also note that comments started like this one will always work. */
183 const char line_comment_chars
[] = "";
185 const char line_separator_chars
[] = ";";
187 /* Chars that can be used to separate mant from exp in floating point nums */
188 const char EXP_CHARS
[] = "eE";
190 /* Chars that mean this number is a floating point constant,
191 as in 0f12.456 or 0d1.2345e12
193 const char FLT_CHARS
[] = "fFdDtT";
195 /* Table used by base assembler to relax addresses based on varying length
196 instructions. The fields are:
197 1) most positive reach of this state,
198 2) most negative reach of this state,
199 3) how many bytes this mode will add to the size of the current frag
200 4) which index into the table to try if we can't fit into this one.
202 For i80960, the only application is the (de-)optimization of cobr
203 instructions into separate compare and branch instructions when a 13-bit
204 displacement won't hack it.
206 const relax_typeS md_relax_table
[] =
208 {0, 0, 0, 0}, /* State 0 => no more relaxation possible */
209 {4088, -4096, 0, 2}, /* State 1: conditional branch (cobr) */
210 {0x800000 - 8, -0x800000, 4, 0}, /* State 2: compare (reg) & branch (ctrl) */
213 static void s_endian
PARAMS ((int));
215 /* These are the machine dependent pseudo-ops.
217 This table describes all the machine specific pseudo-ops the assembler
218 has to support. The fields are:
219 pseudo-op name without dot
220 function to call to execute this pseudo-op
221 integer arg to pass to the function
226 const pseudo_typeS md_pseudo_table
[] =
229 {"endian", s_endian
, 0},
230 {"extended", float_cons
, 't'},
231 {"leafproc", parse_po
, S_LEAFPROC
},
232 {"sysproc", parse_po
, S_SYSPROC
},
240 /* Macros to extract info from an 'expressionS' structure 'e' */
241 #define adds(e) e.X_add_symbol
242 #define offs(e) e.X_add_number
244 /* Branch-prediction bits for CTRL/COBR format opcodes */
245 #define BP_MASK 0x00000002 /* Mask for branch-prediction bit */
246 #define BP_TAKEN 0x00000000 /* Value to OR in to predict branch */
247 #define BP_NOT_TAKEN 0x00000002 /* Value to OR in to predict no branch */
249 /* Some instruction opcodes that we need explicitly */
250 #define BE 0x12000000
251 #define BG 0x11000000
252 #define BGE 0x13000000
253 #define BL 0x14000000
254 #define BLE 0x16000000
255 #define BNE 0x15000000
256 #define BNO 0x10000000
257 #define BO 0x17000000
258 #define CHKBIT 0x5a002700
259 #define CMPI 0x5a002080
260 #define CMPO 0x5a002000
263 #define BAL 0x0b000000
264 #define CALL 0x09000000
265 #define CALLS 0x66003800
266 #define RET 0x0a000000
268 /* These masks are used to build up a set of MEMB mode bits. */
271 #define MEMB_BIT 0x1000
274 /* Mask for the only mode bit in a MEMA instruction (if set, abase reg is
276 #define MEMA_ABASE 0x2000
278 /* Info from which a MEMA or MEMB format instruction can be generated */
281 /* (First) 32 bits of instruction */
283 /* 0-(none), 12- or, 32-bit displacement needed */
285 /* The expression in the source instruction from which the
286 displacement should be determined. */
292 /* The two pieces of info we need to generate a register operand */
295 int mode
; /* 0 =>local/global/spec reg; 1=> literal or fp reg */
296 int special
; /* 0 =>not a sfr; 1=> is a sfr (not valid w/mode=0) */
297 int n
; /* Register number or literal value */
300 /* Number and assembler mnemonic for all registers that can appear in
342 /* Numbers for special-function registers are for assembler internal
343 use only: they are scaled back to range [0-31] for binary output. */
379 /* Numbers for floating point registers are for assembler internal
380 use only: they are scaled back to [0-3] for binary output. */
388 { NULL
, 0 }, /* END OF LIST */
391 #define IS_RG_REG(n) ((0 <= (n)) && ((n) < SF0))
392 #define IS_SF_REG(n) ((SF0 <= (n)) && ((n) < FP0))
393 #define IS_FP_REG(n) ((n) >= FP0)
395 /* Number and assembler mnemonic for all registers that can appear as
396 'abase' (indirect addressing) registers. */
438 /* For assembler internal use only: this number never appears in binary
442 { NULL
, 0 }, /* END OF LIST */
446 static struct hash_control
*op_hash
; /* Opcode mnemonics */
447 static struct hash_control
*reg_hash
; /* Register name hash table */
448 static struct hash_control
*areg_hash
; /* Abase register hash table */
450 /* Architecture for which we are assembling */
451 #define ARCH_ANY 0 /* Default: no architecture checking done */
458 int architecture
= ARCH_ANY
; /* Architecture requested on invocation line */
459 int iclasses_seen
; /* OR of instruction classes (I_* constants)
460 * for which we've actually assembled
464 /* BRANCH-PREDICTION INSTRUMENTATION
466 The following supports generation of branch-prediction instrumentation
467 (turned on by -b switch). The instrumentation collects counts
468 of branches taken/not-taken for later input to a utility that will
469 set the branch prediction bits of the instructions in accordance with
470 the behavior observed. (Note that the KX series does not have
473 The instrumentation consists of:
475 (1) before and after each conditional branch, a call to an external
476 routine that increments and steps over an inline counter. The
477 counter itself, initialized to 0, immediately follows the call
478 instruction. For each branch, the counter following the branch
479 is the number of times the branch was not taken, and the difference
480 between the counters is the number of times it was taken. An
481 example of an instrumented conditional branch:
489 (2) a table of pointers to the instrumented branches, so that an
490 external postprocessing routine can locate all of the counters.
491 the table begins with a 2-word header: a pointer to the next in
492 a linked list of such tables (initialized to 0); and a count
493 of the number of entries in the table (exclusive of the header.
495 Note that input source code is expected to already contain calls
496 an external routine that will link the branch local table into a
500 /* Number of branches instrumented so far. Also used to generate
501 unique local labels for each instrumented branch. */
504 #define BR_LABEL_BASE "LBRANCH"
505 /* Basename of local labels on instrumented branches, to avoid
506 conflict with compiler- generated local labels. */
508 #define BR_CNT_FUNC "__inc_branch"
509 /* Name of the external routine that will increment (and step over) an
512 #define BR_TAB_NAME "__BRANCH_TABLE__"
513 /* Name of the table of pointers to branches. A local (i.e.,
514 non-external) symbol. */
516 /*****************************************************************************
517 md_begin: One-time initialization.
521 *************************************************************************** */
525 int i
; /* Loop counter */
526 const struct i960_opcode
*oP
; /* Pointer into opcode table */
527 const char *retval
; /* Value returned by hash functions */
529 op_hash
= hash_new ();
530 reg_hash
= hash_new ();
531 areg_hash
= hash_new ();
533 /* For some reason, the base assembler uses an empty string for "no
534 error message", instead of a NULL pointer. */
537 for (oP
= i960_opcodes
; oP
->name
&& !retval
; oP
++)
538 retval
= hash_insert (op_hash
, oP
->name
, (PTR
) oP
);
540 for (i
= 0; regnames
[i
].reg_name
&& !retval
; i
++)
541 retval
= hash_insert (reg_hash
, regnames
[i
].reg_name
,
542 (char *) ®names
[i
].reg_num
);
544 for (i
= 0; aregs
[i
].areg_name
&& !retval
; i
++)
545 retval
= hash_insert (areg_hash
, aregs
[i
].areg_name
,
546 (char *) &aregs
[i
].areg_num
);
549 as_fatal (_("Hashing returned \"%s\"."), retval
);
552 /*****************************************************************************
553 md_assemble: Assemble an instruction
555 Assumptions about the passed-in text:
556 - all comments, labels removed
557 - text is an instruction
558 - all white space compressed to single blanks
559 - all character constants have been replaced with decimal
561 *************************************************************************** */
564 char *textP
; /* Source text of instruction */
566 /* Parsed instruction text, containing NO whitespace: arg[0]->opcode
567 mnemonic arg[1-3]->operands, with char constants replaced by
571 int n_ops
; /* Number of instruction operands */
572 /* Pointer to instruction description */
573 struct i960_opcode
*oP
;
574 /* TRUE iff opcode mnemonic included branch-prediction suffix (".f"
577 /* Setting of branch-prediction bit(s) to be OR'd into instruction
578 opcode of CTRL/COBR format instructions. */
581 int n
; /* Offset of last character in opcode mnemonic */
583 const char *bp_error_msg
= _("branch prediction invalid on this opcode");
585 /* Parse instruction into opcode and operands */
586 memset (args
, '\0', sizeof (args
));
587 n_ops
= i_scan (textP
, args
);
590 return; /* Error message already issued */
593 /* Do "macro substitution" (sort of) on 'ldconst' pseudo-instruction */
594 if (!strcmp (args
[0], "ldconst"))
596 n_ops
= parse_ldconst (args
);
603 /* Check for branch-prediction suffix on opcode mnemonic, strip it off */
604 n
= strlen (args
[0]) - 1;
607 if (args
[0][n
- 1] == '.' && (args
[0][n
] == 't' || args
[0][n
] == 'f'))
609 /* We could check here to see if the target architecture
610 supports branch prediction, but why bother? The bit will
611 just be ignored by processors that don't use it. */
613 bp_bits
= (args
[0][n
] == 't') ? BP_TAKEN
: BP_NOT_TAKEN
;
614 args
[0][n
- 1] = '\0'; /* Strip suffix from opcode mnemonic */
617 /* Look up opcode mnemonic in table and check number of operands.
618 Check that opcode is legal for the target architecture. If all
619 looks good, assemble instruction. */
620 oP
= (struct i960_opcode
*) hash_find (op_hash
, args
[0]);
621 if (!oP
|| !targ_has_iclass (oP
->iclass
))
623 as_bad (_("invalid opcode, \"%s\"."), args
[0]);
626 else if (n_ops
!= oP
->num_ops
)
628 as_bad (_("improper number of operands. expecting %d, got %d"),
637 ctrl_fmt (args
[1], oP
->opcode
| bp_bits
, oP
->num_ops
);
638 if (oP
->format
== FBRA
)
640 /* Now generate a 'bno' to same arg */
641 ctrl_fmt (args
[1], BNO
| bp_bits
, 1);
646 cobr_fmt (args
, oP
->opcode
| bp_bits
, oP
);
651 as_warn (bp_error_msg
);
656 if (args
[0][0] == 'c' && args
[0][1] == 'a')
660 as_warn (bp_error_msg
);
662 mem_fmt (args
, oP
, 1);
672 as_warn (bp_error_msg
);
674 mem_fmt (args
, oP
, 0);
679 as_warn (bp_error_msg
);
681 /* Output opcode & set up "fixup" (relocation); flag
682 relocation as 'callj' type. */
683 know (oP
->num_ops
== 1);
684 get_cdisp (args
[1], "CTRL", oP
->opcode
, 24, 0, 1);
687 BAD_CASE (oP
->format
);
691 } /* md_assemble() */
693 /*****************************************************************************
694 md_number_to_chars: convert a number to target byte order
696 *************************************************************************** */
698 md_number_to_chars (buf
, value
, n
)
703 number_to_chars_littleendian (buf
, value
, n
);
706 /*****************************************************************************
707 md_chars_to_number: convert from target byte order to host byte order.
709 *************************************************************************** */
711 md_chars_to_number (val
, n
)
712 unsigned char *val
; /* Value in target byte order */
713 int n
; /* Number of bytes in the input */
717 for (retval
= 0; n
--;)
725 #define MAX_LITTLENUMS 6
726 #define LNUM_SIZE sizeof (LITTLENUM_TYPE)
728 /*****************************************************************************
729 md_atof: convert ascii to floating point
731 Turn a string at input_line_pointer into a floating point constant of type
732 'type', and store the appropriate bytes at *litP. The number of LITTLENUMS
733 emitted is returned at 'sizeP'. An error message is returned, or a pointer
734 to an empty message if OK.
736 Note we call the i386 floating point routine, rather than complicating
737 things with more files or symbolic links.
739 *************************************************************************** */
741 md_atof (type
, litP
, sizeP
)
746 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
747 LITTLENUM_TYPE
*wordP
;
767 type
= 'x'; /* That's what atof_ieee() understands */
772 return _("Bad call to md_atof()");
775 t
= atof_ieee (input_line_pointer
, type
, words
);
778 input_line_pointer
= t
;
781 *sizeP
= prec
* LNUM_SIZE
;
783 /* Output the LITTLENUMs in REVERSE order in accord with i80960
784 word-order. (Dunno why atof_ieee doesn't do it in the right
785 order in the first place -- probably because it's a hack of
788 for (wordP
= words
+ prec
- 1; prec
--;)
790 md_number_to_chars (litP
, (long) (*wordP
--), LNUM_SIZE
);
791 litP
+= sizeof (LITTLENUM_TYPE
);
797 /*****************************************************************************
800 *************************************************************************** */
802 md_number_to_imm (buf
, val
, n
)
807 md_number_to_chars (buf
, val
, n
);
810 /*****************************************************************************
813 *************************************************************************** */
815 md_number_to_disp (buf
, val
, n
)
820 md_number_to_chars (buf
, val
, n
);
823 /*****************************************************************************
826 Stick a value (an address fixup) into a bit field of
827 previously-generated instruction.
829 *************************************************************************** */
831 md_number_to_field (instrP
, val
, bfixP
)
832 char *instrP
; /* Pointer to instruction to be fixed */
833 long val
; /* Address fixup value */
834 bit_fixS
*bfixP
; /* Description of bit field to be fixed up */
836 int numbits
; /* Length of bit field to be fixed */
837 long instr
; /* 32-bit instruction to be fixed-up */
838 long sign
; /* 0 or -1, according to sign bit of 'val' */
840 /* Convert instruction back to host byte order. */
841 instr
= md_chars_to_number (instrP
, 4);
843 /* Surprise! -- we stored the number of bits to be modified rather
844 than a pointer to a structure. */
845 numbits
= (int) bfixP
;
848 /* This is a no-op, stuck here by reloc_callj() */
852 know ((numbits
== 13) || (numbits
== 24));
854 /* Propagate sign bit of 'val' for the given number of bits. Result
855 should be all 0 or all 1. */
856 sign
= val
>> ((int) numbits
- 1);
857 if (((val
< 0) && (sign
!= -1))
858 || ((val
> 0) && (sign
!= 0)))
860 as_bad (_("Fixup of %ld too large for field width of %d"),
865 /* Put bit field into instruction and write back in target
868 val
&= ~(-1 << (int) numbits
); /* Clear unused sign bits */
870 md_number_to_chars (instrP
, instr
, 4);
872 } /* md_number_to_field() */
875 /*****************************************************************************
877 Invocation line includes a switch not recognized by the base assembler.
878 See if it's a processor-specific option. For the 960, these are:
881 Conditional branch instructions that require displacements
882 greater than 13 bits (or that have external targets) should
883 generate errors. The default is to replace each such
884 instruction with the corresponding compare (or chkbit) and
885 branch instructions. Note that the Intel "j" cobr directives
886 are ALWAYS "de-optimized" in this way when necessary,
887 regardless of the setting of this option.
890 Add code to collect information about branches taken, for
891 later optimization of branch prediction bits by a separate
892 tool. COBR and CNTL format instructions have branch
893 prediction bits (in the CX architecture); if "BR" represents
894 an instruction in one of these classes, the following rep-
895 resents the code generated by the assembler:
897 call <increment routine>
898 .word 0 # pre-counter
900 call <increment routine>
901 .word 0 # post-counter
903 A table of all such "Labels" is also generated.
905 -AKA, -AKB, -AKC, -ASA, -ASB, -AMC, -ACA:
906 Select the 80960 architecture. Instructions or features not
907 supported by the selected architecture cause fatal errors.
908 The default is to generate code for any instruction or feature
909 that is supported by SOME version of the 960 (even if this
910 means mixing architectures!).
912 ****************************************************************************/
914 const char *md_shortopts
= "A:b";
915 struct option md_longopts
[] =
917 #define OPTION_LINKRELAX (OPTION_MD_BASE)
918 {"linkrelax", no_argument
, NULL
, OPTION_LINKRELAX
},
919 {"link-relax", no_argument
, NULL
, OPTION_LINKRELAX
},
920 #define OPTION_NORELAX (OPTION_MD_BASE + 1)
921 {"norelax", no_argument
, NULL
, OPTION_NORELAX
},
922 {"no-relax", no_argument
, NULL
, OPTION_NORELAX
},
923 {NULL
, no_argument
, NULL
, 0}
925 size_t md_longopts_size
= sizeof (md_longopts
);
932 static const struct tabentry arch_tab
[] =
936 {"SA", ARCH_KA
}, /* Synonym for KA */
937 {"SB", ARCH_KB
}, /* Synonym for KB */
938 {"KC", ARCH_MC
}, /* Synonym for MC */
947 md_parse_option (c
, arg
)
953 case OPTION_LINKRELAX
:
955 flag_keep_locals
= 1;
963 instrument_branches
= 1;
968 const struct tabentry
*tp
;
971 for (tp
= arch_tab
; tp
->flag
!= NULL
; tp
++)
972 if (!strcmp (p
, tp
->flag
))
975 if (tp
->flag
== NULL
)
977 as_bad (_("invalid architecture %s"), p
);
981 architecture
= tp
->arch
;
993 md_show_usage (stream
)
997 fprintf (stream
, _("I960 options:\n"));
998 for (i
= 0; arch_tab
[i
].flag
; i
++)
999 fprintf (stream
, "%s-A%s", i
? " | " : "", arch_tab
[i
].flag
);
1000 fprintf (stream
, _("\n\
1001 specify variant of 960 architecture\n\
1002 -b add code to collect statistics about branches taken\n\
1003 -link-relax preserve individual alignment directives so linker\n\
1004 can do relaxing (b.out format only)\n\
1005 -no-relax don't alter compare-and-branch instructions for\n\
1006 long displacements\n"));
1010 /*****************************************************************************
1012 Called by base assembler after address relaxation is finished: modify
1013 variable fragments according to how much relaxation was done.
1015 If the fragment substate is still 1, a 13-bit displacement was enough
1016 to reach the symbol in question. Set up an address fixup, but otherwise
1017 leave the cobr instruction alone.
1019 If the fragment substate is 2, a 13-bit displacement was not enough.
1020 Replace the cobr with a two instructions (a compare and a branch).
1022 *************************************************************************** */
1023 #ifndef BFD_ASSEMBLER
1025 md_convert_frag (headers
, seg
, fragP
)
1026 object_headers
*headers
;
1031 md_convert_frag (abfd
, sec
, fragP
)
1037 fixS
*fixP
; /* Structure describing needed address fix */
1039 switch (fragP
->fr_subtype
)
1042 /* LEAVE SINGLE COBR INSTRUCTION */
1043 fixP
= fix_new (fragP
,
1044 fragP
->fr_opcode
- fragP
->fr_literal
,
1051 fixP
->fx_bit_fixP
= (bit_fixS
*) 13; /* size of bit field */
1054 /* REPLACE COBR WITH COMPARE/BRANCH INSTRUCTIONS */
1058 BAD_CASE (fragP
->fr_subtype
);
1063 /*****************************************************************************
1064 md_estimate_size_before_relax: How much does it look like *fragP will grow?
1066 Called by base assembler just before address relaxation.
1067 Return the amount by which the fragment will grow.
1069 Any symbol that is now undefined will not become defined; cobr's
1070 based on undefined symbols will have to be replaced with a compare
1071 instruction and a branch instruction, and the code fragment will grow
1074 *************************************************************************** */
1076 md_estimate_size_before_relax (fragP
, segment_type
)
1077 register fragS
*fragP
;
1078 register segT segment_type
;
1080 /* If symbol is undefined in this segment, go to "relaxed" state
1081 (compare and branch instructions instead of cobr) right now. */
1082 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment_type
)
1088 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
1089 } /* md_estimate_size_before_relax() */
1091 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1093 /*****************************************************************************
1095 This routine exists in order to overcome machine byte-order problems
1096 when dealing with bit-field entries in the relocation_info struct.
1098 But relocation info will be used on the host machine only (only
1099 executable code is actually downloaded to the i80960). Therefore,
1100 we leave it in host byte order.
1102 The above comment is no longer true. This routine now really
1103 does do the reordering (Ian Taylor 28 Aug 92).
1105 *************************************************************************** */
1108 md_ri_to_chars (where
, ri
)
1110 struct relocation_info
*ri
;
1112 md_number_to_chars (where
, ri
->r_address
,
1113 sizeof (ri
->r_address
));
1114 where
[4] = ri
->r_index
& 0x0ff;
1115 where
[5] = (ri
->r_index
>> 8) & 0x0ff;
1116 where
[6] = (ri
->r_index
>> 16) & 0x0ff;
1117 where
[7] = ((ri
->r_pcrel
<< 0)
1118 | (ri
->r_length
<< 1)
1119 | (ri
->r_extern
<< 3)
1122 | (ri
->r_callj
<< 6));
1125 #endif /* defined(OBJ_AOUT) | defined(OBJ_BOUT) */
1128 /* FOLLOWING ARE THE LOCAL ROUTINES, IN ALPHABETICAL ORDER */
1130 /*****************************************************************************
1131 brcnt_emit: Emit code to increment inline branch counter.
1133 See the comments above the declaration of 'br_cnt' for details on
1134 branch-prediction instrumentation.
1135 *************************************************************************** */
1139 ctrl_fmt (BR_CNT_FUNC
, CALL
, 1); /* Emit call to "increment" routine */
1140 emit (0); /* Emit inline counter to be incremented */
1143 /*****************************************************************************
1144 brlab_next: generate the next branch local label
1146 See the comments above the declaration of 'br_cnt' for details on
1147 branch-prediction instrumentation.
1148 *************************************************************************** */
1152 static char buf
[20];
1154 sprintf (buf
, "%s%d", BR_LABEL_BASE
, br_cnt
++);
1158 /*****************************************************************************
1159 brtab_emit: generate the fetch-prediction branch table.
1161 See the comments above the declaration of 'br_cnt' for details on
1162 branch-prediction instrumentation.
1164 The code emitted here would be functionally equivalent to the following
1165 example assembler source.
1170 .word 0 # link to next table
1171 .word 3 # length of table
1172 .word LBRANCH0 # 1st entry in table proper
1175 **************************************************************************** */
1181 char *p
; /* Where the binary was output to */
1182 /* Pointer to description of deferred address fixup. */
1185 if (!instrument_branches
)
1190 subseg_set (data_section
, 0); /* .data */
1191 frag_align (2, 0, 0); /* .align 2 */
1192 record_alignment (now_seg
, 2);
1193 colon (BR_TAB_NAME
); /* BR_TAB_NAME: */
1194 emit (0); /* .word 0 #link to next table */
1195 emit (br_cnt
); /* .word n #length of table */
1197 for (i
= 0; i
< br_cnt
; i
++)
1199 sprintf (buf
, "%s%d", BR_LABEL_BASE
, i
);
1201 fixP
= fix_new (frag_now
,
1202 p
- frag_now
->fr_literal
,
1211 /*****************************************************************************
1212 cobr_fmt: generate a COBR-format instruction
1214 *************************************************************************** */
1217 cobr_fmt (arg
, opcode
, oP
)
1218 /* arg[0]->opcode mnemonic, arg[1-3]->operands (ascii) */
1220 /* Opcode, with branch-prediction bits already set if necessary. */
1222 /* Pointer to description of instruction. */
1223 struct i960_opcode
*oP
;
1225 long instr
; /* 32-bit instruction */
1226 struct regop regop
; /* Description of register operand */
1227 int n
; /* Number of operands */
1228 int var_frag
; /* 1 if varying length code fragment should
1229 * be emitted; 0 if an address fix
1230 * should be emitted.
1238 /* First operand (if any) of a COBR is always a register
1239 operand. Parse it. */
1240 parse_regop (®op
, arg
[1], oP
->operand
[0]);
1241 instr
|= (regop
.n
<< 19) | (regop
.mode
<< 13);
1245 /* Second operand (if any) of a COBR is always a register
1246 operand. Parse it. */
1247 parse_regop (®op
, arg
[2], oP
->operand
[1]);
1248 instr
|= (regop
.n
<< 14) | regop
.special
;
1258 if (instrument_branches
)
1261 colon (brlab_next ());
1264 /* A third operand to a COBR is always a displacement. Parse
1265 it; if it's relaxable (a cobr "j" directive, or any cobr
1266 other than bbs/bbc when the "-norelax" option is not in use)
1267 set up a variable code fragment; otherwise set up an address
1269 var_frag
= !norelax
|| (oP
->format
== COJ
); /* TRUE or FALSE */
1270 get_cdisp (arg
[3], "COBR", instr
, 13, var_frag
, 0);
1272 if (instrument_branches
)
1279 /*****************************************************************************
1280 ctrl_fmt: generate a CTRL-format instruction
1282 *************************************************************************** */
1285 ctrl_fmt (targP
, opcode
, num_ops
)
1286 char *targP
; /* Pointer to text of lone operand (if any) */
1287 long opcode
; /* Template of instruction */
1288 int num_ops
; /* Number of operands */
1290 int instrument
; /* TRUE iff we should add instrumentation to track
1291 * how often the branch is taken
1296 emit (opcode
); /* Output opcode */
1301 instrument
= instrument_branches
&& (opcode
!= CALL
)
1302 && (opcode
!= B
) && (opcode
!= RET
) && (opcode
!= BAL
);
1307 colon (brlab_next ());
1310 /* The operand MUST be an ip-relative displacment. Parse it
1311 * and set up address fix for the instruction we just output.
1313 get_cdisp (targP
, "CTRL", opcode
, 24, 0, 0);
1323 /*****************************************************************************
1324 emit: output instruction binary
1326 Output instruction binary, in target byte order, 4 bytes at a time.
1327 Return pointer to where it was placed.
1329 *************************************************************************** */
1333 long instr
; /* Word to be output, host byte order */
1335 char *toP
; /* Where to output it */
1337 toP
= frag_more (4); /* Allocate storage */
1338 md_number_to_chars (toP
, instr
, 4); /* Convert to target byte order */
1342 /*****************************************************************************
1343 get_args: break individual arguments out of comma-separated list
1346 - all comments and labels have been removed
1347 - all strings of whitespace have been collapsed to a single blank.
1348 - all character constants ('x') have been replaced with decimal
1351 args[0] is untouched. args[1] points to first operand, etc. All args:
1352 - are NULL-terminated
1353 - contain no whitespace
1356 Number of operands (0,1,2, or 3) or -1 on error.
1358 *************************************************************************** */
1361 /* Pointer to comma-separated operands; MUCKED BY US */
1363 /* Output arg: pointers to operands placed in args[1-3]. MUST
1364 ACCOMMODATE 4 ENTRIES (args[0-3]). */
1367 register int n
; /* Number of operands */
1370 /* Skip lead white space */
1384 /* Squeze blanks out by moving non-blanks toward start of string.
1385 * Isolate operands, whenever comma is found.
1392 && (! ISALNUM (p
[1])
1393 || ! ISALNUM (p
[-1])))
1401 /* Start of operand */
1404 as_bad (_("too many operands"));
1407 *to
++ = '\0'; /* Terminate argument */
1408 args
[++n
] = to
; /* Start next argument */
1421 /*****************************************************************************
1422 get_cdisp: handle displacement for a COBR or CTRL instruction.
1424 Parse displacement for a COBR or CTRL instruction.
1426 If successful, output the instruction opcode and set up for it,
1427 depending on the arg 'var_frag', either:
1428 o an address fixup to be done when all symbol values are known, or
1429 o a varying length code fragment, with address fixup info. This
1430 will be done for cobr instructions that may have to be relaxed
1431 in to compare/branch instructions (8 bytes) if the final
1432 address displacement is greater than 13 bits.
1434 ****************************************************************************/
1437 get_cdisp (dispP
, ifmtP
, instr
, numbits
, var_frag
, callj
)
1438 /* displacement as specified in source instruction */
1440 /* "COBR" or "CTRL" (for use in error message) */
1442 /* Instruction needing the displacement */
1444 /* # bits of displacement (13 for COBR, 24 for CTRL) */
1446 /* 1 if varying length code fragment should be emitted;
1447 * 0 if an address fix should be emitted.
1450 /* 1 if callj relocation should be done; else 0 */
1453 expressionS e
; /* Parsed expression */
1454 fixS
*fixP
; /* Structure describing needed address fix */
1455 char *outP
; /* Where instruction binary is output to */
1459 parse_expr (dispP
, &e
);
1463 as_bad (_("expression syntax error"));
1466 if (S_GET_SEGMENT (e
.X_add_symbol
) == now_seg
1467 || S_GET_SEGMENT (e
.X_add_symbol
) == undefined_section
)
1471 outP
= frag_more (8); /* Allocate worst-case storage */
1472 md_number_to_chars (outP
, instr
, 4);
1473 frag_variant (rs_machine_dependent
, 4, 4, 1,
1474 adds (e
), offs (e
), outP
);
1478 /* Set up a new fix structure, so address can be updated
1479 * when all symbol values are known.
1481 outP
= emit (instr
);
1482 fixP
= fix_new (frag_now
,
1483 outP
- frag_now
->fr_literal
,
1490 fixP
->fx_tcbit
= callj
;
1492 /* We want to modify a bit field when the address is
1493 * known. But we don't need all the garbage in the
1494 * bit_fix structure. So we're going to lie and store
1495 * the number of bits affected instead of a pointer.
1497 fixP
->fx_bit_fixP
= (bit_fixS
*) numbits
;
1501 as_bad (_("attempt to branch into different segment"));
1505 as_bad (_("target of %s instruction must be a label"), ifmtP
);
1510 /*****************************************************************************
1511 get_ispec: parse a memory operand for an index specification
1513 Here, an "index specification" is taken to be anything surrounded
1514 by square brackets and NOT followed by anything else.
1516 If it's found, detach it from the input string, remove the surrounding
1517 square brackets, and return a pointer to it. Otherwise, return NULL.
1519 *************************************************************************** */
1523 /* Pointer to memory operand from source instruction, no white space. */
1526 /* Points to start of index specification. */
1528 /* Points to end of index specification. */
1531 /* Find opening square bracket, if any. */
1532 start
= strchr (textP
, '[');
1537 /* Eliminate '[', detach from rest of operand */
1540 end
= strchr (start
, ']');
1544 as_bad (_("unmatched '['"));
1549 /* Eliminate ']' and make sure it was the last thing
1553 if (*(end
+ 1) != '\0')
1555 as_bad (_("garbage after index spec ignored"));
1562 /*****************************************************************************
1565 Look up a (suspected) register name in the register table and return the
1566 associated register number (or -1 if not found).
1568 *************************************************************************** */
1571 get_regnum (regname
)
1572 char *regname
; /* Suspected register name */
1576 rP
= (int *) hash_find (reg_hash
, regname
);
1577 return (rP
== NULL
) ? -1 : *rP
;
1580 /*****************************************************************************
1581 i_scan: perform lexical scan of ascii assembler instruction.
1584 - input string is an i80960 instruction (not a pseudo-op)
1585 - all comments and labels have been removed
1586 - all strings of whitespace have been collapsed to a single blank.
1589 args[0] points to opcode, other entries point to operands. All strings:
1590 - are NULL-terminated
1591 - contain no whitespace
1592 - have character constants ('x') replaced with a decimal number
1595 Number of operands (0,1,2, or 3) or -1 on error.
1597 *************************************************************************** */
1600 /* Pointer to ascii instruction; MUCKED BY US. */
1602 /* Output arg: pointers to opcode and operands placed here. MUST
1603 ACCOMMODATE 4 ENTRIES. */
1607 /* Isolate opcode */
1611 } /* Skip lead space, if any */
1613 for (; *iP
!= ' '; iP
++)
1617 /* There are no operands */
1620 /* We never moved: there was no opcode either! */
1621 as_bad (_("missing opcode"));
1627 *iP
++ = '\0'; /* Terminate opcode */
1628 return (get_args (iP
, args
));
1631 /*****************************************************************************
1632 mem_fmt: generate a MEMA- or MEMB-format instruction
1634 *************************************************************************** */
1636 mem_fmt (args
, oP
, callx
)
1637 char *args
[]; /* args[0]->opcode mnemonic, args[1-3]->operands */
1638 struct i960_opcode
*oP
; /* Pointer to description of instruction */
1639 int callx
; /* Is this a callx opcode */
1641 int i
; /* Loop counter */
1642 struct regop regop
; /* Description of register operand */
1643 char opdesc
; /* Operand descriptor byte */
1644 memS instr
; /* Description of binary to be output */
1645 char *outP
; /* Where the binary was output to */
1646 expressionS expr
; /* Parsed expression */
1647 /* ->description of deferred address fixup */
1651 /* COFF support isn't in place yet for callx relaxing. */
1655 memset (&instr
, '\0', sizeof (memS
));
1656 instr
.opcode
= oP
->opcode
;
1658 /* Process operands. */
1659 for (i
= 1; i
<= oP
->num_ops
; i
++)
1661 opdesc
= oP
->operand
[i
- 1];
1665 parse_memop (&instr
, args
[i
], oP
->format
);
1669 parse_regop (®op
, args
[i
], opdesc
);
1670 instr
.opcode
|= regop
.n
<< 19;
1674 /* Parse the displacement; this must be done before emitting the
1675 opcode, in case it is an expression using `.'. */
1676 parse_expr (instr
.e
, &expr
);
1679 outP
= emit (instr
.opcode
);
1681 if (instr
.disp
== 0)
1686 /* Process the displacement */
1690 as_bad (_("expression syntax error"));
1694 if (instr
.disp
== 32)
1696 (void) emit (offs (expr
)); /* Output displacement */
1700 /* 12-bit displacement */
1701 if (offs (expr
) & ~0xfff)
1703 /* Won't fit in 12 bits: convert already-output
1704 * instruction to MEMB format, output
1707 mema_to_memb (outP
);
1708 (void) emit (offs (expr
));
1712 /* WILL fit in 12 bits: OR into opcode and
1713 * overwrite the binary we already put out
1715 instr
.opcode
|= offs (expr
);
1716 md_number_to_chars (outP
, instr
.opcode
, 4);
1722 if (instr
.disp
== 12)
1724 /* Displacement is dependent on a symbol, whose value
1725 * may change at link time. We HAVE to reserve 32 bits.
1726 * Convert already-output opcode to MEMB format.
1728 mema_to_memb (outP
);
1731 /* Output 0 displacement and set up address fixup for when
1732 * this symbol's value becomes known.
1734 outP
= emit ((long) 0);
1735 fixP
= fix_new_exp (frag_now
,
1736 outP
- frag_now
->fr_literal
,
1741 /* Steve's linker relaxing hack. Mark this 32-bit relocation as
1742 being in the instruction stream, specifically as part of a callx
1744 fixP
->fx_bsr
= callx
;
1749 /*****************************************************************************
1750 mema_to_memb: convert a MEMA-format opcode to a MEMB-format opcode.
1752 There are 2 possible MEMA formats:
1754 - displacement + abase
1756 They are distinguished by the setting of the MEMA_ABASE bit.
1758 *************************************************************************** */
1760 mema_to_memb (opcodeP
)
1761 char *opcodeP
; /* Where to find the opcode, in target byte order */
1763 long opcode
; /* Opcode in host byte order */
1764 long mode
; /* Mode bits for MEMB instruction */
1766 opcode
= md_chars_to_number (opcodeP
, 4);
1767 know (!(opcode
& MEMB_BIT
));
1769 mode
= MEMB_BIT
| D_BIT
;
1770 if (opcode
& MEMA_ABASE
)
1775 opcode
&= 0xffffc000; /* Clear MEMA offset and mode bits */
1776 opcode
|= mode
; /* Set MEMB mode bits */
1778 md_number_to_chars (opcodeP
, opcode
, 4);
1779 } /* mema_to_memb() */
1781 /*****************************************************************************
1782 parse_expr: parse an expression
1784 Use base assembler's expression parser to parse an expression.
1785 It, unfortunately, runs off a global which we have to save/restore
1786 in order to make it work for us.
1788 An empty expression string is treated as an absolute 0.
1790 Sets O_illegal regardless of expression evaluation if entire input
1791 string is not consumed in the evaluation -- tolerate no dangling junk!
1793 *************************************************************************** */
1795 parse_expr (textP
, expP
)
1796 char *textP
; /* Text of expression to be parsed */
1797 expressionS
*expP
; /* Where to put the results of parsing */
1799 char *save_in
; /* Save global here */
1806 /* Treat empty string as absolute 0 */
1807 expP
->X_add_symbol
= expP
->X_op_symbol
= NULL
;
1808 expP
->X_add_number
= 0;
1809 expP
->X_op
= O_constant
;
1813 save_in
= input_line_pointer
; /* Save global */
1814 input_line_pointer
= textP
; /* Make parser work for us */
1816 (void) expression (expP
);
1817 if ((size_t) (input_line_pointer
- textP
) != strlen (textP
))
1819 /* Did not consume all of the input */
1820 expP
->X_op
= O_illegal
;
1822 symP
= expP
->X_add_symbol
;
1823 if (symP
&& (hash_find (reg_hash
, S_GET_NAME (symP
))))
1825 /* Register name in an expression */
1826 /* FIXME: this isn't much of a check any more. */
1827 expP
->X_op
= O_illegal
;
1830 input_line_pointer
= save_in
; /* Restore global */
1834 /*****************************************************************************
1836 Parse and replace a 'ldconst' pseudo-instruction with an appropriate
1839 Assumes the input consists of:
1840 arg[0] opcode mnemonic ('ldconst')
1841 arg[1] first operand (constant)
1842 arg[2] name of register to be loaded
1844 Replaces opcode and/or operands as appropriate.
1846 Returns the new number of arguments, or -1 on failure.
1848 *************************************************************************** */
1852 char *arg
[]; /* See above */
1854 int n
; /* Constant to be loaded */
1855 int shift
; /* Shift count for "shlo" instruction */
1856 static char buf
[5]; /* Literal for first operand */
1857 static char buf2
[5]; /* Literal for second operand */
1858 expressionS e
; /* Parsed expression */
1860 arg
[3] = NULL
; /* So we can tell at the end if it got used or not */
1862 parse_expr (arg
[1], &e
);
1866 /* We're dependent on one or more symbols -- use "lda" */
1871 /* Try the following mappings:
1872 * ldconst 0,<reg> ->mov 0,<reg>
1873 * ldconst 31,<reg> ->mov 31,<reg>
1874 * ldconst 32,<reg> ->addo 1,31,<reg>
1875 * ldconst 62,<reg> ->addo 31,31,<reg>
1876 * ldconst 64,<reg> ->shlo 8,3,<reg>
1877 * ldconst -1,<reg> ->subo 1,0,<reg>
1878 * ldconst -31,<reg>->subo 31,0,<reg>
1880 * anthing else becomes:
1884 if ((0 <= n
) && (n
<= 31))
1889 else if ((-31 <= n
) && (n
<= -1))
1893 sprintf (buf
, "%d", -n
);
1898 else if ((32 <= n
) && (n
<= 62))
1903 sprintf (buf
, "%d", n
- 31);
1907 else if ((shift
= shift_ok (n
)) != 0)
1911 sprintf (buf
, "%d", shift
);
1913 sprintf (buf2
, "%d", n
>> shift
);
1924 as_bad (_("invalid constant"));
1928 return (arg
[3] == 0) ? 2 : 3;
1931 /*****************************************************************************
1932 parse_memop: parse a memory operand
1934 This routine is based on the observation that the 4 mode bits of the
1935 MEMB format, taken individually, have fairly consistent meaning:
1937 M3 (bit 13): 1 if displacement is present (D_BIT)
1938 M2 (bit 12): 1 for MEMB instructions (MEMB_BIT)
1939 M1 (bit 11): 1 if index is present (I_BIT)
1940 M0 (bit 10): 1 if abase is present (A_BIT)
1942 So we parse the memory operand and set bits in the mode as we find
1943 things. Then at the end, if we go to MEMB format, we need only set
1944 the MEMB bit (M2) and our mode is built for us.
1946 Unfortunately, I said "fairly consistent". The exceptions:
1949 0100 Would seem illegal, but means "abase-only".
1951 0101 Would seem to mean "abase-only" -- it means IP-relative.
1952 Must be converted to 0100.
1954 0110 Would seem to mean "index-only", but is reserved.
1955 We turn on the D bit and provide a 0 displacement.
1957 The other thing to observe is that we parse from the right, peeling
1958 things * off as we go: first any index spec, then any abase, then
1961 *************************************************************************** */
1964 parse_memop (memP
, argP
, optype
)
1965 memS
*memP
; /* Where to put the results */
1966 char *argP
; /* Text of the operand to be parsed */
1967 int optype
; /* MEM1, MEM2, MEM4, MEM8, MEM12, or MEM16 */
1969 char *indexP
; /* Pointer to index specification with "[]" removed */
1970 char *p
; /* Temp char pointer */
1971 char iprel_flag
; /* True if this is an IP-relative operand */
1972 int regnum
; /* Register number */
1973 /* Scale factor: 1,2,4,8, or 16. Later converted to internal format
1974 (0,1,2,3,4 respectively). */
1976 int mode
; /* MEMB mode bits */
1977 int *intP
; /* Pointer to register number */
1979 /* The following table contains the default scale factors for each
1980 type of memory instruction. It is accessed using (optype-MEM1)
1981 as an index -- thus it assumes the 'optype' constants are
1982 assigned consecutive values, in the order they appear in this
1984 static const int def_scale
[] =
1990 -1, /* MEM12 -- no valid default */
1994 iprel_flag
= mode
= 0;
1996 /* Any index present? */
1997 indexP
= get_ispec (argP
);
2000 p
= strchr (indexP
, '*');
2003 /* No explicit scale -- use default for this instruction
2004 type and assembler mode. */
2008 /* GNU960 compatibility */
2009 scale
= def_scale
[optype
- MEM1
];
2013 *p
++ = '\0'; /* Eliminate '*' */
2015 /* Now indexP->a '\0'-terminated register name,
2016 * and p->a scale factor.
2019 if (!strcmp (p
, "16"))
2023 else if (strchr ("1248", *p
) && (p
[1] == '\0'))
2033 regnum
= get_regnum (indexP
); /* Get index reg. # */
2034 if (!IS_RG_REG (regnum
))
2036 as_bad (_("invalid index register"));
2040 /* Convert scale to its binary encoding */
2059 as_bad (_("invalid scale factor"));
2063 memP
->opcode
|= scale
| regnum
; /* Set index bits in opcode */
2064 mode
|= I_BIT
; /* Found a valid index spec */
2067 /* Any abase (Register Indirect) specification present? */
2068 if ((p
= strrchr (argP
, '(')) != NULL
)
2070 /* "(" is there -- does it start a legal abase spec? If not, it
2071 could be part of a displacement expression. */
2072 intP
= (int *) hash_find (areg_hash
, p
);
2075 /* Got an abase here */
2077 *p
= '\0'; /* discard register spec */
2078 if (regnum
== IPREL
)
2080 /* We have to specialcase ip-rel mode */
2085 memP
->opcode
|= regnum
<< 14;
2091 /* Any expression present? */
2098 /* Special-case ip-relative addressing */
2107 memP
->opcode
|= 5 << 10; /* IP-relative mode */
2113 /* Handle all other modes */
2117 /* Go with MEMA instruction format for now (grow to MEMB later
2118 if 12 bits is not enough for the displacement). MEMA format
2119 has a single mode bit: set it to indicate that abase is
2121 memP
->opcode
|= MEMA_ABASE
;
2126 /* Go with MEMA instruction format for now (grow to MEMB later
2127 if 12 bits is not enough for the displacement). */
2132 /* For some reason, the bit string for this mode is not
2133 consistent: it should be 0 (exclusive of the MEMB bit), so we
2134 set it "by hand" here. */
2135 memP
->opcode
|= MEMB_BIT
;
2139 /* set MEMB bit in mode, and OR in mode bits */
2140 memP
->opcode
|= mode
| MEMB_BIT
;
2144 /* Treat missing displacement as displacement of 0. */
2146 /* Fall into next case. */
2147 case D_BIT
| A_BIT
| I_BIT
:
2149 /* set MEMB bit in mode, and OR in mode bits */
2150 memP
->opcode
|= mode
| MEMB_BIT
;
2160 /*****************************************************************************
2161 parse_po: parse machine-dependent pseudo-op
2163 This is a top-level routine for machine-dependent pseudo-ops. It slurps
2164 up the rest of the input line, breaks out the individual arguments,
2165 and dispatches them to the correct handler.
2166 *************************************************************************** */
2170 int po_num
; /* Pseudo-op number: currently S_LEAFPROC or S_SYSPROC */
2172 /* Pointers operands, with no embedded whitespace.
2173 arg[0] unused, arg[1-3]->operands */
2175 int n_ops
; /* Number of operands */
2176 char *p
; /* Pointer to beginning of unparsed argument string */
2177 char eol
; /* Character that indicated end of line */
2179 extern char is_end_of_line
[];
2181 /* Advance input pointer to end of line. */
2182 p
= input_line_pointer
;
2183 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2185 input_line_pointer
++;
2187 eol
= *input_line_pointer
; /* Save end-of-line char */
2188 *input_line_pointer
= '\0'; /* Terminate argument list */
2190 /* Parse out operands */
2191 n_ops
= get_args (p
, args
);
2197 /* Dispatch to correct handler */
2201 s_sysproc (n_ops
, args
);
2204 s_leafproc (n_ops
, args
);
2211 /* Restore eol, so line numbers get updated correctly. Base
2212 assembler assumes we leave input pointer pointing at char
2213 following the eol. */
2214 *input_line_pointer
++ = eol
;
2217 /*****************************************************************************
2218 parse_regop: parse a register operand.
2220 In case of illegal operand, issue a message and return some valid
2221 information so instruction processing can continue.
2222 *************************************************************************** */
2225 parse_regop (regopP
, optext
, opdesc
)
2226 struct regop
*regopP
; /* Where to put description of register operand */
2227 char *optext
; /* Text of operand */
2228 char opdesc
; /* Descriptor byte: what's legal for this operand */
2230 int n
; /* Register number */
2231 expressionS e
; /* Parsed expression */
2233 /* See if operand is a register */
2234 n
= get_regnum (optext
);
2239 /* global or local register */
2240 if (!REG_ALIGN (opdesc
, n
))
2242 as_bad (_("unaligned register"));
2246 regopP
->special
= 0;
2249 else if (IS_FP_REG (n
) && FP_OK (opdesc
))
2251 /* Floating point register, and it's allowed */
2252 regopP
->n
= n
- FP0
;
2254 regopP
->special
= 0;
2257 else if (IS_SF_REG (n
) && SFR_OK (opdesc
))
2259 /* Special-function register, and it's allowed */
2260 regopP
->n
= n
- SF0
;
2262 regopP
->special
= 1;
2263 if (!targ_has_sfr (regopP
->n
))
2265 as_bad (_("no such sfr in this architecture"));
2270 else if (LIT_OK (opdesc
))
2272 /* How about a literal? */
2274 regopP
->special
= 0;
2276 { /* floating point literal acceptable */
2277 /* Skip over 0f, 0d, or 0e prefix */
2278 if ((optext
[0] == '0')
2279 && (optext
[1] >= 'd')
2280 && (optext
[1] <= 'f'))
2285 if (!strcmp (optext
, "0.0") || !strcmp (optext
, "0"))
2290 if (!strcmp (optext
, "1.0") || !strcmp (optext
, "1"))
2298 { /* fixed point literal acceptable */
2299 parse_expr (optext
, &e
);
2300 if (e
.X_op
!= O_constant
2301 || (offs (e
) < 0) || (offs (e
) > 31))
2303 as_bad (_("illegal literal"));
2306 regopP
->n
= offs (e
);
2311 /* Nothing worked */
2313 regopP
->mode
= 0; /* Register r0 is always a good one */
2315 regopP
->special
= 0;
2316 } /* parse_regop() */
2318 /*****************************************************************************
2319 reg_fmt: generate a REG-format instruction
2321 *************************************************************************** */
2324 char *args
[]; /* args[0]->opcode mnemonic, args[1-3]->operands */
2325 struct i960_opcode
*oP
; /* Pointer to description of instruction */
2327 long instr
; /* Binary to be output */
2328 struct regop regop
; /* Description of register operand */
2329 int n_ops
; /* Number of operands */
2332 n_ops
= oP
->num_ops
;
2336 parse_regop (®op
, args
[1], oP
->operand
[0]);
2338 if ((n_ops
== 1) && !(instr
& M3
))
2340 /* 1-operand instruction in which the dst field should
2341 * be used (instead of src1).
2346 regop
.mode
= regop
.special
;
2353 /* regop.n goes in bit 0, needs no shifting */
2355 regop
.special
<<= 5;
2357 instr
|= regop
.n
| regop
.mode
| regop
.special
;
2362 parse_regop (®op
, args
[2], oP
->operand
[1]);
2364 if ((n_ops
== 2) && !(instr
& M3
))
2366 /* 2-operand instruction in which the dst field should
2367 * be used instead of src2).
2372 regop
.mode
= regop
.special
;
2381 regop
.special
<<= 6;
2383 instr
|= regop
.n
| regop
.mode
| regop
.special
;
2387 parse_regop (®op
, args
[3], oP
->operand
[2]);
2390 regop
.mode
= regop
.special
;
2392 instr
|= (regop
.n
<<= 19) | (regop
.mode
<<= 13);
2397 /*****************************************************************************
2399 Replace cobr instruction in a code fragment with equivalent branch and
2400 compare instructions, so it can reach beyond a 13-bit displacement.
2401 Set up an address fix/relocation for the new branch instruction.
2403 *************************************************************************** */
2405 /* This "conditional jump" table maps cobr instructions into
2406 equivalent compare and branch opcodes. */
2415 { /* COBR OPCODE: */
2416 { CHKBIT
, BNO
}, /* 0x30 - bbc */
2417 { CMPO
, BG
}, /* 0x31 - cmpobg */
2418 { CMPO
, BE
}, /* 0x32 - cmpobe */
2419 { CMPO
, BGE
}, /* 0x33 - cmpobge */
2420 { CMPO
, BL
}, /* 0x34 - cmpobl */
2421 { CMPO
, BNE
}, /* 0x35 - cmpobne */
2422 { CMPO
, BLE
}, /* 0x36 - cmpoble */
2423 { CHKBIT
, BO
}, /* 0x37 - bbs */
2424 { CMPI
, BNO
}, /* 0x38 - cmpibno */
2425 { CMPI
, BG
}, /* 0x39 - cmpibg */
2426 { CMPI
, BE
}, /* 0x3a - cmpibe */
2427 { CMPI
, BGE
}, /* 0x3b - cmpibge */
2428 { CMPI
, BL
}, /* 0x3c - cmpibl */
2429 { CMPI
, BNE
}, /* 0x3d - cmpibne */
2430 { CMPI
, BLE
}, /* 0x3e - cmpible */
2431 { CMPI
, BO
}, /* 0x3f - cmpibo */
2437 register fragS
*fragP
; /* fragP->fr_opcode is assumed to point to
2438 * the cobr instruction, which comes at the
2439 * end of the code fragment.
2442 int opcode
, src1
, src2
, m1
, s2
;
2443 /* Bit fields from cobr instruction */
2444 long bp_bits
; /* Branch prediction bits from cobr instruction */
2445 long instr
; /* A single i960 instruction */
2446 /* ->instruction to be replaced */
2448 fixS
*fixP
; /* Relocation that can be done at assembly time */
2450 /* PICK UP & PARSE COBR INSTRUCTION */
2451 iP
= fragP
->fr_opcode
;
2452 instr
= md_chars_to_number (iP
, 4);
2453 opcode
= ((instr
>> 24) & 0xff) - 0x30; /* "-0x30" for table index */
2454 src1
= (instr
>> 19) & 0x1f;
2455 m1
= (instr
>> 13) & 1;
2457 src2
= (instr
>> 14) & 0x1f;
2458 bp_bits
= instr
& BP_MASK
;
2460 /* GENERATE AND OUTPUT COMPARE INSTRUCTION */
2461 instr
= coj
[opcode
].compare
2462 | src1
| (m1
<< 11) | (s2
<< 6) | (src2
<< 14);
2463 md_number_to_chars (iP
, instr
, 4);
2465 /* OUTPUT BRANCH INSTRUCTION */
2466 md_number_to_chars (iP
+ 4, coj
[opcode
].branch
| bp_bits
, 4);
2468 /* SET UP ADDRESS FIXUP/RELOCATION */
2469 fixP
= fix_new (fragP
,
2470 iP
+ 4 - fragP
->fr_literal
,
2477 fixP
->fx_bit_fixP
= (bit_fixS
*) 24; /* Store size of bit field */
2483 /*****************************************************************************
2484 reloc_callj: Relocate a 'callj' instruction
2486 This is a "non-(GNU)-standard" machine-dependent hook. The base
2487 assembler calls it when it decides it can relocate an address at
2488 assembly time instead of emitting a relocation directive.
2490 Check to see if the relocation involves a 'callj' instruction to a:
2491 sysproc: Replace the default 'call' instruction with a 'calls'
2492 leafproc: Replace the default 'call' instruction with a 'bal'.
2493 other proc: Do nothing.
2495 See b.out.h for details on the 'n_other' field in a symbol structure.
2498 Assumes the caller has already figured out, in the case of a leafproc,
2499 to use the 'bal' entry point, and has substituted that symbol into the
2500 passed fixup structure.
2502 *************************************************************************** */
2505 /* Relocation that can be done at assembly time */
2508 /* Points to the binary for the instruction being relocated. */
2511 if (!fixP
->fx_tcbit
)
2513 /* This wasn't a callj instruction in the first place */
2517 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2519 if (TC_S_IS_SYSPROC (fixP
->fx_addsy
))
2521 /* Symbol is a .sysproc: replace 'call' with 'calls'. System
2522 procedure number is (other-1). */
2523 md_number_to_chars (where
, CALLS
| TC_S_GET_SYSPROC (fixP
->fx_addsy
), 4);
2525 /* Nothing else needs to be done for this instruction. Make
2526 sure 'md_number_to_field()' will perform a no-op. */
2527 fixP
->fx_bit_fixP
= (bit_fixS
*) 1;
2529 else if (TC_S_IS_CALLNAME (fixP
->fx_addsy
))
2531 /* Should not happen: see block comment above */
2532 as_fatal (_("Trying to 'bal' to %s"), S_GET_NAME (fixP
->fx_addsy
));
2534 else if (TC_S_IS_BALNAME (fixP
->fx_addsy
))
2536 /* Replace 'call' with 'bal'; both instructions have the same
2537 format, so calling code should complete relocation as if
2538 nothing happened here. */
2539 md_number_to_chars (where
, BAL
, 4);
2541 else if (TC_S_IS_BADPROC (fixP
->fx_addsy
))
2543 as_bad (_("Looks like a proc, but can't tell what kind.\n"));
2544 } /* switch on proc type */
2546 /* else Symbol is neither a sysproc nor a leafproc */
2550 /*****************************************************************************
2551 s_leafproc: process .leafproc pseudo-op
2553 .leafproc takes two arguments, the second one is optional:
2554 arg[1]: name of 'call' entry point to leaf procedure
2555 arg[2]: name of 'bal' entry point to leaf procedure
2557 If the two arguments are identical, or if the second one is missing,
2558 the first argument is taken to be the 'bal' entry point.
2560 If there are 2 distinct arguments, we must make sure that the 'bal'
2561 entry point immediately follows the 'call' entry point in the linked
2564 *************************************************************************** */
2566 s_leafproc (n_ops
, args
)
2567 int n_ops
; /* Number of operands */
2568 char *args
[]; /* args[1]->1st operand, args[2]->2nd operand */
2570 symbolS
*callP
; /* Pointer to leafproc 'call' entry point symbol */
2571 symbolS
*balP
; /* Pointer to leafproc 'bal' entry point symbol */
2573 if ((n_ops
!= 1) && (n_ops
!= 2))
2575 as_bad (_("should have 1 or 2 operands"));
2577 } /* Check number of arguments */
2579 /* Find or create symbol for 'call' entry point. */
2580 callP
= symbol_find_or_make (args
[1]);
2582 if (TC_S_IS_CALLNAME (callP
))
2584 as_warn (_("Redefining leafproc %s"), S_GET_NAME (callP
));
2587 /* If that was the only argument, use it as the 'bal' entry point.
2588 * Otherwise, mark it as the 'call' entry point and find or create
2589 * another symbol for the 'bal' entry point.
2591 if ((n_ops
== 1) || !strcmp (args
[1], args
[2]))
2593 TC_S_FORCE_TO_BALNAME (callP
);
2598 TC_S_FORCE_TO_CALLNAME (callP
);
2600 balP
= symbol_find_or_make (args
[2]);
2601 if (TC_S_IS_CALLNAME (balP
))
2603 as_warn (_("Redefining leafproc %s"), S_GET_NAME (balP
));
2605 TC_S_FORCE_TO_BALNAME (balP
);
2608 tc_set_bal_of_call (callP
, balP
);
2610 } /* if only one arg, or the args are the same */
2614 s_sysproc: process .sysproc pseudo-op
2616 .sysproc takes two arguments:
2617 arg[1]: name of entry point to system procedure
2618 arg[2]: 'entry_num' (index) of system procedure in the range
2621 For [ab].out, we store the 'entrynum' in the 'n_other' field of
2622 the symbol. Since that entry is normally 0, we bias 'entrynum'
2623 by adding 1 to it. It must be unbiased before it is used. */
2625 s_sysproc (n_ops
, args
)
2626 int n_ops
; /* Number of operands */
2627 char *args
[]; /* args[1]->1st operand, args[2]->2nd operand */
2634 as_bad (_("should have two operands"));
2636 } /* bad arg count */
2638 /* Parse "entry_num" argument and check it for validity. */
2639 parse_expr (args
[2], &exp
);
2640 if (exp
.X_op
!= O_constant
2642 || (offs (exp
) > 31))
2644 as_bad (_("'entry_num' must be absolute number in [0,31]"));
2648 /* Find/make symbol and stick entry number (biased by +1) into it */
2649 symP
= symbol_find_or_make (args
[1]);
2651 if (TC_S_IS_SYSPROC (symP
))
2653 as_warn (_("Redefining entrynum for sysproc %s"), S_GET_NAME (symP
));
2656 TC_S_SET_SYSPROC (symP
, offs (exp
)); /* encode entry number */
2657 TC_S_FORCE_TO_SYSPROC (symP
);
2660 /*****************************************************************************
2662 Determine if a "shlo" instruction can be used to implement a "ldconst".
2663 This means that some number X < 32 can be shifted left to produce the
2664 constant of interest.
2666 Return the shift count, or 0 if we can't do it.
2667 Caller calculates X by shifting original constant right 'shift' places.
2669 *************************************************************************** */
2673 int n
; /* The constant of interest */
2675 int shift
; /* The shift count */
2679 /* Can't do it for negative numbers */
2683 /* Shift 'n' right until a 1 is about to be lost */
2684 for (shift
= 0; (n
& 1) == 0; shift
++)
2696 /* syntax: issue syntax error */
2701 as_bad (_("syntax error"));
2706 Return TRUE iff the target architecture supports the specified
2707 special-function register (sfr). */
2712 int n
; /* Number (0-31) of sfr */
2714 switch (architecture
)
2722 return ((0 <= n
) && (n
<= 4));
2725 return ((0 <= n
) && (n
<= 2));
2731 Return TRUE iff the target architecture supports the indicated
2732 class of instructions. */
2735 targ_has_iclass (ic
)
2736 /* Instruction class; one of:
2737 I_BASE, I_CX, I_DEC, I_KX, I_FP, I_MIL, I_CASIM, I_CX2, I_HX, I_HX2
2741 iclasses_seen
|= ic
;
2742 switch (architecture
)
2745 return ic
& (I_BASE
| I_KX
);
2747 return ic
& (I_BASE
| I_KX
| I_FP
| I_DEC
);
2749 return ic
& (I_BASE
| I_KX
| I_FP
| I_DEC
| I_MIL
);
2751 return ic
& (I_BASE
| I_CX
| I_CX2
| I_CASIM
);
2753 return ic
& (I_BASE
| I_CX2
| I_JX
);
2755 return ic
& (I_BASE
| I_CX2
| I_JX
| I_HX
);
2757 if ((iclasses_seen
& (I_KX
| I_FP
| I_DEC
| I_MIL
))
2758 && (iclasses_seen
& (I_CX
| I_CX2
)))
2760 as_warn (_("architecture of opcode conflicts with that of earlier instruction(s)"));
2761 iclasses_seen
&= ~ic
;
2767 /* Handle the MRI .endian pseudo-op. */
2776 name
= input_line_pointer
;
2777 c
= get_symbol_end ();
2778 if (strcasecmp (name
, "little") == 0)
2780 else if (strcasecmp (name
, "big") == 0)
2781 as_bad (_("big endian mode is not supported"));
2783 as_warn (_("ignoring unrecognized .endian type `%s'"), name
);
2785 *input_line_pointer
= c
;
2787 demand_empty_rest_of_line ();
2790 /* We have no need to default values of symbols. */
2793 md_undefined_symbol (name
)
2799 /* Exactly what point is a PC-relative offset relative TO?
2800 On the i960, they're relative to the address of the instruction,
2801 which we have set up as the address of the fixup too. */
2803 md_pcrel_from (fixP
)
2806 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2810 md_apply_fix3 (fixP
, valP
, seg
)
2813 segT seg ATTRIBUTE_UNUSED
;
2816 char *place
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2818 if (!fixP
->fx_bit_fixP
)
2820 #ifndef BFD_ASSEMBLER
2821 /* For callx, we always want to write out zero, and emit a
2822 symbolic relocation. */
2826 fixP
->fx_addnumber
= val
;
2829 md_number_to_imm (place
, val
, fixP
->fx_size
, fixP
);
2831 else if ((int) fixP
->fx_bit_fixP
== 13
2832 && fixP
->fx_addsy
!= NULL
2833 && S_GET_SEGMENT (fixP
->fx_addsy
) == undefined_section
)
2835 /* This is a COBR instruction. They have only a
2836 13-bit displacement and are only to be used
2837 for local branches: flag as error, don't generate
2839 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2840 _("can't use COBR format with external label"));
2841 fixP
->fx_addsy
= NULL
;
2844 md_number_to_field (place
, val
, fixP
->fx_bit_fixP
);
2846 if (fixP
->fx_addsy
== NULL
)
2850 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2852 tc_bout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2855 relax_addressT segment_address_in_file
;
2857 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
2858 struct relocation_info ri
;
2861 memset ((char *) &ri
, '\0', sizeof (ri
));
2862 symbolP
= fixP
->fx_addsy
;
2863 know (symbolP
!= 0 || fixP
->fx_r_type
!= NO_RELOC
);
2864 ri
.r_bsr
= fixP
->fx_bsr
; /*SAC LD RELAX HACK */
2865 /* These two 'cuz of NS32K */
2866 ri
.r_callj
= fixP
->fx_tcbit
;
2867 if (fixP
->fx_bit_fixP
)
2870 ri
.r_length
= nbytes_r_length
[fixP
->fx_size
];
2871 ri
.r_pcrel
= fixP
->fx_pcrel
;
2872 ri
.r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
;
2874 if (fixP
->fx_r_type
!= NO_RELOC
)
2876 switch (fixP
->fx_r_type
)
2881 ri
.r_length
= fixP
->fx_size
- 1;
2895 else if (linkrelax
|| !S_IS_DEFINED (symbolP
) || fixP
->fx_bsr
)
2898 ri
.r_index
= symbolP
->sy_number
;
2903 ri
.r_index
= S_GET_TYPE (symbolP
);
2906 /* Output the relocation information in machine-dependent form. */
2907 md_ri_to_chars (where
, &ri
);
2910 #endif /* OBJ_AOUT or OBJ_BOUT */
2912 #if defined (OBJ_COFF) && defined (BFD)
2914 tc_coff_fix2rtype (fixP
)
2920 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
2923 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
2931 tc_coff_sizemachdep (frag
)
2935 return frag
->fr_next
->fr_address
- frag
->fr_address
;
2941 /* Align an address by rounding it up to the specified boundary. */
2943 md_section_align (seg
, addr
)
2945 valueT addr
; /* Address to be rounded up */
2948 #ifdef BFD_ASSEMBLER
2949 align
= bfd_get_section_alignment (stdoutput
, seg
);
2951 align
= section_alignment
[(int) seg
];
2953 return (addr
+ (1 << align
) - 1) & (-1 << align
);
2956 extern int coff_flags
;
2960 tc_headers_hook (headers
)
2961 object_headers
*headers
;
2963 switch (architecture
)
2966 coff_flags
|= F_I960KA
;
2970 coff_flags
|= F_I960KB
;
2974 coff_flags
|= F_I960MC
;
2978 coff_flags
|= F_I960CA
;
2982 coff_flags
|= F_I960JX
;
2986 coff_flags
|= F_I960HX
;
2990 if (iclasses_seen
== I_BASE
)
2991 coff_flags
|= F_I960CORE
;
2992 else if (iclasses_seen
& I_CX
)
2993 coff_flags
|= F_I960CA
;
2994 else if (iclasses_seen
& I_HX
)
2995 coff_flags
|= F_I960HX
;
2996 else if (iclasses_seen
& I_JX
)
2997 coff_flags
|= F_I960JX
;
2998 else if (iclasses_seen
& I_CX2
)
2999 coff_flags
|= F_I960CA
;
3000 else if (iclasses_seen
& I_MIL
)
3001 coff_flags
|= F_I960MC
;
3002 else if (iclasses_seen
& (I_DEC
| I_FP
))
3003 coff_flags
|= F_I960KB
;
3005 coff_flags
|= F_I960KA
;
3009 if (flag_readonly_data_in_text
)
3011 headers
->filehdr
.f_magic
= I960RWMAGIC
;
3012 headers
->aouthdr
.magic
= OMAGIC
;
3016 headers
->filehdr
.f_magic
= I960ROMAGIC
;
3017 headers
->aouthdr
.magic
= NMAGIC
;
3018 } /* set magic numbers */
3021 #endif /* OBJ_COFF */
3023 #ifndef BFD_ASSEMBLER
3025 /* Things going on here:
3027 For bout, We need to assure a couple of simplifying
3028 assumptions about leafprocs for the linker: the leafproc
3029 entry symbols will be defined in the same assembly in
3030 which they're declared with the '.leafproc' directive;
3031 and if a leafproc has both 'call' and 'bal' entry points
3032 they are both global or both local.
3034 For coff, the call symbol has a second aux entry that
3035 contains the bal entry point. The bal symbol becomes a
3038 For coff representation, the call symbol has a second aux entry that
3039 contains the bal entry point. The bal symbol becomes a label. */
3042 tc_crawl_symbol_chain (headers
)
3043 object_headers
*headers
;
3047 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3050 if (TC_S_IS_SYSPROC (symbolP
))
3052 /* second aux entry already contains the sysproc number */
3053 S_SET_NUMBER_AUXILIARY (symbolP
, 2);
3054 S_SET_STORAGE_CLASS (symbolP
, C_SCALL
);
3055 S_SET_DATA_TYPE (symbolP
, S_GET_DATA_TYPE (symbolP
) | (DT_FCN
<< N_BTSHFT
));
3057 } /* rewrite sysproc */
3058 #endif /* OBJ_COFF */
3060 if (!TC_S_IS_BALNAME (symbolP
) && !TC_S_IS_CALLNAME (symbolP
))
3063 } /* Not a leafproc symbol */
3065 if (!S_IS_DEFINED (symbolP
))
3067 as_bad (_("leafproc symbol '%s' undefined"), S_GET_NAME (symbolP
));
3068 } /* undefined leaf */
3070 if (TC_S_IS_CALLNAME (symbolP
))
3072 symbolS
*balP
= tc_get_bal_of_call (symbolP
);
3073 if (S_IS_EXTERNAL (symbolP
) != S_IS_EXTERNAL (balP
))
3075 S_SET_EXTERNAL (symbolP
);
3076 S_SET_EXTERNAL (balP
);
3077 as_warn (_("Warning: making leafproc entries %s and %s both global\n"),
3078 S_GET_NAME (symbolP
), S_GET_NAME (balP
));
3079 } /* externality mismatch */
3081 } /* walk the symbol chain */
3084 #endif /* ! BFD_ASSEMBLER */
3086 /* For aout or bout, the bal immediately follows the call.
3088 For coff, we cheat and store a pointer to the bal symbol in the
3089 second aux entry of the call. */
3100 tc_set_bal_of_call (callP
, balP
)
3104 know (TC_S_IS_CALLNAME (callP
));
3105 know (TC_S_IS_BALNAME (balP
));
3109 callP
->sy_tc
= balP
;
3110 S_SET_NUMBER_AUXILIARY (callP
, 2);
3112 #else /* ! OBJ_COFF */
3115 /* If the 'bal' entry doesn't immediately follow the 'call'
3116 * symbol, unlink it from the symbol list and re-insert it.
3118 if (symbol_next (callP
) != balP
)
3120 symbol_remove (balP
, &symbol_rootP
, &symbol_lastP
);
3121 symbol_append (balP
, callP
, &symbol_rootP
, &symbol_lastP
);
3122 } /* if not in order */
3124 #else /* ! OBJ_ABOUT */
3125 as_fatal ("Only supported for a.out, b.out, or COFF");
3126 #endif /* ! OBJ_ABOUT */
3127 #endif /* ! OBJ_COFF */
3131 tc_get_bal_of_call (callP
)
3136 know (TC_S_IS_CALLNAME (callP
));
3139 retval
= callP
->sy_tc
;
3142 retval
= symbol_next (callP
);
3144 as_fatal ("Only supported for a.out, b.out, or COFF");
3145 #endif /* ! OBJ_ABOUT */
3146 #endif /* ! OBJ_COFF */
3148 know (TC_S_IS_BALNAME (retval
));
3150 } /* _tc_get_bal_of_call() */
3153 tc_coff_symbol_emit_hook (symbolP
)
3156 if (TC_S_IS_CALLNAME (symbolP
))
3159 symbolS
*balP
= tc_get_bal_of_call (symbolP
);
3162 /* second aux entry contains the bal entry point */
3163 S_SET_NUMBER_AUXILIARY (symbolP
, 2);
3165 symbolP
->sy_symbol
.ost_auxent
[1].x_bal
.x_balntry
= S_GET_VALUE (balP
);
3166 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
3167 S_SET_STORAGE_CLASS (symbolP
, C_LEAFEXT
);
3169 S_SET_STORAGE_CLASS (symbolP
, C_LEAFSTAT
);
3170 S_SET_DATA_TYPE (symbolP
, S_GET_DATA_TYPE (symbolP
) | (DT_FCN
<< N_BTSHFT
));
3171 /* fix up the bal symbol */
3172 S_SET_STORAGE_CLASS (balP
, C_LABEL
);
3173 #endif /* OBJ_COFF */
3174 } /* only on calls */
3178 i960_handle_align (fragp
)
3186 as_bad (_("option --link-relax is only supported in b.out format"));
3192 /* The text section "ends" with another alignment reloc, to which we
3193 aren't adding padding. */
3194 if (fragp
->fr_next
== text_last_frag
3195 || fragp
->fr_next
== data_last_frag
)
3198 /* alignment directive */
3199 fix_new (fragp
, fragp
->fr_fix
, fragp
->fr_offset
, 0, 0, 0,
3200 (int) fragp
->fr_type
);
3201 #endif /* OBJ_BOUT */
3205 i960_validate_fix (fixP
, this_segment_type
)
3207 segT this_segment_type
;
3209 if (fixP
->fx_tcbit
&& TC_S_IS_CALLNAME (fixP
->fx_addsy
))
3211 /* Relocation should be done via the associated 'bal'
3212 entry point symbol. */
3214 if (!TC_S_IS_BALNAME (tc_get_bal_of_call (fixP
->fx_addsy
)))
3216 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3217 _("No 'bal' entry point for leafproc %s"),
3218 S_GET_NAME (fixP
->fx_addsy
));
3221 fixP
->fx_addsy
= tc_get_bal_of_call (fixP
->fx_addsy
);
3227 #ifdef BFD_ASSEMBLER
3232 tc_bfd_fix2rtype (fixP
)
3240 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
3241 return BFD_RELOC_32
;
3243 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
3244 return BFD_RELOC_24_PCREL
;
3250 /* Translate internal representation of relocation info to BFD target
3253 FIXME: To what extent can we get all relevant targets to use this? */
3256 tc_gen_reloc (section
, fixP
)
3262 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3264 /* HACK: Is this right? */
3265 fixP
->fx_r_type
= tc_bfd_fix2rtype (fixP
);
3267 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
3268 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
3270 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3271 "internal error: can't export reloc type %d (`%s')",
3273 bfd_get_reloc_code_name (fixP
->fx_r_type
));
3277 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
3279 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3280 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
3281 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
3282 reloc
->addend
= fixP
->fx_addnumber
;
3287 /* end from cgen.c */
3289 #endif /* BFD_ASSEMBLER */
3291 /* end of tc-i960.c */