Commit | Line | Data |
---|---|---|
6f2750fe | 1 | /* Copyright (C) 2007-2016 Free Software Foundation, Inc. |
40b8e679 | 2 | |
9b201bb5 | 3 | This file is part of the GNU opcodes library. |
40b8e679 | 4 | |
9b201bb5 | 5 | This library is free software; you can redistribute it and/or modify |
40b8e679 | 6 | it under the terms of the GNU General Public License as published by |
9b201bb5 NC |
7 | the Free Software Foundation; either version 3, or (at your option) |
8 | any later version. | |
40b8e679 | 9 | |
9b201bb5 NC |
10 | It is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
13 | License for more details. | |
40b8e679 L |
14 | |
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
9b201bb5 NC |
17 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
18 | MA 02110-1301, USA. */ | |
40b8e679 | 19 | |
40fb9820 | 20 | #include "sysdep.h" |
40b8e679 | 21 | #include <stdio.h> |
40b8e679 L |
22 | #include <errno.h> |
23 | #include "getopt.h" | |
24 | #include "libiberty.h" | |
c587b3f9 | 25 | #include "hashtab.h" |
40b8e679 L |
26 | #include "safe-ctype.h" |
27 | ||
28 | #include "i386-opc.h" | |
29 | ||
30 | #include <libintl.h> | |
31 | #define _(String) gettext (String) | |
32 | ||
33 | static const char *program_name = NULL; | |
34 | static int debug = 0; | |
35 | ||
40fb9820 L |
36 | typedef struct initializer |
37 | { | |
38 | const char *name; | |
39 | const char *init; | |
40 | } initializer; | |
41 | ||
8acd5377 | 42 | static initializer cpu_flag_init[] = |
40fb9820 L |
43 | { |
44 | { "CPU_UNKNOWN_FLAGS", | |
7a9068fe | 45 | "~(CpuL1OM|CpuK1OM)" }, |
40fb9820 L |
46 | { "CPU_GENERIC32_FLAGS", |
47 | "Cpu186|Cpu286|Cpu386" }, | |
29c048b6 | 48 | { "CPU_GENERIC64_FLAGS", |
da98bb4c | 49 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuLM" }, |
40fb9820 L |
50 | { "CPU_NONE_FLAGS", |
51 | "0" }, | |
52 | { "CPU_I186_FLAGS", | |
53 | "Cpu186" }, | |
54 | { "CPU_I286_FLAGS", | |
55 | "Cpu186|Cpu286" }, | |
56 | { "CPU_I386_FLAGS", | |
57 | "Cpu186|Cpu286|Cpu386" }, | |
58 | { "CPU_I486_FLAGS", | |
59 | "Cpu186|Cpu286|Cpu386|Cpu486" }, | |
60 | { "CPU_I586_FLAGS", | |
309d3373 | 61 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu387" }, |
40fb9820 | 62 | { "CPU_I686_FLAGS", |
309d3373 | 63 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687" }, |
22109423 L |
64 | { "CPU_PENTIUMPRO_FLAGS", |
65 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687|CpuNop" }, | |
40fb9820 | 66 | { "CPU_P2_FLAGS", |
22109423 | 67 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687|CpuNop|CpuMMX" }, |
40fb9820 | 68 | { "CPU_P3_FLAGS", |
22109423 | 69 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687|CpuNop|CpuMMX|CpuSSE" }, |
40fb9820 | 70 | { "CPU_P4_FLAGS", |
22109423 | 71 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuNop|CpuMMX|CpuSSE|CpuSSE2" }, |
40fb9820 | 72 | { "CPU_NOCONA_FLAGS", |
60aa667e | 73 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuLM|CpuCX16" }, |
40fb9820 | 74 | { "CPU_CORE_FLAGS", |
60aa667e | 75 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuCX16" }, |
40fb9820 | 76 | { "CPU_CORE2_FLAGS", |
60aa667e | 77 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuLM|CpuCX16" }, |
bd5295b2 | 78 | { "CPU_COREI7_FLAGS", |
60aa667e | 79 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuRdtscp|CpuLM|CpuCX16" }, |
40fb9820 | 80 | { "CPU_K6_FLAGS", |
309d3373 | 81 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuSYSCALL|Cpu387|CpuMMX" }, |
40fb9820 | 82 | { "CPU_K6_2_FLAGS", |
d56da83e | 83 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuSYSCALL|Cpu387|CpuMMX|Cpu3dnow" }, |
40fb9820 | 84 | { "CPU_ATHLON_FLAGS", |
22109423 | 85 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|Cpu387|Cpu687|CpuNop|CpuMMX|Cpu3dnow|Cpu3dnowA" }, |
40fb9820 | 86 | { "CPU_K8_FLAGS", |
22109423 | 87 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuNop|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuLM" }, |
40fb9820 | 88 | { "CPU_AMDFAM10_FLAGS", |
22109423 | 89 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM" }, |
68339fdf | 90 | { "CPU_BDVER1_FLAGS", |
160a30bb | 91 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM|CpuFMA4|CpuXOP|CpuLWP|CpuCX16|CpuClflush|CpuSSSE3|CpuSVME|CpuSSE4_1|CpuSSE4_2|CpuXsave|CpuAES|CpuAVX|CpuPCLMUL|CpuLZCNT|CpuPRFCHW" }, |
4cab4add | 92 | { "CPU_BDVER2_FLAGS", |
160a30bb | 93 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM|CpuFMA|CpuFMA4|CpuXOP|CpuLWP|CpuBMI|CpuTBM|CpuF16C|CpuCX16|CpuClflush|CpuSSSE3|CpuSVME|CpuSSE4_1|CpuSSE4_2|CpuXsave|CpuAES|CpuAVX|CpuPCLMUL|CpuLZCNT|CpuPRFCHW" }, |
5e5c50d3 | 94 | { "CPU_BDVER3_FLAGS", |
6091d651 | 95 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM|CpuFMA|CpuFMA4|CpuXOP|CpuLWP|CpuBMI|CpuTBM|CpuF16C|CpuCX16|CpuClflush|CpuSSSE3|CpuSVME|CpuSSE4_1|CpuSSE4_2|CpuAES|CpuAVX|CpuPCLMUL|CpuLZCNT|CpuPRFCHW|CpuXsave|CpuXsaveopt|CpuFSGSBase" }, |
c7b0bd56 | 96 | { "CPU_BDVER4_FLAGS", |
9916071f | 97 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM|CpuFMA|CpuFMA4|CpuXOP|CpuLWP|CpuBMI|CpuTBM|CpuF16C|CpuCX16|CpuClflush|CpuSSSE3|CpuSVME|CpuSSE4_1|CpuSSE4_2|CpuAES|CpuAVX|CpuPCLMUL|CpuLZCNT|CpuPRFCHW|CpuXsave|CpuXsaveopt|CpuFSGSBase|CpuAVX2|CpuMovbe|CpuBMI2|CpuRdRnd|CpuMWAITX" }, |
029f3522 | 98 | { "CPU_ZNVER1_FLAGS", |
36aed29d | 99 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM|CpuFMA|CpuBMI|CpuF16C|CpuCX16|CpuClflush|CpuSSSE3|CpuSVME|CpuSSE4_1|CpuSSE4_2|CpuAES|CpuAVX|CpuPCLMUL|CpuLZCNT|CpuPRFCHW|CpuXsave|CpuXsaveopt|CpuFSGSBase|CpuAVX2|CpuMovbe|CpuBMI2|CpuRdRnd|CpuADX|CpuRdSeed|CpuSMAP|CpuSHA|CpuXSAVEC|CpuXSAVES|CpuClflushOpt|CpuCLZERO|CpuMWAITX" }, |
7b458c12 | 100 | { "CPU_BTVER1_FLAGS", |
160a30bb | 101 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4a|CpuABM|CpuLM|CpuPRFCHW|CpuCX16|CpuClflush|CpuFISTTP|CpuSVME|CpuLZCNT" }, |
7b458c12 | 102 | { "CPU_BTVER2_FLAGS", |
160a30bb | 103 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuNop|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4a|CpuSSE4_1|CpuSSE4_2|CpuABM|CpuLM|CpuBMI|CpuF16C|CpuAES|CpuPCLMUL|CpuAVX|CpuMovbe|CpuXsave|CpuXsaveopt|CpuPRFCHW|CpuCX16|CpuClflush|CpuFISTTP|CpuSVME|CpuLZCNT" }, |
309d3373 JB |
104 | { "CPU_8087_FLAGS", |
105 | "Cpu8087" }, | |
106 | { "CPU_287_FLAGS", | |
107 | "Cpu287" }, | |
108 | { "CPU_387_FLAGS", | |
109 | "Cpu387" }, | |
293f5f65 | 110 | { "CPU_ANY_X87_FLAGS", |
309d3373 | 111 | "Cpu8087|Cpu287|Cpu387|Cpu687|CpuFISTTP" }, |
bd5295b2 L |
112 | { "CPU_CLFLUSH_FLAGS", |
113 | "CpuClflush" }, | |
22109423 L |
114 | { "CPU_NOP_FLAGS", |
115 | "CpuNop" }, | |
bd5295b2 L |
116 | { "CPU_SYSCALL_FLAGS", |
117 | "CpuSYSCALL" }, | |
40fb9820 L |
118 | { "CPU_MMX_FLAGS", |
119 | "CpuMMX" }, | |
120 | { "CPU_SSE_FLAGS", | |
115c7c25 | 121 | "CpuMMX|CpuSSE" }, |
40fb9820 | 122 | { "CPU_SSE2_FLAGS", |
115c7c25 | 123 | "CpuMMX|CpuSSE|CpuSSE2" }, |
40fb9820 | 124 | { "CPU_SSE3_FLAGS", |
115c7c25 | 125 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" }, |
40fb9820 | 126 | { "CPU_SSSE3_FLAGS", |
115c7c25 | 127 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3" }, |
40fb9820 | 128 | { "CPU_SSE4_1_FLAGS", |
115c7c25 | 129 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1" }, |
40fb9820 | 130 | { "CPU_SSE4_2_FLAGS", |
115c7c25 | 131 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2" }, |
309d3373 | 132 | { "CPU_ANY_SSE_FLAGS", |
43234a1e | 133 | "CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuSSE4a|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512CD|CpuAVX512ER|CpuAVX512PF" }, |
6305a203 L |
134 | { "CPU_VMX_FLAGS", |
135 | "CpuVMX" }, | |
136 | { "CPU_SMX_FLAGS", | |
137 | "CpuSMX" }, | |
f03fe4c1 L |
138 | { "CPU_XSAVE_FLAGS", |
139 | "CpuXsave" }, | |
c7b8aa3a L |
140 | { "CPU_XSAVEOPT_FLAGS", |
141 | "CpuXsaveopt" }, | |
c0f3af97 L |
142 | { "CPU_AES_FLAGS", |
143 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAES" }, | |
594ab6a3 L |
144 | { "CPU_PCLMUL_FLAGS", |
145 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuPCLMUL" }, | |
c0f3af97 L |
146 | { "CPU_FMA_FLAGS", |
147 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA" }, | |
922d8de8 DR |
148 | { "CPU_FMA4_FLAGS", |
149 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA4" }, | |
5dd85c99 | 150 | { "CPU_XOP_FLAGS", |
f0ae4a24 | 151 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuSSE4a|CpuABM|CpuAVX|CpuFMA4|CpuXOP" }, |
f88c9eb0 SP |
152 | { "CPU_LWP_FLAGS", |
153 | "CpuLWP" }, | |
f12dc422 L |
154 | { "CPU_BMI_FLAGS", |
155 | "CpuBMI" }, | |
2a2a0f38 QN |
156 | { "CPU_TBM_FLAGS", |
157 | "CpuTBM" }, | |
f1f8f695 L |
158 | { "CPU_MOVBE_FLAGS", |
159 | "CpuMovbe" }, | |
60aa667e L |
160 | { "CPU_CX16_FLAGS", |
161 | "CpuCX16" }, | |
1b7f3fb0 L |
162 | { "CPU_RDTSCP_FLAGS", |
163 | "CpuRdtscp" }, | |
f1f8f695 L |
164 | { "CPU_EPT_FLAGS", |
165 | "CpuEPT" }, | |
c7b8aa3a L |
166 | { "CPU_FSGSBASE_FLAGS", |
167 | "CpuFSGSBase" }, | |
168 | { "CPU_RDRND_FLAGS", | |
169 | "CpuRdRnd" }, | |
170 | { "CPU_F16C_FLAGS", | |
171 | "CpuF16C" }, | |
6c30d220 L |
172 | { "CPU_BMI2_FLAGS", |
173 | "CpuBMI2" }, | |
174 | { "CPU_LZCNT_FLAGS", | |
175 | "CpuLZCNT" }, | |
42164a71 L |
176 | { "CPU_HLE_FLAGS", |
177 | "CpuHLE" }, | |
178 | { "CPU_RTM_FLAGS", | |
179 | "CpuRTM" }, | |
6c30d220 L |
180 | { "CPU_INVPCID_FLAGS", |
181 | "CpuINVPCID" }, | |
8729a6f6 L |
182 | { "CPU_VMFUNC_FLAGS", |
183 | "CpuVMFUNC" }, | |
40fb9820 L |
184 | { "CPU_3DNOW_FLAGS", |
185 | "CpuMMX|Cpu3dnow" }, | |
186 | { "CPU_3DNOWA_FLAGS", | |
115c7c25 | 187 | "CpuMMX|Cpu3dnow|Cpu3dnowA" }, |
293f5f65 L |
188 | { "CPU_ANY_MMX_FLAGS", |
189 | "CpuMMX|Cpu3dnow|Cpu3dnowA" }, | |
40fb9820 L |
190 | { "CPU_PADLOCK_FLAGS", |
191 | "CpuPadLock" }, | |
192 | { "CPU_SVME_FLAGS", | |
193 | "CpuSVME" }, | |
194 | { "CPU_SSE4A_FLAGS", | |
115c7c25 | 195 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a" }, |
40fb9820 | 196 | { "CPU_ABM_FLAGS", |
3629bb00 | 197 | "CpuABM" }, |
c0f3af97 L |
198 | { "CPU_AVX_FLAGS", |
199 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX" }, | |
6c30d220 L |
200 | { "CPU_AVX2_FLAGS", |
201 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2" }, | |
43234a1e | 202 | { "CPU_AVX512F_FLAGS", |
f1360d58 | 203 | "CpuVREX|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F" }, |
43234a1e | 204 | { "CPU_AVX512CD_FLAGS", |
f1360d58 | 205 | "CpuVREX|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512CD" }, |
43234a1e | 206 | { "CPU_AVX512ER_FLAGS", |
f1360d58 | 207 | "CpuVREX|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512ER" }, |
43234a1e | 208 | { "CPU_AVX512PF_FLAGS", |
f1360d58 | 209 | "CpuVREX|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512PF" }, |
309d3373 | 210 | { "CPU_ANY_AVX_FLAGS", |
43234a1e | 211 | "CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512CD|CpuAVX512ER|CpuAVX512PF" }, |
8a9036a4 L |
212 | { "CPU_L1OM_FLAGS", |
213 | "unknown" }, | |
7a9068fe L |
214 | { "CPU_K1OM_FLAGS", |
215 | "unknown" }, | |
7b6d09fb L |
216 | { "CPU_IAMCU_FLAGS", |
217 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586" }, | |
218 | { "CPU_IAMCU_COMPAT_FLAGS", | |
219 | "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuNo64|CpuNop" }, | |
e2e1fcde L |
220 | { "CPU_ADX_FLAGS", |
221 | "CpuADX" }, | |
222 | { "CPU_RDSEED_FLAGS", | |
223 | "CpuRdSeed" }, | |
224 | { "CPU_PRFCHW_FLAGS", | |
225 | "CpuPRFCHW" }, | |
5c111e37 L |
226 | { "CPU_SMAP_FLAGS", |
227 | "CpuSMAP" }, | |
7e8b059b L |
228 | { "CPU_MPX_FLAGS", |
229 | "CpuMPX" }, | |
a0046408 L |
230 | { "CPU_SHA_FLAGS", |
231 | "CpuSHA" }, | |
963f3586 IT |
232 | { "CPU_CLFLUSHOPT_FLAGS", |
233 | "CpuClflushOpt" }, | |
234 | { "CPU_XSAVES_FLAGS", | |
235 | "CpuXSAVES" }, | |
236 | { "CPU_XSAVEC_FLAGS", | |
237 | "CpuXSAVEC" }, | |
dcf893b5 IT |
238 | { "CPU_PREFETCHWT1_FLAGS", |
239 | "CpuPREFETCHWT1" }, | |
2cf200a4 IT |
240 | { "CPU_SE1_FLAGS", |
241 | "CpuSE1" }, | |
90a915bf IT |
242 | { "CPU_AVX512DQ_FLAGS", |
243 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512DQ" }, | |
1ba585e8 IT |
244 | { "CPU_AVX512BW_FLAGS", |
245 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512BW" }, | |
b28d1bda IT |
246 | { "CPU_AVX512VL_FLAGS", |
247 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512VL" }, | |
c5e7287a IT |
248 | { "CPU_CLWB_FLAGS", |
249 | "CpuCLWB" }, | |
9d8596f0 IT |
250 | { "CPU_PCOMMIT_FLAGS", |
251 | "CpuPCOMMIT" }, | |
2cc1b5aa IT |
252 | { "CPU_AVX512IFMA_FLAGS", |
253 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512IFMA" }, | |
14f195c9 IT |
254 | { "CPU_AVX512VBMI_FLAGS", |
255 | "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuAVX2|CpuAVX512F|CpuAVX512VBMI" }, | |
029f3522 GG |
256 | { "CPU_CLZERO_FLAGS", |
257 | "CpuCLZERO" }, | |
9916071f AP |
258 | { "CPU_MWAITX_FLAGS", |
259 | "CpuMWAITX" }, | |
8eab4136 L |
260 | { "CPU_OSPKE_FLAGS", |
261 | "CpuOSPKE" }, | |
8bc52696 AF |
262 | { "CPU_RDPID_FLAGS", |
263 | "CpuRDPID" } | |
40fb9820 L |
264 | }; |
265 | ||
8acd5377 | 266 | static initializer operand_type_init[] = |
40fb9820 L |
267 | { |
268 | { "OPERAND_TYPE_NONE", | |
269 | "0" }, | |
270 | { "OPERAND_TYPE_REG8", | |
271 | "Reg8" }, | |
272 | { "OPERAND_TYPE_REG16", | |
273 | "Reg16" }, | |
274 | { "OPERAND_TYPE_REG32", | |
275 | "Reg32" }, | |
276 | { "OPERAND_TYPE_REG64", | |
277 | "Reg64" }, | |
278 | { "OPERAND_TYPE_IMM1", | |
279 | "Imm1" }, | |
280 | { "OPERAND_TYPE_IMM8", | |
281 | "Imm8" }, | |
282 | { "OPERAND_TYPE_IMM8S", | |
283 | "Imm8S" }, | |
284 | { "OPERAND_TYPE_IMM16", | |
285 | "Imm16" }, | |
286 | { "OPERAND_TYPE_IMM32", | |
287 | "Imm32" }, | |
288 | { "OPERAND_TYPE_IMM32S", | |
289 | "Imm32S" }, | |
290 | { "OPERAND_TYPE_IMM64", | |
291 | "Imm64" }, | |
292 | { "OPERAND_TYPE_BASEINDEX", | |
293 | "BaseIndex" }, | |
294 | { "OPERAND_TYPE_DISP8", | |
295 | "Disp8" }, | |
296 | { "OPERAND_TYPE_DISP16", | |
297 | "Disp16" }, | |
298 | { "OPERAND_TYPE_DISP32", | |
299 | "Disp32" }, | |
300 | { "OPERAND_TYPE_DISP32S", | |
301 | "Disp32S" }, | |
302 | { "OPERAND_TYPE_DISP64", | |
303 | "Disp64" }, | |
304 | { "OPERAND_TYPE_INOUTPORTREG", | |
305 | "InOutPortReg" }, | |
306 | { "OPERAND_TYPE_SHIFTCOUNT", | |
307 | "ShiftCount" }, | |
308 | { "OPERAND_TYPE_CONTROL", | |
309 | "Control" }, | |
310 | { "OPERAND_TYPE_TEST", | |
311 | "Test" }, | |
312 | { "OPERAND_TYPE_DEBUG", | |
313 | "FloatReg" }, | |
314 | { "OPERAND_TYPE_FLOATREG", | |
315 | "FloatReg" }, | |
316 | { "OPERAND_TYPE_FLOATACC", | |
317 | "FloatAcc" }, | |
318 | { "OPERAND_TYPE_SREG2", | |
319 | "SReg2" }, | |
320 | { "OPERAND_TYPE_SREG3", | |
321 | "SReg3" }, | |
322 | { "OPERAND_TYPE_ACC", | |
323 | "Acc" }, | |
324 | { "OPERAND_TYPE_JUMPABSOLUTE", | |
325 | "JumpAbsolute" }, | |
326 | { "OPERAND_TYPE_REGMMX", | |
327 | "RegMMX" }, | |
328 | { "OPERAND_TYPE_REGXMM", | |
329 | "RegXMM" }, | |
c0f3af97 L |
330 | { "OPERAND_TYPE_REGYMM", |
331 | "RegYMM" }, | |
43234a1e L |
332 | { "OPERAND_TYPE_REGZMM", |
333 | "RegZMM" }, | |
334 | { "OPERAND_TYPE_REGMASK", | |
335 | "RegMask" }, | |
40fb9820 L |
336 | { "OPERAND_TYPE_ESSEG", |
337 | "EsSeg" }, | |
338 | { "OPERAND_TYPE_ACC32", | |
7d5e4556 | 339 | "Reg32|Acc|Dword" }, |
40fb9820 | 340 | { "OPERAND_TYPE_ACC64", |
7d5e4556 | 341 | "Reg64|Acc|Qword" }, |
65da13b5 L |
342 | { "OPERAND_TYPE_INOUTPORTREG", |
343 | "InOutPortReg" }, | |
40fb9820 L |
344 | { "OPERAND_TYPE_REG16_INOUTPORTREG", |
345 | "Reg16|InOutPortReg" }, | |
346 | { "OPERAND_TYPE_DISP16_32", | |
347 | "Disp16|Disp32" }, | |
348 | { "OPERAND_TYPE_ANYDISP", | |
349 | "Disp8|Disp16|Disp32|Disp32S|Disp64" }, | |
350 | { "OPERAND_TYPE_IMM16_32", | |
351 | "Imm16|Imm32" }, | |
352 | { "OPERAND_TYPE_IMM16_32S", | |
353 | "Imm16|Imm32S" }, | |
354 | { "OPERAND_TYPE_IMM16_32_32S", | |
355 | "Imm16|Imm32|Imm32S" }, | |
2f81ff92 L |
356 | { "OPERAND_TYPE_IMM32_64", |
357 | "Imm32|Imm64" }, | |
40fb9820 L |
358 | { "OPERAND_TYPE_IMM32_32S_DISP32", |
359 | "Imm32|Imm32S|Disp32" }, | |
360 | { "OPERAND_TYPE_IMM64_DISP64", | |
361 | "Imm64|Disp64" }, | |
362 | { "OPERAND_TYPE_IMM32_32S_64_DISP32", | |
363 | "Imm32|Imm32S|Imm64|Disp32" }, | |
364 | { "OPERAND_TYPE_IMM32_32S_64_DISP32_64", | |
365 | "Imm32|Imm32S|Imm64|Disp32|Disp64" }, | |
a683cc34 SP |
366 | { "OPERAND_TYPE_VEC_IMM4", |
367 | "Vec_Imm4" }, | |
7e8b059b L |
368 | { "OPERAND_TYPE_REGBND", |
369 | "RegBND" }, | |
43234a1e L |
370 | { "OPERAND_TYPE_VEC_DISP8", |
371 | "Vec_Disp8" }, | |
40fb9820 L |
372 | }; |
373 | ||
374 | typedef struct bitfield | |
375 | { | |
376 | int position; | |
377 | int value; | |
378 | const char *name; | |
379 | } bitfield; | |
380 | ||
381 | #define BITFIELD(n) { n, 0, #n } | |
382 | ||
383 | static bitfield cpu_flags[] = | |
384 | { | |
385 | BITFIELD (Cpu186), | |
386 | BITFIELD (Cpu286), | |
387 | BITFIELD (Cpu386), | |
388 | BITFIELD (Cpu486), | |
389 | BITFIELD (Cpu586), | |
390 | BITFIELD (Cpu686), | |
bd5295b2 | 391 | BITFIELD (CpuClflush), |
22109423 | 392 | BITFIELD (CpuNop), |
bd5295b2 | 393 | BITFIELD (CpuSYSCALL), |
309d3373 JB |
394 | BITFIELD (Cpu8087), |
395 | BITFIELD (Cpu287), | |
396 | BITFIELD (Cpu387), | |
397 | BITFIELD (Cpu687), | |
398 | BITFIELD (CpuFISTTP), | |
40fb9820 | 399 | BITFIELD (CpuMMX), |
40fb9820 L |
400 | BITFIELD (CpuSSE), |
401 | BITFIELD (CpuSSE2), | |
402 | BITFIELD (CpuSSE3), | |
403 | BITFIELD (CpuSSSE3), | |
404 | BITFIELD (CpuSSE4_1), | |
405 | BITFIELD (CpuSSE4_2), | |
c0f3af97 | 406 | BITFIELD (CpuAVX), |
6c30d220 | 407 | BITFIELD (CpuAVX2), |
43234a1e L |
408 | BITFIELD (CpuAVX512F), |
409 | BITFIELD (CpuAVX512CD), | |
410 | BITFIELD (CpuAVX512ER), | |
411 | BITFIELD (CpuAVX512PF), | |
b28d1bda | 412 | BITFIELD (CpuAVX512VL), |
90a915bf | 413 | BITFIELD (CpuAVX512DQ), |
1ba585e8 | 414 | BITFIELD (CpuAVX512BW), |
8a9036a4 | 415 | BITFIELD (CpuL1OM), |
7a9068fe | 416 | BITFIELD (CpuK1OM), |
7b6d09fb | 417 | BITFIELD (CpuIAMCU), |
40fb9820 L |
418 | BITFIELD (CpuSSE4a), |
419 | BITFIELD (Cpu3dnow), | |
420 | BITFIELD (Cpu3dnowA), | |
421 | BITFIELD (CpuPadLock), | |
422 | BITFIELD (CpuSVME), | |
423 | BITFIELD (CpuVMX), | |
47dd174c | 424 | BITFIELD (CpuSMX), |
40fb9820 | 425 | BITFIELD (CpuABM), |
475a2301 | 426 | BITFIELD (CpuXsave), |
c7b8aa3a | 427 | BITFIELD (CpuXsaveopt), |
c0f3af97 | 428 | BITFIELD (CpuAES), |
594ab6a3 | 429 | BITFIELD (CpuPCLMUL), |
c0f3af97 | 430 | BITFIELD (CpuFMA), |
f88c9eb0 | 431 | BITFIELD (CpuFMA4), |
5dd85c99 | 432 | BITFIELD (CpuXOP), |
f88c9eb0 | 433 | BITFIELD (CpuLWP), |
f12dc422 | 434 | BITFIELD (CpuBMI), |
2a2a0f38 | 435 | BITFIELD (CpuTBM), |
c0f3af97 | 436 | BITFIELD (CpuLM), |
f1f8f695 | 437 | BITFIELD (CpuMovbe), |
60aa667e | 438 | BITFIELD (CpuCX16), |
f1f8f695 | 439 | BITFIELD (CpuEPT), |
1b7f3fb0 | 440 | BITFIELD (CpuRdtscp), |
c7b8aa3a L |
441 | BITFIELD (CpuFSGSBase), |
442 | BITFIELD (CpuRdRnd), | |
443 | BITFIELD (CpuF16C), | |
6c30d220 L |
444 | BITFIELD (CpuBMI2), |
445 | BITFIELD (CpuLZCNT), | |
42164a71 L |
446 | BITFIELD (CpuHLE), |
447 | BITFIELD (CpuRTM), | |
6c30d220 | 448 | BITFIELD (CpuINVPCID), |
8729a6f6 | 449 | BITFIELD (CpuVMFUNC), |
e2e1fcde L |
450 | BITFIELD (CpuRDSEED), |
451 | BITFIELD (CpuADX), | |
452 | BITFIELD (CpuPRFCHW), | |
5c111e37 | 453 | BITFIELD (CpuSMAP), |
a0046408 | 454 | BITFIELD (CpuSHA), |
43234a1e | 455 | BITFIELD (CpuVREX), |
963f3586 IT |
456 | BITFIELD (CpuClflushOpt), |
457 | BITFIELD (CpuXSAVES), | |
458 | BITFIELD (CpuXSAVEC), | |
dcf893b5 | 459 | BITFIELD (CpuPREFETCHWT1), |
2cf200a4 | 460 | BITFIELD (CpuSE1), |
c5e7287a | 461 | BITFIELD (CpuCLWB), |
9d8596f0 | 462 | BITFIELD (CpuPCOMMIT), |
40fb9820 L |
463 | BITFIELD (Cpu64), |
464 | BITFIELD (CpuNo64), | |
7e8b059b | 465 | BITFIELD (CpuMPX), |
2cc1b5aa | 466 | BITFIELD (CpuAVX512IFMA), |
14f195c9 | 467 | BITFIELD (CpuAVX512VBMI), |
9916071f | 468 | BITFIELD (CpuMWAITX), |
029f3522 | 469 | BITFIELD (CpuCLZERO), |
8eab4136 | 470 | BITFIELD (CpuOSPKE), |
8bc52696 | 471 | BITFIELD (CpuRDPID), |
5db04b09 L |
472 | BITFIELD (CpuAMD64), |
473 | BITFIELD (CpuIntel64), | |
40fb9820 L |
474 | #ifdef CpuUnused |
475 | BITFIELD (CpuUnused), | |
476 | #endif | |
477 | }; | |
478 | ||
479 | static bitfield opcode_modifiers[] = | |
480 | { | |
481 | BITFIELD (D), | |
482 | BITFIELD (W), | |
b6169b20 | 483 | BITFIELD (S), |
40fb9820 L |
484 | BITFIELD (Modrm), |
485 | BITFIELD (ShortForm), | |
486 | BITFIELD (Jump), | |
487 | BITFIELD (JumpDword), | |
488 | BITFIELD (JumpByte), | |
489 | BITFIELD (JumpInterSegment), | |
490 | BITFIELD (FloatMF), | |
491 | BITFIELD (FloatR), | |
492 | BITFIELD (FloatD), | |
493 | BITFIELD (Size16), | |
494 | BITFIELD (Size32), | |
495 | BITFIELD (Size64), | |
56ffb741 | 496 | BITFIELD (CheckRegSize), |
40fb9820 L |
497 | BITFIELD (IgnoreSize), |
498 | BITFIELD (DefaultSize), | |
499 | BITFIELD (No_bSuf), | |
500 | BITFIELD (No_wSuf), | |
501 | BITFIELD (No_lSuf), | |
502 | BITFIELD (No_sSuf), | |
503 | BITFIELD (No_qSuf), | |
7ce189b3 | 504 | BITFIELD (No_ldSuf), |
40fb9820 L |
505 | BITFIELD (FWait), |
506 | BITFIELD (IsString), | |
7e8b059b | 507 | BITFIELD (BNDPrefixOk), |
c32fa91d | 508 | BITFIELD (IsLockable), |
40fb9820 | 509 | BITFIELD (RegKludge), |
e2ec9d29 | 510 | BITFIELD (FirstXmm0), |
c0f3af97 | 511 | BITFIELD (Implicit1stXmm0), |
29c048b6 | 512 | BITFIELD (RepPrefixOk), |
42164a71 | 513 | BITFIELD (HLEPrefixOk), |
ca61edf2 L |
514 | BITFIELD (ToDword), |
515 | BITFIELD (ToQword), | |
516 | BITFIELD (AddrPrefixOp0), | |
40fb9820 L |
517 | BITFIELD (IsPrefix), |
518 | BITFIELD (ImmExt), | |
519 | BITFIELD (NoRex64), | |
520 | BITFIELD (Rex64), | |
521 | BITFIELD (Ugh), | |
c0f3af97 | 522 | BITFIELD (Vex), |
2426c15f | 523 | BITFIELD (VexVVVV), |
1ef99a7b | 524 | BITFIELD (VexW), |
7f399153 | 525 | BITFIELD (VexOpcode), |
8cd7925b | 526 | BITFIELD (VexSources), |
c0f3af97 | 527 | BITFIELD (VexImmExt), |
6c30d220 | 528 | BITFIELD (VecSIB), |
c0f3af97 | 529 | BITFIELD (SSE2AVX), |
81f8a913 | 530 | BITFIELD (NoAVX), |
43234a1e L |
531 | BITFIELD (EVex), |
532 | BITFIELD (Masking), | |
533 | BITFIELD (VecESize), | |
534 | BITFIELD (Broadcast), | |
535 | BITFIELD (StaticRounding), | |
536 | BITFIELD (SAE), | |
537 | BITFIELD (Disp8MemShift), | |
538 | BITFIELD (NoDefMask), | |
1efbbeb4 L |
539 | BITFIELD (OldGcc), |
540 | BITFIELD (ATTMnemonic), | |
e1d4d893 | 541 | BITFIELD (ATTSyntax), |
5c07affc | 542 | BITFIELD (IntelSyntax), |
40fb9820 L |
543 | }; |
544 | ||
545 | static bitfield operand_types[] = | |
546 | { | |
547 | BITFIELD (Reg8), | |
548 | BITFIELD (Reg16), | |
549 | BITFIELD (Reg32), | |
550 | BITFIELD (Reg64), | |
551 | BITFIELD (FloatReg), | |
552 | BITFIELD (RegMMX), | |
553 | BITFIELD (RegXMM), | |
c0f3af97 | 554 | BITFIELD (RegYMM), |
43234a1e L |
555 | BITFIELD (RegZMM), |
556 | BITFIELD (RegMask), | |
94ff3a50 | 557 | BITFIELD (Imm1), |
40fb9820 L |
558 | BITFIELD (Imm8), |
559 | BITFIELD (Imm8S), | |
560 | BITFIELD (Imm16), | |
561 | BITFIELD (Imm32), | |
562 | BITFIELD (Imm32S), | |
563 | BITFIELD (Imm64), | |
40fb9820 L |
564 | BITFIELD (BaseIndex), |
565 | BITFIELD (Disp8), | |
566 | BITFIELD (Disp16), | |
567 | BITFIELD (Disp32), | |
568 | BITFIELD (Disp32S), | |
569 | BITFIELD (Disp64), | |
570 | BITFIELD (InOutPortReg), | |
571 | BITFIELD (ShiftCount), | |
572 | BITFIELD (Control), | |
573 | BITFIELD (Debug), | |
574 | BITFIELD (Test), | |
575 | BITFIELD (SReg2), | |
576 | BITFIELD (SReg3), | |
577 | BITFIELD (Acc), | |
578 | BITFIELD (FloatAcc), | |
579 | BITFIELD (JumpAbsolute), | |
580 | BITFIELD (EsSeg), | |
581 | BITFIELD (RegMem), | |
5c07affc | 582 | BITFIELD (Mem), |
7d5e4556 L |
583 | BITFIELD (Byte), |
584 | BITFIELD (Word), | |
585 | BITFIELD (Dword), | |
586 | BITFIELD (Fword), | |
587 | BITFIELD (Qword), | |
588 | BITFIELD (Tbyte), | |
589 | BITFIELD (Xmmword), | |
c0f3af97 | 590 | BITFIELD (Ymmword), |
43234a1e | 591 | BITFIELD (Zmmword), |
7d5e4556 L |
592 | BITFIELD (Unspecified), |
593 | BITFIELD (Anysize), | |
a683cc34 | 594 | BITFIELD (Vec_Imm4), |
7e8b059b | 595 | BITFIELD (RegBND), |
43234a1e | 596 | BITFIELD (Vec_Disp8), |
40fb9820 L |
597 | #ifdef OTUnused |
598 | BITFIELD (OTUnused), | |
599 | #endif | |
600 | }; | |
601 | ||
3d4d5afa L |
602 | static const char *filename; |
603 | ||
40fb9820 L |
604 | static int |
605 | compare (const void *x, const void *y) | |
606 | { | |
607 | const bitfield *xp = (const bitfield *) x; | |
608 | const bitfield *yp = (const bitfield *) y; | |
609 | return xp->position - yp->position; | |
610 | } | |
611 | ||
40b8e679 L |
612 | static void |
613 | fail (const char *message, ...) | |
614 | { | |
615 | va_list args; | |
29c048b6 | 616 | |
40b8e679 L |
617 | va_start (args, message); |
618 | fprintf (stderr, _("%s: Error: "), program_name); | |
619 | vfprintf (stderr, message, args); | |
620 | va_end (args); | |
621 | xexit (1); | |
622 | } | |
623 | ||
72ffa0fb L |
624 | static void |
625 | process_copyright (FILE *fp) | |
626 | { | |
627 | fprintf (fp, "/* This file is automatically generated by i386-gen. Do not edit! */\n\ | |
6f2750fe | 628 | /* Copyright (C) 2007-2016 Free Software Foundation, Inc.\n\ |
72ffa0fb L |
629 | \n\ |
630 | This file is part of the GNU opcodes library.\n\ | |
631 | \n\ | |
632 | This library is free software; you can redistribute it and/or modify\n\ | |
633 | it under the terms of the GNU General Public License as published by\n\ | |
634 | the Free Software Foundation; either version 3, or (at your option)\n\ | |
635 | any later version.\n\ | |
636 | \n\ | |
637 | It is distributed in the hope that it will be useful, but WITHOUT\n\ | |
638 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\ | |
639 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n\ | |
640 | License for more details.\n\ | |
641 | \n\ | |
642 | You should have received a copy of the GNU General Public License\n\ | |
643 | along with this program; if not, write to the Free Software\n\ | |
644 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\n\ | |
645 | MA 02110-1301, USA. */\n"); | |
646 | } | |
647 | ||
40b8e679 L |
648 | /* Remove leading white spaces. */ |
649 | ||
650 | static char * | |
651 | remove_leading_whitespaces (char *str) | |
652 | { | |
653 | while (ISSPACE (*str)) | |
654 | str++; | |
655 | return str; | |
656 | } | |
657 | ||
658 | /* Remove trailing white spaces. */ | |
659 | ||
660 | static void | |
661 | remove_trailing_whitespaces (char *str) | |
662 | { | |
663 | size_t last = strlen (str); | |
664 | ||
665 | if (last == 0) | |
666 | return; | |
667 | ||
668 | do | |
669 | { | |
670 | last--; | |
671 | if (ISSPACE (str [last])) | |
672 | str[last] = '\0'; | |
673 | else | |
674 | break; | |
675 | } | |
676 | while (last != 0); | |
677 | } | |
678 | ||
93b1ec2c | 679 | /* Find next field separated by SEP and terminate it. Return a |
40b8e679 L |
680 | pointer to the one after it. */ |
681 | ||
682 | static char * | |
c587b3f9 | 683 | next_field (char *str, char sep, char **next, char *last) |
40b8e679 L |
684 | { |
685 | char *p; | |
686 | ||
687 | p = remove_leading_whitespaces (str); | |
93b1ec2c | 688 | for (str = p; *str != sep && *str != '\0'; str++); |
40b8e679 L |
689 | |
690 | *str = '\0'; | |
691 | remove_trailing_whitespaces (p); | |
692 | ||
29c048b6 | 693 | *next = str + 1; |
40b8e679 | 694 | |
c587b3f9 L |
695 | if (p >= last) |
696 | abort (); | |
697 | ||
40b8e679 L |
698 | return p; |
699 | } | |
700 | ||
40fb9820 | 701 | static void |
8a9036a4 L |
702 | set_bitfield (const char *f, bitfield *array, int value, |
703 | unsigned int size, int lineno) | |
40fb9820 L |
704 | { |
705 | unsigned int i; | |
706 | ||
309d3373 JB |
707 | if (strcmp (f, "CpuFP") == 0) |
708 | { | |
8a9036a4 L |
709 | set_bitfield("Cpu387", array, value, size, lineno); |
710 | set_bitfield("Cpu287", array, value, size, lineno); | |
309d3373 JB |
711 | f = "Cpu8087"; |
712 | } | |
713 | else if (strcmp (f, "Mmword") == 0) | |
7d5e4556 L |
714 | f= "Qword"; |
715 | else if (strcmp (f, "Oword") == 0) | |
716 | f= "Xmmword"; | |
40fb9820 L |
717 | |
718 | for (i = 0; i < size; i++) | |
719 | if (strcasecmp (array[i].name, f) == 0) | |
720 | { | |
8a9036a4 | 721 | array[i].value = value; |
40fb9820 L |
722 | return; |
723 | } | |
724 | ||
2bf05e57 L |
725 | if (value) |
726 | { | |
727 | const char *v = strchr (f, '='); | |
728 | ||
729 | if (v) | |
730 | { | |
731 | size_t n = v - f; | |
732 | char *end; | |
733 | ||
734 | for (i = 0; i < size; i++) | |
735 | if (strncasecmp (array[i].name, f, n) == 0) | |
736 | { | |
737 | value = strtol (v + 1, &end, 0); | |
738 | if (*end == '\0') | |
739 | { | |
740 | array[i].value = value; | |
741 | return; | |
742 | } | |
743 | break; | |
744 | } | |
745 | } | |
746 | } | |
747 | ||
bd5295b2 L |
748 | if (lineno != -1) |
749 | fail (_("%s: %d: Unknown bitfield: %s\n"), filename, lineno, f); | |
750 | else | |
751 | fail (_("Unknown bitfield: %s\n"), f); | |
40fb9820 L |
752 | } |
753 | ||
754 | static void | |
755 | output_cpu_flags (FILE *table, bitfield *flags, unsigned int size, | |
756 | int macro, const char *comma, const char *indent) | |
757 | { | |
758 | unsigned int i; | |
759 | ||
760 | fprintf (table, "%s{ { ", indent); | |
761 | ||
762 | for (i = 0; i < size - 1; i++) | |
763 | { | |
10632b79 L |
764 | if (((i + 1) % 20) != 0) |
765 | fprintf (table, "%d, ", flags[i].value); | |
766 | else | |
767 | fprintf (table, "%d,", flags[i].value); | |
40fb9820 L |
768 | if (((i + 1) % 20) == 0) |
769 | { | |
770 | /* We need \\ for macro. */ | |
771 | if (macro) | |
772 | fprintf (table, " \\\n %s", indent); | |
773 | else | |
774 | fprintf (table, "\n %s", indent); | |
775 | } | |
776 | } | |
777 | ||
778 | fprintf (table, "%d } }%s\n", flags[i].value, comma); | |
779 | } | |
780 | ||
781 | static void | |
782 | process_i386_cpu_flag (FILE *table, char *flag, int macro, | |
bd5295b2 L |
783 | const char *comma, const char *indent, |
784 | int lineno) | |
40fb9820 L |
785 | { |
786 | char *str, *next, *last; | |
8a9036a4 | 787 | unsigned int i; |
40fb9820 L |
788 | bitfield flags [ARRAY_SIZE (cpu_flags)]; |
789 | ||
790 | /* Copy the default cpu flags. */ | |
791 | memcpy (flags, cpu_flags, sizeof (cpu_flags)); | |
792 | ||
793 | if (strcasecmp (flag, "unknown") == 0) | |
794 | { | |
40fb9820 | 795 | /* We turn on everything except for cpu64 in case of |
8a9036a4 L |
796 | CPU_UNKNOWN_FLAGS. */ |
797 | for (i = 0; i < ARRAY_SIZE (flags); i++) | |
798 | if (flags[i].position != Cpu64) | |
799 | flags[i].value = 1; | |
800 | } | |
801 | else if (flag[0] == '~') | |
802 | { | |
803 | last = flag + strlen (flag); | |
804 | ||
805 | if (flag[1] == '(') | |
806 | { | |
807 | last -= 1; | |
808 | next = flag + 2; | |
809 | if (*last != ')') | |
810 | fail (_("%s: %d: Missing `)' in bitfield: %s\n"), filename, | |
811 | lineno, flag); | |
812 | *last = '\0'; | |
813 | } | |
814 | else | |
815 | next = flag + 1; | |
816 | ||
817 | /* First we turn on everything except for cpu64. */ | |
40fb9820 L |
818 | for (i = 0; i < ARRAY_SIZE (flags); i++) |
819 | if (flags[i].position != Cpu64) | |
820 | flags[i].value = 1; | |
8a9036a4 L |
821 | |
822 | /* Turn off selective bits. */ | |
823 | for (; next && next < last; ) | |
824 | { | |
825 | str = next_field (next, '|', &next, last); | |
826 | if (str) | |
827 | set_bitfield (str, flags, 0, ARRAY_SIZE (flags), lineno); | |
828 | } | |
40fb9820 L |
829 | } |
830 | else if (strcmp (flag, "0")) | |
831 | { | |
8a9036a4 | 832 | /* Turn on selective bits. */ |
40fb9820 L |
833 | last = flag + strlen (flag); |
834 | for (next = flag; next && next < last; ) | |
835 | { | |
c587b3f9 | 836 | str = next_field (next, '|', &next, last); |
40fb9820 | 837 | if (str) |
8a9036a4 | 838 | set_bitfield (str, flags, 1, ARRAY_SIZE (flags), lineno); |
40fb9820 L |
839 | } |
840 | } | |
841 | ||
842 | output_cpu_flags (table, flags, ARRAY_SIZE (flags), macro, | |
843 | comma, indent); | |
844 | } | |
845 | ||
846 | static void | |
847 | output_opcode_modifier (FILE *table, bitfield *modifier, unsigned int size) | |
848 | { | |
849 | unsigned int i; | |
850 | ||
851 | fprintf (table, " { "); | |
852 | ||
853 | for (i = 0; i < size - 1; i++) | |
854 | { | |
10632b79 L |
855 | if (((i + 1) % 20) != 0) |
856 | fprintf (table, "%d, ", modifier[i].value); | |
857 | else | |
858 | fprintf (table, "%d,", modifier[i].value); | |
40fb9820 L |
859 | if (((i + 1) % 20) == 0) |
860 | fprintf (table, "\n "); | |
861 | } | |
862 | ||
863 | fprintf (table, "%d },\n", modifier[i].value); | |
864 | } | |
865 | ||
866 | static void | |
bd5295b2 | 867 | process_i386_opcode_modifier (FILE *table, char *mod, int lineno) |
40fb9820 L |
868 | { |
869 | char *str, *next, *last; | |
870 | bitfield modifiers [ARRAY_SIZE (opcode_modifiers)]; | |
871 | ||
872 | /* Copy the default opcode modifier. */ | |
873 | memcpy (modifiers, opcode_modifiers, sizeof (modifiers)); | |
874 | ||
875 | if (strcmp (mod, "0")) | |
876 | { | |
877 | last = mod + strlen (mod); | |
878 | for (next = mod; next && next < last; ) | |
879 | { | |
c587b3f9 | 880 | str = next_field (next, '|', &next, last); |
40fb9820 | 881 | if (str) |
8a9036a4 L |
882 | set_bitfield (str, modifiers, 1, ARRAY_SIZE (modifiers), |
883 | lineno); | |
40fb9820 L |
884 | } |
885 | } | |
886 | output_opcode_modifier (table, modifiers, ARRAY_SIZE (modifiers)); | |
887 | } | |
888 | ||
889 | static void | |
890 | output_operand_type (FILE *table, bitfield *types, unsigned int size, | |
891 | int macro, const char *indent) | |
892 | { | |
893 | unsigned int i; | |
894 | ||
895 | fprintf (table, "{ { "); | |
896 | ||
897 | for (i = 0; i < size - 1; i++) | |
898 | { | |
10632b79 L |
899 | if (((i + 1) % 20) != 0) |
900 | fprintf (table, "%d, ", types[i].value); | |
901 | else | |
902 | fprintf (table, "%d,", types[i].value); | |
40fb9820 L |
903 | if (((i + 1) % 20) == 0) |
904 | { | |
905 | /* We need \\ for macro. */ | |
906 | if (macro) | |
10632b79 | 907 | fprintf (table, " \\\n%s", indent); |
40fb9820 L |
908 | else |
909 | fprintf (table, "\n%s", indent); | |
910 | } | |
911 | } | |
912 | ||
913 | fprintf (table, "%d } }", types[i].value); | |
914 | } | |
915 | ||
916 | static void | |
917 | process_i386_operand_type (FILE *table, char *op, int macro, | |
bd5295b2 | 918 | const char *indent, int lineno) |
40fb9820 L |
919 | { |
920 | char *str, *next, *last; | |
921 | bitfield types [ARRAY_SIZE (operand_types)]; | |
922 | ||
923 | /* Copy the default operand type. */ | |
924 | memcpy (types, operand_types, sizeof (types)); | |
925 | ||
926 | if (strcmp (op, "0")) | |
927 | { | |
928 | last = op + strlen (op); | |
929 | for (next = op; next && next < last; ) | |
930 | { | |
c587b3f9 | 931 | str = next_field (next, '|', &next, last); |
40fb9820 | 932 | if (str) |
8a9036a4 | 933 | set_bitfield (str, types, 1, ARRAY_SIZE (types), lineno); |
40fb9820 L |
934 | } |
935 | } | |
936 | output_operand_type (table, types, ARRAY_SIZE (types), macro, | |
937 | indent); | |
938 | } | |
939 | ||
c587b3f9 L |
940 | static void |
941 | output_i386_opcode (FILE *table, const char *name, char *str, | |
bd5295b2 | 942 | char *last, int lineno) |
c587b3f9 L |
943 | { |
944 | unsigned int i; | |
945 | char *operands, *base_opcode, *extension_opcode, *opcode_length; | |
946 | char *cpu_flags, *opcode_modifier, *operand_types [MAX_OPERANDS]; | |
947 | ||
948 | /* Find number of operands. */ | |
949 | operands = next_field (str, ',', &str, last); | |
950 | ||
951 | /* Find base_opcode. */ | |
952 | base_opcode = next_field (str, ',', &str, last); | |
953 | ||
954 | /* Find extension_opcode. */ | |
955 | extension_opcode = next_field (str, ',', &str, last); | |
956 | ||
957 | /* Find opcode_length. */ | |
958 | opcode_length = next_field (str, ',', &str, last); | |
959 | ||
960 | /* Find cpu_flags. */ | |
961 | cpu_flags = next_field (str, ',', &str, last); | |
962 | ||
963 | /* Find opcode_modifier. */ | |
964 | opcode_modifier = next_field (str, ',', &str, last); | |
965 | ||
966 | /* Remove the first {. */ | |
967 | str = remove_leading_whitespaces (str); | |
968 | if (*str != '{') | |
969 | abort (); | |
970 | str = remove_leading_whitespaces (str + 1); | |
971 | ||
972 | i = strlen (str); | |
973 | ||
974 | /* There are at least "X}". */ | |
975 | if (i < 2) | |
976 | abort (); | |
977 | ||
978 | /* Remove trailing white spaces and }. */ | |
979 | do | |
980 | { | |
981 | i--; | |
982 | if (ISSPACE (str[i]) || str[i] == '}') | |
983 | str[i] = '\0'; | |
984 | else | |
985 | break; | |
986 | } | |
987 | while (i != 0); | |
988 | ||
989 | last = str + i; | |
990 | ||
991 | /* Find operand_types. */ | |
992 | for (i = 0; i < ARRAY_SIZE (operand_types); i++) | |
993 | { | |
994 | if (str >= last) | |
995 | { | |
996 | operand_types [i] = NULL; | |
997 | break; | |
998 | } | |
999 | ||
1000 | operand_types [i] = next_field (str, ',', &str, last); | |
1001 | if (*operand_types[i] == '0') | |
1002 | { | |
1003 | if (i != 0) | |
1004 | operand_types[i] = NULL; | |
1005 | break; | |
1006 | } | |
1007 | } | |
1008 | ||
1009 | fprintf (table, " { \"%s\", %s, %s, %s, %s,\n", | |
1010 | name, operands, base_opcode, extension_opcode, | |
1011 | opcode_length); | |
1012 | ||
bd5295b2 | 1013 | process_i386_cpu_flag (table, cpu_flags, 0, ",", " ", lineno); |
c587b3f9 | 1014 | |
bd5295b2 | 1015 | process_i386_opcode_modifier (table, opcode_modifier, lineno); |
c587b3f9 L |
1016 | |
1017 | fprintf (table, " { "); | |
1018 | ||
1019 | for (i = 0; i < ARRAY_SIZE (operand_types); i++) | |
1020 | { | |
1021 | if (operand_types[i] == NULL || *operand_types[i] == '0') | |
1022 | { | |
1023 | if (i == 0) | |
bd5295b2 | 1024 | process_i386_operand_type (table, "0", 0, "\t ", lineno); |
c587b3f9 L |
1025 | break; |
1026 | } | |
1027 | ||
1028 | if (i != 0) | |
1029 | fprintf (table, ",\n "); | |
1030 | ||
1031 | process_i386_operand_type (table, operand_types[i], 0, | |
bd5295b2 | 1032 | "\t ", lineno); |
c587b3f9 L |
1033 | } |
1034 | fprintf (table, " } },\n"); | |
1035 | } | |
1036 | ||
1037 | struct opcode_hash_entry | |
1038 | { | |
1039 | struct opcode_hash_entry *next; | |
1040 | char *name; | |
1041 | char *opcode; | |
bd5295b2 | 1042 | int lineno; |
c587b3f9 L |
1043 | }; |
1044 | ||
1045 | /* Calculate the hash value of an opcode hash entry P. */ | |
1046 | ||
1047 | static hashval_t | |
1048 | opcode_hash_hash (const void *p) | |
1049 | { | |
1050 | struct opcode_hash_entry *entry = (struct opcode_hash_entry *) p; | |
1051 | return htab_hash_string (entry->name); | |
1052 | } | |
1053 | ||
1054 | /* Compare a string Q against an opcode hash entry P. */ | |
1055 | ||
1056 | static int | |
1057 | opcode_hash_eq (const void *p, const void *q) | |
1058 | { | |
1059 | struct opcode_hash_entry *entry = (struct opcode_hash_entry *) p; | |
1060 | const char *name = (const char *) q; | |
1061 | return strcmp (name, entry->name) == 0; | |
1062 | } | |
1063 | ||
40b8e679 | 1064 | static void |
72ffa0fb | 1065 | process_i386_opcodes (FILE *table) |
40b8e679 | 1066 | { |
3d4d5afa | 1067 | FILE *fp; |
40b8e679 | 1068 | char buf[2048]; |
c587b3f9 L |
1069 | unsigned int i, j; |
1070 | char *str, *p, *last, *name; | |
1071 | struct opcode_hash_entry **hash_slot, **entry, *next; | |
1072 | htab_t opcode_hash_table; | |
1073 | struct opcode_hash_entry **opcode_array; | |
1074 | unsigned int opcode_array_size = 1024; | |
bd5295b2 | 1075 | int lineno = 0; |
40b8e679 | 1076 | |
3d4d5afa L |
1077 | filename = "i386-opc.tbl"; |
1078 | fp = fopen (filename, "r"); | |
1079 | ||
40b8e679 | 1080 | if (fp == NULL) |
34edb9ad | 1081 | fail (_("can't find i386-opc.tbl for reading, errno = %s\n"), |
40fb9820 | 1082 | xstrerror (errno)); |
40b8e679 | 1083 | |
c587b3f9 L |
1084 | i = 0; |
1085 | opcode_array = (struct opcode_hash_entry **) | |
1086 | xmalloc (sizeof (*opcode_array) * opcode_array_size); | |
1087 | ||
1088 | opcode_hash_table = htab_create_alloc (16, opcode_hash_hash, | |
1089 | opcode_hash_eq, NULL, | |
1090 | xcalloc, free); | |
1091 | ||
34edb9ad | 1092 | fprintf (table, "\n/* i386 opcode table. */\n\n"); |
d3ce72d0 | 1093 | fprintf (table, "const insn_template i386_optab[] =\n{\n"); |
40b8e679 | 1094 | |
c587b3f9 | 1095 | /* Put everything on opcode array. */ |
40b8e679 L |
1096 | while (!feof (fp)) |
1097 | { | |
1098 | if (fgets (buf, sizeof (buf), fp) == NULL) | |
1099 | break; | |
1100 | ||
3d4d5afa L |
1101 | lineno++; |
1102 | ||
40b8e679 L |
1103 | p = remove_leading_whitespaces (buf); |
1104 | ||
1105 | /* Skip comments. */ | |
1106 | str = strstr (p, "//"); | |
1107 | if (str != NULL) | |
1108 | str[0] = '\0'; | |
1109 | ||
1110 | /* Remove trailing white spaces. */ | |
1111 | remove_trailing_whitespaces (p); | |
1112 | ||
1113 | switch (p[0]) | |
1114 | { | |
1115 | case '#': | |
c587b3f9 | 1116 | /* Ignore comments. */ |
40b8e679 L |
1117 | case '\0': |
1118 | continue; | |
1119 | break; | |
1120 | default: | |
1121 | break; | |
1122 | } | |
1123 | ||
1124 | last = p + strlen (p); | |
1125 | ||
1126 | /* Find name. */ | |
c587b3f9 | 1127 | name = next_field (p, ',', &str, last); |
40b8e679 | 1128 | |
c587b3f9 L |
1129 | /* Get the slot in hash table. */ |
1130 | hash_slot = (struct opcode_hash_entry **) | |
1131 | htab_find_slot_with_hash (opcode_hash_table, name, | |
1132 | htab_hash_string (name), | |
1133 | INSERT); | |
40b8e679 | 1134 | |
c587b3f9 | 1135 | if (*hash_slot == NULL) |
40b8e679 | 1136 | { |
c587b3f9 L |
1137 | /* It is the new one. Put it on opcode array. */ |
1138 | if (i >= opcode_array_size) | |
40b8e679 | 1139 | { |
c587b3f9 L |
1140 | /* Grow the opcode array when needed. */ |
1141 | opcode_array_size += 1024; | |
1142 | opcode_array = (struct opcode_hash_entry **) | |
1143 | xrealloc (opcode_array, | |
1144 | sizeof (*opcode_array) * opcode_array_size); | |
40b8e679 L |
1145 | } |
1146 | ||
c587b3f9 L |
1147 | opcode_array[i] = (struct opcode_hash_entry *) |
1148 | xmalloc (sizeof (struct opcode_hash_entry)); | |
1149 | opcode_array[i]->next = NULL; | |
1150 | opcode_array[i]->name = xstrdup (name); | |
1151 | opcode_array[i]->opcode = xstrdup (str); | |
bd5295b2 | 1152 | opcode_array[i]->lineno = lineno; |
c587b3f9 L |
1153 | *hash_slot = opcode_array[i]; |
1154 | i++; | |
40b8e679 | 1155 | } |
c587b3f9 | 1156 | else |
40b8e679 | 1157 | { |
c587b3f9 L |
1158 | /* Append it to the existing one. */ |
1159 | entry = hash_slot; | |
1160 | while ((*entry) != NULL) | |
1161 | entry = &(*entry)->next; | |
1162 | *entry = (struct opcode_hash_entry *) | |
1163 | xmalloc (sizeof (struct opcode_hash_entry)); | |
1164 | (*entry)->next = NULL; | |
1165 | (*entry)->name = (*hash_slot)->name; | |
1166 | (*entry)->opcode = xstrdup (str); | |
bd5295b2 | 1167 | (*entry)->lineno = lineno; |
c587b3f9 L |
1168 | } |
1169 | } | |
40b8e679 | 1170 | |
c587b3f9 L |
1171 | /* Process opcode array. */ |
1172 | for (j = 0; j < i; j++) | |
1173 | { | |
1174 | for (next = opcode_array[j]; next; next = next->next) | |
1175 | { | |
1176 | name = next->name; | |
1177 | str = next->opcode; | |
bd5295b2 | 1178 | lineno = next->lineno; |
c587b3f9 | 1179 | last = str + strlen (str); |
bd5295b2 | 1180 | output_i386_opcode (table, name, str, last, lineno); |
40b8e679 | 1181 | } |
40b8e679 L |
1182 | } |
1183 | ||
34edb9ad L |
1184 | fclose (fp); |
1185 | ||
4dffcebc | 1186 | fprintf (table, " { NULL, 0, 0, 0, 0,\n"); |
40fb9820 | 1187 | |
bd5295b2 | 1188 | process_i386_cpu_flag (table, "0", 0, ",", " ", -1); |
40fb9820 | 1189 | |
bd5295b2 | 1190 | process_i386_opcode_modifier (table, "0", -1); |
29c048b6 | 1191 | |
40fb9820 | 1192 | fprintf (table, " { "); |
bd5295b2 | 1193 | process_i386_operand_type (table, "0", 0, "\t ", -1); |
40fb9820 L |
1194 | fprintf (table, " } }\n"); |
1195 | ||
34edb9ad | 1196 | fprintf (table, "};\n"); |
40b8e679 L |
1197 | } |
1198 | ||
1199 | static void | |
72ffa0fb | 1200 | process_i386_registers (FILE *table) |
40b8e679 | 1201 | { |
3d4d5afa | 1202 | FILE *fp; |
40b8e679 L |
1203 | char buf[2048]; |
1204 | char *str, *p, *last; | |
1205 | char *reg_name, *reg_type, *reg_flags, *reg_num; | |
a60de03c | 1206 | char *dw2_32_num, *dw2_64_num; |
bd5295b2 | 1207 | int lineno = 0; |
40b8e679 | 1208 | |
3d4d5afa L |
1209 | filename = "i386-reg.tbl"; |
1210 | fp = fopen (filename, "r"); | |
40b8e679 | 1211 | if (fp == NULL) |
34edb9ad | 1212 | fail (_("can't find i386-reg.tbl for reading, errno = %s\n"), |
40fb9820 | 1213 | xstrerror (errno)); |
40b8e679 | 1214 | |
34edb9ad L |
1215 | fprintf (table, "\n/* i386 register table. */\n\n"); |
1216 | fprintf (table, "const reg_entry i386_regtab[] =\n{\n"); | |
40b8e679 L |
1217 | |
1218 | while (!feof (fp)) | |
1219 | { | |
1220 | if (fgets (buf, sizeof (buf), fp) == NULL) | |
1221 | break; | |
1222 | ||
3d4d5afa L |
1223 | lineno++; |
1224 | ||
40b8e679 L |
1225 | p = remove_leading_whitespaces (buf); |
1226 | ||
1227 | /* Skip comments. */ | |
1228 | str = strstr (p, "//"); | |
1229 | if (str != NULL) | |
1230 | str[0] = '\0'; | |
1231 | ||
1232 | /* Remove trailing white spaces. */ | |
1233 | remove_trailing_whitespaces (p); | |
1234 | ||
1235 | switch (p[0]) | |
1236 | { | |
1237 | case '#': | |
34edb9ad | 1238 | fprintf (table, "%s\n", p); |
40b8e679 L |
1239 | case '\0': |
1240 | continue; | |
1241 | break; | |
1242 | default: | |
1243 | break; | |
1244 | } | |
1245 | ||
1246 | last = p + strlen (p); | |
1247 | ||
1248 | /* Find reg_name. */ | |
c587b3f9 | 1249 | reg_name = next_field (p, ',', &str, last); |
40b8e679 L |
1250 | |
1251 | /* Find reg_type. */ | |
c587b3f9 | 1252 | reg_type = next_field (str, ',', &str, last); |
40b8e679 L |
1253 | |
1254 | /* Find reg_flags. */ | |
c587b3f9 | 1255 | reg_flags = next_field (str, ',', &str, last); |
40b8e679 L |
1256 | |
1257 | /* Find reg_num. */ | |
c587b3f9 | 1258 | reg_num = next_field (str, ',', &str, last); |
a60de03c | 1259 | |
40fb9820 L |
1260 | fprintf (table, " { \"%s\",\n ", reg_name); |
1261 | ||
bd5295b2 | 1262 | process_i386_operand_type (table, reg_type, 0, "\t", lineno); |
40fb9820 | 1263 | |
a60de03c | 1264 | /* Find 32-bit Dwarf2 register number. */ |
c587b3f9 | 1265 | dw2_32_num = next_field (str, ',', &str, last); |
a60de03c JB |
1266 | |
1267 | /* Find 64-bit Dwarf2 register number. */ | |
c587b3f9 | 1268 | dw2_64_num = next_field (str, ',', &str, last); |
a60de03c JB |
1269 | |
1270 | fprintf (table, ",\n %s, %s, { %s, %s } },\n", | |
1271 | reg_flags, reg_num, dw2_32_num, dw2_64_num); | |
40b8e679 L |
1272 | } |
1273 | ||
34edb9ad L |
1274 | fclose (fp); |
1275 | ||
1276 | fprintf (table, "};\n"); | |
40b8e679 | 1277 | |
34edb9ad | 1278 | fprintf (table, "\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n"); |
40b8e679 L |
1279 | } |
1280 | ||
40fb9820 L |
1281 | static void |
1282 | process_i386_initializers (void) | |
1283 | { | |
1284 | unsigned int i; | |
1285 | FILE *fp = fopen ("i386-init.h", "w"); | |
1286 | char *init; | |
1287 | ||
1288 | if (fp == NULL) | |
1289 | fail (_("can't create i386-init.h, errno = %s\n"), | |
1290 | xstrerror (errno)); | |
1291 | ||
1292 | process_copyright (fp); | |
1293 | ||
1294 | for (i = 0; i < ARRAY_SIZE (cpu_flag_init); i++) | |
1295 | { | |
1296 | fprintf (fp, "\n#define %s \\\n", cpu_flag_init[i].name); | |
1297 | init = xstrdup (cpu_flag_init[i].init); | |
bd5295b2 | 1298 | process_i386_cpu_flag (fp, init, 1, "", " ", -1); |
40fb9820 L |
1299 | free (init); |
1300 | } | |
1301 | ||
1302 | for (i = 0; i < ARRAY_SIZE (operand_type_init); i++) | |
1303 | { | |
1304 | fprintf (fp, "\n\n#define %s \\\n ", operand_type_init[i].name); | |
1305 | init = xstrdup (operand_type_init[i].init); | |
bd5295b2 | 1306 | process_i386_operand_type (fp, init, 1, " ", -1); |
40fb9820 L |
1307 | free (init); |
1308 | } | |
1309 | fprintf (fp, "\n"); | |
1310 | ||
1311 | fclose (fp); | |
1312 | } | |
1313 | ||
40b8e679 L |
1314 | /* Program options. */ |
1315 | #define OPTION_SRCDIR 200 | |
1316 | ||
29c048b6 | 1317 | struct option long_options[] = |
40b8e679 L |
1318 | { |
1319 | {"srcdir", required_argument, NULL, OPTION_SRCDIR}, | |
1320 | {"debug", no_argument, NULL, 'd'}, | |
1321 | {"version", no_argument, NULL, 'V'}, | |
1322 | {"help", no_argument, NULL, 'h'}, | |
1323 | {0, no_argument, NULL, 0} | |
1324 | }; | |
1325 | ||
1326 | static void | |
1327 | print_version (void) | |
1328 | { | |
1329 | printf ("%s: version 1.0\n", program_name); | |
1330 | xexit (0); | |
1331 | } | |
1332 | ||
1333 | static void | |
1334 | usage (FILE * stream, int status) | |
1335 | { | |
1336 | fprintf (stream, "Usage: %s [-V | --version] [-d | --debug] [--srcdir=dirname] [--help]\n", | |
1337 | program_name); | |
1338 | xexit (status); | |
1339 | } | |
1340 | ||
1341 | int | |
1342 | main (int argc, char **argv) | |
1343 | { | |
1344 | extern int chdir (char *); | |
1345 | char *srcdir = NULL; | |
8b40d594 | 1346 | int c; |
72ffa0fb | 1347 | FILE *table; |
29c048b6 | 1348 | |
40b8e679 L |
1349 | program_name = *argv; |
1350 | xmalloc_set_program_name (program_name); | |
1351 | ||
1352 | while ((c = getopt_long (argc, argv, "vVdh", long_options, 0)) != EOF) | |
1353 | switch (c) | |
1354 | { | |
1355 | case OPTION_SRCDIR: | |
1356 | srcdir = optarg; | |
1357 | break; | |
1358 | case 'V': | |
1359 | case 'v': | |
1360 | print_version (); | |
1361 | break; | |
1362 | case 'd': | |
1363 | debug = 1; | |
1364 | break; | |
1365 | case 'h': | |
1366 | case '?': | |
1367 | usage (stderr, 0); | |
1368 | default: | |
1369 | case 0: | |
1370 | break; | |
1371 | } | |
1372 | ||
1373 | if (optind != argc) | |
1374 | usage (stdout, 1); | |
1375 | ||
29c048b6 | 1376 | if (srcdir != NULL) |
40b8e679 L |
1377 | if (chdir (srcdir) != 0) |
1378 | fail (_("unable to change directory to \"%s\", errno = %s\n"), | |
40fb9820 L |
1379 | srcdir, xstrerror (errno)); |
1380 | ||
1381 | /* Check the unused bitfield in i386_cpu_flags. */ | |
1382 | #ifndef CpuUnused | |
8b40d594 L |
1383 | c = CpuNumOfBits - CpuMax - 1; |
1384 | if (c) | |
1385 | fail (_("%d unused bits in i386_cpu_flags.\n"), c); | |
40fb9820 L |
1386 | #endif |
1387 | ||
1388 | /* Check the unused bitfield in i386_operand_type. */ | |
1389 | #ifndef OTUnused | |
8b40d594 L |
1390 | c = OTNumOfBits - OTMax - 1; |
1391 | if (c) | |
1392 | fail (_("%d unused bits in i386_operand_type.\n"), c); | |
40fb9820 L |
1393 | #endif |
1394 | ||
1395 | qsort (cpu_flags, ARRAY_SIZE (cpu_flags), sizeof (cpu_flags [0]), | |
1396 | compare); | |
1397 | ||
1398 | qsort (opcode_modifiers, ARRAY_SIZE (opcode_modifiers), | |
1399 | sizeof (opcode_modifiers [0]), compare); | |
1400 | ||
1401 | qsort (operand_types, ARRAY_SIZE (operand_types), | |
1402 | sizeof (operand_types [0]), compare); | |
40b8e679 | 1403 | |
34edb9ad L |
1404 | table = fopen ("i386-tbl.h", "w"); |
1405 | if (table == NULL) | |
40fb9820 L |
1406 | fail (_("can't create i386-tbl.h, errno = %s\n"), |
1407 | xstrerror (errno)); | |
34edb9ad | 1408 | |
72ffa0fb | 1409 | process_copyright (table); |
40b8e679 | 1410 | |
72ffa0fb L |
1411 | process_i386_opcodes (table); |
1412 | process_i386_registers (table); | |
40fb9820 | 1413 | process_i386_initializers (); |
40b8e679 | 1414 | |
34edb9ad L |
1415 | fclose (table); |
1416 | ||
40b8e679 L |
1417 | exit (0); |
1418 | } |