31 #ifndef __ARCH_X86_DECODER_HH__ 32 #define __ARCH_X86_DECODER_HH__ 35 #include <unordered_map> 46 #include "debug/Decoder.hh" 108 return ((uint8_t *)&fetchChunk)[
offset];
115 int toGet = size - collected;
117 int remaining =
sizeof(
MachInst) - offset;
119 toGet = toGet > remaining ? remaining : toGet;
122 uint64_t partialImm = fetchChunk >> (offset * 8);
124 partialImm &=
mask(toGet * 8);
128 current |= partialImm;
138 DPRINTF(
Decoder,
"At the end of a chunk, idx = %d, chunks = %d.\n",
139 chunkIdx, instBytes->
chunks.size());
141 if (chunkIdx == instBytes->
chunks.size()) {
218 bool addrSizedImm =
false);
233 typedef std::unordered_map<
238 Decoder(
ISA* isa =
nullptr) : basePC(0), origPC(0), offset(0),
239 outOfBytes(true), instDone(false),
259 mode = (X86Mode)(uint64_t)m5Reg.mode;
260 submode = (
X86SubMode)(uint64_t)m5Reg.submode;
265 altAddr = m5Reg.altAddr;
266 defAddr = m5Reg.defAddr;
269 AddrCacheMap::iterator amIter = addrCacheMap.find(m5Reg);
270 if (amIter != addrCacheMap.end()) {
271 decodePages = amIter->second;
277 InstCacheMap::iterator imIter = instCacheMap.find(m5Reg);
278 if (imIter != instCacheMap.end()) {
279 instMap = imIter->second;
313 fetchChunk =
letoh(data);
331 if (!nextPC.
size()) {
332 int size = basePC + offset -
origPC;
334 "Calculating the instruction size: " 335 "basePC: %#x offset: %#x origPC: %#x size: %d\n",
336 basePC, offset, origPC, size);
338 nextPC.
npc(nextPC.
pc() + size);
354 #endif // __ARCH_X86_DECODER_HH__
static ByteTable UsesModRMThreeByte0F38
RegVal CacheKey
Caching for decoded instruction objects.
State doVex3Of3State(uint8_t)
Addr instAddr() const
Returns the memory address the bytes of this instruction came from.
State doVex2Of3State(uint8_t)
static ByteTable Prefixes
void moreBytes(const PCState &pc, Addr fetchPC, MachInst data)
State doTwoByteOpcodeState(uint8_t)
static ByteTable ImmediateTypeVex[10]
static const uint8_t SizeTypeToSize[3][10]
std::unordered_map< CacheKey, DecodePages * > AddrCacheMap
State doPrefixState(uint8_t)
StaticInstPtr decodeInst(ExtMachInst mach_inst)
State doSIBState(uint8_t)
static ByteTable ImmediateTypeThreeByte0F3A
static ByteTable UsesModRMOneByte
DecodePages * decodePages
static ByteTable UsesModRMTwoByte
static InstCacheMap instCacheMap
State processOpcode(ByteTable &immTable, ByteTable &modrmTable, bool addrSizedImm=false)
void consumeBytes(int numBytes)
State doVexOpcodeState(uint8_t)
void setM5Reg(HandyM5Reg m5Reg)
static ByteTable ImmediateTypeTwoByte
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
AddrCacheMap addrCacheMap
static ByteTable ImmediateTypeOneByte
StaticInstPtr decode(ExtMachInst mach_inst, Addr addr)
Decode a machine instruction.
A sparse map from an Addr to a Value, stored in page chunks.
DecodeCache::AddrMap< Decoder::InstBytes > DecodePages
State doVex2Of2State(uint8_t)
State doModRMState(uint8_t)
Decoder(ISA *isa=nullptr)
std::vector< MachInst > masks
This is exposed globally, independent of the ISA.
DecodeCache::InstMap< ExtMachInst > * instMap
State doDisplacementState()
State doOneByteOpcodeState(uint8_t)
State doThreeByte0F38OpcodeState(uint8_t)
const uint8_t ByteTable[256]
static ByteTable ImmediateTypeThreeByte0F38
void takeOverFrom(Decoder *old)
std::unordered_map< EMI, StaticInstPtr > InstMap
Hash for decoded instructions.
void updateNPC(X86ISA::PCState &nextPC)
std::vector< MachInst > chunks
State doThreeByte0F3AOpcodeState(uint8_t)
State processExtendedOpcode(ByteTable &immTable)
std::unordered_map< CacheKey, DecodeCache::InstMap< ExtMachInst > * > InstCacheMap
static ByteTable UsesModRMThreeByte0F3A
void getImmediate(int &collected, uint64_t ¤t, int size)