RIP gzip, we found a nicer playmate.
[dragonfly.git] / gnu / usr.bin / as / config / tc-i960.h
1 /* tc-i960.h - Basic 80960 instruction formats.
2    Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4    This file is part of GAS, the GNU Assembler.
5
6    GAS is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as
8    published by the Free Software Foundation; either version 2,
9    or (at your option) any later version.
10
11    GAS is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14    the GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public
17    License along with GAS; see the file COPYING.  If not, write
18    to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #ifndef TC_I960
21 #define TC_I960 1
22
23 #define NO_LISTING
24
25 /*
26  * The 'COJ' instructions are actually COBR instructions with the 'b' in
27  * the mnemonic replaced by a 'j';  they are ALWAYS "de-optimized" if necessary:
28  * if the displacement will not fit in 13 bits, the assembler will replace them
29  * with the corresponding compare and branch instructions.
30  *
31  * All of the 'MEMn' instructions are the same format; the 'n' in the name
32  * indicates the default index scale factor (the size of the datum operated on).
33  *
34  * The FBRA formats are not actually an instruction format.  They are the
35  * "convenience directives" for branching on floating-point comparisons,
36  * each of which generates 2 instructions (a 'bno' and one other branch).
37  *
38  * The CALLJ format is not actually an instruction format.  It indicates that
39  * the instruction generated (a CTRL-format 'call') should have its relocation
40  * specially flagged for link-time replacement with a 'bal' or 'calls' if
41  * appropriate.
42  */
43
44 /* tailor gas */
45 #define SYMBOLS_NEED_BACKPOINTERS
46 #define LOCAL_LABELS_FB
47 #define WANT_BITFIELDS
48
49 /* tailor the coff format */
50 #define OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT
51 #define OBJ_COFF_MAX_AUXENTRIES (2)
52
53 /* other */
54 #define CTRL    0
55 #define COBR    1
56 #define COJ     2
57 #define REG     3
58 #define MEM1    4
59 #define MEM2    5
60 #define MEM4    6
61 #define MEM8    7
62 #define MEM12   8
63 #define MEM16   9
64 #define FBRA    10
65 #define CALLJ   11
66
67 /* Masks for the mode bits in REG format instructions */
68 #define M1              0x0800
69 #define M2              0x1000
70 #define M3              0x2000
71
72 /* Generate the 12-bit opcode for a REG format instruction by placing the
73  * high 8 bits in instruction bits 24-31, the low 4 bits in instruction bits
74  * 7-10.
75  */
76
77 #define REG_OPC(opc)    ((opc & 0xff0) << 20) | ((opc & 0xf) << 7)
78
79 /* Generate a template for a REG format instruction:  place the opcode bits
80  * in the appropriate fields and OR in mode bits for the operands that will not
81  * be used.  I.e.,
82  *              set m1=1, if src1 will not be used
83  *              set m2=1, if src2 will not be used
84  *              set m3=1, if dst  will not be used
85  *
86  * Setting the "unused" mode bits to 1 speeds up instruction execution(!).
87  * The information is also useful to us because some 1-operand REG instructions
88  * use the src1 field, others the dst field; and some 2-operand REG instructions
89  * use src1/src2, others src1/dst.  The set mode bits enable us to distinguish.
90  */
91 #define R_0(opc)        ( REG_OPC(opc) | M1 | M2 | M3 ) /* No operands      */
92 #define R_1(opc)        ( REG_OPC(opc) | M2 | M3 )      /* 1 operand: src1  */
93 #define R_1D(opc)       ( REG_OPC(opc) | M1 | M2 )      /* 1 operand: dst   */
94 #define R_2(opc)        ( REG_OPC(opc) | M3 )           /* 2 ops: src1/src2 */
95 #define R_2D(opc)       ( REG_OPC(opc) | M2 )           /* 2 ops: src1/dst  */
96 #define R_3(opc)        ( REG_OPC(opc) )                /* 3 operands       */
97
98 /* DESCRIPTOR BYTES FOR REGISTER OPERANDS
99  *
100  * Interpret names as follows:
101  *      R:   global or local register only
102  *      RS:  global, local, or (if target allows) special-function register only
103  *      RL:  global or local register, or integer literal
104  *      RSL: global, local, or (if target allows) special-function register;
105  *              or integer literal
106  *      F:   global, local, or floating-point register
107  *      FL:  global, local, or floating-point register; or literal (including
108  *              floating point)
109  *
110  * A number appended to a name indicates that registers must be aligned,
111  * as follows:
112  *      2: register number must be multiple of 2
113  *      4: register number must be multiple of 4
114  */
115
116 #define SFR     0x10            /* Mask for the "sfr-OK" bit */
117 #define LIT     0x08            /* Mask for the "literal-OK" bit */
118 #define FP      0x04            /* Mask for "floating-point-OK" bit */
119
120 /* This macro ors the bits together.  Note that 'align' is a mask
121  * for the low 0, 1, or 2 bits of the register number, as appropriate.
122  */
123 #define OP(align,lit,fp,sfr)    ( align | lit | fp | sfr )
124
125 #define R       OP( 0, 0,   0,  0   )
126 #define RS      OP( 0, 0,   0,  SFR )
127 #define RL      OP( 0, LIT, 0,  0   )
128 #define RSL     OP( 0, LIT, 0,  SFR )
129 #define F       OP( 0, 0,   FP, 0   )
130 #define FL      OP( 0, LIT, FP, 0   )
131 #define R2      OP( 1, 0,   0,  0   )
132 #define RL2     OP( 1, LIT, 0,  0   )
133 #define F2      OP( 1, 0,   FP, 0   )
134 #define FL2     OP( 1, LIT, FP, 0   )
135 #define R4      OP( 3, 0,   0,  0   )
136 #define RL4     OP( 3, LIT, 0,  0   )
137 #define F4      OP( 3, 0,   FP, 0   )
138 #define FL4     OP( 3, LIT, FP, 0   )
139
140 #define M       0x7f    /* Memory operand (MEMA & MEMB format instructions) */
141
142 /* Macros to extract info from the register operand descriptor byte 'od'.
143  */
144 #define SFR_OK(od)      (od & SFR)      /* TRUE if sfr operand allowed */
145 #define LIT_OK(od)      (od & LIT)      /* TRUE if literal operand allowed */
146 #define FP_OK(od)       (od & FP)       /* TRUE if floating-point op allowed */
147 #define REG_ALIGN(od,n) ((od & 0x3 & n) == 0)
148 /* TRUE if reg #n is properly aligned */
149 #define MEMOP(od)       (od == M)       /* TRUE if operand is a memory operand*/
150
151 /* Classes of 960 intructions:
152  *      - each instruction falls into one class.
153  *      - each target architecture supports one or more classes.
154  *
155  * EACH CONSTANT MUST CONTAIN 1 AND ONLY 1 SET BIT!:  see targ_has_iclass().
156  */
157 #define I_BASE  0x01    /* 80960 base instruction set   */
158 #define I_CX    0x02    /* 80960Cx instruction          */
159 #define I_DEC   0x04    /* Decimal instruction          */
160 #define I_FP    0x08    /* Floating point instruction   */
161 #define I_KX    0x10    /* 80960Kx instruction          */
162 #define I_MIL   0x20    /* Military instruction         */
163
164 /* MEANING OF 'n_other' in the symbol record.
165  *
166  * If non-zero, the 'n_other' fields indicates either a leaf procedure or
167  * a system procedure, as follows:
168  *
169  *      1 <= n_other <= 32 :
170  *              The symbol is the entry point to a system procedure.
171  *              'n_value' is the address of the entry, as for any other
172  *              procedure.  The system procedure number (which can be used in
173  *              a 'calls' instruction) is (n_other-1).  These entries come from
174  *              '.sysproc' directives.
175  *
176  *      n_other == N_CALLNAME
177  *              the symbol is the 'call' entry point to a leaf procedure.
178  *              The *next* symbol in the symbol table must be the corresponding
179  *              'bal' entry point to the procedure (see following).  These
180  *              entries come from '.leafproc' directives in which two different
181  *              symbols are specified (the first one is represented here).
182  *
183  *
184  *      n_other == N_BALNAME
185  *              the symbol is the 'bal' entry point to a leaf procedure.
186  *              These entries result from '.leafproc' directives in which only
187  *              one symbol is specified, or in which the same symbol is
188  *              specified twice.
189  *
190  * Note that an N_CALLNAME entry *must* have a corresponding N_BALNAME entry,
191  * but not every N_BALNAME entry must have an N_CALLNAME entry.
192  */
193 #define N_CALLNAME      (-1)
194 #define N_BALNAME       (-2)
195
196
197 /* i960 uses a custom relocation record. */
198
199 /* let obj-aout.h know */
200 #define CUSTOM_RELOC_FORMAT 1
201 /* let a.out.gnu.h know */
202 #define N_RELOCATION_INFO_DECLARED 1
203 struct relocation_info {
204         int      r_address;     /* File address of item to be relocated */
205         unsigned
206     r_index:24,/* Index of symbol on which relocation is based*/
207     r_pcrel:1,  /* 1 => relocate PC-relative; else absolute
208                  *      On i960, pc-relative implies 24-bit
209                  *      address, absolute implies 32-bit.
210                  */
211     r_length:2, /* Number of bytes to relocate:
212                  *      0 => 1 byte
213                  *      1 => 2 bytes
214                  *      2 => 4 bytes -- only value used for i960
215                  */
216     r_extern:1,
217     r_bsr:1,    /* Something for the GNU NS32K assembler */
218     r_disp:1,   /* Something for the GNU NS32K assembler */
219     r_callj:1,  /* 1 if relocation target is an i960 'callj' */
220     nuthin:1;   /* Unused                               */
221 };
222
223 /* hacks for tracking callj's */
224 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
225
226 #define TC_S_IS_SYSPROC(s)      ((1 <= S_GET_OTHER(s)) && (S_GET_OTHER(s) <= 32))
227 #define TC_S_IS_BALNAME(s)      (S_GET_OTHER(s) == N_BALNAME)
228 #define TC_S_IS_CALLNAME(s)     (S_GET_OTHER(s) == N_CALLNAME)
229 #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))
230
231 #define TC_S_SET_SYSPROC(s, p)  (S_SET_OTHER((s), (p)+1))
232 #define TC_S_GET_SYSPROC(s)     (S_GET_OTHER(s)-1)
233
234 #define TC_S_FORCE_TO_BALNAME(s)        (S_SET_OTHER((s), N_BALNAME))
235 #define TC_S_FORCE_TO_CALLNAME(s)       (S_SET_OTHER((s), N_CALLNAME))
236 #define TC_S_FORCE_TO_SYSPROC(s)        {;}
237
238 #elif defined(OBJ_COFF)
239
240 #define TC_S_IS_SYSPROC(s)      (S_GET_STORAGE_CLASS(s) == C_SCALL)
241 #define TC_S_IS_BALNAME(s)      (SF_GET_BALNAME(s))
242 #define TC_S_IS_CALLNAME(s)     (SF_GET_CALLNAME(s))
243 #define TC_S_IS_BADPROC(s)      (TC_S_IS_SYSPROC(s) && TC_S_GET_SYSPROC(s) < 0 && 31 < TC_S_GET_SYSPROC(s))
244
245 #define TC_S_SET_SYSPROC(s, p)  ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx = (p))
246 #define TC_S_GET_SYSPROC(s)     ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx)
247
248 #define TC_S_FORCE_TO_BALNAME(s)        (SF_SET_BALNAME(s))
249 #define TC_S_FORCE_TO_CALLNAME(s)       (SF_SET_CALLNAME(s))
250 #define TC_S_FORCE_TO_SYSPROC(s)        (S_SET_STORAGE_CLASS((s), C_SCALL))
251
252 #else /* switch on OBJ */
253 you lose
254 #endif /* witch on OBJ */
255
256 #if __STDC__ == 1
257
258     void brtab_emit(void);
259 void reloc_callj(); /* this is really reloc_callj(fixS *fixP) but I don't want to change header inclusion order. */
260 void tc_set_bal_of_call(); /* this is really tc_set_bal_of_call(symbolS *callP, symbolS *balP) */
261
262 #else /* not __STDC__ */
263
264 void brtab_emit();
265 void reloc_callj();
266 void tc_set_bal_of_call();
267
268 #endif /* not __STDC__ */
269
270 char *_tc_get_bal_of_call(); /* this is really symbolS *tc_get_bal_of_call(symbolS *callP). */
271 #define tc_get_bal_of_call(c)   ((symbolS *) _tc_get_bal_of_call(c))
272 #endif
273
274 /*
275  * Local Variables:
276  * comment-column: 0
277  * fill-column: 131
278  * End:
279  */
280
281 /* end of tc-i960.h */