2009-12-19 03:59:52 +01:00
|
|
|
//===- X86DisassemblerTables.cpp - Disassembler tables ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is part of the X86 Disassembler Emitter.
|
|
|
|
// It contains the implementation of the disassembler tables.
|
|
|
|
// Documentation for the disassembler emitter in general can be found in
|
|
|
|
// X86DisasemblerEmitter.h.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "X86DisassemblerTables.h"
|
2012-12-04 11:37:14 +01:00
|
|
|
#include "X86DisassemblerShared.h"
|
2011-04-04 18:25:38 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2009-12-19 03:59:52 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2012-08-01 09:39:18 +02:00
|
|
|
#include <map>
|
2009-12-19 03:59:52 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace X86Disassembler;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2014-01-01 16:12:34 +01:00
|
|
|
/// stringForContext - Returns a string containing the name of a particular
|
|
|
|
/// InstructionContext, usually for diagnostic purposes.
|
|
|
|
///
|
|
|
|
/// @param insnContext - The instruction class to transform to a string.
|
|
|
|
/// @return - A statically-allocated string constant that contains the
|
|
|
|
/// name of the instruction class.
|
|
|
|
static inline const char* stringForContext(InstructionContext insnContext) {
|
|
|
|
switch (insnContext) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled instruction class");
|
|
|
|
#define ENUM_ENTRY(n, r, d) case n: return #n; break;
|
|
|
|
#define ENUM_ENTRY_K_B(n, r, d) ENUM_ENTRY(n, r, d) ENUM_ENTRY(n##_K_B, r, d)\
|
|
|
|
ENUM_ENTRY(n##_KZ, r, d) ENUM_ENTRY(n##_K, r, d) ENUM_ENTRY(n##_B, r, d)\
|
|
|
|
ENUM_ENTRY(n##_KZ_B, r, d)
|
|
|
|
INSTRUCTION_CONTEXTS
|
|
|
|
#undef ENUM_ENTRY
|
|
|
|
#undef ENUM_ENTRY_K_B
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// stringForOperandType - Like stringForContext, but for OperandTypes.
|
|
|
|
static inline const char* stringForOperandType(OperandType type) {
|
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled type");
|
|
|
|
#define ENUM_ENTRY(i, d) case i: return #i;
|
|
|
|
TYPES
|
|
|
|
#undef ENUM_ENTRY
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// stringForOperandEncoding - like stringForContext, but for
|
|
|
|
/// OperandEncodings.
|
|
|
|
static inline const char* stringForOperandEncoding(OperandEncoding encoding) {
|
|
|
|
switch (encoding) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled encoding");
|
|
|
|
#define ENUM_ENTRY(i, d) case i: return #i;
|
|
|
|
ENCODINGS
|
|
|
|
#undef ENUM_ENTRY
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
/// inheritsFrom - Indicates whether all instructions in one class also belong
|
|
|
|
/// to another class.
|
|
|
|
///
|
|
|
|
/// @param child - The class that may be the subset
|
|
|
|
/// @param parent - The class that may be the superset
|
|
|
|
/// @return - True if child is a subset of parent, false otherwise.
|
|
|
|
static inline bool inheritsFrom(InstructionContext child,
|
2011-10-04 08:30:42 +02:00
|
|
|
InstructionContext parent,
|
2015-01-02 08:02:25 +01:00
|
|
|
bool VEX_LIG = false, bool AdSize64 = false) {
|
2009-12-19 03:59:52 +01:00
|
|
|
if (child == parent)
|
|
|
|
return true;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
switch (parent) {
|
|
|
|
case IC:
|
2015-01-02 08:02:25 +01:00
|
|
|
return(inheritsFrom(child, IC_64BIT, AdSize64) ||
|
2011-09-02 06:17:54 +02:00
|
|
|
inheritsFrom(child, IC_OPSIZE) ||
|
2012-02-27 02:54:29 +01:00
|
|
|
inheritsFrom(child, IC_ADSIZE) ||
|
2011-09-02 06:17:54 +02:00
|
|
|
inheritsFrom(child, IC_XD) ||
|
|
|
|
inheritsFrom(child, IC_XS));
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_64BIT:
|
|
|
|
return(inheritsFrom(child, IC_64BIT_REXW) ||
|
|
|
|
inheritsFrom(child, IC_64BIT_OPSIZE) ||
|
2015-01-02 08:02:25 +01:00
|
|
|
(!AdSize64 && inheritsFrom(child, IC_64BIT_ADSIZE)) ||
|
2009-12-19 03:59:52 +01:00
|
|
|
inheritsFrom(child, IC_64BIT_XD) ||
|
|
|
|
inheritsFrom(child, IC_64BIT_XS));
|
|
|
|
case IC_OPSIZE:
|
2014-12-31 08:07:31 +01:00
|
|
|
return inheritsFrom(child, IC_64BIT_OPSIZE) ||
|
|
|
|
inheritsFrom(child, IC_OPSIZE_ADSIZE);
|
2012-02-27 02:54:29 +01:00
|
|
|
case IC_ADSIZE:
|
2014-12-31 08:07:31 +01:00
|
|
|
return inheritsFrom(child, IC_OPSIZE_ADSIZE);
|
|
|
|
case IC_OPSIZE_ADSIZE:
|
|
|
|
return false;
|
2012-02-27 02:54:29 +01:00
|
|
|
case IC_64BIT_ADSIZE:
|
2014-12-31 08:07:31 +01:00
|
|
|
return inheritsFrom(child, IC_64BIT_OPSIZE_ADSIZE);
|
|
|
|
case IC_64BIT_OPSIZE_ADSIZE:
|
2012-02-27 02:54:29 +01:00
|
|
|
return false;
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_XD:
|
2011-09-02 06:17:54 +02:00
|
|
|
return inheritsFrom(child, IC_64BIT_XD);
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_XS:
|
2011-09-02 06:17:54 +02:00
|
|
|
return inheritsFrom(child, IC_64BIT_XS);
|
2011-10-01 21:54:56 +02:00
|
|
|
case IC_XD_OPSIZE:
|
|
|
|
return inheritsFrom(child, IC_64BIT_XD_OPSIZE);
|
2011-10-11 06:34:23 +02:00
|
|
|
case IC_XS_OPSIZE:
|
|
|
|
return inheritsFrom(child, IC_64BIT_XS_OPSIZE);
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_64BIT_REXW:
|
|
|
|
return(inheritsFrom(child, IC_64BIT_REXW_XS) ||
|
|
|
|
inheritsFrom(child, IC_64BIT_REXW_XD) ||
|
2015-01-03 01:00:20 +01:00
|
|
|
inheritsFrom(child, IC_64BIT_REXW_OPSIZE) ||
|
|
|
|
(!AdSize64 && inheritsFrom(child, IC_64BIT_REXW_ADSIZE)));
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_64BIT_OPSIZE:
|
2014-12-31 08:07:31 +01:00
|
|
|
return inheritsFrom(child, IC_64BIT_REXW_OPSIZE) ||
|
2015-01-03 01:00:20 +01:00
|
|
|
(!AdSize64 && inheritsFrom(child, IC_64BIT_OPSIZE_ADSIZE)) ||
|
|
|
|
(!AdSize64 && inheritsFrom(child, IC_64BIT_REXW_ADSIZE));
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_64BIT_XD:
|
|
|
|
return(inheritsFrom(child, IC_64BIT_REXW_XD));
|
|
|
|
case IC_64BIT_XS:
|
|
|
|
return(inheritsFrom(child, IC_64BIT_REXW_XS));
|
2011-10-01 21:54:56 +02:00
|
|
|
case IC_64BIT_XD_OPSIZE:
|
2011-10-11 06:34:23 +02:00
|
|
|
case IC_64BIT_XS_OPSIZE:
|
2011-10-01 21:54:56 +02:00
|
|
|
return false;
|
2009-12-19 03:59:52 +01:00
|
|
|
case IC_64BIT_REXW_XD:
|
|
|
|
case IC_64BIT_REXW_XS:
|
|
|
|
case IC_64BIT_REXW_OPSIZE:
|
2015-01-03 01:00:20 +01:00
|
|
|
case IC_64BIT_REXW_ADSIZE:
|
2009-12-19 03:59:52 +01:00
|
|
|
return false;
|
2011-03-15 02:23:15 +01:00
|
|
|
case IC_VEX:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return (VEX_LIG && inheritsFrom(child, IC_VEX_L_W)) ||
|
2013-07-28 10:28:38 +02:00
|
|
|
inheritsFrom(child, IC_VEX_W) ||
|
2011-10-04 08:30:42 +02:00
|
|
|
(VEX_LIG && inheritsFrom(child, IC_VEX_L));
|
2011-03-15 02:23:15 +01:00
|
|
|
case IC_VEX_XS:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return (VEX_LIG && inheritsFrom(child, IC_VEX_L_W_XS)) ||
|
2013-07-28 10:28:38 +02:00
|
|
|
inheritsFrom(child, IC_VEX_W_XS) ||
|
2011-10-04 08:30:42 +02:00
|
|
|
(VEX_LIG && inheritsFrom(child, IC_VEX_L_XS));
|
2011-03-15 02:23:15 +01:00
|
|
|
case IC_VEX_XD:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return (VEX_LIG && inheritsFrom(child, IC_VEX_L_W_XD)) ||
|
2013-07-28 10:28:38 +02:00
|
|
|
inheritsFrom(child, IC_VEX_W_XD) ||
|
2011-10-04 08:30:42 +02:00
|
|
|
(VEX_LIG && inheritsFrom(child, IC_VEX_L_XD));
|
2011-09-02 06:17:54 +02:00
|
|
|
case IC_VEX_OPSIZE:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return (VEX_LIG && inheritsFrom(child, IC_VEX_L_W_OPSIZE)) ||
|
2013-07-28 10:28:38 +02:00
|
|
|
inheritsFrom(child, IC_VEX_W_OPSIZE) ||
|
2011-10-04 08:30:42 +02:00
|
|
|
(VEX_LIG && inheritsFrom(child, IC_VEX_L_OPSIZE));
|
2011-09-02 06:17:54 +02:00
|
|
|
case IC_VEX_W:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return VEX_LIG && inheritsFrom(child, IC_VEX_L_W);
|
2011-09-02 06:17:54 +02:00
|
|
|
case IC_VEX_W_XS:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return VEX_LIG && inheritsFrom(child, IC_VEX_L_W_XS);
|
2011-09-02 06:17:54 +02:00
|
|
|
case IC_VEX_W_XD:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return VEX_LIG && inheritsFrom(child, IC_VEX_L_W_XD);
|
2011-09-02 06:17:54 +02:00
|
|
|
case IC_VEX_W_OPSIZE:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return VEX_LIG && inheritsFrom(child, IC_VEX_L_W_OPSIZE);
|
2011-03-15 02:23:15 +01:00
|
|
|
case IC_VEX_L:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return inheritsFrom(child, IC_VEX_L_W);
|
2011-03-15 02:23:15 +01:00
|
|
|
case IC_VEX_L_XS:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return inheritsFrom(child, IC_VEX_L_W_XS);
|
2011-03-15 02:23:15 +01:00
|
|
|
case IC_VEX_L_XD:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return inheritsFrom(child, IC_VEX_L_W_XD);
|
2011-09-02 06:17:54 +02:00
|
|
|
case IC_VEX_L_OPSIZE:
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
return inheritsFrom(child, IC_VEX_L_W_OPSIZE);
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_VEX_L_W:
|
|
|
|
case IC_VEX_L_W_XS:
|
|
|
|
case IC_VEX_L_W_XD:
|
2011-11-07 00:04:08 +01:00
|
|
|
case IC_VEX_L_W_OPSIZE:
|
2011-03-15 02:23:15 +01:00
|
|
|
return false;
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W);
|
|
|
|
case IC_EVEX_XS:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W_XS) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_XS);
|
|
|
|
case IC_EVEX_XD:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W_XD) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_XD);
|
|
|
|
case IC_EVEX_OPSIZE:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W_OPSIZE) ||
|
2013-11-03 14:46:31 +01:00
|
|
|
inheritsFrom(child, IC_EVEX_L_W_OPSIZE);
|
2014-10-28 19:15:20 +01:00
|
|
|
case IC_EVEX_B:
|
|
|
|
return false;
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_W:
|
|
|
|
case IC_EVEX_W_XS:
|
|
|
|
case IC_EVEX_W_XD:
|
|
|
|
case IC_EVEX_W_OPSIZE:
|
|
|
|
return false;
|
|
|
|
case IC_EVEX_L:
|
2014-10-28 19:15:20 +01:00
|
|
|
case IC_EVEX_L_K_B:
|
|
|
|
case IC_EVEX_L_KZ_B:
|
|
|
|
case IC_EVEX_L_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L_XS:
|
|
|
|
case IC_EVEX_L_XD:
|
|
|
|
case IC_EVEX_L_OPSIZE:
|
|
|
|
return false;
|
|
|
|
case IC_EVEX_L_W:
|
|
|
|
case IC_EVEX_L_W_XS:
|
|
|
|
case IC_EVEX_L_W_XD:
|
|
|
|
case IC_EVEX_L_W_OPSIZE:
|
|
|
|
return false;
|
|
|
|
case IC_EVEX_L2:
|
|
|
|
case IC_EVEX_L2_XS:
|
|
|
|
case IC_EVEX_L2_XD:
|
|
|
|
case IC_EVEX_L2_OPSIZE:
|
|
|
|
return false;
|
|
|
|
case IC_EVEX_L2_W:
|
|
|
|
case IC_EVEX_L2_W_XS:
|
|
|
|
case IC_EVEX_L2_W_XD:
|
|
|
|
case IC_EVEX_L2_W_OPSIZE:
|
|
|
|
return false;
|
|
|
|
case IC_EVEX_K:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W_K) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_K);
|
|
|
|
case IC_EVEX_XS_K:
|
2015-03-01 08:44:04 +01:00
|
|
|
case IC_EVEX_XS_K_B:
|
|
|
|
case IC_EVEX_XS_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return inheritsFrom(child, IC_EVEX_W_XS_K) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_XS_K);
|
|
|
|
case IC_EVEX_XD_K:
|
2015-03-01 08:44:04 +01:00
|
|
|
case IC_EVEX_XD_K_B:
|
|
|
|
case IC_EVEX_XD_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return inheritsFrom(child, IC_EVEX_W_XD_K) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_XD_K);
|
2015-03-01 08:44:04 +01:00
|
|
|
case IC_EVEX_XS_B:
|
|
|
|
case IC_EVEX_XD_B:
|
[SKX] Enabling load/store instructions: encoding
Instructions: VMOVAPD, VMOVAPS, VMOVDQA8, VMOVDQA16, VMOVDQA32,VMOVDQA64, VMOVDQU8, VMOVDQU16, VMOVDQU32,VMOVDQU64, VMOVUPD, VMOVUPS,
Reviewed by Elena Demikhovsky <elena.demikhovsky@intel.com>
llvm-svn: 214719
2014-08-04 16:35:15 +02:00
|
|
|
case IC_EVEX_K_B:
|
|
|
|
case IC_EVEX_KZ:
|
|
|
|
return false;
|
|
|
|
case IC_EVEX_XS_KZ:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W_XS_KZ) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_XS_KZ);
|
|
|
|
case IC_EVEX_XD_KZ:
|
|
|
|
return inheritsFrom(child, IC_EVEX_W_XD_KZ) ||
|
|
|
|
inheritsFrom(child, IC_EVEX_L_W_XD_KZ);
|
|
|
|
case IC_EVEX_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_OPSIZE_K:
|
2014-01-13 13:55:03 +01:00
|
|
|
case IC_EVEX_OPSIZE_B:
|
2014-08-25 16:49:34 +02:00
|
|
|
case IC_EVEX_OPSIZE_K_B:
|
[SKX] Enabling load/store instructions: encoding
Instructions: VMOVAPD, VMOVAPS, VMOVDQA8, VMOVDQA16, VMOVDQA32,VMOVDQA64, VMOVDQU8, VMOVDQU16, VMOVDQU32,VMOVDQU64, VMOVUPD, VMOVUPS,
Reviewed by Elena Demikhovsky <elena.demikhovsky@intel.com>
llvm-svn: 214719
2014-08-04 16:35:15 +02:00
|
|
|
case IC_EVEX_OPSIZE_KZ:
|
2014-10-09 10:38:48 +02:00
|
|
|
case IC_EVEX_OPSIZE_KZ_B:
|
2014-01-13 13:55:03 +01:00
|
|
|
return false;
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_W_K:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_W_B:
|
|
|
|
case IC_EVEX_W_K_B:
|
|
|
|
case IC_EVEX_W_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_W_XS_K:
|
|
|
|
case IC_EVEX_W_XD_K:
|
|
|
|
case IC_EVEX_W_OPSIZE_K:
|
2014-01-13 13:55:03 +01:00
|
|
|
case IC_EVEX_W_OPSIZE_B:
|
2014-08-25 16:49:34 +02:00
|
|
|
case IC_EVEX_W_OPSIZE_K_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return false;
|
|
|
|
case IC_EVEX_L_K:
|
|
|
|
case IC_EVEX_L_XS_K:
|
|
|
|
case IC_EVEX_L_XD_K:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_XD_B:
|
|
|
|
case IC_EVEX_L_XD_K_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L_OPSIZE_K:
|
2014-08-25 16:49:34 +02:00
|
|
|
case IC_EVEX_L_OPSIZE_B:
|
|
|
|
case IC_EVEX_L_OPSIZE_K_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return false;
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_W_KZ:
|
|
|
|
case IC_EVEX_W_XS_KZ:
|
|
|
|
case IC_EVEX_W_XD_KZ:
|
2015-03-01 08:44:04 +01:00
|
|
|
case IC_EVEX_W_XS_B:
|
|
|
|
case IC_EVEX_W_XD_B:
|
|
|
|
case IC_EVEX_W_XS_K_B:
|
|
|
|
case IC_EVEX_W_XD_K_B:
|
|
|
|
case IC_EVEX_W_XS_KZ_B:
|
|
|
|
case IC_EVEX_W_XD_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_W_OPSIZE_KZ:
|
2014-10-09 10:38:48 +02:00
|
|
|
case IC_EVEX_W_OPSIZE_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
return false;
|
|
|
|
case IC_EVEX_L_KZ:
|
|
|
|
case IC_EVEX_L_XS_KZ:
|
2015-04-21 15:13:46 +02:00
|
|
|
case IC_EVEX_L_XS_B:
|
|
|
|
case IC_EVEX_L_XS_K_B:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_XS_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L_XD_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_XD_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L_OPSIZE_KZ:
|
2014-10-09 10:38:48 +02:00
|
|
|
case IC_EVEX_L_OPSIZE_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
return false;
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L_W_K:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_W_B:
|
2016-06-20 22:43:26 +02:00
|
|
|
case IC_EVEX_L_W_K_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L_W_XS_K:
|
2015-04-21 15:13:46 +02:00
|
|
|
case IC_EVEX_L_W_XS_B:
|
|
|
|
case IC_EVEX_L_W_XS_K_B:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_W_XS_KZ:
|
|
|
|
case IC_EVEX_L_W_XS_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L_W_OPSIZE_K:
|
2014-08-25 16:49:34 +02:00
|
|
|
case IC_EVEX_L_W_OPSIZE_B:
|
|
|
|
case IC_EVEX_L_W_OPSIZE_K_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L_W_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_W_KZ_B:
|
|
|
|
case IC_EVEX_L_W_XD_K:
|
|
|
|
case IC_EVEX_L_W_XD_B:
|
|
|
|
case IC_EVEX_L_W_XD_K_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L_W_XD_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L_W_XD_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L_W_OPSIZE_KZ:
|
2014-10-09 10:38:48 +02:00
|
|
|
case IC_EVEX_L_W_OPSIZE_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return false;
|
|
|
|
case IC_EVEX_L2_K:
|
|
|
|
case IC_EVEX_L2_B:
|
2014-03-06 09:45:30 +01:00
|
|
|
case IC_EVEX_L2_K_B:
|
|
|
|
case IC_EVEX_L2_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L2_XS_K:
|
2015-04-21 15:13:46 +02:00
|
|
|
case IC_EVEX_L2_XS_K_B:
|
2014-01-01 16:12:34 +01:00
|
|
|
case IC_EVEX_L2_XS_B:
|
|
|
|
case IC_EVEX_L2_XD_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L2_XD_K:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L2_XD_K_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L2_OPSIZE_K:
|
|
|
|
case IC_EVEX_L2_OPSIZE_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_OPSIZE_K_B:
|
|
|
|
case IC_EVEX_L2_KZ:
|
|
|
|
case IC_EVEX_L2_XS_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L2_XS_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_XD_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L2_XD_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_OPSIZE_KZ:
|
|
|
|
case IC_EVEX_L2_OPSIZE_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return false;
|
|
|
|
case IC_EVEX_L2_W_K:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_W_B:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L2_W_K_B:
|
|
|
|
case IC_EVEX_L2_W_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L2_W_XS_K:
|
2015-04-21 15:13:46 +02:00
|
|
|
case IC_EVEX_L2_W_XS_B:
|
|
|
|
case IC_EVEX_L2_W_XS_K_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L2_W_XD_K:
|
2014-01-01 16:12:34 +01:00
|
|
|
case IC_EVEX_L2_W_XD_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
case IC_EVEX_L2_W_OPSIZE_K:
|
|
|
|
case IC_EVEX_L2_W_OPSIZE_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_W_OPSIZE_K_B:
|
|
|
|
case IC_EVEX_L2_W_KZ:
|
|
|
|
case IC_EVEX_L2_W_XS_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L2_W_XS_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_W_XD_KZ:
|
2015-07-13 15:26:20 +02:00
|
|
|
case IC_EVEX_L2_W_XD_K_B:
|
|
|
|
case IC_EVEX_L2_W_XD_KZ_B:
|
2013-11-03 14:46:31 +01:00
|
|
|
case IC_EVEX_L2_W_OPSIZE_KZ:
|
|
|
|
case IC_EVEX_L2_W_OPSIZE_KZ_B:
|
2013-07-28 10:28:38 +02:00
|
|
|
return false;
|
2009-12-19 03:59:52 +01:00
|
|
|
default:
|
2014-01-01 16:12:34 +01:00
|
|
|
errs() << "Unknown instruction class: " <<
|
|
|
|
stringForContext((InstructionContext)parent) << "\n";
|
2011-09-02 06:17:54 +02:00
|
|
|
llvm_unreachable("Unknown instruction class");
|
2009-12-19 03:59:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// outranks - Indicates whether, if an instruction has two different applicable
|
|
|
|
/// classes, which class should be preferred when performing decode. This
|
|
|
|
/// imposes a total ordering (ties are resolved toward "lower")
|
|
|
|
///
|
|
|
|
/// @param upper - The class that may be preferable
|
|
|
|
/// @param lower - The class that may be less preferable
|
|
|
|
/// @return - True if upper is to be preferred, false otherwise.
|
2012-07-31 07:27:01 +02:00
|
|
|
static inline bool outranks(InstructionContext upper,
|
2009-12-19 03:59:52 +01:00
|
|
|
InstructionContext lower) {
|
|
|
|
assert(upper < IC_max);
|
|
|
|
assert(lower < IC_max);
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
#define ENUM_ENTRY(n, r, d) r,
|
2013-07-28 10:28:38 +02:00
|
|
|
#define ENUM_ENTRY_K_B(n, r, d) ENUM_ENTRY(n, r, d) \
|
2013-11-03 14:46:31 +01:00
|
|
|
ENUM_ENTRY(n##_K_B, r, d) ENUM_ENTRY(n##_KZ_B, r, d) \
|
|
|
|
ENUM_ENTRY(n##_KZ, r, d) ENUM_ENTRY(n##_K, r, d) ENUM_ENTRY(n##_B, r, d)
|
2009-12-19 03:59:52 +01:00
|
|
|
static int ranks[IC_max] = {
|
|
|
|
INSTRUCTION_CONTEXTS
|
|
|
|
};
|
|
|
|
#undef ENUM_ENTRY
|
2013-07-28 10:28:38 +02:00
|
|
|
#undef ENUM_ENTRY_K_B
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
return (ranks[upper] > ranks[lower]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getDecisionType - Determines whether a ModRM decision with 255 entries can
|
|
|
|
/// be compacted by eliminating redundant information.
|
|
|
|
///
|
|
|
|
/// @param decision - The decision to be compacted.
|
|
|
|
/// @return - The compactest available representation for the decision.
|
2012-07-31 07:42:02 +02:00
|
|
|
static ModRMDecisionType getDecisionType(ModRMDecision &decision) {
|
2009-12-19 03:59:52 +01:00
|
|
|
bool satisfiesOneEntry = true;
|
|
|
|
bool satisfiesSplitRM = true;
|
2012-02-09 09:58:07 +01:00
|
|
|
bool satisfiesSplitReg = true;
|
2012-09-13 07:45:42 +02:00
|
|
|
bool satisfiesSplitMisc = true;
|
2012-02-09 09:58:07 +01:00
|
|
|
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < 256; ++index) {
|
2009-12-19 03:59:52 +01:00
|
|
|
if (decision.instructionIDs[index] != decision.instructionIDs[0])
|
|
|
|
satisfiesOneEntry = false;
|
2012-02-09 09:58:07 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
if (((index & 0xc0) == 0xc0) &&
|
|
|
|
(decision.instructionIDs[index] != decision.instructionIDs[0xc0]))
|
|
|
|
satisfiesSplitRM = false;
|
2012-02-09 09:58:07 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
if (((index & 0xc0) != 0xc0) &&
|
|
|
|
(decision.instructionIDs[index] != decision.instructionIDs[0x00]))
|
|
|
|
satisfiesSplitRM = false;
|
2012-02-09 09:58:07 +01:00
|
|
|
|
|
|
|
if (((index & 0xc0) == 0xc0) &&
|
|
|
|
(decision.instructionIDs[index] != decision.instructionIDs[index&0xf8]))
|
|
|
|
satisfiesSplitReg = false;
|
|
|
|
|
|
|
|
if (((index & 0xc0) != 0xc0) &&
|
|
|
|
(decision.instructionIDs[index] != decision.instructionIDs[index&0x38]))
|
2012-09-13 07:45:42 +02:00
|
|
|
satisfiesSplitMisc = false;
|
2009-12-19 03:59:52 +01:00
|
|
|
}
|
2012-02-09 09:58:07 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
if (satisfiesOneEntry)
|
|
|
|
return MODRM_ONEENTRY;
|
2012-02-09 09:58:07 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
if (satisfiesSplitRM)
|
|
|
|
return MODRM_SPLITRM;
|
2012-02-09 09:58:07 +01:00
|
|
|
|
2012-09-13 07:45:42 +02:00
|
|
|
if (satisfiesSplitReg && satisfiesSplitMisc)
|
2012-02-09 09:58:07 +01:00
|
|
|
return MODRM_SPLITREG;
|
|
|
|
|
2012-09-13 07:45:42 +02:00
|
|
|
if (satisfiesSplitMisc)
|
|
|
|
return MODRM_SPLITMISC;
|
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
return MODRM_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// stringForDecisionType - Returns a statically-allocated string corresponding
|
|
|
|
/// to a particular decision type.
|
|
|
|
///
|
|
|
|
/// @param dt - The decision type.
|
2012-07-31 07:27:01 +02:00
|
|
|
/// @return - A pointer to the statically-allocated string (e.g.,
|
2009-12-19 03:59:52 +01:00
|
|
|
/// "MODRM_ONEENTRY" for MODRM_ONEENTRY).
|
2012-07-31 07:42:02 +02:00
|
|
|
static const char* stringForDecisionType(ModRMDecisionType dt) {
|
2009-12-19 03:59:52 +01:00
|
|
|
#define ENUM_ENTRY(n) case n: return #n;
|
|
|
|
switch (dt) {
|
|
|
|
default:
|
2012-07-31 07:27:01 +02:00
|
|
|
llvm_unreachable("Unknown decision type");
|
2009-12-19 03:59:52 +01:00
|
|
|
MODRMTYPES
|
2012-07-31 07:27:01 +02:00
|
|
|
};
|
2009-12-19 03:59:52 +01:00
|
|
|
#undef ENUM_ENTRY
|
|
|
|
}
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
DisassemblerTables::DisassemblerTables() {
|
|
|
|
unsigned i;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2011-04-04 18:25:38 +02:00
|
|
|
for (i = 0; i < array_lengthof(Tables); i++) {
|
2009-12-19 03:59:52 +01:00
|
|
|
Tables[i] = new ContextDecision;
|
2009-12-19 05:16:57 +01:00
|
|
|
memset(Tables[i], 0, sizeof(ContextDecision));
|
2009-12-19 03:59:52 +01:00
|
|
|
}
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
HasConflicts = false;
|
|
|
|
}
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
DisassemblerTables::~DisassemblerTables() {
|
|
|
|
unsigned i;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2011-04-04 18:25:38 +02:00
|
|
|
for (i = 0; i < array_lengthof(Tables); i++)
|
2009-12-19 03:59:52 +01:00
|
|
|
delete Tables[i];
|
|
|
|
}
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2012-07-31 07:42:02 +02:00
|
|
|
void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2,
|
2012-07-31 08:02:05 +02:00
|
|
|
unsigned &i1, unsigned &i2,
|
2013-09-30 08:23:19 +02:00
|
|
|
unsigned &ModRMTableNum,
|
2012-07-31 07:42:02 +02:00
|
|
|
ModRMDecision &decision) const {
|
2012-07-31 08:02:05 +02:00
|
|
|
static uint32_t sTableNumber = 0;
|
|
|
|
static uint32_t sEntryNumber = 1;
|
2009-12-19 03:59:52 +01:00
|
|
|
ModRMDecisionType dt = getDecisionType(decision);
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
if (dt == MODRM_ONEENTRY && decision.instructionIDs[0] == 0)
|
|
|
|
{
|
|
|
|
o2.indent(i2) << "{ /* ModRMDecision */" << "\n";
|
|
|
|
i2++;
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
o2.indent(i2) << stringForDecisionType(dt) << "," << "\n";
|
2012-02-09 08:45:30 +01:00
|
|
|
o2.indent(i2) << 0 << " /* EmptyTable */\n";
|
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
i2--;
|
|
|
|
o2.indent(i2) << "}";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-30 08:23:19 +02:00
|
|
|
std::vector<unsigned> ModRMDecision;
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
switch (dt) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown decision type");
|
|
|
|
case MODRM_ONEENTRY:
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[0]);
|
2009-12-19 03:59:52 +01:00
|
|
|
break;
|
|
|
|
case MODRM_SPLITRM:
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[0x00]);
|
|
|
|
ModRMDecision.push_back(decision.instructionIDs[0xc0]);
|
2009-12-19 03:59:52 +01:00
|
|
|
break;
|
2012-02-09 09:58:07 +01:00
|
|
|
case MODRM_SPLITREG:
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < 64; index += 8)
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[index]);
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0xc0; index < 256; index += 8)
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[index]);
|
2012-02-09 09:58:07 +01:00
|
|
|
break;
|
2012-09-13 07:45:42 +02:00
|
|
|
case MODRM_SPLITMISC:
|
|
|
|
for (unsigned index = 0; index < 64; index += 8)
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[index]);
|
2012-09-13 07:45:42 +02:00
|
|
|
for (unsigned index = 0xc0; index < 256; ++index)
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[index]);
|
2012-09-13 07:45:42 +02:00
|
|
|
break;
|
2009-12-19 03:59:52 +01:00
|
|
|
case MODRM_FULL:
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < 256; ++index)
|
2013-09-30 08:23:19 +02:00
|
|
|
ModRMDecision.push_back(decision.instructionIDs[index]);
|
2009-12-19 03:59:52 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2013-09-30 08:23:19 +02:00
|
|
|
unsigned &EntryNumber = ModRMTable[ModRMDecision];
|
|
|
|
if (EntryNumber == 0) {
|
|
|
|
EntryNumber = ModRMTableNum;
|
|
|
|
|
|
|
|
ModRMTableNum += ModRMDecision.size();
|
|
|
|
o1 << "/* Table" << EntryNumber << " */\n";
|
|
|
|
i1++;
|
|
|
|
for (std::vector<unsigned>::const_iterator I = ModRMDecision.begin(),
|
|
|
|
E = ModRMDecision.end(); I != E; ++I) {
|
|
|
|
o1.indent(i1 * 2) << format("0x%hx", *I) << ", /* "
|
|
|
|
<< InstructionSpecifiers[*I].name << " */\n";
|
|
|
|
}
|
|
|
|
i1--;
|
|
|
|
}
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
o2.indent(i2) << "{ /* struct ModRMDecision */" << "\n";
|
|
|
|
i2++;
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
o2.indent(i2) << stringForDecisionType(dt) << "," << "\n";
|
2013-09-30 08:23:19 +02:00
|
|
|
o2.indent(i2) << EntryNumber << " /* Table" << EntryNumber << " */\n";
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
i2--;
|
|
|
|
o2.indent(i2) << "}";
|
2012-02-09 08:45:30 +01:00
|
|
|
|
|
|
|
switch (dt) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown decision type");
|
|
|
|
case MODRM_ONEENTRY:
|
|
|
|
sEntryNumber += 1;
|
|
|
|
break;
|
|
|
|
case MODRM_SPLITRM:
|
|
|
|
sEntryNumber += 2;
|
|
|
|
break;
|
2012-02-09 09:58:07 +01:00
|
|
|
case MODRM_SPLITREG:
|
|
|
|
sEntryNumber += 16;
|
|
|
|
break;
|
2012-09-13 07:45:42 +02:00
|
|
|
case MODRM_SPLITMISC:
|
|
|
|
sEntryNumber += 8 + 64;
|
|
|
|
break;
|
2012-02-09 08:45:30 +01:00
|
|
|
case MODRM_FULL:
|
|
|
|
sEntryNumber += 256;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-11 06:19:21 +02:00
|
|
|
// We assume that the index can fit into uint16_t.
|
|
|
|
assert(sEntryNumber < 65536U &&
|
|
|
|
"Index into ModRMDecision is too large for uint16_t!");
|
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
++sTableNumber;
|
|
|
|
}
|
|
|
|
|
2012-07-31 07:42:02 +02:00
|
|
|
void DisassemblerTables::emitOpcodeDecision(raw_ostream &o1, raw_ostream &o2,
|
2012-07-31 08:02:05 +02:00
|
|
|
unsigned &i1, unsigned &i2,
|
2013-09-30 08:23:19 +02:00
|
|
|
unsigned &ModRMTableNum,
|
2012-07-31 07:42:02 +02:00
|
|
|
OpcodeDecision &decision) const {
|
2009-12-19 03:59:52 +01:00
|
|
|
o2.indent(i2) << "{ /* struct OpcodeDecision */" << "\n";
|
|
|
|
i2++;
|
|
|
|
o2.indent(i2) << "{" << "\n";
|
|
|
|
i2++;
|
|
|
|
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < 256; ++index) {
|
2009-12-19 03:59:52 +01:00
|
|
|
o2.indent(i2);
|
|
|
|
|
|
|
|
o2 << "/* 0x" << format("%02hhx", index) << " */" << "\n";
|
|
|
|
|
2013-09-30 08:23:19 +02:00
|
|
|
emitModRMDecision(o1, o2, i1, i2, ModRMTableNum,
|
|
|
|
decision.modRMDecisions[index]);
|
2009-12-19 03:59:52 +01:00
|
|
|
|
|
|
|
if (index < 255)
|
|
|
|
o2 << ",";
|
|
|
|
|
|
|
|
o2 << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
i2--;
|
|
|
|
o2.indent(i2) << "}" << "\n";
|
|
|
|
i2--;
|
|
|
|
o2.indent(i2) << "}" << "\n";
|
|
|
|
}
|
|
|
|
|
2012-07-31 07:42:02 +02:00
|
|
|
void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2,
|
2012-07-31 08:02:05 +02:00
|
|
|
unsigned &i1, unsigned &i2,
|
2013-09-30 08:23:19 +02:00
|
|
|
unsigned &ModRMTableNum,
|
2012-07-31 07:42:02 +02:00
|
|
|
ContextDecision &decision,
|
|
|
|
const char* name) const {
|
2010-10-23 11:10:44 +02:00
|
|
|
o2.indent(i2) << "static const struct ContextDecision " << name << " = {\n";
|
2009-12-19 03:59:52 +01:00
|
|
|
i2++;
|
|
|
|
o2.indent(i2) << "{ /* opcodeDecisions */" << "\n";
|
|
|
|
i2++;
|
|
|
|
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < IC_max; ++index) {
|
2009-12-19 03:59:52 +01:00
|
|
|
o2.indent(i2) << "/* ";
|
|
|
|
o2 << stringForContext((InstructionContext)index);
|
|
|
|
o2 << " */";
|
|
|
|
o2 << "\n";
|
|
|
|
|
2013-09-30 08:23:19 +02:00
|
|
|
emitOpcodeDecision(o1, o2, i1, i2, ModRMTableNum,
|
|
|
|
decision.opcodeDecisions[index]);
|
2009-12-19 03:59:52 +01:00
|
|
|
|
|
|
|
if (index + 1 < IC_max)
|
|
|
|
o2 << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
i2--;
|
|
|
|
o2.indent(i2) << "}" << "\n";
|
|
|
|
i2--;
|
|
|
|
o2.indent(i2) << "};" << "\n";
|
|
|
|
}
|
|
|
|
|
2012-07-31 08:02:05 +02:00
|
|
|
void DisassemblerTables::emitInstructionInfo(raw_ostream &o,
|
|
|
|
unsigned &i) const {
|
2012-08-01 09:39:18 +02:00
|
|
|
unsigned NumInstructions = InstructionSpecifiers.size();
|
|
|
|
|
|
|
|
o << "static const struct OperandSpecifier x86OperandSets[]["
|
|
|
|
<< X86_MAX_OPERANDS << "] = {\n";
|
|
|
|
|
2015-04-09 06:08:48 +02:00
|
|
|
typedef SmallVector<std::pair<OperandEncoding, OperandType>,
|
|
|
|
X86_MAX_OPERANDS> OperandListTy;
|
2012-08-01 09:39:18 +02:00
|
|
|
std::map<OperandListTy, unsigned> OperandSets;
|
|
|
|
|
|
|
|
unsigned OperandSetNum = 0;
|
|
|
|
for (unsigned Index = 0; Index < NumInstructions; ++Index) {
|
|
|
|
OperandListTy OperandList;
|
|
|
|
|
|
|
|
for (unsigned OperandIndex = 0; OperandIndex < X86_MAX_OPERANDS;
|
|
|
|
++OperandIndex) {
|
2015-04-09 06:08:42 +02:00
|
|
|
OperandEncoding Encoding = (OperandEncoding)InstructionSpecifiers[Index]
|
|
|
|
.operands[OperandIndex].encoding;
|
|
|
|
OperandType Type = (OperandType)InstructionSpecifiers[Index]
|
|
|
|
.operands[OperandIndex].type;
|
2012-08-01 09:39:18 +02:00
|
|
|
OperandList.push_back(std::make_pair(Encoding, Type));
|
|
|
|
}
|
|
|
|
unsigned &N = OperandSets[OperandList];
|
|
|
|
if (N != 0) continue;
|
|
|
|
|
|
|
|
N = ++OperandSetNum;
|
|
|
|
|
|
|
|
o << " { /* " << (OperandSetNum - 1) << " */\n";
|
|
|
|
for (unsigned i = 0, e = OperandList.size(); i != e; ++i) {
|
2015-04-09 06:08:42 +02:00
|
|
|
const char *Encoding = stringForOperandEncoding(OperandList[i].first);
|
|
|
|
const char *Type = stringForOperandType(OperandList[i].second);
|
|
|
|
o << " { " << Encoding << ", " << Type << " },\n";
|
2012-08-01 09:39:18 +02:00
|
|
|
}
|
|
|
|
o << " },\n";
|
|
|
|
}
|
|
|
|
o << "};" << "\n\n";
|
|
|
|
|
2010-10-23 11:10:44 +02:00
|
|
|
o.indent(i * 2) << "static const struct InstructionSpecifier ";
|
|
|
|
o << INSTRUCTIONS_STR "[" << InstructionSpecifiers.size() << "] = {\n";
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
i++;
|
|
|
|
|
2012-08-01 09:39:18 +02:00
|
|
|
for (unsigned index = 0; index < NumInstructions; ++index) {
|
2015-04-09 06:08:46 +02:00
|
|
|
o.indent(i * 2) << "{ /* " << index << " */\n";
|
2009-12-19 03:59:52 +01:00
|
|
|
i++;
|
2012-03-04 03:16:41 +01:00
|
|
|
|
2012-08-01 09:39:18 +02:00
|
|
|
OperandListTy OperandList;
|
|
|
|
for (unsigned OperandIndex = 0; OperandIndex < X86_MAX_OPERANDS;
|
|
|
|
++OperandIndex) {
|
2015-04-09 06:08:42 +02:00
|
|
|
OperandEncoding Encoding = (OperandEncoding)InstructionSpecifiers[index]
|
|
|
|
.operands[OperandIndex].encoding;
|
|
|
|
OperandType Type = (OperandType)InstructionSpecifiers[index]
|
|
|
|
.operands[OperandIndex].type;
|
2012-08-01 09:39:18 +02:00
|
|
|
OperandList.push_back(std::make_pair(Encoding, Type));
|
2009-12-19 03:59:52 +01:00
|
|
|
}
|
2012-08-01 09:39:18 +02:00
|
|
|
o.indent(i * 2) << (OperandSets[OperandList] - 1) << ",\n";
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2015-04-09 06:08:46 +02:00
|
|
|
o.indent(i * 2) << "/* " << InstructionSpecifiers[index].name << " */\n";
|
2009-12-19 03:59:52 +01:00
|
|
|
|
|
|
|
i--;
|
2015-04-09 06:08:46 +02:00
|
|
|
o.indent(i * 2) << "},\n";
|
2009-12-19 03:59:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
i--;
|
|
|
|
o.indent(i * 2) << "};" << "\n";
|
|
|
|
}
|
|
|
|
|
2012-07-31 08:02:05 +02:00
|
|
|
void DisassemblerTables::emitContextTable(raw_ostream &o, unsigned &i) const {
|
2013-12-25 12:40:51 +01:00
|
|
|
const unsigned int tableSize = 16384;
|
2012-07-31 08:15:39 +02:00
|
|
|
o.indent(i * 2) << "static const uint8_t " CONTEXTS_STR
|
2013-12-25 12:40:51 +01:00
|
|
|
"[" << tableSize << "] = {\n";
|
2009-12-19 03:59:52 +01:00
|
|
|
i++;
|
|
|
|
|
2013-12-25 12:40:51 +01:00
|
|
|
for (unsigned index = 0; index < tableSize; ++index) {
|
2009-12-19 03:59:52 +01:00
|
|
|
o.indent(i * 2);
|
|
|
|
|
2013-12-25 12:40:51 +01:00
|
|
|
if (index & ATTR_EVEX) {
|
|
|
|
o << "IC_EVEX";
|
|
|
|
if (index & ATTR_EVEXL2)
|
|
|
|
o << "_L2";
|
|
|
|
else if (index & ATTR_EVEXL)
|
|
|
|
o << "_L";
|
|
|
|
if (index & ATTR_REXW)
|
|
|
|
o << "_W";
|
|
|
|
if (index & ATTR_OPSIZE)
|
|
|
|
o << "_OPSIZE";
|
|
|
|
else if (index & ATTR_XD)
|
|
|
|
o << "_XD";
|
|
|
|
else if (index & ATTR_XS)
|
|
|
|
o << "_XS";
|
|
|
|
if (index & ATTR_EVEXKZ)
|
|
|
|
o << "_KZ";
|
|
|
|
else if (index & ATTR_EVEXK)
|
|
|
|
o << "_K";
|
|
|
|
if (index & ATTR_EVEXB)
|
|
|
|
o << "_B";
|
|
|
|
}
|
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_REXW) && (index & ATTR_OPSIZE))
|
2011-11-07 00:04:08 +01:00
|
|
|
o << "IC_VEX_L_W_OPSIZE";
|
Various x86 disassembler fixes.
Add VEX_LIG to scalar FMA4 instructions.
Use VEX_LIG in some of the inheriting checks in disassembler table generator.
Make use of VEX_L_W, VEX_L_W_XS, VEX_L_W_XD contexts.
Don't let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from their non-L forms unless VEX_LIG is set.
Let VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE inherit from all of their non-L or non-W cases.
Increase ranking on VEX_L_W, VEX_L_W_XS, VEX_L_W_XD, VEX_L_W_OPSIZE so they get chosen over non-L/non-W forms.
llvm-svn: 191649
2013-09-30 04:46:36 +02:00
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_REXW) && (index & ATTR_XD))
|
|
|
|
o << "IC_VEX_L_W_XD";
|
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_REXW) && (index & ATTR_XS))
|
|
|
|
o << "IC_VEX_L_W_XS";
|
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_REXW))
|
|
|
|
o << "IC_VEX_L_W";
|
2011-11-07 00:04:08 +01:00
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_OPSIZE))
|
2011-03-15 02:23:15 +01:00
|
|
|
o << "IC_VEX_L_OPSIZE";
|
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_XD))
|
|
|
|
o << "IC_VEX_L_XD";
|
|
|
|
else if ((index & ATTR_VEXL) && (index & ATTR_XS))
|
|
|
|
o << "IC_VEX_L_XS";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_REXW) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_VEX_W_OPSIZE";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_REXW) && (index & ATTR_XD))
|
|
|
|
o << "IC_VEX_W_XD";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_REXW) && (index & ATTR_XS))
|
|
|
|
o << "IC_VEX_W_XS";
|
|
|
|
else if (index & ATTR_VEXL)
|
|
|
|
o << "IC_VEX_L";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_REXW))
|
|
|
|
o << "IC_VEX_W";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_VEX_OPSIZE";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_XD))
|
|
|
|
o << "IC_VEX_XD";
|
|
|
|
else if ((index & ATTR_VEX) && (index & ATTR_XS))
|
|
|
|
o << "IC_VEX_XS";
|
2011-08-25 09:42:00 +02:00
|
|
|
else if (index & ATTR_VEX)
|
|
|
|
o << "IC_VEX";
|
2011-03-15 02:23:15 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XS))
|
2009-12-19 03:59:52 +01:00
|
|
|
o << "IC_64BIT_REXW_XS";
|
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XD))
|
|
|
|
o << "IC_64BIT_REXW_XD";
|
2012-07-31 07:27:01 +02:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_REXW) &&
|
2009-12-19 03:59:52 +01:00
|
|
|
(index & ATTR_OPSIZE))
|
|
|
|
o << "IC_64BIT_REXW_OPSIZE";
|
2015-01-03 01:00:20 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_REXW) &&
|
|
|
|
(index & ATTR_ADSIZE))
|
|
|
|
o << "IC_64BIT_REXW_ADSIZE";
|
2011-10-01 21:54:56 +02:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_XD) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_64BIT_XD_OPSIZE";
|
2011-10-11 06:34:23 +02:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_XS) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_64BIT_XS_OPSIZE";
|
2009-12-19 03:59:52 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_XS))
|
|
|
|
o << "IC_64BIT_XS";
|
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_XD))
|
|
|
|
o << "IC_64BIT_XD";
|
2014-12-31 08:07:31 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_OPSIZE) &&
|
|
|
|
(index & ATTR_ADSIZE))
|
|
|
|
o << "IC_64BIT_OPSIZE_ADSIZE";
|
2009-12-19 03:59:52 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_64BIT_OPSIZE";
|
2012-02-27 02:54:29 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_ADSIZE))
|
|
|
|
o << "IC_64BIT_ADSIZE";
|
2009-12-19 03:59:52 +01:00
|
|
|
else if ((index & ATTR_64BIT) && (index & ATTR_REXW))
|
|
|
|
o << "IC_64BIT_REXW";
|
|
|
|
else if ((index & ATTR_64BIT))
|
|
|
|
o << "IC_64BIT";
|
2011-10-11 06:34:23 +02:00
|
|
|
else if ((index & ATTR_XS) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_XS_OPSIZE";
|
2011-10-01 21:54:56 +02:00
|
|
|
else if ((index & ATTR_XD) && (index & ATTR_OPSIZE))
|
|
|
|
o << "IC_XD_OPSIZE";
|
2009-12-19 03:59:52 +01:00
|
|
|
else if (index & ATTR_XS)
|
|
|
|
o << "IC_XS";
|
|
|
|
else if (index & ATTR_XD)
|
|
|
|
o << "IC_XD";
|
2014-12-31 08:07:31 +01:00
|
|
|
else if ((index & ATTR_OPSIZE) && (index & ATTR_ADSIZE))
|
|
|
|
o << "IC_OPSIZE_ADSIZE";
|
2009-12-19 03:59:52 +01:00
|
|
|
else if (index & ATTR_OPSIZE)
|
|
|
|
o << "IC_OPSIZE";
|
2012-02-27 02:54:29 +01:00
|
|
|
else if (index & ATTR_ADSIZE)
|
|
|
|
o << "IC_ADSIZE";
|
2009-12-19 03:59:52 +01:00
|
|
|
else
|
|
|
|
o << "IC";
|
|
|
|
|
2013-12-25 12:40:51 +01:00
|
|
|
if (index < tableSize - 1)
|
2009-12-19 03:59:52 +01:00
|
|
|
o << ",";
|
|
|
|
else
|
|
|
|
o << " ";
|
|
|
|
|
|
|
|
o << " /* " << index << " */";
|
|
|
|
|
|
|
|
o << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
i--;
|
|
|
|
o.indent(i * 2) << "};" << "\n";
|
|
|
|
}
|
|
|
|
|
2012-07-31 07:42:02 +02:00
|
|
|
void DisassemblerTables::emitContextDecisions(raw_ostream &o1, raw_ostream &o2,
|
2013-09-30 08:23:19 +02:00
|
|
|
unsigned &i1, unsigned &i2,
|
|
|
|
unsigned &ModRMTableNum) const {
|
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[0], ONEBYTE_STR);
|
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[1], TWOBYTE_STR);
|
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[2], THREEBYTE38_STR);
|
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[3], THREEBYTE3A_STR);
|
2014-02-19 06:34:21 +01:00
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[4], XOP8_MAP_STR);
|
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[5], XOP9_MAP_STR);
|
|
|
|
emitContextDecision(o1, o2, i1, i2, ModRMTableNum, *Tables[6], XOPA_MAP_STR);
|
2009-12-19 03:59:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerTables::emit(raw_ostream &o) const {
|
2012-07-31 08:02:05 +02:00
|
|
|
unsigned i1 = 0;
|
|
|
|
unsigned i2 = 0;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
std::string s1;
|
|
|
|
std::string s2;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
raw_string_ostream o1(s1);
|
|
|
|
raw_string_ostream o2(s2);
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
emitInstructionInfo(o, i2);
|
|
|
|
o << "\n";
|
|
|
|
|
|
|
|
emitContextTable(o, i2);
|
|
|
|
o << "\n";
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2013-09-30 08:23:19 +02:00
|
|
|
unsigned ModRMTableNum = 0;
|
|
|
|
|
2012-02-09 08:45:30 +01:00
|
|
|
o << "static const InstrUID modRMTable[] = {\n";
|
|
|
|
i1++;
|
2013-09-30 08:23:19 +02:00
|
|
|
std::vector<unsigned> EmptyTable(1, 0);
|
|
|
|
ModRMTable[EmptyTable] = ModRMTableNum;
|
|
|
|
ModRMTableNum += EmptyTable.size();
|
|
|
|
o1 << "/* EmptyTable */\n";
|
|
|
|
o1.indent(i1 * 2) << "0x0,\n";
|
2012-02-09 08:45:30 +01:00
|
|
|
i1--;
|
2013-09-30 08:23:19 +02:00
|
|
|
emitContextDecisions(o1, o2, i1, i2, ModRMTableNum);
|
2012-02-09 08:45:30 +01:00
|
|
|
|
2009-12-19 03:59:52 +01:00
|
|
|
o << o1.str();
|
2012-02-09 08:45:30 +01:00
|
|
|
o << " 0x0\n";
|
|
|
|
o << "};\n";
|
2009-12-19 03:59:52 +01:00
|
|
|
o << "\n";
|
|
|
|
o << o2.str();
|
|
|
|
o << "\n";
|
|
|
|
o << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerTables::setTableFields(ModRMDecision &decision,
|
|
|
|
const ModRMFilter &filter,
|
|
|
|
InstrUID uid,
|
|
|
|
uint8_t opcode) {
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < 256; ++index) {
|
2009-12-19 03:59:52 +01:00
|
|
|
if (filter.accepts(index)) {
|
|
|
|
if (decision.instructionIDs[index] == uid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (decision.instructionIDs[index] != 0) {
|
|
|
|
InstructionSpecifier &newInfo =
|
|
|
|
InstructionSpecifiers[uid];
|
|
|
|
InstructionSpecifier &previousInfo =
|
|
|
|
InstructionSpecifiers[decision.instructionIDs[index]];
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2011-09-11 22:23:20 +02:00
|
|
|
if(previousInfo.name == "NOOP" && (newInfo.name == "XCHG16ar" ||
|
|
|
|
newInfo.name == "XCHG32ar" ||
|
2011-10-07 07:35:38 +02:00
|
|
|
newInfo.name == "XCHG32ar64" ||
|
2011-09-11 22:23:20 +02:00
|
|
|
newInfo.name == "XCHG64ar"))
|
|
|
|
continue; // special case for XCHG*ar and NOOP
|
2009-12-19 03:59:52 +01:00
|
|
|
|
|
|
|
if (outranks(previousInfo.insnContext, newInfo.insnContext))
|
|
|
|
continue;
|
2012-07-31 07:27:01 +02:00
|
|
|
|
2014-02-13 08:07:16 +01:00
|
|
|
if (previousInfo.insnContext == newInfo.insnContext) {
|
2009-12-19 03:59:52 +01:00
|
|
|
errs() << "Error: Primary decode conflict: ";
|
|
|
|
errs() << newInfo.name << " would overwrite " << previousInfo.name;
|
|
|
|
errs() << "\n";
|
|
|
|
errs() << "ModRM " << index << "\n";
|
|
|
|
errs() << "Opcode " << (uint16_t)opcode << "\n";
|
|
|
|
errs() << "Context " << stringForContext(newInfo.insnContext) << "\n";
|
|
|
|
HasConflicts = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
decision.instructionIDs[index] = uid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerTables::setTableFields(OpcodeType type,
|
|
|
|
InstructionContext insnContext,
|
|
|
|
uint8_t opcode,
|
|
|
|
const ModRMFilter &filter,
|
2011-09-23 08:57:25 +02:00
|
|
|
InstrUID uid,
|
2011-10-04 08:30:42 +02:00
|
|
|
bool is32bit,
|
2015-01-02 08:02:25 +01:00
|
|
|
bool ignoresVEX_L,
|
|
|
|
unsigned addressSize) {
|
2009-12-19 03:59:52 +01:00
|
|
|
ContextDecision &decision = *Tables[type];
|
|
|
|
|
2012-07-31 08:02:05 +02:00
|
|
|
for (unsigned index = 0; index < IC_max; ++index) {
|
2015-01-02 08:02:25 +01:00
|
|
|
if ((is32bit || addressSize == 16) &&
|
|
|
|
inheritsFrom((InstructionContext)index, IC_64BIT))
|
2011-09-23 08:57:25 +02:00
|
|
|
continue;
|
|
|
|
|
2015-01-02 08:02:25 +01:00
|
|
|
bool adSize64 = addressSize == 64;
|
2012-07-31 07:27:01 +02:00
|
|
|
if (inheritsFrom((InstructionContext)index,
|
2015-01-02 08:02:25 +01:00
|
|
|
InstructionSpecifiers[uid].insnContext, ignoresVEX_L,
|
|
|
|
adSize64))
|
2012-07-31 07:27:01 +02:00
|
|
|
setTableFields(decision.opcodeDecisions[index].modRMDecisions[opcode],
|
2009-12-19 03:59:52 +01:00
|
|
|
filter,
|
|
|
|
uid,
|
|
|
|
opcode);
|
|
|
|
}
|
|
|
|
}
|