1 /* tc-i960.c - All the i80960-specific stuff
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2005
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, 51 Franklin Street - Fifth Floor, 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. */
138 /* See md_parse_option() for meanings of these options. */
139 static char norelax
; /* True if -norelax switch seen. */
140 static char instrument_branches
; /* True if -b switch seen. */
142 /* Characters that always start a comment.
143 If the pre-processor is disabled, these aren't very useful. */
144 const char comment_chars
[] = "#";
146 /* Characters that only start a comment at the beginning of
147 a line. If the line seems to have the form '# 123 filename'
148 .line and .file directives will appear in the pre-processed output.
150 Note that input_file.c hand checks for '#' at the beginning of the
151 first line of the input file. This is because the compiler outputs
152 #NO_APP at the beginning of its output. */
154 /* Also note that comments started like this one will always work. */
156 const char line_comment_chars
[] = "#";
157 const char line_separator_chars
[] = ";";
159 /* Chars that can be used to separate mant from exp in floating point nums. */
160 const char EXP_CHARS
[] = "eE";
162 /* Chars that mean this number is a floating point constant,
163 as in 0f12.456 or 0d1.2345e12. */
164 const char FLT_CHARS
[] = "fFdDtT";
166 /* Table used by base assembler to relax addresses based on varying length
167 instructions. The fields are:
168 1) most positive reach of this state,
169 2) most negative reach of this state,
170 3) how many bytes this mode will add to the size of the current frag
171 4) which index into the table to try if we can't fit into this one.
173 For i80960, the only application is the (de-)optimization of cobr
174 instructions into separate compare and branch instructions when a 13-bit
175 displacement won't hack it. */
176 const relax_typeS md_relax_table
[] =
178 {0, 0, 0, 0}, /* State 0 => no more relaxation possible. */
179 {4088, -4096, 0, 2}, /* State 1: conditional branch (cobr). */
180 {0x800000 - 8, -0x800000, 4, 0}, /* State 2: compare (reg) & branch (ctrl). */
183 /* These are the machine dependent pseudo-ops.
185 This table describes all the machine specific pseudo-ops the assembler
186 has to support. The fields are:
187 pseudo-op name without dot
188 function to call to execute this pseudo-op
189 integer arg to pass to the function. */
193 /* Macros to extract info from an 'expressionS' structure 'e'. */
194 #define adds(e) e.X_add_symbol
195 #define offs(e) e.X_add_number
197 /* Branch-prediction bits for CTRL/COBR format opcodes. */
198 #define BP_MASK 0x00000002 /* Mask for branch-prediction bit. */
199 #define BP_TAKEN 0x00000000 /* Value to OR in to predict branch. */
200 #define BP_NOT_TAKEN 0x00000002 /* Value to OR in to predict no branch. */
202 /* Some instruction opcodes that we need explicitly. */
203 #define BE 0x12000000
204 #define BG 0x11000000
205 #define BGE 0x13000000
206 #define BL 0x14000000
207 #define BLE 0x16000000
208 #define BNE 0x15000000
209 #define BNO 0x10000000
210 #define BO 0x17000000
211 #define CHKBIT 0x5a002700
212 #define CMPI 0x5a002080
213 #define CMPO 0x5a002000
216 #define BAL 0x0b000000
217 #define CALL 0x09000000
218 #define CALLS 0x66003800
219 #define RET 0x0a000000
221 /* These masks are used to build up a set of MEMB mode bits. */
224 #define MEMB_BIT 0x1000
227 /* Mask for the only mode bit in a MEMA instruction (if set, abase reg is
229 #define MEMA_ABASE 0x2000
231 /* Info from which a MEMA or MEMB format instruction can be generated. */
234 /* (First) 32 bits of instruction. */
236 /* 0-(none), 12- or, 32-bit displacement needed. */
238 /* The expression in the source instruction from which the
239 displacement should be determined. */
244 /* The two pieces of info we need to generate a register operand. */
247 int mode
; /* 0 =>local/global/spec reg; 1=> literal or fp reg. */
248 int special
; /* 0 =>not a sfr; 1=> is a sfr (not valid w/mode=0). */
249 int n
; /* Register number or literal value. */
252 /* Number and assembler mnemonic for all registers that can appear in
294 /* Numbers for special-function registers are for assembler internal
295 use only: they are scaled back to range [0-31] for binary output. */
331 /* Numbers for floating point registers are for assembler internal
332 use only: they are scaled back to [0-3] for binary output. */
340 { NULL
, 0 }, /* END OF LIST */
343 #define IS_RG_REG(n) ((0 <= (n)) && ((n) < SF0))
344 #define IS_SF_REG(n) ((SF0 <= (n)) && ((n) < FP0))
345 #define IS_FP_REG(n) ((n) >= FP0)
347 /* Number and assembler mnemonic for all registers that can appear as
348 'abase' (indirect addressing) registers. */
390 /* For assembler internal use only: this number never appears in binary
394 { NULL
, 0 }, /* END OF LIST */
398 static struct hash_control
*op_hash
; /* Opcode mnemonics. */
399 static struct hash_control
*reg_hash
; /* Register name hash table. */
400 static struct hash_control
*areg_hash
; /* Abase register hash table. */
402 /* Architecture for which we are assembling. */
403 #define ARCH_ANY 0 /* Default: no architecture checking done. */
410 int architecture
= ARCH_ANY
; /* Architecture requested on invocation line. */
411 int iclasses_seen
; /* OR of instruction classes (I_* constants)
412 for which we've actually assembled
415 /* BRANCH-PREDICTION INSTRUMENTATION
417 The following supports generation of branch-prediction instrumentation
418 (turned on by -b switch). The instrumentation collects counts
419 of branches taken/not-taken for later input to a utility that will
420 set the branch prediction bits of the instructions in accordance with
421 the behavior observed. (Note that the KX series does not have
424 The instrumentation consists of:
426 (1) before and after each conditional branch, a call to an external
427 routine that increments and steps over an inline counter. The
428 counter itself, initialized to 0, immediately follows the call
429 instruction. For each branch, the counter following the branch
430 is the number of times the branch was not taken, and the difference
431 between the counters is the number of times it was taken. An
432 example of an instrumented conditional branch:
440 (2) a table of pointers to the instrumented branches, so that an
441 external postprocessing routine can locate all of the counters.
442 the table begins with a 2-word header: a pointer to the next in
443 a linked list of such tables (initialized to 0); and a count
444 of the number of entries in the table (exclusive of the header.
446 Note that input source code is expected to already contain calls
447 an external routine that will link the branch local table into a
448 list of such tables. */
450 /* Number of branches instrumented so far. Also used to generate
451 unique local labels for each instrumented branch. */
454 #define BR_LABEL_BASE "LBRANCH"
455 /* Basename of local labels on instrumented branches, to avoid
456 conflict with compiler- generated local labels. */
458 #define BR_CNT_FUNC "__inc_branch"
459 /* Name of the external routine that will increment (and step over) an
462 #define BR_TAB_NAME "__BRANCH_TABLE__"
463 /* Name of the table of pointers to branches. A local (i.e.,
464 non-external) symbol. */
466 static void ctrl_fmt (char *, long, int);
472 int i
; /* Loop counter. */
473 const struct i960_opcode
*oP
; /* Pointer into opcode table. */
474 const char *retval
; /* Value returned by hash functions. */
476 op_hash
= hash_new ();
477 reg_hash
= hash_new ();
478 areg_hash
= hash_new ();
480 /* For some reason, the base assembler uses an empty string for "no
481 error message", instead of a NULL pointer. */
484 for (oP
= i960_opcodes
; oP
->name
&& !retval
; oP
++)
485 retval
= hash_insert (op_hash
, oP
->name
, (void *) oP
);
487 for (i
= 0; regnames
[i
].reg_name
&& !retval
; i
++)
488 retval
= hash_insert (reg_hash
, regnames
[i
].reg_name
,
489 (char *) ®names
[i
].reg_num
);
491 for (i
= 0; aregs
[i
].areg_name
&& !retval
; i
++)
492 retval
= hash_insert (areg_hash
, aregs
[i
].areg_name
,
493 (char *) &aregs
[i
].areg_num
);
496 as_fatal (_("Hashing returned \"%s\"."), retval
);
499 /* parse_expr: parse an expression
501 Use base assembler's expression parser to parse an expression.
502 It, unfortunately, runs off a global which we have to save/restore
503 in order to make it work for us.
505 An empty expression string is treated as an absolute 0.
507 Sets O_illegal regardless of expression evaluation if entire input
508 string is not consumed in the evaluation -- tolerate no dangling junk! */
511 parse_expr (char *textP
, /* Text of expression to be parsed. */
512 expressionS
*expP
) /* Where to put the results of parsing. */
514 char *save_in
; /* Save global here. */
521 /* Treat empty string as absolute 0. */
522 expP
->X_add_symbol
= expP
->X_op_symbol
= NULL
;
523 expP
->X_add_number
= 0;
524 expP
->X_op
= O_constant
;
528 save_in
= input_line_pointer
; /* Save global. */
529 input_line_pointer
= textP
; /* Make parser work for us. */
531 (void) expression (expP
);
532 if ((size_t) (input_line_pointer
- textP
) != strlen (textP
))
533 /* Did not consume all of the input. */
534 expP
->X_op
= O_illegal
;
536 symP
= expP
->X_add_symbol
;
537 if (symP
&& (hash_find (reg_hash
, S_GET_NAME (symP
))))
538 /* Register name in an expression. */
539 /* FIXME: this isn't much of a check any more. */
540 expP
->X_op
= O_illegal
;
542 input_line_pointer
= save_in
; /* Restore global. */
546 /* emit: output instruction binary
548 Output instruction binary, in target byte order, 4 bytes at a time.
549 Return pointer to where it was placed. */
552 emit (long instr
) /* Word to be output, host byte order. */
554 char *toP
; /* Where to output it. */
556 toP
= frag_more (4); /* Allocate storage. */
557 md_number_to_chars (toP
, instr
, 4); /* Convert to target byte order. */
561 /* get_cdisp: handle displacement for a COBR or CTRL instruction.
563 Parse displacement for a COBR or CTRL instruction.
565 If successful, output the instruction opcode and set up for it,
566 depending on the arg 'var_frag', either:
567 o an address fixup to be done when all symbol values are known, or
568 o a varying length code fragment, with address fixup info. This
569 will be done for cobr instructions that may have to be relaxed
570 in to compare/branch instructions (8 bytes) if the final
571 address displacement is greater than 13 bits. */
574 get_cdisp (char *dispP
, /* Displacement as specified in source instruction. */
575 char *ifmtP
, /* "COBR" or "CTRL" (for use in error message). */
576 long instr
, /* Instruction needing the displacement. */
577 int numbits
, /* # bits of displacement (13 for COBR, 24 for CTRL). */
578 int var_frag
,/* 1 if varying length code fragment should be emitted;
579 0 if an address fix should be emitted. */
580 int callj
) /* 1 if callj relocation should be done; else 0. */
582 expressionS e
; /* Parsed expression. */
583 fixS
*fixP
; /* Structure describing needed address fix. */
584 char *outP
; /* Where instruction binary is output to. */
588 parse_expr (dispP
, &e
);
592 as_bad (_("expression syntax error"));
595 if (S_GET_SEGMENT (e
.X_add_symbol
) == now_seg
596 || S_GET_SEGMENT (e
.X_add_symbol
) == undefined_section
)
600 outP
= frag_more (8); /* Allocate worst-case storage. */
601 md_number_to_chars (outP
, instr
, 4);
602 frag_variant (rs_machine_dependent
, 4, 4, 1,
603 adds (e
), offs (e
), outP
);
607 /* Set up a new fix structure, so address can be updated
608 when all symbol values are known. */
610 fixP
= fix_new (frag_now
,
611 outP
- frag_now
->fr_literal
,
618 fixP
->fx_tcbit
= callj
;
620 /* We want to modify a bit field when the address is
621 known. But we don't need all the garbage in the
622 bit_fix structure. So we're going to lie and store
623 the number of bits affected instead of a pointer. */
624 fixP
->fx_bit_fixP
= (bit_fixS
*) (size_t) numbits
;
628 as_bad (_("attempt to branch into different segment"));
632 as_bad (_("target of %s instruction must be a label"), ifmtP
);
638 md_chars_to_number (char * val
, /* Value in target byte order. */
639 int n
) /* Number of bytes in the input. */
643 for (retval
= 0; n
--;)
646 retval
|= (unsigned char) val
[n
];
651 /* mema_to_memb: convert a MEMA-format opcode to a MEMB-format opcode.
653 There are 2 possible MEMA formats:
655 - displacement + abase
657 They are distinguished by the setting of the MEMA_ABASE bit. */
660 mema_to_memb (char * opcodeP
) /* Where to find the opcode, in target byte order. */
662 long opcode
; /* Opcode in host byte order. */
663 long mode
; /* Mode bits for MEMB instruction. */
665 opcode
= md_chars_to_number (opcodeP
, 4);
666 know (!(opcode
& MEMB_BIT
));
668 mode
= MEMB_BIT
| D_BIT
;
669 if (opcode
& MEMA_ABASE
)
672 opcode
&= 0xffffc000; /* Clear MEMA offset and mode bits. */
673 opcode
|= mode
; /* Set MEMB mode bits. */
675 md_number_to_chars (opcodeP
, opcode
, 4);
680 Return TRUE iff the target architecture supports the specified
681 special-function register (sfr). */
684 targ_has_sfr (int n
) /* Number (0-31) of sfr. */
686 switch (architecture
)
694 return ((0 <= n
) && (n
<= 4));
697 return ((0 <= n
) && (n
<= 2));
701 /* Look up a (suspected) register name in the register table and return the
702 associated register number (or -1 if not found). */
705 get_regnum (char *regname
) /* Suspected register name. */
709 rP
= (int *) hash_find (reg_hash
, regname
);
710 return (rP
== NULL
) ? -1 : *rP
;
713 /* syntax: Issue a syntax error. */
718 as_bad (_("syntax error"));
721 /* parse_regop: parse a register operand.
723 In case of illegal operand, issue a message and return some valid
724 information so instruction processing can continue. */
727 parse_regop (struct regop
*regopP
, /* Where to put description of register operand. */
728 char *optext
, /* Text of operand. */
729 char opdesc
) /* Descriptor byte: what's legal for this operand. */
731 int n
; /* Register number. */
732 expressionS e
; /* Parsed expression. */
734 /* See if operand is a register. */
735 n
= get_regnum (optext
);
740 /* Global or local register. */
741 if (!REG_ALIGN (opdesc
, n
))
742 as_bad (_("unaligned register"));
749 else if (IS_FP_REG (n
) && FP_OK (opdesc
))
751 /* Floating point register, and it's allowed. */
757 else if (IS_SF_REG (n
) && SFR_OK (opdesc
))
759 /* Special-function register, and it's allowed. */
763 if (!targ_has_sfr (regopP
->n
))
764 as_bad (_("no such sfr in this architecture"));
769 else if (LIT_OK (opdesc
))
771 /* How about a literal? */
776 /* Floating point literal acceptable. */
777 /* Skip over 0f, 0d, or 0e prefix. */
778 if ((optext
[0] == '0')
779 && (optext
[1] >= 'd')
780 && (optext
[1] <= 'f'))
783 if (!strcmp (optext
, "0.0") || !strcmp (optext
, "0"))
789 if (!strcmp (optext
, "1.0") || !strcmp (optext
, "1"))
797 /* Fixed point literal acceptable. */
798 parse_expr (optext
, &e
);
799 if (e
.X_op
!= O_constant
800 || (offs (e
) < 0) || (offs (e
) > 31))
802 as_bad (_("illegal literal"));
805 regopP
->n
= offs (e
);
810 /* Nothing worked. */
812 regopP
->mode
= 0; /* Register r0 is always a good one. */
817 /* get_ispec: parse a memory operand for an index specification
819 Here, an "index specification" is taken to be anything surrounded
820 by square brackets and NOT followed by anything else.
822 If it's found, detach it from the input string, remove the surrounding
823 square brackets, and return a pointer to it. Otherwise, return NULL. */
826 get_ispec (char *textP
) /* Pointer to memory operand from source instruction, no white space. */
829 /* Points to start of index specification. */
831 /* Points to end of index specification. */
834 /* Find opening square bracket, if any. */
835 start
= strchr (textP
, '[');
839 /* Eliminate '[', detach from rest of operand. */
842 end
= strchr (start
, ']');
845 as_bad (_("unmatched '['"));
848 /* Eliminate ']' and make sure it was the last thing
851 if (*(end
+ 1) != '\0')
852 as_bad (_("garbage after index spec ignored"));
858 /* parse_memop: parse a memory operand
860 This routine is based on the observation that the 4 mode bits of the
861 MEMB format, taken individually, have fairly consistent meaning:
863 M3 (bit 13): 1 if displacement is present (D_BIT)
864 M2 (bit 12): 1 for MEMB instructions (MEMB_BIT)
865 M1 (bit 11): 1 if index is present (I_BIT)
866 M0 (bit 10): 1 if abase is present (A_BIT)
868 So we parse the memory operand and set bits in the mode as we find
869 things. Then at the end, if we go to MEMB format, we need only set
870 the MEMB bit (M2) and our mode is built for us.
872 Unfortunately, I said "fairly consistent". The exceptions:
875 0100 Would seem illegal, but means "abase-only".
877 0101 Would seem to mean "abase-only" -- it means IP-relative.
878 Must be converted to 0100.
880 0110 Would seem to mean "index-only", but is reserved.
881 We turn on the D bit and provide a 0 displacement.
883 The other thing to observe is that we parse from the right, peeling
884 things * off as we go: first any index spec, then any abase, then
888 parse_memop (memS
*memP
, /* Where to put the results. */
889 char *argP
, /* Text of the operand to be parsed. */
890 int optype
) /* MEM1, MEM2, MEM4, MEM8, MEM12, or MEM16. */
892 char *indexP
; /* Pointer to index specification with "[]" removed. */
893 char *p
; /* Temp char pointer. */
894 char iprel_flag
; /* True if this is an IP-relative operand. */
895 int regnum
; /* Register number. */
896 /* Scale factor: 1,2,4,8, or 16. Later converted to internal format
897 (0,1,2,3,4 respectively). */
899 int mode
; /* MEMB mode bits. */
900 int *intP
; /* Pointer to register number. */
902 /* The following table contains the default scale factors for each
903 type of memory instruction. It is accessed using (optype-MEM1)
904 as an index -- thus it assumes the 'optype' constants are
905 assigned consecutive values, in the order they appear in this
907 static const int def_scale
[] =
913 -1, /* MEM12 -- no valid default */
917 iprel_flag
= mode
= 0;
919 /* Any index present? */
920 indexP
= get_ispec (argP
);
923 p
= strchr (indexP
, '*');
926 /* No explicit scale -- use default for this instruction
927 type and assembler mode. */
931 /* GNU960 compatibility */
932 scale
= def_scale
[optype
- MEM1
];
936 *p
++ = '\0'; /* Eliminate '*' */
938 /* Now indexP->a '\0'-terminated register name,
939 and p->a scale factor. */
941 if (!strcmp (p
, "16"))
943 else if (strchr ("1248", *p
) && (p
[1] == '\0'))
949 regnum
= get_regnum (indexP
); /* Get index reg. # */
950 if (!IS_RG_REG (regnum
))
952 as_bad (_("invalid index register"));
956 /* Convert scale to its binary encoding. */
975 as_bad (_("invalid scale factor"));
979 memP
->opcode
|= scale
| regnum
; /* Set index bits in opcode. */
980 mode
|= I_BIT
; /* Found a valid index spec. */
983 /* Any abase (Register Indirect) specification present? */
984 if ((p
= strrchr (argP
, '(')) != NULL
)
986 /* "(" is there -- does it start a legal abase spec? If not, it
987 could be part of a displacement expression. */
988 intP
= (int *) hash_find (areg_hash
, p
);
991 /* Got an abase here. */
993 *p
= '\0'; /* Discard register spec. */
995 /* We have to specialcase ip-rel mode. */
999 memP
->opcode
|= regnum
<< 14;
1005 /* Any expression present? */
1010 /* Special-case ip-relative addressing. */
1017 memP
->opcode
|= 5 << 10; /* IP-relative mode. */
1023 /* Handle all other modes. */
1027 /* Go with MEMA instruction format for now (grow to MEMB later
1028 if 12 bits is not enough for the displacement). MEMA format
1029 has a single mode bit: set it to indicate that abase is
1031 memP
->opcode
|= MEMA_ABASE
;
1036 /* Go with MEMA instruction format for now (grow to MEMB later
1037 if 12 bits is not enough for the displacement). */
1042 /* For some reason, the bit string for this mode is not
1043 consistent: it should be 0 (exclusive of the MEMB bit), so we
1044 set it "by hand" here. */
1045 memP
->opcode
|= MEMB_BIT
;
1049 /* set MEMB bit in mode, and OR in mode bits. */
1050 memP
->opcode
|= mode
| MEMB_BIT
;
1054 /* Treat missing displacement as displacement of 0. */
1056 /* Fall into next case. */
1057 case D_BIT
| A_BIT
| I_BIT
:
1059 /* Set MEMB bit in mode, and OR in mode bits. */
1060 memP
->opcode
|= mode
| MEMB_BIT
;
1070 /* Generate a MEMA- or MEMB-format instruction. */
1073 mem_fmt (char *args
[], /* args[0]->opcode mnemonic, args[1-3]->operands. */
1074 struct i960_opcode
*oP
,/* Pointer to description of instruction. */
1075 int callx
) /* Is this a callx opcode. */
1077 int i
; /* Loop counter. */
1078 struct regop regop
; /* Description of register operand. */
1079 char opdesc
; /* Operand descriptor byte. */
1080 memS instr
; /* Description of binary to be output. */
1081 char *outP
; /* Where the binary was output to. */
1082 expressionS expr
; /* Parsed expression. */
1083 /* ->description of deferred address fixup. */
1087 /* COFF support isn't in place yet for callx relaxing. */
1091 memset (&instr
, '\0', sizeof (memS
));
1092 instr
.opcode
= oP
->opcode
;
1094 /* Process operands. */
1095 for (i
= 1; i
<= oP
->num_ops
; i
++)
1097 opdesc
= oP
->operand
[i
- 1];
1100 parse_memop (&instr
, args
[i
], oP
->format
);
1103 parse_regop (®op
, args
[i
], opdesc
);
1104 instr
.opcode
|= regop
.n
<< 19;
1108 /* Parse the displacement; this must be done before emitting the
1109 opcode, in case it is an expression using `.'. */
1110 parse_expr (instr
.e
, &expr
);
1112 /* Output opcode. */
1113 outP
= emit (instr
.opcode
);
1115 if (instr
.disp
== 0)
1118 /* Process the displacement. */
1122 as_bad (_("expression syntax error"));
1126 if (instr
.disp
== 32)
1127 (void) emit (offs (expr
)); /* Output displacement. */
1130 /* 12-bit displacement. */
1131 if (offs (expr
) & ~0xfff)
1133 /* Won't fit in 12 bits: convert already-output
1134 instruction to MEMB format, output
1136 mema_to_memb (outP
);
1137 (void) emit (offs (expr
));
1141 /* WILL fit in 12 bits: OR into opcode and
1142 overwrite the binary we already put out. */
1143 instr
.opcode
|= offs (expr
);
1144 md_number_to_chars (outP
, instr
.opcode
, 4);
1150 if (instr
.disp
== 12)
1151 /* Displacement is dependent on a symbol, whose value
1152 may change at link time. We HAVE to reserve 32 bits.
1153 Convert already-output opcode to MEMB format. */
1154 mema_to_memb (outP
);
1156 /* Output 0 displacement and set up address fixup for when
1157 this symbol's value becomes known. */
1158 outP
= emit ((long) 0);
1159 fixP
= fix_new_exp (frag_now
,
1160 outP
- frag_now
->fr_literal
,
1161 4, & expr
, 0, NO_RELOC
);
1162 /* Steve's linker relaxing hack. Mark this 32-bit relocation as
1163 being in the instruction stream, specifically as part of a callx
1165 fixP
->fx_bsr
= callx
;
1172 Return TRUE iff the target architecture supports the indicated
1173 class of instructions. */
1176 targ_has_iclass (int ic
) /* Instruction class; one of:
1177 I_BASE, I_CX, I_DEC, I_KX, I_FP, I_MIL, I_CASIM, I_CX2, I_HX, I_HX2. */
1179 iclasses_seen
|= ic
;
1181 switch (architecture
)
1184 return ic
& (I_BASE
| I_KX
);
1186 return ic
& (I_BASE
| I_KX
| I_FP
| I_DEC
);
1188 return ic
& (I_BASE
| I_KX
| I_FP
| I_DEC
| I_MIL
);
1190 return ic
& (I_BASE
| I_CX
| I_CX2
| I_CASIM
);
1192 return ic
& (I_BASE
| I_CX2
| I_JX
);
1194 return ic
& (I_BASE
| I_CX2
| I_JX
| I_HX
);
1196 if ((iclasses_seen
& (I_KX
| I_FP
| I_DEC
| I_MIL
))
1197 && (iclasses_seen
& (I_CX
| I_CX2
)))
1199 as_warn (_("architecture of opcode conflicts with that of earlier instruction(s)"));
1200 iclasses_seen
&= ~ic
;
1207 Determine if a "shlo" instruction can be used to implement a "ldconst".
1208 This means that some number X < 32 can be shifted left to produce the
1209 constant of interest.
1211 Return the shift count, or 0 if we can't do it.
1212 Caller calculates X by shifting original constant right 'shift' places. */
1215 shift_ok (int n
) /* The constant of interest. */
1217 int shift
; /* The shift count. */
1220 /* Can't do it for negative numbers. */
1223 /* Shift 'n' right until a 1 is about to be lost. */
1224 for (shift
= 0; (n
& 1) == 0; shift
++)
1234 Parse and replace a 'ldconst' pseudo-instruction with an appropriate
1237 Assumes the input consists of:
1238 arg[0] opcode mnemonic ('ldconst')
1239 arg[1] first operand (constant)
1240 arg[2] name of register to be loaded
1242 Replaces opcode and/or operands as appropriate.
1244 Returns the new number of arguments, or -1 on failure. */
1247 parse_ldconst (char *arg
[]) /* See above. */
1249 int n
; /* Constant to be loaded. */
1250 int shift
; /* Shift count for "shlo" instruction. */
1251 static char buf
[5]; /* Literal for first operand. */
1252 static char buf2
[5]; /* Literal for second operand. */
1253 expressionS e
; /* Parsed expression. */
1255 arg
[3] = NULL
; /* So we can tell at the end if it got used or not. */
1257 parse_expr (arg
[1], &e
);
1261 /* We're dependent on one or more symbols -- use "lda". */
1266 /* Try the following mappings:
1267 ldconst 0,<reg> -> mov 0,<reg>
1268 ldconst 31,<reg> -> mov 31,<reg>
1269 ldconst 32,<reg> -> addo 1,31,<reg>
1270 ldconst 62,<reg> -> addo 31,31,<reg>
1271 ldconst 64,<reg> -> shlo 8,3,<reg>
1272 ldconst -1,<reg> -> subo 1,0,<reg>
1273 ldconst -31,<reg> -> subo 31,0,<reg>
1275 Anything else becomes:
1278 if ((0 <= n
) && (n
<= 31))
1280 else if ((-31 <= n
) && (n
<= -1))
1284 sprintf (buf
, "%d", -n
);
1288 else if ((32 <= n
) && (n
<= 62))
1293 sprintf (buf
, "%d", n
- 31);
1296 else if ((shift
= shift_ok (n
)) != 0)
1300 sprintf (buf
, "%d", shift
);
1302 sprintf (buf2
, "%d", n
>> shift
);
1310 as_bad (_("invalid constant"));
1314 return (arg
[3] == 0) ? 2 : 3;
1317 /* reg_fmt: generate a REG-format instruction. */
1320 reg_fmt (char *args
[], /* args[0]->opcode mnemonic, args[1-3]->operands. */
1321 struct i960_opcode
*oP
)/* Pointer to description of instruction. */
1323 long instr
; /* Binary to be output. */
1324 struct regop regop
; /* Description of register operand. */
1325 int n_ops
; /* Number of operands. */
1328 n_ops
= oP
->num_ops
;
1332 parse_regop (®op
, args
[1], oP
->operand
[0]);
1334 if ((n_ops
== 1) && !(instr
& M3
))
1336 /* 1-operand instruction in which the dst field should
1337 be used (instead of src1). */
1340 regop
.mode
= regop
.special
;
1346 /* regop.n goes in bit 0, needs no shifting. */
1348 regop
.special
<<= 5;
1350 instr
|= regop
.n
| regop
.mode
| regop
.special
;
1355 parse_regop (®op
, args
[2], oP
->operand
[1]);
1357 if ((n_ops
== 2) && !(instr
& M3
))
1359 /* 2-operand instruction in which the dst field should
1360 be used instead of src2). */
1363 regop
.mode
= regop
.special
;
1371 regop
.special
<<= 6;
1373 instr
|= regop
.n
| regop
.mode
| regop
.special
;
1377 parse_regop (®op
, args
[3], oP
->operand
[2]);
1379 regop
.mode
= regop
.special
;
1380 instr
|= (regop
.n
<<= 19) | (regop
.mode
<<= 13);
1385 /* get_args: break individual arguments out of comma-separated list
1388 - all comments and labels have been removed
1389 - all strings of whitespace have been collapsed to a single blank.
1390 - all character constants ('x') have been replaced with decimal
1393 args[0] is untouched. args[1] points to first operand, etc. All args:
1394 - are NULL-terminated
1395 - contain no whitespace
1398 Number of operands (0,1,2, or 3) or -1 on error. */
1401 get_args (char *p
, /* Pointer to comma-separated operands; Mucked by us. */
1402 char *args
[]) /* Output arg: pointers to operands placed in args[1-3].
1403 Must accommodate 4 entries (args[0-3]). */
1406 int n
; /* Number of operands. */
1409 /* Skip lead white space. */
1419 /* Squeze blanks out by moving non-blanks toward start of string.
1420 Isolate operands, whenever comma is found. */
1425 && (! ISALNUM (p
[1])
1426 || ! ISALNUM (p
[-1])))
1430 /* Start of operand. */
1433 as_bad (_("too many operands"));
1436 *to
++ = '\0'; /* Terminate argument. */
1437 args
[++n
] = to
; /* Start next argument. */
1447 /* i_scan: perform lexical scan of ascii assembler instruction.
1450 - input string is an i80960 instruction (not a pseudo-op)
1451 - all comments and labels have been removed
1452 - all strings of whitespace have been collapsed to a single blank.
1455 args[0] points to opcode, other entries point to operands. All strings:
1456 - are NULL-terminated
1457 - contain no whitespace
1458 - have character constants ('x') replaced with a decimal number
1461 Number of operands (0,1,2, or 3) or -1 on error. */
1464 i_scan (char *iP
, /* Pointer to ascii instruction; Mucked by us. */
1465 char *args
[]) /* Output arg: pointers to opcode and operands placed here.
1466 Must accommodate 4 entries. */
1468 /* Isolate opcode. */
1473 for (; *iP
!= ' '; iP
++)
1477 /* There are no operands. */
1480 /* We never moved: there was no opcode either! */
1481 as_bad (_("missing opcode"));
1488 return (get_args (iP
, args
));
1494 /* Emit call to "increment" routine. */
1495 ctrl_fmt (BR_CNT_FUNC
, CALL
, 1);
1496 /* Emit inline counter to be incremented. */
1503 static char buf
[20];
1505 sprintf (buf
, "%s%d", BR_LABEL_BASE
, br_cnt
++);
1510 ctrl_fmt (char *targP
, /* Pointer to text of lone operand (if any). */
1511 long opcode
, /* Template of instruction. */
1512 int num_ops
) /* Number of operands. */
1514 int instrument
; /* TRUE iff we should add instrumentation to track
1515 how often the branch is taken. */
1518 emit (opcode
); /* Output opcode. */
1521 instrument
= instrument_branches
&& (opcode
!= CALL
)
1522 && (opcode
!= B
) && (opcode
!= RET
) && (opcode
!= BAL
);
1527 colon (brlab_next ());
1530 /* The operand MUST be an ip-relative displacement. Parse it
1531 and set up address fix for the instruction we just output. */
1532 get_cdisp (targP
, "CTRL", opcode
, 24, 0, 0);
1540 cobr_fmt (/* arg[0]->opcode mnemonic, arg[1-3]->operands (ascii) */
1542 /* Opcode, with branch-prediction bits already set if necessary. */
1544 /* Pointer to description of instruction. */
1545 struct i960_opcode
*oP
)
1547 long instr
; /* 32-bit instruction. */
1548 struct regop regop
; /* Description of register operand. */
1549 int n
; /* Number of operands. */
1550 int var_frag
; /* 1 if varying length code fragment should
1551 be emitted; 0 if an address fix
1552 should be emitted. */
1559 /* First operand (if any) of a COBR is always a register
1560 operand. Parse it. */
1561 parse_regop (®op
, arg
[1], oP
->operand
[0]);
1562 instr
|= (regop
.n
<< 19) | (regop
.mode
<< 13);
1567 /* Second operand (if any) of a COBR is always a register
1568 operand. Parse it. */
1569 parse_regop (®op
, arg
[2], oP
->operand
[1]);
1570 instr
|= (regop
.n
<< 14) | regop
.special
;
1577 if (instrument_branches
)
1580 colon (brlab_next ());
1583 /* A third operand to a COBR is always a displacement. Parse
1584 it; if it's relaxable (a cobr "j" directive, or any cobr
1585 other than bbs/bbc when the "-norelax" option is not in use)
1586 set up a variable code fragment; otherwise set up an address
1588 var_frag
= !norelax
|| (oP
->format
== COJ
); /* TRUE or FALSE */
1589 get_cdisp (arg
[3], "COBR", instr
, 13, var_frag
, 0);
1591 if (instrument_branches
)
1596 /* Assumptions about the passed-in text:
1597 - all comments, labels removed
1598 - text is an instruction
1599 - all white space compressed to single blanks
1600 - all character constants have been replaced with decimal. */
1603 md_assemble (char *textP
)
1605 /* Parsed instruction text, containing NO whitespace: arg[0]->opcode
1606 mnemonic arg[1-3]->operands, with char constants replaced by
1609 /* Number of instruction operands. */
1611 /* Pointer to instruction description. */
1612 struct i960_opcode
*oP
;
1613 /* TRUE iff opcode mnemonic included branch-prediction suffix (".f"
1616 /* Setting of branch-prediction bit(s) to be OR'd into instruction
1617 opcode of CTRL/COBR format instructions. */
1619 /* Offset of last character in opcode mnemonic. */
1621 const char *bp_error_msg
= _("branch prediction invalid on this opcode");
1623 /* Parse instruction into opcode and operands. */
1624 memset (args
, '\0', sizeof (args
));
1626 n_ops
= i_scan (textP
, args
);
1629 return; /* Error message already issued. */
1631 /* Do "macro substitution" (sort of) on 'ldconst' pseudo-instruction. */
1632 if (!strcmp (args
[0], "ldconst"))
1634 n_ops
= parse_ldconst (args
);
1639 /* Check for branch-prediction suffix on opcode mnemonic, strip it off. */
1640 n
= strlen (args
[0]) - 1;
1644 if (args
[0][n
- 1] == '.' && (args
[0][n
] == 't' || args
[0][n
] == 'f'))
1646 /* We could check here to see if the target architecture
1647 supports branch prediction, but why bother? The bit will
1648 just be ignored by processors that don't use it. */
1650 bp_bits
= (args
[0][n
] == 't') ? BP_TAKEN
: BP_NOT_TAKEN
;
1651 args
[0][n
- 1] = '\0'; /* Strip suffix from opcode mnemonic */
1654 /* Look up opcode mnemonic in table and check number of operands.
1655 Check that opcode is legal for the target architecture. If all
1656 looks good, assemble instruction. */
1657 oP
= (struct i960_opcode
*) hash_find (op_hash
, args
[0]);
1658 if (!oP
|| !targ_has_iclass (oP
->iclass
))
1659 as_bad (_("invalid opcode, \"%s\"."), args
[0]);
1660 else if (n_ops
!= oP
->num_ops
)
1661 as_bad (_("improper number of operands. expecting %d, got %d"),
1662 oP
->num_ops
, n_ops
);
1669 ctrl_fmt (args
[1], oP
->opcode
| bp_bits
, oP
->num_ops
);
1670 if (oP
->format
== FBRA
)
1671 /* Now generate a 'bno' to same arg */
1672 ctrl_fmt (args
[1], BNO
| bp_bits
, 1);
1676 cobr_fmt (args
, oP
->opcode
| bp_bits
, oP
);
1680 as_warn (bp_error_msg
);
1684 if (args
[0][0] == 'c' && args
[0][1] == 'a')
1687 as_warn (bp_error_msg
);
1688 mem_fmt (args
, oP
, 1);
1697 as_warn (bp_error_msg
);
1698 mem_fmt (args
, oP
, 0);
1702 as_warn (bp_error_msg
);
1703 /* Output opcode & set up "fixup" (relocation); flag
1704 relocation as 'callj' type. */
1705 know (oP
->num_ops
== 1);
1706 get_cdisp (args
[1], "CTRL", oP
->opcode
, 24, 0, 1);
1709 BAD_CASE (oP
->format
);
1716 md_number_to_chars (char *buf
,
1720 number_to_chars_littleendian (buf
, value
, n
);
1723 #define MAX_LITTLENUMS 6
1724 #define LNUM_SIZE sizeof (LITTLENUM_TYPE)
1726 /* md_atof: convert ascii to floating point
1728 Turn a string at input_line_pointer into a floating point constant of type
1729 'type', and store the appropriate bytes at *litP. The number of LITTLENUMS
1730 emitted is returned at 'sizeP'. An error message is returned, or a pointer
1731 to an empty message if OK.
1733 Note we call the i386 floating point routine, rather than complicating
1734 things with more files or symbolic links. */
1737 md_atof (int type
, char *litP
, int *sizeP
)
1739 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1740 LITTLENUM_TYPE
*wordP
;
1759 type
= 'x'; /* That's what atof_ieee() understands. */
1764 return _("Bad call to md_atof()");
1767 t
= atof_ieee (input_line_pointer
, type
, words
);
1769 input_line_pointer
= t
;
1771 *sizeP
= prec
* LNUM_SIZE
;
1773 /* Output the LITTLENUMs in REVERSE order in accord with i80960
1774 word-order. (Dunno why atof_ieee doesn't do it in the right
1775 order in the first place -- probably because it's a hack of
1777 for (wordP
= words
+ prec
- 1; prec
--;)
1779 md_number_to_chars (litP
, (long) (*wordP
--), LNUM_SIZE
);
1780 litP
+= sizeof (LITTLENUM_TYPE
);
1787 md_number_to_imm (char *buf
, long val
, int n
)
1789 md_number_to_chars (buf
, val
, n
);
1793 md_number_to_field (char *instrP
, /* Pointer to instruction to be fixed. */
1794 long val
, /* Address fixup value. */
1795 bit_fixS
*bfixP
) /* Description of bit field to be fixed up. */
1797 int numbits
; /* Length of bit field to be fixed. */
1798 long instr
; /* 32-bit instruction to be fixed-up. */
1799 long sign
; /* 0 or -1, according to sign bit of 'val'. */
1801 /* Convert instruction back to host byte order. */
1802 instr
= md_chars_to_number (instrP
, 4);
1804 /* Surprise! -- we stored the number of bits to be modified rather
1805 than a pointer to a structure. */
1806 numbits
= (int) (size_t) bfixP
;
1808 /* This is a no-op, stuck here by reloc_callj(). */
1811 know ((numbits
== 13) || (numbits
== 24));
1813 /* Propagate sign bit of 'val' for the given number of bits. Result
1814 should be all 0 or all 1. */
1815 sign
= val
>> ((int) numbits
- 1);
1816 if (((val
< 0) && (sign
!= -1))
1817 || ((val
> 0) && (sign
!= 0)))
1818 as_bad (_("Fixup of %ld too large for field width of %d"),
1822 /* Put bit field into instruction and write back in target
1824 val
&= ~(-1 << (int) numbits
); /* Clear unused sign bits. */
1826 md_number_to_chars (instrP
, instr
, 4);
1832 Invocation line includes a switch not recognized by the base assembler.
1833 See if it's a processor-specific option. For the 960, these are:
1836 Conditional branch instructions that require displacements
1837 greater than 13 bits (or that have external targets) should
1838 generate errors. The default is to replace each such
1839 instruction with the corresponding compare (or chkbit) and
1840 branch instructions. Note that the Intel "j" cobr directives
1841 are ALWAYS "de-optimized" in this way when necessary,
1842 regardless of the setting of this option.
1845 Add code to collect information about branches taken, for
1846 later optimization of branch prediction bits by a separate
1847 tool. COBR and CNTL format instructions have branch
1848 prediction bits (in the CX architecture); if "BR" represents
1849 an instruction in one of these classes, the following rep-
1850 resents the code generated by the assembler:
1852 call <increment routine>
1853 .word 0 # pre-counter
1855 call <increment routine>
1856 .word 0 # post-counter
1858 A table of all such "Labels" is also generated.
1860 -AKA, -AKB, -AKC, -ASA, -ASB, -AMC, -ACA:
1861 Select the 80960 architecture. Instructions or features not
1862 supported by the selected architecture cause fatal errors.
1863 The default is to generate code for any instruction or feature
1864 that is supported by SOME version of the 960 (even if this
1865 means mixing architectures!). */
1867 const char *md_shortopts
= "A:b";
1868 struct option md_longopts
[] =
1870 #define OPTION_LINKRELAX (OPTION_MD_BASE)
1871 {"linkrelax", no_argument
, NULL
, OPTION_LINKRELAX
},
1872 {"link-relax", no_argument
, NULL
, OPTION_LINKRELAX
},
1873 #define OPTION_NORELAX (OPTION_MD_BASE + 1)
1874 {"norelax", no_argument
, NULL
, OPTION_NORELAX
},
1875 {"no-relax", no_argument
, NULL
, OPTION_NORELAX
},
1876 {NULL
, no_argument
, NULL
, 0}
1878 size_t md_longopts_size
= sizeof (md_longopts
);
1885 static const struct tabentry arch_tab
[] =
1889 {"SA", ARCH_KA
}, /* Synonym for KA. */
1890 {"SB", ARCH_KB
}, /* Synonym for KB. */
1891 {"KC", ARCH_MC
}, /* Synonym for MC. */
1900 md_parse_option (int c
, char *arg
)
1904 case OPTION_LINKRELAX
:
1906 flag_keep_locals
= 1;
1909 case OPTION_NORELAX
:
1914 instrument_branches
= 1;
1919 const struct tabentry
*tp
;
1922 for (tp
= arch_tab
; tp
->flag
!= NULL
; tp
++)
1923 if (!strcmp (p
, tp
->flag
))
1926 if (tp
->flag
== NULL
)
1928 as_bad (_("invalid architecture %s"), p
);
1932 architecture
= tp
->arch
;
1944 md_show_usage (FILE *stream
)
1948 fprintf (stream
, _("I960 options:\n"));
1949 for (i
= 0; arch_tab
[i
].flag
; i
++)
1950 fprintf (stream
, "%s-A%s", i
? " | " : "", arch_tab
[i
].flag
);
1951 fprintf (stream
, _("\n\
1952 specify variant of 960 architecture\n\
1953 -b add code to collect statistics about branches taken\n\
1954 -link-relax preserve individual alignment directives so linker\n\
1955 can do relaxing (b.out format only)\n\
1956 -no-relax don't alter compare-and-branch instructions for\n\
1957 long displacements\n"));
1961 Replace cobr instruction in a code fragment with equivalent branch and
1962 compare instructions, so it can reach beyond a 13-bit displacement.
1963 Set up an address fix/relocation for the new branch instruction. */
1965 /* This "conditional jump" table maps cobr instructions into
1966 equivalent compare and branch opcodes. */
1976 { /* COBR OPCODE: */
1977 { CHKBIT
, BNO
}, /* 0x30 - bbc */
1978 { CMPO
, BG
}, /* 0x31 - cmpobg */
1979 { CMPO
, BE
}, /* 0x32 - cmpobe */
1980 { CMPO
, BGE
}, /* 0x33 - cmpobge */
1981 { CMPO
, BL
}, /* 0x34 - cmpobl */
1982 { CMPO
, BNE
}, /* 0x35 - cmpobne */
1983 { CMPO
, BLE
}, /* 0x36 - cmpoble */
1984 { CHKBIT
, BO
}, /* 0x37 - bbs */
1985 { CMPI
, BNO
}, /* 0x38 - cmpibno */
1986 { CMPI
, BG
}, /* 0x39 - cmpibg */
1987 { CMPI
, BE
}, /* 0x3a - cmpibe */
1988 { CMPI
, BGE
}, /* 0x3b - cmpibge */
1989 { CMPI
, BL
}, /* 0x3c - cmpibl */
1990 { CMPI
, BNE
}, /* 0x3d - cmpibne */
1991 { CMPI
, BLE
}, /* 0x3e - cmpible */
1992 { CMPI
, BO
}, /* 0x3f - cmpibo */
1996 relax_cobr (fragS
*fragP
) /* fragP->fr_opcode is assumed to point to
1997 the cobr instruction, which comes at the
1998 end of the code fragment. */
2000 int opcode
, src1
, src2
, m1
, s2
;
2001 /* Bit fields from cobr instruction. */
2002 long bp_bits
; /* Branch prediction bits from cobr instruction. */
2003 long instr
; /* A single i960 instruction. */
2004 /* ->instruction to be replaced. */
2006 fixS
*fixP
; /* Relocation that can be done at assembly time. */
2008 /* Pick up & parse cobr instruction. */
2009 iP
= fragP
->fr_opcode
;
2010 instr
= md_chars_to_number (iP
, 4);
2011 opcode
= ((instr
>> 24) & 0xff) - 0x30; /* "-0x30" for table index. */
2012 src1
= (instr
>> 19) & 0x1f;
2013 m1
= (instr
>> 13) & 1;
2015 src2
= (instr
>> 14) & 0x1f;
2016 bp_bits
= instr
& BP_MASK
;
2018 /* Generate and output compare instruction. */
2019 instr
= coj
[opcode
].compare
2020 | src1
| (m1
<< 11) | (s2
<< 6) | (src2
<< 14);
2021 md_number_to_chars (iP
, instr
, 4);
2023 /* Output branch instruction. */
2024 md_number_to_chars (iP
+ 4, coj
[opcode
].branch
| bp_bits
, 4);
2026 /* Set up address fixup/relocation. */
2027 fixP
= fix_new (fragP
,
2028 iP
+ 4 - fragP
->fr_literal
,
2035 fixP
->fx_bit_fixP
= (bit_fixS
*) 24; /* Store size of bit field. */
2043 Called by base assembler after address relaxation is finished: modify
2044 variable fragments according to how much relaxation was done.
2046 If the fragment substate is still 1, a 13-bit displacement was enough
2047 to reach the symbol in question. Set up an address fixup, but otherwise
2048 leave the cobr instruction alone.
2050 If the fragment substate is 2, a 13-bit displacement was not enough.
2051 Replace the cobr with a two instructions (a compare and a branch). */
2053 #ifndef BFD_ASSEMBLER
2055 md_convert_frag (object_headers
*headers ATTRIBUTE_UNUSED
,
2056 segT seg ATTRIBUTE_UNUSED
,
2060 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2061 segT sec ATTRIBUTE_UNUSED
,
2065 /* Structure describing needed address fix. */
2068 switch (fragP
->fr_subtype
)
2071 /* Leave single cobr instruction. */
2072 fixP
= fix_new (fragP
,
2073 fragP
->fr_opcode
- fragP
->fr_literal
,
2080 fixP
->fx_bit_fixP
= (bit_fixS
*) 13; /* Size of bit field. */
2083 /* Replace cobr with compare/branch instructions. */
2087 BAD_CASE (fragP
->fr_subtype
);
2092 /* md_estimate_size_before_relax: How much does it look like *fragP will grow?
2094 Called by base assembler just before address relaxation.
2095 Return the amount by which the fragment will grow.
2097 Any symbol that is now undefined will not become defined; cobr's
2098 based on undefined symbols will have to be replaced with a compare
2099 instruction and a branch instruction, and the code fragment will grow
2103 md_estimate_size_before_relax (fragS
*fragP
, segT segment_type
)
2105 /* If symbol is undefined in this segment, go to "relaxed" state
2106 (compare and branch instructions instead of cobr) right now. */
2107 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment_type
)
2113 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2116 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2119 This routine exists in order to overcome machine byte-order problems
2120 when dealing with bit-field entries in the relocation_info struct.
2122 But relocation info will be used on the host machine only (only
2123 executable code is actually downloaded to the i80960). Therefore,
2124 we leave it in host byte order. */
2127 md_ri_to_chars (char *where
, struct relocation_info
*ri
)
2129 host_number_to_chars (where
, ri
->r_address
, 4);
2130 host_number_to_chars (where
+ 4, ri
->r_index
, 3);
2132 where
[7] = (ri
->r_pcrel
<< 7
2140 where
[7] = (ri
->r_pcrel
<< 0
2150 #endif /* defined(OBJ_AOUT) | defined(OBJ_BOUT) */
2153 /* brtab_emit: generate the fetch-prediction branch table.
2155 See the comments above the declaration of 'br_cnt' for details on
2156 branch-prediction instrumentation.
2158 The code emitted here would be functionally equivalent to the following
2159 example assembler source.
2164 .word 0 # link to next table
2165 .word 3 # length of table
2166 .word LBRANCH0 # 1st entry in table proper
2175 /* Where the binary was output to. */
2177 /* Pointer to description of deferred address fixup. */
2180 if (!instrument_branches
)
2183 subseg_set (data_section
, 0); /* .data */
2184 frag_align (2, 0, 0); /* .align 2 */
2185 record_alignment (now_seg
, 2);
2186 colon (BR_TAB_NAME
); /* BR_TAB_NAME: */
2187 emit (0); /* .word 0 #link to next table */
2188 emit (br_cnt
); /* .word n #length of table */
2190 for (i
= 0; i
< br_cnt
; i
++)
2192 sprintf (buf
, "%s%d", BR_LABEL_BASE
, i
);
2194 fixP
= fix_new (frag_now
,
2195 p
- frag_now
->fr_literal
,
2196 4, symbol_find (buf
), 0, 0, NO_RELOC
);
2200 /* s_leafproc: process .leafproc pseudo-op
2202 .leafproc takes two arguments, the second one is optional:
2203 arg[1]: name of 'call' entry point to leaf procedure
2204 arg[2]: name of 'bal' entry point to leaf procedure
2206 If the two arguments are identical, or if the second one is missing,
2207 the first argument is taken to be the 'bal' entry point.
2209 If there are 2 distinct arguments, we must make sure that the 'bal'
2210 entry point immediately follows the 'call' entry point in the linked
2214 s_leafproc (int n_ops
, /* Number of operands. */
2215 char *args
[]) /* args[1]->1st operand, args[2]->2nd operand. */
2217 symbolS
*callP
; /* Pointer to leafproc 'call' entry point symbol. */
2218 symbolS
*balP
; /* Pointer to leafproc 'bal' entry point symbol. */
2220 if ((n_ops
!= 1) && (n_ops
!= 2))
2222 as_bad (_("should have 1 or 2 operands"));
2226 /* Find or create symbol for 'call' entry point. */
2227 callP
= symbol_find_or_make (args
[1]);
2229 if (TC_S_IS_CALLNAME (callP
))
2230 as_warn (_("Redefining leafproc %s"), S_GET_NAME (callP
));
2232 /* If that was the only argument, use it as the 'bal' entry point.
2233 Otherwise, mark it as the 'call' entry point and find or create
2234 another symbol for the 'bal' entry point. */
2235 if ((n_ops
== 1) || !strcmp (args
[1], args
[2]))
2237 TC_S_FORCE_TO_BALNAME (callP
);
2241 TC_S_FORCE_TO_CALLNAME (callP
);
2243 balP
= symbol_find_or_make (args
[2]);
2244 if (TC_S_IS_CALLNAME (balP
))
2245 as_warn (_("Redefining leafproc %s"), S_GET_NAME (balP
));
2247 TC_S_FORCE_TO_BALNAME (balP
);
2250 tc_set_bal_of_call (callP
, balP
);
2255 /* s_sysproc: process .sysproc pseudo-op
2257 .sysproc takes two arguments:
2258 arg[1]: name of entry point to system procedure
2259 arg[2]: 'entry_num' (index) of system procedure in the range
2262 For [ab].out, we store the 'entrynum' in the 'n_other' field of
2263 the symbol. Since that entry is normally 0, we bias 'entrynum'
2264 by adding 1 to it. It must be unbiased before it is used. */
2267 s_sysproc (int n_ops
, /* Number of operands. */
2268 char *args
[]) /* args[1]->1st operand, args[2]->2nd operand. */
2275 as_bad (_("should have two operands"));
2279 /* Parse "entry_num" argument and check it for validity. */
2280 parse_expr (args
[2], &exp
);
2281 if (exp
.X_op
!= O_constant
2283 || (offs (exp
) > 31))
2285 as_bad (_("'entry_num' must be absolute number in [0,31]"));
2289 /* Find/make symbol and stick entry number (biased by +1) into it. */
2290 symP
= symbol_find_or_make (args
[1]);
2292 if (TC_S_IS_SYSPROC (symP
))
2293 as_warn (_("Redefining entrynum for sysproc %s"), S_GET_NAME (symP
));
2295 TC_S_SET_SYSPROC (symP
, offs (exp
)); /* Encode entry number. */
2296 TC_S_FORCE_TO_SYSPROC (symP
);
2299 /* parse_po: parse machine-dependent pseudo-op
2301 This is a top-level routine for machine-dependent pseudo-ops. It slurps
2302 up the rest of the input line, breaks out the individual arguments,
2303 and dispatches them to the correct handler. */
2306 parse_po (int po_num
) /* Pseudo-op number: currently S_LEAFPROC or S_SYSPROC. */
2308 /* Pointers operands, with no embedded whitespace.
2309 arg[0] unused, arg[1-3]->operands. */
2311 int n_ops
; /* Number of operands. */
2312 char *p
; /* Pointer to beginning of unparsed argument string. */
2313 char eol
; /* Character that indicated end of line. */
2315 extern char is_end_of_line
[];
2317 /* Advance input pointer to end of line. */
2318 p
= input_line_pointer
;
2319 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2320 input_line_pointer
++;
2322 eol
= *input_line_pointer
; /* Save end-of-line char. */
2323 *input_line_pointer
= '\0'; /* Terminate argument list. */
2325 /* Parse out operands. */
2326 n_ops
= get_args (p
, args
);
2330 /* Dispatch to correct handler. */
2334 s_sysproc (n_ops
, args
);
2337 s_leafproc (n_ops
, args
);
2344 /* Restore eol, so line numbers get updated correctly. Base
2345 assembler assumes we leave input pointer pointing at char
2346 following the eol. */
2347 *input_line_pointer
++ = eol
;
2350 /* reloc_callj: Relocate a 'callj' instruction
2352 This is a "non-(GNU)-standard" machine-dependent hook. The base
2353 assembler calls it when it decides it can relocate an address at
2354 assembly time instead of emitting a relocation directive.
2356 Check to see if the relocation involves a 'callj' instruction to a:
2357 sysproc: Replace the default 'call' instruction with a 'calls'
2358 leafproc: Replace the default 'call' instruction with a 'bal'.
2359 other proc: Do nothing.
2361 See b.out.h for details on the 'n_other' field in a symbol structure.
2364 Assumes the caller has already figured out, in the case of a leafproc,
2365 to use the 'bal' entry point, and has substituted that symbol into the
2366 passed fixup structure. */
2369 reloc_callj (fixS
*fixP
) /* Relocation that can be done at assembly time. */
2371 /* Points to the binary for the instruction being relocated. */
2374 if (!fixP
->fx_tcbit
)
2375 /* This wasn't a callj instruction in the first place. */
2378 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2380 if (TC_S_IS_SYSPROC (fixP
->fx_addsy
))
2382 /* Symbol is a .sysproc: replace 'call' with 'calls'. System
2383 procedure number is (other-1). */
2384 md_number_to_chars (where
, CALLS
| TC_S_GET_SYSPROC (fixP
->fx_addsy
), 4);
2386 /* Nothing else needs to be done for this instruction. Make
2387 sure 'md_number_to_field()' will perform a no-op. */
2388 fixP
->fx_bit_fixP
= (bit_fixS
*) 1;
2390 else if (TC_S_IS_CALLNAME (fixP
->fx_addsy
))
2392 /* Should not happen: see block comment above. */
2393 as_fatal (_("Trying to 'bal' to %s"), S_GET_NAME (fixP
->fx_addsy
));
2395 else if (TC_S_IS_BALNAME (fixP
->fx_addsy
))
2397 /* Replace 'call' with 'bal'; both instructions have the same
2398 format, so calling code should complete relocation as if
2399 nothing happened here. */
2400 md_number_to_chars (where
, BAL
, 4);
2402 else if (TC_S_IS_BADPROC (fixP
->fx_addsy
))
2403 as_bad (_("Looks like a proc, but can't tell what kind.\n"));
2405 /* Otherwise Symbol is neither a sysproc nor a leafproc. */
2409 /* Handle the MRI .endian pseudo-op. */
2412 s_endian (int ignore ATTRIBUTE_UNUSED
)
2417 name
= input_line_pointer
;
2418 c
= get_symbol_end ();
2419 if (strcasecmp (name
, "little") == 0)
2421 else if (strcasecmp (name
, "big") == 0)
2422 as_bad (_("big endian mode is not supported"));
2424 as_warn (_("ignoring unrecognized .endian type `%s'"), name
);
2426 *input_line_pointer
= c
;
2428 demand_empty_rest_of_line ();
2431 /* We have no need to default values of symbols. */
2434 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2439 /* Exactly what point is a PC-relative offset relative TO?
2440 On the i960, they're relative to the address of the instruction,
2441 which we have set up as the address of the fixup too. */
2443 md_pcrel_from (fixS
*fixP
)
2445 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2449 md_apply_fix3 (fixS
*fixP
,
2451 segT seg ATTRIBUTE_UNUSED
)
2454 char *place
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2456 if (!fixP
->fx_bit_fixP
)
2458 #ifndef BFD_ASSEMBLER
2459 /* For callx, we always want to write out zero, and emit a
2460 symbolic relocation. */
2464 fixP
->fx_addnumber
= val
;
2467 md_number_to_imm (place
, val
, fixP
->fx_size
);
2469 else if ((int) (size_t) fixP
->fx_bit_fixP
== 13
2470 && fixP
->fx_addsy
!= NULL
2471 && S_GET_SEGMENT (fixP
->fx_addsy
) == undefined_section
)
2473 /* This is a COBR instruction. They have only a
2474 13-bit displacement and are only to be used
2475 for local branches: flag as error, don't generate
2477 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2478 _("can't use COBR format with external label"));
2479 fixP
->fx_addsy
= NULL
;
2482 md_number_to_field (place
, val
, fixP
->fx_bit_fixP
);
2484 if (fixP
->fx_addsy
== NULL
)
2488 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2490 tc_bout_fix_to_chars (char *where
,
2492 relax_addressT segment_address_in_file
)
2494 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
2495 struct relocation_info ri
;
2498 memset ((char *) &ri
, '\0', sizeof (ri
));
2499 symbolP
= fixP
->fx_addsy
;
2500 know (symbolP
!= 0 || fixP
->fx_r_type
!= NO_RELOC
);
2501 ri
.r_bsr
= fixP
->fx_bsr
; /*SAC LD RELAX HACK */
2502 /* These two 'cuz of NS32K */
2503 ri
.r_callj
= fixP
->fx_tcbit
;
2504 if (fixP
->fx_bit_fixP
)
2507 ri
.r_length
= nbytes_r_length
[fixP
->fx_size
];
2508 ri
.r_pcrel
= fixP
->fx_pcrel
;
2509 ri
.r_address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
;
2511 if (fixP
->fx_r_type
!= NO_RELOC
)
2513 switch (fixP
->fx_r_type
)
2518 ri
.r_length
= fixP
->fx_size
- 1;
2532 else if (linkrelax
|| !S_IS_DEFINED (symbolP
) || fixP
->fx_bsr
)
2535 ri
.r_index
= symbolP
->sy_number
;
2540 ri
.r_index
= S_GET_TYPE (symbolP
);
2543 /* Output the relocation information in machine-dependent form. */
2544 md_ri_to_chars (where
, &ri
);
2547 #endif /* OBJ_AOUT or OBJ_BOUT */
2549 #if defined (OBJ_COFF) && defined (BFD)
2551 tc_coff_fix2rtype (fixS
*fixP
)
2556 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
2559 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
2567 tc_coff_sizemachdep (fragS
*frag
)
2570 return frag
->fr_next
->fr_address
- frag
->fr_address
;
2576 /* Align an address by rounding it up to the specified boundary. */
2579 md_section_align (segT seg
,
2580 valueT addr
) /* Address to be rounded up. */
2584 #ifdef BFD_ASSEMBLER
2585 align
= bfd_get_section_alignment (stdoutput
, seg
);
2587 align
= section_alignment
[(int) seg
];
2589 return (addr
+ (1 << align
) - 1) & (-1 << align
);
2592 extern int coff_flags
;
2596 tc_headers_hook (object_headers
*headers
)
2598 switch (architecture
)
2601 coff_flags
|= F_I960KA
;
2605 coff_flags
|= F_I960KB
;
2609 coff_flags
|= F_I960MC
;
2613 coff_flags
|= F_I960CA
;
2617 coff_flags
|= F_I960JX
;
2621 coff_flags
|= F_I960HX
;
2625 if (iclasses_seen
== I_BASE
)
2626 coff_flags
|= F_I960CORE
;
2627 else if (iclasses_seen
& I_CX
)
2628 coff_flags
|= F_I960CA
;
2629 else if (iclasses_seen
& I_HX
)
2630 coff_flags
|= F_I960HX
;
2631 else if (iclasses_seen
& I_JX
)
2632 coff_flags
|= F_I960JX
;
2633 else if (iclasses_seen
& I_CX2
)
2634 coff_flags
|= F_I960CA
;
2635 else if (iclasses_seen
& I_MIL
)
2636 coff_flags
|= F_I960MC
;
2637 else if (iclasses_seen
& (I_DEC
| I_FP
))
2638 coff_flags
|= F_I960KB
;
2640 coff_flags
|= F_I960KA
;
2644 if (flag_readonly_data_in_text
)
2646 headers
->filehdr
.f_magic
= I960RWMAGIC
;
2647 headers
->aouthdr
.magic
= OMAGIC
;
2651 headers
->filehdr
.f_magic
= I960ROMAGIC
;
2652 headers
->aouthdr
.magic
= NMAGIC
;
2653 } /* set magic numbers */
2656 #endif /* OBJ_COFF */
2658 #ifndef BFD_ASSEMBLER
2660 /* Things going on here:
2662 For bout, We need to assure a couple of simplifying
2663 assumptions about leafprocs for the linker: the leafproc
2664 entry symbols will be defined in the same assembly in
2665 which they're declared with the '.leafproc' directive;
2666 and if a leafproc has both 'call' and 'bal' entry points
2667 they are both global or both local.
2669 For coff, the call symbol has a second aux entry that
2670 contains the bal entry point. The bal symbol becomes a
2673 For coff representation, the call symbol has a second aux entry that
2674 contains the bal entry point. The bal symbol becomes a label. */
2677 tc_crawl_symbol_chain (object_headers
*headers ATTRIBUTE_UNUSED
)
2681 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2684 if (TC_S_IS_SYSPROC (symbolP
))
2686 /* Second aux entry already contains the sysproc number. */
2687 S_SET_NUMBER_AUXILIARY (symbolP
, 2);
2688 S_SET_STORAGE_CLASS (symbolP
, C_SCALL
);
2689 S_SET_DATA_TYPE (symbolP
, S_GET_DATA_TYPE (symbolP
) | (DT_FCN
<< N_BTSHFT
));
2692 #endif /* OBJ_COFF */
2694 if (!TC_S_IS_BALNAME (symbolP
) && !TC_S_IS_CALLNAME (symbolP
))
2697 if (!S_IS_DEFINED (symbolP
))
2698 as_bad (_("leafproc symbol '%s' undefined"), S_GET_NAME (symbolP
));
2700 if (TC_S_IS_CALLNAME (symbolP
))
2702 symbolS
*balP
= tc_get_bal_of_call (symbolP
);
2704 if (S_IS_EXTERNAL (symbolP
) != S_IS_EXTERNAL (balP
))
2706 S_SET_EXTERNAL (symbolP
);
2707 S_SET_EXTERNAL (balP
);
2708 as_warn (_("Warning: making leafproc entries %s and %s both global\n"),
2709 S_GET_NAME (symbolP
), S_GET_NAME (balP
));
2710 } /* externality mismatch */
2712 } /* walk the symbol chain */
2715 #endif /* ! BFD_ASSEMBLER */
2717 /* For aout or bout, the bal immediately follows the call.
2719 For coff, we cheat and store a pointer to the bal symbol in the
2720 second aux entry of the call. */
2731 tc_set_bal_of_call (symbolS
*callP ATTRIBUTE_UNUSED
,
2732 symbolS
*balP ATTRIBUTE_UNUSED
)
2734 know (TC_S_IS_CALLNAME (callP
));
2735 know (TC_S_IS_BALNAME (balP
));
2739 callP
->sy_tc
= balP
;
2740 S_SET_NUMBER_AUXILIARY (callP
, 2);
2742 #else /* ! OBJ_COFF */
2745 /* If the 'bal' entry doesn't immediately follow the 'call'
2746 symbol, unlink it from the symbol list and re-insert it. */
2747 if (symbol_next (callP
) != balP
)
2749 symbol_remove (balP
, &symbol_rootP
, &symbol_lastP
);
2750 symbol_append (balP
, callP
, &symbol_rootP
, &symbol_lastP
);
2751 } /* if not in order */
2753 #else /* ! OBJ_ABOUT */
2754 as_fatal ("Only supported for a.out, b.out, or COFF");
2755 #endif /* ! OBJ_ABOUT */
2756 #endif /* ! OBJ_COFF */
2760 tc_get_bal_of_call (symbolS
*callP ATTRIBUTE_UNUSED
)
2764 know (TC_S_IS_CALLNAME (callP
));
2767 retval
= callP
->sy_tc
;
2770 retval
= symbol_next (callP
);
2772 as_fatal ("Only supported for a.out, b.out, or COFF");
2773 #endif /* ! OBJ_ABOUT */
2774 #endif /* ! OBJ_COFF */
2776 know (TC_S_IS_BALNAME (retval
));
2782 tc_coff_symbol_emit_hook (symbolS
*symbolP ATTRIBUTE_UNUSED
)
2784 if (TC_S_IS_CALLNAME (symbolP
))
2786 symbolS
*balP
= tc_get_bal_of_call (symbolP
);
2788 symbolP
->sy_symbol
.ost_auxent
[1].x_bal
.x_balntry
= S_GET_VALUE (balP
);
2789 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2790 S_SET_STORAGE_CLASS (symbolP
, C_LEAFEXT
);
2792 S_SET_STORAGE_CLASS (symbolP
, C_LEAFSTAT
);
2793 S_SET_DATA_TYPE (symbolP
, S_GET_DATA_TYPE (symbolP
) | (DT_FCN
<< N_BTSHFT
));
2794 /* Fix up the bal symbol. */
2795 S_SET_STORAGE_CLASS (balP
, C_LABEL
);
2798 #endif /* OBJ_COFF */
2801 i960_handle_align (fragS
*fragp ATTRIBUTE_UNUSED
)
2807 as_bad (_("option --link-relax is only supported in b.out format"));
2812 /* The text section "ends" with another alignment reloc, to which we
2813 aren't adding padding. */
2814 if (fragp
->fr_next
== text_last_frag
2815 || fragp
->fr_next
== data_last_frag
)
2818 /* alignment directive */
2819 fix_new (fragp
, fragp
->fr_fix
, fragp
->fr_offset
, 0, 0, 0,
2820 (int) fragp
->fr_type
);
2821 #endif /* OBJ_BOUT */
2825 i960_validate_fix (fixS
*fixP
, segT this_segment_type ATTRIBUTE_UNUSED
)
2827 if (fixP
->fx_tcbit
&& TC_S_IS_CALLNAME (fixP
->fx_addsy
))
2829 /* Relocation should be done via the associated 'bal'
2830 entry point symbol. */
2831 if (!TC_S_IS_BALNAME (tc_get_bal_of_call (fixP
->fx_addsy
)))
2833 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2834 _("No 'bal' entry point for leafproc %s"),
2835 S_GET_NAME (fixP
->fx_addsy
));
2838 fixP
->fx_addsy
= tc_get_bal_of_call (fixP
->fx_addsy
);
2844 #ifdef BFD_ASSEMBLER
2849 tc_bfd_fix2rtype (fixS
*fixP
)
2851 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
2852 return BFD_RELOC_32
;
2854 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
2855 return BFD_RELOC_24_PCREL
;
2861 /* Translate internal representation of relocation info to BFD target
2864 FIXME: To what extent can we get all relevant targets to use this? */
2867 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixP
)
2871 reloc
= xmalloc (sizeof (arelent
));
2873 /* HACK: Is this right? */
2874 fixP
->fx_r_type
= tc_bfd_fix2rtype (fixP
);
2876 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
2877 if (reloc
->howto
== NULL
)
2879 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2880 "internal error: can't export reloc type %d (`%s')",
2882 bfd_get_reloc_code_name (fixP
->fx_r_type
));
2886 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
2888 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2889 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
2890 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2891 reloc
->addend
= fixP
->fx_addnumber
;
2896 /* end from cgen.c */
2898 #endif /* BFD_ASSEMBLER */
2900 const pseudo_typeS md_pseudo_table
[] =
2902 {"bss", s_lcomm
, 1},
2903 {"endian", s_endian
, 0},
2904 {"extended", float_cons
, 't'},
2905 {"leafproc", parse_po
, S_LEAFPROC
},
2906 {"sysproc", parse_po
, S_SYSPROC
},