1 1.1 christos /* Declarations for Intel 80386 opcode table 2 1.1.1.11 christos Copyright (C) 2007-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of the GNU opcodes library. 5 1.1 christos 6 1.1 christos This library is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3, or (at your option) 9 1.1 christos any later version. 10 1.1 christos 11 1.1 christos It is distributed in the hope that it will be useful, but WITHOUT 12 1.1 christos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 1.1 christos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14 1.1 christos License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with GAS; see the file COPYING. If not, write to the Free 18 1.1 christos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 19 1.1 christos 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #include "opcode/i386.h" 22 1.1 christos #include <limits.h> 23 1.1 christos #ifndef CHAR_BIT 24 1.1 christos #define CHAR_BIT 8 25 1.1 christos #endif 26 1.1 christos 27 1.1 christos /* Position of cpu flags bitfiled. */ 28 1.1 christos 29 1.1.1.11 christos enum i386_cpu 30 1.1 christos { 31 1.1 christos /* i186 or better required */ 32 1.1 christos Cpu186 = 0, 33 1.1 christos /* i286 or better required */ 34 1.1 christos Cpu286, 35 1.1 christos /* i386 or better required */ 36 1.1 christos Cpu386, 37 1.1 christos /* i486 or better required */ 38 1.1 christos Cpu486, 39 1.1 christos /* i585 or better required */ 40 1.1 christos Cpu586, 41 1.1 christos /* i686 or better required */ 42 1.1 christos Cpu686, 43 1.1.1.8 christos /* CMOV Instruction support required */ 44 1.1.1.8 christos CpuCMOV, 45 1.1.1.8 christos /* FXSR Instruction support required */ 46 1.1.1.8 christos CpuFXSR, 47 1.1 christos /* CLFLUSH Instruction support required */ 48 1.1 christos CpuClflush, 49 1.1 christos /* NOP Instruction support required */ 50 1.1 christos CpuNop, 51 1.1 christos /* SYSCALL Instructions support required */ 52 1.1 christos CpuSYSCALL, 53 1.1 christos /* Floating point support required */ 54 1.1 christos Cpu8087, 55 1.1 christos /* i686 and floating point support required */ 56 1.1 christos Cpu687, 57 1.1 christos /* SSE3 and floating point support required */ 58 1.1 christos CpuFISTTP, 59 1.1 christos /* MMX support required */ 60 1.1 christos CpuMMX, 61 1.1 christos /* SSE support required */ 62 1.1 christos CpuSSE, 63 1.1 christos /* SSE2 support required */ 64 1.1 christos CpuSSE2, 65 1.1 christos /* SSE3 support required */ 66 1.1 christos CpuSSE3, 67 1.1 christos /* VIA PadLock required */ 68 1.1 christos CpuPadLock, 69 1.1.1.12 christos /* ZHAOXIN GMI required */ 70 1.1.1.12 christos CpuGMI, 71 1.1 christos /* AMD Secure Virtual Machine Ext-s required */ 72 1.1 christos CpuSVME, 73 1.1 christos /* VMX Instructions required */ 74 1.1 christos CpuVMX, 75 1.1 christos /* SMX Instructions required */ 76 1.1 christos CpuSMX, 77 1.1 christos /* SSSE3 support required */ 78 1.1 christos CpuSSSE3, 79 1.1 christos /* SSE4a support required */ 80 1.1 christos CpuSSE4a, 81 1.1.1.9 christos /* LZCNT support required */ 82 1.1.1.9 christos CpuLZCNT, 83 1.1.1.9 christos /* POPCNT support required */ 84 1.1.1.9 christos CpuPOPCNT, 85 1.1.1.11 christos /* MONITOR support required */ 86 1.1.1.11 christos CpuMONITOR, 87 1.1 christos /* SSE4.1 support required */ 88 1.1 christos CpuSSE4_1, 89 1.1 christos /* SSE4.2 support required */ 90 1.1 christos CpuSSE4_2, 91 1.1.1.2 christos /* AVX2 support required */ 92 1.1.1.2 christos CpuAVX2, 93 1.1.1.3 christos /* Intel AVX-512 Conflict Detection Instructions support required */ 94 1.1.1.3 christos CpuAVX512CD, 95 1.1.1.3 christos /* Intel AVX-512 Exponential and Reciprocal Instructions support 96 1.1.1.3 christos required */ 97 1.1.1.3 christos CpuAVX512ER, 98 1.1.1.3 christos /* Intel AVX-512 Prefetch Instructions support required */ 99 1.1.1.3 christos CpuAVX512PF, 100 1.1.1.4 christos /* Intel AVX-512 DQ Instructions support required. */ 101 1.1.1.4 christos CpuAVX512DQ, 102 1.1.1.4 christos /* Intel AVX-512 BW Instructions support required. */ 103 1.1.1.4 christos CpuAVX512BW, 104 1.1.1.5 christos /* Intel IAMCU support required */ 105 1.1.1.5 christos CpuIAMCU, 106 1.1 christos /* Xsave/xrstor New Instructions support required */ 107 1.1 christos CpuXsave, 108 1.1 christos /* Xsaveopt New Instructions support required */ 109 1.1 christos CpuXsaveopt, 110 1.1 christos /* AES support required */ 111 1.1 christos CpuAES, 112 1.1.1.11 christos /* PCLMULQDQ support required */ 113 1.1.1.11 christos CpuPCLMULQDQ, 114 1.1 christos /* FMA support required */ 115 1.1 christos CpuFMA, 116 1.1 christos /* FMA4 support required */ 117 1.1 christos CpuFMA4, 118 1.1 christos /* XOP support required */ 119 1.1 christos CpuXOP, 120 1.1 christos /* LWP support required */ 121 1.1 christos CpuLWP, 122 1.1 christos /* BMI support required */ 123 1.1 christos CpuBMI, 124 1.1 christos /* TBM support required */ 125 1.1 christos CpuTBM, 126 1.1 christos /* MOVBE Instruction support required */ 127 1.1 christos CpuMovbe, 128 1.1.1.2 christos /* CMPXCHG16B instruction support required. */ 129 1.1.1.2 christos CpuCX16, 130 1.1.1.11 christos /* LAHF/SAHF instruction support required (in 64-bit mode). */ 131 1.1.1.11 christos CpuLAHF_SAHF, 132 1.1 christos /* EPT Instructions required */ 133 1.1 christos CpuEPT, 134 1.1 christos /* RDTSCP Instruction support required */ 135 1.1 christos CpuRdtscp, 136 1.1 christos /* FSGSBASE Instructions required */ 137 1.1 christos CpuFSGSBase, 138 1.1 christos /* RDRND Instructions required */ 139 1.1 christos CpuRdRnd, 140 1.1 christos /* F16C Instructions required */ 141 1.1 christos CpuF16C, 142 1.1.1.2 christos /* Intel BMI2 support required */ 143 1.1.1.2 christos CpuBMI2, 144 1.1.1.2 christos /* RTM support required */ 145 1.1.1.2 christos CpuRTM, 146 1.1.1.2 christos /* INVPCID Instructions required */ 147 1.1.1.2 christos CpuINVPCID, 148 1.1.1.2 christos /* VMFUNC Instruction required */ 149 1.1.1.2 christos CpuVMFUNC, 150 1.1.1.3 christos /* Intel MPX Instructions required */ 151 1.1.1.3 christos CpuMPX, 152 1.1.1.2 christos /* RDRSEED instruction required. */ 153 1.1.1.2 christos CpuRDSEED, 154 1.1.1.2 christos /* Multi-presisionn add-carry instructions are required. */ 155 1.1.1.2 christos CpuADX, 156 1.1.1.2 christos /* Supports prefetchw and prefetch instructions. */ 157 1.1.1.2 christos CpuPRFCHW, 158 1.1.1.2 christos /* SMAP instructions required. */ 159 1.1.1.2 christos CpuSMAP, 160 1.1.1.3 christos /* SHA instructions required. */ 161 1.1.1.3 christos CpuSHA, 162 1.1.1.11 christos /* SHA512 instructions required. */ 163 1.1.1.11 christos CpuSHA512, 164 1.1.1.11 christos /* SM3 instructions required. */ 165 1.1.1.11 christos CpuSM3, 166 1.1.1.11 christos /* SM4 instructions required. */ 167 1.1.1.11 christos CpuSM4, 168 1.1.1.4 christos /* CLFLUSHOPT instruction required */ 169 1.1.1.4 christos CpuClflushOpt, 170 1.1.1.4 christos /* XSAVES/XRSTORS instruction required */ 171 1.1.1.4 christos CpuXSAVES, 172 1.1.1.4 christos /* XSAVEC instruction required */ 173 1.1.1.4 christos CpuXSAVEC, 174 1.1.1.4 christos /* PREFETCHWT1 instruction required */ 175 1.1.1.4 christos CpuPREFETCHWT1, 176 1.1.1.4 christos /* SE1 instruction required */ 177 1.1.1.4 christos CpuSE1, 178 1.1.1.4 christos /* CLWB instruction required */ 179 1.1.1.4 christos CpuCLWB, 180 1.1.1.4 christos /* Intel AVX-512 IFMA Instructions support required. */ 181 1.1.1.4 christos CpuAVX512IFMA, 182 1.1.1.4 christos /* Intel AVX-512 VBMI Instructions support required. */ 183 1.1.1.4 christos CpuAVX512VBMI, 184 1.1.1.7 christos /* Intel AVX-512 4FMAPS Instructions support required. */ 185 1.1.1.7 christos CpuAVX512_4FMAPS, 186 1.1.1.7 christos /* Intel AVX-512 4VNNIW Instructions support required. */ 187 1.1.1.7 christos CpuAVX512_4VNNIW, 188 1.1.1.7 christos /* Intel AVX-512 VPOPCNTDQ Instructions support required. */ 189 1.1.1.7 christos CpuAVX512_VPOPCNTDQ, 190 1.1.1.8 christos /* Intel AVX-512 VBMI2 Instructions support required. */ 191 1.1.1.8 christos CpuAVX512_VBMI2, 192 1.1.1.8 christos /* Intel AVX-512 VNNI Instructions support required. */ 193 1.1.1.8 christos CpuAVX512_VNNI, 194 1.1.1.8 christos /* Intel AVX-512 BITALG Instructions support required. */ 195 1.1.1.8 christos CpuAVX512_BITALG, 196 1.1.1.9 christos /* Intel AVX-512 BF16 Instructions support required. */ 197 1.1.1.9 christos CpuAVX512_BF16, 198 1.1.1.9 christos /* Intel AVX-512 VP2INTERSECT Instructions support required. */ 199 1.1.1.9 christos CpuAVX512_VP2INTERSECT, 200 1.1.1.10 christos /* TDX Instructions support required. */ 201 1.1.1.10 christos CpuTDX, 202 1.1.1.10 christos /* Intel AVX VNNI Instructions support required. */ 203 1.1.1.10 christos CpuAVX_VNNI, 204 1.1.1.10 christos /* Intel AVX-512 FP16 Instructions support required. */ 205 1.1.1.10 christos CpuAVX512_FP16, 206 1.1.1.10 christos /* PREFETCHI instruction required */ 207 1.1.1.10 christos CpuPREFETCHI, 208 1.1.1.10 christos /* Intel AVX IFMA Instructions support required. */ 209 1.1.1.10 christos CpuAVX_IFMA, 210 1.1.1.10 christos /* Intel AVX VNNI-INT8 Instructions support required. */ 211 1.1.1.10 christos CpuAVX_VNNI_INT8, 212 1.1.1.11 christos /* Intel AVX VNNI-INT16 Instructions support required. */ 213 1.1.1.11 christos CpuAVX_VNNI_INT16, 214 1.1.1.10 christos /* Intel CMPccXADD instructions support required. */ 215 1.1.1.10 christos CpuCMPCCXADD, 216 1.1.1.10 christos /* Intel WRMSRNS Instructions support required */ 217 1.1.1.10 christos CpuWRMSRNS, 218 1.1.1.10 christos /* Intel MSRLIST Instructions support required. */ 219 1.1.1.10 christos CpuMSRLIST, 220 1.1.1.10 christos /* Intel AVX NE CONVERT Instructions support required. */ 221 1.1.1.10 christos CpuAVX_NE_CONVERT, 222 1.1.1.10 christos /* Intel RAO INT Instructions support required. */ 223 1.1.1.10 christos CpuRAO_INT, 224 1.1.1.11 christos /* fred instruction required */ 225 1.1.1.11 christos CpuFRED, 226 1.1.1.11 christos /* lkgs instruction required */ 227 1.1.1.11 christos CpuLKGS, 228 1.1.1.11 christos /* Intel USER_MSR Instruction support required. */ 229 1.1.1.11 christos CpuUSER_MSR, 230 1.1.1.12 christos /* Intel MSR_IMM Instructions support required. */ 231 1.1.1.12 christos CpuMSR_IMM, 232 1.1.1.5 christos /* mwaitx instruction required */ 233 1.1.1.5 christos CpuMWAITX, 234 1.1.1.6 christos /* Clzero instruction required */ 235 1.1.1.5 christos CpuCLZERO, 236 1.1.1.6 christos /* OSPKE instruction required */ 237 1.1.1.6 christos CpuOSPKE, 238 1.1.1.6 christos /* RDPID instruction required */ 239 1.1.1.6 christos CpuRDPID, 240 1.1.1.7 christos /* PTWRITE instruction required */ 241 1.1.1.7 christos CpuPTWRITE, 242 1.1.1.8 christos /* CET instructions support required */ 243 1.1.1.8 christos CpuIBT, 244 1.1.1.8 christos CpuSHSTK, 245 1.1.1.9 christos /* AMX-INT8 instructions required */ 246 1.1.1.9 christos CpuAMX_INT8, 247 1.1.1.9 christos /* AMX-BF16 instructions required */ 248 1.1.1.9 christos CpuAMX_BF16, 249 1.1.1.10 christos /* AMX-FP16 instructions required */ 250 1.1.1.10 christos CpuAMX_FP16, 251 1.1.1.11 christos /* AMX-COMPLEX instructions required. */ 252 1.1.1.11 christos CpuAMX_COMPLEX, 253 1.1.1.9 christos /* AMX-TILE instructions required */ 254 1.1.1.9 christos CpuAMX_TILE, 255 1.1.1.8 christos /* GFNI instructions required */ 256 1.1.1.8 christos CpuGFNI, 257 1.1.1.8 christos /* VAES instructions required */ 258 1.1.1.8 christos CpuVAES, 259 1.1.1.8 christos /* VPCLMULQDQ instructions required */ 260 1.1.1.8 christos CpuVPCLMULQDQ, 261 1.1.1.8 christos /* WBNOINVD instructions required */ 262 1.1.1.8 christos CpuWBNOINVD, 263 1.1.1.8 christos /* PCONFIG instructions required */ 264 1.1.1.8 christos CpuPCONFIG, 265 1.1.1.11 christos /* PBNDKB instructions required. */ 266 1.1.1.11 christos CpuPBNDKB, 267 1.1.1.8 christos /* WAITPKG instructions required */ 268 1.1.1.8 christos CpuWAITPKG, 269 1.1.1.10 christos /* UINTR instructions required */ 270 1.1.1.10 christos CpuUINTR, 271 1.1.1.8 christos /* CLDEMOTE instruction required */ 272 1.1.1.8 christos CpuCLDEMOTE, 273 1.1.1.8 christos /* MOVDIRI instruction support required */ 274 1.1.1.8 christos CpuMOVDIRI, 275 1.1.1.8 christos /* MOVDIRR64B instruction required */ 276 1.1.1.8 christos CpuMOVDIR64B, 277 1.1.1.9 christos /* ENQCMD instruction required */ 278 1.1.1.9 christos CpuENQCMD, 279 1.1.1.9 christos /* SERIALIZE instruction required */ 280 1.1.1.9 christos CpuSERIALIZE, 281 1.1.1.9 christos /* RDPRU instruction required */ 282 1.1.1.9 christos CpuRDPRU, 283 1.1.1.9 christos /* MCOMMIT instruction required */ 284 1.1.1.9 christos CpuMCOMMIT, 285 1.1.1.9 christos /* SEV-ES instruction(s) required */ 286 1.1.1.9 christos CpuSEV_ES, 287 1.1.1.9 christos /* TSXLDTRK instruction required */ 288 1.1.1.9 christos CpuTSXLDTRK, 289 1.1.1.10 christos /* KL instruction support required */ 290 1.1.1.10 christos CpuKL, 291 1.1.1.10 christos /* WideKL instruction support required */ 292 1.1.1.10 christos CpuWideKL, 293 1.1.1.10 christos /* HRESET instruction required */ 294 1.1.1.10 christos CpuHRESET, 295 1.1.1.10 christos /* INVLPGB instructions required */ 296 1.1.1.10 christos CpuINVLPGB, 297 1.1.1.10 christos /* TLBSYNC instructions required */ 298 1.1.1.10 christos CpuTLBSYNC, 299 1.1.1.10 christos /* SNP instructions required */ 300 1.1.1.10 christos CpuSNP, 301 1.1.1.10 christos /* RMPQUERY instruction required */ 302 1.1.1.10 christos CpuRMPQUERY, 303 1.1.1.10 christos 304 1.1.1.11 christos /* NOTE: These items, which can be combined with other ISA flags above, need 305 1.1.1.11 christos to remain second to last and in sync with CPU_FLAGS_COMMON. */ 306 1.1.1.10 christos 307 1.1.1.11 christos /* i287 support required */ 308 1.1.1.11 christos Cpu287, 309 1.1.1.11 christos CpuAttrEnums = Cpu287, 310 1.1.1.11 christos /* i387 support required */ 311 1.1.1.11 christos Cpu387, 312 1.1.1.11 christos /* 3dnow! support required */ 313 1.1.1.11 christos Cpu3dnow, 314 1.1.1.11 christos /* 3dnow! Extensions support required */ 315 1.1.1.11 christos Cpu3dnowA, 316 1.1 christos /* 64bit support required */ 317 1.1 christos Cpu64, 318 1.1.1.11 christos /* AVX support required */ 319 1.1.1.11 christos CpuAVX, 320 1.1.1.11 christos /* HLE support required */ 321 1.1.1.11 christos CpuHLE, 322 1.1.1.11 christos /* Intel AVX-512 Foundation Instructions support required */ 323 1.1.1.11 christos CpuAVX512F, 324 1.1.1.11 christos /* Intel AVX-512 VL Instructions support required. */ 325 1.1.1.11 christos CpuAVX512VL, 326 1.1.1.11 christos /* Intel APX_F Instructions support required. */ 327 1.1.1.11 christos CpuAPX_F, 328 1.1.1.12 christos /* Intel AVX10.2 Instructions support required. */ 329 1.1.1.12 christos CpuAVX10_2, 330 1.1 christos /* Not supported in the 64bit mode */ 331 1.1 christos CpuNo64, 332 1.1.1.11 christos 333 1.1.1.11 christos /* NOTE: This item needs to remain last. */ 334 1.1.1.11 christos 335 1.1 christos /* The last bitfield in i386_cpu_flags. */ 336 1.1 christos CpuMax = CpuNo64 337 1.1 christos }; 338 1.1 christos 339 1.1 christos #define CpuNumOfUints \ 340 1.1 christos (CpuMax / sizeof (unsigned int) / CHAR_BIT + 1) 341 1.1 christos #define CpuNumOfBits \ 342 1.1 christos (CpuNumOfUints * sizeof (unsigned int) * CHAR_BIT) 343 1.1 christos 344 1.1.1.11 christos #define CpuIsaBits 8 345 1.1.1.11 christos #define CpuAttrNumOfUints \ 346 1.1.1.11 christos ((CpuIsaBits + CpuMax - CpuAttrEnums) / sizeof (unsigned int) / CHAR_BIT + 1) 347 1.1.1.11 christos #define CpuAttrNumOfBits \ 348 1.1.1.11 christos (CpuAttrNumOfUints * sizeof (unsigned int) * CHAR_BIT) 349 1.1.1.11 christos 350 1.1.1.11 christos /* If you get a compiler error for zero width of an unused field, 351 1.1.1.11 christos comment the respective one out. */ 352 1.1 christos #define CpuUnused (CpuMax + 1) 353 1.1.1.11 christos #define CpuAttrUnused (CpuIsaBits + CpuMax + 1 - CpuAttrEnums) 354 1.1.1.11 christos 355 1.1.1.11 christos #define CPU_FLAGS_COMMON \ 356 1.1.1.11 christos unsigned int cpu287:1, \ 357 1.1.1.11 christos cpu387:1, \ 358 1.1.1.11 christos cpu3dnow:1, \ 359 1.1.1.11 christos cpu3dnowa:1, \ 360 1.1.1.11 christos cpu64:1, \ 361 1.1.1.11 christos cpuavx:1, \ 362 1.1.1.11 christos cpuhle:1, \ 363 1.1.1.11 christos cpuavx512f:1, \ 364 1.1.1.11 christos cpuavx512vl:1, \ 365 1.1.1.11 christos cpuapx_f:1, \ 366 1.1.1.12 christos cpuavx10_2:1, \ 367 1.1.1.11 christos /* NOTE: This field needs to remain last. */ \ 368 1.1.1.11 christos cpuno64:1 369 1.1.1.11 christos 370 1.1.1.11 christos typedef union i386_cpu_attr 371 1.1.1.11 christos { 372 1.1.1.11 christos struct 373 1.1.1.11 christos { 374 1.1.1.11 christos unsigned int isa:CpuIsaBits; 375 1.1.1.11 christos CPU_FLAGS_COMMON; 376 1.1.1.11 christos #ifdef CpuAttrUnused 377 1.1.1.11 christos unsigned int unused:(CpuAttrNumOfBits - CpuAttrUnused); 378 1.1.1.11 christos #endif 379 1.1.1.11 christos } bitfield; 380 1.1.1.11 christos unsigned int array[CpuAttrNumOfUints]; 381 1.1.1.11 christos } i386_cpu_attr; 382 1.1 christos 383 1.1 christos /* We can check if an instruction is available with array instead 384 1.1 christos of bitfield. */ 385 1.1 christos typedef union i386_cpu_flags 386 1.1 christos { 387 1.1 christos struct 388 1.1 christos { 389 1.1 christos unsigned int cpui186:1; 390 1.1 christos unsigned int cpui286:1; 391 1.1 christos unsigned int cpui386:1; 392 1.1 christos unsigned int cpui486:1; 393 1.1 christos unsigned int cpui586:1; 394 1.1 christos unsigned int cpui686:1; 395 1.1.1.8 christos unsigned int cpucmov:1; 396 1.1.1.8 christos unsigned int cpufxsr:1; 397 1.1 christos unsigned int cpuclflush:1; 398 1.1 christos unsigned int cpunop:1; 399 1.1 christos unsigned int cpusyscall:1; 400 1.1 christos unsigned int cpu8087:1; 401 1.1 christos unsigned int cpu687:1; 402 1.1 christos unsigned int cpufisttp:1; 403 1.1 christos unsigned int cpummx:1; 404 1.1 christos unsigned int cpusse:1; 405 1.1 christos unsigned int cpusse2:1; 406 1.1 christos unsigned int cpusse3:1; 407 1.1 christos unsigned int cpupadlock:1; 408 1.1.1.12 christos unsigned int cpugmi:1; 409 1.1 christos unsigned int cpusvme:1; 410 1.1 christos unsigned int cpuvmx:1; 411 1.1 christos unsigned int cpusmx:1; 412 1.1 christos unsigned int cpussse3:1; 413 1.1 christos unsigned int cpusse4a:1; 414 1.1.1.9 christos unsigned int cpulzcnt:1; 415 1.1.1.9 christos unsigned int cpupopcnt:1; 416 1.1.1.11 christos unsigned int cpumonitor:1; 417 1.1 christos unsigned int cpusse4_1:1; 418 1.1 christos unsigned int cpusse4_2:1; 419 1.1.1.2 christos unsigned int cpuavx2:1; 420 1.1.1.3 christos unsigned int cpuavx512cd:1; 421 1.1.1.3 christos unsigned int cpuavx512er:1; 422 1.1.1.3 christos unsigned int cpuavx512pf:1; 423 1.1.1.4 christos unsigned int cpuavx512dq:1; 424 1.1.1.4 christos unsigned int cpuavx512bw:1; 425 1.1.1.5 christos unsigned int cpuiamcu:1; 426 1.1 christos unsigned int cpuxsave:1; 427 1.1 christos unsigned int cpuxsaveopt:1; 428 1.1 christos unsigned int cpuaes:1; 429 1.1.1.11 christos unsigned int cpupclmulqdq:1; 430 1.1 christos unsigned int cpufma:1; 431 1.1 christos unsigned int cpufma4:1; 432 1.1 christos unsigned int cpuxop:1; 433 1.1 christos unsigned int cpulwp:1; 434 1.1 christos unsigned int cpubmi:1; 435 1.1 christos unsigned int cputbm:1; 436 1.1 christos unsigned int cpumovbe:1; 437 1.1.1.2 christos unsigned int cpucx16:1; 438 1.1.1.11 christos unsigned int cpulahf_sahf:1; 439 1.1 christos unsigned int cpuept:1; 440 1.1 christos unsigned int cpurdtscp:1; 441 1.1 christos unsigned int cpufsgsbase:1; 442 1.1 christos unsigned int cpurdrnd:1; 443 1.1 christos unsigned int cpuf16c:1; 444 1.1.1.2 christos unsigned int cpubmi2:1; 445 1.1.1.2 christos unsigned int cpurtm:1; 446 1.1.1.2 christos unsigned int cpuinvpcid:1; 447 1.1.1.2 christos unsigned int cpuvmfunc:1; 448 1.1.1.3 christos unsigned int cpumpx:1; 449 1.1.1.2 christos unsigned int cpurdseed:1; 450 1.1.1.2 christos unsigned int cpuadx:1; 451 1.1.1.2 christos unsigned int cpuprfchw:1; 452 1.1.1.2 christos unsigned int cpusmap:1; 453 1.1.1.3 christos unsigned int cpusha:1; 454 1.1.1.11 christos unsigned int cpusha512:1; 455 1.1.1.11 christos unsigned int cpusm3:1; 456 1.1.1.11 christos unsigned int cpusm4:1; 457 1.1.1.4 christos unsigned int cpuclflushopt:1; 458 1.1.1.4 christos unsigned int cpuxsaves:1; 459 1.1.1.4 christos unsigned int cpuxsavec:1; 460 1.1.1.4 christos unsigned int cpuprefetchwt1:1; 461 1.1.1.4 christos unsigned int cpuse1:1; 462 1.1.1.4 christos unsigned int cpuclwb:1; 463 1.1.1.4 christos unsigned int cpuavx512ifma:1; 464 1.1.1.4 christos unsigned int cpuavx512vbmi:1; 465 1.1.1.7 christos unsigned int cpuavx512_4fmaps:1; 466 1.1.1.7 christos unsigned int cpuavx512_4vnniw:1; 467 1.1.1.7 christos unsigned int cpuavx512_vpopcntdq:1; 468 1.1.1.8 christos unsigned int cpuavx512_vbmi2:1; 469 1.1.1.8 christos unsigned int cpuavx512_vnni:1; 470 1.1.1.8 christos unsigned int cpuavx512_bitalg:1; 471 1.1.1.9 christos unsigned int cpuavx512_bf16:1; 472 1.1.1.9 christos unsigned int cpuavx512_vp2intersect:1; 473 1.1.1.10 christos unsigned int cputdx:1; 474 1.1.1.10 christos unsigned int cpuavx_vnni:1; 475 1.1.1.10 christos unsigned int cpuavx512_fp16:1; 476 1.1.1.10 christos unsigned int cpuprefetchi:1; 477 1.1.1.10 christos unsigned int cpuavx_ifma:1; 478 1.1.1.10 christos unsigned int cpuavx_vnni_int8:1; 479 1.1.1.11 christos unsigned int cpuavx_vnni_int16:1; 480 1.1.1.10 christos unsigned int cpucmpccxadd:1; 481 1.1.1.10 christos unsigned int cpuwrmsrns:1; 482 1.1.1.10 christos unsigned int cpumsrlist:1; 483 1.1.1.10 christos unsigned int cpuavx_ne_convert:1; 484 1.1.1.10 christos unsigned int cpurao_int:1; 485 1.1.1.11 christos unsigned int cpufred:1; 486 1.1.1.11 christos unsigned int cpulkgs:1; 487 1.1.1.11 christos unsigned int cpuuser_msr:1; 488 1.1.1.12 christos unsigned int cpumsr_imm:1; 489 1.1.1.5 christos unsigned int cpumwaitx:1; 490 1.1.1.5 christos unsigned int cpuclzero:1; 491 1.1.1.6 christos unsigned int cpuospke:1; 492 1.1.1.6 christos unsigned int cpurdpid:1; 493 1.1.1.7 christos unsigned int cpuptwrite:1; 494 1.1.1.8 christos unsigned int cpuibt:1; 495 1.1.1.8 christos unsigned int cpushstk:1; 496 1.1.1.9 christos unsigned int cpuamx_int8:1; 497 1.1.1.9 christos unsigned int cpuamx_bf16:1; 498 1.1.1.10 christos unsigned int cpuamx_fp16:1; 499 1.1.1.11 christos unsigned int cpuamx_complex:1; 500 1.1.1.9 christos unsigned int cpuamx_tile:1; 501 1.1.1.8 christos unsigned int cpugfni:1; 502 1.1.1.8 christos unsigned int cpuvaes:1; 503 1.1.1.8 christos unsigned int cpuvpclmulqdq:1; 504 1.1.1.8 christos unsigned int cpuwbnoinvd:1; 505 1.1.1.8 christos unsigned int cpupconfig:1; 506 1.1.1.11 christos unsigned int cpupbndkb:1; 507 1.1.1.8 christos unsigned int cpuwaitpkg:1; 508 1.1.1.10 christos unsigned int cpuuintr:1; 509 1.1.1.8 christos unsigned int cpucldemote:1; 510 1.1.1.8 christos unsigned int cpumovdiri:1; 511 1.1.1.8 christos unsigned int cpumovdir64b:1; 512 1.1.1.9 christos unsigned int cpuenqcmd:1; 513 1.1.1.9 christos unsigned int cpuserialize:1; 514 1.1.1.9 christos unsigned int cpurdpru:1; 515 1.1.1.9 christos unsigned int cpumcommit:1; 516 1.1.1.9 christos unsigned int cpusev_es:1; 517 1.1.1.9 christos unsigned int cputsxldtrk:1; 518 1.1.1.10 christos unsigned int cpukl:1; 519 1.1.1.10 christos unsigned int cpuwidekl:1; 520 1.1.1.10 christos unsigned int cpuhreset:1; 521 1.1.1.10 christos unsigned int cpuinvlpgb:1; 522 1.1.1.10 christos unsigned int cputlbsync:1; 523 1.1.1.10 christos unsigned int cpusnp:1; 524 1.1.1.10 christos unsigned int cpurmpquery:1; 525 1.1.1.11 christos CPU_FLAGS_COMMON; 526 1.1 christos #ifdef CpuUnused 527 1.1 christos unsigned int unused:(CpuNumOfBits - CpuUnused); 528 1.1 christos #endif 529 1.1 christos } bitfield; 530 1.1 christos unsigned int array[CpuNumOfUints]; 531 1.1 christos } i386_cpu_flags; 532 1.1 christos 533 1.1 christos /* Position of opcode_modifier bits. */ 534 1.1 christos 535 1.1 christos enum 536 1.1 christos { 537 1.1 christos /* has direction bit. */ 538 1.1 christos D = 0, 539 1.1.1.9 christos /* set if operands can be both bytes and words/dwords/qwords, encoded the 540 1.1.1.9 christos canonical way; the base_opcode field should hold the encoding for byte 541 1.1.1.9 christos operands */ 542 1.1 christos W, 543 1.1.1.7 christos /* load form instruction. Must be placed before store form. */ 544 1.1.1.7 christos Load, 545 1.1 christos /* insn has a modrm byte. */ 546 1.1 christos Modrm, 547 1.1.1.9 christos /* special case for jump insns; value has to be 1 */ 548 1.1.1.9 christos #define JUMP 1 549 1.1 christos /* call and jump */ 550 1.1.1.9 christos #define JUMP_DWORD 2 551 1.1 christos /* loop and jecxz */ 552 1.1.1.9 christos #define JUMP_BYTE 3 553 1.1 christos /* special case for intersegment leaps/calls */ 554 1.1.1.9 christos #define JUMP_INTERSEGMENT 4 555 1.1.1.9 christos /* absolute address for jump */ 556 1.1.1.9 christos #define JUMP_ABSOLUTE 5 557 1.1.1.9 christos Jump, 558 1.1 christos /* FP insn memory format bit, sized by 0x4 */ 559 1.1 christos FloatMF, 560 1.1 christos /* needs size prefix if in 32-bit mode */ 561 1.1.1.8 christos #define SIZE16 1 562 1.1 christos /* needs size prefix if in 16-bit mode */ 563 1.1.1.8 christos #define SIZE32 2 564 1.1 christos /* needs size prefix if in 64-bit mode */ 565 1.1.1.8 christos #define SIZE64 3 566 1.1.1.8 christos Size, 567 1.1.1.11 christos /* Check that operand sizes match. */ 568 1.1.1.11 christos CheckOperandSize, 569 1.1.1.10 christos /* any memory size */ 570 1.1.1.10 christos #define ANY_SIZE 1 571 1.1.1.10 christos /* fake an extra reg operand for clr, imul and special register 572 1.1.1.10 christos processing for some instructions. */ 573 1.1.1.10 christos #define REG_KLUDGE 2 574 1.1.1.10 christos /* deprecated fp insn, gets a warning */ 575 1.1.1.10 christos #define UGH 3 576 1.1.1.10 christos /* An implicit xmm0 as the first operand */ 577 1.1.1.10 christos #define IMPLICIT_1ST_XMM0 4 578 1.1.1.12 christos /* One of the operands denotes a sequence of registers, with insn-dependent 579 1.1.1.12 christos constraint on the first register number. It implicitly denotes e.g. the 580 1.1.1.12 christos register group of {x,y,z}mmN - {x,y,z}mm(N + 3), in which case N ought to 581 1.1.1.12 christos be a multiple of 4. 582 1.1.1.10 christos */ 583 1.1.1.12 christos #define IMPLICIT_GROUP 5 584 1.1.1.10 christos /* Default mask isn't allowed. */ 585 1.1.1.11 christos #define NO_DEFAULT_MASK 6 586 1.1.1.10 christos /* Address prefix changes register operand */ 587 1.1.1.11 christos #define ADDR_PREFIX_OP_REG 7 588 1.1.1.10 christos /* Instrucion requires that destination must be distinct from source 589 1.1.1.10 christos registers. */ 590 1.1.1.11 christos #define DISTINCT_DEST 8 591 1.1.1.11 christos /* Instruction updates stack pointer implicitly. */ 592 1.1.1.11 christos #define IMPLICIT_STACK_OP 9 593 1.1.1.12 christos /* Instruction zeroes upper part of register. */ 594 1.1.1.12 christos #define ZERO_UPPER 10 595 1.1.1.12 christos /* Instruction support SCC. */ 596 1.1.1.12 christos #define SCC 11 597 1.1.1.12 christos /* Instruction requires EVEX.NF to be 1. */ 598 1.1.1.12 christos #define EVEX_NF 12 599 1.1.1.10 christos OperandConstraint, 600 1.1 christos /* instruction ignores operand size prefix and in Intel mode ignores 601 1.1 christos mnemonic size suffix check. */ 602 1.1.1.9 christos #define IGNORESIZE 1 603 1.1 christos /* default insn size depends on mode */ 604 1.1.1.9 christos #define DEFAULTSIZE 2 605 1.1.1.9 christos MnemonicSize, 606 1.1 christos /* b suffix on instruction illegal */ 607 1.1 christos No_bSuf, 608 1.1 christos /* w suffix on instruction illegal */ 609 1.1 christos No_wSuf, 610 1.1 christos /* l suffix on instruction illegal */ 611 1.1 christos No_lSuf, 612 1.1 christos /* s suffix on instruction illegal */ 613 1.1 christos No_sSuf, 614 1.1 christos /* q suffix on instruction illegal */ 615 1.1 christos No_qSuf, 616 1.1 christos /* instruction needs FWAIT */ 617 1.1 christos FWait, 618 1.1.1.9 christos /* IsString provides for a quick test for string instructions, and 619 1.1.1.9 christos its actual value also indicates which of the operands (if any) 620 1.1.1.9 christos requires use of the %es segment. */ 621 1.1.1.9 christos #define IS_STRING_ES_OP0 2 622 1.1.1.9 christos #define IS_STRING_ES_OP1 3 623 1.1 christos IsString, 624 1.1.1.9 christos /* RegMem is for instructions with a modrm byte where the register 625 1.1.1.9 christos destination operand should be encoded in the mod and regmem fields. 626 1.1.1.9 christos Normally, it will be encoded in the reg field. We add a RegMem 627 1.1.1.9 christos flag to indicate that it should be encoded in the regmem field. */ 628 1.1.1.9 christos RegMem, 629 1.1.1.3 christos /* quick test if branch instruction is MPX supported */ 630 1.1.1.3 christos BNDPrefixOk, 631 1.1.1.10 christos #define PrefixNone 0 632 1.1.1.10 christos #define PrefixRep 1 633 1.1.1.10 christos #define PrefixHLERelease 2 /* Okay with an XRELEASE (0xf3) prefix. */ 634 1.1.1.10 christos #define PrefixNoTrack 3 635 1.1.1.10 christos /* Prefixes implying "LOCK okay" must come after Lock. All others have 636 1.1.1.10 christos to come before. */ 637 1.1.1.10 christos #define PrefixLock 4 638 1.1.1.10 christos #define PrefixHLELock 5 /* Okay with a LOCK prefix. */ 639 1.1.1.10 christos #define PrefixHLEAny 6 /* Okay with or without a LOCK prefix. */ 640 1.1.1.10 christos PrefixOk, 641 1.1 christos /* opcode is a prefix */ 642 1.1 christos IsPrefix, 643 1.1 christos /* instruction has extension in 8 bit imm */ 644 1.1 christos ImmExt, 645 1.1 christos /* instruction don't need Rex64 prefix. */ 646 1.1 christos NoRex64, 647 1.1 christos /* insn has VEX prefix: 648 1.1.1.8 christos 1: 128bit VEX prefix (or operand dependent). 649 1.1 christos 2: 256bit VEX prefix. 650 1.1 christos 3: Scalar VEX prefix. 651 1.1 christos */ 652 1.1 christos #define VEX128 1 653 1.1 christos #define VEX256 2 654 1.1 christos #define VEXScalar 3 655 1.1 christos Vex, 656 1.1 christos /* How to encode VEX.vvvv: 657 1.1.1.11 christos 1: VEX.vvvv encodes the src1 register operand. 658 1.1.1.11 christos 2: VEX.vvvv encodes the src2 register operand. 659 1.1.1.11 christos 3: VEX.vvvv encodes the dest register operand. 660 1.1 christos */ 661 1.1.1.11 christos #define VexVVVV_SRC1 1 662 1.1.1.11 christos #define VexVVVV_SRC2 2 663 1.1.1.11 christos #define VexVVVV_DST 3 664 1.1.1.11 christos 665 1.1 christos VexVVVV, 666 1.1 christos /* How the VEX.W bit is used: 667 1.1 christos 0: Set by the REX.W bit. 668 1.1 christos 1: VEX.W0. Should always be 0. 669 1.1 christos 2: VEX.W1. Should always be 1. 670 1.1.1.8 christos 3: VEX.WIG. The VEX.W bit is ignored. 671 1.1 christos */ 672 1.1 christos #define VEXW0 1 673 1.1 christos #define VEXW1 2 674 1.1.1.8 christos #define VEXWIG 3 675 1.1 christos VexW, 676 1.1.1.10 christos /* Opcode prefix (values chosen to be usable directly in 677 1.1.1.10 christos VEX/XOP/EVEX pp fields): 678 1.1.1.10 christos 0: None 679 1.1.1.10 christos 1: Add 0x66 opcode prefix. 680 1.1.1.10 christos 2: Add 0xf3 opcode prefix. 681 1.1.1.10 christos 3: Add 0xf2 opcode prefix. 682 1.1.1.10 christos */ 683 1.1.1.10 christos #define PREFIX_NONE 0 684 1.1.1.10 christos #define PREFIX_0X66 1 685 1.1.1.10 christos #define PREFIX_0XF3 2 686 1.1.1.10 christos #define PREFIX_0XF2 3 687 1.1.1.10 christos OpcodePrefix, 688 1.1.1.9 christos /* Instruction with a mandatory SIB byte: 689 1.1.1.2 christos 1: 128bit vector register. 690 1.1.1.2 christos 2: 256bit vector register. 691 1.1.1.3 christos 3: 512bit vector register. 692 1.1.1.2 christos */ 693 1.1.1.9 christos #define VECSIB128 1 694 1.1.1.9 christos #define VECSIB256 2 695 1.1.1.9 christos #define VECSIB512 3 696 1.1.1.9 christos #define SIBMEM 4 697 1.1.1.9 christos SIB, 698 1.1.1.9 christos 699 1.1 christos /* SSE to AVX support required */ 700 1.1 christos SSE2AVX, 701 1.1.1.3 christos 702 1.1.1.3 christos /* insn has EVEX prefix: 703 1.1.1.3 christos 1: 512bit EVEX prefix. 704 1.1.1.3 christos 2: 128bit EVEX prefix. 705 1.1.1.3 christos 3: 256bit EVEX prefix. 706 1.1.1.3 christos 4: Length-ignored (LIG) EVEX prefix. 707 1.1.1.8 christos 5: Length determined from actual operands. 708 1.1.1.11 christos 6: L'L = 3 (reserved, .insn only) 709 1.1.1.3 christos */ 710 1.1.1.3 christos #define EVEX512 1 711 1.1.1.3 christos #define EVEX128 2 712 1.1.1.3 christos #define EVEX256 3 713 1.1.1.3 christos #define EVEXLIG 4 714 1.1.1.8 christos #define EVEXDYN 5 715 1.1.1.11 christos #define EVEX_L3 6 716 1.1.1.3 christos EVex, 717 1.1.1.3 christos 718 1.1.1.11 christos /* AVX512 masking support */ 719 1.1.1.3 christos Masking, 720 1.1.1.3 christos 721 1.1.1.8 christos /* AVX512 broadcast support. The number of bytes to broadcast is 722 1.1.1.8 christos 1 << (Broadcast - 1): 723 1.1.1.8 christos 1: Byte broadcast. 724 1.1.1.8 christos 2: Word broadcast. 725 1.1.1.8 christos 3: Dword broadcast. 726 1.1.1.8 christos 4: Qword broadcast. 727 1.1.1.8 christos */ 728 1.1.1.8 christos #define BYTE_BROADCAST 1 729 1.1.1.8 christos #define WORD_BROADCAST 2 730 1.1.1.8 christos #define DWORD_BROADCAST 3 731 1.1.1.8 christos #define QWORD_BROADCAST 4 732 1.1.1.3 christos Broadcast, 733 1.1.1.3 christos 734 1.1.1.3 christos /* Static rounding control is supported. */ 735 1.1.1.3 christos StaticRounding, 736 1.1.1.3 christos 737 1.1.1.3 christos /* Supress All Exceptions is supported. */ 738 1.1.1.3 christos SAE, 739 1.1.1.3 christos 740 1.1.1.8 christos /* Compressed Disp8*N attribute. */ 741 1.1.1.8 christos #define DISP8_SHIFT_VL 7 742 1.1.1.3 christos Disp8MemShift, 743 1.1.1.3 christos 744 1.1.1.8 christos /* Support encoding optimization. */ 745 1.1.1.8 christos Optimize, 746 1.1.1.8 christos 747 1.1.1.11 christos /* Language dialect. NOTE: Order matters! */ 748 1.1.1.11 christos #define INTEL_SYNTAX 1 749 1.1.1.11 christos #define ATT_SYNTAX 2 750 1.1.1.11 christos #define ATT_MNEMONIC 3 751 1.1.1.11 christos Dialect, 752 1.1.1.11 christos 753 1.1.1.12 christos /* Mnemonic suffix permitted in Intel syntax. */ 754 1.1.1.12 christos IntelSuffix, 755 1.1.1.12 christos 756 1.1.1.9 christos /* ISA64: Don't change the order without other code adjustments. 757 1.1.1.9 christos 0: Common to AMD64 and Intel64. 758 1.1.1.9 christos 1: AMD64. 759 1.1.1.9 christos 2: Intel64. 760 1.1.1.9 christos 3: Only in Intel64. 761 1.1.1.9 christos */ 762 1.1.1.9 christos #define AMD64 1 763 1.1.1.9 christos #define INTEL64 2 764 1.1.1.9 christos #define INTEL64ONLY 3 765 1.1.1.9 christos ISA64, 766 1.1.1.11 christos 767 1.1.1.11 christos /* egprs (r16-r31) on instruction illegal. We also use it to judge 768 1.1.1.11 christos whether the instruction supports pseudo-prefix {rex2}. */ 769 1.1.1.11 christos NoEgpr, 770 1.1.1.11 christos 771 1.1.1.11 christos /* No CSPAZO flags update indication. */ 772 1.1.1.11 christos NF, 773 1.1.1.11 christos 774 1.1.1.11 christos /* Instrucion requires REX2 prefix. */ 775 1.1.1.11 christos Rex2, 776 1.1.1.11 christos 777 1.1 christos /* The last bitfield in i386_opcode_modifier. */ 778 1.1.1.9 christos Opcode_Modifier_Num 779 1.1 christos }; 780 1.1 christos 781 1.1 christos typedef struct i386_opcode_modifier 782 1.1 christos { 783 1.1 christos unsigned int d:1; 784 1.1 christos unsigned int w:1; 785 1.1.1.7 christos unsigned int load:1; 786 1.1 christos unsigned int modrm:1; 787 1.1.1.9 christos unsigned int jump:3; 788 1.1 christos unsigned int floatmf:1; 789 1.1.1.8 christos unsigned int size:2; 790 1.1.1.11 christos unsigned int checkoperandsize:1; 791 1.1.1.10 christos unsigned int operandconstraint:4; 792 1.1.1.9 christos unsigned int mnemonicsize:2; 793 1.1 christos unsigned int no_bsuf:1; 794 1.1 christos unsigned int no_wsuf:1; 795 1.1 christos unsigned int no_lsuf:1; 796 1.1 christos unsigned int no_ssuf:1; 797 1.1 christos unsigned int no_qsuf:1; 798 1.1 christos unsigned int fwait:1; 799 1.1.1.9 christos unsigned int isstring:2; 800 1.1.1.9 christos unsigned int regmem:1; 801 1.1.1.3 christos unsigned int bndprefixok:1; 802 1.1.1.10 christos unsigned int prefixok:3; 803 1.1 christos unsigned int isprefix:1; 804 1.1 christos unsigned int immext:1; 805 1.1 christos unsigned int norex64:1; 806 1.1 christos unsigned int vex:2; 807 1.1 christos unsigned int vexvvvv:2; 808 1.1 christos unsigned int vexw:2; 809 1.1.1.10 christos unsigned int opcodeprefix:2; 810 1.1.1.9 christos unsigned int sib:3; 811 1.1 christos unsigned int sse2avx:1; 812 1.1.1.3 christos unsigned int evex:3; 813 1.1.1.11 christos unsigned int masking:1; 814 1.1.1.3 christos unsigned int broadcast:3; 815 1.1.1.3 christos unsigned int staticrounding:1; 816 1.1.1.3 christos unsigned int sae:1; 817 1.1.1.3 christos unsigned int disp8memshift:3; 818 1.1.1.8 christos unsigned int optimize:1; 819 1.1.1.11 christos unsigned int dialect:2; 820 1.1.1.12 christos unsigned int intelsuffix:1; 821 1.1.1.9 christos unsigned int isa64:2; 822 1.1.1.11 christos unsigned int noegpr:1; 823 1.1.1.11 christos unsigned int nf:1; 824 1.1.1.11 christos unsigned int rex2:1; 825 1.1 christos } i386_opcode_modifier; 826 1.1 christos 827 1.1.1.9 christos /* Operand classes. */ 828 1.1.1.9 christos 829 1.1.1.9 christos #define CLASS_WIDTH 4 830 1.1.1.9 christos enum operand_class 831 1.1.1.9 christos { 832 1.1.1.9 christos ClassNone, 833 1.1.1.9 christos Reg, /* GPRs and FP regs, distinguished by operand size */ 834 1.1.1.9 christos SReg, /* Segment register */ 835 1.1.1.9 christos RegCR, /* Control register */ 836 1.1.1.9 christos RegDR, /* Debug register */ 837 1.1.1.9 christos RegTR, /* Test register */ 838 1.1.1.9 christos RegMMX, /* MMX register */ 839 1.1.1.9 christos RegSIMD, /* XMM/YMM/ZMM registers, distinguished by operand size */ 840 1.1.1.9 christos RegMask, /* Vector Mask register */ 841 1.1.1.9 christos RegBND, /* Bound register */ 842 1.1.1.9 christos }; 843 1.1.1.9 christos 844 1.1.1.9 christos /* Special operand instances. */ 845 1.1.1.9 christos 846 1.1.1.9 christos #define INSTANCE_WIDTH 3 847 1.1.1.9 christos enum operand_instance 848 1.1.1.9 christos { 849 1.1.1.9 christos InstanceNone, 850 1.1.1.9 christos Accum, /* Accumulator %al/%ax/%eax/%rax/%st(0)/%xmm0 */ 851 1.1.1.9 christos RegC, /* %cl / %cx / %ecx / %rcx, e.g. register to hold shift count */ 852 1.1.1.9 christos RegD, /* %dl / %dx / %edx / %rdx, e.g. register to hold I/O port addr */ 853 1.1.1.9 christos RegB, /* %bl / %bx / %ebx / %rbx */ 854 1.1.1.9 christos }; 855 1.1.1.9 christos 856 1.1 christos /* Position of operand_type bits. */ 857 1.1 christos 858 1.1 christos enum 859 1.1 christos { 860 1.1.1.9 christos /* Class and Instance */ 861 1.1.1.9 christos ClassInstance = CLASS_WIDTH + INSTANCE_WIDTH - 1, 862 1.1 christos /* 1 bit immediate */ 863 1.1 christos Imm1, 864 1.1 christos /* 8 bit immediate */ 865 1.1 christos Imm8, 866 1.1 christos /* 8 bit immediate sign extended */ 867 1.1 christos Imm8S, 868 1.1 christos /* 16 bit immediate */ 869 1.1 christos Imm16, 870 1.1 christos /* 32 bit immediate */ 871 1.1 christos Imm32, 872 1.1 christos /* 32 bit immediate sign extended */ 873 1.1 christos Imm32S, 874 1.1 christos /* 64 bit immediate */ 875 1.1 christos Imm64, 876 1.1 christos /* 8bit/16bit/32bit displacements are used in different ways, 877 1.1 christos depending on the instruction. For jumps, they specify the 878 1.1 christos size of the PC relative displacement, for instructions with 879 1.1 christos memory operand, they specify the size of the offset relative 880 1.1 christos to the base register, and for instructions with memory offset 881 1.1 christos such as `mov 1234,%al' they specify the size of the offset 882 1.1 christos relative to the segment base. */ 883 1.1 christos /* 8 bit displacement */ 884 1.1 christos Disp8, 885 1.1 christos /* 16 bit displacement */ 886 1.1 christos Disp16, 887 1.1.1.10 christos /* 32 bit displacement (64-bit: sign-extended) */ 888 1.1 christos Disp32, 889 1.1 christos /* 64 bit displacement */ 890 1.1 christos Disp64, 891 1.1 christos /* Register which can be used for base or index in memory operand. */ 892 1.1 christos BaseIndex, 893 1.1.1.8 christos /* BYTE size. */ 894 1.1 christos Byte, 895 1.1.1.8 christos /* WORD size. 2 byte */ 896 1.1 christos Word, 897 1.1.1.8 christos /* DWORD size. 4 byte */ 898 1.1 christos Dword, 899 1.1.1.8 christos /* FWORD size. 6 byte */ 900 1.1 christos Fword, 901 1.1.1.8 christos /* QWORD size. 8 byte */ 902 1.1 christos Qword, 903 1.1.1.8 christos /* TBYTE size. 10 byte */ 904 1.1 christos Tbyte, 905 1.1.1.8 christos /* XMMWORD size. */ 906 1.1 christos Xmmword, 907 1.1.1.8 christos /* YMMWORD size. */ 908 1.1 christos Ymmword, 909 1.1.1.8 christos /* ZMMWORD size. */ 910 1.1.1.3 christos Zmmword, 911 1.1.1.9 christos /* TMMWORD size. */ 912 1.1.1.9 christos Tmmword, 913 1.1 christos /* Unspecified memory size. */ 914 1.1 christos Unspecified, 915 1.1 christos 916 1.1.1.9 christos /* The number of bits in i386_operand_type. */ 917 1.1.1.8 christos OTNum 918 1.1 christos }; 919 1.1 christos 920 1.1 christos #define OTNumOfUints \ 921 1.1.1.8 christos ((OTNum - 1) / sizeof (unsigned int) / CHAR_BIT + 1) 922 1.1 christos #define OTNumOfBits \ 923 1.1 christos (OTNumOfUints * sizeof (unsigned int) * CHAR_BIT) 924 1.1 christos 925 1.1 christos /* If you get a compiler error for zero width of the unused field, 926 1.1 christos comment it out. */ 927 1.1.1.8 christos #define OTUnused OTNum 928 1.1 christos 929 1.1 christos typedef union i386_operand_type 930 1.1 christos { 931 1.1 christos struct 932 1.1 christos { 933 1.1.1.9 christos unsigned int class:CLASS_WIDTH; 934 1.1.1.9 christos unsigned int instance:INSTANCE_WIDTH; 935 1.1 christos unsigned int imm1:1; 936 1.1 christos unsigned int imm8:1; 937 1.1 christos unsigned int imm8s:1; 938 1.1 christos unsigned int imm16:1; 939 1.1 christos unsigned int imm32:1; 940 1.1 christos unsigned int imm32s:1; 941 1.1 christos unsigned int imm64:1; 942 1.1 christos unsigned int disp8:1; 943 1.1 christos unsigned int disp16:1; 944 1.1 christos unsigned int disp32:1; 945 1.1 christos unsigned int disp64:1; 946 1.1 christos unsigned int baseindex:1; 947 1.1 christos unsigned int byte:1; 948 1.1 christos unsigned int word:1; 949 1.1 christos unsigned int dword:1; 950 1.1 christos unsigned int fword:1; 951 1.1 christos unsigned int qword:1; 952 1.1 christos unsigned int tbyte:1; 953 1.1 christos unsigned int xmmword:1; 954 1.1 christos unsigned int ymmword:1; 955 1.1.1.3 christos unsigned int zmmword:1; 956 1.1.1.9 christos unsigned int tmmword:1; 957 1.1 christos unsigned int unspecified:1; 958 1.1 christos #ifdef OTUnused 959 1.1 christos unsigned int unused:(OTNumOfBits - OTUnused); 960 1.1 christos #endif 961 1.1 christos } bitfield; 962 1.1 christos unsigned int array[OTNumOfUints]; 963 1.1 christos } i386_operand_type; 964 1.1 christos 965 1.1 christos typedef struct insn_template 966 1.1 christos { 967 1.1 christos /* instruction name sans width suffix ("mov" for movl insns) */ 968 1.1.1.11 christos unsigned int mnem_off; 969 1.1.1.10 christos 970 1.1.1.10 christos /* Bitfield arrangement is such that individual fields can be easily 971 1.1.1.10 christos extracted (in native builds at least) - either by at most a masking 972 1.1.1.10 christos operation (base_opcode, operands), or by just a (signed) right shift 973 1.1.1.10 christos (extension_opcode). Please try to maintain this property. */ 974 1.1 christos 975 1.1 christos /* base_opcode is the fundamental opcode byte without optional 976 1.1 christos prefix(es). */ 977 1.1.1.10 christos unsigned int base_opcode:16; 978 1.1 christos #define Opcode_D 0x2 /* Direction bit: 979 1.1 christos set if Reg --> Regmem; 980 1.1 christos unset if Regmem --> Reg. */ 981 1.1.1.11 christos #define Opcode_FloatR 0x8 /* ModR/M bit to swap src/dest for float insns. */ 982 1.1.1.11 christos #define Opcode_FloatD 0x4 /* Direction bit for float insns. */ 983 1.1.1.10 christos #define Opcode_ExtD 0x1 /* Direction bit for extended opcode space insns. */ 984 1.1.1.8 christos #define Opcode_SIMD_IntD 0x10 /* Direction bit for SIMD int insns. */ 985 1.1.1.10 christos /* The next value is arbitrary, as long as it's non-zero and distinct 986 1.1.1.10 christos from all other values above. */ 987 1.1.1.10 christos #define Opcode_VexW 0xf /* Operand order controlled by VEX.W. */ 988 1.1.1.10 christos 989 1.1.1.10 christos /* how many operands */ 990 1.1.1.10 christos unsigned int operands:3; 991 1.1.1.10 christos 992 1.1.1.11 christos /* opcode space */ 993 1.1.1.11 christos unsigned int opcode_space:4; 994 1.1.1.11 christos /* Opcode encoding space (values chosen to be usable directly in 995 1.1.1.12 christos VEX/XOP mmmmm and EVEX mmm fields): 996 1.1.1.11 christos 0: Base opcode space. 997 1.1.1.11 christos 1: 0F opcode prefix / space. 998 1.1.1.11 christos 2: 0F38 opcode prefix / space. 999 1.1.1.11 christos 3: 0F3A opcode prefix / space. 1000 1.1.1.12 christos 4: MAP4 opcode prefix / space. 1001 1.1.1.12 christos 5: MAP5 opcode prefix / space. 1002 1.1.1.12 christos 6: MAP6 opcode prefix / space. 1003 1.1.1.12 christos 7: MAP7 opcode prefix / space. 1004 1.1.1.11 christos 8: XOP 08 opcode space. 1005 1.1.1.11 christos 9: XOP 09 opcode space. 1006 1.1.1.11 christos A: XOP 0A opcode space. 1007 1.1.1.11 christos */ 1008 1.1.1.11 christos #define SPACE_BASE 0 1009 1.1.1.11 christos #define SPACE_0F 1 1010 1.1.1.11 christos #define SPACE_0F38 2 1011 1.1.1.11 christos #define SPACE_0F3A 3 1012 1.1.1.12 christos #define SPACE_MAP4 4 1013 1.1.1.12 christos #define SPACE_MAP5 5 1014 1.1.1.12 christos #define SPACE_MAP6 6 1015 1.1.1.12 christos #define SPACE_MAP7 7 1016 1.1.1.11 christos #define SPACE_XOP08 8 1017 1.1.1.11 christos #define SPACE_XOP09 9 1018 1.1.1.11 christos #define SPACE_XOP0A 0xA 1019 1.1.1.10 christos 1020 1.1.1.10 christos /* (Fake) base opcode value for pseudo prefixes. */ 1021 1.1.1.10 christos #define PSEUDO_PREFIX 0 1022 1.1.1.10 christos 1023 1.1.1.10 christos /* extension_opcode is the 3 bit extension for group <n> insns. 1024 1.1.1.10 christos This field is also used to store the 8-bit opcode suffix for the 1025 1.1.1.10 christos AMD 3DNow! instructions. 1026 1.1.1.10 christos If this template has no extension opcode (the usual case) use None 1027 1.1.1.10 christos Instructions */ 1028 1.1.1.10 christos signed int extension_opcode:9; 1029 1.1.1.10 christos #define None (-1) /* If no extension_opcode is possible. */ 1030 1.1 christos 1031 1.1.1.9 christos /* Pseudo prefixes. */ 1032 1.1.1.9 christos #define Prefix_Disp8 0 /* {disp8} */ 1033 1.1.1.9 christos #define Prefix_Disp16 1 /* {disp16} */ 1034 1.1.1.9 christos #define Prefix_Disp32 2 /* {disp32} */ 1035 1.1.1.9 christos #define Prefix_Load 3 /* {load} */ 1036 1.1.1.9 christos #define Prefix_Store 4 /* {store} */ 1037 1.1.1.9 christos #define Prefix_VEX 5 /* {vex} */ 1038 1.1.1.9 christos #define Prefix_VEX3 6 /* {vex3} */ 1039 1.1.1.9 christos #define Prefix_EVEX 7 /* {evex} */ 1040 1.1.1.9 christos #define Prefix_REX 8 /* {rex} */ 1041 1.1.1.11 christos #define Prefix_REX2 9 /* {rex2} */ 1042 1.1.1.11 christos #define Prefix_NoOptimize 10 /* {nooptimize} */ 1043 1.1.1.11 christos #define Prefix_NF 11 /* {nf} */ 1044 1.1.1.9 christos 1045 1.1 christos /* the bits in opcode_modifier are used to generate the final opcode from 1046 1.1 christos the base_opcode. These bits also are used to detect alternate forms of 1047 1.1 christos the same instruction */ 1048 1.1 christos i386_opcode_modifier opcode_modifier; 1049 1.1 christos 1050 1.1.1.11 christos /* cpu feature attributes */ 1051 1.1.1.11 christos i386_cpu_attr cpu, cpu_any; 1052 1.1.1.10 christos 1053 1.1 christos /* operand_types[i] describes the type of operand i. This is made 1054 1.1 christos by OR'ing together all of the possible type masks. (e.g. 1055 1.1 christos 'operand_types[i] = Reg|Imm' specifies that operand i can be 1056 1.1 christos either a register or an immediate operand. */ 1057 1.1 christos i386_operand_type operand_types[MAX_OPERANDS]; 1058 1.1 christos } 1059 1.1 christos insn_template; 1060 1.1 christos 1061 1.1 christos /* these are for register name --> number & type hash lookup */ 1062 1.1 christos typedef struct 1063 1.1 christos { 1064 1.1.1.11 christos char reg_name[8]; 1065 1.1 christos i386_operand_type reg_type; 1066 1.1 christos unsigned char reg_flags; 1067 1.1 christos #define RegRex 0x1 /* Extended register. */ 1068 1.1 christos #define RegRex64 0x2 /* Extended 8 bit register. */ 1069 1.1.1.3 christos #define RegVRex 0x4 /* Extended vector register. */ 1070 1.1.1.11 christos #define RegRex2 0x8 /* Extended GPRs R16R31 register. */ 1071 1.1 christos unsigned char reg_num; 1072 1.1.1.8 christos #define RegIP ((unsigned char ) ~0) 1073 1.1 christos /* EIZ and RIZ are fake index registers. */ 1074 1.1.1.8 christos #define RegIZ (RegIP - 1) 1075 1.1 christos /* FLAT is a fake segment register (Intel mode). */ 1076 1.1 christos #define RegFlat ((unsigned char) ~0) 1077 1.1.1.11 christos unsigned char dw2_regnum[2]; 1078 1.1.1.11 christos #define Dw2Inval 0xff 1079 1.1 christos } 1080 1.1 christos reg_entry; 1081