Update documentation
[platform/upstream/nasm.git] / insns.h
1 /* insns.h   header file for insns.c
2  *
3  * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4  * Julian Hall. All rights reserved. The software is
5  * redistributable under the licence given in the file "Licence"
6  * distributed in the NASM archive.
7  */
8
9 #ifndef NASM_INSNS_H
10 #define NASM_INSNS_H
11
12 #include "nasm.h"
13
14 /* max length of any instruction, register name etc. */
15 #if MAX_INSLEN > 9              /* MAX_INSLEN defined in insnsi.h */
16 #define MAX_KEYWORD MAX_INSLEN
17 #else
18 #define MAX_KEYWORD 9
19 #endif
20
21 struct itemplate {
22     enum opcode opcode;         /* the token, passed from "parser.c" */
23     int operands;               /* number of operands */
24     opflags_t opd[MAX_OPERANDS]; /* bit flags for operand types */
25     const char *code;           /* the code it assembles to */
26     uint32_t flags;             /* some flags */
27 };
28
29 /* Disassembler table structure */
30 /* If n == -1, then p points to another table of 256
31    struct disasm_index, otherwise p points to a list of n
32    struct itemplates to consider. */
33 struct disasm_index {
34     const void *p;
35     int n;
36 };
37
38 /* Tables for the assembler and disassembler, respectively */
39 extern const struct itemplate * const nasm_instructions[];
40 extern const struct disasm_index itable[256];
41
42 /*
43  * this define is used to signify the end of an itemplate
44  */
45 #define ITEMPLATE_END {-1,-1,{-1,-1,-1},NULL,0}
46
47 /*
48  * Instruction template flags. These specify which processor
49  * targets the instruction is eligible for, whether it is
50  * privileged or undocumented, and also specify extra error
51  * checking on the matching of the instruction.
52  *
53  * IF_SM stands for Size Match: any operand whose size is not
54  * explicitly specified by the template is `really' intended to be
55  * the same size as the first size-specified operand.
56  * Non-specification is tolerated in the input instruction, but
57  * _wrong_ specification is not.
58  *
59  * IF_SM2 invokes Size Match on only the first _two_ operands, for
60  * three-operand instructions such as SHLD: it implies that the
61  * first two operands must match in size, but that the third is
62  * required to be _unspecified_.
63  *
64  * IF_SB invokes Size Byte: operands with unspecified size in the
65  * template are really bytes, and so no non-byte specification in
66  * the input instruction will be tolerated. IF_SW similarly invokes
67  * Size Word, and IF_SD invokes Size Doubleword.
68  *
69  * (The default state if neither IF_SM nor IF_SM2 is specified is
70  * that any operand with unspecified size in the template is
71  * required to have unspecified size in the instruction too...)
72  */
73
74 #define IF_SM     0x00000001UL  /* size match */
75 #define IF_SM2    0x00000002UL  /* size match first two operands */
76 #define IF_SB     0x00000004UL  /* unsized operands can't be non-byte */
77 #define IF_SW     0x00000008UL  /* unsized operands can't be non-word */
78 #define IF_SD     0x0000000CUL  /* unsized operands can't be non-dword */
79 #define IF_SQ     0x00000010UL  /* unsized operands can't be non-qword */
80 #define IF_SO     0x00000014UL  /* unsized operands can't be non-oword */
81 #define IF_SMASK  0x0000001CUL  /* mask for unsized argument size */
82 #define IF_AR0    0x00000020UL  /* SB, SW, SD applies to argument 0 */
83 #define IF_AR1    0x00000040UL  /* SB, SW, SD applies to argument 1 */
84 #define IF_AR2    0x00000060UL  /* SB, SW, SD applies to argument 2 */
85 #define IF_AR3    0x00000080UL  /* SB, SW, SD applies to argument 2 */
86 #define IF_ARMASK 0x000000E0UL  /* mask for unsized argument spec */
87 #define IF_PRIV   0x00000100UL  /* it's a privileged instruction */
88 #define IF_SMM    0x00000200UL  /* it's only valid in SMM */
89 #define IF_PROT   0x00000400UL  /* it's protected mode only */
90 #define IF_NOLONG 0x00000800UL  /* it's not available in long mode */
91 #define IF_UNDOC  0x00001000UL  /* it's an undocumented instruction */
92 #define IF_FPU    0x00002000UL  /* it's an FPU instruction */
93 #define IF_MMX    0x00004000UL  /* it's an MMX instruction */
94 #define IF_3DNOW  0x00008000UL  /* it's a 3DNow! instruction */
95 #define IF_SSE    0x00010000UL  /* it's a SSE (KNI, MMX2) instruction */
96 #define IF_SSE2   0x00020000UL  /* it's a SSE2 instruction */
97 #define IF_SSE3   0x00040000UL  /* it's a SSE3 (PNI) instruction */
98 #define IF_VMX    0x00080000UL  /* it's a VMX instruction */
99 #define IF_LONG   0x00100000UL  /* long mode instruction */
100 #define IF_SSSE3  0x00200000UL  /* it's an SSSE3 instruction */
101 #define IF_SSE41  0x00400000UL  /* it's an SSE4.1 instruction */
102 #define IF_SSE42  0x00800000UL  /* it's an SSE4.2 instruction */
103 #define IF_SSE5   0x00800000UL  /* HACK NEED TO REORGANIZE THESE BITS */
104 #define IF_PMASK  0xFF000000UL  /* the mask for processor types */
105 #define IF_PLEVEL 0x0F000000UL  /* the mask for processor instr. level */
106                                         /* also the highest possible processor */
107 #define IF_PFMASK 0xF01FFF00UL  /* the mask for disassembly "prefer" */
108 #define IF_8086   0x00000000UL  /* 8086 instruction */
109 #define IF_186    0x01000000UL  /* 186+ instruction */
110 #define IF_286    0x02000000UL  /* 286+ instruction */
111 #define IF_386    0x03000000UL  /* 386+ instruction */
112 #define IF_486    0x04000000UL  /* 486+ instruction */
113 #define IF_PENT   0x05000000UL  /* Pentium instruction */
114 #define IF_P6     0x06000000UL  /* P6 instruction */
115 #define IF_KATMAI 0x07000000UL  /* Katmai instructions */
116 #define IF_WILLAMETTE 0x08000000UL      /* Willamette instructions */
117 #define IF_PRESCOTT   0x09000000UL      /* Prescott instructions */
118 #define IF_X86_64 0x0A000000UL  /* x86-64 instruction (long or legacy mode) */
119 #define IF_NEHALEM 0x0B000000UL  /* Nehalem instruction */
120 #define IF_X64    (IF_LONG|IF_X86_64)
121 #define IF_IA64   0x0F000000UL  /* IA64 instructions (in x86 mode) */
122 #define IF_CYRIX  0x10000000UL  /* Cyrix-specific instruction */
123 #define IF_AMD    0x20000000UL  /* AMD-specific instruction */
124
125 #endif