41c41,43
< void Decoder::doReset()
---
>
> Decoder::State
> Decoder::doResetState()
44a47,49
> instBytes = &decodePages->lookup(origPC);
> chunkIdx = 0;
>
58,60c63,69
< m5Reg = tc->readMiscRegNoEffect(MISCREG_M5_REG);
< emi.mode.mode = m5Reg.mode;
< emi.mode.submode = m5Reg.submode;
---
>
> if (instBytes->si) {
> return FromCacheState;
> } else {
> instBytes->chunks.clear();
> return PrefixState;
> }
63c72,73
< void Decoder::process()
---
> void
> Decoder::process()
72a83,90
> if (state == ResetState)
> state = doResetState();
> if (state == FromCacheState) {
> state = doFromCacheState();
> } else {
> instBytes->chunks.push_back(fetchChunk);
> }
>
74,75c92
< while(!instDone && !outOfBytes)
< {
---
> while (!instDone && !outOfBytes) {
77,81c94
< switch(state)
< {
< case ResetState:
< doReset();
< state = PrefixState;
---
> switch (state) {
107a121,152
> Decoder::State
> Decoder::doFromCacheState()
> {
> DPRINTF(Decoder, "Looking at cache state.\n");
> if ((fetchChunk & instBytes->masks[chunkIdx]) !=
> instBytes->chunks[chunkIdx]) {
> DPRINTF(Decoder, "Decode cache miss.\n");
> // The chached chunks didn't match what was fetched. Fall back to the
> // predecoder.
> instBytes->chunks[chunkIdx] = fetchChunk;
> instBytes->chunks.resize(chunkIdx + 1);
> instBytes->si = NULL;
> chunkIdx = 0;
> fetchChunk = instBytes->chunks[0];
> offset = origPC % sizeof(MachInst);
> basePC = origPC - offset;
> return PrefixState;
> } else if (chunkIdx == instBytes->chunks.size() - 1) {
> // We matched the cache, so use its value.
> instDone = true;
> offset = instBytes->lastOffset;
> if (offset == sizeof(MachInst))
> outOfBytes = true;
> return ResetState;
> } else {
> // We matched so far, but need to check more chunks.
> chunkIdx++;
> outOfBytes = true;
> return FromCacheState;
> }
> }
>
110c155,156
< Decoder::State Decoder::doPrefixState(uint8_t nextByte)
---
> Decoder::State
> Decoder::doPrefixState(uint8_t nextByte)
167c213,214
< Decoder::State Decoder::doOpcodeState(uint8_t nextByte)
---
> Decoder::State
> Decoder::doOpcodeState(uint8_t nextByte)
197c244
< logOpSize = m5Reg.altOp;
---
> logOpSize = altOp;
199c246
< logOpSize = m5Reg.defOp;
---
> logOpSize = defOp;
208c255
< logAddrSize = m5Reg.altAddr;
---
> logAddrSize = altAddr;
210c257
< logAddrSize = m5Reg.defAddr;
---
> logAddrSize = defAddr;
217c264
< emi.stackSize = 1 << m5Reg.stack;
---
> emi.stackSize = 1 << stack;
245c292,293
< Decoder::State Decoder::doModRMState(uint8_t nextByte)
---
> Decoder::State
> Decoder::doModRMState(uint8_t nextByte)
251c299
< if (m5Reg.defOp == 1) {
---
> if (defOp == 1) {
300c348,349
< Decoder::State Decoder::doSIBState(uint8_t nextByte)
---
> Decoder::State
> Decoder::doSIBState(uint8_t nextByte)
321c370,371
< Decoder::State Decoder::doDisplacementState()
---
> Decoder::State
> Decoder::doDisplacementState()
368c418,419
< Decoder::State Decoder::doImmediateState()
---
> Decoder::State
> Decoder::doImmediateState()
411,412c462,463
< DecodeCache::InstMap Decoder::instMap;
< DecodeCache::AddrMap<StaticInstPtr> Decoder::decodePages;
---
> Decoder::InstBytes Decoder::dummy;
> Decoder::InstCacheMap Decoder::instCacheMap;
417,419c468,470
< StaticInstPtr &si = decodePages.lookup(addr);
< if (si && (si->machInst == mach_inst))
< return si;
---
> DecodeCache::InstMap::iterator iter = instMap->find(mach_inst);
> if (iter != instMap->end())
> return iter->second;
421,423c472,486
< DecodeCache::InstMap::iterator iter = instMap.find(mach_inst);
< if (iter != instMap.end()) {
< si = iter->second;
---
> StaticInstPtr si = decodeInst(mach_inst);
> (*instMap)[mach_inst] = si;
> return si;
> }
>
> StaticInstPtr
> Decoder::decode(PCState &nextPC)
> {
> if (!instDone)
> return NULL;
> instDone = false;
> updateNPC(nextPC);
>
> StaticInstPtr &si = instBytes->si;
> if (si)
424a488,514
>
> // We didn't match in the AddrMap, but we still populated an entry. Fix
> // up its byte masks.
> const int chunkSize = sizeof(MachInst);
>
> instBytes->lastOffset = offset;
>
> Addr firstBasePC = basePC - (instBytes->chunks.size() - 1) * chunkSize;
> Addr firstOffset = origPC - firstBasePC;
> Addr totalSize = instBytes->lastOffset - firstOffset +
> (instBytes->chunks.size() - 1) * chunkSize;
> int start = firstOffset;
> instBytes->masks.clear();
>
> while (totalSize) {
> int end = start + totalSize;
> end = (chunkSize < end) ? chunkSize : end;
> int size = end - start;
> int idx = instBytes->masks.size();
>
> MachInst maskVal = mask(size * 8) << (start * 8);
> assert(maskVal);
>
> instBytes->masks.push_back(maskVal);
> instBytes->chunks[idx] &= instBytes->masks[idx];
> totalSize -= size;
> start = 0;
427,428c517
< si = decodeInst(mach_inst);
< instMap[mach_inst] = si;
---
> si = decode(emi, origPC);