public void FlushChanges() { TArmInstructionSet originalInstructionSet = iStateData.CurrentInstructionSet; SymAddress originalAddress = new SymAddress(iStateData.CurrentAddress.Address); //if ( !IsLastInstructionCancelled ) { // Set known address iStateData.SetKnownAddressBits(iBranchAddress.Address, iBranchAddress.KnownBits, TETMBranchType.EBranchExplicit); // Handle a change in security mode if (iSecurityMode != TArmSecurityMode.EUnknown) { iStateData.CurrentSecurityMode = iSecurityMode; } if (iExceptionType != TArmExceptionType.EUnknown) { iStateData.CurrentException = iExceptionType; } // Handle a change in instruction set if (iStateData.CurrentInstructionSet != iInstructionSet) { iStateData.CurrentInstructionSet = iInstructionSet; } } DbgTrace(originalAddress, originalInstructionSet); }
private void OnAddress(SymByte aByte) { int byteNumber = 4 - iBytesRemaining; uint val = aByte.LShift(byteNumber * 8); iAddress |= val; if (--iBytesRemaining == 0) { // Save for tracing purposes SymAddress originalAddress = new SymAddress(base.StateData.CurrentAddress.Address); TArmInstructionSet originalInstructionSet = base.StateData.CurrentInstructionSet; // Set new branch address TArmInstructionSet newInstructionSet = iInformationByte.InstructionSet; uint address = iAddress; if ((address & 0x1) == 0x1) { // We branched to THUMB, hence change of instruction set... address &= 0xFFFFFFFE; newInstructionSet = TArmInstructionSet.ETHUMB; } // Store address etc - always 32 bit full address during I-SYNC base.StateData.CurrentInstructionSet = newInstructionSet; base.StateData.SetKnownAddressBits(address, 32, TETMBranchType.EBranchExplicit); // And output debug trace... Trace(originalAddress, originalInstructionSet, base.StateData.CurrentAddress, newInstructionSet); // We're done iState = TState.EStateIdle; } }
private void DbgTrace(string aType, SymAddress aOriginalAddress, TArmInstructionSet aOriginalISet) { StringBuilder lines = new StringBuilder(); lines.AppendLine(" " + aType); // if (iStateData.LastBranch.IsKnown) { lines.AppendLine(string.Format(" using: {0} 0x{1} to go...", iBranchAddress.AddressBinary, iBranchAddress.AddressHex) ); lines.AppendLine(string.Format(" from: {0} 0x{1} {2} 0x{3:x8} {4}", aOriginalAddress.AddressBinary, aOriginalAddress.AddressHex, ETMDecodeState.MakeInstructionSetPrefix(aOriginalISet), aOriginalAddress, iStateData.Engine.LookUpSymbol(aOriginalAddress)) ); lines.AppendLine(string.Format(" to: {0} 0x{1} {2} 0x{3:x8} {4}", iStateData.CurrentAddress.AddressBinary, iStateData.CurrentAddress.AddressHex, ETMDecodeState.MakeInstructionSetPrefix(iStateData.CurrentInstructionSet), iStateData.CurrentAddress, iStateData.Engine.LookUpSymbol(iStateData.CurrentAddress)) ); } // Trace(lines.ToString()); }
public ETMBranch(SymAddress aAddress, int aNumber, TETMBranchType aType, TArmInstructionSet aInstructionSet, TArmExceptionType aExceptionType) { iAddress = aAddress; iNumber = aNumber; iType = aType; iInstructionSet = aInstructionSet; iExceptionType = aExceptionType; }
private void DbgTrace(SymAddress aOriginalAddress, TArmInstructionSet aOriginalISet) { if (Count == 5) { DbgTrace("BRANCH-F", aOriginalAddress, aOriginalISet); } else { DbgTrace("BRANCH-P", aOriginalAddress, aOriginalISet); } }
private void Trace(SymAddress aOriginalAddress, TArmInstructionSet aOriginalISet, SymAddress aNewAddress, TArmInstructionSet aNewISet) { System.Diagnostics.Debug.Assert(base.StateData.LastBranch.IsKnown); // StringBuilder lines = new StringBuilder(); lines.AppendLine(" I-SYNC"); lines.AppendLine(string.Format(" from: {0} 0x{1:x8} {2}", ETMDecodeState.MakeInstructionSetPrefix(aOriginalISet), aOriginalAddress, StateData.Engine.LookUpSymbol(aOriginalAddress))); lines.AppendLine(string.Format(" to: {0} 0x{1:x8} {2}", ETMDecodeState.MakeInstructionSetPrefix(aNewISet), aNewAddress, StateData.Engine.LookUpSymbol(aNewAddress))); // base.Trace(lines.ToString()); }
private void TraceDirectBranch(SymAddress aOriginalAddress, TArmInstructionSet aOriginalISet, SymAddress aNewAddress, TArmInstructionSet aNewISet) { StringBuilder lines = new StringBuilder(); lines.AppendLine(" BRANCH-D"); // if (base.StateData.LastBranch.IsKnown) { lines.AppendLine(string.Format(" from: {0} 0x{1:x8} {2}", ETMDecodeState.MakeInstructionSetPrefix(aOriginalISet), aOriginalAddress, StateData.Engine.LookUpSymbol(aOriginalAddress))); lines.AppendLine(string.Format(" to: {0} 0x{1:x8} {2}", ETMDecodeState.MakeInstructionSetPrefix(aNewISet), aNewAddress, StateData.Engine.LookUpSymbol(aNewAddress))); } else { } // base.Trace(lines.ToString()); }
public ETMInstruction(uint aAddress, IArmInstruction aInstruction) { iAddress = new SymAddress(aAddress); iInstruction = aInstruction; }
private bool CheckForBranch(ETMInstruction aInstruction) { bool branched = false; TArmInstructionSet originalInstructionSet = base.StateData.CurrentInstructionSet; SymAddress originalAddress = new SymAddress(base.StateData.CurrentAddress.Address); // if (base.StateData.LastBranch.IsKnown) { uint address = base.StateData.CurrentAddress; TArmInstructionSet instructionSet = base.StateData.CurrentInstructionSet; // if (instructionSet == TArmInstructionSet.EARM) { if (iBranchMask_ARM_BOrBL.IsMatch(aInstruction)) { // 1110 101 0 111111111111111111111101 int offset = SignExtend24BitTo32BitARM(aInstruction & 0x00FFFFFF); base.StateData.SetPC((uint)(address + offset)); branched = true; } else if (iBranchMask_ARM_BLX_BranchToThumb.IsMatch(aInstruction)) { // TODO: verify this - no data to test at the moment int offset = SignExtend24BitTo32BitARM(aInstruction & 0x00FFFFFF); base.StateData.SetPC((uint)(address + offset), TArmInstructionSet.ETHUMB); branched = true; } } else if (instructionSet == TArmInstructionSet.ETHUMB) { if (iBranchMask_THUMB_B1.IsMatch(aInstruction)) { // 15 14 13 12 11 -> 8 7 -> 0 // ----------------------------------------- // 1 1 0 1 cond signed_immed_8 int offset = SignExtend8BitTo32BitTHUMB(aInstruction & 0xFF); base.StateData.SetPC((uint)(address + offset)); branched = true; } else if (iBranchMask_THUMB_B2.IsMatch(aInstruction)) { // 15 14 13 12 11 10 -> 0 // ----------------------------------------- // 1 1 0 1 1 signed_immed_11 int offset = SignExtend11BitTo32BitTHUMB(aInstruction & 0x7FF); base.StateData.SetPC((uint)(address + offset)); branched = true; } else { ETMInstruction inst1 = base.StateData.LastInstruction; bool inst1Match = iBranchMask_THUMB_BLX_Part1.IsMatch(inst1.AIRawValue); ETMInstruction inst2 = aInstruction; bool inst2Match = iBranchMask_THUMB_BLX_Part2.IsMatch(inst2.AIRawValue); // if (inst1Match && inst2Match) { branched = HandleTHUMBMultiInstructionBranch(inst1.AIRawValue, inst2.AIRawValue); System.Diagnostics.Debug.Assert(branched == true); } } } else { throw new NotSupportedException(); } } if (branched) { base.StateData.IncrementProcessedInstructionCounter(); TraceDirectBranch(originalAddress, originalInstructionSet, base.StateData.CurrentAddress, base.StateData.CurrentInstructionSet); } // Always cache the last processed instruction base.StateData.LastInstruction = aInstruction; return(branched); }