30 X86InstructionSize insnSize;
36 SgUnsignedCharList insnbuf;
40 X86SegmentRegister segOverride;
41 X86BranchPrediction branchPrediction;
42 bool branchPredictionEnabled;
43 bool rexPresent, rexW, rexR, rexX, rexB;
45 bool operandSizeOverride;
46 bool addressSizeOverride;
48 X86RepeatPrefix repeatPrefix;
56 bool isUnconditionalJump;
59 : ip(0), insnbufat(0), segOverride(x86_segreg_none), branchPrediction(x86_branch_prediction_none),
60 branchPredictionEnabled(
false), rexPresent(
false), rexW(
false), rexR(
false), rexX(
false), rexB(
false),
61 sizeMustBe64Bit(
false), operandSizeOverride(
false), addressSizeOverride(
false), lock(
false),
62 repeatPrefix(x86_repeat_none), modregrmByteSet(
false), modregrmByte(0), modeField(0), regField(0),
63 rmField(0), modrm(
nullptr), reg(
nullptr), isUnconditionalJump(
false) {}
69#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
71 friend class boost::serialization::access;
74 void serialize_common(S &s,
const unsigned ) {
78 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
79 s & BOOST_SERIALIZATION_NVP(wordSize);
83 void save(S &s,
const unsigned version)
const {
84 serialize_common(s, version);
88 void load(S &s,
const unsigned version) {
89 serialize_common(s, version);
93 BOOST_SERIALIZATION_SPLIT_MEMBER();
131 ExceptionX86(
const std::string &mesg,
const State &state)
133 ASSERT_require(state.insnbufat <= state.insnbuf.size());
134 if (state.insnbufat > 0)
135 bytes = SgUnsignedCharList(&state.insnbuf[0], &state.insnbuf[0] + state.insnbufat);
136 bit = 8 * state.insnbufat;
139 ExceptionX86(
const std::string &mesg,
const State &state,
size_t bit)
141 ASSERT_require(state.insnbufat <= state.insnbuf.size());
142 if (state.insnbufat > 0)
143 bytes = SgUnsignedCharList(&state.insnbuf[0], &state.insnbuf[0] + state.insnbufat);
150 rmLegacyByte, rmRexByte, rmWord, rmDWord, rmQWord, rmSegment, rmST, rmMM, rmXMM, rmControl, rmDebug, rmReturnNull
155 mmNone, mmF3, mm66, mmF2
167 uint8_t getByte(State &state)
const;
172 uint16_t getWord(State &state)
const;
177 uint32_t getDWord(State &state)
const;
182 uint64_t getQWord(State &state)
const;
195 X86InstructionSize effectiveAddressSize(State &state)
const;
198 RegisterMode effectiveOperandMode(State &state)
const {
199 return sizeToMode(effectiveOperandSize(state));
205 X86InstructionSize effectiveOperandSize(State &state)
const;
208 SgAsmType *effectiveOperandType(State &state)
const {
209 return sizeToType(effectiveOperandSize(state));
213 bool longMode()
const {
214 return insnSize == x86_insnsize_64;
218 MMPrefix mmPrefix(State &state)
const;
221 void not64(State &state)
const {
223 throw ExceptionX86(
"not valid for 64-bit code", state);
228 void setRex(State &state, uint8_t prefix)
const;
231 static RegisterMode sizeToMode(X86InstructionSize);
235 static SgAsmType *sizeToType(X86InstructionSize s);
246 SgAsmExpression *makeAddrSizeValue(State &state, int64_t val,
size_t bit_offset,
size_t bit_size)
const;
272 return makeRegister(state, fullRegisterNumber, effectiveOperandMode(state));
277 return makeRegister(state, registerNumber + (rexExtension ? 8 : 0), effectiveOperandMode(state));
281 SgAsmExpression *makeSegmentRegister(State &state, X86SegmentRegister so,
bool insn64)
const;
303 void getModRegRM(State &state, RegisterMode regMode, RegisterMode rmMode,
SgAsmType *t,
SgAsmType *tForReg =
nullptr)
const;
310 void fillInModRM(State &state, RegisterMode rmMode,
SgAsmType *t)
const;
320 void requireMemory(State &state)
const {
321 if (!state.modregrmByteSet)
322 throw ExceptionX86(
"requires Mod/RM byte", state);
323 if (state.modeField == 3)
324 throw ExceptionX86(
"requires memory", state);
434 void init(
size_t wordsize);
438 void startInstruction(State &state, SgAsmX86Instruction *insn) const {
439 startInstruction(insn->get_address(),
nullptr, 0);
440 insnSize = insn->get_baseSize();
441 state.lock = insn->get_lockPrefix();
442 state.branchPrediction = insn->get_branchPrediction();
443 state.branchPredictionEnabled = state.branchPrediction != x86_branch_prediction_none;
444 state.segOverride = insn->get_segmentOverride();
449 void startInstruction(State &state, rose_addr_t start_va,
const uint8_t *buf,
size_t bufsz)
const {
451 state.insnbuf = SgUnsignedCharList(buf, buf+bufsz);
455 state.segOverride = x86_segreg_none;
456 state.branchPrediction = x86_branch_prediction_none;
457 state.branchPredictionEnabled =
false;
458 state.rexPresent = state.rexW = state.rexR = state.rexX = state.rexB =
false;
459 state.sizeMustBe64Bit =
false;
460 state.operandSizeOverride =
false;
461 state.addressSizeOverride =
false;
463 state.repeatPrefix = x86_repeat_none;
464 state.modregrmByteSet =
false;
465 state.modregrmByte = state.modeField = state.regField = state.rmField = 0;
466 state.modrm = state.reg =
nullptr;
467 state.isUnconditionalJump =
false;