crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStackLib/Plugins/Accurate/Instructions/Types/AccInstDataTransfer.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 SymbianStructuresLib.Arm.Registers.VFP;
       
    28 using SymbianInstructionLib.Arm.Instructions.Common;
       
    29 using SymbianInstructionLib.Arm.Instructions.Arm;
       
    30 using SymbianInstructionLib.Arm.Instructions.Arm.DataTransfer;
       
    31 using SymbianInstructionLib.Arm.Instructions.Thumb;
       
    32 using SymbianInstructionLib.Arm.Instructions.Thumb.DataTransfer;
       
    33 
       
    34 namespace SymbianStackAlgorithmAccurate.Instructions.Types
       
    35 {
       
    36     internal class AccInstDataTransfer : AccInstruction
       
    37     {
       
    38         #region Constructors
       
    39         public AccInstDataTransfer( IArmInstruction aInstruction )
       
    40             : base( aInstruction )
       
    41         {
       
    42             System.Diagnostics.Debug.Assert( base.Instruction.AIGroup == TArmInstructionGroup.EGroupDataTransfer );
       
    43         }
       
    44         #endregion
       
    45 
       
    46         #region API
       
    47         internal override void Process( ArmPrologueHelper aProlog )
       
    48         {
       
    49             IArmInstruction instruction = base.Instruction;
       
    50             
       
    51             // Only unconditional instructions are handled
       
    52             if ( instruction.AIConditionCode == TArmInstructionCondition.AL )
       
    53             {
       
    54                 if ( instruction is ArmInstruction )
       
    55                 {
       
    56                     ArmInstruction armInst = (ArmInstruction) instruction;
       
    57                     //
       
    58                     if ( armInst is Arm_LoadOrStoreMultiple )
       
    59                     {
       
    60                         Arm_LoadOrStoreMultiple lsmInstruction = (Arm_LoadOrStoreMultiple) instruction;
       
    61 
       
    62                         // We're looking for store operations
       
    63                         if ( lsmInstruction.DataTransferType == TArmDataTransferType.EStore )
       
    64                         {
       
    65                             // We're looking for LSM's that involve SP.
       
    66                             if ( lsmInstruction.BaseRegister == TArmRegisterType.EArmReg_SP )
       
    67                             {
       
    68                                 if ( lsmInstruction is Arm_LoadOrStoreMultiple_GP )
       
    69                                 {
       
    70                                     Arm_LoadOrStoreMultiple_GP gpLsmInstruction = (Arm_LoadOrStoreMultiple_GP) lsmInstruction;
       
    71                                     HandleDTOperation( aProlog, gpLsmInstruction.Registers );
       
    72                                 }
       
    73                                 else if ( lsmInstruction is Arm_LoadOrStoreMultiple_VFP )
       
    74                                 {
       
    75                                     Arm_LoadOrStoreMultiple_VFP vfpLsmInstruction = (Arm_LoadOrStoreMultiple_VFP) lsmInstruction;
       
    76                                     HandleDTOperation( aProlog, vfpLsmInstruction.Registers );
       
    77                                 }
       
    78                             }
       
    79                         }
       
    80                     }
       
    81                 }
       
    82                 else if ( instruction is ThumbInstruction )
       
    83                 {
       
    84                     ThumbInstruction thumbInst = (ThumbInstruction) instruction;
       
    85                     //
       
    86                     if ( thumbInst is Thumb_LoadOrStoreMultiple )
       
    87                     {
       
    88                         // Special case that loads or stores multiple registers
       
    89                         Thumb_LoadOrStoreMultiple lsmThumb = (Thumb_LoadOrStoreMultiple) thumbInst;
       
    90                         if ( lsmThumb.DataTransferType == TArmDataTransferType.EStore && lsmThumb.Rd == TArmRegisterType.EArmReg_SP )
       
    91                         {
       
    92                             HandleDTOperation( aProlog, lsmThumb.Registers );
       
    93                         }
       
    94                         else
       
    95                         {
       
    96                         }
       
    97                     }
       
    98                     else if ( thumbInst is Thumb_LDR_RelativeToPC )
       
    99                     {
       
   100                         // When the Prologue needs to establish a working stack slurry, then often
       
   101                         // the scratch registers are used to build up a large subtraction from SP.
       
   102                         HandleDTLoad( aProlog, thumbInst as Thumb_LDR_RelativeToPC );
       
   103                     }
       
   104                 }
       
   105                 else
       
   106                 {
       
   107                     throw new NotSupportedException( "Instruction type not supported" );
       
   108                 }
       
   109             }
       
   110         }
       
   111         #endregion
       
   112 
       
   113         #region Properties
       
   114         #endregion
       
   115 
       
   116         #region Internal methods
       
   117         private void HandleDTOperation( ArmPrologueHelper aProlog, TArmRegisterType[] aRegisterList )
       
   118         {
       
   119             int count = aRegisterList.Length;
       
   120             for ( int i = 0; i < count; i++ )
       
   121             {
       
   122                 TArmRegisterType register = aRegisterList[ i ];
       
   123                 int push = aProlog.IncrementNumberOfWordsPushedOnStack( register );
       
   124                 aProlog.OffsetValues[ register ].Value = (uint) push;
       
   125             }
       
   126         }
       
   127 
       
   128         private void HandleDTOperation( ArmPrologueHelper aProlog, TArmRegisterTypeVFP[] aRegisterList )
       
   129         {
       
   130             int numberOfRegisters = aRegisterList.Length;
       
   131             if ( numberOfRegisters > 0 )
       
   132             {
       
   133                 // The size of the register varies... but the list will be consistent.
       
   134                 TArmRegisterTypeVFP first = aRegisterList[ 0 ];
       
   135                 //
       
   136                 int numberOfBitsPerRegister = ArmVectorFloatingPointUtils.RegisterSizeInBits( first );
       
   137                 int numberOfBytesPerRegister = numberOfBitsPerRegister / 8;
       
   138                 int totalNumberOfBytes = numberOfBytesPerRegister * numberOfRegisters;
       
   139                 int numberOfWords = totalNumberOfBytes / 4;
       
   140                 //
       
   141                 aProlog.AddToNumberOfWordsPushedOnStack( numberOfWords );
       
   142             }
       
   143         }
       
   144 
       
   145         private void HandleDTLoad( ArmPrologueHelper aProlog, Thumb_LoadOrStore_Immediate8 aInstruction )
       
   146         {
       
   147             // E.g:
       
   148             //
       
   149             // LDR R0, [PC, #40] ; Load R0 from PC + 0x40 (= address of the LDR instruction + 8 + 0x40)
       
   150             //
       
   151             TArmRegisterType reg = aInstruction.Rd;
       
   152             uint immed = aInstruction.Immediate * 4u;
       
   153 
       
   154             // PC = Is the program counter. Its value is used to calculate the memory 
       
   155             // address. Bit 1 of the PC value is forced to zero for the purpose of 
       
   156             // this calculation, so the address is always word-aligned.
       
   157             uint pcAddress = aProlog.ProloguePC & 0xFFFFFFFC;
       
   158             pcAddress = pcAddress + immed;
       
   159 
       
   160             // Read code value at specified address
       
   161             uint value = aProlog.CodeHelper.LoadData( pcAddress );
       
   162 
       
   163             // Set the register
       
   164             aProlog.CPU[ reg ].Value = value;
       
   165         }
       
   166         #endregion
       
   167 
       
   168         #region Data members
       
   169         #endregion
       
   170     }
       
   171 }
       
   172