crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStackLib/Plugins/Accurate/Instructions/Types/AccInstDataProcessing.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.Collections.Generic;
       
    19 using System.Text;
       
    20 using System.IO;
       
    21 using SymbianUtils.BasicTypes;
       
    22 using SymbianStackAlgorithmAccurate.CPU;
       
    23 using SymbianStackAlgorithmAccurate.Prologue;
       
    24 using SymbianStructuresLib.Arm;
       
    25 using SymbianStructuresLib.Arm.Instructions;
       
    26 using SymbianStructuresLib.Arm.Registers;
       
    27 using SymbianInstructionLib.Arm.Instructions.Common;
       
    28 using SymbianInstructionLib.Arm.Instructions.Arm;
       
    29 using SymbianInstructionLib.Arm.Instructions.Arm.DataProcessing;
       
    30 using SymbianInstructionLib.Arm.Instructions.Thumb;
       
    31 using SymbianInstructionLib.Arm.Instructions.Thumb.DataProcessing;
       
    32 
       
    33 namespace SymbianStackAlgorithmAccurate.Instructions.Types
       
    34 {
       
    35     internal class AccInstDataProcessing : AccInstruction
       
    36     {
       
    37         #region Constructors
       
    38         public AccInstDataProcessing( IArmInstruction aInstruction )
       
    39             : base( aInstruction )
       
    40         {
       
    41             System.Diagnostics.Debug.Assert( base.Instruction.AIGroup == TArmInstructionGroup.EGroupDataProcessing );
       
    42         }
       
    43         #endregion
       
    44 
       
    45         #region API
       
    46         internal override void Process( ArmPrologueHelper aProlog )
       
    47         {
       
    48             IArmInstruction instruction = base.Instruction;
       
    49             
       
    50             // Only unconditional instructions are handled
       
    51             if ( instruction.AIConditionCode == TArmInstructionCondition.AL )
       
    52             {
       
    53                 // Two heuristically observed requirements:
       
    54                 //
       
    55                 // 1) It must be an immediate instruction
       
    56                 // 2) It must apply with source & destination registers both being SP
       
    57                 if ( instruction is ArmInstruction )
       
    58                 {
       
    59                     // Aim is to detect modifications to SP (i.e. reservation of stack space)
       
    60                     Arm_DataProcessing armDpInst = instruction as Arm_DataProcessing;
       
    61                     
       
    62                     // 1) Must supply an immediate value
       
    63                     if ( armDpInst != null && armDpInst.SuppliesImmediate )
       
    64                     {
       
    65                         // 2) Must apply to SP
       
    66                         if ( armDpInst.Rd == TArmRegisterType.EArmReg_SP &&
       
    67                              armDpInst.Rn == TArmRegisterType.EArmReg_SP )
       
    68                         {
       
    69                             uint immediate = armDpInst.Immediate;
       
    70                             HandleDPOperation( armDpInst.OperationType, immediate, aProlog );
       
    71                         }
       
    72                     }
       
    73                 }
       
    74                 else if ( instruction is ThumbInstruction )
       
    75                 {
       
    76                     Thumb_AddOrSubtract thumbDpInst = instruction as Thumb_AddOrSubtract;
       
    77 
       
    78                     // 2) Must apply to SP
       
    79                     if ( thumbDpInst.Rd == TArmRegisterType.EArmReg_SP )
       
    80                     {
       
    81                         // 1) Must supply an immediate value
       
    82                         if ( thumbDpInst != null && thumbDpInst.SuppliesImmediate )
       
    83                         {
       
    84                             uint immediate = thumbDpInst.Immediate;
       
    85                             HandleDPOperation( thumbDpInst.OperationType, immediate, aProlog );
       
    86                         }
       
    87                         else if ( thumbDpInst is Thumb_Add_2Regs_High )
       
    88                         {
       
    89                             // Handle the case where one register supplies the number of
       
    90                             // words by which the stack pointer is incremented. Used when 
       
    91                             // a large stack allocation is made.
       
    92                         }
       
    93                     }
       
    94                 }
       
    95                 else
       
    96                 {
       
    97                     throw new NotSupportedException( "Instruction type not supported" );
       
    98                 }
       
    99             }
       
   100         }
       
   101         #endregion
       
   102 
       
   103         #region Properties
       
   104         public bool AppliesToSP
       
   105         {
       
   106             get
       
   107             {
       
   108                 bool ret = false;
       
   109                 IArmInstruction instruction = base.Instruction;
       
   110 
       
   111                 // Only unconditional instructions are handled
       
   112                 if ( instruction.AIConditionCode == TArmInstructionCondition.AL )
       
   113                 {
       
   114                     // Two heuristically observed requirements:
       
   115                     //
       
   116                     // 1) It must be an immediate instruction
       
   117                     // 2) It must apply with source & destination registers both being SP
       
   118                     if ( instruction is ArmInstruction )
       
   119                     {
       
   120                         // Aim is to detect modifications to SP (i.e. reservation of stack space)
       
   121                         Arm_DataProcessing armDpInst = instruction as Arm_DataProcessing;
       
   122 
       
   123                         // 1) Must supply an immediate value
       
   124                         if ( armDpInst != null && armDpInst.SuppliesImmediate )
       
   125                         {
       
   126                             // 2) Must apply to SP
       
   127                             if ( armDpInst.Rd == TArmRegisterType.EArmReg_SP &&
       
   128                                  armDpInst.Rn == TArmRegisterType.EArmReg_SP )
       
   129                             {
       
   130                                 ret = true;
       
   131                             }
       
   132                         }
       
   133                     }
       
   134                     else if ( instruction is ThumbInstruction )
       
   135                     {
       
   136                         Thumb_AddOrSubtract thumbDpInst = instruction as Thumb_AddOrSubtract;
       
   137 
       
   138                         // 2) Must apply to SP
       
   139                         if ( thumbDpInst.Rd == TArmRegisterType.EArmReg_SP )
       
   140                         {
       
   141                             // 1) Must supply an immediate value
       
   142                             if ( thumbDpInst != null && thumbDpInst.SuppliesImmediate )
       
   143                             {
       
   144                                 ret = true;
       
   145                             }
       
   146                             else if ( thumbDpInst is Thumb_Add_2Regs_High )
       
   147                             {
       
   148                                 // Handle the case where one register supplies the number of
       
   149                                 // words by which the stack pointer is incremented. Used when 
       
   150                                 // a large stack allocation is made.
       
   151                             }
       
   152                         }
       
   153                     }
       
   154                 }
       
   155 
       
   156                 return ret;
       
   157             }
       
   158         }
       
   159         #endregion
       
   160 
       
   161         #region Internal methods
       
   162         private void HandleDPOperation( TArmDataProcessingType aType, uint aImmediate, ArmPrologueHelper aProlog )
       
   163         {
       
   164             int wordsPushed = (int) aImmediate / 4;
       
   165             //
       
   166             switch( aType )
       
   167             {
       
   168             case TArmDataProcessingType.ADD:
       
   169                 wordsPushed = -wordsPushed;
       
   170                 break;
       
   171             case TArmDataProcessingType.SUB:
       
   172                 break;
       
   173             default:
       
   174                 throw new NotSupportedException( "Data processing does not (yet) support instructions of type: " + aType );
       
   175             }
       
   176             //
       
   177             aProlog.AddToNumberOfWordsPushedOnStack( wordsPushed );
       
   178         }
       
   179         #endregion
       
   180 
       
   181         #region Data members
       
   182         #endregion
       
   183     }
       
   184 }
       
   185