Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / as / config / tc-i386.h
1 /* tc-i386.h -- Header file for tc-i386.c
2    Copyright (C) 1989, 1992 Free Software Foundation.
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 published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GAS is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GAS; see the file COPYING.  If not, write to
18    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 /*
21  * $FreeBSD: src/gnu/usr.bin/as/config/tc-i386.h,v 1.6 1999/08/27 23:34:30 peter Exp $
22  */
23
24 #ifndef TC_I386
25 #define TC_I386 1
26
27 #define AOUT_MACHTYPE 134
28
29 #define REVERSE_SORT_RELOCS
30
31 #define LOCAL_LABELS_FB
32
33 #define tc_coff_symbol_emit_hook(a)     ; /* not used */
34
35    /* Local labels starts with .L */
36  /* fixme-now: this is for testing against old gas */
37 /* #define LOCAL_LABEL(name) ((name)[0] == '.' && (name)[1] == 'L') */
38 #define tc_aout_pre_write_hook(x)       {;} /* not used */
39 #define tc_crawl_symbol_chain(a)        {;} /* not used */
40 #define tc_headers_hook(a)              {;} /* not used */
41
42 #define MAX_OPERANDS 3          /* max operands per insn */
43 #define MAX_PREFIXES 4          /* max prefixes per opcode */
44 #define MAX_IMMEDIATE_OPERANDS 2 /* max immediates per insn */
45 #define MAX_MEMORY_OPERANDS 2   /* max memory ref per insn
46                                  * lcall uses 2
47                                  */
48 /* we define the syntax here (modulo base,index,scale syntax) */
49 #define REGISTER_PREFIX '%'
50 #define IMMEDIATE_PREFIX '$'
51 #define ABSOLUTE_PREFIX '*'
52 #define PREFIX_SEPERATOR '/'
53
54 #define TWO_BYTE_OPCODE_ESCAPE 0x0f
55
56 #ifndef OLD_GAS
57 #define NOP_OPCODE 0x90
58 #else /* OLD_GAS */
59 #define NOP_OPCODE 0x00
60 #endif /* OLD_GAS */
61
62 /* register numbers */
63 #define EBP_REG_NUM 5
64 #define ESP_REG_NUM 4
65
66 /* modrm_byte.regmem for twobyte escape */
67 #define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
68 /* index_base_byte.index for no index register addressing */
69 #define NO_INDEX_REGISTER ESP_REG_NUM
70 /* index_base_byte.base for no base register addressing */
71 #define NO_BASE_REGISTER EBP_REG_NUM
72
73  /* these are the att as opcode suffixes, making movl --> mov, for example */
74 #define DWORD_OPCODE_SUFFIX 'l'
75 #define WORD_OPCODE_SUFFIX  'w'
76 #define BYTE_OPCODE_SUFFIX  'b'
77
78     /* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */
79 #define REGMEM_FIELD_HAS_REG 0x3                /* always = 0x3 */
80 #define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
81
82 #define END_OF_INSN '\0'
83
84 /*
85   When an operand is read in it is classified by its type.  This type includes
86   all the possible ways an operand can be used.  Thus, '%eax' is both 'register
87   # 0' and 'The Accumulator'.  In our language this is expressed by OR'ing
88   'Reg32' (any 32 bit register) and 'Acc' (the accumulator).
89   Operands are classified so that we can match given operand types with
90   the opcode table in i386-opcode.h.
91   */
92 #define Unknown 0x0
93 /* register */
94 #define Reg8    0x1             /* 8 bit reg */
95 #define Reg16   0x2             /* 16 bit reg */
96 #define Reg32   0x4             /* 32 bit reg */
97 #define Reg     (Reg8|Reg16|Reg32)    /* gen'l register */
98 #define WordReg (Reg16|Reg32)   /* for push/pop operands */
99 /* immediate */
100 #define Imm8    0x8             /* 8 bit immediate */
101 #define Imm8S   0x10            /* 8 bit immediate sign extended */
102 #define Imm16   0x20            /* 16 bit immediate */
103 #define Imm32   0x40            /* 32 bit immediate */
104 #define Imm1    0x80            /* 1 bit immediate */
105 #define ImmUnknown Imm32        /* for unknown expressions */
106 #define Imm     (Imm8|Imm8S|Imm16|Imm32)    /* gen'l immediate */
107 /* memory */
108 #define Disp8   0x200           /* 8 bit displacement (for jumps) */
109 #define Disp16  0x400           /* 16 bit displacement */
110 #define Disp32  0x800           /* 32 bit displacement */
111 #define Disp    (Disp8|Disp16|Disp32) /* General displacement */
112 #define DispUnknown Disp32      /* for unknown size displacements */
113 #define Mem8    0x1000
114 #define Mem16   0x2000
115 #define Mem32   0x4000
116 #define BaseIndex 0x8000
117 #define Mem     (Disp|Mem8|Mem16|Mem32|BaseIndex) /* General memory */
118 #define WordMem   (Mem16|Mem32|Disp|BaseIndex)
119 #define ByteMem   (Mem8|Disp|BaseIndex)
120 /* specials */
121 #define InOutPortReg 0x10000    /* register to hold in/out port addr = dx */
122 #define ShiftCount 0x20000      /* register to hold shift cound = cl */
123 #define Control 0x40000         /* Control register */
124 #define Debug   0x80000         /* Debug register */
125 #define Test    0x100000                /* Test register */
126 #define FloatReg 0x200000       /* Float register */
127 #define FloatAcc 0x400000       /* Float stack top %st(0) */
128 #define SReg2   0x800000                /* 2 bit segment register */
129 #define SReg3   0x1000000               /* 3 bit segment register */
130 #define Acc     0x2000000               /* Accumulator %al or %ax or %eax */
131 #define ImplicitRegister (InOutPortReg|ShiftCount|Acc|FloatAcc)
132 #define JumpAbsolute 0x4000000
133 #define Abs8  0x08000000
134 #define Abs16 0x10000000
135 #define Abs32 0x20000000
136 #define Abs (Abs8|Abs16|Abs32)
137
138 #define Byte (Reg8|Imm8|Imm8S)
139 #define Word (Reg16|Imm16)
140 #define DWord (Reg32|Imm32)
141
142 #define SMALLEST_DISP_TYPE(num) \
143     fits_in_signed_byte(num) ? (Disp8|Disp32|Abs8|Abs32) : (Disp32|Abs32)
144
145 typedef struct {
146         /* instruction name sans width suffix ("mov" for movl insns) */
147         char *name;
148
149         /* how many operands */
150         unsigned int operands;
151
152         /* base_opcode is the fundamental opcode byte with a optional prefix(es). */
153         unsigned int base_opcode;
154
155         /* extension_opcode is the 3 bit extension for group <n> insns.
156            If this template has no extension opcode (the usual case) use None */
157         unsigned char extension_opcode;
158 #define None 0xff /* If no extension_opcode is possible. */
159
160         /* the bits in opcode_modifier are used to generate the final opcode from
161            the base_opcode.  These bits also are used to detect alternate forms of
162            the same instruction */
163         unsigned int opcode_modifier;
164
165         /* opcode_modifier bits: */
166 #define W        0x1    /* set if operands are words or dwords */
167 #define D        0x2    /* D = 0 if Reg --> Regmem; D = 1 if Regmem --> Reg */
168         /* direction flag for floating insns:  MUST BE 0x400 */
169 #define FloatD 0x400
170         /* shorthand */
171 #define DW (D|W)
172 #define ShortForm 0x10          /* register is in low 3 bits of opcode */
173 #define ShortFormW 0x20         /* ShortForm and W bit is 0x8 */
174 #define Seg2ShortForm 0x40      /* encoding of load segment reg insns */
175 #define Seg3ShortForm 0x80      /* fs/gs segment register insns. */
176 #define Jump 0x100              /* special case for jump insns. */
177 #define JumpInterSegment 0x200  /* special case for intersegment leaps/calls */
178         /* 0x400 CANNOT BE USED since it's already used by FloatD above */
179 #define DONT_USE 0x400
180 #define NoModrm 0x800
181 #define Modrm 0x1000
182 #define imulKludge 0x2000
183 #define JumpByte 0x4000
184 #define JumpDword 0x8000
185 #define ReverseRegRegmem 0x10000
186
187         /* (opcode_modifier & COMES_IN_ALL_SIZES) is true if the
188            instuction comes in byte, word, and dword sizes and is encoded into
189            machine code in the canonical way. */
190 #define COMES_IN_ALL_SIZES (W)
191
192         /* (opcode_modifier & COMES_IN_BOTH_DIRECTIONS) indicates that the
193            source and destination operands can be reversed by setting either
194            the D (for integer insns) or the FloatD (for floating insns) bit
195            in base_opcode. */
196 #define COMES_IN_BOTH_DIRECTIONS (D|FloatD)
197
198         /* operand_types[i] describes the type of operand i.  This is made
199            by OR'ing together all of the possible type masks.  (e.g.
200            'operand_types[i] = Reg|Imm' specifies that operand i can be
201            either a register or an immediate operand */
202         unsigned int operand_types[3];
203 } template;
204
205 /*
206   'templates' is for grouping together 'template' structures for opcodes
207   of the same name.  This is only used for storing the insns in the grand
208   ole hash table of insns.
209   The templates themselves start at START and range up to (but not including)
210   END.
211   */
212 typedef struct {
213         template *start;
214         template *end;
215 } templates;
216
217 /* these are for register name --> number & type hash lookup */
218 typedef struct {
219         char *reg_name;
220         unsigned int reg_type;
221         unsigned int reg_num;
222 } reg_entry;
223
224 typedef struct {
225         char *seg_name;
226         unsigned int seg_prefix;
227 } seg_entry;
228
229 /* these are for prefix name --> prefix code hash lookup */
230 typedef struct {
231         char *prefix_name;
232         unsigned char prefix_code;
233 } prefix_entry;
234
235 /* 386 operand encoding bytes:  see 386 book for details of this. */
236 typedef struct {
237         unsigned regmem:3;           /* codes register or memory operand */
238         unsigned reg:3;      /* codes register operand (or extended opcode) */
239         unsigned mode:2;             /* how to interpret regmem & reg */
240 } modrm_byte;
241
242 /* 386 opcode byte to code indirect addressing. */
243 typedef struct {
244         unsigned base:3;
245         unsigned index:3;
246         unsigned scale:2;
247 } base_index_byte;
248
249 #endif /* TC_I386 */
250
251 /* end of tc-i386.h */