Example #1
0
        public AccInstructionList LoadInstructions(uint aAddress, int aCount, TArmInstructionSet aType)
        {
            AccInstructionList ret = new AccInstructionList();

            // Get list of instructions from code engine
            IArmInstruction[] basicInstructions = null;
            bool available = iCodeView.GetInstructions(aAddress, aType, aCount, out basicInstructions);

            if (available)
            {
                // Convert the basic instructions into the different types
                // we can handle
                ret.AddRange(basicInstructions);
            }
            //
            return(ret);
        }
Example #2
0
        private void GetPrologueInstructions()
        {
            TArmInstructionSet instSet = CPU.CurrentProcessorMode;
            uint address = FunctionStartingAddressWithoutType;

            // Let's get unadulterated instruction counts
            int instCount = iPrologueInstructionCount;

            if (address > 0 && instCount > 0)
            {
                iInstructions = CodeHelper.LoadInstructions(address, instCount, instSet);
            }
            else
            {
                iInstructions = new AccInstructionList();
            }

            // Verify that we have the expected number of instructions.
            // If, for some reason, the code provider does not supply
            // any Prologue instructions, then we should bail out.
            int actual = iInstructions.Count;

            if (actual != instCount)
            {
                throw new Exception(string.Format("Prologue instructions unavailable or insufficient @ address: 0x{0:x8} - expected: {1}, received: {2}", FunctionStartingAddressWithoutType, instCount, actual));
            }

            // Since we fetch all the instructions from a function (leading up to the current address)
            // we may have lots more instructions that we'd ideally normally expect to see form part
            // of the function prologue. Normally, we cap the prologue instruction count at ~19 instructions,
            // so therefore we should disable any instructions beyond this maximum.
            for (int i = KMaxPrologueInstructionCount - 1; i < iInstructions.Count; i++)
            {
                iInstructions[i].Ignored = true;
            }

            // Run the instructions through the pre-filter. We tell the
            // instruction list how many instructions through the current function
            // we are because this helps to identify whether a branch has been
            // executed as the last instruction, or whether we artificially limited
            // the preamble, in which case the branch was "probably" not taken.
            iInstructions.Prefilter(iPrologueInstructionCount);
            iInstructions.DebugPrint(iEngine as ITracer);
        }
        internal override void Prefilter(AccInstructionList aInstructions, int aMyIndex, int aInstructionCountOffsetToPC)
        {
            if (this.Ignored == false)
            {
                int count = aInstructions.Count;
                //
                if (base.Instruction.AIConditionCode == TArmInstructionCondition.AL)
                {
                    // As soon as we see any unconditional branch statement we can be sure that we are past the Prologue.
                    for (int i = aMyIndex + 1; i < count; i++)
                    {
                        aInstructions[i].Ignored = true;
                    }
                }
                else
                {
                    // Count the number of interesting instructions before the conditional branch
                    int interestingInstructionCount = 0;
                    for (int i = 0; i < aMyIndex; i++)
                    {
                        AccInstruction  accInstruction = aInstructions[i];
                        IArmInstruction inst           = accInstruction.Instruction;
                        //
                        bool involvesSP = inst.QueryInvolvement(TArmRegisterType.EArmReg_SP);
                        if (involvesSP)
                        {
                            ++interestingInstructionCount;
                        }
                    }

                    // If we have seen at least one interesting instruction then assume prologue is complete.
                    if (interestingInstructionCount >= 1)
                    {
                        for (int i = aMyIndex; i < count; i++)
                        {
                            aInstructions[i].Ignored = true;
                        }
                    }
                }
            }
        }