Skip to content

Commit

Permalink
[decoder] make sure to handle register dependencies in all instructio…
Browse files Browse the repository at this point in the history
…n cases
  • Loading branch information
Yang-YiFan authored and Yifan Yang committed Mar 11, 2021
1 parent c3ea067 commit 78a52c4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ Decoder::Instr::Instr(INS _ins) : ins(_ins), numLoads(0), numInRegs(0), numOutRe
// index register; optional
reg = INS_OperandMemoryIndexReg(ins, op);
if (REG_valid(reg)) inRegs[numInRegs++] = REG_FullRegName(reg);
} else if (INS_OperandIsImmediate(ins, op)
|| INS_OperandIsBranchDisplacement(ins, op)) {
// No need to do anything for immediate operands
} else if (INS_OperandReg(ins, op) == REG_X87) {
// We don't model x87 accurately in general
//reportUnhandledCase(*this, "Instr");
} else {
assert(INS_OperandIsImplicit(ins, op));
// Pin classifies the use and update of RSP in various stack
// operations as "implicit" operands. Although they contribute to
// OperandCount, OperandIsReg surprisingly returns false.
// Let's not bother to add RSP to inRegs or outRegs here,
// since we won't want to consider it as an ordinary register operand.
// (See handling of stack operations in Decoder::decodeInstr.)
//
// Even more weirdly, the use and update of RSI and RDI in MOVSB
// and similar string-handling instructions are considered
// implicit operands for which OperandIsReg returns false.
// Oh well, with ERMSB in Ivy Bridge and later,
// who knows what's the right way to model these things anyway?

// [victory] I wish these assertion weren't true, so we could
// cleanly check what the implicit register operand is.
assert(!REG_valid(INS_OperandReg(ins, op)));
assert(!REG_valid(INS_OperandMemoryBaseReg(ins, op)));
}
}

Expand Down

0 comments on commit 78a52c4

Please sign in to comment.