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