1 /* tc-i960.c - All the i80960-specific stuff
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* See comment on md_parse_option for 80960-specific invocation options. */
24 /* There are 4 different lengths of (potentially) symbol-based displacements
25 in the 80960 instruction set, each of which could require address fix-ups
26 and (in the case of external symbols) emission of relocation directives:
29 This is a standard length for the base assembler and requires no
33 This is a non-standard length, but the base assembler has a
34 hook for bit field address fixups: the fixS structure can
35 point to a descriptor of the field, in which case our
36 md_number_to_field() routine gets called to process it.
38 I made the hook a little cleaner by having fix_new() (in the base
39 assembler) return a pointer to the fixS in question. And I made it a
40 little simpler by storing the field size (in this case 13) instead of
41 of a pointer to another structure: 80960 displacements are ALWAYS
42 stored in the low-order bits of a 4-byte word.
44 Since the target of a COBR cannot be external, no relocation
45 directives for this size displacement have to be generated.
46 But the base assembler had to be modified to issue error
47 messages if the symbol did turn out to be external.
50 Fixups are handled as for the 13-bit case (except that 24 is stored
53 The relocation directive generated is the same as that for the 32-bit
54 displacement, except that it's PC-relative (the 32-bit displacement
55 never is). The i80960 version of the linker needs a mod to
56 distinguish and handle the 24-bit case.
59 MEMA formats are always promoted to MEMB (32-bit) if the displacement
60 is based on a symbol, because it could be relocated at link time.
61 The only time we use the 12-bit format is if an absolute value of
62 less than 4096 is specified, in which case we need neither a fixup nor
63 a relocation directive. */
72 #include "opcode/i960.h"
74 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
76 #define TC_S_IS_SYSPROC(s) ((1<=S_GET_OTHER(s)) && (S_GET_OTHER(s)<=32))
77 #define TC_S_IS_BALNAME(s) (S_GET_OTHER(s) == N_BALNAME)
78 #define TC_S_IS_CALLNAME(s) (S_GET_OTHER(s) == N_CALLNAME)
79 #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))
81 #define TC_S_SET_SYSPROC(s, p) (S_SET_OTHER((s), (p)+1))
82 #define TC_S_GET_SYSPROC(s) (S_GET_OTHER(s)-1)
84 #define TC_S_FORCE_TO_BALNAME(s) (S_SET_OTHER((s), N_BALNAME))
85 #define TC_S_FORCE_TO_CALLNAME(s) (S_SET_OTHER((s), N_CALLNAME))
86 #define TC_S_FORCE_TO_SYSPROC(s) {;}
88 #else /* ! OBJ_A/BOUT */
91 #define TC_S_IS_SYSPROC(s) (S_GET_STORAGE_CLASS(s) == C_SCALL)
92 #define TC_S_IS_BALNAME(s) (SF_GET_BALNAME(s))
93 #define TC_S_IS_CALLNAME(s) (SF_GET_CALLNAME(s))
94 #define TC_S_IS_BADPROC(s) (TC_S_IS_SYSPROC(s) && TC_S_GET_SYSPROC(s) < 0 && 31 < TC_S_GET_SYSPROC(s))
96 #define TC_S_SET_SYSPROC(s, p) ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx = (p))
97 #define TC_S_GET_SYSPROC(s) ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx)
99 #define TC_S_FORCE_TO_BALNAME(s) (SF_SET_BALNAME(s))
100 #define TC_S_FORCE_TO_CALLNAME(s) (SF_SET_CALLNAME(s))
101 #define TC_S_FORCE_TO_SYSPROC(s) (S_SET_STORAGE_CLASS((s), C_SCALL))
103 #else /* ! OBJ_COFF */
105 #define TC_S_IS_SYSPROC(s) 0
107 #define TC_S_IS_BALNAME(s) 0
108 #define TC_S_IS_CALLNAME(s) 0
109 #define TC_S_IS_BADPROC(s) 0
111 #define TC_S_SET_SYSPROC(s, p)
112 #define TC_S_GET_SYSPROC(s) 0
114 #define TC_S_FORCE_TO_BALNAME(s)
115 #define TC_S_FORCE_TO_CALLNAME(s)
116 #define TC_S_FORCE_TO_SYSPROC(s)
118 #error COFF, a.out, b.out, and ELF are the only supported formats.
119 #endif /* ! OBJ_ELF */
120 #endif /* ! OBJ_COFF */
121 #endif /* ! OBJ_A/BOUT */
123 extern char *input_line_pointer
;
125 #if !defined (BFD_ASSEMBLER) && !defined (BFD)
127 const int md_reloc_size
= sizeof (struct reloc
);
129 const int md_reloc_size
= sizeof (struct relocation_info
);
130 #endif /* OBJ_COFF */
133 /* Local i80960 routines. */
135 static void brcnt_emit (); /* Emit branch-prediction instrumentation code */
136 static char *brlab_next (); /* Return next branch local label */
137 void brtab_emit (); /* Emit br-predict instrumentation table */
138 static void cobr_fmt (); /* Generate COBR instruction */
139 static void ctrl_fmt (); /* Generate CTRL instruction */
140 static char *emit (); /* Emit (internally) binary */
141 static int get_args (); /* Break arguments out of comma-separated list */
142 static void get_cdisp (); /* Handle COBR or CTRL displacement */
143 static char *get_ispec (); /* Find index specification string */
144 static int get_regnum (); /* Translate text to register number */
145 static int i_scan (); /* Lexical scan of instruction source */
146 static void mem_fmt (); /* Generate MEMA or MEMB instruction */
147 static void mema_to_memb (); /* Convert MEMA instruction to MEMB format */
148 static void parse_expr (); /* Parse an expression */
149 static int parse_ldconst (); /* Parse and replace a 'ldconst' pseudo-op */
150 static void parse_memop (); /* Parse a memory operand */
151 static void parse_po (); /* Parse machine-dependent pseudo-op */
152 static void parse_regop (); /* Parse a register operand */
153 static void reg_fmt (); /* Generate a REG format instruction */
154 void reloc_callj (); /* Relocate a 'callj' 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
[1];
185 const char line_separator_chars
[1];
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";
196 /* Table used by base assembler to relax addresses based on varying length
197 instructions. The fields are:
198 1) most positive reach of this state,
199 2) most negative reach of this state,
200 3) how many bytes this mode will add to the size of the current frag
201 4) which index into the table to try if we can't fit into this one.
203 For i80960, the only application is the (de-)optimization of cobr
204 instructions into separate compare and branch instructions when a 13-bit
205 displacement won't hack it.
207 const relax_typeS md_relax_table
[] =
209 {0, 0, 0, 0}, /* State 0 => no more relaxation possible */
210 {4088, -4096, 0, 2}, /* State 1: conditional branch (cobr) */
211 {0x800000 - 8, -0x800000, 4, 0}, /* State 2: compare (reg) & branch (ctrl) */
214 static void s_endian
PARAMS ((int));
216 /* These are the machine dependent pseudo-ops.
218 This table describes all the machine specific pseudo-ops the assembler
219 has to support. The fields are:
220 pseudo-op name without dot
221 function to call to execute this pseudo-op
222 integer arg to pass to the function
227 const pseudo_typeS md_pseudo_table
[] =
230 {"endian", s_endian
, 0},
231 {"extended", float_cons
, 't'},
232 {"leafproc", parse_po
, S_LEAFPROC
},
233 {"sysproc", parse_po
, S_SYSPROC
},
241 /* Macros to extract info from an 'expressionS' structure 'e' */
242 #define adds(e) e.X_add_symbol
243 #define offs(e) e.X_add_number
246 /* Branch-prediction bits for CTRL/COBR format opcodes */
247 #define BP_MASK 0x00000002 /* Mask for branch-prediction bit */
248 #define BP_TAKEN 0x00000000 /* Value to OR in to predict branch */
249 #define BP_NOT_TAKEN 0x00000002 /* Value to OR in to predict no branch */
252 /* Some instruction opcodes that we need explicitly */
253 #define BE 0x12000000
254 #define BG 0x11000000
255 #define BGE 0x13000000
256 #define BL 0x14000000
257 #define BLE 0x16000000
258 #define BNE 0x15000000
259 #define BNO 0x10000000
260 #define BO 0x17000000
261 #define CHKBIT 0x5a002700
262 #define CMPI 0x5a002080
263 #define CMPO 0x5a002000
266 #define BAL 0x0b000000
267 #define CALL 0x09000000
268 #define CALLS 0x66003800
269 #define RET 0x0a000000
272 /* These masks are used to build up a set of MEMB mode bits. */
275 #define MEMB_BIT 0x1000
279 /* Mask for the only mode bit in a MEMA instruction (if set, abase reg is
281 #define MEMA_ABASE 0x2000
283 /* Info from which a MEMA or MEMB format instruction can be generated */
286 /* (First) 32 bits of instruction */
288 /* 0-(none), 12- or, 32-bit displacement needed */
290 /* The expression in the source instruction from which the
291 displacement should be determined. */
298 /* The two pieces of info we need to generate a register operand */
301 int mode
; /* 0 =>local/global/spec reg; 1=> literal or fp reg */
302 int special
; /* 0 =>not a sfr; 1=> is a sfr (not valid w/mode=0) */
303 int n
; /* Register number or literal value */
307 /* Number and assembler mnemonic for all registers that can appear in
349 /* Numbers for special-function registers are for assembler internal
350 use only: they are scaled back to range [0-31] for binary output. */
386 /* Numbers for floating point registers are for assembler internal
387 use only: they are scaled back to [0-3] for binary output. */
395 { NULL
, 0 }, /* END OF LIST */
398 #define IS_RG_REG(n) ((0 <= (n)) && ((n) < SF0))
399 #define IS_SF_REG(n) ((SF0 <= (n)) && ((n) < FP0))
400 #define IS_FP_REG(n) ((n) >= FP0)
402 /* Number and assembler mnemonic for all registers that can appear as
403 'abase' (indirect addressing) registers. */
445 /* For assembler internal use only: this number never appears in binary
449 { NULL
, 0 }, /* END OF LIST */
454 static struct hash_control
*op_hash
; /* Opcode mnemonics */
455 static struct hash_control
*reg_hash
; /* Register name hash table */
456 static struct hash_control
*areg_hash
; /* Abase register hash table */
459 /* Architecture for which we are assembling */
460 #define ARCH_ANY 0 /* Default: no architecture checking done */
467 int architecture
= ARCH_ANY
; /* Architecture requested on invocation line */
468 int iclasses_seen
; /* OR of instruction classes (I_* constants)
469 * for which we've actually assembled
474 /* BRANCH-PREDICTION INSTRUMENTATION
476 The following supports generation of branch-prediction instrumentation
477 (turned on by -b switch). The instrumentation collects counts
478 of branches taken/not-taken for later input to a utility that will
479 set the branch prediction bits of the instructions in accordance with
480 the behavior observed. (Note that the KX series does not have
483 The instrumentation consists of:
485 (1) before and after each conditional branch, a call to an external
486 routine that increments and steps over an inline counter. The
487 counter itself, initialized to 0, immediately follows the call
488 instruction. For each branch, the counter following the branch
489 is the number of times the branch was not taken, and the difference
490 between the counters is the number of times it was taken. An
491 example of an instrumented conditional branch:
499 (2) a table of pointers to the instrumented branches, so that an
500 external postprocessing routine can locate all of the counters.
501 the table begins with a 2-word header: a pointer to the next in
502 a linked list of such tables (initialized to 0); and a count
503 of the number of entries in the table (exclusive of the header.
505 Note that input source code is expected to already contain calls
506 an external routine that will link the branch local table into a
510 /* Number of branches instrumented so far. Also used to generate
511 unique local labels for each instrumented branch. */
514 #define BR_LABEL_BASE "LBRANCH"
515 /* Basename of local labels on instrumented branches, to avoid
516 conflict with compiler- generated local labels. */
518 #define BR_CNT_FUNC "__inc_branch"
519 /* Name of the external routine that will increment (and step over) an
522 #define BR_TAB_NAME "__BRANCH_TABLE__"
523 /* Name of the table of pointers to branches. A local (i.e.,
524 non-external) symbol. */
526 /*****************************************************************************
527 md_begin: One-time initialization.
531 *************************************************************************** */
535 int i
; /* Loop counter */
536 const struct i960_opcode
*oP
; /* Pointer into opcode table */
537 const char *retval
; /* Value returned by hash functions */
539 op_hash
= hash_new ();
540 reg_hash
= hash_new ();
541 areg_hash
= hash_new ();
543 /* For some reason, the base assembler uses an empty string for "no
544 error message", instead of a NULL pointer. */
547 for (oP
= i960_opcodes
; oP
->name
&& !retval
; oP
++)
548 retval
= hash_insert (op_hash
, oP
->name
, (PTR
) oP
);
550 for (i
= 0; regnames
[i
].reg_name
&& !retval
; i
++)
551 retval
= hash_insert (reg_hash
, regnames
[i
].reg_name
,
552 (char *) ®names
[i
].reg_num
);
554 for (i
= 0; aregs
[i
].areg_name
&& !retval
; i
++)
555 retval
= hash_insert (areg_hash
, aregs
[i
].areg_name
,
556 (char *) &aregs
[i
].areg_num
);
559 as_fatal (_("Hashing returned \"%s\"."), retval
);
562 /*****************************************************************************
563 md_assemble: Assemble an instruction
565 Assumptions about the passed-in text:
566 - all comments, labels removed
567 - text is an instruction
568 - all white space compressed to single blanks
569 - all character constants have been replaced with decimal
571 *************************************************************************** */
574 char *textP
; /* Source text of instruction */
576 /* Parsed instruction text, containing NO whitespace: arg[0]->opcode
577 mnemonic arg[1-3]->operands, with char constants replaced by
581 int n_ops
; /* Number of instruction operands */
582 /* Pointer to instruction description */
583 struct i960_opcode
*oP
;
584 /* TRUE iff opcode mnemonic included branch-prediction suffix (".f"
587 /* Setting of branch-prediction bit(s) to be OR'd into instruction
588 opcode of CTRL/COBR format instructions. */
591 int n
; /* Offset of last character in opcode mnemonic */
593 const char *bp_error_msg
= _("branch prediction invalid on this opcode");
596 /* Parse instruction into opcode and operands */
597 memset (args
, '\0', sizeof (args
));
598 n_ops
= i_scan (textP
, args
);
601 return; /* Error message already issued */
604 /* Do "macro substitution" (sort of) on 'ldconst' pseudo-instruction */
605 if (!strcmp (args
[0], "ldconst"))
607 n_ops
= parse_ldconst (args
);
616 /* Check for branch-prediction suffix on opcode mnemonic, strip it off */
617 n
= strlen (args
[0]) - 1;
620 if (args
[0][n
- 1] == '.' && (args
[0][n
] == 't' || args
[0][n
] == 'f'))
622 /* We could check here to see if the target architecture
623 supports branch prediction, but why bother? The bit will
624 just be ignored by processors that don't use it. */
626 bp_bits
= (args
[0][n
] == 't') ? BP_TAKEN
: BP_NOT_TAKEN
;
627 args
[0][n
- 1] = '\0'; /* Strip suffix from opcode mnemonic */
630 /* Look up opcode mnemonic in table and check number of operands.
631 Check that opcode is legal for the target architecture. If all
632 looks good, assemble instruction. */
633 oP
= (struct i960_opcode
*) hash_find (op_hash
, args
[0]);
634 if (!oP
|| !targ_has_iclass (oP
->iclass
))
636 as_bad (_("invalid opcode, \"%s\"."), args
[0]);
639 else if (n_ops
!= oP
->num_ops
)
641 as_bad (_("improper number of operands. expecting %d, got %d"),
650 ctrl_fmt (args
[1], oP
->opcode
| bp_bits
, oP
->num_ops
);
651 if (oP
->format
== FBRA
)
653 /* Now generate a 'bno' to same arg */
654 ctrl_fmt (args
[1], BNO
| bp_bits
, 1);
659 cobr_fmt (args
, oP
->opcode
| bp_bits
, oP
);
664 as_warn (bp_error_msg
);
669 if (args
[0][0] == 'c' && args
[0][1] == 'a')
673 as_warn (bp_error_msg
);
675 mem_fmt (args
, oP
, 1);
685 as_warn (bp_error_msg
);
687 mem_fmt (args
, oP
, 0);
692 as_warn (bp_error_msg
);
694 /* Output opcode & set up "fixup" (relocation); flag
695 relocation as 'callj' type. */
696 know (oP
->num_ops
== 1);
697 get_cdisp (args
[1], "CTRL", oP
->opcode
, 24, 0, 1);
700 BAD_CASE (oP
->format
);
704 } /* md_assemble() */
706 /*****************************************************************************
707 md_number_to_chars: convert a number to target byte order
709 *************************************************************************** */
711 md_number_to_chars (buf
, value
, n
)
716 number_to_chars_littleendian (buf
, value
, n
);
719 /*****************************************************************************
720 md_chars_to_number: convert from target byte order to host byte order.
722 *************************************************************************** */
724 md_chars_to_number (val
, n
)
725 unsigned char *val
; /* Value in target byte order */
726 int n
; /* Number of bytes in the input */
730 for (retval
= 0; n
--;)
739 #define MAX_LITTLENUMS 6
740 #define LNUM_SIZE sizeof(LITTLENUM_TYPE)
742 /*****************************************************************************
743 md_atof: convert ascii to floating point
745 Turn a string at input_line_pointer into a floating point constant of type
746 'type', and store the appropriate bytes at *litP. The number of LITTLENUMS
747 emitted is returned at 'sizeP'. An error message is returned, or a pointer
748 to an empty message if OK.
750 Note we call the i386 floating point routine, rather than complicating
751 things with more files or symbolic links.
753 *************************************************************************** */
755 md_atof (type
, litP
, sizeP
)
760 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
761 LITTLENUM_TYPE
*wordP
;
781 type
= 'x'; /* That's what atof_ieee() understands */
786 return _("Bad call to md_atof()");
789 t
= atof_ieee (input_line_pointer
, type
, words
);
792 input_line_pointer
= t
;
795 *sizeP
= prec
* LNUM_SIZE
;
797 /* Output the LITTLENUMs in REVERSE order in accord with i80960
798 word-order. (Dunno why atof_ieee doesn't do it in the right
799 order in the first place -- probably because it's a hack of
802 for (wordP
= words
+ prec
- 1; prec
--;)
804 md_number_to_chars (litP
, (long) (*wordP
--), LNUM_SIZE
);
805 litP
+= sizeof (LITTLENUM_TYPE
);
812 /*****************************************************************************
815 *************************************************************************** */
817 md_number_to_imm (buf
, val
, n
)
822 md_number_to_chars (buf
, val
, n
);
826 /*****************************************************************************
829 *************************************************************************** */
831 md_number_to_disp (buf
, val
, n
)
836 md_number_to_chars (buf
, val
, n
);
839 /*****************************************************************************
842 Stick a value (an address fixup) into a bit field of
843 previously-generated instruction.
845 *************************************************************************** */
847 md_number_to_field (instrP
, val
, bfixP
)
848 char *instrP
; /* Pointer to instruction to be fixed */
849 long val
; /* Address fixup value */
850 bit_fixS
*bfixP
; /* Description of bit field to be fixed up */
852 int numbits
; /* Length of bit field to be fixed */
853 long instr
; /* 32-bit instruction to be fixed-up */
854 long sign
; /* 0 or -1, according to sign bit of 'val' */
856 /* Convert instruction back to host byte order. */
857 instr
= md_chars_to_number (instrP
, 4);
859 /* Surprise! -- we stored the number of bits to be modified rather
860 than a pointer to a structure. */
861 numbits
= (int) bfixP
;
864 /* This is a no-op, stuck here by reloc_callj() */
868 know ((numbits
== 13) || (numbits
== 24));
870 /* Propagate sign bit of 'val' for the given number of bits. Result
871 should be all 0 or all 1. */
872 sign
= val
>> ((int) numbits
- 1);
873 if (((val
< 0) && (sign
!= -1))
874 || ((val
> 0) && (sign
!= 0)))
876 as_bad (_("Fixup of %ld too large for field width of %d"),
881 /* Put bit field into instruction and write back in target
884 val
&= ~(-1 << (int) numbits
); /* Clear unused sign bits */
886 md_number_to_chars (instrP
, instr
, 4);
888 } /* md_number_to_field() */
891 /*****************************************************************************
893 Invocation line includes a switch not recognized by the base assembler.
894 See if it's a processor-specific option. For the 960, these are:
897 Conditional branch instructions that require displacements
898 greater than 13 bits (or that have external targets) should
899 generate errors. The default is to replace each such
900 instruction with the corresponding compare (or chkbit) and
901 branch instructions. Note that the Intel "j" cobr directives
902 are ALWAYS "de-optimized" in this way when necessary,
903 regardless of the setting of this option.
906 Add code to collect information about branches taken, for
907 later optimization of branch prediction bits by a separate
908 tool. COBR and CNTL format instructions have branch
909 prediction bits (in the CX architecture); if "BR" represents
910 an instruction in one of these classes, the following rep-
911 resents the code generated by the assembler:
913 call <increment routine>
914 .word 0 # pre-counter
916 call <increment routine>
917 .word 0 # post-counter
919 A table of all such "Labels" is also generated.
922 -AKA, -AKB, -AKC, -ASA, -ASB, -AMC, -ACA:
923 Select the 80960 architecture. Instructions or features not
924 supported by the selected architecture cause fatal errors.
925 The default is to generate code for any instruction or feature
926 that is supported by SOME version of the 960 (even if this
927 means mixing architectures!).
929 ****************************************************************************/
931 CONST
char *md_shortopts
= "A:b";
932 struct option md_longopts
[] =
934 #define OPTION_LINKRELAX (OPTION_MD_BASE)
935 {"linkrelax", no_argument
, NULL
, OPTION_LINKRELAX
},
936 {"link-relax", no_argument
, NULL
, OPTION_LINKRELAX
},
937 #define OPTION_NORELAX (OPTION_MD_BASE + 1)
938 {"norelax", no_argument
, NULL
, OPTION_NORELAX
},
939 {"no-relax", no_argument
, NULL
, OPTION_NORELAX
},
940 {NULL
, no_argument
, NULL
, 0}
942 size_t md_longopts_size
= sizeof (md_longopts
);
949 static const struct tabentry arch_tab
[] =
953 {"SA", ARCH_KA
}, /* Synonym for KA */
954 {"SB", ARCH_KB
}, /* Synonym for KB */
955 {"KC", ARCH_MC
}, /* Synonym for MC */
964 md_parse_option (c
, arg
)
970 case OPTION_LINKRELAX
:
972 flag_keep_locals
= 1;
980 instrument_branches
= 1;
985 const struct tabentry
*tp
;
988 for (tp
= arch_tab
; tp
->flag
!= NULL
; tp
++)
989 if (!strcmp (p
, tp
->flag
))
992 if (tp
->flag
== NULL
)
994 as_bad (_("invalid architecture %s"), p
);
998 architecture
= tp
->arch
;
1010 md_show_usage (stream
)
1014 fprintf (stream
, _("I960 options:\n"));
1015 for (i
= 0; arch_tab
[i
].flag
; i
++)
1016 fprintf (stream
, "%s-A%s", i
? " | " : "", arch_tab
[i
].flag
);
1017 fprintf (stream
, _("\n\
1018 specify variant of 960 architecture\n\
1019 -b add code to collect statistics about branches taken\n\
1020 -link-relax preserve individual alignment directives so linker\n\
1021 can do relaxing (b.out format only)\n\
1022 -no-relax don't alter compare-and-branch instructions for\n\
1023 long displacements\n"));
1027 /*****************************************************************************
1029 Called by base assembler after address relaxation is finished: modify
1030 variable fragments according to how much relaxation was done.
1032 If the fragment substate is still 1, a 13-bit displacement was enough
1033 to reach the symbol in question. Set up an address fixup, but otherwise
1034 leave the cobr instruction alone.
1036 If the fragment substate is 2, a 13-bit displacement was not enough.
1037 Replace the cobr with a two instructions (a compare and a branch).
1039 *************************************************************************** */
1040 #ifndef BFD_ASSEMBLER
1042 md_convert_frag (headers
, seg
, fragP
)
1043 object_headers
*headers
;
1048 md_convert_frag (abfd
, sec
, fragP
)
1054 fixS
*fixP
; /* Structure describing needed address fix */
1056 switch (fragP
->fr_subtype
)
1059 /* LEAVE SINGLE COBR INSTRUCTION */
1060 fixP
= fix_new (fragP
,
1061 fragP
->fr_opcode
- fragP
->fr_literal
,
1068 fixP
->fx_bit_fixP
= (bit_fixS
*) 13; /* size of bit field */
1071 /* REPLACE COBR WITH COMPARE/BRANCH INSTRUCTIONS */
1075 BAD_CASE (fragP
->fr_subtype
);
1080 /*****************************************************************************
1081 md_estimate_size_before_relax: How much does it look like *fragP will grow?
1083 Called by base assembler just before address relaxation.
1084 Return the amount by which the fragment will grow.
1086 Any symbol that is now undefined will not become defined; cobr's
1087 based on undefined symbols will have to be replaced with a compare
1088 instruction and a branch instruction, and the code fragment will grow
1091 *************************************************************************** */
1093 md_estimate_size_before_relax (fragP
, segment_type
)
1094 register fragS
*fragP
;
1095 register segT segment_type
;
1097 /* If symbol is undefined in this segment, go to "relaxed" state
1098 (compare and branch instructions instead of cobr) right now. */
1099 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment_type
)
1105 } /* md_estimate_size_before_relax() */
1107 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1109 /*****************************************************************************
1111 This routine exists in order to overcome machine byte-order problems
1112 when dealing with bit-field entries in the relocation_info struct.
1114 But relocation info will be used on the host machine only (only
1115 executable code is actually downloaded to the i80960). Therefore,
1116 we leave it in host byte order.
1118 The above comment is no longer true. This routine now really
1119 does do the reordering (Ian Taylor 28 Aug 92).
1121 *************************************************************************** */
1124 md_ri_to_chars (where
, ri
)
1126 struct relocation_info
*ri
;
1128 md_number_to_chars (where
, ri
->r_address
,
1129 sizeof (ri
->r_address
));
1130 where
[4] = ri
->r_index
& 0x0ff;
1131 where
[5] = (ri
->r_index
>> 8) & 0x0ff;
1132 where
[6] = (ri
->r_index
>> 16) & 0x0ff;
1133 where
[7] = ((ri
->r_pcrel
<< 0)
1134 | (ri
->r_length
<< 1)
1135 | (ri
->r_extern
<< 3)
1138 | (ri
->r_callj
<< 6));
1141 #endif /* defined(OBJ_AOUT) | defined(OBJ_BOUT) */
1144 /* FOLLOWING ARE THE LOCAL ROUTINES, IN ALPHABETICAL ORDER */
1146 /*****************************************************************************
1147 brcnt_emit: Emit code to increment inline branch counter.
1149 See the comments above the declaration of 'br_cnt' for details on
1150 branch-prediction instrumentation.
1151 *************************************************************************** */
1155 ctrl_fmt (BR_CNT_FUNC
, CALL
, 1); /* Emit call to "increment" routine */
1156 emit (0); /* Emit inline counter to be incremented */
1159 /*****************************************************************************
1160 brlab_next: generate the next branch local label
1162 See the comments above the declaration of 'br_cnt' for details on
1163 branch-prediction instrumentation.
1164 *************************************************************************** */
1168 static char buf
[20];
1170 sprintf (buf
, "%s%d", BR_LABEL_BASE
, br_cnt
++);
1174 /*****************************************************************************
1175 brtab_emit: generate the fetch-prediction branch table.
1177 See the comments above the declaration of 'br_cnt' for details on
1178 branch-prediction instrumentation.
1180 The code emitted here would be functionally equivalent to the following
1181 example assembler source.
1186 .word 0 # link to next table
1187 .word 3 # length of table
1188 .word LBRANCH0 # 1st entry in table proper
1191 **************************************************************************** */
1197 char *p
; /* Where the binary was output to */
1198 /* Pointer to description of deferred address fixup. */
1201 if (!instrument_branches
)
1206 subseg_set (data_section
, 0); /* .data */
1207 frag_align (2, 0, 0); /* .align 2 */
1208 record_alignment (now_seg
, 2);
1209 colon (BR_TAB_NAME
); /* BR_TAB_NAME: */
1210 emit (0); /* .word 0 #link to next table */
1211 emit (br_cnt
); /* .word n #length of table */
1213 for (i
= 0; i
< br_cnt
; i
++)
1215 sprintf (buf
, "%s%d", BR_LABEL_BASE
, i
);
1217 fixP
= fix_new (frag_now
,
1218 p
- frag_now
->fr_literal
,
1227 /*****************************************************************************
1228 cobr_fmt: generate a COBR-format instruction
1230 *************************************************************************** */
1233 cobr_fmt (arg
, opcode
, oP
)
1234 /* arg[0]->opcode mnemonic, arg[1-3]->operands (ascii) */
1236 /* Opcode, with branch-prediction bits already set if necessary. */
1238 /* Pointer to description of instruction. */
1239 struct i960_opcode
*oP
;
1241 long instr
; /* 32-bit instruction */
1242 struct regop regop
; /* Description of register operand */
1243 int n
; /* Number of operands */
1244 int var_frag
; /* 1 if varying length code fragment should
1245 * be emitted; 0 if an address fix
1246 * should be emitted.
1254 /* First operand (if any) of a COBR is always a register
1255 operand. Parse it. */
1256 parse_regop (®op
, arg
[1], oP
->operand
[0]);
1257 instr
|= (regop
.n
<< 19) | (regop
.mode
<< 13);
1261 /* Second operand (if any) of a COBR is always a register
1262 operand. Parse it. */
1263 parse_regop (®op
, arg
[2], oP
->operand
[1]);
1264 instr
|= (regop
.n
<< 14) | regop
.special
;
1275 if (instrument_branches
)
1278 colon (brlab_next ());
1281 /* A third operand to a COBR is always a displacement. Parse
1282 it; if it's relaxable (a cobr "j" directive, or any cobr
1283 other than bbs/bbc when the "-norelax" option is not in use)
1284 set up a variable code fragment; otherwise set up an address
1286 var_frag
= !norelax
|| (oP
->format
== COJ
); /* TRUE or FALSE */
1287 get_cdisp (arg
[3], "COBR", instr
, 13, var_frag
, 0);
1289 if (instrument_branches
)
1297 /*****************************************************************************
1298 ctrl_fmt: generate a CTRL-format instruction
1300 *************************************************************************** */
1303 ctrl_fmt (targP
, opcode
, num_ops
)
1304 char *targP
; /* Pointer to text of lone operand (if any) */
1305 long opcode
; /* Template of instruction */
1306 int num_ops
; /* Number of operands */
1308 int instrument
; /* TRUE iff we should add instrumentation to track
1309 * how often the branch is taken
1315 emit (opcode
); /* Output opcode */
1320 instrument
= instrument_branches
&& (opcode
!= CALL
)
1321 && (opcode
!= B
) && (opcode
!= RET
) && (opcode
!= BAL
);
1326 colon (brlab_next ());
1329 /* The operand MUST be an ip-relative displacment. Parse it
1330 * and set up address fix for the instruction we just output.
1332 get_cdisp (targP
, "CTRL", opcode
, 24, 0, 0);
1343 /*****************************************************************************
1344 emit: output instruction binary
1346 Output instruction binary, in target byte order, 4 bytes at a time.
1347 Return pointer to where it was placed.
1349 *************************************************************************** */
1353 long instr
; /* Word to be output, host byte order */
1355 char *toP
; /* Where to output it */
1357 toP
= frag_more (4); /* Allocate storage */
1358 md_number_to_chars (toP
, instr
, 4); /* Convert to target byte order */
1363 /*****************************************************************************
1364 get_args: break individual arguments out of comma-separated list
1367 - all comments and labels have been removed
1368 - all strings of whitespace have been collapsed to a single blank.
1369 - all character constants ('x') have been replaced with decimal
1372 args[0] is untouched. args[1] points to first operand, etc. All args:
1373 - are NULL-terminated
1374 - contain no whitespace
1377 Number of operands (0,1,2, or 3) or -1 on error.
1379 *************************************************************************** */
1382 /* Pointer to comma-separated operands; MUCKED BY US */
1384 /* Output arg: pointers to operands placed in args[1-3]. MUST
1385 ACCOMMODATE 4 ENTRIES (args[0-3]). */
1388 register int n
; /* Number of operands */
1391 /* Skip lead white space */
1405 /* Squeze blanks out by moving non-blanks toward start of string.
1406 * Isolate operands, whenever comma is found.
1413 && (! isalnum ((unsigned char) p
[1])
1414 || ! isalnum ((unsigned char) p
[-1])))
1422 /* Start of operand */
1425 as_bad (_("too many operands"));
1428 *to
++ = '\0'; /* Terminate argument */
1429 args
[++n
] = to
; /* Start next argument */
1443 /*****************************************************************************
1444 get_cdisp: handle displacement for a COBR or CTRL instruction.
1446 Parse displacement for a COBR or CTRL instruction.
1448 If successful, output the instruction opcode and set up for it,
1449 depending on the arg 'var_frag', either:
1450 o an address fixup to be done when all symbol values are known, or
1451 o a varying length code fragment, with address fixup info. This
1452 will be done for cobr instructions that may have to be relaxed
1453 in to compare/branch instructions (8 bytes) if the final
1454 address displacement is greater than 13 bits.
1456 ****************************************************************************/
1459 get_cdisp (dispP
, ifmtP
, instr
, numbits
, var_frag
, callj
)
1460 /* displacement as specified in source instruction */
1462 /* "COBR" or "CTRL" (for use in error message) */
1464 /* Instruction needing the displacement */
1466 /* # bits of displacement (13 for COBR, 24 for CTRL) */
1468 /* 1 if varying length code fragment should be emitted;
1469 * 0 if an address fix should be emitted.
1472 /* 1 if callj relocation should be done; else 0 */
1475 expressionS e
; /* Parsed expression */
1476 fixS
*fixP
; /* Structure describing needed address fix */
1477 char *outP
; /* Where instruction binary is output to */
1481 parse_expr (dispP
, &e
);
1485 as_bad (_("expression syntax error"));
1488 if (S_GET_SEGMENT (e
.X_add_symbol
) == now_seg
1489 || S_GET_SEGMENT (e
.X_add_symbol
) == undefined_section
)
1493 outP
= frag_more (8); /* Allocate worst-case storage */
1494 md_number_to_chars (outP
, instr
, 4);
1495 frag_variant (rs_machine_dependent
, 4, 4, 1,
1496 adds (e
), offs (e
), outP
);
1500 /* Set up a new fix structure, so address can be updated
1501 * when all symbol values are known.
1503 outP
= emit (instr
);
1504 fixP
= fix_new (frag_now
,
1505 outP
- frag_now
->fr_literal
,
1512 fixP
->fx_tcbit
= callj
;
1514 /* We want to modify a bit field when the address is
1515 * known. But we don't need all the garbage in the
1516 * bit_fix structure. So we're going to lie and store
1517 * the number of bits affected instead of a pointer.
1519 fixP
->fx_bit_fixP
= (bit_fixS
*) numbits
;
1523 as_bad (_("attempt to branch into different segment"));
1527 as_bad (_("target of %s instruction must be a label"), ifmtP
);
1533 /*****************************************************************************
1534 get_ispec: parse a memory operand for an index specification
1536 Here, an "index specification" is taken to be anything surrounded
1537 by square brackets and NOT followed by anything else.
1539 If it's found, detach it from the input string, remove the surrounding
1540 square brackets, and return a pointer to it. Otherwise, return NULL.
1542 *************************************************************************** */
1546 /* Pointer to memory operand from source instruction, no white space. */
1549 /* Points to start of index specification. */
1551 /* Points to end of index specification. */
1554 /* Find opening square bracket, if any. */
1555 start
= strchr (textP
, '[');
1560 /* Eliminate '[', detach from rest of operand */
1563 end
= strchr (start
, ']');
1567 as_bad (_("unmatched '['"));
1572 /* Eliminate ']' and make sure it was the last thing
1576 if (*(end
+ 1) != '\0')
1578 as_bad (_("garbage after index spec ignored"));
1585 /*****************************************************************************
1588 Look up a (suspected) register name in the register table and return the
1589 associated register number (or -1 if not found).
1591 *************************************************************************** */
1594 get_regnum (regname
)
1595 char *regname
; /* Suspected register name */
1599 rP
= (int *) hash_find (reg_hash
, regname
);
1600 return (rP
== NULL
) ? -1 : *rP
;
1604 /*****************************************************************************
1605 i_scan: perform lexical scan of ascii assembler instruction.
1608 - input string is an i80960 instruction (not a pseudo-op)
1609 - all comments and labels have been removed
1610 - all strings of whitespace have been collapsed to a single blank.
1613 args[0] points to opcode, other entries point to operands. All strings:
1614 - are NULL-terminated
1615 - contain no whitespace
1616 - have character constants ('x') replaced with a decimal number
1619 Number of operands (0,1,2, or 3) or -1 on error.
1621 *************************************************************************** */
1624 /* Pointer to ascii instruction; MUCKED BY US. */
1626 /* Output arg: pointers to opcode and operands placed here. MUST
1627 ACCOMMODATE 4 ENTRIES. */
1631 /* Isolate opcode */
1635 } /* Skip lead space, if any */
1637 for (; *iP
!= ' '; iP
++)
1641 /* There are no operands */
1644 /* We never moved: there was no opcode either! */
1645 as_bad (_("missing opcode"));
1651 *iP
++ = '\0'; /* Terminate opcode */
1652 return (get_args (iP
, args
));
1656 /*****************************************************************************
1657 mem_fmt: generate a MEMA- or MEMB-format instruction
1659 *************************************************************************** */
1661 mem_fmt (args
, oP
, callx
)
1662 char *args
[]; /* args[0]->opcode mnemonic, args[1-3]->operands */
1663 struct i960_opcode
*oP
; /* Pointer to description of instruction */
1664 int callx
; /* Is this a callx opcode */
1666 int i
; /* Loop counter */
1667 struct regop regop
; /* Description of register operand */
1668 char opdesc
; /* Operand descriptor byte */
1669 memS instr
; /* Description of binary to be output */
1670 char *outP
; /* Where the binary was output to */
1671 expressionS expr
; /* Parsed expression */
1672 /* ->description of deferred address fixup */
1676 /* COFF support isn't in place yet for callx relaxing. */
1680 memset (&instr
, '\0', sizeof (memS
));
1681 instr
.opcode
= oP
->opcode
;
1683 /* Process operands. */
1684 for (i
= 1; i
<= oP
->num_ops
; i
++)
1686 opdesc
= oP
->operand
[i
- 1];
1690 parse_memop (&instr
, args
[i
], oP
->format
);
1694 parse_regop (®op
, args
[i
], opdesc
);
1695 instr
.opcode
|= regop
.n
<< 19;
1699 /* Parse the displacement; this must be done before emitting the
1700 opcode, in case it is an expression using `.'. */
1701 parse_expr (instr
.e
, &expr
);
1704 outP
= emit (instr
.opcode
);
1706 if (instr
.disp
== 0)
1711 /* Process the displacement */
1715 as_bad (_("expression syntax error"));
1719 if (instr
.disp
== 32)
1721 (void) emit (offs (expr
)); /* Output displacement */
1725 /* 12-bit displacement */
1726 if (offs (expr
) & ~0xfff)
1728 /* Won't fit in 12 bits: convert already-output
1729 * instruction to MEMB format, output
1732 mema_to_memb (outP
);
1733 (void) emit (offs (expr
));
1737 /* WILL fit in 12 bits: OR into opcode and
1738 * overwrite the binary we already put out
1740 instr
.opcode
|= offs (expr
);
1741 md_number_to_chars (outP
, instr
.opcode
, 4);
1747 if (instr
.disp
== 12)
1749 /* Displacement is dependent on a symbol, whose value
1750 * may change at link time. We HAVE to reserve 32 bits.
1751 * Convert already-output opcode to MEMB format.
1753 mema_to_memb (outP
);
1756 /* Output 0 displacement and set up address fixup for when
1757 * this symbol's value becomes known.
1759 outP
= emit ((long) 0);
1760 fixP
= fix_new_exp (frag_now
,
1761 outP
- frag_now
->fr_literal
,
1766 /* Steve's linker relaxing hack. Mark this 32-bit relocation as
1767 being in the instruction stream, specifically as part of a callx
1769 fixP
->fx_bsr
= callx
;
1775 /*****************************************************************************
1776 mema_to_memb: convert a MEMA-format opcode to a MEMB-format opcode.
1778 There are 2 possible MEMA formats:
1780 - displacement + abase
1782 They are distinguished by the setting of the MEMA_ABASE bit.
1784 *************************************************************************** */
1786 mema_to_memb (opcodeP
)
1787 char *opcodeP
; /* Where to find the opcode, in target byte order */
1789 long opcode
; /* Opcode in host byte order */
1790 long mode
; /* Mode bits for MEMB instruction */
1792 opcode
= md_chars_to_number (opcodeP
, 4);
1793 know (!(opcode
& MEMB_BIT
));
1795 mode
= MEMB_BIT
| D_BIT
;
1796 if (opcode
& MEMA_ABASE
)
1801 opcode
&= 0xffffc000; /* Clear MEMA offset and mode bits */
1802 opcode
|= mode
; /* Set MEMB mode bits */
1804 md_number_to_chars (opcodeP
, opcode
, 4);
1805 } /* mema_to_memb() */
1808 /*****************************************************************************
1809 parse_expr: parse an expression
1811 Use base assembler's expression parser to parse an expression.
1812 It, unfortunately, runs off a global which we have to save/restore
1813 in order to make it work for us.
1815 An empty expression string is treated as an absolute 0.
1817 Sets O_illegal regardless of expression evaluation if entire input
1818 string is not consumed in the evaluation -- tolerate no dangling junk!
1820 *************************************************************************** */
1822 parse_expr (textP
, expP
)
1823 char *textP
; /* Text of expression to be parsed */
1824 expressionS
*expP
; /* Where to put the results of parsing */
1826 char *save_in
; /* Save global here */
1833 /* Treat empty string as absolute 0 */
1834 expP
->X_add_symbol
= expP
->X_op_symbol
= NULL
;
1835 expP
->X_add_number
= 0;
1836 expP
->X_op
= O_constant
;
1840 save_in
= input_line_pointer
; /* Save global */
1841 input_line_pointer
= textP
; /* Make parser work for us */
1843 (void) expression (expP
);
1844 if ((size_t) (input_line_pointer
- textP
) != strlen (textP
))
1846 /* Did not consume all of the input */
1847 expP
->X_op
= O_illegal
;
1849 symP
= expP
->X_add_symbol
;
1850 if (symP
&& (hash_find (reg_hash
, S_GET_NAME (symP
))))
1852 /* Register name in an expression */
1853 /* FIXME: this isn't much of a check any more. */
1854 expP
->X_op
= O_illegal
;
1857 input_line_pointer
= save_in
; /* Restore global */
1862 /*****************************************************************************
1864 Parse and replace a 'ldconst' pseudo-instruction with an appropriate
1867 Assumes the input consists of:
1868 arg[0] opcode mnemonic ('ldconst')
1869 arg[1] first operand (constant)
1870 arg[2] name of register to be loaded
1872 Replaces opcode and/or operands as appropriate.
1874 Returns the new number of arguments, or -1 on failure.
1876 *************************************************************************** */
1880 char *arg
[]; /* See above */
1882 int n
; /* Constant to be loaded */
1883 int shift
; /* Shift count for "shlo" instruction */
1884 static char buf
[5]; /* Literal for first operand */
1885 static char buf2
[5]; /* Literal for second operand */
1886 expressionS e
; /* Parsed expression */
1889 arg
[3] = NULL
; /* So we can tell at the end if it got used or not */
1891 parse_expr (arg
[1], &e
);
1895 /* We're dependent on one or more symbols -- use "lda" */
1900 /* Try the following mappings:
1901 * ldconst 0,<reg> ->mov 0,<reg>
1902 * ldconst 31,<reg> ->mov 31,<reg>
1903 * ldconst 32,<reg> ->addo 1,31,<reg>
1904 * ldconst 62,<reg> ->addo 31,31,<reg>
1905 * ldconst 64,<reg> ->shlo 8,3,<reg>
1906 * ldconst -1,<reg> ->subo 1,0,<reg>
1907 * ldconst -31,<reg>->subo 31,0,<reg>
1909 * anthing else becomes:
1913 if ((0 <= n
) && (n
<= 31))
1918 else if ((-31 <= n
) && (n
<= -1))
1922 sprintf (buf
, "%d", -n
);
1927 else if ((32 <= n
) && (n
<= 62))
1932 sprintf (buf
, "%d", n
- 31);
1936 else if ((shift
= shift_ok (n
)) != 0)
1940 sprintf (buf
, "%d", shift
);
1942 sprintf (buf2
, "%d", n
>> shift
);
1953 as_bad (_("invalid constant"));
1957 return (arg
[3] == 0) ? 2 : 3;
1960 /*****************************************************************************
1961 parse_memop: parse a memory operand
1963 This routine is based on the observation that the 4 mode bits of the
1964 MEMB format, taken individually, have fairly consistent meaning:
1966 M3 (bit 13): 1 if displacement is present (D_BIT)
1967 M2 (bit 12): 1 for MEMB instructions (MEMB_BIT)
1968 M1 (bit 11): 1 if index is present (I_BIT)
1969 M0 (bit 10): 1 if abase is present (A_BIT)
1971 So we parse the memory operand and set bits in the mode as we find
1972 things. Then at the end, if we go to MEMB format, we need only set
1973 the MEMB bit (M2) and our mode is built for us.
1975 Unfortunately, I said "fairly consistent". The exceptions:
1978 0100 Would seem illegal, but means "abase-only".
1980 0101 Would seem to mean "abase-only" -- it means IP-relative.
1981 Must be converted to 0100.
1983 0110 Would seem to mean "index-only", but is reserved.
1984 We turn on the D bit and provide a 0 displacement.
1986 The other thing to observe is that we parse from the right, peeling
1987 things * off as we go: first any index spec, then any abase, then
1990 *************************************************************************** */
1993 parse_memop (memP
, argP
, optype
)
1994 memS
*memP
; /* Where to put the results */
1995 char *argP
; /* Text of the operand to be parsed */
1996 int optype
; /* MEM1, MEM2, MEM4, MEM8, MEM12, or MEM16 */
1998 char *indexP
; /* Pointer to index specification with "[]" removed */
1999 char *p
; /* Temp char pointer */
2000 char iprel_flag
; /* True if this is an IP-relative operand */
2001 int regnum
; /* Register number */
2002 /* Scale factor: 1,2,4,8, or 16. Later converted to internal format
2003 (0,1,2,3,4 respectively). */
2005 int mode
; /* MEMB mode bits */
2006 int *intP
; /* Pointer to register number */
2008 /* The following table contains the default scale factors for each
2009 type of memory instruction. It is accessed using (optype-MEM1)
2010 as an index -- thus it assumes the 'optype' constants are
2011 assigned consecutive values, in the order they appear in this
2013 static const int def_scale
[] =
2019 -1, /* MEM12 -- no valid default */
2024 iprel_flag
= mode
= 0;
2026 /* Any index present? */
2027 indexP
= get_ispec (argP
);
2030 p
= strchr (indexP
, '*');
2033 /* No explicit scale -- use default for this instruction
2034 type and assembler mode. */
2038 /* GNU960 compatibility */
2039 scale
= def_scale
[optype
- MEM1
];
2043 *p
++ = '\0'; /* Eliminate '*' */
2045 /* Now indexP->a '\0'-terminated register name,
2046 * and p->a scale factor.
2049 if (!strcmp (p
, "16"))
2053 else if (strchr ("1248", *p
) && (p
[1] == '\0'))
2063 regnum
= get_regnum (indexP
); /* Get index reg. # */
2064 if (!IS_RG_REG (regnum
))
2066 as_bad (_("invalid index register"));
2070 /* Convert scale to its binary encoding */
2089 as_bad (_("invalid scale factor"));
2093 memP
->opcode
|= scale
| regnum
; /* Set index bits in opcode */
2094 mode
|= I_BIT
; /* Found a valid index spec */
2097 /* Any abase (Register Indirect) specification present? */
2098 if ((p
= strrchr (argP
, '(')) != NULL
)
2100 /* "(" is there -- does it start a legal abase spec? If not, it
2101 could be part of a displacement expression. */
2102 intP
= (int *) hash_find (areg_hash
, p
);
2105 /* Got an abase here */
2107 *p
= '\0'; /* discard register spec */
2108 if (regnum
== IPREL
)
2110 /* We have to specialcase ip-rel mode */
2115 memP
->opcode
|= regnum
<< 14;
2121 /* Any expression present? */
2128 /* Special-case ip-relative addressing */
2137 memP
->opcode
|= 5 << 10; /* IP-relative mode */
2143 /* Handle all other modes */
2147 /* Go with MEMA instruction format for now (grow to MEMB later
2148 if 12 bits is not enough for the displacement). MEMA format
2149 has a single mode bit: set it to indicate that abase is
2151 memP
->opcode
|= MEMA_ABASE
;
2156 /* Go with MEMA instruction format for now (grow to MEMB later
2157 if 12 bits is not enough for the displacement). */
2162 /* For some reason, the bit string for this mode is not
2163 consistent: it should be 0 (exclusive of the MEMB bit), so we
2164 set it "by hand" here. */
2165 memP
->opcode
|= MEMB_BIT
;
2169 /* set MEMB bit in mode, and OR in mode bits */
2170 memP
->opcode
|= mode
| MEMB_BIT
;
2174 /* Treat missing displacement as displacement of 0. */
2176 /* Fall into next case. */
2177 case D_BIT
| A_BIT
| I_BIT
:
2179 /* set MEMB bit in mode, and OR in mode bits */
2180 memP
->opcode
|= mode
| MEMB_BIT
;
2190 /*****************************************************************************
2191 parse_po: parse machine-dependent pseudo-op
2193 This is a top-level routine for machine-dependent pseudo-ops. It slurps
2194 up the rest of the input line, breaks out the individual arguments,
2195 and dispatches them to the correct handler.
2196 *************************************************************************** */
2200 int po_num
; /* Pseudo-op number: currently S_LEAFPROC or S_SYSPROC */
2202 /* Pointers operands, with no embedded whitespace.
2203 arg[0] unused, arg[1-3]->operands */
2205 int n_ops
; /* Number of operands */
2206 char *p
; /* Pointer to beginning of unparsed argument string */
2207 char eol
; /* Character that indicated end of line */
2209 extern char is_end_of_line
[];
2211 /* Advance input pointer to end of line. */
2212 p
= input_line_pointer
;
2213 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2215 input_line_pointer
++;
2217 eol
= *input_line_pointer
; /* Save end-of-line char */
2218 *input_line_pointer
= '\0'; /* Terminate argument list */
2220 /* Parse out operands */
2221 n_ops
= get_args (p
, args
);
2227 /* Dispatch to correct handler */
2231 s_sysproc (n_ops
, args
);
2234 s_leafproc (n_ops
, args
);
2241 /* Restore eol, so line numbers get updated correctly. Base
2242 assembler assumes we leave input pointer pointing at char
2243 following the eol. */
2244 *input_line_pointer
++ = eol
;
2247 /*****************************************************************************
2248 parse_regop: parse a register operand.
2250 In case of illegal operand, issue a message and return some valid
2251 information so instruction processing can continue.
2252 *************************************************************************** */
2255 parse_regop (regopP
, optext
, opdesc
)
2256 struct regop
*regopP
; /* Where to put description of register operand */
2257 char *optext
; /* Text of operand */
2258 char opdesc
; /* Descriptor byte: what's legal for this operand */
2260 int n
; /* Register number */
2261 expressionS e
; /* Parsed expression */
2263 /* See if operand is a register */
2264 n
= get_regnum (optext
);
2269 /* global or local register */
2270 if (!REG_ALIGN (opdesc
, n
))
2272 as_bad (_("unaligned register"));
2276 regopP
->special
= 0;
2279 else if (IS_FP_REG (n
) && FP_OK (opdesc
))
2281 /* Floating point register, and it's allowed */
2282 regopP
->n
= n
- FP0
;
2284 regopP
->special
= 0;
2287 else if (IS_SF_REG (n
) && SFR_OK (opdesc
))
2289 /* Special-function register, and it's allowed */
2290 regopP
->n
= n
- SF0
;
2292 regopP
->special
= 1;
2293 if (!targ_has_sfr (regopP
->n
))
2295 as_bad (_("no such sfr in this architecture"));
2300 else if (LIT_OK (opdesc
))
2302 /* How about a literal? */
2304 regopP
->special
= 0;
2306 { /* floating point literal acceptable */
2307 /* Skip over 0f, 0d, or 0e prefix */
2308 if ((optext
[0] == '0')
2309 && (optext
[1] >= 'd')
2310 && (optext
[1] <= 'f'))
2315 if (!strcmp (optext
, "0.0") || !strcmp (optext
, "0"))
2320 if (!strcmp (optext
, "1.0") || !strcmp (optext
, "1"))
2328 { /* fixed point literal acceptable */
2329 parse_expr (optext
, &e
);
2330 if (e
.X_op
!= O_constant
2331 || (offs (e
) < 0) || (offs (e
) > 31))
2333 as_bad (_("illegal literal"));
2336 regopP
->n
= offs (e
);
2341 /* Nothing worked */
2343 regopP
->mode
= 0; /* Register r0 is always a good one */
2345 regopP
->special
= 0;
2346 } /* parse_regop() */
2348 /*****************************************************************************
2349 reg_fmt: generate a REG-format instruction
2351 *************************************************************************** */
2354 char *args
[]; /* args[0]->opcode mnemonic, args[1-3]->operands */
2355 struct i960_opcode
*oP
; /* Pointer to description of instruction */
2357 long instr
; /* Binary to be output */
2358 struct regop regop
; /* Description of register operand */
2359 int n_ops
; /* Number of operands */
2363 n_ops
= oP
->num_ops
;
2367 parse_regop (®op
, args
[1], oP
->operand
[0]);
2369 if ((n_ops
== 1) && !(instr
& M3
))
2371 /* 1-operand instruction in which the dst field should
2372 * be used (instead of src1).
2377 regop
.mode
= regop
.special
;
2384 /* regop.n goes in bit 0, needs no shifting */
2386 regop
.special
<<= 5;
2388 instr
|= regop
.n
| regop
.mode
| regop
.special
;
2393 parse_regop (®op
, args
[2], oP
->operand
[1]);
2395 if ((n_ops
== 2) && !(instr
& M3
))
2397 /* 2-operand instruction in which the dst field should
2398 * be used instead of src2).
2403 regop
.mode
= regop
.special
;
2412 regop
.special
<<= 6;
2414 instr
|= regop
.n
| regop
.mode
| regop
.special
;
2418 parse_regop (®op
, args
[3], oP
->operand
[2]);
2421 regop
.mode
= regop
.special
;
2423 instr
|= (regop
.n
<<= 19) | (regop
.mode
<<= 13);
2429 /*****************************************************************************
2431 Replace cobr instruction in a code fragment with equivalent branch and
2432 compare instructions, so it can reach beyond a 13-bit displacement.
2433 Set up an address fix/relocation for the new branch instruction.
2435 *************************************************************************** */
2437 /* This "conditional jump" table maps cobr instructions into
2438 equivalent compare and branch opcodes. */
2447 { /* COBR OPCODE: */
2448 { CHKBIT
, BNO
}, /* 0x30 - bbc */
2449 { CMPO
, BG
}, /* 0x31 - cmpobg */
2450 { CMPO
, BE
}, /* 0x32 - cmpobe */
2451 { CMPO
, BGE
}, /* 0x33 - cmpobge */
2452 { CMPO
, BL
}, /* 0x34 - cmpobl */
2453 { CMPO
, BNE
}, /* 0x35 - cmpobne */
2454 { CMPO
, BLE
}, /* 0x36 - cmpoble */
2455 { CHKBIT
, BO
}, /* 0x37 - bbs */
2456 { CMPI
, BNO
}, /* 0x38 - cmpibno */
2457 { CMPI
, BG
}, /* 0x39 - cmpibg */
2458 { CMPI
, BE
}, /* 0x3a - cmpibe */
2459 { CMPI
, BGE
}, /* 0x3b - cmpibge */
2460 { CMPI
, BL
}, /* 0x3c - cmpibl */
2461 { CMPI
, BNE
}, /* 0x3d - cmpibne */
2462 { CMPI
, BLE
}, /* 0x3e - cmpible */
2463 { CMPI
, BO
}, /* 0x3f - cmpibo */
2469 register fragS
*fragP
; /* fragP->fr_opcode is assumed to point to
2470 * the cobr instruction, which comes at the
2471 * end of the code fragment.
2474 int opcode
, src1
, src2
, m1
, s2
;
2475 /* Bit fields from cobr instruction */
2476 long bp_bits
; /* Branch prediction bits from cobr instruction */
2477 long instr
; /* A single i960 instruction */
2478 /* ->instruction to be replaced */
2480 fixS
*fixP
; /* Relocation that can be done at assembly time */
2482 /* PICK UP & PARSE COBR INSTRUCTION */
2483 iP
= fragP
->fr_opcode
;
2484 instr
= md_chars_to_number (iP
, 4);
2485 opcode
= ((instr
>> 24) & 0xff) - 0x30; /* "-0x30" for table index */
2486 src1
= (instr
>> 19) & 0x1f;
2487 m1
= (instr
>> 13) & 1;
2489 src2
= (instr
>> 14) & 0x1f;
2490 bp_bits
= instr
& BP_MASK
;
2492 /* GENERATE AND OUTPUT COMPARE INSTRUCTION */
2493 instr
= coj
[opcode
].compare
2494 | src1
| (m1
<< 11) | (s2
<< 6) | (src2
<< 14);
2495 md_number_to_chars (iP
, instr
, 4);
2497 /* OUTPUT BRANCH INSTRUCTION */
2498 md_number_to_chars (iP
+ 4, coj
[opcode
].branch
| bp_bits
, 4);
2500 /* SET UP ADDRESS FIXUP/RELOCATION */
2501 fixP
= fix_new (fragP
,
2502 iP
+ 4 - fragP
->fr_literal
,
2509 fixP
->fx_bit_fixP
= (bit_fixS
*) 24; /* Store size of bit field */
2516 /*****************************************************************************
2517 reloc_callj: Relocate a 'callj' instruction
2519 This is a "non-(GNU)-standard" machine-dependent hook. The base
2520 assembler calls it when it decides it can relocate an address at
2521 assembly time instead of emitting a relocation directive.
2523 Check to see if the relocation involves a 'callj' instruction to a:
2524 sysproc: Replace the default 'call' instruction with a 'calls'
2525 leafproc: Replace the default 'call' instruction with a 'bal'.
2526 other proc: Do nothing.
2528 See b.out.h for details on the 'n_other' field in a symbol structure.
2531 Assumes the caller has already figured out, in the case of a leafproc,
2532 to use the 'bal' entry point, and has substituted that symbol into the
2533 passed fixup structure.
2535 *************************************************************************** */
2538 /* Relocation that can be done at assembly time */
2541 /* Points to the binary for the instruction being relocated. */
2544 if (!fixP
->fx_tcbit
)
2546 /* This wasn't a callj instruction in the first place */
2550 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2552 if (TC_S_IS_SYSPROC (fixP
->fx_addsy
))
2554 /* Symbol is a .sysproc: replace 'call' with 'calls'. System
2555 procedure number is (other-1). */
2556 md_number_to_chars (where
, CALLS
| TC_S_GET_SYSPROC (fixP
->fx_addsy
), 4);
2558 /* Nothing else needs to be done for this instruction. Make
2559 sure 'md_number_to_field()' will perform a no-op. */
2560 fixP
->fx_bit_fixP
= (bit_fixS
*) 1;
2563 else if (TC_S_IS_CALLNAME (fixP
->fx_addsy
))
2565 /* Should not happen: see block comment above */
2566 as_fatal (_("Trying to 'bal' to %s"), S_GET_NAME (fixP
->fx_addsy
));
2568 else if (TC_S_IS_BALNAME (fixP
->fx_addsy
))
2570 /* Replace 'call' with 'bal'; both instructions have the same
2571 format, so calling code should complete relocation as if
2572 nothing happened here. */
2573 md_number_to_chars (where
, BAL
, 4);
2575 else if (TC_S_IS_BADPROC (fixP
->fx_addsy
))
2577 as_bad (_("Looks like a proc, but can't tell what kind.\n"));
2578 } /* switch on proc type */
2580 /* else Symbol is neither a sysproc nor a leafproc */
2584 /*****************************************************************************
2585 s_leafproc: process .leafproc pseudo-op
2587 .leafproc takes two arguments, the second one is optional:
2588 arg[1]: name of 'call' entry point to leaf procedure
2589 arg[2]: name of 'bal' entry point to leaf procedure
2591 If the two arguments are identical, or if the second one is missing,
2592 the first argument is taken to be the 'bal' entry point.
2594 If there are 2 distinct arguments, we must make sure that the 'bal'
2595 entry point immediately follows the 'call' entry point in the linked
2598 *************************************************************************** */
2600 s_leafproc (n_ops
, args
)
2601 int n_ops
; /* Number of operands */
2602 char *args
[]; /* args[1]->1st operand, args[2]->2nd operand */
2604 symbolS
*callP
; /* Pointer to leafproc 'call' entry point symbol */
2605 symbolS
*balP
; /* Pointer to leafproc 'bal' entry point symbol */
2607 if ((n_ops
!= 1) && (n_ops
!= 2))
2609 as_bad (_("should have 1 or 2 operands"));
2611 } /* Check number of arguments */
2613 /* Find or create symbol for 'call' entry point. */
2614 callP
= symbol_find_or_make (args
[1]);
2616 if (TC_S_IS_CALLNAME (callP
))
2618 as_warn (_("Redefining leafproc %s"), S_GET_NAME (callP
));
2621 /* If that was the only argument, use it as the 'bal' entry point.
2622 * Otherwise, mark it as the 'call' entry point and find or create
2623 * another symbol for the 'bal' entry point.
2625 if ((n_ops
== 1) || !strcmp (args
[1], args
[2]))
2627 TC_S_FORCE_TO_BALNAME (callP
);
2632 TC_S_FORCE_TO_CALLNAME (callP
);
2634 balP
= symbol_find_or_make (args
[2]);
2635 if (TC_S_IS_CALLNAME (balP
))
2637 as_warn (_("Redefining leafproc %s"), S_GET_NAME (balP
));
2639 TC_S_FORCE_TO_BALNAME (balP
);
2642 tc_set_bal_of_call (callP
, balP
);
2644 } /* if only one arg, or the args are the same */
2649 s_sysproc: process .sysproc pseudo-op
2651 .sysproc takes two arguments:
2652 arg[1]: name of entry point to system procedure
2653 arg[2]: 'entry_num' (index) of system procedure in the range
2656 For [ab].out, we store the 'entrynum' in the 'n_other' field of
2657 the symbol. Since that entry is normally 0, we bias 'entrynum'
2658 by adding 1 to it. It must be unbiased before it is used. */
2660 s_sysproc (n_ops
, args
)
2661 int n_ops
; /* Number of operands */
2662 char *args
[]; /* args[1]->1st operand, args[2]->2nd operand */
2669 as_bad (_("should have two operands"));
2671 } /* bad arg count */
2673 /* Parse "entry_num" argument and check it for validity. */
2674 parse_expr (args
[2], &exp
);
2675 if (exp
.X_op
!= O_constant
2677 || (offs (exp
) > 31))
2679 as_bad (_("'entry_num' must be absolute number in [0,31]"));
2683 /* Find/make symbol and stick entry number (biased by +1) into it */
2684 symP
= symbol_find_or_make (args
[1]);
2686 if (TC_S_IS_SYSPROC (symP
))
2688 as_warn (_("Redefining entrynum for sysproc %s"), S_GET_NAME (symP
));
2691 TC_S_SET_SYSPROC (symP
, offs (exp
)); /* encode entry number */
2692 TC_S_FORCE_TO_SYSPROC (symP
);
2696 /*****************************************************************************
2698 Determine if a "shlo" instruction can be used to implement a "ldconst".
2699 This means that some number X < 32 can be shifted left to produce the
2700 constant of interest.
2702 Return the shift count, or 0 if we can't do it.
2703 Caller calculates X by shifting original constant right 'shift' places.
2705 *************************************************************************** */
2709 int n
; /* The constant of interest */
2711 int shift
; /* The shift count */
2715 /* Can't do it for negative numbers */
2719 /* Shift 'n' right until a 1 is about to be lost */
2720 for (shift
= 0; (n
& 1) == 0; shift
++)
2733 /* syntax: issue syntax error */
2738 as_bad (_("syntax error"));
2744 Return TRUE iff the target architecture supports the specified
2745 special-function register (sfr). */
2750 int n
; /* Number (0-31) of sfr */
2752 switch (architecture
)
2760 return ((0 <= n
) && (n
<= 4));
2763 return ((0 <= n
) && (n
<= 2));
2770 Return TRUE iff the target architecture supports the indicated
2771 class of instructions. */
2774 targ_has_iclass (ic
)
2775 /* Instruction class; one of:
2776 I_BASE, I_CX, I_DEC, I_KX, I_FP, I_MIL, I_CASIM, I_CX2, I_HX, I_HX2
2780 iclasses_seen
|= ic
;
2781 switch (architecture
)
2784 return ic
& (I_BASE
| I_KX
);
2786 return ic
& (I_BASE
| I_KX
| I_FP
| I_DEC
);
2788 return ic
& (I_BASE
| I_KX
| I_FP
| I_DEC
| I_MIL
);
2790 return ic
& (I_BASE
| I_CX
| I_CX2
| I_CASIM
);
2792 return ic
& (I_BASE
| I_CX2
| I_JX
);
2794 return ic
& (I_BASE
| I_CX2
| I_JX
| I_HX
);
2796 if ((iclasses_seen
& (I_KX
| I_FP
| I_DEC
| I_MIL
))
2797 && (iclasses_seen
& (I_CX
| I_CX2
)))
2799 as_warn (_("architecture of opcode conflicts with that of earlier instruction(s)"));
2800 iclasses_seen
&= ~ic
;
2806 /* Handle the MRI .endian pseudo-op. */
2815 name
= input_line_pointer
;
2816 c
= get_symbol_end ();
2817 if (strcasecmp (name
, "little") == 0)
2819 else if (strcasecmp (name
, "big") == 0)
2820 as_bad (_("big endian mode is not supported"));
2822 as_warn (_("ignoring unrecognized .endian type `%s'"), name
);
2824 *input_line_pointer
= c
;
2826 demand_empty_rest_of_line ();
2829 /* We have no need to default values of symbols. */
2833 md_undefined_symbol (name
)
2839 /* Exactly what point is a PC-relative offset relative TO?
2840 On the i960, they're relative to the address of the instruction,
2841 which we have set up as the address of the fixup too. */
2843 md_pcrel_from (fixP
)
2846 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2849 #ifdef BFD_ASSEMBLER
2851 md_apply_fix (fixP
, valp
)
2856 md_apply_fix (fixP
, val
)
2861 #ifdef BFD_ASSEMBLER
2864 char *place
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2866 if (!fixP
->fx_bit_fixP
)
2868 #ifndef BFD_ASSEMBLER
2869 /* For callx, we always want to write out zero, and emit a
2870 symbolic relocation. */
2874 fixP
->fx_addnumber
= val
;
2877 md_number_to_imm (place
, val
, fixP
->fx_size
, fixP
);
2880 md_number_to_field (place
, val
, fixP
->fx_bit_fixP
);
2882 #ifdef BFD_ASSEMBLER
2887 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2889 tc_bout_fix_to_chars (where
, fixP
, segment_address_in_file
)
2892 relax_addressT segment_address_in_file
;
2894 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
2895 struct relocation_info ri
;
2898 memset ((char *) &ri
, '\0', sizeof (ri
));
2899 symbolP
= fixP
->fx_addsy
;
2900 know (symbolP
!= 0 || fixP
->fx_r_type
!= NO_RELOC
);
2901 ri
.r_bsr
= fixP
->fx_bsr
; /*SAC LD RELAX HACK */
2902 /* These two 'cuz of NS32K */
2903 ri
.r_callj
= fixP
->fx_tcbit
;
2904 if (fixP
->fx_bit_fixP
)
2907 ri
.r_length
= nbytes_r_length
[fixP
->fx_size
];
2908 ri
.r_pcrel
= fixP
->fx_pcrel
;
2909 ri
.r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
;
2911 if (fixP
->fx_r_type
!= NO_RELOC
)
2913 switch (fixP
->fx_r_type
)
2918 ri
.r_length
= fixP
->fx_size
- 1;
2932 else if (linkrelax
|| !S_IS_DEFINED (symbolP
) || fixP
->fx_bsr
)
2935 ri
.r_index
= symbolP
->sy_number
;
2940 ri
.r_index
= S_GET_TYPE (symbolP
);
2943 /* Output the relocation information in machine-dependent form. */
2944 md_ri_to_chars (where
, &ri
);
2947 #endif /* OBJ_AOUT or OBJ_BOUT */
2949 #if defined (OBJ_COFF) && defined (BFD)
2951 tc_coff_fix2rtype (fixP
)
2957 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
2960 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
2968 tc_coff_sizemachdep (frag
)
2972 return frag
->fr_next
->fr_address
- frag
->fr_address
;
2978 /* Align an address by rounding it up to the specified boundary. */
2980 md_section_align (seg
, addr
)
2982 valueT addr
; /* Address to be rounded up */
2985 #ifdef BFD_ASSEMBLER
2986 align
= bfd_get_section_alignment (stdoutput
, seg
);
2988 align
= section_alignment
[(int) seg
];
2990 return (addr
+ (1 << align
) - 1) & (-1 << align
);
2993 extern int coff_flags
;
2997 tc_headers_hook (headers
)
2998 object_headers
*headers
;
3000 switch (architecture
)
3003 coff_flags
|= F_I960KA
;
3007 coff_flags
|= F_I960KB
;
3011 coff_flags
|= F_I960MC
;
3015 coff_flags
|= F_I960CA
;
3019 coff_flags
|= F_I960JX
;
3023 coff_flags
|= F_I960HX
;
3027 if (iclasses_seen
== I_BASE
)
3028 coff_flags
|= F_I960CORE
;
3029 else if (iclasses_seen
& I_CX
)
3030 coff_flags
|= F_I960CA
;
3031 else if (iclasses_seen
& I_HX
)
3032 coff_flags
|= F_I960HX
;
3033 else if (iclasses_seen
& I_JX
)
3034 coff_flags
|= F_I960JX
;
3035 else if (iclasses_seen
& I_CX2
)
3036 coff_flags
|= F_I960CA
;
3037 else if (iclasses_seen
& I_MIL
)
3038 coff_flags
|= F_I960MC
;
3039 else if (iclasses_seen
& (I_DEC
| I_FP
))
3040 coff_flags
|= F_I960KB
;
3042 coff_flags
|= F_I960KA
;
3046 if (flag_readonly_data_in_text
)
3048 headers
->filehdr
.f_magic
= I960RWMAGIC
;
3049 headers
->aouthdr
.magic
= OMAGIC
;
3053 headers
->filehdr
.f_magic
= I960ROMAGIC
;
3054 headers
->aouthdr
.magic
= NMAGIC
;
3055 } /* set magic numbers */
3058 #endif /* OBJ_COFF */
3060 #ifndef BFD_ASSEMBLER
3062 /* Things going on here:
3064 For bout, We need to assure a couple of simplifying
3065 assumptions about leafprocs for the linker: the leafproc
3066 entry symbols will be defined in the same assembly in
3067 which they're declared with the '.leafproc' directive;
3068 and if a leafproc has both 'call' and 'bal' entry points
3069 they are both global or both local.
3071 For coff, the call symbol has a second aux entry that
3072 contains the bal entry point. The bal symbol becomes a
3075 For coff representation, the call symbol has a second aux entry that
3076 contains the bal entry point. The bal symbol becomes a label. */
3079 tc_crawl_symbol_chain (headers
)
3080 object_headers
*headers
;
3084 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3087 if (TC_S_IS_SYSPROC (symbolP
))
3089 /* second aux entry already contains the sysproc number */
3090 S_SET_NUMBER_AUXILIARY (symbolP
, 2);
3091 S_SET_STORAGE_CLASS (symbolP
, C_SCALL
);
3092 S_SET_DATA_TYPE (symbolP
, S_GET_DATA_TYPE (symbolP
) | (DT_FCN
<< N_BTSHFT
));
3094 } /* rewrite sysproc */
3095 #endif /* OBJ_COFF */
3097 if (!TC_S_IS_BALNAME (symbolP
) && !TC_S_IS_CALLNAME (symbolP
))
3100 } /* Not a leafproc symbol */
3102 if (!S_IS_DEFINED (symbolP
))
3104 as_bad (_("leafproc symbol '%s' undefined"), S_GET_NAME (symbolP
));
3105 } /* undefined leaf */
3107 if (TC_S_IS_CALLNAME (symbolP
))
3109 symbolS
*balP
= tc_get_bal_of_call (symbolP
);
3110 if (S_IS_EXTERNAL (symbolP
) != S_IS_EXTERNAL (balP
))
3112 S_SET_EXTERNAL (symbolP
);
3113 S_SET_EXTERNAL (balP
);
3114 as_warn (_("Warning: making leafproc entries %s and %s both global\n"),
3115 S_GET_NAME (symbolP
), S_GET_NAME (balP
));
3116 } /* externality mismatch */
3118 } /* walk the symbol chain */
3121 #endif /* ! BFD_ASSEMBLER */
3123 /* For aout or bout, the bal immediately follows the call.
3125 For coff, we cheat and store a pointer to the bal symbol in the
3126 second aux entry of the call. */
3137 tc_set_bal_of_call (callP
, balP
)
3141 know (TC_S_IS_CALLNAME (callP
));
3142 know (TC_S_IS_BALNAME (balP
));
3146 callP
->sy_tc
= balP
;
3147 S_SET_NUMBER_AUXILIARY (callP
, 2);
3149 #else /* ! OBJ_COFF */
3152 /* If the 'bal' entry doesn't immediately follow the 'call'
3153 * symbol, unlink it from the symbol list and re-insert it.
3155 if (symbol_next (callP
) != balP
)
3157 symbol_remove (balP
, &symbol_rootP
, &symbol_lastP
);
3158 symbol_append (balP
, callP
, &symbol_rootP
, &symbol_lastP
);
3159 } /* if not in order */
3161 #else /* ! OBJ_ABOUT */
3162 as_fatal ("Only supported for a.out, b.out, or COFF");
3163 #endif /* ! OBJ_ABOUT */
3164 #endif /* ! OBJ_COFF */
3168 tc_get_bal_of_call (callP
)
3173 know (TC_S_IS_CALLNAME (callP
));
3176 retval
= callP
->sy_tc
;
3179 retval
= symbol_next (callP
);
3181 as_fatal ("Only supported for a.out, b.out, or COFF");
3182 #endif /* ! OBJ_ABOUT */
3183 #endif /* ! OBJ_COFF */
3185 know (TC_S_IS_BALNAME (retval
));
3187 } /* _tc_get_bal_of_call() */
3190 tc_coff_symbol_emit_hook (symbolP
)
3193 if (TC_S_IS_CALLNAME (symbolP
))
3196 symbolS
*balP
= tc_get_bal_of_call (symbolP
);
3199 /* second aux entry contains the bal entry point */
3200 S_SET_NUMBER_AUXILIARY (symbolP
, 2);
3202 symbolP
->sy_symbol
.ost_auxent
[1].x_bal
.x_balntry
= S_GET_VALUE (balP
);
3203 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
3204 S_SET_STORAGE_CLASS (symbolP
, C_LEAFEXT
);
3206 S_SET_STORAGE_CLASS (symbolP
, C_LEAFSTAT
);
3207 S_SET_DATA_TYPE (symbolP
, S_GET_DATA_TYPE (symbolP
) | (DT_FCN
<< N_BTSHFT
));
3208 /* fix up the bal symbol */
3209 S_SET_STORAGE_CLASS (balP
, C_LABEL
);
3210 #endif /* OBJ_COFF */
3211 } /* only on calls */
3215 i960_handle_align (fragp
)
3223 as_bad (_("option --link-relax is only supported in b.out format"));
3229 /* The text section "ends" with another alignment reloc, to which we
3230 aren't adding padding. */
3231 if (fragp
->fr_next
== text_last_frag
3232 || fragp
->fr_next
== data_last_frag
)
3235 /* alignment directive */
3236 fix_new (fragp
, fragp
->fr_fix
, fragp
->fr_offset
, 0, 0, 0,
3237 (int) fragp
->fr_type
);
3238 #endif /* OBJ_BOUT */
3242 i960_validate_fix (fixP
, this_segment_type
, add_symbolPP
)
3244 segT this_segment_type
;
3245 symbolS
**add_symbolPP
;
3247 #define add_symbolP (*add_symbolPP)
3248 if (fixP
->fx_tcbit
&& TC_S_IS_CALLNAME (add_symbolP
))
3250 /* Relocation should be done via the associated 'bal'
3251 entry point symbol. */
3253 if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3255 as_bad (_("No 'bal' entry point for leafproc %s"),
3256 S_GET_NAME (add_symbolP
));
3259 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3262 /* Still have to work out other conditions for these tests. */
3266 as_bad (_("callj to difference of two symbols"));
3270 if ((int) fixP
->fx_bit_fixP
== 13)
3272 /* This is a COBR instruction. They have only a 13-bit
3273 displacement and are only to be used for local branches:
3274 flag as error, don't generate relocation. */
3275 as_bad (_("can't use COBR format with external label"));
3276 fixP
->fx_addsy
= NULL
; /* No relocations please. */
3285 #ifdef BFD_ASSEMBLER
3290 tc_bfd_fix2rtype (fixP
)
3298 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
3299 return BFD_RELOC_32
;
3301 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
3302 return BFD_RELOC_24_PCREL
;
3308 /* Translate internal representation of relocation info to BFD target
3311 FIXME: To what extent can we get all relevant targets to use this? */
3314 tc_gen_reloc (section
, fixP
)
3320 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3322 /* HACK: Is this right? */
3323 fixP
->fx_r_type
= tc_bfd_fix2rtype (fixP
);
3325 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
3326 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
3328 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3329 "internal error: can't export reloc type %d (`%s')",
3331 bfd_get_reloc_code_name (fixP
->fx_r_type
));
3335 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
3337 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3338 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
3339 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
3340 reloc
->addend
= fixP
->fx_addnumber
;
3345 /* end from cgen.c */
3347 #endif /* BFD_ASSEMBLER */
3349 /* end of tc-i960.c */