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