|
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 |
|
18 using System; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using SymbianUtils.BasicTypes; |
|
22 using SymbianETMLib.Common.Types; |
|
23 using SymbianETMLib.Common.Packets; |
|
24 using SymbianETMLib.Common.Utilities; |
|
25 |
|
26 namespace SymbianETMLib.Common.State |
|
27 { |
|
28 public class ETMDecodeStateCycleCount : ETMDecodeState |
|
29 { |
|
30 #region Constructors |
|
31 public ETMDecodeStateCycleCount( ETMStateData aManager ) |
|
32 : base( aManager ) |
|
33 { |
|
34 } |
|
35 #endregion |
|
36 |
|
37 #region API |
|
38 public override ETMDecodeState HandleByte( SymByte aByte ) |
|
39 { |
|
40 ETMDecodeState nextState = new ETMDecodeStateSynchronized( base.StateData ); |
|
41 |
|
42 ETMPcktCycleCount cycle = new ETMPcktCycleCount( aByte ); |
|
43 |
|
44 // Always save the byte |
|
45 iPreviousBytes.Add( aByte ); |
|
46 |
|
47 // Is the top bit set? if so, then another branch packet follows. |
|
48 // If not, we're done. |
|
49 if ( iPreviousBytes.Count == 5 ) |
|
50 { |
|
51 // Have obtained 5 bytes or then last byte of smaller run. |
|
52 Flush(); |
|
53 } |
|
54 else if ( cycle.MoreToCome ) |
|
55 { |
|
56 nextState = this; |
|
57 } |
|
58 else |
|
59 { |
|
60 // Have obtained last byte of smaller run. |
|
61 Flush(); |
|
62 } |
|
63 |
|
64 // Done. |
|
65 return nextState; |
|
66 } |
|
67 #endregion |
|
68 |
|
69 #region Properties |
|
70 protected bool IsFullBranch |
|
71 { |
|
72 get { return iPreviousBytes.Count == 5; } |
|
73 } |
|
74 #endregion |
|
75 |
|
76 #region Internal methods |
|
77 private void Flush() |
|
78 { |
|
79 // If we have a full 5 bytes, then mask off the top bits |
|
80 // from the last byte because these are reserved. |
|
81 int count = iPreviousBytes.Count; |
|
82 if ( count == 5 ) |
|
83 { |
|
84 iPreviousBytes[ 4 ].Value = (byte) ( iPreviousBytes[ 4 ].Value & 0xF ); |
|
85 } |
|
86 |
|
87 // Build final 32 bit value |
|
88 uint counter = 0; |
|
89 for ( int shift = 0; shift < count; shift++ ) |
|
90 { |
|
91 int shiftBits = shift * 8; |
|
92 uint v = (uint) ( iPreviousBytes[ shift ] << shiftBits ); |
|
93 counter |= v; |
|
94 } |
|
95 } |
|
96 |
|
97 private void Trace( uint aCounter ) |
|
98 { |
|
99 base.DbgTrace( "CYCLE_COUNT", string.Format( " - {0}", aCounter ) ); |
|
100 } |
|
101 #endregion |
|
102 |
|
103 #region Internal constants |
|
104 protected const string KFifthByteMask_NormalStateBranchAddressArm = "00001xxx"; |
|
105 protected const string KFifthByteMask_NormalStateBranchAddressThumb = "0001xxxx"; |
|
106 protected const string KFifthByteMask_NormalStateBranchAddressJazelle = "001xxxxx"; |
|
107 protected const string KFifthByteMask_Reserved1 = "00000xxx"; |
|
108 protected const string KFifthByteMask_StateBranchWithFollowingExceptionArm = "01001xxx"; |
|
109 protected const string KFifthByteMask_StateBranchWithFollowingExceptionThumb = "0101xxxx"; |
|
110 protected const string KFifthByteMask_StateBranchWithFollowingExceptionJazelle = "011xxxxx"; |
|
111 protected const string KFifthByteMask_Reserved2 = "01000xxx"; |
|
112 protected const string KFifthByteMask_ExceptionInArmState = "1xxxxxxx"; |
|
113 #endregion |
|
114 |
|
115 #region Data members |
|
116 private List<SymByte> iPreviousBytes = new List<SymByte>(); |
|
117 #endregion |
|
118 } |
|
119 } |