crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianETMLib/ETB/Config/ETBEngineConfig.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 DecompressETB.Buffer;
       
    21 using DecompressETB.State;
       
    22 using DecompressETB.Types;
       
    23 
       
    24 namespace DecompressETB.Config
       
    25 {
       
    26     public class ETBEngineConfig
       
    27     {
       
    28         #region Constructors
       
    29         public ETBEngineConfig()
       
    30         {
       
    31             SetExceptionVector( TETBExceptionVector.EReset, 0 );
       
    32             SetExceptionVector( TETBExceptionVector.EUndefinedInstruction, 0 );
       
    33             SetExceptionVector( TETBExceptionVector.ESWI, 0 );
       
    34             SetExceptionVector( TETBExceptionVector.EPrefetchAbort, 0 );
       
    35             SetExceptionVector( TETBExceptionVector.EDataAbort, 0 );
       
    36             SetExceptionVector( TETBExceptionVector.EIRQ, 0 );
       
    37             SetExceptionVector( TETBExceptionVector.EFIQ, 0 );
       
    38         }
       
    39         #endregion
       
    40 
       
    41         #region API
       
    42         // <summary>
       
    43         // Use this to seed the context id to thread name mapping
       
    44         // </summary>
       
    45         public void SetRegisterContextID( uint aID, string aName )
       
    46         {
       
    47             if ( !iContextIDs.ContainsKey( aID ) )
       
    48             {
       
    49                 iContextIDs.Add( aID, aName );
       
    50             }
       
    51         }
       
    52 
       
    53         public void SetExceptionVector( TETBExceptionVector aVector, uint aInstruction )
       
    54         {
       
    55             if ( !iExceptionVectors.ContainsKey( aVector ) )
       
    56             {
       
    57                 iExceptionVectors.Add( aVector, aInstruction );
       
    58             }
       
    59             else
       
    60             {
       
    61                 iExceptionVectors[ aVector ] = aInstruction;
       
    62             }
       
    63         }
       
    64 
       
    65         public string GetContextID( uint aID )
       
    66         {
       
    67             string ret = "Unknown Thread";
       
    68             //
       
    69             if ( iContextIDs.ContainsKey( aID ) )
       
    70             {
       
    71                 ret = iContextIDs[ aID ];
       
    72             }
       
    73             //
       
    74             return ret;
       
    75         }
       
    76 
       
    77         internal uint GetExceptionVector( TETBExceptionVector aVector )
       
    78         {
       
    79             uint ret = iExceptionVectors[ aVector ];
       
    80             return ret;
       
    81         }
       
    82 
       
    83         internal TETBExceptionVector MapToExceptionVector( uint aAddress )
       
    84         {
       
    85             System.Diagnostics.Debug.Assert( IsExceptionVector( aAddress ) );
       
    86             // 
       
    87             TETBExceptionVector ret = TETBExceptionVector.EUndefinedInstruction;
       
    88             //
       
    89             uint baseAddress = (uint) ExceptionVectorLocation;
       
    90             uint delta = aAddress - baseAddress;
       
    91             switch ( delta )
       
    92             {
       
    93             case (uint) TETBExceptionVector.EReset:
       
    94             case (uint) TETBExceptionVector.EUndefinedInstruction:
       
    95             case (uint) TETBExceptionVector.ESWI:
       
    96             case (uint) TETBExceptionVector.EPrefetchAbort:
       
    97             case (uint) TETBExceptionVector.EDataAbort:
       
    98             case (uint) TETBExceptionVector.EIRQ:
       
    99             case (uint) TETBExceptionVector.EFIQ:
       
   100                 ret = (TETBExceptionVector) delta;
       
   101                 break;
       
   102             default:
       
   103                 throw new NotSupportedException( "Specified address is an unsupported vector location" );
       
   104                 break;
       
   105             }
       
   106             //
       
   107             return ret;
       
   108         }
       
   109 
       
   110         internal bool IsExceptionVector( uint aAddress )
       
   111         {
       
   112             bool ret = false;
       
   113             
       
   114             // Get current vector setting and also the vector address range
       
   115             TETBExceptionVectorLocation type = ExceptionVectorLocation;
       
   116             uint min = (uint) type;
       
   117             uint max = min + (uint) TETBExceptionVector.EFIQ;
       
   118             //
       
   119             ret = ( aAddress >= min && aAddress <= max );
       
   120             //
       
   121             return ret;
       
   122         }
       
   123         #endregion
       
   124 
       
   125         #region Properties
       
   126         public bool Verbose
       
   127         {
       
   128             get { return iVerbose; }
       
   129             set { iVerbose = value; }
       
   130         }
       
   131 
       
   132         public uint ETMControlRegister
       
   133         {
       
   134             get { return iETMControlRegister; }
       
   135             set { iETMControlRegister = value; }
       
   136         }
       
   137 
       
   138         public uint SystemControlRegister
       
   139         {
       
   140             get { return iSystemControlRegister; }
       
   141             set { iSystemControlRegister = value; }
       
   142         }
       
   143 
       
   144         public int ContextIDSize
       
   145         {
       
   146             get
       
   147             {
       
   148                 // Bits [15:14] define the context id size.
       
   149                 uint ret = iETMControlRegister & 0xC000; // b11000000 00000000
       
   150                 ret >>= 14;
       
   151                 if ( ret > 0 )
       
   152                 {
       
   153                     ++ret;
       
   154                 }
       
   155                 return (int) ret;
       
   156             }
       
   157         }
       
   158 
       
   159         public TETBExceptionVectorLocation ExceptionVectorLocation
       
   160         {
       
   161             get
       
   162             {
       
   163                 TETBExceptionVectorLocation ret = TETBExceptionVectorLocation.ENormal;
       
   164                 uint mask = (uint) ( 1 << 13 );
       
   165                 if ( ( iSystemControlRegister & mask ) == mask )
       
   166                 {
       
   167                     ret = TETBExceptionVectorLocation.EHigh;
       
   168                 }
       
   169                 return ret;
       
   170             }
       
   171         }
       
   172         #endregion
       
   173 
       
   174         #region Internal constants
       
   175         #endregion
       
   176 
       
   177         #region From System.Object
       
   178         #endregion
       
   179 
       
   180         #region Data members
       
   181         private bool iVerbose = false;
       
   182         private uint iETMControlRegister = 0xC000; // 4 byte context id
       
   183         private uint iSystemControlRegister = 1 << 13;
       
   184         private Dictionary<TETBExceptionVector, uint> iExceptionVectors = new Dictionary<TETBExceptionVector, uint>();
       
   185         private Dictionary<uint, string> iContextIDs = new Dictionary<uint, string>();
       
   186         #endregion
       
   187     }
       
   188 }