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