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