32 X86InstructionSize insnSize;
38 SgUnsignedCharList insnbuf;
42 X86SegmentRegister segOverride;
43 X86BranchPrediction branchPrediction;
44 bool branchPredictionEnabled;
45 bool rexPresent, rexW, rexR, rexX, rexB;
47 bool operandSizeOverride;
48 bool addressSizeOverride;
50 X86RepeatPrefix repeatPrefix;
58 bool isUnconditionalJump;
61 : ip(0), insnbufat(0), segOverride(x86_segreg_none), branchPrediction(x86_branch_prediction_none),
62 branchPredictionEnabled(
false), rexPresent(
false), rexW(
false), rexR(
false), rexX(
false), rexB(
false),
63 sizeMustBe64Bit(
false), operandSizeOverride(
false), addressSizeOverride(
false), lock(
false),
64 repeatPrefix(x86_repeat_none), modregrmByteSet(
false), modregrmByte(0), modeField(0), regField(0),
65 rmField(0), modrm(
nullptr), reg(
nullptr), isUnconditionalJump(
false) {}
71#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
73 friend class boost::serialization::access;
76 void serialize_common(S &s,
const unsigned ) {
80 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
81 s & BOOST_SERIALIZATION_NVP(wordSize);
85 void save(S &s,
const unsigned version)
const {
86 serialize_common(s, version);
90 void load(S &s,
const unsigned version) {
91 serialize_common(s, version);
95 BOOST_SERIALIZATION_SPLIT_MEMBER();
132 ExceptionX86(
const std::string &mesg,
const State &state)
134 ASSERT_require(state.insnbufat <= state.insnbuf.size());
135 if (state.insnbufat > 0)
136 bytes = SgUnsignedCharList(&state.insnbuf[0], &state.insnbuf[0] + state.insnbufat);
137 bit = 8 * state.insnbufat;
140 ExceptionX86(
const std::string &mesg,
const State &state,
size_t bit)
142 ASSERT_require(state.insnbufat <= state.insnbuf.size());
143 if (state.insnbufat > 0)
144 bytes = SgUnsignedCharList(&state.insnbuf[0], &state.insnbuf[0] + state.insnbufat);
151 rmLegacyByte, rmRexByte, rmWord, rmDWord, rmQWord, rmSegment, rmST, rmMM, rmXMM, rmControl, rmDebug, rmReturnNull
156 mmNone, mmF3, mm66, mmF2
168 uint8_t getByte(State &state)
const;
173 uint16_t getWord(State &state)
const;
178 uint32_t getDWord(State &state)
const;
183 uint64_t getQWord(State &state)
const;
196 X86InstructionSize effectiveAddressSize(State &state)
const;
199 RegisterMode effectiveOperandMode(State &state)
const {
200 return sizeToMode(effectiveOperandSize(state));
206 X86InstructionSize effectiveOperandSize(State &state)
const;
209 SgAsmType *effectiveOperandType(State &state)
const {
210 return sizeToType(effectiveOperandSize(state));
214 bool longMode()
const {
215 return insnSize == x86_insnsize_64;
219 MMPrefix mmPrefix(State &state)
const;
222 void not64(State &state)
const {
224 throw ExceptionX86(
"not valid for 64-bit code", state);
229 void setRex(State &state, uint8_t prefix)
const;
232 static RegisterMode sizeToMode(X86InstructionSize);
236 static SgAsmType *sizeToType(X86InstructionSize s);
247 SgAsmExpression *makeAddrSizeValue(State &state, int64_t val,
size_t bit_offset,
size_t bit_size)
const;
273 return makeRegister(state, fullRegisterNumber, effectiveOperandMode(state));
278 return makeRegister(state, registerNumber + (rexExtension ? 8 : 0), effectiveOperandMode(state));
282 SgAsmExpression *makeSegmentRegister(State &state, X86SegmentRegister so,
bool insn64)
const;
304 void getModRegRM(State &state, RegisterMode regMode, RegisterMode rmMode,
SgAsmType *t,
SgAsmType *tForReg =
nullptr)
const;
311 void fillInModRM(State &state, RegisterMode rmMode,
SgAsmType *t)
const;
321 void requireMemory(State &state)
const {
322 if (!state.modregrmByteSet)
323 throw ExceptionX86(
"requires Mod/RM byte", state);
324 if (state.modeField == 3)
325 throw ExceptionX86(
"requires memory", state);
435 void init(
size_t wordsize);
439 void startInstruction(State &state, SgAsmX86Instruction *insn) const {
440 startInstruction(insn->get_address(),
nullptr, 0);
441 insnSize = insn->get_baseSize();
442 state.lock = insn->get_lockPrefix();
443 state.branchPrediction = insn->get_branchPrediction();
444 state.branchPredictionEnabled = state.branchPrediction != x86_branch_prediction_none;
445 state.segOverride = insn->get_segmentOverride();
450 void startInstruction(State &state,
Address start_va,
const uint8_t *buf,
size_t bufsz)
const {
452 state.insnbuf = SgUnsignedCharList(buf, buf+bufsz);
456 state.segOverride = x86_segreg_none;
457 state.branchPrediction = x86_branch_prediction_none;
458 state.branchPredictionEnabled =
false;
459 state.rexPresent = state.rexW = state.rexR = state.rexX = state.rexB =
false;
460 state.sizeMustBe64Bit =
false;
461 state.operandSizeOverride =
false;
462 state.addressSizeOverride =
false;
464 state.repeatPrefix = x86_repeat_none;
465 state.modregrmByteSet =
false;
466 state.modregrmByte = state.modeField = state.regField = state.rmField = 0;
467 state.modrm = state.reg =
nullptr;
468 state.isUnconditionalJump =
false;