opflags: Drop never used REG_RIP/REG_EIP
[nasm.git] / opflags.h
blobd3da5b3846208f43dee157ecc2752a133f74eccc
1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 1996-2012 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * opflags.h - operand flags
38 #ifndef NASM_OPFLAGS_H
39 #define NASM_OPFLAGS_H
41 #include "compiler.h"
44 * Here we define the operand types. These are implemented as bit
45 * masks, since some are subsets of others; e.g. AX in a MOV
46 * instruction is a special operand type, whereas AX in other
47 * contexts is just another 16-bit register. (Also, consider CL in
48 * shift instructions, DX in OUT, etc.)
50 * The basic concept here is that
51 * (class & ~operand) == 0
53 * if and only if "operand" belongs to class type "class".
55 * The bits are assigned as follows:
57 * Bits 0-7, 23, 29: sizes
58 * 0: 8 bits (BYTE)
59 * 1: 16 bits (WORD)
60 * 2: 32 bits (DWORD)
61 * 3: 64 bits (QWORD)
62 * 4: 80 bits (TWORD)
63 * 5: FAR
64 * 6: NEAR
65 * 7: SHORT
66 * 23: 256 bits (YWORD)
67 * 29: 128 bits (OWORD)
69 * Bits 8-10 modifiers
70 * 8: TO
71 * 9: COLON
72 * 10: STRICT
74 * Bits 12-15: type of operand
75 * 12: REGISTER
76 * 13: IMMEDIATE
77 * 14: MEMORY (always has REGMEM attribute as well)
78 * 15: REGMEM (valid EA operand)
80 * Bits 11, 16-19, 28: subclasses
81 * With REG_CDT:
82 * 16: REG_CREG (CRx)
83 * 17: REG_DREG (DRx)
84 * 18: REG_TREG (TRx)
86 * With REG_GPR:
87 * 16: REG_ACCUM (AL, AX, EAX, RAX)
88 * 17: REG_COUNT (CL, CX, ECX, RCX)
89 * 18: REG_DATA (DL, DX, EDX, RDX)
90 * 19: REG_HIGH (AH, CH, DH, BH)
91 * 28: REG_NOTACC (not REG_ACCUM)
93 * With REG_SREG:
94 * 16: REG_CS
95 * 17: REG_DESS (DS, ES, SS)
96 * 18: REG_FSGS
97 * 19: REG_SEG67
99 * With FPUREG:
100 * 16: FPU0
102 * With XMMREG:
103 * 16: XMM0
105 * With YMMREG:
106 * 16: YMM0
108 * With MEMORY:
109 * 16: MEM_OFFS (this is a simple offset)
110 * 17: IP_REL (IP-relative offset)
112 * With IMMEDIATE:
113 * 16: UNITY (1)
114 * 17: BYTENESS16 (-128..127)
115 * 18: BYTENESS32 (-128..127)
116 * 19: BYTENESS64 (-128..127)
117 * 28: SDWORD64 (-2^31..2^31-1)
118 * 11: UDWORD64 (0..2^32-1)
120 * Bits 20-22, 24-27: register classes
121 * 20: REG_CDT (CRx, DRx, TRx)
122 * 21: RM_GPR (REG_GPR) (integer register)
123 * 22: REG_SREG
124 * 24: FPUREG
125 * 25: RM_MMX (MMXREG)
126 * 26: RM_XMM (XMMREG)
127 * 27: RM_YMM (YMMREG)
129 * 30: SAME_AS
130 * Special flag only used in instruction patterns; means this operand
131 * has to be identical to another operand. Currently only supported
132 * for registers.
135 typedef uint64_t opflags_t;
137 /* Size, and other attributes, of the operand */
138 #define BITS8 UINT64_C(0x00000001)
139 #define BITS16 UINT64_C(0x00000002)
140 #define BITS32 UINT64_C(0x00000004)
141 #define BITS64 UINT64_C(0x00000008) /* x64 and FPU only */
142 #define BITS80 UINT64_C(0x00000010) /* FPU only */
143 #define BITS128 UINT64_C(0x20000000)
144 #define BITS256 UINT64_C(0x00800000)
145 #define FAR UINT64_C(0x00000020) /* grotty: this means 16:16 or */
146 /* 16:32, like in CALL/JMP */
147 #define NEAR UINT64_C(0x00000040)
148 #define SHORT UINT64_C(0x00000080) /* and this means what it says :) */
150 #define SIZE_MASK UINT64_C(0x208000FF) /* all the size attributes */
152 /* Modifiers */
153 #define MODIFIER_MASK UINT64_C(0x00000700)
154 #define TO UINT64_C(0x00000100) /* reverse effect in FADD, FSUB &c */
155 #define COLON UINT64_C(0x00000200) /* operand is followed by a colon */
156 #define STRICT UINT64_C(0x00000400) /* do not optimize this operand */
158 /* Type of operand: memory reference, register, etc. */
159 #define OPTYPE_MASK UINT64_C(0x0000f000)
160 #define REGISTER UINT64_C(0x00001000) /* register number in 'basereg' */
161 #define IMMEDIATE UINT64_C(0x00002000)
162 #define MEMORY UINT64_C(0x0000c000)
163 #define REGMEM UINT64_C(0x00008000) /* for r/m, ie EA, operands */
165 #define is_class(class, op) (!((opflags_t)(class) & ~(opflags_t)(op)))
167 #define IS_SREG(op) is_class(REG_SREG, nasm_reg_flags[(op)])
168 #define IS_FSGS(op) is_class(REG_FSGS, nasm_reg_flags[(op)])
170 /* Register classes */
171 #define REG_EA UINT64_C(0x00009000) /* 'normal' reg, qualifies as EA */
172 #define RM_GPR UINT64_C(0x00208000) /* integer operand */
173 #define REG_GPR UINT64_C(0x00209000) /* integer register */
174 #define REG8 UINT64_C(0x00209001) /* 8-bit GPR */
175 #define REG16 UINT64_C(0x00209002) /* 16-bit GPR */
176 #define REG32 UINT64_C(0x00209004) /* 32-bit GPR */
177 #define REG64 UINT64_C(0x00209008) /* 64-bit GPR */
178 #define FPUREG UINT64_C(0x01001000) /* floating point stack registers */
179 #define FPU0 UINT64_C(0x01011000) /* FPU stack register zero */
180 #define RM_MMX UINT64_C(0x02008000) /* MMX operand */
181 #define MMXREG UINT64_C(0x02009000) /* MMX register */
182 #define RM_XMM UINT64_C(0x04008000) /* XMM (SSE) operand */
183 #define XMMREG UINT64_C(0x04009000) /* XMM (SSE) register */
184 #define XMM0 UINT64_C(0x04019000) /* XMM register zero */
185 #define RM_YMM UINT64_C(0x08008000) /* YMM (AVX) operand */
186 #define YMMREG UINT64_C(0x08009000) /* YMM (AVX) register */
187 #define YMM0 UINT64_C(0x08019000) /* YMM register zero */
188 #define REG_CDT UINT64_C(0x00101004) /* CRn, DRn and TRn */
189 #define REG_CREG UINT64_C(0x00111004) /* CRn */
190 #define REG_DREG UINT64_C(0x00121004) /* DRn */
191 #define REG_TREG UINT64_C(0x00141004) /* TRn */
192 #define REG_SREG UINT64_C(0x00401002) /* any segment register */
193 #define REG_CS UINT64_C(0x00411002) /* CS */
194 #define REG_DESS UINT64_C(0x00421002) /* DS, ES, SS */
195 #define REG_FSGS UINT64_C(0x00441002) /* FS, GS */
196 #define REG_SEG67 UINT64_C(0x00481002) /* Unimplemented segment registers */
198 /* Special GPRs */
199 #define REG_SMASK UINT64_C(0x100f0800) /* a mask for the following */
200 #define REG_ACCUM UINT64_C(0x00219000) /* accumulator: AL, AX, EAX, RAX */
201 #define REG_AL UINT64_C(0x00219001)
202 #define REG_AX UINT64_C(0x00219002)
203 #define REG_EAX UINT64_C(0x00219004)
204 #define REG_RAX UINT64_C(0x00219008)
205 #define REG_COUNT UINT64_C(0x10229000) /* counter: CL, CX, ECX, RCX */
206 #define REG_CL UINT64_C(0x10229001)
207 #define REG_CX UINT64_C(0x10229002)
208 #define REG_ECX UINT64_C(0x10229004)
209 #define REG_RCX UINT64_C(0x10229008)
210 #define REG_DL UINT64_C(0x10249001) /* data: DL, DX, EDX, RDX */
211 #define REG_DX UINT64_C(0x10249002)
212 #define REG_EDX UINT64_C(0x10249004)
213 #define REG_RDX UINT64_C(0x10249008)
214 #define REG_HIGH UINT64_C(0x10289001) /* high regs: AH, CH, DH, BH */
215 #define REG_NOTACC UINT64_C(0x10000000) /* non-accumulator register */
216 #define REG8NA UINT64_C(0x10209001) /* 8-bit non-acc GPR */
217 #define REG16NA UINT64_C(0x10209002) /* 16-bit non-acc GPR */
218 #define REG32NA UINT64_C(0x10209004) /* 32-bit non-acc GPR */
219 #define REG64NA UINT64_C(0x10209008) /* 64-bit non-acc GPR */
221 /* special types of EAs */
222 #define MEM_OFFS UINT64_C(0x0001c000) /* simple [address] offset - absolute! */
223 #define IP_REL UINT64_C(0x0002c000) /* IP-relative offset */
225 /* memory which matches any type of r/m operand */
226 #define MEMORY_ANY (MEMORY|RM_GPR|RM_MMX|RM_XMM|RM_YMM)
228 /* special type of immediate operand */
229 #define UNITY UINT64_C(0x00012000) /* for shift/rotate instructions */
230 #define SBYTE16 UINT64_C(0x00022000) /* for op r16,immediate instrs. */
231 #define SBYTE32 UINT64_C(0x00042000) /* for op r32,immediate instrs. */
232 #define SBYTE64 UINT64_C(0x00082000) /* for op r64,immediate instrs. */
233 #define BYTENESS UINT64_C(0x000e0000) /* for testing for byteness */
234 #define SDWORD64 UINT64_C(0x10002000) /* for op r64,simm32 instrs. */
235 #define UDWORD64 UINT64_C(0x00002800) /* for op r64,uimm32 instrs. */
237 /* special flags */
238 #define SAME_AS UINT64_C(0x40000000)
240 #endif /* NASM_OPFLAGS_H */